From f154930bf8de2125f9dc6a1e450c0036e9b49d98 Mon Sep 17 00:00:00 2001 From: scottmk Date: Mon, 28 Sep 2009 12:26:21 +0000 Subject: [PATCH] 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 git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1797 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/log.h | 2 +- src/gateway/osrf_http_translator.c | 4 ++-- src/libopensrf/log.c | 2 +- src/libopensrf/osrf_application.c | 2 +- src/libopensrf/osrf_prefork.c | 8 ++++---- src/router/osrf_router_main.c | 28 ++++++++++++---------------- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/include/opensrf/log.h b/include/opensrf/log.h index a50e21e..8463708 100644 --- a/include/opensrf/log.h +++ b/include/opensrf/log.h @@ -94,7 +94,7 @@ void osrfLogSetActivityEnabled( int enabled ); /* 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 } diff --git a/src/gateway/osrf_http_translator.c b/src/gateway/osrf_http_translator.c index d794d08..df2d273 100644 --- a/src/gateway/osrf_http_translator.c +++ b/src/gateway/osrf_http_translator.c @@ -194,8 +194,8 @@ static int osrfHttpTranslatorSetTo(osrfHttpTranslator* trans) { 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) diff --git a/src/libopensrf/log.c b/src/libopensrf/log.c index aca653e..7cb9232 100644 --- a/src/libopensrf/log.c +++ b/src/libopensrf/log.c @@ -299,7 +299,7 @@ static void _osrfLogToFile( const char* msg, ... ) { } -int osrfLogFacilityToInt( char* facility ) { +int osrfLogFacilityToInt( const char* facility ) { if(!facility) return LOG_LOCAL0; if(strlen(facility) < 6) return LOG_LOCAL0; switch( facility[5] ) { diff --git a/src/libopensrf/osrf_application.c b/src/libopensrf/osrf_application.c index b4dde46..d25eeec 100644 --- a/src/libopensrf/osrf_application.c +++ b/src/libopensrf/osrf_application.c @@ -452,7 +452,7 @@ static int _osrfAppRunSystemMethod(osrfMethodContext* ctx) { 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; diff --git a/src/libopensrf/osrf_prefork.c b/src/libopensrf/osrf_prefork.c index ce19e35..7cfd535 100644 --- a/src/libopensrf/osrf_prefork.c +++ b/src/libopensrf/osrf_prefork.c @@ -158,14 +158,14 @@ static void osrf_prefork_send_router_registration(const char* appname, const cha /** 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 ) { diff --git a/src/router/osrf_router_main.c b/src/router/osrf_router_main.c index d15f164..db4a299 100644 --- a/src/router/osrf_router_main.c +++ b/src/router/osrf_router_main.c @@ -84,15 +84,15 @@ int setupRouter(jsonObject* configChunk) { 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 @@ int setupRouter(jsonObject* configChunk) { 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 @@ int setupRouter(jsonObject* configChunk) { 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); } -- 2.43.2