LP#1234816: improve const-correctness of osrfCachePutString and osrfCachePutObject
authorGalen Charlton <gmc@esilibrary.com>
Wed, 2 Apr 2014 23:05:33 +0000 (16:05 -0700)
committerBill Erickson <berick@esilibrary.com>
Fri, 2 May 2014 18:06:16 +0000 (14:06 -0400)
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 <gmc@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>

include/opensrf/osrf_cache.h
src/gateway/osrf_http_translator.c
src/libopensrf/osrf_cache.c

index 591b3a8..37e48ac 100644 (file)
@@ -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.
index cec0d4e..ab46db4 100644 (file)
@@ -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);
 }
 
 
index c19354a..fc4d488 100644 (file)
@@ -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;