diff --git a/include/re_sipevent.h b/include/re_sipevent.h index e7813cf..78de579 100644 --- a/include/re_sipevent.h +++ b/include/re_sipevent.h @@ -21,6 +21,11 @@ int sipevent_subscribe(struct sipsub **subp, struct sipevent_sock *sock, const char *fmt, ...); +struct sipevent_event { + struct pl event; + struct pl params; +}; + enum sipevent_subst { SIPEVENT_ACTIVE = 0, SIPEVENT_TERMINATED, @@ -32,6 +37,7 @@ struct sipevent_substate { uint32_t expires; }; +int sipevent_event_decode(struct sipevent_event *se, const struct pl *pl); int sipevent_substate_decode(struct sipevent_substate *ss, const struct pl *pl); const char *sipevent_substate_name(enum sipevent_subst state); diff --git a/src/sipevent/listen.c b/src/sipevent/listen.c index b391e41..fbf8cfc 100644 --- a/src/sipevent/listen.c +++ b/src/sipevent/listen.c @@ -82,6 +82,7 @@ static void notify_handler(struct sipevent_sock *sock, struct sipevent_substate ss; struct sip *sip = sock->sip; const struct sip_hdr *hdr; + struct sipevent_event se; struct sipsub *sub; sub = sipsub_find(sock, msg, true); @@ -105,8 +106,8 @@ static void notify_handler(struct sipevent_sock *sock, hdr = sip_msg_hdr(msg, SIP_HDR_EVENT); - // todo: check case sensitiveness, header syntax and status code - if (!hdr || pl_strcmp(&hdr->val, sub->event)) { + if (!hdr || sipevent_event_decode(&se, &hdr->val) || + pl_strcasecmp(&se.event, sub->event)) { (void)sip_reply(sip, msg, 489, "Bad Event"); return; } @@ -173,7 +174,7 @@ static void subscribe_handler(struct sipevent_sock *sock, (void)sip_dialog_update(not->dlg, msg); - // ... + /* todo: implement notifier */ } diff --git a/src/sipevent/mod.mk b/src/sipevent/mod.mk index ae2e417..0dbf7a0 100644 --- a/src/sipevent/mod.mk +++ b/src/sipevent/mod.mk @@ -6,4 +6,4 @@ SRCS += sipevent/listen.c SRCS += sipevent/subscribe.c -SRCS += sipevent/substate.c +SRCS += sipevent/msg.c diff --git a/src/sipevent/substate.c b/src/sipevent/msg.c similarity index 80% rename from src/sipevent/substate.c rename to src/sipevent/msg.c index dd72bed..f49b4a1 100644 --- a/src/sipevent/substate.c +++ b/src/sipevent/msg.c @@ -13,6 +13,22 @@ #include +int sipevent_event_decode(struct sipevent_event *se, const struct pl *pl) +{ + int err; + + if (!se || !pl) + return EINVAL; + + err = re_regex(pl->p, pl->l, "[^; \t\r\n]+[ \t\r\n]*[^]*", + &se->event, NULL, &se->params); + if (err) + return EBADMSG; + + return 0; +} + + int sipevent_substate_decode(struct sipevent_substate *ss, const struct pl *pl) { struct pl state, expires; @@ -26,7 +42,6 @@ int sipevent_substate_decode(struct sipevent_substate *ss, const struct pl *pl) if (err) return EBADMSG; - // todo: check case-sensitiveness if (!pl_strcasecmp(&state, "active")) ss->state = SIPEVENT_ACTIVE; else if (!pl_strcasecmp(&state, "terminated"))