MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / parse_fcaps

Function parse_fcaps

parser/parse_fcaps.c:31–90  ·  view source on GitHub ↗

Feature-Caps: +sip.pns="apns";+sip.pnsreg="130" */

Source from the content-addressed store, hash-verified

29
30/* Feature-Caps: +sip.pns="apns";+sip.pnsreg="130" */
31int parse_fcaps(struct hdr_field* _h)
32{
33 fcaps_body_t *b = NULL;
34 int len = _h->body.len;
35 char *s = _h->body.s, *end = s + len, *p;
36
37 if (_h->parsed)
38 return 0;
39
40 /* optimized, simplistic parser. Ideal for the PN proxy use case! */
41 while (len > 0 && (p = q_memchr(s, '+', len))) {
42 len -= p + 1 - s;
43 s = p + 1;
44
45 if (end - p >= (fcaps_pns.len + 4) &&
46 !memcmp(p, fcaps_pns.s, fcaps_pns.len)) {
47
48 p += fcaps_pns.len;
49 len -= p - s;
50 s = p;
51
52 /* start LDQUOT */
53 if (*p != '=' || *(p + 1) != '"')
54 continue;
55
56 /* end LDQUOT */
57 p += 2;
58 len -= 2;
59 s = p;
60
61 if (!(p = q_memchr(s + 1, '"', len - 1)))
62 goto out;
63
64 /* successfully matched a +sip.pns="..." string */
65
66 if (!b) {
67 b = pkg_malloc(sizeof *b);
68 if (!b) {
69 LM_ERR("oom\n");
70 return -1;
71 }
72 memset(b, 0, sizeof *b);
73 }
74
75 b->pns.s = s;
76 b->pns.len = p - s;
77
78 p++;
79 len -= p - s;
80 s = p;
81 }
82 }
83
84out:
85 if (!b)
86 return -1;
87
88 _h->parsed = (void *)b;

Callers 2

test_parse_fcapsFunction · 0.85
pn_fcaps_match_providerFunction · 0.85

Calls 1

q_memchrFunction · 0.85

Tested by 1

test_parse_fcapsFunction · 0.68