fix header parsing
This commit is contained in:
parent
ec8dcbfd47
commit
b8a5996b67
4 changed files with 27 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
|
||||
SRCS += sipevent/listen.c
|
||||
SRCS += sipevent/subscribe.c
|
||||
SRCS += sipevent/substate.c
|
||||
SRCS += sipevent/msg.c
|
||||
|
|
|
@ -13,6 +13,22 @@
|
|||
#include <re_sipevent.h>
|
||||
|
||||
|
||||
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"))
|
Loading…
Add table
Reference in a new issue