Browse code

- added parsing mimetype application/cpim-pidf+xml - added parsing cpim-pidf+xml document (draft version 07 - the same as PIDF, but other namespace) - corrected a little bug in parsing mimetypes - using default_expires for PUBLISH handling

Vaclav Kubart authored on 07/12/2005 17:53:31
Showing 4 changed files
... ...
@@ -147,7 +147,7 @@ static int read_note(xmlNode *node, presence_note_t **dst)
147 147
 }
148 148
 
149 149
 
150
-static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
150
+static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst, int ignore_ns)
151 151
 {
152 152
 	str_t contact, id;
153 153
 	presence_tuple_status_t status;
... ...
@@ -156,12 +156,13 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
156 156
 	const char *s;
157 157
 	int res = 0;
158 158
 	presence_note_t *note;
159
+	char *ns = ignore_ns ? NULL: pidf_ns;
159 160
 
160 161
 	*dst = NULL;
161 162
 
162 163
 	DEBUG_LOG("read_tuple()\n");
163 164
 	/* process contact (only one node) */
164
-	n = find_node(tuple, "contact", pidf_ns);
165
+	n = find_node(tuple, "contact", ns);
165 166
 	if (!n) {
166 167
 		ERROR_LOG("contact not found\n");
167 168
 		return -1;
... ...
@@ -178,12 +179,12 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
178 178
 	}	
179 179
 	
180 180
 	/* process status (only one node) */
181
-	n = find_node(tuple, "status", pidf_ns);
181
+	n = find_node(tuple, "status", ns);
182 182
 	if (!n) {
183 183
 		ERROR_LOG("status not found\n");
184 184
 		return -1;
185 185
 	}
186
-	n = find_node(n, "basic", pidf_ns);
186
+	n = find_node(n, "basic", ns);
187 187
 	if (!n) {
188 188
 		ERROR_LOG("basic status not found\n");
189 189
 		return -1;
... ...
@@ -214,7 +215,7 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
214 214
 	n = tuple->children;
215 215
 	while (n) {
216 216
 		if (n->type == XML_ELEMENT_NODE) {
217
-			if (cmp_node(n, "note", pidf_ns) >= 0) {
217
+			if (cmp_node(n, "note", ns) >= 0) {
218 218
 				res = read_note(n, &note);
219 219
 				if ((res == 0) && note) {
220 220
 					DOUBLE_LINKED_LIST_ADD((*dst)->first_note, 
... ...
@@ -229,16 +230,17 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
229 229
 	return res;
230 230
 }
231 231
 
232
-static int read_presentity(xmlNode *root, presentity_info_t **dst)
232
+static int read_presentity(xmlNode *root, presentity_info_t **dst, int ignore_ns)
233 233
 {
234 234
 	xmlNode *n;
235 235
 	str_t entity;
236 236
 	presence_tuple_info_t *t;
237 237
 	presence_note_t *note;
238 238
 	int res = 0;
239
+	char *ns = ignore_ns ? NULL: pidf_ns;
239 240
 	
240 241
 	DEBUG_LOG("read_presentity()\n");
241
-	if (cmp_node(root, "presence", pidf_ns) < 0) {
242
+	if (cmp_node(root, "presence", ns) < 0) {
242 243
 		ERROR_LOG("document is not presence \n");
243 244
 		return -1;
244 245
 	}
... ...
@@ -250,12 +252,12 @@ static int read_presentity(xmlNode *root, presentity_info_t **dst)
250 250
 	n = root->children;
251 251
 	while (n) {
252 252
 		if (n->type == XML_ELEMENT_NODE) {
253
-			if (cmp_node(n, "tuple", pidf_ns) >= 0) {
254
-				res = read_tuple(n, &t);
253
+			if (cmp_node(n, "tuple", ns) >= 0) {
254
+				res = read_tuple(n, &t, ignore_ns);
255 255
 				if ((res == 0) && t) add_tuple_info(*dst, t);
256 256
 				else break;
257 257
 			}
258
-			if (cmp_node(n, "note", pidf_ns) >= 0) {
258
+			if (cmp_node(n, "note", ns) >= 0) {
259 259
 				res = read_note(n, &note);
260 260
 				if ((res == 0) && note) {
261 261
 					DOUBLE_LINKED_LIST_ADD((*dst)->first_note, 
... ...
@@ -271,7 +273,7 @@ static int read_presentity(xmlNode *root, presentity_info_t **dst)
271 271
 }
272 272
 
273 273
 /* libxml2 must be initialized before calling this function ! */
274
-int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len)
274
+int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len, int ignore_ns)
275 275
 {
276 276
 	int res = 0;
277 277
 	xmlDocPtr doc;
... ...
@@ -286,7 +288,7 @@ int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len)
286 286
 		return -1;
287 287
 	}
288 288
 	
289
-	res = read_presentity(xmlDocGetRootElement(doc), dst);
289
+	res = read_presentity(xmlDocGetRootElement(doc), dst, ignore_ns);
290 290
 	if (res != 0) {
291 291
 		/* may be set => must be freed */
292 292
 		if (*dst) free_presentity_info(*dst);
... ...
@@ -30,6 +30,8 @@
30 30
 #include <presence/pres_doc.h>
31 31
 
32 32
 int create_pidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type);
33
-int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len);
33
+
34
+/* ignore ns added for cpim-pidf+xml, draft version 07 (differs only in ns) */
35
+int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len, int ignore_ns);
34 36
 
35 37
 #endif
... ...
@@ -112,30 +112,39 @@ static type_node_t subtype_tree[] = {
112 112
 	{'s',SUBTYPE_UNKNOWN,1,16}, /* 13 */
113 113
 		{'d',SUBTYPE_UNKNOWN,1,-1},
114 114
 			{'p',SUBTYPE_SDP,0,-1},
115
-	{'c',SUBTYPE_UNKNOWN,1,25}, /* 16 */
115
+	{'c',SUBTYPE_UNKNOWN,1,34}, /* 16 */
116 116
 		{'p',SUBTYPE_UNKNOWN,2,-1},
117
-			{'i',SUBTYPE_UNKNOWN,1,20},
118
-				{'m',SUBTYPE_CPIM,0,-1},
119
-			{'l',SUBTYPE_UNKNOWN,1,-1},
117
+			{'i',SUBTYPE_UNKNOWN,1,29},
118
+				{'m',SUBTYPE_CPIM,1,-1},
119
+					{'-',SUBTYPE_UNKNOWN,1,-1},
120
+						{'p',SUBTYPE_UNKNOWN,1,-1},
121
+							{'i',SUBTYPE_UNKNOWN,1,-1},
122
+								{'d',SUBTYPE_UNKNOWN,1,-1},
123
+									{'f',SUBTYPE_UNKNOWN,1,-1},
124
+										{'+',SUBTYPE_UNKNOWN,1,-1},
125
+											{'x',SUBTYPE_UNKNOWN,1,-1},
126
+												{'m',SUBTYPE_UNKNOWN,1,-1},
127
+													{'l',SUBTYPE_CPIM_PIDFXML,0,-1},
128
+			{'l',SUBTYPE_UNKNOWN,1,-1}, /* 29 */
120 129
 				{'+',TYPE_UNKNOWN,1,-1},
121 130
 					{'x',TYPE_UNKNOWN,1,-1},
122 131
 						{'m',TYPE_UNKNOWN,1,-1},
123 132
 							{'l',SUBTYPE_CPLXML,0,-1},
124
-	{'r',SUBTYPE_UNKNOWN,2,39}, /* 25 */
125
-		{'l',SUBTYPE_UNKNOWN,1,33},/* 26 */
133
+	{'r',SUBTYPE_UNKNOWN,2,48}, /* 34 */
134
+		{'l',SUBTYPE_UNKNOWN,1,42},/* 35 */
126 135
 			{'m',SUBTYPE_UNKNOWN,1,-1},
127 136
 				{'i',SUBTYPE_UNKNOWN,1,-1},
128 137
 					{'+',TYPE_UNKNOWN,1,-1},
129 138
 						{'x',TYPE_UNKNOWN,1,-1},
130 139
 							{'m',TYPE_UNKNOWN,1,-1},
131 140
 								{'l',SUBTYPE_RLMIXML,0,-1},
132
-		{'e',SUBTYPE_UNKNOWN,1,-1}, /* 33 */
141
+		{'e',SUBTYPE_UNKNOWN,1,-1}, /* 42 */
133 142
 			{'l',SUBTYPE_UNKNOWN,1,-1},
134 143
 				{'a',SUBTYPE_UNKNOWN,1,-1},
135 144
 					{'t',SUBTYPE_UNKNOWN,1,-1},
136 145
 						{'e',SUBTYPE_UNKNOWN,1,-1},
137 146
 							{'d',SUBTYPE_RELATED,0,-1},
138
-	{'l',SUBTYPE_UNKNOWN,1,48}, /* 39 */
147
+	{'l',SUBTYPE_UNKNOWN,1,57}, /* 48 */
139 148
 		{'p',SUBTYPE_UNKNOWN,1,-1},
140 149
 			{'i',SUBTYPE_UNKNOWN,1,-1},
141 150
 				{'d',SUBTYPE_UNKNOWN,1,-1},
... ...
@@ -144,7 +153,7 @@ static type_node_t subtype_tree[] = {
144 144
 							{'x',SUBTYPE_UNKNOWN,1,-1},
145 145
 								{'m',SUBTYPE_UNKNOWN,1,-1},
146 146
 									{'l',SUBTYPE_LPIDFXML,0,-1},
147
-	{'w',SUBTYPE_UNKNOWN,1,63}, /* 48 */
147
+	{'w',SUBTYPE_UNKNOWN,1,72}, /* 57 */
148 148
 		{'a',SUBTYPE_UNKNOWN,1,-1},
149 149
 			{'t',SUBTYPE_UNKNOWN,1,-1},
150 150
 				{'c',SUBTYPE_UNKNOWN,1,-1},
... ...
@@ -159,8 +168,8 @@ static type_node_t subtype_tree[] = {
159 159
 													{'x',TYPE_UNKNOWN,1,-1},
160 160
 														{'m',TYPE_UNKNOWN,1,-1},
161 161
 															{'l',SUBTYPE_WATCHERINFOXML,0,-1},
162
-	{'x',SUBTYPE_UNKNOWN,2,85}, /* 63 */
163
-		{'p',SUBTYPE_UNKNOWN,1,72}, /* 64 */
162
+	{'x',SUBTYPE_UNKNOWN,2,94}, /* 72 */
163
+		{'p',SUBTYPE_UNKNOWN,1,81}, /* 73 */
164 164
 			{'i',SUBTYPE_UNKNOWN,1,-1},
165 165
 				{'d',SUBTYPE_UNKNOWN,1,-1},
166 166
 					{'f',SUBTYPE_UNKNOWN,1,-1},
... ...
@@ -168,7 +177,7 @@ static type_node_t subtype_tree[] = {
168 168
 							{'x',SUBTYPE_UNKNOWN,1,-1},
169 169
 								{'m',SUBTYPE_UNKNOWN,1,-1},
170 170
 									{'l',SUBTYPE_XPIDFXML,0,-1},
171
-		{'m',SUBTYPE_UNKNOWN,1,-1}, /* 72 */
171
+		{'m',SUBTYPE_UNKNOWN,1,-1}, /* 81 */
172 172
 			{'l',SUBTYPE_UNKNOWN,1,-1},
173 173
 				{'+',SUBTYPE_UNKNOWN,1,-1},
174 174
 					{'m',SUBTYPE_UNKNOWN,1,-1},
... ...
@@ -181,7 +190,7 @@ static type_node_t subtype_tree[] = {
181 181
 												{'i',SUBTYPE_UNKNOWN,1,-1}, 
182 182
 													{'d',SUBTYPE_UNKNOWN,1,-1},
183 183
 														{'f',SUBTYPE_XML_MSRTC_PIDF,0,-1},
184
-	{'e',SUBTYPE_UNKNOWN,1,-1}, /* 85 */
184
+	{'e',SUBTYPE_UNKNOWN,1,-1}, /* 94 */
185 185
 		{'x',SUBTYPE_UNKNOWN,1,-1},
186 186
 			{'t',SUBTYPE_UNKNOWN,1,-1},
187 187
 				{'e',SUBTYPE_UNKNOWN,1,-1},
... ...
@@ -269,7 +278,9 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
269 269
 				node = type_tree[node].next;
270 270
 			}
271 271
 			if (node!=-1 && type_tree[node].nr_sons)
272
-				node++;
272
+				node++; 
273
+				/* ? increment only for (p < end - 1), 
274
+				 * otherwise will not work for final nodes with children */
273 275
 			p++;
274 276
 		}
275 277
 		if (p==end || mark==p)
... ...
@@ -304,7 +315,7 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
304 304
 		while (p<end && is_mime_char(*p) ) {
305 305
 			while(node!=-1 && !is_char_equal(*p,subtype_tree[node].c) )
306 306
 				node = subtype_tree[node].next;
307
-			if (node!=-1 && subtype_tree[node].nr_sons)
307
+			if (node!=-1 && subtype_tree[node].nr_sons && (p < end - 1))
308 308
 				node++;
309 309
 			p++;
310 310
 		}
... ...
@@ -61,6 +61,7 @@ struct mime_type {
61 61
 #define SUBTYPE_WATCHERINFOXML     10
62 62
 #define SUBTYPE_EXTERNAL_BODY      11
63 63
 #define SUBTYPE_XML_MSRTC_PIDF     12
64
+#define SUBTYPE_CPIM_PIDFXML       13
64 65
 #define SUBTYPE_ALL          0xfe
65 66
 #define SUBTYPE_UNKNOWN      0xff
66 67