6d67cecd7c0896718c28c44c350f8182f79b0f10
[OpenSRF.git] / src / libopensrf / transport_session.c
1 #include <opensrf/transport_session.h>
2
3 static char* get_xml_attr( const xmlChar** atts, const char* attr_name );
4
5 // ---------------------------------------------------------------------------------
6 // returns a built and allocated transport_session object.
7 // This codes does no network activity, only memory initilization
8 // ---------------------------------------------------------------------------------
9 transport_session* init_transport(  const char* server, 
10         int port, const char* unix_path, void* user_data, int component ) {
11
12         /* create the session struct */
13         transport_session* session = 
14                 (transport_session*) safe_malloc( sizeof(transport_session) );
15
16         session->user_data = user_data;
17
18         session->component = component;
19
20         /* initialize the data buffers */
21         session->body_buffer                    = buffer_init( JABBER_BODY_BUFSIZE );
22         session->subject_buffer         = buffer_init( JABBER_SUBJECT_BUFSIZE );
23         session->thread_buffer          = buffer_init( JABBER_THREAD_BUFSIZE );
24         session->from_buffer                    = buffer_init( JABBER_JID_BUFSIZE );
25         session->status_buffer          = buffer_init( JABBER_STATUS_BUFSIZE );
26         session->recipient_buffer       = buffer_init( JABBER_JID_BUFSIZE );
27         session->message_error_type = buffer_init( JABBER_JID_BUFSIZE );
28         session->session_id                     = buffer_init( 64 );
29
30         session->message_error_code = 0;
31
32         /* for OpenSRF extensions */
33         session->router_to_buffer               = buffer_init( JABBER_JID_BUFSIZE );
34         session->router_from_buffer     = buffer_init( JABBER_JID_BUFSIZE );
35         session->osrf_xid_buffer        = buffer_init( JABBER_JID_BUFSIZE );
36         session->router_class_buffer    = buffer_init( JABBER_JID_BUFSIZE );
37         session->router_command_buffer  = buffer_init( JABBER_JID_BUFSIZE );
38
39         session->router_broadcast   = 0;
40
41         if(     session->body_buffer            == NULL || session->subject_buffer       == NULL        ||
42                         session->thread_buffer  == NULL || session->from_buffer          == NULL        ||
43                         session->status_buffer  == NULL || session->recipient_buffer == NULL ||
44                         session->router_to_buffer       == NULL || session->router_from_buffer   == NULL ||
45                         session->router_class_buffer == NULL || session->router_command_buffer == NULL ||
46                         session->session_id == NULL ) { 
47
48                 osrfLogError(OSRF_LOG_MARK,  "init_transport(): buffer_init returned NULL" );
49                 buffer_free( session->body_buffer );
50                 buffer_free( session->subject_buffer );
51                 buffer_free( session->thread_buffer );
52                 buffer_free( session->from_buffer );
53                 buffer_free( session->status_buffer );
54                 buffer_free( session->recipient_buffer );
55                 buffer_free( session->router_to_buffer );
56                 buffer_free( session->router_from_buffer );
57                 buffer_free( session->router_class_buffer );
58                 buffer_free( session->router_command_buffer );
59                 buffer_free( session->session_id );
60                 free( session );
61                 return 0;
62         }
63
64
65         /* initialize the jabber state machine */
66         session->state_machine = (jabber_machine*) safe_malloc( sizeof(jabber_machine) );
67         session->state_machine->connected        = 0;
68         session->state_machine->connecting       = 0;
69         session->state_machine->in_message       = 0;
70         session->state_machine->in_message_body  = 0;
71         session->state_machine->in_thread        = 0;
72         session->state_machine->in_subject       = 0;
73         session->state_machine->in_error         = 0;
74         session->state_machine->in_message_error = 0;
75         session->state_machine->in_iq            = 0;
76         session->state_machine->in_presence      = 0;
77         session->state_machine->in_status        = 0;
78
79         /* initialize the sax push parser */
80         session->parser_ctxt = xmlCreatePushParserCtxt(SAXHandler, session, "", 0, NULL);
81
82         /* initialize the transport_socket structure */
83         session->sock_mgr = (socket_manager*) safe_malloc( sizeof(socket_manager) );
84
85         session->sock_mgr->data_received = &grab_incoming;
86         session->sock_mgr->on_socket_closed = NULL;
87         session->sock_mgr->socket = NULL;
88         session->sock_mgr->blob = session;
89         
90         session->port = port;
91         session->server = strdup(server);
92         if(unix_path)   
93                 session->unix_path = strdup(unix_path);
94         else session->unix_path = NULL;
95
96         session->sock_id = 0;
97         session->message_callback = NULL;
98
99         return session;
100 }
101
102
103
104 /* XXX FREE THE BUFFERS */
105 int session_free( transport_session* session ) {
106         if( ! session ) { return 0; }
107
108         if(session->sock_mgr)
109                 socket_manager_free(session->sock_mgr);
110
111         if( session->state_machine ) free( session->state_machine );
112         if( session->parser_ctxt) {
113                 xmlFreeDoc( session->parser_ctxt->myDoc );
114                 xmlFreeParserCtxt(session->parser_ctxt);
115         }
116
117         xmlCleanupCharEncodingHandlers();
118         xmlDictCleanup();
119         xmlCleanupParser();
120
121         buffer_free(session->body_buffer);
122         buffer_free(session->subject_buffer);
123         buffer_free(session->thread_buffer);
124         buffer_free(session->from_buffer);
125         buffer_free(session->recipient_buffer);
126         buffer_free(session->status_buffer);
127         buffer_free(session->message_error_type);
128         buffer_free(session->router_to_buffer);
129         buffer_free(session->router_from_buffer);
130         buffer_free(session->osrf_xid_buffer);
131         buffer_free(session->router_class_buffer);
132         buffer_free(session->router_command_buffer);
133         buffer_free(session->session_id);
134
135         free(session->server);
136         free(session->unix_path);
137
138         free( session );
139         return 1;
140 }
141
142
143 int session_wait( transport_session* session, int timeout ) {
144         if( ! session || ! session->sock_mgr ) {
145                 return 0;
146         }
147
148         int ret =  socket_wait( session->sock_mgr, timeout, session->sock_id );
149
150         if( ret ) {
151                 osrfLogDebug(OSRF_LOG_MARK, "socket_wait returned error code %d", ret);
152                 session->state_machine->connected = 0;
153         }
154         return ret;
155 }
156
157 int session_send_msg( 
158                 transport_session* session, transport_message* msg ) {
159
160         if( ! session ) { return -1; }
161
162         if( ! session->state_machine->connected ) {
163                 osrfLogWarning(OSRF_LOG_MARK, "State machine is not connected in send_msg()");
164                 return -1;
165         }
166
167         message_prepare_xml( msg );
168         //tcp_send( session->sock_obj, msg->msg_xml );
169         return socket_send( session->sock_id, msg->msg_xml );
170
171 }
172
173
174 /* connects to server and connects to jabber */
175 int session_connect( transport_session* session, 
176                 const char* username, const char* password, 
177                 const char* resource, int connect_timeout, enum TRANSPORT_AUTH_TYPE auth_type ) {
178
179         int size1 = 0;
180         int size2 = 0;
181
182         if( ! session ) { 
183                 osrfLogWarning(OSRF_LOG_MARK,  "session is null in connect" );
184                 return 0; 
185         }
186
187
188         //char* server = session->sock_obj->server;
189         char* server = session->server;
190
191         if( ! session->sock_id ) {
192
193                 if(session->port > 0) {
194                         if( (session->sock_id = socket_open_tcp_client(
195                                 session->sock_mgr, session->port, session->server)) <= 0 ) 
196                         return 0;
197
198                 } else if(session->unix_path != NULL) {
199                         if( (session->sock_id = socket_open_unix_client(
200                                 session->sock_mgr, session->unix_path)) <= 0 ) 
201                         return 0;
202                 }
203                 else {
204                         osrfLogWarning( OSRF_LOG_MARK, "Can't open session: no port or unix path" );
205                         return 0;
206                 }
207         }
208
209         if( session->component ) {
210
211                 /* the first Jabber connect stanza */
212                 char* our_hostname = getenv("HOSTNAME");
213                 size1 = 150 + strlen( server );
214                 char stanza1[ size1 ]; 
215                 snprintf( stanza1, sizeof(stanza1),
216                                 "<stream:stream version='1.0' xmlns:stream='http://etherx.jabber.org/streams' "
217                                 "xmlns='jabber:component:accept' to='%s' from='%s' xml:lang='en'>",
218                                 username, our_hostname );
219
220                 /* send the first stanze */
221                 session->state_machine->connecting = CONNECTING_1;
222
223 //              if( ! tcp_send( session->sock_obj, stanza1 ) ) {
224                 if( socket_send( session->sock_id, stanza1 ) ) {
225                         osrfLogWarning(OSRF_LOG_MARK, "error sending");
226                         return 0;
227                 }
228         
229                 /* wait for reply */
230                 //tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
231                 socket_wait(session->sock_mgr, connect_timeout, session->sock_id);
232         
233                 /* server acknowledges our existence, now see if we can login */
234                 if( session->state_machine->connecting == CONNECTING_2 ) {
235         
236                         int ss = session->session_id->n_used + strlen(password) + 5;
237                         char hashstuff[ss];
238                         snprintf( hashstuff, sizeof(hashstuff), "%s%s", session->session_id->buf, password );
239
240                         char* hash = shahash( hashstuff );
241                         size2 = 100 + strlen( hash );
242                         char stanza2[ size2 ];
243                         snprintf( stanza2, sizeof(stanza2), "<handshake>%s</handshake>", hash );
244         
245                         //if( ! tcp_send( session->sock_obj, stanza2 )  ) {
246                         if( socket_send( session->sock_id, stanza2 )  ) {
247                                 osrfLogWarning(OSRF_LOG_MARK, "error sending");
248                                 return 0;
249                         }
250                 }
251
252         } else { /* we're not a component */
253
254                 /* the first Jabber connect stanza */
255                 size1 = 100 + strlen( server );
256                 char stanza1[ size1 ]; 
257                 snprintf( stanza1, sizeof(stanza1), 
258                                 "<stream:stream to='%s' xmlns='jabber:client' "
259                                 "xmlns:stream='http://etherx.jabber.org/streams'>",
260                         server );
261         
262
263                 /* send the first stanze */
264                 session->state_machine->connecting = CONNECTING_1;
265                 //if( ! tcp_send( session->sock_obj, stanza1 ) ) {
266                 if( socket_send( session->sock_id, stanza1 ) ) {
267                         osrfLogWarning(OSRF_LOG_MARK, "error sending");
268                         return 0;
269                 }
270
271
272                 /* wait for reply */
273                 //tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
274                 socket_wait( session->sock_mgr, connect_timeout, session->sock_id ); /* make the timeout smarter XXX */
275
276                 if( auth_type == AUTH_PLAIN ) {
277
278                         /* the second jabber connect stanza including login info*/
279                         size2 = 150 + strlen( username ) + strlen(password) + strlen(resource);
280                         char stanza2[ size2 ];
281                         snprintf( stanza2, sizeof(stanza2), 
282                                         "<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'>"
283                                         "<username>%s</username><password>%s</password><resource>%s</resource></query></iq>",
284                                         username, password, resource );
285         
286                         /* server acknowledges our existence, now see if we can login */
287                         if( session->state_machine->connecting == CONNECTING_2 ) {
288                                 //if( ! tcp_send( session->sock_obj, stanza2 )  ) {
289                                 if( socket_send( session->sock_id, stanza2 )  ) {
290                                         osrfLogWarning(OSRF_LOG_MARK, "error sending");
291                                         return 0;
292                                 }
293                         }
294
295                 } else if( auth_type == AUTH_DIGEST ) {
296
297                         int ss = session->session_id->n_used + strlen(password) + 5;
298                         char hashstuff[ss];
299                         snprintf( hashstuff, sizeof(hashstuff), "%s%s", session->session_id->buf, password );
300
301                         char* hash = shahash( hashstuff );
302
303                         /* the second jabber connect stanza including login info*/
304                         size2 = 150 + strlen( hash ) + strlen(password) + strlen(resource);
305                         char stanza2[ size2 ];
306                         snprintf( stanza2, sizeof(stanza2), 
307                                         "<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'>"
308                                         "<username>%s</username><digest>%s</digest><resource>%s</resource></query></iq>",
309                                         username, hash, resource );
310         
311                         /* server acknowledges our existence, now see if we can login */
312                         if( session->state_machine->connecting == CONNECTING_2 ) {
313                                 //if( ! tcp_send( session->sock_obj, stanza2 )  ) {
314                                 if( socket_send( session->sock_id, stanza2 )  ) {
315                                         osrfLogWarning(OSRF_LOG_MARK, "error sending");
316                                         return 0;
317                                 }
318                         }
319
320                 }
321
322         } // not component
323
324
325         /* wait for reply */
326         //tcp_wait( session->sock_obj, connect_timeout );
327         socket_wait( session->sock_mgr, connect_timeout, session->sock_id );
328
329         if( session->state_machine->connected ) {
330                 /* yar! */
331                 return 1;
332         }
333
334         return 0;
335 }
336
337 // ---------------------------------------------------------------------------------
338 // TCP data callback. Shove the data into the push parser.
339 // ---------------------------------------------------------------------------------
340 //void grab_incoming( void * session, char* data ) {
341 void grab_incoming(void* blob, socket_manager* mgr, int sockid, char* data, int parent) {
342         transport_session* ses = (transport_session*) blob;
343         if( ! ses ) { return; }
344         xmlParseChunk(ses->parser_ctxt, data, strlen(data), 0);
345 }
346
347
348 void startElementHandler(
349         void *session, const xmlChar *name, const xmlChar **atts) {
350
351         transport_session* ses = (transport_session*) session;
352         if( ! ses ) { return; }
353
354         
355         if( strcmp( (char*) name, "message" ) == 0 ) {
356                 ses->state_machine->in_message = 1;
357                 buffer_add( ses->from_buffer, get_xml_attr( atts, "from" ) );
358                 buffer_add( ses->recipient_buffer, get_xml_attr( atts, "to" ) );
359                 buffer_add( ses->router_from_buffer, get_xml_attr( atts, "router_from" ) );
360                 buffer_add( ses->osrf_xid_buffer, get_xml_attr( atts, "osrf_xid" ) );
361                 buffer_add( ses->router_to_buffer, get_xml_attr( atts, "router_to" ) );
362                 buffer_add( ses->router_class_buffer, get_xml_attr( atts, "router_class" ) );
363                 buffer_add( ses->router_command_buffer, get_xml_attr( atts, "router_command" ) );
364                 char* broadcast = get_xml_attr( atts, "broadcast" );
365                 if( broadcast )
366                         ses->router_broadcast = atoi( broadcast );
367
368                 return;
369         }
370
371         if( ses->state_machine->in_message ) {
372
373                 if( strcmp( (char*) name, "body" ) == 0 ) {
374                         ses->state_machine->in_message_body = 1;
375                         return;
376                 }
377         
378                 if( strcmp( (char*) name, "subject" ) == 0 ) {
379                         ses->state_machine->in_subject = 1;
380                         return;
381                 }
382         
383                 if( strcmp( (char*) name, "thread" ) == 0 ) {
384                         ses->state_machine->in_thread = 1;
385                         return;
386                 }
387
388         }
389
390         if( strcmp( (char*) name, "presence" ) == 0 ) {
391                 ses->state_machine->in_presence = 1;
392                 buffer_add( ses->from_buffer, get_xml_attr( atts, "from" ) );
393                 buffer_add( ses->recipient_buffer, get_xml_attr( atts, "to" ) );
394                 return;
395         }
396
397         if( strcmp( (char*) name, "status" ) == 0 ) {
398                 ses->state_machine->in_status = 1;
399                 return;
400         }
401
402
403         if( strcmp( (char*) name, "stream:error" ) == 0 ) {
404                 ses->state_machine->in_error = 1;
405                 ses->state_machine->connected = 0;
406                 osrfLogWarning(  OSRF_LOG_MARK, "Received <stream:error> message from Jabber server" );
407                 return;
408         }
409
410
411         /* first server response from a connect attempt */
412         if( strcmp( (char*) name, "stream:stream" ) == 0 ) {
413                 if( ses->state_machine->connecting == CONNECTING_1 ) {
414                         ses->state_machine->connecting = CONNECTING_2;
415                         buffer_add( ses->session_id, get_xml_attr(atts, "id") );
416                 }
417         }
418
419         if( strcmp( (char*) name, "handshake" ) == 0 ) {
420                 ses->state_machine->connected = 1;
421                 ses->state_machine->connecting = 0;
422                 return;
423         }
424
425
426         if( strcmp( (char*) name, "error" ) == 0 ) {
427                 ses->state_machine->in_message_error = 1;
428                 buffer_add( ses->message_error_type, get_xml_attr( atts, "type" ) );
429                 ses->message_error_code = atoi( get_xml_attr( atts, "code" ) );
430                 osrfLogInfo( OSRF_LOG_MARK,  "Received <error> message with type %s and code %s", 
431                         get_xml_attr( atts, "type"), get_xml_attr( atts, "code") );
432                 return;
433         }
434
435         if( strcmp( (char*) name, "iq" ) == 0 ) {
436                 ses->state_machine->in_iq = 1;
437
438                 if( strcmp( get_xml_attr(atts, "type"), "result") == 0 
439                                 && ses->state_machine->connecting == CONNECTING_2 ) {
440                         ses->state_machine->connected = 1;
441                         ses->state_machine->connecting = 0;
442                         return;
443                 }
444
445                 if( strcmp( get_xml_attr(atts, "type"), "error") == 0 ) {
446                         osrfLogWarning( OSRF_LOG_MARK,  "Error connecting to jabber" );
447                         return;
448                 }
449         }
450 }
451
452 // ------------------------------------------------------------------
453 // Returns the value of the given XML attribute
454 // The xmlChar** construct is commonly returned from SAX event
455 // handlers.  Pass that in with the name of the attribute you want
456 // to retrieve.
457 // ------------------------------------------------------------------
458 static char* get_xml_attr( const xmlChar** atts, const char* attr_name ) {
459         int i;
460         if (atts != NULL) {
461                 for(i = 0;(atts[i] != NULL);i++) {
462                         if( strcmp( (char*) atts[i++], attr_name ) == 0 ) {
463                                 if( atts[i] != NULL ) {
464                                         return (char*) atts[i];
465                                 }
466                         }
467                 }
468         }
469         return NULL;
470 }
471
472
473 // ------------------------------------------------------------------
474 // See which tags are ending
475 // ------------------------------------------------------------------
476 void endElementHandler( void *session, const xmlChar *name) {
477         transport_session* ses = (transport_session*) session;
478         if( ! ses ) { return; }
479
480         if( strcmp( (char*) name, "message" ) == 0 ) {
481
482
483                 /* pass off the message info the callback */
484                 if( ses->message_callback ) {
485
486                         /* here it's ok to pass in the raw buffers because
487                                 message_init allocates new space for the chars 
488                                 passed in */
489                         transport_message* msg =  message_init( 
490                                 ses->body_buffer->buf, 
491                                 ses->subject_buffer->buf,
492                                 ses->thread_buffer->buf, 
493                                 ses->recipient_buffer->buf, 
494                                 ses->from_buffer->buf );
495
496                         message_set_router_info( msg, 
497                                 ses->router_from_buffer->buf, 
498                                 ses->router_to_buffer->buf, 
499                                 ses->router_class_buffer->buf,
500                                 ses->router_command_buffer->buf,
501                                 ses->router_broadcast );
502
503          message_set_osrf_xid( msg, ses->osrf_xid_buffer->buf );
504
505                         if( ses->message_error_type->n_used > 0 ) {
506                                 set_msg_error( msg, ses->message_error_type->buf, ses->message_error_code );
507                         }
508
509                         if( msg == NULL ) { return; }
510                         ses->message_callback( ses->user_data, msg );
511                 }
512
513                 ses->state_machine->in_message = 0;
514                 reset_session_buffers( session );
515                 return;
516         }
517         
518         if( strcmp( (const char*) name, "body" ) == 0 ) {
519                 ses->state_machine->in_message_body = 0;
520                 return;
521         }
522
523         if( strcmp( (const char*) name, "subject" ) == 0 ) {
524                 ses->state_machine->in_subject = 0;
525                 return;
526         }
527
528         if( strcmp( (const char*) name, "thread" ) == 0 ) {
529                 ses->state_machine->in_thread = 0;
530                 return;
531         }
532         
533         if( strcmp( (const char*) name, "iq" ) == 0 ) {
534                 ses->state_machine->in_iq = 0;
535                 if( ses->message_error_code > 0 ) {
536                         osrfLogWarning( OSRF_LOG_MARK,  "Error in IQ packet: code %d",  ses->message_error_code );
537                         osrfLogWarning( OSRF_LOG_MARK,  "Error 401 means not authorized" );
538                 }
539                 reset_session_buffers( session );
540                 return;
541         }
542
543         if( strcmp( (const char*) name, "presence" ) == 0 ) {
544                 ses->state_machine->in_presence = 0;
545                 /*
546                 if( ses->presence_callback ) {
547                         // call the callback with the status, etc.
548                 }
549                 */
550                 reset_session_buffers( session );
551                 return;
552         }
553
554         if( strcmp( (const char*) name, "status" ) == 0 ) {
555                 ses->state_machine->in_status = 0;
556                 return;
557         }
558
559         if( strcmp( (const char*) name, "error" ) == 0 ) {
560                 ses->state_machine->in_message_error = 0;
561                 return;
562         }
563
564         if( strcmp( (const char*) name, "error:error" ) == 0 ) {
565                 ses->state_machine->in_error = 0;
566                 return;
567         }
568 }
569
570 int reset_session_buffers( transport_session* ses ) {
571         buffer_reset( ses->body_buffer );
572         buffer_reset( ses->subject_buffer );
573         buffer_reset( ses->thread_buffer );
574         buffer_reset( ses->from_buffer );
575         buffer_reset( ses->recipient_buffer );
576         buffer_reset( ses->router_from_buffer );
577         buffer_reset( ses->osrf_xid_buffer );
578         buffer_reset( ses->router_to_buffer );
579         buffer_reset( ses->router_class_buffer );
580         buffer_reset( ses->router_command_buffer );
581         buffer_reset( ses->message_error_type );
582         buffer_reset( ses->session_id );
583
584         return 1;
585 }
586
587 // ------------------------------------------------------------------
588 // takes data out of the body of the message and pushes it into
589 // the appropriate buffer
590 // ------------------------------------------------------------------
591 void characterHandler(
592                 void *session, const xmlChar *ch, int len) {
593
594         char data[len+1];
595         strncpy( data, (const char*) ch, len );
596         data[len] = 0;
597
598         //printf( "Handling characters: %s\n", data );
599         transport_session* ses = (transport_session*) session;
600         if( ! ses ) { return; }
601
602         /* set the various message parts */
603         if( ses->state_machine->in_message ) {
604
605                 if( ses->state_machine->in_message_body ) {
606                         buffer_add( ses->body_buffer, data );
607                 }
608
609                 if( ses->state_machine->in_subject ) {
610                         buffer_add( ses->subject_buffer, data );
611                 }
612
613                 if( ses->state_machine->in_thread ) {
614                         buffer_add( ses->thread_buffer, data );
615                 }
616         }
617
618         /* set the presence status */
619         if( ses->state_machine->in_presence && ses->state_machine->in_status ) {
620                 buffer_add( ses->status_buffer, data );
621         }
622
623         if( ses->state_machine->in_error ) {
624                 /* for now... */
625                 osrfLogWarning( OSRF_LOG_MARK,  "ERROR XML fragment: %s\n", ch );
626         }
627
628 }
629
630 /* XXX change to warning handlers */
631 void  parseWarningHandler( void *session, const char* msg, ... ) {
632
633         va_list args;
634         va_start(args, msg);
635         fprintf(stdout, "transport_session XML WARNING");
636         vfprintf(stdout, msg, args);
637         va_end(args);
638         fprintf(stderr, "XML WARNING: %s\n", msg ); 
639 }
640
641 void  parseErrorHandler( void *session, const char* msg, ... ){
642
643         va_list args;
644         va_start(args, msg);
645         fprintf(stdout, "transport_session XML ERROR");
646         vfprintf(stdout, msg, args);
647         va_end(args);
648         fprintf(stderr, "XML ERROR: %s\n", msg ); 
649
650 }
651
652 int session_disconnect( transport_session* session ) {
653         if( session == NULL ) { return 0; }
654         //tcp_send( session->sock_obj, "</stream:stream>");
655         socket_send(session->sock_id, "</stream:stream>");
656         socket_disconnect(session->sock_mgr, session->sock_id);
657         return 0;
658         //return tcp_disconnect( session->sock_obj );
659 }
660