This patch applies the const qualifier to various things:

1. To a number of function parameters.

2. To a couple of local variables, so that we can eventually change
jsonObjectGetString() so as to return a const pointer, as it should.

3. To the pointer returned by oilsFMGetObject().

The last change may be a bit controversial because it restricts
the future use of this function -- i.e. the pointer it returns
may not be used to change the jsonObject to which it points.

As it happens, in no case do we use the returned pointer to change
the referenced jsonObject.  In an earlier patch I tweaked
oils_requestor.c to assign the return value to a const pointer
instead of a non-const pointer, but no other changes are needed to
accommodate the constness.

The reason for this change is that the pointer returned is obtained
from a call to jsonObjectGetIndex(), which itself should return
a const pointer (though it doesn't yet).

If the constness proves too restrictive, we can revisit the matter
or find a workaround.  If all else fails we can use an evil cast
somewhere.  In practice I doubt that the issue will arise.

Scott McKellar
http://home.swbell.net/mck9/ct/

Developer's Certificate of Origin 1.1 By making a contribution to
this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license indicated
in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source license
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under the
same open source license (unless I am permitted to submit under a
different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it; and

(d) In the case of each of (a), (b), or (c), I understand and agree
that this project and the contribution are public and that a record
of the contribution (including all personal information I submit
with it, including my sign-off) is maintained indefinitely and may
be redistributed consistent with this project or the open source
license indicated in the file.
*** trunk/Open-ILS/src/c-apps/openils/oils_utils.h	2007-11-20 23:17:15.000000000 -0600
--- trunk-mod/Open-ILS/src/c-apps/openils/oils_utils.h	2007-11-20 23:42:20.000000000 -0600
***************
*** 28,34 ****
    @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 );
  
  
  /**
--- 28,34 ----
    @return The string at the given position, if none exists, 
    then NULL is returned.  The caller must free the returned string
    */
! char* oilsFMGetString( const jsonObject* object, const char* field );
  
  
  /**
***************
*** 39,45 ****
    @return The found object or NULL if none exists.  Do NOT free the 
    returned object.
    */
! jsonObject* oilsFMGetObject( jsonObject* object, char* field );
  
  /**
    Sets the given field in the given object to the given string
--- 39,45 ----
    @return The found object or NULL if none exists.  Do NOT free the 
    returned object.
    */
! const jsonObject* oilsFMGetObject( const jsonObject* object, const char* field );
  
  /**
    Sets the given field in the given object to the given string
***************
*** 48,60 ****
    @param string The new data
    @return 0 if the field was updated successfully, -1 on error
    */
! int oilsFMSetString( jsonObject* object, char* field, 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 );
  
  
  /**
--- 48,60 ----
    @param string The new data
    @return 0 if the field was updated successfully, -1 on error
    */
! 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( const jsonObject* obj );
  
  
  /**
***************
*** 71,101 ****
   * 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* oilsUtilsStorageReq( char* method, jsonObject* params );
  
! jsonObject* oilsUtilsCStoreReq( char* method, 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 );
  
  
  /**
   * Returns the setting value
   * Caller must free the returned string
   */
! char* oilsUtilsFetchOrgSetting( int orgid, 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 );
  
  
  /**
--- 71,102 ----
   * Performs a single request and returns the resulting data
   * Caller is responsible for freeing the returned response object
   */
! jsonObject* oilsUtilsQuickReq( const char* service, const char* method,
! 		const jsonObject* params );
  
! jsonObject* oilsUtilsStorageReq( const char* method, const 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( const char* name );
  
  
  /**
   * Returns the setting value
   * Caller must free the returned string
   */
! 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( const char* uname, const char* passwd, const char* type, int orgId );
  
  
  /**
***************
*** 103,111 ****
   */
  jsonObject* oilsUtilsFetchWorkstation( long id );
  
! jsonObject* oilsUtilsFetchUserByBarcode(char* barcode);
  
! jsonObject* oilsUtilsFetchWorkstationByName( char* name );
  
  
! int oilsUtilsIsDBTrue( char* val );
--- 104,112 ----
   */
  jsonObject* oilsUtilsFetchWorkstation( long id );
  
! jsonObject* oilsUtilsFetchUserByBarcode(const char* barcode);
  
! jsonObject* oilsUtilsFetchWorkstationByName( const char* name );
  
  
! int oilsUtilsIsDBTrue( const char* val );
*** trunk/Open-ILS/src/c-apps/oils_utils.c	2007-11-20 23:17:15.000000000 -0600
--- trunk-mod/Open-ILS/src/c-apps/oils_utils.c	2007-11-20 23:40:36.000000000 -0600
***************
*** 25,36 ****
  	return oilsIDL();
  }
  
! char* oilsFMGetString( jsonObject* object, char* field ) {
  	return jsonObjectToSimpleString(oilsFMGetObject( object, field ));
  }
  
  
! jsonObject* oilsFMGetObject( jsonObject* object, char* field ) {
  	if(!(object && field)) return NULL;
  	if( object->type != JSON_ARRAY || !object->classname ) return NULL;
  	int pos = fm_ntop(object->classname, field);
--- 25,36 ----
  	return oilsIDL();
  }
  
! char* oilsFMGetString( const jsonObject* object, const char* field ) {
  	return jsonObjectToSimpleString(oilsFMGetObject( object, 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,45 ****
  }
  
  
! int oilsFMSetString( jsonObject* object, char* field, 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);
--- 39,45 ----
  }
  
  
! 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,65 ****
  }
  
  
! int oilsUtilsIsDBTrue( char* val ) {
  	if( val && strcasecmp(val, "f") && strcmp(val, "0") ) return 1;
  	return 0;
  }
  
  
! long oilsFMGetObjectId( jsonObject* obj ) {
  	long id = -1;
  	if(!obj) return id;
  	char* ids = oilsFMGetString( obj, "id" );
--- 53,65 ----
  }
  
  
! int oilsUtilsIsDBTrue( const char* val ) {
  	if( val && strcasecmp(val, "f") && strcmp(val, "0") ) return 1;
  	return 0;
  }
  
  
! long oilsFMGetObjectId( const jsonObject* obj ) {
  	long id = -1;
  	if(!obj) return id;
  	char* ids = oilsFMGetString( obj, "id" );
***************
*** 96,102 ****
  	return evt;
  }
  
! jsonObject* oilsUtilsQuickReq( char* service, char* method, jsonObject* params ) {
  	if(!(service && method)) return NULL;
  	osrfLogDebug(OSRF_LOG_MARK, "oilsUtilsQuickReq(): %s - %s", service, method );
  	osrfAppSession* session = osrfAppSessionClientInit( service ); 
--- 96,103 ----
  	return evt;
  }
  
! 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,124 ****
  	return result;
  }
  
! jsonObject* oilsUtilsStorageReq( char* method, jsonObject* params ) {
  	return oilsUtilsQuickReq( "open-ils.storage", method, params );
  }
  
! jsonObject* oilsUtilsCStoreReq( char* method, jsonObject* params ) {
  	return oilsUtilsQuickReq("open-ils.cstore", method, params);
  }
  
  
  
! jsonObject* oilsUtilsFetchUserByUsername( char* name ) {
  	if(!name) return NULL;
  	jsonObject* params = jsonParseStringFmt("{\"usrname\":\"%s\"}", name);
  	jsonObject* user = oilsUtilsQuickReq( 
--- 109,125 ----
  	return result;
  }
  
! jsonObject* oilsUtilsStorageReq( const char* method, const jsonObject* params ) {
  	return oilsUtilsQuickReq( "open-ils.storage", method, params );
  }
  
! jsonObject* oilsUtilsCStoreReq( const char* method, const jsonObject* params ) {
  	return oilsUtilsQuickReq("open-ils.cstore", method, params);
  }
  
  
  
! jsonObject* oilsUtilsFetchUserByUsername( const char* name ) {
  	if(!name) return NULL;
  	jsonObject* params = jsonParseStringFmt("{\"usrname\":\"%s\"}", name);
  	jsonObject* user = oilsUtilsQuickReq( 
***************
*** 130,136 ****
  	return user;
  }
  
! jsonObject* oilsUtilsFetchUserByBarcode(char* barcode) {
  	if(!barcode) return NULL;
  
  	osrfLogInfo(OSRF_LOG_MARK, "Fetching user by barcode %s", barcode);
--- 131,137 ----
  	return user;
  }
  
! jsonObject* oilsUtilsFetchUserByBarcode(const char* barcode) {
  	if(!barcode) return NULL;
  
  	osrfLogInfo(OSRF_LOG_MARK, "Fetching user by barcode %s", barcode);
***************
*** 155,161 ****
  	return user;
  }
  
! char* oilsUtilsFetchOrgSetting( int orgid, char* setting ) {
  	if(!setting) return NULL;
  
  	jsonObject* params = jsonParseStringFmt(
--- 156,162 ----
  	return user;
  }
  
! char* oilsUtilsFetchOrgSetting( int orgid, const char* setting ) {
  	if(!setting) return NULL;
  
  	jsonObject* params = jsonParseStringFmt(
***************
*** 175,181 ****
  
  
  
! char* oilsUtilsLogin( char* uname, char* passwd, char* type, int orgId ) {
  	if(!(uname && passwd)) return NULL;
  
  	osrfLogDebug(OSRF_LOG_MARK, "Logging in with username %s", uname );
--- 176,182 ----
  
  
  
! 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,192 ****
  	jsonObject* o = oilsUtilsQuickReq( 
  		"open-ils.auth", "open-ils.auth.authenticate.init", params );
  
! 	char* seed = jsonObjectGetString(o);
  	char* passhash = md5sum(passwd);
  	char buf[256];
  	snprintf(buf, sizeof(buf), "%s%s", seed, passhash);
--- 187,193 ----
  	jsonObject* o = oilsUtilsQuickReq( 
  		"open-ils.auth", "open-ils.auth.authenticate.init", params );
  
! 	const char* seed = jsonObjectGetString(o);
  	char* passhash = md5sum(passwd);
  	char buf[256];
  	snprintf(buf, sizeof(buf), "%s%s", seed, passhash);
***************
*** 201,207 ****
  		"open-ils.auth.authenticate.complete", params );
  
  	if(o) {
! 		char* tok = jsonObjectGetString(
  			jsonObjectGetKey(jsonObjectGetKey(o,"payload"), "authtoken"));
  		if(tok) token = strdup(tok);
  	}
--- 202,208 ----
  		"open-ils.auth.authenticate.complete", params );
  
  	if(o) {
! 		const char* tok = jsonObjectGetString(
  			jsonObjectGetKey(jsonObjectGetKey(o,"payload"), "authtoken"));
  		if(tok) token = strdup(tok);
  	}
***************
*** 223,229 ****
  	return r;
  }
  
! jsonObject* oilsUtilsFetchWorkstationByName( char* name ) {
  	jsonObject* p = jsonParseStringFmt("[\"%s\"]", name);
  	jsonObject* r = oilsUtilsStorageReq(
  		"open-ils.storage.direct.actor.workstation.search.name", p );
--- 224,230 ----
  	return r;
  }
  
! jsonObject* oilsUtilsFetchWorkstationByName( const char* name ) {
  	jsonObject* p = jsonParseStringFmt("[\"%s\"]", name);
  	jsonObject* r = oilsUtilsStorageReq(
  		"open-ils.storage.direct.actor.workstation.search.name", p );

Reply via email to