Skip to content

Commit

Permalink
dialog: fix rtags of forking INVITE with 100rel
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianfridrich committed Sep 7, 2023
1 parent 9f69a23 commit 19b4512
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 11 deletions.
47 changes: 44 additions & 3 deletions src/sip/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ int sip_dialog_update(struct sip_dialog *dlg, const struct sip_msg *msg)
{
const struct sip_hdr *contact;
struct sip_addr addr;
char *uri;
struct route_enc renc;
struct pl pl;
char *uri, *rtag = NULL;
int err;

if (!dlg || !msg)
Expand All @@ -475,14 +477,46 @@ int sip_dialog_update(struct sip_dialog *dlg, const struct sip_msg *msg)
if (sip_addr_decode(&addr, &contact->val))
return EBADMSG;

renc.mb = mbuf_alloc(512);
if (!renc.mb)
return ENOMEM;

err = pl_strdup(&uri, &addr.auri);
if (err)
return err;

if (dlg->route.scheme.p == dlg->uri) {
err = pl_strdup(&rtag, msg->req ? &msg->from.tag : &msg->to.tag);
if (err)
goto out;

renc.end = 0;

err |= sip_msg_hdr_apply(msg, msg->req, SIP_HDR_RECORD_ROUTE,
record_route_handler, &renc) ? ENOMEM : 0;
err |= mbuf_printf(renc.mb, "To: %r\r\n",
msg->req ? &msg->from.val : &msg->to.val);

dlg->mb->pos = dlg->cpos;
err |= mbuf_write_mem(renc.mb, mbuf_buf(dlg->mb),
mbuf_get_left(dlg->mb));
dlg->mb->pos = 0;

if (err)
goto out;

renc.mb->pos = 0;

if (renc.end) {
pl.p = (const char *)mbuf_buf(renc.mb) + ROUTE_OFFSET;
pl.l = renc.end - ROUTE_OFFSET;
err = sip_addr_decode(&addr, &pl);
if (err)
goto out;

dlg->route = addr.uri;
}
else {
struct uri tmp;
struct pl pl;

pl_set_str(&pl, uri);
err = uri_decode(&tmp, &pl);
Expand All @@ -492,11 +526,18 @@ int sip_dialog_update(struct sip_dialog *dlg, const struct sip_msg *msg)
dlg->route = tmp;
}

mem_deref(dlg->mb);
mem_deref(dlg->uri);
mem_deref(dlg->rtag);

dlg->mb = mem_ref(renc.mb);
dlg->uri = mem_ref(uri);
dlg->rtag = mem_ref(rtag);

out:
mem_deref(renc.mb);
mem_deref(uri);
mem_deref(rtag);

return err;
}
Expand Down
Loading

0 comments on commit 19b4512

Please sign in to comment.