osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
//void osrf_message_set_request_info( osrf_message*, char* param_name, json* params );
-void osrf_message_set_status_info( osrf_message*, char* status_name, char* status_text, int status_code );
-void osrf_message_set_result_content( osrf_message*, char* json_string );
+void osrf_message_set_status_info( osrf_message*,
+ const char* status_name, const char* status_text, int status_code );
+void osrf_message_set_result_content( osrf_message*, const char* json_string );
void osrfMessageFree( osrfMessage* );
void osrf_message_free( osrf_message* );
char* osrf_message_to_xml( osrf_message* );
-char* osrf_message_serialize(osrf_message*);
+char* osrf_message_serialize(const osrf_message*);
/* count is the max number of messages we'll put into msgs[] */
-int osrf_message_deserialize(char* json, osrf_message* msgs[], int count);
+int osrf_message_deserialize(const char* json, osrf_message* msgs[], int count);
*/
int osrf_message_from_xml( char* xml, osrf_message* msgs[] );
-void osrf_message_set_params( osrf_message* msg, jsonObject* o );
-void osrf_message_set_method( osrf_message* msg, char* method_name );
-void osrf_message_add_object_param( osrf_message* msg, jsonObject* o );
-void osrf_message_add_param( osrf_message*, char* param_string );
+void osrf_message_set_params( osrf_message* msg, const jsonObject* o );
+void osrf_message_set_method( osrf_message* msg, const char* method_name );
+void osrf_message_add_object_param( osrf_message* msg, const jsonObject* o );
+void osrf_message_add_param( osrf_message*, const char* param_string );
jsonObject* osrfMessageGetResult( osrfMessage* msg );
Returns the message as a jsonObject
@return The jsonObject which must be freed by the caller.
*/
-jsonObject* osrfMessageToJSON( osrfMessage* msg );
+jsonObject* osrfMessageToJSON( const osrfMessage* msg );
char* osrfMessageSerializeBatch( osrfMessage* msgs [], int count );
const char* osrf_message_set_default_locale( const char* locale ) {
if( locale == NULL ) return NULL;
- if( strlen(locale) > 16 ) return NULL;
+ if( strlen(locale) > sizeof(default_locale) - 1 ) return NULL;
- memcpy( default_locale, locale, strlen(locale) );
- default_locale[strlen(locale)] = '\0';
+ strcpy( default_locale, locale );
return (const char*) default_locale;
}
-void osrf_message_set_method( osrf_message* msg, char* method_name ) {
+void osrf_message_set_method( osrf_message* msg, const char* method_name ) {
if( msg == NULL || method_name == NULL ) return;
msg->method_name = strdup( method_name );
}
-void osrf_message_add_object_param( osrf_message* msg, jsonObject* o ) {
+void osrf_message_add_object_param( osrf_message* msg, const jsonObject* o ) {
if(!msg|| !o) return;
if(!msg->_params)
msg->_params = jsonParseString("[]");
free(j);
}
-void osrf_message_set_params( osrf_message* msg, jsonObject* o ) {
+void osrf_message_set_params( osrf_message* msg, const jsonObject* o ) {
if(!msg || !o) return;
if(o->type != JSON_ARRAY) {
osrfLogDebug( OSRF_LOG_MARK, "passing non-array to osrf_message_set_params(), fixing...");
- jsonObject* clone = jsonObjectClone(o);
- o = jsonNewObject(NULL);
- jsonObjectPush(o, clone);
if(msg->_params) jsonObjectFree(msg->_params);
- msg->_params = o;
+ jsonObject* clone = jsonObjectClone(o);
+ msg->_params = jsonNewObject(NULL);
+ jsonObjectPush(msg->_params, clone);
return;
}
/* only works if parse_json_params is false */
-void osrf_message_add_param( osrf_message* msg, char* param_string ) {
+void osrf_message_add_param( osrf_message* msg, const char* param_string ) {
if(msg == NULL || param_string == NULL) return;
if(!msg->_params) msg->_params = jsonParseString("[]");
jsonObjectPush(msg->_params, jsonParseString(param_string));
}
-void osrf_message_set_status_info(
- osrf_message* msg, char* status_name, char* status_text, int status_code ) {
+void osrf_message_set_status_info( osrf_message* msg,
+ const char* status_name, const char* status_text, int status_code ) {
if(!msg) return;
if( status_name != NULL )
}
-void osrf_message_set_result_content( osrf_message* msg, char* json_string ) {
+void osrf_message_set_result_content( osrf_message* msg, const char* json_string ) {
if( msg == NULL || json_string == NULL) return;
msg->result_string = strdup(json_string);
if(json_string) msg->_result_content = jsonParseString(json_string);
char* j;
int i = 0;
- osrfMessage* msg = NULL;
+ const osrfMessage* msg = NULL;
jsonObject* wrapper = jsonNewObject(NULL);
while( ((msg = msgs[i]) && (i++ < count)) )
}
-char* osrf_message_serialize(osrf_message* msg) {
+char* osrf_message_serialize(const osrf_message* msg) {
if( msg == NULL ) return NULL;
char* j = NULL;
}
-jsonObject* osrfMessageToJSON( osrfMessage* msg ) {
+jsonObject* osrfMessageToJSON( const osrfMessage* msg ) {
jsonObject* json = jsonNewObject(NULL);
jsonObjectSetClass(json, "osrfMessage");
}
-int osrf_message_deserialize(char* string, osrf_message* msgs[], int count) {
+int osrf_message_deserialize(const char* string, osrf_message* msgs[], int count) {
if(!string || !msgs || count <= 0) return 0;
int numparsed = 0;