diff --git a/src/include/switch.h b/src/include/switch.h index 2b007d2425..275e51fdac 100644 --- a/src/include/switch.h +++ b/src/include/switch.h @@ -132,6 +132,7 @@ #include "switch_config.h" #include "switch_nat.h" #include "switch_odbc.h" +#include "switch_json.h" #include diff --git a/src/include/switch_event.h b/src/include/switch_event.h index 7064fe4e33..d5438b28ed 100644 --- a/src/include/switch_event.h +++ b/src/include/switch_event.h @@ -283,6 +283,8 @@ SWITCH_DECLARE(switch_status_t) switch_event_free_subclass_detailed(const char * \note you must free the resulting string when you are finished with it */ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode); +SWITCH_DECLARE(switch_status_t) switch_event_serialize_json(switch_event_t *event, char **str); +SWITCH_DECLARE(switch_status_t) switch_event_create_json(switch_event_t **event, const char *json); #ifndef SWIG /*! diff --git a/src/include/switch_json.h b/src/include/switch_json.h new file mode 100755 index 0000000000..80320f1f6c --- /dev/null +++ b/src/include/switch_json.h @@ -0,0 +1,125 @@ +/* + Copyright (c) 2009 Dave Gamble + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "switch.h" + +#ifndef cJSON__h +#define cJSON__h + +#ifdef __cplusplus +extern "C" +{ +#endif + +// cJSON Types: +#define cJSON_False 0 +#define cJSON_True 1 +#define cJSON_NULL 2 +#define cJSON_Number 3 +#define cJSON_String 4 +#define cJSON_Array 5 +#define cJSON_Object 6 + +#define cJSON_IsReference 256 + +// The cJSON structure: +typedef struct cJSON { + struct cJSON *next,*prev; // next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem + struct cJSON *child; // An array or object item will have a child pointer pointing to a chain of the items in the array/object. + + int type; // The type of the item, as above. + + char *valuestring; // The item's string, if type==cJSON_String + int valueint; // The item's number, if type==cJSON_Number + double valuedouble; // The item's number, if type==cJSON_Number + + char *string; // The item's name string, if this item is the child of, or is in the list of subitems of an object. +} cJSON; + +typedef struct cJSON_Hooks { + void *(*malloc_fn)(size_t sz); + void (*free_fn)(void *ptr); +} cJSON_Hooks; + +// Supply malloc, realloc and free functions to cJSON +extern void cJSON_InitHooks(cJSON_Hooks* hooks); + + +// Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. +extern cJSON *cJSON_Parse(const char *value); +// Render a cJSON entity to text for transfer/storage. Free the char* when finished. +extern char *cJSON_Print(cJSON *item); +// Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. +extern char *cJSON_PrintUnformatted(cJSON *item); +// Delete a cJSON entity and all subentities. +extern void cJSON_Delete(cJSON *c); + +// Returns the number of items in an array (or object). +extern int cJSON_GetArraySize(cJSON *array); +// Retrieve item number "item" from array "array". Returns NULL if unsuccessful. +extern cJSON *cJSON_GetArrayItem(cJSON *array,int item); +// Get item "string" from object. Case insensitive. +extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string); + +// These calls create a cJSON item of the appropriate type. +extern cJSON *cJSON_CreateNull(void); +extern cJSON *cJSON_CreateTrue(void); +extern cJSON *cJSON_CreateFalse(void); +extern cJSON *cJSON_CreateNumber(double num); +extern cJSON *cJSON_CreateString(const char *string); +extern cJSON *cJSON_CreateArray(void); +extern cJSON *cJSON_CreateObject(void); + +// These utilities create an Array of count items. +extern cJSON *cJSON_CreateIntArray(int *numbers,int count); +extern cJSON *cJSON_CreateFloatArray(float *numbers,int count); +extern cJSON *cJSON_CreateDoubleArray(double *numbers,int count); +extern cJSON *cJSON_CreateStringArray(const char **strings,int count); + +// Append item to the specified array/object. +extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); +extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item); +// Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. +extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item); + +// Remove/Detatch items from Arrays/Objects. +extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which); +extern void cJSON_DeleteItemFromArray(cJSON *array,int which); +extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); +extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); + +// Update array items. +extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem); +extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); + +#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) +#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) +#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) +#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) +#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 5a2110d345..bc80c046e6 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -61,7 +61,8 @@ typedef enum { typedef enum { EVENT_FORMAT_PLAIN, - EVENT_FORMAT_XML + EVENT_FORMAT_XML, + EVENT_FORMAT_JSON } event_format_t; struct listener { @@ -126,6 +127,20 @@ static struct { } prefs; +static const char *format2str(event_format_t format) +{ + switch (format) { + case EVENT_FORMAT_PLAIN: + return "plain"; + case EVENT_FORMAT_XML: + return "xml"; + case EVENT_FORMAT_JSON: + return "json"; + } + + return "invalid"; +} + static void remove_listener(listener_t *listener); static void kill_all_listeners(void); @@ -605,7 +620,7 @@ static void xmlize_listener(listener_t *listener, switch_stream_handle_t *stream { stream->write_function(stream, " \n"); stream->write_function(stream, " %u\n", listener->id); - stream->write_function(stream, " %s\n", listener->format == EVENT_FORMAT_XML ? "xml" : "plain"); + stream->write_function(stream, " %s\n", format2str(listener->format)); stream->write_function(stream, " %u\n", listener->timeout); stream->write_function(stream, " \n"); } @@ -792,6 +807,8 @@ SWITCH_STANDARD_API(event_sink_function) if (switch_stristr("xml", format)) { listener->format = EVENT_FORMAT_XML; + } else if (switch_stristr("json", format)) { + listener->format = EVENT_FORMAT_JSON; } else { listener->format = EVENT_FORMAT_PLAIN; } @@ -931,6 +948,9 @@ SWITCH_STANDARD_API(event_sink_function) etype = "plain"; switch_event_serialize(pevent, &listener->ebuf, SWITCH_TRUE); stream->write_function(stream, "\n%s", listener->ebuf); + } else if (listener->format == EVENT_FORMAT_JSON) { + etype = "json"; + switch_event_serialize_json(pevent, &listener->ebuf); } else { switch_xml_t xml; etype = "xml"; @@ -1219,6 +1239,9 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event, if (listener->format == EVENT_FORMAT_PLAIN) { etype = "plain"; switch_event_serialize(pevent, &listener->ebuf, SWITCH_TRUE); + } else if (listener->format == EVENT_FORMAT_JSON) { + etype = "json"; + switch_event_serialize_json(pevent, &listener->ebuf); } else { switch_xml_t xml; etype = "xml"; @@ -1846,6 +1869,9 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even if (strstr(cmd, "xml") || strstr(cmd, "XML")) { listener->format = EVENT_FORMAT_XML; } + if (strstr(cmd, "json") || strstr(cmd, "JSON")) { + listener->format = EVENT_FORMAT_JSON; + } switch_snprintf(reply, reply_len, "+OK Events Enabled"); goto done; } @@ -2171,6 +2197,9 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even } else if (!strcasecmp(cur, "plain")) { listener->format = EVENT_FORMAT_PLAIN; goto end; + } else if (!strcasecmp(cur, "json")) { + listener->format = EVENT_FORMAT_JSON; + goto end; } } @@ -2218,7 +2247,7 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even switch_set_flag_locked(listener, LFLAG_EVENTS); } - switch_snprintf(reply, reply_len, "+OK event listener enabled %s", listener->format == EVENT_FORMAT_XML ? "xml" : "plain"); + switch_snprintf(reply, reply_len, "+OK event listener enabled %s", format2str(listener->format)); } else if (!strncasecmp(cmd, "nixevent", 8)) { char *next, *cur; diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.cxx index 24f2c4aff2..74827479e1 100644 --- a/src/mod/languages/mod_managed/freeswitch_wrap.cxx +++ b/src/mod/languages/mod_managed/freeswitch_wrap.cxx @@ -3637,7 +3637,7 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_t38_options_t_T38VendorInfo_get(void } -SWIGEXPORT void SWIGSTDCALL CSharp_switch_t38_options_t_ip_set(void * jarg1, char * jarg2) { +SWIGEXPORT void SWIGSTDCALL CSharp_switch_t38_options_t_remote_ip_set(void * jarg1, char * jarg2) { switch_t38_options_t *arg1 = (switch_t38_options_t *) 0 ; char *arg2 = (char *) 0 ; @@ -3645,45 +3645,97 @@ SWIGEXPORT void SWIGSTDCALL CSharp_switch_t38_options_t_ip_set(void * jarg1, cha arg2 = (char *)jarg2; { if (arg2) { - arg1->ip = (char const *) (new char[strlen((const char *)arg2)+1]); - strcpy((char *)arg1->ip, (const char *)arg2); + arg1->remote_ip = (char const *) (new char[strlen((const char *)arg2)+1]); + strcpy((char *)arg1->remote_ip, (const char *)arg2); } else { - arg1->ip = 0; + arg1->remote_ip = 0; } } } -SWIGEXPORT char * SWIGSTDCALL CSharp_switch_t38_options_t_ip_get(void * jarg1) { +SWIGEXPORT char * SWIGSTDCALL CSharp_switch_t38_options_t_remote_ip_get(void * jarg1) { char * jresult ; switch_t38_options_t *arg1 = (switch_t38_options_t *) 0 ; char *result = 0 ; arg1 = (switch_t38_options_t *)jarg1; - result = (char *) ((arg1)->ip); + result = (char *) ((arg1)->remote_ip); jresult = SWIG_csharp_string_callback((const char *)result); return jresult; } -SWIGEXPORT void SWIGSTDCALL CSharp_switch_t38_options_t_port_set(void * jarg1, unsigned long jarg2) { +SWIGEXPORT void SWIGSTDCALL CSharp_switch_t38_options_t_remote_port_set(void * jarg1, unsigned long jarg2) { switch_t38_options_t *arg1 = (switch_t38_options_t *) 0 ; uint32_t arg2 ; arg1 = (switch_t38_options_t *)jarg1; arg2 = (uint32_t)jarg2; - if (arg1) (arg1)->port = arg2; + if (arg1) (arg1)->remote_port = arg2; } -SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_t38_options_t_port_get(void * jarg1) { +SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_t38_options_t_remote_port_get(void * jarg1) { unsigned long jresult ; switch_t38_options_t *arg1 = (switch_t38_options_t *) 0 ; uint32_t result; arg1 = (switch_t38_options_t *)jarg1; - result = (uint32_t) ((arg1)->port); + result = (uint32_t) ((arg1)->remote_port); + jresult = (unsigned long)result; + return jresult; +} + + +SWIGEXPORT void SWIGSTDCALL CSharp_switch_t38_options_t_local_ip_set(void * jarg1, char * jarg2) { + switch_t38_options_t *arg1 = (switch_t38_options_t *) 0 ; + char *arg2 = (char *) 0 ; + + arg1 = (switch_t38_options_t *)jarg1; + arg2 = (char *)jarg2; + { + if (arg2) { + arg1->local_ip = (char const *) (new char[strlen((const char *)arg2)+1]); + strcpy((char *)arg1->local_ip, (const char *)arg2); + } else { + arg1->local_ip = 0; + } + } +} + + +SWIGEXPORT char * SWIGSTDCALL CSharp_switch_t38_options_t_local_ip_get(void * jarg1) { + char * jresult ; + switch_t38_options_t *arg1 = (switch_t38_options_t *) 0 ; + char *result = 0 ; + + arg1 = (switch_t38_options_t *)jarg1; + result = (char *) ((arg1)->local_ip); + jresult = SWIG_csharp_string_callback((const char *)result); + return jresult; +} + + +SWIGEXPORT void SWIGSTDCALL CSharp_switch_t38_options_t_local_port_set(void * jarg1, unsigned long jarg2) { + switch_t38_options_t *arg1 = (switch_t38_options_t *) 0 ; + uint32_t arg2 ; + + arg1 = (switch_t38_options_t *)jarg1; + arg2 = (uint32_t)jarg2; + if (arg1) (arg1)->local_port = arg2; + +} + + +SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_t38_options_t_local_port_get(void * jarg1) { + unsigned long jresult ; + switch_t38_options_t *arg1 = (switch_t38_options_t *) 0 ; + uint32_t result; + + arg1 = (switch_t38_options_t *)jarg1; + result = (uint32_t) ((arg1)->local_port); jresult = (unsigned long)result; return jresult; } @@ -11638,6 +11690,22 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_number_cmp(char * jarg1, int jarg2) { } +SWIGEXPORT int SWIGSTDCALL CSharp_switch_split_user_domain(char * jarg1, void * jarg2, void * jarg3) { + int jresult ; + char *arg1 = (char *) 0 ; + char **arg2 = (char **) 0 ; + char **arg3 = (char **) 0 ; + int result; + + arg1 = (char *)jarg1; + arg2 = (char **)jarg2; + arg3 = (char **)jarg3; + result = (int)switch_split_user_domain(arg1,arg2,arg3); + jresult = result; + return jresult; +} + + SWIGEXPORT void SWIGSTDCALL CSharp_switch_caller_profile_username_set(void * jarg1, char * jarg2) { switch_caller_profile *arg1 = (switch_caller_profile *) 0 ; char *arg2 = (char *) 0 ; @@ -21966,19 +22034,21 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_perform_mark_answered(void * ja } -SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_perform_ring_ready(void * jarg1, char * jarg2, char * jarg3, int jarg4) { +SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_perform_ring_ready_value(void * jarg1, int jarg2, char * jarg3, char * jarg4, int jarg5) { int jresult ; switch_channel_t *arg1 = (switch_channel_t *) 0 ; - char *arg2 = (char *) 0 ; + switch_ring_ready_t arg2 ; char *arg3 = (char *) 0 ; - int arg4 ; + char *arg4 = (char *) 0 ; + int arg5 ; switch_status_t result; arg1 = (switch_channel_t *)jarg1; - arg2 = (char *)jarg2; + arg2 = (switch_ring_ready_t)jarg2; arg3 = (char *)jarg3; - arg4 = (int)jarg4; - result = (switch_status_t)switch_channel_perform_ring_ready(arg1,(char const *)arg2,(char const *)arg3,arg4); + arg4 = (char *)jarg4; + arg5 = (int)jarg5; + result = (switch_status_t)switch_channel_perform_ring_ready_value(arg1,arg2,(char const *)arg3,(char const *)arg4,arg5); jresult = result; return jresult; } @@ -22020,19 +22090,21 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_perform_mark_pre_answered(void } -SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_perform_mark_ring_ready(void * jarg1, char * jarg2, char * jarg3, int jarg4) { +SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_perform_mark_ring_ready_value(void * jarg1, int jarg2, char * jarg3, char * jarg4, int jarg5) { int jresult ; switch_channel_t *arg1 = (switch_channel_t *) 0 ; - char *arg2 = (char *) 0 ; + switch_ring_ready_t arg2 ; char *arg3 = (char *) 0 ; - int arg4 ; + char *arg4 = (char *) 0 ; + int arg5 ; switch_status_t result; arg1 = (switch_channel_t *)jarg1; - arg2 = (char *)jarg2; + arg2 = (switch_ring_ready_t)jarg2; arg3 = (char *)jarg3; - arg4 = (int)jarg4; - result = (switch_status_t)switch_channel_perform_mark_ring_ready(arg1,(char const *)arg2,(char const *)arg3,arg4); + arg4 = (char *)jarg4; + arg5 = (int)jarg5; + result = (switch_status_t)switch_channel_perform_mark_ring_ready_value(arg1,arg2,(char const *)arg3,(char const *)arg4,arg5); jresult = result; return jresult; } @@ -22484,6 +22556,80 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_get_cap_string(void * jarg1) } +SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_state_change_pending(void * jarg1) { + int jresult ; + switch_channel_t *arg1 = (switch_channel_t *) 0 ; + int result; + + arg1 = (switch_channel_t *)jarg1; + result = (int)switch_channel_state_change_pending(arg1); + jresult = result; + return jresult; +} + + +SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_perform_set_callstate(void * jarg1, int jarg2, char * jarg3, char * jarg4, int jarg5) { + switch_channel_t *arg1 = (switch_channel_t *) 0 ; + switch_channel_callstate_t arg2 ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; + int arg5 ; + + arg1 = (switch_channel_t *)jarg1; + arg2 = (switch_channel_callstate_t)jarg2; + arg3 = (char *)jarg3; + arg4 = (char *)jarg4; + arg5 = (int)jarg5; + switch_channel_perform_set_callstate(arg1,arg2,(char const *)arg3,(char const *)arg4,arg5); +} + + +SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_get_callstate(void * jarg1) { + int jresult ; + switch_channel_t *arg1 = (switch_channel_t *) 0 ; + switch_channel_callstate_t result; + + arg1 = (switch_channel_t *)jarg1; + result = (switch_channel_callstate_t)switch_channel_get_callstate(arg1); + jresult = result; + return jresult; +} + + +SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_callstate2str(int jarg1) { + char * jresult ; + switch_channel_callstate_t arg1 ; + char *result = 0 ; + + arg1 = (switch_channel_callstate_t)jarg1; + result = (char *)switch_channel_callstate2str(arg1); + jresult = SWIG_csharp_string_callback((const char *)result); + return jresult; +} + + +SWIGEXPORT int SWIGSTDCALL CSharp_switch_channel_str2callstate(char * jarg1) { + int jresult ; + char *arg1 = (char *) 0 ; + switch_call_cause_t result; + + arg1 = (char *)jarg1; + result = (switch_call_cause_t)switch_channel_str2callstate((char const *)arg1); + jresult = result; + return jresult; +} + + +SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_mark_hold(void * jarg1, int jarg2) { + switch_channel_t *arg1 = (switch_channel_t *) 0 ; + switch_bool_t arg2 ; + + arg1 = (switch_channel_t *)jarg1; + arg2 = (switch_bool_t)jarg2; + switch_channel_mark_hold(arg1,arg2); +} + + SWIGEXPORT int SWIGSTDCALL CSharp_switch_buffer_create(void * jarg1, void * jarg2, void * jarg3) { int jresult ; switch_memory_pool_t *arg1 = (switch_memory_pool_t *) 0 ; @@ -23389,6 +23535,16 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_dup(void * jarg1, void * jarg2) { } +SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_merge(void * jarg1, void * jarg2) { + switch_event_t *arg1 = (switch_event_t *) 0 ; + switch_event_t *arg2 = (switch_event_t *) 0 ; + + arg1 = (switch_event_t *)jarg1; + arg2 = (switch_event_t *)jarg2; + switch_event_merge(arg1,arg2); +} + + SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_fire_detailed(char * jarg1, char * jarg2, int jarg3, void * jarg4, void * jarg5) { int jresult ; char *arg1 = (char *) 0 ; @@ -23559,6 +23715,34 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_serialize(void * jarg1, void * ja } +SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_serialize_json(void * jarg1, void * jarg2) { + int jresult ; + switch_event_t *arg1 = (switch_event_t *) 0 ; + char **arg2 = (char **) 0 ; + switch_status_t result; + + arg1 = (switch_event_t *)jarg1; + arg2 = (char **)jarg2; + result = (switch_status_t)switch_event_serialize_json(arg1,arg2); + jresult = result; + return jresult; +} + + +SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_create_json(void * jarg1, char * jarg2) { + int jresult ; + switch_event_t **arg1 = (switch_event_t **) 0 ; + char *arg2 = (char *) 0 ; + switch_status_t result; + + arg1 = (switch_event_t **)jarg1; + arg2 = (char *)jarg2; + result = (switch_status_t)switch_event_create_json(arg1,(char const *)arg2); + jresult = result; + return jresult; +} + + SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_running() { int jresult ; switch_status_t result; @@ -25929,6 +26113,30 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_read(void * jarg1, unsigned long ja } +SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_block_dtmf_session(void * jarg1) { + int jresult ; + switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; + switch_status_t result; + + arg1 = (switch_core_session_t *)jarg1; + result = (switch_status_t)switch_ivr_block_dtmf_session(arg1); + jresult = result; + return jresult; +} + + +SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_unblock_dtmf_session(void * jarg1) { + int jresult ; + switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; + switch_status_t result; + + arg1 = (switch_core_session_t *)jarg1; + result = (switch_status_t)switch_ivr_unblock_dtmf_session(arg1); + jresult = result; + return jresult; +} + + SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_bind_dtmf_meta_session(void * jarg1, unsigned long jarg2, unsigned long jarg3, char * jarg4) { int jresult ; switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index 5ea7c1e0fe..1ad708504f 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -2738,6 +2738,11 @@ public class freeswitch { return ret; } + public static int switch_split_user_domain(string arg0, ref string user, ref string domain) { + int ret = freeswitchPINVOKE.switch_split_user_domain(arg0, ref user, ref domain); + return ret; + } + public static switch_caller_extension switch_caller_extension_new(SWIGTYPE_p_switch_core_session session, string extension_name, string extension_number) { IntPtr cPtr = freeswitchPINVOKE.switch_caller_extension_new(SWIGTYPE_p_switch_core_session.getCPtr(session), extension_name, extension_number); switch_caller_extension ret = (cPtr == IntPtr.Zero) ? null : new switch_caller_extension(cPtr, false); @@ -3057,8 +3062,8 @@ public class freeswitch { return ret; } - public static switch_status_t switch_channel_perform_ring_ready(SWIGTYPE_p_switch_channel channel, string file, string func, int line) { - switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_perform_ring_ready(SWIGTYPE_p_switch_channel.getCPtr(channel), file, func, line); + public static switch_status_t switch_channel_perform_ring_ready_value(SWIGTYPE_p_switch_channel channel, switch_ring_ready_t rv, string file, string func, int line) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_perform_ring_ready_value(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)rv, file, func, line); return ret; } @@ -3072,8 +3077,8 @@ public class freeswitch { return ret; } - public static switch_status_t switch_channel_perform_mark_ring_ready(SWIGTYPE_p_switch_channel channel, string file, string func, int line) { - switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_perform_mark_ring_ready(SWIGTYPE_p_switch_channel.getCPtr(channel), file, func, line); + public static switch_status_t switch_channel_perform_mark_ring_ready_value(SWIGTYPE_p_switch_channel channel, switch_ring_ready_t rv, string file, string func, int line) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_channel_perform_mark_ring_ready_value(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)rv, file, func, line); return ret; } @@ -3246,6 +3251,34 @@ public class freeswitch { return ret; } + public static int switch_channel_state_change_pending(SWIGTYPE_p_switch_channel channel) { + int ret = freeswitchPINVOKE.switch_channel_state_change_pending(SWIGTYPE_p_switch_channel.getCPtr(channel)); + return ret; + } + + public static void switch_channel_perform_set_callstate(SWIGTYPE_p_switch_channel channel, switch_channel_callstate_t callstate, string file, string func, int line) { + freeswitchPINVOKE.switch_channel_perform_set_callstate(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)callstate, file, func, line); + } + + public static switch_channel_callstate_t switch_channel_get_callstate(SWIGTYPE_p_switch_channel channel) { + switch_channel_callstate_t ret = (switch_channel_callstate_t)freeswitchPINVOKE.switch_channel_get_callstate(SWIGTYPE_p_switch_channel.getCPtr(channel)); + return ret; + } + + public static string switch_channel_callstate2str(switch_channel_callstate_t callstate) { + string ret = freeswitchPINVOKE.switch_channel_callstate2str((int)callstate); + return ret; + } + + public static switch_call_cause_t switch_channel_str2callstate(string str) { + switch_call_cause_t ret = (switch_call_cause_t)freeswitchPINVOKE.switch_channel_str2callstate(str); + return ret; + } + + public static void switch_channel_mark_hold(SWIGTYPE_p_switch_channel channel, switch_bool_t on) { + freeswitchPINVOKE.switch_channel_mark_hold(SWIGTYPE_p_switch_channel.getCPtr(channel), (int)on); + } + public static switch_status_t switch_buffer_create(SWIGTYPE_p_apr_pool_t pool, SWIGTYPE_p_p_switch_buffer buffer, SWIGTYPE_p_switch_size_t max_len) { switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_buffer_create(SWIGTYPE_p_apr_pool_t.getCPtr(pool), SWIGTYPE_p_p_switch_buffer.getCPtr(buffer), SWIGTYPE_p_switch_size_t.getCPtr(max_len)); if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve(); @@ -3398,6 +3431,10 @@ public class freeswitch { return ret; } + public static void switch_event_merge(switch_event arg0, switch_event tomerge) { + freeswitchPINVOKE.switch_event_merge(switch_event.getCPtr(arg0), switch_event.getCPtr(tomerge)); + } + public static switch_status_t switch_event_fire_detailed(string file, string func, int line, SWIGTYPE_p_p_switch_event arg3, SWIGTYPE_p_void user_data) { switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_fire_detailed(file, func, line, SWIGTYPE_p_p_switch_event.getCPtr(arg3), SWIGTYPE_p_void.getCPtr(user_data)); return ret; @@ -3452,6 +3489,16 @@ public class freeswitch { return ret; } + public static switch_status_t switch_event_serialize_json(switch_event arg0, ref string str) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_serialize_json(switch_event.getCPtr(arg0), ref str); + return ret; + } + + public static switch_status_t switch_event_create_json(SWIGTYPE_p_p_switch_event arg0, string json) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_create_json(SWIGTYPE_p_p_switch_event.getCPtr(arg0), json); + return ret; + } + public static switch_status_t switch_event_running() { switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_running(); return ret; @@ -3965,6 +4012,16 @@ public class freeswitch { return ret; } + public static switch_status_t switch_ivr_block_dtmf_session(SWIGTYPE_p_switch_core_session session) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_block_dtmf_session(SWIGTYPE_p_switch_core_session.getCPtr(session)); + return ret; + } + + public static switch_status_t switch_ivr_unblock_dtmf_session(SWIGTYPE_p_switch_core_session session) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_unblock_dtmf_session(SWIGTYPE_p_switch_core_session.getCPtr(session)); + return ret; + } + public static switch_status_t switch_ivr_bind_dtmf_meta_session(SWIGTYPE_p_switch_core_session session, uint key, uint bind_flags, string app) { switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_bind_dtmf_meta_session(SWIGTYPE_p_switch_core_session.getCPtr(session), key, bind_flags, app); return ret; @@ -6023,17 +6080,29 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_T38VendorInfo_get")] public static extern string switch_t38_options_t_T38VendorInfo_get(HandleRef jarg1); - [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_ip_set")] - public static extern void switch_t38_options_t_ip_set(HandleRef jarg1, string jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_remote_ip_set")] + public static extern void switch_t38_options_t_remote_ip_set(HandleRef jarg1, string jarg2); - [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_ip_get")] - public static extern string switch_t38_options_t_ip_get(HandleRef jarg1); + [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_remote_ip_get")] + public static extern string switch_t38_options_t_remote_ip_get(HandleRef jarg1); - [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_port_set")] - public static extern void switch_t38_options_t_port_set(HandleRef jarg1, uint jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_remote_port_set")] + public static extern void switch_t38_options_t_remote_port_set(HandleRef jarg1, uint jarg2); - [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_port_get")] - public static extern uint switch_t38_options_t_port_get(HandleRef jarg1); + [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_remote_port_get")] + public static extern uint switch_t38_options_t_remote_port_get(HandleRef jarg1); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_local_ip_set")] + public static extern void switch_t38_options_t_local_ip_set(HandleRef jarg1, string jarg2); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_local_ip_get")] + public static extern string switch_t38_options_t_local_ip_get(HandleRef jarg1); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_local_port_set")] + public static extern void switch_t38_options_t_local_port_set(HandleRef jarg1, uint jarg2); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_t38_options_t_local_port_get")] + public static extern uint switch_t38_options_t_local_port_get(HandleRef jarg1); [DllImport("mod_managed", EntryPoint="CSharp_new_switch_t38_options_t")] public static extern IntPtr new_switch_t38_options_t(); @@ -7853,6 +7922,9 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_number_cmp")] public static extern int switch_number_cmp(string jarg1, int jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_split_user_domain")] + public static extern int switch_split_user_domain(string jarg1, ref string jarg2, ref string jarg3); + [DllImport("mod_managed", EntryPoint="CSharp_switch_caller_profile_username_set")] public static extern void switch_caller_profile_username_set(HandleRef jarg1, string jarg2); @@ -10409,8 +10481,8 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_mark_answered")] public static extern int switch_channel_perform_mark_answered(HandleRef jarg1, string jarg2, string jarg3, int jarg4); - [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_ring_ready")] - public static extern int switch_channel_perform_ring_ready(HandleRef jarg1, string jarg2, string jarg3, int jarg4); + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_ring_ready_value")] + public static extern int switch_channel_perform_ring_ready_value(HandleRef jarg1, int jarg2, string jarg3, string jarg4, int jarg5); [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_pre_answer")] public static extern int switch_channel_perform_pre_answer(HandleRef jarg1, string jarg2, string jarg3, int jarg4); @@ -10418,8 +10490,8 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_mark_pre_answered")] public static extern int switch_channel_perform_mark_pre_answered(HandleRef jarg1, string jarg2, string jarg3, int jarg4); - [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_mark_ring_ready")] - public static extern int switch_channel_perform_mark_ring_ready(HandleRef jarg1, string jarg2, string jarg3, int jarg4); + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_mark_ring_ready_value")] + public static extern int switch_channel_perform_mark_ring_ready_value(HandleRef jarg1, int jarg2, string jarg3, string jarg4, int jarg5); [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_add_state_handler")] public static extern int switch_channel_add_state_handler(HandleRef jarg1, HandleRef jarg2); @@ -10526,6 +10598,24 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_cap_string")] public static extern string switch_channel_get_cap_string(HandleRef jarg1); + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_state_change_pending")] + public static extern int switch_channel_state_change_pending(HandleRef jarg1); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_perform_set_callstate")] + public static extern void switch_channel_perform_set_callstate(HandleRef jarg1, int jarg2, string jarg3, string jarg4, int jarg5); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_callstate")] + public static extern int switch_channel_get_callstate(HandleRef jarg1); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_callstate2str")] + public static extern string switch_channel_callstate2str(int jarg1); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_str2callstate")] + public static extern int switch_channel_str2callstate(string jarg1); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_mark_hold")] + public static extern void switch_channel_mark_hold(HandleRef jarg1, int jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_buffer_create")] public static extern int switch_buffer_create(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3); @@ -10724,6 +10814,9 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_event_dup")] public static extern int switch_event_dup(HandleRef jarg1, HandleRef jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_event_merge")] + public static extern void switch_event_merge(HandleRef jarg1, HandleRef jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_event_fire_detailed")] public static extern int switch_event_fire_detailed(string jarg1, string jarg2, int jarg3, HandleRef jarg4, HandleRef jarg5); @@ -10757,6 +10850,12 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_event_serialize")] public static extern int switch_event_serialize(HandleRef jarg1, ref string jarg2, int jarg3); + [DllImport("mod_managed", EntryPoint="CSharp_switch_event_serialize_json")] + public static extern int switch_event_serialize_json(HandleRef jarg1, ref string jarg2); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_event_create_json")] + public static extern int switch_event_create_json(HandleRef jarg1, string jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_event_running")] public static extern int switch_event_running(); @@ -11225,6 +11324,12 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_read")] public static extern int switch_ivr_read(HandleRef jarg1, uint jarg2, uint jarg3, string jarg4, string jarg5, string jarg6, HandleRef jarg7, uint jarg8, string jarg9); + [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_block_dtmf_session")] + public static extern int switch_ivr_block_dtmf_session(HandleRef jarg1); + + [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_unblock_dtmf_session")] + public static extern int switch_ivr_unblock_dtmf_session(HandleRef jarg1); + [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_bind_dtmf_meta_session")] public static extern int switch_ivr_bind_dtmf_meta_session(HandleRef jarg1, uint jarg2, uint jarg3, string jarg4); @@ -19852,6 +19957,27 @@ public enum switch_channel_app_flag_t { namespace FreeSWITCH.Native { +public enum switch_channel_callstate_t { + CCS_DOWN, + CCS_DIALING, + CCS_RINGING, + CCS_EARLY, + CCS_ACTIVE, + CCS_HELD, + CCS_HANGUP +} + +} +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 1.3.35 + * + * Do not make changes to this file unless you know what you are doing--modify + * the SWIG interface file instead. + * ----------------------------------------------------------------------------- */ + +namespace FreeSWITCH.Native { + public enum switch_channel_cap_t { CC_MEDIA_ACK = 1, CC_BYPASS_MEDIA, @@ -19922,6 +20048,7 @@ public enum switch_channel_flag_t { CF_BROADCAST_DROP_MEDIA, CF_EARLY_HANGUP, CF_MEDIA_SET, + CF_CONSUME_ON_ORIGINATE, CF_FLAG_MAX } @@ -22975,11 +23102,14 @@ public enum switch_event_types_t { SWITCH_EVENT_CHANNEL_CREATE, SWITCH_EVENT_CHANNEL_DESTROY, SWITCH_EVENT_CHANNEL_STATE, + SWITCH_EVENT_CHANNEL_CALLSTATE, SWITCH_EVENT_CHANNEL_ANSWER, SWITCH_EVENT_CHANNEL_HANGUP, SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE, SWITCH_EVENT_CHANNEL_EXECUTE, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE, + SWITCH_EVENT_CHANNEL_HOLD, + SWITCH_EVENT_CHANNEL_UNHOLD, SWITCH_EVENT_CHANNEL_BRIDGE, SWITCH_EVENT_CHANNEL_UNBRIDGE, SWITCH_EVENT_CHANNEL_PROGRESS, @@ -25947,6 +26077,23 @@ public enum switch_priority_t { namespace FreeSWITCH.Native { +public enum switch_ring_ready_t { + SWITCH_RING_READY_NONE, + SWITCH_RING_READY_RINGING, + SWITCH_RING_READY_QUEUED +} + +} +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 1.3.35 + * + * Do not make changes to this file unless you know what you are doing--modify + * the SWIG interface file instead. + * ----------------------------------------------------------------------------- */ + +namespace FreeSWITCH.Native { + using System; using System.Runtime.InteropServices; @@ -26047,7 +26194,8 @@ namespace FreeSWITCH.Native { public enum switch_rtp_bug_flag_t { RTP_BUG_NONE = 0, RTP_BUG_CISCO_SKIP_MARK_BIT_2833 = (1 << 0), - RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833 = (1 << 1) + RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833 = (1 << 1), + RTP_BUG_IGNORE_MARK_BIT = (1 << 2) } } @@ -28090,22 +28238,42 @@ public class switch_t38_options_t : IDisposable { } } - public string ip { + public string remote_ip { set { - freeswitchPINVOKE.switch_t38_options_t_ip_set(swigCPtr, value); + freeswitchPINVOKE.switch_t38_options_t_remote_ip_set(swigCPtr, value); } get { - string ret = freeswitchPINVOKE.switch_t38_options_t_ip_get(swigCPtr); + string ret = freeswitchPINVOKE.switch_t38_options_t_remote_ip_get(swigCPtr); return ret; } } - public uint port { + public uint remote_port { set { - freeswitchPINVOKE.switch_t38_options_t_port_set(swigCPtr, value); + freeswitchPINVOKE.switch_t38_options_t_remote_port_set(swigCPtr, value); } get { - uint ret = freeswitchPINVOKE.switch_t38_options_t_port_get(swigCPtr); + uint ret = freeswitchPINVOKE.switch_t38_options_t_remote_port_get(swigCPtr); + return ret; + } + } + + public string local_ip { + set { + freeswitchPINVOKE.switch_t38_options_t_local_ip_set(swigCPtr, value); + } + get { + string ret = freeswitchPINVOKE.switch_t38_options_t_local_ip_get(swigCPtr); + return ret; + } + } + + public uint local_port { + set { + freeswitchPINVOKE.switch_t38_options_t_local_port_set(swigCPtr, value); + } + get { + uint ret = freeswitchPINVOKE.switch_t38_options_t_local_port_get(swigCPtr); return ret; } } diff --git a/src/mod/languages/mod_perl/mod_perl_wrap.cpp b/src/mod/languages/mod_perl/mod_perl_wrap.cpp index 5ba899fbf8..b615b9d930 100644 --- a/src/mod/languages/mod_perl/mod_perl_wrap.cpp +++ b/src/mod/languages/mod_perl/mod_perl_wrap.cpp @@ -9708,17 +9708,17 @@ XS(SWIG_init) { SWIG_TypeClientData(SWIGTYPE_p_IVRMenu, (void*) "freeswitch::IVRMenu"); SWIG_TypeClientData(SWIGTYPE_p_API, (void*) "freeswitch::API"); SWIG_TypeClientData(SWIGTYPE_p_input_callback_state, (void*) "freeswitch::input_callback_state_t"); - /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_HUP", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_HUP))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; - /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_FREE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_FREE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; - /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_RDLOCK", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_RDLOCK))); SvREADONLY_on(sv); diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index 1ff5071317..09af60f9cb 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -627,7 +627,7 @@ static JSBool event_serialize(JSContext * cx, JSObject * obj, uintN argc, jsval { struct event_obj *eo = JS_GetPrivate(cx, obj); char *buf; - uint8_t isxml = 0; + uint8_t isxml = 0, isjson = 0; if (!eo) { *rval = BOOLEAN_TO_JSVAL(JS_FALSE); @@ -638,6 +638,8 @@ static JSBool event_serialize(JSContext * cx, JSObject * obj, uintN argc, jsval char *arg = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); if (!strcasecmp(arg, "xml")) { isxml++; + } else if (!strcasecmp(arg, "json")) { + isjson++; } } @@ -652,6 +654,11 @@ static JSBool event_serialize(JSContext * cx, JSObject * obj, uintN argc, jsval } else { *rval = BOOLEAN_TO_JSVAL(JS_FALSE); } + } else if (isjson) { + if (switch_event_serialize_json(eo->event, &buf) == SWITCH_STATUS_SUCCESS) { + *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf)); + switch_safe_free(buf); + } } else { if (switch_event_serialize(eo->event, &buf, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf)); diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index dab28c7afb..3c71d35370 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -237,19 +237,28 @@ SWITCH_DECLARE(const char *) API::executeString(const char *cmd) SWITCH_DECLARE_CONSTRUCTOR Event::Event(const char *type, const char *subclass_name) { switch_event_types_t event_id; - - if (switch_name_event(type, &event_id) != SWITCH_STATUS_SUCCESS) { - event_id = SWITCH_EVENT_MESSAGE; - } - if (!zstr(subclass_name) && event_id != SWITCH_EVENT_CUSTOM) { - switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_WARNING, "Changing event type to custom because you specified a subclass name!\n"); - event_id = SWITCH_EVENT_CUSTOM; - } + if (!strcasecmp(type, "json") && !zstr(subclass_name)) { + if (switch_event_create_json(&event, subclass_name) != SWITCH_STATUS_SUCCESS) { + return; + } + + event_id = event->event_id; - if (switch_event_create_subclass(&event, event_id, subclass_name) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Failed to create event!\n"); - event = NULL; + } else { + if (switch_name_event(type, &event_id) != SWITCH_STATUS_SUCCESS) { + event_id = SWITCH_EVENT_MESSAGE; + } + + if (!zstr(subclass_name) && event_id != SWITCH_EVENT_CUSTOM) { + switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_WARNING, "Changing event type to custom because you specified a subclass name!\n"); + event_id = SWITCH_EVENT_CUSTOM; + } + + if (switch_event_create_subclass(&event, event_id, subclass_name) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Failed to create event!\n"); + event = NULL; + } } serialized_string = NULL; @@ -278,8 +287,6 @@ SWITCH_DECLARE_CONSTRUCTOR Event::~Event() SWITCH_DECLARE(const char *)Event::serialize(const char *format) { - int isxml = 0; - this_check(""); @@ -290,10 +297,6 @@ SWITCH_DECLARE(const char *)Event::serialize(const char *format) } if (format && !strcasecmp(format, "xml")) { - isxml++; - } - - if (isxml) { switch_xml_t xml; if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) { serialized_string = switch_xml_toxml(xml, SWITCH_FALSE); @@ -302,6 +305,9 @@ SWITCH_DECLARE(const char *)Event::serialize(const char *format) } else { return ""; } + } else if (format && !strcasecmp(format, "json")) { + switch_event_serialize_json(event, &serialized_string); + return serialized_string; } else { if (switch_event_serialize(event, &serialized_string, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { char *new_serialized_string = switch_mprintf("'%s'", serialized_string); diff --git a/src/switch_event.c b/src/switch_event.c index f39a176bad..49d87e4e68 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -1047,6 +1047,73 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch return SWITCH_STATUS_SUCCESS; } +SWITCH_DECLARE(switch_status_t) switch_event_create_json(switch_event_t **event, const char *json) +{ + switch_event_t *new_event; + cJSON *cj, *cjp; + + + if (!(cj = cJSON_Parse(json))) { + return SWITCH_STATUS_FALSE; + } + + if (switch_event_create(&new_event, SWITCH_EVENT_CLONE) != SWITCH_STATUS_SUCCESS) { + cJSON_Delete(cj); + return SWITCH_STATUS_FALSE; + } + + for (cjp = cj->child; cjp; cjp = cjp->next) { + char *name = cjp->string; + char *value = cjp->valuestring; + + if (name && value) { + if (!strcasecmp(name, "_body")) { + switch_event_add_body(new_event, value); + } else { + if (!strcasecmp(name, "event-name")) { + switch_event_del_header(new_event, "event-name"); + } + + switch_name_event(value, &new_event->event_id); + switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, name, value); + } + + } + } + + cJSON_Delete(cj); + *event = new_event; + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_DECLARE(switch_status_t) switch_event_serialize_json(switch_event_t *event, char **str) +{ + switch_event_header_t *hp; + cJSON *cj; + + *str = NULL; + + cj = cJSON_CreateObject(); + + for (hp = event->headers; hp; hp = hp->next) { + cJSON_AddItemToObject(cj, hp->name, cJSON_CreateString(hp->value)); + } + if (event->body) { + int blen = (int) strlen(event->body); + char tmp[25]; + + switch_snprintf(tmp, sizeof(tmp), "%d", blen); + + cJSON_AddItemToObject(cj, "Content-Length", cJSON_CreateString(tmp)); + cJSON_AddItemToObject(cj, "_body", cJSON_CreateString(event->body)); + } + + *str = cJSON_Print(cj); + cJSON_Delete(cj); + + return SWITCH_STATUS_SUCCESS; +} + static switch_xml_t add_xml_header(switch_xml_t xml, char *name, char *value, int offset) { switch_xml_t header = switch_xml_add_child_d(xml, name, offset); diff --git a/src/switch_json.c b/src/switch_json.c new file mode 100644 index 0000000000..a3211e6e3e --- /dev/null +++ b/src/switch_json.c @@ -0,0 +1,484 @@ +/* + Copyright (c) 2009 Dave Gamble + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +// cJSON +// JSON parser in C. + +#include "switch.h" +#include + +static int cJSON_strcasecmp(const char *s1,const char *s2) +{ + if (!s1) return (s1==s2)?0:1;if (!s2) return 1; + for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0; + return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2); +} + +static void *(*cJSON_malloc)(size_t sz) = malloc; +static void (*cJSON_free)(void *ptr) = free; + +static char* cJSON_strdup(const char* str) +{ + size_t len; + char* copy; + + len = strlen(str) + 1; + if (!(copy = (char*)cJSON_malloc(len))) return 0; + memcpy(copy,str,len); + return copy; +} + +void cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (!hooks) { /* Reset hooks */ + cJSON_malloc = malloc; + cJSON_free = free; + return; + } + + cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc; + cJSON_free = (hooks->free_fn)?hooks->free_fn:free; +} + +// Internal constructor. +static cJSON *cJSON_New_Item(void) +{ + cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON)); + if (node) memset(node,0,sizeof(cJSON)); + return node; +} + +// Delete a cJSON structure. +void cJSON_Delete(cJSON *c) +{ + cJSON *next; + while (c) + { + next=c->next; + if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child); + if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring); + if (c->string) cJSON_free(c->string); + cJSON_free(c); + c=next; + } +} + +// Parse the input text to generate a number, and populate the result into item. +static const char *parse_number(cJSON *item,const char *num) +{ + double n=0,sign=1,scale=0;int subscale=0,signsubscale=1; + + // Could use sscanf for this? + if (*num=='-') sign=-1,num++; // Has sign? + if (*num=='0') num++; // is zero + if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); // Number? + if (*num=='.') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} // Fractional part? + if (*num=='e' || *num=='E') // Exponent? + { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; // With sign? + while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); // Number? + } + + n=sign*n*pow(10.0,(scale+subscale*signsubscale)); // number = +/- number.fraction * 10^+/- exponent + + item->valuedouble=n; + item->valueint=(int)n; + item->type=cJSON_Number; + return num; +} + +// Render the number nicely from the given item into a string. +static char *print_number(cJSON *item) +{ + char *str; + double d=item->valuedouble; + if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN) + { + str=(char*)cJSON_malloc(21); // 2^64+1 can be represented in 21 chars. + sprintf(str,"%d",item->valueint); + } + else + { + str=(char*)cJSON_malloc(64); // This is a nice tradeoff. + if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d); + else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); + else sprintf(str,"%f",d); + } + return str; +} + +// Parse the input text into an unescaped cstring, and populate item. +static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; +static const char *parse_string(cJSON *item,const char *str) +{ + const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc; + if (*str!='\"') return 0; // not a string! + + while (*ptr!='\"' && (unsigned char)*ptr>31 && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes. + + out=(char*)cJSON_malloc(len+1); // This is how long we need for the string, roughly. + if (!out) return 0; + + ptr=str+1;ptr2=out; + while (*ptr!='\"' && (unsigned char)*ptr>31) + { + if (*ptr!='\\') *ptr2++=*ptr++; + else + { + ptr++; + switch (*ptr) + { + case 'b': *ptr2++='\b'; break; + case 'f': *ptr2++='\f'; break; + case 'n': *ptr2++='\n'; break; + case 'r': *ptr2++='\r'; break; + case 't': *ptr2++='\t'; break; + case 'u': // transcode utf16 to utf8. DOES NOT SUPPORT SURROGATE PAIRS CORRECTLY. + sscanf(ptr+1,"%4x",&uc); // get the unicode char. + len=3;if (uc<0x80) len=1;else if (uc<0x800) len=2;ptr2+=len; + + switch (len) { + case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; + case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; + case 1: *--ptr2 =(uc | firstByteMark[len]); + } + ptr2+=len;ptr+=4; + break; + default: *ptr2++=*ptr; break; + } + ptr++; + } + } + *ptr2=0; + if (*ptr=='\"') ptr++; + item->valuestring=out; + item->type=cJSON_String; + return ptr; +} + +// Render the cstring provided to an escaped version that can be printed. +static char *print_string_ptr(const char *str) +{ + const char *ptr;char *ptr2,*out;int len=0; + + if (!str) return cJSON_strdup(""); + ptr=str;while (*ptr && ++len) {if ((unsigned char)*ptr<32 || *ptr=='\"' || *ptr=='\\') len++;ptr++;} + + out=(char*)cJSON_malloc(len+3); + ptr2=out;ptr=str; + *ptr2++='\"'; + while (*ptr) + { + if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++; + else + { + *ptr2++='\\'; + switch (*ptr++) + { + case '\\': *ptr2++='\\'; break; + case '\"': *ptr2++='\"'; break; + case '\b': *ptr2++='b'; break; + case '\f': *ptr2++='f'; break; + case '\n': *ptr2++='n'; break; + case '\r': *ptr2++='r'; break; + case '\t': *ptr2++='t'; break; + default: ptr2--; break; // eviscerate with prejudice. + } + } + } + *ptr2++='\"';*ptr2++=0; + return out; +} +// Invote print_string_ptr (which is useful) on an item. +static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);} + +// Predeclare these prototypes. +static const char *parse_value(cJSON *item,const char *value); +static char *print_value(cJSON *item,int depth,int fmt); +static const char *parse_array(cJSON *item,const char *value); +static char *print_array(cJSON *item,int depth,int fmt); +static const char *parse_object(cJSON *item,const char *value); +static char *print_object(cJSON *item,int depth,int fmt); + +// Utility to jump whitespace and cr/lf +static const char *skip(const char *in) {while (in && (unsigned char)*in<=32) in++; return in;} + +// Parse an object - create a new root, and populate. +cJSON *cJSON_Parse(const char *value) +{ + cJSON *c=cJSON_New_Item(); + if (!c) return 0; /* memory fail */ + + if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;} + return c; +} + +// Render a cJSON item/entity/structure to text. +char *cJSON_Print(cJSON *item) {return print_value(item,0,1);} +char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);} + +// Parser core - when encountering text, process appropriately. +static const char *parse_value(cJSON *item,const char *value) +{ + if (!value) return 0; // Fail on null. + if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; } + if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; } + if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; } + if (*value=='\"') { return parse_string(item,value); } + if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); } + if (*value=='[') { return parse_array(item,value); } + if (*value=='{') { return parse_object(item,value); } + + return 0; // failure. +} + +// Render a value to text. +static char *print_value(cJSON *item,int depth,int fmt) +{ + char *out=0; + if (!item) return 0; + switch ((item->type)&255) + { + case cJSON_NULL: out=cJSON_strdup("null"); break; + case cJSON_False: out=cJSON_strdup("false");break; + case cJSON_True: out=cJSON_strdup("true"); break; + case cJSON_Number: out=print_number(item);break; + case cJSON_String: out=print_string(item);break; + case cJSON_Array: out=print_array(item,depth,fmt);break; + case cJSON_Object: out=print_object(item,depth,fmt);break; + } + return out; +} + +// Build an array from input text. +static const char *parse_array(cJSON *item,const char *value) +{ + cJSON *child; + if (*value!='[') return 0; // not an array! + + item->type=cJSON_Array; + value=skip(value+1); + if (*value==']') return value+1; // empty array. + + item->child=child=cJSON_New_Item(); + if (!item->child) return 0; // memory fail + value=skip(parse_value(child,skip(value))); // skip any spacing, get the value. + if (!value) return 0; + + while (*value==',') + { + cJSON *new_item; + if (!(new_item=cJSON_New_Item())) return 0; // memory fail + child->next=new_item;new_item->prev=child;child=new_item; + value=skip(parse_value(child,skip(value+1))); + if (!value) return 0; // memory fail + } + + if (*value==']') return value+1; // end of array + return 0; // malformed. +} + +// Render an array to text +static char *print_array(cJSON *item,int depth,int fmt) +{ + char **entries; + char *out=0,*ptr,*ret;int len=5; + cJSON *child=item->child; + int numentries=0,i=0,fail=0; + + // How many entries in the array? + while (child) numentries++,child=child->next; + // Allocate an array to hold the values for each + entries=(char**)cJSON_malloc(numentries*sizeof(char*)); + if (!entries) return 0; + memset(entries,0,numentries*sizeof(char*)); + // Retrieve all the results: + child=item->child; + while (child && !fail) + { + ret=print_value(child,depth+1,fmt); + entries[i++]=ret; + if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1; + child=child->next; + } + + // If we didn't fail, try to malloc the output string + if (!fail) out=cJSON_malloc(len); + // If that fails, we fail. + if (!out) fail=1; + + // Handle failure. + if (fail) + { + for (i=0;itype=cJSON_Object; + value=skip(value+1); + if (*value=='}') return value+1; // empty array. + + item->child=child=cJSON_New_Item(); + value=skip(parse_string(child,skip(value))); + if (!value) return 0; + child->string=child->valuestring;child->valuestring=0; + if (*value!=':') return 0; // fail! + value=skip(parse_value(child,skip(value+1))); // skip any spacing, get the value. + if (!value) return 0; + + while (*value==',') + { + cJSON *new_item; + if (!(new_item=cJSON_New_Item())) return 0; // memory fail + child->next=new_item;new_item->prev=child;child=new_item; + value=skip(parse_string(child,skip(value+1))); + if (!value) return 0; + child->string=child->valuestring;child->valuestring=0; + if (*value!=':') return 0; // fail! + value=skip(parse_value(child,skip(value+1))); // skip any spacing, get the value. + if (!value) return 0; + } + + if (*value=='}') return value+1; // end of array + return 0; // malformed. +} + +// Render an object to text. +static char *print_object(cJSON *item,int depth,int fmt) +{ + char **entries=0,**names=0; + char *out=0,*ptr,*ret,*str;int len=7,i=0,j; + cJSON *child=item->child; + int numentries=0,fail=0; + // Count the number of entries. + while (child) numentries++,child=child->next; + // Allocate space for the names and the objects + entries=(char**)cJSON_malloc(numentries*sizeof(char*)); + if (!entries) return 0; + names=(char**)cJSON_malloc(numentries*sizeof(char*)); + if (!names) {cJSON_free(entries);return 0;} + memset(entries,0,sizeof(char*)*numentries); + memset(names,0,sizeof(char*)*numentries); + + // Collect all the results into our arrays: + child=item->child;depth++;if (fmt) len+=depth; + while (child) + { + names[i]=str=print_string_ptr(child->string); + entries[i++]=ret=print_value(child,depth,fmt); + if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1; + child=child->next; + } + + // Try to allocate the output string + if (!fail) out=(char*)cJSON_malloc(len); + if (!out) fail=1; + + // Handle failure + if (fail) + { + for (i=0;ichild;int i=0;while(c)i++,c=c->next;return i;} +cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;} +cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;} + +// Utility for array list handling. +static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;} +// Utility for handling references. +static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;} + +// Add item to array/object. +void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}} +void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);} +void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));} +void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));} + +cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0; + if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;} +void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));} +cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;} +void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));} + +// Replace array/object items with new ones. +void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return; + newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem; + if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);} +void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}} + +// Create basic types: +cJSON *cJSON_CreateNull() {cJSON *item=cJSON_New_Item();item->type=cJSON_NULL;return item;} +cJSON *cJSON_CreateTrue() {cJSON *item=cJSON_New_Item();item->type=cJSON_True;return item;} +cJSON *cJSON_CreateFalse() {cJSON *item=cJSON_New_Item();item->type=cJSON_False;return item;} +cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int)num;return item;} +cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();item->type=cJSON_String;item->valuestring=cJSON_strdup(string);return item;} +cJSON *cJSON_CreateArray() {cJSON *item=cJSON_New_Item();item->type=cJSON_Array;return item;} +cJSON *cJSON_CreateObject() {cJSON *item=cJSON_New_Item();item->type=cJSON_Object;return item;} + +// Create Arrays: +cJSON *cJSON_CreateIntArray(int *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateFloatArray(float *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateDoubleArray(double *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateStringArray(const char **strings,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;ichild=n;else suffix_object(p,n);p=n;}return a;}