[open-ils-commits] r8678 - branches/acq-experiment/Open-ILS/src/c-apps

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Feb 6 20:55:38 EST 2008


Author: miker
Date: 2008-02-06 20:27:07 -0500 (Wed, 06 Feb 2008)
New Revision: 8678

Modified:
   branches/acq-experiment/Open-ILS/src/c-apps/oils_cstore.c
Log:
merging recent cstore fixes with acq branch

Modified: branches/acq-experiment/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- branches/acq-experiment/Open-ILS/src/c-apps/oils_cstore.c	2008-02-07 01:26:36 UTC (rev 8677)
+++ branches/acq-experiment/Open-ILS/src/c-apps/oils_cstore.c	2008-02-07 01:27:07 UTC (rev 8678)
@@ -191,7 +191,7 @@
 			char* readonly = osrfHashGet(idlClass, "readonly");
 			if (	readonly &&
 				!strncasecmp( "true", readonly, 4) &&
-				( *method_type == 's' || *method_type == 'r' || *method_type == 'i')
+				( *method_type == 'c' || *method_type == 'u' || *method_type == 'd')
 			) continue;
 
 			method_meta = osrfNewHash();
@@ -463,8 +463,6 @@
 int setSavepoint ( osrfMethodContext* ctx ) {
 	OSRF_METHOD_VERIFY_CONTEXT(ctx);
 
-	char* spName = jsonObjectToSimpleString(jsonObjectGetIndex(ctx->params, 0));
-
 	if (!osrfHashGet( (osrfHash*)ctx->session->userData, "xact_id" )) {
 		osrfAppSessionStatus(
 			ctx->session,
@@ -476,6 +474,8 @@
 		return -1;
 	}
 
+	char* spName = jsonObjectToSimpleString(jsonObjectGetIndex(ctx->params, 0));
+
 	dbi_result result = dbi_conn_queryf(writehandle, "SAVEPOINT \"%s\";", spName);
 	if (!result) {
 		osrfLogError(
@@ -486,20 +486,20 @@
 			osrfHashGet( (osrfHash*)ctx->session->userData, "xact_id" )
 		);
 		osrfAppSessionStatus( ctx->session, OSRF_STATUS_INTERNALSERVERERROR, "osrfMethodException", ctx->request, "Error creating savepoint" );
+		free(spName);
 		return -1;
 	} else {
 		jsonObject* ret = jsonNewObject(spName);
 		osrfAppRespondComplete( ctx, ret );
 		jsonObjectFree(ret);
 	}
+	free(spName);
 	return 0;
 }
 
 int releaseSavepoint ( osrfMethodContext* ctx ) {
 	OSRF_METHOD_VERIFY_CONTEXT(ctx);
 
-	char* spName = jsonObjectToSimpleString(jsonObjectGetIndex(ctx->params, 0));
-
 	if (!osrfHashGet( (osrfHash*)ctx->session->userData, "xact_id" )) {
 		osrfAppSessionStatus(
 			ctx->session,
@@ -511,6 +511,8 @@
 		return -1;
 	}
 
+	char* spName = jsonObjectToSimpleString(jsonObjectGetIndex(ctx->params, 0));
+
 	dbi_result result = dbi_conn_queryf(writehandle, "RELEASE SAVEPOINT \"%s\";", spName);
 	if (!result) {
 		osrfLogError(
@@ -521,20 +523,20 @@
 			osrfHashGet( (osrfHash*)ctx->session->userData, "xact_id" )
 		);
 		osrfAppSessionStatus( ctx->session, OSRF_STATUS_INTERNALSERVERERROR, "osrfMethodException", ctx->request, "Error releasing savepoint" );
+		free(spName);
 		return -1;
 	} else {
 		jsonObject* ret = jsonNewObject(spName);
 		osrfAppRespondComplete( ctx, ret );
 		jsonObjectFree(ret);
 	}
+	free(spName);
 	return 0;
 }
 
 int rollbackSavepoint ( osrfMethodContext* ctx ) {
 	OSRF_METHOD_VERIFY_CONTEXT(ctx);
 
-	char* spName = jsonObjectToSimpleString(jsonObjectGetIndex(ctx->params, 0));
-
 	if (!osrfHashGet( (osrfHash*)ctx->session->userData, "xact_id" )) {
 		osrfAppSessionStatus(
 			ctx->session,
@@ -546,6 +548,8 @@
 		return -1;
 	}
 
+	char* spName = jsonObjectToSimpleString(jsonObjectGetIndex(ctx->params, 0));
+
 	dbi_result result = dbi_conn_queryf(writehandle, "ROLLBACK TO SAVEPOINT \"%s\";", spName);
 	if (!result) {
 		osrfLogError(
@@ -556,12 +560,14 @@
 			osrfHashGet( (osrfHash*)ctx->session->userData, "xact_id" )
 		);
 		osrfAppSessionStatus( ctx->session, OSRF_STATUS_INTERNALSERVERERROR, "osrfMethodException", ctx->request, "Error rolling back savepoint" );
+		free(spName);
 		return -1;
 	} else {
 		jsonObject* ret = jsonNewObject(spName);
 		osrfAppRespondComplete( ctx, ret );
 		jsonObjectFree(ret);
 	}
+	free(spName);
 	return 0;
 }
 
@@ -922,11 +928,19 @@
 			id = buffer_release(_id);
 		}
 
-		if (	!options
-			|| !jsonObjectGetKeyConst( options, "quiet")
-			|| strcmp( jsonObjectToSimpleString(jsonObjectGetKeyConst( options, "quiet")), "true" )
-		) {
+		// Find quietness specification, if present
+		char* quiet_str = NULL;
+		if ( options ) {
+			const jsonObject* quiet_obj = jsonObjectGetKeyConst( options, "quiet" );
+			if( quiet_obj )
+				quiet_str = jsonObjectToSimpleString( quiet_obj );
+		}
 
+		if( quiet_str && !strcmp( quiet_str, "true" )) {  // if quietness is specified
+			obj = jsonNewObject(id);
+		}
+		else {
+
 			jsonObject* fake_params = jsonParseString("[]");
 			jsonObjectPush(fake_params, jsonParseString("{}"));
 
@@ -947,11 +961,9 @@
 
 			jsonObjectFree( list );
 			jsonObjectFree( fake_params );
-
-		} else {
-			obj = jsonNewObject(id);
 		}
 
+		if(quiet_str) free(quiet_str);
 		free(id);
 	}
 
@@ -988,6 +1000,8 @@
 		jsonParseString(id)
 	);
 
+	free(id);
+
 	if (order_hash) jsonObjectPush(fake_params, jsonObjectClone(order_hash) );
 
 	jsonObject* list = doFieldmapperSearch( ctx,meta, fake_params, err);
@@ -1010,11 +1024,19 @@
 
 	if ( !strncmp(osrfHashGet(field, "datatype"), "INT", (size_t)3) ) {
 		if (value->type == JSON_NUMBER) buffer_fadd( val_buf, "%ld", (long)jsonObjectGetNumber(value) );
-		else buffer_fadd( val_buf, "%ld", atol(jsonObjectToSimpleString(value)) );
+		else {
+			char* val_str = jsonObjectToSimpleString(value);
+			buffer_fadd( val_buf, "%ld", atol(val_str) );
+			free(val_str);
+		}
 
 	} else if ( !strcmp(osrfHashGet(field, "datatype"), "NUMERIC") ) {
 		if (value->type == JSON_NUMBER) buffer_fadd( val_buf, "%f",  jsonObjectGetNumber(value) );
-		else buffer_fadd( val_buf, "%f", atof(jsonObjectToSimpleString(value)) );
+		else {
+			char* val_str = jsonObjectToSimpleString(value);
+			buffer_fadd( val_buf, "%f", atof(val_str) );
+			free(val_str);
+		}
 	}
 
 	return buffer_release(val_buf);
@@ -1160,10 +1182,12 @@
         		} else {
 	        		osrfLogError(OSRF_LOG_MARK, "%s: Error quoting key string [%s]", MODULENAME, val);
 		    	    free(field_transform);
+					free(val);
         			buffer_free(sql_buf);
 	        		return NULL;
     	    	}
-    	    }
+				free(val);
+			}
 
         }
 
@@ -1414,15 +1438,9 @@
 
 		char* class = osrfHashGet(idlClass, "classname");
 
-		char* table = getSourceDefinition(idlClass);
-		char* type = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode->item, "type" ) );
-		char* filter_op = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode->item, "filter_op" ) );
 		char* fkey = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode->item, "fkey" ) );
 		char* field = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode->item, "field" ) );
 
-		const jsonObject* filter = jsonObjectGetKeyConst( snode->item, "filter" );
-		const jsonObject* join_filter = jsonObjectGetKeyConst( snode->item, "join" );
-
 		if (field && !fkey) {
 			fkey = (char*)oilsIDLFindPath("/%s/links/%s/key", class, field);
 			if (!fkey) {
@@ -1435,7 +1453,7 @@
 					leftclass
 				);
 				buffer_free(join_buf);
-				free(table);
+				free(field);
 				return NULL;
 			}
 			fkey = strdup( fkey );
@@ -1452,7 +1470,7 @@
 					class
 				);
 				buffer_free(join_buf);
-				free(table);
+				free(fkey);
 				return NULL;
 			}
 			field = strdup( field );
@@ -1499,12 +1517,12 @@
 					class
 				);
 				buffer_free(join_buf);
-				free(table);
 				return NULL;
 			}
 
 		}
 
+		char* type = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode->item, "type" ) );
 		if (type) {
 			if ( !strcasecmp(type,"left") ) {
 				buffer_add(join_buf, " LEFT JOIN");
@@ -1518,11 +1536,15 @@
 		} else {
 			buffer_add(join_buf, " INNER JOIN");
 		}
+		free(type);
 
+		char* table = getSourceDefinition(idlClass);
 		buffer_fadd(join_buf, " %s AS \"%s\" ON ( \"%s\".%s = \"%s\".%s", table, class, class, field, leftclass, fkey);
 		free(table);
 
+		const jsonObject* filter = jsonObjectGetKeyConst( snode->item, "filter" );
 		if (filter) {
+			char* filter_op = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode->item, "filter_op" ) );
 			if (filter_op) {
 				if (!strcasecmp("or",filter_op)) {
 					buffer_add( join_buf, " OR " );
@@ -1536,18 +1558,18 @@
 			char* jpred = searchWHERE( filter, idlClass, AND_OP_JOIN );
 			buffer_fadd( join_buf, " %s", jpred );
 			free(jpred);
+			free(filter_op);
 		}
 
 		buffer_add(join_buf, " ) ");
 		
+		const jsonObject* join_filter = jsonObjectGetKeyConst( snode->item, "join" );
 		if (join_filter) {
 			char* jpred = searchJOIN( join_filter, idlClass );
 			buffer_fadd( join_buf, " %s", jpred );
 			free(jpred);
 		}
 
-		free(type);
-		free(filter_op);
 		free(fkey);
 		free(field);
 	}
@@ -2227,7 +2249,9 @@
 
 		jsonObjectIterator* select_itr = jsonNewObjectIterator( snode->item );
 		while ( (node = jsonObjectIteratorNext( select_itr )) ) {
-			osrfHash* field = osrfHashGet( osrfHashGet( idlClass, "fields" ), jsonObjectToSimpleString(node->item) );
+			char* item_str = jsonObjectToSimpleString(node->item);
+			osrfHash* field = osrfHashGet( osrfHashGet( idlClass, "fields" ), item_str );
+			free(item_str);
 			char* fname = osrfHashGet(field, "name");
 
 			if (!field) continue;
@@ -2546,6 +2570,7 @@
 				char* pkey_val = jsonObjectToSimpleString( jsonObjectGetIndex( obj, pkey_pos ) );
 				if ( osrfHashGet( dedup, pkey_val ) ) {
 					jsonObjectFree(obj);
+					free(pkey_val);
 				} else {
 					osrfHashSet( dedup, pkey_val, pkey_val );
 					jsonObjectPush(res_list, obj);



More information about the open-ils-commits mailing list