[network-manager-applet/aleksander/mobile-providers: 12/19] libnm-gtk: return DNS list defined in the access methods as an array of strings



commit d99d2b52a970b5b7031f5b9f947a85ac7a4098aa
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Tue Nov 27 13:58:03 2012 +0100

    libnm-gtk: return DNS list defined in the access methods as an array of strings

 src/libnm-gtk/nm-mobile-providers.c |   49 ++++++++++++++++++++++-------------
 src/libnm-gtk/nm-mobile-providers.h |   20 +++++++-------
 2 files changed, 41 insertions(+), 28 deletions(-)
---
diff --git a/src/libnm-gtk/nm-mobile-providers.c b/src/libnm-gtk/nm-mobile-providers.c
index cd49c59..c1da2f2 100644
--- a/src/libnm-gtk/nm-mobile-providers.c
+++ b/src/libnm-gtk/nm-mobile-providers.c
@@ -57,7 +57,7 @@ struct _NMAMobileAccessMethod {
 	char *username;
 	char *password;
 	char *gateway;
-	GSList *dns; /* GSList of 'char *' */
+	GArray *dns; /* GArray of 'char *' */
 
 	/* Only used with 3GPP family type providers */
 	char *apn;
@@ -103,8 +103,14 @@ nma_mobile_access_method_unref (NMAMobileAccessMethod *method)
 		g_free (method->password);
 		g_free (method->gateway);
 		g_free (method->apn);
-		g_slist_foreach (method->dns, (GFunc) g_free, NULL);
-		g_slist_free (method->dns);
+
+		if (method->dns) {
+			guint i;
+
+			for (i = 0; i < method->dns->len; i++)
+				g_free (g_array_index (method->dns, gchar *, i));
+			g_array_unref (method->dns);
+		}
 
 		g_slice_free (NMAMobileAccessMethod, method);
 	}
@@ -165,14 +171,14 @@ nma_mobile_access_method_get_gateway (NMAMobileAccessMethod *method)
 /**
  * nma_mobile_access_method_get_dns:
  *
- * Returns: (element-type utf8) (transfer none): the list of DNS.
+ * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): the list of DNS.
  */
-const GSList *
+const gchar **
 nma_mobile_access_method_get_dns (NMAMobileAccessMethod *method)
 {
 	g_return_val_if_fail (method != NULL, NULL);
 
-	return method->dns;
+	return method->dns ? (const gchar **)method->dns->data : NULL;
 }
 
 /**
@@ -778,14 +784,15 @@ parser_gsm_apn_end (MobileParser *parser,
 		parser->current_method->password = parser->text_buffer;
 		parser->text_buffer = NULL;
 	} else if (!strcmp (name, "dns")) {
-		parser->current_method->dns = g_slist_prepend (parser->current_method->dns, parser->text_buffer);
+		if (!parser->current_method->dns)
+			parser->current_method->dns = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), 2);
+		g_array_append_val (parser->current_method->dns, parser->text_buffer);
 		parser->text_buffer = NULL;
 	} else if (!strcmp (name, "gateway")) {
 		parser->current_method->gateway = parser->text_buffer;
 		parser->text_buffer = NULL;
 	} else if (!strcmp (name, "apn")) {
 		parser->current_method->family = NMA_MOBILE_FAMILY_3GPP;
-		parser->current_method->dns = g_slist_reverse (parser->current_method->dns);
 
 		if (!parser->current_method->name)
 			parser->current_method->name = g_strdup (_("Default"));
@@ -809,14 +816,15 @@ parser_cdma_end (MobileParser *parser,
 		parser->current_method->password = parser->text_buffer;
 		parser->text_buffer = NULL;
 	} else if (!strcmp (name, "dns")) {
-		parser->current_method->dns = g_slist_prepend (parser->current_method->dns, parser->text_buffer);
+		if (!parser->current_method->dns)
+			parser->current_method->dns = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), 1);
+		g_array_append_val (parser->current_method->dns, parser->text_buffer);
 		parser->text_buffer = NULL;
 	} else if (!strcmp (name, "gateway")) {
 		parser->current_method->gateway = parser->text_buffer;
 		parser->text_buffer = NULL;
 	} else if (!strcmp (name, "cdma")) {
 		parser->current_method->family = NMA_MOBILE_FAMILY_CDMA;
-		parser->current_method->dns = g_slist_reverse (parser->current_method->dns);
 
 		if (!parser->current_method->name)
 			parser->current_method->name = g_strdup (parser->current_provider->name);
@@ -978,17 +986,22 @@ out:
 static void
 dump_generic (NMAMobileAccessMethod *method)
 {
-	GSList *iter;
-	GString *dns;
-
 	g_print ("		  username: %s\n", method->username ? method->username : "");
 	g_print ("		  password: %s\n", method->password ? method->password : "");
 
-	dns = g_string_new (NULL);
-	for (iter = method->dns; iter; iter = g_slist_next (iter))
-		g_string_append_printf (dns, "%s%s", dns->len ? ", " : "", (char *) iter->data);
-	g_print ("		  dns	  : %s\n", dns->str);
-	g_string_free (dns, TRUE);
+	if (method->dns) {
+		guint i;
+		GString *dns;
+
+		dns = g_string_new (NULL);
+		for (i = 0; i < method->dns->len; i++)
+			g_string_append_printf (dns,
+			                        "%s%s",
+			                        i == 0 ? "" : ", ",
+			                        g_array_index (method->dns, char *, i));
+		g_print ("		  dns	  : %s\n", dns->str);
+		g_string_free (dns, TRUE);
+	}
 
 	g_print ("		  gateway : %s\n", method->gateway ? method->gateway : "");
 }
diff --git a/src/libnm-gtk/nm-mobile-providers.h b/src/libnm-gtk/nm-mobile-providers.h
index e8c1d93..908f987 100644
--- a/src/libnm-gtk/nm-mobile-providers.h
+++ b/src/libnm-gtk/nm-mobile-providers.h
@@ -45,16 +45,16 @@ typedef enum {
 
 typedef struct _NMAMobileAccessMethod NMAMobileAccessMethod;
 
-GType                  nma_mobile_access_method_get_type     (void);
-NMAMobileAccessMethod *nma_mobile_access_method_ref          (NMAMobileAccessMethod *method);
-void                   nma_mobile_access_method_unref        (NMAMobileAccessMethod *method);
-const gchar           *nma_mobile_access_method_get_name     (NMAMobileAccessMethod *method);
-const gchar           *nma_mobile_access_method_get_username (NMAMobileAccessMethod *method);
-const gchar           *nma_mobile_access_method_get_password (NMAMobileAccessMethod *method);
-const gchar           *nma_mobile_access_method_get_gateway  (NMAMobileAccessMethod *method);
-const GSList          *nma_mobile_access_method_get_dns      (NMAMobileAccessMethod *method);
-const gchar           *nma_mobile_access_method_get_3gpp_apn (NMAMobileAccessMethod *method);
-NMAMobileFamily        nma_mobile_access_method_get_family   (NMAMobileAccessMethod *method);
+GType                   nma_mobile_access_method_get_type     (void);
+NMAMobileAccessMethod  *nma_mobile_access_method_ref          (NMAMobileAccessMethod *method);
+void                    nma_mobile_access_method_unref        (NMAMobileAccessMethod *method);
+const gchar            *nma_mobile_access_method_get_name     (NMAMobileAccessMethod *method);
+const gchar            *nma_mobile_access_method_get_username (NMAMobileAccessMethod *method);
+const gchar            *nma_mobile_access_method_get_password (NMAMobileAccessMethod *method);
+const gchar            *nma_mobile_access_method_get_gateway  (NMAMobileAccessMethod *method);
+const gchar           **nma_mobile_access_method_get_dns      (NMAMobileAccessMethod *method);
+const gchar            *nma_mobile_access_method_get_3gpp_apn (NMAMobileAccessMethod *method);
+NMAMobileFamily         nma_mobile_access_method_get_family   (NMAMobileAccessMethod *method);
 
 /******************************************************************************/
 /* Mobile provider type */



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