Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strans/accept: fix cancel/rejection #423

Merged
merged 4 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/sip/strans.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,13 @@ int sip_strans_reply(struct sip_strans **stp, struct sip *sip,
}
else if (scode < 300) {
tmr_start(&st->tmr, 64 * SIP_T1, tmr_handler, st);
st->state = ACCEPTED;
if (pl_strcmp(&msg->met, "PRACK"))
st->state = ACCEPTED;
maximilianfridrich marked this conversation as resolved.
Show resolved Hide resolved
}
else {
tmr_start(&st->tmr, 64 * SIP_T1, tmr_handler, st);
st->state = COMPLETED;
if (pl_strcmp(&msg->met, "PRACK"))
st->state = COMPLETED;
maximilianfridrich marked this conversation as resolved.
Show resolved Hide resolved

if (!sip_transp_reliable(st->msg->tp))
tmr_start(&st->tmrg, SIP_T1,
Expand Down
26 changes: 18 additions & 8 deletions src/sipsess/accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ static void cancel_handler(void *arg)
{
struct sipsess *sess = arg;

(void)sip_treply(&sess->st, sess->sip, sess->msg,
487, "Request Terminated");
if (!sess->st && !sess->awaiting_answer && !sess->established)
(void)sip_reply(sess->sip, sess->msg, 487,
"Request Terminated");
else
(void)sip_treply(&sess->st, sess->sip, sess->msg, 487,
"Request Terminated");

sess->peerterm = true;

Expand Down Expand Up @@ -197,9 +201,8 @@ int sipsess_answer(struct sipsess *sess, uint16_t scode, const char *reason,
va_list ap;
int err;

if (!sess || (!sess->st
&& (sess->established || sess->awaiting_answer))
|| !sess->msg || scode < 200 || scode > 299)
if (!sess || !sess->msg || scode < 200 || scode > 299
|| (!sess->st && (sess->established || sess->awaiting_answer)))
return EINVAL;

va_start(ap, fmt);
Expand Down Expand Up @@ -227,12 +230,19 @@ int sipsess_reject(struct sipsess *sess, uint16_t scode, const char *reason,
va_list ap;
int err;

if (!sess || !sess->st || !sess->msg || scode < 300)
if (!sess || !sess->msg || scode < 300
|| (!sess->st && (sess->established || sess->awaiting_answer)))
return EINVAL;
maximilianfridrich marked this conversation as resolved.
Show resolved Hide resolved
maximilianfridrich marked this conversation as resolved.
Show resolved Hide resolved

va_start(ap, fmt);
err = sip_treplyf(&sess->st, NULL, sess->sip, sess->msg, false,
scode, reason, fmt ? "%v" : NULL, fmt, &ap);

if (!sess->st && !sess->awaiting_answer && !sess->established)
err = sip_replyf(sess->sip, sess->msg, scode, reason,
fmt ? "%v" : NULL, fmt, &ap);
else
err = sip_treplyf(&sess->st, NULL, sess->sip, sess->msg, false,
scode, reason, fmt ? "%v" : NULL, fmt, &ap);

maximilianfridrich marked this conversation as resolved.
Show resolved Hide resolved
va_end(ap);

return err;
Expand Down