3 #include <cds/sip_utils.h>
5 #include <parser/parse_expires.h>
6 #include <parser/parse_subscription_state.h>
7 #include <parser/parser_f.h>
8 #include <parser/parse_to.h>
12 int get_expiration_value(struct sip_msg *m, int *value)
14 exp_body_t *expires = NULL;
17 if (parse_headers(m, HDR_EXPIRES_F, 0) == -1) {
18 /* can't parse expires header */
22 if (parse_expires(m->expires) < 0) {
27 expires = (exp_body_t *)m->expires->parsed;
28 if (expires) if (expires->valid && value) *value = expires->val;
30 /* ERR("subscription will expire in %d secs\n", e); */
34 int is_terminating_notify(struct sip_msg *m)
36 subscription_state_t *ss;
38 if (parse_headers(m, HDR_SUBSCRIPTION_STATE_F, 0) == -1) {
39 ERR("Error while parsing headers\n");
40 return 0; /* ignore */
42 if (!m->subscription_state) {
43 ERR("Invalid NOTIFY request (without Subscription-State)\n");
44 return 0; /* ignore */
46 if (parse_subscription_state(m->subscription_state) < 0) {
47 ERR("can't parse Subscription-State\n");
48 return 0; /* ignore */
50 ss = (subscription_state_t*)m->subscription_state->parsed;
52 ERR("invalid Subscription-State\n");
53 return 0; /* ignore */
56 if (ss->value == ss_terminated) return 1;
61 static inline int contains_extension_support(struct hdr_field *h,
64 /* "parses" Supported header and looks for extension */
72 c = find_not_quoted(&s, ',');
77 if (str_case_equals(&val, extension) == 0) return 1;
78 s.len = s.len - (c - s.s) - 1;
83 if (str_case_equals(&s, extension) == 0) return 1;
90 int supports_extension(struct sip_msg *m, str *extension)
92 /* walk through all Supported headers */
96 /* we need all Supported headers */
97 res = parse_headers(m, HDR_EOH_F, 0);
99 ERR("Error while parsing headers (%d)\n", res);
100 return 0; /* what to return here ? */
105 if (h->type == HDR_SUPPORTED_T) {
106 if (contains_extension_support(h, extension)) return 1;
113 int requires_extension(struct sip_msg *m, str *extension)
115 /* walk through all Require headers */
119 /* we need all Require headers */
120 res = parse_headers(m, HDR_EOH_F, 0);
122 ERR("Error while parsing headers (%d)\n", res);
123 return 0; /* what to return here ? */
128 if (h->type == HDR_REQUIRE_T) {
129 if (contains_extension_support(h, extension)) return 1;
137 * Verifies presence of the To-tag in message. Returns 1 if
138 * the tag is present, 0 if not, -1 on error.
140 int has_to_tag(struct sip_msg *_m)
142 struct to_body *to = (struct to_body*)_m->to->parsed;
144 if (to->tag_value.len > 0) return 1;