All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mbpi: Parse gsm provider name
@ 2014-04-16 14:00 Slava Monich
  2014-04-17  4:07 ` Denis Kenzior
  0 siblings, 1 reply; 10+ messages in thread
From: Slava Monich @ 2014-04-16 14:00 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4062 bytes --]

This gives the provisioning plugin more information to work with and
improves the chance of automatically picking the right AP in case if
we have more than one for the same mcc/mnc combination.
---
 include/gprs-provision.h |  1 +
 plugins/mbpi.c           | 47 +++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/include/gprs-provision.h b/include/gprs-provision.h
index e9eec61..0129cd0 100644
--- a/include/gprs-provision.h
+++ b/include/gprs-provision.h
@@ -31,6 +31,7 @@ extern "C" {
 struct ofono_gprs_provision_data {
 	enum ofono_gprs_context_type type;
 	enum ofono_gprs_proto proto;
+	char *provider_name;
 	char *name;
 	char *apn;
 	char *username;
diff --git a/plugins/mbpi.c b/plugins/mbpi.c
index dff8752..f2b00d0 100644
--- a/plugins/mbpi.c
+++ b/plugins/mbpi.c
@@ -53,6 +53,7 @@ enum MBPI_ERROR {
 struct gsm_data {
 	const char *match_mcc;
 	const char *match_mnc;
+	char *provider_name;
 	GSList *apns;
 	gboolean match_found;
 	gboolean allow_duplicates;
@@ -84,6 +85,7 @@ static GQuark mbpi_error_quark(void)
 
 void mbpi_ap_free(struct ofono_gprs_provision_data *ap)
 {
+	g_free(ap->provider_name);
 	g_free(ap->name);
 	g_free(ap->apn);
 	g_free(ap->username);
@@ -117,6 +119,7 @@ static void text_handler(GMarkupParseContext *context,
 {
 	char **string = userdata;
 
+        g_free(*string);
 	*string = g_strndup(text, text_len);
 }
 
@@ -288,6 +291,7 @@ static void apn_handler(GMarkupParseContext *context, struct gsm_data *gsm,
 	}
 
 	ap = g_new0(struct ofono_gprs_provision_data, 1);
+	ap->provider_name = g_strdup(gsm->provider_name);
 	ap->apn = g_strdup(apn);
 	ap->type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
 	ap->proto = OFONO_GPRS_PROTO_IP;
@@ -454,7 +458,7 @@ static const GMarkupParser provider_parser = {
 	NULL,
 };
 
-static void toplevel_gsm_start(GMarkupParseContext *context,
+static void gsm_provider_start(GMarkupParseContext *context,
 					const gchar *element_name,
 					const gchar **atribute_names,
 					const gchar **attribute_values,
@@ -462,19 +466,53 @@ static void toplevel_gsm_start(GMarkupParseContext *context,
 {
 	struct gsm_data *gsm = userdata;
 
-	if (g_str_equal(element_name, "gsm")) {
+	if (g_str_equal(element_name, "name")) {
+		g_free(gsm->provider_name);
+		gsm->provider_name = NULL;
+		g_markup_parse_context_push(context, &text_parser,
+						&gsm->provider_name);
+	} else if (g_str_equal(element_name, "gsm")) {
 		gsm->match_found = FALSE;
 		g_markup_parse_context_push(context, &gsm_parser, gsm);
 	} else if (g_str_equal(element_name, "cdma"))
 		g_markup_parse_context_push(context, &skip_parser, NULL);
 }
 
+static void gsm_provider_end(GMarkupParseContext *context,
+					const gchar *element_name,
+					gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "name") ||
+				g_str_equal(element_name, "gsm") ||
+				g_str_equal(element_name, "cdma"))
+		g_markup_parse_context_pop(context);
+}
+
+static const GMarkupParser gsm_provider_parser = {
+	gsm_provider_start,
+	gsm_provider_end,
+	NULL,
+	NULL,
+	NULL,
+};
+
+static void toplevel_gsm_start(GMarkupParseContext *context,
+					const gchar *element_name,
+					const gchar **atribute_names,
+					const gchar **attribute_values,
+					gpointer userdata, GError **error)
+{
+	struct gsm_data *gsm = userdata;
+
+	if (g_str_equal(element_name, "provider"))
+		g_markup_parse_context_push(context, &gsm_provider_parser, gsm);
+}
+
 static void toplevel_gsm_end(GMarkupParseContext *context,
 					const gchar *element_name,
 					gpointer userdata, GError **error)
 {
-	if (g_str_equal(element_name, "gsm") ||
-			g_str_equal(element_name, "cdma"))
+	if (g_str_equal(element_name, "provider"))
 		g_markup_parse_context_pop(context);
 }
 
@@ -591,6 +629,7 @@ GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 		gsm.apns = NULL;
 	}
 
+	g_free(gsm.provider_name);
 	return gsm.apns;
 }
 
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-04-18 14:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-16 14:00 [PATCH] mbpi: Parse gsm provider name Slava Monich
2014-04-17  4:07 ` Denis Kenzior
2014-04-17  8:24   ` Slava Monich
2014-04-17 15:40     ` Denis Kenzior
2014-04-17 18:29       ` Slava Monich
2014-04-17 22:12         ` Denis Kenzior
2014-04-17 23:22           ` Slava Monich
2014-04-18  0:58             ` Denis Kenzior
2014-04-18 12:02               ` Slava Monich
2014-04-18 14:56                 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.