Patch from Scott McKellar to inject more tasty const correctness
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 25 Nov 2007 21:11:57 +0000 (21:11 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 25 Nov 2007 21:11:57 +0000 (21:11 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@8113 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/c-apps/oils_utils.c
Open-ILS/src/c-apps/openils/oils_utils.h

index 2f27ac1..db25e42 100644 (file)
@@ -25,12 +25,12 @@ osrfHash* oilsInitIDL(char* idl_filename) {
        return oilsIDL();
 }
 
-char* oilsFMGetString( jsonObject* object, char* field ) {
+char* oilsFMGetString( const jsonObject* object, const char* field ) {
        return jsonObjectToSimpleString(oilsFMGetObject( object, field ));
 }
 
 
-jsonObject* oilsFMGetObject( jsonObject* object, char* field ) {
+const jsonObject* oilsFMGetObject( const jsonObject* object, const char* field ) {
        if(!(object && field)) return NULL;
        if( object->type != JSON_ARRAY || !object->classname ) return NULL;
        int pos = fm_ntop(object->classname, field);
@@ -39,7 +39,7 @@ jsonObject* oilsFMGetObject( jsonObject* object, char* field ) {
 }
 
 
-int oilsFMSetString( jsonObject* object, char* field, char* string ) {
+int oilsFMSetString( jsonObject* object, const char* field, const char* string ) {
        if(!(object && field && string)) return -1;
        osrfLogInternal(OSRF_LOG_MARK, "oilsFMSetString(): Collecing position for field %s", field);
        int pos = fm_ntop(object->classname, field);
@@ -53,13 +53,13 @@ int oilsFMSetString( jsonObject* object, char* field, char* string ) {
 }
 
 
-int oilsUtilsIsDBTrue( char* val ) {
+int oilsUtilsIsDBTrue( const char* val ) {
        if( val && strcasecmp(val, "f") && strcmp(val, "0") ) return 1;
        return 0;
 }
 
 
-long oilsFMGetObjectId( jsonObject* obj ) {
+long oilsFMGetObjectId( const jsonObject* obj ) {
        long id = -1;
        if(!obj) return id;
        char* ids = oilsFMGetString( obj, "id" );
@@ -96,7 +96,8 @@ oilsEvent* oilsUtilsCheckPerms( int userid, int orgid, char* permissions[], int
        return evt;
 }
 
-jsonObject* oilsUtilsQuickReq( char* service, char* method, jsonObject* params ) {
+jsonObject* oilsUtilsQuickReq( const char* service, const char* method,
+               const jsonObject* params ) {
        if(!(service && method)) return NULL;
        osrfLogDebug(OSRF_LOG_MARK, "oilsUtilsQuickReq(): %s - %s", service, method );
        osrfAppSession* session = osrfAppSessionClientInit( service ); 
@@ -108,17 +109,17 @@ jsonObject* oilsUtilsQuickReq( char* service, char* method, jsonObject* params )
        return result;
 }
 
-jsonObject* oilsUtilsStorageReq( char* method, jsonObject* params ) {
+jsonObject* oilsUtilsStorageReq( const char* method, const jsonObject* params ) {
        return oilsUtilsQuickReq( "open-ils.storage", method, params );
 }
 
-jsonObject* oilsUtilsCStoreReq( char* method, jsonObject* params ) {
+jsonObject* oilsUtilsCStoreReq( const char* method, const jsonObject* params ) {
        return oilsUtilsQuickReq("open-ils.cstore", method, params);
 }
 
 
 
-jsonObject* oilsUtilsFetchUserByUsername( char* name ) {
+jsonObject* oilsUtilsFetchUserByUsername( const char* name ) {
        if(!name) return NULL;
        jsonObject* params = jsonParseStringFmt("{\"usrname\":\"%s\"}", name);
        jsonObject* user = oilsUtilsQuickReq( 
@@ -130,7 +131,7 @@ jsonObject* oilsUtilsFetchUserByUsername( char* name ) {
        return user;
 }
 
-jsonObject* oilsUtilsFetchUserByBarcode(char* barcode) {
+jsonObject* oilsUtilsFetchUserByBarcode(const char* barcode) {
        if(!barcode) return NULL;
 
        osrfLogInfo(OSRF_LOG_MARK, "Fetching user by barcode %s", barcode);
@@ -155,7 +156,7 @@ jsonObject* oilsUtilsFetchUserByBarcode(char* barcode) {
        return user;
 }
 
-char* oilsUtilsFetchOrgSetting( int orgid, char* setting ) {
+char* oilsUtilsFetchOrgSetting( int orgid, const char* setting ) {
        if(!setting) return NULL;
 
        jsonObject* params = jsonParseStringFmt(
@@ -175,7 +176,7 @@ char* oilsUtilsFetchOrgSetting( int orgid, char* setting ) {
 
 
 
-char* oilsUtilsLogin( char* uname, char* passwd, char* type, int orgId ) {
+char* oilsUtilsLogin( const char* uname, const char* passwd, const char* type, int orgId ) {
        if(!(uname && passwd)) return NULL;
 
        osrfLogDebug(OSRF_LOG_MARK, "Logging in with username %s", uname );
@@ -186,7 +187,7 @@ char* oilsUtilsLogin( char* uname, char* passwd, char* type, int orgId ) {
        jsonObject* o = oilsUtilsQuickReq( 
                "open-ils.auth", "open-ils.auth.authenticate.init", params );
 
-       char* seed = jsonObjectGetString(o);
+       const char* seed = jsonObjectGetString(o);
        char* passhash = md5sum(passwd);
        char buf[256];
        snprintf(buf, sizeof(buf), "%s%s", seed, passhash);
@@ -201,7 +202,7 @@ char* oilsUtilsLogin( char* uname, char* passwd, char* type, int orgId ) {
                "open-ils.auth.authenticate.complete", params );
 
        if(o) {
-               char* tok = jsonObjectGetString(
+               const char* tok = jsonObjectGetString(
                        jsonObjectGetKey(jsonObjectGetKey(o,"payload"), "authtoken"));
                if(tok) token = strdup(tok);
        }
@@ -223,7 +224,7 @@ jsonObject* oilsUtilsFetchWorkstation( long id ) {
        return r;
 }
 
-jsonObject* oilsUtilsFetchWorkstationByName( char* name ) {
+jsonObject* oilsUtilsFetchWorkstationByName( const char* name ) {
        jsonObject* p = jsonParseStringFmt("[\"%s\"]", name);
        jsonObject* r = oilsUtilsStorageReq(
                "open-ils.storage.direct.actor.workstation.search.name", p );
index 3e134d5..64a785f 100644 (file)
@@ -28,7 +28,7 @@ osrfHash* oilsInitIDL( char* idl_filename );
   @return The string at the given position, if none exists, 
   then NULL is returned.  The caller must free the returned string
   */
-char* oilsFMGetString( jsonObject* object, char* field );
+char* oilsFMGetString( const jsonObject* object, const char* field );
 
 
 /**
@@ -39,7 +39,7 @@ char* oilsFMGetString( jsonObject* object, char* field );
   @return The found object or NULL if none exists.  Do NOT free the 
   returned object.
   */
-jsonObject* oilsFMGetObject( jsonObject* object, char* field );
+const jsonObject* oilsFMGetObject( const jsonObject* object, const char* field );
 
 /**
   Sets the given field in the given object to the given string
@@ -48,13 +48,13 @@ jsonObject* oilsFMGetObject( jsonObject* object, char* field );
   @param string The new data
   @return 0 if the field was updated successfully, -1 on error
   */
-int oilsFMSetString( jsonObject* object, char* field, char* string );
+int oilsFMSetString( jsonObject* object, const char* field, const char* string );
 
 /**
  * Returns the data stored in the id field of the object if it exists
  * returns -1 if the id field or the id value is not found
  */
-long oilsFMGetObjectId( jsonObject* obj );
+long oilsFMGetObjectId( const jsonObject* obj );
 
 
 /**
@@ -71,31 +71,32 @@ oilsEvent* oilsUtilsCheckPerms( int userid, int orgid, char* permissions[], int
  * Performs a single request and returns the resulting data
  * Caller is responsible for freeing the returned response object
  */
-jsonObject* oilsUtilsQuickReq( char* service, char* method, jsonObject* params );
+jsonObject* oilsUtilsQuickReq( const char* service, const char* method,
+               const jsonObject* params );
 
-jsonObject* oilsUtilsStorageReq( char* method, jsonObject* params );
+jsonObject* oilsUtilsStorageReq( const char* method, const jsonObject* params );
 
-jsonObject* oilsUtilsCStoreReq( char* method, jsonObject* params );
+jsonObject* oilsUtilsCStoreReq( const char* method, const jsonObject* params );
 
 /**
  * Searches the storage server for a user with the given username 
  * Caller is responsible for freeing the returned object
  */
-jsonObject* oilsUtilsFetchUserByUsername( char* name );
+jsonObject* oilsUtilsFetchUserByUsername( const char* name );
 
 
 /**
  * Returns the setting value
  * Caller must free the returned string
  */
-char* oilsUtilsFetchOrgSetting( int orgid, char* setting );
+char* oilsUtilsFetchOrgSetting( int orgid, const char* setting );
 
 
 /**
  * Logs into the auth server with the given username and password
  * @return The authtoken string which must be de-allocated by the caller
  */
-char* oilsUtilsLogin( char* uname, char* passwd, char* type, int orgId );
+char* oilsUtilsLogin( const char* uname, const char* passwd, const char* type, int orgId );
 
 
 /**
@@ -103,9 +104,9 @@ char* oilsUtilsLogin( char* uname, char* passwd, char* type, int orgId );
  */
 jsonObject* oilsUtilsFetchWorkstation( long id );
 
-jsonObject* oilsUtilsFetchUserByBarcode(char* barcode);
+jsonObject* oilsUtilsFetchUserByBarcode(const char* barcode);
 
-jsonObject* oilsUtilsFetchWorkstationByName( char* name );
+jsonObject* oilsUtilsFetchWorkstationByName( const char* name );
 
 
-int oilsUtilsIsDBTrue( char* val );
+int oilsUtilsIsDBTrue( const char* val );