diff --git a/include/re_sipreg.h b/include/re_sipreg.h index a0c1bae8c..a8b949ca4 100644 --- a/include/re_sipreg.h +++ b/include/re_sipreg.h @@ -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); diff --git a/src/sipreg/reg.c b/src/sipreg/reg.c index 3967200f0..0375d1892 100644 --- a/src/sipreg/reg.c +++ b/src/sipreg/reg.c @@ -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; @@ -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) @@ -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 @@ -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; @@ -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 *