All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/3] mbpi: mbpi_lookup becomes mbpi_lookup_apn
  2011-11-15 13:04 ` [PATCH 1/3] mbpi: mbpi_lookup becomes mbpi_lookup_apn Philippe Nunes
@ 2011-11-14 20:12   ` Denis Kenzior
  0 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2011-11-14 20:12 UTC (permalink / raw)
  To: ofono

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

Hi Philippe,

On 11/15/2011 07:04 AM, Philippe Nunes wrote:
> ---
>  plugins/mbpi.c      |   71 +++++++++++++++++++++++++--------------------------
>  plugins/mbpi.h      |    2 +-
>  plugins/provision.c |    2 +-
>  tools/lookup-apn.c  |    2 +-
>  4 files changed, 38 insertions(+), 39 deletions(-)
> 

Patch looks good to me and has been applied.  I did however split it up
into three commits, one for mbpi changes, one for provision updates and
one for look-apn updates.

Regards,
-Denis

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

* Re: [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API
  2011-11-15 13:04 ` [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API Philippe Nunes
@ 2011-11-14 20:42   ` Denis Kenzior
  0 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2011-11-14 20:42 UTC (permalink / raw)
  To: ofono

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

Hi Philippe,

On 11/15/2011 07:04 AM, Philippe Nunes wrote:
> ---
>  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;

Why do you check this here, but also make the same exact check in
cdma_start?

> +
> +	for (i = 0; attribute_names[i]; i++) {
> +		if (g_str_equal(attribute_names[i], "value") == TRUE)
> +			sid = attribute_values[i];

Just a small nitpick, but you probably want to break from the loop once
you find the value attribute.  Also, the braces around the outer for
loop are not really necessary in this case and the style preference is
not to include them.

> +	}
> +
> +	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)) {

This is against our style guidelines, please get rid of the parens.

Also, do you ever expect this function to be called when match_found is
not FALSE?  The DTD is funny here, it says that several name tags can be
provided.  Not sure why anyone would do that or how we want to handle
this.  However, all name elements must be before any cdma or gsm tags.

> +			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);

Regards,
-Denis

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

* Re: [PATCH 3/3] tools: Add utility for looking CDMA network name from database
  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
  0 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2011-11-14 20:45 UTC (permalink / raw)
  To: ofono

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

Hi Philippe,

On 11/15/2011 07:04 AM, Philippe Nunes wrote:
> ---
>  Makefile.am                  |    7 ++-
>  tools/lookup-provider-name.c |  104 ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 110 insertions(+), 1 deletions(-)
>  create mode 100644 tools/lookup-provider-name.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index a28f790..337aeb7 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -627,7 +627,8 @@ TESTS = $(unit_tests)
>  
>  if TOOLS
>  noinst_PROGRAMS += tools/huawei-audio tools/auto-enable \
> -			tools/get-location tools/lookup-apn
> +			tools/get-location tools/lookup-apn \
> +			tools/lookup-provider-name
>  
>  tools_huawei_audio_SOURCES = $(gdbus_sources) tools/huawei-audio.c
>  tools_huawei_audio_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
> @@ -640,6 +641,10 @@ tools_get_location_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
>  
>  tools_lookup_apn_SOURCES = plugins/mbpi.c plugins/mbpi.h tools/lookup-apn.c
>  tools_lookup_apn_LDADD = @GLIB_LIBS@
> +
> +tools_lookup_provider_name_SOURCES = plugins/mbpi.c plugins/mbpi.h \
> +				tools/lookup-provider-name.c
> +tools_lookup_provider_name_LDADD = @GLIB_LIBS@
>  endif
>  
>  noinst_PROGRAMS += gatchat/gsmdial gatchat/test-server gatchat/test-qcdm
> diff --git a/tools/lookup-provider-name.c b/tools/lookup-provider-name.c
> new file mode 100644
> index 0000000..dc91ae5
> --- /dev/null
> +++ b/tools/lookup-provider-name.c
> @@ -0,0 +1,104 @@
> +/*
> + *
> + *  oFono - Open Source Telephony
> + *
> + *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2 as
> + *  published by the Free Software Foundation.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, write to the Free Software
> + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <stdlib.h>
> +
> +#include <glib.h>
> +
> +#define OFONO_API_SUBJECT_TO_CHANGE
> +#include <ofono/modem.h>
> +#include <ofono/gprs-provision.h>
> +
> +#include "plugins/mbpi.h"
> +
> +static void lookup_cdma_provider_name(const char *match_sid)
> +{
> +	GError *error = NULL;
> +	char *name;
> +
> +	g_print("Searching for serving network name with SID: %s\n", match_sid);
> +
> +	name = mbpi_lookup_cdma_provider_name(match_sid, &error);
> +
> +	if (name == NULL) {
> +		if (error != NULL) {
> +			g_printerr("Lookup failed: %s\n", error->message);
> +			g_error_free(error);
> +		}
> +		else
> +			g_printerr("Not found\n");

Please re-read the kernel style guidelines with regard to placing of
curly braces in compound statements.  It should be on the same line as
the else statement.

> +
> +		return;
> +	}
> +
> +	g_print("CDMA provider name: %s\n", name);
> +
> +	g_free(name);
> +}
> +
> +static gboolean option_version = FALSE;
> +static gboolean option_duplicates = FALSE;
> +
> +static GOptionEntry options[] = {
> +	{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
> +				"Show version information and exit" },
> +	{ "allow-duplicates", 0, 0, G_OPTION_ARG_NONE, &option_duplicates,
> +				"Allow duplicate access point types" },

Why exactly do we need this option?

> +	{ NULL },
> +};
> +
> +int main(int argc, char **argv)
> +{
> +	GOptionContext *context;
> +	GError *error = NULL;
> +
> +	context = g_option_context_new(NULL);
> +	g_option_context_add_main_entries(context, options, NULL);
> +
> +	if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
> +		if (error != NULL) {
> +			g_printerr("%s\n", error->message);
> +			g_error_free(error);
> +		} else
> +			g_printerr("An unknown error occurred\n");
> +		exit(1);
> +	}
> +
> +	g_option_context_free(context);
> +
> +	if (option_version == TRUE) {
> +		g_print("%s\n", VERSION);
> +		exit(0);
> +	}
> +
> +	if (argc < 1) {
> +		g_printerr("Missing parameters\n");
> +		exit(1);
> +	}
> +
> +	lookup_cdma_provider_name(argv[1]);
> +
> +	return 0;
> +}

Regards,
-Denis

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

* [PATCH 0/3] Add a parser to retrieve the CDMA network name
@ 2011-11-15 13:04 Philippe Nunes
  2011-11-15 13:04 ` [PATCH 1/3] mbpi: mbpi_lookup becomes mbpi_lookup_apn Philippe Nunes
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Philippe Nunes @ 2011-11-15 13:04 UTC (permalink / raw)
  To: ofono

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

A new API is introduced in mbpi plugin to parse the mobile broadband provider
info' database in order to retrieve the serving network name from the System
Identifier (SID).
Next step is precisely to retrieve the SID broadcasted by the CDMA modem 

Philippe Nunes (3):
  mbpi: mbpi_lookup becomes mbpi_lookup_apn
  mbpi: Add mbpi_lookup_cdma_provider_name API
  tools: Add utility for looking CDMA network name from database

 Makefile.am                  |    7 +-
 plugins/mbpi.c               |  214 +++++++++++++++++++++++++++++++++++------
 plugins/mbpi.h               |    4 +-
 plugins/provision.c          |    2 +-
 tools/lookup-apn.c           |    2 +-
 tools/lookup-provider-name.c |  104 ++++++++++++++++++++
 6 files changed, 297 insertions(+), 36 deletions(-)
 create mode 100644 tools/lookup-provider-name.c


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

* [PATCH 1/3] mbpi: mbpi_lookup becomes mbpi_lookup_apn
  2011-11-15 13:04 [PATCH 0/3] Add a parser to retrieve the CDMA network name Philippe Nunes
@ 2011-11-15 13:04 ` Philippe Nunes
  2011-11-14 20:12   ` Denis Kenzior
  2011-11-15 13:04 ` [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API Philippe Nunes
  2011-11-15 13:04 ` [PATCH 3/3] tools: Add utility for looking CDMA network name from database Philippe Nunes
  2 siblings, 1 reply; 7+ messages in thread
From: Philippe Nunes @ 2011-11-15 13:04 UTC (permalink / raw)
  To: ofono

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

---
 plugins/mbpi.c      |   71 +++++++++++++++++++++++++--------------------------
 plugins/mbpi.h      |    2 +-
 plugins/provision.c |    2 +-
 tools/lookup-apn.c  |    2 +-
 4 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/plugins/mbpi.c b/plugins/mbpi.c
index 53d4b27..1e41ecb 100644
--- a/plugins/mbpi.c
+++ b/plugins/mbpi.c
@@ -347,7 +347,7 @@ static const GMarkupParser gsm_parser = {
 	NULL,
 };
 
-static void toplevel_start(GMarkupParseContext *context,
+static void toplevel_gsm_start(GMarkupParseContext *context,
 					const gchar *element_name,
 					const gchar **atribute_names,
 					const gchar **attribute_values,
@@ -362,7 +362,7 @@ static void toplevel_start(GMarkupParseContext *context,
 		g_markup_parse_context_push(context, &skip_parser, NULL);
 }
 
-static void toplevel_end(GMarkupParseContext *context,
+static void toplevel_gsm_end(GMarkupParseContext *context,
 					const gchar *element_name,
 					gpointer userdata, GError **error)
 {
@@ -371,42 +371,22 @@ static void toplevel_end(GMarkupParseContext *context,
 		g_markup_parse_context_pop(context);
 }
 
-static const GMarkupParser toplevel_parser = {
-	toplevel_start,
-	toplevel_end,
+static const GMarkupParser toplevel_gsm_parser = {
+	toplevel_gsm_start,
+	toplevel_gsm_end,
 	NULL,
 	NULL,
 	NULL,
 };
 
-static gboolean mbpi_parse(const char *data, ssize_t size,
-				struct gsm_data *gsm, GError **error)
-{
-	GMarkupParseContext *context;
-	gboolean ret;
-
-	context = g_markup_parse_context_new(&toplevel_parser,
-						G_MARKUP_TREAT_CDATA_AS_TEXT,
-						gsm, NULL);
-
-	ret = g_markup_parse_context_parse(context, data, size, error);
-
-	if (ret == TRUE)
-		g_markup_parse_context_end_parse(context, error);
-
-	g_markup_parse_context_free(context);
-
-	return ret;
-}
-
-GSList *mbpi_lookup(const char *mcc, const char *mnc,
-			gboolean allow_duplicates, GError **error)
+static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata,
+				GError **error)
 {
 	struct stat st;
 	char *db;
 	int fd;
-	struct gsm_data gsm;
-	GSList *l;
+	GMarkupParseContext *context;
+	gboolean ret;
 
 	fd = open(MBPI_DATABASE, O_RDONLY);
 	if (fd < 0) {
@@ -414,7 +394,7 @@ GSList *mbpi_lookup(const char *mcc, const char *mnc,
 				g_file_error_from_errno(errno),
 				"open(%s) failed: %s", MBPI_DATABASE,
 				g_strerror(errno));
-		return NULL;
+		return FALSE;
 	}
 
 	if (fstat(fd, &st) < 0) {
@@ -423,7 +403,7 @@ GSList *mbpi_lookup(const char *mcc, const char *mnc,
 				g_file_error_from_errno(errno),
 				"fstat(%s) failed: %s", MBPI_DATABASE,
 				g_strerror(errno));
-		return NULL;
+		return FALSE;
 	}
 
 	db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
@@ -433,15 +413,37 @@ GSList *mbpi_lookup(const char *mcc, const char *mnc,
 				g_file_error_from_errno(errno),
 				"mmap(%s) failed: %s", MBPI_DATABASE,
 				g_strerror(errno));
-		return NULL;
+		return FALSE;
 	}
 
+	context = g_markup_parse_context_new(parser,
+						G_MARKUP_TREAT_CDATA_AS_TEXT,
+						userdata, NULL);
+
+	ret = g_markup_parse_context_parse(context, db, st.st_size, error);
+
+	if (ret == TRUE)
+		g_markup_parse_context_end_parse(context, error);
+
+	munmap(db, st.st_size);
+	close(fd);
+	g_markup_parse_context_free(context);
+
+	return ret;
+}
+
+GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
+			gboolean allow_duplicates, GError **error)
+{
+	struct gsm_data gsm;
+	GSList *l;
+
 	memset(&gsm, 0, sizeof(gsm));
 	gsm.match_mcc = mcc;
 	gsm.match_mnc = mnc;
 	gsm.allow_duplicates = allow_duplicates;
 
-	if (mbpi_parse(db, st.st_size, &gsm, error) == FALSE) {
+	if (mbpi_parse(&toplevel_gsm_parser, &gsm, error) == FALSE) {
 		for (l = gsm.apns; l; l = l->next)
 			mbpi_ap_free(l->data);
 
@@ -449,8 +451,5 @@ GSList *mbpi_lookup(const char *mcc, const char *mnc,
 		gsm.apns = NULL;
 	}
 
-	munmap(db, st.st_size);
-	close(fd);
-
 	return gsm.apns;
 }
diff --git a/plugins/mbpi.h b/plugins/mbpi.h
index 42e439b..6d34358 100644
--- a/plugins/mbpi.h
+++ b/plugins/mbpi.h
@@ -23,5 +23,5 @@ const char *mbpi_ap_type(enum ofono_gprs_context_type type);
 
 void mbpi_ap_free(struct ofono_gprs_provision_data *data);
 
-GSList *mbpi_lookup(const char *mcc, const char *mnc,
+GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 			gboolean allow_duplicates, GError **error);
diff --git a/plugins/provision.c b/plugins/provision.c
index 06cba6f..99c299e 100644
--- a/plugins/provision.c
+++ b/plugins/provision.c
@@ -50,7 +50,7 @@ static int provision_get_settings(const char *mcc, const char *mnc,
 
 	DBG("Provisioning for MCC %s, MNC %s, SPN '%s'", mcc, mnc, spn);
 
-	apns = mbpi_lookup(mcc, mnc, FALSE, &error);
+	apns = mbpi_lookup_apn(mcc, mnc, FALSE, &error);
 	if (apns == NULL) {
 		if (error != NULL) {
 			ofono_error("%s", error->message);
diff --git a/tools/lookup-apn.c b/tools/lookup-apn.c
index b833b6c..884b32a 100644
--- a/tools/lookup-apn.c
+++ b/tools/lookup-apn.c
@@ -42,7 +42,7 @@ static void lookup_apn(const char *match_mcc, const char *match_mnc,
 
 	g_print("Searching for info for network: %s%s\n", match_mcc, match_mnc);
 
-	apns = mbpi_lookup(match_mcc, match_mnc, allow_duplicates, &error);
+	apns = mbpi_lookup_apn(match_mcc, match_mnc, allow_duplicates, &error);
 
 	if (apns == NULL) {
 		if (error != NULL) {
-- 
1.7.1


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

* [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API
  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-15 13:04 ` Philippe Nunes
  2011-11-14 20:42   ` Denis Kenzior
  2011-11-15 13:04 ` [PATCH 3/3] tools: Add utility for looking CDMA network name from database Philippe Nunes
  2 siblings, 1 reply; 7+ messages in thread
From: Philippe Nunes @ 2011-11-15 13:04 UTC (permalink / raw)
  To: ofono

[-- 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


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

* [PATCH 3/3] tools: Add utility for looking CDMA network name from database
  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-15 13:04 ` [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API Philippe Nunes
@ 2011-11-15 13:04 ` Philippe Nunes
  2011-11-14 20:45   ` Denis Kenzior
  2 siblings, 1 reply; 7+ messages in thread
From: Philippe Nunes @ 2011-11-15 13:04 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am                  |    7 ++-
 tools/lookup-provider-name.c |  104 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 1 deletions(-)
 create mode 100644 tools/lookup-provider-name.c

diff --git a/Makefile.am b/Makefile.am
index a28f790..337aeb7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -627,7 +627,8 @@ TESTS = $(unit_tests)
 
 if TOOLS
 noinst_PROGRAMS += tools/huawei-audio tools/auto-enable \
-			tools/get-location tools/lookup-apn
+			tools/get-location tools/lookup-apn \
+			tools/lookup-provider-name
 
 tools_huawei_audio_SOURCES = $(gdbus_sources) tools/huawei-audio.c
 tools_huawei_audio_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
@@ -640,6 +641,10 @@ tools_get_location_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
 
 tools_lookup_apn_SOURCES = plugins/mbpi.c plugins/mbpi.h tools/lookup-apn.c
 tools_lookup_apn_LDADD = @GLIB_LIBS@
+
+tools_lookup_provider_name_SOURCES = plugins/mbpi.c plugins/mbpi.h \
+				tools/lookup-provider-name.c
+tools_lookup_provider_name_LDADD = @GLIB_LIBS@
 endif
 
 noinst_PROGRAMS += gatchat/gsmdial gatchat/test-server gatchat/test-qcdm
diff --git a/tools/lookup-provider-name.c b/tools/lookup-provider-name.c
new file mode 100644
index 0000000..dc91ae5
--- /dev/null
+++ b/tools/lookup-provider-name.c
@@ -0,0 +1,104 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/modem.h>
+#include <ofono/gprs-provision.h>
+
+#include "plugins/mbpi.h"
+
+static void lookup_cdma_provider_name(const char *match_sid)
+{
+	GError *error = NULL;
+	char *name;
+
+	g_print("Searching for serving network name with SID: %s\n", match_sid);
+
+	name = mbpi_lookup_cdma_provider_name(match_sid, &error);
+
+	if (name == NULL) {
+		if (error != NULL) {
+			g_printerr("Lookup failed: %s\n", error->message);
+			g_error_free(error);
+		}
+		else
+			g_printerr("Not found\n");
+
+		return;
+	}
+
+	g_print("CDMA provider name: %s\n", name);
+
+	g_free(name);
+}
+
+static gboolean option_version = FALSE;
+static gboolean option_duplicates = FALSE;
+
+static GOptionEntry options[] = {
+	{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
+				"Show version information and exit" },
+	{ "allow-duplicates", 0, 0, G_OPTION_ARG_NONE, &option_duplicates,
+				"Allow duplicate access point types" },
+	{ NULL },
+};
+
+int main(int argc, char **argv)
+{
+	GOptionContext *context;
+	GError *error = NULL;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
+		if (error != NULL) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		exit(1);
+	}
+
+	g_option_context_free(context);
+
+	if (option_version == TRUE) {
+		g_print("%s\n", VERSION);
+		exit(0);
+	}
+
+	if (argc < 1) {
+		g_printerr("Missing parameters\n");
+		exit(1);
+	}
+
+	lookup_cdma_provider_name(argv[1]);
+
+	return 0;
+}
-- 
1.7.1


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

end of thread, other threads:[~2011-11-15 13:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API Philippe Nunes
2011-11-14 20:42   ` 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

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.