diff --git a/include/re_sipreg.h b/include/re_sipreg.h index c99db7db3..4e8d11668 100644 --- a/include/re_sipreg.h +++ b/include/re_sipreg.h @@ -14,6 +14,7 @@ int sipreg_register(struct sipreg **regp, struct sip *sip, const char *reg_uri, int regid, sip_auth_h *authh, void *aarg, bool aref, sip_resp_h *resph, void *arg, const char *params, const char *fmt, ...); +void sipreg_unregister(struct sipreg *reg); int sipreg_alloc(struct sipreg **regp, struct sip *sip, const char *reg_uri, const char *to_uri, const char *from_name, const char *from_uri, uint32_t expires, diff --git a/src/sipreg/reg.c b/src/sipreg/reg.c index f787624fa..35f83d645 100644 --- a/src/sipreg/reg.c +++ b/src/sipreg/reg.c @@ -246,14 +246,17 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg) if (msg && msg->scode >= 400 && msg->scode < 500) reg->fbregint = 0; - if (!reg->terminated && reg->fbregint) { - tmr_start(®->tmr, reg->fbregint * 1000, tmr_handler, - reg); - reg->resph(err, msg, reg->arg); - } - else if (reg->terminated) { + if (reg->terminated) { mem_deref(reg); + return; } + + if (reg->fbregint) + tmr_start(®->tmr, reg->fbregint * 1000, + tmr_handler, reg); + + reg->resph(err, msg, reg->arg); + } else if (reg->terminated) { if (!reg->registered || request(reg, true)) @@ -450,6 +453,22 @@ int sipreg_register(struct sipreg **regp, struct sip *sip, const char *reg_uri, } +/** + * Unregisters SIP Registration client + * + * @param reg SIP Registration client + */ +void sipreg_unregister(struct sipreg *reg) +{ + if (!reg) + return; + + reg->expires = 0; + + (void)sipreg_send(reg); +} + + /** * Allocate a SIP Registration client *