From 90ab9e4f301c48ba9f080014330b933457d68e96 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Wed, 13 Sep 2017 18:07:34 +0200 Subject: [PATCH] usrloc: use app name in UL rpc UA, shift from mi to rpc in strings - coherent indentation --- src/modules/usrloc/ul_rpc.c | 284 ++++++++++++++++++------------------ 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/src/modules/usrloc/ul_rpc.c b/src/modules/usrloc/ul_rpc.c index bace4885e1c..c27921d0fc7 100644 --- a/src/modules/usrloc/ul_rpc.c +++ b/src/modules/usrloc/ul_rpc.c @@ -31,11 +31,11 @@ /*! CSEQ nr used */ #define RPC_UL_CSEQ 1 /*! call-id used for ul_add and ul_rm_contact */ -static str rpc_ul_cid = str_init("dfjrewr12386fd6-343@kamailio.mi"); +static str rpc_ul_cid = str_init("dfjrewr12386fd6-343@kamailio.rpc"); /*! path used for ul_add and ul_rm_contact */ static str rpc_ul_path = str_init("dummypath"); /*! user agent used for ul_add */ -static str rpc_ul_ua = str_init("SIP Router MI Server"); +static str rpc_ul_ua = str_init(NAME " SIP Router - RPC Server"); extern sruid_t _ul_sruid; @@ -65,10 +65,10 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c) return -1; } if (c->expires == 0) { if(rpc->struct_add(vh, "s", "Expires", "permanent")<0) - { + { rpc->fault(ctx, 500, "Internal error adding expire"); return -1; - } + } } else if (c->expires == UL_EXPIRED_TIME) { if(rpc->struct_add(vh, "s", "Expires", "deleted")<0) { @@ -122,19 +122,19 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c) return -1; } if(rpc->struct_add(vh, "S", "User-Agent", - (c->user_agent.len)?&c->user_agent: &empty_str)<0) + (c->user_agent.len)?&c->user_agent: &empty_str)<0) { rpc->fault(ctx, 500, "Internal error adding user-agent"); return -1; } if(rpc->struct_add(vh, "S", "Received", - (c->received.len)?&c->received: &empty_str)<0) + (c->received.len)?&c->received: &empty_str)<0) { rpc->fault(ctx, 500, "Internal error adding received"); return -1; } if(rpc->struct_add(vh, "S", "Path", - (c->path.len)?&c->path: &empty_str)<0) + (c->path.len)?&c->path: &empty_str)<0) { rpc->fault(ctx, 500, "Internal error adding path"); return -1; @@ -170,7 +170,7 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c) return -1; } if(rpc->struct_add(vh, "S", "Instance", - (c->instance.len)?&c->instance: &empty_str)<0) + (c->instance.len)?&c->instance: &empty_str)<0) { rpc->fault(ctx, 500, "Internal error adding instance"); return -1; @@ -180,17 +180,17 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c) rpc->fault(ctx, 500, "Internal error adding reg_id"); return -1; } - if(rpc->struct_add(vh, "d", "Server-Id", c->server_id)<0) + if(rpc->struct_add(vh, "d", "Server-Id", c->server_id)<0) { rpc->fault(ctx, 500, "Internal error adding server_id"); return -1; } - if(rpc->struct_add(vh, "d", "Tcpconn-Id", c->tcpconn_id)<0) + if(rpc->struct_add(vh, "d", "Tcpconn-Id", c->tcpconn_id)<0) { rpc->fault(ctx, 500, "Internal error adding tcpconn_id"); return -1; } - if(rpc->struct_add(vh, "d", "Keepalive", c->keepalive)<0) + if(rpc->struct_add(vh, "d", "Keepalive", c->keepalive)<0) { rpc->fault(ctx, 500, "Internal error adding keepalive"); return -1; @@ -227,7 +227,7 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx) if(brief.len==5 && (strncmp(brief.s, "brief", 5)==0)) summary = 1; - + for( dl=root ; dl ; dl=dl->next ) { dom = dl->d; if (rpc->add(ctx, "{", &th) < 0) @@ -252,23 +252,23 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx) if(summary==1) { if(rpc->struct_add(ah, "S", - "AoR", &r->aor)<0) + "AoR", &r->aor)<0) { rpc->fault(ctx, 500, "Internal error creating aor struct"); return; } } else { if(rpc->struct_add(ah, "{", - "Info", &bh)<0) + "Info", &bh)<0) { unlock_ulslot( dom, i); rpc->fault(ctx, 500, "Internal error creating aor struct"); return; } if(rpc->struct_add(bh, "Sd[", - "AoR", &r->aor, - "HashID", r->aorhash, - "Contacts", &ih)<0) + "AoR", &r->aor, + "HashID", r->aorhash, + "Contacts", &ih)<0) { unlock_ulslot( dom, i); rpc->fault(ctx, 500, "Internal error creating aor struct"); @@ -294,8 +294,8 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx) return; } if(rpc->struct_add(sh, "dd", - "Records", n, - "Max-Slots", max)<0) + "Records", n, + "Max-Slots", max)<0) { rpc->fault(ctx, 500, "Internal error adding stats"); return; @@ -319,7 +319,7 @@ static inline udomain_t* rpc_find_domain(str* table) for( dom=root ; dom ; dom=dom->next ) { if ((dom->name.len == table->len) && - !memcmp(dom->name.s, table->s, table->len)) + !memcmp(dom->name.s, table->s, table->len)) return dom->d; } return 0; @@ -410,8 +410,8 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx) return; } if(rpc->struct_add(th, "S[", - "AoR", &aor, - "Contacts", &ih)<0) + "AoR", &aor, + "Contacts", &ih)<0) { unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Internal error creating aor struct"); @@ -578,7 +578,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx) memset( &ci, 0, sizeof(ucontact_info_t)); ret = rpc->scan(ctx, "SSSdfSddd", &table, &aor, &contact, &ci.expires, - &dtemp, &path, &ci.flags, &ci.cflags, &ci.methods); + &dtemp, &path, &ci.flags, &ci.cflags, &ci.methods); if(path.len==1 && (strncmp(path.s, "0", 1)==0)) { LM_DBG("path == 0 -> unset\n"); } @@ -586,8 +586,8 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx) ci.path = &path; } LM_DBG("ret: %d table:%.*s aor:%.*s contact:%.*s expires:%d dtemp:%f path:%.*s flags:%d bflags:%d methods:%d\n", - ret, table.len, table.s, aor.len, aor.s, contact.len, contact.s, - (int) ci.expires, dtemp, (ci.path)?ci.path->len:0, (ci.path && ci.path->s)?ci.path->s:"", ci.flags, ci.cflags, (int) ci.methods); + ret, table.len, table.s, aor.len, aor.s, contact.len, contact.s, + (int) ci.expires, dtemp, (ci.path)?ci.path->len:0, (ci.path && ci.path->s)?ci.path->s:"", ci.flags, ci.cflags, (int) ci.methods); if ( ret != 9) { rpc->fault(ctx, 500, "Not enough parameters or wrong format"); return; @@ -676,52 +676,52 @@ static const char* ul_rpc_add_doc[2] = { static void ul_rpc_db_users(rpc_t* rpc, void* ctx) { - str table = {0, 0}; - char query[QUERY_LEN]; - str query_str; - db1_res_t* res; - int count; - - if (db_mode == NO_DB) { - rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); - return; - } + str table = {0, 0}; + char query[QUERY_LEN]; + str query_str; + db1_res_t* res; + int count; - if (rpc->scan(ctx, "S", &table) != 1) { - rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); - return; - } + if (db_mode == NO_DB) { + rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); + return; + } - if (user_col.len + domain_col.len + table.len + 32 > QUERY_LEN) { - rpc->fault(ctx, 500, "Too long database query"); - return; - } + if (rpc->scan(ctx, "S", &table) != 1) { + rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); + return; + } - if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { - rpc->fault(ctx, 500, "Database does not support raw queries"); - return; - } - if (ul_dbf.use_table(ul_dbh, &table) < 0) { - rpc->fault(ctx, 500, "Failed to use table"); - return; - } - - memset(query, 0, QUERY_LEN); - query_str.len = snprintf(query, QUERY_LEN, - "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())", - user_col.len, user_col.s, - domain_col.len, domain_col.s, - table.len, table.s); - query_str.s = query; - if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) { - rpc->fault(ctx, 500, "Failed to query AoR count"); - return; - } + if (user_col.len + domain_col.len + table.len + 32 > QUERY_LEN) { + rpc->fault(ctx, 500, "Too long database query"); + return; + } + + if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { + rpc->fault(ctx, 500, "Database does not support raw queries"); + return; + } + if (ul_dbf.use_table(ul_dbh, &table) < 0) { + rpc->fault(ctx, 500, "Failed to use table"); + return; + } + + memset(query, 0, QUERY_LEN); + query_str.len = snprintf(query, QUERY_LEN, + "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())", + user_col.len, user_col.s, + domain_col.len, domain_col.s, + table.len, table.s); + query_str.s = query; + if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) { + rpc->fault(ctx, 500, "Failed to query AoR count"); + return; + } - count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); - ul_dbf.free_result(ul_dbh, res); + count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); + ul_dbf.free_result(ul_dbh, res); - rpc->add(ctx, "d", count); + rpc->add(ctx, "d", count); } static const char* ul_rpc_db_users_doc[2] = { @@ -731,49 +731,49 @@ static const char* ul_rpc_db_users_doc[2] = { static void ul_rpc_db_contacts(rpc_t* rpc, void* ctx) { - str table = {0, 0}; - char query[QUERY_LEN]; - str query_str; - db1_res_t* res; - int count; - - if (db_mode == NO_DB) { - rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); - return; - } + str table = {0, 0}; + char query[QUERY_LEN]; + str query_str; + db1_res_t* res; + int count; - if (rpc->scan(ctx, "S", &table) != 1) { - rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); - return; - } + if (db_mode == NO_DB) { + rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); + return; + } - if (table.len + 22 > QUERY_LEN) { - rpc->fault(ctx, 500, "Too long database query"); - return; - } + if (rpc->scan(ctx, "S", &table) != 1) { + rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); + return; + } - if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { - rpc->fault(ctx, 500, "Database does not support raw queries"); - return; - } - if (ul_dbf.use_table(ul_dbh, &table) < 0) { - rpc->fault(ctx, 500, "Failed to use table"); - return; - } - - memset(query, 0, QUERY_LEN); - query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())", - table.len, table.s); - query_str.s = query; - if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) { - rpc->fault(ctx, 500, "Failed to query contact count"); - return; - } + if (table.len + 22 > QUERY_LEN) { + rpc->fault(ctx, 500, "Too long database query"); + return; + } + + if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { + rpc->fault(ctx, 500, "Database does not support raw queries"); + return; + } + if (ul_dbf.use_table(ul_dbh, &table) < 0) { + rpc->fault(ctx, 500, "Failed to use table"); + return; + } - count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); - ul_dbf.free_result(ul_dbh, res); + memset(query, 0, QUERY_LEN); + query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())", + table.len, table.s); + query_str.s = query; + if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) { + rpc->fault(ctx, 500, "Failed to query contact count"); + return; + } - rpc->add(ctx, "d", count); + count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); + ul_dbf.free_result(ul_dbh, res); + + rpc->add(ctx, "d", count); } static const char* ul_rpc_db_contacts_doc[2] = { @@ -783,49 +783,49 @@ static const char* ul_rpc_db_contacts_doc[2] = { static void ul_rpc_db_expired_contacts(rpc_t* rpc, void* ctx) { - str table = {0, 0}; - char query[QUERY_LEN]; - str query_str; - db1_res_t* res; - int count; - - if (db_mode == NO_DB) { - rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); - return; - } + str table = {0, 0}; + char query[QUERY_LEN]; + str query_str; + db1_res_t* res; + int count; - if (rpc->scan(ctx, "S", &table) != 1) { - rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); - return; - } + if (db_mode == NO_DB) { + rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); + return; + } - if (table.len + 22 > QUERY_LEN) { - rpc->fault(ctx, 500, "Too long database query"); - return; - } + if (rpc->scan(ctx, "S", &table) != 1) { + rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); + return; + } - if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { - rpc->fault(ctx, 500, "Database does not support raw queries"); - return; - } - if (ul_dbf.use_table(ul_dbh, &table) < 0) { - rpc->fault(ctx, 500, "Failed to use table"); - return; - } - - memset(query, 0, QUERY_LEN); - query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) > 0) AND (expires <= NOW())", - table.len, table.s); - query_str.s = query; - if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) { - rpc->fault(ctx, 500, "Failed to query contact count"); - return; - } + if (table.len + 22 > QUERY_LEN) { + rpc->fault(ctx, 500, "Too long database query"); + return; + } + + if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { + rpc->fault(ctx, 500, "Database does not support raw queries"); + return; + } + if (ul_dbf.use_table(ul_dbh, &table) < 0) { + rpc->fault(ctx, 500, "Failed to use table"); + return; + } + + memset(query, 0, QUERY_LEN); + query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) > 0) AND (expires <= NOW())", + table.len, table.s); + query_str.s = query; + if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) { + rpc->fault(ctx, 500, "Failed to query contact count"); + return; + } - count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); - ul_dbf.free_result(ul_dbh, res); + count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); + ul_dbf.free_result(ul_dbh, res); - rpc->add(ctx, "d", count); + rpc->add(ctx, "d", count); } static const char* ul_rpc_db_expired_contacts_doc[2] = {