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