Skip to content

Commit

Permalink
Merge pull request #1418 from kamailio/json-update-api
Browse files Browse the repository at this point in the history
json: pass str pointer to API
  • Loading branch information
Emmanuel Schmidbauer committed Jan 30, 2018
2 parents 5fe8618 + 26b09ae commit 00da053
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/modules/json/api.h
Expand Up @@ -26,7 +26,7 @@

typedef struct json_object *(*json_parse_f) (const char *str);
typedef struct json_object *(*json_get_object_f) (struct json_object *json_obj, const char *str);
typedef str (*json_extract_field_f) (struct json_object *json_obj, char *json_name);
typedef int (*json_extract_field_f) (struct json_object *json_obj, char *json_name, str *var);

typedef struct json_api {
json_parse_f json_parse;
Expand Down
22 changes: 11 additions & 11 deletions src/modules/json/json_funcs.h
Expand Up @@ -29,18 +29,18 @@

int json_get_field(struct sip_msg* msg, char* json, char* field, char* dst);

#define json_extract_field(json_name, field) \
do { \
#define json_extract_field(json_name, field) \
do { \
struct json_object *obj = json_get_object(json_obj, json_name); \
field.s = (char *)json_object_get_string(obj); \
if(field.s == NULL) { \
LM_DBG("Json-c error - failed to extract field [%s]\n", \
json_name); \
field.s = ""; \
} else { \
field.len = strlen(field.s); \
} \
LM_DBG("%s: [%s]\n", json_name, field.s ? field.s : "Empty"); \
field->s = (char *)json_object_get_string(obj); \
if(field->s == NULL) { \
LM_DBG("Json-c error - failed to extract field [%s]\n", \
json_name); \
field->s = ""; \
} else { \
field->len = strlen(field->s); \
} \
LM_DBG("%s: [%s]\n", json_name, field->s ? field->s : "Empty"); \
} while(0);


Expand Down
5 changes: 2 additions & 3 deletions src/modules/json/json_mod.c
Expand Up @@ -65,10 +65,9 @@ struct module_exports exports = {
0 /* per-child init function */
};

str _json_extract_field(struct json_object *json_obj, char *json_name) {
str val = {0, 0};
int _json_extract_field(struct json_object *json_obj, char *json_name, str *val) {
json_extract_field(json_name, val);
return val;
return 0;
}

/**
Expand Down

0 comments on commit 00da053

Please sign in to comment.