Skip to content

Commit

Permalink
b2b_entities: provide dlginfo for entity_delete
Browse files Browse the repository at this point in the history
Each module that uses b2b_entities, should duplicate the dlginfo
structure and pass it to the entity_delete API call, otherwise wrong
entities might be deleted due to mismatches

(cherry picked from commit ce19581)
  • Loading branch information
razvancrainea committed Aug 16, 2022
1 parent 470d780 commit 43f0030
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
31 changes: 31 additions & 0 deletions modules/b2b_entities/b2be_load.h
Expand Up @@ -187,4 +187,35 @@ static inline int load_b2b_api( struct b2b_api *b2b_api)
return load_b2b( b2b_api );
}

static inline b2b_dlginfo_t *b2b_dup_dlginfo(b2b_dlginfo_t *info)
{
b2b_dlginfo_t* dlg = NULL;
int size;

size = sizeof(b2b_dlginfo_t) + info->callid.len;
if (info->totag.s)
size += info->totag.len;
if (info->fromtag.s)
size += info->fromtag.len;
dlg = shm_malloc(size);
if (!dlg)
return NULL;
memset(dlg, 0, size);

dlg->callid.s = (char *)(dlg + 1);
dlg->callid.len = info->callid.len;
memcpy(dlg->callid.s, info->callid.s, dlg->callid.len);
if (info->totag.s) {
dlg->totag.len = info->totag.len;
dlg->totag.s = dlg->callid.s + dlg->callid.len;
memcpy(dlg->totag.s, info->totag.s, dlg->totag.len);
}
if (info->fromtag.s) {
dlg->fromtag.len = info->fromtag.len;
dlg->fromtag.s = dlg->callid.s + dlg->callid.len + dlg->totag.len;
memcpy(dlg->fromtag.s, info->fromtag.s, dlg->fromtag.len);
}
return dlg;
}

#endif
15 changes: 9 additions & 6 deletions modules/media_exchange/media_exchange.c
Expand Up @@ -332,7 +332,7 @@ static int handle_media_fork_to_uri(struct media_session_leg *msl, struct socket
if (shm_str_dup(&msl->b2b_key, b2b_key) < 0) {
LM_ERR("could not copy b2b client key\n");
/* key is not yet stored, so cannot be deleted */
media_b2b.entity_delete(B2B_CLIENT, b2b_key, NULL, 1, 1);
media_b2b.entity_delete(B2B_CLIENT, b2b_key, msl->dlginfo, 1, 1);
goto release;
}
msl->params = mf;
Expand Down Expand Up @@ -532,7 +532,7 @@ static int media_fork_from_call(struct sip_msg *msg, str *callid, int leg, int *
if (shm_str_dup(&msl->b2b_key, b2b_key) < 0) {
LM_ERR("could not copy b2b server key for callid %.*s\n", callid->len, callid->s);
/* key is not yet stored, so cannot be deleted */
media_b2b.entity_delete(B2B_SERVER, b2b_key, NULL, 1, 1);
media_b2b.entity_delete(B2B_SERVER, b2b_key, msl->dlginfo, 1, 1);
goto destroy;
}
msl->b2b_entity = B2B_SERVER;
Expand Down Expand Up @@ -613,7 +613,7 @@ static int handle_media_exchange_from_uri(struct socket_info *si, struct dlg_cel
if (shm_str_dup(&msl->b2b_key, b2b_key) < 0) {
LM_ERR("could not copy b2b client key\n");
/* key is not yet stored, so cannot be deleted */
media_b2b.entity_delete(B2B_CLIENT, b2b_key, NULL, 1, 1);
media_b2b.entity_delete(B2B_CLIENT, b2b_key, msl->dlginfo, 1, 1);
goto unref;
}
msl->b2b_entity = B2B_CLIENT;
Expand Down Expand Up @@ -805,7 +805,7 @@ static int media_exchange_to_call(struct sip_msg *msg, str *callid, int leg, int
if (shm_str_dup(&msl->b2b_key, b2b_key) < 0) {
LM_ERR("could not copy b2b server key for callid %.*s\n", callid->len, callid->s);
/* key is not yet stored, so cannot be deleted */
media_b2b.entity_delete(B2B_SERVER, b2b_key, NULL, 1, 1);
media_b2b.entity_delete(B2B_SERVER, b2b_key, msl->dlginfo, 1, 1);
goto destroy;
}
msl->b2b_entity = B2B_SERVER;
Expand Down Expand Up @@ -1512,9 +1512,12 @@ static int b2b_media_notify(struct sip_msg *msg, str *key, int type, void *param

static int b2b_media_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* info)
{
/* TODO: copy from info fromtag, totag, callid
struct media_session_leg *msl = *(struct media_session_leg **)((str *)key)->s;
*/
msl->dlginfo = b2b_dup_dlginfo(info);
if (!msl->dlginfo) {
LM_ERR("could not duplicate b2be dialog info!\n");
return -1;
}
return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion modules/media_exchange/media_sessions.c
Expand Up @@ -73,13 +73,15 @@ void media_session_leg_free(struct media_session_leg *msl)
msl, msl->ms);
}
if (msl->b2b_key.s) {
media_b2b.entity_delete(msl->b2b_entity, &msl->b2b_key, NULL, 1, 1);
media_b2b.entity_delete(msl->b2b_entity, &msl->b2b_key, msl->dlginfo, 1, 1);
shm_free(msl->b2b_key.s);
msl->b2b_key.s = NULL;
}
LM_DBG("releasing media_session_leg=%p\n", msl);
if (msl->params && msl->type == MEDIA_SESSION_TYPE_FORK)
media_forks_free(msl->params);
if (msl->dlginfo)
shm_free(msl->dlginfo);
shm_free(msl);
}

Expand Down
1 change: 1 addition & 0 deletions modules/media_exchange/media_sessions.h
Expand Up @@ -45,6 +45,7 @@ struct media_session_leg {
str b2b_key;
int nohold;
gen_lock_t lock;
b2b_dlginfo_t *dlginfo;
enum b2b_entity_type b2b_entity;
struct media_session_leg *next;
void *params;
Expand Down

0 comments on commit 43f0030

Please sign in to comment.