[Opensrf-commits] r1573 - in trunk: include/opensrf src/libopensrf
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Jan 6 15:55:07 EST 2009
Author: scottmk
Date: 2009-01-06 15:55:03 -0500 (Tue, 06 Jan 2009)
New Revision: 1573
Modified:
trunk/include/opensrf/transport_session.h
trunk/src/libopensrf/transport_session.c
Log:
1. Make the functions reset_session_buffers() and grab_incoming()
static, since no other source file references them by name.
2. Delete various fragments of dead, obsolete, commented-out code.
3. In init_transport: delete the cleanup code after failure
of previous calls to buffer_init(). It's unreachable, since
buffer_init() can never return NULL.
4. Change transport_session.c so that it uses buffer_add_n()
instead of passing data through an intermediate buffer.
Modified: trunk/include/opensrf/transport_session.h
===================================================================
--- trunk/include/opensrf/transport_session.h 2009-01-06 16:01:41 UTC (rev 1572)
+++ trunk/include/opensrf/transport_session.h 2009-01-06 20:55:03 UTC (rev 1573)
@@ -34,12 +34,6 @@
#define JABBER_STATUS_BUFSIZE 16
// ---------------------------------------------------------------------------------
-// Takes data from the socket handler and pushes it directly into the push parser
-// ---------------------------------------------------------------------------------
-//void grab_incoming( void * session, char* data );
-void grab_incoming(void* blob, socket_manager* mgr, int sockid, char* data, int parent);
-
-// ---------------------------------------------------------------------------------
// Callback for handling the startElement event. Much of the jabber logic occurs
// in this and the characterHandler callbacks.
// Here we check for the various top level jabber elements: body, iq, etc.
@@ -134,7 +128,6 @@
struct transport_session_struct {
/* our socket connection */
- //transport_socket* sock_obj;
socket_manager* sock_mgr;
/* our Jabber state machine */
@@ -221,6 +214,4 @@
int session_disconnect( transport_session* session );
-int reset_session_buffers( transport_session* session );
-
#endif
Modified: trunk/src/libopensrf/transport_session.c
===================================================================
--- trunk/src/libopensrf/transport_session.c 2009-01-06 16:01:41 UTC (rev 1572)
+++ trunk/src/libopensrf/transport_session.c 2009-01-06 20:55:03 UTC (rev 1573)
@@ -4,6 +4,8 @@
#define HOST_NAME_MAX 256
#endif
+static void grab_incoming(void* blob, socket_manager* mgr, int sockid, char* data, int parent);
+static int reset_session_buffers( transport_session* session );
static char* get_xml_attr( const xmlChar** atts, const char* attr_name );
// ---------------------------------------------------------------------------------
@@ -42,30 +44,6 @@
session->router_broadcast = 0;
- if( session->body_buffer == NULL || session->subject_buffer == NULL ||
- session->thread_buffer == NULL || session->from_buffer == NULL ||
- session->status_buffer == NULL || session->recipient_buffer == NULL ||
- session->router_to_buffer == NULL || session->router_from_buffer == NULL ||
- session->router_class_buffer == NULL || session->router_command_buffer == NULL ||
- session->session_id == NULL ) {
-
- osrfLogError(OSRF_LOG_MARK, "init_transport(): buffer_init returned NULL" );
- buffer_free( session->body_buffer );
- buffer_free( session->subject_buffer );
- buffer_free( session->thread_buffer );
- buffer_free( session->from_buffer );
- buffer_free( session->status_buffer );
- buffer_free( session->recipient_buffer );
- buffer_free( session->router_to_buffer );
- buffer_free( session->router_from_buffer );
- buffer_free( session->router_class_buffer );
- buffer_free( session->router_command_buffer );
- buffer_free( session->session_id );
- free( session );
- return 0;
- }
-
-
/* initialize the jabber state machine */
session->state_machine = (jabber_machine*) safe_malloc( sizeof(jabber_machine) );
session->state_machine->connected = 0;
@@ -169,7 +147,6 @@
}
message_prepare_xml( msg );
- //tcp_send( session->sock_obj, msg->msg_xml );
return socket_send( session->sock_id, msg->msg_xml );
}
@@ -189,7 +166,6 @@
}
- //char* server = session->sock_obj->server;
char* server = session->server;
if( ! session->sock_id ) {
@@ -226,14 +202,12 @@
/* send the first stanze */
session->state_machine->connecting = CONNECTING_1;
-// if( ! tcp_send( session->sock_obj, stanza1 ) ) {
if( socket_send( session->sock_id, stanza1 ) ) {
osrfLogWarning(OSRF_LOG_MARK, "error sending");
return 0;
}
/* wait for reply */
- //tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
socket_wait(session->sock_mgr, connect_timeout, session->sock_id);
/* server acknowledges our existence, now see if we can login */
@@ -248,7 +222,6 @@
char stanza2[ size2 ];
snprintf( stanza2, sizeof(stanza2), "<handshake>%s</handshake>", hash );
- //if( ! tcp_send( session->sock_obj, stanza2 ) ) {
if( socket_send( session->sock_id, stanza2 ) ) {
osrfLogWarning(OSRF_LOG_MARK, "error sending");
return 0;
@@ -268,7 +241,6 @@
/* send the first stanze */
session->state_machine->connecting = CONNECTING_1;
- //if( ! tcp_send( session->sock_obj, stanza1 ) ) {
if( socket_send( session->sock_id, stanza1 ) ) {
osrfLogWarning(OSRF_LOG_MARK, "error sending");
return 0;
@@ -276,7 +248,6 @@
/* wait for reply */
- //tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
socket_wait( session->sock_mgr, connect_timeout, session->sock_id ); /* make the timeout smarter XXX */
if( auth_type == AUTH_PLAIN ) {
@@ -291,7 +262,6 @@
/* server acknowledges our existence, now see if we can login */
if( session->state_machine->connecting == CONNECTING_2 ) {
- //if( ! tcp_send( session->sock_obj, stanza2 ) ) {
if( socket_send( session->sock_id, stanza2 ) ) {
osrfLogWarning(OSRF_LOG_MARK, "error sending");
return 0;
@@ -316,7 +286,6 @@
/* server acknowledges our existence, now see if we can login */
if( session->state_machine->connecting == CONNECTING_2 ) {
- //if( ! tcp_send( session->sock_obj, stanza2 ) ) {
if( socket_send( session->sock_id, stanza2 ) ) {
osrfLogWarning(OSRF_LOG_MARK, "error sending");
return 0;
@@ -329,7 +298,6 @@
/* wait for reply */
- //tcp_wait( session->sock_obj, connect_timeout );
socket_wait( session->sock_mgr, connect_timeout, session->sock_id );
if( session->state_machine->connected ) {
@@ -341,10 +309,10 @@
}
// ---------------------------------------------------------------------------------
-// TCP data callback. Shove the data into the push parser.
+// TCP data callback. Takes data from the socket handler and pushes it directly
+// into the push parser
// ---------------------------------------------------------------------------------
-//void grab_incoming( void * session, char* data ) {
-void grab_incoming(void* blob, socket_manager* mgr, int sockid, char* data, int parent) {
+static void grab_incoming(void* blob, socket_manager* mgr, int sockid, char* data, int parent) {
transport_session* ses = (transport_session*) blob;
if( ! ses ) { return; }
xmlParseChunk(ses->parser_ctxt, data, strlen(data), 0);
@@ -573,7 +541,7 @@
}
}
-int reset_session_buffers( transport_session* ses ) {
+static int reset_session_buffers( transport_session* ses ) {
buffer_reset( ses->body_buffer );
buffer_reset( ses->subject_buffer );
buffer_reset( ses->thread_buffer );
@@ -597,11 +565,8 @@
void characterHandler(
void *session, const xmlChar *ch, int len) {
- char data[len+1];
- strncpy( data, (const char*) ch, len );
- data[len] = 0;
+ const char* p = (const char*) ch;
- //printf( "Handling characters: %s\n", data );
transport_session* ses = (transport_session*) session;
if( ! ses ) { return; }
@@ -609,21 +574,21 @@
if( ses->state_machine->in_message ) {
if( ses->state_machine->in_message_body ) {
- buffer_add( ses->body_buffer, data );
+ buffer_add_n( ses->body_buffer, p, len );
}
if( ses->state_machine->in_subject ) {
- buffer_add( ses->subject_buffer, data );
+ buffer_add_n( ses->subject_buffer, p, len );
}
if( ses->state_machine->in_thread ) {
- buffer_add( ses->thread_buffer, data );
+ buffer_add_n( ses->thread_buffer, p, len );
}
}
/* set the presence status */
if( ses->state_machine->in_presence && ses->state_machine->in_status ) {
- buffer_add( ses->status_buffer, data );
+ buffer_add_n( ses->status_buffer, p, len );
}
if( ses->state_machine->in_error ) {
@@ -657,10 +622,8 @@
int session_disconnect( transport_session* session ) {
if( session == NULL ) { return 0; }
- //tcp_send( session->sock_obj, "</stream:stream>");
socket_send(session->sock_id, "</stream:stream>");
socket_disconnect(session->sock_mgr, session->sock_id);
return 0;
- //return tcp_disconnect( session->sock_obj );
}
More information about the opensrf-commits
mailing list