RTS API Documentation  1.10.11
Functions
switch_json.h File Reference
#include "switch.h"
#include "switch_cJSON.h"
#include "switch_cJSON_Utils.h"
+ Include dependency graph for switch_json.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

cJSONcJSON_CreateStringPrintf (const char *fmt,...)
 
const char * cJSON_GetObjectCstr (const cJSON *object, const char *string)
 
static cJSONjson_add_child_obj (cJSON *json, const char *name, cJSON *obj)
 
static cJSONjson_add_child_array (cJSON *json, const char *name)
 
static cJSONjson_add_child_string (cJSON *json, const char *name, const char *val)
 
static int cJSON_isTrue (cJSON *json)
 

Function Documentation

◆ cJSON_CreateStringPrintf()

cJSON* cJSON_CreateStringPrintf ( const char *  fmt,
  ... 
)

Definition at line 3 of file switch_json.c.

References item, and switch_vmprintf().

4 {
5  va_list ap;
6  char *str;
7  cJSON *item;
8 
9  va_start(ap, fmt);
10  str = switch_vmprintf(fmt, ap);
11  va_end(ap);
12 
13  if (!str) return NULL;
14 
15  item = cJSON_CreateString(str);
16 
17  free(str);
18 
19  return item;
20 }
int cJSON_bool fmt
Definition: switch_cJSON.h:150
cJSON * item
Definition: switch_cJSON.h:210
char * switch_vmprintf(const char *zFormat, va_list ap)

◆ cJSON_GetObjectCstr()

const char* cJSON_GetObjectCstr ( const cJSON object,
const char *  string 
)

Definition at line 22 of file switch_json.c.

References cJSON_String, cJSON::type, and cJSON::valuestring.

Referenced by switch_collect_input_callback(), switch_dial_handle_create_json_obj(), switch_jwt_verify(), switch_live_array_add(), and switch_live_array_parse_json().

23 {
24  cJSON *cj = cJSON_GetObjectItem(object, string);
25 
26  if (!cj || cj->type != cJSON_String || !cj->valuestring) return NULL;
27 
28  return cj->valuestring;
29 }
char * valuestring
Definition: switch_cJSON.h:107
#define cJSON_String
Definition: switch_cJSON.h:86
int type
Definition: switch_cJSON.h:104

◆ cJSON_isTrue()

static int cJSON_isTrue ( cJSON json)
inlinestatic

Definition at line 96 of file switch_json.h.

References cJSON_Number, cJSON_String, cJSON_True, cJSON::type, cJSON::valuedouble, cJSON::valueint, and cJSON::valuestring.

97 {
98  if (!json) return 0;
99 
100  if (json->type == cJSON_True) return 1;
101 
102  if (json->type == cJSON_String && (
103  !strcasecmp(json->valuestring, "yes") ||
104  !strcasecmp(json->valuestring, "on") ||
105  !strcasecmp(json->valuestring, "true") ||
106  !strcasecmp(json->valuestring, "t") ||
107  !strcasecmp(json->valuestring, "enabled") ||
108  !strcasecmp(json->valuestring, "active") ||
109  !strcasecmp(json->valuestring, "allow") ||
110  atoi(json->valuestring))) {
111  return 1;
112  }
113 
114  if (json->type == cJSON_Number && (json->valueint || json->valuedouble)) {
115  return 1;
116  }
117 
118  return 0;
119 }
int valueint
Definition: switch_cJSON.h:109
char * valuestring
Definition: switch_cJSON.h:107
#define cJSON_String
Definition: switch_cJSON.h:86
#define cJSON_True
Definition: switch_cJSON.h:83
int type
Definition: switch_cJSON.h:104
double valuedouble
Definition: switch_cJSON.h:111
#define cJSON_Number
Definition: switch_cJSON.h:85

◆ json_add_child_array()

static cJSON* json_add_child_array ( cJSON json,
const char *  name 
)
inlinestatic

Definition at line 68 of file switch_json.h.

References switch_assert.

Referenced by switch_live_array_bootstrap().

69 {
70  cJSON *new_json = NULL;
71 
72  switch_assert(json);
73 
74  new_json = cJSON_CreateArray();
75  switch_assert(new_json);
76 
77  cJSON_AddItemToObject(json, name, new_json);
78 
79  return new_json;
80 }
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)

◆ json_add_child_obj()

static cJSON* json_add_child_obj ( cJSON json,
const char *  name,
cJSON obj 
)
inlinestatic

Definition at line 49 of file switch_json.h.

References switch_assert.

Referenced by switch_live_array_add(), switch_live_array_bootstrap(), switch_live_array_clear(), switch_live_array_del(), and switch_live_array_visible().

50 {
51  cJSON *new_json = NULL;
52 
53  switch_assert(json);
54 
55  if (obj) {
56  new_json = obj;
57  } else {
58  new_json = cJSON_CreateObject();
59  }
60 
61  switch_assert(new_json);
62 
63  cJSON_AddItemToObject(json, name, new_json);
64 
65  return new_json;
66 }
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)

◆ json_add_child_string()

static cJSON* json_add_child_string ( cJSON json,
const char *  name,
const char *  val 
)
inlinestatic

Definition at line 82 of file switch_json.h.

References switch_assert.

Referenced by switch_json_add_presence_data_cols().

83 {
84  cJSON *new_json = NULL;
85 
86  switch_assert(json);
87 
88  new_json = cJSON_CreateString(val);
89  switch_assert(new_json);
90 
91  cJSON_AddItemToObject(json, name, new_json);
92 
93  return new_json;
94 }
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)