From 742370f8aa3cbec12b2df414513acc30aa765634 Mon Sep 17 00:00:00 2001 From: Felix Burton Date: Tue, 1 May 2012 11:44:08 -0700 Subject: TCF Agent: Add send_redirect_command_by_props() to be able to redirect to a peer that is not know by the remote Locator For consistency also changed the name of send_redirect_command() to send_redirect_command_by_id(). For backwards compatibility a #define is used to map send_redirect_command() to send_redirect_command_by_id(). --- agent/tcf/framework/protocol.c | 27 ++++++++++++++++++++++++++- agent/tcf/framework/protocol.h | 6 +++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/agent/tcf/framework/protocol.c b/agent/tcf/framework/protocol.c index fcf896b2..9574f408 100644 --- a/agent/tcf/framework/protocol.c +++ b/agent/tcf/framework/protocol.c @@ -476,7 +476,7 @@ static void redirect_done(Channel * c, void * client_data, int error) { info->handler(c, info->client_data, error); } -ReplyHandlerInfo * send_redirect_command(Channel * c, const char * peerId, ReplyHandlerCB handler, void * client_data) { +ReplyHandlerInfo * send_redirect_command_by_id(Channel * c, const char * peerId, ReplyHandlerCB handler, void * client_data) { struct sendRedirectInfo * info = (struct sendRedirectInfo *)loc_alloc_zero(sizeof *info); ReplyHandlerInfo * rh; @@ -491,6 +491,31 @@ ReplyHandlerInfo * send_redirect_command(Channel * c, const char * peerId, Reply return rh; } +ReplyHandlerInfo * send_redirect_command_by_props(Channel * c, const PeerServer * ps, ReplyHandlerCB handler, void * client_data) { + struct sendRedirectInfo * info = (struct sendRedirectInfo *)loc_alloc_zero(sizeof *info); + ReplyHandlerInfo * rh; + unsigned i; + + assert(c->state == ChannelStateConnected); + c->state = ChannelStateRedirectSent; + info->handler = handler; + info->client_data = client_data; + rh = protocol_send_command(c, LOCATOR, "redirect", redirect_done, info); + write_stream(&c->out, '{'); + for (i = 0; i < ps->ind; i++) { + if (i > 0) { + write_stream(&c->out, ','); + } + json_write_string(&c->out, ps->list[i].name); + write_stream(&c->out, ':'); + json_write_string(&c->out, ps->list[i].value); + } + write_stream(&c->out, '}'); + write_stream(&c->out, 0); + write_stream(&c->out, MARKER_EOM); + return rh; +} + static void connect_done(Channel * c) { assert(c->state == ChannelStateConnected); notify_channel_opened(c); diff --git a/agent/tcf/framework/protocol.h b/agent/tcf/framework/protocol.h index c7d886fd..aa2ca7d7 100644 --- a/agent/tcf/framework/protocol.h +++ b/agent/tcf/framework/protocol.h @@ -112,7 +112,11 @@ extern int protocol_cancel_command(ReplyHandlerInfo * rh); /* * Send redirect command. */ -extern ReplyHandlerInfo * send_redirect_command(Channel * c, const char * peerId, ReplyHandlerCB handler, void * client_data); +extern ReplyHandlerInfo * send_redirect_command_by_id(Channel * c, const char * peerId, ReplyHandlerCB handler, void * client_data); +extern ReplyHandlerInfo * send_redirect_command_by_props(Channel * c, const PeerServer * ps, ReplyHandlerCB handler, void * client_data); + +/* Deprecated, use send_redirect_by_id_command */ +#define send_redirect_command send_redirect_command_by_id /* * Create protocol instance -- cgit v1.2.3