Просмотр исходного кода

- 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 20 лет назад
Родитель
Сommit
4526254b71
4 измененных файлов с 44 добавлено и 28 удалено
  1. 14 12
      lib/presence/pidf.c
  2. 3 1
      lib/presence/pidf.h
  3. 26 15
      parser/parse_content.c
  4. 1 0
      parser/parse_content.h

+ 14 - 12
lib/presence/pidf.c

@@ -147,7 +147,7 @@ static int read_note(xmlNode *node, presence_note_t **dst)
 }
 
 
-static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
+static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst, int ignore_ns)
 {
 	str_t contact, id;
 	presence_tuple_status_t status;
@@ -156,12 +156,13 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
 	const char *s;
 	int res = 0;
 	presence_note_t *note;
+	char *ns = ignore_ns ? NULL: pidf_ns;
 
 	*dst = NULL;
 
 	DEBUG_LOG("read_tuple()\n");
 	/* process contact (only one node) */
-	n = find_node(tuple, "contact", pidf_ns);
+	n = find_node(tuple, "contact", ns);
 	if (!n) {
 		ERROR_LOG("contact not found\n");
 		return -1;
@@ -178,12 +179,12 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
 	}	
 	
 	/* process status (only one node) */
-	n = find_node(tuple, "status", pidf_ns);
+	n = find_node(tuple, "status", ns);
 	if (!n) {
 		ERROR_LOG("status not found\n");
 		return -1;
 	}
-	n = find_node(n, "basic", pidf_ns);
+	n = find_node(n, "basic", ns);
 	if (!n) {
 		ERROR_LOG("basic status not found\n");
 		return -1;
@@ -214,7 +215,7 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
 	n = tuple->children;
 	while (n) {
 		if (n->type == XML_ELEMENT_NODE) {
-			if (cmp_node(n, "note", pidf_ns) >= 0) {
+			if (cmp_node(n, "note", ns) >= 0) {
 				res = read_note(n, &note);
 				if ((res == 0) && note) {
 					DOUBLE_LINKED_LIST_ADD((*dst)->first_note, 
@@ -229,16 +230,17 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst)
 	return res;
 }
 
-static int read_presentity(xmlNode *root, presentity_info_t **dst)
+static int read_presentity(xmlNode *root, presentity_info_t **dst, int ignore_ns)
 {
 	xmlNode *n;
 	str_t entity;
 	presence_tuple_info_t *t;
 	presence_note_t *note;
 	int res = 0;
+	char *ns = ignore_ns ? NULL: pidf_ns;
 	
 	DEBUG_LOG("read_presentity()\n");
-	if (cmp_node(root, "presence", pidf_ns) < 0) {
+	if (cmp_node(root, "presence", ns) < 0) {
 		ERROR_LOG("document is not presence \n");
 		return -1;
 	}
@@ -250,12 +252,12 @@ static int read_presentity(xmlNode *root, presentity_info_t **dst)
 	n = root->children;
 	while (n) {
 		if (n->type == XML_ELEMENT_NODE) {
-			if (cmp_node(n, "tuple", pidf_ns) >= 0) {
-				res = read_tuple(n, &t);
+			if (cmp_node(n, "tuple", ns) >= 0) {
+				res = read_tuple(n, &t, ignore_ns);
 				if ((res == 0) && t) add_tuple_info(*dst, t);
 				else break;
 			}
-			if (cmp_node(n, "note", pidf_ns) >= 0) {
+			if (cmp_node(n, "note", ns) >= 0) {
 				res = read_note(n, &note);
 				if ((res == 0) && note) {
 					DOUBLE_LINKED_LIST_ADD((*dst)->first_note, 
@@ -271,7 +273,7 @@ static int read_presentity(xmlNode *root, presentity_info_t **dst)
 }
 
 /* libxml2 must be initialized before calling this function ! */
-int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len)
+int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len, int ignore_ns)
 {
 	int res = 0;
 	xmlDocPtr doc;
@@ -286,7 +288,7 @@ int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len)
 		return -1;
 	}
 	
-	res = read_presentity(xmlDocGetRootElement(doc), dst);
+	res = read_presentity(xmlDocGetRootElement(doc), dst, ignore_ns);
 	if (res != 0) {
 		/* may be set => must be freed */
 		if (*dst) free_presentity_info(*dst);

+ 3 - 1
lib/presence/pidf.h

@@ -30,6 +30,8 @@
 #include <presence/pres_doc.h>
 
 int create_pidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type);
-int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len);
+
+/* ignore ns added for cpim-pidf+xml, draft version 07 (differs only in ns) */
+int parse_pidf_document(presentity_info_t **dst, const char *data, int data_len, int ignore_ns);
 
 #endif

+ 26 - 15
parser/parse_content.c

@@ -112,30 +112,39 @@ static type_node_t subtype_tree[] = {
 	{'s',SUBTYPE_UNKNOWN,1,16}, /* 13 */
 		{'d',SUBTYPE_UNKNOWN,1,-1},
 			{'p',SUBTYPE_SDP,0,-1},
-	{'c',SUBTYPE_UNKNOWN,1,25}, /* 16 */
+	{'c',SUBTYPE_UNKNOWN,1,34}, /* 16 */
 		{'p',SUBTYPE_UNKNOWN,2,-1},
-			{'i',SUBTYPE_UNKNOWN,1,20},
-				{'m',SUBTYPE_CPIM,0,-1},
-			{'l',SUBTYPE_UNKNOWN,1,-1},
+			{'i',SUBTYPE_UNKNOWN,1,29},
+				{'m',SUBTYPE_CPIM,1,-1},
+					{'-',SUBTYPE_UNKNOWN,1,-1},
+						{'p',SUBTYPE_UNKNOWN,1,-1},
+							{'i',SUBTYPE_UNKNOWN,1,-1},
+								{'d',SUBTYPE_UNKNOWN,1,-1},
+									{'f',SUBTYPE_UNKNOWN,1,-1},
+										{'+',SUBTYPE_UNKNOWN,1,-1},
+											{'x',SUBTYPE_UNKNOWN,1,-1},
+												{'m',SUBTYPE_UNKNOWN,1,-1},
+													{'l',SUBTYPE_CPIM_PIDFXML,0,-1},
+			{'l',SUBTYPE_UNKNOWN,1,-1}, /* 29 */
 				{'+',TYPE_UNKNOWN,1,-1},
 					{'x',TYPE_UNKNOWN,1,-1},
 						{'m',TYPE_UNKNOWN,1,-1},
 							{'l',SUBTYPE_CPLXML,0,-1},
-	{'r',SUBTYPE_UNKNOWN,2,39}, /* 25 */
-		{'l',SUBTYPE_UNKNOWN,1,33},/* 26 */
+	{'r',SUBTYPE_UNKNOWN,2,48}, /* 34 */
+		{'l',SUBTYPE_UNKNOWN,1,42},/* 35 */
 			{'m',SUBTYPE_UNKNOWN,1,-1},
 				{'i',SUBTYPE_UNKNOWN,1,-1},
 					{'+',TYPE_UNKNOWN,1,-1},
 						{'x',TYPE_UNKNOWN,1,-1},
 							{'m',TYPE_UNKNOWN,1,-1},
 								{'l',SUBTYPE_RLMIXML,0,-1},
-		{'e',SUBTYPE_UNKNOWN,1,-1}, /* 33 */
+		{'e',SUBTYPE_UNKNOWN,1,-1}, /* 42 */
 			{'l',SUBTYPE_UNKNOWN,1,-1},
 				{'a',SUBTYPE_UNKNOWN,1,-1},
 					{'t',SUBTYPE_UNKNOWN,1,-1},
 						{'e',SUBTYPE_UNKNOWN,1,-1},
 							{'d',SUBTYPE_RELATED,0,-1},
-	{'l',SUBTYPE_UNKNOWN,1,48}, /* 39 */
+	{'l',SUBTYPE_UNKNOWN,1,57}, /* 48 */
 		{'p',SUBTYPE_UNKNOWN,1,-1},
 			{'i',SUBTYPE_UNKNOWN,1,-1},
 				{'d',SUBTYPE_UNKNOWN,1,-1},
@@ -144,7 +153,7 @@ static type_node_t subtype_tree[] = {
 							{'x',SUBTYPE_UNKNOWN,1,-1},
 								{'m',SUBTYPE_UNKNOWN,1,-1},
 									{'l',SUBTYPE_LPIDFXML,0,-1},
-	{'w',SUBTYPE_UNKNOWN,1,63}, /* 48 */
+	{'w',SUBTYPE_UNKNOWN,1,72}, /* 57 */
 		{'a',SUBTYPE_UNKNOWN,1,-1},
 			{'t',SUBTYPE_UNKNOWN,1,-1},
 				{'c',SUBTYPE_UNKNOWN,1,-1},
@@ -159,8 +168,8 @@ static type_node_t subtype_tree[] = {
 													{'x',TYPE_UNKNOWN,1,-1},
 														{'m',TYPE_UNKNOWN,1,-1},
 															{'l',SUBTYPE_WATCHERINFOXML,0,-1},
-	{'x',SUBTYPE_UNKNOWN,2,85}, /* 63 */
-		{'p',SUBTYPE_UNKNOWN,1,72}, /* 64 */
+	{'x',SUBTYPE_UNKNOWN,2,94}, /* 72 */
+		{'p',SUBTYPE_UNKNOWN,1,81}, /* 73 */
 			{'i',SUBTYPE_UNKNOWN,1,-1},
 				{'d',SUBTYPE_UNKNOWN,1,-1},
 					{'f',SUBTYPE_UNKNOWN,1,-1},
@@ -168,7 +177,7 @@ static type_node_t subtype_tree[] = {
 							{'x',SUBTYPE_UNKNOWN,1,-1},
 								{'m',SUBTYPE_UNKNOWN,1,-1},
 									{'l',SUBTYPE_XPIDFXML,0,-1},
-		{'m',SUBTYPE_UNKNOWN,1,-1}, /* 72 */
+		{'m',SUBTYPE_UNKNOWN,1,-1}, /* 81 */
 			{'l',SUBTYPE_UNKNOWN,1,-1},
 				{'+',SUBTYPE_UNKNOWN,1,-1},
 					{'m',SUBTYPE_UNKNOWN,1,-1},
@@ -181,7 +190,7 @@ static type_node_t subtype_tree[] = {
 												{'i',SUBTYPE_UNKNOWN,1,-1}, 
 													{'d',SUBTYPE_UNKNOWN,1,-1},
 														{'f',SUBTYPE_XML_MSRTC_PIDF,0,-1},
-	{'e',SUBTYPE_UNKNOWN,1,-1}, /* 85 */
+	{'e',SUBTYPE_UNKNOWN,1,-1}, /* 94 */
 		{'x',SUBTYPE_UNKNOWN,1,-1},
 			{'t',SUBTYPE_UNKNOWN,1,-1},
 				{'e',SUBTYPE_UNKNOWN,1,-1},
@@ -269,7 +278,9 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
 				node = type_tree[node].next;
 			}
 			if (node!=-1 && type_tree[node].nr_sons)
-				node++;
+				node++; 
+				/* ? increment only for (p < end - 1), 
+				 * otherwise will not work for final nodes with children */
 			p++;
 		}
 		if (p==end || mark==p)
@@ -304,7 +315,7 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
 		while (p<end && is_mime_char(*p) ) {
 			while(node!=-1 && !is_char_equal(*p,subtype_tree[node].c) )
 				node = subtype_tree[node].next;
-			if (node!=-1 && subtype_tree[node].nr_sons)
+			if (node!=-1 && subtype_tree[node].nr_sons && (p < end - 1))
 				node++;
 			p++;
 		}

+ 1 - 0
parser/parse_content.h

@@ -61,6 +61,7 @@ struct mime_type {
 #define SUBTYPE_WATCHERINFOXML     10
 #define SUBTYPE_EXTERNAL_BODY      11
 #define SUBTYPE_XML_MSRTC_PIDF     12
+#define SUBTYPE_CPIM_PIDFXML       13
 #define SUBTYPE_ALL          0xfe
 #define SUBTYPE_UNKNOWN      0xff