transport_client* transport_handle;
/** Cache of active app_request objects */
- //osrf_app_request* request_queue;
+ //osrfAppRequest* request_queue;
osrfList* request_queue;
// --------------------------------------------------------------------------
/** Allocates a initializes a new app_session */
-osrf_app_session* osrfAppSessionClientInit( const char* remote_service );
-osrf_app_session* osrf_app_client_session_init( const char* remote_service );
+osrfAppSession* osrfAppSessionClientInit( const char* remote_service );
+osrfAppSession* osrf_app_client_session_init( const char* remote_service );
/** Allocates and initializes a new server session. The global session cache
* is checked to see if this session already exists, if so, it's returned
*/
-osrf_app_session* osrf_app_server_session_init(
+osrfAppSession* osrf_app_server_session_init(
const char* session_id, const char* our_app, const char* remote_id );
/** sets the default locale for a session **/
-char* osrf_app_session_set_locale( osrf_app_session*, const char* );
+char* osrf_app_session_set_locale( osrfAppSession*, const char* );
/** returns a session from the global session hash */
-osrf_app_session* osrf_app_session_find_session( const char* session_id );
+osrfAppSession* osrf_app_session_find_session( const char* session_id );
/** Builds a new app_request object with the given payload andn returns
* the id of the request. This id is then used to perform work on the
* requeset.
*/
int osrfAppSessionMakeRequest(
- osrf_app_session* session, const jsonObject* params,
+ osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings);
int osrf_app_session_make_req(
- osrf_app_session* session, const jsonObject* params,
+ osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings);
-int osrfAppSessionMakeLocaleRequest(
- osrf_app_session* session, const jsonObject* params, const char* method_name,
- int protocol, string_array* param_strings, char* locale);
-
-int osrf_app_session_make_locale_req(
- osrf_app_session* session, const jsonObject* params, const char* method_name,
- int protocol, string_array* param_strings, char* locale);
-
/** Sets the given request to complete state */
-void osrf_app_session_set_complete( osrf_app_session* session, int request_id );
+void osrf_app_session_set_complete( osrfAppSession* session, int request_id );
/** Returns true if the given request is complete */
-int osrf_app_session_request_complete( const osrf_app_session* session, int request_id );
+int osrf_app_session_request_complete( const osrfAppSession* session, int request_id );
/** Does a recv call on the given request */
osrf_message* osrfAppSessionRequestRecv(
- osrf_app_session* session, int request_id, int timeout );
+ osrfAppSession* session, int request_id, int timeout );
osrf_message* osrf_app_session_request_recv(
- osrf_app_session* session, int request_id, int timeout );
+ osrfAppSession* session, int request_id, int timeout );
/** Removes the request from the request set and frees the reqest */
-void osrf_app_session_request_finish( osrf_app_session* session, int request_id );
+void osrf_app_session_request_finish( osrfAppSession* session, int request_id );
/** Resends the orginal request with the given request id */
-int osrf_app_session_request_resend( osrf_app_session*, int request_id );
+int osrf_app_session_request_resend( osrfAppSession*, int request_id );
/** Resets the remote connection target to that of the original*/
-void osrf_app_session_reset_remote( osrf_app_session* );
+void osrf_app_session_reset_remote( osrfAppSession* );
/** Sets the remote target to 'remote_id' */
-void osrf_app_session_set_remote( osrf_app_session* session, const char* remote_id );
+void osrf_app_session_set_remote( osrfAppSession* session, const char* remote_id );
/** pushes the given message into the result list of the app_request
* whose request_id matches the messages thread_trace
*/
-int osrf_app_session_push_queue( osrf_app_session*, osrf_message* msg );
+int osrf_app_session_push_queue( osrfAppSession*, osrf_message* msg );
/** Attempts to connect to the remote service. Returns 1 on successful
* connection, 0 otherwise.
*/
-int osrf_app_session_connect( osrf_app_session* );
-int osrfAppSessionConnect( osrf_app_session* );
+int osrf_app_session_connect( osrfAppSession* );
+int osrfAppSessionConnect( osrfAppSession* );
/** Sends a disconnect message to the remote service. No response is expected */
-int osrf_app_session_disconnect( osrf_app_session* );
+int osrf_app_session_disconnect( osrfAppSession* );
/** Waits up to 'timeout' seconds for some data to arrive.
* Any data that arrives will be processed according to its
* payload and message type. This method will return after
* any data has arrived.
*/
-int osrf_app_session_queue_wait( osrf_app_session*, int timeout, int* recvd );
+int osrf_app_session_queue_wait( osrfAppSession*, int timeout, int* recvd );
/** Disconnects (if client), frees any attached app_reuqests, removes the session from the
* global session cache and frees the session. Needless to say, only call this when the
* session is completey done.
*/
-void osrf_app_session_destroy ( osrf_app_session* );
+void osrf_app_session_destroy ( osrfAppSession* );
void osrfAppSessionFree( osrfAppSession* );
-
-
-// --------------------------------------------------------------------------
-// --------------------------------------------------------------------------
-// Request functions
-// --------------------------------------------------------------------------
-
-/** Allocations and initializes a new app_request object */
-osrf_app_request* _osrf_app_request_init( osrf_app_session* session, osrf_message* msg );
-
-/** Frees memory used by an app_request object */
-void _osrf_app_request_free( void * req );
-
-/** Pushes the given message onto the list of 'responses' to this request */
-void _osrf_app_request_push_queue( osrf_app_request*, osrf_message* payload );
-
-/** Checks the receive queue for messages. If any are found, the first
- * is popped off and returned. Otherwise, this method will wait at most timeout
- * seconds for a message to appear in the receive queue. Once it arrives it is returned.
- * If no messages arrive in the timeout provided, null is returned.
- */
-osrf_message* _osrf_app_request_recv( osrf_app_request* req, int timeout );
-
-/** Resend this requests original request message */
-int _osrf_app_request_resend( osrf_app_request* req );
-
-
/* tells the request to reset it's wait timeout */
-void osrf_app_session_request_reset_timeout( osrf_app_session* session, int req_id );
-
-// --------------------------------------------------------------------------
-// --------------------------------------------------------------------------
-// Session functions
-// --------------------------------------------------------------------------
-
-/** Returns the app_request with the given thread_trace (request_id) */
-osrf_app_request* _osrf_app_session_get_request( osrf_app_session*, int thread_trace );
-
-/** frees memory held by a session. Note: We delete all requests in the request list */
-void _osrf_app_session_free( osrf_app_session* );
-
-/** adds a session to the global session cache */
-void _osrf_app_session_push_session( osrf_app_session* );
-
-/** Adds an app_request to the request set */
-void _osrf_app_session_push_request( osrf_app_session*, osrf_app_request* req );
-
-/** Removes an app_request from this session request set, freeing the request object */
-void _osrf_app_session_remove_request( osrf_app_session*, osrf_app_request* req );
-
-/** Send the given message */
-int _osrf_app_session_send( osrf_app_session*, osrf_message* msg );
-
-int osrfAppSessionSendBatch( osrf_app_session*, osrf_message* msgs[], int size );
+void osrf_app_session_request_reset_timeout( osrfAppSession* session, int req_id );
-int osrfAppRequestRespond( osrfAppSession* ses, int requestId, const jsonObject* data );
+int osrfAppRequestRespond( osrfAppSession* ses, int requestId, const jsonObject* data );
int osrfAppRequestRespondComplete(
osrfAppSession* ses, int requestId, const jsonObject* data );
-int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message );
+int osrfAppSessionStatus( osrfAppSession* ses, int type,
+ const char* name, int reqId, const char* message );
void osrfAppSessionCleanup();
#include <opensrf/osrf_app_session.h>
#include <time.h>
+/** Send the given message */
+static int _osrf_app_session_send( osrfAppSession*, osrf_message* msg );
+
+static int osrfAppSessionMakeLocaleRequest(
+ osrfAppSession* session, const jsonObject* params, const char* method_name,
+ int protocol, string_array* param_strings, char* locale );
+
/* the global app_session cache */
osrfHash* osrfAppSessionCache = NULL;
// Request API
// --------------------------------------------------------------------------
-/** Allocation and initializes a new app_request object */
-osrf_app_request* _osrf_app_request_init(
- osrf_app_session* session, osrf_message* msg ) {
+/** Allocates and initializes a new app_request object */
+static osrfAppRequest* _osrf_app_request_init(
+ osrfAppSession* session, osrf_message* msg ) {
- osrf_app_request* req =
- (osrf_app_request*) safe_malloc(sizeof(osrf_app_request));
+ osrfAppRequest* req =
+ (osrfAppRequest*) safe_malloc(sizeof(osrfAppRequest));
req->session = session;
req->request_id = msg->thread_trace;
osrfHashFree(osrfAppSessionCache);
}
-
-
/** Frees memory used by an app_request object */
-void _osrf_app_request_free( void * req ){
+static void _osrf_app_request_free( void * req ){
if( req == NULL ) return;
osrfAppRequest* r = (osrfAppRequest*) req;
if( r->payload ) osrf_message_free( r->payload );
}
/** Pushes the given message onto the list of 'responses' to this request */
-void _osrf_app_request_push_queue( osrf_app_request* req, osrf_message* result ){
+static void _osrf_app_request_push_queue( osrfAppRequest* req, osrf_message* result ){
if(req == NULL || result == NULL) return;
osrfLogDebug( OSRF_LOG_MARK, "App Session pushing request [%d] onto request queue", result->thread_trace );
if(req->result == NULL) {
/** Removes this app_request from our session request set */
void osrf_app_session_request_finish(
- osrf_app_session* session, int req_id ){
+ osrfAppSession* session, int req_id ){
if(session == NULL) return;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
if(req == NULL) return;
osrfListRemove( req->session->request_queue, req->request_id );
}
-void osrf_app_session_request_reset_timeout( osrf_app_session* session, int req_id ) {
+void osrf_app_session_request_reset_timeout( osrfAppSession* session, int req_id ) {
if(session == NULL) return;
osrfLogDebug( OSRF_LOG_MARK, "Resetting request timeout %d", req_id );
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
if(req == NULL) return;
req->reset_timeout = 1;
}
* seconds for a message to appear in the receive queue. Once it arrives it is returned.
* If no messages arrive in the timeout provided, null is returned.
*/
-osrf_message* _osrf_app_request_recv( osrf_app_request* req, int timeout ) {
+static osrf_message* _osrf_app_request_recv( osrfAppRequest* req, int timeout ) {
if(req == NULL) return NULL;
}
/** Resend this requests original request message */
-int _osrf_app_request_resend( osrf_app_request* req ) {
+static int _osrf_app_request_resend( osrfAppRequest* req ) {
if(req == NULL) return 0;
if(!req->complete) {
osrfLogDebug( OSRF_LOG_MARK, "Resending request [%d]", req->request_id );
// --------------------------------------------------------------------------
/** returns a session from the global session hash */
-char* osrf_app_session_set_locale( osrf_app_session* session, const char* locale ) {
+char* osrf_app_session_set_locale( osrfAppSession* session, const char* locale ) {
if (!session || !locale)
return NULL;
}
/** returns a session from the global session hash */
-osrf_app_session* osrf_app_session_find_session( const char* session_id ) {
+osrfAppSession* osrf_app_session_find_session( const char* session_id ) {
if(session_id) return osrfHashGet(osrfAppSessionCache, session_id);
return NULL;
}
/** adds a session to the global session cache */
-void _osrf_app_session_push_session( osrf_app_session* session ) {
+static void _osrf_app_session_push_session( osrfAppSession* session ) {
if(!session) return;
if( osrfAppSessionCache == NULL ) osrfAppSessionCache = osrfNewHash();
if( osrfHashGet( osrfAppSessionCache, session->session_id ) ) return;
/** Allocates and initializes a new app_session */
-osrf_app_session* osrfAppSessionClientInit( const char* remote_service ) {
+osrfAppSession* osrfAppSessionClientInit( const char* remote_service ) {
return osrf_app_client_session_init( remote_service );
}
-osrf_app_session* osrf_app_client_session_init( const char* remote_service ) {
+osrfAppSession* osrf_app_client_session_init( const char* remote_service ) {
if (!remote_service) {
osrfLogWarning( OSRF_LOG_MARK, "No remote service specified in osrf_app_client_session_init");
return NULL;
}
- osrf_app_session* session = safe_malloc(sizeof(osrf_app_session));
+ osrfAppSession* session = safe_malloc(sizeof(osrfAppSession));
session->transport_handle = osrf_system_get_transport_client();
if( session->transport_handle == NULL ) {
return session;
}
-osrf_app_session* osrf_app_server_session_init(
+osrfAppSession* osrf_app_server_session_init(
const char* session_id, const char* our_app, const char* remote_id ) {
osrfLogDebug( OSRF_LOG_MARK, "Initing server session with session id %s, service %s,"
" and remote_id %s", session_id, our_app, remote_id );
- osrf_app_session* session = osrf_app_session_find_session( session_id );
+ osrfAppSession* session = osrf_app_session_find_session( session_id );
if(session) return session;
- session = safe_malloc(sizeof(osrf_app_session));
+ session = safe_malloc(sizeof(osrfAppSession));
session->transport_handle = osrf_system_get_transport_client();
if( session->transport_handle == NULL ) {
#ifdef ASSUME_STATELESS
session->stateless = 1;
+ #else
+ session->stateless = 0;
#endif
session->thread_trace = 0;
session->state = OSRF_SESSION_DISCONNECTED;
session->type = OSRF_SESSION_SERVER;
+ session->session_locale = NULL;
session->userData = NULL;
session->userDataFree = NULL;
/** frees memory held by a session */
-void _osrf_app_session_free( osrf_app_session* session ){
+static void _osrf_app_session_free( osrfAppSession* session ){
if(session==NULL)
return;
}
int osrfAppSessionMakeRequest(
- osrf_app_session* session, const jsonObject* params,
+ osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings ) {
- return osrf_app_session_make_locale_req( session, params,
+ return osrfAppSessionMakeLocaleRequest( session, params,
method_name, protocol, param_strings, NULL );
}
-int osrfAppSessionMakeLocaleRequest(
- osrf_app_session* session, const jsonObject* params, const char* method_name,
- int protocol, string_array* param_strings, char* locale ) {
-
- return osrf_app_session_make_locale_req( session, params,
- method_name, protocol, param_strings, locale );
-}
-
-int osrf_app_session_make_req(
- osrf_app_session* session, const jsonObject* params,
+int osrf_app_session_make_req(
+ osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings) {
- return osrf_app_session_make_locale_req(session, params,
+ return osrfAppSessionMakeLocaleRequest(session, params,
method_name, protocol, param_strings, NULL);
}
-int osrf_app_session_make_locale_req(
- osrf_app_session* session, const jsonObject* params, const char* method_name,
+static int osrfAppSessionMakeLocaleRequest(
+ osrfAppSession* session, const jsonObject* params, const char* method_name,
int protocol, string_array* param_strings, char* locale ) {
+
if(session == NULL) return -1;
osrfLogMkXid();
}
}
- osrf_app_request* req = _osrf_app_request_init( session, req_msg );
+ osrfAppRequest* req = _osrf_app_request_init( session, req_msg );
if(_osrf_app_session_send( session, req_msg ) ) {
osrfLogWarning( OSRF_LOG_MARK, "Error sending request message [%d]", session->thread_trace );
return -1;
return req->request_id;
}
-void osrf_app_session_set_complete( osrf_app_session* session, int request_id ) {
+void osrf_app_session_set_complete( osrfAppSession* session, int request_id ) {
if(session == NULL)
return;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
if(req) req->complete = 1;
}
-int osrf_app_session_request_complete( const osrf_app_session* session, int request_id ) {
+int osrf_app_session_request_complete( const osrfAppSession* session, int request_id ) {
if(session == NULL)
return 0;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
if(req)
return req->complete;
return 0;
/** Resets the remote connection id to that of the original*/
-void osrf_app_session_reset_remote( osrf_app_session* session ){
+void osrf_app_session_reset_remote( osrfAppSession* session ){
if( session==NULL )
return;
session->remote_id = strdup(session->orig_remote_id);
}
-void osrf_app_session_set_remote( osrf_app_session* session, const char* remote_id ) {
+void osrf_app_session_set_remote( osrfAppSession* session, const char* remote_id ) {
if(session == NULL)
return;
if( session->remote_id )
/** pushes the given message into the result list of the app_request
with the given request_id */
int osrf_app_session_push_queue(
- osrf_app_session* session, osrf_message* msg ){
+ osrfAppSession* session, osrf_message* msg ){
if(session == NULL || msg == NULL) return 0;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, msg->thread_trace );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, msg->thread_trace );
if(req == NULL) return 0;
_osrf_app_request_push_queue( req, msg );
return 0;
}
-int osrfAppSessionConnect( osrf_app_session* session ) {
+int osrfAppSessionConnect( osrfAppSession* session ) {
return osrf_app_session_connect(session);
}
/** Attempts to connect to the remote service */
-int osrf_app_session_connect(osrf_app_session* session){
+int osrf_app_session_connect(osrfAppSession* session){
if(session == NULL)
return 0;
/** Disconnects from the remote service */
-int osrf_app_session_disconnect( osrf_app_session* session){
+int osrf_app_session_disconnect( osrfAppSession* session){
if(session == NULL)
return 1;
return 1;
}
-int osrf_app_session_request_resend( osrf_app_session* session, int req_id ) {
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
+int osrf_app_session_request_resend( osrfAppSession* session, int req_id ) {
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
return _osrf_app_request_resend( req );
}
-int osrfAppSessionSendBatch( osrfAppSession* session, osrf_message* msgs[], int size ) {
+static int osrfAppSessionSendBatch( osrfAppSession* session, osrf_message* msgs[], int size ) {
if( !(session && msgs && size > 0) ) return 0;
int retval = 0;
-int _osrf_app_session_send( osrf_app_session* session, osrf_message* msg ){
+static int _osrf_app_session_send( osrfAppSession* session, osrf_message* msg ){
if( !(session && msg) ) return 0;
osrfMessage* a[1];
a[0] = msg;
* payload and message type. This method will return after
* any data has arrived.
*/
-int osrf_app_session_queue_wait( osrf_app_session* session, int timeout, int* recvd ){
+int osrf_app_session_queue_wait( osrfAppSession* session, int timeout, int* recvd ){
if(session == NULL) return 0;
osrfLogDebug(OSRF_LOG_MARK, "AppSession in queue_wait with timeout %d", timeout );
return osrf_stack_entry_point(session->transport_handle, timeout, recvd);
}
-void osrf_app_session_destroy( osrf_app_session* session ){
+void osrf_app_session_destroy( osrfAppSession* session ){
if(session == NULL) return;
osrfLogDebug(OSRF_LOG_MARK, "AppSession [%s] [%s] destroying self and deleting requests",
}
osrf_message* osrfAppSessionRequestRecv(
- osrf_app_session* session, int req_id, int timeout ) {
+ osrfAppSession* session, int req_id, int timeout ) {
return osrf_app_session_request_recv( session, req_id, timeout );
}
osrf_message* osrf_app_session_request_recv(
- osrf_app_session* session, int req_id, int timeout ) {
+ osrfAppSession* session, int req_id, int timeout ) {
if(req_id < 0 || session == NULL)
return NULL;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
return _osrf_app_request_recv( req, timeout );
}
return 0;
}
-int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message ) {
+int osrfAppSessionStatus( osrfAppSession* ses, int type,
+ const char* name, int reqId, const char* message ) {
if(ses) {
osrf_message* msg = osrf_message_init( STATUS, reqId, 1);