From 6504e5250e7cbc30c9a1fd2c7b4966a403c9b52c Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sun, 8 Feb 2009 12:59:48 -0200 Subject: [PATCH] Started adding support for Entry Content. 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 | 2 +- atom/content.c | 159 ++++++++++++++++++++++++++++++++++ include/atompub/Makefile.am | 2 +- include/atompub/atom-xml.h | 1 + include/atompub/atom.h | 1 + include/atompub/content-xml.h | 32 +++++++ include/atompub/content.h | 39 +++++++++ 7 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 atom/content.c create mode 100644 include/atompub/content-xml.h create mode 100644 include/atompub/content.h diff --git a/atom/Makefile.am b/atom/Makefile.am index ad734e5..7978733 100644 --- a/atom/Makefile.am +++ b/atom/Makefile.am @@ -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 index 0000000..01e3ab0 --- /dev/null +++ b/atom/content.c @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2009 Thadeu Lima de Souza Cascardo + * + * 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 +#include + +#include +#include +#include + +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 + "<br>" */ +} + +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); +} diff --git a/include/atompub/Makefile.am b/include/atompub/Makefile.am index 1b94248..d140d65 100644 --- a/include/atompub/Makefile.am +++ b/include/atompub/Makefile.am @@ -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 diff --git a/include/atompub/atom-xml.h b/include/atompub/atom-xml.h index 03bec00..dfc13a3 100644 --- a/include/atompub/atom-xml.h +++ b/include/atompub/atom-xml.h @@ -22,6 +22,7 @@ #include #include +#include #include #include diff --git a/include/atompub/atom.h b/include/atompub/atom.h index 926d250..c0c5175 100644 --- a/include/atompub/atom.h +++ b/include/atompub/atom.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/include/atompub/content-xml.h b/include/atompub/content-xml.h new file mode 100644 index 0000000..4f01251 --- /dev/null +++ b/include/atompub/content-xml.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2009 Thadeu Lima de Souza Cascardo + * + * 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 + +#include + +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 index 0000000..30073ca --- /dev/null +++ b/include/atompub/content.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2009 Thadeu Lima de Souza Cascardo + * + * 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 + +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 -- 2.20.1