Browse code

xcap_server: use a static table to keep the list of supported auids

- adding new auid requires an entry in this table and define of the
internal type

Daniel-Constantin Mierla authored on 25/10/2012 08:56:41
Showing 1 changed files
... ...
@@ -40,6 +40,59 @@ extern str xcaps_root;
40 40
 
41 41
 static param_t *_xcaps_xpath_ns_root = NULL;
42 42
 
43
+typedef struct xcaps_auid_list {
44
+	str auid;  /* auid value */
45
+	char term; /* ending char (next one after auid) */
46
+	int type;  /* internaly type id for auid */
47
+} xcaps_auid_list_t;
48
+
49
+/* list of supported auid */
50
+static xcaps_auid_list_t _xcaps_auid_list[] = {
51
+	{ { "pres-rules", 10 },
52
+			'/', PRES_RULES },
53
+	{ { "org.openmobilealliance.pres-rules", 33 },
54
+			'/', PRES_RULES },
55
+	{ { "rls-services", 12 },
56
+			'/', RLS_SERVICE },
57
+	{ { "pidf-manipulation", 17 },
58
+			'/', PIDF_MANIPULATION },
59
+	{ { "resource-lists", 14 },
60
+			'/', RESOURCE_LIST },
61
+	{ { "xcap-caps", 9 },
62
+			'/', XCAP_CAPS },
63
+	{ { "org.openmobilealliance.user-profile", 35},
64
+			'/', USER_PROFILE },
65
+	{ { "org.openmobilealliance.pres-content", 15},
66
+			'/', PRES_CONTENT },
67
+	{ { "org.openmobilealliance.search", 29},
68
+			'?', SEARCH },
69
+
70
+	{ { 0, 0 }, 0, 0 }
71
+};
72
+
73
+static int xcaps_find_auid(str *s, xcap_uri_t *xuri)
74
+{
75
+	int i;
76
+	for(i=0; _xcaps_auid_list[i].auid.s!=NULL; i++)
77
+	{
78
+		if(s->len > _xcaps_auid_list[i].auid.len
79
+			&& s->s[_xcaps_auid_list[i].auid.len] == _xcaps_auid_list[i].term
80
+			&& strncmp(s->s, _xcaps_auid_list[i].auid.s,
81
+							_xcaps_auid_list[i].auid.len) == 0)
82
+		{
83
+			LM_DBG("matched %.*s\n", _xcaps_auid_list[i].auid.len,
84
+					_xcaps_auid_list[i].auid.s);
85
+			xuri->type = _xcaps_auid_list[i].type;
86
+			xuri->auid.s = s->s;
87
+			xuri->auid.len = _xcaps_auid_list[i].auid.len;
88
+			return 0;
89
+		}
90
+	}
91
+	LM_ERR("unsupported auid in [%.*s]\n", xuri->uri.len,
92
+				xuri->uri.s);
93
+	return -1;
94
+}
95
+
43 96
 /**
44 97
  * parse xcap uri
45 98
  */
... ...
@@ -127,45 +180,11 @@ int xcap_parse_uri(str *huri, str *xroot, xcap_uri_t *xuri)
127 127
 	}
128 128
 
129 129
 	/* auid */
130
-	xuri->auid.s = s.s;
131
-	if(s.len>11 && strncmp(s.s, "pres-rules/", 11)==0)
132
-	{
133
-		LM_DBG("matched pres-rules\n");
134
-		xuri->type = PRES_RULES;
135
-		xuri->auid.len = 10;
136
-	} else if(s.len>34 && strncmp(s.s, "org.openmobilealliance.pres-rules/", 34)==0) {
137
-		LM_DBG("matched oma pres-rules\n");
138
-		xuri->type = PRES_RULES;
139
-		xuri->auid.len = 33;
140
-	} else if(s.len>13 && strncmp(s.s, "rls-services/", 13)==0) {
141
-		LM_DBG("matched rls-services\n");
142
-		xuri->type = RLS_SERVICE;
143
-		xuri->auid.len = 12;
144
-	} else if(s.len>18 && strncmp(s.s, "pidf-manipulation/", 18)==0) {
145
-		LM_DBG("matched pidf-manipulation\n");
146
-		xuri->type = PIDF_MANIPULATION;
147
-		xuri->auid.len = 17;
148
-	} else if(s.len>15 && strncmp(s.s, "resource-lists/", 15)==0) {
149
-		LM_DBG("matched resource-lists\n");
150
-		xuri->type = RESOURCE_LIST;
151
-		xuri->auid.len = 14;
152
-	} else if(s.len>10 && strncmp(s.s, "xcap-caps/", 10)==0) {
153
-		LM_DBG("matched xcap-caps\n");
154
-		xuri->type = XCAP_CAPS;
155
-		xuri->auid.len = 9;
156
-	} else if(s.len> 36 && strncmp(s.s, "org.openmobilealliance.user-profile/", 36)==0) {
157
-		LM_DBG("matched oma user-profile\n");
158
-		xuri->type = USER_PROFILE;
159
-		xuri->auid.len = 35;
160
-	} else if(s.len> 36 && strncmp(s.s, "org.openmobilealliance.pres-content/", 36)==0) {
161
-		LM_DBG("matched oma pres-content\n");
162
-		xuri->type = PRES_CONTENT;
163
-		xuri->auid.len = 35;
164
-	} else if(s.len> 30 && strncmp(s.s, "org.openmobilealliance.search?", 30)==0) {
165
-		LM_DBG("matched oma search\n");
166
-		xuri->type = SEARCH;
167
-		xuri->auid.len = 29;
130
+	if(xcaps_find_auid(&s, xuri)<0)
131
+		return -1;
168 132
 
133
+	/* handling special auids */
134
+	if(xuri->type == SEARCH) {
169 135
 		s.s   += xuri->auid.len + 1;
170 136
 		s.len -= xuri->auid.len + 1;
171 137
 
... ...
@@ -197,10 +216,6 @@ int xcap_parse_uri(str *huri, str *xroot, xcap_uri_t *xuri)
197 197
 		}
198 198
 
199 199
 		return 0;
200
-	} else {
201
-		LM_ERR("unsupported auid in [%.*s]\n", xuri->uri.len,
202
-				xuri->uri.s);
203
-		return -1;
204 200
 	}
205 201
 
206 202
 	s.s   += xuri->auid.len + 1;