char* osrf_app_session_set_locale( osrfAppSession*, const char* );
+/* ingress used by all sessions until replaced */
+char* osrfAppSessionSetIngress( const char* );
+
+const char* osrfAppSessionGetIngress();
+
osrfAppSession* osrf_app_session_find_session( const char* session_id );
/* DEPRECATED; use osrfAppSessionSendRequest() instead. */
/** Magical LOCALE hint. */
char* sender_locale;
+
+ /** Magical ingress hint. */
+ char* sender_ingress;
};
typedef struct osrf_message_struct osrfMessage;
const char* osrf_message_set_locale( osrfMessage* msg, const char* locale );
+const char* osrfMessageSetIngress( osrfMessage* msg, const char* ingress );
+
const char* osrf_message_set_default_locale( const char* locale );
const char* osrf_message_get_last_locale(void);
#include "opensrf/osrf_app_session.h"
#include "opensrf/osrf_stack.h"
+static char* current_ingress = NULL;
+
struct osrf_app_request_struct {
/** The controlling session. */
struct osrf_app_session_struct* session;
}
/**
+ @brief Install a copy of a ingress string as the new default.
+ @param session Pointer to the new strdup'ed default_ingress
+ @param ingress The ingress string to be copied and installed.
+*/
+char* osrfAppSessionSetIngress(const char* ingress) {
+ if (!ingress) return NULL;
+ if(current_ingress)
+ free(current_ingress);
+ return current_ingress = strdup(ingress);
+}
+
+/**
+ @brief Returns the current ingress value
+ @return A pointer to the installed copy of the ingress string
+*/
+const char* osrfAppSessionGetIngress() {
+ return current_ingress;
+}
+
+/**
@brief Find the osrfAppSession for a given session id.
@param session_id The session id to look for.
@return Pointer to the corresponding osrfAppSession if found, or NULL if not.
osrf_message_set_locale(req_msg, session->session_locale);
}
+ if (!current_ingress)
+ osrfAppSessionSetIngress("opensrf");
+ osrfMessageSetIngress(req_msg, current_ingress);
+
if(params) {
osrf_message_set_params(req_msg, params);
msg->_result_content = NULL;
msg->method_name = NULL;
msg->sender_locale = NULL;
+ msg->sender_ingress = NULL;
return msg;
}
}
/**
+ @brief Set the ingress for a specified osrfMessage.
+ @param msg Pointer to the osrfMessage.
+ @param ingress Pointer to the ingress string to be installed in the osrfMessage.
+ @return Pointer to the new ingress string for the osrfMessage, or NULL if either
+ parameter is NULL.
+
+ If no ingress is specified for an osrfMessage, we use the default ingress.
+
+ Used for a REQUEST message.
+*/
+const char* osrfMessageSetIngress( osrfMessage* msg, const char* ingress ) {
+ if( msg == NULL || ingress == NULL )
+ return NULL;
+ if( msg->sender_ingress )
+ free( msg->sender_ingress );
+ return msg->sender_ingress = strdup( ingress );
+}
+
+/**
@brief Change the default locale.
@param locale The new default locale.
@return A pointer to the new default locale if successful, or NULL if not.
if( msg->sender_locale != NULL )
free(msg->sender_locale);
+ if( msg->sender_ingress != NULL )
+ free(msg->sender_ingress);
+
if( msg->_params != NULL )
jsonObjectFree(msg->_params);
The resulting jsonObject is a JSON_HASH with a classname of "osrfMessage", and the following keys:
- "threadTrace"
- "locale"
+ - "ingress"
- "type"
- "payload" (only for STATUS, REQUEST, and RESULT messages)
jsonObjectSetKey(json, "locale", jsonNewObject(default_locale));
}
+ if (msg->sender_ingress != NULL)
+ jsonObjectSetKey(json, "ingress", jsonNewObject(msg->sender_ingress));
+
switch(msg->m_type) {
case CONNECT:
}
}
+ tmp = jsonObjectGetKeyConst(obj, "ingress");
+ if (tmp) {
+ osrfMessageSetIngress(msg, jsonObjectGetString(tmp));
+ }
+
tmp = jsonObjectGetKeyConst( obj, "payload" );
if(tmp) {
// Get method name and parameters for a REQUEST
}
}
+ // 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