From 8a8b4cbbae62d3e927b24541f31fec93949b1752 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 2 Apr 2014 16:05:33 -0700 Subject: [PATCH] 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 Signed-off-by: Bill Erickson --- include/opensrf/osrf_cache.h | 4 ++-- src/gateway/osrf_http_translator.c | 2 +- src/libopensrf/osrf_cache.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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; -- 2.43.2