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>
33 atom_person_new (char *name)
36 person = g_slice_new (AtomPerson);
37 person->name = g_strdup (name);
44 atom_person_delete (AtomPerson *person)
47 g_free (person->name);
49 iri_delete (person->uri);
51 g_free (person->email);
52 g_slice_free (AtomPerson, person);
56 atom_person_name (AtomPerson *person)
62 atom_person_name_set (AtomPerson *person, char *name)
65 g_free (person->name);
66 person->name = g_strdup (name);
70 atom_person_uri (AtomPerson *person)
76 atom_person_uri_set (AtomPerson *person, IRI *uri)
79 iri_delete (person->uri);
80 person->uri = iri_copy (uri);
84 atom_person_email (AtomPerson *person)
90 atom_person_email_set (AtomPerson *person, char *email)
93 g_free (person->email);
94 person->email = g_strdup (email);
98 atom_person_to_xmlnode (AtomPerson *person, char *elname)
101 node = xmlNewNode (NULL, elname);
102 xmlNewTextChild (node, NULL, "name", person->name);
104 xmlNewTextChild (node, NULL, "uri", iri_get_string (person->uri));
106 xmlNewTextChild (node, NULL, "email", person->email);
111 atom_person_new_from_xmlnode (xmlNodePtr node)
115 person = g_slice_new0 (AtomPerson);
116 for (child = node->xmlChildrenNode; child != NULL; child = child->next)
118 char *content = xmlNodeGetContent (child->xmlChildrenNode);
119 if (!xmlStrcmp (child->name, "name"))
120 person->name = content;
121 else if (!xmlStrcmp (child->name, "uri"))
122 person->uri = iri_new_from_string (content);
123 else if (!xmlStrcmp (child->name, "email"))
124 person->email = content;