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 adbefdf commit 9ee9046
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 90 deletions.
33 changes: 19 additions & 14 deletions modules/b2b_entities/b2be_load.h
Expand Up @@ -194,35 +194,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
25 changes: 15 additions & 10 deletions modules/b2b_sdp_demux/b2b_sdp_demux.c
Expand Up @@ -198,7 +198,8 @@ struct b2b_sdp_stream {
struct list_head ordered;
};
static int b2b_sdp_ack(int type, str *key);
static int b2b_sdp_reply(str *b2b_key, int type, int method, int code, str *body);
static int b2b_sdp_reply(str *b2b_key, b2b_dlginfo_t *dlginfo,
int type, int method, int code, str *body);
static int b2b_sdp_client_sync(struct b2b_sdp_client *client, str *body);
static struct b2b_sdp_stream *b2b_sdp_stream_raw_new(struct b2b_sdp_client *client,
str *disabled_body, int index, int client_index);
Expand Down Expand Up @@ -413,6 +414,7 @@ static void b2b_sdp_client_terminate(struct b2b_sdp_client *client, str *key)
req_data.no_cb = 1; /* do not call callback */
req_data.et = B2B_CLIENT;
req_data.b2b_key = key;
req_data.dlginfo = client->dlginfo;
req_data.method = &method;
b2b_api.send_request(&req_data);
LM_INFO("[%.*s] client request %.*s sent\n", key->len, key->s, method.len, method.s);
Expand Down Expand Up @@ -897,7 +899,7 @@ static int b2b_sdp_client_reinvite(struct sip_msg *msg, struct b2b_sdp_client *c
}
}
if (code)
b2b_sdp_reply(&client->b2b_key, B2B_CLIENT, msg->REQ_METHOD, code, rbody);
b2b_sdp_reply(&client->b2b_key, client->dlginfo, B2B_CLIENT, msg->REQ_METHOD, code, rbody);
return ret;
}

Expand Down Expand Up @@ -954,7 +956,7 @@ static int b2b_sdp_client_bye(struct sip_msg *msg, struct b2b_sdp_client *client
struct b2b_sdp_ctx *ctx = client->ctx;

b2b_sdp_client_remove(client);
b2b_sdp_reply(&client->b2b_key, B2B_CLIENT, METHOD_BYE, 200, NULL);
b2b_sdp_reply(&client->b2b_key, client->dlginfo, B2B_CLIENT, METHOD_BYE, 200, NULL);
b2b_sdp_client_release(client, 1);
b2b_api.entity_delete(B2B_CLIENT, &client->b2b_key, client->dlginfo, 1, 1);
lock_get(&ctx->lock);
Expand Down Expand Up @@ -1007,7 +1009,8 @@ static int b2b_sdp_client_bye(struct sip_msg *msg, struct b2b_sdp_client *client
return 0;
}

static int b2b_sdp_reply(str *b2b_key, int type, int method, int code, str *body)
static int b2b_sdp_reply(str *b2b_key, b2b_dlginfo_t *dlginfo,
int type, int method, int code, str *body)
{
char *etype = (type==B2B_CLIENT?"client":"server");
b2b_rpl_data_t reply_data;
Expand All @@ -1021,6 +1024,7 @@ static int b2b_sdp_reply(str *b2b_key, int type, int method, int code, str *body
reply_data.code = code;
reply_data.text = &text;
reply_data.body = body;
reply_data.dlginfo = dlginfo;
if (body)
reply_data.extra_headers = &content_type_sdp_hdr;
LM_INFO("[%.*s] %s reply %d sent\n", b2b_key->len, b2b_key->s, etype, code);
Expand Down Expand Up @@ -1229,11 +1233,11 @@ static int b2b_sdp_client_reply_invite(struct sip_msg *msg, struct b2b_sdp_clien
/* avoid sending reply under lock */
if (body) {
/* we are done - answer the call */
if (b2b_sdp_reply(&ctx->b2b_key, B2B_SERVER, METHOD_INVITE, 200, body) < 0)
if (b2b_sdp_reply(&ctx->b2b_key, NULL, B2B_SERVER, METHOD_INVITE, 200, body) < 0)
LM_CRIT("could not answer B2B call!\n");
pkg_free(body->s);
} else if (ret == -2) {
b2b_sdp_reply(&ctx->b2b_key, B2B_SERVER, METHOD_INVITE, 503, NULL);
b2b_sdp_reply(&ctx->b2b_key, NULL, B2B_SERVER, METHOD_INVITE, 503, NULL);
}
if (ret < 0 && ctx->clients_no == 0) {
/* no more remaining clients - terminate the entity as well */
Expand Down Expand Up @@ -1426,7 +1430,7 @@ static int b2b_sdp_server_reply_invite(struct sip_msg *msg, struct b2b_sdp_ctx *
code = msg->REPLY_STATUS;
}
lock_release(&client->ctx->lock);
b2b_sdp_reply(&client->b2b_key, B2B_CLIENT, METHOD_INVITE, code, body);
b2b_sdp_reply(&client->b2b_key, client->dlginfo, B2B_CLIENT, METHOD_INVITE, code, body);
if (body)
free_sdp_content(&sdp);
lock_get(&client->ctx->lock);
Expand All @@ -1443,7 +1447,7 @@ static int b2b_sdp_server_reply_bye(struct sip_msg *msg, struct b2b_sdp_ctx *ctx

static int b2b_sdp_server_bye(struct sip_msg *msg, struct b2b_sdp_ctx *ctx)
{
b2b_sdp_reply(&ctx->b2b_key, B2B_SERVER, msg->REQ_METHOD, 200, NULL);
b2b_sdp_reply(&ctx->b2b_key, NULL, B2B_SERVER, msg->REQ_METHOD, 200, NULL);
b2b_sdp_ctx_release(ctx, 1);
return 0;
}
Expand Down Expand Up @@ -1480,6 +1484,7 @@ static int b2b_sdp_server_invite(struct sip_msg *msg, struct b2b_sdp_ctx *ctx)
req_data.et = B2B_CLIENT;
req_data.b2b_key = &client->b2b_key;
req_data.method = &method;
req_data.dlginfo = client->dlginfo;
req_data.body = &client->body;
LM_INFO("[%.*s] client request INVITE sent\n", client->b2b_key.len, client->b2b_key.s);
if (b2b_api.send_request(&req_data) < 0)
Expand All @@ -1490,7 +1495,7 @@ static int b2b_sdp_server_invite(struct sip_msg *msg, struct b2b_sdp_ctx *ctx)

return 0;
error:
b2b_sdp_reply(&ctx->b2b_key, B2B_SERVER, METHOD_INVITE, 606, NULL);
b2b_sdp_reply(&ctx->b2b_key, NULL, B2B_SERVER, METHOD_INVITE, 606, NULL);
return -1;
}

Expand All @@ -1510,7 +1515,7 @@ static int b2b_sdp_server_notify(struct sip_msg *msg, str *key, int type,
if (ctx->pending_no) {
lock_release(&ctx->lock);
LM_INFO("we still have pending clients!\n");
b2b_sdp_reply(&ctx->b2b_key, B2B_SERVER, msg->REQ_METHOD, 491, NULL);
b2b_sdp_reply(&ctx->b2b_key, NULL, B2B_SERVER, msg->REQ_METHOD, 491, NULL);
return -1;
}
lock_release(&ctx->lock);
Expand Down
2 changes: 2 additions & 0 deletions modules/media_exchange/media_sessions.c
Expand Up @@ -251,6 +251,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 @@ -278,6 +279,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
49 changes: 11 additions & 38 deletions modules/siprec/siprec_logic.c
Expand Up @@ -134,6 +134,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 @@ -209,6 +210,7 @@ int srec_reply(struct src_sess *ss, int method, int code, str *body)
reply_data.code = code;
reply_data.text = &reason;
reply_data.body = body;
reply_data.dlginfo = ss->dlginfo;
if (body)
reply_data.extra_headers = &content_type_sdp_hdr;

Expand Down Expand Up @@ -289,6 +291,7 @@ static int srec_b2b_notify(struct sip_msg *msg, str *key, int type,
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 @@ -332,6 +335,7 @@ static int srec_b2b_notify(struct sip_msg *msg, str *key, int type,
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 @@ -370,7 +374,6 @@ int srec_restore_callback(struct src_sess *sess)

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 *)param;
Expand All @@ -379,32 +382,11 @@ static int srec_b2b_confirm(str* logic_key, str* entity_key, int src, b2b_dlginf
entity_key->len, entity_key->s);
return -1;
}
tmp = shm_malloc(info->fromtag.len);
if (!tmp) {
LM_ERR("cannot allocate dialog info fromtag!\n");
ss->dlginfo = b2b_dup_dlginfo(info);
if (!ss->dlginfo) {
LM_ERR("could not duplicate b2b dialog info!\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");
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 @@ -566,6 +548,7 @@ static void srs_send_update_invite(struct src_sess *sess, str *body)
req.b2b_key = &sess->b2b_key;
req.method = &inv;
req.extra_headers = &extra_headers;
req.dlginfo = sess->dlginfo;
req.body = body;

if (srec_b2b.send_request(&req) < 0)
Expand Down Expand Up @@ -643,26 +626,16 @@ 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);

if (sess->initial_sdp.s)
shm_free(sess->initial_sdp.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;
}

Expand Down
45 changes: 20 additions & 25 deletions modules/siprec/siprec_sess.c
Expand Up @@ -262,6 +262,7 @@ void srec_loaded_callback(struct dlg_cell *dlg, int type,
rtp_ctx rtp;
int p_type;
int flags;
str from_tag, to_tag;

if (!dlg) {
LM_ERR("null dialog - cannot fetch siprec info!\n");
Expand Down Expand Up @@ -344,30 +345,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 @@ -498,9 +487,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 @@ -114,9 +115,7 @@ struct src_sess {

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

#ifdef DBG_SIPREC_HIST
struct struct_hist *hist;
Expand Down

0 comments on commit 9ee9046

Please sign in to comment.