static void osrfHttpTranslatorFree(osrfHttpTranslator* trans) { if(!trans) return; if(trans->body) free(trans->body); if(trans->delim) free(trans->delim); osrfListFree(trans->messages); }
jsonObject* jsonXMLToJSONObject(const char* xml) { osrfXMLGatewayParser parser; /* don't define freeItem, since objects will be cleaned by freeing the parent */ parser.objStack = osrfNewList(); /* don't define freeItem, since the list eill end up empty if there are no errors*/ parser.keyStack = osrfNewList(); parser.obj = NULL; parser.inString = 0; parser.inNumber = 0; xmlParserCtxtPtr ctxt = xmlCreatePushParserCtxt(SAXHandler, &parser, "", 0, NULL); xmlParseChunk(ctxt, xml, strlen(xml), 1); osrfListFree(parser.objStack); osrfListFree(parser.keyStack); xmlFreeParserCtxt(ctxt); xmlCleanupCharEncodingHandlers(); xmlDictCleanup(); xmlCleanupParser(); return parser.obj; }
void* osrf_responder_thread_main_body(transport_message *tmsg) { osrfList *msg_list = NULL; osrfMessage *one_msg = NULL; int i; osrfLogDebug(OSRF_LOG_MARK, "WS received opensrf response for thread=%s", tmsg->thread); // first we need to perform some maintenance msg_list = osrfMessageDeserialize(tmsg->body, NULL); for (i = 0; i < msg_list->size; i++) { one_msg = OSRF_LIST_GET_INDEX(msg_list, i); osrfLogDebug(OSRF_LOG_MARK, "WS returned response of type %d", one_msg->m_type); /* if our client just successfully connected to an opensrf service, cache the sender so that future calls on this thread will use the correct recipient. */ if (one_msg && one_msg->m_type == STATUS) { if (one_msg->status_code == OSRF_STATUS_OK) { if (!apr_hash_get(trans->stateful_session_cache, tmsg->thread, APR_HASH_KEY_STRING)) { apr_size_t ses_size = apr_hash_count(trans->stateful_session_cache); if (ses_size < MAX_ACTIVE_STATEFUL_SESSIONS) { osrfLogDebug(OSRF_LOG_MARK, "WS caching sender " "thread=%s, sender=%s; concurrent=%d", tmsg->thread, tmsg->sender, ses_size); apr_hash_set(trans->stateful_session_cache, apr_pstrdup(trans->stateful_session_pool, tmsg->thread), APR_HASH_KEY_STRING, apr_pstrdup(trans->stateful_session_pool, tmsg->sender)); } else { osrfLogWarning(OSRF_LOG_MARK, "WS max concurrent sessions (%d) reached. " "Current session will not be tracked", MAX_ACTIVE_STATEFUL_SESSIONS ); } } } else { // connection timed out; clear the cached recipient if (one_msg->status_code == OSRF_STATUS_TIMEOUT) { clear_cached_recipient(tmsg->thread); } else { if (one_msg->status_code == OSRF_STATUS_COMPLETE) requests_in_flight--; } } } } // osrfMessageDeserialize applies the freeItem handler to the // newly created osrfList. We only need to free the list and // the individual osrfMessage's will be freed along with it osrfListFree(msg_list); // relay the response messages to the client jsonObject *msg_wrapper = NULL; char *msg_string = NULL; // build the wrapper object msg_wrapper = jsonNewObject(NULL); jsonObjectSetKey(msg_wrapper, "thread", jsonNewObject(tmsg->thread)); jsonObjectSetKey(msg_wrapper, "log_xid", jsonNewObject(tmsg->osrf_xid)); jsonObjectSetKey(msg_wrapper, "osrf_msg", jsonParseRaw(tmsg->body)); if (tmsg->is_error) { osrfLogError(OSRF_LOG_MARK, "WS received jabber error message in response to thread=%s", tmsg->thread); jsonObjectSetKey(msg_wrapper, "transport_error", jsonNewBoolObject(1)); } msg_string = jsonObjectToJSONRaw(msg_wrapper); // drop the JSON on the outbound wire trans->server->send(trans->server, MESSAGE_TYPE_TEXT, (unsigned char*) msg_string, strlen(msg_string)); free(msg_string); jsonObjectFree(msg_wrapper); }