2 * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <atompub/atom.h>
23 #include <libxml/tree.h>
24 #include <libxml/parser.h>
26 #define ATOM_NAMESPACE "http://www.w3.org/2005/Atom"
38 atom_entry_new (char *title, AtomPerson *author)
41 entry = g_slice_new (AtomEntry);
44 entry->title = g_strdup (title);
45 entry->author = author;
46 entry->summary = NULL;
51 atom_entry_new_data_len (char *data, size_t len)
56 entry = g_slice_new0 (AtomEntry);
57 entry->doc = xmlReadMemory (data, len, NULL, NULL, XML_PARSE_RECOVER);
58 if (entry->doc == NULL)
60 g_slice_free (AtomEntry, entry);
63 root = xmlDocGetRootElement (entry->doc);
64 if (xmlStrcmp (root->name, "entry"))
66 xmlFreeDoc (entry->doc);
67 g_slice_free (AtomEntry, entry);
70 for (child = root->xmlChildrenNode; child != NULL; child = child->next)
73 content = xmlNodeGetContent (child->xmlChildrenNode);
74 if (!xmlStrcmp (child->name, "id"))
76 else if (!xmlStrcmp (child->name, "title"))
77 entry->title = content;
78 else if (!xmlStrcmp (child->name, "summary"))
79 entry->summary = content;
80 else if (!xmlStrcmp (child->name, "author"))
81 entry->author = atom_person_new_from_xmlnode (child);
89 atom_entry_delete (AtomEntry *entry)
92 xmlFreeDoc (entry->doc);
96 g_free (entry->title);
98 atom_person_delete (entry->author);
100 g_free (entry->summary);
101 g_slice_free (AtomEntry, entry);
105 atom_entry_id (AtomEntry *entry)
111 atom_entry_id_set (AtomEntry *entry, char *id)
115 entry->id = g_strdup (id);
119 atom_entry_title (AtomEntry *entry)
125 atom_entry_title_set (AtomEntry *entry, char *title)
129 entry->title = g_strdup (entry);
133 atom_entry_author (AtomEntry *entry)
135 return entry->author;
139 atom_entry_author_set (AtomEntry *entry, AtomPerson *author)
142 atom_person_delete (entry->author);
143 entry->author = author;
147 atom_entry_summary (AtomEntry *entry)
149 return entry->summary;
153 atom_entry_summary_set (AtomEntry *entry, char *summary)
156 g_free (entry->summary);
157 entry->summary = g_strdup (summary);
161 atom_entry_string (AtomEntry *entry)
165 xmlDocDumpMemory (entry->doc, &buffer, &size);
170 atom_entry_len (AtomEntry *entry)
174 xmlDocDumpMemory (entry->doc, &buffer, &size);