diff --git a/include/re_sipevent.h b/include/re_sipevent.h index 0812921..8f60470 100644 --- a/include/re_sipevent.h +++ b/include/re_sipevent.h @@ -60,8 +60,9 @@ typedef void (sipevent_close_h)(int err, const struct sip_msg *msg, void *arg); int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock, const struct sip_msg *msg, struct sip_dialog *dlg, const struct sipevent_event *event, - uint16_t scode, const char *reason, uint32_t expires_dfl, - uint32_t expires_max, const char *cuser, const char *ctype, + uint16_t scode, const char *reason, uint32_t expires_min, + uint32_t expires_dfl, uint32_t expires_max, + const char *cuser, const char *ctype, sip_auth_h *authh, void *aarg, bool aref, sipevent_close_h *closeh, void *arg, const char *fmt, ...); int sipevent_notify(struct sipnot *not, struct mbuf *mb, bool term, diff --git a/src/sipevent/listen.c b/src/sipevent/listen.c index a4b6434..2224728 100644 --- a/src/sipevent/listen.c +++ b/src/sipevent/listen.c @@ -254,6 +254,20 @@ static void subscribe_handler(struct sipevent_sock *sock, return; } + if (pl_isset(&msg->expires)) + expires = pl_u32(&msg->expires); + else + expires = not->expires_dfl; + + if (expires > 0 && expires < not->expires_min) { + (void)sip_replyf(sip, msg, 423, "Interval Too Brief", + "Min-Expires: %u\r\n" + "Content-Length: 0\r\n" + "\r\n", + not->expires_min); + return; + } + if (!sip_dialog_rseq_valid(not->dlg, msg)) { (void)sip_reply(sip, msg, 500, "Bad Sequence"); return; @@ -261,11 +275,6 @@ static void subscribe_handler(struct sipevent_sock *sock, (void)sip_dialog_update(not->dlg, msg); - if (pl_isset(&msg->expires)) - expires = pl_u32(&msg->expires); - else - expires = not->expires_dfl; - sipnot_refresh(not, expires); (void)sipnot_reply(not, msg, 200, "OK"); diff --git a/src/sipevent/notify.c b/src/sipevent/notify.c index d86dc23..9fb716a 100644 --- a/src/sipevent/notify.c +++ b/src/sipevent/notify.c @@ -293,8 +293,9 @@ int sipnot_reply(struct sipnot *not, const struct sip_msg *msg, int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock, const struct sip_msg *msg, struct sip_dialog *dlg, const struct sipevent_event *event, - uint16_t scode, const char *reason, uint32_t expires_dfl, - uint32_t expires_max, const char *cuser, const char *ctype, + uint16_t scode, const char *reason, uint32_t expires_min, + uint32_t expires_dfl, uint32_t expires_max, + const char *cuser, const char *ctype, sip_auth_h *authh, void *aarg, bool aref, sipevent_close_h *closeh, void *arg, const char *fmt, ...) { @@ -303,7 +304,7 @@ int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock, int err; if (!notp || !sock || !msg || !scode || !reason || !expires_dfl || - !expires_max || !cuser || !ctype) + !expires_max || !cuser || !ctype || expires_dfl < expires_min) return EINVAL; not = mem_zalloc(sizeof(*not), destructor); @@ -373,6 +374,7 @@ int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock, goto out; } + not->expires_min = expires_min; not->expires_dfl = expires_dfl; not->expires_max = expires_max; not->sock = mem_ref(sock); diff --git a/src/sipevent/sipevent.h b/src/sipevent/sipevent.h index d3d122b..1fdef5f 100644 --- a/src/sipevent/sipevent.h +++ b/src/sipevent/sipevent.h @@ -35,6 +35,7 @@ struct sipnot { char *ctype; sipevent_close_h *closeh; void *arg; + uint32_t expires_min; uint32_t expires_dfl; uint32_t expires_max; enum sipevent_reason reason;