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

Function parse_xcap_uri

modules/xcap/uri.c:31–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30
31int parse_xcap_uri(const str *uri, xcap_uri_t *xcap_uri)
32{
33 char *ns_ptr, *tree_ptr, *tmp;
34 str unescaped_uri;
35
36 if (uri == NULL || uri->s == NULL ||xcap_uri == NULL) {
37 return -1;
38 }
39
40 if (uri->len > MAX_URI_SIZE-1) {
41 LM_ERR("XCAP URI is too long\n");
42 return -1;
43 }
44
45 memset(xcap_uri, 0, sizeof(xcap_uri_t));
46
47 unescaped_uri.s = xcap_uri->buf;
48 if (un_escape((str *)uri, &unescaped_uri) < 0) {
49 LM_ERR("Error un-escaping XCAP URI\n");
50 return -1;
51 }
52 xcap_uri->buf[uri->len] = '\0';
53
54 xcap_uri->uri.s = xcap_uri->buf;
55 xcap_uri->uri.len = uri->len;
56
57 /* selector */
58 if ((ns_ptr = strstr(xcap_uri->uri.s, "/~~/"))) {
59 xcap_uri->selector.s = ns_ptr+3;
60 xcap_uri->selector.len = xcap_uri->uri.s+xcap_uri->uri.len - xcap_uri->selector.s;
61 }
62
63 /* tree */
64 if ((tree_ptr = strstr(xcap_uri->uri.s, "/global/"))) {
65 xcap_uri->tree.s = tree_ptr+1;
66 xcap_uri->tree.len = 6;
67 } else if ((tree_ptr = strstr(xcap_uri->uri.s, "/users/"))) {
68 xcap_uri->tree.s = tree_ptr+1;
69 xcap_uri->tree.len = 5;
70 } else {
71 LM_ERR("Unknown XCAP URI tree\n");
72 return -1;
73 }
74
75 /* AUID */
76 tmp = tree_ptr-1;
77 while (tmp > xcap_uri->uri.s) {
78 if (tmp[0] == '/')
79 break;
80 tmp--;
81 }
82 if (tmp < xcap_uri->uri.s) {
83 LM_ERR("Error parsing AUID\n");
84 return -1;
85 }
86 xcap_uri->auid.s = tmp+1;
87 xcap_uri->auid.len = tree_ptr-1 - tmp;
88

Callers

nothing calls this directly

Calls 1

un_escapeFunction · 0.85

Tested by

no test coverage detected