[Opensrf-commits] r1068 - trunk/src/gateway

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Aug 2 22:21:11 EDT 2007


Author: miker
Date: 2007-08-02 22:19:02 -0400 (Thu, 02 Aug 2007)
New Revision: 1068

Modified:
   trunk/src/gateway/osrf_json_gateway.c
Log:
formatting fixes; protect against NULL apache setting

Modified: trunk/src/gateway/osrf_json_gateway.c
===================================================================
--- trunk/src/gateway/osrf_json_gateway.c	2007-08-02 03:03:35 UTC (rev 1067)
+++ trunk/src/gateway/osrf_json_gateway.c	2007-08-03 02:19:02 UTC (rev 1068)
@@ -126,10 +126,10 @@
 	char* (*jsonToStringFunc) (const jsonObject*) = legacy_jsonObjectToJSON;
 
 	if(dir_conf->legacyJSON) {
-	    ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Using legacy JSON");
+		ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Using legacy JSON");
 
-    } else {
-	    ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Not using legacy JSON");
+	} else {
+		ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Not using legacy JSON");
 		parseJSONFunc = jsonParseString;
 		jsonToStringFunc = jsonObjectToJSON;
 	}
@@ -152,39 +152,38 @@
 	char* service		= NULL;	/* service to connect to */
 	char* method		= NULL;	/* method to perform */
 	char* format		= NULL;	/* method to perform */
-	char* a_l			= NULL;	/* request api level */
-    char* input_format  = NULL; /* POST data format, defaults to 'format' */
-	int   isXML			= 0;
-	int   api_level	= 1;
+	char* a_l		= NULL;	/* request api level */
+	char* input_format	= NULL; /* POST data format, defaults to 'format' */
+	int   isXML		= 0;
+	int   api_level		= 1;
 
 	r->allowed |= (AP_METHOD_BIT << M_GET);
 	r->allowed |= (AP_METHOD_BIT << M_POST);
 
 	osrfLogDebug(OSRF_LOG_MARK, "osrf gateway: parsing URL params");
 	string_array* mparams	= NULL;
-	string_array* params		= apacheParseParms(r); /* free me */
+	string_array* params	= apacheParseParms(r); /* free me */
 	param_locale		= apacheGetFirstParamValue( params, "locale" );
-	service		= apacheGetFirstParamValue( params, "service" );
-	method		= apacheGetFirstParamValue( params, "method" ); 
-	format		= apacheGetFirstParamValue( params, "format" ); 
-	input_format = apacheGetFirstParamValue( params, "input_format" ); 
+	service			= apacheGetFirstParamValue( params, "service" );
+	method			= apacheGetFirstParamValue( params, "method" ); 
+	format			= apacheGetFirstParamValue( params, "format" ); 
+	input_format		= apacheGetFirstParamValue( params, "input_format" ); 
 	a_l			= apacheGetFirstParamValue( params, "api_level" ); 
-	mparams		= apacheGetParamValues( params, "param" ); /* free me */
+	mparams			= apacheGetParamValues( params, "param" ); /* free me */
 
-    if(format == NULL)
-        format = "json";
-    if(input_format == NULL)
-        input_format = format;
+	if(format == NULL)
+		format = "json";
+	if(input_format == NULL)
+		input_format = format;
 
-   /* set the user defined timeout value */
-   int timeout = 60;
-   char* tout = apacheGetFirstParamValue( params, "timeout" ); /* request timeout in seconds */
-   if( tout ) {
-      timeout = atoi(tout);
-      osrfLogDebug(OSRF_LOG_MARK, "Client supplied timeout of %d", timeout);
-   }
+	/* set the user defined timeout value */
+	int timeout = 60;
+	char* tout = apacheGetFirstParamValue( params, "timeout" ); /* request timeout in seconds */
+	if( tout ) {
+		timeout = atoi(tout);
+		osrfLogDebug(OSRF_LOG_MARK, "Client supplied timeout of %d", timeout);
+	}
 
-
 	if (a_l)
 		api_level = atoi(a_l);
 
@@ -255,35 +254,36 @@
 		double starttime = get_timestamp_millis();
 		int req_id = -1;
 
-        if(!strcasecmp(input_format, "json")) {
-            jsonObject * arr = jsonNewObject(NULL);
-            char* str;
-            int i = 0;
-            while( (str = osrfStringArrayGetString(mparams, i++)) ) 
-                jsonObjectPush(arr, parseJSONFunc(str));
+		if(!strcasecmp(input_format, "json")) {
+			jsonObject * arr = jsonNewObject(NULL);
 
-		    req_id = osrf_app_session_make_req( session, arr, method, api_level, NULL );
+			char* str;
+			int i = 0;
 
-        } else {
+			while( (str = osrfStringArrayGetString(mparams, i++)) ) 
+				jsonObjectPush(arr, parseJSONFunc(str));
 
-            /**
-             * If we receive XML method params, convert each param to a JSON object
-             * and pass the array of JSON object params to the method */
-            if(!strcasecmp(input_format, "xml")) {
-                jsonObject* jsonParams = jsonNewObject(NULL);
+			req_id = osrf_app_session_make_req( session, arr, method, api_level, NULL );
+		} else {
 
-                char* str;
-                int i = 0;
-                while( (str = osrfStringArrayGetString(mparams, i++)) ) {
-                    jsonObjectPush(jsonParams, jsonXMLToJSONObject(str));
-                }
+			/**
+			* If we receive XML method params, convert each param to a JSON object
+			* and pass the array of JSON object params to the method */
+			if(!strcasecmp(input_format, "xml")) {
+				jsonObject* jsonParams = jsonNewObject(NULL);
 
-		        req_id = osrf_app_session_make_req( session, jsonParams, method, api_level, NULL );
-                jsonObjectFree(jsonParams);
-            }
-        }
+				char* str;
+				int i = 0;
+				while( (str = osrfStringArrayGetString(mparams, i++)) ) {
+					jsonObjectPush(jsonParams, jsonXMLToJSONObject(str));
+				}
 
+				req_id = osrf_app_session_make_req( session, jsonParams, method, api_level, NULL );
+				jsonObjectFree(jsonParams);
+			}
+		}
 
+
 		if( req_id == -1 ) {
 			osrfLogError(OSRF_LOG_MARK, "I am unable to communcate with opensrf..going away...");
 			/* we don't want to spawn an intense re-forking storm 
@@ -302,7 +302,7 @@
 		char* str; int i = 0;
 		while( (str = osrfStringArrayGetString(mparams, i++)) ) {
 			if( i == 1 ) {
-            OSRF_BUFFER_ADD(act, " ");
+				OSRF_BUFFER_ADD(act, " ");
 				OSRF_BUFFER_ADD(act, str);
 			} else {
 				OSRF_BUFFER_ADD(act, ", ");
@@ -340,7 +340,7 @@
 				if (isXML) {
 					output = jsonObjectToXML( res );
 				} else {
-                    output = jsonToStringFunc( res );
+					output = jsonToStringFunc( res );
 					if( morethan1 ) ap_rputs(",", r); /* comma between JSON array items */
 				}
 				ap_rputs(output, r);
@@ -386,7 +386,7 @@
 				bzero(bb, l);
 				snprintf(bb, l,  "%s : %s", statusname, statustext);
 				jsonObject* tmp = jsonNewObject(bb);
-                char* j = jsonToStringFunc(tmp);
+				char* j = jsonToStringFunc(tmp);
 				snprintf( buf, l, ",\"debug\": %s", j);
 				free(j);
 				jsonObjectFree(tmp);
@@ -423,7 +423,7 @@
 	string_array_destroy(mparams);
 
 	osrfLogDebug(OSRF_LOG_MARK, "Gateway served %d requests", ++numserved);
-   osrfLogClearXid();
+	osrfLogClearXid();
 
 	return ret;
 }



More information about the opensrf-commits mailing list