2 * \brief Parser :: Parse subscription-state in NOTIFY
7 #include "parse_subscription_state.h"
10 #include "../mem/mem.h"
13 #include "parse_param.h"
16 void free_subscription_state(subscription_state_t**ss)
19 if (*ss) pkg_free(*ss);
24 static inline int str_cmp(const str *a, const str *b)
28 if (a->len != b->len) return 1;
30 for (i = 0; i < a->len; i++)
31 if (a->s[i] != b->s[i]) return 1;
35 static int ss_parse(str *src, subscription_state_t *ss)
37 static str active = STR_STATIC_INIT("active");
38 static str pending = STR_STATIC_INIT("pending");
39 static str terminated = STR_STATIC_INIT("terminated");
56 c = find_not_quoted(&s, ';');
58 /* first parameter starts after c */
59 state.len = c - state.s;
60 s.len = s.len - (c - s.s) - 1;
69 if (str_cmp(&state, &active) == 0) {
70 ss->value = ss_active;
72 else if (str_cmp(&state, &pending) == 0) {
73 ss->value = ss_pending;
75 else if (str_cmp(&state, &terminated) == 0) {
76 ss->value = ss_terminated;
79 /* INFO("unknown subscription-State value :%.*s\n",
80 state.len, state.s); */
81 ss->value = ss_extension;
84 /* explore parameters */
89 if (parse_params(&s, CLASS_CONTACT, &ph, ¶ms) < 0) {
90 ERR("can't parse params\n");
94 if (ph.contact.expires) {
96 res = str2int(&ph.contact.expires->body, &ss->expires);
98 ERR("invalid expires value: \'%.*s\'\n",
99 ph.contact.expires->body.len,
100 ph.contact.expires->body.s);
102 if (params) free_params(params);
106 ss->value = ss_active;
113 int parse_subscription_state(struct hdr_field *h)
115 subscription_state_t *ss;
116 if (h->parsed) return 0;
118 ss = (subscription_state_t*)pkg_malloc(sizeof(*ss));
120 ERR("No memory left\n");
124 memset(ss, 0, sizeof(*ss));
126 if (ss_parse(&h->body, ss) < 0) {
127 ERR("Can't parse Subscription-State\n");
132 h->parsed = (void*)ss;