core: port GRegex/GMatchInfo to use autoptr()

The behavior of GRegex changed in 2.73.2 once it was ported from pcre1
to pcre2. In some cases it was made more strict, which is fine, in
other cases it exposed some change in how it behaves on certain
matches that is not extremely clear whether it's ok or not.

See https://gitlab.gnome.org/GNOME/glib/-/issues/2729
See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/601
See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/621

Either way, one thing that was assumed was that initializing all
GRegex/GMatchInfo variables to NULL and making sure they're NULL
before they're initialized by glib (especially the GMatchInfo) was a
good and safer approach.

So, whenever possible, g_autoptr() is used to cleanup the allocated
GMatchInfo/GRegex variables, and otherwise, g_clear_pointer() is used
to ensure that no free/unref is attempted unless the given variable is
not NULL, and also so that the variable is reseted to NULL after being
disposed.
This commit is contained in:
Aleksander Morgado
2022-09-05 17:33:11 +00:00
parent b2a186b5c8
commit 74fc5baca2
33 changed files with 850 additions and 1268 deletions
+4 -6
View File
@@ -54,9 +54,7 @@ static gboolean
check_append_or_replace (MMLocationGpsNmea *self, check_append_or_replace (MMLocationGpsNmea *self,
const gchar *trace) const gchar *trace)
{ {
/* By default, replace */ g_autoptr(GMatchInfo) match_info = NULL;
gboolean append_or_replace = FALSE;
GMatchInfo *match_info = NULL;
if (G_UNLIKELY (!self->priv->sequence_regex)) if (G_UNLIKELY (!self->priv->sequence_regex))
self->priv->sequence_regex = g_regex_new ("\\$..(?:ALM|GSV|RTE|SFI),(\\d),(\\d).*", self->priv->sequence_regex = g_regex_new ("\\$..(?:ALM|GSV|RTE|SFI),(\\d),(\\d).*",
@@ -69,11 +67,11 @@ check_append_or_replace (MMLocationGpsNmea *self,
/* If we don't have the first element of a sequence, append */ /* 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) 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 static gboolean
+1 -3
View File
@@ -190,7 +190,7 @@ gboolean
mm_location_gps_raw_add_trace (MMLocationGpsRaw *self, mm_location_gps_raw_add_trace (MMLocationGpsRaw *self,
const gchar *trace) const gchar *trace)
{ {
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
/* Current implementation works only with $GPGGA and $GNGGA traces */ /* Current implementation works only with $GPGGA and $GNGGA traces */
do { do {
@@ -268,8 +268,6 @@ mm_location_gps_raw_add_trace (MMLocationGpsRaw *self,
mm_get_double_from_match_info (match_info, 9, &self->priv->altitude); mm_get_double_from_match_info (match_info, 9, &self->priv->altitude);
} }
g_match_info_free (match_info);
return TRUE; return TRUE;
} }
+35 -47
View File
@@ -72,10 +72,10 @@ hstate_ready (MMIfaceModemCdma *self,
GTask *task) GTask *task)
{ {
DetailedRegistrationStateResults *results; DetailedRegistrationStateResults *results;
GError *error = NULL; GError *error = NULL;
const gchar *response; const gchar *response;
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
results = g_task_get_task_data (task); results = g_task_get_task_data (task);
@@ -129,9 +129,6 @@ hstate_ready (MMIfaceModemCdma *self,
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
g_task_return_pointer (task, g_memdup (results, sizeof (*results)), g_free); g_task_return_pointer (task, g_memdup (results, sizeof (*results)), g_free);
g_object_unref (task); g_object_unref (task);
} }
@@ -142,10 +139,10 @@ state_ready (MMIfaceModemCdma *self,
GTask *task) GTask *task)
{ {
DetailedRegistrationStateResults *results; DetailedRegistrationStateResults *results;
GError *error = NULL; GError *error = NULL;
const gchar *response; const gchar *response;
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error) { if (error) {
@@ -194,9 +191,6 @@ state_ready (MMIfaceModemCdma *self,
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
/* Try for EVDO state too */ /* Try for EVDO state too */
mm_base_modem_at_command (MM_BASE_MODEM (self), mm_base_modem_at_command (MM_BASE_MODEM (self),
"*HSTATE?", "*HSTATE?",
@@ -261,9 +255,14 @@ reset (MMIfaceModem *self,
static void static void
setup_ports (MMBroadbandModem *self) setup_ports (MMBroadbandModem *self)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GRegex *regex; g_autoptr(GRegex) active_regex = NULL;
guint i; 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 */ /* Call parent's setup ports first always */
MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_anydata_parent_class)->setup_ports (self); MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_anydata_parent_class)->setup_ports (self);
@@ -271,48 +270,37 @@ setup_ports (MMBroadbandModem *self)
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_peek_port_secondary (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 */ /* Now reset the unsolicited messages */
for (i = 0; i < G_N_ELEMENTS (ports); i++) { for (i = 0; i < G_N_ELEMENTS (ports); i++) {
if (!ports[i]) if (!ports[i])
continue; continue;
/* Data state notifications */ /* Data state notifications */
mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), active_regex, NULL, NULL, NULL);
/* Data call has connected */ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), inactive_regex, NULL, NULL, NULL);
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]), dormant_regex, NULL, NULL, 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);
/* Abnormal state notifications /* Abnormal state notifications
* *
* FIXME: set 1X/EVDO registration state to UNKNOWN when these * FIXME: set 1X/EVDO registration state to UNKNOWN when these
* notifications are received? * notifications are received?
*/ */
mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), offline_regex, NULL, NULL, NULL);
/* Network acquisition fail */ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regreq_regex, NULL, NULL, NULL);
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]), authreq_regex, NULL, NULL, 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);
} }
} }
+22 -40
View File
@@ -554,14 +554,14 @@ mm_cinterion_parse_cnmi_test (const gchar *response,
GArray **supported_bfr, GArray **supported_bfr,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
GArray *tmp_supported_mode = NULL; GArray *tmp_supported_mode = NULL;
GArray *tmp_supported_mt = NULL; GArray *tmp_supported_mt = NULL;
GArray *tmp_supported_bm = NULL; GArray *tmp_supported_bm = NULL;
GArray *tmp_supported_ds = NULL; GArray *tmp_supported_ds = NULL;
GArray *tmp_supported_bfr = NULL; GArray *tmp_supported_bfr = NULL;
if (!response) { if (!response) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing response"); g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing response");
@@ -576,57 +576,48 @@ mm_cinterion_parse_cnmi_test (const gchar *response,
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
if (!inner_error && g_match_info_matches (match_info)) { if (!inner_error && g_match_info_matches (match_info)) {
if (supported_mode) { if (supported_mode) {
gchar *str; g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 1); str = mm_get_string_unquoted_from_match_info (match_info, 1);
tmp_supported_mode = mm_parse_uint_list (str, &inner_error); tmp_supported_mode = mm_parse_uint_list (str, &inner_error);
g_free (str);
if (inner_error) if (inner_error)
goto out; goto out;
} }
if (supported_mt) { if (supported_mt) {
gchar *str; g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 2); str = mm_get_string_unquoted_from_match_info (match_info, 2);
tmp_supported_mt = mm_parse_uint_list (str, &inner_error); tmp_supported_mt = mm_parse_uint_list (str, &inner_error);
g_free (str);
if (inner_error) if (inner_error)
goto out; goto out;
} }
if (supported_bm) { if (supported_bm) {
gchar *str; g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 3); str = mm_get_string_unquoted_from_match_info (match_info, 3);
tmp_supported_bm = mm_parse_uint_list (str, &inner_error); tmp_supported_bm = mm_parse_uint_list (str, &inner_error);
g_free (str);
if (inner_error) if (inner_error)
goto out; goto out;
} }
if (supported_ds) { if (supported_ds) {
gchar *str; g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 4); str = mm_get_string_unquoted_from_match_info (match_info, 4);
tmp_supported_ds = mm_parse_uint_list (str, &inner_error); tmp_supported_ds = mm_parse_uint_list (str, &inner_error);
g_free (str);
if (inner_error) if (inner_error)
goto out; goto out;
} }
if (supported_bfr) { if (supported_bfr) {
gchar *str; g_autofree gchar *str = NULL;
str = mm_get_string_unquoted_from_match_info (match_info, 5); str = mm_get_string_unquoted_from_match_info (match_info, 5);
tmp_supported_bfr = mm_parse_uint_list (str, &inner_error); tmp_supported_bfr = mm_parse_uint_list (str, &inner_error);
g_free (str);
if (inner_error) if (inner_error)
goto out; goto out;
} }
} }
out: out:
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_clear_pointer (&tmp_supported_mode, g_array_unref); g_clear_pointer (&tmp_supported_mode, g_array_unref);
g_clear_pointer (&tmp_supported_mt, g_array_unref); g_clear_pointer (&tmp_supported_mt, g_array_unref);
@@ -763,9 +754,9 @@ mm_cinterion_parse_sind_response (const gchar *response,
guint *value, guint *value,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
guint errors = 0; guint errors = 0;
if (!response) { if (!response) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing response"); g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing response");
@@ -788,9 +779,6 @@ mm_cinterion_parse_sind_response (const gchar *response,
} else } else
errors++; errors++;
g_match_info_free (match_info);
g_regex_unref (r);
if (errors > 0) { if (errors > 0) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Failed parsing ^SIND response"); g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Failed parsing ^SIND response");
return FALSE; return FALSE;
@@ -836,8 +824,8 @@ mm_cinterion_parse_swwan_response (const gchar *response,
gpointer log_object, gpointer log_object,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
MMBearerConnectionStatus status; MMBearerConnectionStatus status;
@@ -883,9 +871,6 @@ mm_cinterion_parse_swwan_response (const gchar *response,
g_match_info_next (match_info, &inner_error); 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) if (status == MM_BEARER_CONNECTION_STATUS_UNKNOWN)
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"No state returned for CID %u", cid); "No state returned for CID %u", cid);
@@ -1078,10 +1063,10 @@ mm_cinterion_parse_slcc_list (const gchar *str,
GList **out_list, GList **out_list,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GList *list = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GList *list = NULL;
GMatchInfo *match_info = NULL; GError *inner_error = NULL;
static const MMCallDirection cinterion_call_direction[] = { static const MMCallDirection cinterion_call_direction[] = {
[0] = MM_CALL_DIRECTION_OUTGOING, [0] = MM_CALL_DIRECTION_OUTGOING,
@@ -1158,9 +1143,6 @@ mm_cinterion_parse_slcc_list (const gchar *str,
} }
out: out:
g_clear_pointer (&match_info, g_match_info_free);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
mm_cinterion_call_info_list_free (list); mm_cinterion_call_info_list_free (list);
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
@@ -1192,18 +1192,17 @@ test_smong_response_no_match (void)
/* Test ^SLCC URCs */ /* Test ^SLCC URCs */
static void static void
common_test_slcc_urc (const gchar *urc, common_test_slcc_urc (const gchar *urc,
const MMCallInfo *expected_call_info_list, const MMCallInfo *expected_call_info_list,
guint expected_call_info_list_size) guint expected_call_info_list_size)
{ {
GError *error = NULL; g_autoptr(GRegex) slcc_regex = NULL;
GRegex *slcc_regex = NULL; g_autoptr(GMatchInfo) match_info = NULL;
gboolean result; g_autofree gchar *str = NULL;
GMatchInfo *match_info = NULL; GError *error = NULL;
gchar *str; GList *call_info_list = NULL;
GList *call_info_list = NULL; GList *l;
GList *l; gboolean result;
slcc_regex = mm_cinterion_get_slcc_regex (); slcc_regex = mm_cinterion_get_slcc_regex ();
@@ -1230,8 +1229,8 @@ common_test_slcc_urc (const gchar *urc,
for (l = call_info_list; l; l = g_list_next (l)) { for (l = call_info_list; l; l = g_list_next (l)) {
const MMCallInfo *call_info = (const MMCallInfo *)(l->data); const MMCallInfo *call_info = (const MMCallInfo *)(l->data);
gboolean found = FALSE; gboolean found = FALSE;
guint i; guint i;
g_debug ("call at index %u: direction %s, state %s, number %s", g_debug ("call at index %u: direction %s, state %s, number %s",
call_info->index, call_info->index,
@@ -1248,10 +1247,6 @@ common_test_slcc_urc (const gchar *urc,
g_assert (found); 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); mm_cinterion_call_info_list_free (call_info_list);
} }
@@ -1322,12 +1317,12 @@ common_test_ctzu_urc (const gchar *urc,
gint expected_offset, gint expected_offset,
gint expected_dst_offset) gint expected_dst_offset)
{ {
GError *error = NULL; g_autoptr(GRegex) ctzu_regex = NULL;
GRegex *ctzu_regex = NULL; g_autoptr(GMatchInfo) match_info = NULL;
gboolean result; g_autofree gchar *iso8601 = NULL;
GMatchInfo *match_info = NULL; GError *error = NULL;
gchar *iso8601; gboolean result;
MMNetworkTimezone *tz = NULL; MMNetworkTimezone *tz = NULL;
ctzu_regex = mm_cinterion_get_ctzu_regex (); ctzu_regex = mm_cinterion_get_ctzu_regex ();
@@ -1342,7 +1337,6 @@ common_test_ctzu_urc (const gchar *urc,
g_assert (iso8601); g_assert (iso8601);
g_assert_cmpstr (expected_iso8601, ==, iso8601); g_assert_cmpstr (expected_iso8601, ==, iso8601);
g_free (iso8601);
g_assert (tz); g_assert (tz);
g_assert_cmpint (expected_offset, ==, mm_network_timezone_get_offset (tz)); g_assert_cmpint (expected_offset, ==, mm_network_timezone_get_offset (tz));
@@ -1351,8 +1345,6 @@ common_test_ctzu_urc (const gchar *urc,
g_assert_cmpuint ((guint)expected_dst_offset, ==, mm_network_timezone_get_dst_offset (tz)); g_assert_cmpuint ((guint)expected_dst_offset, ==, mm_network_timezone_get_dst_offset (tz));
g_object_unref (tz); g_object_unref (tz);
g_match_info_free (match_info);
g_regex_unref (ctzu_regex);
} }
static void static void
+7 -12
View File
@@ -627,12 +627,13 @@ load_unlock_retries_finish (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GError **error)
{ {
MMUnlockRetries *unlock_retries; g_autoptr(GRegex) r = NULL;
const gchar *result; g_autoptr(GMatchInfo) match_info = NULL;
GRegex *r; MMUnlockRetries *unlock_retries;
GMatchInfo *match_info = NULL; const gchar *result;
GError *match_error = NULL; GError *match_error = NULL;
guint i; guint i;
MMModemLock locks[4] = { MMModemLock locks[4] = {
MM_MODEM_LOCK_SIM_PUK, MM_MODEM_LOCK_SIM_PUK,
MM_MODEM_LOCK_SIM_PIN, MM_MODEM_LOCK_SIM_PIN,
@@ -657,9 +658,6 @@ load_unlock_retries_finish (MMIfaceModem *self,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Could not parse ^CPIN results: Response didn't match (%s)", "Could not parse ^CPIN results: Response didn't match (%s)",
result); result);
g_match_info_free (match_info);
g_regex_unref (r);
return NULL; return NULL;
} }
@@ -683,9 +681,6 @@ load_unlock_retries_finish (MMIfaceModem *self,
mm_unlock_retries_set (unlock_retries, locks[i], num); mm_unlock_retries_set (unlock_retries, locks[i], num);
} }
g_match_info_free (match_info);
g_regex_unref (r);
return unlock_retries; return unlock_retries;
} }
+153 -180
View File
@@ -39,8 +39,6 @@ mm_huawei_parse_ndisstatqry_response (const gchar *response,
gboolean *ipv6_connected, gboolean *ipv6_connected,
GError **error) GError **error)
{ {
GRegex *r;
GMatchInfo *match_info;
GError *inner_error = NULL; GError *inner_error = NULL;
if (!response || if (!response ||
@@ -71,6 +69,9 @@ mm_huawei_parse_ndisstatqry_response (const gchar *response,
/* If multiple fields available, try first parsing method */ /* If multiple fields available, try first parsing method */
if (strchr (response, ',')) { 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)?" r = g_regex_new ("\\^NDISSTAT(?:QRY)?(?:Qry)?:\\s*(\\d),([^,]*),([^,]*),([^,\\r\\n]*)(?:\\r\\n)?"
"(?:\\^NDISSTAT:|\\^NDISSTATQRY:)?\\s*,?(\\d)?,?([^,]*)?,?([^,]*)?,?([^,\\r\\n]*)?(?:\\r\\n)?", "(?:\\^NDISSTAT:|\\^NDISSTATQRY:)?\\s*,?(\\d)?,?([^,]*)?,?([^,]*)?,?([^,\\r\\n]*)?(?:\\r\\n)?",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
@@ -108,12 +109,12 @@ mm_huawei_parse_ndisstatqry_response (const gchar *response,
ip_type_field += 4; ip_type_field += 4;
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
} }
/* No separate IPv4/IPv6 info given just connected/not connected */ /* No separate IPv4/IPv6 info given just connected/not connected */
else { else {
g_autoptr(GRegex) r = NULL;
g_autoptr(GMatchInfo) match_info = NULL;
r = g_regex_new ("\\^NDISSTAT(?:QRY)?(?:Qry)?:\\s*(\\d)(?:\\r\\n)?", r = g_regex_new ("\\^NDISSTAT(?:QRY)?(?:Qry)?:\\s*(\\d)(?:\\r\\n)?",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
0, NULL); 0, NULL);
@@ -134,9 +135,6 @@ mm_huawei_parse_ndisstatqry_response (const gchar *response,
*ipv4_connected = (gboolean)connected; *ipv4_connected = (gboolean)connected;
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
} }
if (!ipv4_available && !ipv6_available) { if (!ipv4_available && !ipv6_available) {
@@ -208,10 +206,10 @@ mm_huawei_parse_dhcp_response (const char *reply,
guint *out_dns2, guint *out_dns2,
GError **error) GError **error)
{ {
gboolean matched; g_autoptr(GRegex) r = NULL;
GRegex *r; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info = NULL; gboolean matched;
GError *match_error = NULL; GError *match_error = NULL;
g_assert (reply != NULL); g_assert (reply != NULL);
g_assert (out_address != NULL); g_assert (out_address != NULL);
@@ -257,8 +255,6 @@ mm_huawei_parse_dhcp_response (const char *reply,
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
return matched; return matched;
} }
@@ -276,10 +272,10 @@ mm_huawei_parse_sysinfo_response (const char *reply,
guint *out_sys_submode, guint *out_sys_submode,
GError **error) GError **error)
{ {
gboolean matched; g_autoptr(GRegex) r = NULL;
GRegex *r; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info = NULL; gboolean matched;
GError *match_error = NULL; GError *match_error = NULL;
g_assert (out_srv_status != NULL); g_assert (out_srv_status != NULL);
g_assert (out_srv_domain != NULL); g_assert (out_srv_domain != NULL);
@@ -323,8 +319,6 @@ mm_huawei_parse_sysinfo_response (const char *reply,
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
return matched; return matched;
} }
@@ -341,10 +335,10 @@ mm_huawei_parse_sysinfoex_response (const char *reply,
guint *out_sys_submode, guint *out_sys_submode,
GError **error) GError **error)
{ {
gboolean matched; g_autoptr(GRegex) r = NULL;
GRegex *r; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info = NULL; gboolean matched;
GError *match_error = NULL; GError *match_error = NULL;
g_assert (out_srv_status != NULL); g_assert (out_srv_status != NULL);
g_assert (out_srv_domain != NULL); g_assert (out_srv_domain != NULL);
@@ -387,8 +381,6 @@ mm_huawei_parse_sysinfoex_response (const char *reply,
mm_get_uint_from_match_info (match_info, 8, out_sys_submode); mm_get_uint_from_match_info (match_info, 8, out_sys_submode);
} }
g_match_info_free (match_info);
g_regex_unref (r);
return matched; return matched;
} }
@@ -1189,17 +1181,23 @@ mm_huawei_parse_syscfgex_response (const gchar *response,
/*****************************************************************************/ /*****************************************************************************/
/* ^NWTIME response parser */ /* ^NWTIME response parser */
gboolean mm_huawei_parse_nwtime_response (const gchar *response, gboolean
gchar **iso8601p, mm_huawei_parse_nwtime_response (const gchar *response,
MMNetworkTimezone **tzp, gchar **iso8601p,
GError **error) MMNetworkTimezone **tzp,
GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *match_error = NULL; GError *match_error = NULL;
guint year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, dt = 0; guint year = 0;
gint tz = 0; guint month = 0;
gboolean ret = FALSE; 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 */ g_assert (iso8601p || tzp); /* at least one */
@@ -1211,75 +1209,72 @@ gboolean mm_huawei_parse_nwtime_response (const gchar *response,
g_propagate_error (error, match_error); g_propagate_error (error, match_error);
g_prefix_error (error, "Could not parse ^NWTIME results: "); g_prefix_error (error, "Could not parse ^NWTIME results: ");
} else { } else {
g_set_error_literal (error, g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't match ^NWTIME reply"); "Couldn't match ^NWTIME reply");
} }
} else { return FALSE;
/* 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");
}
} }
g_match_info_free (match_info); /* Remember that g_match_info_get_match_count() includes match #0 */
g_regex_unref (r); 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 */ /* ^TIME response parser */
gboolean mm_huawei_parse_time_response (const gchar *response, gboolean
gchar **iso8601p, mm_huawei_parse_time_response (const gchar *response,
MMNetworkTimezone **tzp, gchar **iso8601p,
GError **error) MMNetworkTimezone **tzp,
GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *match_error = NULL; GError *match_error = NULL;
guint year, month, day, hour, minute, second; guint year = 0;
gboolean ret = FALSE; guint month = 0;
guint day = 0;
guint hour = 0;
guint minute = 0;
guint second = 0;
g_assert (iso8601p || tzp); /* at least one */ g_assert (iso8601p || tzp); /* at least one */
@@ -1306,41 +1301,35 @@ gboolean mm_huawei_parse_time_response (const gchar *response,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't match ^TIME reply"); "Couldn't match ^TIME reply");
} }
} else { return FALSE;
/* 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");
}
} }
g_match_info_free (match_info); /* Remember that g_match_info_get_match_count() includes match #0 */
g_regex_unref (r); 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 @@ mm_huawei_parse_hcsq_response (const gchar *response,
guint *out_value5, guint *out_value5,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *match_error = NULL; GError *match_error = NULL;
gboolean ret = FALSE;
char *s;
r = g_regex_new ("\\^HCSQ:\\s*\"?([a-zA-Z]*)\"?,(\\d+),?(\\d+)?,?(\\d+)?,?(\\d+)?,?(\\d+)?$", 0, 0, NULL); r = g_regex_new ("\\^HCSQ:\\s*\"?([a-zA-Z]*)\"?,(\\d+),?(\\d+)?,?(\\d+)?,?(\\d+)?,?(\\d+)?$", 0, 0, NULL);
g_assert (r != NULL); g_assert (r != NULL);
@@ -1370,27 +1357,24 @@ mm_huawei_parse_hcsq_response (const gchar *response,
g_propagate_error (error, match_error); g_propagate_error (error, match_error);
g_prefix_error (error, "Could not parse ^HCSQ results: "); g_prefix_error (error, "Could not parse ^HCSQ results: ");
} else { } else {
g_set_error_literal (error, g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't match ^HCSQ reply"); "Couldn't match ^HCSQ reply");
} }
goto done; return FALSE;
} }
/* Remember that g_match_info_get_match_count() includes match #0 */ /* Remember that g_match_info_get_match_count() includes match #0 */
if (g_match_info_get_match_count (match_info) < 3) { if (g_match_info_get_match_count (match_info) < 3) {
g_set_error_literal (error, g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Not enough elements in ^HCSQ reply"); "Not enough elements in ^HCSQ reply");
goto done; return FALSE;
} }
if (out_act) { if (out_act) {
g_autofree gchar *s = NULL;
s = g_match_info_fetch (match_info, 1); s = g_match_info_fetch (match_info, 1);
*out_act = mm_string_to_access_tech (s); *out_act = mm_string_to_access_tech (s);
g_free (s);
} }
if (out_value1) if (out_value1)
@@ -1404,13 +1388,7 @@ mm_huawei_parse_hcsq_response (const gchar *response,
if (out_value5) if (out_value5)
mm_get_uint_from_match_info (match_info, 6, out_value5); mm_get_uint_from_match_info (match_info, 6, out_value5);
ret = TRUE; return TRUE;
done:
g_match_info_free (match_info);
g_regex_unref (r);
return ret;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -1422,11 +1400,12 @@ mm_huawei_parse_cvoice_response (const gchar *response,
guint *out_bits, guint *out_bits,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *match_error = NULL; GError *match_error = NULL;
guint supported = 0, hz = 0, bits = 0; guint supported = 0;
gboolean ret = FALSE; guint hz = 0;
guint bits = 0;
/* ^CVOICE: <0=supported,1=unsupported>,<hz>,<bits>,<unknown> */ /* ^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); r = g_regex_new ("\\^CVOICE:\\s*(\\d)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)$", 0, 0, NULL);
@@ -1442,37 +1421,31 @@ mm_huawei_parse_cvoice_response (const gchar *response,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't match ^CVOICE reply"); "Couldn't match ^CVOICE reply");
} }
} else { return FALSE;
/* 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");
}
} }
g_match_info_free (match_info); /* Remember that g_match_info_get_match_count() includes match #0 */
g_regex_unref (r); 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;
} }
/*****************************************************************************/ /*****************************************************************************/
+13 -19
View File
@@ -123,12 +123,12 @@ load_supported_modes_finish (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GError **error)
{ {
GArray *combinations = NULL; GArray *combinations = NULL;
const gchar *response; const gchar *response;
gchar **split = NULL; gchar **split = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GRegex *r; g_autoptr(GRegex) r = NULL;
guint i; guint i;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
if (!response) if (!response)
@@ -145,18 +145,13 @@ load_supported_modes_finish (MMIfaceModem *self,
g_regex_match (r, response, 0, &match_info); g_regex_match (r, response, 0, &match_info);
if (g_match_info_matches (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); aux = mm_get_string_unquoted_from_match_info (match_info, 1);
if (aux) { if (aux)
split = g_strsplit (aux, ",", -1); split = g_strsplit (aux, ",", -1);
g_free (aux);
}
} }
g_match_info_free (match_info);
g_regex_unref (r);
if (!split) { if (!split) {
g_set_error (error, g_set_error (error,
MM_CORE_ERROR, MM_CORE_ERROR,
@@ -1122,11 +1117,12 @@ icera_band_to_mm (const char *icera)
} }
static GSList * static GSList *
parse_bands (const gchar *response, guint32 *out_len) parse_bands (const gchar *response,
guint32 *out_len)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *info; g_autoptr(GMatchInfo) info = NULL;
GSList *bands = NULL; GSList *bands = NULL;
g_return_val_if_fail (out_len != NULL, NULL); g_return_val_if_fail (out_len != NULL, NULL);
@@ -1163,8 +1159,6 @@ parse_bands (const gchar *response, guint32 *out_len)
g_free (enabled); g_free (enabled);
g_match_info_next (info, NULL); g_match_info_next (info, NULL);
} }
g_match_info_free (info);
g_regex_unref (r);
return bands; return bands;
} }
+19 -18
View File
@@ -55,15 +55,17 @@ mm_mbm_parse_e2ipcfg_response (const gchar *response,
MMBearerIpConfig **out_ip6_config, MMBearerIpConfig **out_ip6_config,
GError **error) GError **error)
{ {
MMBearerIpConfig **ip_config = NULL; MMBearerIpConfig **ip_config = NULL;
gboolean got_address = FALSE, got_gw = FALSE, got_dns = FALSE; gboolean got_address = FALSE;
GRegex *r; gboolean got_gw = FALSE;
GMatchInfo *match_info = NULL; gboolean got_dns = FALSE;
GError *match_error = NULL; g_autoptr(GRegex) r = NULL;
gchar *dns[3] = { 0 }; g_autoptr(GMatchInfo) match_info = NULL;
guint dns_idx = 0; GError *match_error = NULL;
int family = AF_INET; gchar *dns[3] = { 0 };
MMBearerIpMethod method = MM_BEARER_IP_METHOD_STATIC; 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_ip4_config, FALSE);
g_return_val_if_fail (out_ip6_config, FALSE); g_return_val_if_fail (out_ip6_config, FALSE);
@@ -108,14 +110,17 @@ mm_mbm_parse_e2ipcfg_response (const gchar *response,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't match " E2IPCFG_TAG " reply"); "Couldn't match " E2IPCFG_TAG " reply");
} }
goto done; return FALSE;
} }
*ip_config = mm_bearer_ip_config_new (); *ip_config = mm_bearer_ip_config_new ();
mm_bearer_ip_config_set_method (*ip_config, method); mm_bearer_ip_config_set_method (*ip_config, method);
while (g_match_info_matches (match_info)) { while (g_match_info_matches (match_info)) {
char *id = g_match_info_fetch (match_info, 1); g_autofree gchar *id = NULL;
char *str = g_match_info_fetch (match_info, 2); g_autofree gchar *str = NULL;
id = g_match_info_fetch (match_info, 1);
str = g_match_info_fetch (match_info, 2);
switch (atoi (id)) { switch (atoi (id)) {
case 1: case 1:
@@ -140,8 +145,6 @@ mm_mbm_parse_e2ipcfg_response (const gchar *response,
default: default:
break; break;
} }
g_free (id);
g_free (str);
g_match_info_next (match_info, NULL); g_match_info_next (match_info, NULL);
} }
@@ -156,12 +159,10 @@ mm_mbm_parse_e2ipcfg_response (const gchar *response,
*ip_config = NULL; *ip_config = NULL;
g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Got incomplete IP configuration from " E2IPCFG_TAG); "Got incomplete IP configuration from " E2IPCFG_TAG);
return FALSE;
} }
done: return TRUE;
g_match_info_free (match_info);
g_regex_unref (r);
return !!*ip_config;
} }
/*****************************************************************************/ /*****************************************************************************/
+38 -66
View File
@@ -67,13 +67,16 @@ load_unlock_retries_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
const gchar *response; g_autoptr(GMatchInfo) match_info = NULL;
GError *error = NULL; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; const gchar *response;
GError *match_error = NULL; GError *error = NULL;
GRegex *r = NULL; GError *match_error = NULL;
gint pin1, puk1, pin2, puk2; gint pin1;
MMUnlockRetries *retries; gint puk1;
gint pin2;
gint puk2;
MMUnlockRetries *retries;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) { if (!response) {
@@ -91,14 +94,11 @@ load_unlock_retries_ready (MMBaseModem *self,
g_assert (r != NULL); g_assert (r != NULL);
if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)){ if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)){
if (match_error) { if (match_error)
g_propagate_error (&error, match_error); g_task_return_error (task, match_error);
} else { else
g_set_error (&error, g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
MM_CORE_ERROR, "Failed to match EPINC response: %s", response);
MM_CORE_ERROR_FAILED,
"Failed to match EPINC response: %s", response);
}
g_task_return_error (task, error); g_task_return_error (task, error);
} else if (!mm_get_int_from_match_info (match_info, 1, &pin1) || } else if (!mm_get_int_from_match_info (match_info, 1, &pin1) ||
!mm_get_int_from_match_info (match_info, 2, &pin2) || !mm_get_int_from_match_info (match_info, 2, &pin2) ||
@@ -120,9 +120,6 @@ load_unlock_retries_ready (MMBaseModem *self,
g_task_return_pointer (task, retries, g_object_unref); g_task_return_pointer (task, retries, g_object_unref);
} }
g_object_unref (task); g_object_unref (task);
g_match_info_free (match_info);
g_regex_unref (r);
} }
static void static void
@@ -178,14 +175,14 @@ get_supported_modes_ready (MMBaseModem *self,
GTask *task) GTask *task)
{ {
const gchar *response; g_autoptr(GMatchInfo) match_info = NULL;
GError *error = NULL; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; const gchar *response;
MMModemModeCombination mode; GError *error = NULL;
GArray *combinations; MMModemModeCombination mode;
GRegex *r; GArray *combinations;
GError *match_error = NULL; GError *match_error = NULL;
gint device_type; gint device_type;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) { if (!response) {
@@ -205,9 +202,6 @@ get_supported_modes_ready (MMBaseModem *self,
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Failed to match EGMR response: %s", response); "Failed to match EGMR response: %s", response);
g_object_unref (task); g_object_unref (task);
g_match_info_free (match_info);
g_regex_unref (r);
return; return;
} }
@@ -216,9 +210,6 @@ get_supported_modes_ready (MMBaseModem *self,
"Failed to parse the allowed mode response: '%s'", "Failed to parse the allowed mode response: '%s'",
response); response);
g_object_unref (task); g_object_unref (task);
g_regex_unref (r);
g_match_info_free (match_info);
return; return;
} }
@@ -271,9 +262,6 @@ get_supported_modes_ready (MMBaseModem *self,
*/ */
g_task_return_pointer (task, combinations, (GDestroyNotify)g_array_unref); g_task_return_pointer (task, combinations, (GDestroyNotify)g_array_unref);
g_object_unref (task); g_object_unref (task);
g_regex_unref (r);
g_match_info_free (match_info);
} }
static void static void
@@ -307,17 +295,16 @@ load_current_modes_finish (MMIfaceModem *self,
MMModemMode *preferred, MMModemMode *preferred,
GError **error) GError **error)
{ {
const gchar *response; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GRegex) r = NULL;
GRegex *r; const gchar *response;
gint erat_mode = -1; gint erat_mode = -1;
gint erat_pref = -1; gint erat_pref = -1;
GError *match_error = NULL; GError *match_error = NULL;
gboolean result = FALSE;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
if (!response) if (!response)
return result; return FALSE;
r = g_regex_new ( r = g_regex_new (
"\\+ERAT:\\s*[0-9]+,\\s*[0-9]+,\\s*([0-9]+),\\s*([0-9]+)", "\\+ERAT:\\s*[0-9]+,\\s*[0-9]+,\\s*([0-9]+),\\s*([0-9]+)",
@@ -329,30 +316,22 @@ load_current_modes_finish (MMIfaceModem *self,
if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)) { if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)) {
if (match_error) if (match_error)
g_propagate_error (error, match_error); g_propagate_error (error, match_error);
else { else
g_set_error (error, g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't parse +ERAT response: '%s'", "Couldn't parse +ERAT response: '%s'",
response); response);
return FALSE;
}
goto done;
} }
if (!mm_get_int_from_match_info (match_info, 1, &erat_mode) || if (!mm_get_int_from_match_info (match_info, 1, &erat_mode) ||
!mm_get_int_from_match_info (match_info, 2, &erat_pref)) { !mm_get_int_from_match_info (match_info, 2, &erat_pref)) {
g_set_error (error, g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Failed to parse the ERAT response: m=%d p=%d", "Failed to parse the ERAT response: m=%d p=%d",
erat_mode, erat_pref); erat_mode, erat_pref);
goto done; return FALSE;
} }
/* Correctly parsed! */ /* Correctly parsed! */
result = TRUE;
switch (erat_mode) { switch (erat_mode) {
case 0: case 0:
*allowed = MM_MODEM_MODE_2G; *allowed = MM_MODEM_MODE_2G;
@@ -376,9 +355,8 @@ load_current_modes_finish (MMIfaceModem *self,
*allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G; *allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G;
break; break;
default: default:
result = FALSE;
mm_obj_dbg (self, "unsupported allowed mode reported in +ERAT: %d", erat_mode); mm_obj_dbg (self, "unsupported allowed mode reported in +ERAT: %d", erat_mode);
goto done; return FALSE;
} }
switch (erat_pref) { switch (erat_pref) {
@@ -395,17 +373,11 @@ load_current_modes_finish (MMIfaceModem *self,
*preferred = MM_MODEM_MODE_4G; *preferred = MM_MODEM_MODE_4G;
break; break;
default: default:
result = FALSE;
mm_obj_dbg (self, "unsupported preferred mode %d", erat_pref); mm_obj_dbg (self, "unsupported preferred mode %d", erat_pref);
goto done; return FALSE;
} }
done: return TRUE;
if (r)
g_regex_unref (r);
g_match_info_free (match_info);
return result;
} }
static void static void
+19 -26
View File
@@ -159,12 +159,12 @@ nwrat_query_ready (MMBaseModem *self,
GTask *task) GTask *task)
{ {
LoadCurrentModesResult *result; LoadCurrentModesResult *result;
GError *error = NULL; GError *error = NULL;
const gchar *response; const gchar *response;
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
gint a = -1; gint a = -1;
gint b = -1; gint b = -1;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) { if (!response) {
@@ -187,8 +187,6 @@ nwrat_query_ready (MMBaseModem *self,
"Couldn't match NWRAT reply: %s", "Couldn't match NWRAT reply: %s",
response); response);
g_object_unref (task); g_object_unref (task);
g_match_info_free (match_info);
g_regex_unref (r);
return; return;
} }
@@ -203,8 +201,6 @@ nwrat_query_ready (MMBaseModem *self,
"Failed to parse mode/tech response '%s': invalid modes reported", "Failed to parse mode/tech response '%s': invalid modes reported",
response); response);
g_object_unref (task); g_object_unref (task);
g_match_info_free (match_info);
g_regex_unref (r);
return; return;
} }
@@ -239,9 +235,6 @@ nwrat_query_ready (MMBaseModem *self,
break; break;
} }
g_match_info_free (match_info);
g_regex_unref (r);
g_task_return_pointer (task, result, g_free); g_task_return_pointer (task, result, g_free);
g_object_unref (task); g_object_unref (task);
} }
@@ -1396,13 +1389,18 @@ parse_nwltime_reply (const char *response,
MMNetworkTimezone **out_tz, MMNetworkTimezone **out_tz,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *match_error = NULL; GError *match_error = NULL;
guint year, month, day, hour, minute, second; guint year;
gchar *result = NULL; guint month;
gint utc_offset = 0; guint day;
gboolean success = FALSE; 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 */ /* 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); r = g_regex_new ("(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.([\\-\\+\\d]+)$", 0, 0, NULL);
@@ -1429,7 +1427,6 @@ parse_nwltime_reply (const char *response,
mm_get_uint_from_match_info (match_info, 5, &minute) && mm_get_uint_from_match_info (match_info, 5, &minute) &&
mm_get_uint_from_match_info (match_info, 6, &second) && mm_get_uint_from_match_info (match_info, 6, &second) &&
mm_get_int_from_match_info (match_info, 8, &utc_offset)) { mm_get_int_from_match_info (match_info, 8, &utc_offset)) {
result = mm_new_iso8601_time (year, month, day, hour, minute, second, result = mm_new_iso8601_time (year, month, day, hour, minute, second,
TRUE, utc_offset * 60, error); TRUE, utc_offset * 60, error);
if (out_tz) { if (out_tz) {
@@ -1447,12 +1444,8 @@ parse_nwltime_reply (const char *response,
} }
if (out_iso_8601) if (out_iso_8601)
*out_iso_8601 = result; *out_iso_8601 = g_steal_pointer (&result);
else
g_free (result);
g_match_info_free (match_info);
g_regex_unref (r);
return success; return success;
} }
+17 -25
View File
@@ -362,12 +362,10 @@ static gboolean
parse_ossys_response (const gchar *response, parse_ossys_response (const gchar *response,
MMModemAccessTechnology *access_technology) MMModemAccessTechnology *access_technology)
{ {
MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
const gchar *p; const gchar *p;
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
gchar *str;
gboolean success = FALSE;
p = mm_strip_tag (response, "_OSSYS:"); p = mm_strip_tag (response, "_OSSYS:");
r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL); r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL);
@@ -375,17 +373,15 @@ parse_ossys_response (const gchar *response,
g_regex_match (r, p, 0, &match_info); g_regex_match (r, p, 0, &match_info);
if (g_match_info_matches (match_info)) { if (g_match_info_matches (match_info)) {
g_autofree gchar *str = NULL;
str = g_match_info_fetch (match_info, 2); str = g_match_info_fetch (match_info, 2);
if (str && ossys_to_mm (str[0], &current)) { if (str && ossys_to_mm (str[0], &current)) {
*access_technology = current; *access_technology = current;
success = TRUE; return TRUE;
} }
g_free (str);
} }
g_match_info_free (match_info); return FALSE;
g_regex_unref (r);
return success;
} }
static void static void
@@ -445,12 +441,10 @@ static gboolean
parse_octi_response (const gchar *response, parse_octi_response (const gchar *response,
MMModemAccessTechnology *access_technology) MMModemAccessTechnology *access_technology)
{ {
MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
const gchar *p; const gchar *p;
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
gchar *str;
gboolean success = FALSE;
p = mm_strip_tag (response, "_OCTI:"); p = mm_strip_tag (response, "_OCTI:");
r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL); r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL);
@@ -458,17 +452,15 @@ parse_octi_response (const gchar *response,
g_regex_match (r, p, 0, &match_info); g_regex_match (r, p, 0, &match_info);
if (g_match_info_matches (match_info)) { if (g_match_info_matches (match_info)) {
g_autofree gchar *str = NULL;
str = g_match_info_fetch (match_info, 2); str = g_match_info_fetch (match_info, 2);
if (str && octi_to_mm (str[0], &current)) { if (str && octi_to_mm (str[0], &current)) {
*access_technology = current; *access_technology = current;
success = TRUE; return TRUE;
} }
g_free (str);
} }
g_match_info_free (match_info); return FALSE;
g_regex_unref (r);
return success;
} }
static void static void
+1 -2
View File
@@ -440,8 +440,8 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
Private *priv; Private *priv;
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GTask *task; GTask *task;
GRegex *pattern;
guint i; guint i;
g_autoptr(GRegex) pattern = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
priv = get_private (MM_SHARED_QUECTEL (self)); priv = get_private (MM_SHARED_QUECTEL (self));
@@ -464,7 +464,6 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
NULL); NULL);
} }
g_regex_unref (pattern);
mm_obj_dbg (self, "+QUSIM detection set up"); mm_obj_dbg (self, "+QUSIM detection set up");
if (!mm_broadband_modem_sim_hot_swap_ports_context_init (MM_BROADBAND_MODEM (self), &error)) if (!mm_broadband_modem_sim_hot_swap_ports_context_init (MM_BROADBAND_MODEM (self), &error))
+19 -22
View File
@@ -624,7 +624,7 @@ load_current_modes_finish (MMIfaceModem *self,
MMModemMode *preferred, MMModemMode *preferred,
GError **error) GError **error)
{ {
LoadCurrentModesResult *result; g_autofree LoadCurrentModesResult *result = NULL;
result = g_task_propagate_pointer (G_TASK (res), error); result = g_task_propagate_pointer (G_TASK (res), error);
if (!result) if (!result)
@@ -632,7 +632,6 @@ load_current_modes_finish (MMIfaceModem *self,
*allowed = result->allowed; *allowed = result->allowed;
*preferred = result->preferred; *preferred = result->preferred;
g_free (result);
return TRUE; return TRUE;
} }
@@ -641,11 +640,11 @@ selrat_query_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
LoadCurrentModesResult *result; g_autofree LoadCurrentModesResult *result = NULL;
const gchar *response; const gchar *response;
GError *error = NULL; GError *error = NULL;
GRegex *r = NULL; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
response = mm_base_modem_at_command_full_finish (self, res, &error); response = mm_base_modem_at_command_full_finish (self, res, &error);
if (!response) { if (!response) {
@@ -727,15 +726,10 @@ selrat_query_ready (MMBaseModem *self,
"Could not parse allowed mode response: Response didn't match: '%s'", "Could not parse allowed mode response: Response didn't match: '%s'",
response); response);
g_match_info_free (match_info); if (error)
g_regex_unref (r);
if (error) {
g_free (result);
g_task_return_error (task, error); g_task_return_error (task, error);
} else else
g_task_return_pointer (task, result, g_free); g_task_return_pointer (task, g_steal_pointer (&result), g_free);
g_object_unref (task); g_object_unref (task);
} }
@@ -1630,11 +1624,16 @@ parse_time (const gchar *response,
const gchar *tag, const gchar *tag,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *match_error = NULL; GError *match_error = NULL;
guint year, month, day, hour, minute, second; guint year;
gchar *result = NULL; guint month;
guint day;
guint hour;
guint minute;
guint second;
gchar *result = NULL;
r = g_regex_new (regex, 0, 0, NULL); r = g_regex_new (regex, 0, 0, NULL);
g_assert (r != NULL); g_assert (r != NULL);
@@ -1665,8 +1664,6 @@ parse_time (const gchar *response,
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
return result; return result;
} }
+1 -3
View File
@@ -480,7 +480,7 @@ mm_common_sierra_setup_ports (MMBroadbandModem *self)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
guint i; 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); pacsp_regex = g_regex_new ("\\r\\n\\+PACSP.*\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
@@ -505,8 +505,6 @@ mm_common_sierra_setup_ports (MMBroadbandModem *self)
pacsp_regex, pacsp_regex,
NULL, NULL, NULL); NULL, NULL, NULL);
} }
g_regex_unref (pacsp_regex);
} }
/*****************************************************************************/ /*****************************************************************************/
+5 -11
View File
@@ -23,16 +23,15 @@ GList *
mm_sierra_parse_scact_read_response (const gchar *reply, mm_sierra_parse_scact_read_response (const gchar *reply,
GError **error) GError **error)
{ {
GError *inner_error = NULL; g_autoptr(GRegex) r = NULL;
GRegex *r; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info; GError *inner_error = NULL;
GList *list; GList *list = NULL;
if (!reply || !reply[0]) if (!reply || !reply[0])
/* Nothing configured, all done */ /* Nothing configured, all done */
return NULL; return NULL;
list = NULL;
r = g_regex_new ("!SCACT:\\s*(\\d+),(\\d+)", r = g_regex_new ("!SCACT:\\s*(\\d+),(\\d+)",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, &inner_error); G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, &inner_error);
g_assert (r); g_assert (r);
@@ -66,9 +65,6 @@ mm_sierra_parse_scact_read_response (const gchar *reply,
g_match_info_next (match_info, &inner_error); g_match_info_next (match_info, &inner_error);
} }
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
mm_3gpp_pdp_context_active_list_free (list); mm_3gpp_pdp_context_active_list_free (list);
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
@@ -76,7 +72,5 @@ mm_sierra_parse_scact_read_response (const gchar *reply,
return NULL; return NULL;
} }
list = g_list_sort (list, (GCompareFunc) mm_3gpp_pdp_context_active_cmp); return g_list_sort (list, (GCompareFunc) mm_3gpp_pdp_context_active_cmp);
return list;
} }
@@ -33,13 +33,13 @@ common_test_clcc_urc (const gchar *urc,
const MMCallInfo *expected_call_info_list, const MMCallInfo *expected_call_info_list,
guint expected_call_info_list_size) guint expected_call_info_list_size)
{ {
GError *error = NULL; g_autoptr(GRegex) clcc_regex = NULL;
GRegex *clcc_regex = NULL; g_autoptr(GMatchInfo) match_info = NULL;
gboolean result; g_autofree gchar *str = NULL;
GMatchInfo *match_info = NULL; GError *error = NULL;
gchar *str; GList *call_info_list = NULL;
GList *call_info_list = NULL; GList *l;
GList *l; gboolean result;
clcc_regex = mm_simtech_get_clcc_urc_regex (); clcc_regex = mm_simtech_get_clcc_urc_regex ();
@@ -84,10 +84,6 @@ common_test_clcc_urc (const gchar *urc,
g_assert (found); 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); mm_simtech_call_info_list_free (call_info_list);
} }
@@ -148,12 +144,12 @@ common_test_voice_call_urc (const gchar *urc,
gboolean expected_start_or_stop, gboolean expected_start_or_stop,
guint expected_duration) guint expected_duration)
{ {
GError *error = NULL; g_autoptr(GRegex) voice_call_regex = NULL;
gboolean start_or_stop = FALSE; /* start = TRUE, stop = FALSE */ g_autoptr(GMatchInfo) match_info = NULL;
guint duration = 0; GError *error = NULL;
GRegex *voice_call_regex = NULL; gboolean start_or_stop = FALSE; /* start = TRUE, stop = FALSE */
gboolean result; guint duration = 0;
GMatchInfo *match_info = NULL; gboolean result;
voice_call_regex = mm_simtech_get_voice_call_urc_regex (); voice_call_regex = mm_simtech_get_voice_call_urc_regex ();
@@ -168,9 +164,6 @@ common_test_voice_call_urc (const gchar *urc,
g_assert_cmpuint (expected_start_or_stop, ==, start_or_stop); g_assert_cmpuint (expected_start_or_stop, ==, start_or_stop);
g_assert_cmpuint (expected_duration, ==, duration); g_assert_cmpuint (expected_duration, ==, duration);
g_match_info_free (match_info);
g_regex_unref (voice_call_regex);
} }
static void static void
@@ -197,11 +190,11 @@ static void
common_test_missed_call_urc (const gchar *urc, common_test_missed_call_urc (const gchar *urc,
const gchar *expected_details) const gchar *expected_details)
{ {
GError *error = NULL; g_autoptr(GRegex) missed_call_regex = NULL;
gchar *details = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GRegex *missed_call_regex = NULL; g_autofree gchar *details = NULL;
gboolean result; GError *error = NULL;
GMatchInfo *match_info = NULL; gboolean result;
missed_call_regex = mm_simtech_get_missed_call_urc_regex (); missed_call_regex = mm_simtech_get_missed_call_urc_regex ();
@@ -215,10 +208,6 @@ common_test_missed_call_urc (const gchar *urc,
g_assert (result); g_assert (result);
g_assert_cmpstr (expected_details, ==, details); g_assert_cmpstr (expected_details, ==, details);
g_free (details);
g_match_info_free (match_info);
g_regex_unref (missed_call_regex);
} }
static void static void
@@ -233,11 +222,11 @@ static void
common_test_cring_urc (const gchar *urc, common_test_cring_urc (const gchar *urc,
const gchar *expected_type) const gchar *expected_type)
{ {
GError *error = NULL; g_autoptr(GRegex) cring_regex = NULL;
GRegex *cring_regex = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info = NULL; g_autofree gchar *type = NULL;
gchar *type; GError *error = NULL;
gboolean result; gboolean result;
cring_regex = mm_simtech_get_cring_urc_regex (); cring_regex = mm_simtech_get_cring_urc_regex ();
@@ -250,10 +239,6 @@ common_test_cring_urc (const gchar *urc,
g_assert (type); g_assert (type);
g_assert_cmpstr (type, ==, expected_type); g_assert_cmpstr (type, ==, expected_type);
g_match_info_free (match_info);
g_regex_unref (cring_regex);
g_free (type);
} }
static void static void
@@ -274,11 +259,11 @@ static void
common_test_rxdtmf_urc (const gchar *urc, common_test_rxdtmf_urc (const gchar *urc,
const gchar *expected_str) const gchar *expected_str)
{ {
GError *error = NULL; g_autoptr(GRegex) rxdtmf_regex = NULL;
GRegex *rxdtmf_regex = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info = NULL; g_autofree gchar *type = NULL;
gchar *type; GError *error = NULL;
gboolean result; gboolean result;
rxdtmf_regex = mm_simtech_get_rxdtmf_urc_regex (); rxdtmf_regex = mm_simtech_get_rxdtmf_urc_regex ();
@@ -291,10 +276,6 @@ common_test_rxdtmf_urc (const gchar *urc,
g_assert (type); g_assert (type);
g_assert_cmpstr (type, ==, expected_str); g_assert_cmpstr (type, ==, expected_str);
g_match_info_free (match_info);
g_regex_unref (rxdtmf_regex);
g_free (type);
} }
static void static void
+4 -5
View File
@@ -501,10 +501,10 @@ telit_qss_enable_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
QssSetupContext *ctx; QssSetupContext *ctx;
MMPortSerialAt *port; MMPortSerialAt *port;
GError **error; GError **error;
GRegex *pattern; g_autoptr(GRegex) pattern = NULL;
ctx = g_task_get_task_data (task); ctx = g_task_get_task_data (task);
@@ -530,7 +530,6 @@ telit_qss_enable_ready (MMBaseModem *self,
(MMPortSerialAtUnsolicitedMsgFn)telit_qss_unsolicited_handler, (MMPortSerialAtUnsolicitedMsgFn)telit_qss_unsolicited_handler,
self, self,
NULL); NULL);
g_regex_unref (pattern);
next_step: next_step:
ctx->step++; ctx->step++;
+7 -9
View File
@@ -112,12 +112,12 @@ cache_port_mode (MMPortProbe *probe,
MMDevice *device, MMDevice *device,
const gchar *reply) const gchar *reply)
{ {
GRegex *r = NULL; g_autoptr(GRegex) r = NULL;
GRegexCompileFlags flags = G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info = NULL; GRegexCompileFlags flags = G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW;
GError *error = NULL; GError *error = NULL;
gboolean ret = FALSE; gboolean ret = FALSE;
guint portcfg_current; guint portcfg_current;
/* #PORTCFG: <requested>,<active> */ /* #PORTCFG: <requested>,<active> */
r = g_regex_new ("#PORTCFG:\\s*(\\d+),(\\d+)", flags, 0, NULL); r = g_regex_new ("#PORTCFG:\\s*(\\d+),(\\d+)", flags, 0, NULL);
@@ -173,9 +173,7 @@ cache_port_mode (MMPortProbe *probe,
ret = TRUE; ret = TRUE;
out: out:
g_match_info_free (match_info); if (error) {
g_regex_unref (r);
if (error != NULL) {
mm_obj_dbg (probe, "error while matching #PORTCFG: %s", error->message); mm_obj_dbg (probe, "error while matching #PORTCFG: %s", error->message);
g_error_free (error); g_error_free (error);
} }
+5 -8
View File
@@ -701,11 +701,11 @@ common_parse_bnd_response (const gchar *response,
gpointer log_object, gpointer log_object,
GError **error) GError **error)
{ {
GError *inner_error = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GArray *bands = NULL; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; GError *inner_error = NULL;
GRegex *r = NULL; GArray *bands = NULL;
const gchar *load_bands_regex = NULL; const gchar *load_bands_regex = NULL;
static const gchar *load_bands_regex_4g_hex[] = { 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, [LOAD_BANDS_TYPE_SUPPORTED] = "#BND:"MM_SUPPORTED_BANDS_2G MM_SUPPORTED_BANDS_3G MM_SUPPORTED_BANDS_4G_HEX,
@@ -761,9 +761,6 @@ common_parse_bnd_response (const gchar *response,
goto out; goto out;
} }
out: out:
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
g_clear_pointer (&bands, g_array_unref); g_clear_pointer (&bands, g_array_unref);
+4 -7
View File
@@ -1122,10 +1122,10 @@ static void
ublox_setup_ciev_handler (MMIfaceModem *self, ublox_setup_ciev_handler (MMIfaceModem *self,
guint simind_idx) guint simind_idx)
{ {
GRegex *pattern; g_autoptr(GRegex) pattern = NULL;
gchar *ciev_regex; g_autofree gchar *ciev_regex = NULL;
MMPortSerialAt *primary_port; MMPortSerialAt *primary_port;
MMPortSerialAt *secondary_port; MMPortSerialAt *secondary_port;
primary_port = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); 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); mm_obj_dbg (self, "setting up simind 'CIEV: %d' events handler", simind_idx);
@@ -1149,9 +1149,6 @@ ublox_setup_ciev_handler (MMIfaceModem *self,
(MMPortSerialAtUnsolicitedMsgFn) ublox_ciev_unsolicited_handler, (MMPortSerialAtUnsolicitedMsgFn) ublox_ciev_unsolicited_handler,
self, self,
NULL); NULL);
g_regex_unref (pattern);
g_free (ciev_regex);
} }
static void static void
+59 -93
View File
@@ -31,14 +31,14 @@ mm_ublox_parse_upincnt_response (const gchar *response,
guint *out_puk2_attempts, guint *out_puk2_attempts,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
guint pin_attempts = 0; guint pin_attempts = 0;
guint pin2_attempts = 0; guint pin2_attempts = 0;
guint puk_attempts = 0; guint puk_attempts = 0;
guint puk2_attempts = 0; guint puk2_attempts = 0;
gboolean success = TRUE; gboolean success = TRUE;
g_assert (out_pin_attempts); g_assert (out_pin_attempts);
g_assert (out_pin2_attempts); g_assert (out_pin2_attempts);
@@ -78,9 +78,6 @@ mm_ublox_parse_upincnt_response (const gchar *response,
out: out:
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
return FALSE; return FALSE;
@@ -107,10 +104,10 @@ mm_ublox_parse_uusbconf_response (const gchar *response,
MMUbloxUsbProfile *out_profile, MMUbloxUsbProfile *out_profile,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
MMUbloxUsbProfile profile = MM_UBLOX_USB_PROFILE_UNKNOWN; MMUbloxUsbProfile profile = MM_UBLOX_USB_PROFILE_UNKNOWN;
g_assert (out_profile != NULL); g_assert (out_profile != NULL);
@@ -127,7 +124,7 @@ mm_ublox_parse_uusbconf_response (const gchar *response,
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
if (!inner_error && g_match_info_matches (match_info)) { 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); profile_name = mm_get_string_unquoted_from_match_info (match_info, 2);
if (profile_name && profile_name[0]) { if (profile_name && profile_name[0]) {
@@ -140,12 +137,8 @@ mm_ublox_parse_uusbconf_response (const gchar *response,
"Unknown USB profile: '%s'", profile_name); "Unknown USB profile: '%s'", profile_name);
} else } else
profile = MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE; profile = MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE;
g_free (profile_name);
} }
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
return FALSE; return FALSE;
@@ -169,10 +162,10 @@ mm_ublox_parse_ubmconf_response (const gchar *response,
MMUbloxNetworkingMode *out_mode, MMUbloxNetworkingMode *out_mode,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
MMUbloxNetworkingMode mode = MM_UBLOX_NETWORKING_MODE_UNKNOWN; MMUbloxNetworkingMode mode = MM_UBLOX_NETWORKING_MODE_UNKNOWN;
g_assert (out_mode != NULL); g_assert (out_mode != NULL);
@@ -203,9 +196,6 @@ mm_ublox_parse_ubmconf_response (const gchar *response,
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
return FALSE; return FALSE;
@@ -234,15 +224,15 @@ mm_ublox_parse_uipaddr_response (const gchar *response,
gchar **out_ipv6_link_local_address, gchar **out_ipv6_link_local_address,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
guint cid = 0; guint cid = 0;
gchar *if_name = NULL; gchar *if_name = NULL;
gchar *ipv4_address = NULL; gchar *ipv4_address = NULL;
gchar *ipv4_subnet = NULL; gchar *ipv4_subnet = NULL;
gchar *ipv6_global_address = NULL; gchar *ipv6_global_address = NULL;
gchar *ipv6_link_local_address = NULL; gchar *ipv6_link_local_address = NULL;
/* Response may be e.g.: /* Response may be e.g.:
* +UIPADDR: 1,"ccinet0","5.168.120.13","255.255.255.0","","" * +UIPADDR: 1,"ccinet0","5.168.120.13","255.255.255.0","",""
@@ -288,10 +278,6 @@ mm_ublox_parse_uipaddr_response (const gchar *response,
ipv6_link_local_address = mm_get_string_unquoted_from_match_info (match_info, 6); ipv6_link_local_address = mm_get_string_unquoted_from_match_info (match_info, 6);
out: out:
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_free (if_name); g_free (if_name);
g_free (ipv4_address); g_free (ipv4_address);
@@ -1550,11 +1536,11 @@ GArray *
mm_ublox_parse_uact_response (const gchar *response, mm_ublox_parse_uact_response (const gchar *response,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
GArray *nums = NULL; GArray *nums = NULL;
GArray *bands = NULL; GArray *bands = NULL;
/* /*
* AT+UACT? * AT+UACT?
@@ -1566,16 +1552,12 @@ mm_ublox_parse_uact_response (const gchar *response,
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
if (!inner_error && g_match_info_matches (match_info)) { 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); bandstr = mm_get_string_unquoted_from_match_info (match_info, 4);
nums = mm_parse_uint_list (bandstr, &inner_error); nums = mm_parse_uint_list (bandstr, &inner_error);
g_free (bandstr);
} }
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
return NULL; return NULL;
@@ -1632,16 +1614,16 @@ mm_ublox_parse_uact_test (const gchar *response,
GArray **bands4g_out, GArray **bands4g_out,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; g_auto(GStrv) split = NULL;
const gchar *bands2g_str = NULL; GError *inner_error = NULL;
const gchar *bands3g_str = NULL; const gchar *bands2g_str = NULL;
const gchar *bands4g_str = NULL; const gchar *bands3g_str = NULL;
GArray *bands2g = NULL; const gchar *bands4g_str = NULL;
GArray *bands3g = NULL; GArray *bands2g = NULL;
GArray *bands4g = NULL; GArray *bands3g = NULL;
gchar **split = NULL; GArray *bands4g = NULL;
g_assert (bands2g_out && bands3g_out && bands4g_out); g_assert (bands2g_out && bands3g_out && bands4g_out);
@@ -1658,8 +1640,8 @@ mm_ublox_parse_uact_test (const gchar *response,
goto out; goto out;
if (g_match_info_matches (match_info)) { if (g_match_info_matches (match_info)) {
gchar *aux; g_autofree gchar *aux = NULL;
guint n_groups; guint n_groups;
aux = mm_get_string_unquoted_from_match_info (match_info, 4); aux = mm_get_string_unquoted_from_match_info (match_info, 4);
split = mm_split_string_groups (aux); split = mm_split_string_groups (aux);
@@ -1670,7 +1652,6 @@ mm_ublox_parse_uact_test (const gchar *response,
bands3g_str = split[1]; bands3g_str = split[1];
if (n_groups >= 3) if (n_groups >= 3)
bands4g_str = split[2]; bands4g_str = split[2];
g_free (aux);
} }
if (!bands2g_str && !bands3g_str && !bands4g_str) { if (!bands2g_str && !bands3g_str && !bands4g_str) {
@@ -1692,10 +1673,6 @@ mm_ublox_parse_uact_test (const gchar *response,
/* success */ /* success */
out: out:
g_strfreev (split);
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
if (bands2g) if (bands2g)
g_array_unref (bands2g); g_array_unref (bands2g);
@@ -1760,13 +1737,13 @@ mm_ublox_parse_urat_read_response (const gchar *response,
MMModemMode *out_preferred, MMModemMode *out_preferred,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
MMModemMode allowed = MM_MODEM_MODE_NONE; MMModemMode allowed = MM_MODEM_MODE_NONE;
MMModemMode preferred = MM_MODEM_MODE_NONE; MMModemMode preferred = MM_MODEM_MODE_NONE;
gchar *allowed_str = NULL; g_autofree gchar *allowed_str = NULL;
gchar *preferred_str = NULL; g_autofree gchar *preferred_str = NULL;
g_assert (out_allowed != NULL && out_preferred != NULL); g_assert (out_allowed != NULL && out_preferred != NULL);
@@ -1821,13 +1798,6 @@ mm_ublox_parse_urat_read_response (const gchar *response,
} }
out: out:
g_free (allowed_str);
g_free (preferred_str);
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
return FALSE; return FALSE;
@@ -1981,14 +1951,14 @@ mm_ublox_parse_ugcntrd_response_for_cid (const gchar *response,
guint64 *out_total_rx_bytes, guint64 *out_total_rx_bytes,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
guint64 session_tx_bytes = 0; guint64 session_tx_bytes = 0;
guint64 session_rx_bytes = 0; guint64 session_rx_bytes = 0;
guint64 total_tx_bytes = 0; guint64 total_tx_bytes = 0;
guint64 total_rx_bytes = 0; guint64 total_rx_bytes = 0;
gboolean matched = FALSE; gboolean matched = FALSE;
/* Response may be e.g.: /* Response may be e.g.:
* +UGCNTRD: 31,2704,1819,2724,1839 * +UGCNTRD: 31,2704,1819,2724,1839
@@ -2044,10 +2014,6 @@ mm_ublox_parse_ugcntrd_response_for_cid (const gchar *response,
} }
out: out:
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
return FALSE; return FALSE;
+9 -13
View File
@@ -153,7 +153,7 @@ get_detailed_registration_state_finish (MMIfaceModemCdma *self,
MMModemCdmaRegistrationState *detailed_evdo_state, MMModemCdmaRegistrationState *detailed_evdo_state,
GError **error) GError **error)
{ {
DetailedRegistrationStateResults *results; g_autofree DetailedRegistrationStateResults *results = NULL;
results = g_task_propagate_pointer (G_TASK (res), error); results = g_task_propagate_pointer (G_TASK (res), error);
if (!results) if (!results)
@@ -161,7 +161,6 @@ get_detailed_registration_state_finish (MMIfaceModemCdma *self,
*detailed_cdma1x_state = results->detailed_cdma1x_state; *detailed_cdma1x_state = results->detailed_cdma1x_state;
*detailed_evdo_state = results->detailed_evdo_state; *detailed_evdo_state = results->detailed_evdo_state;
g_free (results);
return TRUE; return TRUE;
} }
@@ -171,13 +170,13 @@ sysinfo_ready (MMBaseModem *self,
GTask *task) GTask *task)
{ {
DetailedRegistrationStateResults *ctx; DetailedRegistrationStateResults *ctx;
DetailedRegistrationStateResults *results; g_autofree DetailedRegistrationStateResults *results = NULL;
const gchar *response; const gchar *response;
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
MMModemCdmaRegistrationState reg_state; MMModemCdmaRegistrationState reg_state;
guint val = 0; guint val = 0;
ctx = g_task_get_task_data (task); ctx = g_task_get_task_data (task);
@@ -236,11 +235,8 @@ sysinfo_ready (MMBaseModem *self,
results->detailed_cdma1x_state = reg_state; results->detailed_cdma1x_state = reg_state;
} }
g_match_info_free (match_info);
g_regex_unref (r);
out: out:
g_task_return_pointer (task, results, NULL); g_task_return_pointer (task, g_steal_pointer (&results), g_free);
g_object_unref (task); g_object_unref (task);
} }
+3 -4
View File
@@ -1223,9 +1223,9 @@ modem_power_off (MMIfaceModem *self,
static void static void
setup_ports (MMBroadbandModem *self) setup_ports (MMBroadbandModem *self)
{ {
gpointer parser; gpointer parser;
MMPortSerialAt *primary; MMPortSerialAt *primary;
GRegex *regex; g_autoptr(GRegex) regex = NULL;
/* Call parent's setup ports first always */ /* Call parent's setup ports first always */
MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_wavecom_parent_class)->setup_ports (self); MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_wavecom_parent_class)->setup_ports (self);
@@ -1242,7 +1242,6 @@ setup_ports (MMBroadbandModem *self)
G_REGEX_RAW | G_REGEX_OPTIMIZE, G_REGEX_RAW | G_REGEX_OPTIMIZE,
0, NULL); 0, NULL);
mm_serial_parser_v1_set_custom_regex (parser, regex, 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_port_serial_at_set_response_parser (MM_PORT_SERIAL_AT (primary),
mm_serial_parser_v1_parse, mm_serial_parser_v1_parse,
+6 -11
View File
@@ -120,12 +120,12 @@ load_current_modes_finish (MMIfaceModem *self,
MMModemMode *preferred, MMModemMode *preferred,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
const gchar *response; const gchar *response;
gchar *str; gchar *str;
gint mode = -1; gint mode = -1;
GError *match_error = NULL; GError *match_error = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
if (!response) if (!response)
@@ -143,17 +143,12 @@ load_current_modes_finish (MMIfaceModem *self,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't match +SYSSEL reply: %s", response); "Couldn't match +SYSSEL reply: %s", response);
} }
g_match_info_free (match_info);
g_regex_unref (r);
return FALSE; return FALSE;
} }
str = g_match_info_fetch (match_info, 3); str = g_match_info_fetch (match_info, 3);
mode = atoi (str); mode = atoi (str);
g_free (str); g_free (str);
g_match_info_free (match_info);
g_regex_unref (r);
switch (mode) { switch (mode) {
case 0: case 0:
+21 -30
View File
@@ -364,11 +364,11 @@ mm_xmm_parse_xact_query_response (const gchar *response,
GArray **bands_out, GArray **bands_out,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
GArray *bands = NULL; GArray *bands = NULL;
guint i; guint i;
MMModemModeCombination mode = { MMModemModeCombination mode = {
.allowed = MM_MODEM_MODE_NONE, .allowed = MM_MODEM_MODE_NONE,
@@ -450,9 +450,6 @@ mm_xmm_parse_xact_query_response (const gchar *response,
/* success */ /* success */
out: out:
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
if (bands) if (bands)
g_array_unref (bands); g_array_unref (bands);
@@ -609,17 +606,17 @@ mm_xmm_parse_xcesq_query_response (const gchar *response,
gint *out_rssnr, gint *out_rssnr,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
guint rxlev = 99; guint rxlev = 99;
guint ber = 99; guint ber = 99;
guint rscp = 255; guint rscp = 255;
guint ecn0 = 255; guint ecn0 = 255;
guint rsrq = 255; guint rsrq = 255;
guint rsrp = 255; guint rsrp = 255;
gint rssnr = 255; gint rssnr = 255;
gboolean success = FALSE; gboolean success = FALSE;
g_assert (out_rxlev); g_assert (out_rxlev);
g_assert (out_ber); g_assert (out_ber);
@@ -672,9 +669,6 @@ mm_xmm_parse_xcesq_query_response (const gchar *response,
} }
out: out:
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
return FALSE; return FALSE;
@@ -959,11 +953,11 @@ mm_xmm_parse_xlcsslp_query_response (const gchar *response,
gchar **supl_address, gchar **supl_address,
GError **error) GError **error)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
gchar *address = NULL; gchar *address = NULL;
guint port = 0; guint port = 0;
/* /*
* E.g.: * E.g.:
@@ -996,9 +990,6 @@ mm_xmm_parse_xlcsslp_query_response (const gchar *response,
} }
out: out:
g_match_info_free (match_info);
g_regex_unref (r);
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
return FALSE; return FALSE;
+10 -18
View File
@@ -339,22 +339,20 @@ load_current_modes_finish (MMIfaceModem *self,
MMModemMode *preferred, MMModemMode *preferred,
GError **error) GError **error)
{ {
const gchar *response; const gchar *response;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GRegex *r; g_autoptr(GRegex) r = NULL;
gint cm_mode = -1; gint cm_mode = -1;
gint pref_acq = -1; gint pref_acq = -1;
gboolean result; GError *match_error = NULL;
GError *match_error = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
if (!response) if (!response)
return FALSE; 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); g_assert (r != NULL);
result = FALSE;
if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)) { if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)) {
if (match_error) if (match_error)
g_propagate_error (error, match_error); g_propagate_error (error, match_error);
@@ -364,7 +362,7 @@ load_current_modes_finish (MMIfaceModem *self,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't parse +ZSNT response: '%s'", "Couldn't parse +ZSNT response: '%s'",
response); response);
goto done; return FALSE;
} }
if (!mm_get_int_from_match_info (match_info, 1, &cm_mode) || if (!mm_get_int_from_match_info (match_info, 1, &cm_mode) ||
@@ -376,11 +374,10 @@ load_current_modes_finish (MMIfaceModem *self,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Failed to parse the allowed mode response: '%s'", "Failed to parse the allowed mode response: '%s'",
response); response);
goto done; return FALSE;
} }
/* Correctly parsed! */ /* Correctly parsed! */
result = TRUE;
if (cm_mode == 0) { if (cm_mode == 0) {
/* Both 2G, 3G and LTE allowed. For LTE modems, no 2G/3G preference supported. */ /* 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)) { if (pref_acq == 0 || mm_iface_modem_is_3gpp_lte (self)) {
@@ -410,12 +407,7 @@ load_current_modes_finish (MMIfaceModem *self,
} else } else
g_assert_not_reached (); g_assert_not_reached ();
done: return TRUE;
g_match_info_free (match_info);
if (r)
g_regex_unref (r);
return result;
} }
static void static void
+63 -126
View File
@@ -3169,9 +3169,9 @@ static void
set_cgev_unsolicited_events_handlers (MMBroadbandModem *self, set_cgev_unsolicited_events_handlers (MMBroadbandModem *self,
gboolean enable) gboolean enable)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GRegex *cgev_regex; g_autoptr(GRegex) cgev_regex = NULL;
guint i; guint i;
cgev_regex = mm_3gpp_cgev_regex_get (); cgev_regex = mm_3gpp_cgev_regex_get ();
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
@@ -3193,8 +3193,6 @@ set_cgev_unsolicited_events_handlers (MMBroadbandModem *self,
enable ? self : NULL, enable ? self : NULL,
NULL); NULL);
} }
g_regex_unref (cgev_regex);
} }
static void static void
@@ -3245,9 +3243,9 @@ static void
set_ciev_unsolicited_events_handlers (MMBroadbandModem *self, set_ciev_unsolicited_events_handlers (MMBroadbandModem *self,
gboolean enable) gboolean enable)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GRegex *ciev_regex; g_autoptr(GRegex) ciev_regex = NULL;
guint i; guint i;
ciev_regex = mm_3gpp_ciev_regex_get (); ciev_regex = mm_3gpp_ciev_regex_get ();
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
@@ -3269,8 +3267,6 @@ set_ciev_unsolicited_events_handlers (MMBroadbandModem *self,
enable ? self : NULL, enable ? self : NULL,
NULL); NULL);
} }
g_regex_unref (ciev_regex);
} }
static void static void
@@ -5160,20 +5156,20 @@ registration_status_check_ready (MMBroadbandModem *self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
g_autoptr(GMatchInfo) match_info = NULL;
RunRegistrationChecksContext *ctx; RunRegistrationChecksContext *ctx;
const gchar *response; const gchar *response;
GError *error = NULL; GError *error = NULL;
GMatchInfo *match_info = NULL; guint i;
guint i; gboolean parsed;
gboolean parsed; gboolean cgreg = FALSE;
gboolean cgreg = FALSE; gboolean cereg = FALSE;
gboolean cereg = FALSE; gboolean c5greg = FALSE;
gboolean c5greg = FALSE; MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN;
MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; gulong lac = 0;
gulong lac = 0; gulong tac = 0;
gulong tac = 0; gulong cid = 0;
gulong cid = 0;
ctx = g_task_get_task_data (task); ctx = g_task_get_task_data (task);
@@ -5205,8 +5201,7 @@ registration_status_check_ready (MMBroadbandModem *self,
0, 0,
&match_info)) &match_info))
break; break;
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
match_info = NULL;
} }
if (!match_info) { if (!match_info) {
@@ -5229,7 +5224,6 @@ registration_status_check_ready (MMBroadbandModem *self,
&cereg, &cereg,
&c5greg, &c5greg,
&error); &error);
g_match_info_free (match_info);
if (!parsed) { if (!parsed) {
if (!error) if (!error)
@@ -6306,10 +6300,10 @@ set_unsolicited_result_code_handlers (MMIfaceModem3gppUssd *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GRegex *cusd_regex; g_autoptr(GRegex) cusd_regex = NULL;
guint i; guint i;
GTask *task; GTask *task;
cusd_regex = mm_3gpp_cusd_regex_get (); cusd_regex = mm_3gpp_cusd_regex_get ();
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
@@ -6331,8 +6325,6 @@ set_unsolicited_result_code_handlers (MMIfaceModem3gppUssd *self,
NULL); NULL);
} }
g_regex_unref (cusd_regex);
task = g_task_new (self, NULL, callback, user_data); task = g_task_new (self, NULL, callback, user_data);
g_task_return_boolean (task, TRUE); g_task_return_boolean (task, TRUE);
g_object_unref (task); g_object_unref (task);
@@ -7233,11 +7225,11 @@ set_messaging_unsolicited_events_handlers (MMIfaceModemMessaging *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GRegex *cmti_regex; g_autoptr(GRegex) cmti_regex = NULL;
GRegex *cds_regex; g_autoptr(GRegex) cds_regex = NULL;
guint i; guint i;
GTask *task; GTask *task;
cmti_regex = mm_3gpp_cmti_regex_get (); cmti_regex = mm_3gpp_cmti_regex_get ();
cds_regex = mm_3gpp_cds_regex_get (); cds_regex = mm_3gpp_cds_regex_get ();
@@ -7267,9 +7259,6 @@ set_messaging_unsolicited_events_handlers (MMIfaceModemMessaging *self,
NULL); NULL);
} }
g_regex_unref (cmti_regex);
g_regex_unref (cds_regex);
task = g_task_new (self, NULL, callback, user_data); task = g_task_new (self, NULL, callback, user_data);
g_task_return_boolean (task, TRUE); g_task_return_boolean (task, TRUE);
g_object_unref (task); g_object_unref (task);
@@ -7486,11 +7475,11 @@ sms_text_part_list_ready (MMBroadbandModem *self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
ListPartsContext *ctx; ListPartsContext *ctx;
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
const gchar *response; const gchar *response;
GError *error = NULL; GError *error = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error) { if (error) {
@@ -7510,8 +7499,6 @@ sms_text_part_list_ready (MMBroadbandModem *self,
MM_CORE_ERROR_INVALID_ARGS, MM_CORE_ERROR_INVALID_ARGS,
"Couldn't parse SMS list response"); "Couldn't parse SMS list response");
g_object_unref (task); g_object_unref (task);
g_match_info_free (match_info);
g_regex_unref (r);
return; return;
} }
@@ -7597,8 +7584,6 @@ sms_text_part_list_ready (MMBroadbandModem *self,
next: next:
g_match_info_next (match_info, NULL); g_match_info_next (match_info, NULL);
} }
g_match_info_free (match_info);
g_regex_unref (r);
/* We consider all done */ /* We consider all done */
g_task_return_boolean (task, TRUE); g_task_return_boolean (task, TRUE);
@@ -7929,9 +7914,9 @@ set_voice_in_call_unsolicited_events_handlers (MMBroadbandModem *self,
PortsContext *ports_ctx, PortsContext *ports_ctx,
gboolean enable) gboolean enable)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GRegex *in_call_event_regex; g_autoptr(GRegex) in_call_event_regex = NULL;
guint i; guint i;
in_call_event_regex = g_regex_new ("\\r\\n(NO CARRIER|BUSY|NO ANSWER|NO DIALTONE)(\\r)?\\r\\n$", 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); G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
@@ -7954,8 +7939,6 @@ set_voice_in_call_unsolicited_events_handlers (MMBroadbandModem *self,
enable ? self : NULL, enable ? self : NULL,
NULL); NULL);
} }
g_regex_unref (in_call_event_regex);
} }
static void static void
@@ -8146,13 +8129,13 @@ set_voice_unsolicited_events_handlers (MMIfaceModemVoice *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GRegex *cring_regex; g_autoptr(GRegex) cring_regex = NULL;
GRegex *ring_regex; g_autoptr(GRegex) ring_regex = NULL;
GRegex *clip_regex; g_autoptr(GRegex) clip_regex = NULL;
GRegex *ccwa_regex; g_autoptr(GRegex) ccwa_regex = NULL;
guint i; guint i;
GTask *task; GTask *task;
cring_regex = mm_voice_cring_regex_get (); cring_regex = mm_voice_cring_regex_get ();
ring_regex = mm_voice_ring_regex_get (); ring_regex = mm_voice_ring_regex_get ();
@@ -8196,11 +8179,6 @@ set_voice_unsolicited_events_handlers (MMIfaceModemVoice *self,
NULL); 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); task = g_task_new (self, NULL, callback, user_data);
g_task_return_boolean (task, TRUE); g_task_return_boolean (task, TRUE);
g_object_unref (task); g_object_unref (task);
@@ -9264,8 +9242,8 @@ css_query_ready (MMIfaceModemCdma *self,
band = 'Z'; band = 'Z';
success = TRUE; success = TRUE;
} else { } else {
GRegex *r; g_autoptr(GRegex) r = NULL;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
/* Format is "<band_class>,<band>,<sid>" */ /* Format is "<band_class>,<band>,<sid>" */
r = g_regex_new ("\\s*([^,]*?)\\s*,\\s*([^,]*?)\\s*,\\s*(\\d+)", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); r = g_regex_new ("\\s*([^,]*?)\\s*,\\s*([^,]*?)\\s*,\\s*(\\d+)", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
@@ -9296,9 +9274,6 @@ css_query_ready (MMIfaceModemCdma *self,
success = TRUE; success = TRUE;
} }
g_match_info_free (match_info);
g_regex_unref (r);
} }
if (!success) { if (!success) {
@@ -10914,10 +10889,13 @@ static const gchar *secondary_init_sequence[] = {
static void static void
setup_ports (MMBroadbandModem *self) setup_ports (MMBroadbandModem *self)
{ {
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GRegex *regex; g_autoptr(GRegex) ciev_regex = NULL;
GPtrArray *array; g_autoptr(GRegex) cmti_regex = NULL;
guint i, j; 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[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
@@ -10933,64 +10911,23 @@ setup_ports (MMBroadbandModem *self)
NULL); NULL);
/* Cleanup all unsolicited message handlers in all AT ports */ /* 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); 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++) { for (i = 0; i < 2; i++) {
if (!ports[i]) if (!ports[i])
continue; continue;
for (j = 0; j < array->len; j++) { for (j = 0; j < array->len; j++)
mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), (GRegex *)g_ptr_array_index (array, j), NULL, NULL, NULL);
(GRegex *)g_ptr_array_index (array, j), mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), ciev_regex, NULL, NULL, NULL);
NULL, mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), cmti_regex, NULL, NULL, NULL);
NULL, mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), cusd_regex, NULL, NULL, NULL);
NULL);
}
} }
mm_3gpp_creg_regex_destroy (array); 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);
} }
/*****************************************************************************/ /*****************************************************************************/
+210 -324
View File
File diff suppressed because it is too large Load Diff
+4 -7
View File
@@ -269,8 +269,8 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response)
for (iter = self->priv->unsolicited_msg_handlers; iter; iter = iter->next) { for (iter = self->priv->unsolicited_msg_handlers; iter; iter = iter->next) {
MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data; MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data;
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
gboolean matches; gboolean matches;
if (!handler->enable) if (!handler->enable)
continue; continue;
@@ -286,12 +286,10 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response)
} }
} }
g_match_info_free (match_info);
if (matches) { if (matches) {
/* Remove matches */ /* Remove matches */
char *str; g_autofree gchar *str = NULL;
int result_len = response->len; gint result_len = response->len;
str = g_regex_replace_eval (handler->regex, str = g_regex_replace_eval (handler->regex,
(const char *) response->data, (const char *) response->data,
@@ -301,7 +299,6 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response)
g_byte_array_remove_range (response, 0, response->len); g_byte_array_remove_range (response, 0, response->len);
g_byte_array_append (response, (const guint8 *) str, result_len); g_byte_array_append (response, (const guint8 *) str, result_len);
g_free (str);
} }
} }
} }
+6 -8
View File
@@ -74,12 +74,12 @@ parse_response (MMPortSerial *port,
GByteArray **parsed_response, GByteArray **parsed_response,
GError **error) GError **error)
{ {
MMPortSerialGps *self = MM_PORT_SERIAL_GPS (port); MMPortSerialGps *self = MM_PORT_SERIAL_GPS (port);
gboolean matches; g_autoptr(GMatchInfo) match_info = NULL;
GMatchInfo *match_info; gboolean matches;
gchar *str; gchar *str;
gint result_len; gint result_len;
guint i; guint i;
for (i = 0; i < response->len; i++) { for (i = 0; i < response->len; i++) {
/* If there is any content before the first $, /* If there is any content before the first $,
@@ -110,8 +110,6 @@ parse_response (MMPortSerial *port,
} }
} }
g_match_info_free (match_info);
if (!matches) if (!matches)
return MM_PORT_SERIAL_RESPONSE_NONE; return MM_PORT_SERIAL_RESPONSE_NONE;
+11 -10
View File
@@ -167,7 +167,7 @@ mm_serial_parser_v1_parse (gpointer data,
GError **error) GError **error)
{ {
MMSerialParserV1 *parser = (MMSerialParserV1 *) data; MMSerialParserV1 *parser = (MMSerialParserV1 *) data;
GMatchInfo *match_info; GMatchInfo *match_info = NULL;
GError *local_error = NULL; GError *local_error = NULL;
gboolean found = FALSE; gboolean found = FALSE;
char *str = NULL; char *str = NULL;
@@ -242,7 +242,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object); local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object);
goto done; goto done;
} }
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
} }
/* Numeric CME errors */ /* Numeric CME errors */
@@ -255,7 +255,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object); local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object);
goto done; goto done;
} }
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
/* Numeric CMS errors */ /* Numeric CMS errors */
found = g_regex_match_full (parser->regex_cms_error, found = g_regex_match_full (parser->regex_cms_error,
@@ -267,7 +267,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_message_error_for_code (atoi (str), log_object); local_error = mm_message_error_for_code (atoi (str), log_object);
goto done; goto done;
} }
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
/* String CME errors */ /* String CME errors */
found = g_regex_match_full (parser->regex_cme_error_str, found = g_regex_match_full (parser->regex_cme_error_str,
@@ -279,7 +279,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_string (str, log_object); local_error = mm_mobile_equipment_error_for_string (str, log_object);
goto done; goto done;
} }
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
/* String CMS errors */ /* String CMS errors */
found = g_regex_match_full (parser->regex_cms_error_str, found = g_regex_match_full (parser->regex_cms_error_str,
@@ -291,7 +291,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_message_error_for_string (str, log_object); local_error = mm_message_error_for_string (str, log_object);
goto done; goto done;
} }
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
/* Motorola EZX errors */ /* Motorola EZX errors */
found = g_regex_match_full (parser->regex_ezx_error, found = g_regex_match_full (parser->regex_ezx_error,
@@ -303,7 +303,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object); local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object);
goto done; goto done;
} }
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
/* Last resort; unknown error */ /* Last resort; unknown error */
found = g_regex_match_full (parser->regex_unknown_error, found = g_regex_match_full (parser->regex_unknown_error,
@@ -313,7 +313,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object); local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object);
goto done; goto done;
} }
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
/* Connection failures */ /* Connection failures */
found = g_regex_match_full (parser->regex_connect_failed, found = g_regex_match_full (parser->regex_connect_failed,
@@ -341,7 +341,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_connection_error_for_code (code, log_object); local_error = mm_connection_error_for_code (code, log_object);
goto done; goto done;
} }
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
/* NA error */ /* NA error */
found = g_regex_match_full (parser->regex_na, found = g_regex_match_full (parser->regex_na,
@@ -357,7 +357,8 @@ mm_serial_parser_v1_parse (gpointer data,
done: done:
g_free (str); g_free (str);
g_match_info_free (match_info); g_clear_pointer (&match_info, g_match_info_free);
if (found) if (found)
response_clean (response); response_clean (response);
+29 -43
View File
@@ -1129,15 +1129,19 @@ test_creg_match (const char *test,
RegTestData *data, RegTestData *data,
const CregResult *result) const CregResult *result)
{ {
guint i; g_autoptr(GMatchInfo) info = NULL;
GMatchInfo *info = NULL; guint i;
MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN;
MMModemAccessTechnology access_tech = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; MMModemAccessTechnology access_tech = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
gulong lac = 0, ci = 0; gulong lac = 0;
GError *error = NULL; gulong ci = 0;
gboolean success, cgreg = FALSE, cereg = FALSE, c5greg = FALSE; GError *error = NULL;
guint regex_num = 0; gboolean success;
GPtrArray *array; gboolean cgreg = FALSE;
gboolean cereg = FALSE;
gboolean c5greg = FALSE;
guint regex_num = 0;
GPtrArray *array;
g_assert (reply); g_assert (reply);
g_assert (test); g_assert (test);
@@ -1158,8 +1162,7 @@ test_creg_match (const char *test,
regex_num = i; regex_num = i;
break; break;
} }
g_match_info_free (info); g_clear_pointer (&info, g_match_info_free);
info = NULL;
} }
g_debug (" regex_num (%u) == result->regex_num (%u)", g_debug (" regex_num (%u) == result->regex_num (%u)",
@@ -1171,7 +1174,6 @@ test_creg_match (const char *test,
success = mm_3gpp_parse_creg_response (info, NULL, &state, &lac, &ci, &access_tech, &cgreg, &cereg, &c5greg, &error); 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 (success);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpuint (state, ==, result->state); g_assert_cmpuint (state, ==, result->state);
@@ -3351,10 +3353,10 @@ common_parse_cds (const gchar *str,
guint expected_pdu_len, guint expected_pdu_len,
const gchar *expected_pdu) const gchar *expected_pdu)
{ {
GMatchInfo *match_info; g_autoptr(GMatchInfo) match_info = NULL;
GRegex *regex; g_autoptr(GRegex) regex = NULL;
gchar *pdu_len_str; g_autofree gchar *pdu_len_str = NULL;
gchar *pdu; g_autofree gchar *pdu = NULL;
regex = mm_3gpp_cds_regex_get (); regex = mm_3gpp_cds_regex_get ();
g_regex_match (regex, str, 0, &match_info); g_regex_match (regex, str, 0, &match_info);
@@ -3368,12 +3370,6 @@ common_parse_cds (const gchar *str,
g_assert (pdu != NULL); g_assert (pdu != NULL);
g_assert_cmpstr (pdu, ==, expected_pdu); 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 static void
@@ -4143,15 +4139,15 @@ static const ClipUrcTest clip_urc_tests[] = {
static void static void
test_clip_indication (void) test_clip_indication (void)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
guint i; guint i;
r = mm_voice_clip_regex_get (); r = mm_voice_clip_regex_get ();
for (i = 0; i < G_N_ELEMENTS (clip_urc_tests); i++) { for (i = 0; i < G_N_ELEMENTS (clip_urc_tests); i++) {
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
gchar *number; g_autofree gchar *number = NULL;
guint type; guint type;
g_assert (g_regex_match (r, clip_urc_tests[i].str, 0, &match_info)); g_assert (g_regex_match (r, clip_urc_tests[i].str, 0, &match_info));
g_assert (g_match_info_matches (match_info)); g_assert (g_match_info_matches (match_info));
@@ -4161,12 +4157,7 @@ test_clip_indication (void)
g_assert (mm_get_uint_from_match_info (match_info, 2, &type)); g_assert (mm_get_uint_from_match_info (match_info, 2, &type));
g_assert_cmpuint (type, ==, clip_urc_tests[i].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 const CcwaUrcTest ccwa_urc_tests[] = {
static void static void
test_ccwa_indication (void) test_ccwa_indication (void)
{ {
GRegex *r; g_autoptr(GRegex) r = NULL;
guint i; guint i;
r = mm_voice_ccwa_regex_get (); r = mm_voice_ccwa_regex_get ();
for (i = 0; i < G_N_ELEMENTS (ccwa_urc_tests); i++) { for (i = 0; i < G_N_ELEMENTS (ccwa_urc_tests); i++) {
GMatchInfo *match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
gchar *number; g_autofree gchar *number = NULL;
guint type; guint type;
guint class; guint class;
g_assert (g_regex_match (r, ccwa_urc_tests[i].str, 0, &match_info)); g_assert (g_regex_match (r, ccwa_urc_tests[i].str, 0, &match_info));
g_assert (g_match_info_matches (match_info)); g_assert (g_match_info_matches (match_info));
@@ -4210,12 +4201,7 @@ test_ccwa_indication (void)
g_assert (mm_get_uint_from_match_info (match_info, 3, &class)); g_assert (mm_get_uint_from_match_info (match_info, 3, &class));
g_assert_cmpuint (class, ==, ccwa_urc_tests[i].class); g_assert_cmpuint (class, ==, ccwa_urc_tests[i].class);
g_free (number);
g_match_info_free (match_info);
} }
g_regex_unref (r);
} }
/*****************************************************************************/ /*****************************************************************************/