Skip to content

Commit

Permalink
b2b*: consider dlginfo for requests an replies as well
Browse files Browse the repository at this point in the history
(cherry picked from commit 7aa2007)
  • Loading branch information
razvancrainea committed Aug 22, 2022
1 parent de731a2 commit a518e41
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 80 deletions.
33 changes: 19 additions & 14 deletions modules/b2b_entities/b2be_load.h
Expand Up @@ -187,35 +187,40 @@ 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)
static inline b2b_dlginfo_t *b2b_new_dlginfo(str *callid, str *fromtag, str *totag)
{
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;
size = sizeof(b2b_dlginfo_t) + callid->len;
if (totag && totag->s)
size += totag->len;
if (fromtag && fromtag->s)
size += 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->callid.len = callid->len;
memcpy(dlg->callid.s, callid->s, callid->len);
if (totag->s) {
dlg->totag.len = totag->len;
dlg->totag.s = dlg->callid.s + dlg->callid.len;
memcpy(dlg->totag.s, info->totag.s, dlg->totag.len);
memcpy(dlg->totag.s, totag->s, totag->len);
}
if (info->fromtag.s) {
dlg->fromtag.len = info->fromtag.len;
if (fromtag->s) {
dlg->fromtag.len = fromtag->len;
dlg->fromtag.s = dlg->callid.s + dlg->callid.len + dlg->totag.len;
memcpy(dlg->fromtag.s, info->fromtag.s, dlg->fromtag.len);
memcpy(dlg->fromtag.s, fromtag->s, fromtag->len);
}
return dlg;
}

static inline b2b_dlginfo_t *b2b_dup_dlginfo(b2b_dlginfo_t *info)
{
return b2b_new_dlginfo(&info->callid, &info->fromtag, &info->totag);
}

#endif
2 changes: 2 additions & 0 deletions modules/media_exchange/media_sessions.c
Expand Up @@ -250,6 +250,7 @@ int media_session_req(struct media_session_leg *msl, const char *method, str *bo
memset(&req, 0, sizeof(req));
req.et = msl->b2b_entity;
req.b2b_key = &msl->b2b_key;
req.dlginfo = msl->dlginfo;
req.method = &m;
req.body = body;
if (body)
Expand Down Expand Up @@ -277,6 +278,7 @@ int media_session_rpl(struct media_session_leg *msl,
reply_data.code = code;
reply_data.text = reason;
reply_data.body = body;
reply_data.dlginfo = msl->dlginfo;
if (body)
reply_data.extra_headers = &content_type_sdp_hdr;

Expand Down
48 changes: 10 additions & 38 deletions modules/siprec/siprec_logic.c
Expand Up @@ -124,6 +124,7 @@ static void srec_dlg_end(struct dlg_cell *dlg, int type, struct dlg_cb_params *_
req.et = B2B_CLIENT;
req.b2b_key = &ss->b2b_key;
req.method = &bye;
req.dlginfo = ss->dlginfo;
req.no_cb = 1; /* do not call callback */

if (srec_b2b.send_request(&req) < 0)
Expand Down Expand Up @@ -243,6 +244,7 @@ static int srec_b2b_notify(struct sip_msg *msg, str *key, int type, void *param,
req.et = B2B_CLIENT;
req.b2b_key = &ss->b2b_key;
req.method = &ack;
req.dlginfo = ss->dlginfo;
req.no_cb = 1; /* do not call callback */

if (srec_b2b.send_request(&req) < 0) {
Expand Down Expand Up @@ -281,6 +283,7 @@ static int srec_b2b_notify(struct sip_msg *msg, str *key, int type, void *param,
req.et = B2B_CLIENT;
req.b2b_key = &ss->b2b_key;
req.method = &bye;
req.dlginfo = ss->dlginfo;
req.no_cb = 1; /* do not call callback */

if (srec_b2b.send_request(&req) < 0)
Expand Down Expand Up @@ -310,7 +313,6 @@ int srec_restore_callback(struct src_sess *sess)

static int srec_b2b_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* info)
{
char *tmp;
struct src_sess *ss;

ss = *(struct src_sess **)key->s;
Expand All @@ -319,32 +321,11 @@ static int srec_b2b_confirm(str* key, str* entity_key, int src, b2b_dlginfo_t* i
entity_key->len, entity_key->s);
return -1;
}
tmp = shm_malloc(info->fromtag.len);
if (!tmp) {
LM_ERR("cannot allocate dialog info fromtag!\n");
return -1;
}
ss->b2b_fromtag.s = tmp;
ss->b2b_fromtag.len = info->fromtag.len;
memcpy(ss->b2b_fromtag.s, info->fromtag.s, ss->b2b_fromtag.len);

tmp = shm_malloc(info->totag.len);
if (!tmp) {
LM_ERR("cannot allocate dialog info totag!\n");
return -1;
}
ss->b2b_totag.s = tmp;
ss->b2b_totag.len = info->totag.len;
memcpy(ss->b2b_totag.s, info->totag.s, ss->b2b_totag.len);

tmp = shm_malloc(info->callid.len);
if (!tmp) {
LM_ERR("cannot allocate dialog info callid!\n");
ss->dlginfo = b2b_dup_dlginfo(info);
if (!ss->dlginfo) {
LM_ERR("could not duplicate b2b dialog info!\n");
return -1;
}
ss->b2b_callid.s = tmp;
ss->b2b_callid.len = info->callid.len;
memcpy(ss->b2b_callid.s, info->callid.s, ss->b2b_callid.len);
return 0;
}

Expand Down Expand Up @@ -498,6 +479,7 @@ static int src_update_recording(struct sip_msg *msg, struct src_sess *sess, int
goto error;
}
req.body = &body;
req.dlginfo = sess->dlginfo;

if (srec_b2b.send_request(&req) < 0)
LM_ERR("Cannot end recording session for key %.*s\n",
Expand Down Expand Up @@ -546,23 +528,13 @@ void tm_start_recording(struct cell *t, int type, struct tmcb_params *ps)

void srec_logic_destroy(struct src_sess *sess)
{
b2b_dlginfo_t info;
if (!sess->b2b_key.s)
return;
shm_free(sess->b2b_key.s);

info.fromtag = sess->b2b_fromtag;
info.totag = sess->b2b_totag;
info.callid = sess->b2b_callid;
srec_b2b.entity_delete(B2B_CLIENT, &sess->b2b_key,
(info.callid.s ? &info: NULL), 1, 1);
if (sess->b2b_fromtag.s)
shm_free(sess->b2b_fromtag.s);
if (sess->b2b_totag.s)
shm_free(sess->b2b_totag.s);
if (sess->b2b_callid.s)
shm_free(sess->b2b_callid.s);
sess->b2b_callid.s = sess->b2b_totag.s = sess->b2b_fromtag.s = NULL;
srec_b2b.entity_delete(B2B_CLIENT, &sess->b2b_key, sess->dlginfo, 1, 1);
if (sess->dlginfo)
shm_free(sess->dlginfo);
sess->b2b_key.s = NULL;
}

45 changes: 20 additions & 25 deletions modules/siprec/siprec_sess.c
Expand Up @@ -251,6 +251,7 @@ void srec_loaded_callback(struct dlg_cell *dlg, int type,
struct socket_info *si;
int p, port, proto, c, label, medianum;
int p_type;
str from_tag, to_tag;

if (!dlg) {
LM_ERR("null dialog - cannot fetch siprec info!\n");
Expand Down Expand Up @@ -331,30 +332,18 @@ void srec_loaded_callback(struct dlg_cell *dlg, int type,
}
memcpy(sess->b2b_key.s, tmp.s, tmp.len);
sess->b2b_key.len = tmp.len;
SIPREC_BIN_POP(str, &from_tag);
SIPREC_BIN_POP(str, &to_tag);
SIPREC_BIN_POP(str, &tmp);
sess->b2b_fromtag.s = shm_malloc(tmp.len);
if (!sess->b2b_fromtag.s) {
LM_ERR("cannot allocate memory for b2b_fromtag!\n");
goto error;
}
memcpy(sess->b2b_fromtag.s, tmp.s, tmp.len);
sess->b2b_fromtag.len = tmp.len;
SIPREC_BIN_POP(str, &tmp);
sess->b2b_totag.s = shm_malloc(tmp.len);
if (!sess->b2b_totag.s) {
LM_ERR("cannot allocate memory for b2b_totag!\n");
goto error;
}
memcpy(sess->b2b_totag.s, tmp.s, tmp.len);
sess->b2b_totag.len = tmp.len;
SIPREC_BIN_POP(str, &tmp);
sess->b2b_callid.s = shm_malloc(tmp.len);
if (!sess->b2b_callid.s) {
LM_ERR("cannot allocate memory for b2b_callid!\n");
goto error;

if (tmp.len) {
sess->dlginfo = b2b_new_dlginfo(&tmp, &from_tag, &to_tag);
if (!sess->dlginfo) {
LM_ERR("could not create b2b dlginfo for %.*s/%.*s/%.*s!\n",
tmp.len, tmp.s, from_tag.len, from_tag.s, to_tag.len, to_tag.s);
goto error;
}
}
memcpy(sess->b2b_callid.s, tmp.s, tmp.len);
sess->b2b_callid.len = tmp.len;

SIPREC_BIN_POP(int, &p);
for (; p > 0; p--) {
Expand Down Expand Up @@ -483,9 +472,15 @@ void srec_dlg_write_callback(struct dlg_cell *dlg, int type,
SIPREC_BIN_PUSH(str, &empty);
SIPREC_BIN_PUSH(str, SIPREC_SERIALIZE(ss->uuid));
SIPREC_BIN_PUSH(str, &ss->b2b_key);
SIPREC_BIN_PUSH(str, &ss->b2b_fromtag);
SIPREC_BIN_PUSH(str, &ss->b2b_totag);
SIPREC_BIN_PUSH(str, &ss->b2b_callid);
if (ss->dlginfo) {
SIPREC_BIN_PUSH(str, &ss->dlginfo->fromtag);
SIPREC_BIN_PUSH(str, &ss->dlginfo->totag);
SIPREC_BIN_PUSH(str, &ss->dlginfo->callid);
} else {
SIPREC_BIN_PUSH(str, &empty);
SIPREC_BIN_PUSH(str, &empty);
SIPREC_BIN_PUSH(str, &empty);
}
SIPREC_BIN_PUSH(int, ss->participants_no);

for (p = 0; p < ss->participants_no; p++) {
Expand Down
5 changes: 2 additions & 3 deletions modules/siprec/siprec_sess.h
Expand Up @@ -28,6 +28,7 @@

#include "siprec_body.h"
#include "../dialog/dlg_load.h"
#include "../b2b_entities/b2be_load.h"
#include "../tm//tm_load.h"
#include "../../ut.h"

Expand Down Expand Up @@ -97,9 +98,7 @@ struct src_sess {

/* b2b */
str b2b_key;
str b2b_fromtag;
str b2b_totag;
str b2b_callid;
b2b_dlginfo_t *dlginfo;
};

void src_unref_session(void *p);
Expand Down

0 comments on commit a518e41

Please sign in to comment.