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

sipreg: make re-register interval configurable #13

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions include/re_sipreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ int sipreg_register(struct sipreg **regp, struct sip *sip, const char *reg_uri,
sip_resp_h *resph, void *arg,
const char *params, const char *fmt, ...);

int sipreg_set_rwait(struct sipreg *reg, uint32_t rwait);

const struct sa *sipreg_laddr(const struct sipreg *reg);
25 changes: 23 additions & 2 deletions src/sipreg/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct sipreg {
void *arg;
uint32_t expires;
uint32_t failc;
uint32_t rwait;
uint32_t wait;
enum sip_transp tp;
bool registered;
Expand Down Expand Up @@ -188,7 +189,7 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)
reg->wait = reg->expires;
sip_msg_hdr_apply(msg, true, SIP_HDR_CONTACT, contact_handler,
reg);
reg->wait *= 900;
reg->wait *= reg->rwait * (1000 / 100);
reg->failc = 0;

if (reg->regid > 0 && !reg->terminated && !reg->ka)
Expand Down Expand Up @@ -308,7 +309,7 @@ static int request(struct sipreg *reg, bool reset_ls)
* @param to_uri SIP To-header URI
* @param from_name SIP From-header display name (optional)
* @param from_uri SIP From-header URI
* @param expires Registration interval in [seconds]
* @param expires Registration expiry time in [seconds]
* @param cuser Contact username
* @param routev Optional route vector
* @param routec Number of routes
Expand Down Expand Up @@ -378,6 +379,7 @@ int sipreg_register(struct sipreg **regp, struct sip *sip, const char *reg_uri,

reg->sip = mem_ref(sip);
reg->expires = expires;
reg->rwait = 90;
reg->resph = resph ? resph : dummy_handler;
reg->arg = arg;
reg->regid = regid;
Expand All @@ -396,6 +398,25 @@ int sipreg_register(struct sipreg **regp, struct sip *sip, const char *reg_uri,
}


/**
* Set the relative registration interval in percent from proxy expiry time. A
* value from 5-95% is accepted.
*
* @param reg SIP Registration client
* @param rwait The relative registration interval in [%].
*
* @return 0 if success, otherwise errorcode
*/
int sipreg_set_rwait(struct sipreg *reg, uint32_t rwait)
{
if (!reg || rwait < 5 || rwait > 95)
return EINVAL;

reg->rwait = rwait;
return 0;
}


/**
* Get the local socket address for a SIP Registration client
*
Expand Down