]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/libstack/osrf_app_session.c
changed router binary to opensrf_router to prevent opensrf_all from destroying
[Evergreen.git] / OpenSRF / src / libstack / osrf_app_session.c
1 #include "osrf_app_session.h"
2 #include <time.h>
3
4 /* the global app_session cache */
5 osrf_app_session* app_session_cache;
6
7
8
9 // --------------------------------------------------------------------------
10 // --------------------------------------------------------------------------
11 // Request API
12 // --------------------------------------------------------------------------
13
14 /** Allocation and initializes a new app_request object */
15 osrf_app_request* _osrf_app_request_init( 
16                 osrf_app_session* session, osrf_message* msg ) {
17
18         osrf_app_request* req = 
19                 (osrf_app_request*) safe_malloc(sizeof(osrf_app_request));
20
21         req->session            = session;
22         req->request_id = msg->thread_trace;
23         req->complete           = 0;
24         req->payload            = msg;
25         req->result                     = NULL;
26
27         return req;
28
29 }
30
31 /** Frees memory used by an app_request object */
32 void _osrf_app_request_free( osrf_app_request * req ){
33         if( req == NULL ) return;
34
35         if( req->payload ) {
36                 osrf_message_free( req->payload );
37         }
38
39         /*
40         osrf_message* cur_msg = req->result;
41         while( cur_msg != NULL ) {
42                 osrf_message* next_msg = cur_msg->next;
43                 osrf_message_free( cur_msg );
44                 cur_msg = next_msg;
45         }
46         osrf_message_free( req->payload );
47         */
48
49         free( req );
50         debug_handler("after request free");
51 }
52
53 /** Pushes the given message onto the list of 'responses' to this request */
54 void _osrf_app_request_push_queue( osrf_app_request* req, osrf_message* result ){
55         if(req == NULL || result == NULL) return;
56         debug_handler( "App Session pushing [%d] onto request queue", result->thread_trace );
57         if(req->result == NULL)
58                 req->result = result;
59         else {
60                 result->next = req->result;
61                 req->result = result;
62         }
63 }
64
65 /** Removes this app_request from our session request set */
66 void osrf_app_session_request_finish( 
67                 osrf_app_session* session, int req_id ){
68
69         if(session == NULL) return;
70         debug_handler("Finishing request %d", req_id );
71         osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
72         if(req == NULL) return;
73         _osrf_app_session_remove_request( req->session, req );
74         _osrf_app_request_free( req );
75 }
76
77
78 void osrf_app_session_request_reset_timeout( osrf_app_session* session, int req_id ) {
79         if(session == NULL) return;
80         debug_handler("Resetting timeout %d", req_id );
81         osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
82         if(req == NULL) return;
83         req->reset_timeout = 1;
84 }
85
86 /** Checks the receive queue for messages.  If any are found, the first
87   * is popped off and returned.  Otherwise, this method will wait at most timeout 
88   * seconds for a message to appear in the receive queue.  Once it arrives it is returned.
89   * If no messages arrive in the timeout provided, null is returned.
90   */
91 osrf_message* _osrf_app_request_recv( osrf_app_request* req, int timeout ) {
92
93         if(req == NULL) return NULL;
94
95         if( req->result != NULL ) {
96                 debug_handler("app_request receive already has a message, returning it");
97                 /* pop off the first message in the list */
98                 osrf_message* tmp_msg = req->result;
99                 req->result = req->result->next;
100                 return tmp_msg;
101         }
102
103         time_t start = time(NULL);      
104         time_t remaining = (time_t) timeout;
105
106         while( remaining >= 0 ) {
107                 /* tell the session to wait for stuff */
108                 debug_handler( "In app_request receive with remaining time [%d]", (int) remaining );
109
110                 osrf_app_session_queue_wait( req->session, 0 );
111
112                 if( req->result != NULL ) { /* if we received anything */
113                         /* pop off the first message in the list */
114                         debug_handler( "app_request_recv received a message, returning it");
115                         osrf_message* ret_msg = req->result;
116                         osrf_message* tmp_msg = ret_msg->next;
117                         req->result = tmp_msg;
118                         return ret_msg;
119                 }
120
121                 if( req->complete )
122                         return NULL;
123
124                 osrf_app_session_queue_wait( req->session, (int) remaining );
125
126                 if( req->result != NULL ) { /* if we received anything */
127                         /* pop off the first message in the list */
128                         debug_handler( "app_request_recv received a message, returning it");
129                         osrf_message* ret_msg = req->result;
130                         osrf_message* tmp_msg = ret_msg->next;
131                         req->result = tmp_msg;
132                         return ret_msg;
133                 }
134                 if( req->complete )
135                         return NULL;
136
137                 if(req->reset_timeout) {
138                         remaining = (time_t) timeout;
139                         req->reset_timeout = 0;
140                         debug_handler("Recevied a timeout reset");
141                 } else {
142                         remaining -= (int) (time(NULL) - start);
143                 }
144         }
145
146         debug_handler("Returning NULL from app_request_recv after timeout");
147         return NULL;
148 }
149
150 /** Resend this requests original request message */
151 int _osrf_app_request_resend( osrf_app_request* req ) {
152         if(req == NULL) return 0;
153         if(!req->complete) {
154                 debug_handler( "Resending request [%d]", req->request_id );
155                 return _osrf_app_session_send( req->session, req->payload );
156         }
157         return 1;
158 }
159
160
161
162 // --------------------------------------------------------------------------
163 // --------------------------------------------------------------------------
164 // Session API
165 // --------------------------------------------------------------------------
166
167 /** returns a session from the global session hash */
168 osrf_app_session* osrf_app_session_find_session( char* session_id ) {
169         osrf_app_session* ptr = app_session_cache;
170         debug_handler("Searching for session in global cache with id [%s]", session_id );
171         while( ptr != NULL ) {
172                 if( !strcmp(ptr->session_id,session_id) )
173                         return ptr;
174                 ptr = ptr->next;
175         }
176         return NULL;
177 }
178
179
180 /** adds a session to the global session cache */
181 void _osrf_app_session_push_session( osrf_app_session* session ) {
182
183         if( app_session_cache == NULL ) {
184                 app_session_cache = session;
185                 return;
186         }
187
188         osrf_app_session* ptr = app_session_cache;
189         debug_handler( "Pushing [%s] [%s] onto global session cache", 
190                         session->remote_service, session->session_id );
191         while( ptr != NULL ) {
192                 if( !strcmp(ptr->session_id, session->session_id) )
193                         return;
194                 if( ptr->next == NULL ) {
195                         ptr->next = session;
196                         return;
197                 }
198                 ptr = ptr->next;
199         }
200 }
201
202
203 /** unlinks from global session cache */
204 void _osrf_app_session_remove_session( char* session_id ) {
205
206         if( app_session_cache == NULL )
207                 return;
208
209         debug_handler( "App Session removing session [%s] from global cache", session_id );
210         if( !strcmp(app_session_cache->session_id, session_id) ) {
211                 if( app_session_cache->next != NULL ) {
212                         osrf_app_session* next = app_session_cache->next;
213                         app_session_cache = next;
214                         return;
215                 } else {
216                         app_session_cache = NULL;
217                         return;
218                 }
219         }
220
221         if( app_session_cache->next == NULL )
222                 return;
223
224         osrf_app_session* prev = app_session_cache;
225         osrf_app_session* ptr = prev->next;
226         while( ptr != NULL ) {
227                 if( ptr->session_id == session_id ) {
228                         osrf_app_session* tmp = ptr->next;
229                         prev->next = tmp;
230                         return;
231                 }
232                 ptr = ptr->next;
233         }
234 }
235
236 /** Allocates a initializes a new app_session */
237
238 osrf_app_session* osrfAppSessionClientInit( char* remote_service ) {
239         return osrf_app_client_session_init( remote_service );
240 }
241
242 osrf_app_session* osrf_app_client_session_init( char* remote_service ) {
243
244         osrf_app_session* session = safe_malloc(sizeof(osrf_app_session));      
245
246         session->transport_handle = osrf_system_get_transport_client();
247         if( session->transport_handle == NULL ) {
248                 warning_handler("No transport client for service 'client'");
249                 return NULL;
250         }
251
252         char target_buf[512];
253         memset(target_buf,0,512);
254         //char* domain  = config_value( "opensrf.bootstrap", "//%s/domains/domain1", osrf_get_config_context() ); /* just the first for now */
255         //char* router_name = config_value( "opensrf.bootstrap", "//%s/router_name", osrf_get_config_context() );
256
257         osrfStringArray* arr = osrfNewStringArray(8);
258         osrfConfigGetValueList(NULL, arr, "/domains/domain");
259         char* domain = osrfStringArrayGetString(arr, 0);
260         char* router_name = osrfConfigGetValue(NULL, "/router_name");
261         osrfStringArrayFree(arr);
262         
263         sprintf( target_buf, "%s@%s/%s",  router_name, domain, remote_service );
264         //free(domain);
265         free(router_name);
266
267         session->request_queue = NULL;
268         session->remote_id = strdup(target_buf);
269         session->orig_remote_id = strdup(session->remote_id);
270         session->remote_service = strdup(remote_service);
271
272         #ifdef ASSUME_STATELESS
273         session->stateless = 1;
274         debug_handler("session is stateless");
275         #else
276         session->stateless = 0;
277         debug_handler("session is NOT stateless");
278         #endif
279
280         /* build a chunky, random session id */
281         char id[256];
282         memset(id,0,256);
283
284         sprintf(id, "%lf.%d%d", get_timestamp_millis(), (int)time(NULL), getpid());
285         session->session_id = strdup(id);
286         debug_handler( "Building a new client session with id [%s] [%s]", 
287                         session->remote_service, session->session_id );
288
289         session->thread_trace = 0;
290         session->state = OSRF_SESSION_DISCONNECTED;
291         session->type = OSRF_SESSION_CLIENT;
292         session->next = NULL;
293         _osrf_app_session_push_session( session );
294         return session;
295 }
296
297 osrf_app_session* osrf_app_server_session_init( 
298                 char* session_id, char* our_app, char* remote_id ) {
299
300         info_handler("Initing server session with session id %s, service %s,"
301                         " and remote_id %s", session_id, our_app, remote_id );
302
303         osrf_app_session* session = osrf_app_session_find_session( session_id );
304         if(session) return session;
305
306         session = safe_malloc(sizeof(osrf_app_session));        
307
308         session->transport_handle = osrf_system_get_transport_client();
309         if( session->transport_handle == NULL ) {
310                 warning_handler("No transport client for service '%s'", our_app );
311                 return NULL;
312         }
313
314         int stateless = 0;
315         char* statel = osrf_settings_host_value("/apps/%s/stateless", our_app );
316         if(statel) stateless = atoi(statel);
317         free(statel);
318
319
320         session->request_queue = NULL;
321         session->remote_id = strdup(remote_id);
322         session->orig_remote_id = strdup(remote_id);
323         session->session_id = strdup(session_id);
324         session->remote_service = strdup(our_app);
325         session->stateless = stateless;
326
327         #ifdef ASSUME_STATELESS
328         session->stateless = 1;
329         #endif
330
331         session->thread_trace = 0;
332         session->state = OSRF_SESSION_DISCONNECTED;
333         session->type = OSRF_SESSION_SERVER;
334         session->next = NULL;
335
336         _osrf_app_session_push_session( session );
337         return session;
338
339 }
340
341
342
343 /** frees memory held by a session */
344 void _osrf_app_session_free( osrf_app_session* session ){
345         if(session==NULL)
346                 return;
347         
348         free(session->remote_id);
349         free(session->orig_remote_id);
350         free(session->session_id);
351         free(session->remote_service);
352         free(session);
353 }
354
355 int osrfAppSessionMakeRequest(
356                 osrf_app_session* session, jsonObject* params, 
357                 char* method_name, int protocol, string_array* param_strings ) {
358
359         return osrf_app_session_make_req( session, params, 
360                         method_name, protocol, param_strings );
361 }
362
363 int osrf_app_session_make_req( 
364                 osrf_app_session* session, jsonObject* params, 
365                 char* method_name, int protocol, string_array* param_strings ) {
366         if(session == NULL) return -1;
367
368         osrf_message* req_msg = osrf_message_init( REQUEST, ++(session->thread_trace), protocol );
369         osrf_message_set_method(req_msg, method_name);
370         if(params) {
371                 osrf_message_set_params(req_msg, params);
372
373         } else {
374
375                 if(param_strings) {
376                         int i;
377                         for(i = 0; i!= param_strings->size ; i++ ) {
378                                 osrf_message_add_param(req_msg,
379                                         string_array_get_string(param_strings,i));
380                         }
381                 }
382         }
383
384         osrf_app_request* req = _osrf_app_request_init( session, req_msg );
385         if(!_osrf_app_session_send( session, req_msg ) ) {
386                 warning_handler( "Error sending request message [%d]", session->thread_trace );
387                 return -1;
388         }
389
390         _osrf_app_session_push_request( session, req );
391         return req->request_id;
392 }
393
394
395
396 /** Adds an app_request to the request set */
397 void _osrf_app_session_push_request( osrf_app_session* session, osrf_app_request* req ){
398         if(session == NULL || req == NULL)
399                 return;
400
401         debug_handler( "Pushing [%d] onto requeust queue for session [%s] [%s]",
402                         req->request_id, session->remote_service, session->session_id );
403
404         if(session->request_queue == NULL) 
405                 session->request_queue = req;
406         else {
407                 osrf_app_request* req2 = session->request_queue->next;
408                 session->request_queue = req;
409                 req->next = req2;
410         }
411 }
412
413
414
415 /** Removes an app_request from this session request set */
416 void _osrf_app_session_remove_request( osrf_app_session* session, osrf_app_request* req ){
417         if(session == NULL || req == NULL)
418                 return;
419
420         if(session->request_queue == NULL)
421                 return;
422
423         debug_handler("Removing request [%d] from session [%s] [%s]",
424                         req->request_id, session->remote_service, session->session_id );
425
426         osrf_app_request* first = session->request_queue;
427         if(first->request_id == req->request_id) {
428                 session->request_queue = first->next;
429                 return;
430                 /*
431                 if(first->next == NULL) { 
432                         session->request_queue = NULL;
433                 } else {
434                         osrf_app_request* tmp = first->next;
435                         session->request_queue = tmp;
436                 }
437                 */
438         }
439
440         osrf_app_request* lead = first->next;
441
442         while( lead != NULL ) {
443                 if(lead->request_id == req->request_id) {
444                         first->next = lead->next;
445                         return;
446                 }
447                 first = lead;
448                 lead = lead->next;
449         }
450 }
451
452
453 void osrf_app_session_set_complete( osrf_app_session* session, int request_id ) {
454         if(session == NULL)
455                 return;
456
457         osrf_app_request* req = _osrf_app_session_get_request( session, request_id );
458         if(req) req->complete = 1;
459 }
460
461 int osrf_app_session_request_complete( osrf_app_session* session, int request_id ) {
462         if(session == NULL)
463                 return 0;
464         osrf_app_request* req = _osrf_app_session_get_request( session, request_id );
465         if(req)
466                 return req->complete;
467         return 0;
468 }
469
470 /** Returns the app_request with the given request_id (request_id) */
471 osrf_app_request* _osrf_app_session_get_request( 
472                 osrf_app_session* session, int request_id ){
473         if(session == NULL)
474                 return NULL;
475
476         debug_handler( "App Session searching for request [%d] in request queue",request_id );
477         osrf_app_request* req = session->request_queue;
478         while( req != NULL ) {
479                 if(req->request_id == request_id)
480                         return req;
481                 req = req->next;
482         }
483         return NULL;
484 }
485
486
487 /** Resets the remote connection id to that of the original*/
488 void osrf_app_session_reset_remote( osrf_app_session* session ){
489         if( session==NULL )
490                 return;
491
492         free(session->remote_id);
493         debug_handler( "App Session [%s] [%s] resetting remote id to %s",
494                         session->remote_service, session->session_id, session->orig_remote_id );
495
496         session->remote_id = strdup(session->orig_remote_id);
497 }
498
499 void osrf_app_session_set_remote( osrf_app_session* session, char* remote_id ) {
500         if(session == NULL)
501                 return;
502         if( session->remote_id )
503                 free(session->remote_id );
504         session->remote_id = strdup( remote_id );
505 }
506
507 /** pushes the given message into the result list of the app_request
508   with the given request_id */
509 int osrf_app_session_push_queue( 
510                 osrf_app_session* session, osrf_message* msg ){
511
512         if(session == NULL || msg == NULL)
513                 return 0;
514
515         debug_handler( "AppSession pushing result for [%d] onto request payload queue",
516                         msg->thread_trace );
517
518         osrf_app_request* req = session->request_queue;
519
520         if(req == NULL) {
521                 warning_handler( "app_session has no app_requests in its queue yet we have a result for [%d]", msg->thread_trace );
522                 return 0;
523         }
524
525         while( req != NULL ) {
526                 if(req->request_id == msg->thread_trace) {
527                         debug_handler( "Found app_request for tt [%d]", msg->thread_trace );
528                         _osrf_app_request_push_queue( req, msg );
529                         return 1;
530                 }
531                 req = req->next;
532         } 
533
534         return 0;
535         
536 }
537
538 /** Attempts to connect to the remote service */
539 int osrf_app_session_connect(osrf_app_session* session){
540         
541         if(session == NULL)
542                 return 0;
543
544         if(session->state == OSRF_SESSION_CONNECTED) {
545                 debug_handler("Already Connected, returning");
546                 return 1;
547         }
548
549         int timeout = 5; /* XXX CONFIG VALUE */
550
551         debug_handler( "AppSession connecting to %s", session->remote_id );
552
553         /* defaulting to protocol 1 for now */
554         osrf_message* con_msg = osrf_message_init( CONNECT, session->thread_trace, 1 );
555         osrf_app_session_reset_remote( session );
556         session->state = OSRF_SESSION_CONNECTING;
557         int ret = _osrf_app_session_send( session, con_msg );
558         osrf_message_free(con_msg);
559         if(!ret)        return 0;
560
561         time_t start = time(NULL);      
562         time_t remaining = (time_t) timeout;
563
564         while( session->state != OSRF_SESSION_CONNECTED && remaining >= 0 ) {
565                 osrf_app_session_queue_wait( session, remaining );
566                 remaining -= (int) (time(NULL) - start);
567         }
568
569         if(session->state == OSRF_SESSION_CONNECTED)
570                 debug_handler(" * Connected Successfully");
571
572         if(session->state != OSRF_SESSION_CONNECTED)
573                 return 0;
574
575         return 1;
576 }
577
578
579
580 /** Disconnects from the remote service */
581 int osrf_app_session_disconnect( osrf_app_session* session){
582         if(session == NULL)
583                 return 1;
584
585         if(session->state == OSRF_SESSION_DISCONNECTED)
586                 return 1;
587
588         if(session->stateless && session->state != OSRF_SESSION_CONNECTED) {
589                 debug_handler(
590                                 "Exiting disconnect on stateless session %s", 
591                                 session->session_id);
592                 return 1;
593         }
594
595         debug_handler( "AppSession disconnecting from %s", session->remote_id );
596
597         osrf_message* dis_msg = osrf_message_init( DISCONNECT, session->thread_trace, 1 );
598         session->state = OSRF_SESSION_DISCONNECTED;
599         _osrf_app_session_send( session, dis_msg );
600
601         osrf_message_free( dis_msg );
602         osrf_app_session_reset_remote( session );
603         return 1;
604 }
605
606 int osrf_app_session_request_resend( osrf_app_session* session, int req_id ) {
607         debug_handler("In reqeust resend searching for resend-able messages");
608         osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
609         return _osrf_app_request_resend( req );
610 }
611
612
613 int osrfAppSessionSendBatch( osrfAppSession* session, osrf_message* msgs[], int size ) {
614
615         if( !(session && msgs && size > 0) ) return 0;
616         int retval = 0;
617
618
619         osrfMessage* msg = msgs[0];
620
621         if(msg) {
622
623                 osrf_app_session_queue_wait( session, 0 );
624
625                 /* if we're not stateless and the first message is not a connect
626                         message, then we do the connect first */
627                 if(session->stateless) {
628                                 osrf_app_session_reset_remote(session);
629
630                 } else {
631
632                         if( (msg->m_type != CONNECT) && (msg->m_type != DISCONNECT) &&
633                                 (session->state != OSRF_SESSION_CONNECTED) ) {
634                                 if(!osrf_app_session_connect( session )) 
635                                         return 0;
636                         }
637                 }
638         }
639
640         char* string = osrfMessageSerializeBatch(msgs, size);
641
642         if( string ) {
643
644                 transport_message* t_msg = message_init( 
645                                 string, "", session->session_id, session->remote_id, NULL );
646         
647                 debug_handler("Session [%s] [%s]  sending to %s \nXML:\n%s", 
648                                 session->remote_service, session->session_id, t_msg->recipient, string );
649
650                 retval = client_send_message( session->transport_handle, t_msg );
651         
652                 free(string);
653                 message_free( t_msg );
654         }
655
656         return retval; 
657
658
659 }
660
661
662
663 int _osrf_app_session_send( osrf_app_session* session, osrf_message* msg ){
664         if( !(session && msg) ) return 0;
665         osrfMessage* a[1];
666         a[0] = msg;
667         return osrfAppSessionSendBatch( session, a, 1 );
668 }
669
670
671
672
673 /**  Waits up to 'timeout' seconds for some data to arrive.
674   * Any data that arrives will be processed according to its
675   * payload and message type.  This method will return after
676   * any data has arrived.
677   */
678 int osrf_app_session_queue_wait( osrf_app_session* session, int timeout ){
679         if(session == NULL) return 0;
680         int ret_val = 0;
681         debug_handler( "AppSession in queue_wait with timeout %d", timeout );
682         ret_val = osrf_stack_entry_point(session->transport_handle, timeout);
683         return ret_val;
684 }
685
686 /** Disconnects (if client) and removes the given session from the global session cache 
687   * ! This free's all attached app_requests ! 
688   */
689 void osrf_app_session_destroy ( osrf_app_session* session ){
690         if(session == NULL) return;
691
692         debug_handler( "AppSession [%s] [%s] destroying self and deleting requests", 
693                         session->remote_service, session->session_id );
694         if(session->type == OSRF_SESSION_CLIENT 
695                         && session->state != OSRF_SESSION_DISCONNECTED ) { /* disconnect if we're a client */
696                 osrf_message* dis_msg = osrf_message_init( DISCONNECT, session->thread_trace, 1 );
697                 _osrf_app_session_send( session, dis_msg ); 
698                 osrf_message_free(dis_msg);
699         }
700         //session->state = OSRF_SESSION_DISCONNECTED;
701         _osrf_app_session_remove_session(session->session_id);
702         debug_handler("AppSession [%s] [%s] removed from cache", 
703                         session->remote_service, session->session_id );
704
705         osrf_app_request* req;
706         while( session->request_queue != NULL ) {
707                 req = session->request_queue->next;
708                 _osrf_app_request_free( session->request_queue );
709                 session->request_queue = req;
710         }
711
712         _osrf_app_session_free( session );
713 }
714
715 osrf_message* osrfAppSessionRequestRecv(
716                 osrf_app_session* session, int req_id, int timeout ) {
717         return osrf_app_session_request_recv( session, req_id, timeout );
718 }
719 osrf_message* osrf_app_session_request_recv( 
720                 osrf_app_session* session, int req_id, int timeout ) {
721         if(req_id < 0 || session == NULL)
722                 return NULL;
723         debug_handler("somebody callled recv");
724         osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
725         return _osrf_app_request_recv( req, timeout );
726 }
727
728
729
730 int osrfAppRequestRespond( osrfAppSession* ses, int requestId, jsonObject* data ) {
731         if(!ses || ! data ) return -1;
732
733         osrf_message* msg = osrf_message_init( RESULT, requestId, 1 );
734         char* json = jsonObjectToJSON( data );
735         osrf_message_set_result_content( msg, json );
736         _osrf_app_session_send( ses, msg ); 
737
738         free(json);
739         osrf_message_free( msg );
740
741         return 0;
742 }
743
744
745 int osrfAppRequestRespondComplete( 
746                 osrfAppSession* ses, int requestId, jsonObject* data ) {
747
748         osrf_message* payload = osrf_message_init( RESULT, requestId, 1 );
749         osrf_message_set_status_info( payload, NULL, "OK", OSRF_STATUS_OK );
750
751         char* json = jsonObjectToJSON( data );
752         osrf_message_set_result_content( payload, json );
753         free(json);
754
755         osrf_message* status = osrf_message_init( STATUS, requestId, 1);
756         osrf_message_set_status_info( status, "osrfConnectStatus", "Request Complete", OSRF_STATUS_COMPLETE );
757
758         osrfMessage* ms[2];
759         ms[0] = payload;
760         ms[1] = status;
761
762         osrfAppSessionSendBatch( ses, ms, 2 );
763
764         osrf_message_free( payload );
765         osrf_message_free( status );
766
767         /* join and free */
768
769         return 0;
770 }
771
772
773
774 int osrfAppSessionStatus( osrfAppSession* ses, int type, int reqId, char* message ) {
775
776         if(ses) {
777                 osrf_message* msg = osrf_message_init( STATUS, reqId, 1);
778                 osrf_message_set_status_info( msg, "Server Error", message, type );
779                 _osrf_app_session_send( ses, msg ); 
780                 osrf_message_free( msg );
781                 return 0;
782         }
783         return -1;
784 }
785
786
787
788
789
790