Added more interface for IRI
[cascardo/atompub.git] / iri / iri.c
1 /*
2  *  Copyright (C) 2007  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 _iri
25 {
26   char *scheme;
27   char *host;
28   char *path;
29 };
30
31 IRI *
32 iri_new ()
33 {
34   IRI *iri;
35   iri = g_slice_new (IRI);
36   iri->scheme = NULL;
37   iri->host = NULL;
38   iri->path = NULL;
39   return iri;
40 }
41
42 void
43 iri_delete (IRI *iri)
44 {
45   if (iri->scheme)
46     g_free (iri->scheme);
47   if (iri->host)
48     g_free (iri->host);
49   if (iri->path)
50     g_free (iri->path);
51   g_slice_free (IRI, iri);
52 }
53
54 IRI *
55 iri_copy (IRI *iri)
56 {
57   IRI *niri;
58   niri = g_slice_new (IRI);
59   niri->scheme = g_strdup (iri->scheme);
60   niri->host = g_strdup (iri->host);
61   niri->path = g_strdup (iri->path);
62   return niri;
63 }
64
65 char *
66 iri_get_scheme (IRI *iri)
67 {
68   return iri->scheme;
69 }
70
71 void
72 iri_set_scheme (IRI *iri, char *scheme)
73 {
74   if (iri->scheme)
75     g_free (iri->scheme);
76   iri->scheme = g_strdup (iri->scheme);
77 }
78
79 char *
80 iri_get_host (IRI *iri)
81 {
82   return iri->host;
83 }
84
85 void
86 iri_set_host (IRI *iri, char *host)
87 {
88   if (iri->host)
89     g_free (iri->host);
90   iri->host = g_strdup (host);
91 }
92
93 char *
94 iri_get_path (IRI *iri)
95 {
96   return iri->path;
97 }
98
99 void
100 iri_set_path (IRI *iri, char *path)
101 {
102   if (iri->path)
103     g_free (iri->path);
104   iri->path = g_strdup (path);
105 }
106
107 char *
108 iri_get_string (IRI *iri)
109 {
110   if (iri->scheme == NULL || iri->host == NULL || iri->path == NULL)
111     return NULL;
112   return g_strconcat (iri->scheme, iri->host, iri->path, NULL);
113 }