TT#38155 Add tcap_extract_var function to tcap module

The function is necessary to extract the FCI code from the
variable instead of reading it from the SIP message.

Change-Id: If8a19d205e1ccad64e44cfa75501daa672165a59
changes/21/21921/3
Marco Capetta 8 years ago
parent 5e852cbcd1
commit 0948636930

@ -33,6 +33,7 @@ sipwise/fix_db_redis_time_schema.patch
sipwise/fix_db_redis_free_memory.patch
sipwise/fix_db_redis_memory_issues.patch
sipwise/rtpengine-balancing.patch
sipwise/tcap_add_tcap_var_extract.patch
# backport from kamailio 5.1.3
sipwise/0001-topos-reuse-uuid-for-requests-withing-dialog.patch
sipwise/0002-core-improve-to-header-check-guards-str-consists-of-.patch

@ -0,0 +1,89 @@
--- 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