[Opensrf-commits] r1114 - in trunk: include/opensrf src/gateway src/libopensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Oct 25 08:34:08 EDT 2007


Author: miker
Date: 2007-10-25 08:20:16 -0400 (Thu, 25 Oct 2007)
New Revision: 1114

Modified:
   trunk/include/opensrf/osrf_json.h
   trunk/include/opensrf/osrf_legacy_json.h
   trunk/src/gateway/osrf_json_gateway.c
   trunk/src/libopensrf/osrf_json_parser.c
   trunk/src/libopensrf/osrf_legacy_json.c
Log:
Patch from Scott McKellar to increase const correctness in the JSON parser.

Also made the top level legacy_jsonParseString[Fmt] API const-correct, though this is removed within those wrapper calls to avoid potentially breaking the legacy code.



Modified: trunk/include/opensrf/osrf_json.h
===================================================================
--- trunk/include/opensrf/osrf_json.h	2007-10-25 12:04:05 UTC (rev 1113)
+++ trunk/include/opensrf/osrf_json.h	2007-10-25 12:20:16 UTC (rev 1114)
@@ -73,7 +73,7 @@
 
 struct jsonParserContextStruct {
 	int state;						/* what are we currently parsing */
-	char* chunk;					/* the chunk we're currently parsing */
+	const char* chunk;				/* the chunk we're currently parsing */
 	int index;						/* where we are in parsing the current chunk */
 	int chunksize;					/* the size of the current chunk */
 	int flags;						/* parser flags */
@@ -147,7 +147,7 @@
  * @param datalen The size of the chunk to parser
  * @param flags Reserved
  */
-int jsonParseChunk( jsonParserContext* ctx, char* data, int datalen, int flags );
+int jsonParseChunk( jsonParserContext* ctx, const char* data, int datalen, int flags );
 
 
 /**
@@ -155,10 +155,10 @@
  * @param str The string to parser
  * @return The resulting JSON object or NULL on error
  */
-jsonObject* jsonParseString( char* str );
-jsonObject* jsonParseStringRaw( char* str );
+jsonObject* jsonParseString( const char* str );
+jsonObject* jsonParseStringRaw( const char* str );
 
-jsonObject* jsonParseStringFmt( char* str, ... );
+jsonObject* jsonParseStringFmt( const char* str, ... );
 
 /**
  * Parses a JSON string;

Modified: trunk/include/opensrf/osrf_legacy_json.h
===================================================================
--- trunk/include/opensrf/osrf_legacy_json.h	2007-10-25 12:04:05 UTC (rev 1113)
+++ trunk/include/opensrf/osrf_legacy_json.h	2007-10-25 12:20:16 UTC (rev 1114)
@@ -33,8 +33,8 @@
 
 jsonObject* json_parse_string(char* string);
 
-jsonObject* legacy_jsonParseString(char* string);
-jsonObject* legacy_jsonParseStringFmt( char* string, ... );
+jsonObject* legacy_jsonParseString(const char* string);
+jsonObject* legacy_jsonParseStringFmt( const char* string, ... );
 
 jsonObject* json_parse_file( const char* filename );
 

Modified: trunk/src/gateway/osrf_json_gateway.c
===================================================================
--- trunk/src/gateway/osrf_json_gateway.c	2007-10-25 12:04:05 UTC (rev 1113)
+++ trunk/src/gateway/osrf_json_gateway.c	2007-10-25 12:20:16 UTC (rev 1114)
@@ -122,7 +122,7 @@
 
 
 	/* provide 2 different JSON parsers and serializers to support legacy JSON */
-	jsonObject* (*parseJSONFunc) (char*) = legacy_jsonParseString;
+	jsonObject* (*parseJSONFunc) (const char*) = legacy_jsonParseString;
 	char* (*jsonToStringFunc) (const jsonObject*) = legacy_jsonObjectToJSON;
 
 	if(dir_conf->legacyJSON) {

Modified: trunk/src/libopensrf/osrf_json_parser.c
===================================================================
--- trunk/src/libopensrf/osrf_json_parser.c	2007-10-25 12:04:05 UTC (rev 1113)
+++ trunk/src/libopensrf/osrf_json_parser.c	2007-10-25 12:20:16 UTC (rev 1114)
@@ -332,7 +332,7 @@
 
 
 
-int jsonParseChunk( jsonParserContext* ctx, char* data, int datalen, int flags ) {
+int jsonParseChunk( jsonParserContext* ctx, const char* data, int datalen, int flags ) {
 
 	if( !( ctx && ctx->handler && data && datalen > 0 )) return -1;
 	ctx->chunksize  = datalen;
@@ -514,7 +514,7 @@
 	free(p);
 }
 
-static jsonObject* _jsonParseStringImpl(char* str, void (*errorHandler) (const char*) ) {
+static jsonObject* _jsonParseStringImpl(const char* str, void (*errorHandler) (const char*) ) {
 	jsonInternalParser* parser = _jsonNewInternalParser();
 	parser->handleError = errorHandler;
 	jsonParseChunk( parser->ctx, str, strlen(str),  JSON_PARSE_LAST_CHUNK );
@@ -530,7 +530,7 @@
 	return _jsonParseStringImpl(VA_BUF, errorHandler);
 }
 
-jsonObject* jsonParseString( char* str ) {
+jsonObject* jsonParseString( const char* str ) {
 	if(!str) return NULL;
 	jsonObject* obj =  _jsonParseStringImpl(str, NULL);
 	jsonObject* obj2 = jsonObjectDecodeClass(obj);
@@ -538,12 +538,12 @@
 	return obj2;
 }
 
-jsonObject* jsonParseStringRaw( char* str ) {
+jsonObject* jsonParseStringRaw( const char* str ) {
 	if(!str) return NULL;
 	return _jsonParseStringImpl(str, NULL);
 }
 
-jsonObject* jsonParseStringFmt( char* str, ... ) {
+jsonObject* jsonParseStringFmt( const char* str, ... ) {
 	if(!str) return NULL;
 	VA_LIST_TO_STRING(str);
 	return _jsonParseStringImpl(VA_BUF, NULL);

Modified: trunk/src/libopensrf/osrf_legacy_json.c
===================================================================
--- trunk/src/libopensrf/osrf_legacy_json.c	2007-10-25 12:04:05 UTC (rev 1113)
+++ trunk/src/libopensrf/osrf_legacy_json.c	2007-10-25 12:20:16 UTC (rev 1114)
@@ -22,11 +22,11 @@
 int current_strlen; 
 
 
-jsonObject* legacy_jsonParseString( char* string) {
-	return json_parse_string( string );
+jsonObject* legacy_jsonParseString( const char* string) {
+	return json_parse_string( (char*) string );
 }
 
-jsonObject* legacy_jsonParseStringFmt( char* string, ... ) {
+jsonObject* legacy_jsonParseStringFmt( const char* string, ... ) {
 	VA_LIST_TO_STRING(string);
 	return json_parse_string( VA_BUF );
 }



More information about the opensrf-commits mailing list