static int handler(request_rec *r) { int stat = OK; if(strcmp(r->handler, MODULE_NAME)) return DECLINED; if(r->header_only) return stat; r->allowed |= (AP_METHOD_BIT << M_GET); r->allowed |= (AP_METHOD_BIT << M_POST); osrfLogSetAppname("osrf_http_translator"); osrfAppSessionSetIngress(TRANSLATOR_INGRESS); testConnection(r); crossOriginHeaders(r, allowedOrigins); osrfLogMkXid(); osrfHttpTranslator* trans = osrfNewHttpTranslator(r); if(trans->body) { stat = osrfHttpTranslatorProcess(trans); //osrfHttpTranslatorDebug(trans); osrfLogInfo(OSRF_LOG_MARK, "translator resulted in status %d", stat); } else { osrfLogWarning(OSRF_LOG_MARK, "no message body to process"); } osrfHttpTranslatorFree(trans); return stat; }
/** @brief Unpack a transport_message into one or more osrfMessages, and process each one. @param msg Pointer to the transport_message to be unpacked and processed. @param my_service Application name (optional). @return Pointer to an osrfAppSession -- either a pre-existing one or a new one. Look for an existing osrfAppSession with which the message is associated. Such a session may already exist if, for example, you're a client waiting for a response from some other application, or if you're a server that has opened a stateful session with a client. If you can't find an existing session for the current message, and the @a my_service parameter has provided an application name, then you're presumably a server receiving something from a new client. Create an application server session to own the new message. Barring various errors and malformations, extract one or more osrfMessages from the transport_message. Pass each one to the appropriate routine for processing, depending on whether you're acting as a client or as a server. */ struct osrf_app_session_struct* osrf_stack_transport_handler( transport_message* msg, const char* my_service ) { if(!msg) return NULL; osrfLogSetXid(msg->osrf_xid); osrfLogDebug( OSRF_LOG_MARK, "Transport handler received new message \nfrom %s " "to %s with body \n\n%s\n", msg->sender, msg->recipient, msg->body ); if( msg->is_error && ! msg->thread ) { osrfLogWarning( OSRF_LOG_MARK, "!! Received jabber layer error for %s ... exiting\n", msg->sender ); message_free( msg ); return NULL; } if(! msg->thread && ! msg->is_error ) { osrfLogWarning( OSRF_LOG_MARK, "Received a non-error message with no thread trace... dropping"); message_free( msg ); return NULL; } osrfAppSession* session = osrf_app_session_find_session( msg->thread ); if( !session && my_service ) session = osrf_app_server_session_init( msg->thread, my_service, msg->sender); if( !session ) { message_free( msg ); return NULL; } if(!msg->is_error) osrfLogDebug( OSRF_LOG_MARK, "Session [%s] found or built", session->session_id ); osrf_app_session_set_remote( session, msg->sender ); osrfMessage* arr[OSRF_MAX_MSGS_PER_PACKET]; /* Convert the message body into one or more osrfMessages */ int num_msgs = osrf_message_deserialize(msg->body, arr, OSRF_MAX_MSGS_PER_PACKET); osrfLogDebug( OSRF_LOG_MARK, "We received %d messages from %s", num_msgs, msg->sender ); double starttime = get_timestamp_millis(); int i; for( i = 0; i < num_msgs; i++ ) { /* if we've received a jabber layer error message (probably talking to someone who no longer exists) and we're not talking to the original remote id for this server, consider it a redirect and pass it up */ if(msg->is_error) { osrfLogWarning( OSRF_LOG_MARK, " !!! Received Jabber layer error message" ); if( strcmp( session->remote_id, session->orig_remote_id ) ) { osrfLogWarning( OSRF_LOG_MARK, "Treating jabber error as redirect for tt [%d] " "and session [%s]", arr[i]->thread_trace, session->session_id ); arr[i]->m_type = STATUS; arr[i]->status_code = OSRF_STATUS_REDIRECTED; } else { osrfLogWarning( OSRF_LOG_MARK, " * Jabber Error is for top level remote " " id [%s], no one to send my message to! Cutting request short...", session->remote_id ); session->transport_error = 1; break; } } // grab the ingress value from the first message. // they will all be the same if (i == 0) osrfAppSessionSetIngress(arr[i]->sender_ingress); if( session->type == OSRF_SESSION_CLIENT ) _do_client( session, arr[i] ); else _do_server( session, arr[i] ); } double duration = get_timestamp_millis() - starttime; osrfLogInfo(OSRF_LOG_MARK, "Message processing duration %f", duration); message_free( msg ); osrfLogDebug( OSRF_LOG_MARK, "after msg delete"); return session; }