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");
57 c = find_not_quoted(&s, ';');
59 /* first parameter starts after c */
60 state.len = c - state.s;
61 s.len = s.len - (c - s.s) - 1;
70 if (str_cmp(&state, &active) == 0) {
71 ss->value = ss_active;
73 else if (str_cmp(&state, &pending) == 0) {
74 ss->value = ss_pending;
76 else if (str_cmp(&state, &terminated) == 0) {
77 ss->value = ss_terminated;
80 /* INFO("unknown subscription-State value :%.*s\n",
81 state.len, state.s); */
82 ss->value = ss_extension;
85 /* explore parameters */
90 if (parse_params(&s, CLASS_CONTACT, &ph, ¶ms) < 0) {
91 ERR("can't parse params\n");
95 if (ph.contact.expires) {
97 res = str2int(&ph.contact.expires->body, &ss->expires);
99 ERR("invalid expires value: \'%.*s\'\n",
100 ph.contact.expires->body.len,
101 ph.contact.expires->body.s);
103 if (params) free_params(params);
107 ss->value = ss_active;
114 int parse_subscription_state(struct hdr_field *h)
116 subscription_state_t *ss;
117 if (h->parsed) return 0;
119 ss = (subscription_state_t*)pkg_malloc(sizeof(*ss));
121 ERR("No memory left\n");
125 memset(ss, 0, sizeof(*ss));
127 if (ss_parse(&h->body, ss) < 0) {
128 ERR("Can't parse Subscription-State\n");
133 h->parsed = (void*)ss;