From: Galen Charlton Date: Wed, 2 Apr 2014 23:05:33 +0000 (-0700) Subject: LP#1234816: improve const-correctness of osrfCachePutString and osrfCachePutObject X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a5528ed11fafe6f0c79dfbe93123ef68799e4f2a;p=working%2FOpenSRF.git LP#1234816: improve const-correctness of osrfCachePutString and osrfCachePutObject Since the cache key is not modified by osrfCachePutString and osrfCachePutObject, this patch changes the key parameter of those two functions from char* to const char*. It also updates one caller osrfCachePutObject to not cast away const-ness. This patch has no functional impact, but enables future callers of osrfCachePut* to pass constant strings without having to cast away the const-ness. Signed-off-by: Galen Charlton --- diff --git a/include/opensrf/osrf_cache.h b/include/opensrf/osrf_cache.h index 591b3a8..37e48ac 100644 --- a/include/opensrf/osrf_cache.h +++ b/include/opensrf/osrf_cache.h @@ -47,7 +47,7 @@ int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds to cache up to 'maxCacheSeconds' as set by osrfCacheInit() @return 0 on success, -1 on error */ -int osrfCachePutObject( char* key, const jsonObject* obj, time_t seconds ); +int osrfCachePutObject( const char* key, const jsonObject* obj, time_t seconds ); /** Puts a string into the cache @@ -57,7 +57,7 @@ int osrfCachePutObject( char* key, const jsonObject* obj, time_t seconds ); to cache up to 'maxCacheSeconds' as set by osrfCacheInit() @return 0 on success, -1 on error */ -int osrfCachePutString( char* key, const char* value, time_t seconds); +int osrfCachePutString( const char* key, const char* value, time_t seconds); /** Grabs an object from the cache. diff --git a/src/gateway/osrf_http_translator.c b/src/gateway/osrf_http_translator.c index cec0d4e..ab46db4 100644 --- a/src/gateway/osrf_http_translator.c +++ b/src/gateway/osrf_http_translator.c @@ -382,7 +382,7 @@ static void osrfHttpTranslatorCacheSession(osrfHttpTranslator* trans, const char jsonObjectSetKey(cacheObj, "ip", jsonNewObject(trans->remoteHost)); jsonObjectSetKey(cacheObj, "jid", jsonNewObject(jid)); jsonObjectSetKey(cacheObj, "service", jsonNewObject(trans->service)); - osrfCachePutObject((char*) trans->thread, cacheObj, CACHE_TIME); + osrfCachePutObject(trans->thread, cacheObj, CACHE_TIME); } diff --git a/src/libopensrf/osrf_cache.c b/src/libopensrf/osrf_cache.c index c19354a..fc4d488 100644 --- a/src/libopensrf/osrf_cache.c +++ b/src/libopensrf/osrf_cache.c @@ -43,7 +43,7 @@ int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds return 0; } -int osrfCachePutObject( char* key, const jsonObject* obj, time_t seconds ) { +int osrfCachePutObject( const char* key, const jsonObject* obj, time_t seconds ) { if( !(key && obj) ) return -1; char* s = jsonObjectToJSON( obj ); osrfLogInternal( OSRF_LOG_MARK, "osrfCachePut(): Putting object (key=%s): %s", key, s); @@ -52,7 +52,7 @@ int osrfCachePutObject( char* key, const jsonObject* obj, time_t seconds ) { return 0; } -int osrfCachePutString( char* key, const char* value, time_t seconds ) { +int osrfCachePutString( const char* key, const char* value, time_t seconds ) { memcached_return rc; if( !(key && value) ) return -1; seconds = (seconds <= 0 || seconds > _osrfCacheMaxSeconds) ? _osrfCacheMaxSeconds : seconds;