Merge "Merge cros/upstream to cros/master"
diff --git a/libmm-glib/mm-location-gps-nmea.c b/libmm-glib/mm-location-gps-nmea.c
index d23bc14..b2ef695 100644
--- a/libmm-glib/mm-location-gps-nmea.c
+++ b/libmm-glib/mm-location-gps-nmea.c
@@ -54,9 +54,7 @@
check_append_or_replace (MMLocationGpsNmea *self,
const gchar *trace)
{
- /* By default, replace */
- gboolean append_or_replace = FALSE;
- GMatchInfo *match_info = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
if (G_UNLIKELY (!self->priv->sequence_regex))
self->priv->sequence_regex = g_regex_new ("\\$..(?:ALM|GSV|RTE|SFI),(\\d),(\\d).*",
@@ -69,11 +67,11 @@
/* If we don't have the first element of a sequence, append */
if (mm_get_uint_from_match_info (match_info, 2, &index) && index != 1)
- append_or_replace = TRUE;
+ return TRUE;
}
- g_match_info_free (match_info);
- return append_or_replace;
+ /* By default, replace */
+ return FALSE;
}
static gboolean
diff --git a/libmm-glib/mm-location-gps-raw.c b/libmm-glib/mm-location-gps-raw.c
index fddc562..d776d1c 100644
--- a/libmm-glib/mm-location-gps-raw.c
+++ b/libmm-glib/mm-location-gps-raw.c
@@ -190,7 +190,7 @@
mm_location_gps_raw_add_trace (MMLocationGpsRaw *self,
const gchar *trace)
{
- GMatchInfo *match_info = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
/* Current implementation works only with $GPGGA and $GNGGA traces */
do {
@@ -268,8 +268,6 @@
mm_get_double_from_match_info (match_info, 9, &self->priv->altitude);
}
- g_match_info_free (match_info);
-
return TRUE;
}
diff --git a/plugins/anydata/mm-broadband-modem-anydata.c b/plugins/anydata/mm-broadband-modem-anydata.c
index 95f8cbd..36d72e5 100644
--- a/plugins/anydata/mm-broadband-modem-anydata.c
+++ b/plugins/anydata/mm-broadband-modem-anydata.c
@@ -72,10 +72,10 @@
GTask *task)
{
DetailedRegistrationStateResults *results;
- GError *error = NULL;
- const gchar *response;
- GRegex *r;
- GMatchInfo *match_info;
+ GError *error = NULL;
+ const gchar *response;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
results = g_task_get_task_data (task);
@@ -129,9 +129,6 @@
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
g_task_return_pointer (task, g_memdup (results, sizeof (*results)), g_free);
g_object_unref (task);
}
@@ -142,10 +139,10 @@
GTask *task)
{
DetailedRegistrationStateResults *results;
- GError *error = NULL;
- const gchar *response;
- GRegex *r;
- GMatchInfo *match_info;
+ GError *error = NULL;
+ const gchar *response;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error) {
@@ -194,9 +191,6 @@
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
/* Try for EVDO state too */
mm_base_modem_at_command (MM_BASE_MODEM (self),
"*HSTATE?",
@@ -261,9 +255,14 @@
static void
setup_ports (MMBroadbandModem *self)
{
- MMPortSerialAt *ports[2];
- GRegex *regex;
- guint i;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) active_regex = NULL;
+ g_autoptr(GRegex) inactive_regex = NULL;
+ g_autoptr(GRegex) dormant_regex = NULL;
+ g_autoptr(GRegex) offline_regex = NULL;
+ g_autoptr(GRegex) regreq_regex = NULL;
+ g_autoptr(GRegex) authreq_regex = NULL;
+ guint i;
/* Call parent's setup ports first always */
MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_anydata_parent_class)->setup_ports (self);
@@ -271,48 +270,37 @@
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
+ /* Data call has connected */
+ active_regex = g_regex_new ("\\r\\n\\*ACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Data call disconnected */
+ inactive_regex = g_regex_new ("\\r\\n\\*INACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Modem is now dormant */
+ dormant_regex = g_regex_new ("\\r\\n\\*DORMANT:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Network acquisition fail */
+ offline_regex = g_regex_new ("\\r\\n\\*OFFLINE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Registration fail */
+ regreq_regex = g_regex_new ("\\r\\n\\*REGREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Authentication fail */
+ authreq_regex = g_regex_new ("\\r\\n\\*AUTHREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+
/* Now reset the unsolicited messages */
for (i = 0; i < G_N_ELEMENTS (ports); i++) {
if (!ports[i])
continue;
/* Data state notifications */
-
- /* Data call has connected */
- regex = g_regex_new ("\\r\\n\\*ACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
-
- /* Data call disconnected */
- regex = g_regex_new ("\\r\\n\\*INACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
-
- /* Modem is now dormant */
- regex = g_regex_new ("\\r\\n\\*DORMANT:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), active_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), inactive_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), dormant_regex, NULL, NULL, NULL);
/* Abnormal state notifications
*
* FIXME: set 1X/EVDO registration state to UNKNOWN when these
* notifications are received?
*/
-
- /* Network acquisition fail */
- regex = g_regex_new ("\\r\\n\\*OFFLINE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
-
- /* Registration fail */
- regex = g_regex_new ("\\r\\n\\*REGREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
-
- /* Authentication fail */
- regex = g_regex_new ("\\r\\n\\*AUTHREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), offline_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regreq_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), authreq_regex, NULL, NULL, NULL);
}
}
diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c
index a75eb53..9219bff 100644
--- a/plugins/cinterion/mm-modem-helpers-cinterion.c
+++ b/plugins/cinterion/mm-modem-helpers-cinterion.c
@@ -554,14 +554,14 @@
GArray **supported_bfr,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- GArray *tmp_supported_mode = NULL;
- GArray *tmp_supported_mt = NULL;
- GArray *tmp_supported_bm = NULL;
- GArray *tmp_supported_ds = NULL;
- GArray *tmp_supported_bfr = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autoptr(GArray) tmp_supported_mode = NULL;
+ g_autoptr(GArray) tmp_supported_mt = NULL;
+ g_autoptr(GArray) tmp_supported_bm = NULL;
+ g_autoptr(GArray) tmp_supported_ds = NULL;
+ g_autoptr(GArray) tmp_supported_bfr = NULL;
+ GError *inner_error = NULL;
if (!response) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing response");
@@ -576,77 +576,63 @@
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
if (!inner_error && g_match_info_matches (match_info)) {
if (supported_mode) {
- gchar *str;
+ g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 1);
tmp_supported_mode = mm_parse_uint_list (str, &inner_error);
- g_free (str);
if (inner_error)
goto out;
}
if (supported_mt) {
- gchar *str;
+ g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 2);
tmp_supported_mt = mm_parse_uint_list (str, &inner_error);
- g_free (str);
if (inner_error)
goto out;
}
if (supported_bm) {
- gchar *str;
+ g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 3);
tmp_supported_bm = mm_parse_uint_list (str, &inner_error);
- g_free (str);
if (inner_error)
goto out;
}
if (supported_ds) {
- gchar *str;
+ g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 4);
tmp_supported_ds = mm_parse_uint_list (str, &inner_error);
- g_free (str);
if (inner_error)
goto out;
}
if (supported_bfr) {
- gchar *str;
+ g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 5);
tmp_supported_bfr = mm_parse_uint_list (str, &inner_error);
- g_free (str);
if (inner_error)
goto out;
}
}
out:
-
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
- g_clear_pointer (&tmp_supported_mode, g_array_unref);
- g_clear_pointer (&tmp_supported_mt, g_array_unref);
- g_clear_pointer (&tmp_supported_bm, g_array_unref);
- g_clear_pointer (&tmp_supported_ds, g_array_unref);
- g_clear_pointer (&tmp_supported_bfr, g_array_unref);
g_propagate_error (error, inner_error);
return FALSE;
}
if (supported_mode)
- *supported_mode = tmp_supported_mode;
+ *supported_mode = g_steal_pointer (&tmp_supported_mode);
if (supported_mt)
- *supported_mt = tmp_supported_mt;
+ *supported_mt = g_steal_pointer (&tmp_supported_mt);
if (supported_bm)
- *supported_bm = tmp_supported_bm;
+ *supported_bm = g_steal_pointer (&tmp_supported_bm);
if (supported_ds)
- *supported_ds = tmp_supported_ds;
+ *supported_ds = g_steal_pointer (&tmp_supported_ds);
if (supported_bfr)
- *supported_bfr = tmp_supported_bfr;
+ *supported_bfr = g_steal_pointer (&tmp_supported_bfr);
return TRUE;
}
@@ -763,9 +749,9 @@
guint *value,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- guint errors = 0;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ guint errors = 0;
if (!response) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing response");
@@ -788,9 +774,6 @@
} else
errors++;
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (errors > 0) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Failed parsing ^SIND response");
return FALSE;
@@ -836,8 +819,8 @@
gpointer log_object,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL;
MMBearerConnectionStatus status;
@@ -883,9 +866,6 @@
g_match_info_next (match_info, &inner_error);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (status == MM_BEARER_CONNECTION_STATUS_UNKNOWN)
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"No state returned for CID %u", cid);
@@ -1078,10 +1058,10 @@
GList **out_list,
GError **error)
{
- GRegex *r;
- GList *list = NULL;
- GError *inner_error = NULL;
- GMatchInfo *match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GList *list = NULL;
+ GError *inner_error = NULL;
static const MMCallDirection cinterion_call_direction[] = {
[0] = MM_CALL_DIRECTION_OUTGOING,
@@ -1158,9 +1138,6 @@
}
out:
- g_clear_pointer (&match_info, g_match_info_free);
- g_regex_unref (r);
-
if (inner_error) {
mm_cinterion_call_info_list_free (list);
g_propagate_error (error, inner_error);
diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c
index c3e7e9e..8332700 100644
--- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c
+++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c
@@ -1192,18 +1192,17 @@
/* Test ^SLCC URCs */
static void
-common_test_slcc_urc (const gchar *urc,
+common_test_slcc_urc (const gchar *urc,
const MMCallInfo *expected_call_info_list,
- guint expected_call_info_list_size)
+ guint expected_call_info_list_size)
{
- GError *error = NULL;
- GRegex *slcc_regex = NULL;
- gboolean result;
- GMatchInfo *match_info = NULL;
- gchar *str;
- GList *call_info_list = NULL;
- GList *l;
-
+ g_autoptr(GRegex) slcc_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *str = NULL;
+ GError *error = NULL;
+ GList *call_info_list = NULL;
+ GList *l;
+ gboolean result;
slcc_regex = mm_cinterion_get_slcc_regex ();
@@ -1230,8 +1229,8 @@
for (l = call_info_list; l; l = g_list_next (l)) {
const MMCallInfo *call_info = (const MMCallInfo *)(l->data);
- gboolean found = FALSE;
- guint i;
+ gboolean found = FALSE;
+ guint i;
g_debug ("call at index %u: direction %s, state %s, number %s",
call_info->index,
@@ -1248,10 +1247,6 @@
g_assert (found);
}
- g_match_info_free (match_info);
- g_regex_unref (slcc_regex);
- g_free (str);
-
mm_cinterion_call_info_list_free (call_info_list);
}
@@ -1322,12 +1317,12 @@
gint expected_offset,
gint expected_dst_offset)
{
- GError *error = NULL;
- GRegex *ctzu_regex = NULL;
- gboolean result;
- GMatchInfo *match_info = NULL;
- gchar *iso8601;
- MMNetworkTimezone *tz = NULL;
+ g_autoptr(GRegex) ctzu_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *iso8601 = NULL;
+ GError *error = NULL;
+ gboolean result;
+ MMNetworkTimezone *tz = NULL;
ctzu_regex = mm_cinterion_get_ctzu_regex ();
@@ -1342,7 +1337,6 @@
g_assert (iso8601);
g_assert_cmpstr (expected_iso8601, ==, iso8601);
- g_free (iso8601);
g_assert (tz);
g_assert_cmpint (expected_offset, ==, mm_network_timezone_get_offset (tz));
@@ -1351,8 +1345,6 @@
g_assert_cmpuint ((guint)expected_dst_offset, ==, mm_network_timezone_get_dst_offset (tz));
g_object_unref (tz);
- g_match_info_free (match_info);
- g_regex_unref (ctzu_regex);
}
static void
diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c
index 866707d..c7c68b9 100644
--- a/plugins/huawei/mm-broadband-modem-huawei.c
+++ b/plugins/huawei/mm-broadband-modem-huawei.c
@@ -627,12 +627,13 @@
GAsyncResult *res,
GError **error)
{
- MMUnlockRetries *unlock_retries;
- const gchar *result;
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- guint i;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ MMUnlockRetries *unlock_retries;
+ const gchar *result;
+ GError *match_error = NULL;
+ guint i;
+
MMModemLock locks[4] = {
MM_MODEM_LOCK_SIM_PUK,
MM_MODEM_LOCK_SIM_PIN,
@@ -657,9 +658,6 @@
MM_CORE_ERROR_FAILED,
"Could not parse ^CPIN results: Response didn't match (%s)",
result);
-
- g_match_info_free (match_info);
- g_regex_unref (r);
return NULL;
}
@@ -683,9 +681,6 @@
mm_unlock_retries_set (unlock_retries, locks[i], num);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
return unlock_retries;
}
diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c
index 3ded623..67bb708 100644
--- a/plugins/huawei/mm-modem-helpers-huawei.c
+++ b/plugins/huawei/mm-modem-helpers-huawei.c
@@ -39,8 +39,6 @@
gboolean *ipv6_connected,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
GError *inner_error = NULL;
if (!response ||
@@ -71,6 +69,9 @@
/* If multiple fields available, try first parsing method */
if (strchr (response, ',')) {
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+
r = g_regex_new ("\\^NDISSTAT(?:QRY)?(?:Qry)?:\\s*(\\d),([^,]*),([^,]*),([^,\\r\\n]*)(?:\\r\\n)?"
"(?:\\^NDISSTAT:|\\^NDISSTATQRY:)?\\s*,?(\\d)?,?([^,]*)?,?([^,]*)?,?([^,\\r\\n]*)?(?:\\r\\n)?",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
@@ -108,12 +109,12 @@
ip_type_field += 4;
}
}
-
- g_match_info_free (match_info);
- g_regex_unref (r);
}
/* No separate IPv4/IPv6 info given just connected/not connected */
else {
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+
r = g_regex_new ("\\^NDISSTAT(?:QRY)?(?:Qry)?:\\s*(\\d)(?:\\r\\n)?",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
0, NULL);
@@ -134,9 +135,6 @@
*ipv4_connected = (gboolean)connected;
}
}
-
- g_match_info_free (match_info);
- g_regex_unref (r);
}
if (!ipv4_available && !ipv6_available) {
@@ -208,10 +206,10 @@
guint *out_dns2,
GError **error)
{
- gboolean matched;
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gboolean matched;
+ GError *match_error = NULL;
g_assert (reply != NULL);
g_assert (out_address != NULL);
@@ -257,8 +255,6 @@
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
return matched;
}
@@ -276,10 +272,10 @@
guint *out_sys_submode,
GError **error)
{
- gboolean matched;
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gboolean matched;
+ GError *match_error = NULL;
g_assert (out_srv_status != NULL);
g_assert (out_srv_domain != NULL);
@@ -323,8 +319,6 @@
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
return matched;
}
@@ -341,10 +335,10 @@
guint *out_sys_submode,
GError **error)
{
- gboolean matched;
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gboolean matched;
+ GError *match_error = NULL;
g_assert (out_srv_status != NULL);
g_assert (out_srv_domain != NULL);
@@ -387,8 +381,6 @@
mm_get_uint_from_match_info (match_info, 8, out_sys_submode);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
return matched;
}
@@ -1189,17 +1181,23 @@
/*****************************************************************************/
/* ^NWTIME response parser */
-gboolean mm_huawei_parse_nwtime_response (const gchar *response,
- gchar **iso8601p,
- MMNetworkTimezone **tzp,
- GError **error)
+gboolean
+mm_huawei_parse_nwtime_response (const gchar *response,
+ gchar **iso8601p,
+ MMNetworkTimezone **tzp,
+ GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- guint year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, dt = 0;
- gint tz = 0;
- gboolean ret = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *match_error = NULL;
+ guint year = 0;
+ guint month = 0;
+ guint day = 0;
+ guint hour = 0;
+ guint minute = 0;
+ guint second = 0;
+ guint dt = 0;
+ gint tz = 0;
g_assert (iso8601p || tzp); /* at least one */
@@ -1211,75 +1209,72 @@
g_propagate_error (error, match_error);
g_prefix_error (error, "Could not parse ^NWTIME results: ");
} else {
- g_set_error_literal (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
+ g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Couldn't match ^NWTIME reply");
}
- } else {
- /* Remember that g_match_info_get_match_count() includes match #0 */
- g_assert (g_match_info_get_match_count (match_info) >= 9);
-
- if (mm_get_uint_from_match_info (match_info, 1, &year) &&
- mm_get_uint_from_match_info (match_info, 2, &month) &&
- mm_get_uint_from_match_info (match_info, 3, &day) &&
- mm_get_uint_from_match_info (match_info, 4, &hour) &&
- mm_get_uint_from_match_info (match_info, 5, &minute) &&
- mm_get_uint_from_match_info (match_info, 6, &second) &&
- mm_get_int_from_match_info (match_info, 7, &tz) &&
- mm_get_uint_from_match_info (match_info, 8, &dt)) {
-
- ret = TRUE;
-
- /* adjust year */
- if (year < 100)
- year += 2000;
- /*
- * tz = timezone offset in 15 minute intervals
- * dt = daylight adjustment, 0 = none, 1 = 1 hour, 2 = 2 hours
- * other values are marked reserved.
- */
- if (iso8601p) {
- /* Return ISO-8601 format date/time string */
- *iso8601p = mm_new_iso8601_time (year, month, day, hour,
- minute, second,
- TRUE, (tz * 15) + (dt * 60),
- error);
- ret = (*iso8601p != NULL);
- }
- if (tzp) {
- *tzp = mm_network_timezone_new ();
- mm_network_timezone_set_offset (*tzp, tz * 15);
- mm_network_timezone_set_dst_offset (*tzp, dt * 60);
- }
-
- } else {
- g_set_error_literal (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Failed to parse ^NWTIME reply");
- }
+ return FALSE;
}
- g_match_info_free (match_info);
- g_regex_unref (r);
+ /* Remember that g_match_info_get_match_count() includes match #0 */
+ g_assert (g_match_info_get_match_count (match_info) >= 9);
- return ret;
+ if (mm_get_uint_from_match_info (match_info, 1, &year) &&
+ mm_get_uint_from_match_info (match_info, 2, &month) &&
+ mm_get_uint_from_match_info (match_info, 3, &day) &&
+ mm_get_uint_from_match_info (match_info, 4, &hour) &&
+ mm_get_uint_from_match_info (match_info, 5, &minute) &&
+ mm_get_uint_from_match_info (match_info, 6, &second) &&
+ mm_get_int_from_match_info (match_info, 7, &tz) &&
+ mm_get_uint_from_match_info (match_info, 8, &dt)) {
+
+ /* adjust year */
+ if (year < 100)
+ year += 2000;
+ /*
+ * tz = timezone offset in 15 minute intervals
+ * dt = daylight adjustment, 0 = none, 1 = 1 hour, 2 = 2 hours
+ * other values are marked reserved.
+ */
+ if (tzp) {
+ *tzp = mm_network_timezone_new ();
+ mm_network_timezone_set_offset (*tzp, tz * 15);
+ mm_network_timezone_set_dst_offset (*tzp, dt * 60);
+ }
+ if (iso8601p) {
+ /* Return ISO-8601 format date/time string */
+ *iso8601p = mm_new_iso8601_time (year, month, day, hour,
+ minute, second,
+ TRUE, (tz * 15) + (dt * 60),
+ error);
+ return (*iso8601p != NULL);
+ }
+
+ return TRUE;
+ }
+
+ g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Failed to parse ^NWTIME reply");
+ return FALSE;
}
/*****************************************************************************/
/* ^TIME response parser */
-gboolean mm_huawei_parse_time_response (const gchar *response,
- gchar **iso8601p,
- MMNetworkTimezone **tzp,
- GError **error)
+gboolean
+mm_huawei_parse_time_response (const gchar *response,
+ gchar **iso8601p,
+ MMNetworkTimezone **tzp,
+ GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- guint year, month, day, hour, minute, second;
- gboolean ret = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *match_error = NULL;
+ guint year = 0;
+ guint month = 0;
+ guint day = 0;
+ guint hour = 0;
+ guint minute = 0;
+ guint second = 0;
g_assert (iso8601p || tzp); /* at least one */
@@ -1306,41 +1301,35 @@
MM_CORE_ERROR_FAILED,
"Couldn't match ^TIME reply");
}
- } else {
- /* Remember that g_match_info_get_match_count() includes match #0 */
- g_assert (g_match_info_get_match_count (match_info) >= 7);
-
- if (mm_get_uint_from_match_info (match_info, 1, &year) &&
- mm_get_uint_from_match_info (match_info, 2, &month) &&
- mm_get_uint_from_match_info (match_info, 3, &day) &&
- mm_get_uint_from_match_info (match_info, 4, &hour) &&
- mm_get_uint_from_match_info (match_info, 5, &minute) &&
- mm_get_uint_from_match_info (match_info, 6, &second)) {
- ret = TRUE;
-
- /* adjust year */
- if (year < 100)
- year += 2000;
-
- /* Return ISO-8601 format date/time string */
- if (iso8601p) {
- *iso8601p = mm_new_iso8601_time (year, month, day, hour,
- minute, second, FALSE, 0,
- error);
- ret = (*iso8601p != NULL);
- }
- } else {
- g_set_error_literal (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Failed to parse ^TIME reply");
- }
+ return FALSE;
}
- g_match_info_free (match_info);
- g_regex_unref (r);
+ /* Remember that g_match_info_get_match_count() includes match #0 */
+ g_assert (g_match_info_get_match_count (match_info) >= 7);
- return ret;
+ if (mm_get_uint_from_match_info (match_info, 1, &year) &&
+ mm_get_uint_from_match_info (match_info, 2, &month) &&
+ mm_get_uint_from_match_info (match_info, 3, &day) &&
+ mm_get_uint_from_match_info (match_info, 4, &hour) &&
+ mm_get_uint_from_match_info (match_info, 5, &minute) &&
+ mm_get_uint_from_match_info (match_info, 6, &second)) {
+ /* adjust year */
+ if (year < 100)
+ year += 2000;
+
+ /* Return ISO-8601 format date/time string */
+ if (iso8601p) {
+ *iso8601p = mm_new_iso8601_time (year, month, day, hour,
+ minute, second, FALSE, 0,
+ error);
+ return (*iso8601p != NULL);
+ }
+ return TRUE;
+ }
+
+ g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Failed to parse ^TIME reply");
+ return FALSE;
}
/*****************************************************************************/
@@ -1356,11 +1345,9 @@
guint *out_value5,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- gboolean ret = FALSE;
- char *s;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *match_error = NULL;
r = g_regex_new ("\\^HCSQ:\\s*\"?([a-zA-Z]*)\"?,(\\d+),?(\\d+)?,?(\\d+)?,?(\\d+)?,?(\\d+)?$", 0, 0, NULL);
g_assert (r != NULL);
@@ -1370,27 +1357,24 @@
g_propagate_error (error, match_error);
g_prefix_error (error, "Could not parse ^HCSQ results: ");
} else {
- g_set_error_literal (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
+ g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Couldn't match ^HCSQ reply");
}
- goto done;
+ return FALSE;
}
/* Remember that g_match_info_get_match_count() includes match #0 */
if (g_match_info_get_match_count (match_info) < 3) {
- g_set_error_literal (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
+ g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Not enough elements in ^HCSQ reply");
- goto done;
+ return FALSE;
}
if (out_act) {
+ g_autofree gchar *s = NULL;
+
s = g_match_info_fetch (match_info, 1);
*out_act = mm_string_to_access_tech (s);
- g_free (s);
}
if (out_value1)
@@ -1404,13 +1388,7 @@
if (out_value5)
mm_get_uint_from_match_info (match_info, 6, out_value5);
- ret = TRUE;
-
-done:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
- return ret;
+ return TRUE;
}
/*****************************************************************************/
@@ -1422,11 +1400,12 @@
guint *out_bits,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- guint supported = 0, hz = 0, bits = 0;
- gboolean ret = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *match_error = NULL;
+ guint supported = 0;
+ guint hz = 0;
+ guint bits = 0;
/* ^CVOICE: <0=supported,1=unsupported>,<hz>,<bits>,<unknown> */
r = g_regex_new ("\\^CVOICE:\\s*(\\d)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)$", 0, 0, NULL);
@@ -1442,37 +1421,31 @@
MM_CORE_ERROR_FAILED,
"Couldn't match ^CVOICE reply");
}
- } else {
- /* Remember that g_match_info_get_match_count() includes match #0 */
- g_assert (g_match_info_get_match_count (match_info) >= 5);
-
- if (mm_get_uint_from_match_info (match_info, 1, &supported) &&
- mm_get_uint_from_match_info (match_info, 2, &hz) &&
- mm_get_uint_from_match_info (match_info, 3, &bits)) {
- if (supported == 0) {
- if (out_hz)
- *out_hz = hz;
- if (out_bits)
- *out_bits = bits;
- ret = TRUE;
- } else {
- g_set_error_literal (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_UNSUPPORTED,
- "^CVOICE not supported by this device");
- }
- } else {
- g_set_error_literal (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Failed to parse ^CVOICE reply");
- }
+ return FALSE;
}
- g_match_info_free (match_info);
- g_regex_unref (r);
+ /* Remember that g_match_info_get_match_count() includes match #0 */
+ g_assert (g_match_info_get_match_count (match_info) >= 5);
- return ret;
+ if (mm_get_uint_from_match_info (match_info, 1, &supported) &&
+ mm_get_uint_from_match_info (match_info, 2, &hz) &&
+ mm_get_uint_from_match_info (match_info, 3, &bits)) {
+ if (supported == 0) {
+ if (out_hz)
+ *out_hz = hz;
+ if (out_bits)
+ *out_bits = bits;
+ return TRUE;
+ }
+
+ g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
+ "^CVOICE not supported by this device");
+ return FALSE;
+ }
+
+ g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Failed to parse ^CVOICE reply");
+ return FALSE;
}
/*****************************************************************************/
diff --git a/plugins/icera/mm-broadband-modem-icera.c b/plugins/icera/mm-broadband-modem-icera.c
index 897d256..759985e 100644
--- a/plugins/icera/mm-broadband-modem-icera.c
+++ b/plugins/icera/mm-broadband-modem-icera.c
@@ -123,12 +123,12 @@
GAsyncResult *res,
GError **error)
{
- GArray *combinations = NULL;
- const gchar *response;
- gchar **split = NULL;
- GMatchInfo *match_info;
- GRegex *r;
- guint i;
+ GArray *combinations = NULL;
+ const gchar *response;
+ gchar **split = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ guint i;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
if (!response)
@@ -145,18 +145,13 @@
g_regex_match (r, response, 0, &match_info);
if (g_match_info_matches (match_info)) {
- gchar *aux;
+ g_autofree gchar *aux = NULL;
aux = mm_get_string_unquoted_from_match_info (match_info, 1);
- if (aux) {
+ if (aux)
split = g_strsplit (aux, ",", -1);
- g_free (aux);
- }
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (!split) {
g_set_error (error,
MM_CORE_ERROR,
@@ -1122,11 +1117,12 @@
}
static GSList *
-parse_bands (const gchar *response, guint32 *out_len)
+parse_bands (const gchar *response,
+ guint32 *out_len)
{
- GRegex *r;
- GMatchInfo *info;
- GSList *bands = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) info = NULL;
+ GSList *bands = NULL;
g_return_val_if_fail (out_len != NULL, NULL);
@@ -1163,8 +1159,6 @@
g_free (enabled);
g_match_info_next (info, NULL);
}
- g_match_info_free (info);
- g_regex_unref (r);
return bands;
}
diff --git a/plugins/mbm/mm-modem-helpers-mbm.c b/plugins/mbm/mm-modem-helpers-mbm.c
index 31fbb37..846cc4d 100644
--- a/plugins/mbm/mm-modem-helpers-mbm.c
+++ b/plugins/mbm/mm-modem-helpers-mbm.c
@@ -55,15 +55,17 @@
MMBearerIpConfig **out_ip6_config,
GError **error)
{
- MMBearerIpConfig **ip_config = NULL;
- gboolean got_address = FALSE, got_gw = FALSE, got_dns = FALSE;
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- gchar *dns[3] = { 0 };
- guint dns_idx = 0;
- int family = AF_INET;
- MMBearerIpMethod method = MM_BEARER_IP_METHOD_STATIC;
+ MMBearerIpConfig **ip_config = NULL;
+ gboolean got_address = FALSE;
+ gboolean got_gw = FALSE;
+ gboolean got_dns = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *match_error = NULL;
+ gchar *dns[3] = { 0 };
+ guint dns_idx = 0;
+ int family = AF_INET;
+ MMBearerIpMethod method = MM_BEARER_IP_METHOD_STATIC;
g_return_val_if_fail (out_ip4_config, FALSE);
g_return_val_if_fail (out_ip6_config, FALSE);
@@ -108,14 +110,17 @@
MM_CORE_ERROR_FAILED,
"Couldn't match " E2IPCFG_TAG " reply");
}
- goto done;
+ return FALSE;
}
*ip_config = mm_bearer_ip_config_new ();
mm_bearer_ip_config_set_method (*ip_config, method);
while (g_match_info_matches (match_info)) {
- char *id = g_match_info_fetch (match_info, 1);
- char *str = g_match_info_fetch (match_info, 2);
+ g_autofree gchar *id = NULL;
+ g_autofree gchar *str = NULL;
+
+ id = g_match_info_fetch (match_info, 1);
+ str = g_match_info_fetch (match_info, 2);
switch (atoi (id)) {
case 1:
@@ -140,8 +145,6 @@
default:
break;
}
- g_free (id);
- g_free (str);
g_match_info_next (match_info, NULL);
}
@@ -156,12 +159,10 @@
*ip_config = NULL;
g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Got incomplete IP configuration from " E2IPCFG_TAG);
+ return FALSE;
}
-done:
- g_match_info_free (match_info);
- g_regex_unref (r);
- return !!*ip_config;
+ return TRUE;
}
/*****************************************************************************/
diff --git a/plugins/mtk/mm-broadband-modem-mtk.c b/plugins/mtk/mm-broadband-modem-mtk.c
index 0ceca79..869784f 100644
--- a/plugins/mtk/mm-broadband-modem-mtk.c
+++ b/plugins/mtk/mm-broadband-modem-mtk.c
@@ -67,13 +67,16 @@
GAsyncResult *res,
GTask *task)
{
- const gchar *response;
- GError *error = NULL;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- GRegex *r = NULL;
- gint pin1, puk1, pin2, puk2;
- MMUnlockRetries *retries;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ const gchar *response;
+ GError *error = NULL;
+ GError *match_error = NULL;
+ gint pin1;
+ gint puk1;
+ gint pin2;
+ gint puk2;
+ MMUnlockRetries *retries;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) {
@@ -91,14 +94,11 @@
g_assert (r != NULL);
if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)){
- if (match_error) {
- g_propagate_error (&error, match_error);
- } else {
- g_set_error (&error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Failed to match EPINC response: %s", response);
- }
+ if (match_error)
+ g_task_return_error (task, match_error);
+ else
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Failed to match EPINC response: %s", response);
g_task_return_error (task, error);
} else if (!mm_get_int_from_match_info (match_info, 1, &pin1) ||
!mm_get_int_from_match_info (match_info, 2, &pin2) ||
@@ -120,9 +120,6 @@
g_task_return_pointer (task, retries, g_object_unref);
}
g_object_unref (task);
-
- g_match_info_free (match_info);
- g_regex_unref (r);
}
static void
@@ -178,14 +175,14 @@
GTask *task)
{
- const gchar *response;
- GError *error = NULL;
- GMatchInfo *match_info = NULL;
- MMModemModeCombination mode;
- GArray *combinations;
- GRegex *r;
- GError *match_error = NULL;
- gint device_type;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ const gchar *response;
+ GError *error = NULL;
+ MMModemModeCombination mode;
+ GArray *combinations;
+ GError *match_error = NULL;
+ gint device_type;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) {
@@ -205,9 +202,6 @@
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Failed to match EGMR response: %s", response);
g_object_unref (task);
-
- g_match_info_free (match_info);
- g_regex_unref (r);
return;
}
@@ -216,9 +210,6 @@
"Failed to parse the allowed mode response: '%s'",
response);
g_object_unref (task);
-
- g_regex_unref (r);
- g_match_info_free (match_info);
return;
}
@@ -271,9 +262,6 @@
*/
g_task_return_pointer (task, combinations, (GDestroyNotify)g_array_unref);
g_object_unref (task);
-
- g_regex_unref (r);
- g_match_info_free (match_info);
}
static void
@@ -307,17 +295,16 @@
MMModemMode *preferred,
GError **error)
{
- const gchar *response;
- GMatchInfo *match_info = NULL;
- GRegex *r;
- gint erat_mode = -1;
- gint erat_pref = -1;
- GError *match_error = NULL;
- gboolean result = FALSE;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ const gchar *response;
+ gint erat_mode = -1;
+ gint erat_pref = -1;
+ GError *match_error = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
if (!response)
- return result;
+ return FALSE;
r = g_regex_new (
"\\+ERAT:\\s*[0-9]+,\\s*[0-9]+,\\s*([0-9]+),\\s*([0-9]+)",
@@ -329,30 +316,22 @@
if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)) {
if (match_error)
g_propagate_error (error, match_error);
- else {
- g_set_error (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
+ else
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Couldn't parse +ERAT response: '%s'",
response);
-
- }
- goto done;
+ return FALSE;
}
if (!mm_get_int_from_match_info (match_info, 1, &erat_mode) ||
!mm_get_int_from_match_info (match_info, 2, &erat_pref)) {
- g_set_error (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Failed to parse the ERAT response: m=%d p=%d",
erat_mode, erat_pref);
- goto done;
+ return FALSE;
}
/* Correctly parsed! */
- result = TRUE;
-
switch (erat_mode) {
case 0:
*allowed = MM_MODEM_MODE_2G;
@@ -376,9 +355,8 @@
*allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G;
break;
default:
- result = FALSE;
mm_obj_dbg (self, "unsupported allowed mode reported in +ERAT: %d", erat_mode);
- goto done;
+ return FALSE;
}
switch (erat_pref) {
@@ -395,17 +373,11 @@
*preferred = MM_MODEM_MODE_4G;
break;
default:
- result = FALSE;
mm_obj_dbg (self, "unsupported preferred mode %d", erat_pref);
- goto done;
+ return FALSE;
}
-done:
- if (r)
- g_regex_unref (r);
- g_match_info_free (match_info);
-
- return result;
+ return TRUE;
}
static void
diff --git a/plugins/novatel/mm-broadband-modem-novatel.c b/plugins/novatel/mm-broadband-modem-novatel.c
index 1cc88e9..46bf438 100644
--- a/plugins/novatel/mm-broadband-modem-novatel.c
+++ b/plugins/novatel/mm-broadband-modem-novatel.c
@@ -159,12 +159,12 @@
GTask *task)
{
LoadCurrentModesResult *result;
- GError *error = NULL;
- const gchar *response;
- GRegex *r;
- GMatchInfo *match_info = NULL;
- gint a = -1;
- gint b = -1;
+ GError *error = NULL;
+ const gchar *response;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gint a = -1;
+ gint b = -1;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) {
@@ -187,8 +187,6 @@
"Couldn't match NWRAT reply: %s",
response);
g_object_unref (task);
- g_match_info_free (match_info);
- g_regex_unref (r);
return;
}
@@ -203,8 +201,6 @@
"Failed to parse mode/tech response '%s': invalid modes reported",
response);
g_object_unref (task);
- g_match_info_free (match_info);
- g_regex_unref (r);
return;
}
@@ -239,9 +235,6 @@
break;
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
g_task_return_pointer (task, result, g_free);
g_object_unref (task);
}
@@ -1396,13 +1389,18 @@
MMNetworkTimezone **out_tz,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- guint year, month, day, hour, minute, second;
- gchar *result = NULL;
- gint utc_offset = 0;
- gboolean success = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *match_error = NULL;
+ guint year;
+ guint month;
+ guint day;
+ guint hour;
+ guint minute;
+ guint second;
+ g_autofree gchar *result = NULL;
+ gint utc_offset = 0;
+ gboolean success = FALSE;
/* Sample reply: 2013.3.27.15.47.19.2.-5 */
r = g_regex_new ("(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.([\\-\\+\\d]+)$", 0, 0, NULL);
@@ -1429,7 +1427,6 @@
mm_get_uint_from_match_info (match_info, 5, &minute) &&
mm_get_uint_from_match_info (match_info, 6, &second) &&
mm_get_int_from_match_info (match_info, 8, &utc_offset)) {
-
result = mm_new_iso8601_time (year, month, day, hour, minute, second,
TRUE, utc_offset * 60, error);
if (out_tz) {
@@ -1447,12 +1444,8 @@
}
if (out_iso_8601)
- *out_iso_8601 = result;
- else
- g_free (result);
+ *out_iso_8601 = g_steal_pointer (&result);
- g_match_info_free (match_info);
- g_regex_unref (r);
return success;
}
diff --git a/plugins/option/mm-broadband-modem-option.c b/plugins/option/mm-broadband-modem-option.c
index 5919364..dcecd5b 100644
--- a/plugins/option/mm-broadband-modem-option.c
+++ b/plugins/option/mm-broadband-modem-option.c
@@ -362,12 +362,10 @@
parse_ossys_response (const gchar *response,
MMModemAccessTechnology *access_technology)
{
- MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
- const gchar *p;
- GRegex *r;
- GMatchInfo *match_info;
- gchar *str;
- gboolean success = FALSE;
+ MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+ const gchar *p;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
p = mm_strip_tag (response, "_OSSYS:");
r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL);
@@ -375,17 +373,15 @@
g_regex_match (r, p, 0, &match_info);
if (g_match_info_matches (match_info)) {
+ g_autofree gchar *str = NULL;
+
str = g_match_info_fetch (match_info, 2);
if (str && ossys_to_mm (str[0], ¤t)) {
*access_technology = current;
- success = TRUE;
- }
- g_free (str);
+ return TRUE;
+ }
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
- return success;
+ return FALSE;
}
static void
@@ -445,12 +441,10 @@
parse_octi_response (const gchar *response,
MMModemAccessTechnology *access_technology)
{
- MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
- const gchar *p;
- GRegex *r;
- GMatchInfo *match_info;
- gchar *str;
- gboolean success = FALSE;
+ MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+ const gchar *p;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
p = mm_strip_tag (response, "_OCTI:");
r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL);
@@ -458,17 +452,15 @@
g_regex_match (r, p, 0, &match_info);
if (g_match_info_matches (match_info)) {
+ g_autofree gchar *str = NULL;
+
str = g_match_info_fetch (match_info, 2);
if (str && octi_to_mm (str[0], ¤t)) {
*access_technology = current;
- success = TRUE;
+ return TRUE;
}
- g_free (str);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
- return success;
+ return FALSE;
}
static void
diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c
index ab07943..c383dc0 100644
--- a/plugins/quectel/mm-shared-quectel.c
+++ b/plugins/quectel/mm-shared-quectel.c
@@ -440,8 +440,8 @@
Private *priv;
MMPortSerialAt *ports[2];
GTask *task;
- GRegex *pattern;
guint i;
+ g_autoptr(GRegex) pattern = NULL;
g_autoptr(GError) error = NULL;
priv = get_private (MM_SHARED_QUECTEL (self));
@@ -464,7 +464,6 @@
NULL);
}
- g_regex_unref (pattern);
mm_obj_dbg (self, "+QUSIM detection set up");
if (!mm_broadband_modem_sim_hot_swap_ports_context_init (MM_BROADBAND_MODEM (self), &error))
diff --git a/plugins/sierra/mm-broadband-modem-sierra.c b/plugins/sierra/mm-broadband-modem-sierra.c
index 3ac2080..bae8e34 100644
--- a/plugins/sierra/mm-broadband-modem-sierra.c
+++ b/plugins/sierra/mm-broadband-modem-sierra.c
@@ -624,7 +624,7 @@
MMModemMode *preferred,
GError **error)
{
- LoadCurrentModesResult *result;
+ g_autofree LoadCurrentModesResult *result = NULL;
result = g_task_propagate_pointer (G_TASK (res), error);
if (!result)
@@ -632,7 +632,6 @@
*allowed = result->allowed;
*preferred = result->preferred;
- g_free (result);
return TRUE;
}
@@ -641,11 +640,11 @@
GAsyncResult *res,
GTask *task)
{
- LoadCurrentModesResult *result;
- const gchar *response;
- GError *error = NULL;
- GRegex *r = NULL;
- GMatchInfo *match_info = NULL;
+ g_autofree LoadCurrentModesResult *result = NULL;
+ const gchar *response;
+ GError *error = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
response = mm_base_modem_at_command_full_finish (self, res, &error);
if (!response) {
@@ -727,15 +726,10 @@
"Could not parse allowed mode response: Response didn't match: '%s'",
response);
- g_match_info_free (match_info);
- g_regex_unref (r);
-
- if (error) {
- g_free (result);
+ if (error)
g_task_return_error (task, error);
- } else
- g_task_return_pointer (task, result, g_free);
-
+ else
+ g_task_return_pointer (task, g_steal_pointer (&result), g_free);
g_object_unref (task);
}
@@ -1630,11 +1624,16 @@
const gchar *tag,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- guint year, month, day, hour, minute, second;
- gchar *result = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *match_error = NULL;
+ guint year;
+ guint month;
+ guint day;
+ guint hour;
+ guint minute;
+ guint second;
+ gchar *result = NULL;
r = g_regex_new (regex, 0, 0, NULL);
g_assert (r != NULL);
@@ -1665,8 +1664,6 @@
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
return result;
}
diff --git a/plugins/sierra/mm-common-sierra.c b/plugins/sierra/mm-common-sierra.c
index 341006d..72cbc34 100644
--- a/plugins/sierra/mm-common-sierra.c
+++ b/plugins/sierra/mm-common-sierra.c
@@ -480,7 +480,7 @@
{
MMPortSerialAt *ports[2];
guint i;
- GRegex *pacsp_regex;
+ g_autoptr(GRegex) pacsp_regex = NULL;
pacsp_regex = g_regex_new ("\\r\\n\\+PACSP.*\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
@@ -505,8 +505,6 @@
pacsp_regex,
NULL, NULL, NULL);
}
-
- g_regex_unref (pacsp_regex);
}
/*****************************************************************************/
diff --git a/plugins/sierra/mm-modem-helpers-sierra.c b/plugins/sierra/mm-modem-helpers-sierra.c
index ac07c9e..821be19 100644
--- a/plugins/sierra/mm-modem-helpers-sierra.c
+++ b/plugins/sierra/mm-modem-helpers-sierra.c
@@ -23,16 +23,15 @@
mm_sierra_parse_scact_read_response (const gchar *reply,
GError **error)
{
- GError *inner_error = NULL;
- GRegex *r;
- GMatchInfo *match_info;
- GList *list;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ GList *list = NULL;
if (!reply || !reply[0])
/* Nothing configured, all done */
return NULL;
- list = NULL;
r = g_regex_new ("!SCACT:\\s*(\\d+),(\\d+)",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, &inner_error);
g_assert (r);
@@ -66,9 +65,6 @@
g_match_info_next (match_info, &inner_error);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
mm_3gpp_pdp_context_active_list_free (list);
g_propagate_error (error, inner_error);
@@ -76,7 +72,5 @@
return NULL;
}
- list = g_list_sort (list, (GCompareFunc) mm_3gpp_pdp_context_active_cmp);
-
- return list;
+ return g_list_sort (list, (GCompareFunc) mm_3gpp_pdp_context_active_cmp);
}
diff --git a/plugins/simtech/tests/test-modem-helpers-simtech.c b/plugins/simtech/tests/test-modem-helpers-simtech.c
index d5d774f..ba6532c 100644
--- a/plugins/simtech/tests/test-modem-helpers-simtech.c
+++ b/plugins/simtech/tests/test-modem-helpers-simtech.c
@@ -33,13 +33,13 @@
const MMCallInfo *expected_call_info_list,
guint expected_call_info_list_size)
{
- GError *error = NULL;
- GRegex *clcc_regex = NULL;
- gboolean result;
- GMatchInfo *match_info = NULL;
- gchar *str;
- GList *call_info_list = NULL;
- GList *l;
+ g_autoptr(GRegex) clcc_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *str = NULL;
+ GError *error = NULL;
+ GList *call_info_list = NULL;
+ GList *l;
+ gboolean result;
clcc_regex = mm_simtech_get_clcc_urc_regex ();
@@ -84,10 +84,6 @@
g_assert (found);
}
- g_match_info_free (match_info);
- g_regex_unref (clcc_regex);
- g_free (str);
-
mm_simtech_call_info_list_free (call_info_list);
}
@@ -148,12 +144,12 @@
gboolean expected_start_or_stop,
guint expected_duration)
{
- GError *error = NULL;
- gboolean start_or_stop = FALSE; /* start = TRUE, stop = FALSE */
- guint duration = 0;
- GRegex *voice_call_regex = NULL;
- gboolean result;
- GMatchInfo *match_info = NULL;
+ g_autoptr(GRegex) voice_call_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *error = NULL;
+ gboolean start_or_stop = FALSE; /* start = TRUE, stop = FALSE */
+ guint duration = 0;
+ gboolean result;
voice_call_regex = mm_simtech_get_voice_call_urc_regex ();
@@ -168,9 +164,6 @@
g_assert_cmpuint (expected_start_or_stop, ==, start_or_stop);
g_assert_cmpuint (expected_duration, ==, duration);
-
- g_match_info_free (match_info);
- g_regex_unref (voice_call_regex);
}
static void
@@ -197,11 +190,11 @@
common_test_missed_call_urc (const gchar *urc,
const gchar *expected_details)
{
- GError *error = NULL;
- gchar *details = NULL;
- GRegex *missed_call_regex = NULL;
- gboolean result;
- GMatchInfo *match_info = NULL;
+ g_autoptr(GRegex) missed_call_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *details = NULL;
+ GError *error = NULL;
+ gboolean result;
missed_call_regex = mm_simtech_get_missed_call_urc_regex ();
@@ -215,10 +208,6 @@
g_assert (result);
g_assert_cmpstr (expected_details, ==, details);
- g_free (details);
-
- g_match_info_free (match_info);
- g_regex_unref (missed_call_regex);
}
static void
@@ -233,11 +222,11 @@
common_test_cring_urc (const gchar *urc,
const gchar *expected_type)
{
- GError *error = NULL;
- GRegex *cring_regex = NULL;
- GMatchInfo *match_info = NULL;
- gchar *type;
- gboolean result;
+ g_autoptr(GRegex) cring_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *type = NULL;
+ GError *error = NULL;
+ gboolean result;
cring_regex = mm_simtech_get_cring_urc_regex ();
@@ -250,10 +239,6 @@
g_assert (type);
g_assert_cmpstr (type, ==, expected_type);
-
- g_match_info_free (match_info);
- g_regex_unref (cring_regex);
- g_free (type);
}
static void
@@ -274,11 +259,11 @@
common_test_rxdtmf_urc (const gchar *urc,
const gchar *expected_str)
{
- GError *error = NULL;
- GRegex *rxdtmf_regex = NULL;
- GMatchInfo *match_info = NULL;
- gchar *type;
- gboolean result;
+ g_autoptr(GRegex) rxdtmf_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *type = NULL;
+ GError *error = NULL;
+ gboolean result;
rxdtmf_regex = mm_simtech_get_rxdtmf_urc_regex ();
@@ -291,10 +276,6 @@
g_assert (type);
g_assert_cmpstr (type, ==, expected_str);
-
- g_match_info_free (match_info);
- g_regex_unref (rxdtmf_regex);
- g_free (type);
}
static void
diff --git a/plugins/telit/mm-broadband-modem-telit.c b/plugins/telit/mm-broadband-modem-telit.c
index 49e4824..bbf3f76 100644
--- a/plugins/telit/mm-broadband-modem-telit.c
+++ b/plugins/telit/mm-broadband-modem-telit.c
@@ -501,10 +501,10 @@
GAsyncResult *res,
GTask *task)
{
- QssSetupContext *ctx;
- MMPortSerialAt *port;
- GError **error;
- GRegex *pattern;
+ QssSetupContext *ctx;
+ MMPortSerialAt *port;
+ GError **error;
+ g_autoptr(GRegex) pattern = NULL;
ctx = g_task_get_task_data (task);
@@ -530,7 +530,6 @@
(MMPortSerialAtUnsolicitedMsgFn)telit_qss_unsolicited_handler,
self,
NULL);
- g_regex_unref (pattern);
next_step:
ctx->step++;
diff --git a/plugins/telit/mm-common-telit.c b/plugins/telit/mm-common-telit.c
index 2e0b380..911c605 100644
--- a/plugins/telit/mm-common-telit.c
+++ b/plugins/telit/mm-common-telit.c
@@ -112,12 +112,12 @@
MMDevice *device,
const gchar *reply)
{
- GRegex *r = NULL;
- GRegexCompileFlags flags = G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW;
- GMatchInfo *match_info = NULL;
- GError *error = NULL;
- gboolean ret = FALSE;
- guint portcfg_current;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GRegexCompileFlags flags = G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW;
+ GError *error = NULL;
+ gboolean ret = FALSE;
+ guint portcfg_current;
/* #PORTCFG: <requested>,<active> */
r = g_regex_new ("#PORTCFG:\\s*(\\d+),(\\d+)", flags, 0, NULL);
@@ -173,9 +173,7 @@
ret = TRUE;
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
- if (error != NULL) {
+ if (error) {
mm_obj_dbg (probe, "error while matching #PORTCFG: %s", error->message);
g_error_free (error);
}
diff --git a/plugins/telit/mm-modem-helpers-telit.c b/plugins/telit/mm-modem-helpers-telit.c
index c2061fc..54cd6a0 100644
--- a/plugins/telit/mm-modem-helpers-telit.c
+++ b/plugins/telit/mm-modem-helpers-telit.c
@@ -701,11 +701,11 @@
gpointer log_object,
GError **error)
{
- GError *inner_error = NULL;
- GArray *bands = NULL;
- GMatchInfo *match_info = NULL;
- GRegex *r = NULL;
- const gchar *load_bands_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ GError *inner_error = NULL;
+ GArray *bands = NULL;
+ const gchar *load_bands_regex = NULL;
static const gchar *load_bands_regex_4g_hex[] = {
[LOAD_BANDS_TYPE_SUPPORTED] = "#BND:"MM_SUPPORTED_BANDS_2G MM_SUPPORTED_BANDS_3G MM_SUPPORTED_BANDS_4G_HEX,
@@ -761,9 +761,6 @@
goto out;
}
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
g_clear_pointer (&bands, g_array_unref);
diff --git a/plugins/telit/mm-shared-telit.c b/plugins/telit/mm-shared-telit.c
index 2dc6b57..e5f4413 100644
--- a/plugins/telit/mm-shared-telit.c
+++ b/plugins/telit/mm-shared-telit.c
@@ -61,7 +61,15 @@
is_bnd_4g_format_hex (MMBaseModem *self,
const gchar *revision)
{
- return mm_telit_model_from_revision (revision) == MM_TELIT_MODEL_LE910C1;
+ MMTelitModel model;
+
+ model = mm_telit_model_from_revision (revision);
+
+ return (model == MM_TELIT_MODEL_FN980 ||
+ model == MM_TELIT_MODEL_LE910C1 ||
+ model == MM_TELIT_MODEL_LM940 ||
+ model == MM_TELIT_MODEL_LM960 ||
+ model == MM_TELIT_MODEL_LN920);
}
static void
diff --git a/plugins/ublox/mm-broadband-modem-ublox.c b/plugins/ublox/mm-broadband-modem-ublox.c
index b5c2072..e070b75 100644
--- a/plugins/ublox/mm-broadband-modem-ublox.c
+++ b/plugins/ublox/mm-broadband-modem-ublox.c
@@ -1122,10 +1122,10 @@
ublox_setup_ciev_handler (MMIfaceModem *self,
guint simind_idx)
{
- GRegex *pattern;
- gchar *ciev_regex;
- MMPortSerialAt *primary_port;
- MMPortSerialAt *secondary_port;
+ g_autoptr(GRegex) pattern = NULL;
+ g_autofree gchar *ciev_regex = NULL;
+ MMPortSerialAt *primary_port;
+ MMPortSerialAt *secondary_port;
primary_port = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
mm_obj_dbg (self, "setting up simind 'CIEV: %d' events handler", simind_idx);
@@ -1149,9 +1149,6 @@
(MMPortSerialAtUnsolicitedMsgFn) ublox_ciev_unsolicited_handler,
self,
NULL);
-
- g_regex_unref (pattern);
- g_free (ciev_regex);
}
static void
diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c
index bb0e02a..84a7cf2 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.c
+++ b/plugins/ublox/mm-modem-helpers-ublox.c
@@ -31,14 +31,14 @@
guint *out_puk2_attempts,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- guint pin_attempts = 0;
- guint pin2_attempts = 0;
- guint puk_attempts = 0;
- guint puk2_attempts = 0;
- gboolean success = TRUE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint pin_attempts = 0;
+ guint pin2_attempts = 0;
+ guint puk_attempts = 0;
+ guint puk2_attempts = 0;
+ gboolean success = TRUE;
g_assert (out_pin_attempts);
g_assert (out_pin2_attempts);
@@ -78,9 +78,6 @@
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -107,10 +104,10 @@
MMUbloxUsbProfile *out_profile,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- MMUbloxUsbProfile profile = MM_UBLOX_USB_PROFILE_UNKNOWN;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ MMUbloxUsbProfile profile = MM_UBLOX_USB_PROFILE_UNKNOWN;
g_assert (out_profile != NULL);
@@ -127,7 +124,7 @@
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
if (!inner_error && g_match_info_matches (match_info)) {
- gchar *profile_name;
+ g_autofree gchar *profile_name = NULL;
profile_name = mm_get_string_unquoted_from_match_info (match_info, 2);
if (profile_name && profile_name[0]) {
@@ -140,12 +137,8 @@
"Unknown USB profile: '%s'", profile_name);
} else
profile = MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE;
- g_free (profile_name);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -169,10 +162,10 @@
MMUbloxNetworkingMode *out_mode,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- MMUbloxNetworkingMode mode = MM_UBLOX_NETWORKING_MODE_UNKNOWN;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ MMUbloxNetworkingMode mode = MM_UBLOX_NETWORKING_MODE_UNKNOWN;
g_assert (out_mode != NULL);
@@ -203,9 +196,6 @@
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -234,15 +224,15 @@
gchar **out_ipv6_link_local_address,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- guint cid = 0;
- gchar *if_name = NULL;
- gchar *ipv4_address = NULL;
- gchar *ipv4_subnet = NULL;
- gchar *ipv6_global_address = NULL;
- gchar *ipv6_link_local_address = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint cid = 0;
+ g_autofree gchar *if_name = NULL;
+ g_autofree gchar *ipv4_address = NULL;
+ g_autofree gchar *ipv4_subnet = NULL;
+ g_autofree gchar *ipv6_global_address = NULL;
+ g_autofree gchar *ipv6_link_local_address = NULL;
/* Response may be e.g.:
* +UIPADDR: 1,"ccinet0","5.168.120.13","255.255.255.0","",""
@@ -255,65 +245,44 @@
g_assert (r != NULL);
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
- if (inner_error)
- goto out;
-
- if (!g_match_info_matches (match_info)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, "Couldn't match +UIPADDR response");
- goto out;
- }
-
- if (out_cid && !mm_get_uint_from_match_info (match_info, 1, &cid)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing cid");
- goto out;
- }
-
- if (out_if_name && !(if_name = mm_get_string_unquoted_from_match_info (match_info, 2))) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing interface name");
- goto out;
- }
-
- /* Remaining strings are optional */
-
- if (out_ipv4_address)
- ipv4_address = mm_get_string_unquoted_from_match_info (match_info, 3);
-
- if (out_ipv4_subnet)
- ipv4_subnet = mm_get_string_unquoted_from_match_info (match_info, 4);
-
- if (out_ipv6_global_address)
- ipv6_global_address = mm_get_string_unquoted_from_match_info (match_info, 5);
-
- if (out_ipv6_link_local_address)
- ipv6_link_local_address = mm_get_string_unquoted_from_match_info (match_info, 6);
-
-out:
-
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
- g_free (if_name);
- g_free (ipv4_address);
- g_free (ipv4_subnet);
- g_free (ipv6_global_address);
- g_free (ipv6_link_local_address);
g_propagate_error (error, inner_error);
return FALSE;
}
+ if (!g_match_info_matches (match_info)) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, "Couldn't match +UIPADDR response");
+ return FALSE;
+ }
+
+ if (out_cid && !mm_get_uint_from_match_info (match_info, 1, &cid)) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing cid");
+ return FALSE;
+ }
+
+ if (out_if_name && !(if_name = mm_get_string_unquoted_from_match_info (match_info, 2))) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing interface name");
+ return FALSE;
+ }
+
+ /* Remaining strings are optional */
+ ipv4_address = mm_get_string_unquoted_from_match_info (match_info, 3);
+ ipv4_subnet = mm_get_string_unquoted_from_match_info (match_info, 4);
+ ipv6_global_address = mm_get_string_unquoted_from_match_info (match_info, 5);
+ ipv6_link_local_address = mm_get_string_unquoted_from_match_info (match_info, 6);
+
if (out_cid)
*out_cid = cid;
if (out_if_name)
- *out_if_name = if_name;
+ *out_if_name = g_steal_pointer (&if_name);
if (out_ipv4_address)
- *out_ipv4_address = ipv4_address;
+ *out_ipv4_address = g_steal_pointer (&ipv4_address);
if (out_ipv4_subnet)
- *out_ipv4_subnet = ipv4_subnet;
+ *out_ipv4_subnet = g_steal_pointer (&ipv4_subnet);
if (out_ipv6_global_address)
- *out_ipv6_global_address = ipv6_global_address;
+ *out_ipv6_global_address = g_steal_pointer (&ipv6_global_address);
if (out_ipv6_link_local_address)
- *out_ipv6_link_local_address = ipv6_link_local_address;
+ *out_ipv6_link_local_address = g_steal_pointer (&ipv6_link_local_address);
return TRUE;
}
@@ -1550,11 +1519,11 @@
mm_ublox_parse_uact_response (const gchar *response,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- GArray *nums = NULL;
- GArray *bands = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ GArray *nums = NULL;
+ GArray *bands = NULL;
/*
* AT+UACT?
@@ -1566,16 +1535,12 @@
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
if (!inner_error && g_match_info_matches (match_info)) {
- gchar *bandstr;
+ g_autofree gchar *bandstr = NULL;
bandstr = mm_get_string_unquoted_from_match_info (match_info, 4);
nums = mm_parse_uint_list (bandstr, &inner_error);
- g_free (bandstr);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return NULL;
@@ -1632,16 +1597,16 @@
GArray **bands4g_out,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- const gchar *bands2g_str = NULL;
- const gchar *bands3g_str = NULL;
- const gchar *bands4g_str = NULL;
- GArray *bands2g = NULL;
- GArray *bands3g = NULL;
- GArray *bands4g = NULL;
- gchar **split = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_auto(GStrv) split = NULL;
+ GError *inner_error = NULL;
+ const gchar *bands2g_str = NULL;
+ const gchar *bands3g_str = NULL;
+ const gchar *bands4g_str = NULL;
+ GArray *bands2g = NULL;
+ GArray *bands3g = NULL;
+ GArray *bands4g = NULL;
g_assert (bands2g_out && bands3g_out && bands4g_out);
@@ -1658,8 +1623,8 @@
goto out;
if (g_match_info_matches (match_info)) {
- gchar *aux;
- guint n_groups;
+ g_autofree gchar *aux = NULL;
+ guint n_groups;
aux = mm_get_string_unquoted_from_match_info (match_info, 4);
split = mm_split_string_groups (aux);
@@ -1670,7 +1635,6 @@
bands3g_str = split[1];
if (n_groups >= 3)
bands4g_str = split[2];
- g_free (aux);
}
if (!bands2g_str && !bands3g_str && !bands4g_str) {
@@ -1692,10 +1656,6 @@
/* success */
out:
- g_strfreev (split);
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
if (bands2g)
g_array_unref (bands2g);
@@ -1760,13 +1720,13 @@
MMModemMode *out_preferred,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- MMModemMode allowed = MM_MODEM_MODE_NONE;
- MMModemMode preferred = MM_MODEM_MODE_NONE;
- gchar *allowed_str = NULL;
- gchar *preferred_str = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ MMModemMode allowed = MM_MODEM_MODE_NONE;
+ MMModemMode preferred = MM_MODEM_MODE_NONE;
+ g_autofree gchar *allowed_str = NULL;
+ g_autofree gchar *preferred_str = NULL;
g_assert (out_allowed != NULL && out_preferred != NULL);
@@ -1821,13 +1781,6 @@
}
out:
-
- g_free (allowed_str);
- g_free (preferred_str);
-
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -1981,14 +1934,14 @@
guint64 *out_total_rx_bytes,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *inner_error = NULL;
- guint64 session_tx_bytes = 0;
- guint64 session_rx_bytes = 0;
- guint64 total_tx_bytes = 0;
- guint64 total_rx_bytes = 0;
- gboolean matched = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint64 session_tx_bytes = 0;
+ guint64 session_rx_bytes = 0;
+ guint64 total_tx_bytes = 0;
+ guint64 total_rx_bytes = 0;
+ gboolean matched = FALSE;
/* Response may be e.g.:
* +UGCNTRD: 31,2704,1819,2724,1839
@@ -2044,10 +1997,6 @@
}
out:
-
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
diff --git a/plugins/via/mm-broadband-modem-via.c b/plugins/via/mm-broadband-modem-via.c
index 6a8b450..896db8c 100644
--- a/plugins/via/mm-broadband-modem-via.c
+++ b/plugins/via/mm-broadband-modem-via.c
@@ -153,7 +153,7 @@
MMModemCdmaRegistrationState *detailed_evdo_state,
GError **error)
{
- DetailedRegistrationStateResults *results;
+ g_autofree DetailedRegistrationStateResults *results = NULL;
results = g_task_propagate_pointer (G_TASK (res), error);
if (!results)
@@ -161,7 +161,6 @@
*detailed_cdma1x_state = results->detailed_cdma1x_state;
*detailed_evdo_state = results->detailed_evdo_state;
- g_free (results);
return TRUE;
}
@@ -171,13 +170,13 @@
GTask *task)
{
- DetailedRegistrationStateResults *ctx;
- DetailedRegistrationStateResults *results;
- const gchar *response;
- GRegex *r;
- GMatchInfo *match_info;
- MMModemCdmaRegistrationState reg_state;
- guint val = 0;
+ DetailedRegistrationStateResults *ctx;
+ g_autofree DetailedRegistrationStateResults *results = NULL;
+ const gchar *response;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ MMModemCdmaRegistrationState reg_state;
+ guint val = 0;
ctx = g_task_get_task_data (task);
@@ -236,11 +235,8 @@
results->detailed_cdma1x_state = reg_state;
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
out:
- g_task_return_pointer (task, results, NULL);
+ g_task_return_pointer (task, g_steal_pointer (&results), g_free);
g_object_unref (task);
}
diff --git a/plugins/wavecom/mm-broadband-modem-wavecom.c b/plugins/wavecom/mm-broadband-modem-wavecom.c
index 8659e1c..521e72d 100644
--- a/plugins/wavecom/mm-broadband-modem-wavecom.c
+++ b/plugins/wavecom/mm-broadband-modem-wavecom.c
@@ -1223,9 +1223,9 @@
static void
setup_ports (MMBroadbandModem *self)
{
- gpointer parser;
- MMPortSerialAt *primary;
- GRegex *regex;
+ gpointer parser;
+ MMPortSerialAt *primary;
+ g_autoptr(GRegex) regex = NULL;
/* Call parent's setup ports first always */
MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_wavecom_parent_class)->setup_ports (self);
@@ -1242,7 +1242,6 @@
G_REGEX_RAW | G_REGEX_OPTIMIZE,
0, NULL);
mm_serial_parser_v1_set_custom_regex (parser, regex, NULL);
- g_regex_unref (regex);
mm_port_serial_at_set_response_parser (MM_PORT_SERIAL_AT (primary),
mm_serial_parser_v1_parse,
diff --git a/plugins/x22x/mm-broadband-modem-x22x.c b/plugins/x22x/mm-broadband-modem-x22x.c
index c474426..1ce32f5 100644
--- a/plugins/x22x/mm-broadband-modem-x22x.c
+++ b/plugins/x22x/mm-broadband-modem-x22x.c
@@ -120,12 +120,12 @@
MMModemMode *preferred,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- const gchar *response;
- gchar *str;
- gint mode = -1;
- GError *match_error = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ const gchar *response;
+ gchar *str;
+ gint mode = -1;
+ GError *match_error = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
if (!response)
@@ -143,17 +143,12 @@
MM_CORE_ERROR_FAILED,
"Couldn't match +SYSSEL reply: %s", response);
}
-
- g_match_info_free (match_info);
- g_regex_unref (r);
return FALSE;
}
str = g_match_info_fetch (match_info, 3);
mode = atoi (str);
g_free (str);
- g_match_info_free (match_info);
- g_regex_unref (r);
switch (mode) {
case 0:
diff --git a/plugins/xmm/mm-modem-helpers-xmm.c b/plugins/xmm/mm-modem-helpers-xmm.c
index 9b3933d..70e02a8 100644
--- a/plugins/xmm/mm-modem-helpers-xmm.c
+++ b/plugins/xmm/mm-modem-helpers-xmm.c
@@ -364,11 +364,11 @@
GArray **bands_out,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- GArray *bands = NULL;
- guint i;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ GArray *bands = NULL;
+ guint i;
MMModemModeCombination mode = {
.allowed = MM_MODEM_MODE_NONE,
@@ -450,9 +450,6 @@
/* success */
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
if (bands)
g_array_unref (bands);
@@ -609,17 +606,17 @@
gint *out_rssnr,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- guint rxlev = 99;
- guint ber = 99;
- guint rscp = 255;
- guint ecn0 = 255;
- guint rsrq = 255;
- guint rsrp = 255;
- gint rssnr = 255;
- gboolean success = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint rxlev = 99;
+ guint ber = 99;
+ guint rscp = 255;
+ guint ecn0 = 255;
+ guint rsrq = 255;
+ guint rsrp = 255;
+ gint rssnr = 255;
+ gboolean success = FALSE;
g_assert (out_rxlev);
g_assert (out_ber);
@@ -672,9 +669,6 @@
}
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -959,11 +953,11 @@
gchar **supl_address,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- gchar *address = NULL;
- guint port = 0;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ gchar *address = NULL;
+ guint port = 0;
/*
* E.g.:
@@ -996,9 +990,6 @@
}
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
diff --git a/plugins/zte/mm-broadband-modem-zte.c b/plugins/zte/mm-broadband-modem-zte.c
index f4cb774..3528353 100644
--- a/plugins/zte/mm-broadband-modem-zte.c
+++ b/plugins/zte/mm-broadband-modem-zte.c
@@ -339,22 +339,20 @@
MMModemMode *preferred,
GError **error)
{
- const gchar *response;
- GMatchInfo *match_info = NULL;
- GRegex *r;
- gint cm_mode = -1;
- gint pref_acq = -1;
- gboolean result;
- GError *match_error = NULL;
+ const gchar *response;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ gint cm_mode = -1;
+ gint pref_acq = -1;
+ GError *match_error = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
if (!response)
return FALSE;
- r = g_regex_new ("\\+ZSNT:\\s*(\\d),(\\d),(\\d)", G_REGEX_UNGREEDY, 0, error);
+ r = g_regex_new ("\\+ZSNT:\\s*(\\d),(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL);
g_assert (r != NULL);
- result = FALSE;
if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)) {
if (match_error)
g_propagate_error (error, match_error);
@@ -364,7 +362,7 @@
MM_CORE_ERROR_FAILED,
"Couldn't parse +ZSNT response: '%s'",
response);
- goto done;
+ return FALSE;
}
if (!mm_get_int_from_match_info (match_info, 1, &cm_mode) ||
@@ -376,11 +374,10 @@
MM_CORE_ERROR_FAILED,
"Failed to parse the allowed mode response: '%s'",
response);
- goto done;
+ return FALSE;
}
/* Correctly parsed! */
- result = TRUE;
if (cm_mode == 0) {
/* Both 2G, 3G and LTE allowed. For LTE modems, no 2G/3G preference supported. */
if (pref_acq == 0 || mm_iface_modem_is_3gpp_lte (self)) {
@@ -410,12 +407,7 @@
} else
g_assert_not_reached ();
-done:
- g_match_info_free (match_info);
- if (r)
- g_regex_unref (r);
-
- return result;
+ return TRUE;
}
static void
diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c
index b322ceb..8b6a8a4 100644
--- a/src/mm-broadband-modem-qmi.c
+++ b/src/mm-broadband-modem-qmi.c
@@ -191,6 +191,10 @@
gboolean dsd_supported;
gboolean dsd_data_rat_available;
MMModem3gppRegistrationState system_info_ps_registration_state;
+ MMModemAccessTechnology access_tech;
+ guint16 location_area_code;
+ guint16 tracking_area_code;
+ guint32 cell_id;
};
/*****************************************************************************/
@@ -3970,6 +3974,10 @@
self->priv->system_info_ps_registration_state = ps_registration_state;
consolidated_update_ps_registration_state (self, has_lte_info, has_nr5g_info);
+ self->priv->access_tech = act;
+ self->priv->location_area_code = lac;
+ self->priv->tracking_area_code = tac;
+ self->priv->cell_id = cid;
mm_iface_modem_3gpp_update_access_technologies (MM_IFACE_MODEM_3GPP (self), act);
mm_iface_modem_3gpp_update_location (MM_IFACE_MODEM_3GPP (self), lac, tac, cid);
}
@@ -4057,6 +4065,8 @@
/* Store DSD data RAT availability and update PS/EPS/5GS states accordingly */
self->priv->dsd_data_rat_available = data_rat_available;
consolidated_update_ps_registration_state (self, is_lte, is_nr5g);
+ mm_iface_modem_3gpp_update_access_technologies (MM_IFACE_MODEM_3GPP (self), self->priv->access_tech);
+ mm_iface_modem_3gpp_update_location (MM_IFACE_MODEM_3GPP (self), self->priv->location_area_code, self->priv->tracking_area_code, self->priv->cell_id);
}
static void
@@ -13442,6 +13452,7 @@
MMBroadbandModemQmiPrivate);
self->priv->current_pdn_list = g_array_new (FALSE, FALSE, sizeof (guint16));
self->priv->system_info_ps_registration_state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN;
+ self->priv->access_tech = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
}
static void
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
index c30021c..12b7764 100644
--- a/src/mm-broadband-modem.c
+++ b/src/mm-broadband-modem.c
@@ -3169,9 +3169,9 @@
set_cgev_unsolicited_events_handlers (MMBroadbandModem *self,
gboolean enable)
{
- MMPortSerialAt *ports[2];
- GRegex *cgev_regex;
- guint i;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) cgev_regex = NULL;
+ guint i;
cgev_regex = mm_3gpp_cgev_regex_get ();
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
@@ -3193,8 +3193,6 @@
enable ? self : NULL,
NULL);
}
-
- g_regex_unref (cgev_regex);
}
static void
@@ -3245,9 +3243,9 @@
set_ciev_unsolicited_events_handlers (MMBroadbandModem *self,
gboolean enable)
{
- MMPortSerialAt *ports[2];
- GRegex *ciev_regex;
- guint i;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) ciev_regex = NULL;
+ guint i;
ciev_regex = mm_3gpp_ciev_regex_get ();
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
@@ -3269,8 +3267,6 @@
enable ? self : NULL,
NULL);
}
-
- g_regex_unref (ciev_regex);
}
static void
@@ -5160,20 +5156,20 @@
GAsyncResult *res,
GTask *task)
{
+ g_autoptr(GMatchInfo) match_info = NULL;
RunRegistrationChecksContext *ctx;
- const gchar *response;
- GError *error = NULL;
- GMatchInfo *match_info = NULL;
- guint i;
- gboolean parsed;
- gboolean cgreg = FALSE;
- gboolean cereg = FALSE;
- gboolean c5greg = FALSE;
- MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN;
- MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
- gulong lac = 0;
- gulong tac = 0;
- gulong cid = 0;
+ const gchar *response;
+ GError *error = NULL;
+ guint i;
+ gboolean parsed;
+ gboolean cgreg = FALSE;
+ gboolean cereg = FALSE;
+ gboolean c5greg = FALSE;
+ MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN;
+ MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+ gulong lac = 0;
+ gulong tac = 0;
+ gulong cid = 0;
ctx = g_task_get_task_data (task);
@@ -5205,8 +5201,7 @@
0,
&match_info))
break;
- g_match_info_free (match_info);
- match_info = NULL;
+ g_clear_pointer (&match_info, g_match_info_free);
}
if (!match_info) {
@@ -5229,7 +5224,6 @@
&cereg,
&c5greg,
&error);
- g_match_info_free (match_info);
if (!parsed) {
if (!error)
@@ -6306,10 +6300,10 @@
GAsyncReadyCallback callback,
gpointer user_data)
{
- MMPortSerialAt *ports[2];
- GRegex *cusd_regex;
- guint i;
- GTask *task;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) cusd_regex = NULL;
+ guint i;
+ GTask *task;
cusd_regex = mm_3gpp_cusd_regex_get ();
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
@@ -6331,8 +6325,6 @@
NULL);
}
- g_regex_unref (cusd_regex);
-
task = g_task_new (self, NULL, callback, user_data);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
@@ -7233,11 +7225,11 @@
GAsyncReadyCallback callback,
gpointer user_data)
{
- MMPortSerialAt *ports[2];
- GRegex *cmti_regex;
- GRegex *cds_regex;
- guint i;
- GTask *task;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) cmti_regex = NULL;
+ g_autoptr(GRegex) cds_regex = NULL;
+ guint i;
+ GTask *task;
cmti_regex = mm_3gpp_cmti_regex_get ();
cds_regex = mm_3gpp_cds_regex_get ();
@@ -7267,9 +7259,6 @@
NULL);
}
- g_regex_unref (cmti_regex);
- g_regex_unref (cds_regex);
-
task = g_task_new (self, NULL, callback, user_data);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
@@ -7486,11 +7475,11 @@
GAsyncResult *res,
GTask *task)
{
- ListPartsContext *ctx;
- GRegex *r;
- GMatchInfo *match_info = NULL;
- const gchar *response;
- GError *error = NULL;
+ ListPartsContext *ctx;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ const gchar *response;
+ GError *error = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error) {
@@ -7510,8 +7499,6 @@
MM_CORE_ERROR_INVALID_ARGS,
"Couldn't parse SMS list response");
g_object_unref (task);
- g_match_info_free (match_info);
- g_regex_unref (r);
return;
}
@@ -7597,8 +7584,6 @@
next:
g_match_info_next (match_info, NULL);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
/* We consider all done */
g_task_return_boolean (task, TRUE);
@@ -7929,9 +7914,9 @@
PortsContext *ports_ctx,
gboolean enable)
{
- MMPortSerialAt *ports[2];
- GRegex *in_call_event_regex;
- guint i;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) in_call_event_regex = NULL;
+ guint i;
in_call_event_regex = g_regex_new ("\\r\\n(NO CARRIER|BUSY|NO ANSWER|NO DIALTONE)(\\r)?\\r\\n$",
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
@@ -7954,8 +7939,6 @@
enable ? self : NULL,
NULL);
}
-
- g_regex_unref (in_call_event_regex);
}
static void
@@ -8146,13 +8129,13 @@
GAsyncReadyCallback callback,
gpointer user_data)
{
- MMPortSerialAt *ports[2];
- GRegex *cring_regex;
- GRegex *ring_regex;
- GRegex *clip_regex;
- GRegex *ccwa_regex;
- guint i;
- GTask *task;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) cring_regex = NULL;
+ g_autoptr(GRegex) ring_regex = NULL;
+ g_autoptr(GRegex) clip_regex = NULL;
+ g_autoptr(GRegex) ccwa_regex = NULL;
+ guint i;
+ GTask *task;
cring_regex = mm_voice_cring_regex_get ();
ring_regex = mm_voice_ring_regex_get ();
@@ -8196,11 +8179,6 @@
NULL);
}
- g_regex_unref (ccwa_regex);
- g_regex_unref (clip_regex);
- g_regex_unref (cring_regex);
- g_regex_unref (ring_regex);
-
task = g_task_new (self, NULL, callback, user_data);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
@@ -9264,8 +9242,8 @@
band = 'Z';
success = TRUE;
} else {
- GRegex *r;
- GMatchInfo *match_info;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
/* Format is "<band_class>,<band>,<sid>" */
r = g_regex_new ("\\s*([^,]*?)\\s*,\\s*([^,]*?)\\s*,\\s*(\\d+)", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
@@ -9296,9 +9274,6 @@
success = TRUE;
}
-
- g_match_info_free (match_info);
- g_regex_unref (r);
}
if (!success) {
@@ -10914,10 +10889,13 @@
static void
setup_ports (MMBroadbandModem *self)
{
- MMPortSerialAt *ports[2];
- GRegex *regex;
- GPtrArray *array;
- guint i, j;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) ciev_regex = NULL;
+ g_autoptr(GRegex) cmti_regex = NULL;
+ g_autoptr(GRegex) cusd_regex = NULL;
+ GPtrArray *array;
+ guint i;
+ guint j;
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
@@ -10933,64 +10911,23 @@
NULL);
/* Cleanup all unsolicited message handlers in all AT ports */
-
- /* Set up CREG unsolicited message handlers, with NULL callbacks */
array = mm_3gpp_creg_regex_get (FALSE);
+ ciev_regex = mm_3gpp_ciev_regex_get ();
+ cmti_regex = mm_3gpp_cmti_regex_get ();
+ cusd_regex = mm_3gpp_cusd_regex_get ();
+
for (i = 0; i < 2; i++) {
if (!ports[i])
continue;
- for (j = 0; j < array->len; j++) {
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]),
- (GRegex *)g_ptr_array_index (array, j),
- NULL,
- NULL,
- NULL);
- }
+ for (j = 0; j < array->len; j++)
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), (GRegex *)g_ptr_array_index (array, j), NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), ciev_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), cmti_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), cusd_regex, NULL, NULL, NULL);
}
+
mm_3gpp_creg_regex_destroy (array);
-
- /* Set up CIEV unsolicited message handler, with NULL callback */
- regex = mm_3gpp_ciev_regex_get ();
- for (i = 0; i < 2; i++) {
- if (!ports[i])
- continue;
-
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]),
- regex,
- NULL,
- NULL,
- NULL);
- }
- g_regex_unref (regex);
-
- /* Set up CMTI unsolicited message handler, with NULL callback */
- regex = mm_3gpp_cmti_regex_get ();
- for (i = 0; i < 2; i++) {
- if (!ports[i])
- continue;
-
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]),
- regex,
- NULL,
- NULL,
- NULL);
- }
- g_regex_unref (regex);
-
- /* Set up CUSD unsolicited message handler, with NULL callback */
- regex = mm_3gpp_cusd_regex_get ();
- for (i = 0; i < 2; i++) {
- if (!ports[i])
- continue;
-
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]),
- regex,
- NULL,
- NULL,
- NULL);
- }
- g_regex_unref (regex);
}
/*****************************************************************************/
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 5e58ba9..d71e108 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -528,10 +528,10 @@
GList **out_list,
GError **error)
{
- GRegex *r;
- GList *list = NULL;
- GError *inner_error = NULL;
- GMatchInfo *match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GList *list = NULL;
+ GError *inner_error = NULL;
static const MMCallDirection call_direction[] = {
[0] = MM_CALL_DIRECTION_OUTGOING,
@@ -641,9 +641,6 @@
}
out:
- g_clear_pointer (&match_info, g_match_info_free);
- g_regex_unref (r);
-
if (inner_error) {
mm_3gpp_call_info_list_free (list);
g_propagate_error (error, inner_error);
@@ -736,12 +733,12 @@
gpointer log_object,
GError **error)
{
- GRegex *r;
- GError *inner_error = NULL;
- GMatchInfo *match_info = NULL;
- MMFlowControl te_mask = MM_FLOW_CONTROL_UNKNOWN;
- MMFlowControl ta_mask = MM_FLOW_CONTROL_UNKNOWN;
- MMFlowControl mask = MM_FLOW_CONTROL_UNKNOWN;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ MMFlowControl te_mask = MM_FLOW_CONTROL_UNKNOWN;
+ MMFlowControl ta_mask = MM_FLOW_CONTROL_UNKNOWN;
+ MMFlowControl mask = MM_FLOW_CONTROL_UNKNOWN;
r = g_regex_new ("(?:\\+IFC:)?\\s*\\((.*)\\),\\((.*)\\)(?:\\r\\n)?", 0, 0, NULL);
g_assert (r != NULL);
@@ -767,10 +764,6 @@
mask = te_mask & ta_mask;
out:
-
- g_clear_pointer (&match_info, g_match_info_free);
- g_regex_unref (r);
-
if (inner_error)
g_propagate_error (error, inner_error);
@@ -982,21 +975,21 @@
gpointer log_object,
GError **error)
{
- GArray *modes = NULL;
- GArray *tech_values = NULL;
- GRegex *r;
- GError *inner_error = NULL;
- GMatchInfo *match_info = NULL;
- gchar *full_list = NULL;
- guint val;
- guint i;
- guint j;
- gboolean supported_5g = FALSE;
- gboolean supported_4g = FALSE;
- gboolean supported_3g = FALSE;
- gboolean supported_2g = FALSE;
- gboolean supported_mode_25 = FALSE;
- gboolean supported_mode_29 = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GArray *modes = NULL;
+ GArray *tech_values = NULL;
+ GError *inner_error = NULL;
+ gchar *full_list = NULL;
+ guint val;
+ guint i;
+ guint j;
+ gboolean supported_5g = FALSE;
+ gboolean supported_4g = FALSE;
+ gboolean supported_3g = FALSE;
+ gboolean supported_2g = FALSE;
+ gboolean supported_mode_25 = FALSE;
+ gboolean supported_mode_29 = FALSE;
r = g_regex_new ("(?:\\+WS46:)?\\s*\\((.*)\\)(?:\\r\\n)?", 0, 0, NULL);
g_assert (r != NULL);
@@ -1095,9 +1088,6 @@
g_free (full_list);
- g_clear_pointer (&match_info, g_match_info_free);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return NULL;
@@ -1190,10 +1180,10 @@
gpointer log_object,
GError **error)
{
- GRegex *r;
- GList *info_list = NULL;
- GMatchInfo *match_info;
- gboolean umts_format = TRUE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GList *info_list = NULL;
+ gboolean umts_format = TRUE;
g_return_val_if_fail (reply != NULL, NULL);
if (error)
@@ -1227,9 +1217,8 @@
/* If we didn't get any hits, try the pre-UMTS format match */
if (!g_regex_match (r, reply, 0, &match_info)) {
- g_regex_unref (r);
- g_match_info_free (match_info);
- match_info = NULL;
+ g_clear_pointer (&r, g_regex_unref);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Pre-UMTS format doesn't include the cell access technology after
* the numeric operator element.
@@ -1320,9 +1309,6 @@
g_match_info_next (match_info, NULL);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
return info_list;
}
@@ -1337,14 +1323,14 @@
gpointer log_object,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- guint mode = 0;
- guint format = 0;
- gchar *operator = NULL;
- guint actval = 0;
- MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint mode = 0;
+ guint format = 0;
+ gchar *operator = NULL;
+ guint actval = 0;
+ MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
g_assert (out_mode || out_format || out_operator || out_act);
@@ -1390,9 +1376,6 @@
}
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_free (operator);
g_propagate_error (error, inner_error);
@@ -1725,10 +1708,10 @@
gpointer log_object,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- GList *list = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ GList *list = NULL;
if (!response || !g_str_has_prefix (response, "+CGDCONT:")) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing +CGDCONT prefix");
@@ -1776,9 +1759,6 @@
g_match_info_next (match_info, &inner_error);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
mm_obj_warn (log_object, "unexpected error matching +CGDCONT response: '%s'", inner_error->message);
g_error_free (inner_error);
@@ -1813,52 +1793,46 @@
mm_3gpp_parse_cgdcont_read_response (const gchar *reply,
GError **error)
{
- GError *inner_error = NULL;
- GRegex *r;
- GMatchInfo *match_info;
- GList *list;
+ GError *inner_error = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GList *list = NULL;
if (!reply || !reply[0])
/* No APNs configured, all done */
return NULL;
- list = NULL;
r = g_regex_new ("\\+CGDCONT:\\s*(\\d+)\\s*,([^, \\)]*)\\s*,([^, \\)]*)\\s*,([^, \\)]*)",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
- 0, &inner_error);
- if (r) {
- g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, &inner_error);
+ 0, NULL);
+ g_assert (r);
- while (!inner_error &&
- g_match_info_matches (match_info)) {
- gchar *str;
- MMBearerIpFamily ip_family;
+ g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, &inner_error);
+ while (!inner_error && g_match_info_matches (match_info)) {
+ gchar *str;
+ MMBearerIpFamily ip_family;
- str = mm_get_string_unquoted_from_match_info (match_info, 2);
- ip_family = mm_3gpp_get_ip_family_from_pdp_type (str);
- if (ip_family != MM_BEARER_IP_FAMILY_NONE) {
- MM3gppPdpContext *pdp;
+ str = mm_get_string_unquoted_from_match_info (match_info, 2);
+ ip_family = mm_3gpp_get_ip_family_from_pdp_type (str);
+ if (ip_family != MM_BEARER_IP_FAMILY_NONE) {
+ MM3gppPdpContext *pdp;
- pdp = g_slice_new0 (MM3gppPdpContext);
- if (!mm_get_uint_from_match_info (match_info, 1, &pdp->cid)) {
- inner_error = g_error_new (MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Couldn't parse CID from reply: '%s'",
- reply);
- break;
- }
- pdp->pdp_type = ip_family;
- pdp->apn = mm_get_string_unquoted_from_match_info (match_info, 3);
-
- list = g_list_prepend (list, pdp);
+ pdp = g_slice_new0 (MM3gppPdpContext);
+ if (!mm_get_uint_from_match_info (match_info, 1, &pdp->cid)) {
+ inner_error = g_error_new (MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Couldn't parse CID from reply: '%s'",
+ reply);
+ break;
}
+ pdp->pdp_type = ip_family;
+ pdp->apn = mm_get_string_unquoted_from_match_info (match_info, 3);
- g_free (str);
- g_match_info_next (match_info, &inner_error);
+ list = g_list_prepend (list, pdp);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
+ g_free (str);
+ g_match_info_next (match_info, &inner_error);
}
if (inner_error) {
@@ -1868,9 +1842,7 @@
return NULL;
}
- list = g_list_sort (list, (GCompareFunc)mm_3gpp_pdp_context_cmp);
-
- return list;
+ return g_list_sort (list, (GCompareFunc)mm_3gpp_pdp_context_cmp);
}
/*************************************************************************/
@@ -1898,16 +1870,15 @@
mm_3gpp_parse_cgact_read_response (const gchar *reply,
GError **error)
{
- GError *inner_error = NULL;
- GRegex *r;
- GMatchInfo *match_info;
- GList *list;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ GList *list = NULL;
if (!reply || !reply[0])
/* Nothing configured, all done */
return NULL;
- list = NULL;
r = g_regex_new ("\\+CGACT:\\s*(\\d+),(\\d+)",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, &inner_error);
g_assert (r);
@@ -1941,9 +1912,6 @@
g_match_info_next (match_info, &inner_error);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
mm_3gpp_pdp_context_active_list_free (list);
g_propagate_error (error, inner_error);
@@ -2142,10 +2110,11 @@
gboolean *sms_text_supported,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- gchar *s;
- guint32 min = -1, max = -1;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gchar *s;
+ guint32 min = -1;
+ guint32 max = -1;
/* Strip whitespace and response tag */
if (g_str_has_prefix (reply, CMGF_TAG))
@@ -2163,8 +2132,6 @@
MM_CORE_ERROR_FAILED,
"Failed to parse CMGF query result '%s'",
reply);
- g_match_info_free (match_info);
- g_regex_unref (r);
return FALSE;
}
@@ -2184,8 +2151,6 @@
/* CMGF=1 for Text mode */
*sms_text_supported = (max >= 1);
- g_match_info_free (match_info);
- g_regex_unref (r);
return TRUE;
}
@@ -2196,12 +2161,12 @@
guint index,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- gint count;
- gint status;
- gchar *pdu;
- MM3gppPduInfo *info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gint count;
+ gint status;
+ gchar *pdu;
+ MM3gppPduInfo *info = NULL;
/* +CMGR: <stat>,<alpha>,<length>(whitespace)<pdu> */
/* The <alpha> and <length> fields are matched, but not currently used */
@@ -2214,7 +2179,7 @@
MM_CORE_ERROR_FAILED,
"Failed to parse CMGR read result: response didn't match '%s'",
reply);
- goto done;
+ return NULL;
}
/* g_match_info_get_match_count includes match #0 */
@@ -2225,7 +2190,7 @@
"Failed to match CMGR fields (matched %d) '%s'",
count,
reply);
- goto done;
+ return NULL;
}
if (!mm_get_int_from_match_info (match_info, 1, &status)) {
@@ -2234,7 +2199,7 @@
MM_CORE_ERROR_FAILED,
"Failed to extract CMGR status field '%s'",
reply);
- goto done;
+ return NULL;
}
@@ -2245,18 +2210,13 @@
MM_CORE_ERROR_FAILED,
"Failed to extract CMGR pdu field '%s'",
reply);
- goto done;
+ return NULL;
}
info = g_new0 (MM3gppPduInfo, 1);
info->index = index;
info->status = status;
info->pdu = pdu;
-
-done:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
return info;
}
@@ -2270,8 +2230,8 @@
gchar **hex,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
g_assert (sw1 != NULL);
g_assert (sw2 != NULL);
@@ -2292,11 +2252,9 @@
if (g_regex_match (r, reply, 0, &match_info) &&
mm_get_uint_from_match_info (match_info, 1, sw1) &&
- mm_get_uint_from_match_info (match_info, 2, sw2))
+ mm_get_uint_from_match_info (match_info, 2, sw2)) {
*hex = mm_get_string_unquoted_from_match_info (match_info, 3);
-
- g_match_info_free (match_info);
- g_regex_unref (r);
+ }
if (*hex == NULL) {
g_set_error (error,
@@ -2372,19 +2330,19 @@
gchar **out_dns_secondary_address,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- guint cid = 0;
- guint bearer_id = 0;
- gchar *apn = NULL;
- gchar *local_address_and_subnet = NULL;
- gchar *local_address = NULL;
- gchar *subnet = NULL;
- gchar *gateway_address = NULL;
- gchar *dns_primary_address = NULL;
- gchar *dns_secondary_address = NULL;
- guint field_format_extra_index = 0;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint cid = 0;
+ guint bearer_id = 0;
+ g_autofree gchar *apn = NULL;
+ g_autofree gchar *local_address_and_subnet = NULL;
+ g_autofree gchar *local_address = NULL;
+ g_autofree gchar *subnet = NULL;
+ g_autofree gchar *gateway_address = NULL;
+ g_autofree gchar *dns_primary_address = NULL;
+ g_autofree gchar *dns_secondary_address = NULL;
+ guint field_format_extra_index = 0;
/* Response may be e.g.:
* +CGCONTRDP: 4,5,"ibox.tim.it.mnc001.mcc222.gprs","2.197.17.49.255.255.255.255","2.197.17.49","10.207.43.46","10.206.56.132","0.0.0.0","0.0.0.0",0
@@ -2413,28 +2371,28 @@
g_assert (r != NULL);
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
- if (inner_error)
- goto out;
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return FALSE;
+ }
if (!g_match_info_matches (match_info)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, "Couldn't match +CGCONTRDP response");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, "Couldn't match +CGCONTRDP response");
+ return FALSE;
}
if (out_cid && !mm_get_uint_from_match_info (match_info, 1, &cid)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing cid");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing cid");
+ return FALSE;
}
if (out_bearer_id && !mm_get_uint_from_match_info (match_info, 2, &bearer_id)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing bearer id");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing bearer id");
+ return FALSE;
}
/* Remaining strings are optional or empty allowed */
-
- if (out_apn)
- apn = mm_get_string_unquoted_from_match_info (match_info, 3);
+ apn = mm_get_string_unquoted_from_match_info (match_info, 3);
/*
* The +CGCONTRDP=[cid] response format before version TS 27.007 v9.4.0 had
@@ -2442,67 +2400,39 @@
*/
local_address_and_subnet = mm_get_string_unquoted_from_match_info (match_info, 4);
if (local_address_and_subnet && !split_local_address_and_subnet (local_address_and_subnet, &local_address, &subnet)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing local address and subnet");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing local address and subnet");
+ return FALSE;
}
+
/* If we don't have a subnet in field 4, we're using the old format with subnet in an extra field */
if (!subnet) {
- if (out_subnet)
- subnet = mm_get_string_unquoted_from_match_info (match_info, 5);
+ subnet = mm_get_string_unquoted_from_match_info (match_info, 5);
field_format_extra_index = 1;
}
- if (out_gateway_address)
- gateway_address = mm_get_string_unquoted_from_match_info (match_info, 5 + field_format_extra_index);
-
- if (out_dns_primary_address)
- dns_primary_address = mm_get_string_unquoted_from_match_info (match_info, 6 + field_format_extra_index);
-
- if (out_dns_secondary_address)
- dns_secondary_address = mm_get_string_unquoted_from_match_info (match_info, 7 + field_format_extra_index);
-
-out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
- g_free (local_address_and_subnet);
-
- if (inner_error) {
- g_free (apn);
- g_free (local_address);
- g_free (subnet);
- g_free (gateway_address);
- g_free (dns_primary_address);
- g_free (dns_secondary_address);
- g_propagate_error (error, inner_error);
- return FALSE;
- }
+ gateway_address = mm_get_string_unquoted_from_match_info (match_info, 5 + field_format_extra_index);
+ dns_primary_address = mm_get_string_unquoted_from_match_info (match_info, 6 + field_format_extra_index);
+ dns_secondary_address = mm_get_string_unquoted_from_match_info (match_info, 7 + field_format_extra_index);
if (out_cid)
*out_cid = cid;
if (out_bearer_id)
*out_bearer_id = bearer_id;
if (out_apn)
- *out_apn = apn;
-
+ *out_apn = g_steal_pointer (&apn);
/* Local address and subnet may always be retrieved, even if not requested
* by the caller, as we need them to know which +CGCONTRDP=[cid] response is
* being parsed. So make sure we free them if not needed. */
if (out_local_address)
- *out_local_address = local_address;
- else
- g_free (local_address);
+ *out_local_address = g_steal_pointer (&local_address);
if (out_subnet)
- *out_subnet = subnet;
- else
- g_free (subnet);
-
+ *out_subnet = g_steal_pointer (&subnet);
if (out_gateway_address)
- *out_gateway_address = gateway_address;
+ *out_gateway_address = g_steal_pointer (&gateway_address);
if (out_dns_primary_address)
- *out_dns_primary_address = dns_primary_address;
+ *out_dns_primary_address = g_steal_pointer (&dns_primary_address);
if (out_dns_secondary_address)
- *out_dns_secondary_address = dns_secondary_address;
+ *out_dns_secondary_address = g_steal_pointer (&dns_secondary_address);
return TRUE;
}
@@ -2513,10 +2443,10 @@
guint *out_state,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- guint state = G_MAXUINT;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint state = G_MAXUINT;
g_assert (out_state != NULL);
@@ -2546,9 +2476,6 @@
*out_state = state;
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -2570,16 +2497,16 @@
guint *out_rsrp,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- guint rxlev = 99;
- guint ber = 99;
- guint rscp = 255;
- guint ecn0 = 255;
- guint rsrq = 255;
- guint rsrp = 255;
- gboolean success = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint rxlev = 99;
+ guint ber = 99;
+ guint rscp = 255;
+ guint ecn0 = 255;
+ guint rsrq = 255;
+ guint rsrp = 255;
+ gboolean success = FALSE;
g_assert (out_rxlev);
g_assert (out_ber);
@@ -2624,9 +2551,6 @@
}
out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -2883,10 +2807,10 @@
gboolean *status,
GError **error)
{
- GRegex *r;
- GError *inner_error = NULL;
- GMatchInfo *match_info = NULL;
- gint class_1_status = -1;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ gint class_1_status = -1;
/*
* AT+CCWA=<n>[,<mode>]
@@ -2928,9 +2852,6 @@
}
out:
- g_clear_pointer (&match_info, g_match_info_free);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -3035,8 +2956,8 @@
g_assert (r);
for (i = 0; i < N_EXPECTED_GROUPS; i++) {
- GMatchInfo *match_info = NULL;
- GArray *array;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GArray *array;
/* We always return a valid array, even if it may be empty */
array = g_array_new (FALSE, FALSE, sizeof (MMSmsStorage));
@@ -3058,7 +2979,6 @@
g_match_info_next (match_info, NULL);
}
}
- g_match_info_free (match_info);
if (!tmp1)
tmp1 = array;
@@ -3100,43 +3020,31 @@
MMSmsStorage *memw,
GError **error)
{
- GRegex *r = NULL;
- gboolean ret = FALSE;
- GMatchInfo *match_info = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
r = g_regex_new (CPMS_QUERY_REGEX, G_REGEX_RAW, 0, NULL);
-
g_assert (r);
if (!g_regex_match (r, reply, 0, &match_info)) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Could not parse CPMS query response '%s'", reply);
- goto end;
+ return FALSE;
}
if (!g_match_info_matches (match_info)) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Could not find matches in CPMS query reply '%s'", reply);
- goto end;
+ return FALSE;
}
- if (!mm_3gpp_get_cpms_storage_match (match_info, "memr", memr, error)) {
- goto end;
- }
+ if (!mm_3gpp_get_cpms_storage_match (match_info, "memr", memr, error))
+ return FALSE;
- if (!mm_3gpp_get_cpms_storage_match (match_info, "memw", memw, error)) {
- goto end;
- }
+ if (!mm_3gpp_get_cpms_storage_match (match_info, "memw", memw, error))
+ return FALSE;
- ret = TRUE;
-
-end:
- if (r != NULL)
- g_regex_unref (r);
-
- g_match_info_free (match_info);
-
- return ret;
+ return TRUE;
}
gboolean
@@ -3168,11 +3076,12 @@
mm_3gpp_parse_cscs_test_response (const gchar *reply,
MMModemCharset *out_charsets)
{
- MMModemCharset charsets = MM_MODEM_CHARSET_UNKNOWN;
- GRegex *r;
- GMatchInfo *match_info;
- gchar *p, *str;
- gboolean success = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ MMModemCharset charsets = MM_MODEM_CHARSET_UNKNOWN;
+ gchar *p;
+ gchar *str;
+ gboolean success = FALSE;
g_return_val_if_fail (reply != NULL, FALSE);
g_return_val_if_fail (out_charsets != NULL, FALSE);
@@ -3194,8 +3103,7 @@
/* Now parse each charset */
r = g_regex_new ("\\s*([^,\\)]+)\\s*", 0, 0, NULL);
- if (!r)
- return FALSE;
+ g_assert (r);
if (g_regex_match (r, p, 0, &match_info)) {
while (g_match_info_matches (match_info)) {
@@ -3207,8 +3115,6 @@
success = TRUE;
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
if (success)
*out_charsets = charsets;
@@ -3222,8 +3128,8 @@
mm_3gpp_parse_clck_test_response (const gchar *reply,
MMModem3gppFacility *out_facilities)
{
- GRegex *r;
- GMatchInfo *match_info;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
g_return_val_if_fail (reply != NULL, FALSE);
g_return_val_if_fail (out_facilities != NULL, FALSE);
@@ -3252,8 +3158,6 @@
g_match_info_next (match_info, NULL);
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
return (*out_facilities != MM_MODEM_3GPP_FACILITY_NONE);
}
@@ -3264,9 +3168,8 @@
mm_3gpp_parse_clck_write_response (const gchar *reply,
gboolean *enabled)
{
- GRegex *r;
- GMatchInfo *match_info;
- gboolean success = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
g_return_val_if_fail (reply != NULL, FALSE);
g_return_val_if_fail (enabled != NULL, FALSE);
@@ -3277,7 +3180,7 @@
g_assert (r != NULL);
if (g_regex_match (r, reply, 0, &match_info)) {
- gchar *str;
+ g_autofree gchar *str = NULL;
str = g_match_info_fetch (match_info, 1);
if (str) {
@@ -3289,15 +3192,11 @@
*enabled = TRUE;
else
g_assert_not_reached ();
-
- g_free (str);
- success = TRUE;
+ return TRUE;
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
- return success;
+ return FALSE;
}
/*************************************************************************/
@@ -3530,10 +3429,10 @@
mm_3gpp_parse_cind_test_response (const gchar *reply,
GError **error)
{
- GHashTable *hash;
- GRegex *r;
- GMatchInfo *match_info;
- guint idx = 1;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GHashTable *hash;
+ guint idx = 1;
g_return_val_if_fail (reply != NULL, NULL);
@@ -3544,12 +3443,7 @@
reply++;
r = g_regex_new ("\\(([^,]*),\\((\\d+)[-,](\\d+).*\\)", G_REGEX_UNGREEDY, 0, NULL);
- if (!r) {
- g_set_error_literal (error,
- MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
- "Could not parse scan results.");
- return NULL;
- }
+ g_assert (r);
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) cind_response_free);
@@ -3578,8 +3472,6 @@
g_match_info_next (match_info, NULL);
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
return hash;
}
@@ -3590,11 +3482,11 @@
mm_3gpp_parse_cind_read_response (const gchar *reply,
GError **error)
{
- GByteArray *array = NULL;
- GRegex *r = NULL;
- GMatchInfo *match_info;
- GError *inner_error = NULL;
- guint8 t;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GByteArray *array = NULL;
+ GError *inner_error = NULL;
+ guint8 t;
g_return_val_if_fail (reply != NULL, NULL);
@@ -3614,7 +3506,7 @@
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Could not parse the +CIND response '%s': didn't match",
reply);
- goto done;
+ return NULL;
}
array = g_byte_array_sized_new (g_match_info_get_match_count (match_info));
@@ -3625,10 +3517,9 @@
t = 0;
g_byte_array_append (array, &t, 1);
- while (!inner_error &&
- g_match_info_matches (match_info)) {
- gchar *str;
- guint val = 0;
+ while (!inner_error && g_match_info_matches (match_info)) {
+ g_autofree gchar *str = NULL;
+ guint val = 0;
str = g_match_info_fetch (match_info, 1);
if (mm_get_uint_from_str (str, &val) && val < 255) {
@@ -3639,21 +3530,14 @@
"Could not parse the +CIND response: invalid index '%s'",
str);
}
-
- g_free (str);
g_match_info_next (match_info, NULL);
}
if (inner_error) {
g_propagate_error (error, inner_error);
- g_byte_array_unref (array);
- array = NULL;
+ g_clear_pointer (&array, g_byte_array_unref);
}
-done:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
return array;
}
@@ -3755,12 +3639,12 @@
guint *out_cid,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *inner_error = NULL;
- gchar *pdp_type = NULL;
- gchar *pdp_addr = NULL;
- guint cid = 0;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ g_autofree gchar *pdp_type = NULL;
+ g_autofree gchar *pdp_addr = NULL;
+ guint cid = 0;
g_assert (type == MM_3GPP_CGEV_REJECT ||
type == MM_3GPP_CGEV_NW_REACT ||
@@ -3772,51 +3656,42 @@
"NW REACT|"
"NW DEACT|ME DEACT"
")\\s*([^,]*),\\s*([^,]*)(?:,\\s*([0-9]+))?", 0, 0, NULL);
+ g_assert (r);
str = mm_strip_tag (str, "+CGEV:");
g_regex_match_full (r, str, strlen (str), 0, 0, &match_info, &inner_error);
- if (inner_error)
- goto out;
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return FALSE;
+ }
if (!g_match_info_matches (match_info)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't match response");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't match response");
+ return FALSE;
}
if (out_pdp_type && !(pdp_type = mm_get_string_unquoted_from_match_info (match_info, 1))) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP type");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP type");
+ return FALSE;
}
if (out_pdp_addr && !(pdp_addr = mm_get_string_unquoted_from_match_info (match_info, 2))) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP addr");
- goto out;
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP addr");
+ return FALSE;
}
/* CID is optional */
if (out_cid &&
(g_match_info_get_match_count (match_info) >= 4) &&
!mm_get_uint_from_match_info (match_info, 3, &cid)) {
- inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing CID");
- goto out;
- }
-
-out:
- if (match_info)
- g_match_info_free (match_info);
- g_regex_unref (r);
-
- if (inner_error) {
- g_free (pdp_type);
- g_free (pdp_addr);
- g_propagate_error (error, inner_error);
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing CID");
return FALSE;
}
if (out_pdp_type)
- *out_pdp_type = pdp_type;
+ *out_pdp_type = g_steal_pointer (&pdp_type);
if (out_pdp_addr)
- *out_pdp_addr = pdp_addr;
+ *out_pdp_addr = g_steal_pointer (&pdp_addr);
if (out_cid)
*out_cid = cid;
return TRUE;
@@ -3841,10 +3716,10 @@
guint *out_cid,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *inner_error = NULL;
- guint cid = 0;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint cid = 0;
g_assert ((type == MM_3GPP_CGEV_NW_ACT_PRIMARY) ||
(type == MM_3GPP_CGEV_ME_ACT_PRIMARY) ||
@@ -3872,10 +3747,6 @@
}
out:
- if (match_info)
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -3900,12 +3771,12 @@
guint *out_event_type,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *inner_error = NULL;
- guint p_cid = 0;
- guint cid = 0;
- guint event_type = 0;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ guint p_cid = 0;
+ guint cid = 0;
+ guint event_type = 0;
g_assert (type == MM_3GPP_CGEV_NW_ACT_SECONDARY ||
type == MM_3GPP_CGEV_ME_ACT_SECONDARY ||
@@ -3943,10 +3814,6 @@
}
out:
- if (match_info)
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -3980,10 +3847,10 @@
mm_3gpp_parse_pdu_cmgl_response (const gchar *str,
GError **error)
{
- GError *inner_error = NULL;
- GList *list = NULL;
- GMatchInfo *match_info;
- GRegex *r;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *inner_error = NULL;
+ GList *list = NULL;
/*
* +CMGL: <index>, <status>, [<alpha>], <length>
@@ -4016,9 +3883,6 @@
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
if (inner_error) {
g_propagate_error (error, inner_error);
mm_3gpp_pdu_info_list_free (list);
@@ -4754,10 +4618,10 @@
MMModemCdmaRmProtocol *max,
GError **error)
{
- gboolean result = FALSE;
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gboolean result = FALSE;
+ GError *match_error = NULL;
/* Expected reply format is:
* ---> AT+CRM=?
@@ -4810,9 +4674,6 @@
reply);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
return result;
}
@@ -5039,12 +4900,16 @@
MMNetworkTimezone **tzp,
GError **error)
{
- GRegex *r;
- GMatchInfo *match_info = NULL;
- GError *match_error = NULL;
- guint year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
- gint tz = 0;
- gboolean ret = FALSE;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ GError *match_error = NULL;
+ guint year = 0;
+ guint month = 0;
+ guint day = 0;
+ guint hour = 0;
+ guint minute = 0;
+ guint second = 0;
+ gint tz = 0;
g_assert (iso8601p || tzp); /* at least one */
@@ -5065,7 +4930,7 @@
MM_CORE_ERROR_FAILED,
"Couldn't match +CCLK reply: %s", response);
}
- goto out;
+ return FALSE;
}
/* Remember that g_match_info_get_match_count() includes match #0 */
@@ -5082,7 +4947,7 @@
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Failed to parse +CCLK reply: %s", response);
- goto out;
+ return FALSE;
}
/* Read optional time zone offset; if not given assume UTC (tz = 0).
@@ -5094,7 +4959,7 @@
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Failed to parse timezone in +CCLK reply: %s", response);
- goto out;
+ return FALSE;
}
/* Adjust year to support YYYY format, as per +CSDF in 3GPP TS 27.007. Also,
@@ -5112,22 +4977,16 @@
mm_network_timezone_set_offset (*tzp, tz * 15);
}
- ret = TRUE;
-
if (iso8601p) {
/* Return ISO-8601 format date/time string */
*iso8601p = mm_new_iso8601_time (year, month, day, hour,
minute, second,
TRUE, (tz * 15),
error);
- ret = (*iso8601p != NULL);
+ return (*iso8601p != NULL);
}
- out:
- g_match_info_free (match_info);
- g_regex_unref (r);
-
- return ret;
+ return TRUE;
}
/*****************************************************************************/
@@ -5139,12 +4998,12 @@
mm_parse_csim_response (const gchar *response,
GError **error)
{
- GMatchInfo *match_info = NULL;
- GRegex *r = NULL;
- gchar *str_code = NULL;
- gint retries = -1;
- guint hex_code;
- GError *inner_error = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *str_code = NULL;
+ gint retries = -1;
+ guint hex_code;
+ GError *inner_error = NULL;
r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*\".*([0-9a-fA-F]{4})\"", G_REGEX_RAW, 0, NULL);
g_regex_match (r, response, 0, &match_info);
@@ -5202,10 +5061,6 @@
retries = (gint)(hex_code - MM_MIN_SIM_RETRY_HEX);
out:
- g_regex_unref (r);
- g_match_info_free (match_info);
- g_free (str_code);
-
if (inner_error) {
g_propagate_error (error, inner_error);
return -1;
diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c
index 44c0fc9..88d01cf 100644
--- a/src/mm-port-serial-at.c
+++ b/src/mm-port-serial-at.c
@@ -269,8 +269,8 @@
for (iter = self->priv->unsolicited_msg_handlers; iter; iter = iter->next) {
MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data;
- GMatchInfo *match_info;
- gboolean matches;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gboolean matches;
if (!handler->enable)
continue;
@@ -286,12 +286,10 @@
}
}
- g_match_info_free (match_info);
-
if (matches) {
/* Remove matches */
- char *str;
- int result_len = response->len;
+ g_autofree gchar *str = NULL;
+ gint result_len = response->len;
str = g_regex_replace_eval (handler->regex,
(const char *) response->data,
@@ -301,7 +299,6 @@
g_byte_array_remove_range (response, 0, response->len);
g_byte_array_append (response, (const guint8 *) str, result_len);
- g_free (str);
}
}
}
diff --git a/src/mm-port-serial-gps.c b/src/mm-port-serial-gps.c
index ea40499..fe8ec6a 100644
--- a/src/mm-port-serial-gps.c
+++ b/src/mm-port-serial-gps.c
@@ -74,12 +74,12 @@
GByteArray **parsed_response,
GError **error)
{
- MMPortSerialGps *self = MM_PORT_SERIAL_GPS (port);
- gboolean matches;
- GMatchInfo *match_info;
- gchar *str;
- gint result_len;
- guint i;
+ MMPortSerialGps *self = MM_PORT_SERIAL_GPS (port);
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gboolean matches;
+ gchar *str;
+ gint result_len;
+ guint i;
for (i = 0; i < response->len; i++) {
/* If there is any content before the first $,
@@ -110,8 +110,6 @@
}
}
- g_match_info_free (match_info);
-
if (!matches)
return MM_PORT_SERIAL_RESPONSE_NONE;
diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c
index 0b60d60..a577fae 100644
--- a/src/mm-serial-parsers.c
+++ b/src/mm-serial-parsers.c
@@ -115,7 +115,7 @@
parser->regex_cms_error = g_regex_new ("\\r\\n\\+CMS ERROR:\\s*(\\d+)\\r\\n", flags, 0, NULL);
parser->regex_cme_error_str = g_regex_new ("\\r\\n\\+CME ERROR:\\s*([^\\n\\r]+)\\r\\n", flags, 0, NULL);
parser->regex_cms_error_str = g_regex_new ("\\r\\n\\+CMS ERROR:\\s*([^\\n\\r]+)\\r\\n", flags, 0, NULL);
- parser->regex_ezx_error = g_regex_new ("\\r\\n\\MODEM ERROR:\\s*(\\d+)\\r\\n", flags, 0, NULL);
+ parser->regex_ezx_error = g_regex_new ("\\r\\nMODEM ERROR:\\s*(\\d+)\\r\\n", flags, 0, NULL);
parser->regex_unknown_error = g_regex_new ("\\r\\n(ERROR)|(COMMAND NOT SUPPORT)\\r\\n", flags, 0, NULL);
parser->regex_connect_failed = g_regex_new ("\\r\\n(NO CARRIER)|(BUSY)|(NO ANSWER)|(NO DIALTONE)\\r\\n", flags, 0, NULL);
/* Samsung Z810 may reply "NA" to report a not-available error */
@@ -167,7 +167,7 @@
GError **error)
{
MMSerialParserV1 *parser = (MMSerialParserV1 *) data;
- GMatchInfo *match_info;
+ GMatchInfo *match_info = NULL;
GError *local_error = NULL;
gboolean found = FALSE;
char *str = NULL;
@@ -242,7 +242,7 @@
local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
}
/* Numeric CME errors */
@@ -255,7 +255,7 @@
local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Numeric CMS errors */
found = g_regex_match_full (parser->regex_cms_error,
@@ -267,7 +267,7 @@
local_error = mm_message_error_for_code (atoi (str), log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* String CME errors */
found = g_regex_match_full (parser->regex_cme_error_str,
@@ -279,7 +279,7 @@
local_error = mm_mobile_equipment_error_for_string (str, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* String CMS errors */
found = g_regex_match_full (parser->regex_cms_error_str,
@@ -291,7 +291,7 @@
local_error = mm_message_error_for_string (str, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Motorola EZX errors */
found = g_regex_match_full (parser->regex_ezx_error,
@@ -303,7 +303,7 @@
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Last resort; unknown error */
found = g_regex_match_full (parser->regex_unknown_error,
@@ -313,7 +313,7 @@
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Connection failures */
found = g_regex_match_full (parser->regex_connect_failed,
@@ -341,7 +341,7 @@
local_error = mm_connection_error_for_code (code, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* NA error */
found = g_regex_match_full (parser->regex_na,
@@ -357,7 +357,8 @@
done:
g_free (str);
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
+
if (found)
response_clean (response);
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index 489cbd4..01f4c91 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -1129,15 +1129,19 @@
RegTestData *data,
const CregResult *result)
{
- guint i;
- GMatchInfo *info = NULL;
- MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN;
- MMModemAccessTechnology access_tech = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
- gulong lac = 0, ci = 0;
- GError *error = NULL;
- gboolean success, cgreg = FALSE, cereg = FALSE, c5greg = FALSE;
- guint regex_num = 0;
- GPtrArray *array;
+ g_autoptr(GMatchInfo) info = NULL;
+ guint i;
+ MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN;
+ MMModemAccessTechnology access_tech = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+ gulong lac = 0;
+ gulong ci = 0;
+ GError *error = NULL;
+ gboolean success;
+ gboolean cgreg = FALSE;
+ gboolean cereg = FALSE;
+ gboolean c5greg = FALSE;
+ guint regex_num = 0;
+ GPtrArray *array;
g_assert (reply);
g_assert (test);
@@ -1158,8 +1162,7 @@
regex_num = i;
break;
}
- g_match_info_free (info);
- info = NULL;
+ g_clear_pointer (&info, g_match_info_free);
}
g_debug (" regex_num (%u) == result->regex_num (%u)",
@@ -1171,7 +1174,6 @@
success = mm_3gpp_parse_creg_response (info, NULL, &state, &lac, &ci, &access_tech, &cgreg, &cereg, &c5greg, &error);
- g_match_info_free (info);
g_assert (success);
g_assert_no_error (error);
g_assert_cmpuint (state, ==, result->state);
@@ -3351,10 +3353,10 @@
guint expected_pdu_len,
const gchar *expected_pdu)
{
- GMatchInfo *match_info;
- GRegex *regex;
- gchar *pdu_len_str;
- gchar *pdu;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autoptr(GRegex) regex = NULL;
+ g_autofree gchar *pdu_len_str = NULL;
+ g_autofree gchar *pdu = NULL;
regex = mm_3gpp_cds_regex_get ();
g_regex_match (regex, str, 0, &match_info);
@@ -3368,12 +3370,6 @@
g_assert (pdu != NULL);
g_assert_cmpstr (pdu, ==, expected_pdu);
-
- g_free (pdu);
- g_free (pdu_len_str);
-
- g_match_info_free (match_info);
- g_regex_unref (regex);
}
static void
@@ -4143,15 +4139,15 @@
static void
test_clip_indication (void)
{
- GRegex *r;
- guint i;
+ g_autoptr(GRegex) r = NULL;
+ guint i;
r = mm_voice_clip_regex_get ();
for (i = 0; i < G_N_ELEMENTS (clip_urc_tests); i++) {
- GMatchInfo *match_info = NULL;
- gchar *number;
- guint type;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *number = NULL;
+ guint type;
g_assert (g_regex_match (r, clip_urc_tests[i].str, 0, &match_info));
g_assert (g_match_info_matches (match_info));
@@ -4161,12 +4157,7 @@
g_assert (mm_get_uint_from_match_info (match_info, 2, &type));
g_assert_cmpuint (type, ==, clip_urc_tests[i].type);
-
- g_free (number);
- g_match_info_free (match_info);
}
-
- g_regex_unref (r);
}
/*****************************************************************************/
@@ -4188,16 +4179,16 @@
static void
test_ccwa_indication (void)
{
- GRegex *r;
- guint i;
+ g_autoptr(GRegex) r = NULL;
+ guint i;
r = mm_voice_ccwa_regex_get ();
for (i = 0; i < G_N_ELEMENTS (ccwa_urc_tests); i++) {
- GMatchInfo *match_info = NULL;
- gchar *number;
- guint type;
- guint class;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_autofree gchar *number = NULL;
+ guint type;
+ guint class;
g_assert (g_regex_match (r, ccwa_urc_tests[i].str, 0, &match_info));
g_assert (g_match_info_matches (match_info));
@@ -4210,12 +4201,7 @@
g_assert (mm_get_uint_from_match_info (match_info, 3, &class));
g_assert_cmpuint (class, ==, ccwa_urc_tests[i].class);
-
- g_free (number);
- g_match_info_free (match_info);
}
-
- g_regex_unref (r);
}
/*****************************************************************************/
@@ -4250,8 +4236,8 @@
} TestCcwa;
static TestCcwa test_ccwa[] = {
- { "+CCWA: 0,255", FALSE, FALSE }, /* all disabled */
- { "+CCWA: 1,255", TRUE, FALSE }, /* all enabled */
+ { "+CCWA: 0,255\r\n", FALSE, FALSE }, /* all disabled */
+ { "+CCWA: 1,255\r\n", TRUE, FALSE }, /* all enabled */
{ "+CCWA: 0,1\r\n"
"+CCWA: 0,4\r\n", FALSE, FALSE }, /* voice and fax disabled */
{ "+CCWA: 1,1\r\n"
@@ -4326,7 +4312,7 @@
static void
test_clcc_response_empty (void)
{
- const gchar *response = "";
+ const gchar *response = "\r\n";
common_test_clcc_response (response, NULL, 0);
}
@@ -4339,7 +4325,7 @@
};
const gchar *response =
- "+CLCC: 1,1,0,0,0,\"123456789\",161";
+ "+CLCC: 1,1,0,0,0,\"123456789\",161\r\n";
common_test_clcc_response (response, expected_call_info_list, G_N_ELEMENTS (expected_call_info_list));
}
@@ -4353,7 +4339,7 @@
/* NOTE: priority field is EMPTY */
const gchar *response =
- "+CLCC: 1,1,4,0,0,\"123456789\",129,\"\",,0";
+ "+CLCC: 1,1,4,0,0,\"123456789\",129,\"\",,0\r\n";
common_test_clcc_response (response, expected_call_info_list, G_N_ELEMENTS (expected_call_info_list));
}