From 3e75330c8f4576eb7f6fff7d43108b336c5dca48 Mon Sep 17 00:00:00 2001 From: miker Date: Sun, 30 Sep 2007 14:03:19 +0000 Subject: [PATCH] Patch from Scott McKellar which introduces a const-accepting and -returning version of jsonObjectGetKey. This is the first step in a plan to push const-correctness on the OpenSRF stack when dealing with complex objects. The hope is that this will increase the utility of compile-time checks in new client code. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1093 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/osrf_json.h | 2 +- src/libopensrf/osrf_json_object.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/opensrf/osrf_json.h b/include/opensrf/osrf_json.h index 23eabda..9acb6e5 100644 --- a/include/opensrf/osrf_json.h +++ b/include/opensrf/osrf_json.h @@ -224,7 +224,7 @@ char* jsonObjectToJSONRaw( const jsonObject* obj ); * Retrieves the object at the given key */ jsonObject* jsonObjectGetKey( const jsonObject* obj, const char* key ); - +const jsonObject* jsonObjectGetKeyConst( const jsonObject* obj, const char* key ); diff --git a/src/libopensrf/osrf_json_object.c b/src/libopensrf/osrf_json_object.c index 0b1ffd4..878e3ee 100644 --- a/src/libopensrf/osrf_json_object.c +++ b/src/libopensrf/osrf_json_object.c @@ -132,6 +132,11 @@ jsonObject* jsonObjectGetKey( const jsonObject* obj, const char* key ) { return osrfHashGet( obj->value.h, key); } +const jsonObject* jsonObjectGetKeyConst( const jsonObject* obj, const char* key ) { + if(!(obj && obj->type == JSON_HASH && obj->value.h && key)) return NULL; + return osrfHashGet( obj->value.h, key); +} + char* jsonObjectToJSON( const jsonObject* obj ) { jsonObject* obj2 = jsonObjectEncodeClass( (jsonObject*) obj); char* json = jsonObjectToJSONRaw(obj2); -- 2.11.0