modem-helpers: handle commas within +COPS response items (bgo #701329)

Modems can probably put whatever they want between the quotes for
the operator name, including commas.  Handle that.

https://bugzilla.gnome.org/show_bug.cgi?id=701329
This commit is contained in:
Dan Williams
2013-05-30 23:51:05 -05:00
parent 67d3ed11d3
commit 93fcaf93ce
2 changed files with 15 additions and 1 deletions

View File

@@ -530,7 +530,7 @@ mm_3gpp_parse_cops_test_response (const gchar *reply,
* +COPS: (2,"","T-Mobile","31026",0),(1,"AT&T","AT&T","310410"),0) * +COPS: (2,"","T-Mobile","31026",0),(1,"AT&T","AT&T","310410"),0)
*/ */
r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &inner_error); r = g_regex_new ("\\((\\d),\"([^\"\\)]*)\",([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &inner_error);
if (inner_error) { if (inner_error) {
mm_err ("Invalid regular expression: %s", inner_error->message); mm_err ("Invalid regular expression: %s", inner_error->message);
g_error_free (inner_error); g_error_free (inner_error);

View File

@@ -581,6 +581,19 @@ test_cops_response_sek600i (void *f, gpointer d)
test_cops_results ("Sony-Ericsson K600i", reply, &expected[0], G_N_ELEMENTS (expected)); test_cops_results ("Sony-Ericsson K600i", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void
test_cops_response_samsung_z810 (void *f, gpointer d)
{
/* Ensure commas within quotes don't trip up the parser */
const char *reply = "+COPS: (1,\"T-Mobile USA, In\",\"T-Mobile\",\"310260\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)";
static MM3gppNetworkInfo expected[] = {
{ MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "T-Mobile USA, In", "T-Mobile", "310260", MM_MODEM_ACCESS_TECHNOLOGY_GSM },
{ MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECHNOLOGY_GSM },
};
test_cops_results ("Samsung Z810", reply, &expected[0], G_N_ELEMENTS (expected));
}
static void static void
test_cops_response_gsm_invalid (void *f, gpointer d) test_cops_response_gsm_invalid (void *f, gpointer d)
{ {
@@ -1883,6 +1896,7 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_cops_response_n2720, NULL)); g_test_suite_add (suite, TESTCASE (test_cops_response_n2720, NULL));
g_test_suite_add (suite, TESTCASE (test_cops_response_gobi, NULL)); g_test_suite_add (suite, TESTCASE (test_cops_response_gobi, NULL));
g_test_suite_add (suite, TESTCASE (test_cops_response_sek600i, NULL)); g_test_suite_add (suite, TESTCASE (test_cops_response_sek600i, NULL));
g_test_suite_add (suite, TESTCASE (test_cops_response_samsung_z810, NULL));
g_test_suite_add (suite, TESTCASE (test_cops_response_gsm_invalid, NULL)); g_test_suite_add (suite, TESTCASE (test_cops_response_gsm_invalid, NULL));
g_test_suite_add (suite, TESTCASE (test_cops_response_umts_invalid, NULL)); g_test_suite_add (suite, TESTCASE (test_cops_response_umts_invalid, NULL));