Skip to content

Commit

Permalink
ua,call: prevent double ua_accept
Browse files Browse the repository at this point in the history
API function ua_accept() can be called by multiple modules which handle
the shortly added UA_EVENT_SIPSESS_CONN. This commit prevents that
multiple call/sipsess/sip_dialog objects are created for a single SIP
INVITE message
  • Loading branch information
cspiel1 committed Dec 4, 2024
1 parent 4c0bee6 commit 3f38e92
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/baresip.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ bool call_has_video(const struct call *call);
bool call_early_video_available(const struct call *call);
bool call_refresh_allowed(const struct call *call);
bool call_ack_pending(const struct call *call);
bool call_sess_cmp(const struct call *call, const struct sip_msg *msg);
int call_transfer(struct call *call, const char *uri);
int call_replace_transfer(struct call *target_call, struct call *source_call);
int call_status(struct re_printf *pf, const struct call *call);
Expand Down Expand Up @@ -963,6 +964,7 @@ int ua_call_alloc(struct call **callp, struct ua *ua,
struct call *xcall, const char *local_uri,
bool use_rtp);
struct call *ua_find_call_state(const struct ua *ua, enum call_state st);
struct call *ua_find_call_msg(struct ua *ua, const struct sip_msg *msg);
int ua_raise(struct ua *ua);
int ua_set_autoanswer_value(struct ua *ua, const char *value);
void ua_add_extension(struct ua *ua, const char *extension);
Expand Down
6 changes: 6 additions & 0 deletions src/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,12 @@ int call_accept(struct call *call, struct sipsess_sock *sess_sock,
}


bool call_sess_cmp(const struct call *call, const struct sip_msg *msg)
{
return sipsess_msg_equal(call->sess, msg);
}


static void delayed_answer_handler(void *arg)
{
struct call *call = arg;
Expand Down
21 changes: 21 additions & 0 deletions src/ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,22 @@ struct call *ua_find_active_call(struct ua *ua)
}


struct call *ua_find_call_msg(struct ua *ua, const struct sip_msg *msg)
{
if (!ua || !msg)
return NULL;

struct le *le = NULL;
for (le = list_tail(&ua->calls); le; le = le->prev) {
struct call *call = le->data;
if (call_sess_cmp(call, msg))
break;
}

return le ? le->data : NULL;
}


static void call_event_handler(struct call *call, enum call_event ev,
const char *str, void *arg)
{
Expand Down Expand Up @@ -786,6 +802,11 @@ int ua_accept(struct ua *ua, const struct sip_msg *msg)
if (!ua || !msg)
return EINVAL;

if (ua_find_call_msg(ua, msg)) {
warning("ua: call was already accepted\n");
return EINVAL;
}

err = pl_strdup(&to_uri, &msg->to.auri);
if (err)
goto error;
Expand Down

0 comments on commit 3f38e92

Please sign in to comment.