Open Source Telephony
 help / color / mirror / Atom feed
From: Philippe Nunes <philippe.nunes@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API
Date: Tue, 15 Nov 2011 14:04:14 +0100	[thread overview]
Message-ID: <1321362255-11262-3-git-send-email-philippe.nunes@linux.intel.com> (raw)
In-Reply-To: <1321362255-11262-1-git-send-email-philippe.nunes@linux.intel.com>

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

---
 plugins/mbpi.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 plugins/mbpi.h |    2 +
 2 files changed, 153 insertions(+), 0 deletions(-)

diff --git a/plugins/mbpi.c b/plugins/mbpi.c
index 1e41ecb..14aa339 100644
--- a/plugins/mbpi.c
+++ b/plugins/mbpi.c
@@ -58,6 +58,12 @@ struct gsm_data {
 	gboolean allow_duplicates;
 };
 
+struct cdma_data {
+	const char *match_sid;
+	char *provider_name;
+	gboolean match_found;
+};
+
 const char *mbpi_ap_type(enum ofono_gprs_context_type type)
 {
 	switch (type) {
@@ -281,6 +287,34 @@ static void apn_handler(GMarkupParseContext *context, struct gsm_data *gsm,
 	g_markup_parse_context_push(context, &apn_parser, ap);
 }
 
+static void sid_handler(GMarkupParseContext *context,
+				struct cdma_data *cdma,
+				const gchar **attribute_names,
+				const gchar **attribute_values,
+				GError **error)
+{
+	const char *sid = NULL;
+	int i;
+
+	if (cdma->match_found == TRUE)
+		return;
+
+	for (i = 0; attribute_names[i]; i++) {
+		if (g_str_equal(attribute_names[i], "value") == TRUE)
+			sid = attribute_values[i];
+	}
+
+	if (sid == NULL) {
+		mbpi_g_set_error(context, error, G_MARKUP_ERROR,
+					G_MARKUP_ERROR_MISSING_ATTRIBUTE,
+					"Missing attribute: sid");
+		return;
+	}
+
+	if (g_str_equal(sid, cdma->match_sid))
+		cdma->match_found = TRUE;
+}
+
 static void gsm_start(GMarkupParseContext *context, const gchar *element_name,
 			const gchar **attribute_names,
 			const gchar **attribute_values,
@@ -347,6 +381,74 @@ static const GMarkupParser gsm_parser = {
 	NULL,
 };
 
+static void cdma_start(GMarkupParseContext *context, const gchar *element_name,
+			const gchar **attribute_names,
+			const gchar **attribute_values,
+			gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "sid")) {
+		struct cdma_data *cdma = userdata;
+		/*
+		 * For entries with multiple sid elements, don't bother
+		 * searching if we already have a match
+		 */
+		if (cdma->match_found == TRUE)
+			return;
+
+		sid_handler(context, cdma, attribute_names, attribute_values,
+				error);
+	}
+}
+
+static const GMarkupParser cdma_parser = {
+	cdma_start,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+};
+
+static void provider_start(GMarkupParseContext *context,
+				const gchar *element_name,
+				const gchar **attribute_names,
+				const gchar **attribute_values,
+				gpointer userdata, GError **error)
+{
+	struct cdma_data *cdma = userdata;
+
+	if (g_str_equal(element_name, "name")) {
+		if ((cdma->match_found == FALSE) && (cdma->provider_name)) {
+			g_free(cdma->provider_name);
+			cdma->provider_name = NULL;
+		}
+
+		g_markup_parse_context_push(context, &text_parser,
+						&cdma->provider_name);
+	} else if (g_str_equal(element_name, "gsm"))
+		g_markup_parse_context_push(context, &skip_parser, NULL);
+	else if (g_str_equal(element_name, "cdma"))
+		g_markup_parse_context_push(context, &cdma_parser, userdata);
+}
+
+static void 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 provider_parser = {
+	provider_start,
+	provider_end,
+	NULL,
+	NULL,
+	NULL,
+};
+
 static void toplevel_gsm_start(GMarkupParseContext *context,
 					const gchar *element_name,
 					const gchar **atribute_names,
@@ -379,6 +481,40 @@ static const GMarkupParser toplevel_gsm_parser = {
 	NULL,
 };
 
+static void toplevel_cdma_start(GMarkupParseContext *context,
+					const gchar *element_name,
+					const gchar **atribute_names,
+					const gchar **attribute_values,
+					gpointer userdata, GError **error)
+{
+	struct cdma_data *cdma = userdata;
+
+	if (g_str_equal(element_name, "provider")) {
+		if (cdma->match_found == TRUE)
+			g_markup_parse_context_push(context, &skip_parser,
+								NULL);
+		else
+			g_markup_parse_context_push(context, &provider_parser,
+								userdata);
+	}
+}
+
+static void toplevel_cdma_end(GMarkupParseContext *context,
+					const gchar *element_name,
+					gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "provider"))
+		g_markup_parse_context_pop(context);
+}
+
+static const GMarkupParser toplevel_cdma_parser = {
+	toplevel_cdma_start,
+	toplevel_cdma_end,
+	NULL,
+	NULL,
+	NULL,
+};
+
 static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata,
 				GError **error)
 {
@@ -453,3 +589,18 @@ GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 
 	return gsm.apns;
 }
+
+char *mbpi_lookup_cdma_provider_name(const char *sid, GError **error)
+{
+	struct cdma_data cdma;
+
+	memset(&cdma, 0, sizeof(cdma));
+	cdma.match_sid = sid;
+
+	if (mbpi_parse(&toplevel_cdma_parser, &cdma, error) == FALSE) {
+		g_free(cdma.provider_name);
+		cdma.provider_name = NULL;
+	}
+
+	return cdma.provider_name;
+}
diff --git a/plugins/mbpi.h b/plugins/mbpi.h
index 6d34358..64b7ea5 100644
--- a/plugins/mbpi.h
+++ b/plugins/mbpi.h
@@ -25,3 +25,5 @@ void mbpi_ap_free(struct ofono_gprs_provision_data *data);
 
 GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 			gboolean allow_duplicates, GError **error);
+
+char *mbpi_lookup_cdma_provider_name(const char *sid, GError **error);
-- 
1.7.1


  parent reply	other threads:[~2011-11-15 13:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-15 13:04 [PATCH 0/3] Add a parser to retrieve the CDMA network name Philippe Nunes
2011-11-15 13:04 ` [PATCH 1/3] mbpi: mbpi_lookup becomes mbpi_lookup_apn Philippe Nunes
2011-11-14 20:12   ` Denis Kenzior
2011-11-15 13:04 ` Philippe Nunes [this message]
2011-11-14 20:42   ` [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API Denis Kenzior
2011-11-15 13:04 ` [PATCH 3/3] tools: Add utility for looking CDMA network name from database Philippe Nunes
2011-11-14 20:45   ` Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1321362255-11262-3-git-send-email-philippe.nunes@linux.intel.com \
    --to=philippe.nunes@linux.intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox