mirror of https://github.com/sipwise/kamailio.git
Change-Id: I8c8c23e3f27f581fbf894dd6d5383f9db8843dbachanges/57/22357/1
parent
4bb3d4227f
commit
9d621381c3
@ -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…
Reference in new issue