From b9dbd538caa53d676019ba04b80e28a3692508a1 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Mon, 9 Feb 2009 00:25:43 -0200 Subject: [PATCH] Added atom:content constructore from a xml node. When parsing an entry, we will have the pointer to a xmlnode containing the entire content element, including its type. So, split the buffer constructor into a part that converts it to a xmlDoc and the part that creates the content object from its root xmlnode. --- atom/content.c | 24 +++++++++++++++--------- include/atompub/content-xml.h | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/atom/content.c b/atom/content.c index 2adb776..274e92a 100644 --- a/atom/content.c +++ b/atom/content.c @@ -56,26 +56,18 @@ atom_content_new_src (char *type, char *src) } AtomContent * -atom_content_new_data_len (char *buffer, size_t len) +atom_content_new_from_xmlnode (xmlNodePtr root) { AtomContent *content; - xmlDocPtr doc; - xmlNodePtr root; xmlNodePtr child; - doc = xmlReadMemory (buffer, len, NULL, NULL, - XML_PARSE_RECOVER | XML_PARSE_NOERROR); - if (doc == NULL || (root = xmlDocGetRootElement (doc)) == NULL) - return NULL; if (xmlStrcmp (root->name, "content")) { - xmlFreeDoc (doc); return NULL; } content = g_slice_new0 (AtomContent); if ((content->type = xmlGetProp (root, "type")) == NULL) { g_slice_free (AtomContent, content); - xmlFreeDoc (doc); return NULL; } content->src = xmlGetProp (root, "src"); @@ -95,6 +87,20 @@ atom_content_new_data_len (char *buffer, size_t len) content->content_len = xmlStrlen (content->content); } } + return content; +} + +AtomContent * +atom_content_new_data_len (char * buffer, size_t len) +{ + AtomContent *content; + xmlDocPtr doc; + xmlNodePtr root; + doc = xmlReadMemory (buffer, len, NULL, NULL, + XML_PARSE_RECOVER | XML_PARSE_NOERROR); + if (doc == NULL || (root = xmlDocGetRootElement (doc)) == NULL) + return NULL; + content = atom_content_new_from_xmlnode (root); xmlFreeDoc (doc); return content; } diff --git a/include/atompub/content-xml.h b/include/atompub/content-xml.h index 4f01251..f89c538 100644 --- a/include/atompub/content-xml.h +++ b/include/atompub/content-xml.h @@ -25,6 +25,7 @@ #include AtomContent * atom_content_new_xmlnode (char *, xmlNodePtr); +AtomContent * atom_content_new_from_xmlnode (xmlNodePtr); xmlNodePtr atom_content_to_xmlnode (AtomContent *); xmlNodePtr atom_content_content_to_xmlnode (AtomContent *); void atom_content_content_set_xmlnode (AtomContent *, xmlNodePtr); -- 2.20.1