aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-02-29 16:57:41 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-16 14:53:18 +0100
commit75a2b407bdd976b862d5745705afc41b3c3fa7ac (patch)
tree890d413361f6374402f08df53c14dc6603f0d9ce
parent1628f495fe5f38c579f87920ef492a47ef73335e (diff)
modem-helpers: port facility lock related helpers to use `MMModemFacility' enums
-rw-r--r--src/mm-modem-helpers.c138
-rw-r--r--src/mm-modem-helpers.h15
2 files changed, 63 insertions, 90 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 31978bf2..3b2e9e1a 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -1202,74 +1202,57 @@ mm_3gpp_parse_operator (const gchar *reply,
/*************************************************************************/
-/* TODO: port to the new codebase */
-#if 0
-
/* Map two letter facility codes into flag values. There are
* many more facilities defined (for various flavors of call
* barring); we only map the ones we care about. */
-static MMModemGsmFacility
-mm_gsm_string_to_facility (const char *string)
+typedef struct {
+ MMModem3gppFacility facility;
+ gchar *acronym;
+} FacilityAcronym;
+
+static const FacilityAcronym facility_acronyms[] = {
+ { MM_MODEM_3GPP_FACILITY_SIM, "SC" },
+ { MM_MODEM_3GPP_FACILITY_PH_SIM, "PS" },
+ { MM_MODEM_3GPP_FACILITY_PH_FSIM, "PF" },
+ { MM_MODEM_3GPP_FACILITY_FIXED_DIALING, "FD" },
+ { MM_MODEM_3GPP_FACILITY_NET_PERS, "PN" },
+ { MM_MODEM_3GPP_FACILITY_NET_SUB_PERS, "PU" },
+ { MM_MODEM_3GPP_FACILITY_PROVIDER_PERS, "PP" },
+ { MM_MODEM_3GPP_FACILITY_CORP_PERS, "PC" }
+};
+
+static MMModem3gppFacility
+string_to_facility (const gchar *str)
{
- g_return_val_if_fail (string != NULL, MM_MODEM_GSM_FACILITY_NONE);
-
- if (!strcmp (string, "SC"))
- return MM_MODEM_GSM_FACILITY_SIM;
- else if (!strcmp (string, "PS"))
- return MM_MODEM_GSM_FACILITY_PH_SIM;
- else if (!strcmp (string, "PF"))
- return MM_MODEM_GSM_FACILITY_PH_FSIM;
- else if (!strcmp (string, "FD"))
- return MM_MODEM_GSM_FACILITY_FIXED_DIALING;
- else if (!strcmp (string, "PN"))
- return MM_MODEM_GSM_FACILITY_NET_PERS;
- else if (!strcmp (string, "PU"))
- return MM_MODEM_GSM_FACILITY_NET_SUB_PERS;
- else if (!strcmp (string, "PP"))
- return MM_MODEM_GSM_FACILITY_PROVIDER_PERS;
- else if (!strcmp (string, "PC"))
- return MM_MODEM_GSM_FACILITY_CORP_PERS;
- else
- return MM_MODEM_GSM_FACILITY_NONE;
+ guint i;
-}
+ for (i = 0; i < G_N_ELEMENTS (facility_acronyms); i++) {
+ if (g_str_equal (facility_acronyms[i].acronym, str))
+ return facility_acronyms[i].facility;
+ }
-/*************************************************************************/
+ return MM_MODEM_3GPP_FACILITY_NONE;
+}
-char *
-mm_gsm_get_facility_name (MMModemGsmFacility facility)
+gchar *
+mm_3gpp_get_facility_acronym (MMModem3gppFacility facility)
{
- switch (facility) {
- case MM_MODEM_GSM_FACILITY_SIM:
- return "SC";
- case MM_MODEM_GSM_FACILITY_PH_SIM:
- return "PS";
- case MM_MODEM_GSM_FACILITY_PH_FSIM:
- return "PF";
- case MM_MODEM_GSM_FACILITY_FIXED_DIALING:
- return "FD";
- case MM_MODEM_GSM_FACILITY_NET_PERS:
- return "PN";
- case MM_MODEM_GSM_FACILITY_NET_SUB_PERS:
- return "PU";
- case MM_MODEM_GSM_FACILITY_PROVIDER_PERS:
- return "PP";
- case MM_MODEM_GSM_FACILITY_CORP_PERS:
- return "PC";
- default:
- return NULL;
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (facility_acronyms); i++) {
+ if (facility_acronyms[i].facility == facility)
+ return facility_acronyms[i].acronym;
}
+
+ return NULL;
}
gboolean
-mm_gsm_parse_clck_test_response (const char *reply,
- MMModemGsmFacility *out_facilities)
+mm_3gpp_parse_clck_test_response (const gchar *reply,
+ MMModem3gppFacility *out_facilities)
{
- MMModemGsmFacility facilities = MM_MODEM_GSM_FACILITY_NONE;
GRegex *r;
GMatchInfo *match_info;
- char *p, *str;
- gboolean success = FALSE;
g_return_val_if_fail (reply != NULL, FALSE);
g_return_val_if_fail (out_facilities != NULL, FALSE);
@@ -1278,81 +1261,72 @@ mm_gsm_parse_clck_test_response (const char *reply,
*
* +CLCK: ("SC","AO","AI","PN")
*/
- p = strchr (reply, '(');
- if (p)
- p++;
- else {
- p = strchr (reply, '"');
- if (!p)
- return FALSE;
- }
+ reply = mm_strip_tag (reply, "+CLCK:");
/* Now parse each facility */
r = g_regex_new ("\\s*\"([^,\\)]+)\"\\s*", 0, 0, NULL);
- if (!r)
- return FALSE;
+ g_assert (r != NULL);
- if (g_regex_match_full (r, p, strlen (p), 0, 0, &match_info, NULL)) {
+ *out_facilities = MM_MODEM_3GPP_FACILITY_NONE;
+ if (g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, NULL)) {
while (g_match_info_matches (match_info)) {
+ gchar *str;
+
str = g_match_info_fetch (match_info, 1);
if (str) {
- facilities |= mm_gsm_string_to_facility (str);
+ *out_facilities |= string_to_facility (str);
g_free (str);
}
g_match_info_next (match_info, NULL);
- success = TRUE;
}
}
g_match_info_free (match_info);
g_regex_unref (r);
- if (success)
- *out_facilities = facilities;
-
- return success;
+ return (*out_facilities != MM_MODEM_3GPP_FACILITY_NONE);
}
gboolean
-mm_gsm_parse_clck_response (const char *reply, gboolean *enabled)
+mm_3gpp_parse_clck_response (const gchar *reply,
+ gboolean *enabled)
{
GRegex *r;
GMatchInfo *match_info;
- char *p, *str;
gboolean success = FALSE;
g_return_val_if_fail (reply != NULL, FALSE);
g_return_val_if_fail (enabled != NULL, FALSE);
- p = strchr (reply, ':');
- if (p)
- p++;
+ reply = mm_strip_tag (reply, "+CLCK:");
r = g_regex_new ("\\s*([01])\\s*", 0, 0, NULL);
- if (!r)
- return FALSE;
+ g_assert (r != NULL);
+
+ if (g_regex_match (r, reply, 0, &match_info)) {
+ gchar *str;
- if (g_regex_match (r, p, 0, &match_info)) {
- success = TRUE;
str = g_match_info_fetch (match_info, 1);
if (str) {
+ /* We're trying to match either '0' or '1',
+ * so we don't expect any other thing */
if (*str == '0')
*enabled = FALSE;
else if (*str == '1')
*enabled = TRUE;
else
- success = FALSE;
+ g_assert_not_reached ();
g_free (str);
+ success = TRUE;
}
}
g_match_info_free (match_info);
g_regex_unref (r);
+
return success;
}
-#endif
-
/*************************************************************************/
MMModemAccessTechnology
diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h
index 63bfbd3a..bc8967a2 100644
--- a/src/mm-modem-helpers.h
+++ b/src/mm-modem-helpers.h
@@ -103,14 +103,13 @@ gboolean mm_cdma_parse_crm_range_response (const gchar *reply,
gboolean mm_gsm_parse_cscs_support_response (const char *reply,
MMModemCharset *out_charsets);
-/* TODO: port to the new codebase */
-#if 0
-gboolean mm_gsm_parse_clck_test_response (const char *reply,
- MMModemGsmFacility *out_facilities);
-gboolean mm_gsm_parse_clck_response (const char *reply,
- gboolean *enabled);
-char *mm_gsm_get_facility_name (MMModemGsmFacility facility);
-#endif
+gchar *mm_3gpp_get_facility_acronym (MMModem3gppFacility facility);
+
+gboolean mm_3gpp_parse_clck_test_response (const gchar *reply,
+ MMModem3gppFacility *out_facilities);
+
+gboolean mm_3gpp_parse_clck_response (const gchar *reply,
+ gboolean *enabled);
gchar *mm_3gpp_parse_operator (const gchar *reply,
MMModemCharset cur_charset);