Implement listen mode (ticket #25).

This commit is contained in:
Michael Jumper 2013-09-19 14:41:28 -07:00
parent 9c4adf60a2
commit 157828ef18
2 changed files with 40 additions and 0 deletions

View File

@ -77,6 +77,8 @@ const char* GUAC_CLIENT_ARGS[] = {
"audio-servername", "audio-servername",
#endif #endif
"reverse-connect",
"listen-timeout",
NULL NULL
}; };
@ -102,6 +104,8 @@ enum VNC_ARGS_IDX {
IDX_AUDIO_SERVERNAME, IDX_AUDIO_SERVERNAME,
#endif #endif
IDX_REVERSE_CONNECT,
IDX_LISTEN_TIMEOUT,
VNC_ARGS_COUNT VNC_ARGS_COUNT
}; };
@ -165,6 +169,20 @@ static rfbClient* __guac_vnc_get_client(guac_client* client) {
} }
#endif #endif
/* If reverse connection enabled, start listening */
if (guac_client_data->reverse_connect) {
guac_client_log_info(client, "Listening for connections on port %i",
guac_client_data->port);
/* Listen for connection from server */
rfb_client->listenPort = guac_client_data->port;
if (listenForIncomingConnectionsNoFork(rfb_client,
guac_client_data->listen_timeout*1000) <= 0)
return NULL;
}
/* Connect */ /* Connect */
if (rfbInitClient(rfb_client, NULL, NULL)) if (rfbInitClient(rfb_client, NULL, NULL))
return rfb_client; return rfb_client;
@ -239,6 +257,16 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
else else
retries_remaining = 0; retries_remaining = 0;
/* Set reverse-connection flag */
guac_client_data->reverse_connect =
(strcmp(argv[IDX_REVERSE_CONNECT], "true") == 0);
/* Parse listen timeout */
if (argv[IDX_LISTEN_TIMEOUT][0] != '\0')
guac_client_data->listen_timeout = atoi(argv[IDX_LISTEN_TIMEOUT]);
else
guac_client_data->listen_timeout = 5000;
/* Attempt connection */ /* Attempt connection */
rfb_client = __guac_vnc_get_client(client); rfb_client = __guac_vnc_get_client(client);

View File

@ -134,6 +134,18 @@ typedef struct vnc_guac_client_data {
*/ */
int dest_port; int dest_port;
/**
* Whether not actually connecting to a VNC server, but rather listening
* for a connection from the VNC server (reverse connection).
*/
int reverse_connect;
/**
* The maximum amount of time to wait when listening for connections, in
* milliseconds.
*/
int listen_timeout;
/** /**
* Whether the cursor should be rendered on the server (remote) or on the * Whether the cursor should be rendered on the server (remote) or on the
* client (local). * client (local).