[Opensrf-commits] r1805 - trunk/src/libopensrf (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Oct 4 22:01:41 EDT 2009


Author: scottmk
Date: 2009-10-04 22:01:39 -0400 (Sun, 04 Oct 2009)
New Revision: 1805

Modified:
   trunk/src/libopensrf/osrf_json_tools.c
Log:
Tweak jsonObjectDecodeClass so that it preserves classnames
that are already present.  The previous version would add
new classnames, if it found them encoded, but would drop
any old ones.

At present this change will have no effect.  Apart from a
couple of recursive calls, the only function that calls
jsonObjectDecodeClass() is jsonParseString().  In that case,
we pass a freshly parsed jsonObject that can't possibly
have any classnames yet.

However this change will enable us to use this function
elsewhere (specifically in osrf_message.c), resulting in
simpler and faster code.

M    src/libopensrf/osrf_json_tools.c


Modified: trunk/src/libopensrf/osrf_json_tools.c
===================================================================
--- trunk/src/libopensrf/osrf_json_tools.c	2009-10-04 15:13:36 UTC (rev 1804)
+++ trunk/src/libopensrf/osrf_json_tools.c	2009-10-05 02:01:39 UTC (rev 1805)
@@ -21,6 +21,13 @@
 static jsonObject* findMultiPathRecurse( const jsonObject* o, const char* root );
 static jsonObject* _jsonObjectEncodeClass( const jsonObject* obj, int ignoreClass );
 
+/**
+	@brief Append some spaces to a growing_buffer, for indentation.
+	@param buf Pointer to the growing_buffer.
+	@param depth Degree of indentation.
+
+	We append 2 spaces per degree of indentation.
+*/
 static void append_indentation( growing_buffer* buf, int depth ) {
 	size_t n = 2 * depth;
 	char indent[ n ];
@@ -28,6 +35,18 @@
 	buffer_add_n( buf, indent, n );
 }
 
+/**
+	@brief Make a prettyprint copy of a JSON string.
+	@param string Pointer to the JSON string to be formatted.
+	@return Pointer to a newly allocated and reformatted JSON string.
+
+	Create a copy of the input JSON string, with newlines and
+	indentation for readability.
+
+	If the input pointer is NULL, return an empty string.
+
+	The calling code is responsible for freeing the formatted copy.
+*/
 char* jsonFormatString( const char* string ) {
 	if(!string) return strdup("");
 
@@ -81,7 +100,7 @@
 
 			/* do we have a payload */
 			if( (payloadObj = jsonObjectGetKeyConst( obj, JSON_DATA_KEY )) ) {
-				newObj = jsonObjectDecodeClass( payloadObj ); 
+				newObj = jsonObjectDecodeClass( payloadObj );
 				jsonObjectSetClass( newObj, jsonObjectGetString(classObj) );
 
 			} else { /* class is defined but there is no payload */
@@ -98,6 +117,8 @@
 				jsonObjectSetKey( newObj, itr->key, o );
 			}
 			jsonIteratorFree(itr);
+			if( obj->classname )
+				jsonObjectSetClass( newObj, obj->classname );
 		}
 
 	} else {
@@ -108,6 +129,8 @@
 				jsonObject* tmp = jsonObjectDecodeClass(jsonObjectGetIndex( obj, i ) );
 				jsonObjectSetIndex( newObj, i, tmp );
 			}
+			if( obj->classname )
+				jsonObjectSetClass( newObj, obj->classname );
 
 		} else { /* not an aggregate type */
 			newObj = jsonObjectClone(obj);



More information about the opensrf-commits mailing list