From 1473be69e191c6873cfc4e2501999ebeb8a45159 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 28 Sep 2017 08:41:57 +0200 Subject: [PATCH] cfgt: format code using clang-format --- src/modules/cfgt/cfgt.c | 10 +- src/modules/cfgt/cfgt.h | 9 +- src/modules/cfgt/cfgt_int.c | 454 +++++++++++++++-------------------- src/modules/cfgt/cfgt_int.h | 13 +- src/modules/cfgt/cfgt_json.c | 259 +++++++++----------- src/modules/cfgt/cfgt_json.h | 20 +- src/modules/cfgt/cfgt_mod.c | 59 +++-- src/modules/cfgt/cfgt_mod.h | 2 +- 8 files changed, 367 insertions(+), 459 deletions(-) diff --git a/src/modules/cfgt/cfgt.c b/src/modules/cfgt/cfgt.c index 256a259039a..2d6bb730b68 100644 --- a/src/modules/cfgt/cfgt.c +++ b/src/modules/cfgt/cfgt.c @@ -28,18 +28,18 @@ * \param api cfgt API * \return 0 on success, -1 on failure */ -int bind_cfgt(cfgt_api_t* api) +int bind_cfgt(cfgt_api_t *api) { - if (!api) { + if(!api) { LM_ERR("invalid parameter value\n"); return -1; } - if (init_flag==0) { + if(init_flag == 0) { LM_ERR("configuration error - trying to bind to cfgt module" - " before being initialized\n"); + " before being initialized\n"); return -1; } - api->cfgt_process_route = cfgt_process_route; + api->cfgt_process_route = cfgt_process_route; return 0; } diff --git a/src/modules/cfgt/cfgt.h b/src/modules/cfgt/cfgt.h index 17822f394c3..ea6101c2f59 100644 --- a/src/modules/cfgt/cfgt.h +++ b/src/modules/cfgt/cfgt.h @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * */ @@ -26,15 +26,16 @@ #include "../../core/sr_module.h" /* export not usable from scripts */ -#define NO_SCRIPT -1 +#define NO_SCRIPT -1 typedef int (*cfgt_process_route_f)(struct sip_msg *msg, struct action *a); -typedef struct cfgt_api { +typedef struct cfgt_api +{ cfgt_process_route_f cfgt_process_route; } cfgt_api_t; /*! cfgt API export bind function */ -typedef int (*bind_cfgt_t)(cfgt_api_t* api); +typedef int (*bind_cfgt_t)(cfgt_api_t *api); #endif diff --git a/src/modules/cfgt/cfgt_int.c b/src/modules/cfgt/cfgt_int.c index 20fcfb0fb8a..e2f402f587d 100644 --- a/src/modules/cfgt/cfgt_int.c +++ b/src/modules/cfgt/cfgt_int.c @@ -31,13 +31,8 @@ #include "cfgt_int.h" #include "cfgt_json.h" -static str _cfgt_route_prefix[] = { - str_init("start|"), - str_init("exit|"), - str_init("drop|"), - str_init("return|"), - {0, 0} -}; +static str _cfgt_route_prefix[] = {str_init("start|"), str_init("exit|"), + str_init("drop|"), str_init("return|"), {0, 0}}; cfgt_node_p _cfgt_node = NULL; cfgt_hash_p _cfgt_uuid = NULL; str cfgt_hdr_prefix = {"NGCP%", 5}; @@ -48,7 +43,7 @@ static int shm_str_hash_alloc(struct str_hash_table *ht, int size) { ht->table = shm_malloc(sizeof(struct str_hash_head) * size); - if (!ht->table) + if(!ht->table) return -1; ht->size = size; @@ -57,8 +52,7 @@ static int shm_str_hash_alloc(struct str_hash_table *ht, int size) static int _cfgt_init_hashtable(struct str_hash_table *ht) { - if (shm_str_hash_alloc(ht, CFGT_HASH_SIZE) != 0) - { + if(shm_str_hash_alloc(ht, CFGT_HASH_SIZE) != 0) { LM_ERR("Error allocating shared memory hashtable\n"); return -1; } @@ -70,12 +64,10 @@ static int _cfgt_init_hashtable(struct str_hash_table *ht) int _cfgt_pv_parse(str *param, pv_elem_p *elem) { - if (param->s && param->len > 0) - { - if (pv_parse_format(param, elem)<0) - { - LM_ERR("malformed or non AVP %.*s AVP definition\n", - param->len, param->s); + if(param->s && param->len > 0) { + if(pv_parse_format(param, elem) < 0) { + LM_ERR("malformed or non AVP %.*s AVP definition\n", param->len, + param->s); return -1; } } @@ -88,31 +80,27 @@ void _cfgt_remove_uuid(const str *uuid) struct str_hash_entry *entry, *back; int i; - if(_cfgt_uuid==NULL) return; - if(uuid) - { + if(_cfgt_uuid == NULL) + return; + if(uuid) { lock_get(&_cfgt_uuid->lock); entry = str_hash_get(&_cfgt_uuid->hash, uuid->s, uuid->len); - if(entry) - { + if(entry) { str_hash_del(entry); shm_free(entry->key.s); shm_free(entry); LM_DBG("uuid[%.*s] removed from hash\n", uuid->len, uuid->s); - } - else LM_DBG("uuid[%.*s] not found in hash\n", uuid->len, uuid->s); + } else + LM_DBG("uuid[%.*s] not found in hash\n", uuid->len, uuid->s); lock_release(&_cfgt_uuid->lock); - } - else - { + } else { lock_get(&_cfgt_uuid->lock); - for(i=0; ihash.table+i; + for(i = 0; i < CFGT_HASH_SIZE; i++) { + head = _cfgt_uuid->hash.table + i; clist_foreach_safe(head, entry, back, next) { - LM_DBG("uuid[%.*s] removed from hash\n", - entry->key.len, entry->key.s); + LM_DBG("uuid[%.*s] removed from hash\n", entry->key.len, + entry->key.s); str_hash_del(entry); shm_free(entry->key.s); shm_free(entry); @@ -127,25 +115,21 @@ int _cfgt_get_uuid_id(cfgt_node_p node) { struct str_hash_entry *entry; - if(_cfgt_uuid==NULL || node==NULL || node->uuid.len == 0) return -1; + if(_cfgt_uuid == NULL || node == NULL || node->uuid.len == 0) + return -1; lock_get(&_cfgt_uuid->lock); entry = str_hash_get(&_cfgt_uuid->hash, node->uuid.s, node->uuid.len); - if(entry) - { + if(entry) { entry->u.n = entry->u.n + 1; node->msgid = entry->u.n; - } - else - { + } else { entry = shm_malloc(sizeof(struct str_hash_entry)); - if(entry==NULL) - { + if(entry == NULL) { lock_release(&_cfgt_uuid->lock); LM_ERR("No shared memory left\n"); return -1; } - if (shm_str_dup(&entry->key, &node->uuid) != 0) - { + if(shm_str_dup(&entry->key, &node->uuid) != 0) { lock_release(&_cfgt_uuid->lock); shm_free(entry); LM_ERR("No shared memory left\n"); @@ -167,41 +151,35 @@ int _cfgt_get_hdr_helper(struct sip_msg *msg, str *res, int mode) char *delimiter, *end; str tmp = STR_NULL; - if(msg==NULL || (mode==0 && res==NULL)) + if(msg == NULL || (mode == 0 && res == NULL)) return -1; /* we need to be sure we have parsed all headers */ - if(parse_headers(msg, HDR_EOH_F, 0)<0) - { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("error parsing headers\n"); return -1; } hf = msg->callid; - if(!hf) return 1; + if(!hf) + return 1; - if(strncmp(hf->body.s, cfgt_hdr_prefix.s, cfgt_hdr_prefix.len)==0) - { - tmp.s = hf->body.s+cfgt_hdr_prefix.len; - delimiter = tmp.s-1; + if(strncmp(hf->body.s, cfgt_hdr_prefix.s, cfgt_hdr_prefix.len) == 0) { + tmp.s = hf->body.s + cfgt_hdr_prefix.len; + delimiter = tmp.s - 1; LM_DBG("Prefix detected. delimiter[%c]\n", *delimiter); - if(mode==0) - { + if(mode == 0) { end = strchr(tmp.s, *delimiter); - if(end) - { - tmp.len = end-tmp.s; - if(pkg_str_dup(res, &tmp)<0) - { + if(end) { + tmp.len = end - tmp.s; + if(pkg_str_dup(res, &tmp) < 0) { LM_ERR("error copying header\n"); return -1; } LM_DBG("cfgtest uuid:[%.*s]\n", res->len, res->s); return 0; } - } - else - { + } else { tmp.len = res->len; LM_DBG("tmp[%.*s] res[%.*s]\n", tmp.len, tmp.s, res->len, res->s); return STR_EQ(tmp, *res); @@ -224,51 +202,45 @@ cfgt_node_p cfgt_create_node(struct sip_msg *msg) { cfgt_node_p node; - node = (cfgt_node_p) pkg_malloc(sizeof(cfgt_node_t)); - if(node==NULL) - { + node = (cfgt_node_p)pkg_malloc(sizeof(cfgt_node_t)); + if(node == NULL) { LM_ERR("cannot allocate cfgtest msgnode\n"); return node; } memset(node, 0, sizeof(cfgt_node_t)); srjson_InitDoc(&node->jdoc, NULL); - if (msg) - { + if(msg) { node->msgid = msg->id; LM_DBG("msgid:%d\n", node->msgid); - if(_cfgt_get_hdr(msg, &node->uuid)!=0 || node->uuid.len==0) - { + if(_cfgt_get_hdr(msg, &node->uuid) != 0 || node->uuid.len == 0) { LM_ERR("cannot get value of cfgtest uuid header!!\n"); goto error; } } node->jdoc.root = srjson_CreateObject(&node->jdoc); - if(node->jdoc.root==NULL) - { + if(node->jdoc.root == NULL) { LM_ERR("cannot create json root\n"); goto error; } node->flow = srjson_CreateArray(&node->jdoc); - if(node->flow==NULL) - { + if(node->flow == NULL) { LM_ERR("cannot create json object\n"); goto error; } srjson_AddItemToObject(&node->jdoc, node->jdoc.root, "flow\0", node->flow); node->in = srjson_CreateArray(&node->jdoc); - if(node->in==NULL) - { + if(node->in == NULL) { LM_ERR("cannot create json object\n"); goto error; } srjson_AddItemToObject(&node->jdoc, node->jdoc.root, "sip_in\0", node->in); node->out = srjson_CreateArray(&node->jdoc); - if(node->out==NULL) - { + if(node->out == NULL) { LM_ERR("cannot create json object\n"); goto error; } - srjson_AddItemToObject(&node->jdoc, node->jdoc.root, "sip_out\0", node->out); + srjson_AddItemToObject( + &node->jdoc, node->jdoc.root, "sip_out\0", node->out); LM_DBG("node created\n"); return node; @@ -280,11 +252,12 @@ cfgt_node_p cfgt_create_node(struct sip_msg *msg) void _cfgt_remove_node(cfgt_node_p node) { - if(!node) return; + if(!node) + return; srjson_DestroyDoc(&node->jdoc); - if(node->uuid.s) pkg_free(node->uuid.s); - while(node->flow_head) - { + if(node->uuid.s) + pkg_free(node->uuid.s); + while(node->flow_head) { node->route = node->flow_head; node->flow_head = node->route->next; pkg_free(node->route); @@ -298,57 +271,56 @@ int _cfgt_get_filename(int msgid, str uuid, str *dest, int *dir) int i, lid; char buff_id[INT2STR_MAX_LEN]; char *sid; - if(dest==NULL || uuid.len == 0) return -1; + if(dest == NULL || uuid.len == 0) + return -1; dest->len = cfgt_basedir.len + uuid.len; - if(cfgt_basedir.s[cfgt_basedir.len-1]!='/') + if(cfgt_basedir.s[cfgt_basedir.len - 1] != '/') dest->len = dest->len + 1; sid = sint2strbuf(msgid, buff_id, INT2STR_MAX_LEN, &lid); dest->len += lid + 6; - dest->s = (char *) pkg_malloc((dest->len*sizeof(char)+1)); - if(dest->s==NULL) - { + dest->s = (char *)pkg_malloc((dest->len * sizeof(char) + 1)); + if(dest->s == NULL) { LM_ERR("no more memory.\n"); return -1; } strncpy(dest->s, cfgt_basedir.s, cfgt_basedir.len); i = cfgt_basedir.len; - if(cfgt_basedir.s[cfgt_basedir.len-1]!='/') - { - strncpy(dest->s+i, "/", 1); + if(cfgt_basedir.s[cfgt_basedir.len - 1] != '/') { + strncpy(dest->s + i, "/", 1); i = i + 1; } - strncpy(dest->s+i, uuid.s, uuid.len); - i = i + uuid.len; (*dir) = i; - strncpy(dest->s+i, "\0", 1); + strncpy(dest->s + i, uuid.s, uuid.len); + i = i + uuid.len; + (*dir) = i; + strncpy(dest->s + i, "\0", 1); i = i + 1; - strncpy(dest->s+i, sid, lid); + strncpy(dest->s + i, sid, lid); i = i + lid; - strncpy(dest->s+i, ".json\0", 6); + strncpy(dest->s + i, ".json\0", 6); return 0; } int _cfgt_node2json(cfgt_node_p node) { - srjson_t *jobj; - - if(!node) return -1; - jobj = srjson_CreateStr(&node->jdoc, node->uuid.s, node->uuid.len); - if(jobj==NULL) - { - LM_ERR("cannot create json object\n"); - return -1; - } - srjson_AddItemToObject(&node->jdoc, node->jdoc.root, "uuid\0", jobj); - - jobj = srjson_CreateNumber(&node->jdoc, (double)node->msgid); - if(jobj==NULL) - { - LM_ERR("cannot create json object\n"); - return -1; - } - srjson_AddItemToObject(&node->jdoc, node->jdoc.root, "msgid\0", jobj); - return 0; + srjson_t *jobj; + + if(!node) + return -1; + jobj = srjson_CreateStr(&node->jdoc, node->uuid.s, node->uuid.len); + if(jobj == NULL) { + LM_ERR("cannot create json object\n"); + return -1; + } + srjson_AddItemToObject(&node->jdoc, node->jdoc.root, "uuid\0", jobj); + + jobj = srjson_CreateNumber(&node->jdoc, (double)node->msgid); + if(jobj == NULL) { + LM_ERR("cannot create json object\n"); + return -1; + } + srjson_AddItemToObject(&node->jdoc, node->jdoc.root, "msgid\0", jobj); + return 0; } void cfgt_save_node(cfgt_node_p node) @@ -356,13 +328,12 @@ void cfgt_save_node(cfgt_node_p node) FILE *fp; str dest = STR_NULL; int dir = 0; - if(_cfgt_get_filename(node->msgid, node->uuid, &dest, &dir)<0) - { + if(_cfgt_get_filename(node->msgid, node->uuid, &dest, &dir) < 0) { LM_ERR("can't build filename\n"); return; } LM_DBG("dir [%s]\n", dest.s); - if(mkdir(dest.s, S_IRWXO|S_IXGRP|S_IRWXU)<0) { + if(mkdir(dest.s, S_IRWXO | S_IXGRP | S_IRWXU) < 0) { LM_ERR("failed to make directory (%d)\n", errno); return; } @@ -372,19 +343,17 @@ void cfgt_save_node(cfgt_node_p node) if(fp) { pkg_free(dest.s); dest.s = srjson_Print(&node->jdoc, node->jdoc.root); - if(dest.s==NULL) - { - LM_ERR("Cannot get the json string\n"); - fclose(fp); - return; - } - if(fputs(dest.s, fp)<0){ - LM_ERR("failed writing to file\n"); - } - fclose(fp); - node->jdoc.free_fn(dest.s); - } - else { + if(dest.s == NULL) { + LM_ERR("Cannot get the json string\n"); + fclose(fp); + return; + } + if(fputs(dest.s, fp) < 0) { + LM_ERR("failed writing to file\n"); + } + fclose(fp); + node->jdoc.free_fn(dest.s); + } else { LM_ERR("Can't open file [%s] to write\n", dest.s); pkg_free(dest.s); } @@ -395,30 +364,28 @@ void _cfgt_print_node(cfgt_node_p node, int json) char *buf = NULL; cfgt_str_list_p route; - if(!node) return; - if(node->flow_head) - { + if(!node) + return; + if(node->flow_head) { route = node->flow_head; - while(route) - { + while(route) { if(route == node->route) - LM_DBG("[--[%.*s][%d]--]\n", - route->s.len, route->s.s, route->type); - else LM_DBG("[%.*s][%d]\n", - route->s.len, route->s.s, route->type); + LM_DBG("[--[%.*s][%d]--]\n", route->s.len, route->s.s, + route->type); + else + LM_DBG("[%.*s][%d]\n", route->s.len, route->s.s, route->type); route = route->next; } - } - else LM_DBG("flow:empty\n"); + } else + LM_DBG("flow:empty\n"); if(json) { buf = srjson_PrintUnformatted(&node->jdoc, node->jdoc.root); - if(buf==NULL) - { + if(buf == NULL) { LM_ERR("Cannot get the json string\n"); return; } - LM_DBG("node[%p]: id:[%d] uuid:[%.*s] info:[%s]\n", - node, node->msgid, node->uuid.len, node->uuid.s, buf); + LM_DBG("node[%p]: id:[%d] uuid:[%.*s] info:[%s]\n", node, node->msgid, + node->uuid.len, node->uuid.s, buf); node->jdoc.free_fn(buf); } } @@ -427,27 +394,24 @@ int _cfgt_set_dump(struct sip_msg *msg, cfgt_node_p node, str *flow) { srjson_t *f, *vars; - if(node==NULL || flow == NULL) return -1; + if(node == NULL || flow == NULL) + return -1; vars = srjson_CreateObject(&node->jdoc); - if(vars==NULL) - { + if(vars == NULL) { LM_ERR("cannot create json object\n"); return -1; } - if(cfgt_get_json(msg, 30, &node->jdoc, vars)<0) - { + if(cfgt_get_json(msg, 30, &node->jdoc, vars) < 0) { LM_ERR("cannot get var info\n"); return -1; } f = srjson_CreateObject(&node->jdoc); - if(f==NULL) - { + if(f == NULL) { LM_ERR("cannot create json object\n"); srjson_Delete(&node->jdoc, vars); return -1; } - srjson_AddStrItemToObject(&node->jdoc, f, - flow->s, flow->len, vars); + srjson_AddStrItemToObject(&node->jdoc, f, flow->s, flow->len, vars); srjson_AddItemToArray(&node->jdoc, node->flow, f); LM_DBG("node[%.*s] flow created\n", flow->len, flow->s); return 0; @@ -455,18 +419,16 @@ int _cfgt_set_dump(struct sip_msg *msg, cfgt_node_p node, str *flow) void _cfgt_set_type(cfgt_str_list_p route, struct action *a) { - switch(a->type) - { + switch(a->type) { case DROP_T: - if(a->val[1].u.number&DROP_R_F) { + if(a->val[1].u.number & DROP_R_F) { route->type = CFGT_DROP_D; LM_DBG("set[%.*s]->CFGT_DROP_D\n", route->s.len, route->s.s); } - if(a->val[1].u.number&RETURN_R_F){ + if(a->val[1].u.number & RETURN_R_F) { route->type = CFGT_DROP_R; LM_DBG("set[%.*s]->CFGT_DROP_R\n", route->s.len, route->s.s); - } - else { + } else { route->type = CFGT_DROP_E; LM_DBG("set[%.*s]->CFGT_DROP_E\n", route->s.len, route->s.s); } @@ -476,23 +438,19 @@ void _cfgt_set_type(cfgt_str_list_p route, struct action *a) LM_DBG("set[%.*s]->CFGT_ROUTE\n", route->s.len, route->s.s); break; default: - if(route->type!=CFGT_DROP_E) - { + if(route->type != CFGT_DROP_E) { route->type = CFGT_DROP_R; LM_DBG("[%.*s] no relevant action: CFGT_DROP_R[%d]\n", - route->s.len, route->s.s, a->type); - } - else - { - LM_DBG("[%.*s] already set to CFGT_DROP_E[%d]\n", - route->s.len, route->s.s, a->type); + route->s.len, route->s.s, a->type); + } else { + LM_DBG("[%.*s] already set to CFGT_DROP_E[%d]\n", route->s.len, + route->s.s, a->type); } break; } } -int _cfgt_add_routename(cfgt_node_p node, struct action *a, - str *routename) +int _cfgt_add_routename(cfgt_node_p node, struct action *a, str *routename) { cfgt_str_list_p route; int ret = 0; @@ -500,8 +458,7 @@ int _cfgt_add_routename(cfgt_node_p node, struct action *a, if(!node->route) /* initial */ { node->route = pkg_malloc(sizeof(cfgt_str_list_t)); - if(!node->route) - { + if(!node->route) { LM_ERR("No more pkg mem\n"); return -1; } @@ -509,34 +466,28 @@ int _cfgt_add_routename(cfgt_node_p node, struct action *a, node->flow_head = node->route; node->route->type = CFGT_ROUTE; ret = 1; - } - else - { + } else { LM_DBG("actual routename:[%.*s][%d]\n", node->route->s.len, - node->route->s.s, node->route->type); + node->route->s.s, node->route->type); if(node->route->prev) LM_DBG("prev routename:[%.*s][%d]\n", node->route->prev->s.len, - node->route->prev->s.s, node->route->prev->type); + node->route->prev->s.s, node->route->prev->type); if(node->route->next) LM_DBG("next routename:[%.*s][%d]\n", node->route->next->s.len, - node->route->next->s.s, node->route->next->type); - if(STR_EQ(*routename, node->route->s)) - { + node->route->next->s.s, node->route->next->type); + if(STR_EQ(*routename, node->route->s)) { LM_DBG("same route\n"); _cfgt_set_type(node->route, a); return 2; - } - else if(node->route->prev && - STR_EQ(*routename, node->route->prev->s)) - { + } else if(node->route->prev + && STR_EQ(*routename, node->route->prev->s)) { LM_DBG("back to route[%.*s]\n", node->route->prev->s.len, - node->route->prev->s.s); + node->route->prev->s.s); _cfgt_set_type(node->route->prev, a); return 3; } route = pkg_malloc(sizeof(cfgt_str_list_t)); - if(!route) - { + if(!route) { LM_ERR("No more pkg mem\n"); return -1; } @@ -555,7 +506,7 @@ int _cfgt_add_routename(cfgt_node_p node, struct action *a, void _cfgt_del_routename(cfgt_node_p node) { - if(node->route->next!=NULL) { + if(node->route->next != NULL) { LM_ERR("wtf!! route->next[%p] not null!!\n", node->route->next); _cfgt_print_node(node, 0); } @@ -568,14 +519,14 @@ void _cfgt_del_routename(cfgt_node_p node) int _cfgt_node_get_flowname(cfgt_str_list_p route, int *indx, str *dest) { int i; - if(route==NULL) return -1; - LM_DBG("routename:[%.*s][%d]\n", route->s.len, route->s.s, - route->type); - if(indx) i = *indx; - else i = route->type-1; - if(str_append(&_cfgt_route_prefix[i], - &route->s, dest)<0) - { + if(route == NULL) + return -1; + LM_DBG("routename:[%.*s][%d]\n", route->s.len, route->s.s, route->type); + if(indx) + i = *indx; + else + i = route->type - 1; + if(str_append(&_cfgt_route_prefix[i], &route->s, dest) < 0) { LM_ERR("Cannot create route name\n"); return -1; } @@ -592,21 +543,21 @@ int cfgt_process_route(struct sip_msg *msg, struct action *a) LM_ERR("node empty\n"); return -1; } - if (a->rname==NULL) { + if(a->rname == NULL) { LM_DBG("no routename. type:%d\n", a->type); return 0; } LM_DBG("route from action:[%s]\n", a->rname); - routename.s = a->rname; routename.len = strlen(a->rname); - switch(_cfgt_add_routename(_cfgt_node, a, &routename)) - { + routename.s = a->rname; + routename.len = strlen(a->rname); + switch(_cfgt_add_routename(_cfgt_node, a, &routename)) { case 2: /* same name */ return 0; case 1: /* initial */ - LM_DBG("Initial route[%.*s]. dump vars\n", - _cfgt_node->route->s.len, _cfgt_node->route->s.s); - if(_cfgt_node_get_flowname(_cfgt_node->route, &indx, &flowname)<0) - { + LM_DBG("Initial route[%.*s]. dump vars\n", _cfgt_node->route->s.len, + _cfgt_node->route->s.s); + if(_cfgt_node_get_flowname(_cfgt_node->route, &indx, &flowname) + < 0) { LM_ERR("cannot create flowname\n"); return -1; } @@ -614,18 +565,18 @@ int cfgt_process_route(struct sip_msg *msg, struct action *a) break; case 0: /* new */ LM_DBG("Change from[%.*s] route to route[%.*s]. dump vars\n", - _cfgt_node->route->prev->s.len, _cfgt_node->route->prev->s.s, - _cfgt_node->route->s.len, _cfgt_node->route->s.s); - if(_cfgt_node_get_flowname(_cfgt_node->route, &indx, &flowname)<0) - { + _cfgt_node->route->prev->s.len, + _cfgt_node->route->prev->s.s, _cfgt_node->route->s.len, + _cfgt_node->route->s.s); + if(_cfgt_node_get_flowname(_cfgt_node->route, &indx, &flowname) + < 0) { LM_ERR("cannot create flowname\n"); return -1; } ret = _cfgt_set_dump(msg, _cfgt_node, &flowname); break; case 3: /* back to previous */ - if(_cfgt_node_get_flowname(_cfgt_node->route, 0, &flowname)<0) - { + if(_cfgt_node_get_flowname(_cfgt_node->route, 0, &flowname) < 0) { LM_ERR("cannot create flowname\n"); return -1; } @@ -635,7 +586,8 @@ int cfgt_process_route(struct sip_msg *msg, struct action *a) default: return -1; } - if(flowname.s) pkg_free(flowname.s); + if(flowname.s) + pkg_free(flowname.s); return ret; } @@ -648,7 +600,8 @@ int cfgt_msgin(sr_event_param_t *evp) { srjson_t *jobj; str *buf = (str *)evp->data; - if(buf==NULL) return 0; + if(buf == NULL) + return 0; if(_cfgt_node) { cfgt_save_node(_cfgt_node); _cfgt_remove_node(_cfgt_node); @@ -657,11 +610,9 @@ int cfgt_msgin(sr_event_param_t *evp) } LM_DBG("msg in:{%.*s}\n", buf->len, buf->s); _cfgt_node = cfgt_create_node(NULL); - if(_cfgt_node) - { + if(_cfgt_node) { jobj = srjson_CreateStr(&_cfgt_node->jdoc, buf->s, buf->len); - if(jobj==NULL) - { + if(jobj == NULL) { LM_ERR("cannot create json object\n"); return -1; } @@ -672,38 +623,33 @@ int cfgt_msgin(sr_event_param_t *evp) return -1; } -int cfgt_pre(struct sip_msg *msg, unsigned int flags, void *bar) { +int cfgt_pre(struct sip_msg *msg, unsigned int flags, void *bar) +{ str unknown = {"unknown", 7}; - if(_cfgt_node) - { - if (_cfgt_node->msgid == 0) - { + if(_cfgt_node) { + if(_cfgt_node->msgid == 0) { LM_DBG("new node\n"); - if(_cfgt_get_hdr(msg, &_cfgt_node->uuid)!=0 || - _cfgt_node->uuid.len==0) - { + if(_cfgt_get_hdr(msg, &_cfgt_node->uuid) != 0 + || _cfgt_node->uuid.len == 0) { LM_ERR("cannot get value of cfgtest uuid header." - " Using unknown\n"); + " Using unknown\n"); pkg_str_dup(&_cfgt_node->uuid, &unknown); } return _cfgt_get_uuid_id(_cfgt_node); - } - else - { + } else { LM_DBG("_cfgt_node->uuid:[%.*s]\n", _cfgt_node->uuid.len, - _cfgt_node->uuid.s); - if(_cfgt_cmp_hdr(msg, &_cfgt_node->uuid)) - { + _cfgt_node->uuid.s); + if(_cfgt_cmp_hdr(msg, &_cfgt_node->uuid)) { LM_DBG("same uuid\n"); return 1; - } - else { + } else { LM_DBG("different uuid\n"); } } + } else { + LM_ERR("node empty??\n"); } - else { LM_ERR("node empty??\n"); } _cfgt_node = cfgt_create_node(msg); if(_cfgt_node) { LM_DBG("node created\n"); @@ -711,15 +657,18 @@ int cfgt_pre(struct sip_msg *msg, unsigned int flags, void *bar) { } return -1; } -int cfgt_post(struct sip_msg *msg, unsigned int flags, void *bar) { +int cfgt_post(struct sip_msg *msg, unsigned int flags, void *bar) +{ str flowname = STR_NULL; if(_cfgt_node) { LM_DBG("dump last flow\n"); - if(_cfgt_node_get_flowname(_cfgt_node->route, 0, &flowname)<0) + if(_cfgt_node_get_flowname(_cfgt_node->route, 0, &flowname) < 0) LM_ERR("cannot create flowname\n"); - else _cfgt_set_dump(msg, _cfgt_node, &flowname); - if(flowname.s) pkg_free(flowname.s); + else + _cfgt_set_dump(msg, _cfgt_node, &flowname); + if(flowname.s) + pkg_free(flowname.s); cfgt_save_node(_cfgt_node); } return 1; @@ -729,14 +678,13 @@ int cfgt_msgout(sr_event_param_t *evp) { srjson_t *jobj; str *buf = (str *)evp->data; - if(buf==NULL) return 0; + if(buf == NULL) + return 0; LM_DBG("msg out:{%.*s}\n", buf->len, buf->s); - if(_cfgt_node) - { + if(_cfgt_node) { jobj = srjson_CreateStr(&_cfgt_node->jdoc, buf->s, buf->len); - if(jobj==NULL) - { + if(jobj == NULL) { LM_ERR("cannot create json object\n"); return -1; } @@ -750,16 +698,13 @@ int cfgt_msgout(sr_event_param_t *evp) /** * */ -static const char* cfgt_rpc_mask_doc[2] = { - "Specify module mask", - 0 -}; +static const char *cfgt_rpc_mask_doc[2] = {"Specify module mask", 0}; -static void cfgt_rpc_mask(rpc_t* rpc, void* ctx){ +static void cfgt_rpc_mask(rpc_t *rpc, void *ctx) +{ int mask = CFGT_DP_ALL; - if (rpc->scan(ctx, "*d", &mask) != 1) - { + if(rpc->scan(ctx, "*d", &mask) != 1) { rpc->fault(ctx, 500, "invalid parameters"); return; } @@ -768,31 +713,26 @@ static void cfgt_rpc_mask(rpc_t* rpc, void* ctx){ } rpc_export_t cfgt_rpc[] = { - {"dbg.mask", cfgt_rpc_mask, cfgt_rpc_mask_doc, 0}, - {0, 0, 0, 0} -}; + {"dbg.mask", cfgt_rpc_mask, cfgt_rpc_mask_doc, 0}, {0, 0, 0, 0}}; int cfgt_init(void) { - if (rpc_register_array(cfgt_rpc)!=0) - { + if(rpc_register_array(cfgt_rpc) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } _cfgt_uuid = shm_malloc(sizeof(cfgt_hash_t)); - if(_cfgt_uuid==NULL) - { + if(_cfgt_uuid == NULL) { LM_ERR("Cannot allocate shared memory\n"); return -1; } - if(!lock_init(&_cfgt_uuid->lock)) - { + if(!lock_init(&_cfgt_uuid->lock)) { LM_ERR("cannot init the lock\n"); shm_free(_cfgt_uuid); _cfgt_uuid = NULL; return -1; } - if(_cfgt_init_hashtable(&_cfgt_uuid->hash)<0) + if(_cfgt_init_hashtable(&_cfgt_uuid->hash) < 0) return -1; sr_event_register_cb(SREV_NET_DATA_IN, cfgt_msgin); sr_event_register_cb(SREV_NET_DATA_OUT, cfgt_msgout); diff --git a/src/modules/cfgt/cfgt_int.h b/src/modules/cfgt/cfgt_int.h index 2882097c0ed..2a9ff2dfa41 100644 --- a/src/modules/cfgt/cfgt_int.h +++ b/src/modules/cfgt/cfgt_int.h @@ -16,22 +16,25 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef _CFGT_INT_H_ #define _CFGT_INT_H_ -#include "../../lib/srutils/srjson.h" #include "../../core/locking.h" #include "../../core/route_struct.h" #include "../../core/str_hash.h" +#include "../../lib/srutils/srjson.h" #define CFGT_HASH_SIZE 32 -enum _cfgt_action_type { - CFGT_ROUTE=1, - CFGT_DROP_E, CFGT_DROP_D, CFGT_DROP_R +enum _cfgt_action_type +{ + CFGT_ROUTE = 1, + CFGT_DROP_E, + CFGT_DROP_D, + CFGT_DROP_R }; typedef struct _cfgt_hash diff --git a/src/modules/cfgt/cfgt_json.c b/src/modules/cfgt/cfgt_json.c index 2974adfaa18..b3dea63de4e 100644 --- a/src/modules/cfgt/cfgt_json.c +++ b/src/modules/cfgt/cfgt_json.c @@ -28,9 +28,8 @@ #include "cfgt_json.h" -int _cfgt_get_array_avp_vals(struct sip_msg *msg, - pv_param_t *param, srjson_doc_t *jdoc, srjson_t **jobj, - str *item_name) +int _cfgt_get_array_avp_vals(struct sip_msg *msg, pv_param_t *param, + srjson_doc_t *jdoc, srjson_t **jobj, str *item_name) { struct usr_avp *avp; unsigned short name_type; @@ -40,69 +39,60 @@ int _cfgt_get_array_avp_vals(struct sip_msg *msg, srjson_t *jobjt; memset(&state, 0, sizeof(struct search_state)); - if(pv_get_avp_name(msg, param, &avp_name, &name_type)!=0) - { + if(pv_get_avp_name(msg, param, &avp_name, &name_type) != 0) { LM_ERR("invalid name\n"); return -1; } *jobj = srjson_CreateArray(jdoc); - if(*jobj==NULL) - { + if(*jobj == NULL) { LM_ERR("cannot create json object\n"); return -1; } - if ((avp=search_first_avp(name_type, avp_name, &avp_value, &state))==0) - { + if((avp = search_first_avp(name_type, avp_name, &avp_value, &state)) == 0) { goto ok; } - do - { - if(avp->flags & AVP_VAL_STR) - { + do { + if(avp->flags & AVP_VAL_STR) { jobjt = srjson_CreateStr(jdoc, avp_value.s.s, avp_value.s.len); - if(jobjt==NULL) - { + if(jobjt == NULL) { LM_ERR("cannot create json object\n"); return -1; } } else { jobjt = srjson_CreateNumber(jdoc, avp_value.n); - if(jobjt==NULL) - { + if(jobjt == NULL) { LM_ERR("cannot create json object\n"); return -1; } } srjson_AddItemToArray(jdoc, *jobj, jobjt); - } while ((avp=search_next_avp(&state, &avp_value))!=0); + } while((avp = search_next_avp(&state, &avp_value)) != 0); ok: item_name->s = avp_name.s.s; item_name->len = avp_name.s.len; return 0; } #define CFGT_XAVP_DUMP_SIZE 32 -static str* _cfgt_xavp_dump[CFGT_XAVP_DUMP_SIZE]; +static str *_cfgt_xavp_dump[CFGT_XAVP_DUMP_SIZE]; int _cfgt_xavp_dump_lookup(pv_param_t *param) { unsigned int i = 0; pv_xavp_name_t *xname; - if(param==NULL) + if(param == NULL) return -1; - xname = (pv_xavp_name_t*)param->pvn.u.dname; + xname = (pv_xavp_name_t *)param->pvn.u.dname; - while(ilen==xname->name.len) - { - if(strncmp(_cfgt_xavp_dump[i]->s, xname->name.s, xname->name.len)==0) + while(i < CFGT_XAVP_DUMP_SIZE && _cfgt_xavp_dump[i] != NULL) { + if(_cfgt_xavp_dump[i]->len == xname->name.len) { + if(strncmp(_cfgt_xavp_dump[i]->s, xname->name.s, xname->name.len) + == 0) return 1; /* already dump before */ } i++; } - if(i==CFGT_XAVP_DUMP_SIZE) - { + if(i == CFGT_XAVP_DUMP_SIZE) { LM_WARN("full _cfgt_xavp_dump cache array\n"); return 0; /* end cache names */ } @@ -118,61 +108,60 @@ void _cfgt_get_obj_xavp_val(sr_xavp_t *avp, srjson_doc_t *jdoc, srjson_t **jobj) switch(avp->val.type) { case SR_XTYPE_NULL: *jobj = srjson_CreateNull(jdoc); - break; + break; case SR_XTYPE_INT: *jobj = srjson_CreateNumber(jdoc, avp->val.v.i); - break; + break; case SR_XTYPE_STR: *jobj = srjson_CreateStr(jdoc, avp->val.v.s.s, avp->val.v.s.len); - break; + break; case SR_XTYPE_TIME: - result = snprintf(_pv_xavp_buf, 128, "%lu", (long unsigned)avp->val.v.t); - break; + result = snprintf( + _pv_xavp_buf, 128, "%lu", (long unsigned)avp->val.v.t); + break; case SR_XTYPE_LONG: - result = snprintf(_pv_xavp_buf, 128, "%ld", (long unsigned)avp->val.v.l); - break; + result = snprintf( + _pv_xavp_buf, 128, "%ld", (long unsigned)avp->val.v.l); + break; case SR_XTYPE_LLONG: result = snprintf(_pv_xavp_buf, 128, "%lld", avp->val.v.ll); - break; + break; case SR_XTYPE_XAVP: - result = snprintf(_pv_xavp_buf, 128, "<>", avp->val.v.xavp); - break; + result = + snprintf(_pv_xavp_buf, 128, "<>", avp->val.v.xavp); + break; case SR_XTYPE_DATA: - result = snprintf(_pv_xavp_buf, 128, "<>", avp->val.v.data); - break; + result = + snprintf(_pv_xavp_buf, 128, "<>", avp->val.v.data); + break; default: LM_WARN("unknown data type\n"); *jobj = srjson_CreateNull(jdoc); } - if(result<0) - { + if(result < 0) { LM_ERR("cannot convert to str\n"); *jobj = srjson_CreateNull(jdoc); - } - else if(*jobj==NULL) - { + } else if(*jobj == NULL) { *jobj = srjson_CreateStr(jdoc, _pv_xavp_buf, 128); } } -int _cfgt_get_obj_avp_vals(str name, sr_xavp_t *xavp, srjson_doc_t *jdoc, srjson_t **jobj) +int _cfgt_get_obj_avp_vals( + str name, sr_xavp_t *xavp, srjson_doc_t *jdoc, srjson_t **jobj) { sr_xavp_t *avp = NULL; srjson_t *jobjt = NULL; *jobj = srjson_CreateArray(jdoc); - if(*jobj==NULL) - { + if(*jobj == NULL) { LM_ERR("cannot create json object\n"); return -1; } avp = xavp; - while(avp!=NULL&&!STR_EQ(avp->name,name)) - { + while(avp != NULL && !STR_EQ(avp->name, name)) { avp = avp->next; } - while(avp!=NULL) - { + while(avp != NULL) { _cfgt_get_obj_xavp_val(avp, jdoc, &jobjt); srjson_AddItemToArray(jdoc, *jobj, jobjt); jobjt = NULL; @@ -182,11 +171,10 @@ int _cfgt_get_obj_avp_vals(str name, sr_xavp_t *xavp, srjson_doc_t *jdoc, srjson return 0; } -int _cfgt_get_obj_xavp_vals(struct sip_msg *msg, - pv_param_t *param, srjson_doc_t *jdoc, srjson_t **jobjr, - str *item_name) +int _cfgt_get_obj_xavp_vals(struct sip_msg *msg, pv_param_t *param, + srjson_doc_t *jdoc, srjson_t **jobjr, str *item_name) { - pv_xavp_name_t *xname = (pv_xavp_name_t*)param->pvn.u.dname; + pv_xavp_name_t *xname = (pv_xavp_name_t *)param->pvn.u.dname; sr_xavp_t *xavp = NULL; sr_xavp_t *avp = NULL; srjson_t *jobj = NULL; @@ -195,8 +183,7 @@ int _cfgt_get_obj_xavp_vals(struct sip_msg *msg, struct str_list *k; *jobjr = srjson_CreateArray(jdoc); - if(*jobjr==NULL) - { + if(*jobjr == NULL) { LM_ERR("cannot create json object\n"); return -1; } @@ -204,49 +191,42 @@ int _cfgt_get_obj_xavp_vals(struct sip_msg *msg, item_name->s = xname->name.s; item_name->len = xname->name.len; xavp = xavp_get_by_index(&xname->name, 0, NULL); - if(xavp==NULL) - { + if(xavp == NULL) { return 0; /* empty */ } - do - { - if(xavp->val.type==SR_XTYPE_XAVP) - { + do { + if(xavp->val.type == SR_XTYPE_XAVP) { avp = xavp->val.v.xavp; jobj = srjson_CreateObject(jdoc); - if(jobj==NULL) - { + if(jobj == NULL) { LM_ERR("cannot create json object\n"); return -1; } keys = xavp_get_list_key_names(xavp); - if(keys!=NULL) - { - do - { + if(keys != NULL) { + do { _cfgt_get_obj_avp_vals(keys->s, avp, jdoc, &jobjt); - srjson_AddStrItemToObject(jdoc, jobj, keys->s.s, - keys->s.len, jobjt); + srjson_AddStrItemToObject( + jdoc, jobj, keys->s.s, keys->s.len, jobjt); k = keys; keys = keys->next; pkg_free(k); jobjt = NULL; - }while(keys!=NULL); + } while(keys != NULL); } } - if(jobj!=NULL) - { + if(jobj != NULL) { srjson_AddItemToArray(jdoc, *jobjr, jobj); jobj = NULL; } - }while((xavp = xavp_get_next(xavp))!=0); + } while((xavp = xavp_get_next(xavp)) != 0); return 0; } -int cfgt_get_json(struct sip_msg* msg, unsigned int mask, srjson_doc_t *jdoc, - srjson_t *head) +int cfgt_get_json(struct sip_msg *msg, unsigned int mask, srjson_doc_t *jdoc, + srjson_t *head) { int i; pv_value_t value; @@ -256,36 +236,34 @@ int cfgt_get_json(struct sip_msg* msg, unsigned int mask, srjson_doc_t *jdoc, str item_name = STR_NULL; static char iname[128]; - if(_pv_cache==NULL) - { + if(_pv_cache == NULL) { LM_ERR("cannot access pv_cache\n"); return -1; } - if(jdoc==NULL){ + if(jdoc == NULL) { LM_ERR("jdoc is null\n"); return -1; } - if(head==NULL){ + if(head == NULL) { LM_ERR("head is null\n"); return -1; } - memset(_cfgt_xavp_dump, 0, sizeof(str*)*CFGT_XAVP_DUMP_SIZE); - for(i=0;ispec.type==PVT_AVP|| - el->spec.type==PVT_SCRIPTVAR|| - el->spec.type==PVT_XAVP|| - el->spec.type==PVT_OTHER)|| - !((el->spec.type==PVT_AVP&&mask&CFGT_DP_AVP)|| - (el->spec.type==PVT_XAVP&&mask&CFGT_DP_XAVP)|| - (el->spec.type==PVT_SCRIPTVAR&&mask&CFGT_DP_SCRIPTVAR)|| - (el->spec.type==PVT_OTHER&&mask&CFGT_DP_OTHER))|| - (el->spec.trans!=NULL)) - { + while(el) { + if(!(el->spec.type == PVT_AVP || el->spec.type == PVT_SCRIPTVAR + || el->spec.type == PVT_XAVP + || el->spec.type == PVT_OTHER) + || !((el->spec.type == PVT_AVP && mask & CFGT_DP_AVP) + || (el->spec.type == PVT_XAVP + && mask & CFGT_DP_XAVP) + || (el->spec.type == PVT_SCRIPTVAR + && mask & CFGT_DP_SCRIPTVAR) + || (el->spec.type == PVT_OTHER + && mask & CFGT_DP_OTHER)) + || (el->spec.trans != NULL)) { el = el->next; continue; } @@ -293,89 +271,80 @@ int cfgt_get_json(struct sip_msg* msg, unsigned int mask, srjson_doc_t *jdoc, item_name.len = 0; item_name.s = 0; iname[0] = '\0'; - if(el->spec.type==PVT_AVP) - { - if(el->spec.pvp.pvi.type==PV_IDX_ALL|| - (el->spec.pvp.pvi.type==PV_IDX_INT&&el->spec.pvp.pvi.u.ival!=0)) - { + if(el->spec.type == PVT_AVP) { + if(el->spec.pvp.pvi.type == PV_IDX_ALL + || (el->spec.pvp.pvi.type == PV_IDX_INT + && el->spec.pvp.pvi.u.ival != 0)) { el = el->next; continue; - } - else - { - if(_cfgt_get_array_avp_vals(msg, &el->spec.pvp, jdoc, &jobj, &item_name)!=0) - { - LM_WARN("can't get value[%.*s]\n", el->pvname.len, el->pvname.s); + } else { + if(_cfgt_get_array_avp_vals( + msg, &el->spec.pvp, jdoc, &jobj, &item_name) + != 0) { + LM_WARN("can't get value[%.*s]\n", el->pvname.len, + el->pvname.s); el = el->next; continue; } - if(srjson_GetArraySize(jdoc, jobj)==0 && !(mask&CFGT_DP_NULL)) - { + if(srjson_GetArraySize(jdoc, jobj) == 0 + && !(mask & CFGT_DP_NULL)) { el = el->next; continue; } - snprintf(iname, 128, "$avp(%.*s)", item_name.len, item_name.s); + snprintf(iname, 128, "$avp(%.*s)", item_name.len, + item_name.s); } - } - else if(el->spec.type==PVT_XAVP) - { - if(_cfgt_xavp_dump_lookup(&el->spec.pvp)!=0) - { + } else if(el->spec.type == PVT_XAVP) { + if(_cfgt_xavp_dump_lookup(&el->spec.pvp) != 0) { el = el->next; continue; } - if(_cfgt_get_obj_xavp_vals(msg, &el->spec.pvp, jdoc, &jobj, &item_name)!=0) - { - LM_WARN("can't get value[%.*s]\n", el->pvname.len, el->pvname.s); + if(_cfgt_get_obj_xavp_vals( + msg, &el->spec.pvp, jdoc, &jobj, &item_name) + != 0) { + LM_WARN("can't get value[%.*s]\n", el->pvname.len, + el->pvname.s); el = el->next; continue; } - if(srjson_GetArraySize(jdoc, jobj)==0 && !(mask&CFGT_DP_NULL)) - { + if(srjson_GetArraySize(jdoc, jobj) == 0 + && !(mask & CFGT_DP_NULL)) { el = el->next; continue; } snprintf(iname, 128, "$xavp(%.*s)", item_name.len, item_name.s); - } - else - { - if(pv_get_spec_value(msg, &el->spec, &value)!=0) - { - LM_WARN("can't get value[%.*s]\n", el->pvname.len, el->pvname.s); + } else { + if(pv_get_spec_value(msg, &el->spec, &value) != 0) { + LM_WARN("can't get value[%.*s]\n", el->pvname.len, + el->pvname.s); el = el->next; continue; } - if(value.flags&(PV_VAL_NULL|PV_VAL_EMPTY|PV_VAL_NONE)) - { - if(mask&CFGT_DP_NULL) - { + if(value.flags & (PV_VAL_NULL | PV_VAL_EMPTY | PV_VAL_NONE)) { + if(mask & CFGT_DP_NULL) { jobj = srjson_CreateNull(jdoc); - } - else - { + } else { el = el->next; continue; } - }else if(value.flags&(PV_VAL_INT)){ + } else if(value.flags & (PV_VAL_INT)) { jobj = srjson_CreateNumber(jdoc, value.ri); - }else if(value.flags&(PV_VAL_STR)){ + } else if(value.flags & (PV_VAL_STR)) { jobj = srjson_CreateStr(jdoc, value.rs.s, value.rs.len); - }else { - LM_WARN("el->pvname[%.*s] value[%d] unhandled\n", el->pvname.len, el->pvname.s, - value.flags); + } else { + LM_WARN("el->pvname[%.*s] value[%d] unhandled\n", + el->pvname.len, el->pvname.s, value.flags); el = el->next; continue; } - if(jobj==NULL) - { - LM_ERR("el->pvname[%.*s] empty json object\n", el->pvname.len, - el->pvname.s); + if(jobj == NULL) { + LM_ERR("el->pvname[%.*s] empty json object\n", + el->pvname.len, el->pvname.s); goto error; } snprintf(iname, 128, "%.*s", el->pvname.len, el->pvname.s); } - if(jobj!=NULL) - { + if(jobj != NULL) { srjson_AddItemToObject(jdoc, head, iname, jobj); } el = el->next; diff --git a/src/modules/cfgt/cfgt_json.h b/src/modules/cfgt/cfgt_json.h index 07b329b6666..f39d73a1d59 100644 --- a/src/modules/cfgt/cfgt_json.h +++ b/src/modules/cfgt/cfgt_json.h @@ -16,23 +16,23 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef _CFGT_JSON_H #define _CFGT_JSON_H -#include "../../lib/srutils/srjson.h" #include "../../core/route_struct.h" +#include "../../lib/srutils/srjson.h" -#define CFGT_DP_NULL 1 -#define CFGT_DP_AVP 2 -#define CFGT_DP_SCRIPTVAR 4 -#define CFGT_DP_XAVP 8 -#define CFGT_DP_OTHER 16 -#define CFGT_DP_ALL 31 +#define CFGT_DP_NULL 1 +#define CFGT_DP_AVP 2 +#define CFGT_DP_SCRIPTVAR 4 +#define CFGT_DP_XAVP 8 +#define CFGT_DP_OTHER 16 +#define CFGT_DP_ALL 31 -int cfgt_get_json(struct sip_msg* msg, unsigned int mask, srjson_doc_t *jdoc, - srjson_t *head); +int cfgt_get_json(struct sip_msg *msg, unsigned int mask, srjson_doc_t *jdoc, + srjson_t *head); #endif diff --git a/src/modules/cfgt/cfgt_mod.c b/src/modules/cfgt/cfgt_mod.c index 63c215c429a..6cfdbb56b43 100644 --- a/src/modules/cfgt/cfgt_mod.c +++ b/src/modules/cfgt/cfgt_mod.c @@ -31,11 +31,11 @@ MODULE_VERSION -static int mod_init(void); /*!< Module initialization function */ -static void destroy(void); /*!< Module destroy function */ -static int child_init(int rank); /*!< Per-child init function */ +static int mod_init(void); /*!< Module initialization function */ +static void destroy(void); /*!< Module destroy function */ +static int child_init(int rank); /*!< Per-child init function */ -extern int bind_cfgt(cfgt_api_t* api); +extern int bind_cfgt(cfgt_api_t *api); /*! flag to protect against wrong initialization */ unsigned int init_flag = 0; @@ -47,33 +47,28 @@ extern str cfgt_hdr_prefix; * Exported functions */ static cmd_export_t cmds[] = { - {"cfgt_bind_cfgt", (cmd_function)bind_cfgt, 1, 0, 0, 0}, - {0, 0, 0, 0, 0, 0} -}; + {"cfgt_bind_cfgt", (cmd_function)bind_cfgt, 1, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}}; /*! \brief * Exported parameters */ -static param_export_t params[] = { - {"basedir", PARAM_STR, &cfgt_basedir}, - {"mask", INT_PARAM, &cfgt_mask }, - {"callid_prefix", PARAM_STR, &cfgt_hdr_prefix }, - {0, 0, 0} -}; +static param_export_t params[] = {{"basedir", PARAM_STR, &cfgt_basedir}, + {"mask", INT_PARAM, &cfgt_mask}, + {"callid_prefix", PARAM_STR, &cfgt_hdr_prefix}, {0, 0, 0}}; struct module_exports exports = { - "cfgt", - DEFAULT_DLFLAGS, /*!< dlopen flags */ - cmds, /*!< Exported functions */ - params, /*!< Export parameters */ - 0, /*!< exported statistics */ - 0, /*!< exported MI functions */ - 0, /*!< exported pseudo-variables */ - 0, /*!< extra processes */ - mod_init, /*!< Module initialization function */ - 0, /*!< Response function */ - destroy, /*!< Destroy function */ - child_init /*!< Child initialization function */ + "cfgt", DEFAULT_DLFLAGS, /*!< dlopen flags */ + cmds, /*!< Exported functions */ + params, /*!< Export parameters */ + 0, /*!< exported statistics */ + 0, /*!< exported MI functions */ + 0, /*!< exported pseudo-variables */ + 0, /*!< extra processes */ + mod_init, /*!< Module initialization function */ + 0, /*!< Response function */ + destroy, /*!< Destroy function */ + child_init /*!< Child initialization function */ }; /*! \brief @@ -81,16 +76,16 @@ struct module_exports exports = { */ static int mod_init(void) { - unsigned int ALL = REQUEST_CB+FAILURE_CB+ONREPLY_CB - +BRANCH_CB+ONSEND_CB+ERROR_CB+LOCAL_CB+EVENT_CB+BRANCH_FAILURE_CB; - if(cfgt_init()<0) return -1; - if (register_script_cb(cfgt_pre, PRE_SCRIPT_CB|ALL, 0) != 0) - { + unsigned int ALL = REQUEST_CB + FAILURE_CB + ONREPLY_CB + BRANCH_CB + + ONSEND_CB + ERROR_CB + LOCAL_CB + EVENT_CB + + BRANCH_FAILURE_CB; + if(cfgt_init() < 0) + return -1; + if(register_script_cb(cfgt_pre, PRE_SCRIPT_CB | ALL, 0) != 0) { LM_ERR("could not insert PRE_SCRIPT callback"); return -1; } - if (register_script_cb(cfgt_post, POST_SCRIPT_CB|ALL, 0) != 0) - { + if(register_script_cb(cfgt_post, POST_SCRIPT_CB | ALL, 0) != 0) { LM_ERR("could not insert POST_SCRIPT callback"); return -1; } diff --git a/src/modules/cfgt/cfgt_mod.h b/src/modules/cfgt/cfgt_mod.h index 1d8323d03e1..02b74c46f6e 100644 --- a/src/modules/cfgt/cfgt_mod.h +++ b/src/modules/cfgt/cfgt_mod.h @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * */