/** the current locale for this session. **/
char* session_locale;
+ /** the current TZ for this session. **/
+ char* session_tz;
+
/** let the user use the session to store their own session data. */
void* userData;
char* osrf_app_session_set_locale( osrfAppSession*, const char* );
+char* osrf_app_session_set_tz( osrfAppSession*, const char* );
+
/* ingress used by all sessions until replaced */
char* osrfAppSessionSetIngress( const char* );
/** Magical ingress hint. */
char* sender_ingress;
+
+ /** Magical TZ hint. */
+ char* sender_tz;
};
typedef struct osrf_message_struct osrfMessage;
const char* osrf_message_set_locale( osrfMessage* msg, const char* locale );
+const char* osrf_message_set_tz( osrfMessage* msg, const char* tz );
+
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);
+const char* osrf_message_get_last_tz(void);
+
osrfMessage* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
void osrf_message_set_status_info( osrfMessage*,
}
/**
+ @brief Install a copy of a TZ string in a specified session.
+ @param session Pointer to the osrfAppSession in which the TZ is to be installed.
+ @param TZ The TZ string to be copied and installed.
+ @return A pointer to the installed copy of the TZ string.
+*/
+char* osrf_app_session_set_tz( osrfAppSession* session, const char* tz ) {
+ if (!session || !tz)
+ return NULL;
+
+ if(session->session_tz) {
+ if( strlen(session->session_tz) >= strlen(tz) ) {
+ /* There's room available; just copy */
+ strcpy(session->session_tz, tz);
+ } else {
+ free(session->session_tz);
+ session->session_tz = strdup( tz );
+ }
+ } else {
+ session->session_tz = strdup( tz );
+ }
+
+ return session->session_tz;
+}
+
+/**
@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.
session->orig_remote_id = strdup(session->remote_id);
session->remote_service = strdup(remote_service);
session->session_locale = NULL;
+ session->session_tz = NULL;
session->transport_error = 0;
session->panic = 0;
session->outbuf = NULL; // Not used by client
session->state = OSRF_SESSION_DISCONNECTED;
session->type = OSRF_SESSION_SERVER;
session->session_locale = NULL;
+ session->session_tz = NULL;
session->userData = NULL;
session->userDataFree = NULL;
osrf_message_set_locale(req_msg, session->session_locale);
}
+ osrf_message_set_tz(req_msg, session->session_tz);
+
if (!current_ingress)
osrfAppSessionSetIngress("opensrf");
osrfMessageSetIngress(req_msg, current_ingress);
if(session->session_locale)
free(session->session_locale);
+ if(session->session_tz)
+ free(session->session_tz);
+
free(session->remote_id);
free(session->orig_remote_id);
free(session->session_id);
msg->_result_content = NULL;
msg->method_name = NULL;
msg->sender_locale = NULL;
+ msg->sender_tz = NULL;
msg->sender_ingress = NULL;
return msg;
}
/**
+ @brief Set the TZ for a specified osrfMessage.
+ @param msg Pointer to the osrfMessage.
+ @param TZ Pointer to the TZ string to be installed in the osrfMessage.
+ @return Pointer to the new TZ string for the osrfMessage, or NULL if either
+ parameter is NULL.
+
+ If no TZ is specified for an osrfMessage, we use the system TZ.
+
+ Used for a REQUEST message.
+*/
+const char* osrf_message_set_tz( osrfMessage* msg, const char* tz ) {
+ if( msg == NULL || tz == NULL )
+ return NULL;
+ if( msg->sender_tz )
+ free( msg->sender_tz );
+ return msg->sender_tz = strdup( tz );
+}
+
+/**
@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.
if( msg->sender_locale != NULL )
free(msg->sender_locale);
+ if( msg->sender_tz != NULL )
+ free(msg->sender_tz);
+
if( msg->sender_ingress != NULL )
free(msg->sender_ingress);
The resulting jsonObject is a JSON_HASH with a classname of "osrfMessage", and the following keys:
- "threadTrace"
- "locale"
+ - "tz"
- "ingress"
- "type"
- "payload" (only for STATUS, REQUEST, and RESULT messages)
jsonObjectSetKey(json, "locale", jsonNewObject(default_locale));
}
+ if (msg->sender_tz != NULL) {
+ jsonObjectSetKey(json, "tz", jsonNewObject(msg->sender_tz));
+ }
+
if (msg->sender_ingress != NULL)
jsonObjectSetKey(json, "ingress", jsonNewObject(msg->sender_ingress));
osrfMessageSetIngress(msg, jsonObjectGetString(tmp));
}
+ tmp = jsonObjectGetKeyConst(obj, "tz");
+ if (tmp) {
+ osrf_message_set_tz(msg, jsonObjectGetString(tmp));
+ }
+
tmp = jsonObjectGetKeyConst( obj, "payload" );
if(tmp) {
// Get method name and parameters for a REQUEST
osrfLogDebug( OSRF_LOG_MARK, "Server received message of type %d", msg->m_type );
+ osrf_app_session_set_tz(session, msg->sender_tz);
+ osrf_app_session_set_locale(session, msg->sender_locale);
+
+ osrfLogDebug( OSRF_LOG_MARK, "Message has locale %s and tz %s", session->session_locale, session->session_tz );
+
switch( msg->m_type ) {
case STATUS: