Skip to content

Commit

Permalink
sipreg: refactor respons_handle else optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jun 20, 2024
1 parent 5628b79 commit 19854fe
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions src/sipreg/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)
{
const struct sip_hdr *minexp;
struct sipreg *reg = arg;
uint16_t last_scode = reg->ls.last_scode;

reg->wait = failwait(reg->failc + 1);
if (err || !msg || sip_request_loops(&reg->ls, msg->scode)) {
Expand All @@ -215,54 +214,54 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)

if (reg->regid > 0 && !reg->terminated && !reg->ka)
start_outbound(reg, msg);
goto out;
}
else {
if (reg->terminated && !reg->registered)
goto out;

switch (msg->scode) {

case 401:
case 407:
if (reg->ls.failc > 1 && last_scode == msg->scode) {
reg->failc++;
goto out;
}
if (reg->terminated && !reg->registered)
goto out;

sip_auth_reset(reg->auth);
err = sip_auth_authenticate(reg->auth, msg);
if (err) {
err = (err == EAUTH) ? 0 : err;
break;
}
switch (msg->scode) {

err = request(reg, false);
if (err)
break;
case 401:
case 407:
if (reg->ls.failc > 1 && reg->ls.last_scode == msg->scode) {
reg->failc++;
goto out;
}

return;
sip_auth_reset(reg->auth);
err = sip_auth_authenticate(reg->auth, msg);
if (err) {
err = (err == EAUTH) ? 0 : err;
break;
}

case 403:
sip_auth_reset(reg->auth);
err = request(reg, false);
if (err)
break;

case 423:
minexp = sip_msg_hdr(msg, SIP_HDR_MIN_EXPIRES);
if (!minexp || !pl_u32(&minexp->val) || !reg->expires)
break;
return;

reg->expires = pl_u32(&minexp->val);
case 403:
sip_auth_reset(reg->auth);
break;

err = request(reg, false);
if (err)
break;
case 423:
minexp = sip_msg_hdr(msg, SIP_HDR_MIN_EXPIRES);
if (!minexp || !pl_u32(&minexp->val) || !reg->expires)
break;

return;
}
reg->expires = pl_u32(&minexp->val);

++reg->failc;
err = request(reg, false);
if (err)
break;

return;
}

++reg->failc;

out:
if (!reg->expires) {
if (msg && msg->scode >= 400 && msg->scode < 500)
Expand Down

0 comments on commit 19854fe

Please sign in to comment.