提交 20bcb2ed authored 作者: Mike Jerris's avatar Mike Jerris

FS-10036: update cJSON code to pre 1.4.0 release of cJSON. this includes…

FS-10036: update cJSON code to pre 1.4.0 release of cJSON.  this includes backports of all our fixes, and our build macros for windows and visibility.  It also makes it easy to drop in a new version, and to in the future be able to switch to a system version of cJSON easily (after all these updates are in, probably around v2.0 timeframe.  Note this new version adds a lot of extra error checking, fixes some buffer overruns, and improves parser and printer performance
上级 ab21189e
...@@ -299,6 +299,8 @@ library_include_HEADERS = \ ...@@ -299,6 +299,8 @@ library_include_HEADERS = \
src/include/switch_xml_config.h \ src/include/switch_xml_config.h \
src/include/switch_cpp.h \ src/include/switch_cpp.h \
src/include/switch_curl.h \ src/include/switch_curl.h \
src/include/switch_cJSON.h \
src/include/switch_cJSON_Utils.h \
src/include/switch_json.h \ src/include/switch_json.h \
src/include/switch_utf8.h \ src/include/switch_utf8.h \
src/include/switch_msrp.h \ src/include/switch_msrp.h \
...@@ -379,6 +381,8 @@ libfreeswitch_la_SOURCES = \ ...@@ -379,6 +381,8 @@ libfreeswitch_la_SOURCES = \
src/switch_pcm.c \ src/switch_pcm.c \
src/switch_speex.c \ src/switch_speex.c \
src/switch_profile.c \ src/switch_profile.c \
src/cJSON.c \
src/cJSON_Utils.c \
src/switch_json.c \ src/switch_json.c \
src/switch_curl.c \ src/switch_curl.c \
src/switch_hashtable.c\ src/switch_hashtable.c\
...@@ -422,7 +426,7 @@ bin_PROGRAMS = freeswitch fs_cli fs_ivrd tone2wav fs_encode ...@@ -422,7 +426,7 @@ bin_PROGRAMS = freeswitch fs_cli fs_ivrd tone2wav fs_encode
## fs_cli () ## fs_cli ()
## ##
fs_cli_SOURCES = libs/esl/src/esl.c libs/esl/src/esl_config.c libs/esl/src/esl_event.c \ fs_cli_SOURCES = libs/esl/src/esl.c libs/esl/src/esl_config.c libs/esl/src/esl_event.c \
libs/esl/src/esl_threadmutex.c libs/esl/fs_cli.c libs/esl/src/esl_json.c libs/esl/src/esl_buffer.c libs/esl/src/esl_threadmutex.c libs/esl/fs_cli.c libs/esl/src/esl_json.c libs/esl/src/esl_buffer.c libs/esl/src/cJSON.c libs/esl/src/cJSON_Utils.c
fs_cli_CFLAGS = $(AM_CFLAGS) -I$(switch_srcdir)/libs/esl/src/include $(LIBEDIT_CFLAGS) fs_cli_CFLAGS = $(AM_CFLAGS) -I$(switch_srcdir)/libs/esl/src/include $(LIBEDIT_CFLAGS)
fs_cli_LDFLAGS = $(AM_LDFLAGS) -lpthread $(ESL_LDFLAGS) -lm $(LIBEDIT_LIBS) fs_cli_LDFLAGS = $(AM_LDFLAGS) -lpthread $(ESL_LDFLAGS) -lm $(LIBEDIT_LIBS)
...@@ -460,7 +464,7 @@ endif ...@@ -460,7 +464,7 @@ endif
## fs_ivrd () ## fs_ivrd ()
## ##
fs_ivrd_SOURCES = libs/esl/src/esl.c libs/esl/src/esl_config.c libs/esl/src/esl_event.c \ fs_ivrd_SOURCES = libs/esl/src/esl.c libs/esl/src/esl_config.c libs/esl/src/esl_event.c \
libs/esl/src/esl_threadmutex.c libs/esl/ivrd.c libs/esl/src/esl_json.c libs/esl/src/esl_buffer.c libs/esl/src/esl_threadmutex.c libs/esl/ivrd.c libs/esl/src/esl_json.c libs/esl/src/esl_buffer.c libs/esl/src/cJSON.c libs/esl/src/cJSON_Utils.c
fs_ivrd_CFLAGS = $(AM_CFLAGS) -I$(switch_srcdir)/libs/esl/src/include fs_ivrd_CFLAGS = $(AM_CFLAGS) -I$(switch_srcdir)/libs/esl/src/include
fs_ivrd_LDFLAGS = $(AM_LDFLAGS) -lpthread $(ESL_LDFLAGS) -lm fs_ivrd_LDFLAGS = $(AM_LDFLAGS) -lpthread $(ESL_LDFLAGS) -lm
......
...@@ -496,8 +496,8 @@ if test "x${enable_visibility}" != "xno" ; then ...@@ -496,8 +496,8 @@ if test "x${enable_visibility}" != "xno" ; then
)], )],
[AC_MSG_RESULT([yes]) [AC_MSG_RESULT([yes])
APR_ADDTO([SWITCH_AM_CFLAGS], [-fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DHAVE_VISIBILITY=1]) APR_ADDTO([SWITCH_AM_CFLAGS], [-fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DCJSON_API_VISIBILITY=1 -DHAVE_VISIBILITY=1])
APR_ADDTO([SWITCH_AM_CXXFLAGS], [-fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DHAVE_VISIBILITY=1]) APR_ADDTO([SWITCH_AM_CXXFLAGS], [-fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DCJSON_API_VISIBILITY=1 -DHAVE_VISIBILITY=1])
HAVE_VISIBILITY="yes"], HAVE_VISIBILITY="yes"],
[AC_MSG_RESULT([no])] [AC_MSG_RESULT([no])]
......
...@@ -10,7 +10,7 @@ libesl_la_CFLAGS = $(SWITCH_AM_CFLAGS) $(PICKY) $(SYSTEM_CFLAGS) ...@@ -10,7 +10,7 @@ libesl_la_CFLAGS = $(SWITCH_AM_CFLAGS) $(PICKY) $(SYSTEM_CFLAGS)
libesl_la_CXXFLAGS = $(SWITCH_AM_CXXFLAGS) libesl_la_CXXFLAGS = $(SWITCH_AM_CXXFLAGS)
libesl_la_CPPFLAGS = -I$(switch_srcdir)/libs/esl/src/include libesl_la_CPPFLAGS = -I$(switch_srcdir)/libs/esl/src/include
libesl_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) -static -no-undefined -L. $(SYSTEM_LDFLAGS) libesl_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) -static -no-undefined -L. $(SYSTEM_LDFLAGS)
libesl_la_SOURCES = src/esl.c src/esl_event.c src/esl_threadmutex.c src/esl_config.c src/esl_json.c src/esl_buffer.c libesl_la_SOURCES = src/esl.c src/esl_event.c src/esl_threadmutex.c src/esl_config.c src/esl_json.c src/esl_buffer.c src/cJSON.c src/cJSON_Utils.c
if ENABLE_CPP if ENABLE_CPP
libesl_la_SOURCES += src/esl_oop.cpp libesl_la_SOURCES += src/esl_oop.cpp
endif endif
......
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
#include "switch_cJSON.h"
/* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */
CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON *object, const char *pointer);
/* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */
CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON *from, cJSON *to);
/* Utility for generating patch array entries. */
CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON *array, const char *op, const char *path, cJSON *val);
/* Returns 0 for success. */
CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON *object, cJSON *patches);
/*
// Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use:
//int cJSONUtils_AtomicApplyPatches(cJSON **object, cJSON *patches)
//{
// cJSON *modme = cJSON_Duplicate(*object, 1);
// int error = cJSONUtils_ApplyPatches(modme, patches);
// if (!error)
// {
// cJSON_Delete(*object);
// *object = modme;
// }
// else
// {
// cJSON_Delete(modme);
// }
//
// return error;
//}
// Code not added to library since this strategy is a LOT slower.
*/
/* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */
/* target will be modified by patch. return value is new ptr for target. */
CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatch(cJSON *target, cJSON *patch);
/* generates a patch to move from -> to */
CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to);
/* Given a root object and a target object, construct a pointer from one to the other. */
CJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(cJSON *object, cJSON *target);
/* Sorts the members of the object into alphabetical order. */
CJSON_PUBLIC(void) cJSONUtils_SortObject(cJSON *object);
...@@ -20,119 +20,80 @@ ...@@ -20,119 +20,80 @@
THE SOFTWARE. THE SOFTWARE.
*/ */
#include "esl.h" #include "esl.h"
#ifndef cJSON__h #ifndef ESL_JSON__h
#define cJSON__h #define ESL_JSON__h
#ifdef ESL_EXPORTS
#ifndef CJSON_EXPORT_SYMBOLS
#define CJSON_EXPORT_SYMBOLS 1
#endif
#endif
#ifdef SWITCH_API_VISIBILITY
#ifndef CJSON_API_VISIBILITY
#define CJSON_API_VISIBILITY 1
#endif
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
/* cJSON Types: */ #include "esl_cJSON.h"
#define cJSON_False 0 #include "esl_cJSON_Utils.h"
#define cJSON_True 1
#define cJSON_NULL 2 ESL_DECLARE(const char *)cJSON_GetObjectCstr(const cJSON *object, const char *string);
#define cJSON_Number 3
#define cJSON_String 4 static inline cJSON *esl_json_add_child_obj(cJSON *json, const char *name, cJSON *obj)
#define cJSON_Array 5 {
#define cJSON_Object 6 cJSON *new_json = NULL;
#define cJSON_IsReference 256 esl_assert(json);
/* The cJSON structure: */ if (obj) {
typedef struct cJSON { new_json = obj;
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ } else {
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ new_json = cJSON_CreateObject();
}
int type; /* The type of the item, as above. */
esl_assert(new_json);
char *valuestring; /* The item's string, if type==cJSON_String */
int valueint; /* The item's number, if type==cJSON_Number */ cJSON_AddItemToObject(json, name, new_json);
double valuedouble; /* The item's number, if type==cJSON_Number */
return new_json;
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;
static inline cJSON *esl_json_add_child_array(cJSON *json, const char *name)
typedef struct cJSON_Hooks { {
void *(*malloc_fn)(size_t sz); cJSON *new_json = NULL;
void (*free_fn)(void *ptr);
} cJSON_Hooks; esl_assert(json);
/* Supply malloc, realloc and free functions to cJSON */ new_json = cJSON_CreateArray();
ESL_DECLARE(void) cJSON_InitHooks(cJSON_Hooks* hooks); esl_assert(new_json);
cJSON_AddItemToObject(json, name, new_json);
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
ESL_DECLARE(cJSON *)cJSON_Parse(const char *value); return new_json;
/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ }
ESL_DECLARE(char *)cJSON_Print(cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ static inline cJSON *esl_json_add_child_string(cJSON *json, const char *name, const char *val)
ESL_DECLARE(char *)cJSON_PrintUnformatted(cJSON *item); {
/* Delete a cJSON entity and all subentities. */ cJSON *new_json = NULL;
ESL_DECLARE(void) cJSON_Delete(cJSON *c);
esl_assert(json);
/* Returns the number of items in an array (or object). */
ESL_DECLARE(int) cJSON_GetArraySize(cJSON *array); new_json = cJSON_CreateString(val);
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ esl_assert(new_json);
ESL_DECLARE(cJSON *)cJSON_GetArrayItem(cJSON *array,int item);
/* Get item "string" from object. Case insensitive. */ cJSON_AddItemToObject(json, name, new_json);
ESL_DECLARE(cJSON *)cJSON_GetObjectItem(cJSON *object,const char *string);
return new_json;
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ }
ESL_DECLARE(const char *)cJSON_GetErrorPtr(void);
/* These calls create a cJSON item of the appropriate type. */
ESL_DECLARE(cJSON *)cJSON_CreateNull(void);
ESL_DECLARE(cJSON *)cJSON_CreateTrue(void);
ESL_DECLARE(cJSON *)cJSON_CreateFalse(void);
ESL_DECLARE(cJSON *)cJSON_CreateBool(int b);
ESL_DECLARE(cJSON *)cJSON_CreateNumber(double num);
ESL_DECLARE(cJSON *)cJSON_CreateString(const char *string);
ESL_DECLARE(cJSON *)cJSON_CreateArray(void);
ESL_DECLARE(cJSON *)cJSON_CreateObject(void);
/* These utilities create an Array of count items. */
ESL_DECLARE(cJSON *)cJSON_CreateIntArray(int *numbers,int count);
ESL_DECLARE(cJSON *)cJSON_CreateFloatArray(float *numbers,int count);
ESL_DECLARE(cJSON *)cJSON_CreateDoubleArray(double *numbers,int count);
ESL_DECLARE(cJSON *)cJSON_CreateStringArray(const char **strings,int count);
/* Append item to the specified array/object. */
ESL_DECLARE(void) cJSON_AddItemToArray(cJSON *array, cJSON *item);
ESL_DECLARE(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. */
ESL_DECLARE(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
ESL_DECLARE(void) cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
/* Remove/Detatch items from Arrays/Objects. */
ESL_DECLARE(cJSON *)cJSON_DetachItemFromArray(cJSON *array,int which);
ESL_DECLARE(void) cJSON_DeleteItemFromArray(cJSON *array,int which);
ESL_DECLARE(cJSON *)cJSON_DetachItemFromObject(cJSON *object,const char *string);
ESL_DECLARE(void) cJSON_DeleteItemFromObject(cJSON *object,const char *string);
/* Update array items. */
ESL_DECLARE(void) cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
ESL_DECLARE(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 #ifdef __cplusplus
} }
#endif #endif
#endif #endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
...@@ -7,7 +7,7 @@ AM_CFLAGS += -I$(top_srcdir)/src -I$(top_srcdir)/src/include -I$(top_srcdir)/ ...@@ -7,7 +7,7 @@ AM_CFLAGS += -I$(top_srcdir)/src -I$(top_srcdir)/src/include -I$(top_srcdir)/
AM_CPPFLAGS = $(AM_CFLAGS) AM_CPPFLAGS = $(AM_CFLAGS)
lib_LTLIBRARIES = libks.la lib_LTLIBRARIES = libks.la
libks_la_SOURCES = src/ks.c src/ks_string.c src/ks_json.c src/ks_thread.c src/ks_thread_pool.c src/ks_mutex.c src/ks_config.c libks_la_SOURCES = src/ks.c src/ks_string.c src/ks_json.c src/cJSON.c src/cJSON_Utils.c src/ks_thread.c src/ks_thread_pool.c src/ks_mutex.c src/ks_config.c
libks_la_SOURCES += src/ks_log.c src/ks_socket.c src/ks_buffer.c src/ks_pool.c src/simclist.c libks_la_SOURCES += src/ks_log.c src/ks_socket.c src/ks_buffer.c src/ks_pool.c src/simclist.c
libks_la_SOURCES += src/ks_time.c src/ks_printf.c src/ks_hash.c src/ks_q.c src/ks_dso.c # src/ks_dht.c libks_la_SOURCES += src/ks_time.c src/ks_printf.c src/ks_hash.c src/ks_q.c src/ks_dso.c # src/ks_dht.c
libks_la_SOURCES += src/ks_ssl.c src/kws.c src/ks_rng.c libks_la_SOURCES += src/ks_ssl.c src/kws.c src/ks_rng.c
...@@ -26,7 +26,7 @@ libks_la_LDFLAGS = $(AM_LDFLAGS) -version-info 0:1:0 -lncurses -lpthread -lm ...@@ -26,7 +26,7 @@ libks_la_LDFLAGS = $(AM_LDFLAGS) -version-info 0:1:0 -lncurses -lpthread -lm
library_includedir = $(prefix)/include library_includedir = $(prefix)/include
library_include_HEADERS = src/include/ks_config.h src/include/ks.h src/include/ks_threadmutex.h src/include/ks_json.h src/include/ks_buffer.h library_include_HEADERS = src/include/ks_config.h src/include/ks.h src/include/ks_threadmutex.h src/include/ks_json.h src/include/ks_buffer.h
library_include_HEADERS += src/include/ks_thread_pool.h library_include_HEADERS += src/include/ks_thread_pool.h src/include/ks_cJSON.h src/include/ks_cJSON_Utils.h
library_include_HEADERS += src/include/ks_pool.h src/include/simclist.h src/include/ks_time.h src/include/ks_q.h src/include/ks_socket.h library_include_HEADERS += src/include/ks_pool.h src/include/simclist.h src/include/ks_time.h src/include/ks_q.h src/include/ks_socket.h
library_include_HEADERS += src/include/ks_dso.h src/include/ks_platform.h src/include/ks_types.h # src/include/ks_rng.h src/include/ks_dht.h library_include_HEADERS += src/include/ks_dso.h src/include/ks_platform.h src/include/ks_types.h # src/include/ks_rng.h src/include/ks_dht.h
library_include_HEADERS += src/include/ks_printf.h src/include/ks_hash.h src/include/ks_ssl.h src/include/kws.h library_include_HEADERS += src/include/ks_printf.h src/include/ks_hash.h src/include/ks_ssl.h src/include/kws.h
......
...@@ -124,7 +124,7 @@ if test "x${enable_visibility}" != "xno" ; then ...@@ -124,7 +124,7 @@ if test "x${enable_visibility}" != "xno" ; then
)], )],
[AC_MSG_RESULT([yes]) [AC_MSG_RESULT([yes])
AM_CFLAGS="${AM_CFLAGS} -DKS_API_VISIBILITY=1 -fvisibility=hidden" AM_CFLAGS="${AM_CFLAGS} -DKS_API_VISIBILITY=1 -DCJSON_API_VISIBILITY=1 -fvisibility=hidden"
AC_DEFINE([HAVE_VISIBILITY], [1], [GCC visibility support available]) AC_DEFINE([HAVE_VISIBILITY], [1], [GCC visibility support available])
HAVE_VISIBILITY="yes"], HAVE_VISIBILITY="yes"],
...@@ -144,7 +144,7 @@ if test "x${enable_visibility}" != "xno" ; then ...@@ -144,7 +144,7 @@ if test "x${enable_visibility}" != "xno" ; then
)], )],
[AC_MSG_RESULT([yes]) [AC_MSG_RESULT([yes])
AM_CFLAGS="${AM_CFLAGS} -DKS_API_VISIBILITY=1 -xldscope=hidden" AM_CFLAGS="${AM_CFLAGS} -DKS_API_VISIBILITY=1 -DCJSON_API_VISIBILITY=1 -xldscope=hidden"
AC_DEFINE([HAVE_VISIBILITY], [1], [SUNCC visibility support available]) AC_DEFINE([HAVE_VISIBILITY], [1], [SUNCC visibility support available])
HAVE_VISIBILITY="yes"], HAVE_VISIBILITY="yes"],
......
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论