From 0fd36820934ad7d78b1733afa4277e87da2d92fd Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 25 Oct 2007 12:20:16 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1114 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/osrf_json.h | 10 +++++----- include/opensrf/osrf_legacy_json.h | 4 ++-- src/gateway/osrf_json_gateway.c | 2 +- src/libopensrf/osrf_json_parser.c | 10 +++++----- src/libopensrf/osrf_legacy_json.c | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/opensrf/osrf_json.h b/include/opensrf/osrf_json.h index 5243f03..64844fd 100644 --- a/include/opensrf/osrf_json.h +++ b/include/opensrf/osrf_json.h @@ -73,7 +73,7 @@ GNU General Public License for more details. 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 @@ void jsonParserFree( jsonParserContext* ctx ); * @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 @@ int jsonParseChunk( jsonParserContext* ctx, char* data, int datalen, int flags ) * @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; diff --git a/include/opensrf/osrf_legacy_json.h b/include/opensrf/osrf_legacy_json.h index a79fbbe..a825a8d 100644 --- a/include/opensrf/osrf_legacy_json.h +++ b/include/opensrf/osrf_legacy_json.h @@ -33,8 +33,8 @@ GNU General Public License for more details. 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 ); diff --git a/src/gateway/osrf_json_gateway.c b/src/gateway/osrf_json_gateway.c index 4c6a247..cce7e8b 100644 --- a/src/gateway/osrf_json_gateway.c +++ b/src/gateway/osrf_json_gateway.c @@ -122,7 +122,7 @@ static int osrf_json_gateway_method_handler (request_rec *r) { /* 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) { diff --git a/src/libopensrf/osrf_json_parser.c b/src/libopensrf/osrf_json_parser.c index 14cb45c..e7b3f26 100644 --- a/src/libopensrf/osrf_json_parser.c +++ b/src/libopensrf/osrf_json_parser.c @@ -332,7 +332,7 @@ int _jsonParserHandleNumber( jsonParserContext* ctx ) { -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 @@ void _jsonInternalParserFree(jsonInternalParser* p) { 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 @@ jsonObject* jsonParseStringHandleError( 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 @@ jsonObject* jsonParseString( char* str ) { 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); diff --git a/src/libopensrf/osrf_legacy_json.c b/src/libopensrf/osrf_legacy_json.c index ae75588..a81d46d 100644 --- a/src/libopensrf/osrf_legacy_json.c +++ b/src/libopensrf/osrf_legacy_json.c @@ -22,11 +22,11 @@ GNU General Public License for more details. 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 ); } -- 2.43.2