diff --git a/src/modules/pv_headers/pv_headers.c b/src/modules/pv_headers/pv_headers.c index fdb6f2e75c3..c6196a1f5f6 100644 --- a/src/modules/pv_headers/pv_headers.c +++ b/src/modules/pv_headers/pv_headers.c @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -39,27 +39,29 @@ MODULE_VERSION #define MODULE_NAME "pv_headers" #define XAVP_NAME "headers" -uac_api_t uac; -static tm_api_t tmb; - -str xavi_name = str_init(XAVP_NAME); -str xavi_helper_xname = str_init("modparam_pv_headers"); -str xavi_parsed_xname = str_init("parsed_pv_headers"); -unsigned int header_name_size = 255; -unsigned int header_value_size = 1024; -int FL_PV_HDRS_COLLECTED = 27; -int FL_PV_HDRS_APPLIED = 28; -static str skip_headers_param = - str_init("Record-Route,Via,Route,Content-Length,Max-Forwards,CSeq"); -static str split_headers_param = STR_NULL; -static str single_headers_param = str_init(""); -static int auto_msg_param = 1; - -str _hdr_from = {"From", 4}; -str _hdr_to = {"To", 2}; -str _hdr_reply_reason = {"@Reply-Reason", 13}; -int _branch = T_BR_UNDEFINED; -int _reply_counter = -1; +uac_api_t pvh_uac; +static tm_api_t pvh_tmb; + +_pvh_params_t _pvh_params = { + .xavi_name = str_init(XAVP_NAME), + .xavi_helper_xname = str_init("modparam_pv_headers"), + .xavi_parsed_xname = str_init("parsed_pv_headers"), + .hdr_value_size = 1024, + .flags[PVH_HDRS_COLLECTED] = 27, + .flags[PVH_HDRS_APPLIED] = 28, + .skip_hdrs = str_init( + "Record-Route,Via,Route,Content-Length,Max-Forwards,CSeq"), + .split_hdrs = STR_NULL, + .single_hdrs = str_init(""), + .auto_msg = 1, +}; + +unsigned int pvh_hdr_name_size = 255; +str pvh_hdr_from = {"From", 4}; +str pvh_hdr_to = {"To", 2}; +str pvh_hdr_reply_reason = {"@Reply-Reason", 13}; +int pvh_branch = T_BR_UNDEFINED; +int pvh_reply_counter = -1; static void mod_destroy(void); static int mod_init(void); @@ -80,9 +82,9 @@ static 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]; + char parsed_br_idx[_pvh_params.hdr_value_size]; - if(msg->add_to_branch_len > header_value_size) { + if(msg->add_to_branch_len > _pvh_params.hdr_value_size) { LM_ERR("branch name is too long\n"); return -1; } @@ -106,10 +108,10 @@ static int w_pvh_collect_headers(struct sip_msg *msg, char *p1, char *p2) { sr_xavp_t **backup_xavis = NULL; - if(pvh_get_branch_index(msg, &_branch) < 0) + if(pvh_get_branch_index(msg, &pvh_branch) < 0) return -1; if(msg->first_line.type == SIP_REPLY) { - if((_reply_counter = pvh_reply_append(backup_xavis)) < 0) { + if((pvh_reply_counter = pvh_reply_append(backup_xavis)) < 0) { return -1; } } @@ -120,10 +122,10 @@ static int ki_pvh_collect_headers(struct sip_msg *msg) { sr_xavp_t **backup_xavis = NULL; - if(pvh_get_branch_index(msg, &_branch) < 0) + if(pvh_get_branch_index(msg, &pvh_branch) < 0) return -1; if(msg->first_line.type == SIP_REPLY) { - if((_reply_counter = pvh_reply_append(backup_xavis)) < 0) { + if((pvh_reply_counter = pvh_reply_append(backup_xavis)) < 0) { return -1; } } @@ -132,21 +134,21 @@ static int ki_pvh_collect_headers(struct sip_msg *msg) static int w_pvh_apply_headers(struct sip_msg *msg, char *p1, char *p2) { - if(pvh_get_branch_index(msg, &_branch) < 0) + if(pvh_get_branch_index(msg, &pvh_branch) < 0) return -1; return pvh_apply_headers(msg); } static int ki_pvh_apply_headers(struct sip_msg *msg) { - if(pvh_get_branch_index(msg, &_branch) < 0) + if(pvh_get_branch_index(msg, &pvh_branch) < 0) return -1; return pvh_apply_headers(msg); } static int w_pvh_reset_headers(struct sip_msg *msg, char *p1, char *p2) { - if(pvh_get_branch_index(msg, &_branch) < 0) + if(pvh_get_branch_index(msg, &pvh_branch) < 0) return -1; return pvh_reset_headers(msg); } @@ -228,7 +230,7 @@ static int ki_pvh_remove_header_param( int idx = 0; int new_size; str dst = STR_NULL; - sr_xavp_t *avi = pvh_xavi_get_child(msg, &xavi_name, hname); + sr_xavp_t *avi = pvh_xavi_get_child(msg, &_pvh_params.xavi_name, hname); while(avi) { next = 1; @@ -242,7 +244,8 @@ static int ki_pvh_remove_header_param( STR_FMT(hname), idx); if(pvh_remove_header(msg, hname, idx) < 0) return -1; - avi = pvh_xavi_get_child(msg, &xavi_name, hname); + avi = pvh_xavi_get_child( + msg, &_pvh_params.xavi_name, hname); if(idx > 0) idx = 0; next = 0; @@ -252,8 +255,8 @@ static int ki_pvh_remove_header_param( } else { LM_DBG("old_value:'%.*s' new_value:'%.*s'\n", STR_FMT(&avi->val.v.s), STR_FMT(&dst)); - avi = pvh_set_xavi( - msg, &xavi_name, hname, &dst, SR_XTYPE_STR, idx, 0); + avi = pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, &dst, + SR_XTYPE_STR, idx, 0); if(avi == NULL) { LM_ERR("can't set new value\n"); return -1; @@ -344,13 +347,13 @@ static pv_export_t mod_pvs[] = { }; static param_export_t params[] = { - {"xavi_name", PARAM_STR, &xavi_name}, - {"header_value_size", PARAM_INT, &header_value_size}, - {"header_collect_flag", PARAM_INT, &FL_PV_HDRS_COLLECTED}, - {"header_apply_flag", PARAM_INT, &FL_PV_HDRS_APPLIED}, - {"skip_headers", PARAM_STR, &skip_headers_param}, - {"split_headers", PARAM_STR, &split_headers_param}, - {"auto_msg", PARAM_INT, &auto_msg_param}, + {"xavi_name", PARAM_STR, &_pvh_params.xavi_name}, + {"header_value_size", PARAM_INT, &_pvh_params.hdr_value_size}, + {"header_collect_flag", PARAM_INT, &_pvh_params.flags[PVH_HDRS_COLLECTED]}, + {"header_apply_flag", PARAM_INT, &_pvh_params.flags[PVH_HDRS_APPLIED]}, + {"skip_headers", PARAM_STR, &_pvh_params.skip_hdrs}, + {"split_headers", PARAM_STR, &_pvh_params.split_hdrs}, + {"auto_msg", PARAM_INT, &_pvh_params.auto_msg}, {0, 0, 0} }; @@ -372,17 +375,17 @@ int mod_init(void) { LM_INFO("%s module init...\n", MODULE_NAME); - if(load_uac_api(&uac) < 0) { + if(load_uac_api(&pvh_uac) < 0) { LM_NOTICE("could not bind to the 'uac' module, From/To headers will " "not be modified\n"); } - if(load_tm_api(&tmb) < 0) { + if(load_tm_api(&pvh_tmb) < 0) { LM_NOTICE("could not bind to the 'tm' module, automatic headers " "collect/apply is disabled\n"); - auto_msg_param = 0; + _pvh_params.auto_msg = 0; } - if(auto_msg_param) { + if(_pvh_params.auto_msg) { if(register_script_cb(handle_msg_cb, PRE_SCRIPT_CB | REQUEST_CB, 0) < 0) { LM_ERR("cannot register PRE_SCRIPT_CB REQUEST_CB callbacks\n"); @@ -408,9 +411,9 @@ int mod_init(void) } } - pvh_str_hash_init(&skip_headers, &skip_headers_param, "skip_headers"); - pvh_str_hash_init(&split_headers, &split_headers_param, "split_headers"); - pvh_str_hash_init(&single_headers, &single_headers_param, "single_headers"); + pvh_str_hash_init(&skip_hdrs, &_pvh_params.skip_hdrs, "skip_headers"); + pvh_str_hash_init(&split_hdrs, &_pvh_params.split_hdrs, "split_headers"); + pvh_str_hash_init(&single_hdrs, &_pvh_params.single_hdrs, "single_headers"); return 0; } @@ -525,11 +528,11 @@ void handle_tm_t(tm_cell_t *t, int type, struct tmcb_params *params) LM_DBG("T:%p picked_branch:%d label:%d branches:%d\n", t, - tmb.t_get_picked_branch(), t->label, t->nr_of_outgoings); + pvh_tmb.t_get_picked_branch(), t->label, t->nr_of_outgoings); if(msg != NULL && msg != FAKED_REPLY) { - pvh_get_branch_index(msg, &_branch); - LM_DBG("T:%p set branch:%d\n", t, _branch); + pvh_get_branch_index(msg, &pvh_branch); + LM_DBG("T:%p set branch:%d\n", t, pvh_branch); pvh_apply_headers(msg); } return; @@ -542,8 +545,8 @@ int handle_msg_failed_cb(struct sip_msg *msg, unsigned int flags, void *cb) if(pvh_parse_msg(msg) != 0) return 1; - _branch = 0; - LM_DBG("msg:%p set branch:%d\n", msg, _branch); + pvh_branch = 0; + LM_DBG("msg:%p set branch:%d\n", msg, pvh_branch); return 1; } @@ -557,13 +560,13 @@ int handle_msg_cb(struct sip_msg *msg, unsigned int flags, void *cb) if(pvh_parse_msg(msg) != 0) return 1; - if(tmb.register_tmcb(msg, 0, msg_cbs, handle_tm_t, 0, 0) <= 0) { + if(pvh_tmb.register_tmcb(msg, 0, msg_cbs, handle_tm_t, 0, 0) <= 0) { LM_ERR("cannot register TM callbacks\n"); return -1; } - _branch = 0; - LM_DBG("msg:%p set branch:%d\n", msg, _branch); + pvh_branch = 0; + LM_DBG("msg:%p set branch:%d\n", msg, pvh_branch); pvh_collect_headers(msg); return 1; } @@ -571,13 +574,13 @@ int handle_msg_cb(struct sip_msg *msg, unsigned int flags, void *cb) int handle_msg_branch_cb(struct sip_msg *msg, unsigned int flags, void *cb) { - LM_DBG("msg:%p previous branch:%d\n", msg, _branch); + LM_DBG("msg:%p previous branch:%d\n", msg, pvh_branch); print_cb_flags(flags); if(flags & PRE_SCRIPT_CB) { - pvh_get_branch_index(msg, &_branch); - LM_DBG("msg:%p set branch:%d\n", msg, _branch); - pvh_clone_branch_xavi(msg, &xavi_name); + pvh_get_branch_index(msg, &pvh_branch); + LM_DBG("msg:%p set branch:%d\n", msg, pvh_branch); + pvh_clone_branch_xavi(msg, &_pvh_params.xavi_name); } return 1; @@ -595,22 +598,22 @@ int handle_msg_reply_cb(struct sip_msg *msg, unsigned int flags, void *cb) if(msg == FAKED_REPLY) { LM_DBG("FAKED_REPLY\n"); } - LM_DBG("msg:%p previous branch:%d\n", msg, _branch); + LM_DBG("msg:%p previous branch:%d\n", msg, pvh_branch); print_cb_flags(flags); - t = tmb.t_find(msg, &_branch, &vref); + t = pvh_tmb.t_find(msg, &pvh_branch, &vref); if(t != NULL && t != T_UNDEFINED) { - LM_DBG("T:%p t_check-branch:%d xavi_list:%p branches:%d\n", t, _branch, - &t->xavis_list, t->nr_of_outgoings); + LM_DBG("T:%p t_check-branch:%d xavi_list:%p branches:%d\n", t, + pvh_branch, &t->xavis_list, t->nr_of_outgoings); list = &t->xavis_list; backup_xavis = xavi_set_list(&t->xavis_list); } - pvh_get_branch_index(msg, &_branch); - LM_DBG("T:%p set branch:%d picked_branch:%d\n", t, _branch, - tmb.t_get_picked_branch()); + pvh_get_branch_index(msg, &pvh_branch); + LM_DBG("T:%p set branch:%d picked_branch:%d\n", t, pvh_branch, + pvh_tmb.t_get_picked_branch()); - if((_reply_counter = pvh_reply_append(list)) < 0) { + if((pvh_reply_counter = pvh_reply_append(list)) < 0) { return -1; } pvh_collect_headers(msg); @@ -621,7 +624,7 @@ int handle_msg_reply_cb(struct sip_msg *msg, unsigned int flags, void *cb) if(t != NULL && t != T_UNDEFINED && vref != 0) { /* t_find() above has the side effect of setting T and REFerencing T => we must unref and unset it */ - tmb.t_unset(); + pvh_tmb.t_unset(); LM_DBG("T:%p unref\n", t); } diff --git a/src/modules/pv_headers/pv_headers.h b/src/modules/pv_headers/pv_headers.h index 5ee4efc2f53..81e2b5c8d31 100644 --- a/src/modules/pv_headers/pv_headers.h +++ b/src/modules/pv_headers/pv_headers.h @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -36,22 +36,29 @@ typedef struct _xavp_c_data str value; } xavp_c_data_t; -extern uac_api_t uac; +extern uac_api_t pvh_uac; -extern str xavi_name; -extern str xavi_parsed_xname; -extern str xavi_helper_xname; - -extern unsigned int header_name_size; -extern unsigned int header_value_size; - -extern str _hdr_from; -extern str _hdr_to; -extern str _hdr_reply_reason; -extern int _branch; -extern int _reply_counter; +#define PVH_HDRS_COLLECTED 0 +#define PVH_HDRS_APPLIED 1 +typedef struct _pvh_params +{ + str xavi_name; + str xavi_helper_xname; + str xavi_parsed_xname; + unsigned int hdr_value_size; + int flags[2]; + str skip_hdrs; + str split_hdrs; + str single_hdrs; + unsigned int auto_msg; +} _pvh_params_t; +extern _pvh_params_t _pvh_params; -extern int FL_PV_HDRS_COLLECTED; -extern int FL_PV_HDRS_APPLIED; +extern unsigned int pvh_hdr_name_size; +extern str pvh_hdr_from; +extern str pvh_hdr_to; +extern str pvh_hdr_reply_reason; +extern int pvh_branch; +extern int pvh_reply_counter; #endif /* PV_HEADERS_H */ diff --git a/src/modules/pv_headers/pvh_func.c b/src/modules/pv_headers/pvh_func.c index 150cc65e5b7..f809c3c339b 100644 --- a/src/modules/pv_headers/pvh_func.c +++ b/src/modules/pv_headers/pvh_func.c @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -59,7 +59,7 @@ int pvh_collect_headers(struct sip_msg *msg) struct hdr_field *hf = NULL; str name = STR_NULL; str val = STR_NULL; - char hvals[header_name_size][header_value_size]; + char hvals[pvh_hdr_name_size][_pvh_params.hdr_value_size]; int idx = 0, d_size = 0; str val_part = STR_NULL; char *marker = NULL; @@ -80,13 +80,13 @@ int pvh_collect_headers(struct sip_msg *msg) switch(hf->type) { case HDR_FROM_T: - name.len = _hdr_from.len; - name.s = _hdr_from.s; + name.len = pvh_hdr_from.len; + name.s = pvh_hdr_from.s; LM_DBG("force [From] as key\n"); break; case HDR_TO_T: - name.len = _hdr_to.len; - name.s = _hdr_to.s; + name.len = pvh_hdr_to.len; + name.s = pvh_hdr_to.s; LM_DBG("force [To] as key\n"); break; default: @@ -97,7 +97,7 @@ int pvh_collect_headers(struct sip_msg *msg) val.s = hf->body.s; if((marker = pvh_detect_split_char(val.s)) != NULL - && str_hash_case_get(&split_headers, name.s, name.len)) { + && str_hash_case_get(&split_hdrs, name.s, name.len)) { if(pvh_split_values(&val, hvals, &d_size, 1, marker) < 0) { LM_ERR("could not parse %.*s header comma separated " @@ -109,19 +109,21 @@ int pvh_collect_headers(struct sip_msg *msg) for(idx = 0; idx < d_size; idx++) { val_part.s = hvals[idx]; val_part.len = strlen(hvals[idx]); - if(pvh_set_xavi(msg, &xavi_name, &name, &val_part, SR_XTYPE_STR, - 0, 1) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, &name, &val_part, + SR_XTYPE_STR, 0, 1) < 0) return -1; } continue; } - if(pvh_set_xavi(msg, &xavi_name, &name, &val, SR_XTYPE_STR, 0, 1) < 0) + if(pvh_set_xavi( + msg, &_pvh_params.xavi_name, &name, &val, SR_XTYPE_STR, 0, 1) + < 0) return -1; } - if(pvh_set_xavi(msg, &xavi_helper_xname, &xavi_helper_name, &xavi_name, - SR_XTYPE_STR, 0, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_helper_xname, &xavi_helper_name, + &_pvh_params.xavi_name, SR_XTYPE_STR, 0, 0) < 0) return -1; @@ -136,11 +138,11 @@ int pvh_apply_headers(struct sip_msg *msg) sr_xavp_t *sub = NULL; struct str_hash_table rm_hdrs; int from_cnt = 0, to_cnt = 0; - char t[header_name_size]; - char tv[2][header_value_size]; - str display = {tv[0], header_value_size}; - str uri = {tv[1], header_value_size}; - str br_xname = {t, header_name_size}; + char t[pvh_hdr_name_size]; + char tv[2][_pvh_params.hdr_value_size]; + str display = {tv[0], _pvh_params.hdr_value_size}; + str uri = {tv[1], _pvh_params.hdr_value_size}; + str br_xname = {t, pvh_hdr_name_size}; int skip_from_to = 0, keys_count = 0; int res = -1; @@ -156,26 +158,29 @@ int pvh_apply_headers(struct sip_msg *msg) return -1; } - pvh_get_branch_xname(msg, &xavi_name, &br_xname); + pvh_get_branch_xname(msg, &_pvh_params.xavi_name, &br_xname); if((xavi = xavi_get(&br_xname, NULL)) == NULL - && (xavi = xavi_get(&xavi_name, NULL)) == NULL) { + && (xavi = xavi_get(&_pvh_params.xavi_name, NULL)) == NULL) { LM_ERR("missing xavi %.*s, run pv_collect_headers() first\n", - xavi_name.len, xavi_name.s); + _pvh_params.xavi_name.len, _pvh_params.xavi_name.s); return -1; } if(xavi->val.type != SR_XTYPE_XAVP) { - LM_ERR("not xavp child type %.*s\n", xavi_name.len, xavi_name.s); + LM_ERR("not xavp child type %.*s\n", _pvh_params.xavi_name.len, + _pvh_params.xavi_name.s); return -1; } if((sub = xavi->val.v.xavp) == NULL) { - LM_ERR("invalid xavp structure: %.*s\n", xavi_name.len, xavi_name.s); + LM_ERR("invalid xavp structure: %.*s\n", _pvh_params.xavi_name.len, + _pvh_params.xavi_name.s); return -1; } keys_count = pvh_xavi_keys_count(&sub); if(keys_count <= 0) { - LM_ERR("no keys found: %.*s\n", xavi_name.len, xavi_name.s); + LM_ERR("no keys found: %.*s\n", _pvh_params.xavi_name.len, + _pvh_params.xavi_name.s); return -1; } if(str_hash_alloc(&rm_hdrs, keys_count) < 0) { @@ -194,7 +199,7 @@ int pvh_apply_headers(struct sip_msg *msg) if(msg->to == NULL) { LM_DBG("no To header, can't store To info in parsed\n"); } else { - if(pvh_set_parsed(msg, &_hdr_to, &msg->to->body, NULL) == NULL) + if(pvh_set_parsed(msg, &pvh_hdr_to, &msg->to->body, NULL) == NULL) LM_ERR("can't store To info in parsed\n"); } } @@ -203,7 +208,7 @@ int pvh_apply_headers(struct sip_msg *msg) if(pvh_skip_header(&sub->name)) continue; - if(cmpi_str(&sub->name, &_hdr_from) == 0) { + if(cmpi_str(&sub->name, &pvh_hdr_from) == 0) { if(skip_from_to) { LM_DBG("skip From header change in reply messages\n"); continue; @@ -215,27 +220,27 @@ int pvh_apply_headers(struct sip_msg *msg) if(from_cnt > 0) continue; - memset(display.s, 0, header_value_size); - memset(uri.s, 0, header_value_size); + memset(display.s, 0, _pvh_params.hdr_value_size); + memset(uri.s, 0, _pvh_params.hdr_value_size); if(pvh_extract_display_uri(sub->val.v.s.s, &display, &uri) < 0) { LM_ERR("error parsing From header\n"); goto err; } - if(uac.replace_from != NULL) { + if(pvh_uac.replace_from != NULL) { LM_DBG("replace_from[%s]: %s %s\n", sub->name.s, display.s, uri.s); if(display.len == 0) pvh_real_hdr_remove_display(msg, &sub->name); - uac.replace_from(msg, &display, &uri); + pvh_uac.replace_from(msg, &display, &uri); } from_cnt++; continue; } - if(cmpi_str(&sub->name, &_hdr_to) == 0) { + if(cmpi_str(&sub->name, &pvh_hdr_to) == 0) { if(skip_from_to) { LM_DBG("skip To header change in reply messages\n"); continue; @@ -247,27 +252,27 @@ int pvh_apply_headers(struct sip_msg *msg) if(to_cnt > 0) continue; - memset(display.s, 0, header_value_size); - memset(uri.s, 0, header_value_size); + memset(display.s, 0, _pvh_params.hdr_value_size); + memset(uri.s, 0, _pvh_params.hdr_value_size); if(pvh_extract_display_uri(sub->val.v.s.s, &display, &uri) < 0) { LM_ERR("error parsing To header\n"); goto err; } - if(uac.replace_to != NULL) { + if(pvh_uac.replace_to != NULL) { LM_DBG("replace_to[%s]: %s %s\n", sub->name.s, display.s, uri.s); if(display.len == 0) pvh_real_hdr_remove_display(msg, &sub->name); - uac.replace_to(msg, &display, &uri); + pvh_uac.replace_to(msg, &display, &uri); } to_cnt++; continue; } - if(cmpi_str(&sub->name, &_hdr_reply_reason) == 0) { + if(cmpi_str(&sub->name, &pvh_hdr_reply_reason) == 0) { if(str_hash_case_get(&rm_hdrs, sub->name.s, sub->name.len)) continue; pvh_real_replace_reply_reason(msg, &sub->val.v.s); @@ -299,13 +304,13 @@ int pvh_apply_headers(struct sip_msg *msg) int pvh_reset_headers(struct sip_msg *msg) { - char t[header_name_size]; - str br_xname = {t, header_name_size}; + char t[pvh_hdr_name_size]; + str br_xname = {t, pvh_hdr_name_size}; - pvh_get_branch_xname(msg, &xavi_name, &br_xname); + pvh_get_branch_xname(msg, &_pvh_params.xavi_name, &br_xname); LM_DBG("clean xavi:%.*s\n", br_xname.len, br_xname.s); xavi_rm_by_name(&br_xname, 1, NULL); - pvh_get_branch_xname(msg, &xavi_parsed_xname, &br_xname); + pvh_get_branch_xname(msg, &_pvh_params.xavi_parsed_xname, &br_xname); LM_DBG("clean xavi:%.*s\n", br_xname.len, br_xname.s); xavi_rm_by_name(&br_xname, 1, NULL); @@ -317,7 +322,7 @@ int pvh_reset_headers(struct sip_msg *msg) int pvh_check_header(struct sip_msg *msg, str *hname) { - if(pvh_xavi_get_child(msg, &xavi_name, hname) == NULL) + if(pvh_xavi_get_child(msg, &_pvh_params.xavi_name, hname) == NULL) return -1; return 1; @@ -325,14 +330,17 @@ int pvh_check_header(struct sip_msg *msg, str *hname) int pvh_append_header(struct sip_msg *msg, str *hname, str *hvalue) { - if(pvh_set_xavi(msg, &xavi_name, hname, hvalue, SR_XTYPE_STR, 0, 1) == NULL) + if(pvh_set_xavi( + msg, &_pvh_params.xavi_name, hname, hvalue, SR_XTYPE_STR, 0, 1) + == NULL) return -1; return 1; } int pvh_modify_header(struct sip_msg *msg, str *hname, str *hvalue, int indx) { - if(pvh_set_xavi(msg, &xavi_name, hname, hvalue, SR_XTYPE_STR, indx, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, hvalue, SR_XTYPE_STR, + indx, 0) == NULL) return -1; return 1; @@ -343,19 +351,20 @@ int pvh_remove_header(struct sip_msg *msg, str *hname, int indx) sr_xavp_t *avp = NULL; int count = 0; - if((avp = pvh_xavi_get_child(msg, &xavi_name, hname)) == NULL) + if((avp = pvh_xavi_get_child(msg, &_pvh_params.xavi_name, hname)) == NULL) return 1; if(indx < 0) { count = xavi_count(hname, &avp); do { - if(pvh_set_xavi( - msg, &xavi_name, hname, NULL, SR_XTYPE_STR, indx++, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, NULL, + SR_XTYPE_STR, indx++, 0) == NULL) return -1; } while(indx < count); } else { - if(pvh_set_xavi(msg, &xavi_name, hname, NULL, SR_XTYPE_STR, indx, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, NULL, SR_XTYPE_STR, + indx, 0) == NULL) return -1; } @@ -366,11 +375,11 @@ int pvh_remove_header(struct sip_msg *msg, str *hname, int indx) int pvh_header_param_exists(struct sip_msg *msg, str *hname, str *hvalue) { sr_xavp_t *avi = NULL; - char head_name[header_name_size]; - str br_xname = {head_name, header_name_size}; + char head_name[pvh_hdr_name_size]; + str br_xname = {head_name, pvh_hdr_name_size}; - avi = xavi_get(&xavi_name, NULL); - pvh_get_branch_xname(msg, &xavi_name, &br_xname); + avi = xavi_get(&_pvh_params.xavi_name, NULL); + pvh_get_branch_xname(msg, &_pvh_params.xavi_name, &br_xname); avi = xavi_get_child(&br_xname, hname); @@ -393,7 +402,7 @@ int pvh_remove_header_param_helper(str *orig, const str *toRemove, str *dst) int offset = 0; char *saveptr = NULL; char *token; - char t[header_value_size]; + char t[_pvh_params.hdr_value_size]; char *result = pv_get_buffer(); int maxSize = pv_get_buffer_size(); diff --git a/src/modules/pv_headers/pvh_func.h b/src/modules/pv_headers/pvh_func.h index 737212c3fc7..54f8b45c64d 100644 --- a/src/modules/pv_headers/pvh_func.h +++ b/src/modules/pv_headers/pvh_func.h @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. diff --git a/src/modules/pv_headers/pvh_hash.c b/src/modules/pv_headers/pvh_hash.c index 545fcd0578a..b0aea1abb5b 100644 --- a/src/modules/pv_headers/pvh_hash.c +++ b/src/modules/pv_headers/pvh_hash.c @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -27,13 +27,13 @@ #include "pvh_hash.h" #include "pvh_str.h" -struct str_hash_table skip_headers; -struct str_hash_table split_headers; -struct str_hash_table single_headers; +struct str_hash_table skip_hdrs; +struct str_hash_table split_hdrs; +struct str_hash_table single_hdrs; int pvh_str_hash_init(struct str_hash_table *ht, str *keys, char *desc) { - char split[header_name_size][header_value_size]; + char split[pvh_hdr_name_size][_pvh_params.hdr_value_size]; int idx = 0, d_size = 0; str val = STR_NULL; @@ -117,7 +117,7 @@ int pvh_skip_header(str *hname) if(hname == NULL) return 0; - if(str_hash_case_get(&skip_headers, hname->s, hname->len)) + if(str_hash_case_get(&skip_hdrs, hname->s, hname->len)) return 1; return 0; @@ -128,7 +128,7 @@ int pvh_single_header(str *hname) if(hname == NULL) return 0; - if(str_hash_case_get(&single_headers, hname->s, hname->len)) + if(str_hash_case_get(&single_hdrs, hname->s, hname->len)) return 1; return 0; diff --git a/src/modules/pv_headers/pvh_hash.h b/src/modules/pv_headers/pvh_hash.h index d7e25f8b5df..b458e9f0bdf 100644 --- a/src/modules/pv_headers/pvh_hash.h +++ b/src/modules/pv_headers/pvh_hash.h @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -28,9 +28,9 @@ #include "../../core/str_hash.h" -extern struct str_hash_table skip_headers; -extern struct str_hash_table split_headers; -extern struct str_hash_table single_headers; +extern struct str_hash_table skip_hdrs; +extern struct str_hash_table split_hdrs; +extern struct str_hash_table single_hdrs; int pvh_str_hash_init(struct str_hash_table *ht, str *keys, char *desc); int pvh_str_hash_add_key(struct str_hash_table *ht, str *key); diff --git a/src/modules/pv_headers/pvh_hdr.c b/src/modules/pv_headers/pvh_hdr.c index fbb471ccd59..472b10e6b46 100644 --- a/src/modules/pv_headers/pvh_hdr.c +++ b/src/modules/pv_headers/pvh_hdr.c @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -31,11 +31,11 @@ int pvh_hdrs_collected(struct sip_msg *msg) { if(msg->first_line.type == SIP_REPLY) { - if(isflagset(msg, FL_PV_HDRS_COLLECTED) == 1) { + if(isflagset(msg, _pvh_params.flags[PVH_HDRS_COLLECTED]) == 1) { return 1; } } else { - if(isbflagset(_branch, FL_PV_HDRS_COLLECTED) == 1) { + if(isbflagset(pvh_branch, _pvh_params.flags[PVH_HDRS_COLLECTED]) == 1) { return 1; } } @@ -45,11 +45,11 @@ int pvh_hdrs_collected(struct sip_msg *msg) int pvh_hdrs_applied(struct sip_msg *msg) { if(msg->first_line.type == SIP_REPLY) { - if(isflagset(msg, FL_PV_HDRS_APPLIED) == 1) { + if(isflagset(msg, _pvh_params.flags[PVH_HDRS_APPLIED]) == 1) { return 1; } } else { - if(isbflagset(_branch, FL_PV_HDRS_APPLIED) == 1) { + if(isbflagset(pvh_branch, _pvh_params.flags[PVH_HDRS_APPLIED]) == 1) { return 1; } } @@ -59,29 +59,29 @@ int pvh_hdrs_applied(struct sip_msg *msg) void pvh_hdrs_set_applied(struct sip_msg *msg) { if(msg->first_line.type == SIP_REPLY) { - setflag(msg, FL_PV_HDRS_APPLIED); + setflag(msg, _pvh_params.flags[PVH_HDRS_APPLIED]); } else { - setbflag(_branch, FL_PV_HDRS_APPLIED); + setbflag(pvh_branch, _pvh_params.flags[PVH_HDRS_APPLIED]); } } void pvh_hdrs_set_collected(struct sip_msg *msg) { if(msg->first_line.type == SIP_REPLY) { - setflag(msg, FL_PV_HDRS_COLLECTED); + setflag(msg, _pvh_params.flags[PVH_HDRS_COLLECTED]); } else { - setbflag(_branch, FL_PV_HDRS_COLLECTED); + setbflag(pvh_branch, _pvh_params.flags[PVH_HDRS_COLLECTED]); } } void pvh_hdrs_reset_flags(struct sip_msg *msg) { if(msg->first_line.type == SIP_REPLY) { - resetflag(msg, FL_PV_HDRS_COLLECTED); - resetflag(msg, FL_PV_HDRS_APPLIED); + resetflag(msg, _pvh_params.flags[PVH_HDRS_COLLECTED]); + resetflag(msg, _pvh_params.flags[PVH_HDRS_APPLIED]); } else { - resetbflag(_branch, FL_PV_HDRS_COLLECTED); - resetbflag(_branch, FL_PV_HDRS_APPLIED); + resetbflag(pvh_branch, _pvh_params.flags[PVH_HDRS_COLLECTED]); + resetbflag(pvh_branch, _pvh_params.flags[PVH_HDRS_APPLIED]); } } diff --git a/src/modules/pv_headers/pvh_hdr.h b/src/modules/pv_headers/pvh_hdr.h index a5ad4157f9d..289ae9a2a76 100644 --- a/src/modules/pv_headers/pvh_hdr.h +++ b/src/modules/pv_headers/pvh_hdr.h @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -43,4 +43,4 @@ int pvh_real_hdr_remove_display(struct sip_msg *msg, str *hname); int pvh_real_replace_reply_reason(struct sip_msg *msg, str *value); int pvh_create_hdr_str(str *hname, str *hvalue, str *dst); -#endif /* PV_HDR_H */ \ No newline at end of file +#endif /* PV_HDR_H */ diff --git a/src/modules/pv_headers/pvh_str.c b/src/modules/pv_headers/pvh_str.c index 60c1a2fe455..9b7cf013061 100644 --- a/src/modules/pv_headers/pvh_str.c +++ b/src/modules/pv_headers/pvh_str.c @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -132,7 +132,7 @@ char *pvh_detect_split_char(char *val) return pvh_detect_split_char(val + (quote_b - val + 1)); } -int pvh_split_values(str *s, char d[][header_value_size], int *d_size, +int pvh_split_values(str *s, char d[][_pvh_params.hdr_value_size], int *d_size, int keep_spaces, char *marker) { char *p = NULL; @@ -157,7 +157,7 @@ int pvh_split_values(str *s, char d[][header_value_size], int *d_size, } if(c_idx == 0) continue; - if(c_idx + 1 < header_value_size) + if(c_idx + 1 < _pvh_params.hdr_value_size) c_idx++; d[*d_size][c_idx] = '\0'; c_idx = 0; @@ -169,7 +169,7 @@ int pvh_split_values(str *s, char d[][header_value_size], int *d_size, } if(c_idx > 0) { - if(c_idx >= header_value_size) + if(c_idx >= _pvh_params.hdr_value_size) c_idx--; d[*d_size][c_idx] = '\0'; } @@ -177,4 +177,4 @@ int pvh_split_values(str *s, char d[][header_value_size], int *d_size, (*d_size)++; return 1; -} \ No newline at end of file +} diff --git a/src/modules/pv_headers/pvh_str.h b/src/modules/pv_headers/pvh_str.h index 24feb330c3c..8ca80394b3e 100644 --- a/src/modules/pv_headers/pvh_str.h +++ b/src/modules/pv_headers/pvh_str.h @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -35,7 +35,7 @@ int pvh_str_free(str *s); int pvh_str_copy(str *dst, str *src, unsigned int max_size); int pvh_extract_display_uri(char *suri, str *display, str *duri); char *pvh_detect_split_char(char *s); -int pvh_split_values(str *s, char d[][header_value_size], int *d_size, +int pvh_split_values(str *s, char d[][_pvh_params.hdr_value_size], int *d_size, int keep_spaces, char *marker); -#endif /* PV_STR_H */ \ No newline at end of file +#endif /* PV_STR_H */ diff --git a/src/modules/pv_headers/pvh_xavp.c b/src/modules/pv_headers/pvh_xavp.c index 203c8b8be2a..f3675881e81 100644 --- a/src/modules/pv_headers/pvh_xavp.c +++ b/src/modules/pv_headers/pvh_xavp.c @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server. @@ -62,8 +62,8 @@ int pvh_reply_append(sr_xavp_t **start) sr_xavp_t *xavi = NULL; sr_xval_t xval; - xavi = pvh_xavi_get_child_with_ival( - &xavi_helper_xname, &reply_counter, start ? *start : NULL); + xavi = pvh_xavi_get_child_with_ival(&_pvh_params.xavi_helper_xname, + &reply_counter, start ? *start : NULL); if(xavi) { xavi->val.v.l++; LM_DBG("reply message: %ld\n", xavi->val.v.l); @@ -74,17 +74,18 @@ int pvh_reply_append(sr_xavp_t **start) xval.type = SR_XTYPE_LONG; xval.v.l = 0; - xavi = xavi_get(&xavi_helper_xname, start ? *start : NULL); + xavi = xavi_get(&_pvh_params.xavi_helper_xname, start ? *start : NULL); if(xavi == NULL) { - if(xavi_add_xavi_value(&xavi_helper_xname, &reply_counter, &xval, - start ? start : NULL) + if(xavi_add_xavi_value(&_pvh_params.xavi_helper_xname, &reply_counter, + &xval, start ? start : NULL) == NULL) { - LM_ERR("can't create xavi:%.*s\n", xavi_helper_xname.len, - xavi_helper_xname.s); + LM_ERR("can't create xavi:%.*s\n", + _pvh_params.xavi_helper_xname.len, + _pvh_params.xavi_helper_xname.s); return -1; } - LM_DBG("xavi_name:%.*s created\n", xavi_helper_xname.len, - xavi_helper_xname.s); + LM_DBG("xavi_name:%.*s created\n", _pvh_params.xavi_helper_xname.len, + _pvh_params.xavi_helper_xname.s); } else { if(xavi_add_value(&reply_counter, &xval, &xavi->val.v.xavp) == NULL) { LM_ERR("can't add reply_counter value\n"); @@ -180,8 +181,8 @@ static sr_xavp_t *pvh_xavi_set_value( static sr_xavp_t *pvh_get_xavi(struct sip_msg *msg, str *xname) { sr_xavp_t *xavi = NULL; - char t[header_name_size]; - str br_xname = {t, header_name_size}; + char t[pvh_hdr_name_size]; + str br_xname = {t, pvh_hdr_name_size}; pvh_get_branch_xname(msg, xname, &br_xname); if((xavi = xavi_get(&br_xname, NULL)) == NULL) { @@ -228,7 +229,7 @@ int pvh_parse_header_name(pv_spec_p sp, str *hname) return -1; } - if(hname->len >= header_name_size) { + if(hname->len >= pvh_hdr_name_size) { LM_ERR("header name is too long\n"); return -1; } @@ -280,8 +281,8 @@ static sr_xval_t *pvh_xavi_get_value( sr_xavp_t *pvh_xavi_get_child(struct sip_msg *msg, str *xname, str *name) { sr_xavp_t *xavi = NULL; - char t[header_name_size]; - str br_xname = {t, header_name_size}; + char t[pvh_hdr_name_size]; + str br_xname = {t, pvh_hdr_name_size}; pvh_get_branch_xname(msg, xname, &br_xname); xavi = xavi_get_child(&br_xname, name); @@ -362,8 +363,8 @@ sr_xavp_t *pvh_set_xavi(struct sip_msg *msg, str *xname, str *name, void *data, sr_xavp_t *result = NULL; sr_xval_t root_xval; sr_xval_t xval; - char t[header_name_size]; - str br_xname = {t, header_name_size}; + char t[pvh_hdr_name_size]; + str br_xname = {t, pvh_hdr_name_size}; if(xname == NULL || name == NULL) { LM_ERR("missing xavi/pv name\n"); @@ -393,7 +394,7 @@ sr_xavp_t *pvh_set_xavi(struct sip_msg *msg, str *xname, str *name, void *data, root = xavi_get(&br_xname, NULL); - if(root == NULL && _branch > 0) { + if(root == NULL && pvh_branch > 0) { pvh_clone_branch_xavi(msg, xname); root = xavi_get(&br_xname, NULL); } @@ -447,8 +448,8 @@ int pvh_get_branch_xname(struct sip_msg *msg, str *xname, str *dst) memcpy(dst->s, xname->s, xname->len); os += xname->len; - if(_branch > 0) { - snprintf(br_idx_s, 32, "%d", _branch - 1); + if(pvh_branch > 0) { + snprintf(br_idx_s, 32, "%d", pvh_branch - 1); br_idx_len = strlen(br_idx_s); memcpy(dst->s + os, ".", 1); os += 1; @@ -456,7 +457,7 @@ int pvh_get_branch_xname(struct sip_msg *msg, str *xname, str *dst) os += br_idx_len; } if(msg->first_line.type == SIP_REPLY) { - snprintf(br_idx_s, 32, ".r.%d", _reply_counter); + snprintf(br_idx_s, 32, ".r.%d", pvh_reply_counter); br_idx_len = strlen(br_idx_s); memcpy(dst->s + os, br_idx_s, br_idx_len); os += br_idx_len; @@ -476,8 +477,8 @@ int pvh_clone_branch_xavi(struct sip_msg *msg, str *xname) 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}; + char t[pvh_hdr_name_size]; + str br_xname = {t, pvh_hdr_name_size}; int i = 0; if((xavi = xavi_get(xname, NULL)) == NULL) { @@ -487,12 +488,14 @@ int pvh_clone_branch_xavi(struct sip_msg *msg, str *xname) } if(xavi->val.type != SR_XTYPE_XAVP) { - LM_ERR("not xavp child type %.*s\n", xavi_name.len, xavi_name.s); + LM_ERR("not xavp child type %.*s\n", _pvh_params.xavi_name.len, + _pvh_params.xavi_name.s); return -1; } if((sub = xavi->val.v.xavp) == NULL) { - LM_ERR("invalid xavi structure: %.*s\n", xavi_name.len, xavi_name.s); + LM_ERR("invalid xavi structure: %.*s\n", _pvh_params.xavi_name.len, + _pvh_params.xavi_name.s); return -1; } @@ -507,7 +510,7 @@ int pvh_clone_branch_xavi(struct sip_msg *msg, str *xname) return -1; } - if(cmp_str(xname, &xavi_parsed_xname) == 0) { + if(cmp_str(xname, &_pvh_params.xavi_parsed_xname) == 0) { return 1; } @@ -551,7 +554,8 @@ int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) } if(idx < 0) { - if((xavi = pvh_xavi_get_child(msg, &xavi_name, hname)) == NULL) + if((xavi = pvh_xavi_get_child(msg, &_pvh_params.xavi_name, hname)) + == NULL) cnt = 0; else cnt = xavi_count(hname, &xavi); @@ -560,7 +564,7 @@ int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) return pv_get_null(msg, param, res); } - xval = pvh_xavi_get_value(msg, &xavi_name, hname, idx); + xval = pvh_xavi_get_value(msg, &_pvh_params.xavi_name, hname, idx); if(xval == NULL || !xval->v.s.s) return pv_get_null(msg, param, res); @@ -593,8 +597,9 @@ int pvh_set_header( return -1; } - if((xavi = pvh_get_xavi(msg, &xavi_name)) == NULL) { - LM_ERR("xavi %.*s not found\n", xavi_name.len, xavi_name.s); + if((xavi = pvh_get_xavi(msg, &_pvh_params.xavi_name)) == NULL) { + LM_ERR("xavi %.*s not found\n", _pvh_params.xavi_name.len, + _pvh_params.xavi_name.s); return -1; } avi = xavi->val.v.xavp; @@ -618,11 +623,13 @@ int pvh_set_header( 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) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, NULL, + SR_XTYPE_NULL, 0, 0) == NULL) goto err; } else { - if(pvh_set_xavi(msg, &xavi_name, hname, NULL, SR_XTYPE_NULL, idx, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, NULL, + SR_XTYPE_NULL, idx, 0) == NULL) goto err; } @@ -641,7 +648,8 @@ int pvh_set_header( goto err; } if(idx == 0 && idxf == PV_IDX_NONE) { - if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, 0, 1) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, &fval, + SR_XTYPE_STR, 0, 1) == NULL) goto err; } else if(idxf == PV_IDX_ALL) { @@ -650,12 +658,13 @@ int pvh_set_header( LM_DBG("removed %d values of %.*s=>%.*s\n", cnt, xavi->name.len, xavi->name.s, hname->len, hname->s); } - if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, 0, - hname_cnt ? 0 : 1) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, &fval, + SR_XTYPE_STR, 0, hname_cnt ? 0 : 1) == NULL) goto err; } else { - if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, idx, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, hname, &fval, + SR_XTYPE_STR, idx, 0) == NULL) goto err; } @@ -693,7 +702,8 @@ 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_xavi(msg, &xavi_parsed_xname, hname, c_data, SR_XTYPE_DATA, 0, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_parsed_xname, hname, c_data, + SR_XTYPE_DATA, 0, 0) == NULL) goto err; LM_DBG("c_data from pvh_merge_uri hname:%.*s\n", hname->len, hname->s); @@ -717,23 +727,24 @@ int pvh_get_uri(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) str sval = STR_NULL; int ival = 0; int is_strint = 0; - char t[header_name_size]; - str hname = {t, header_name_size - 1}; + char t[pvh_hdr_name_size]; + str hname = {t, pvh_hdr_name_size - 1}; p_no = param->pvn.u.isname.name.n; if(p_no >= 1 && p_no <= 5) - pvh_str_copy(&hname, &_hdr_from, header_name_size); + pvh_str_copy(&hname, &pvh_hdr_from, pvh_hdr_name_size); else if(p_no >= 6 && p_no <= 10) - pvh_str_copy(&hname, &_hdr_to, header_name_size); + pvh_str_copy(&hname, &pvh_hdr_to, pvh_hdr_name_size); - xval = pvh_xavi_get_value(msg, &xavi_name, &hname, 0); + xval = pvh_xavi_get_value(msg, &_pvh_params.xavi_name, &hname, 0); if(xval == NULL || !xval->v.s.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_xavi_get_value(msg, &xavi_parsed_xname, &hname, 0); + xval_pd = + pvh_xavi_get_value(msg, &_pvh_params.xavi_parsed_xname, &hname, 0); if(xval_pd) { /* LM_DBG("p_no:%d c_data from xavi_parsed_xname hname:%.*s\n", p_no, @@ -795,15 +806,15 @@ int pvh_set_uri(struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val) pv_elem_p pv_format = NULL; int p_no = 0; enum action_type a_type; - char t[header_name_size]; - str hname = {t, header_name_size - 1}; + char t[pvh_hdr_name_size]; + str hname = {t, pvh_hdr_name_size - 1}; str fval; p_no = param->pvn.u.isname.name.n; if(p_no >= 1 && p_no <= 5) - pvh_str_copy(&hname, &_hdr_from, header_name_size); + pvh_str_copy(&hname, &pvh_hdr_from, pvh_hdr_name_size); else if(p_no >= 6 && p_no <= 10) - pvh_str_copy(&hname, &_hdr_to, header_name_size); + pvh_str_copy(&hname, &pvh_hdr_to, pvh_hdr_name_size); switch(p_no) { case 1: // uri from @@ -842,7 +853,7 @@ int pvh_set_uri(struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val) goto err; } - xval = pvh_xavi_get_value(msg, &xavi_name, &hname, 0); + xval = pvh_xavi_get_value(msg, &_pvh_params.xavi_name, &hname, 0); if(xval == NULL || !xval->v.s.s) goto err; @@ -854,14 +865,15 @@ 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("xavi:%.*s hname:%.*s value:%.*s\n", xavi_name.len, xavi_name.s, + /* LM_DBG("xavi:%.*s hname:%.*s value:%.*s\n", _pvh_params.xavi_name.len, _pvh_params.xavi_name.s, hname.len, hname.s, c_data->value.len, c_data->value.s); */ - if(pvh_set_xavi(msg, &xavi_name, &hname, &c_data->value, SR_XTYPE_STR, 0, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, &hname, &c_data->value, + SR_XTYPE_STR, 0, 0) == NULL) goto err; - if(pvh_set_xavi( - msg, &xavi_parsed_xname, &hname, c_data, SR_XTYPE_DATA, 0, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_parsed_xname, &hname, c_data, + SR_XTYPE_DATA, 0, 0) == NULL) goto err; @@ -904,7 +916,7 @@ int pvh_merge_uri(struct sip_msg *msg, enum action_type type, str *cur, } puri = tb.parsed_uri; - c_data->value.s = (char *)shm_malloc(header_value_size); + c_data->value.s = (char *)shm_malloc(_pvh_params.hdr_value_size); if(c_data->value.s == NULL) { SHM_MEM_ERROR; goto err; @@ -912,7 +924,7 @@ int pvh_merge_uri(struct sip_msg *msg, enum action_type type, str *cur, merged = &c_data->value; if(type == SET_URI_T && strchr(new->s, '<')) { - pvh_str_copy(merged, new, header_value_size); + pvh_str_copy(merged, new, _pvh_params.hdr_value_size); goto reparse; } @@ -1054,7 +1066,8 @@ 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_xavi_get_value(msg, &xavi_name, &_hdr_reply_reason, 0); + xval = pvh_xavi_get_value( + msg, &_pvh_params.xavi_name, &pvh_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); @@ -1125,8 +1138,8 @@ int pvh_set_reply_sr( msg->first_line.u.reply.status.s[0] = code + '0'; break; case 2: // reason - if(pvh_set_xavi(msg, &xavi_name, &_hdr_reply_reason, &fval, - SR_XTYPE_STR, 0, 0) + if(pvh_set_xavi(msg, &_pvh_params.xavi_name, &pvh_hdr_reply_reason, + &fval, SR_XTYPE_STR, 0, 0) == NULL) { LM_ERR("set reply: cannot set reply reason\n"); goto err; diff --git a/src/modules/pv_headers/pvh_xavp.h b/src/modules/pv_headers/pvh_xavp.h index 4acceacdd64..b2e201d8724 100644 --- a/src/modules/pv_headers/pvh_xavp.h +++ b/src/modules/pv_headers/pvh_xavp.h @@ -2,7 +2,7 @@ * pv_headers * * Copyright (C) - * 2020 Victor Seva + * 2020-2023 Victor Seva * 2018 Kirill Solomko * * This file is part of Kamailio, a free SIP server.