+/*
+ * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include <atompub/content.h>
+#include <atompub/content-xml.h>
+
+#include <glib.h>
+#include <libxml/tree.h>
+#include <string.h>
+
+struct _atom_content
+{
+ char *type;
+ char *src;
+ char *content;
+ size_t content_len;
+ xmlNodePtr xmlcontent;
+};
+
+AtomContent *
+atom_content_new (char *type, char *buffer, size_t len)
+{
+ AtomContent *content;
+ content = g_slice_new0 (AtomContent);
+ content->type = g_strdup (type);
+ content->content = g_malloc (len);
+ memcpy (content->content, buffer, len);
+ content->content_len = len;
+ return content;
+}
+
+AtomContent *
+atom_content_new_src (char *type, char *src)
+{
+ AtomContent *content;
+ content = g_slice_new0 (AtomContent);
+ content->type = g_strdup (type);
+ content->src = g_strdup (src);
+ return content;
+}
+
+AtomContent *
+atom_content_new_data_len (char *buffer, size_t len)
+{
+ /* TODO: Here we decode the XML to find content type, possible
+ source and data */
+ return NULL;
+}
+
+void
+atom_content_delete (AtomContent *content)
+{
+ if (content->type)
+ g_free (content->type);
+ if (content->src)
+ g_free (content->src);
+ if (content->content)
+ g_free (content->content);
+ if (content->xmlcontent)
+ xmlFreeNode (content->xmlcontent);
+ g_slice_free (AtomContent, content);
+}
+
+char *
+atom_content_type (AtomContent *content)
+{
+ return content->type;
+}
+
+void
+atom_content_type_set (AtomContent *content, char *type)
+{
+ if (content->type)
+ g_free (content->type);
+ content->type = g_strdup (type);
+}
+
+char *
+atom_content_src (AtomContent *content)
+{
+ return content->src;
+}
+
+void
+atom_content_src_set (AtomContent *content, char *src)
+{
+ if (content->src)
+ g_free (content->src);
+ content->src = g_strdup (src);
+}
+
+void
+atom_content_content (AtomContent *content, char **buffer, size_t *len)
+{
+ /* TODO: Copy the content or allocated the buffer? */
+}
+
+void
+atom_content_content_set (AtomContent *content, char *buffer, size_t len)
+{
+ if (content->content)
+ g_free (content->content);
+ content->content = g_malloc (len);
+ memcpy (content->content, buffer, len);
+}
+
+void
+atom_content_string (AtomContent *content, char **buffer, size_t *len)
+{
+ /* TODO: convert everything into a string, like
+ "<content type="html"><br></content>" */
+}
+
+AtomContent *
+atom_content_new_xmlnode (char *type, xmlNodePtr node)
+{
+ AtomContent *content;
+ content = g_slice_new0 (AtomContent);
+ content->type = g_strdup (type);
+ content->xmlcontent = xmlCopyNodeList (node);
+ return content;
+}
+
+xmlNodePtr
+atom_content_to_xmlnode (AtomContent *content)
+{
+ /* TODO: Convert everything into a xmlnode */
+ return NULL;
+}
+
+xmlNodePtr
+atom_content_content_xmlnode (AtomContent *content)
+{
+ return content->xmlcontent;
+}
+
+void
+atom_content_content_set_xmlnode (AtomContent *content, xmlNodePtr node)
+{
+ if (content->xmlcontent)
+ xmlFreeNode (content->xmlcontent);
+ content->xmlcontent = xmlCopyNodeList (node);
+}