diff options
author | Benoit Perrin | 2013-03-19 12:59:41 +0000 |
---|---|---|
committer | Eugene Tarassov | 2013-03-19 19:27:10 +0000 |
commit | 6f5bd82b98d630bf0caa70e8d0ba8e3d5f78b97d (patch) | |
tree | 231312f50a00ff67e591634c26cdab15d00c9df6 /agent/tcf/main/cmdline.c | |
parent | af4f4632da8cdd11ea553acf0939dee139ca9620 (diff) | |
download | org.eclipse.tcf.agent-6f5bd82b98d630bf0caa70e8d0ba8e3d5f78b97d.tar.gz org.eclipse.tcf.agent-6f5bd82b98d630bf0caa70e8d0ba8e3d5f78b97d.tar.xz org.eclipse.tcf.agent-6f5bd82b98d630bf0caa70e8d0ba8e3d5f78b97d.zip |
Bug 403788 - Add redirect and services command to client interactive mode.
In order to get the list of services available after a redirect of the connection, two new commands are added: redirect and services.
Diffstat (limited to 'agent/tcf/main/cmdline.c')
-rw-r--r-- | agent/tcf/main/cmdline.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/agent/tcf/main/cmdline.c b/agent/tcf/main/cmdline.c index e123f404..e77dcb14 100644 --- a/agent/tcf/main/cmdline.c +++ b/agent/tcf/main/cmdline.c @@ -290,6 +290,50 @@ static int cmd_connect(char * s) { return 1; } +static void redirect_cb(Channel * c, void * client_data, int error) { + if (error) { + fprintf(stderr, "Reply error %d: %s\n", error, errno_to_str(error)); + cmd_done(error); + return; + } + + /* We flush the stream to be able to connect to the client with pipes + * and receive the message when it's displayed */ + + fflush(0); + + /* The cmd_done() is done by channel_connected() in the case the + * redirection succeed. */ +} + +static int cmd_redirect(char * s) { + PeerServer * ps; + + ps = channel_peer_from_url(s); + if (ps == NULL) { + fprintf(stderr, "Error: Cannot parse peer identifier: %s\n", s); + return -1; + } + send_redirect_command_by_props(chan, ps, redirect_cb, NULL); + peer_server_free(ps); + return 1; +} + +static int cmd_services(char * s) { + int i; + if (chan == NULL) { + printf (" Not connected to a peer.\n"); + return 0; + } + printf (" Remote services = ["); + for (i = 0; i < chan->peer_service_cnt; i++) { + if (i == 0) printf ("%s", chan->peer_service_list[i]); + else printf (", %s", chan->peer_service_list[i]); + } + printf ("]\n"); + return 0; +} + static void event_cmd_line(void * arg) { char * s = (char *)arg; size_t len; @@ -527,6 +571,8 @@ void ini_cmdline_handler(int mode, Protocol * protocol) { add_cmdline_cmd("peers", "show list of known peers", cmd_peers); add_cmdline_cmd("peerinfo", "show info about a peer", cmd_peerinfo); add_cmdline_cmd("connect", "connect a peer", cmd_connect); + add_cmdline_cmd("redirect", "redirect connection to another peer", cmd_redirect); + add_cmdline_cmd("services", "display list of services for the current connection", cmd_services); mode_flag = mode; if (infile == NULL) infile = stdin; |