From e4be6fb90710d6646526fe0dcc7db9cd70e9179a Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sat, 9 Aug 2008 15:46:43 -0300 Subject: [PATCH] Added more interface for IRI You can set scheme and host part of IRIs now. You can also get it as a string, which should be revised, because of the needed separators. You can also make a copy of a IRI. --- include/atompub/iri.h | 6 ++++++ iri/iri.c | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/include/atompub/iri.h b/include/atompub/iri.h index 0135916..94de6e3 100644 --- a/include/atompub/iri.h +++ b/include/atompub/iri.h @@ -26,7 +26,13 @@ typedef struct _iri IRI; IRI * iri_new (void); void iri_delete (IRI *); +IRI * iri_copy (IRI *); +char *iri_get_scheme (IRI *); +void iri_set_scheme (IRI *, char *); +char * iri_get_host (IRI *); +void iri_set_host (IRI *, char *); char * iri_get_path (IRI *); void iri_set_path (IRI *, char *); +char * iri_get_string (IRI *); #endif diff --git a/iri/iri.c b/iri/iri.c index 47b79ac..dd82a6a 100644 --- a/iri/iri.c +++ b/iri/iri.c @@ -51,6 +51,45 @@ iri_delete (IRI *iri) g_slice_free (IRI, iri); } +IRI * +iri_copy (IRI *iri) +{ + IRI *niri; + niri = g_slice_new (IRI); + niri->scheme = g_strdup (iri->scheme); + niri->host = g_strdup (iri->host); + niri->path = g_strdup (iri->path); + return niri; +} + +char * +iri_get_scheme (IRI *iri) +{ + return iri->scheme; +} + +void +iri_set_scheme (IRI *iri, char *scheme) +{ + if (iri->scheme) + g_free (iri->scheme); + iri->scheme = g_strdup (iri->scheme); +} + +char * +iri_get_host (IRI *iri) +{ + return iri->host; +} + +void +iri_set_host (IRI *iri, char *host) +{ + if (iri->host) + g_free (iri->host); + iri->host = g_strdup (host); +} + char * iri_get_path (IRI *iri) { @@ -64,3 +103,11 @@ iri_set_path (IRI *iri, char *path) g_free (iri->path); iri->path = g_strdup (path); } + +char * +iri_get_string (IRI *iri) +{ + if (iri->scheme == NULL || iri->host == NULL || iri->path == NULL) + return NULL; + return g_strconcat (iri->scheme, iri->host, iri->path, NULL); +} -- 2.20.1