From 75b96a2cf57a281cd3c3811891e25ce487685331 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 12 Nov 2012 16:46:19 -0500 Subject: [PATCH] LP#1268619: wesocket translator : starting packet inspection Signed-off-by: Bill Erickson --- src/gateway/osrf_websocket_translator.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/gateway/osrf_websocket_translator.c b/src/gateway/osrf_websocket_translator.c index b6205d8..49cff49 100644 --- a/src/gateway/osrf_websocket_translator.c +++ b/src/gateway/osrf_websocket_translator.c @@ -271,12 +271,14 @@ static size_t CALLBACK on_message_handler(void *data, jsonObject *msg_wrapper = NULL; // free me const jsonObject *tmp_obj = NULL; + const jsonObject *osrf_msg_list = NULL; const jsonObject *osrf_msg = NULL; const char *service = NULL; const char *thread = NULL; const char *log_xid = NULL; char *msg_body = NULL; char *recipient = NULL; + int i; if (buffer_size <= 0) return OK; @@ -287,14 +289,14 @@ static size_t CALLBACK on_message_handler(void *data, memcpy(buf, buffer, buffer_size); buf[buffer_size] = '\0'; - msg_wrapper = jsonParseRaw(buf); + msg_wrapper = jsonParse(buf); if (msg_wrapper == NULL) { osrfLogWarning(OSRF_LOG_MARK, "WS Invalid JSON: %s", buf); return HTTP_BAD_REQUEST; } - osrf_msg = jsonObjectGetKeyConst(msg_wrapper, "osrf_msg"); + osrf_msg_list = jsonObjectGetKeyConst(msg_wrapper, "osrf_msg"); if (tmp_obj = jsonObjectGetKeyConst(msg_wrapper, "service")) service = jsonObjectGetString(tmp_obj); @@ -353,20 +355,36 @@ static size_t CALLBACK on_message_handler(void *data, } } - // TODO: activity log entry? -- requires message analysis osrfLogDebug(OSRF_LOG_MARK, "WS relaying message thread=%s, xid=%s, recipient=%s", thread, osrfLogGetXid(), recipient); - msg_body = jsonObjectToJSONRaw(osrf_msg); + // for each included message: + // 1. Stamp the ingress + // 2. REQUEST: log it as activity + // 3. DISCONNECT: remove the cached recipient + + osrfMessage* msg; + osrfMessage* msg_ist[MAX_MSGS_PER_PACKET]; + int num_msgs = osrfMessageDeserialize(osrf_msg_list, msg_list, MAX_MSGS_PER_PACKET); + + msg_body = jsonObjectToJSON(osrf_msg_list); transport_message *tmsg = message_init( msg_body, NULL, thread, recipient, NULL); message_set_osrf_xid(tmsg, osrfLogGetXid()); client_send_message(osrf_handle, tmsg); - osrfLogClearXid(); + + for (i = 0; i < osrf_msg_list->size; i++) { + osrf_msg = jsonObjectGetIndex(osrf_msg_list, i); + if (osrf_msg) { + } + } + + + osrfLogClearXid(); message_free(tmsg); jsonObjectFree(msg_wrapper); free(msg_body); -- 2.11.0