Started adding support for Entry Content.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 8 Feb 2009 14:59:48 +0000 (12:59 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 8 Feb 2009 14:59:48 +0000 (12:59 -0200)
The required and long expected support for entry content has get
started. We have some not implemented functions and it is possible to
get some inconsistencies, like setting the content as xmlnode after
creating a content with a different text and being able to retrieve the
original text after that.

It is also not integrated into AtomEntry, but we are getting closer with
this step.

atom/Makefile.am
atom/content.c [new file with mode: 0644]
include/atompub/Makefile.am
include/atompub/atom-xml.h
include/atompub/atom.h
include/atompub/content-xml.h [new file with mode: 0644]
include/atompub/content.h [new file with mode: 0644]

index ad734e5..7978733 100644 (file)
@@ -1,7 +1,7 @@
 lib_LTLIBRARIES = libatom.la
 libatom_la_SOURCES = id.c entry.c person.c category.c feed.c \
                config.c ctx.c backend.c error.c frontend.c request.c \
-               core.c
+               core.c content.c
 libatom_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
 libatom_la_CFLAGS += $(XML_CFLAGS) $(GIO_CFLAGS) $(SOUP_CFLAGS)
 libatom_la_LIBADD = $(GIO_LIBS) $(GLIB_LIBS) $(XML_LIBS) $(SOUP_LIBS)
diff --git a/atom/content.c b/atom/content.c
new file mode 100644 (file)
index 0000000..01e3ab0
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ *  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">&lt;br&gt;</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);
+}
index 1b94248..d140d65 100644 (file)
@@ -2,4 +2,4 @@ pkginclude_HEADERS = atom.h config.h ctx.h entry.h person.h error.h feed.h \
                id.h iri.h backend.h atom-glib.h error-glib.h atom-xml.h \
                entry-xml.h person-xml.h feed-xml.h globals.h \
                map.h frontend.h request.h core.h category.h \
-               category-xml.h
+               category-xml.h content.h content-xml.h
index 03bec00..dfc13a3 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <atompub/person-xml.h>
 #include <atompub/category-xml.h>
+#include <atompub/content-xml.h>
 #include <atompub/entry-xml.h>
 #include <atompub/feed-xml.h>
 
index 926d250..c0c5175 100644 (file)
@@ -26,6 +26,7 @@
 #include <atompub/error.h>
 #include <atompub/iri.h>
 #include <atompub/id.h>
+#include <atompub/content.h>
 #include <atompub/entry.h>
 #include <atompub/person.h>
 #include <atompub/category.h>
diff --git a/include/atompub/content-xml.h b/include/atompub/content-xml.h
new file mode 100644 (file)
index 0000000..4f01251
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *  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.
+ */
+
+
+#ifndef ATOMPUB_CONTENT_XML_H
+#define ATOMPUB_CONTENT_XML_H
+
+#include <atompub/content.h>
+
+#include <libxml/tree.h>
+
+AtomContent * atom_content_new_xmlnode (char *, xmlNodePtr);
+xmlNodePtr atom_content_to_xmlnode (AtomContent *);
+xmlNodePtr atom_content_content_to_xmlnode (AtomContent *);
+void atom_content_content_set_xmlnode (AtomContent *, xmlNodePtr);
+
+#endif
diff --git a/include/atompub/content.h b/include/atompub/content.h
new file mode 100644 (file)
index 0000000..30073ca
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  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.
+ */
+
+
+#ifndef ATOMPUB_CONTENT_H
+#define ATOMPUB_CONTENT_H
+
+#include <sys/types.h>
+
+typedef struct _atom_content AtomContent;
+
+AtomContent * atom_content_new (char *, char *, size_t);
+AtomContent * atom_content_new_src (char *, char *);
+AtomContent * atom_content_new_data_len (char *, size_t);
+void atom_content_delete (AtomContent *);
+char * atom_content_type (AtomContent *);
+void atom_content_type_set (AtomContent *, char *);
+char * atom_content_src (AtomContent *);
+void atom_content_src_set (AtomContent *, char *);
+void atom_content_content (AtomContent *, char **, size_t *);
+void atom_content_content_set (AtomContent *, char *, size_t);
+void atom_content_string (AtomContent *, char **, size_t *);
+
+#endif