From: Thadeu Lima de Souza Cascardo Date: Wed, 17 Dec 2008 01:29:44 +0000 (-0200) Subject: Added support for category element X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fatompub.git;a=commitdiff_plain;h=d2405ffa69d9d7ff3eea3ced764355ed665c7ae1 Added support for category element A new object to represent an entry or feed category. --- diff --git a/atom/Makefile.am b/atom/Makefile.am index 0206273..166e8fc 100644 --- a/atom/Makefile.am +++ b/atom/Makefile.am @@ -1,5 +1,5 @@ lib_LTLIBRARIES = libatom.la -libatom_la_SOURCES = id.c entry.c person.c feed.c \ +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 libatom_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS) diff --git a/atom/category.c b/atom/category.c new file mode 100644 index 0000000..6b18679 --- /dev/null +++ b/atom/category.c @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2008 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 + +struct _atom_category +{ + char *term; + IRI *scheme; + char *label; +}; + +AtomCategory * +atom_category_new (char *term) +{ + AtomCategory *category; + category = g_slice_new (AtomCategory); + category->term = g_strdup (term); + category->scheme = NULL; + category->label = NULL; + return category; +} + +void +atom_category_delete (AtomCategory *category) +{ + if (category->term) + g_free (category->term); + if (category->scheme) + iri_delete (category->scheme); + if (category->label) + g_free (category->label); + g_slice_free (AtomCategory, category); +} + +char * +atom_category_term (AtomCategory *category) +{ + return category->term; +} + +void +atom_category_term_set (AtomCategory *category, char *term) +{ + if (category->term) + g_free (category->term); + category->term = g_strdup (term); +} + +IRI * +atom_category_scheme (AtomCategory *category) +{ + return category->scheme; +} + +void +atom_category_scheme_set (AtomCategory *category, IRI *scheme) +{ + if (category->scheme) + iri_delete (category->scheme); + category->scheme = iri_copy (scheme); +} + +char * +atom_category_label (AtomCategory *category) +{ + return category->label; +} + +void +atom_category_label_set (AtomCategory *category, char *label) +{ + if (category->label) + g_free (category->label); + category->label = g_strdup (label); +} + +xmlNodePtr +atom_category_to_xmlnode (AtomCategory *category, char *elname) +{ + xmlNodePtr node; + node = xmlNewNode (NULL, elname); + xmlNewTextChild (node, NULL, "term", category->term); + if (category->scheme) + xmlNewTextChild (node, NULL, "scheme", iri_get_string (category->scheme)); + if (category->label) + xmlNewTextChild (node, NULL, "label", category->label); + return node; +} + +AtomPerson * +atom_category_new_from_xmlnode (xmlNodePtr node) +{ + xmlNodePtr child; + AtomCategory *category; + category = g_slice_new0 (AtomCategory); + for (child = node->xmlChildrenNode; child != NULL; child = child->next) + { + char *content = xmlNodeGetContent (child->xmlChildrenNode); + if (!xmlStrcmp (child->name, "term")) + category->term = content; + else if (!xmlStrcmp (child->name, "scheme")) + category->scheme = iri_new_from_string (content); + else if (!xmlStrcmp (child->name, "label")) + category->label = content; + else + xmlFree (content); + } + return category; +} diff --git a/include/atompub/Makefile.am b/include/atompub/Makefile.am index 1ac753d..8af120b 100644 --- a/include/atompub/Makefile.am +++ b/include/atompub/Makefile.am @@ -1,4 +1,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 + map.h frontend.h request.h core.h category.h diff --git a/include/atompub/atom-xml.h b/include/atompub/atom-xml.h index 5ae430d..03bec00 100644 --- a/include/atompub/atom-xml.h +++ b/include/atompub/atom-xml.h @@ -21,6 +21,7 @@ #define ATOMPUB_ATOM_XML_H #include +#include #include #include diff --git a/include/atompub/atom.h b/include/atompub/atom.h index 15e18e9..926d250 100644 --- a/include/atompub/atom.h +++ b/include/atompub/atom.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/include/atompub/category-xml.h b/include/atompub/category-xml.h new file mode 100644 index 0000000..d0ce07a --- /dev/null +++ b/include/atompub/category-xml.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2008 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 ATOM_CATEGORY_XML_H +#define ATOM_CATEGORY_XML_H + +#include + +#include + +xmlNodePtr atom_category_to_xmlnode (AtomCategory *, char *); +AtomCategory * atom_category_new_from_xmlnode (xmlNodePtr); + +#endif diff --git a/include/atompub/category.h b/include/atompub/category.h new file mode 100644 index 0000000..5b88408 --- /dev/null +++ b/include/atompub/category.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008 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 ATOM_CATEGORY_H +#define ATOM_CATEGORY_H + +#include + +typedef struct _atom_category AtomCategory; + +AtomCategory * atom_category_new (char *); +void atom_category_delete (AtomCategory *); +char * atom_category_term (AtomCategory *); +void atom_category_term_set (AtomCategory *, char *); +IRI * atom_category_scheme (AtomCategory *); +void atom_category_scheme_set (AtomCategory *, IRI *); +char * atom_category_label (AtomCategory *); +void atom_category_label_set (AtomCategory *, char *); + +#endif