|
@@ -33,57 +33,60 @@
|
|
|
|
|
|
static str reply_counter = str_init("reply_counter");
|
|
|
|
|
|
-sr_xavp_t *pvh_xavp_get_child_with_ival(
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static sr_xavp_t *pvh_xavi_get_child_with_ival(
|
|
|
str *rname, str *cname, sr_xavp_t *start)
|
|
|
{
|
|
|
- sr_xavp_t *ravp = NULL;
|
|
|
- sr_xavp_t *vavp = NULL;
|
|
|
+ sr_xavp_t *ravi = NULL;
|
|
|
+ sr_xavp_t *vavi = NULL;
|
|
|
|
|
|
- ravp = xavp_get(rname, start);
|
|
|
- if(ravp == NULL || ravp->val.type != SR_XTYPE_XAVP)
|
|
|
+ ravi = xavi_get(rname, start);
|
|
|
+ if(ravi == NULL || ravi->val.type != SR_XTYPE_XAVP)
|
|
|
return NULL;
|
|
|
|
|
|
- vavp = xavp_get(cname, ravp->val.v.xavp);
|
|
|
- if(vavp == NULL || vavp->val.type != SR_XTYPE_INT)
|
|
|
+ vavi = xavi_get(cname, ravi->val.v.xavp);
|
|
|
+ if(vavi == NULL || vavi->val.type != SR_XTYPE_INT)
|
|
|
return NULL;
|
|
|
|
|
|
- return vavp;
|
|
|
+ return vavi;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * We keep a $xavp(xavp_helper_xname=>reply_counter) with the number of replies
|
|
|
- * so we will use $xavp(xavp_name.r.<id>) on reply_route
|
|
|
+ * We keep a $xavi(xavi_helper_xname=>reply_counter) with the number of replies
|
|
|
+ * so we will use $xavi(xavi_name.r.<id>) on reply_route
|
|
|
*/
|
|
|
int pvh_reply_append(sr_xavp_t **start)
|
|
|
{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL;
|
|
|
sr_xval_t xval;
|
|
|
|
|
|
- xavp = pvh_xavp_get_child_with_ival(
|
|
|
- &xavp_helper_xname, &reply_counter, start ? *start : NULL);
|
|
|
- if(xavp) {
|
|
|
- xavp->val.v.i++;
|
|
|
- LM_DBG("reply message: %d\n", xavp->val.v.i);
|
|
|
- return xavp->val.v.i;
|
|
|
+ xavi = pvh_xavi_get_child_with_ival(
|
|
|
+ &xavi_helper_xname, &reply_counter, start ? *start : NULL);
|
|
|
+ if(xavi) {
|
|
|
+ xavi->val.v.i++;
|
|
|
+ LM_DBG("reply message: %d\n", xavi->val.v.i);
|
|
|
+ return xavi->val.v.i;
|
|
|
}
|
|
|
|
|
|
memset(&xval, 0, sizeof(sr_xval_t));
|
|
|
xval.type = SR_XTYPE_INT;
|
|
|
xval.v.i = 0;
|
|
|
|
|
|
- xavp = xavp_get(&xavp_helper_xname, start ? *start : NULL);
|
|
|
- if(xavp == NULL) {
|
|
|
- if(xavp_add_xavp_value(&xavp_helper_xname, &reply_counter, &xval,
|
|
|
+ xavi = xavi_get(&xavi_helper_xname, start ? *start : NULL);
|
|
|
+ if(xavi == NULL) {
|
|
|
+ if(xavi_add_xavi_value(&xavi_helper_xname, &reply_counter, &xval,
|
|
|
start ? start : NULL)
|
|
|
== NULL) {
|
|
|
- LM_ERR("can't create xavp:%.*s\n", xavp_helper_xname.len,
|
|
|
- xavp_helper_xname.s);
|
|
|
+ LM_ERR("can't create xavi:%.*s\n", xavi_helper_xname.len,
|
|
|
+ xavi_helper_xname.s);
|
|
|
return -1;
|
|
|
}
|
|
|
- LM_DBG("xavp_name:%.*s created\n", xavp_helper_xname.len,
|
|
|
- xavp_helper_xname.s);
|
|
|
+ LM_DBG("xavi_name:%.*s created\n", xavi_helper_xname.len,
|
|
|
+ xavi_helper_xname.s);
|
|
|
} else {
|
|
|
- if(xavp_add_value(&reply_counter, &xval, &xavp->val.v.xavp) == NULL) {
|
|
|
+ if(xavi_add_value(&reply_counter, &xval, &xavi->val.v.xavp) == NULL) {
|
|
|
LM_ERR("can't add reply_counter value\n");
|
|
|
return -1;
|
|
|
}
|
|
@@ -93,7 +96,7 @@ int pvh_reply_append(sr_xavp_t **start)
|
|
|
return xval.v.i;
|
|
|
}
|
|
|
|
|
|
-sr_xavp_t *pvh_xavp_new_value(str *name, sr_xval_t *val)
|
|
|
+static sr_xavp_t *pvh_xavi_new_value(str *name, sr_xval_t *val)
|
|
|
{
|
|
|
sr_xavp_t *avp = NULL;
|
|
|
int size;
|
|
@@ -101,7 +104,7 @@ sr_xavp_t *pvh_xavp_new_value(str *name, sr_xval_t *val)
|
|
|
|
|
|
if(name == NULL || name->s == NULL || val == NULL)
|
|
|
return NULL;
|
|
|
- id = get_hash1_raw(name->s, name->len);
|
|
|
+ id = get_hash1_case_raw(name->s, name->len);
|
|
|
|
|
|
size = sizeof(sr_xavp_t) + name->len + 1;
|
|
|
if(val->type == SR_XTYPE_STR)
|
|
@@ -128,83 +131,82 @@ sr_xavp_t *pvh_xavp_new_value(str *name, sr_xval_t *val)
|
|
|
return avp;
|
|
|
}
|
|
|
|
|
|
-int pvh_xavp_append_value(str *name, sr_xval_t *val, sr_xavp_t **start)
|
|
|
+int pvh_xavi_append_value(str *name, sr_xval_t *val, sr_xavp_t **start)
|
|
|
{
|
|
|
sr_xavp_t *last = NULL;
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL;
|
|
|
|
|
|
- if((xavp = pvh_xavp_new_value(name, val)) == NULL)
|
|
|
+ if((xavi = pvh_xavi_new_value(name, val)) == NULL)
|
|
|
return -1;
|
|
|
|
|
|
if(*start == NULL) {
|
|
|
- xavp->next = *start;
|
|
|
- *start = xavp;
|
|
|
+ xavi->next = *start;
|
|
|
+ *start = xavi;
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
last = *start;
|
|
|
while(last->next)
|
|
|
last = last->next;
|
|
|
- last->next = xavp;
|
|
|
+ last->next = xavi;
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-int pvh_xavp_set_value(str *name, sr_xval_t *val, int idx, sr_xavp_t **start)
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static int pvh_xavi_set_value(
|
|
|
+ str *name, sr_xval_t *val, int idx, sr_xavp_t **start)
|
|
|
{
|
|
|
int cnt = 0;
|
|
|
|
|
|
if(idx < 0) {
|
|
|
- cnt = xavp_count(name, start);
|
|
|
+ cnt = xavi_count(name, start);
|
|
|
idx = idx + cnt;
|
|
|
- if(idx < 0)
|
|
|
+ if(idx < 0) {
|
|
|
+ LM_ERR("wrong calculated idx:%d\n", idx);
|
|
|
return -1;
|
|
|
+ }
|
|
|
}
|
|
|
- LM_DBG("xavp name: %.*s\n", name->len, name->s);
|
|
|
- if(xavp_set_value(name, idx, val, start) == NULL)
|
|
|
+ LM_DBG("xavi name: %.*s\n", name->len, name->s);
|
|
|
+ if(xavi_set_value(name, idx, val, start) == NULL)
|
|
|
return -1;
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-sr_xavp_t *pvh_xavp_get(struct sip_msg *msg, str *xname)
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static sr_xavp_t *pvh_get_xavi(struct sip_msg *msg, str *xname)
|
|
|
{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL;
|
|
|
char t[header_name_size];
|
|
|
str br_xname = {t, header_name_size};
|
|
|
|
|
|
pvh_get_branch_xname(msg, xname, &br_xname);
|
|
|
- if((xavp = xavp_get(&br_xname, NULL)) == NULL) {
|
|
|
+ if((xavi = xavi_get(&br_xname, NULL)) == NULL) {
|
|
|
if(cmp_str(xname, &br_xname) == 0)
|
|
|
goto end;
|
|
|
- if((xavp = xavp_get(xname, NULL)) == NULL)
|
|
|
+ if((xavi = xavi_get(xname, NULL)) == NULL)
|
|
|
goto end;
|
|
|
- if(xname != &xavp_parsed_xname) {
|
|
|
- LM_DBG("br_xname:%.*s is not there, using xname:%.*s\n",
|
|
|
- br_xname.len, br_xname.s, xname->len, xname->s);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- if(xavp->val.type != SR_XTYPE_XAVP) {
|
|
|
+ if(xavi->val.type != SR_XTYPE_XAVP) {
|
|
|
LM_ERR("not xavp child type %s\n", br_xname.s);
|
|
|
- xavp = NULL;
|
|
|
+ xavi = NULL;
|
|
|
goto end;
|
|
|
}
|
|
|
|
|
|
end:
|
|
|
- return xavp;
|
|
|
-}
|
|
|
-
|
|
|
-int pvh_free_xavp(str *xname)
|
|
|
-{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
- xavp_rm_by_name(xname, 1, NULL);
|
|
|
- if((xavp = xavp_get(xname, NULL)) != NULL)
|
|
|
- xavp_rm(xavp, NULL);
|
|
|
- return 1;
|
|
|
+ return xavi;
|
|
|
}
|
|
|
|
|
|
-void pvh_free_to_params(struct to_param *param, sr_xavp_sfree_f sfree)
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static void pvh_free_to_params(struct to_param *param, sr_xavp_sfree_f sfree)
|
|
|
{
|
|
|
struct to_param *n = NULL;
|
|
|
|
|
@@ -216,6 +218,9 @@ void pvh_free_to_params(struct to_param *param, sr_xavp_sfree_f sfree)
|
|
|
param = NULL;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_parse_header_name(pv_spec_p sp, str *hname)
|
|
|
{
|
|
|
pv_spec_p psp = NULL;
|
|
@@ -237,13 +242,12 @@ int pvh_parse_header_name(pv_spec_p sp, str *hname)
|
|
|
return -1;
|
|
|
}
|
|
|
if(pv_parse_spec(hname, psp) == NULL) {
|
|
|
- LM_ERR("invalid avp name [%.*s]\n", hname->len, hname->s);
|
|
|
+ LM_ERR("invalid name [%.*s]\n", hname->len, hname->s);
|
|
|
pv_spec_free(psp);
|
|
|
return -1;
|
|
|
}
|
|
|
sp->pvp.pvn.type = PV_NAME_PVAR;
|
|
|
sp->pvp.pvn.u.dname = (void *)psp;
|
|
|
- sp->pvp.pvn.u.isname.name.s = *hname;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -254,42 +258,51 @@ int pvh_parse_header_name(pv_spec_p sp, str *hname)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-sr_xval_t *pvh_xavp_get_value(
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static sr_xval_t *pvh_xavi_get_value(
|
|
|
struct sip_msg *msg, str *xname, str *name, int idx)
|
|
|
{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL;
|
|
|
sr_xavp_t *sub = NULL;
|
|
|
|
|
|
- if((xavp = pvh_xavp_get(msg, xname)) != NULL) {
|
|
|
- /* LM_DBG("xavp:%.*s name:%.*s idx:%d\n", xavp->name.len, xavp->name.s,
|
|
|
+ if((xavi = pvh_get_xavi(msg, xname)) != NULL) {
|
|
|
+ /* LM_DBG("xavi:%.*s name:%.*s idx:%d\n", xavi->name.len, xavi->name.s,
|
|
|
name->len, name->s, idx); */
|
|
|
- sub = xavp_get_by_index(name, idx, &xavp->val.v.xavp);
|
|
|
+ sub = xavi_get_by_index(name, idx, &xavi->val.v.xavp);
|
|
|
}
|
|
|
|
|
|
return sub ? &sub->val : NULL;
|
|
|
}
|
|
|
|
|
|
-sr_xavp_t *pvh_xavp_get_child(struct sip_msg *msg, str *xname, str *name)
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+sr_xavp_t *pvh_xavi_get_child(struct sip_msg *msg, str *xname, str *name)
|
|
|
{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL;
|
|
|
char t[header_name_size];
|
|
|
str br_xname = {t, header_name_size};
|
|
|
|
|
|
pvh_get_branch_xname(msg, xname, &br_xname);
|
|
|
- xavp = xavp_get_child(&br_xname, name);
|
|
|
- if(xavp == NULL) {
|
|
|
+ xavi = xavi_get_child(&br_xname, name);
|
|
|
+ if(xavi == NULL) {
|
|
|
if(cmp_str(xname, &br_xname) != 0) {
|
|
|
- xavp = xavp_get_child(xname, name);
|
|
|
- if(xavp) {
|
|
|
- LM_DBG("br_xname:%.*s is not there, using xname:%.*s\n",
|
|
|
+ xavi = xavi_get_child(xname, name);
|
|
|
+ if(xavi) {
|
|
|
+ LM_DBG("br_xname:%.*s is not here, using xname:%.*s\n",
|
|
|
br_xname.len, br_xname.s, xname->len, xname->s);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return xavp;
|
|
|
+ return xavi;
|
|
|
}
|
|
|
|
|
|
-int pvh_xavp_is_null(sr_xavp_t *avp)
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int pvh_avp_is_null(sr_xavp_t *avp)
|
|
|
{
|
|
|
if(avp == NULL)
|
|
|
return 1;
|
|
@@ -303,7 +316,10 @@ int pvh_xavp_is_null(sr_xavp_t *avp)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-void pvh_xavp_free_data(void *p, sr_xavp_sfree_f sfree)
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static void pvh_xavi_free_data(void *p, sr_xavp_sfree_f sfree)
|
|
|
{
|
|
|
xavp_c_data_t *c_data = NULL;
|
|
|
|
|
@@ -316,28 +332,34 @@ void pvh_xavp_free_data(void *p, sr_xavp_sfree_f sfree)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int pvh_xavp_keys_count(sr_xavp_t **start)
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int pvh_xavi_keys_count(sr_xavp_t **start)
|
|
|
{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL;
|
|
|
int cnt = 0;
|
|
|
|
|
|
if(*start == NULL)
|
|
|
return 0;
|
|
|
|
|
|
- xavp = *start;
|
|
|
+ xavi = *start;
|
|
|
|
|
|
- while(xavp) {
|
|
|
+ while(xavi) {
|
|
|
cnt++;
|
|
|
- xavp = xavp->next;
|
|
|
+ xavi = xavi->next;
|
|
|
}
|
|
|
|
|
|
return cnt;
|
|
|
}
|
|
|
|
|
|
-int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int pvh_set_xavi(struct sip_msg *msg, str *xname, str *name, void *data,
|
|
|
sr_xtype_t type, int idx, int append)
|
|
|
{
|
|
|
- sr_xavp_t **xavp = NULL;
|
|
|
+ sr_xavp_t **xavi = NULL;
|
|
|
sr_xavp_t *root = NULL;
|
|
|
sr_xval_t root_xval;
|
|
|
sr_xval_t xval;
|
|
@@ -345,13 +367,13 @@ int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
|
|
|
str br_xname = {t, header_name_size};
|
|
|
|
|
|
if(xname == NULL || name == NULL) {
|
|
|
- LM_ERR("missing xavp/pv name\n");
|
|
|
+ LM_ERR("missing xavi/pv name\n");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
pvh_get_branch_xname(msg, xname, &br_xname);
|
|
|
- LM_DBG("br_xname: %.*s name: %.*s\n", br_xname.len, br_xname.s, name->len,
|
|
|
- name->s);
|
|
|
+ LM_DBG("br_xname: %.*s name: %.*s append:%d\n", br_xname.len, br_xname.s,
|
|
|
+ name->len, name->s, append);
|
|
|
memset(&xval, 0, sizeof(sr_xval_t));
|
|
|
if(data == NULL || SR_XTYPE_NULL) {
|
|
|
xval.type = SR_XTYPE_NULL;
|
|
@@ -367,17 +389,17 @@ int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
|
|
|
}
|
|
|
memset(xval.v.data, 0, sizeof(sr_data_t));
|
|
|
xval.v.data->p = data;
|
|
|
- xval.v.data->pfree = pvh_xavp_free_data;
|
|
|
+ xval.v.data->pfree = pvh_xavi_free_data;
|
|
|
}
|
|
|
|
|
|
- root = xavp_get(&br_xname, NULL);
|
|
|
+ root = xavi_get(&br_xname, NULL);
|
|
|
|
|
|
if(root == NULL && _branch > 0) {
|
|
|
- pvh_clone_branch_xavp(msg, xname);
|
|
|
- root = xavp_get(&br_xname, NULL);
|
|
|
+ pvh_clone_branch_xavi(msg, xname);
|
|
|
+ root = xavi_get(&br_xname, NULL);
|
|
|
}
|
|
|
|
|
|
- xavp = root ? &root->val.v.xavp : &root;
|
|
|
+ xavi = root ? &root->val.v.xavp : &root;
|
|
|
|
|
|
if(root == NULL) {
|
|
|
append = 1;
|
|
@@ -385,25 +407,25 @@ int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
|
|
|
root_xval.type = SR_XTYPE_XAVP;
|
|
|
root_xval.v.xavp = NULL;
|
|
|
|
|
|
- if((root = xavp_add_value(&br_xname, &root_xval, NULL)) == NULL) {
|
|
|
- LM_ERR("error create xavp %s\n", br_xname.s);
|
|
|
+ if((root = xavi_add_value(&br_xname, &root_xval, NULL)) == NULL) {
|
|
|
+ LM_ERR("error create xavi %.*s\n", br_xname.len, br_xname.s);
|
|
|
return -1;
|
|
|
}
|
|
|
- xavp = &root->val.v.xavp;
|
|
|
- } else if(xavp_get_child(&br_xname, name) == NULL) {
|
|
|
+ xavi = &root->val.v.xavp;
|
|
|
+ } else if(xavi_get_child(&br_xname, name) == NULL) {
|
|
|
append = 1;
|
|
|
}
|
|
|
|
|
|
if(append) {
|
|
|
- if(pvh_xavp_append_value(name, &xval, xavp) < 0) {
|
|
|
- LM_ERR("error append xavp=>name %s=>%.*s\n", br_xname.s, name->len,
|
|
|
- name->s);
|
|
|
+ if(pvh_xavi_append_value(name, &xval, xavi) < 0) {
|
|
|
+ LM_ERR("error append xavi=>name %.*s=>%.*s\n", br_xname.len,
|
|
|
+ br_xname.s, name->len, name->s);
|
|
|
return -1;
|
|
|
}
|
|
|
} else {
|
|
|
- if(pvh_xavp_set_value(name, &xval, idx, xavp) < 0) {
|
|
|
- LM_ERR("error modify xavp=>name %s=>%.*s idx=%d\n", br_xname.s,
|
|
|
- name->len, name->s, idx);
|
|
|
+ if(pvh_xavi_set_value(name, &xval, idx, xavi) < 0) {
|
|
|
+ LM_ERR("error modify xavi=>name %.*s=>%.*s idx=%d\n", br_xname.len,
|
|
|
+ br_xname.s, name->len, name->s, idx);
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
@@ -411,32 +433,10 @@ int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-int pvh_get_branch_index(struct sip_msg *msg, int *br_idx)
|
|
|
-{
|
|
|
- int os = 0;
|
|
|
- int len = 0;
|
|
|
- char parsed_br_idx[header_value_size];
|
|
|
-
|
|
|
- if(msg->add_to_branch_len > header_value_size) {
|
|
|
- LM_ERR("branch name is too long\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- os = msg->add_to_branch_len;
|
|
|
- while(os > 0 && memcmp(msg->add_to_branch_s + os - 1, ".", 1))
|
|
|
- os--;
|
|
|
- len = msg->add_to_branch_len - os;
|
|
|
- if(os > 0 && len > 0) {
|
|
|
- memcpy(parsed_br_idx, msg->add_to_branch_s + os, len);
|
|
|
- parsed_br_idx[len] = '\0';
|
|
|
- *br_idx = atoi(parsed_br_idx) + 1;
|
|
|
- } else {
|
|
|
- *br_idx = 0;
|
|
|
- }
|
|
|
-
|
|
|
- return 1;
|
|
|
-}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_get_branch_xname(struct sip_msg *msg, str *xname, str *dst)
|
|
|
{
|
|
|
int os = 0;
|
|
@@ -470,28 +470,32 @@ int pvh_get_branch_xname(struct sip_msg *msg, str *xname, str *dst)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname)
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int pvh_clone_branch_xavi(struct sip_msg *msg, str *xname)
|
|
|
{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
- sr_xavp_t *br_xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL;
|
|
|
+ sr_xavp_t *br_xavi = NULL;
|
|
|
sr_xavp_t *sub = NULL;
|
|
|
sr_xval_t root_xval;
|
|
|
char t[header_name_size];
|
|
|
str br_xname = {t, header_name_size};
|
|
|
int i = 0;
|
|
|
|
|
|
- if((xavp = xavp_get(xname, NULL)) == NULL) {
|
|
|
- LM_ERR("cannot clone xavp from non existing %s\n", xname->s);
|
|
|
+ if((xavi = xavi_get(xname, NULL)) == NULL) {
|
|
|
+ LM_ERR("cannot clone xavi from non existing %.*s\n", xname->len,
|
|
|
+ xname->s);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- if(xavp->val.type != SR_XTYPE_XAVP) {
|
|
|
- LM_ERR("not xavp child type %s\n", xavp_name.s);
|
|
|
+ if(xavi->val.type != SR_XTYPE_XAVP) {
|
|
|
+ LM_ERR("not xavp child type %.*s\n", xavi_name.len, xavi_name.s);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- if((sub = xavp->val.v.xavp) == NULL) {
|
|
|
- LM_ERR("invalid xavp structure: %s\n", xavp_name.s);
|
|
|
+ if((sub = xavi->val.v.xavp) == NULL) {
|
|
|
+ LM_ERR("invalid xavi structure: %.*s\n", xavi_name.len, xavi_name.s);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -501,12 +505,12 @@ int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname)
|
|
|
root_xval.type = SR_XTYPE_XAVP;
|
|
|
root_xval.v.xavp = NULL;
|
|
|
|
|
|
- if((br_xavp = xavp_add_value(&br_xname, &root_xval, NULL)) == NULL) {
|
|
|
- LM_ERR("error create xavp %s\n", br_xname.s);
|
|
|
+ if((br_xavi = xavi_add_value(&br_xname, &root_xval, NULL)) == NULL) {
|
|
|
+ LM_ERR("error create xavi %.*s\n", br_xname.len, br_xname.s);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- if(cmp_str(xname, &xavp_parsed_xname) == 0) {
|
|
|
+ if(cmp_str(xname, &xavi_parsed_xname) == 0) {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
@@ -515,9 +519,9 @@ int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname)
|
|
|
continue;
|
|
|
if(sub->val.type == SR_XTYPE_DATA)
|
|
|
continue;
|
|
|
- if(pvh_xavp_append_value(&sub->name, &sub->val, &br_xavp->val.v.xavp)
|
|
|
+ if(pvh_xavi_append_value(&sub->name, &sub->val, &br_xavi->val.v.xavp)
|
|
|
< 0) {
|
|
|
- LM_ERR("cannot clone xavp %s\n", sub->name.s);
|
|
|
+ LM_ERR("cannot clone xavi %.*s\n", sub->name.len, sub->name.s);
|
|
|
return -1;
|
|
|
}
|
|
|
++i;
|
|
@@ -527,9 +531,12 @@ int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
|
|
|
{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL;
|
|
|
sr_xval_t *xval = NULL;
|
|
|
pv_value_t tv;
|
|
|
str hname = STR_NULL;
|
|
@@ -554,16 +561,16 @@ int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
|
|
|
}
|
|
|
|
|
|
if(idx < 0) {
|
|
|
- if((xavp = pvh_xavp_get_child(msg, &xavp_name, &hname)) == NULL)
|
|
|
+ if((xavi = pvh_xavi_get_child(msg, &xavi_name, &hname)) == NULL)
|
|
|
cnt = 0;
|
|
|
else
|
|
|
- cnt = xavp_count(&hname, &xavp);
|
|
|
+ cnt = xavi_count(&hname, &xavi);
|
|
|
idx = idx + cnt;
|
|
|
if(idx < 0)
|
|
|
pv_get_null(msg, param, res);
|
|
|
}
|
|
|
|
|
|
- xval = pvh_xavp_get_value(msg, &xavp_name, &hname, idx);
|
|
|
+ xval = pvh_xavi_get_value(msg, &xavi_name, &hname, idx);
|
|
|
|
|
|
if(xval == NULL || !xval->v.s.s)
|
|
|
return pv_get_null(msg, param, res);
|
|
@@ -571,56 +578,56 @@ int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
|
|
|
return pv_get_strval(msg, param, res, &xval->v.s);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_set_header(
|
|
|
struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
|
|
|
{
|
|
|
- sr_xavp_t *xavp = NULL;
|
|
|
+ sr_xavp_t *xavi = NULL, *avi = NULL;
|
|
|
pv_elem_p pv_format = NULL;
|
|
|
pv_value_t tv;
|
|
|
- str hname = STR_NULL;
|
|
|
- str orig_hname = STR_NULL;
|
|
|
- str fval;
|
|
|
- int idx = 0;
|
|
|
- int cnt = 0;
|
|
|
- int itype;
|
|
|
-
|
|
|
- idx = param->pvi.u.ival;
|
|
|
- itype = param->pvi.type;
|
|
|
+ str *hname = NULL;
|
|
|
+ str fval = STR_NULL;
|
|
|
+ int idxf, idx, hname_cnt, cnt;
|
|
|
|
|
|
- if(param->pvn.type == PV_NAME_PVAR) {
|
|
|
- if(pv_get_spec_value(msg, (pv_spec_p)(param->pvn.u.dname), &tv) != 0) {
|
|
|
- LM_ERR("cannot get avp value\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if(!(tv.flags & PV_VAL_STR)) {
|
|
|
- LM_ERR("invalid avp value, must be a string\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- hname = tv.rs;
|
|
|
- orig_hname = param->pvn.u.isname.name.s;
|
|
|
- } else if(param->pvn.u.isname.type == AVP_NAME_STR) {
|
|
|
- hname = param->pvn.u.isname.name.s;
|
|
|
- orig_hname = hname;
|
|
|
- } else {
|
|
|
+ if(pv_get_spec_name(msg, param, &tv) != 0 || (!(tv.flags & PV_VAL_STR))) {
|
|
|
LM_ERR("invalid header name, must be a string\n");
|
|
|
return -1;
|
|
|
}
|
|
|
+ hname = &tv.rs;
|
|
|
+
|
|
|
+ /* get the index */
|
|
|
+ if(pv_get_spec_index(msg, param, &idx, &idxf) != 0) {
|
|
|
+ LM_ERR("invalid index\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
- if((xavp = pvh_xavp_get_child(msg, &xavp_name, &hname)) == NULL)
|
|
|
+ xavi = pvh_get_xavi(msg, &xavi_name);
|
|
|
+ avi = xavi->val.v.xavp;
|
|
|
+ hname_cnt = xavi_count(hname, &avi);
|
|
|
+ if(hname_cnt == 0) {
|
|
|
idx = 0;
|
|
|
- else if(idx < 0)
|
|
|
- idx = idx + xavp_count(&hname, &xavp);
|
|
|
+ } else if(idx < 0) {
|
|
|
+ idx = idx + hname_cnt;
|
|
|
+ }
|
|
|
+ if(idx < 0) {
|
|
|
+ LM_ERR("invalid index\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ LM_DBG("xavi:%.*s hname:%.*s hname_cnt:%d idx:%d idxf:%d\n", xavi->name.len,
|
|
|
+ xavi->name.s, hname->len, hname->s, hname_cnt, idx, idxf);
|
|
|
|
|
|
if(val == NULL || (val->flags & PV_VAL_NULL)) {
|
|
|
- if(itype == PV_IDX_ALL) {
|
|
|
- for(idx = xavp_count(&hname, &xavp) - 1; idx >= 0; idx--) {
|
|
|
- if(pvh_set_xavp(
|
|
|
- msg, &xavp_name, &hname, NULL, SR_XTYPE_STR, idx, 0)
|
|
|
- < 0)
|
|
|
- goto err;
|
|
|
- }
|
|
|
+ if(idxf == PV_IDX_ALL) {
|
|
|
+ cnt = xavi_rm_by_name(hname, 1, &xavi);
|
|
|
+ LM_DBG("removed %d values of %.*s=>%.*s, set $null\n", cnt,
|
|
|
+ xavi->name.len, xavi->name.s, hname->len, hname->s);
|
|
|
+ if(pvh_set_xavi(msg, &xavi_name, hname, NULL, SR_XTYPE_NULL, 0, 0)
|
|
|
+ < 0)
|
|
|
+ goto err;
|
|
|
} else {
|
|
|
- if(pvh_set_xavp(msg, &xavp_name, &hname, NULL, SR_XTYPE_STR, idx, 0)
|
|
|
+ if(pvh_set_xavi(msg, &xavi_name, hname, NULL, SR_XTYPE_NULL, idx, 0)
|
|
|
< 0)
|
|
|
goto err;
|
|
|
}
|
|
@@ -638,27 +645,22 @@ int pvh_set_header(
|
|
|
LM_ERR("cannot parse format: %.*s\n", val->rs.len, val->rs.s);
|
|
|
goto err;
|
|
|
}
|
|
|
- if(strlen(orig_hname.s) > 1
|
|
|
- && strcmp(orig_hname.s + strlen(orig_hname.s) - 2, "])") != 0) {
|
|
|
- if(pvh_set_xavp(msg, &xavp_name, &hname, &fval, SR_XTYPE_STR, 0, 1)
|
|
|
+ if(idx == 0 && idxf == PV_IDX_NONE) {
|
|
|
+ if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, 0, 1)
|
|
|
< 0)
|
|
|
goto err;
|
|
|
- } else if(itype == PV_IDX_ALL) {
|
|
|
- idx = 0;
|
|
|
- cnt = xavp_count(&hname, &xavp);
|
|
|
- while(idx < cnt) {
|
|
|
- if(pvh_set_xavp(msg, &xavp_name, &hname, NULL, SR_XTYPE_STR,
|
|
|
- idx++, 0)
|
|
|
- < 1)
|
|
|
- goto err;
|
|
|
+ } else if(idxf == PV_IDX_ALL) {
|
|
|
+ if(hname_cnt > 1) {
|
|
|
+ cnt = xavi_rm_by_name(hname, 1, &xavi);
|
|
|
+ LM_DBG("removed %d values of %.*s=>%.*s\n", cnt, xavi->name.len,
|
|
|
+ xavi->name.s, hname->len, hname->s);
|
|
|
}
|
|
|
- if(pvh_set_xavp(msg, &xavp_name, &hname, &fval, SR_XTYPE_STR, 0,
|
|
|
- cnt ? 0 : 1)
|
|
|
+ if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, 0,
|
|
|
+ hname_cnt ? 0 : 1)
|
|
|
< 0)
|
|
|
goto err;
|
|
|
} else {
|
|
|
- if(pvh_set_xavp(
|
|
|
- msg, &xavp_name, &hname, &fval, SR_XTYPE_STR, idx, 0)
|
|
|
+ if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, idx, 0)
|
|
|
< 0)
|
|
|
goto err;
|
|
|
}
|
|
@@ -666,7 +668,7 @@ int pvh_set_header(
|
|
|
pv_elem_free_all(pv_format);
|
|
|
} else {
|
|
|
LM_ERR("x_hdr %.*s value can be either string, integer or null\n",
|
|
|
- hname.len, hname.s);
|
|
|
+ hname->len, hname->s);
|
|
|
goto err;
|
|
|
}
|
|
|
return 1;
|
|
@@ -677,6 +679,9 @@ err:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
xavp_c_data_t *pvh_set_parsed(
|
|
|
struct sip_msg *msg, str *hname, str *cur, str *new)
|
|
|
{
|
|
@@ -693,7 +698,7 @@ xavp_c_data_t *pvh_set_parsed(
|
|
|
val = cur;
|
|
|
if(pvh_merge_uri(msg, SET_URI_T, cur, val, c_data) < 0)
|
|
|
goto err;
|
|
|
- if(pvh_set_xavp(msg, &xavp_parsed_xname, hname, c_data, SR_XTYPE_DATA, 0, 0)
|
|
|
+ if(pvh_set_xavi(msg, &xavi_parsed_xname, hname, c_data, SR_XTYPE_DATA, 0, 0)
|
|
|
< 0)
|
|
|
goto err;
|
|
|
LM_DBG("c_data from pvh_merge_uri hname:%.*s\n", hname->len, hname->s);
|
|
@@ -701,10 +706,13 @@ xavp_c_data_t *pvh_set_parsed(
|
|
|
return c_data;
|
|
|
|
|
|
err:
|
|
|
- // how can I call?? pvh_xavp_free_data(c_data, shm_free);
|
|
|
+ // how can I call?? pvh_xavi_free_data(c_data, shm_free);
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_get_uri(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
|
|
|
{
|
|
|
sr_xval_t *xval = NULL;
|
|
@@ -723,17 +731,17 @@ int pvh_get_uri(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
|
|
|
else if(p_no >= 6 && p_no <= 10)
|
|
|
pvh_str_copy(&hname, &_hdr_to, header_name_size);
|
|
|
|
|
|
- xval = pvh_xavp_get_value(msg, &xavp_name, &hname, 0);
|
|
|
+ xval = pvh_xavi_get_value(msg, &xavi_name, &hname, 0);
|
|
|
if(xval == NULL || !xval->v.s.s) {
|
|
|
- /* LM_DBG("xavp:%.*s hname:%.*s is null\n", xavp_name.len, xavp_name.s,
|
|
|
+ /* LM_DBG("xavi:%.*s hname:%.*s is null\n", xavi_name.len, xavi_name.s,
|
|
|
hname.len, hname.s); */
|
|
|
goto err;
|
|
|
}
|
|
|
|
|
|
- xval_pd = pvh_xavp_get_value(msg, &xavp_parsed_xname, &hname, 0);
|
|
|
+ xval_pd = pvh_xavi_get_value(msg, &xavi_parsed_xname, &hname, 0);
|
|
|
|
|
|
if(xval_pd) {
|
|
|
- /* LM_DBG("p_no:%d c_data from xavp_parsed_xname hname:%.*s\n", p_no,
|
|
|
+ /* LM_DBG("p_no:%d c_data from xavi_parsed_xname hname:%.*s\n", p_no,
|
|
|
hname.len, hname.s); */
|
|
|
c_data = (xavp_c_data_t *)xval_pd->v.data->p;
|
|
|
}
|
|
@@ -782,6 +790,9 @@ err:
|
|
|
return pv_get_null(msg, param, res);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_set_uri(struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
|
|
|
{
|
|
|
sr_xval_t *xval = NULL;
|
|
@@ -836,7 +847,7 @@ int pvh_set_uri(struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
|
|
|
goto err;
|
|
|
}
|
|
|
|
|
|
- xval = pvh_xavp_get_value(msg, &xavp_name, &hname, 0);
|
|
|
+ xval = pvh_xavi_get_value(msg, &xavi_name, &hname, 0);
|
|
|
if(xval == NULL || !xval->v.s.s)
|
|
|
goto err;
|
|
|
|
|
@@ -848,14 +859,14 @@ int pvh_set_uri(struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
|
|
|
memset(c_data, 0, sizeof(xavp_c_data_t));
|
|
|
if(pvh_merge_uri(msg, a_type, &xval->v.s, &fval, c_data) < 0)
|
|
|
goto err;
|
|
|
- /* LM_DBG("xavp:%.*s hname:%.*s value:%.*s\n", xavp_name.len, xavp_name.s,
|
|
|
+ /* LM_DBG("xavi:%.*s hname:%.*s value:%.*s\n", xavi_name.len, xavi_name.s,
|
|
|
hname.len, hname.s, c_data->value.len, c_data->value.s); */
|
|
|
- if(pvh_set_xavp(msg, &xavp_name, &hname, &c_data->value, SR_XTYPE_STR, 0, 0)
|
|
|
+ if(pvh_set_xavi(msg, &xavi_name, &hname, &c_data->value, SR_XTYPE_STR, 0, 0)
|
|
|
< 0)
|
|
|
goto err;
|
|
|
|
|
|
- if(pvh_set_xavp(
|
|
|
- msg, &xavp_parsed_xname, &hname, c_data, SR_XTYPE_DATA, 0, 0)
|
|
|
+ if(pvh_set_xavi(
|
|
|
+ msg, &xavi_parsed_xname, &hname, c_data, SR_XTYPE_DATA, 0, 0)
|
|
|
< 0)
|
|
|
goto err;
|
|
|
|
|
@@ -869,6 +880,9 @@ err:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_merge_uri(struct sip_msg *msg, enum action_type type, str *cur,
|
|
|
str *new, xavp_c_data_t *c_data)
|
|
|
{
|
|
@@ -1025,6 +1039,9 @@ err:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_get_reply_sr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
|
|
|
{
|
|
|
sr_xval_t *xval = NULL;
|
|
@@ -1042,7 +1059,7 @@ int pvh_get_reply_sr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
|
|
|
&msg->first_line.u.reply.status);
|
|
|
break;
|
|
|
case 2: // reason
|
|
|
- xval = pvh_xavp_get_value(msg, &xavp_name, &_hdr_reply_reason, 0);
|
|
|
+ xval = pvh_xavi_get_value(msg, &xavi_name, &_hdr_reply_reason, 0);
|
|
|
return pv_get_strval(msg, param, res,
|
|
|
xval && xval->v.s.s ? &xval->v.s
|
|
|
: &msg->first_line.u.reply.reason);
|
|
@@ -1054,6 +1071,9 @@ int pvh_get_reply_sr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
|
|
|
return pv_get_null(msg, param, res);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
int pvh_set_reply_sr(
|
|
|
struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
|
|
|
{
|
|
@@ -1110,7 +1130,7 @@ int pvh_set_reply_sr(
|
|
|
msg->first_line.u.reply.status.s[0] = code + '0';
|
|
|
break;
|
|
|
case 2: // reason
|
|
|
- if(pvh_set_xavp(msg, &xavp_name, &_hdr_reply_reason, &fval,
|
|
|
+ if(pvh_set_xavi(msg, &xavi_name, &_hdr_reply_reason, &fval,
|
|
|
SR_XTYPE_STR, 0, 0)
|
|
|
< 0) {
|
|
|
LM_ERR("set reply: cannot set reply reason\n");
|