Copy IRI when setting AtomPerson uri
[cascardo/atompub.git] / atom / person.c
1 /*
2  *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19
20 #include <atompub/atom.h>
21
22 #include <glib.h>
23
24 struct _atom_person
25 {
26   char *name;
27   IRI *uri;
28   char *email;
29 };
30
31 AtomPerson *
32 atom_person_new (char *name)
33 {
34   AtomPerson *person;
35   person = g_slice_new (AtomPerson);
36   person->name = g_strdup (name);
37   person->uri = NULL;
38   person->email = NULL;
39   return person;
40 }
41
42 void
43 atom_person_delete (AtomPerson *person)
44 {
45   if (person->name)
46     g_free (person->name);
47   if (person->uri)
48     iri_delete (person->uri);
49   if (person->email)
50     g_free (person->email);
51   g_slice_free (AtomPerson, person);
52 }
53
54 char *
55 atom_person_name (AtomPerson *person)
56 {
57   return person->name;
58 }
59
60 void
61 atom_person_name_set (AtomPerson *person, char *name)
62 {
63   if (person->name)
64     g_free (person->name);
65   person->name = g_strdup (name);
66 }
67
68 IRI *
69 atom_person_uri (AtomPerson *person)
70 {
71   return person->uri;
72 }
73
74 void
75 atom_person_uri_set (AtomPerson *person, IRI *uri)
76 {
77   if (person->uri)
78     iri_delete (person->uri);
79   person->uri = iri_copy (uri);
80 }
81
82 char *
83 atom_person_email (AtomPerson *person)
84 {
85   return person->email;
86 }
87
88 void
89 atom_person_email_set (AtomPerson *person, char *email)
90 {
91   if (person->email)
92     g_free (person->email);
93   person->email = g_strdup (email);
94 }