TT#39700 Fold tcap_add_tcap_var_extract.patch into add_tcap_module.patch

Change-Id: I8c8c23e3f27f581fbf894dd6d5383f9db8843dba
changes/57/22357/1
Guillem Jover 8 years ago
parent 4bb3d4227f
commit 9d621381c3

@ -34,7 +34,6 @@ upstream/fix_db_redis_free_memory.patch
upstream/fix_db_redis_memory_issues.patch
upstream/fix_db_redis_manual_key_issue.patch
sipwise/rtpengine-balancing.patch
sipwise/tcap_add_tcap_var_extract.patch
## backport from kamailio upstream (5.2)
upstream/0001-tm-free-new-cell-in-case-of-error.patch
upstream/0002-tm-force-free-cell-if-transaction-is-unlinkled.patch

@ -1,3 +1,9 @@
---
src/Makefile.groups | 6
src/modules/tcap/Makefile | 9 +
src/modules/tcap/tcap_mod.c | 395 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 410 insertions(+)
--- a/src/Makefile.groups
+++ b/src/Makefile.groups
@@ -196,6 +196,9 @@ mod_list_erlang=erlang
@ -34,7 +40,7 @@
+include ../../Makefile.modules
--- /dev/null
+++ b/src/modules/tcap/tcap_mod.c
@@ -0,0 +1,329 @@
@@ -0,0 +1,395 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
@ -57,6 +63,7 @@
+
+static int mod_init(void);
+static int tcap_extract_f(sip_msg_t *msg, char *su, char *sq);
+static int tcap_extract_var_f(sip_msg_t *msg, char *o, char *f, char *d);
+static int inap_extract_f(sip_msg_t *msg, char *su, char *sq);
+static int inap_extract_var_f(sip_msg_t *msg, char *o, char *f, char *d);
+static int isup_decode_number_f(sip_msg_t *msg, char *su, char *sq);
@ -67,6 +74,8 @@
+static cmd_export_t cmds[] = {
+ {"tcap_extract", (cmd_function)tcap_extract_f, 2,
+ fixup_spve_str, 0, ANY_ROUTE},
+ {"tcap_extract_var", (cmd_function)tcap_extract_var_f, 3,
+ fixup_pvar_pvar_pvar, fixup_free_pvar_pvar_pvar, ANY_ROUTE},
+ {"inap_extract", (cmd_function)inap_extract_f, 2,
+ fixup_spve_str, 0, ANY_ROUTE},
+ {"inap_extract_var", (cmd_function)inap_extract_var_f, 3,
@ -271,6 +280,69 @@
+ return i;
+}
+
+static int tcap_extract_var_f(sip_msg_t *msg, char *pv_orig, char *pv_field,
+ char *pv_dest)
+{
+ const char *err;
+ char *bin;
+ int bin_len;
+ static char buf[1024];
+ static char cfield[512];
+ struct output_buffer out;
+ pv_spec_p orig_spec = (pv_spec_t *) pv_orig;
+ pv_spec_p field_spec = (pv_spec_t *) pv_field;
+ pv_spec_p dest_spec = (pv_spec_t *) pv_dest;
+ pv_value_t tcap, field, dest;
+
+ err = "Can't get tcap PV value";
+ if (pv_get_spec_value(msg, orig_spec, &tcap) != 0)
+ goto error;
+
+ err = "orig has to be a string";
+ if(!(tcap.flags&PV_VAL_STR))
+ goto error;
+
+ err = "Can't get field PV value";
+ if (pv_get_spec_value(msg, field_spec, &field) != 0)
+ goto error;
+
+ err = "field has to be a string";
+ if (!(field.flags&PV_VAL_STR))
+ goto error;
+
+ err = "field is too big for internal buffer";
+ if (field.rs.len > 512)
+ goto error;
+ strncpy(cfield, field.rs.s, field.rs.len);
+ cfield[field.rs.len] = '\0';
+
+ err = "Can't decode.hexa";
+ bin_len = _tcap_decode_hexa(&(tcap.rs), &bin);
+ if(bin<=0)
+ goto error;
+
+ OUTPUT_BUFFER_INIT(&out, buf);
+ LM_DBG("tcap:[%.*s][%d] bin:[%.*s] field:[%s]\n", tcap.rs.len, tcap.rs.s,
+ tcap.rs.len, bin_len, bin, cfield);
+
+ err = "Error parsing TCAP body";
+ if (tcap_extract(bin, bin_len, cfield, &out)<0)
+ goto error;
+
+ memset(&dest, 0, sizeof(pv_value_t));
+ dest.flags = PV_VAL_STR;
+ dest.rs.s = out.buf;
+ dest.rs.len = out.used;
+ err = "Failed to set return value";
+ if(pv_set_spec_value(msg, dest_spec, 0, &dest)<0)
+ goto error;
+
+ return 1;
+error:
+ LM_ERR("%s\n", err);
+ return -1;
+}
+
+static int inap_extract_var_f(sip_msg_t *msg, char *pv_orig, char *pv_field,
+ char *pv_dest)
+{

@ -1,89 +0,0 @@
--- a/src/modules/tcap/tcap_mod.c
+++ b/src/modules/tcap/tcap_mod.c
@@ -20,6 +20,7 @@ static int strip_trailing_crlf;
static int mod_init(void);
static int tcap_extract_f(sip_msg_t *msg, char *su, char *sq);
+static int tcap_extract_var_f(sip_msg_t *msg, char *o, char *f, char *d);
static int inap_extract_f(sip_msg_t *msg, char *su, char *sq);
static int inap_extract_var_f(sip_msg_t *msg, char *o, char *f, char *d);
static int isup_decode_number_f(sip_msg_t *msg, char *su, char *sq);
@@ -30,6 +31,8 @@ static int isup_decode_number_hex_f(sip_
static cmd_export_t cmds[] = {
{"tcap_extract", (cmd_function)tcap_extract_f, 2,
fixup_spve_str, 0, ANY_ROUTE},
+ {"tcap_extract_var", (cmd_function)tcap_extract_var_f, 3,
+ fixup_pvar_pvar_pvar, fixup_free_pvar_pvar_pvar, ANY_ROUTE},
{"inap_extract", (cmd_function)inap_extract_f, 2,
fixup_spve_str, 0, ANY_ROUTE},
{"inap_extract_var", (cmd_function)inap_extract_var_f, 3,
@@ -234,6 +237,69 @@ static int _tcap_decode_hexa(str *in, ch
return i;
}
+static int tcap_extract_var_f(sip_msg_t *msg, char *pv_orig, char *pv_field,
+ char *pv_dest)
+{
+ const char *err;
+ char *bin;
+ int bin_len;
+ static char buf[1024];
+ static char cfield[512];
+ struct output_buffer out;
+ pv_spec_p orig_spec = (pv_spec_t *) pv_orig;
+ pv_spec_p field_spec = (pv_spec_t *) pv_field;
+ pv_spec_p dest_spec = (pv_spec_t *) pv_dest;
+ pv_value_t tcap, field, dest;
+
+ err = "Can't get tcap PV value";
+ if (pv_get_spec_value(msg, orig_spec, &tcap) != 0)
+ goto error;
+
+ err = "orig has to be a string";
+ if(!(tcap.flags&PV_VAL_STR))
+ goto error;
+
+ err = "Can't get field PV value";
+ if (pv_get_spec_value(msg, field_spec, &field) != 0)
+ goto error;
+
+ err = "field has to be a string";
+ if (!(field.flags&PV_VAL_STR))
+ goto error;
+
+ err = "field is too big for internal buffer";
+ if (field.rs.len > 512)
+ goto error;
+ strncpy(cfield, field.rs.s, field.rs.len);
+ cfield[field.rs.len] = '\0';
+
+ err = "Can't decode.hexa";
+ bin_len = _tcap_decode_hexa(&(tcap.rs), &bin);
+ if(bin<=0)
+ goto error;
+
+ OUTPUT_BUFFER_INIT(&out, buf);
+ LM_DBG("tcap:[%.*s][%d] bin:[%.*s] field:[%s]\n", tcap.rs.len, tcap.rs.s,
+ tcap.rs.len, bin_len, bin, cfield);
+
+ err = "Error parsing TCAP body";
+ if (tcap_extract(bin, bin_len, cfield, &out)<0)
+ goto error;
+
+ memset(&dest, 0, sizeof(pv_value_t));
+ dest.flags = PV_VAL_STR;
+ dest.rs.s = out.buf;
+ dest.rs.len = out.used;
+ err = "Failed to set return value";
+ if(pv_set_spec_value(msg, dest_spec, 0, &dest)<0)
+ goto error;
+
+ return 1;
+error:
+ LM_ERR("%s\n", err);
+ return -1;
+}
+
static int inap_extract_var_f(sip_msg_t *msg, char *pv_orig, char *pv_field,
char *pv_dest)
{
Loading…
Cancel
Save