This patch extends a bit more const-correctness into osrf_message.c.

1. It replaces jsonObjectGetKey() with jsonObjectGetKeyConst().

2. It uses const pointers, instead of non-const pointers, to capture
the return values of jsonObjectGetIndex() and jsonObjectGetString().

The use of jsonObjectGetKeyConst() requires the prior application of
a previous pair of patches from yesterday.

Scott McKellar
http://home.swbell.net/mck9/ct/

Developer's Certificate of Origin 1.1 By making a contribution to
this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license indicated
in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source license
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under the
same open source license (unless I am permitted to submit under a
different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it; and

(d) In the case of each of (a), (b), or (c), I understand and agree
that this project and the contribution are public and that a record
of the contribution (including all personal information I submit
with it, including my sign-off) is maintained indefinitely and may
be redistributed consistent with this project or the open source
license indicated in the file.
*** trunk/src/libopensrf/osrf_message.c	2007-09-22 09:14:45.000000000 -0500
--- trunk-mod/src/libopensrf/osrf_message.c	2007-09-23 09:20:40.000000000 -0500
***************
*** 256,271 ****
  
  	for( x = 0; x < json->size && x < count; x++ ) {
  
! 		jsonObject* message = jsonObjectGetIndex(json, x);
  
  		if(message && message->type != JSON_NULL && 
  			message->classname && !strcmp(message->classname, "osrfMessage")) {
  
  			osrf_message* new_msg = safe_malloc(sizeof(osrf_message));
  
! 			jsonObject* tmp = jsonObjectGetKey(message, "type");
  
! 			char* t;
  			if( ( t = jsonObjectGetString(tmp)) ) {
  
  				if(!strcmp(t, "CONNECT")) 		new_msg->m_type = CONNECT;
--- 256,271 ----
  
  	for( x = 0; x < json->size && x < count; x++ ) {
  
! 		const jsonObject* message = jsonObjectGetIndex(json, x);
  
  		if(message && message->type != JSON_NULL && 
  			message->classname && !strcmp(message->classname, "osrfMessage")) {
  
  			osrf_message* new_msg = safe_malloc(sizeof(osrf_message));
  
! 			const jsonObject* tmp = jsonObjectGetKeyConst(message, "type");
  
! 			const char* t;
  			if( ( t = jsonObjectGetString(tmp)) ) {
  
  				if(!strcmp(t, "CONNECT")) 		new_msg->m_type = CONNECT;
***************
*** 275,281 ****
  				if(!strcmp(t, "RESULT")) 		new_msg->m_type = RESULT;
  			}
  
! 			tmp = jsonObjectGetKey(message, "threadTrace");
  			if(tmp) {
  				char* tt = jsonObjectToSimpleString(tmp);
  				if(tt) {
--- 275,281 ----
  				if(!strcmp(t, "RESULT")) 		new_msg->m_type = RESULT;
  			}
  
! 			tmp = jsonObjectGetKeyConst(message, "threadTrace");
  			if(tmp) {
  				char* tt = jsonObjectToSimpleString(tmp);
  				if(tt) {
***************
*** 288,294 ****
  			if (current_locale)
  				free( current_locale );
  
! 			tmp = jsonObjectGetKey(message, "locale");
  			if(tmp) {
  				new_msg->sender_locale = jsonObjectToSimpleString(tmp);
  				current_locale = strdup( new_msg->sender_locale );
--- 288,294 ----
  			if (current_locale)
  				free( current_locale );
  
! 			tmp = jsonObjectGetKeyConst(message, "locale");
  			if(tmp) {
  				new_msg->sender_locale = jsonObjectToSimpleString(tmp);
  				current_locale = strdup( new_msg->sender_locale );
***************
*** 296,302 ****
  				current_locale = NULL;
  			}
  
! 			tmp = jsonObjectGetKey(message, "protocol");
  
  			if(tmp) {
  				char* proto = jsonObjectToSimpleString(tmp);
--- 296,302 ----
  				current_locale = NULL;
  			}
  
! 			tmp = jsonObjectGetKeyConst(message, "protocol");
  
  			if(tmp) {
  				char* proto = jsonObjectToSimpleString(tmp);
***************
*** 306,321 ****
  				}
  			}
  
! 			tmp = jsonObjectGetKey(message, "payload");
  			if(tmp) {
  				if(tmp->classname)
  					new_msg->status_name = strdup(tmp->classname);
  
! 				jsonObject* tmp0 = jsonObjectGetKey(tmp,"method");
  				if(jsonObjectGetString(tmp0))
  					new_msg->method_name = strdup(jsonObjectGetString(tmp0));
  
! 				tmp0 = jsonObjectGetKey(tmp,"params");
  				if(tmp0) {
  					char* s = jsonObjectToJSON(tmp0);
  					new_msg->_params = jsonParseString(s);
--- 306,321 ----
  				}
  			}
  
! 			tmp = jsonObjectGetKeyConst(message, "payload");
  			if(tmp) {
  				if(tmp->classname)
  					new_msg->status_name = strdup(tmp->classname);
  
! 				const jsonObject* tmp0 = jsonObjectGetKeyConst(tmp,"method");
  				if(jsonObjectGetString(tmp0))
  					new_msg->method_name = strdup(jsonObjectGetString(tmp0));
  
! 				tmp0 = jsonObjectGetKeyConst(tmp,"params");
  				if(tmp0) {
  					char* s = jsonObjectToJSON(tmp0);
  					new_msg->_params = jsonParseString(s);
***************
*** 324,334 ****
  					free(s);
  				}
  
! 				tmp0 = jsonObjectGetKey(tmp,"status");
  				if(jsonObjectGetString(tmp0))
  					new_msg->status_text = strdup(jsonObjectGetString(tmp0));
  
! 				tmp0 = jsonObjectGetKey(tmp,"statusCode");
  				if(tmp0) {
  					if(jsonObjectGetString(tmp0))
  						new_msg->status_code = atoi(jsonObjectGetString(tmp0));
--- 324,334 ----
  					free(s);
  				}
  
! 				tmp0 = jsonObjectGetKeyConst(tmp,"status");
  				if(jsonObjectGetString(tmp0))
  					new_msg->status_text = strdup(jsonObjectGetString(tmp0));
  
! 				tmp0 = jsonObjectGetKeyConst(tmp,"statusCode");
  				if(tmp0) {
  					if(jsonObjectGetString(tmp0))
  						new_msg->status_code = atoi(jsonObjectGetString(tmp0));
***************
*** 336,342 ****
  						new_msg->status_code = (int) jsonObjectGetNumber(tmp0);
  				}
  
! 				tmp0 = jsonObjectGetKey(tmp,"content");
  				if(tmp0) {
  					char* s = jsonObjectToJSON(tmp0);
  					new_msg->_result_content = jsonParseString(s);
--- 336,342 ----
  						new_msg->status_code = (int) jsonObjectGetNumber(tmp0);
  				}
  
! 				tmp0 = jsonObjectGetKeyConst(tmp,"content");
  				if(tmp0) {
  					char* s = jsonObjectToJSON(tmp0);
  					new_msg->_result_content = jsonParseString(s);

Reply via email to