Skip to content

Commit a7197f8

Browse files
committed
b2b_logic: determine entity type if not explicit
1 parent 6da409d commit a7197f8

6 files changed

Lines changed: 36 additions & 14 deletions

File tree

modules/b2b_logic/b2b_load.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ typedef int (*b2bl_bridge_2calls_t)(str* key1, str* key2);
8787
int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no,
8888
unsigned int flags, str *adv_ct);
8989
int b2bl_get_tuple_key(str *key, unsigned int *hash_index,
90-
unsigned int *local_index);
90+
unsigned int *local_index, str *entity_str);
9191
typedef int (*b2bl_bridge_msg_t)(struct sip_msg* msg, str* key, int entity_no);
9292

9393
int b2bl_get_stats(str* key, b2bl_dlg_stat_t* stat);

modules/b2b_logic/b2b_logic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ static mi_response_t *mi_b2b_terminate_call(const mi_params_t *params,
13041304
if (get_mi_string_param(params, "key", &key.s, &key.len) < 0)
13051305
return init_mi_param_error();
13061306

1307-
if (b2bl_get_tuple_key(&key, &hash_index, &local_index) < 0)
1307+
if (b2bl_get_tuple_key(&key, &hash_index, &local_index, NULL) < 0)
13081308
return init_mi_error(404, MI_SSTR("B2B session not found"));
13091309

13101310
B2BL_LOCK_GET(hash_index);
@@ -1349,7 +1349,7 @@ static mi_response_t *mi_b2b_bridge_f(const mi_params_t *params,
13491349
if (get_mi_int_param(params, "flag", &flag) < 0)
13501350
return init_mi_param_error();
13511351

1352-
return mi_b2b_bridge(params, flag, NULL);
1352+
return mi_b2b_bridge(params, &flag, NULL);
13531353
}
13541354

13551355
static mi_response_t *mi_b2b_bridge_pmu(const mi_params_t *params,
@@ -1377,7 +1377,7 @@ static mi_response_t *mi_b2b_bridge_4(const mi_params_t *params,
13771377
&prov_media.s, &prov_media.len) < 0)
13781378
return init_mi_param_error();
13791379

1380-
return mi_b2b_bridge(params, flag, &prov_media);
1380+
return mi_b2b_bridge(params, &flag, &prov_media);
13811381
}
13821382

13831383
static inline int internal_mi_print_b2bl_entity_id(mi_item_t *item, b2bl_entity_id_t *c)

modules/b2b_logic/bridging.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int retry_init_bridge(struct sip_msg *msg, b2bl_tuple_t* tuple,
6565
b2bl_entity_id_t *entity, struct b2bl_new_entity *new_entity);
6666

6767
mi_response_t *mi_b2b_bridge(const mi_params_t *params,
68-
int entity_no, str *prov_media)
68+
int *_entity_no, str *prov_media)
6969
{
7070
str key;
7171
b2bl_tuple_t* tuple;
@@ -79,6 +79,9 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params,
7979
b2b_req_data_t req_data;
8080
b2b_rpl_data_t rpl_data;
8181
int ret;
82+
int entity_no;
83+
str entity_str = str_init("");
84+
b2bl_entity_id_t **head;
8285

8386
if (get_mi_string_param(params, "dialog_id", &key.s, &key.len) < 0)
8487
return init_mi_param_error();
@@ -95,8 +98,13 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params,
9598
/* if 'flag' parameter is 1 - >
9699
* means that destination from the current call must be
97100
* bridged to the new destination */
98-
if (entity_no != 0 && entity_no != 1)
99-
return init_mi_error(404, MI_SSTR("Invalid 'flag' parameter"));
101+
if (_entity_no) {
102+
entity_no = *_entity_no;
103+
if (entity_no != 0 && entity_no != 1)
104+
return init_mi_error(404, MI_SSTR("Invalid 'flag' parameter"));
105+
} else {
106+
entity_no = 0;
107+
}
100108

101109
if (prov_media) {
102110
/* parse new uri */
@@ -114,7 +122,7 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params,
114122
}
115123
}
116124

117-
ret = b2bl_get_tuple_key(&key, &hash_index, &local_index);
125+
ret = b2bl_get_tuple_key(&key, &hash_index, &local_index, &entity_str);
118126
if(ret < 0)
119127
{
120128
if (ret == -1)
@@ -143,6 +151,18 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params,
143151
}
144152

145153
local_ctx_tuple = tuple;
154+
if (!_entity_no && entity_str.len) {
155+
old_entity = b2bl_search_entity(tuple, &entity_str, B2B_SERVER, &head);
156+
if (!old_entity) {
157+
old_entity = b2bl_search_entity(tuple, &entity_str, B2B_CLIENT, &head);
158+
if (!old_entity) {
159+
LM_ERR("Can not determine entity to bridge [%.*s]\n",
160+
entity_str.len, entity_str.s);
161+
goto error;
162+
}
163+
}
164+
entity_no = old_entity->no;
165+
}
146166

147167
if (!tuple->bridge_entities[entity_no] ||
148168
tuple->bridge_entities[entity_no]->disconnected)
@@ -2162,7 +2182,7 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no,
21622182
return -1;
21632183
}
21642184

2165-
ret = b2bl_get_tuple_key(key, &hash_index, &local_index);
2185+
ret = b2bl_get_tuple_key(key, &hash_index, &local_index, NULL);
21662186
if(ret < 0)
21672187
{
21682188
if (ret == -1)

modules/b2b_logic/bridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
mi_response_t *mi_b2b_bridge(const mi_params_t *params,
22-
int entity_no, str *prov_media);
22+
int *_entity_no, str *prov_media);
2323
int b2b_script_bridge(struct sip_msg *msg, str *br_ent1_str, str *br_ent2_str,
2424
str *provmedia_uri, struct b2b_bridge_params *params);
2525
int b2b_script_bridge_retry(struct sip_msg *msg, str *new_ent_str);

modules/b2b_logic/doc/b2b_logic_admin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,9 @@ if(is_method("REFER") &amp;&amp; !has_totag()) {
12261226
</listitem>
12271227
<listitem>
12281228
<para><emphasis>flag</emphasis> (optional) - used to specify that the callee must be bridged to the new destination. If not present the caller will be bridged. Possible values are
1229-
'0' or '1'.</para>
1229+
'0' or '1'.</para>. If missing and the <emphasis>b2b_logic key</emphasis> is in the
1230+
<emphasis>callid;from-tag;to-tag</emphasis> form, the module determines the entity
1231+
based on the key used.
12301232
</listitem>
12311233
<listitem>
12321234
<para><emphasis>prov_media_uri</emphasis> (optional) - the uri of a media server able to play

modules/b2b_logic/logic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,7 +3530,7 @@ int script_trigger_scenario(struct sip_msg* msg, str *id, str * params,
35303530

35313531
if (tuple->bridge_flags & B2BL_BR_FLAG_NOTIFY) {
35323532
if (remote_tuple) {
3533-
ret = b2bl_get_tuple_key(remote_tuple, &remote_tuple_hash_index, &local_index);
3533+
ret = b2bl_get_tuple_key(remote_tuple, &remote_tuple_hash_index, &local_index, NULL);
35343534
if(ret < 0)
35353535
{
35363536
if (ret == -1)
@@ -3839,7 +3839,7 @@ int b2bl_get_stats(str* key, b2bl_dlg_stat_t* stat)
38393839
}
38403840

38413841
int b2bl_get_tuple_key(str *key, unsigned int *hash_index,
3842-
unsigned int *local_index)
3842+
unsigned int *local_index, str *entity_str)
38433843
{
38443844
int ret;
38453845
str callid, from_tag, to_tag, *tuple;
@@ -3865,7 +3865,7 @@ int b2bl_get_tuple_key(str *key, unsigned int *hash_index,
38653865
to_tag.len = key->s + key->len - to_tag.s;
38663866

38673867
/* we've got the entity's coordinates, try to find the entity now */
3868-
tuple = b2b_api.get_b2bl_key(&callid, &from_tag, &to_tag, NULL);
3868+
tuple = b2b_api.get_b2bl_key(&callid, &from_tag, &to_tag, entity_str);
38693869
if(!tuple) {
38703870
LM_DBG("cannot find entity [%.*s]\n", key->len, key->s);
38713871
return -2;

0 commit comments

Comments
 (0)