[sr-dev] git:master:40468c0f: secfilter: simplify RPC code
Jose Luis Verdeguer
pepeluxx at gmail.com
Thu Dec 20 10:51:10 CET 2018
Module: kamailio
Branch: master
Commit: 40468c0fb437545cd7ee211ee71183f99f413b9e
URL: https://github.com/kamailio/kamailio/commit/40468c0fb437545cd7ee211ee71183f99f413b9e
Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Jose Luis Verdeguer <pepeluxx at gmail.com>
Date: 2018-12-20T10:51:03+01:00
secfilter: simplify RPC code
---
Modified: src/modules/secfilter/secfilter_rpc.c
---
Diff: https://github.com/kamailio/kamailio/commit/40468c0fb437545cd7ee211ee71183f99f413b9e.diff
Patch: https://github.com/kamailio/kamailio/commit/40468c0fb437545cd7ee211ee71183f99f413b9e.patch
---
diff --git a/src/modules/secfilter/secfilter_rpc.c b/src/modules/secfilter/secfilter_rpc.c
index 2e5a33288a..e437524336 100644
--- a/src/modules/secfilter/secfilter_rpc.c
+++ b/src/modules/secfilter/secfilter_rpc.c
@@ -65,81 +65,81 @@ void rpc_add_dst(rpc_t *rpc, void *ctx)
"Invalid Parameters. Usage: secfilter.add_dst "
"number\n Example: secfilter.add_dst "
"555123123");
+ return;
+ }
+ text = int2str(number, &data.len);
+ data.s = pkg_malloc(data.len * sizeof(char));
+ if(!data.s) {
+ PKG_MEM_ERROR;
+ rpc->rpl_printf(ctx, "Error insert values in the blacklist");
+ return;
+ }
+ memcpy(data.s, text, data.len);
+ lock_get(&secf_data->lock);
+ if(append_rule(2, 0, &data) == 0) {
+ rpc->rpl_printf(ctx,
+ "Values (%s) inserted into blacklist destinations", data);
} else {
- text = int2str(number, &data.len);
- data.s = pkg_malloc(data.len * sizeof(char));
- if(!data.s) {
- PKG_MEM_ERROR;
- rpc->rpl_printf(ctx, "Error insert values in the blacklist");
- return;
- }
- memcpy(data.s, text, data.len);
- lock_get(&secf_data->lock);
- if(append_rule(2, 0, &data) == 0) {
- rpc->rpl_printf(ctx,
- "Values (%s) inserted into blacklist destinations", data);
- } else {
- rpc->rpl_printf(ctx, "Error insert values in the blacklist");
- }
- lock_release(&secf_data->lock);
- if(data.s)
- pkg_free(data.s);
+ rpc->rpl_printf(ctx, "Error insert values in the blacklist");
}
+ lock_release(&secf_data->lock);
+ if(data.s)
+ pkg_free(data.s);
}
/* Add blacklist value */
void rpc_add_bl(rpc_t *rpc, void *ctx)
{
- char *ctype;
+ char *ctype = NULL;
str data = STR_NULL;
int type;
- if(rpc->scan(ctx, "ss", (char *)(&ctype), (char *)(&data.s)) < 2) {
+ if(rpc->scan(ctx, "ss", ctype, &data.s) < 2) {
rpc->fault(ctx, 0,
"Invalid Parameters. Usage: secfilter.add_bl type "
"value\n Example: secfilter.add_bl user "
"sipvicious");
+ return;
+ }
+ data.len = strlen(data.s);
+ type = get_type(ctype);
+
+ lock_get(&secf_data->lock);
+ if(append_rule(0, type, &data) == 0) {
+ rpc->rpl_printf(ctx, "Values (%s, %s) inserted into blacklist",
+ ctype, data);
} else {
- data.len = strlen(data.s);
- type = get_type(ctype);
-
- lock_get(&secf_data->lock);
- if(append_rule(0, type, &data) == 0) {
- rpc->rpl_printf(ctx, "Values (%s, %s) inserted into blacklist",
- ctype, data);
- } else {
- rpc->rpl_printf(ctx, "Error insert values in the blacklist");
- }
- lock_release(&secf_data->lock);
+ rpc->rpl_printf(ctx, "Error insert values in the blacklist");
}
+ lock_release(&secf_data->lock);
}
/* Add whitelist value */
void rpc_add_wl(rpc_t *rpc, void *ctx)
{
- char *ctype;
+ char *ctype = NULL;
str data = STR_NULL;
int type;
- if(rpc->scan(ctx, "ss", (char *)(&ctype), (char *)(&data.s)) < 2) {
+ if(rpc->scan(ctx, "ss", ctype, &data.s) < 2) {
rpc->fault(ctx, 0,
"Invalid Parameters. Usage: secfilter.add_wl type "
"value\n Example: secfilter.add_wl user "
"trusted_user");
+ return;
+ }
+ data.len = strlen(data.s);
+ type = get_type(ctype);
+
+ lock_get(&secf_data->lock);
+ if(append_rule(1, type, &data) == 0) {
+ rpc->rpl_printf(
+ ctx, "Values (%s, %s) inserted into whitelist", type, data);
} else {
- data.len = strlen(data.s);
- type = get_type(ctype);
-
- lock_get(&secf_data->lock);
- if(append_rule(1, type, &data) == 0) {
- rpc->rpl_printf(
- ctx, "Values (%s, %s) inserted into whitelist", type, data);
- } else {
- rpc->rpl_printf(ctx, "Error insert values in the whitelist");
- }
- lock_release(&secf_data->lock);
+ rpc->rpl_printf(ctx, "Error insert values in the whitelist");
}
+ lock_release(&secf_data->lock);
}
More information about the sr-dev
mailing list