[open-ils-commits] r13583 - trunk/Open-ILS/src/c-apps (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jul 14 09:30:43 EDT 2009


Author: scottmk
Date: 2009-07-14 09:30:41 -0400 (Tue, 14 Jul 2009)
New Revision: 13583

Modified:
   trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
Tweaks to oils_cstore.c:

1. Added a couple of const qualifiers.

2. In verifyObjectPCRUD: renamed meta to method_metadata, for clarity.
In many places we use "meta" for class metadata.

3. In verifyObjectPCRUD: when looking for the root of the org tree,
build the where clause object directly instead of incurring the overhead
of jsonParseString().

4. A few lines further down: free the where clause object in only
a single place.

5. In single_hash(): represent a NULL value as a JSON_NULL.


Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-07-14 02:38:09 UTC (rev 13582)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-07-14 13:30:41 UTC (rev 13583)
@@ -92,7 +92,7 @@
 static dbi_conn writehandle; /* our MASTER db connection */
 static dbi_conn dbhandle; /* our CURRENT db connection */
 //static osrfHash * readHandles;
-static jsonObject* jsonNULL = NULL; // 
+static jsonObject* const jsonNULL = NULL; // 
 static int max_flesh_depth = 100;
 
 /* called when this process is about to exit */
@@ -932,9 +932,9 @@
 
 	dbhandle = writehandle;
 
-	osrfHash* meta = (osrfHash*) ctx->method->userData;
-	osrfHash* class = osrfHashGet( meta, "class" );
-	const char* method_type = osrfHashGet( meta, "methodtype" );
+	osrfHash* method_metadata = (osrfHash*) ctx->method->userData;
+	osrfHash* class = osrfHashGet( method_metadata, "class" );
+	const char* method_type = osrfHashGet( method_metadata, "methodtype" );
 	int fetch = 0;
 
 	if ( ( *method_type == 's' || *method_type == 'i' ) ) {
@@ -953,7 +953,7 @@
             msg,
             "%s: %s on class %s has no permacrud IDL entry",
             MODULENAME,
-            osrfHashGet(meta, "methodtype"),
+            osrfHashGet(method_metadata, "methodtype"),
             osrfHashGet(class, "classname")
         );
 
@@ -980,24 +980,24 @@
     int err = 0;
     char* pkey_value = NULL;
 	if ( str_is_true( osrfHashGet(pcrud, "global_required") ) ) {
-	    osrfLogDebug( OSRF_LOG_MARK, "global-level permissions required, fetching top of the org tree" );
+		osrfLogDebug( OSRF_LOG_MARK, "global-level permissions required, fetching top of the org tree" );
 
-        // check for perm at top of org tree
-        jsonObject* _tmp_params = jsonParseString("{\"parent_ou\":null}");
+		// check for perm at top of org tree
+		jsonObject* _tmp_params = single_hash( "parent_ou", NULL );
 		jsonObject* _list = doFieldmapperSearch(ctx, osrfHashGet( oilsIDL(), "aou" ),
 				_tmp_params, NULL, &err);
+		jsonObjectFree(_tmp_params);
 
-        jsonObject* _tree_top = jsonObjectGetIndex(_list, 0);
+		jsonObject* _tree_top = jsonObjectGetIndex(_list, 0);
 
-        if (!_tree_top) {
-            jsonObjectFree(_tmp_params);
-            jsonObjectFree(_list);
-    
-            growing_buffer* msg = buffer_init(128);
+		if (!_tree_top) {
+			jsonObjectFree(_list);
+
+			growing_buffer* msg = buffer_init(128);
 			OSRF_BUFFER_ADD( msg, MODULENAME );
 			OSRF_BUFFER_ADD( msg,
 				": Internal error, could not find the top of the org tree (parent_ou = NULL)" );
-    
+
             char* m = buffer_release(msg);
             osrfAppSessionStatus( ctx->session, OSRF_STATUS_INTERNALSERVERERROR, "osrfMethodException", ctx->request, m );
             free(m);
@@ -1008,12 +1008,11 @@
         osrfStringArrayAdd( context_org_array, oilsFMGetString( _tree_top, "id" ) );
 	    osrfLogDebug( OSRF_LOG_MARK, "top of the org tree is %s", osrfStringArrayGetString(context_org_array, 0) );
 
-        jsonObjectFree(_tmp_params);
         jsonObjectFree(_list);
 
     } else {
 	    osrfLogDebug( OSRF_LOG_MARK, "global-level permissions not required, fetching context org ids" );
-	    char* pkey = osrfHashGet(class, "primarykey");
+	    const char* pkey = osrfHashGet(class, "primarykey");
         jsonObject *param = NULL;
 
         if (obj->classname) {
@@ -1026,16 +1025,15 @@
 	        osrfLogDebug( OSRF_LOG_MARK, "Object not supplied, using primary key value of %s and retrieving from the database", pkey_value );
         }
 
-        if (fetch) {
+		if (fetch) {
 			jsonObject* _tmp_params = single_hash( pkey, pkey_value );
 			jsonObject* _list = doFieldmapperSearch( ctx, class, _tmp_params, NULL, &err );
+			jsonObjectFree(_tmp_params);
 
 			param = jsonObjectExtractIndex(_list, 0);
+			jsonObjectFree(_list);
+		}
 
-            jsonObjectFree(_tmp_params);
-            jsonObjectFree(_list);
-        }
-
         if (!param) {
             osrfLogDebug( OSRF_LOG_MARK, "Object not found in the database with primary key %s of %s", pkey, pkey_value );
 
@@ -1305,12 +1303,15 @@
 
 	jsonParseStringFmt( "{\"%s\":\"%s\"}", key, value )
 
+or, if value is NULL:
+
+	jsonParseStringFmt( "{\"%s\":null}", key )
+
 ...but faster because it doesn't create and parse a JSON string.
 */
 static jsonObject* single_hash( const char* key, const char* value ) {
-	// Sanity checks
+	// Sanity check
 	if( ! key ) key = "";
-	if( ! value ) value = "";
 
 	jsonObject* hash = jsonNewObjectType( JSON_HASH );
 	jsonObjectSetKey( hash, key, jsonNewObject( value ) );
@@ -1718,7 +1719,7 @@
 			if ( in_item->type != JSON_STRING && in_item->type != JSON_NUMBER ) {
 				osrfLogError(OSRF_LOG_MARK, "%s: Expected string or number within IN list; found %s",
 						MODULENAME, json_type( in_item->type ) );
-									buffer_free(sql_buf);
+				buffer_free(sql_buf);
 				return NULL;
 			}
 			



More information about the open-ils-commits mailing list