[Opensrf-commits] SPAM: r1130 - in trunk: include/opensrf src/c-apps src/libopensrf src/router

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Nov 18 22:36:28 EST 2007


Author: miker
Date: 2007-11-18 22:19:09 -0500 (Sun, 18 Nov 2007)
New Revision: 1130

Modified:
   trunk/include/opensrf/osrf_app_session.h
   trunk/include/opensrf/osrf_application.h
   trunk/include/opensrf/osrf_cache.h
   trunk/include/opensrf/transport_client.h
   trunk/include/opensrf/transport_session.h
   trunk/include/opensrf/utils.h
   trunk/src/c-apps/osrf_dbmath.c
   trunk/src/c-apps/osrf_math.c
   trunk/src/c-apps/osrf_version.c
   trunk/src/libopensrf/osrf_app_session.c
   trunk/src/libopensrf/osrf_application.c
   trunk/src/libopensrf/osrf_cache.c
   trunk/src/libopensrf/osrf_json_tools.c
   trunk/src/libopensrf/osrf_json_xml.c
   trunk/src/libopensrf/osrf_system.c
   trunk/src/libopensrf/transport_client.c
   trunk/src/libopensrf/transport_session.c
   trunk/src/libopensrf/utils.c
   trunk/src/router/osrf_router.c
   trunk/src/router/osrf_router.h
Log:
uber-patch from Scott McKellar cleans up large amounts of const-correctness issues and static-ifies several areas of unused header-based code; several cleanups to use simpler APIs such as buffer_release

Modified: trunk/include/opensrf/osrf_app_session.h
===================================================================
--- trunk/include/opensrf/osrf_app_session.h	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/include/opensrf/osrf_app_session.h	2007-11-19 03:19:09 UTC (rev 1130)
@@ -93,46 +93,46 @@
 // -------------------------------------------------------------------------- 
 
 /** Allocates a initializes a new app_session */
-osrf_app_session* osrfAppSessionClientInit( char* remote_service );
-osrf_app_session* osrf_app_client_session_init( char* remote_service );
+osrf_app_session* osrfAppSessionClientInit( const char* remote_service );
+osrf_app_session* osrf_app_client_session_init( const char* remote_service );
 
 /** Allocates and initializes a new server session.  The global session cache
   * is checked to see if this session already exists, if so, it's returned 
   */
 osrf_app_session* osrf_app_server_session_init( 
-		char* session_id, char* our_app, char* remote_id );
+		const char* session_id, const char* our_app, const char* remote_id );
 
 /** sets the default locale for a session **/
 char* osrf_app_session_set_locale( osrf_app_session*, const char* );
 
 /** returns a session from the global session hash */
-osrf_app_session* osrf_app_session_find_session( char* session_id );
+osrf_app_session* osrf_app_session_find_session( const char* session_id );
 
 /** Builds a new app_request object with the given payload andn returns
   * the id of the request.  This id is then used to perform work on the
   * requeset.
   */
 int osrfAppSessionMakeRequest(
-		osrf_app_session* session, jsonObject* params, 
-		char* method_name, int protocol, string_array* param_strings);
+		osrf_app_session* session, const jsonObject* params, 
+		const char* method_name, int protocol, string_array* param_strings);
 
 int osrf_app_session_make_req( 
-		osrf_app_session* session, jsonObject* params, 
-		char* method_name, int protocol, string_array* param_strings);
+		osrf_app_session* session, const jsonObject* params, 
+		const char* method_name, int protocol, string_array* param_strings);
 
 int osrfAppSessionMakeLocaleRequest(
-		osrf_app_session* session, jsonObject* params, 
-		char* method_name, int protocol, string_array* param_strings, char* locale);
+		osrf_app_session* session, const jsonObject* params, const char* method_name,
+		int protocol, string_array* param_strings, char* locale);
 
 int osrf_app_session_make_locale_req( 
-		osrf_app_session* session, jsonObject* params, 
-		char* method_name, int protocol, string_array* param_strings, char* locale);
+		osrf_app_session* session, const jsonObject* params, const char* method_name,
+		int protocol, string_array* param_strings, char* locale);
 
 /** Sets the given request to complete state */
 void osrf_app_session_set_complete( osrf_app_session* session, int request_id );
 
 /** Returns true if the given request is complete */
-int osrf_app_session_request_complete( osrf_app_session* session, int request_id );
+int osrf_app_session_request_complete( const osrf_app_session* session, int request_id );
 
 /** Does a recv call on the given request */
 osrf_message* osrfAppSessionRequestRecv(
@@ -150,7 +150,7 @@
 void osrf_app_session_reset_remote( osrf_app_session* );
 
 /** Sets the remote target to 'remote_id' */
-void osrf_app_session_set_remote( osrf_app_session* session, char* remote_id );
+void osrf_app_session_set_remote( osrf_app_session* session, const char* remote_id );
 
 /** pushes the given message into the result list of the app_request
   * whose request_id matches the messages thread_trace 
@@ -235,8 +235,9 @@
 
 int osrfAppSessionSendBatch( osrf_app_session*, osrf_message* msgs[], int size );
 
-int osrfAppRequestRespond( osrfAppSession* ses, int requestId, jsonObject* data ); 
-int osrfAppRequestRespondComplete( osrfAppSession* ses, int requestId, jsonObject* data ); 
+int osrfAppRequestRespond( osrfAppSession* ses, int requestId, const jsonObject* data ); 
+int osrfAppRequestRespondComplete(
+		osrfAppSession* ses, int requestId, const jsonObject* data ); 
 
 int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message );
 

Modified: trunk/include/opensrf/osrf_application.h
===================================================================
--- trunk/include/opensrf/osrf_application.h	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/include/opensrf/osrf_application.h	2007-11-19 03:19:09 UTC (rev 1130)
@@ -120,7 +120,7 @@
   @param soFile The library (.so) file that implements this application
   @return 0 on success, -1 on error
   */
-int osrfAppRegisterApplication( char* appName, char* soFile );
+int osrfAppRegisterApplication( const char* appName, const char* soFile );
 
 /**
   Register a method
@@ -134,22 +134,22 @@
   @param streaming True if this is a streaming method that requires an atomic version
   @return 0 on success, -1 on error
   */
-int osrfAppRegisterMethod( char* appName, char* methodName, 
-		char* symbolName, char* notes, int argc, int options );
+int osrfAppRegisterMethod( const char* appName, const char* methodName, 
+		const char* symbolName, const char* notes, int argc, int options );
 
 
-int osrfAppRegisterExtendedMethod( char* appName, char* methodName, 
-		char* symbolName, char* notes, int argc, int options, void* );
+int osrfAppRegisterExtendedMethod( const char* appName, const char* methodName, 
+		const char* symbolName, const char* notes, int argc, int options, void* );
 
-osrfMethod* _osrfAppBuildMethod( char* methodName, 
-		char* symbolName, char* notes, int argc, int options, void* );
+osrfMethod* _osrfAppBuildMethod( const char* methodName, const char* symbolName,
+		const char* notes, int argc, int options, void* );
 
 /**
   Finds the given app in the list of apps
   @param name The name of the application
   @return The application pointer or NULL if there is no such application
   */
-osrfApplication* _osrfAppFindApplication( char* name );
+osrfApplication* _osrfAppFindApplication( const char* name );
 
 /**
   Finds the given method for the given app
@@ -158,7 +158,7 @@
   @return A method pointer or NULL if no such method 
   exists for the given application
   */
-osrfMethod* _osrfAppFindMethod( char* appName, char* methodName );
+osrfMethod* _osrfAppFindMethod( const char* appName, const char* methodName );
 
 /**
   Finds the given method for the given app
@@ -167,7 +167,7 @@
   @return A method pointer or NULL if no such method 
   exists for the given application
   */
-osrfMethod* __osrfAppFindMethod( osrfApplication* app, char* methodName );
+osrfMethod* __osrfAppFindMethod( osrfApplication* app, const char* methodName );
 
 
 /**
@@ -178,7 +178,7 @@
   @params reqId The request id for this request
   @param params The method parameters
   */
-int osrfAppRunMethod( char* appName, char* methodName, 
+int osrfAppRunMethod( const char* appName, const char* methodName, 
 		osrfAppSession* ses, int reqId, jsonObject* params );
 
 
@@ -197,7 +197,7 @@
 /**
   Registers all of the system methods for this app so that they may be
   treated the same as other methods */
-int __osrfAppRegisterSysMethods( char* app );
+int __osrfAppRegisterSysMethods( const char* app );
 
 
 
@@ -208,14 +208,14 @@
   @param msg The debug message to send to the client
   @return 0 on successfully sending of the message, -1 otherwise
   */
-int osrfAppRequestRespondException( osrfAppSession* ses, int request, char* msg, ... );
+int osrfAppRequestRespondException( osrfAppSession* ses, int request, const char* msg, ... );
 
 int __osrfAppPostProcess( osrfMethodContext* context, int retcode );
 
 
-int osrfAppRespond( osrfMethodContext* context, jsonObject* data );
-int _osrfAppRespond( osrfMethodContext* context, jsonObject* data, int complete );
-int osrfAppRespondComplete( osrfMethodContext* context, jsonObject* data );
+int osrfAppRespond( osrfMethodContext* context, const jsonObject* data );
+int _osrfAppRespond( osrfMethodContext* context, const jsonObject* data, int complete );
+int osrfAppRespondComplete( osrfMethodContext* context, const jsonObject* data );
 
 /* OSRF_METHOD_ATOMIC and/or OSRF_METHOD_CACHABLE and/or 0 for no special options */
 //int osrfAppProcessMethodOptions( char* method );
@@ -227,8 +227,8 @@
 
 /**
  * Tells the backend process to run its child init function */
-int osrfAppRunChildInit(char* appname);
-void osrfAppSetOnExit(osrfApplication* app, char* appName);
+int osrfAppRunChildInit(const char* appname);
+void osrfAppSetOnExit(osrfApplication* app, const char* appName);
 void osrfAppRunExitCode();
 
 

Modified: trunk/include/opensrf/osrf_cache.h
===================================================================
--- trunk/include/opensrf/osrf_cache.h	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/include/opensrf/osrf_cache.h	2007-11-19 03:19:09 UTC (rev 1130)
@@ -30,7 +30,7 @@
   @param maxCacheSeconds The maximum amount of time an object / string may
 	be cached.  Negative number means there is no limit
   */
-int osrfCacheInit( char* serverStrings[], int size, time_t maxCacheSeconds );
+int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds );
 
 
 /**
@@ -58,25 +58,25 @@
   @param key The cache key
   @return The object (which must be freed) if it exists, otherwise returns NULL
   */
-jsonObject* osrfCacheGetObject( char* key, ... );
+jsonObject* osrfCacheGetObject( const char* key, ... );
 
 /**
   Grabs a string from the cache.
   @param key The cache key
   @return The string (which must be freed) if it exists, otherwise returns NULL
   */
-char* osrfCacheGetString( char* key, ... );
+char* osrfCacheGetString( const char* key, ... );
 
 /**
   Removes the item with the given key from the cache.
   @return 0 on success, -1 on error.
   */
-int osrfCacheRemove( char* key, ... );
+int osrfCacheRemove( const char* key, ... );
 
 /**
  * Sets the expire time to 'seconds' for the given key
  */
-int osrfCacheSetExpire( time_t seconds, char* key, ... );
+int osrfCacheSetExpire( time_t seconds, const char* key, ... );
 
 
 

Modified: trunk/include/opensrf/transport_client.h
===================================================================
--- trunk/include/opensrf/transport_client.h	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/include/opensrf/transport_client.h	2007-11-19 03:19:09 UTC (rev 1130)
@@ -50,7 +50,7 @@
 // success, 0 otherwise.
 // ---------------------------------------------------------------------------
 int client_connect( transport_client* client, 
-		char* username, char* password, char* resource, 
+		const char* username, const char* password, const char* resource,
 		int connect_timeout, enum TRANSPORT_AUTH_TYPE auth_type );
 
 
@@ -71,7 +71,7 @@
 // ---------------------------------------------------------------------------
 // Returns 1 if this client is currently connected to the server, 0 otherwise
 // ---------------------------------------------------------------------------
-int client_connected( transport_client* client );
+int client_connected( const transport_client* client );
 
 // ---------------------------------------------------------------------------
 // This is the message handler required by transport_session.  This handler

Modified: trunk/include/opensrf/transport_session.h
===================================================================
--- trunk/include/opensrf/transport_session.h	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/include/opensrf/transport_session.h	2007-11-19 03:19:09 UTC (rev 1130)
@@ -190,14 +190,6 @@
 	const char* unix_path, void* user_data, int component );
 
 // ------------------------------------------------------------------
-// Returns the value of the given XML attribute
-// The xmlChar** construct is commonly returned from SAX event
-// handlers.  Pass that in with the name of the attribute you want
-// to retrieve.
-// ------------------------------------------------------------------
-char* get_xml_attr( const xmlChar** atts, char* attr_name );
-
-// ------------------------------------------------------------------
 // Waits  at most 'timeout' seconds  for data to arrive from the 
 // TCP handler. A timeout of -1 means to wait indefinitely.
 // ------------------------------------------------------------------

Modified: trunk/include/opensrf/utils.h
===================================================================
--- trunk/include/opensrf/utils.h	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/include/opensrf/utils.h	2007-11-19 03:19:09 UTC (rev 1130)
@@ -165,10 +165,10 @@
 	truncation may occurr.
  */
 int init_proc_title( int argc, char* argv[] );
-int set_proc_title( char* format, ... );
+int set_proc_title( const char* format, ... );
 
 
-int daemonize();
+int daemonize( void );
 
 void* safe_malloc(int size);
 void* safe_calloc(int size);
@@ -188,10 +188,10 @@
 // XXX This isn't defined in utils.c!! removing for now...
 //int buffer_addchar(growing_buffer* gb, char c);
 
-int buffer_add(growing_buffer* gb, char* c);
+int buffer_add(growing_buffer* gb, const char* c);
 int buffer_fadd(growing_buffer* gb, const char* format, ... );
 int buffer_reset( growing_buffer* gb);
-char* buffer_data( growing_buffer* gb);
+char* buffer_data( const growing_buffer* gb);
 char* buffer_release( growing_buffer* gb );
 int buffer_free( growing_buffer* gb );
 int buffer_add_char(growing_buffer* gb, char c);
@@ -226,11 +226,11 @@
 
 
 // Utility method
-double get_timestamp_millis();
+double get_timestamp_millis( void );
 
 
 /* returns true if the whole string is a number */
-int stringisnum(char* s);
+int stringisnum(const char* s);
 
 /* reads a file and returns the string version of the file
 	user is responsible for freeing the returned char*
@@ -243,7 +243,7 @@
   Calculates the md5 of the text provided.
   The returned string must be freed by the caller.
   */
-char* md5sum( char* text, ... );
+char* md5sum( const char* text, ... );
 
 
 /**

Modified: trunk/src/c-apps/osrf_dbmath.c
===================================================================
--- trunk/src/c-apps/osrf_dbmath.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/c-apps/osrf_dbmath.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -47,8 +47,8 @@
 
 	OSRF_METHOD_VERIFY_CONTEXT(ctx);	
 
-	jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
-	jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
+	const jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
+	const jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
 
 	if( x && y ) {
 

Modified: trunk/src/c-apps/osrf_math.c
===================================================================
--- trunk/src/c-apps/osrf_math.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/c-apps/osrf_math.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -58,8 +58,8 @@
 	OSRF_METHOD_VERIFY_CONTEXT(ctx); /* see osrf_application.h */
 
 	/* collect the request params */
-	jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
-	jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
+	const jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
+	const jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
 
 	if( x && y ) {
 

Modified: trunk/src/c-apps/osrf_version.c
===================================================================
--- trunk/src/c-apps/osrf_version.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/c-apps/osrf_version.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -49,10 +49,10 @@
 		return 0;
 	}
 
-	jsonObject* serv = jsonObjectGetIndex(ctx->params, 0);
-	jsonObject* meth = jsonObjectGetIndex(ctx->params, 1);
-	char* service = jsonObjectGetString(serv);
-	char* methd = jsonObjectGetString(meth);
+	const jsonObject* serv = jsonObjectGetIndex(ctx->params, 0);
+	const jsonObject* meth = jsonObjectGetIndex(ctx->params, 1);
+	const char* service = jsonObjectGetString(serv);
+	const char* methd = jsonObjectGetString(meth);
 
 	if( service && methd ) {
 		/* shove the additional params into an array */

Modified: trunk/src/libopensrf/osrf_app_session.c
===================================================================
--- trunk/src/libopensrf/osrf_app_session.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/osrf_app_session.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -21,6 +21,7 @@
 	req->complete		= 0;
 	req->payload		= msg;
 	req->result			= NULL;
+	req->reset_timeout  = 0;
 
 	return req;
 
@@ -182,7 +183,7 @@
 }
 
 /** returns a session from the global session hash */
-osrf_app_session* osrf_app_session_find_session( char* session_id ) {
+osrf_app_session* osrf_app_session_find_session( const char* session_id ) {
 	if(session_id) return osrfHashGet(osrfAppSessionCache, session_id);
 	return NULL;
 }
@@ -196,13 +197,13 @@
 	osrfHashSet( osrfAppSessionCache, session, session->session_id );
 }
 
-/** Allocates a initializes a new app_session */
+/** Allocates and initializes a new app_session */
 
-osrf_app_session* osrfAppSessionClientInit( char* remote_service ) {
+osrf_app_session* osrfAppSessionClientInit( const char* remote_service ) {
 	return osrf_app_client_session_init( remote_service );
 }
 
-osrf_app_session* osrf_app_client_session_init( char* remote_service ) {
+osrf_app_session* osrf_app_client_session_init( const char* remote_service ) {
 
 	if (!remote_service) {
 		osrfLogWarning( OSRF_LOG_MARK, "No remote service specified in osrf_app_client_session_init");
@@ -281,12 +282,16 @@
 	session->state = OSRF_SESSION_DISCONNECTED;
 	session->type = OSRF_SESSION_CLIENT;
 	//session->next = NULL;
+
+	session->userData = NULL;
+	session->userDataFree = NULL;
+	
 	_osrf_app_session_push_session( session );
 	return session;
 }
 
 osrf_app_session* osrf_app_server_session_init( 
-		char* session_id, char* our_app, char* remote_id ) {
+		const char* session_id, const char* our_app, const char* remote_id ) {
 
 	osrfLogDebug( OSRF_LOG_MARK, "Initing server session with session id %s, service %s,"
 			" and remote_id %s", session_id, our_app, remote_id );
@@ -324,6 +329,9 @@
 	session->state = OSRF_SESSION_DISCONNECTED;
 	session->type = OSRF_SESSION_SERVER;
 
+	session->userData = NULL;
+	session->userDataFree = NULL;
+	
 	_osrf_app_session_push_session( session );
 	return session;
 
@@ -351,32 +359,32 @@
 }
 
 int osrfAppSessionMakeRequest(
-		osrf_app_session* session, jsonObject* params, 
-		char* method_name, int protocol, string_array* param_strings ) {
+		osrf_app_session* session, const jsonObject* params, 
+		const char* method_name, int protocol, string_array* param_strings ) {
 
 	return osrf_app_session_make_locale_req( session, params, 
 			method_name, protocol, param_strings, NULL );
 }
 
 int osrfAppSessionMakeLocaleRequest(
-		osrf_app_session* session, jsonObject* params, 
-		char* method_name, int protocol, string_array* param_strings, char* locale ) {
+		osrf_app_session* session, const jsonObject* params, const char* method_name,
+		int protocol, string_array* param_strings, char* locale ) {
 
 	return osrf_app_session_make_locale_req( session, params, 
 			method_name, protocol, param_strings, locale );
 }
 
 int osrf_app_session_make_req( 
-		osrf_app_session* session, jsonObject* params, 
-		char* method_name, int protocol, string_array* param_strings) {
+		osrf_app_session* session, const jsonObject* params, 
+		const char* method_name, int protocol, string_array* param_strings) {
 
 	return osrf_app_session_make_locale_req(session, params,
 			method_name, protocol, param_strings, NULL);
 }
 
 int osrf_app_session_make_locale_req( 
-		osrf_app_session* session, jsonObject* params, 
-		char* method_name, int protocol, string_array* param_strings, char* locale ) {
+		osrf_app_session* session, const jsonObject* params, const char* method_name,
+		int protocol, string_array* param_strings, char* locale ) {
 	if(session == NULL) return -1;
 
 	osrfLogMkXid();
@@ -424,7 +432,7 @@
 	if(req) req->complete = 1;
 }
 
-int osrf_app_session_request_complete( osrf_app_session* session, int request_id ) {
+int osrf_app_session_request_complete( const osrf_app_session* session, int request_id ) {
 	if(session == NULL)
 		return 0;
 	osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
@@ -446,7 +454,7 @@
 	session->remote_id = strdup(session->orig_remote_id);
 }
 
-void osrf_app_session_set_remote( osrf_app_session* session, char* remote_id ) {
+void osrf_app_session_set_remote( osrf_app_session* session, const char* remote_id ) {
 	if(session == NULL)
 		return;
 	if( session->remote_id )
@@ -619,10 +627,8 @@
   */
 int osrf_app_session_queue_wait( osrf_app_session* session, int timeout, int* recvd ){
 	if(session == NULL) return 0;
-	int ret_val = 0;
 	osrfLogDebug(OSRF_LOG_MARK,  "AppSession in queue_wait with timeout %d", timeout );
-	ret_val = osrf_stack_entry_point(session->transport_handle, timeout, recvd);
-	return ret_val;
+	return osrf_stack_entry_point(session->transport_handle, timeout, recvd);
 }
 
 /** Disconnects (if client) and removes the given session from the global session cache 
@@ -663,7 +669,7 @@
 
 
 
-int osrfAppRequestRespond( osrfAppSession* ses, int requestId, jsonObject* data ) {
+int osrfAppRequestRespond( osrfAppSession* ses, int requestId, const jsonObject* data ) {
 	if(!ses || ! data ) return -1;
 
 	osrf_message* msg = osrf_message_init( RESULT, requestId, 1 );
@@ -681,7 +687,7 @@
 
 
 int osrfAppRequestRespondComplete( 
-		osrfAppSession* ses, int requestId, jsonObject* data ) {
+		osrfAppSession* ses, int requestId, const jsonObject* data ) {
 
 	osrf_message* payload = osrf_message_init( RESULT, requestId, 1 );
 	osrf_message_set_status_info( payload, NULL, "OK", OSRF_STATUS_OK );

Modified: trunk/src/libopensrf/osrf_application.c
===================================================================
--- trunk/src/libopensrf/osrf_application.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/osrf_application.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -1,12 +1,12 @@
 #include <opensrf/osrf_application.h>
 
-osrfHash* __osrfAppHash = NULL;
+static osrfHash* _osrfAppHash = NULL;
 
-int osrfAppRegisterApplication( char* appName, char* soFile ) {
+int osrfAppRegisterApplication( const char* appName, const char* soFile ) {
 	if(!appName || ! soFile) return -1;
 	char* error;
 
-	if(!__osrfAppHash) __osrfAppHash = osrfNewHash();
+	if(!_osrfAppHash) _osrfAppHash = osrfNewHash();
 
 	osrfLogInfo( OSRF_LOG_MARK, "Registering application %s with file %s", appName, soFile );
 
@@ -22,7 +22,7 @@
 	}
 
 	app->methods = osrfNewHash();
-	osrfHashSet( __osrfAppHash, app, appName );
+	osrfHashSet( _osrfAppHash, app, appName );
 
 	/* see if we can run the initialize method */
 	int (*init) (void);
@@ -57,7 +57,7 @@
 }
 
 
-void osrfAppSetOnExit(osrfApplication* app, char* appName) {
+void osrfAppSetOnExit(osrfApplication* app, const char* appName) {
 	if(!(app && appName)) return;
 
 	/* see if we can run the initialize method */
@@ -75,7 +75,7 @@
 }
 
 
-int osrfAppRunChildInit(char* appname) {
+int osrfAppRunChildInit(const char* appname) {
 	osrfApplication* app = _osrfAppFindApplication(appname);
 	if(!app) return -1;
 
@@ -101,7 +101,7 @@
 
 
 void osrfAppRunExitCode() { 
-	osrfHashIterator* itr = osrfNewHashIterator(__osrfAppHash);
+	osrfHashIterator* itr = osrfNewHashIterator(_osrfAppHash);
 	osrfApplication* app;
 	while( (app = osrfHashIteratorNext(itr)) ) {
 		if( app->onExit ) {
@@ -112,8 +112,8 @@
 }
 
 
-int osrfAppRegisterMethod( char* appName, char* methodName, 
-		char* symbolName, char* notes, int argc, int options ) {
+int osrfAppRegisterMethod( const char* appName, const char* methodName, 
+		const char* symbolName, const char* notes, int argc, int options ) {
 
 	return osrfAppRegisterExtendedMethod(
 			appName,
@@ -127,8 +127,8 @@
 
 }
 
-int osrfAppRegisterExtendedMethod( char* appName, char* methodName, 
-		char* symbolName, char* notes, int argc, int options, void * user_data ) {
+int osrfAppRegisterExtendedMethod( const char* appName, const char* methodName, 
+		const char* symbolName, const char* notes, int argc, int options, void * user_data ) {
 
 	if( !appName || ! methodName  ) return -1;
 
@@ -160,8 +160,8 @@
 
 
 
-osrfMethod* _osrfAppBuildMethod( char* methodName, 
-	char* symbolName, char* notes, int argc, int options, void* user_data ) {
+osrfMethod* _osrfAppBuildMethod( const char* methodName, const char* symbolName,
+		const char* notes, int argc, int options, void* user_data ) {
 
 	osrfMethod* method					= safe_malloc(sizeof(osrfMethod));
 
@@ -185,7 +185,7 @@
 }
 
 
-int __osrfAppRegisterSysMethods( char* app ) {
+int __osrfAppRegisterSysMethods( const char* app ) {
 
 	osrfAppRegisterMethod( 
 			app, OSRF_SYSMETHOD_INTROSPECT, NULL, 
@@ -206,23 +206,23 @@
 	return 0;
 }
 
-osrfApplication* _osrfAppFindApplication( char* name ) {
+osrfApplication* _osrfAppFindApplication( const char* name ) {
 	if(!name) return NULL;
-	return (osrfApplication*) osrfHashGet(__osrfAppHash, name);
+	return (osrfApplication*) osrfHashGet(_osrfAppHash, name);
 }
 
-osrfMethod* __osrfAppFindMethod( osrfApplication* app, char* methodName ) {
+osrfMethod* __osrfAppFindMethod( osrfApplication* app, const char* methodName ) {
 	if(!app || ! methodName) return NULL;
 	return (osrfMethod*) osrfHashGet( app->methods, methodName );
 }
 
-osrfMethod* _osrfAppFindMethod( char* appName, char* methodName ) {
+osrfMethod* _osrfAppFindMethod( const char* appName, const char* methodName ) {
 	if(!appName || ! methodName) return NULL;
 	return __osrfAppFindMethod( _osrfAppFindApplication(appName), methodName );
 }
 
 
-int osrfAppRunMethod( char* appName, char* methodName, 
+int osrfAppRunMethod( const char* appName, const char* methodName, 
 		osrfAppSession* ses, int reqId, jsonObject* params ) {
 
 	if( !(appName && methodName && ses) ) return -1;
@@ -285,15 +285,15 @@
 }
 
 
-int osrfAppRespond( osrfMethodContext* ctx, jsonObject* data ) {
+int osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data ) {
 	return _osrfAppRespond( ctx, data, 0 );
 }
 
-int osrfAppRespondComplete( osrfMethodContext* context, jsonObject* data ) {
+int osrfAppRespondComplete( osrfMethodContext* context, const jsonObject* data ) {
 	return _osrfAppRespond( context, data, 1 );
 }
 
-int _osrfAppRespond( osrfMethodContext* ctx, jsonObject* data, int complete ) {
+int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int complete ) {
 	if(!(ctx && ctx->method)) return -1;
 
 	if( ctx->method->options & OSRF_METHOD_ATOMIC ) {
@@ -346,7 +346,7 @@
 	return 0;
 }
 
-int osrfAppRequestRespondException( osrfAppSession* ses, int request, char* msg, ... ) {
+int osrfAppRequestRespondException( osrfAppSession* ses, int request, const char* msg, ... ) {
 	if(!ses) return -1;
 	if(!msg) msg = "";
 	VA_LIST_TO_STRING(msg);
@@ -356,11 +356,11 @@
 }
 
 
-static void __osrfAppSetIntrospectMethod( osrfMethodContext* ctx, osrfMethod* method, jsonObject* resp ) {
+static void _osrfAppSetIntrospectMethod( osrfMethodContext* ctx, const osrfMethod* method, jsonObject* resp ) {
 	if(!(ctx && resp)) return;
 
 	jsonObjectSetKey(resp, "api_name",	jsonNewObject(method->name));
-	jsonObjectSetKey(resp, "method",		jsonNewObject(method->symbol));
+	jsonObjectSetKey(resp, "method",	jsonNewObject(method->symbol));
 	jsonObjectSetKey(resp, "service",	jsonNewObject(ctx->session->remote_service));
 	jsonObjectSetKey(resp, "notes",		jsonNewObject(method->notes));
 	jsonObjectSetKey(resp, "argc",		jsonNewNumberObject(method->argc));
@@ -425,7 +425,7 @@
 			if( (len = strlen(methodSubstring)) <= strlen(method->name) ) {
 				if( !strncmp( method->name, methodSubstring, len) ) {
 					resp = jsonNewObject(NULL);
-					__osrfAppSetIntrospectMethod( ctx, method, resp );
+					_osrfAppSetIntrospectMethod( ctx, method, resp );
 					osrfAppRespond(ctx, resp);
 					jsonObjectFree(resp);
 				}
@@ -449,7 +449,7 @@
 		osrfMethod* method;
 		while( (method = osrfHashIteratorNext(itr)) ) {
 			resp = jsonNewObject(NULL);
-			__osrfAppSetIntrospectMethod( ctx, method, resp );
+			_osrfAppSetIntrospectMethod( ctx, method, resp );
 			osrfAppRespond(ctx, resp);
 			jsonObjectFree(resp);
 		}
@@ -464,7 +464,7 @@
 	OSRF_METHOD_VERIFY_CONTEXT(ctx);
 	int i;
 	for( i = 0; i < ctx->params->size; i++ ) {
-		jsonObject* str = jsonObjectGetIndex(ctx->params,i);
+		const jsonObject* str = jsonObjectGetIndex(ctx->params,i);
 		osrfAppRespond(ctx, str);
 	}
 	return 1;

Modified: trunk/src/libopensrf/osrf_cache.c
===================================================================
--- trunk/src/libopensrf/osrf_cache.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/osrf_cache.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -15,18 +15,18 @@
 
 #include <opensrf/osrf_cache.h>
 
-struct memcache* __osrfCache = NULL;
-time_t __osrfCacheMaxSeconds = -1;
+static struct memcache* _osrfCache = NULL;
+static time_t _osrfCacheMaxSeconds = -1;
 
-int osrfCacheInit( char* serverStrings[], int size, time_t maxCacheSeconds ) {
+int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds ) {
 	if( !(serverStrings && size > 0) ) return -1;
 
 	int i;
-	__osrfCache = mc_new();
-	__osrfCacheMaxSeconds = maxCacheSeconds;
+	_osrfCache = mc_new();
+	_osrfCacheMaxSeconds = maxCacheSeconds;
 
 	for( i = 0; i < size && serverStrings[i]; i++ ) 
-		mc_server_add4( __osrfCache, serverStrings[i] );
+		mc_server_add4( _osrfCache, serverStrings[i] );
 
 	return 0;
 }
@@ -35,26 +35,26 @@
 	if( !(key && obj) ) return -1;
 	char* s = jsonObjectToJSON( obj );
 	osrfLogInternal( OSRF_LOG_MARK, "osrfCachePut(): Putting object: %s", s);
-	if( seconds < 0 ) seconds = __osrfCacheMaxSeconds;
+	if( seconds < 0 ) seconds = _osrfCacheMaxSeconds;
 
-	mc_set(__osrfCache, key, strlen(key), s, strlen(s), seconds, 0);
+	mc_set(_osrfCache, key, strlen(key), s, strlen(s), seconds, 0);
 	free(s);
 	return 0;
 }
 
 int osrfCachePutString( char* key, const char* value, time_t seconds ) {
 	if( !(key && value) ) return -1;
-	if( seconds < 0 ) seconds = __osrfCacheMaxSeconds;
+	if( seconds < 0 ) seconds = _osrfCacheMaxSeconds;
 	osrfLogInternal( OSRF_LOG_MARK, "osrfCachePutString(): Putting string: %s", value);
-	mc_set(__osrfCache, key, strlen(key), value, strlen(value), seconds, 0);
+	mc_set(_osrfCache, key, strlen(key), value, strlen(value), seconds, 0);
 	return 0;
 }
 
-jsonObject* osrfCacheGetObject( char* key, ... ) {
+jsonObject* osrfCacheGetObject( const char* key, ... ) {
 	jsonObject* obj = NULL;
 	if( key ) {
 		VA_LIST_TO_STRING(key);
-		char* data = (char*) mc_aget( __osrfCache, VA_BUF, strlen(VA_BUF) );
+		char* data = (char*) mc_aget( _osrfCache, VA_BUF, strlen(VA_BUF) );
 		if( data ) {
 			osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetObject(): Returning object: %s", data);
 			obj = jsonParseString( data );
@@ -65,10 +65,10 @@
 	return NULL;
 }
 
-char* osrfCacheGetString( char* key, ... ) {
+char* osrfCacheGetString( const char* key, ... ) {
 	if( key ) {
 		VA_LIST_TO_STRING(key);
-		char* data = (char*) mc_aget(__osrfCache, VA_BUF, strlen(VA_BUF) );
+		char* data = (char*) mc_aget(_osrfCache, VA_BUF, strlen(VA_BUF) );
 		osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetObject(): Returning object: %s", data);
 		if(!data) osrfLogWarning(OSRF_LOG_MARK, "No cache data exists with key %s", VA_BUF);
 		return data;
@@ -77,16 +77,16 @@
 }
 
 
-int osrfCacheRemove( char* key, ... ) {
+int osrfCacheRemove( const char* key, ... ) {
 	if( key ) {
 		VA_LIST_TO_STRING(key);
-		return mc_delete(__osrfCache, VA_BUF, strlen(VA_BUF), 0 );
+		return mc_delete(_osrfCache, VA_BUF, strlen(VA_BUF), 0 );
 	}
 	return -1;
 }
 
 
-int osrfCacheSetExpire( time_t seconds, char* key, ... ) {
+int osrfCacheSetExpire( time_t seconds, const char* key, ... ) {
 	if( key ) {
 		VA_LIST_TO_STRING(key);
 		jsonObject* o = osrfCacheGetObject( VA_BUF );
@@ -97,8 +97,8 @@
 }
 
 void osrfCacheCleanup() {
-    if(__osrfCache) 
-        mc_free(__osrfCache);
+    if(_osrfCache)
+        mc_free(_osrfCache);
 }
 
 

Modified: trunk/src/libopensrf/osrf_json_tools.c
===================================================================
--- trunk/src/libopensrf/osrf_json_tools.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/osrf_json_tools.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -14,16 +14,11 @@
 */
 
 #include <opensrf/osrf_json.h>
+#include <opensrf/osrf_json_utils.h>
 
-jsonObject* _jsonObjectEncodeClass( const jsonObject* obj, int ignoreClass );
+static jsonObject* _jsonObjectEncodeClass( const jsonObject* obj, int ignoreClass );
 
-
-jsonObject* jsonObjectFindPath( const jsonObject* obj, char* path, ...);
-jsonObject* _jsonObjectFindPathRecurse(const jsonObject* obj, char* root, char* path);
-jsonObject* __jsonObjectFindPathRecurse(const jsonObject* obj, char* root);
-
-
-static char* __tabs(int count) {
+static char* _tabs(int count) {
 	growing_buffer* buf = buffer_init(24);
 	int i;
 	for(i=0;i<count;i++) OSRF_BUFFER_ADD(buf, "  ");
@@ -44,25 +39,25 @@
 
 		if( c == '{' || c == '[' ) {
 
-			tab = __tabs(++depth);
+			tab = _tabs(++depth);
 			buffer_fadd( buf, "%c\n%s", c, tab);
 			free(tab);
 
 		} else if( c == '}' || c == ']' ) {
 
-			tab = __tabs(--depth);
+			tab = _tabs(--depth);
 			buffer_fadd( buf, "\n%s%c", tab, c);
 			free(tab);
 
 			if(string[i+1] != ',') {
-				tab = __tabs(depth);
+				tab = _tabs(depth);
 				buffer_fadd( buf, "%s", tab );	
 				free(tab);
 			}
 
 		} else if( c == ',' ) {
 
-			tab = __tabs(depth);
+			tab = _tabs(depth);
 			buffer_fadd(buf, ",\n%s", tab);
 			free(tab);
 
@@ -130,7 +125,7 @@
 	return _jsonObjectEncodeClass( obj, 0 );
 }
 
-jsonObject* _jsonObjectEncodeClass( const jsonObject* obj, int ignoreClass ) {
+static jsonObject* _jsonObjectEncodeClass( const jsonObject* obj, int ignoreClass ) {
 
 	//if(!obj) return NULL;
 	if(!obj) return jsonNewObject(NULL);
@@ -210,7 +205,7 @@
 
 	t = NULL;
 	do { 
-		obj = jsonObjectGetKey(obj, token);
+		obj = jsonObjectGetKeyConst(obj, token);
 	} while( (token = strtok_r(NULL, "/", &tt)) && obj);
 
 	return jsonObjectClone(obj);
@@ -269,7 +264,7 @@
 
 	/* if the current object has a node that matches, add it */
 
-	jsonObject* o = jsonObjectGetKey(obj, root);
+	const jsonObject* o = jsonObjectGetKeyConst(obj, root);
 	if(o) jsonObjectPush( arr, jsonObjectClone(o) );
 
 	jsonObject* tmp = NULL;

Modified: trunk/src/libopensrf/osrf_json_xml.c
===================================================================
--- trunk/src/libopensrf/osrf_json_xml.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/osrf_json_xml.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -13,7 +13,7 @@
 typedef struct osrfXMLGatewayParserStruct osrfXMLGatewayParser;
 
 /** returns the attribute value with the given attribute name */
-static char* getXMLAttr(const xmlChar** atts, char* attr_name) {
+static char* getXMLAttr(const xmlChar** atts, const char* attr_name) {
     int i;
     if (atts != NULL) {
         for(i = 0; (atts[i] != NULL); i++) {
@@ -228,13 +228,12 @@
 
 
 
-static char* _escape_xml (char*);
+static char* _escape_xml (const char*);
 static int _recurse_jsonObjectToXML(jsonObject*, growing_buffer*);
 
-char* jsonObjectToXML(jsonObject* obj) {
+char* jsonObjectToXML(const jsonObject* obj) {
 
 	growing_buffer * res_xml;
-	char * output;
 
 	res_xml = buffer_init(1024);
 
@@ -242,19 +241,13 @@
 		return strdup("<null/>");
 	
 	_recurse_jsonObjectToXML( obj, res_xml );
-	output = buffer_data(res_xml);
-	
-	buffer_free(res_xml);
+	return buffer_release(res_xml);
 
-	return output;
-
 }
 
-int _recurse_jsonObjectToXML(jsonObject* obj, growing_buffer* res_xml) {
+int _recurse_jsonObjectToXML(const jsonObject* obj, growing_buffer* res_xml) {
 
 	char * hint = NULL;
-	char * bool_val = NULL;
-	int i = 0;
 	
 	if (obj->classname)
 		hint = strdup(obj->classname);
@@ -268,18 +261,17 @@
 
 	} else if(obj->type == JSON_BOOL) {
 
+		const char* bool_val;
 		if (obj->value.b)
-			bool_val = strdup("true");
+			bool_val = "true";
 		else
-			bool_val = strdup("false");
+			bool_val = "false";
 
 		if (hint)
 			buffer_fadd(res_xml, "<boolean value=\"%s\" class_hint=\"%s\"/>", bool_val, hint);
 		else
 			buffer_fadd(res_xml, "<boolean value=\"%s\"/>", bool_val);
 
-		free(bool_val);
-                
 	} else if (obj->type == JSON_STRING) {
 		if (hint) {
 			char * t = _escape_xml(jsonObjectGetString(obj));
@@ -312,7 +304,7 @@
 		else
                		buffer_add(res_xml,"<array>");
 
-	       	for ( i = 0; i!= obj->size; i++ )
+	       	for ( int i = 0; i!= obj->size; i++ )
 			_recurse_jsonObjectToXML(jsonObjectGetIndex(obj,i), res_xml);
 
 		buffer_add(res_xml,"</array>");
@@ -325,7 +317,7 @@
 			buffer_add(res_xml,"<object>");
 
 		jsonIterator* itr = jsonNewIterator(obj);
-		jsonObject* tmp;
+		const jsonObject* tmp;
 		while( (tmp = jsonIteratorNext(itr)) ) {
 			buffer_fadd(res_xml,"<element key=\"%s\">",itr->key);
 			_recurse_jsonObjectToXML(tmp, res_xml);
@@ -342,8 +334,7 @@
 	return 1;
 }
 
-char* _escape_xml (char* text) {
-	char* out;
+char* _escape_xml (const char* text) {
 	growing_buffer* b = buffer_init(256);
 	int len = strlen(text);
 	int i;
@@ -357,9 +348,7 @@
 		else
 			buffer_add_char(b,text[i]);
 	}
-	out = buffer_data(b);
-	buffer_free(b);
-	return out;
+	return buffer_release(b);
 }
 
 #endif

Modified: trunk/src/libopensrf/osrf_system.c
===================================================================
--- trunk/src/libopensrf/osrf_system.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/osrf_system.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -56,7 +56,7 @@
 
 		if( cacheServers->type == JSON_ARRAY ) {
 			int i;
-			char* servers[cacheServers->size];
+			const char* servers[cacheServers->size];
 			for( i = 0; i != cacheServers->size; i++ ) {
 				servers[i] = jsonObjectGetString( jsonObjectGetIndex(cacheServers, i) );
 				osrfLogInfo( OSRF_LOG_MARK, "Adding cache server %s", servers[i]);
@@ -64,7 +64,7 @@
 			osrfCacheInit( servers, cacheServers->size, atoi(maxCache) );
 
 		} else {
-			char* servers[] = { jsonObjectGetString(cacheServers) };		
+			const char* servers[] = { jsonObjectGetString(cacheServers) };		
 			osrfLogInfo( OSRF_LOG_MARK, "Adding cache server %s", servers[0]);
 			osrfCacheInit( servers, 1, atoi(maxCache) );
 		}
@@ -116,7 +116,7 @@
 			osrfStringArrayAdd(arr, jsonObjectGetString(apps));
 
 		} else {
-			jsonObject* app;
+			const jsonObject* app;
 			while( (app = jsonObjectGetIndex(apps, i++)) ) 
 				osrfStringArrayAdd(arr, jsonObjectGetString(app));
 		}

Modified: trunk/src/libopensrf/transport_client.c
===================================================================
--- trunk/src/libopensrf/transport_client.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/transport_client.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -50,12 +50,10 @@
 	if(server == NULL) return NULL;
 
 	/* build and clear the client object */
-	size_t c_size = sizeof( transport_client);
-	transport_client* client = safe_malloc( c_size );
+	transport_client* client = safe_malloc( sizeof( transport_client) );
 
 	/* build and clear the message list */
-	size_t l_size = sizeof( transport_message_list );
-	client->m_list = safe_malloc( l_size );
+	client->m_list = safe_malloc( sizeof( transport_message_list ) );
 
 	client->m_list->next = NULL;
 	client->m_list->message = NULL;
@@ -73,7 +71,7 @@
 
 
 int client_connect( transport_client* client, 
-		char* username, char* password, char* resource, 
+		const char* username, const char* password, const char* resource, 
 		int connect_timeout, enum TRANSPORT_AUTH_TYPE  auth_type ) {
 	if(client == NULL) return 0; 
 	return session_connect( client->session, username, 
@@ -86,7 +84,7 @@
 	return session_disconnect( client->session );
 }
 
-int client_connected( transport_client* client ) {
+int client_connected( const transport_client* client ) {
 	if(client == NULL) return 0;
 	return client->session->state_machine->connected;
 }
@@ -184,9 +182,8 @@
 
 	transport_client* cli = (transport_client*) client;
 
-	size_t len = sizeof(transport_message_node);
-	transport_message_node* node = 
-		(transport_message_node*) safe_malloc(len);
+	transport_message_node* node = safe_malloc( sizeof( transport_message_node) );
+	node->next = NULL;
 	node->type = MESSAGE_LIST_ITEM;
 	node->message = msg;
 

Modified: trunk/src/libopensrf/transport_session.c
===================================================================
--- trunk/src/libopensrf/transport_session.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/transport_session.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -1,7 +1,7 @@
 #include <opensrf/transport_session.h>
 
+static char* get_xml_attr( const xmlChar** atts, const char* attr_name );
 
-
 // ---------------------------------------------------------------------------------
 // returns a built and allocated transport_session object.
 // This codes does no network activity, only memory initilization
@@ -25,8 +25,10 @@
 	session->status_buffer		= buffer_init( JABBER_STATUS_BUFSIZE );
 	session->recipient_buffer	= buffer_init( JABBER_JID_BUFSIZE );
 	session->message_error_type = buffer_init( JABBER_JID_BUFSIZE );
-	session->session_id			= buffer_init( 64 ); 
+	session->session_id			= buffer_init( 64 );
 
+	session->message_error_code = 0;
+
 	/* for OpenSRF extensions */
 	session->router_to_buffer		= buffer_init( JABBER_JID_BUFSIZE );
 	session->router_from_buffer	= buffer_init( JABBER_JID_BUFSIZE );
@@ -34,6 +36,7 @@
 	session->router_class_buffer	= buffer_init( JABBER_JID_BUFSIZE );
 	session->router_command_buffer	= buffer_init( JABBER_JID_BUFSIZE );
 
+	session->router_broadcast   = 0;
 
 	if(	session->body_buffer		== NULL || session->subject_buffer	 == NULL	||
 			session->thread_buffer	== NULL || session->from_buffer		 == NULL	||
@@ -43,12 +46,35 @@
 			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;
+	session->state_machine->connecting       = 0;
+	session->state_machine->in_message       = 0;
+	session->state_machine->in_message_body  = 0;
+	session->state_machine->in_thread        = 0;
+	session->state_machine->in_subject       = 0;
+	session->state_machine->in_error         = 0;
+	session->state_machine->in_message_error = 0;
+	session->state_machine->in_iq            = 0;
+	session->state_machine->in_presence      = 0;
+	session->state_machine->in_status        = 0;
 
 	/* initialize the sax push parser */
 	session->parser_ctxt = xmlCreatePushParserCtxt(SAXHandler, session, "", 0, NULL);
@@ -57,6 +83,8 @@
 	session->sock_mgr = (socket_manager*) safe_malloc( sizeof(socket_manager) );
 
 	session->sock_mgr->data_received = &grab_incoming;
+	session->sock_mgr->on_socket_closed = NULL;
+	session->sock_mgr->socket = NULL;
 	session->sock_mgr->blob	= session;
 	
 	session->port = port;
@@ -66,6 +94,7 @@
 	else session->unix_path = NULL;
 
 	session->sock_id = 0;
+	session->message_callback = NULL;
 
 	return session;
 }
@@ -420,7 +449,13 @@
 	}
 }
 
-char* get_xml_attr( const xmlChar** atts, char* attr_name ) {
+// ------------------------------------------------------------------
+// Returns the value of the given XML attribute
+// The xmlChar** construct is commonly returned from SAX event
+// handlers.  Pass that in with the name of the attribute you want
+// to retrieve.
+// ------------------------------------------------------------------
+static char* get_xml_attr( const xmlChar** atts, const char* attr_name ) {
 	int i;
 	if (atts != NULL) {
 		for(i = 0;(atts[i] != NULL);i++) {
@@ -480,22 +515,22 @@
 		return;
 	}
 	
-	if( strcmp( (char*) name, "body" ) == 0 ) {
+	if( strcmp( (const char*) name, "body" ) == 0 ) {
 		ses->state_machine->in_message_body = 0;
 		return;
 	}
 
-	if( strcmp( (char*) name, "subject" ) == 0 ) {
+	if( strcmp( (const char*) name, "subject" ) == 0 ) {
 		ses->state_machine->in_subject = 0;
 		return;
 	}
 
-	if( strcmp( (char*) name, "thread" ) == 0 ) {
+	if( strcmp( (const char*) name, "thread" ) == 0 ) {
 		ses->state_machine->in_thread = 0;
 		return;
 	}
 	
-	if( strcmp( (char*) name, "iq" ) == 0 ) {
+	if( strcmp( (const char*) name, "iq" ) == 0 ) {
 		ses->state_machine->in_iq = 0;
 		if( ses->message_error_code > 0 ) {
 			osrfLogWarning( OSRF_LOG_MARK,  "Error in IQ packet: code %d",  ses->message_error_code );
@@ -505,7 +540,7 @@
 		return;
 	}
 
-	if( strcmp( (char*) name, "presence" ) == 0 ) {
+	if( strcmp( (const char*) name, "presence" ) == 0 ) {
 		ses->state_machine->in_presence = 0;
 		/*
 		if( ses->presence_callback ) {
@@ -516,17 +551,17 @@
 		return;
 	}
 
-	if( strcmp( (char*) name, "status" ) == 0 ) {
+	if( strcmp( (const char*) name, "status" ) == 0 ) {
 		ses->state_machine->in_status = 0;
 		return;
 	}
 
-	if( strcmp( (char*) name, "error" ) == 0 ) {
+	if( strcmp( (const char*) name, "error" ) == 0 ) {
 		ses->state_machine->in_message_error = 0;
 		return;
 	}
 
-	if( strcmp( (char*) name, "error:error" ) == 0 ) {
+	if( strcmp( (const char*) name, "error:error" ) == 0 ) {
 		ses->state_machine->in_error = 0;
 		return;
 	}
@@ -557,7 +592,7 @@
 		void *session, const xmlChar *ch, int len) {
 
 	char data[len+1];
-	strncpy( data, (char*) ch, len );
+	strncpy( data, (const char*) ch, len );
 	data[len] = 0;
 
 	//printf( "Handling characters: %s\n", data );

Modified: trunk/src/libopensrf/utils.c
===================================================================
--- trunk/src/libopensrf/utils.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/libopensrf/utils.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -64,7 +64,7 @@
 	return 0;
 }
 
-int set_proc_title( char* format, ... ) {
+int set_proc_title( const char* format, ... ) {
 	VA_LIST_TO_STRING(format);
 	osrf_clearbuf( *(global_argv), global_argv_size);
 	return snprintf( *(global_argv), global_argv_size, VA_BUF );
@@ -72,7 +72,7 @@
 
 
 /* utility method for profiling */
-double get_timestamp_millis() {
+double get_timestamp_millis( void ) {
 	struct timeval tv;
 	gettimeofday(&tv, NULL);
 	double time	= (int)tv.tv_sec	+ ( ((double)tv.tv_usec / 1000000) );
@@ -186,7 +186,7 @@
 }
 
 
-int buffer_add(growing_buffer* gb, char* data) {
+int buffer_add(growing_buffer* gb, const char* data) {
 	if(!(gb && data)) return 0;
 
 	int data_len = strlen( data );
@@ -248,7 +248,7 @@
 	return 1;
 }
 
-char* buffer_data( growing_buffer *gb) {
+char* buffer_data( const growing_buffer *gb) {
 	return strdup( gb->buf );
 }
 
@@ -379,7 +379,7 @@
 
 
 // A function to turn a process into a daemon 
-int daemonize() {
+int daemonize( void ) {
 	pid_t f = fork();
 
 	if (f == -1) {
@@ -413,7 +413,7 @@
 /* Return 1 if the string represents an integer,  */
 /* as recognized by strtol(); Otherwise return 0. */
 
-int stringisnum(char* s) {
+int stringisnum(const char* s) {
 	char* w;
 	strtol(s, &w, 10);
 	return *w ? 0 : 1;
@@ -449,7 +449,7 @@
 }
 
 
-char* md5sum( char* text, ... ) {
+char* md5sum( const char* text, ... ) {
 
 	struct md5_ctx ctx;
 	unsigned char digest[16];

Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/router/osrf_router.c	2007-11-19 03:19:09 UTC (rev 1130)
@@ -12,8 +12,8 @@
 #define ROUTER_REQUEST_STATS_CLASS_SUMMARY "opensrf.router.info.stats.class.summary"
 
 osrfRouter* osrfNewRouter( 
-		char* domain, char* name, 
-		char* resource, char* password, int port, 
+		const char* domain, const char* name, 
+		const char* resource, const char* password, int port,
 		osrfStringArray* trustedClients, osrfStringArray* trustedServers ) {
 
 	if(!( domain && name && resource && password && port && trustedClients && trustedServers )) return NULL;
@@ -132,7 +132,8 @@
 	}
 }
 
-int osrfRouterClassHandleIncoming( osrfRouter* router, char* classname, osrfRouterClass* class ) {
+int osrfRouterClassHandleIncoming( osrfRouter* router, const char* classname,
+		osrfRouterClass* class ) {
 	if(!(router && class)) return -1;
 
 	transport_message* msg;
@@ -220,7 +221,7 @@
 
 
 
-osrfRouterClass* osrfRouterAddClass( osrfRouter* router, char* classname ) {
+osrfRouterClass* osrfRouterAddClass( osrfRouter* router, const char* classname ) {
 	if(!(router && router->classes && classname)) return NULL;
 
 	osrfRouterClass* class = safe_malloc(sizeof(osrfRouterClass));
@@ -231,9 +232,14 @@
 
 	class->connection = client_init( router->domain, router->port, NULL, 0 );
 
-	if(!client_connect( class->connection, router->name, 
+	if(!client_connect( class->connection, router->name,
 			router->password, classname, 10, AUTH_DIGEST ) ) {
-		osrfRouterClassFree( classname, class );
+				// We cast away the constness of classname.  Though ugly, this
+				// cast is benign because osrfRouterClassFree doesn't actually
+				// write through the pointer.  We can't readily change its
+				// signature because it is used for a function pointer, and
+				// we would have to change other signatures the same way.
+				osrfRouterClassFree( (char *) classname, class );
 		return NULL;
 	}
 	
@@ -242,7 +248,7 @@
 }
 
 
-int osrfRouterClassAddNode( osrfRouterClass* rclass, char* remoteId ) {
+int osrfRouterClassAddNode( osrfRouterClass* rclass, const char* remoteId ) {
 	if(!(rclass && rclass->nodes && remoteId)) return -1;
 
 	osrfLogInfo( OSRF_LOG_MARK, "Adding router node for remote id %s", remoteId );
@@ -260,8 +266,8 @@
 	? return NULL if it's the last node ?
  */
 
-transport_message* osrfRouterClassHandleBounce( 
-		osrfRouter* router, char* classname, osrfRouterClass* rclass, transport_message* msg ) {
+transport_message* osrfRouterClassHandleBounce( osrfRouter* router,
+		const char* classname, osrfRouterClass* rclass, transport_message* msg ) {
 
 	osrfLogDebug( OSRF_LOG_MARK, "osrfRouterClassHandleBounce()");
 
@@ -356,7 +362,7 @@
 }
 
 
-int osrfRouterRemoveClass( osrfRouter* router, char* classname ) {
+int osrfRouterRemoveClass( osrfRouter* router, const char* classname ) {
 	if(!(router && router->classes && classname)) return -1;
 	osrfLogInfo( OSRF_LOG_MARK, "Removing router class %s", classname );
 	osrfHashRemove( router->classes, classname );
@@ -365,7 +371,7 @@
 
 
 int osrfRouterClassRemoveNode( 
-		osrfRouter* router, char* classname, char* remoteId ) {
+		osrfRouter* router, const char* classname, const char* remoteId ) {
 
 	if(!(router && router->classes && classname && remoteId)) return 0;
 
@@ -433,13 +439,13 @@
 
 
 
-osrfRouterClass* osrfRouterFindClass( osrfRouter* router, char* classname ) {
+osrfRouterClass* osrfRouterFindClass( osrfRouter* router, const char* classname ) {
 	if(!( router && router->classes && classname )) return NULL;
 	return (osrfRouterClass*) osrfHashGet( router->classes, classname );
 }
 
 
-osrfRouterNode* osrfRouterClassFindNode( osrfRouterClass* rclass, char* remoteId ) {
+osrfRouterNode* osrfRouterClassFindNode( osrfRouterClass* rclass, const char* remoteId ) {
 	if(!(rclass && remoteId))  return NULL;
 	return (osrfRouterNode*) osrfHashGet( rclass->nodes, remoteId );
 }
@@ -689,7 +695,7 @@
 
 
 int osrfRouterHandleAppResponse( osrfRouter* router, 
-	transport_message* msg, osrfMessage* omsg, jsonObject* response ) {
+	transport_message* msg, osrfMessage* omsg, const jsonObject* response ) {
 
 	if( response ) { /* send the response message */
 

Modified: trunk/src/router/osrf_router.h
===================================================================
--- trunk/src/router/osrf_router.h	2007-11-15 16:21:32 UTC (rev 1129)
+++ trunk/src/router/osrf_router.h	2007-11-19 03:19:09 UTC (rev 1130)
@@ -62,8 +62,9 @@
   @param trustedServers The array of server domains that we allow to register, etc. with ust.
   @return The allocated router or NULL on memory error
   */
-osrfRouter* osrfNewRouter( char* domain, char* name, char* resource, 
-	char* password, int port, osrfStringArray* trustedClients, osrfStringArray* trustedServers );
+osrfRouter* osrfNewRouter( const char* domain, const char* name, const char* resource, 
+	const char* password, int port, osrfStringArray* trustedClients,
+	osrfStringArray* trustedServers );
 
 /**
   Connects the given router to the network
@@ -85,7 +86,7 @@
   @param classname The name of the class this node handles.
   @return 0 on success, -1 on connection error.
   */
-osrfRouterClass* osrfRouterAddClass( osrfRouter* router, char* classname );
+osrfRouterClass* osrfRouterAddClass( osrfRouter* router, const char* classname );
 
 /**
   Adds a new server node to the given class.
@@ -93,7 +94,7 @@
   @param remoteId The remote login of this node
   @return 0 on success, -1 on generic error
   */
-int osrfRouterClassAddNode( osrfRouterClass* rclass, char* remoteId );
+int osrfRouterClassAddNode( osrfRouterClass* rclass, const char* remoteId );
 
 
 /**
@@ -113,7 +114,7 @@
 /**
   Removes a given class from the router, freeing as it goes
   */
-int osrfRouterRemoveClass( osrfRouter* router, char* classname );
+int osrfRouterRemoveClass( osrfRouter* router, const char* classname );
 
 /**
   Removes the given node from the class.  Also, if this is that last node in the set,
@@ -122,7 +123,8 @@
   @return 1 on successful remove with class removal
   @return -1 error on removal
  */
-int osrfRouterClassRemoveNode( osrfRouter* router, char* classname, char* remoteId );
+int osrfRouterClassRemoveNode( osrfRouter* router, const char* classname,
+		const char* remoteId );
 
 /**
   Frees a router class object
@@ -145,12 +147,12 @@
 /**
   Finds the class associated with the given class name in the list of classes
   */
-osrfRouterClass* osrfRouterFindClass( osrfRouter* router, char* classname );
+osrfRouterClass* osrfRouterFindClass( osrfRouter* router, const char* classname );
 
 /**
   Finds the router node within this class with the given remote id 
   */
-osrfRouterNode* osrfRouterClassFindNode( osrfRouterClass* rclass, char* remoteId );
+osrfRouterNode* osrfRouterClassFindNode( osrfRouterClass* rclass, const char* remoteId );
 
 
 /**
@@ -173,15 +175,16 @@
 	Utility method for handling incoming requests to a router class,
 	makes sure sender is a trusted client
 	*/
-int osrfRouterClassHandleIncoming( osrfRouter* router, char* classname,  osrfRouterClass* class );
+int osrfRouterClassHandleIncoming( osrfRouter* router,
+		const char* classname,  osrfRouterClass* class );
 
 /* handles case where router node is not longer reachable.  copies over the
 	data from the last sent message and returns a newly crafted suitable for treating
 	as a newly inconing message.  Removes the dead node and If there are no more
 	nodes to send the new message to, returns NULL.
 	*/
-transport_message* osrfRouterClassHandleBounce(
-		osrfRouter* router, char* classname, osrfRouterClass* rclass, transport_message* msg );
+transport_message* osrfRouterClassHandleBounce( osrfRouter* router,
+		const char* classname, osrfRouterClass* rclass, transport_message* msg );
 
 
 
@@ -215,7 +218,7 @@
 int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* msg, osrfMessage* omsg );
 
 int osrfRouterHandleAppResponse( osrfRouter* router, 
-		transport_message* msg, osrfMessage* omsg, jsonObject* response );
+		transport_message* msg, osrfMessage* omsg, const jsonObject* response );
 
 
 int osrfRouterHandleMethodNFound( osrfRouter* router, transport_message* msg, osrfMessage* omsg );



More information about the opensrf-commits mailing list