Skip to content

Commit 1fff680

Browse files
committed
b2b_logic: reverse peer when entity not specified
completes/fixes commit f2ef8d391b
1 parent a7197f8 commit 1fff680

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

modules/b2b_logic/bridging.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static b2bl_entity_id_t *bridging_new_client(b2bl_tuple_t* tuple,
6060
str *body, struct sip_msg *msg, int set_maxfwd);
6161
static int bridging_start_old_ent(b2bl_tuple_t* tuple, b2bl_entity_id_t *old_entity,
6262
b2bl_entity_id_t *new_entity, str *provmedia_uri, str *body);
63+
static int b2bl_search_other_entity(b2bl_tuple_t *tuple, str *entity_str);
6364

6465
int retry_init_bridge(struct sip_msg *msg, b2bl_tuple_t* tuple,
6566
b2bl_entity_id_t *entity, struct b2bl_new_entity *new_entity);
@@ -81,7 +82,6 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params,
8182
int ret;
8283
int entity_no;
8384
str entity_str = str_init("");
84-
b2bl_entity_id_t **head;
8585

8686
if (get_mi_string_param(params, "dialog_id", &key.s, &key.len) < 0)
8787
return init_mi_param_error();
@@ -152,16 +152,12 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params,
152152

153153
local_ctx_tuple = tuple;
154154
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-
}
155+
entity_no = b2bl_search_other_entity(tuple, &entity_str);
156+
if (entity_no < 0) {
157+
LM_ERR("Can not determine entity to bridge [%.*s]\n",
158+
entity_str.len, entity_str.s);
159+
goto error;
163160
}
164-
entity_no = old_entity->no;
165161
}
166162

167163
if (!tuple->bridge_entities[entity_no] ||
@@ -2547,3 +2543,23 @@ void b2bl_timer_bridge_retry(unsigned int ticks, void* param)
25472543
it = next;
25482544
}
25492545
}
2546+
2547+
static int b2bl_search_other_entity(b2bl_tuple_t *tuple, str *entity_str)
2548+
{
2549+
b2bl_entity_id_t *entity;
2550+
b2bl_entity_id_t **head;
2551+
2552+
/* search for current entity */
2553+
entity = b2bl_search_entity(tuple, entity_str, B2B_SERVER, &head);
2554+
if (!entity) {
2555+
entity = b2bl_search_entity(tuple, entity_str, B2B_CLIENT, &head);
2556+
if (!entity)
2557+
return -1;
2558+
}
2559+
/* retrieve the peer */
2560+
if (tuple->bridge_entities[0] == entity)
2561+
return 1;
2562+
if (tuple->bridge_entities[1] == entity)
2563+
return 0;
2564+
return -1;
2565+
}

0 commit comments

Comments
 (0)