From a1e74ef76c7c08665ae834f5569a8ea6d1ac02aa Mon Sep 17 00:00:00 2001 From: Razvan Crainea Date: Fri, 4 Feb 2022 18:32:37 +0200 Subject: [PATCH] b2b_entities: add support for custom params in callbacks --- modules/b2b_entities/b2b_common.h | 2 - modules/b2b_entities/b2b_entities.c | 57 +++++---- modules/b2b_entities/b2be_clustering.c | 16 +-- modules/b2b_entities/b2be_db.c | 14 +-- modules/b2b_entities/b2be_load.h | 20 ++-- modules/b2b_entities/client.c | 37 +++--- modules/b2b_entities/client.h | 2 +- modules/b2b_entities/dlg.c | 110 +++++++++++------- modules/b2b_entities/dlg.h | 4 +- .../b2b_entities/doc/b2b_entities_devel.xml | 9 +- modules/b2b_entities/server.c | 17 +-- modules/b2b_entities/server.h | 2 +- modules/b2b_logic/b2b_logic.h | 10 +- modules/b2b_logic/b2bl_db.c | 2 +- modules/b2b_logic/entity_storage.c | 2 +- modules/b2b_logic/logic.c | 88 +++++++------- modules/b2b_logic_xml/b2b_load.h | 4 +- modules/b2b_logic_xml/b2b_logic.c | 2 +- modules/b2b_logic_xml/b2b_logic.h | 10 +- modules/b2b_logic_xml/b2bl_db.c | 2 +- modules/b2b_logic_xml/entity_storage.c | 2 +- modules/b2b_logic_xml/logic.c | 84 ++++++------- modules/b2b_sca/sca_db_handler.c | 12 +- modules/b2b_sca/sca_records.c | 16 +-- modules/media_exchange/media_exchange.c | 45 +++---- modules/siprec/siprec_logic.c | 25 ++-- 26 files changed, 299 insertions(+), 295 deletions(-) diff --git a/modules/b2b_entities/b2b_common.h b/modules/b2b_entities/b2b_common.h index 768b6192b01..07b389aa1cb 100644 --- a/modules/b2b_entities/b2b_common.h +++ b/modules/b2b_entities/b2b_common.h @@ -27,8 +27,6 @@ #ifndef _B2B_COMMON_H_ #define _B2B_COMMON_H_ -#define B2BL_MAX_KEY_LEN 21 - struct b2b_context { str b2bl_key; void *data; diff --git a/modules/b2b_entities/b2b_entities.c b/modules/b2b_entities/b2b_entities.c index 375f7fc3833..7881789d2d3 100644 --- a/modules/b2b_entities/b2b_entities.c +++ b/modules/b2b_entities/b2b_entities.c @@ -478,7 +478,7 @@ static void mod_destroy(void) } int b2b_restore_logic_info(enum b2b_entity_type type, str* key, - b2b_notify_t cback) + b2b_notify_t cback, void *param, b2b_param_free_cb free_param) { b2b_dlg_t* dlg; b2b_table table; @@ -510,26 +510,22 @@ int b2b_restore_logic_info(enum b2b_entity_type type, str* key, return -1; } dlg->b2b_cback = cback; + dlg->param = param; + dlg->free_param = free_param; return 0; } int b2b_update_b2bl_param(enum b2b_entity_type type, str* key, - str* param, int replicate) + str* logic_key, int replicate) { b2b_dlg_t* dlg; b2b_table table; unsigned int hash_index, local_index; int unlock = 1; - if(!param) + if(!logic_key) { - LM_ERR("NULL param\n"); - return -1; - } - if(param->len > B2BL_MAX_KEY_LEN) - { - LM_ERR("parameter too long, received [%d], maximum [%d]\n", - param->len, B2BL_MAX_KEY_LEN); + LM_ERR("NULL logic_key\n"); return -1; } @@ -559,39 +555,35 @@ int b2b_update_b2bl_param(enum b2b_entity_type type, str* key, lock_release(&table[hash_index].lock); return -1; } - memcpy(dlg->param.s, param->s, param->len); - dlg->param.len = param->len; + memcpy(dlg->logic_key.s, logic_key->s, logic_key->len); + dlg->logic_key.len = logic_key->len; if (unlock) lock_release(&table[hash_index].lock); if (b2be_cluster && replicate) - replicate_entity_update(dlg, type, hash_index, param, -1, NULL); + replicate_entity_update(dlg, type, hash_index, logic_key, -1, NULL); return 0; } -int b2b_get_b2bl_key(str* callid, str* from_tag, str* to_tag, str* entity_key, str* tuple_key) +str *b2b_get_b2bl_key(str* callid, str* from_tag, str* to_tag, str* entity_key) { b2b_dlg_t* dlg; unsigned int hash_index, local_index; b2b_table table; - int ret; + str *tuple_key = NULL; if(!callid || !callid->s || !callid->len){ LM_ERR("Wrong callid param\n"); - return -1; + return NULL; } if(!from_tag || !from_tag->s || !from_tag->len){ LM_ERR("Wrong from_tag param\n"); - return -1; + return NULL; } if(!to_tag){ LM_ERR("Wrong to_tag param\n"); - return -1; - } - if(!tuple_key || !tuple_key->s || tuple_key->len meaning that it is a server request */ @@ -600,13 +592,19 @@ int b2b_get_b2bl_key(str* callid, str* from_tag, str* to_tag, str* entity_key, s else if (b2b_parse_key(callid, &hash_index, &local_index, NULL)>=0) table = client_htable; else - return -1; /* to tag and/or callid are not part of this B2B */ + return NULL; /* to tag and/or callid are not part of this B2B */ lock_get(&table[hash_index].lock); dlg=b2b_search_htable_dlg(table, hash_index, local_index, to_tag, from_tag, callid); if(dlg){ - memcpy(tuple_key->s, dlg->param.s, dlg->param.len); - tuple_key->len = dlg->param.len; + tuple_key = pkg_malloc(sizeof(str) + dlg->logic_key.len); + if (!tuple_key) { + LM_ERR("cannot duplicate logic\n"); + return NULL; + } + tuple_key->s = (char *)(tuple_key + 1); + memcpy(tuple_key->s, dlg->logic_key.s, dlg->logic_key.len); + tuple_key->len = dlg->logic_key.len; if (entity_key) { if (table == server_htable) { entity_key->s = to_tag->s; @@ -620,12 +618,9 @@ int b2b_get_b2bl_key(str* callid, str* from_tag, str* to_tag, str* entity_key, s tuple_key->len, tuple_key->s, (entity_key?entity_key->len:0), (entity_key?entity_key->s:NULL)); - ret = 0; - } else { - ret = -1; } lock_release(&table[hash_index].lock); - return ret; + return tuple_key; } void *b2b_get_context(void) @@ -700,10 +695,10 @@ static inline int mi_print_b2be_dlg(mi_item_t *resp_arr, b2b_table htable, unsig if (add_mi_number(arr_item, MI_SSTR("dlg"), dlg->id) < 0) goto error; /* check if param is printable */ - param = dlg->param; + param = dlg->logic_key; if (!str_check_token(¶m)) init_str(¶m, ""); - if (add_mi_string(arr_item, MI_SSTR("param"), + if (add_mi_string(arr_item, MI_SSTR("logic_key"), param.s, param.len) < 0) goto error; if (add_mi_string(arr_item, MI_SSTR("mod_name"), diff --git a/modules/b2b_entities/b2be_clustering.c b/modules/b2b_entities/b2be_clustering.c index e93383deeeb..23634f4410a 100644 --- a/modules/b2b_entities/b2be_clustering.c +++ b/modules/b2b_entities/b2be_clustering.c @@ -97,7 +97,7 @@ void bin_pack_entity(bin_packet_t *packet, b2b_dlg_t *dlg, int etype) bin_push_str(packet, &dlg->route_set[1]); bin_push_str(packet, dlg->send_sock ? get_socket_internal_name(dlg->send_sock) : NULL); - bin_push_str(packet, &dlg->param); + bin_push_str(packet, &dlg->logic_key); bin_push_str(packet, &dlg->mod_name); bin_push_int(packet, dlg->state); @@ -428,7 +428,7 @@ int receive_entity_create(bin_packet_t *packet, b2b_dlg_t *dlg, int type, return -1; } - bin_pop_str(packet, &dlg->param); + bin_pop_str(packet, &dlg->logic_key); bin_pop_str(packet, &dlg->mod_name); bin_pop_int(packet, &dlg->state); @@ -497,17 +497,13 @@ int receive_entity_create(bin_packet_t *packet, b2b_dlg_t *dlg, int type, static inline int recv_b2bl_param_update(bin_packet_t *packet, b2b_dlg_t *dlg) { - str param; + str logic_key; - bin_pop_str(packet, ¶m); - - if (param.len > B2BL_MAX_KEY_LEN) { - LM_ERR("b2bl parameter too long, received [%d], maximum [%d]\n", - param.len, B2BL_MAX_KEY_LEN); + bin_pop_str(packet, &logic_key); + if (shm_str_sync(&dlg->logic_key, &logic_key) < 0) { + LM_ERR("cannot duplicate logic key!\n"); return -1; } - memcpy(dlg->param.s, param.s, param.len); - dlg->param.len = param.len; return 0; } diff --git a/modules/b2b_entities/b2be_db.c b/modules/b2b_entities/b2be_db.c index 85ea6ffcc6c..234fe638dbb 100644 --- a/modules/b2b_entities/b2be_db.c +++ b/modules/b2b_entities/b2be_db.c @@ -258,11 +258,11 @@ int b2be_db_insert(b2b_dlg_t* dlg, int type) qvals[11].val.str_val.s = 0; qvals[11].val.str_val.len = 0; } - if (!str_check_token(&dlg->param)) { + if (!str_check_token(&dlg->logic_key)) { qvals[12].val.str_val.s = NULL; qvals[12].val.str_val.len = 0; } else { - qvals[12].val.str_val = dlg->param; + qvals[12].val.str_val = dlg->logic_key; } qvals[13].val.str_val= dlg->mod_name; @@ -327,10 +327,10 @@ static void b2b_entity_cdb_delete(int type, b2b_dlg_t* dlg) return; } - if (!str_check_token(&dlg->param)) { + if (!str_check_token(&dlg->logic_key)) { cdb_subkey = NULL; } else { - cdb_subkey = get_b2be_map_subkey(&dlg->param); + cdb_subkey = get_b2be_map_subkey(&dlg->logic_key); if (!cdb_subkey) { LM_ERR("Failed to build map key\n"); return; @@ -503,11 +503,11 @@ void store_b2b_dlg(b2b_table htable, unsigned int hsize, int type, int no_lock) qvals[11].val.str_val.s = 0; qvals[11].val.str_val.len = 0; } - if (!str_check_token(&dlg->param)) { + if (!str_check_token(&dlg->logic_key)) { qvals[12].val.str_val.s = NULL; qvals[12].val.str_val.len = 0; } else { - qvals[12].val.str_val = dlg->param; + qvals[12].val.str_val = dlg->logic_key; } qvals[13].val.str_val= dlg->mod_name; } @@ -662,7 +662,7 @@ static int load_entity(int_str_t *vals) dlg.last_method = vals[18].i; dlg.last_reply_code = vals[19].i; dlg.last_invite_cseq = vals[20].i; - dlg.param = vals[12].s; + dlg.logic_key = vals[12].s; dlg.mod_name = vals[13].s; sockinfo_str = vals[11].s; if(sockinfo_str.s) diff --git a/modules/b2b_entities/b2be_load.h b/modules/b2b_entities/b2be_load.h index c5700079de7..b949bd4fd03 100644 --- a/modules/b2b_entities/b2be_load.h +++ b/modules/b2b_entities/b2be_load.h @@ -120,17 +120,19 @@ typedef void (*b2b_cb_t)(enum b2b_entity_type entity_type, str* entity_key, str *param, enum b2b_event_type event_type, bin_packet_t *storage, int backend); -typedef int (*b2b_notify_t)(struct sip_msg* msg, str* key, int type, void* param, - int flags); +typedef int (*b2b_notify_t)(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags); typedef int (*b2b_add_dlginfo_t)(str* key, str* entity_key, int src, - b2b_dlginfo_t* info); + b2b_dlginfo_t* info, void *); +typedef void (*b2b_param_free_cb)(void *param); typedef str* (*b2b_server_new_t) (struct sip_msg* , str* local_contact, - b2b_notify_t , str *mod_name, str* param, struct b2b_tracer *tracer); + b2b_notify_t , str *mod_name, str* logic_key, struct b2b_tracer *tracer, + void *param, b2b_param_free_cb free_param); typedef str* (*b2b_client_new_t) (client_info_t* , b2b_notify_t b2b_cback, - b2b_add_dlginfo_t add_dlginfo_f, str *mod_name, str* param, - struct b2b_tracer *tracer); + b2b_add_dlginfo_t add_dlginfo_f, str *mod_name, str* logic_key, + struct b2b_tracer *tracer, void *param, b2b_param_free_cb free_param); typedef int (*b2b_send_request_t)(b2b_req_data_t*); typedef int (*b2b_send_reply_t)(b2b_rpl_data_t*); @@ -141,14 +143,14 @@ typedef int (*b2b_entity_exists_t)(enum b2b_entity_type et, str* b2b_key); typedef void (*b2b_db_delete_t)(str param); typedef int (*b2b_restore_linfo_t)(enum b2b_entity_type type, str* key, - b2b_notify_t cback); + b2b_notify_t cback, void *param, b2b_param_free_cb free_param); typedef int (*b2b_reg_cb_t) (b2b_cb_t cb, int cb_type, str *mod_name); typedef int (*b2b_update_b2bl_param_t)(enum b2b_entity_type type, str* key, str* param, int replicate); -typedef int (*b2b_get_b2bl_key_t)(str* callid, str* from_tag, str* to_tag, - str* entity_key, str* tuple_key); +typedef str *(*b2b_get_b2bl_key_t)(str* callid, str* from_tag, str* to_tag, + str* entity_key); typedef int (*b2b_apply_lumps_t)(struct sip_msg* msg); diff --git a/modules/b2b_entities/client.c b/modules/b2b_entities/client.c index 2df1da890d9..445111c8fc1 100644 --- a/modules/b2b_entities/client.c +++ b/modules/b2b_entities/client.c @@ -72,14 +72,17 @@ static void generate_tag(str* tag, str* src, str* callid) * from_uri: the source URI * extra_headers: the extra headers to be added in the request * b2b_cback : callback function to notify the logic about a change in dialog - * param : the parameter that will be used when calling b2b_cback function + * logic_key : the logic identifier + * tracer : structure used to instruct how the client should be traced + * param : optional, the parameter that will be used when calling b2b_cback function + * free_param: an optional function to free the parameter * * Return value: dialog key allocated in private memory * */ #define HASH_SIZE 1<<23 str* client_new(client_info_t* ci,b2b_notify_t b2b_cback, - b2b_add_dlginfo_t add_dlginfo, str *mod_name, str* param, - struct b2b_tracer *tracer) + b2b_add_dlginfo_t add_dlginfo, str *mod_name, str* logic_key, + struct b2b_tracer *tracer, void *param, b2b_param_free_cb free_param) { int result; b2b_dlg_t* dlg; @@ -92,17 +95,11 @@ str* client_new(client_info_t* ci,b2b_notify_t b2b_cback, str from_tag; str random_info = {0, 0}; - if(ci == NULL || b2b_cback == NULL || param== NULL) + if(ci == NULL || b2b_cback == NULL || logic_key == NULL) { LM_ERR("Wrong parameters.\n"); return NULL; } - if(param && param->len > B2BL_MAX_KEY_LEN) - { - LM_ERR("parameter too long, received [%d], maximum [%d]\n", - param->len, B2BL_MAX_KEY_LEN); - return 0; - } hash_index = core_hash(&ci->from_uri, &ci->to_uri, client_hsize); @@ -115,7 +112,7 @@ str* client_new(client_info_t* ci,b2b_notify_t b2b_cback, size = sizeof(b2b_dlg_t) + ci->to_uri.len + ci->from_uri.len + ci->from_dname.len + ci->to_dname.len + from_tag.len + ci->local_contact.len + B2B_MAX_KEY_SIZE + - B2BL_MAX_KEY_LEN + mod_name->len; + mod_name->len; /* create record in hash table */ dlg = (b2b_dlg_t*)shm_malloc(size); @@ -136,14 +133,13 @@ str* client_new(client_info_t* ci,b2b_notify_t b2b_cback, CONT_COPY(dlg, dlg->tag[CALLER_LEG], from_tag); CONT_COPY(dlg, dlg->contact[CALLER_LEG], ci->local_contact); - if(param && param->s) - { - dlg->param.s = (char*)dlg + size; - memcpy(dlg->param.s, param->s, param->len); - dlg->param.len = param->len; - size+= B2BL_MAX_KEY_LEN; + if(logic_key->s && shm_str_dup(&dlg->logic_key, logic_key) < 0) { + LM_ERR("not enough shm memory\n"); + goto error; } dlg->b2b_cback = b2b_cback; + dlg->param = param; + dlg->free_param = free_param; dlg->add_dlginfo = add_dlginfo; dlg->tracer = tracer; @@ -152,7 +148,6 @@ str* client_new(client_info_t* ci,b2b_notify_t b2b_cback, if(parse_method(ci->method.s, ci->method.s+ci->method.len, &dlg->last_method) == 0) { LM_ERR("wrong method %.*s\n", ci->method.len, ci->method.s); - shm_free(dlg); goto error; } dlg->state = B2B_NEW; @@ -170,7 +165,6 @@ str* client_new(client_info_t* ci,b2b_notify_t b2b_cback, if(callid == NULL) { LM_ERR("Inserting new record in hash table failed\n"); - shm_free(dlg); goto error; } @@ -257,11 +251,14 @@ str* client_new(client_info_t* ci,b2b_notify_t b2b_cback, " last method=[%d] dlg->uac_tran=[%p]\n", dlg, callid->len, callid->s, dlg->tag[CALLER_LEG].len, dlg->tag[CALLER_LEG].s, - dlg->param.len, dlg->param.s, dlg->last_method, dlg->uac_tran); + dlg->logic_key.len, dlg->logic_key.s, dlg->last_method, dlg->uac_tran); return callid; error: + if (dlg->logic_key.s) + shm_free(dlg->logic_key.s); + shm_free(dlg); if(callid) pkg_free(callid); return NULL; diff --git a/modules/b2b_entities/client.h b/modules/b2b_entities/client.h index 959341429bc..b91a2156304 100644 --- a/modules/b2b_entities/client.h +++ b/modules/b2b_entities/client.h @@ -35,7 +35,7 @@ str* client_new(client_info_t* ci, b2b_notify_t b2b_cback, b2b_add_dlginfo_t add_dlginfo, str *mod_name, str* param, - struct b2b_tracer *tracer); + struct b2b_tracer*, void *, b2b_param_free_cb); void b2b_client_tm_cback( struct cell *t, int type, struct tmcb_params *ps); diff --git a/modules/b2b_entities/dlg.c b/modules/b2b_entities/dlg.c index f10ed5e043c..a002e3cea14 100644 --- a/modules/b2b_entities/dlg.c +++ b/modules/b2b_entities/dlg.c @@ -76,9 +76,9 @@ void print_b2b_dlg(b2b_dlg_t *dlg) { dlg_leg_t *leg = dlg->legs; - LM_DBG("dlg[%p][%p][%p]: [%.*s] id=[%d] param=[%.*s] state=[%d] db_flag=[%d]\n", + LM_DBG("dlg[%p][%p][%p]: [%.*s] id=[%d] logic_key=[%.*s] state=[%d] db_flag=[%d]\n", dlg, dlg->prev, dlg->next, dlg->ruri.len, dlg->ruri.s, - dlg->id, dlg->param.len, dlg->param.s, dlg->state, dlg->db_flag); + dlg->id, dlg->logic_key.len, dlg->logic_key.s, dlg->state, dlg->db_flag); LM_DBG(" from=[%.*s] [%.*s]\n", dlg->from_dname.len, dlg->from_dname.s, dlg->from_uri.len, dlg->from_uri.s); LM_DBG(" to=[%.*s] [%.*s]\n", @@ -384,18 +384,27 @@ str* b2b_key_copy_shm(str* b2b_key) b2b_dlg_t* b2b_dlg_copy(b2b_dlg_t* dlg) { + str logic_key; b2b_dlg_t* new_dlg; int size; + if (dlg->logic_key.s && shm_str_dup(&logic_key, &dlg->logic_key) < 0) + { + LM_ERR("No more shared memory\n"); + return 0; + } + size = sizeof(b2b_dlg_t) + dlg->callid.len+ dlg->from_uri.len+ dlg->to_uri.len+ dlg->tag[0].len + dlg->tag[1].len+ dlg->route_set[0].len+ dlg->route_set[1].len+ - dlg->contact[0].len+ dlg->contact[1].len+ dlg->ruri.len+ B2BL_MAX_KEY_LEN+ + dlg->contact[0].len+ dlg->contact[1].len+ dlg->ruri.len+ dlg->from_dname.len + dlg->to_dname.len + dlg->mod_name.len; new_dlg = (b2b_dlg_t*)shm_malloc(size); if(new_dlg == 0) { LM_ERR("No more shared memory\n"); + if (dlg->logic_key.s) + shm_free(logic_key.s); return 0; } memset(new_dlg, 0, size); @@ -418,13 +427,8 @@ b2b_dlg_t* b2b_dlg_copy(b2b_dlg_t* dlg) CONT_COPY(new_dlg, new_dlg->contact[0], dlg->contact[0]); if(dlg->contact[1].len && dlg->contact[1].s) CONT_COPY(new_dlg, new_dlg->contact[1], dlg->contact[1]); - if(dlg->param.s) - { - new_dlg->param.s= (char*)new_dlg+ size; - memcpy(new_dlg->param.s, dlg->param.s, dlg->param.len); - new_dlg->param.len= dlg->param.len; - size+= B2BL_MAX_KEY_LEN; - } + if(dlg->logic_key.s) + new_dlg->logic_key = logic_key; CONT_COPY(new_dlg, new_dlg->mod_name, dlg->mod_name); @@ -438,6 +442,8 @@ b2b_dlg_t* b2b_dlg_copy(b2b_dlg_t* dlg) new_dlg->id = dlg->id; new_dlg->state = dlg->state; new_dlg->b2b_cback = dlg->b2b_cback; + new_dlg->param = dlg->param; + new_dlg->free_param = dlg->free_param; new_dlg->add_dlginfo = dlg->add_dlginfo; new_dlg->last_invite_cseq = dlg->last_invite_cseq; new_dlg->db_flag = dlg->db_flag; @@ -580,7 +586,7 @@ void b2b_run_cb(b2b_dlg_t *dlg, unsigned int hash_index, int entity_type, lock_release(&client_htable[hash_index].lock); cb->cbf(entity_type, entity_type == B2B_SERVER ? &dlg->tag[1] : &dlg->callid, - &dlg->param, event_type, storage, backend); + &dlg->logic_key, event_type, storage, backend); if (entity_type == B2B_SERVER) lock_get(&server_htable[hash_index].lock); @@ -641,7 +647,7 @@ static void run_create_cb_all(struct b2b_callback *cb, int etype) } cb->cbf(etype, etype == B2B_CLIENT ? &dlg->callid : &dlg->tag[1], - &dlg->param, B2B_EVENT_CREATE, dlg->storage.len ? &storage : NULL, + &dlg->logic_key, B2B_EVENT_CREATE, dlg->storage.len ? &storage : NULL, B2BCB_BACKEND_DB); if (dlg->storage.len) { @@ -693,7 +699,7 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam) b2b_dlg_t* dlg = 0, *aux_dlg; unsigned int hash_index, local_index; b2b_notify_t b2b_cback; - str param= {NULL,0}; + str logic_key= {NULL,0}; b2b_table table = NULL; int method_value; str from_tag; @@ -884,7 +890,7 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam) lock_release(&server_htable[hash_index].lock); return SCB_DROP_MSG; } - if (dlg->param.s && pkg_str_dup(&ctx->b2bl_key, &dlg->param) < 0) { + if (dlg->logic_key.s && pkg_str_dup(&ctx->b2bl_key, &dlg->logic_key) < 0) { LM_ERR("Failed to copy b2b_logic key to b2b context\n"); lock_release(&server_htable[hash_index].lock); return SCB_DROP_MSG; @@ -1017,7 +1023,7 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam) lock_release(&server_htable[hash_index].lock); return SCB_DROP_MSG; } - if (dlg->param.s && pkg_str_dup(&ctx->b2bl_key, &dlg->param) < 0) { + if (dlg->logic_key.s && pkg_str_dup(&ctx->b2bl_key, &dlg->logic_key) < 0) { LM_ERR("Failed to copy b2b_logic key to b2b context\n"); lock_release(&server_htable[hash_index].lock); return SCB_DROP_MSG; @@ -1154,17 +1160,17 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam) } b2b_cback = dlg->b2b_cback; - if(dlg->param.s) + if(dlg->logic_key.s) { - param.s = (char*)pkg_malloc(dlg->param.len); - if(param.s == NULL) + logic_key.s = (char*)pkg_malloc(dlg->logic_key.len); + if(logic_key.s == NULL) { LM_ERR("No more private memory\n"); lock_release(&table[hash_index].lock); return SCB_RUN_ALL; } - memcpy(param.s, dlg->param.s, dlg->param.len); - param.len = dlg->param.len; + memcpy(logic_key.s, dlg->logic_key.s, dlg->logic_key.len); + logic_key.len = dlg->logic_key.len; } set_dlg_state( dlg, method_value); @@ -1181,10 +1187,10 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam) dlg_state = dlg->state; lock_release(&table[hash_index].lock); - b2b_cback(msg, &b2b_key, B2B_REQUEST, param.s?¶m:0, b2b_cb_flags); + b2b_cback(msg, &b2b_key, B2B_REQUEST, logic_key.s?&logic_key:0, dlg->param, b2b_cb_flags); - if(param.s) - pkg_free(param.s); + if(logic_key.s) + pkg_free(logic_key.s); lock_get(&table[hash_index].lock); @@ -1288,6 +1294,10 @@ void destroy_b2b_htables(void) shm_free(dlg->tag[CALLEE_LEG].s); if(dlg->ack_sdp.s) shm_free(dlg->ack_sdp.s); + if (dlg->logic_key.s) + shm_free(dlg->logic_key.s); + if (dlg->free_param) + dlg->free_param(dlg->param); shm_free(dlg); dlg = aux; } @@ -1307,6 +1317,10 @@ void destroy_b2b_htables(void) b2b_delete_legs(&dlg->legs); if(dlg->ack_sdp.s) shm_free(dlg->ack_sdp.s); + if (dlg->logic_key.s) + shm_free(dlg->logic_key.s); + if (dlg->free_param) + dlg->free_param(dlg->param); shm_free(dlg); dlg = aux; } @@ -1317,7 +1331,7 @@ void destroy_b2b_htables(void) b2b_dlg_t* b2b_new_dlg(struct sip_msg* msg, str* local_contact, - b2b_dlg_t* init_dlg, str* param, str *mod_name) + b2b_dlg_t* init_dlg, str* logic_key, str *mod_name) { struct to_body *pto, *pfrom = NULL; b2b_dlg_t dlg; @@ -1457,8 +1471,8 @@ b2b_dlg_t* b2b_new_dlg(struct sip_msg* msg, str* local_contact, } } - if(param) - dlg.param = *param; + if(logic_key) + dlg.logic_key = *logic_key; dlg.db_flag = INSERTDB_FLAG; dlg.mod_name = *mod_name; @@ -1776,12 +1790,18 @@ void b2b_delete_record(b2b_dlg_t* dlg, b2b_table htable, unsigned int hash_index if(dlg->uac_tran) tmb.unref_cell(dlg->uac_tran); + if (dlg->logic_key.s) + shm_free(dlg->logic_key.s); + if(dlg->uas_tran) tmb.unref_cell(dlg->uas_tran); if(dlg->ack_sdp.s) shm_free(dlg->ack_sdp.s); + if (dlg->free_param) + dlg->free_param(dlg->param); + shm_free(dlg); } @@ -2568,9 +2588,10 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) str* b2b_key; unsigned int hash_index, local_index; b2b_notify_t b2b_cback; + void *b2b_param; b2b_dlg_t *dlg, *previous_dlg; b2b_dlg_t *aux_dlg,*new_dlg; - str param= {NULL, 0}; + str logic_key= {NULL, 0}; int statuscode = 0; dlg_leg_t* leg; struct to_body* pto; @@ -2775,7 +2796,7 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) lock_release(&server_htable[hash_index].lock); return; } - if (dlg->param.s && pkg_str_dup(&ctx->b2bl_key, &dlg->param) < 0) { + if (dlg->logic_key.s && pkg_str_dup(&ctx->b2bl_key, &dlg->logic_key) < 0) { LM_ERR("Failed to copy b2b_logic key to b2b context\n"); lock_release(&server_htable[hash_index].lock); return; @@ -2833,17 +2854,18 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) prev_state = dlg->state; b2b_cback = dlg->b2b_cback; - if(dlg->param.s) + b2b_param = dlg->param; + if(dlg->logic_key.s) { - param.s = (char*)pkg_malloc(dlg->param.len); - if(param.s == NULL) + logic_key.s = (char*)pkg_malloc(dlg->logic_key.len); + if(logic_key.s == NULL) { LM_ERR("No more private memory\n"); lock_release(&htable[hash_index].lock); return; } - memcpy(param.s, dlg->param.s, dlg->param.len); - param.len = dlg->param.len; + memcpy(logic_key.s, dlg->logic_key.s, dlg->logic_key.len); + logic_key.len = dlg->logic_key.len; } LM_DBG("Received reply [%d] for dialog [%p], method [%.*s]\n", @@ -3106,7 +3128,7 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) dlg->state == B2B_EARLY)) { new_dlg = b2b_new_dlg(msg, &dlg->contact[CALLER_LEG], - dlg, &dlg->param, &dlg->mod_name); + dlg, &dlg->logic_key, &dlg->mod_name); if(new_dlg == NULL) { LM_ERR("Failed to create b2b dialog structure\n"); @@ -3116,6 +3138,8 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) new_dlg->id = dlg->id; new_dlg->state = dlg->state; new_dlg->b2b_cback = dlg->b2b_cback; + new_dlg->param = dlg->param; + new_dlg->free_param = dlg->free_param; new_dlg->uac_tran = dlg->uac_tran; new_dlg->uas_tran = dlg->uas_tran; new_dlg->next = dlg->next; @@ -3135,6 +3159,8 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) dlg->next= dlg->prev = NULL; b2b_delete_legs(&dlg->legs); + if (dlg->logic_key.s) + shm_free(dlg->logic_key.s); shm_free(dlg); dlg = new_dlg; UPDATE_DBFLAG(dlg); @@ -3269,8 +3295,8 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) lock_release(&htable[hash_index].lock); - if(add_infof && add_infof(param.s?¶m:0, b2b_key, - etype,&dlginfo)< 0) + if(add_infof && add_infof(logic_key.s?&logic_key:0, b2b_key, + etype,&dlginfo, b2b_param)< 0) { LM_ERR("Failed to add dialoginfo\n"); goto error1; @@ -3312,11 +3338,11 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) if (msg != FAKED_REPLY) b2b_apply_lumps(msg); } - b2b_cback(msg, b2b_key, B2B_REPLY, param.s?¶m:0, b2b_cb_flags); - if(param.s) + b2b_cback(msg, b2b_key, B2B_REPLY, logic_key.s?&logic_key:0, b2b_param, b2b_cb_flags); + if(logic_key.s) { - pkg_free(param.s); - param.s = NULL; + pkg_free(logic_key.s); + logic_key.s = NULL; } if (msg == &dummy_msg) { free_lump_list(msg->add_rm); @@ -3399,8 +3425,8 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps) error: lock_release(&htable[hash_index].lock); error1: - if(param.s) - pkg_free(param.s); + if(logic_key.s) + pkg_free(logic_key.s); if (msg == &dummy_msg) { free_lump_list(msg->add_rm); free_lump_list(msg->body_lumps); diff --git a/modules/b2b_entities/dlg.h b/modules/b2b_entities/dlg.h index 6029c680a01..e6d5a9274e8 100644 --- a/modules/b2b_entities/dlg.h +++ b/modules/b2b_entities/dlg.h @@ -100,7 +100,7 @@ typedef struct b2b_dlg struct b2b_dlg *prev; b2b_notify_t b2b_cback; b2b_add_dlginfo_t add_dlginfo; - str param; + str logic_key; str storage; str mod_name; str ack_sdp; @@ -114,6 +114,8 @@ typedef struct b2b_dlg int db_flag; int replicated; struct b2b_tracer *tracer; + void *param; + b2b_param_free_cb free_param; }b2b_dlg_t; typedef struct b2b_entry diff --git a/modules/b2b_entities/doc/b2b_entities_devel.xml b/modules/b2b_entities/doc/b2b_entities_devel.xml index ec400093103..f2cd71ffe73 100644 --- a/modules/b2b_entities/doc/b2b_entities_devel.xml +++ b/modules/b2b_entities/doc/b2b_entities_devel.xml @@ -48,7 +48,9 @@ typedef struct b2b_api { ... -typedef str* (*b2b_server_new_t) (struct sip_msg* ,b2b_notify_t , void* param); +typedef str* (*b2b_server_new_t) (struct sip_msg* , str* local_contact, + b2b_notify_t , str *mod_name, str* logic_key, struct b2b_tracer *tracer, + void *param, b2b_param_free_cb free_param); ... @@ -92,7 +94,8 @@ typedef int (*b2b_notify_t)(struct sip_msg* msg, str* id, int type, void* param) ... typedef str* (*b2b_client_new_t) (client_info_t* , b2b_notify_t b2b_cback, - b2b_add_dlginfo_t add_dlginfo_f, str* param); + b2b_add_dlginfo_t add_dlginfo_f, str *mod_name, str *logic_key, + struct b2b_tracer *tracer, void *param, b2b_param_free_cb free_param); ... @@ -199,7 +202,7 @@ typedef void (*b2b_entity_delete_t)(enum b2b_entity_type et, str* b2b_key, ... typedef int (*b2b_restore_linfo_t)(enum b2b_entity_type type, str* key, - b2b_notify_t cback); + b2b_notify_t cback, void *param, b2b_param_free_cb free_param); ... diff --git a/modules/b2b_entities/server.c b/modules/b2b_entities/server.c index 8ad828ee30a..a118474c7f5 100644 --- a/modules/b2b_entities/server.c +++ b/modules/b2b_entities/server.c @@ -48,22 +48,15 @@ * */ str* server_new(struct sip_msg* msg, str* local_contact, - b2b_notify_t b2b_cback, str *mod_name, str* param, - struct b2b_tracer *tracer) + b2b_notify_t b2b_cback, str *mod_name, str* logic_key, + struct b2b_tracer *tracer, void *param, b2b_param_free_cb free_param) { b2b_dlg_t* dlg; unsigned int hash_index; int ret; - if(param && param->len > B2BL_MAX_KEY_LEN) - { - LM_ERR("parameter too long, received [%d], maximum [%d]\n", - param->len, B2BL_MAX_KEY_LEN); - return NULL; - } - /* create new entry in hash table */ - dlg = b2b_new_dlg(msg, local_contact, 0, param, mod_name); + dlg = b2b_new_dlg(msg, local_contact, 0, logic_key, mod_name); if( dlg == NULL ) { LM_ERR("failed to create new dialog structure entry\n"); @@ -75,6 +68,8 @@ str* server_new(struct sip_msg* msg, str* local_contact, dlg->state = B2B_NEW; dlg->b2b_cback = b2b_cback; + dlg->param = param; + dlg->free_param = free_param; dlg->tracer = tracer; /* get the pointer to the tm transaction to store it the tuple record */ @@ -104,7 +99,7 @@ str* server_new(struct sip_msg* msg, str* local_contact, LM_DBG("new server entity[%p]: callid=[%.*s] tag=[%.*s] param=[%.*s] dlg->uas_tran=[%p]\n", dlg, dlg->callid.len, dlg->callid.s, dlg->tag[CALLER_LEG].len, dlg->tag[CALLER_LEG].s, - dlg->param.len, dlg->param.s, dlg->uas_tran); + dlg->logic_key.len, dlg->logic_key.s, dlg->uas_tran); /* add the record in hash table */ dlg->db_flag = INSERTDB_FLAG; diff --git a/modules/b2b_entities/server.h b/modules/b2b_entities/server.h index 0f69df8bcc9..81c9c469f84 100644 --- a/modules/b2b_entities/server.h +++ b/modules/b2b_entities/server.h @@ -32,7 +32,7 @@ #include "b2be_load.h" str* server_new(struct sip_msg*, str* local_contact, b2b_notify_t, str *, - str*, struct b2b_tracer*); + str*, struct b2b_tracer*, void *, b2b_param_free_cb); dlg_t* b2b_server_build_dlg(b2b_dlg_t* dlg); diff --git a/modules/b2b_logic/b2b_logic.h b/modules/b2b_logic/b2b_logic.h index a6b293632ed..bbac3d577f4 100644 --- a/modules/b2b_logic/b2b_logic.h +++ b/modules/b2b_logic/b2b_logic.h @@ -170,11 +170,11 @@ static inline int b2b_get_request_id(str* request) return -1; } -int b2b_add_dlginfo(str* key, str* entity_key,int src, b2b_dlginfo_t* info); -int b2b_server_notify(struct sip_msg* msg, str* key, int type, void* param, - int flags); -int b2b_client_notify(struct sip_msg* msg, str* key, int type, void* param, - int flags); +int b2b_add_dlginfo(str* key, str* entity_key,int src, b2b_dlginfo_t* info, void *param); +int b2b_server_notify(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags); +int b2b_client_notify(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags); void b2bl_db_init(void); #endif diff --git a/modules/b2b_logic/b2bl_db.c b/modules/b2b_logic/b2bl_db.c index 472834c224a..cddb2385e33 100644 --- a/modules/b2b_logic/b2bl_db.c +++ b/modules/b2b_logic/b2bl_db.c @@ -396,7 +396,7 @@ static int b2bl_add_tuple(b2bl_tuple_t* tuple) /* restore to the entities from b2b_entities module * the parameter and callback function */ if(b2b_api.restore_logic_info(tuple->bridge_entities[i]->type, - &tuple->bridge_entities[i]->key, cback)< 0) + &tuple->bridge_entities[i]->key, cback, NULL, NULL)< 0) LM_WARN("Failed to restore logic info for tuple:entity [%.*s][%d]\n", b2bl_key->len, b2bl_key->s, i); else diff --git a/modules/b2b_logic/entity_storage.c b/modules/b2b_logic/entity_storage.c index aa643a62b2d..9da0394e2e9 100644 --- a/modules/b2b_logic/entity_storage.c +++ b/modules/b2b_logic/entity_storage.c @@ -337,7 +337,7 @@ static void receive_entity_create(enum b2b_entity_type entity_type, } if (b2b_api.restore_logic_info(entity_type, entity_key, - entity_type == B2B_SERVER ? b2b_server_notify : b2b_client_notify) < 0) { + entity_type == B2B_SERVER ? b2b_server_notify : b2b_client_notify, NULL, NULL) < 0) { LM_ERR("Failed to restore entity notify callback\n"); goto error; } diff --git a/modules/b2b_logic/logic.c b/modules/b2b_logic/logic.c index 5d68ff590f1..63a61b9fe14 100644 --- a/modules/b2b_logic/logic.c +++ b/modules/b2b_logic/logic.c @@ -123,7 +123,7 @@ int entity_add_dlginfo(b2bl_entity_id_t* entity, b2b_dlginfo_t* dlginfo) return 0; } -int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo) +int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo, void *param) { b2bl_tuple_t* tuple; b2bl_entity_id_t* entity = NULL; @@ -703,8 +703,8 @@ static b2bl_entity_id_t* b2bl_new_client(str* to_uri, str *proxy, str* from_uri, b2bl_htable[tuple->hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, tuple->key, get_tracer(tuple)); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, tuple->key, get_tracer(tuple), NULL, NULL); b2bl_htable[tuple->hash_index].locked_by = -1; @@ -841,7 +841,7 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, &b2bl_mod_name, tuple->key, - get_tracer(tuple)); + get_tracer(tuple), NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -2414,8 +2414,7 @@ static inline int get_b2b_dialog_by_replace(str *replaces, str *u_replaces, str *entity_key, unsigned int *hash_idx, unsigned int *local_idx ) { struct replaces_body replaces_b; - char tuple_buf[B2BL_MAX_KEY_LEN]; - str tuple_key; + str *tuple_key; //LM_DBG("Replaces=[%.*s]\n",replaces->len,replaces->s); if(unescape_param(replaces,u_replaces)!=0) @@ -2435,13 +2434,11 @@ static inline int get_b2b_dialog_by_replace(str *replaces, str *u_replaces, u_replaces->len, u_replaces->s); return -1; } - tuple_key.s = tuple_buf; - tuple_key.len = B2BL_MAX_KEY_LEN; - if(b2b_api.get_b2bl_key(&replaces_b.callid_val, + tuple_key = b2b_api.get_b2bl_key(&replaces_b.callid_val, &replaces_b.from_tag_val, &replaces_b.to_tag_val, - entity_key, - &tuple_key)!=0) + entity_key); + if(!tuple_key) { LM_ERR("no b2bl key for [%.*s][%.*s][%.*s]\n", replaces_b.callid_val.len, @@ -2452,10 +2449,11 @@ static inline int get_b2b_dialog_by_replace(str *replaces, str *u_replaces, replaces_b.from_tag_val.s); return -1; } - if(b2bl_parse_key(&tuple_key, hash_idx, local_idx)< 0) + if(b2bl_parse_key(tuple_key, hash_idx, local_idx)< 0) { LM_ERR("Failed to parse b2b logic key [%.*s]\n", - tuple_key.len, tuple_key.s); + tuple_key->len, tuple_key->s); + pkg_free(tuple_key); return -1; } LM_DBG("Need to replace callid=[%.*s] to-tag=[%.*s] and " @@ -2463,12 +2461,13 @@ static inline int get_b2b_dialog_by_replace(str *replaces, str *u_replaces, replaces_b.callid_val.len, replaces_b.callid_val.s, replaces_b.to_tag_val.len, replaces_b.to_tag_val.s, replaces_b.from_tag_val.len, replaces_b.from_tag_val.s, - tuple_key.len, tuple_key.s); + tuple_key->len, tuple_key->s); + pkg_free(tuple_key); return 0; } -int b2b_logic_notify(int src, struct sip_msg* msg, str* key, int type, void* param, +int b2b_logic_notify(int src, struct sip_msg* msg, str* key, int type, str* b2bl_key, int flags) { #define U_REPLACES_BUF_LEN 512 @@ -2478,7 +2477,6 @@ int b2b_logic_notify(int src, struct sip_msg* msg, str* key, int type, void* par unsigned int hash_idx, local_idx; str entity_key = {NULL, 0}; b2bl_tuple_t* tuple; - str* b2bl_key = (str*)param; str body= {NULL, 0}; str extra_headers = {NULL, 0}; str new_body={NULL, 0}; @@ -2878,8 +2876,8 @@ int process_bridge_action(struct sip_msg* msg, b2bl_tuple_t* tuple, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, tuple->key, get_tracer(tuple)); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, tuple->key, get_tracer(tuple), NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -2937,17 +2935,17 @@ int process_bridge_action(struct sip_msg* msg, b2bl_tuple_t* tuple, return -1; } -int b2b_server_notify(struct sip_msg* msg, str* key, int type, void* param, - int flags) +int b2b_server_notify(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags) { - return b2b_logic_notify(B2B_SERVER, msg, key, type, param, flags); + return b2b_logic_notify(B2B_SERVER, msg, key, type, logic_key, flags); } -int b2b_client_notify(struct sip_msg* msg, str* key, int type, void* param, - int flags) +int b2b_client_notify(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags) { - return b2b_logic_notify(B2B_CLIENT, msg, key, type, param, flags); + return b2b_logic_notify(B2B_CLIENT, msg, key, type, logic_key, flags); } static char fromtag_buf[MD5_LEN]; @@ -3050,8 +3048,8 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, tuple->lifetime = params->init_timeout + get_ticks(); /* create new server */ - server_id = b2b_api.server_new(msg, &tuple->local_contact, - b2b_server_notify, &b2bl_mod_name, b2bl_key, get_tracer(tuple)); + server_id = b2b_api.server_new(msg, &tuple->local_contact, b2b_server_notify, + &b2bl_mod_name, b2bl_key, get_tracer(tuple), NULL, NULL); if(server_id == NULL) { LM_ERR("failed to create new b2b server instance\n"); @@ -3107,8 +3105,8 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, get_tracer(tuple)); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, b2bl_key, get_tracer(tuple), NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -3149,8 +3147,8 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, get_tracer(tuple)); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, b2bl_key, get_tracer(tuple), NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -3397,7 +3395,8 @@ str* b2b_process_scenario_init(struct sip_msg* msg, b2bl_cback_f cbf, /* create new server entity */ server_id = b2b_api.server_new(msg, new_entity->adv_contact.s ? &new_entity->adv_contact : &tuple->local_contact, - b2b_server_notify, &b2bl_mod_name, b2bl_key, get_tracer(tuple)); + b2b_server_notify, &b2bl_mod_name, b2bl_key, + get_tracer(tuple), NULL, NULL); if(server_id == NULL) { LM_ERR("failed to create new b2b server instance\n"); @@ -3465,8 +3464,8 @@ str* b2b_process_scenario_init(struct sip_msg* msg, b2bl_cback_f cbf, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, get_tracer(tuple)); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, b2bl_key, get_tracer(tuple), NULL, NULL); pkg_free(to_uri.s); to_uri.s = 0; @@ -4028,8 +4027,8 @@ int b2bl_bridge(str* key, str* new_dst, str *new_proxy, str* new_from_dname, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, tuple->key, get_tracer(tuple)); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, tuple->key, get_tracer(tuple), NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -4399,14 +4398,15 @@ int b2bl_bridge_2calls(str* key1, str* key2) int b2bl_get_tuple_key(str *key, unsigned int *hash_index, unsigned int *local_index) { - char tuple_buffer[B2BL_MAX_KEY_LEN]; - str callid, from_tag, to_tag, tuple; + int ret; + str callid, from_tag, to_tag, *tuple; /* check to see if the key is specified as callid;from_tag;to_tag */ from_tag.s = q_memchr(key->s, ';', key->len); if (!from_tag.s) { LM_DBG("there's no tuple separator: must be plain key: %.*s\n", key->len, key->s); + tuple = key; goto end; } callid.s = key->s; @@ -4422,15 +4422,16 @@ int b2bl_get_tuple_key(str *key, unsigned int *hash_index, to_tag.len = key->s + key->len - to_tag.s; /* we've got the entity's coordinates, try to find the entity now */ - tuple.s = tuple_buffer; - tuple.len = B2BL_MAX_KEY_LEN; - if(b2b_api.get_b2bl_key(&callid, &from_tag, &to_tag, NULL, &tuple)) { + tuple = b2b_api.get_b2bl_key(&callid, &from_tag, &to_tag, NULL); + if(!tuple) { LM_DBG("cannot find entity [%.*s]\n", key->len, key->s); return -2; } - key = &tuple; end: - return b2bl_parse_key(key, hash_index, local_index); + ret = b2bl_parse_key(tuple, hash_index, local_index); + if (key != tuple) + pkg_free(tuple); + return ret; } @@ -4624,7 +4625,8 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no, str *adv_ct) goto error; } server_id = b2b_api.server_new(msg, adv_ct ? adv_ct : &local_contact, - b2b_server_notify, &b2bl_mod_name, tuple->key, get_tracer(tuple)); + b2b_server_notify, &b2bl_mod_name, tuple->key, + get_tracer(tuple), NULL, NULL); if(server_id == NULL) { LM_ERR("failed to create new b2b server instance\n"); diff --git a/modules/b2b_logic_xml/b2b_load.h b/modules/b2b_logic_xml/b2b_load.h index b09abdda03c..f710274d45a 100644 --- a/modules/b2b_logic_xml/b2b_load.h +++ b/modules/b2b_logic_xml/b2b_load.h @@ -47,7 +47,7 @@ typedef int (*b2bl_cback_f)(b2bl_cb_params_t *params, unsigned int b2b_event); **/ -typedef str* (*b2bl_init_f)(struct sip_msg* msg, str* name, str* args[5], +typedef str* (*b2bl_init_f)(struct sip_msg* msg, str* name, str* args[MAX_SCENARIO_PARAMS], b2bl_cback_f, void* param, unsigned int cb_mask, str* custom_hdrs); typedef int (*b2bl_bridge_f)(str* key, str* new_uri, str* new_from_dname,int entity_type); @@ -97,7 +97,7 @@ typedef struct b2bl_api b2bl_restore_upper_info_f restore_upper_info; }b2bl_api_t; -str* internal_init_scenario(struct sip_msg* msg, str* name, str* args[5], +str* internal_init_scenario(struct sip_msg* msg, str* name, str* args[MAX_SCENARIO_PARAMS], b2bl_cback_f, void* param, unsigned int cb_mask, str* custom_hdrs); typedef int(*load_b2bl_f)( b2bl_api_t *api ); diff --git a/modules/b2b_logic_xml/b2b_logic.c b/modules/b2b_logic_xml/b2b_logic.c index 646d8989207..f438d7e91a0 100644 --- a/modules/b2b_logic_xml/b2b_logic.c +++ b/modules/b2b_logic_xml/b2b_logic.c @@ -1087,7 +1087,7 @@ struct to_body* get_b2bl_from(struct sip_msg* msg) } -str* b2bl_bridge_extern(str* scenario_name, str* args[], +str* b2bl_bridge_extern(str* scenario_name, str* args[5], b2bl_cback_f cbf, void* cb_param, unsigned int cb_mask) { b2b_scenario_t* scenario_struct; diff --git a/modules/b2b_logic_xml/b2b_logic.h b/modules/b2b_logic_xml/b2b_logic.h index d039e15a41e..927287198c5 100644 --- a/modules/b2b_logic_xml/b2b_logic.h +++ b/modules/b2b_logic_xml/b2b_logic.h @@ -170,11 +170,11 @@ static inline int b2b_get_request_id(str* request) b2b_scenario_t* b2b_find_scenario(b2b_scenario_t* scenario, unsigned int scenario_id); -int b2b_add_dlginfo(str* key, str* entity_key,int src, b2b_dlginfo_t* info); -int b2b_server_notify(struct sip_msg* msg, str* key, int type, void* param, - int flags); -int b2b_client_notify(struct sip_msg* msg, str* key, int type, void* param, - int flags); +int b2b_add_dlginfo(str* key, str* entity_key,int src, b2b_dlginfo_t* info, void *param); +int b2b_server_notify(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags); +int b2b_client_notify(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags); b2b_scenario_t* get_scenario_id_list(str* sid, b2b_scenario_t* list); b2b_scenario_t* get_scenario_id(str* sid); void b2bl_db_init(void); diff --git a/modules/b2b_logic_xml/b2bl_db.c b/modules/b2b_logic_xml/b2bl_db.c index 9f63e4428b1..d2bc5c2d026 100644 --- a/modules/b2b_logic_xml/b2bl_db.c +++ b/modules/b2b_logic_xml/b2bl_db.c @@ -309,7 +309,7 @@ static int b2bl_add_tuple(b2bl_tuple_t* tuple, str* params[]) /* restore to the entities from b2b_entities module * the parameter and callback function */ if(b2b_api.restore_logic_info(tuple->bridge_entities[i]->type, - &tuple->bridge_entities[i]->key, cback)< 0) + &tuple->bridge_entities[i]->key, cback, NULL, NULL)< 0) LM_WARN("Failed to restore logic info for tuple:entity [%.*s][%d]\n", b2bl_key->len, b2bl_key->s, i); else diff --git a/modules/b2b_logic_xml/entity_storage.c b/modules/b2b_logic_xml/entity_storage.c index b9281036fe1..ab1124c5c54 100644 --- a/modules/b2b_logic_xml/entity_storage.c +++ b/modules/b2b_logic_xml/entity_storage.c @@ -343,7 +343,7 @@ static void receive_entity_create(enum b2b_entity_type entity_type, } if (b2b_api.restore_logic_info(entity_type, entity_key, - entity_type == B2B_SERVER ? b2b_server_notify : b2b_client_notify) < 0) { + entity_type == B2B_SERVER ? b2b_server_notify : b2b_client_notify, NULL, NULL) < 0) { LM_ERR("Failed to restore entity notify callback\n"); goto error; } diff --git a/modules/b2b_logic_xml/logic.c b/modules/b2b_logic_xml/logic.c index 5485849560d..66ce363e34a 100644 --- a/modules/b2b_logic_xml/logic.c +++ b/modules/b2b_logic_xml/logic.c @@ -115,7 +115,7 @@ int entity_add_dlginfo(b2bl_entity_id_t* entity, b2b_dlginfo_t* dlginfo) return 0; } -int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo) +int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo, void *param) { b2bl_tuple_t* tuple; b2bl_entity_id_t* entity = NULL; @@ -607,8 +607,8 @@ static b2bl_entity_id_t* b2bl_new_client(str* to_uri, str* from_uri, b2bl_htable[tuple->hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, tuple->key, NULL); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, tuple->key, NULL, NULL, NULL); b2bl_htable[tuple->hash_index].locked_by = -1; @@ -736,8 +736,8 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, tuple->key, NULL); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, tuple->key, NULL, NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -1965,8 +1965,7 @@ static inline int get_b2b_dialog_by_replace(str *replaces, str *u_replaces, str *entity_key, unsigned int *hash_idx, unsigned int *local_idx ) { struct replaces_body replaces_b; - char tuple_buf[B2BL_MAX_KEY_LEN]; - str tuple_key; + str *tuple_key; //LM_DBG("Replaces=[%.*s]\n",replaces->len,replaces->s); if(unescape_param(replaces,u_replaces)!=0) @@ -1986,13 +1985,11 @@ static inline int get_b2b_dialog_by_replace(str *replaces, str *u_replaces, u_replaces->len, u_replaces->s); return -1; } - tuple_key.s = tuple_buf; - tuple_key.len = B2BL_MAX_KEY_LEN; - if(b2b_api.get_b2bl_key(&replaces_b.callid_val, + tuple_key = b2b_api.get_b2bl_key(&replaces_b.callid_val, &replaces_b.from_tag_val, &replaces_b.to_tag_val, - entity_key, - &tuple_key)!=0) + entity_key); + if(!tuple_key) { LM_ERR("no b2bl key for [%.*s][%.*s][%.*s]\n", replaces_b.callid_val.len, @@ -2003,10 +2000,11 @@ static inline int get_b2b_dialog_by_replace(str *replaces, str *u_replaces, replaces_b.from_tag_val.s); return -1; } - if(b2bl_parse_key(&tuple_key, hash_idx, local_idx)< 0) + if(b2bl_parse_key(tuple_key, hash_idx, local_idx)< 0) { LM_ERR("Failed to parse b2b logic key [%.*s]\n", - tuple_key.len, tuple_key.s); + tuple_key->len, tuple_key->s); + pkg_free(tuple_key); return -1; } LM_DBG("Need to replace callid=[%.*s] to-tag=[%.*s] and " @@ -2014,12 +2012,13 @@ static inline int get_b2b_dialog_by_replace(str *replaces, str *u_replaces, replaces_b.callid_val.len, replaces_b.callid_val.s, replaces_b.to_tag_val.len, replaces_b.to_tag_val.s, replaces_b.from_tag_val.len, replaces_b.from_tag_val.s, - tuple_key.len, tuple_key.s); + tuple_key->len, tuple_key->s); + pkg_free(tuple_key); return 0; } -int b2b_logic_notify(int src, struct sip_msg* msg, str* key, int type, void* param) +int b2b_logic_notify(int src, struct sip_msg* msg, str* key, int type, str* b2bl_key) { #define U_REPLACES_BUF_LEN 512 char u_replaces_buf[U_REPLACES_BUF_LEN]; @@ -2028,7 +2027,6 @@ int b2b_logic_notify(int src, struct sip_msg* msg, str* key, int type, void* par unsigned int hash_idx, local_idx; str entity_key = {NULL, 0}; b2bl_tuple_t* tuple; - str* b2bl_key = (str*)param; str body= {NULL, 0}; str extra_headers = {NULL, 0}; str new_body={NULL, 0}; @@ -2599,8 +2597,8 @@ int process_bridge_action(struct sip_msg* msg, b2bl_entity_id_t* curr_entity, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, tuple->key, NULL); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, tuple->key, NULL, NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -2674,15 +2672,17 @@ int process_bridge_action(struct sip_msg* msg, b2bl_entity_id_t* curr_entity, return -1; } -int b2b_server_notify(struct sip_msg* msg, str* key, int type, void* param, int flags) +int b2b_server_notify(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags) { - return b2b_logic_notify(B2B_SERVER, msg, key, type, param); + return b2b_logic_notify(B2B_SERVER, msg, key, type, logic_key); } -int b2b_client_notify(struct sip_msg* msg, str* key, int type, void* param, int flags) +int b2b_client_notify(struct sip_msg* msg, str* key, int type, + str *logic_key, void* param, int flags) { - return b2b_logic_notify(B2B_CLIENT, msg, key, type, param); + return b2b_logic_notify(B2B_CLIENT, msg, key, type, logic_key); } static char fromtag_buf[MD5_LEN]; @@ -2782,7 +2782,7 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, /* create new server */ server_id = b2b_api.server_new(msg, &tuple->local_contact, - b2b_server_notify, &b2bl_mod_name, b2bl_key, NULL); + b2b_server_notify, &b2bl_mod_name, b2bl_key, NULL, NULL, NULL); if(server_id == NULL) { LM_ERR("failed to create new b2b server instance\n"); @@ -2831,8 +2831,8 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, NULL); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, b2bl_key, NULL, NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -2873,8 +2873,8 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, NULL); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, b2bl_key, NULL, NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -3396,7 +3396,7 @@ str* b2b_process_scenario_init(b2b_scenario_t* scenario_struct, /* create new server entity */ server_id = b2b_api.server_new(msg, &tuple->local_contact, - b2b_server_notify, &b2bl_mod_name, b2bl_key, NULL); + b2b_server_notify, &b2bl_mod_name, b2bl_key, NULL, NULL, NULL); if(server_id == NULL) { LM_ERR("failed to create new b2b server instance\n"); @@ -3502,8 +3502,8 @@ str* b2b_process_scenario_init(b2b_scenario_t* scenario_struct, b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, NULL); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, b2bl_key, NULL, NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -3823,8 +3823,8 @@ int b2bl_bridge(str* key, str* new_dst, str* new_from_dname, int entity_no) b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, - b2b_add_dlginfo, &b2bl_mod_name, tuple->key, NULL); + client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, + &b2bl_mod_name, tuple->key, NULL, NULL, NULL); b2bl_htable[hash_index].locked_by = -1; @@ -4223,14 +4223,15 @@ int b2bl_bridge_2calls(str* key1, str* key2) int b2bl_get_tuple_key(str *key, unsigned int *hash_index, unsigned int *local_index) { - char tuple_buffer[B2BL_MAX_KEY_LEN]; - str callid, from_tag, to_tag, tuple; + int ret; + str callid, from_tag, to_tag, *tuple; /* check to see if the key is specified as callid;from_tag;to_tag */ from_tag.s = q_memchr(key->s, ';', key->len); if (!from_tag.s) { LM_DBG("there's no tuple separator: must be plain key: %.*s\n", key->len, key->s); + tuple = key; goto end; } callid.s = key->s; @@ -4246,15 +4247,16 @@ int b2bl_get_tuple_key(str *key, unsigned int *hash_index, to_tag.len = key->s + key->len - to_tag.s; /* we've got the entity's coordinates, try to find the entity now */ - tuple.s = tuple_buffer; - tuple.len = B2BL_MAX_KEY_LEN; - if(b2b_api.get_b2bl_key(&callid, &from_tag, &to_tag, NULL, &tuple)) { + tuple = b2b_api.get_b2bl_key(&callid, &from_tag, &to_tag, NULL); + if(!tuple) { LM_DBG("cannot find entity [%.*s]\n", key->len, key->s); return -2; } - key = &tuple; end: - return b2bl_parse_key(key, hash_index, local_index); + ret = b2bl_parse_key(tuple, hash_index, local_index); + if (key != tuple) + pkg_free(tuple); + return ret; } @@ -4419,7 +4421,7 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no) goto error; } server_id = b2b_api.server_new(msg, &tuple->local_contact, - b2b_server_notify, &b2bl_mod_name, tuple->key, NULL); + b2b_server_notify, &b2bl_mod_name, tuple->key, NULL, NULL, NULL); if(server_id == NULL) { LM_ERR("failed to create new b2b server instance\n"); diff --git a/modules/b2b_sca/sca_db_handler.c b/modules/b2b_sca/sca_db_handler.c index d780e18b53d..de2070eff3f 100644 --- a/modules/b2b_sca/sca_db_handler.c +++ b/modules/b2b_sca/sca_db_handler.c @@ -493,14 +493,6 @@ static int load_sca_info_from_db(void) b2bl_key.s = (char*)values[app_b2bl_key_col[j]].val.string_val; if (b2bl_key.s) { b2bl_key.len = strlen(b2bl_key.s); - if (b2bl_key.len > B2BL_MAX_KEY_LEN) { - LM_ERR("buffer overflow on b2bl_key [%.*s]" - " for shared_line [%.*s][%d]\n", - b2bl_key.len, b2bl_key.s, - shared_line.len, shared_line.s, - appearance_index); - goto cont; - } LM_DBG("b2bl_key=[%.*s]\n", b2bl_key.len, b2bl_key.s); } else { LM_ERR("Missing b2bl_key for shared_line [%.*s][1]\n", @@ -518,6 +510,8 @@ static int load_sca_info_from_db(void) if (0!=b2b_sca_update_call_record_key(call, &b2bl_key)) { LM_ERR("Unable to update b2bl_key [%.*s]\n", b2bl_key.len, b2bl_key.s); + if (call->b2bl_key.s) + shm_free(call->b2bl_key.s); shm_free(call); call = NULL; record->call[appearance_index-1] = NULL; @@ -534,6 +528,8 @@ static int load_sca_info_from_db(void) if(b2bl_api.register_cb(&b2bl_key, &sca_logic_notify, cb_params, B2B_RE_INVITE_CB|B2B_CONFIRMED_CB|B2B_DESTROY_CB) != 0){ LM_ERR("Unable register b2b cb\n"); + if (call->b2bl_key.s) + shm_free(call->b2bl_key.s); shm_free(call); call = NULL; record->call[appearance_index-1] = NULL; diff --git a/modules/b2b_sca/sca_records.c b/modules/b2b_sca/sca_records.c index 77790b5fbf3..d5ff92a6b22 100644 --- a/modules/b2b_sca/sca_records.c +++ b/modules/b2b_sca/sca_records.c @@ -267,8 +267,7 @@ b2b_sca_call_t* restore_call(b2b_sca_record_t *record, size = sizeof(b2b_sca_call_t) + appearance_index_str.len + call_info_uri->len + - call_info_apperance_uri->len + - B2BL_MAX_KEY_LEN; + call_info_apperance_uri->len; call = (b2b_sca_call_t *)shm_malloc(size); if (call == NULL) { LM_ERR("OOM\n"); @@ -298,8 +297,7 @@ b2b_sca_call_t* restore_call(b2b_sca_record_t *record, p += call_info_apperance_uri->len; call->b2bl_key.len = 0; - call->b2bl_key.s = p; - p += B2BL_MAX_KEY_LEN; + call->b2bl_key.s = NULL; record->call[appearance_index-1] = call; @@ -339,10 +337,10 @@ b2b_sca_record_t* restore_record(str *shared_line, str *watchers_csv) int b2b_sca_update_call_record_key(b2b_sca_call_t *call, str* b2bl_key) { - if (!b2bl_key || !b2bl_key->s || b2bl_key->len > B2BL_MAX_KEY_LEN) + if (!b2bl_key || !b2bl_key->s) + return -1; + if (shm_str_sync(&call->b2bl_key, b2bl_key) < 0) return -1; - memcpy(call->b2bl_key.s, b2bl_key->s, b2bl_key->len); - call->b2bl_key.len = b2bl_key->len; return 0; } @@ -461,6 +459,8 @@ void b2b_sca_delete_call_record(int hash_index, b2b_sca_record_t *record, unsign { b2b_sca_call_t *call = b2b_sca_search_call_safe(record, appearance); if (call) { + if (call->b2bl_key.s) + shm_free(call->b2bl_key.s); shm_free(call); record->call[appearance - 1] = NULL; } @@ -489,6 +489,8 @@ void b2b_sca_delete_record(b2b_sca_record_t *record, unsigned int hash_index) if (record->call[i]) { b2b_sca_print_call_record(i, record->call[i]); LM_WARN("delete record with active appearance [%d]\n", i+1); + if (record->call[i]->b2bl_key.s) + shm_free(record->call[i]->b2bl_key.s); shm_free(record->call[i]); } diff --git a/modules/media_exchange/media_exchange.c b/modules/media_exchange/media_exchange.c index 7886feadbd3..14eb4d03ddc 100644 --- a/modules/media_exchange/media_exchange.c +++ b/modules/media_exchange/media_exchange.c @@ -47,9 +47,9 @@ static int media_indialog(struct sip_msg *msg); static int fixup_media_leg(void **param); static int fixup_media_leg_both(void **param); -static int b2b_media_notify(struct sip_msg *msg, str *key, int type, void *param, - int flags); -static int b2b_media_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* info); +static int b2b_media_notify(struct sip_msg *msg, str *key, int type, + str *logic_key, void *param, int flags); +static int b2b_media_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* info, void *param); static mi_response_t *mi_media_fork_from_call_to_uri(const mi_params_t *params, struct mi_handler *async_hdl); @@ -294,7 +294,6 @@ static inline client_info_t *media_get_client_info(struct socket_info *si, static int handle_media_fork_to_uri(struct media_session_leg *msl, struct socket_info *si, str *uri, str *headers, int medianum, str *caller_body, str *callee_body) { - str hack; static client_info_t *ci; struct media_fork_info *mf; str *b2b_key; @@ -321,10 +320,8 @@ static int handle_media_fork_to_uri(struct media_session_leg *msl, struct socket goto release; } - hack.s = (char *)&msl; - hack.len = sizeof(void *); - b2b_key = media_b2b.client_new(ci, b2b_media_notify, - b2b_media_confirm, &b2b_media_exchange_cap, &hack, NULL); + b2b_key = media_b2b.client_new(ci, b2b_media_notify, b2b_media_confirm, + &b2b_media_exchange_cap, &msl->ms->dlg->callid, NULL, msl, NULL); if (!b2b_key) { LM_ERR("could not create b2b client!\n"); goto release; @@ -457,7 +454,6 @@ static int media_fork_to_uri(struct sip_msg *msg, static int media_fork_from_call(struct sip_msg *msg, str *callid, int leg, int *medianum) { - str hack; str contact; str *b2b_key; sdp_info_t *sdp; @@ -521,10 +517,8 @@ static int media_fork_from_call(struct sip_msg *msg, str *callid, int leg, int * MEDIA_LEG_STATE_SET_UNSAFE(msl, MEDIA_SESSION_STATE_UPDATING); MEDIA_LEG_UNLOCK(msl); - hack.s = (char *)&msl; - hack.len = sizeof(void *); b2b_key = media_b2b.server_new(msg, &contact, b2b_media_notify, - &b2b_media_exchange_cap, &hack, NULL); + &b2b_media_exchange_cap, callid, NULL, msl, NULL); if (!b2b_key) { LM_ERR("could not create b2b server for callid %.*s\n", callid->len, callid->s); goto destroy; @@ -583,7 +577,6 @@ static int handle_media_exchange_from_uri(struct socket_info *si, struct dlg_cel str *uri, int leg, str *body, str *headers, int nohold, struct media_session_tm_param *p) { - str hack; struct media_session_leg *msl; static client_info_t *ci; str *b2b_key; @@ -602,10 +595,8 @@ static int handle_media_exchange_from_uri(struct socket_info *si, struct dlg_cel msl->params = p; } - hack.s = (char *)&msl; - hack.len = sizeof(void *); - b2b_key = media_b2b.client_new(ci, b2b_media_notify, - b2b_media_confirm, &b2b_media_exchange_cap, &hack, NULL); + b2b_key = media_b2b.client_new(ci, b2b_media_notify, b2b_media_confirm, + &b2b_media_exchange_cap, &dlg->callid, NULL, msl, NULL); if (!b2b_key) { LM_ERR("could not create b2b client!\n"); goto unref; @@ -759,7 +750,6 @@ static int media_exchange_to_call(struct sip_msg *msg, str *callid, int leg, int struct dlg_cell *dlg; struct media_session_leg *msl; static str inv = str_init("INVITE"); - str hack; if (leg == MEDIA_LEG_UNSPEC) { LM_BUG("leg parameter is mandatory for media_exchange_to_call!\n"); @@ -794,10 +784,8 @@ static int media_exchange_to_call(struct sip_msg *msg, str *callid, int leg, int goto unref; } - hack.s = (char *)&msl; - hack.len = sizeof(void *); b2b_key = media_b2b.server_new(msg, &contact, b2b_media_notify, - &b2b_media_exchange_cap, &hack, NULL); + &b2b_media_exchange_cap, callid, NULL, msl, NULL); if (!b2b_key) { LM_ERR("could not create b2b server for callid %.*s\n", callid->len, callid->s); goto destroy; @@ -1454,10 +1442,10 @@ static int handle_indialog_request(struct sip_msg *msg, struct media_session_leg } } -static int b2b_media_notify(struct sip_msg *msg, str *key, int type, void *param, - int flags) +static int b2b_media_notify(struct sip_msg *msg, str *key, int type, + str *logic_key, void *param, int flags) { - struct media_session_leg *msl = *(struct media_session_leg **)((str *)param)->s; + struct media_session_leg *msl = (struct media_session_leg *)param; int initial_state; if (type == B2B_REPLY) { @@ -1510,7 +1498,7 @@ static int b2b_media_notify(struct sip_msg *msg, str *key, int type, void *param return -1; } -static int b2b_media_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* info) +static int b2b_media_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* info, void *param) { /* TODO: copy from info fromtag, totag, callid struct media_session_leg *msl = *(struct media_session_leg **)((str *)key)->s; @@ -1520,15 +1508,12 @@ static int b2b_media_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* int b2b_media_restore_callbacks(struct media_session_leg *msl) { - str hack; - hack.s = (char *)&msl; - hack.len = sizeof(void *); - if (media_b2b.update_b2bl_param(msl->b2b_entity, &msl->b2b_key, &hack, 0) < 0) { + if (media_b2b.update_b2bl_param(msl->b2b_entity, &msl->b2b_key, &msl->ms->dlg->callid, 0) < 0) { LM_ERR("could not update restore param!\n"); return -1; } if (media_b2b.restore_logic_info(msl->b2b_entity, - &msl->b2b_key, b2b_media_notify) < 0) { + &msl->b2b_key, b2b_media_notify, msl, NULL) < 0) { LM_ERR("could not register restore logic!\n"); return -1; } diff --git a/modules/siprec/siprec_logic.c b/modules/siprec/siprec_logic.c index 538e7f51be2..5586bcff2c4 100644 --- a/modules/siprec/siprec_logic.c +++ b/modules/siprec/siprec_logic.c @@ -260,8 +260,8 @@ static int srec_b2b_req(struct sip_msg *msg, struct src_sess *ss) return 0; } -static int srec_b2b_notify(struct sip_msg *msg, str *key, int type, void *param, - int flags) +static int srec_b2b_notify(struct sip_msg *msg, str *key, int type, + str *logic_key, void *param, int flags) { struct b2b_req_data req; struct src_sess *ss; @@ -273,7 +273,7 @@ static int srec_b2b_notify(struct sip_msg *msg, str *key, int type, void *param, LM_ERR("no callback parameter specified!\n"); return -1; } - ss = *(struct src_sess **)((str *)param)->s; + ss = (struct src_sess *)param; if (!ss) { LM_ERR("cannot find session in parameter!\n"); return -1; @@ -371,20 +371,26 @@ static int srec_b2b_notify(struct sip_msg *msg, str *key, int type, void *param, int srec_restore_callback(struct src_sess *sess) { if (srec_b2b.restore_logic_info(B2B_CLIENT, &sess->b2b_key, - srec_b2b_notify) < 0) { + srec_b2b_notify, sess, NULL) < 0) { LM_ERR("cannot register notify callback for [%.*s]!\n", sess->b2b_key.len, sess->b2b_key.s); return -1; } + if (srec_b2b.update_b2bl_param(B2B_CLIENT, &sess->b2b_key, + &sess->dlg->callid, 1) < 0) { + LM_ERR("cannot update param for [%.*s]!\n", + sess->b2b_key.len, sess->b2b_key.s); + return -1; + } return 0; } -static int srec_b2b_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* info) +static int srec_b2b_confirm(str* logic_key, str* entity_key, int src, b2b_dlginfo_t* info, void *param) { char *tmp; struct src_sess *ss; - ss = *(struct src_sess **)key->s; + ss = (struct src_sess *)param; if (!ss) { LM_ERR("cannot find session in key parameter [%.*s]!\n", entity_key->len, entity_key->s); @@ -422,7 +428,7 @@ static int srec_b2b_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* i static int srs_send_invite(struct src_sess *sess) { client_info_t ci; - str param, body; + str body; str *client; str hdrs; str ct, contact; @@ -476,11 +482,8 @@ static int srs_send_invite(struct src_sess *sess) ci.local_contact = ct; } - /* XXX: hack to pass a parameter :( */ - param.s = (char *)&sess; - param.len = sizeof(void *); client = srec_b2b.client_new(&ci, srec_b2b_notify, srec_b2b_confirm, - &mod_name, (str *)¶m, NULL); + &mod_name, &sess->dlg->callid, NULL, sess, NULL); pkg_free(body.s); if (contact.s) pkg_free(contact.s);