Dummy IRI parsing. Needed to fix segfault bug, when freeing person's URI
[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 IRI *
43 iri_new_from_string (char *str)
44 {
45   IRI *iri;
46   return iri_new ();
47 }
48
49 void
50 iri_delete (IRI *iri)
51 {
52   if (iri->scheme)
53     g_free (iri->scheme);
54   if (iri->host)
55     g_free (iri->host);
56   if (iri->path)
57     g_free (iri->path);
58   g_slice_free (IRI, iri);
59 }
60
61 IRI *
62 iri_copy (IRI *iri)
63 {
64   IRI *niri;
65   niri = g_slice_new (IRI);
66   niri->scheme = g_strdup (iri->scheme);
67   niri->host = g_strdup (iri->host);
68   niri->path = g_strdup (iri->path);
69   return niri;
70 }
71
72 char *
73 iri_get_scheme (IRI *iri)
74 {
75   return iri->scheme;
76 }
77
78 void
79 iri_set_scheme (IRI *iri, char *scheme)
80 {
81   if (iri->scheme)
82     g_free (iri->scheme);
83   iri->scheme = g_strdup (iri->scheme);
84 }
85
86 char *
87 iri_get_host (IRI *iri)
88 {
89   return iri->host;
90 }
91
92 void
93 iri_set_host (IRI *iri, char *host)
94 {
95   if (iri->host)
96     g_free (iri->host);
97   iri->host = g_strdup (host);
98 }
99
100 char *
101 iri_get_path (IRI *iri)
102 {
103   return iri->path;
104 }
105
106 void
107 iri_set_path (IRI *iri, char *path)
108 {
109   if (iri->path)
110     g_free (iri->path);
111   iri->path = g_strdup (path);
112 }
113
114 char *
115 iri_get_string (IRI *iri)
116 {
117   if (iri->scheme == NULL || iri->host == NULL || iri->path == NULL)
118     return NULL;
119   return g_strconcat (iri->scheme, iri->host, iri->path, NULL);
120 }