[evolution-data-server] Define a boxed GType for CamelURL.



commit d051278f5dfbb28cf5ab0fbc97a3259f2f67c56d
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Apr 17 19:59:15 2011 -0400

    Define a boxed GType for CamelURL.
    
    And clean up the header file.

 camel/camel-url.c                       |  107 +++++++++++++++++++++++++------
 camel/camel-url.h                       |   72 +++++++++++++--------
 docs/reference/camel/camel-sections.txt |    3 +
 3 files changed, 137 insertions(+), 45 deletions(-)
---
diff --git a/camel/camel-url.c b/camel/camel-url.c
index 7f8590e..1dedf5f 100644
--- a/camel/camel-url.c
+++ b/camel/camel-url.c
@@ -45,6 +45,20 @@ static void output_param (GQuark key_id, gpointer data, gpointer user_data);
 
 static void append_url_encoded (GString *str, const gchar *in, const gchar *extra_enc_chars);
 
+GType
+camel_url_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (G_UNLIKELY (type == G_TYPE_INVALID))
+		type = g_boxed_type_register_static (
+			"CamelURL",
+			(GBoxedCopyFunc) camel_url_copy,
+			(GBoxedFreeFunc) camel_url_free);
+
+	return type;
+}
+
 /**
  * camel_url_new_with_base:
  * @base: a base URL
@@ -433,16 +447,6 @@ camel_url_free (CamelURL *url)
 	}
 }
 
-#define DEFINE_CAMEL_URL_SET(part)			\
-void							\
-camel_url_set_##part (CamelURL *url, const gchar *part)	\
-{							\
-	g_return_if_fail (url != NULL);			\
-							\
-	g_free (url->part);				\
-	url->part = g_strdup (part);			\
-}
-
 /**
  * camel_url_set_protocol:
  * @url: a #CamelURL
@@ -450,7 +454,15 @@ camel_url_set_##part (CamelURL *url, const gchar *part)	\
  *
  * Set the protocol of a #CamelURL.
  **/
-DEFINE_CAMEL_URL_SET (protocol)
+void
+camel_url_set_protocol (CamelURL *url,
+                        const gchar *protocol)
+{
+	g_return_if_fail (url != NULL);
+
+	g_free (url->protocol);
+	url->protocol = g_strdup (protocol);
+}
 
 /**
  * camel_url_set_user:
@@ -459,7 +471,16 @@ DEFINE_CAMEL_URL_SET (protocol)
  *
  * Set the user of a #CamelURL.
  **/
-DEFINE_CAMEL_URL_SET (user)
+void
+camel_url_set_user (CamelURL *url,
+                    const gchar *user)
+{
+	g_return_if_fail (url != NULL);
+
+	g_free (url->user);
+	url->user = g_strdup (user);
+}
+
 
 /**
  * camel_url_set_authmech:
@@ -468,7 +489,15 @@ DEFINE_CAMEL_URL_SET (user)
  *
  * Set the authmech of a #CamelURL.
  **/
-DEFINE_CAMEL_URL_SET (authmech)
+void
+camel_url_set_authmech (CamelURL *url,
+                        const gchar *authmech)
+{
+	g_return_if_fail (url != NULL);
+
+	g_free (url->authmech);
+	url->authmech = g_strdup (authmech);
+}
 
 /**
  * camel_url_set_passwd:
@@ -477,7 +506,15 @@ DEFINE_CAMEL_URL_SET (authmech)
  *
  * Set the password of a #CamelURL.
  **/
-DEFINE_CAMEL_URL_SET (passwd)
+void
+camel_url_set_passwd (CamelURL *url,
+                      const gchar *passwd)
+{
+	g_return_if_fail (url != NULL);
+
+	g_free (url->passwd);
+	url->passwd = g_strdup (passwd);
+}
 
 /**
  * camel_url_set_host:
@@ -486,7 +523,15 @@ DEFINE_CAMEL_URL_SET (passwd)
  *
  * Set the hostname of a #CamelURL.
  **/
-DEFINE_CAMEL_URL_SET (host)
+void
+camel_url_set_host (CamelURL *url,
+                    const gchar *host)
+{
+	g_return_if_fail (url != NULL);
+
+	g_free (url->host);
+	url->host = g_strdup (host);
+}
 
 /**
  * camel_url_set_path:
@@ -495,7 +540,15 @@ DEFINE_CAMEL_URL_SET (host)
  *
  * Set the path component of a #CamelURL.
  **/
-DEFINE_CAMEL_URL_SET (path)
+void
+camel_url_set_path (CamelURL *url,
+                    const gchar *path)
+{
+	g_return_if_fail (url != NULL);
+
+	g_free (url->path);
+	url->path = g_strdup (path);
+}
 
 /**
  * camel_url_set_query:
@@ -504,7 +557,15 @@ DEFINE_CAMEL_URL_SET (path)
  *
  * Set the query of a #CamelURL.
  **/
-DEFINE_CAMEL_URL_SET (query)
+void
+camel_url_set_query (CamelURL *url,
+                     const gchar *query)
+{
+	g_return_if_fail (url != NULL);
+
+	g_free (url->query);
+	url->query = g_strdup (query);
+}
 
 /**
  * camel_url_set_fragment:
@@ -513,7 +574,15 @@ DEFINE_CAMEL_URL_SET (query)
  *
  * Set the fragment of a #CamelURL.
  **/
-DEFINE_CAMEL_URL_SET (fragment)
+void
+camel_url_set_fragment (CamelURL *url,
+                        const gchar *fragment)
+{
+	g_return_if_fail (url != NULL);
+
+	g_free (url->fragment);
+	url->fragment = g_strdup (fragment);
+}
 
 /**
  * camel_url_set_port:
@@ -712,7 +781,7 @@ camel_url_equal (gconstpointer v, gconstpointer v2)
  * Returns: a duplicate copy of @in
  **/
 CamelURL *
-camel_url_copy (const CamelURL *in)
+camel_url_copy (CamelURL *in)
 {
 	CamelURL *out;
 
diff --git a/camel/camel-url.h b/camel/camel-url.h
index 3f2fae6..a8e89c1 100644
--- a/camel/camel-url.h
+++ b/camel/camel-url.h
@@ -32,10 +32,14 @@
 
 #include <glib.h>
 
+#define CAMEL_TYPE_URL (camel_url_get_type ())
+
 G_BEGIN_DECLS
 
+typedef struct _CamelURL CamelURL;
+
 /* if this changes, remember to change camel_url_copy */
-typedef struct _CamelURL {
+struct _CamelURL {
 	gchar  *protocol;
 	gchar  *user;
 	gchar  *authmech;
@@ -46,7 +50,7 @@ typedef struct _CamelURL {
 	GData *params;
 	gchar  *query;
 	gchar  *fragment;
-} CamelURL;
+};
 
 typedef enum {
 	CAMEL_URL_HIDE_PASSWORD = 1 << 0,
@@ -57,33 +61,49 @@ typedef enum {
 #define CAMEL_URL_HIDE_ALL \
 	(CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS | CAMEL_URL_HIDE_AUTH)
 
-CamelURL *camel_url_new_with_base (CamelURL *base, const gchar *url_string);
-CamelURL *camel_url_new (const gchar *url_string, GError **error);
-gchar *camel_url_to_string (CamelURL *url, CamelURLFlags flags);
-void camel_url_free (CamelURL *url);
+GType		camel_url_get_type		(void) G_GNUC_CONST;
+CamelURL *	camel_url_new_with_base		(CamelURL *base,
+						 const gchar *url_string);
+CamelURL *	camel_url_new			(const gchar *url_string,
+						 GError **error);
+gchar *		camel_url_to_string		(CamelURL *url,
+						 CamelURLFlags flags);
+guint		camel_url_hash			(gconstpointer v);
+gint		camel_url_equal			(gconstpointer v,
+						 gconstpointer v2);
+CamelURL *	camel_url_copy			(CamelURL *in);
+void		camel_url_free			(CamelURL *url);
 
-gchar *camel_url_encode (const gchar *part, const gchar *escape_extra);
-void camel_url_decode (gchar *part);
-gchar *camel_url_decode_path (const gchar *path);
+gchar *		camel_url_encode		(const gchar *part,
+						 const gchar *escape_extra);
+void		camel_url_decode		(gchar *part);
+gchar *		camel_url_decode_path		(const gchar *path);
 
 /* for editing url's */
-void camel_url_set_protocol (CamelURL *url, const gchar *protocol);
-void camel_url_set_user (CamelURL *url, const gchar *user);
-void camel_url_set_authmech (CamelURL *url, const gchar *authmech);
-void camel_url_set_passwd (CamelURL *url, const gchar *passwd);
-void camel_url_set_host (CamelURL *url, const gchar *host);
-void camel_url_set_port (CamelURL *url, gint port);
-void camel_url_set_path (CamelURL *url, const gchar *path);
-void camel_url_set_param (CamelURL *url, const gchar *name, const gchar *value);
-void camel_url_set_query (CamelURL *url, const gchar *query);
-void camel_url_set_fragment (CamelURL *url, const gchar *fragment);
-
-const gchar *camel_url_get_param (CamelURL *url, const gchar *name);
-
-/* for putting url's into hash tables */
-guint camel_url_hash (gconstpointer v);
-gint camel_url_equal (gconstpointer v, gconstpointer v2);
-CamelURL *camel_url_copy (const CamelURL *in);
+void		camel_url_set_protocol		(CamelURL *url,
+						 const gchar *protocol);
+void		camel_url_set_user		(CamelURL *url,
+						 const gchar *user);
+void		camel_url_set_authmech		(CamelURL *url,
+						 const gchar *authmech);
+void		camel_url_set_passwd		(CamelURL *url,
+						 const gchar *passwd);
+void		camel_url_set_host		(CamelURL *url,
+						 const gchar *host);
+void		camel_url_set_port		(CamelURL *url,
+						 gint port);
+void		camel_url_set_path		(CamelURL *url,
+						 const gchar *path);
+void		camel_url_set_param		(CamelURL *url,
+						 const gchar *name,
+						 const gchar *value);
+void		camel_url_set_query		(CamelURL *url,
+						 const gchar *query);
+void		camel_url_set_fragment		(CamelURL *url,
+						 const gchar *fragment);
+
+const gchar *	camel_url_get_param		(CamelURL *url,
+						 const gchar *name);
 
 G_END_DECLS
 
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index 1ab9804..d94d791 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -2880,6 +2880,9 @@ camel_url_get_param
 camel_url_hash
 camel_url_equal
 camel_url_copy
+<SUBSECTION Standard>
+CAMEL_TYPE_URL
+camel_url_get_type
 </SECTION>
 
 <SECTION>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]