[Opensrf-commits] r1797 - in trunk: include/opensrf src/gateway src/libopensrf src/router (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Sep 28 08:26:23 EDT 2009


Author: scottmk
Date: 2009-09-28 08:26:21 -0400 (Mon, 28 Sep 2009)
New Revision: 1797

Modified:
   trunk/include/opensrf/log.h
   trunk/src/gateway/osrf_http_translator.c
   trunk/src/libopensrf/log.c
   trunk/src/libopensrf/osrf_application.c
   trunk/src/libopensrf/osrf_prefork.c
   trunk/src/router/osrf_router_main.c
Log:
1. Changed osrfLogFacilityToInt() so that it accepts
a const pointer.

2. Added the const qualifier to various variables.

3. In osrf_router_main.c: Removed three inappropriate
calls to free().  Some memory leaks remain, where we
fetch some cloned jsonObjects from jsonObjectFindPath()
and don't free them.

M    include/opensrf/log.h
M    src/router/osrf_router_main.c
M    src/gateway/osrf_http_translator.c
M    src/libopensrf/osrf_prefork.c
M    src/libopensrf/log.c
M    src/libopensrf/osrf_application.c


Modified: trunk/include/opensrf/log.h
===================================================================
--- trunk/include/opensrf/log.h	2009-09-28 04:38:16 UTC (rev 1796)
+++ trunk/include/opensrf/log.h	2009-09-28 12:26:21 UTC (rev 1797)
@@ -94,7 +94,7 @@
 /* returns the int representation of the log facility based on the facility name
  * if the facility name is invalid, LOG_LOCAL0 is returned 
  */
-int osrfLogFacilityToInt( char* facility );
+int osrfLogFacilityToInt( const char* facility );
 
 #ifdef __cplusplus
 }

Modified: trunk/src/gateway/osrf_http_translator.c
===================================================================
--- trunk/src/gateway/osrf_http_translator.c	2009-09-28 04:38:16 UTC (rev 1796)
+++ trunk/src/gateway/osrf_http_translator.c	2009-09-28 12:26:21 UTC (rev 1797)
@@ -194,8 +194,8 @@
             sessionCache = osrfCacheGetObject(trans->thread);
 
             if(sessionCache) {
-                char* ipAddr = jsonObjectGetString(jsonObjectGetKey(sessionCache, "ip"));
-                char* recipient = jsonObjectGetString(jsonObjectGetKey(sessionCache, "jid"));
+                const char* ipAddr = jsonObjectGetString(jsonObjectGetKey(sessionCache, "ip"));
+                const char* recipient = jsonObjectGetString(jsonObjectGetKey(sessionCache, "jid"));
 
                 // choosing a specific recipient address requires that the recipient and 
                 // thread be cached on the server (so drone processes cannot be hijacked)

Modified: trunk/src/libopensrf/log.c
===================================================================
--- trunk/src/libopensrf/log.c	2009-09-28 04:38:16 UTC (rev 1796)
+++ trunk/src/libopensrf/log.c	2009-09-28 12:26:21 UTC (rev 1797)
@@ -299,7 +299,7 @@
 }
 
 
-int osrfLogFacilityToInt( char* facility ) {
+int osrfLogFacilityToInt( const char* facility ) {
 	if(!facility) return LOG_LOCAL0;
 	if(strlen(facility) < 6) return LOG_LOCAL0;
 	switch( facility[5] ) {

Modified: trunk/src/libopensrf/osrf_application.c
===================================================================
--- trunk/src/libopensrf/osrf_application.c	2009-09-28 04:38:16 UTC (rev 1796)
+++ trunk/src/libopensrf/osrf_application.c	2009-09-28 12:26:21 UTC (rev 1797)
@@ -452,7 +452,7 @@
 static int osrfAppIntrospect( osrfMethodContext* ctx ) {
 
 	jsonObject* resp = NULL;
-	char* methodSubstring = jsonObjectGetString( jsonObjectGetIndex(ctx->params, 0) );
+	const char* methodSubstring = jsonObjectGetString( jsonObjectGetIndex(ctx->params, 0) );
 	osrfApplication* app = _osrfAppFindApplication( ctx->session->remote_service );
 	int len = 0;
 

Modified: trunk/src/libopensrf/osrf_prefork.c
===================================================================
--- trunk/src/libopensrf/osrf_prefork.c	2009-09-28 04:38:16 UTC (rev 1796)
+++ trunk/src/libopensrf/osrf_prefork.c	2009-09-28 12:26:21 UTC (rev 1797)
@@ -158,14 +158,14 @@
 /** parses a single "complex" router configuration chunk */
 static void osrf_prefork_parse_router_chunk(const char* appname, jsonObject* routerChunk) {
 
-	char* routerName = jsonObjectGetString(jsonObjectGetKey(routerChunk, "name"));
-	char* domain = jsonObjectGetString(jsonObjectGetKey(routerChunk, "domain"));
-	jsonObject* services = jsonObjectGetKey(routerChunk, "services");
+	const char* routerName = jsonObjectGetString(jsonObjectGetKeyConst(routerChunk, "name"));
+	const char* domain = jsonObjectGetString(jsonObjectGetKeyConst(routerChunk, "domain"));
+	const jsonObject* services = jsonObjectGetKeyConst(routerChunk, "services");
 	osrfLogDebug(OSRF_LOG_MARK, "found router config with domain %s and name %s", routerName, domain);
 
 	if( services && services->type == JSON_HASH ) {
 		osrfLogDebug(OSRF_LOG_MARK, "investigating router information...");
-		jsonObject* service_obj = jsonObjectGetKey(services, "service");
+		const jsonObject* service_obj = jsonObjectGetKeyConst(services, "service");
 		if( !service_obj )
 			;    // do nothing (shouldn't happen)
 		else if( JSON_ARRAY == service_obj->type ) {

Modified: trunk/src/router/osrf_router_main.c
===================================================================
--- trunk/src/router/osrf_router_main.c	2009-09-28 04:38:16 UTC (rev 1796)
+++ trunk/src/router/osrf_router_main.c	2009-09-28 12:26:21 UTC (rev 1797)
@@ -84,15 +84,15 @@
     if(!jsonObjectGetKey(configChunk, "transport"))
         return 0; /* these are not the configs you're looking for */
 
-	char* server = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/server"));
-	char* port = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/port"));
-	char* username = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/username"));
-	char* password = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/password"));
-	char* resource = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/resource"));
+	const char* server   = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/server"));
+	const char* port     = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/port"));
+	const char* username = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/username"));
+	const char* password = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/password"));
+	const char* resource = jsonObjectGetString(jsonObjectFindPath(configChunk, "/transport/resource"));
 
-	char* level = jsonObjectGetString(jsonObjectFindPath(configChunk, "/loglevel"));
-	char* log_file = jsonObjectGetString(jsonObjectFindPath(configChunk, "/logfile"));
-	char* facility = jsonObjectGetString(jsonObjectFindPath(configChunk, "/syslog"));
+	const char* level    = jsonObjectGetString(jsonObjectFindPath(configChunk, "/loglevel"));
+	const char* log_file = jsonObjectGetString(jsonObjectFindPath(configChunk, "/logfile"));
+	const char* facility = jsonObjectGetString(jsonObjectFindPath(configChunk, "/syslog"));
 
 	int llevel = 1;
 	if(level) llevel = atoi(level);
@@ -108,10 +108,6 @@
 		osrfLogSetFile( log_file );
 	}
 
-	free(facility);
-	free(level);
-	free(log_file);
-
 	osrfLogInfo(  OSRF_LOG_MARK, "Router connecting as: server: %s port: %s "
 			"user: %s resource: %s", server, port, username, resource );
 
@@ -128,24 +124,24 @@
 
     if(tserversList->type == JSON_ARRAY) {
 	    for( i = 0; i != tserversList->size; i++ ) {
-            char* serverDomain = jsonObjectGetString(jsonObjectGetIndex(tserversList, i));
+            const char* serverDomain = jsonObjectGetString(jsonObjectGetIndex(tserversList, i));
 		    osrfLogInfo( OSRF_LOG_MARK,  "Router adding trusted server: %s", serverDomain);
             osrfStringArrayAdd(tservers, serverDomain);
         }
     } else {
-        char* serverDomain = jsonObjectGetString(tserversList);
+        const char* serverDomain = jsonObjectGetString(tserversList);
         osrfLogInfo( OSRF_LOG_MARK,  "Router adding trusted server: %s", serverDomain);
         osrfStringArrayAdd(tservers, serverDomain);
     }
 
     if(tclientsList->type == JSON_ARRAY) {
 	    for( i = 0; i != tclientsList->size; i++ ) {
-            char* clientDomain = jsonObjectGetString(jsonObjectGetIndex(tclientsList, i));
+            const char* clientDomain = jsonObjectGetString(jsonObjectGetIndex(tclientsList, i));
 		    osrfLogInfo( OSRF_LOG_MARK,  "Router adding trusted client: %s", clientDomain);
             osrfStringArrayAdd(tclients, clientDomain);
         }
     } else {
-        char* clientDomain = jsonObjectGetString(tclientsList);
+        const char* clientDomain = jsonObjectGetString(tclientsList);
         osrfLogInfo( OSRF_LOG_MARK,  "Router adding trusted client: %s", clientDomain);
         osrfStringArrayAdd(tclients, clientDomain);
     }



More information about the opensrf-commits mailing list