From c7ff9bdcf1dd43af962c9eeed62f49f752912231 Mon Sep 17 00:00:00 2001 From: Josh Elsasser Date: Thu, 24 May 2007 06:15:48 +0000 Subject: [PATCH] Return response for tagged add message. Support noop message. --- gtk/ipc.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/gtk/ipc.c b/gtk/ipc.c index 28ca036b1..3d9d0a81e 100644 --- a/gtk/ipc.c +++ b/gtk/ipc.c @@ -103,6 +103,8 @@ static void smsg_quit( enum ipc_msg id, benc_val_t * val, int64_t tag, void * arg ); static void all_default( enum ipc_msg id, benc_val_t * val, int64_t tag, void * arg ); +static gboolean +simpleresp( struct constate * con, enum ipc_msg id, int64_t tag ); /* this is only used on the server */ static char *gl_sockpath = NULL; @@ -480,8 +482,7 @@ cli_io_sent(GSource *source SHUTUP, unsigned int id, void *vdata) { } static void -smsg_add( enum ipc_msg id SHUTUP, benc_val_t * val, int64_t tag SHUTUP, - void * arg ) +smsg_add( enum ipc_msg id SHUTUP, benc_val_t * val, int64_t tag, void * arg ) { struct constate * con = arg; struct constate_serv * srv = &con->u.serv; @@ -489,11 +490,17 @@ smsg_add( enum ipc_msg id SHUTUP, benc_val_t * val, int64_t tag SHUTUP, benc_val_t * path; int ii; - if( NULL == srv->core || TYPE_LIST != val->type ) + if( NULL == srv->core ) { return; } + if( NULL == val || TYPE_LIST != val->type ) + { + simpleresp( con, tag, IPC_MSG_NOTSUP ); + return; + } + action = toraddaction( tr_prefs_get( PREF_ID_ADDIPC ) ); for( ii = 0; ii < val->val.l.count; ii++ ) { @@ -506,6 +513,9 @@ smsg_add( enum ipc_msg id SHUTUP, benc_val_t * val, int64_t tag SHUTUP, } } tr_core_torrents_added( TR_CORE( srv->core ) ); + + /* XXX should send info response back with torrent ids */ + simpleresp( con, IPC_MSG_OK, tag ); } static void @@ -519,16 +529,36 @@ smsg_quit( enum ipc_msg id SHUTUP, benc_val_t * val SHUTUP, int64_t tag SHUTUP, } static void -all_default( enum ipc_msg id SHUTUP, benc_val_t * val SHUTUP, int64_t tag, - void * arg ) +all_default( enum ipc_msg id, benc_val_t * val SHUTUP, int64_t tag, void * arg ) +{ + switch( id ) + { + case IPC_MSG_FAIL: + case IPC_MSG_NOTSUP: + case IPC_MSG_OK: + break; + case IPC_MSG_NOOP: + simpleresp( arg, IPC_MSG_OK, tag ); + break; + default: + simpleresp( arg, IPC_MSG_NOTSUP, tag ); + break; + } +} + +static gboolean +simpleresp( struct constate * con, enum ipc_msg id, int64_t tag ) { - struct constate * con = arg; uint8_t * buf; size_t size; - buf = ipc_mkempty( &con->ipc, &size, IPC_MSG_NOTSUP, tag ); - if( NULL != buf ) + buf = ipc_mkempty( &con->ipc, &size, id, tag ); + if( NULL == buf ) { - io_send_keepdata( con->source, buf, size ); + return FALSE; } + + io_send_keepdata( con->source, buf, size ); + + return TRUE; }