aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-12-10 22:33:59 -0600
committerDan Williams <dcbw@redhat.com>2012-12-13 10:35:14 -0600
commit780fadd71e39518cea20aea3fd9e2b56b6eba506 (patch)
treea0fbe43d7645debcd68b1d16b6f98368f248e641
parentc1a1d20adaa54de958b070ea3dc3894116009431 (diff)
gsm: simplify some code
We never expect g_regex_new() to fail, because if it does, that means the regex isn't valid, and that's a programmer error, not a runtime one.
-rw-r--r--src/mm-generic-gsm.c111
1 files changed, 56 insertions, 55 deletions
diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c
index e15fac5b..754a0cac 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -4220,39 +4220,39 @@ cid_range_read (MMAtSerialPort *port,
r = g_regex_new ("\\+CGDCONT:\\s*\\((\\d+)-(\\d+)\\),\\(?\"(\\S+)\"",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
0, &info->error);
- if (r) {
- g_regex_match_full (r, response->str, response->len, 0, 0, &match_info, &info->error);
- while (cid == 0 && g_match_info_matches (match_info)) {
- char *tmp;
+ g_assert (r);
- tmp = g_match_info_fetch (match_info, 3);
- if (!strcmp (tmp, "IP")) {
- int max_cid;
- int highest_cid = GPOINTER_TO_INT (mm_callback_info_get_data (info, "highest-cid"));
+ g_regex_match_full (r, response->str, response->len, 0, 0, &match_info, &info->error);
+ while (cid == 0 && g_match_info_matches (match_info)) {
+ char *tmp;
- g_free (tmp);
+ tmp = g_match_info_fetch (match_info, 3);
+ if (!strcmp (tmp, "IP")) {
+ int max_cid;
+ int highest_cid = GPOINTER_TO_INT (mm_callback_info_get_data (info, "highest-cid"));
- tmp = g_match_info_fetch (match_info, 2);
- max_cid = atoi (tmp);
+ g_free (tmp);
- if (highest_cid < max_cid)
- cid = highest_cid + 1;
- else
- cid = highest_cid;
- }
+ tmp = g_match_info_fetch (match_info, 2);
+ max_cid = atoi (tmp);
- g_free (tmp);
- g_match_info_next (match_info, NULL);
+ if (highest_cid < max_cid)
+ cid = highest_cid + 1;
+ else
+ cid = highest_cid;
}
- if (cid == 0) {
- /* Choose something */
- cid = 1;
- }
+ g_free (tmp);
+ g_match_info_next (match_info, NULL);
+ }
- g_match_info_free (match_info);
- g_regex_unref (r);
+ if (cid == 0) {
+ /* Choose something */
+ cid = 1;
}
+
+ g_match_info_free (match_info);
+ g_regex_unref (r);
} else
info->error = g_error_new_literal (MM_MODEM_ERROR,
MM_MODEM_ERROR_GENERAL,
@@ -4296,47 +4296,48 @@ existing_apns_read (MMAtSerialPort *port,
} else if (g_str_has_prefix (response->str, "+CGDCONT:")) {
GRegex *r;
GMatchInfo *match_info;
+ const char *new_apn;
r = g_regex_new ("\\+CGDCONT:\\s*(\\d+)\\s*,\"(\\S+)\",\"(\\S+)\",\"(\\S*)\"",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
0, &info->error);
- if (r) {
- const char *new_apn = (const char *) mm_callback_info_get_data (info, "apn");
-
- g_regex_match_full (r, response->str, response->len, 0, 0, &match_info, &info->error);
- while (!found && g_match_info_matches (match_info)) {
- char *cid;
- char *pdp_type;
- char *apn;
- int num_cid;
-
- cid = g_match_info_fetch (match_info, 1);
- num_cid = atoi (cid);
- pdp_type = g_match_info_fetch (match_info, 2);
- apn = g_match_info_fetch (match_info, 3);
-
- if (!strcmp (apn, new_apn)) {
- MM_GENERIC_GSM_GET_PRIVATE (info->modem)->cid = num_cid;
- found = TRUE;
- }
+ g_assert (r);
- if (!found && !strcmp (pdp_type, "IP")) {
- int highest_cid;
+ new_apn = (const char *) mm_callback_info_get_data (info, "apn");
- highest_cid = GPOINTER_TO_INT (mm_callback_info_get_data (info, "highest-cid"));
- if (num_cid > highest_cid)
- mm_callback_info_set_data (info, "highest-cid", GINT_TO_POINTER (num_cid), NULL);
- }
+ g_regex_match_full (r, response->str, response->len, 0, 0, &match_info, &info->error);
+ while (!found && g_match_info_matches (match_info)) {
+ char *cid;
+ char *pdp_type;
+ char *apn;
+ int num_cid;
+
+ cid = g_match_info_fetch (match_info, 1);
+ num_cid = atoi (cid);
+ pdp_type = g_match_info_fetch (match_info, 2);
+ apn = g_match_info_fetch (match_info, 3);
+
+ if (!strcmp (apn, new_apn)) {
+ MM_GENERIC_GSM_GET_PRIVATE (info->modem)->cid = num_cid;
+ found = TRUE;
+ }
- g_free (cid);
- g_free (pdp_type);
- g_free (apn);
- g_match_info_next (match_info, NULL);
+ if (!found && !strcmp (pdp_type, "IP")) {
+ int highest_cid;
+
+ highest_cid = GPOINTER_TO_INT (mm_callback_info_get_data (info, "highest-cid"));
+ if (num_cid > highest_cid)
+ mm_callback_info_set_data (info, "highest-cid", GINT_TO_POINTER (num_cid), NULL);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
+ g_free (cid);
+ g_free (pdp_type);
+ g_free (apn);
+ g_match_info_next (match_info, NULL);
}
+
+ g_match_info_free (match_info);
+ g_regex_unref (r);
} else if (strlen (response->str) == 0) {
/* No APNs configured, just don't set error */
} else