diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-broadband-modem.c | 187 | ||||
-rw-r--r-- | src/mm-modem-helpers.c | 538 | ||||
-rw-r--r-- | src/mm-port-serial-at.c | 11 | ||||
-rw-r--r-- | src/mm-port-serial-gps.c | 14 | ||||
-rw-r--r-- | src/mm-serial-parsers.c | 21 | ||||
-rw-r--r-- | src/tests/test-modem-helpers.c | 72 |
6 files changed, 324 insertions, 519 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index c30021cb..12b77649 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -3169,9 +3169,9 @@ static void set_cgev_unsolicited_events_handlers (MMBroadbandModem *self, gboolean enable) { - MMPortSerialAt *ports[2]; - GRegex *cgev_regex; - guint i; + MMPortSerialAt *ports[2]; + g_autoptr(GRegex) cgev_regex = NULL; + guint i; cgev_regex = mm_3gpp_cgev_regex_get (); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); @@ -3193,8 +3193,6 @@ set_cgev_unsolicited_events_handlers (MMBroadbandModem *self, enable ? self : NULL, NULL); } - - g_regex_unref (cgev_regex); } static void @@ -3245,9 +3243,9 @@ static void set_ciev_unsolicited_events_handlers (MMBroadbandModem *self, gboolean enable) { - MMPortSerialAt *ports[2]; - GRegex *ciev_regex; - guint i; + MMPortSerialAt *ports[2]; + g_autoptr(GRegex) ciev_regex = NULL; + guint i; ciev_regex = mm_3gpp_ciev_regex_get (); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); @@ -3269,8 +3267,6 @@ set_ciev_unsolicited_events_handlers (MMBroadbandModem *self, enable ? self : NULL, NULL); } - - g_regex_unref (ciev_regex); } static void @@ -5160,20 +5156,20 @@ registration_status_check_ready (MMBroadbandModem *self, GAsyncResult *res, GTask *task) { + g_autoptr(GMatchInfo) match_info = NULL; RunRegistrationChecksContext *ctx; - const gchar *response; - GError *error = NULL; - GMatchInfo *match_info = NULL; - guint i; - gboolean parsed; - gboolean cgreg = FALSE; - gboolean cereg = FALSE; - gboolean c5greg = FALSE; - MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; - MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; - gulong lac = 0; - gulong tac = 0; - gulong cid = 0; + const gchar *response; + GError *error = NULL; + guint i; + gboolean parsed; + gboolean cgreg = FALSE; + gboolean cereg = FALSE; + gboolean c5greg = FALSE; + MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; + MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + gulong lac = 0; + gulong tac = 0; + gulong cid = 0; ctx = g_task_get_task_data (task); @@ -5205,8 +5201,7 @@ registration_status_check_ready (MMBroadbandModem *self, 0, &match_info)) break; - g_match_info_free (match_info); - match_info = NULL; + g_clear_pointer (&match_info, g_match_info_free); } if (!match_info) { @@ -5229,7 +5224,6 @@ registration_status_check_ready (MMBroadbandModem *self, &cereg, &c5greg, &error); - g_match_info_free (match_info); if (!parsed) { if (!error) @@ -6306,10 +6300,10 @@ set_unsolicited_result_code_handlers (MMIfaceModem3gppUssd *self, GAsyncReadyCallback callback, gpointer user_data) { - MMPortSerialAt *ports[2]; - GRegex *cusd_regex; - guint i; - GTask *task; + MMPortSerialAt *ports[2]; + g_autoptr(GRegex) cusd_regex = NULL; + guint i; + GTask *task; cusd_regex = mm_3gpp_cusd_regex_get (); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); @@ -6331,8 +6325,6 @@ set_unsolicited_result_code_handlers (MMIfaceModem3gppUssd *self, NULL); } - g_regex_unref (cusd_regex); - task = g_task_new (self, NULL, callback, user_data); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -7233,11 +7225,11 @@ set_messaging_unsolicited_events_handlers (MMIfaceModemMessaging *self, GAsyncReadyCallback callback, gpointer user_data) { - MMPortSerialAt *ports[2]; - GRegex *cmti_regex; - GRegex *cds_regex; - guint i; - GTask *task; + MMPortSerialAt *ports[2]; + g_autoptr(GRegex) cmti_regex = NULL; + g_autoptr(GRegex) cds_regex = NULL; + guint i; + GTask *task; cmti_regex = mm_3gpp_cmti_regex_get (); cds_regex = mm_3gpp_cds_regex_get (); @@ -7267,9 +7259,6 @@ set_messaging_unsolicited_events_handlers (MMIfaceModemMessaging *self, NULL); } - g_regex_unref (cmti_regex); - g_regex_unref (cds_regex); - task = g_task_new (self, NULL, callback, user_data); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -7486,11 +7475,11 @@ sms_text_part_list_ready (MMBroadbandModem *self, GAsyncResult *res, GTask *task) { - ListPartsContext *ctx; - GRegex *r; - GMatchInfo *match_info = NULL; - const gchar *response; - GError *error = NULL; + ListPartsContext *ctx; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + const gchar *response; + GError *error = NULL; response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (error) { @@ -7510,8 +7499,6 @@ sms_text_part_list_ready (MMBroadbandModem *self, MM_CORE_ERROR_INVALID_ARGS, "Couldn't parse SMS list response"); g_object_unref (task); - g_match_info_free (match_info); - g_regex_unref (r); return; } @@ -7597,8 +7584,6 @@ sms_text_part_list_ready (MMBroadbandModem *self, next: g_match_info_next (match_info, NULL); } - g_match_info_free (match_info); - g_regex_unref (r); /* We consider all done */ g_task_return_boolean (task, TRUE); @@ -7929,9 +7914,9 @@ set_voice_in_call_unsolicited_events_handlers (MMBroadbandModem *self, PortsContext *ports_ctx, gboolean enable) { - MMPortSerialAt *ports[2]; - GRegex *in_call_event_regex; - guint i; + MMPortSerialAt *ports[2]; + g_autoptr(GRegex) in_call_event_regex = NULL; + guint i; in_call_event_regex = g_regex_new ("\\r\\n(NO CARRIER|BUSY|NO ANSWER|NO DIALTONE)(\\r)?\\r\\n$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); @@ -7954,8 +7939,6 @@ set_voice_in_call_unsolicited_events_handlers (MMBroadbandModem *self, enable ? self : NULL, NULL); } - - g_regex_unref (in_call_event_regex); } static void @@ -8146,13 +8129,13 @@ set_voice_unsolicited_events_handlers (MMIfaceModemVoice *self, GAsyncReadyCallback callback, gpointer user_data) { - MMPortSerialAt *ports[2]; - GRegex *cring_regex; - GRegex *ring_regex; - GRegex *clip_regex; - GRegex *ccwa_regex; - guint i; - GTask *task; + MMPortSerialAt *ports[2]; + g_autoptr(GRegex) cring_regex = NULL; + g_autoptr(GRegex) ring_regex = NULL; + g_autoptr(GRegex) clip_regex = NULL; + g_autoptr(GRegex) ccwa_regex = NULL; + guint i; + GTask *task; cring_regex = mm_voice_cring_regex_get (); ring_regex = mm_voice_ring_regex_get (); @@ -8196,11 +8179,6 @@ set_voice_unsolicited_events_handlers (MMIfaceModemVoice *self, NULL); } - g_regex_unref (ccwa_regex); - g_regex_unref (clip_regex); - g_regex_unref (cring_regex); - g_regex_unref (ring_regex); - task = g_task_new (self, NULL, callback, user_data); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -9264,8 +9242,8 @@ css_query_ready (MMIfaceModemCdma *self, band = 'Z'; success = TRUE; } else { - GRegex *r; - GMatchInfo *match_info; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; /* Format is "<band_class>,<band>,<sid>" */ r = g_regex_new ("\\s*([^,]*?)\\s*,\\s*([^,]*?)\\s*,\\s*(\\d+)", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); @@ -9296,9 +9274,6 @@ css_query_ready (MMIfaceModemCdma *self, success = TRUE; } - - g_match_info_free (match_info); - g_regex_unref (r); } if (!success) { @@ -10914,10 +10889,13 @@ static const gchar *secondary_init_sequence[] = { static void setup_ports (MMBroadbandModem *self) { - MMPortSerialAt *ports[2]; - GRegex *regex; - GPtrArray *array; - guint i, j; + MMPortSerialAt *ports[2]; + g_autoptr(GRegex) ciev_regex = NULL; + g_autoptr(GRegex) cmti_regex = NULL; + g_autoptr(GRegex) cusd_regex = NULL; + GPtrArray *array; + guint i; + guint j; ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); @@ -10933,64 +10911,23 @@ setup_ports (MMBroadbandModem *self) NULL); /* Cleanup all unsolicited message handlers in all AT ports */ - - /* Set up CREG unsolicited message handlers, with NULL callbacks */ array = mm_3gpp_creg_regex_get (FALSE); - for (i = 0; i < 2; i++) { - if (!ports[i]) - continue; - - for (j = 0; j < array->len; j++) { - mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), - (GRegex *)g_ptr_array_index (array, j), - NULL, - NULL, - NULL); - } - } - 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); + ciev_regex = mm_3gpp_ciev_regex_get (); + cmti_regex = mm_3gpp_cmti_regex_get (); + cusd_regex = mm_3gpp_cusd_regex_get (); - /* 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); + for (j = 0; j < array->len; j++) + mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), (GRegex *)g_ptr_array_index (array, j), NULL, NULL, NULL); + mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), ciev_regex, NULL, NULL, NULL); + mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), cmti_regex, NULL, NULL, NULL); + mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), cusd_regex, NULL, NULL, NULL); } - 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); + mm_3gpp_creg_regex_destroy (array); } /*****************************************************************************/ diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 5e58ba9d..58207bb1 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -528,10 +528,10 @@ mm_3gpp_parse_clcc_response (const gchar *str, GList **out_list, GError **error) { - GRegex *r; - GList *list = NULL; - GError *inner_error = NULL; - GMatchInfo *match_info = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GList *list = NULL; + GError *inner_error = NULL; static const MMCallDirection call_direction[] = { [0] = MM_CALL_DIRECTION_OUTGOING, @@ -641,9 +641,6 @@ mm_3gpp_parse_clcc_response (const gchar *str, } out: - g_clear_pointer (&match_info, g_match_info_free); - g_regex_unref (r); - if (inner_error) { mm_3gpp_call_info_list_free (list); g_propagate_error (error, inner_error); @@ -736,12 +733,12 @@ mm_parse_ifc_test_response (const gchar *response, gpointer log_object, GError **error) { - GRegex *r; - GError *inner_error = NULL; - GMatchInfo *match_info = NULL; - MMFlowControl te_mask = MM_FLOW_CONTROL_UNKNOWN; - MMFlowControl ta_mask = MM_FLOW_CONTROL_UNKNOWN; - MMFlowControl mask = MM_FLOW_CONTROL_UNKNOWN; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + MMFlowControl te_mask = MM_FLOW_CONTROL_UNKNOWN; + MMFlowControl ta_mask = MM_FLOW_CONTROL_UNKNOWN; + MMFlowControl mask = MM_FLOW_CONTROL_UNKNOWN; r = g_regex_new ("(?:\\+IFC:)?\\s*\\((.*)\\),\\((.*)\\)(?:\\r\\n)?", 0, 0, NULL); g_assert (r != NULL); @@ -767,10 +764,6 @@ mm_parse_ifc_test_response (const gchar *response, mask = te_mask & ta_mask; out: - - g_clear_pointer (&match_info, g_match_info_free); - g_regex_unref (r); - if (inner_error) g_propagate_error (error, inner_error); @@ -982,21 +975,21 @@ mm_3gpp_parse_ws46_test_response (const gchar *response, gpointer log_object, GError **error) { - GArray *modes = NULL; - GArray *tech_values = NULL; - GRegex *r; - GError *inner_error = NULL; - GMatchInfo *match_info = NULL; - gchar *full_list = NULL; - guint val; - guint i; - guint j; - gboolean supported_5g = FALSE; - gboolean supported_4g = FALSE; - gboolean supported_3g = FALSE; - gboolean supported_2g = FALSE; - gboolean supported_mode_25 = FALSE; - gboolean supported_mode_29 = FALSE; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GArray *modes = NULL; + GArray *tech_values = NULL; + GError *inner_error = NULL; + gchar *full_list = NULL; + guint val; + guint i; + guint j; + gboolean supported_5g = FALSE; + gboolean supported_4g = FALSE; + gboolean supported_3g = FALSE; + gboolean supported_2g = FALSE; + gboolean supported_mode_25 = FALSE; + gboolean supported_mode_29 = FALSE; r = g_regex_new ("(?:\\+WS46:)?\\s*\\((.*)\\)(?:\\r\\n)?", 0, 0, NULL); g_assert (r != NULL); @@ -1095,9 +1088,6 @@ out: g_free (full_list); - g_clear_pointer (&match_info, g_match_info_free); - g_regex_unref (r); - if (inner_error) { g_propagate_error (error, inner_error); return NULL; @@ -1190,10 +1180,10 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, gpointer log_object, GError **error) { - GRegex *r; - GList *info_list = NULL; - GMatchInfo *match_info; - gboolean umts_format = TRUE; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GList *info_list = NULL; + gboolean umts_format = TRUE; g_return_val_if_fail (reply != NULL, NULL); if (error) @@ -1227,9 +1217,8 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, /* If we didn't get any hits, try the pre-UMTS format match */ if (!g_regex_match (r, reply, 0, &match_info)) { - g_regex_unref (r); - g_match_info_free (match_info); - match_info = NULL; + g_clear_pointer (&r, g_regex_unref); + g_clear_pointer (&match_info, g_match_info_free); /* Pre-UMTS format doesn't include the cell access technology after * the numeric operator element. @@ -1320,9 +1309,6 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, g_match_info_next (match_info, NULL); } - g_match_info_free (match_info); - g_regex_unref (r); - return info_list; } @@ -1337,14 +1323,14 @@ mm_3gpp_parse_cops_read_response (const gchar *response, gpointer log_object, GError **error) { - GRegex *r; - GMatchInfo *match_info; - GError *inner_error = NULL; - guint mode = 0; - guint format = 0; - gchar *operator = NULL; - guint actval = 0; - MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + guint mode = 0; + guint format = 0; + gchar *operator = NULL; + guint actval = 0; + MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; g_assert (out_mode || out_format || out_operator || out_act); @@ -1390,9 +1376,6 @@ mm_3gpp_parse_cops_read_response (const gchar *response, } out: - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { g_free (operator); g_propagate_error (error, inner_error); @@ -1725,10 +1708,10 @@ mm_3gpp_parse_cgdcont_test_response (const gchar *response, gpointer log_object, GError **error) { - GRegex *r; - GMatchInfo *match_info; - GError *inner_error = NULL; - GList *list = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + GList *list = NULL; if (!response || !g_str_has_prefix (response, "+CGDCONT:")) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing +CGDCONT prefix"); @@ -1776,9 +1759,6 @@ mm_3gpp_parse_cgdcont_test_response (const gchar *response, g_match_info_next (match_info, &inner_error); } - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { mm_obj_warn (log_object, "unexpected error matching +CGDCONT response: '%s'", inner_error->message); g_error_free (inner_error); @@ -1813,52 +1793,46 @@ GList * mm_3gpp_parse_cgdcont_read_response (const gchar *reply, GError **error) { - GError *inner_error = NULL; - GRegex *r; - GMatchInfo *match_info; - GList *list; + GError *inner_error = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GList *list = NULL; if (!reply || !reply[0]) /* No APNs configured, all done */ return NULL; - list = NULL; r = g_regex_new ("\\+CGDCONT:\\s*(\\d+)\\s*,([^, \\)]*)\\s*,([^, \\)]*)\\s*,([^, \\)]*)", G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, - 0, &inner_error); - if (r) { - g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, &inner_error); - - while (!inner_error && - g_match_info_matches (match_info)) { - gchar *str; - MMBearerIpFamily ip_family; - - str = mm_get_string_unquoted_from_match_info (match_info, 2); - ip_family = mm_3gpp_get_ip_family_from_pdp_type (str); - if (ip_family != MM_BEARER_IP_FAMILY_NONE) { - MM3gppPdpContext *pdp; - - pdp = g_slice_new0 (MM3gppPdpContext); - if (!mm_get_uint_from_match_info (match_info, 1, &pdp->cid)) { - inner_error = g_error_new (MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't parse CID from reply: '%s'", - reply); - break; - } - pdp->pdp_type = ip_family; - pdp->apn = mm_get_string_unquoted_from_match_info (match_info, 3); + 0, NULL); + g_assert (r); - list = g_list_prepend (list, pdp); + g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, &inner_error); + while (!inner_error && g_match_info_matches (match_info)) { + gchar *str; + MMBearerIpFamily ip_family; + + str = mm_get_string_unquoted_from_match_info (match_info, 2); + ip_family = mm_3gpp_get_ip_family_from_pdp_type (str); + if (ip_family != MM_BEARER_IP_FAMILY_NONE) { + MM3gppPdpContext *pdp; + + pdp = g_slice_new0 (MM3gppPdpContext); + if (!mm_get_uint_from_match_info (match_info, 1, &pdp->cid)) { + inner_error = g_error_new (MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't parse CID from reply: '%s'", + reply); + break; } + pdp->pdp_type = ip_family; + pdp->apn = mm_get_string_unquoted_from_match_info (match_info, 3); - g_free (str); - g_match_info_next (match_info, &inner_error); + list = g_list_prepend (list, pdp); } - g_match_info_free (match_info); - g_regex_unref (r); + g_free (str); + g_match_info_next (match_info, &inner_error); } if (inner_error) { @@ -1868,9 +1842,7 @@ mm_3gpp_parse_cgdcont_read_response (const gchar *reply, return NULL; } - list = g_list_sort (list, (GCompareFunc)mm_3gpp_pdp_context_cmp); - - return list; + return g_list_sort (list, (GCompareFunc)mm_3gpp_pdp_context_cmp); } /*************************************************************************/ @@ -1898,16 +1870,15 @@ GList * mm_3gpp_parse_cgact_read_response (const gchar *reply, GError **error) { - GError *inner_error = NULL; - GRegex *r; - GMatchInfo *match_info; - GList *list; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + GList *list = NULL; if (!reply || !reply[0]) /* Nothing configured, all done */ return NULL; - list = NULL; r = g_regex_new ("\\+CGACT:\\s*(\\d+),(\\d+)", G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, &inner_error); g_assert (r); @@ -1941,9 +1912,6 @@ mm_3gpp_parse_cgact_read_response (const gchar *reply, g_match_info_next (match_info, &inner_error); } - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { mm_3gpp_pdp_context_active_list_free (list); g_propagate_error (error, inner_error); @@ -2142,10 +2110,11 @@ mm_3gpp_parse_cmgf_test_response (const gchar *reply, gboolean *sms_text_supported, GError **error) { - GRegex *r; - GMatchInfo *match_info; - gchar *s; - guint32 min = -1, max = -1; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + gchar *s; + guint32 min = -1; + guint32 max = -1; /* Strip whitespace and response tag */ if (g_str_has_prefix (reply, CMGF_TAG)) @@ -2163,8 +2132,6 @@ mm_3gpp_parse_cmgf_test_response (const gchar *reply, MM_CORE_ERROR_FAILED, "Failed to parse CMGF query result '%s'", reply); - g_match_info_free (match_info); - g_regex_unref (r); return FALSE; } @@ -2184,8 +2151,6 @@ mm_3gpp_parse_cmgf_test_response (const gchar *reply, /* CMGF=1 for Text mode */ *sms_text_supported = (max >= 1); - g_match_info_free (match_info); - g_regex_unref (r); return TRUE; } @@ -2196,12 +2161,12 @@ mm_3gpp_parse_cmgr_read_response (const gchar *reply, guint index, GError **error) { - GRegex *r; - GMatchInfo *match_info; - gint count; - gint status; - gchar *pdu; - MM3gppPduInfo *info = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + gint count; + gint status; + gchar *pdu; + MM3gppPduInfo *info = NULL; /* +CMGR: <stat>,<alpha>,<length>(whitespace)<pdu> */ /* The <alpha> and <length> fields are matched, but not currently used */ @@ -2214,7 +2179,7 @@ mm_3gpp_parse_cmgr_read_response (const gchar *reply, MM_CORE_ERROR_FAILED, "Failed to parse CMGR read result: response didn't match '%s'", reply); - goto done; + return NULL; } /* g_match_info_get_match_count includes match #0 */ @@ -2225,7 +2190,7 @@ mm_3gpp_parse_cmgr_read_response (const gchar *reply, "Failed to match CMGR fields (matched %d) '%s'", count, reply); - goto done; + return NULL; } if (!mm_get_int_from_match_info (match_info, 1, &status)) { @@ -2234,7 +2199,7 @@ mm_3gpp_parse_cmgr_read_response (const gchar *reply, MM_CORE_ERROR_FAILED, "Failed to extract CMGR status field '%s'", reply); - goto done; + return NULL; } @@ -2245,18 +2210,13 @@ mm_3gpp_parse_cmgr_read_response (const gchar *reply, MM_CORE_ERROR_FAILED, "Failed to extract CMGR pdu field '%s'", reply); - goto done; + return NULL; } info = g_new0 (MM3gppPduInfo, 1); info->index = index; info->status = status; info->pdu = pdu; - -done: - g_match_info_free (match_info); - g_regex_unref (r); - return info; } @@ -2270,8 +2230,8 @@ mm_3gpp_parse_crsm_response (const gchar *reply, gchar **hex, GError **error) { - GRegex *r; - GMatchInfo *match_info; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; g_assert (sw1 != NULL); g_assert (sw2 != NULL); @@ -2292,11 +2252,9 @@ mm_3gpp_parse_crsm_response (const gchar *reply, if (g_regex_match (r, reply, 0, &match_info) && mm_get_uint_from_match_info (match_info, 1, sw1) && - mm_get_uint_from_match_info (match_info, 2, sw2)) + mm_get_uint_from_match_info (match_info, 2, sw2)) { *hex = mm_get_string_unquoted_from_match_info (match_info, 3); - - g_match_info_free (match_info); - g_regex_unref (r); + } if (*hex == NULL) { g_set_error (error, @@ -2372,19 +2330,19 @@ mm_3gpp_parse_cgcontrdp_response (const gchar *response, gchar **out_dns_secondary_address, GError **error) { - GRegex *r; - GMatchInfo *match_info; - GError *inner_error = NULL; - guint cid = 0; - guint bearer_id = 0; - gchar *apn = NULL; - gchar *local_address_and_subnet = NULL; - gchar *local_address = NULL; - gchar *subnet = NULL; - gchar *gateway_address = NULL; - gchar *dns_primary_address = NULL; - gchar *dns_secondary_address = NULL; - guint field_format_extra_index = 0; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + guint cid = 0; + guint bearer_id = 0; + gchar *apn = NULL; + gchar *local_address_and_subnet = NULL; + gchar *local_address = NULL; + gchar *subnet = NULL; + gchar *gateway_address = NULL; + gchar *dns_primary_address = NULL; + gchar *dns_secondary_address = NULL; + guint field_format_extra_index = 0; /* Response may be e.g.: * +CGCONTRDP: 4,5,"ibox.tim.it.mnc001.mcc222.gprs","2.197.17.49.255.255.255.255","2.197.17.49","10.207.43.46","10.206.56.132","0.0.0.0","0.0.0.0",0 @@ -2462,9 +2420,6 @@ mm_3gpp_parse_cgcontrdp_response (const gchar *response, dns_secondary_address = mm_get_string_unquoted_from_match_info (match_info, 7 + field_format_extra_index); out: - g_match_info_free (match_info); - g_regex_unref (r); - g_free (local_address_and_subnet); if (inner_error) { @@ -2513,10 +2468,10 @@ mm_3gpp_parse_cfun_query_response (const gchar *response, guint *out_state, GError **error) { - GRegex *r; - GMatchInfo *match_info; - GError *inner_error = NULL; - guint state = G_MAXUINT; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + guint state = G_MAXUINT; g_assert (out_state != NULL); @@ -2546,9 +2501,6 @@ mm_3gpp_parse_cfun_query_response (const gchar *response, *out_state = state; out: - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { g_propagate_error (error, inner_error); return FALSE; @@ -2570,16 +2522,16 @@ mm_3gpp_parse_cesq_response (const gchar *response, guint *out_rsrp, GError **error) { - GRegex *r; - GMatchInfo *match_info; - GError *inner_error = NULL; - guint rxlev = 99; - guint ber = 99; - guint rscp = 255; - guint ecn0 = 255; - guint rsrq = 255; - guint rsrp = 255; - gboolean success = FALSE; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + guint rxlev = 99; + guint ber = 99; + guint rscp = 255; + guint ecn0 = 255; + guint rsrq = 255; + guint rsrp = 255; + gboolean success = FALSE; g_assert (out_rxlev); g_assert (out_ber); @@ -2624,9 +2576,6 @@ mm_3gpp_parse_cesq_response (const gchar *response, } out: - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { g_propagate_error (error, inner_error); return FALSE; @@ -2883,10 +2832,10 @@ mm_3gpp_parse_ccwa_service_query_response (const gchar *response, gboolean *status, GError **error) { - GRegex *r; - GError *inner_error = NULL; - GMatchInfo *match_info = NULL; - gint class_1_status = -1; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + gint class_1_status = -1; /* * AT+CCWA=<n>[,<mode>] @@ -2928,9 +2877,6 @@ mm_3gpp_parse_ccwa_service_query_response (const gchar *response, } out: - g_clear_pointer (&match_info, g_match_info_free); - g_regex_unref (r); - if (inner_error) { g_propagate_error (error, inner_error); return FALSE; @@ -3035,8 +2981,8 @@ mm_3gpp_parse_cpms_test_response (const gchar *reply, g_assert (r); for (i = 0; i < N_EXPECTED_GROUPS; i++) { - GMatchInfo *match_info = NULL; - GArray *array; + g_autoptr(GMatchInfo) match_info = NULL; + GArray *array; /* We always return a valid array, even if it may be empty */ array = g_array_new (FALSE, FALSE, sizeof (MMSmsStorage)); @@ -3058,7 +3004,6 @@ mm_3gpp_parse_cpms_test_response (const gchar *reply, g_match_info_next (match_info, NULL); } } - g_match_info_free (match_info); if (!tmp1) tmp1 = array; @@ -3100,43 +3045,31 @@ mm_3gpp_parse_cpms_query_response (const gchar *reply, MMSmsStorage *memw, GError **error) { - GRegex *r = NULL; - gboolean ret = FALSE; - GMatchInfo *match_info = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; r = g_regex_new (CPMS_QUERY_REGEX, G_REGEX_RAW, 0, NULL); - g_assert (r); if (!g_regex_match (r, reply, 0, &match_info)) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Could not parse CPMS query response '%s'", reply); - goto end; + return FALSE; } if (!g_match_info_matches (match_info)) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Could not find matches in CPMS query reply '%s'", reply); - goto end; - } - - if (!mm_3gpp_get_cpms_storage_match (match_info, "memr", memr, error)) { - goto end; - } - - if (!mm_3gpp_get_cpms_storage_match (match_info, "memw", memw, error)) { - goto end; + return FALSE; } - ret = TRUE; - -end: - if (r != NULL) - g_regex_unref (r); + if (!mm_3gpp_get_cpms_storage_match (match_info, "memr", memr, error)) + return FALSE; - g_match_info_free (match_info); + if (!mm_3gpp_get_cpms_storage_match (match_info, "memw", memw, error)) + return FALSE; - return ret; + return TRUE; } gboolean @@ -3168,11 +3101,12 @@ gboolean mm_3gpp_parse_cscs_test_response (const gchar *reply, MMModemCharset *out_charsets) { - MMModemCharset charsets = MM_MODEM_CHARSET_UNKNOWN; - GRegex *r; - GMatchInfo *match_info; - gchar *p, *str; - gboolean success = FALSE; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + MMModemCharset charsets = MM_MODEM_CHARSET_UNKNOWN; + gchar *p; + gchar *str; + gboolean success = FALSE; g_return_val_if_fail (reply != NULL, FALSE); g_return_val_if_fail (out_charsets != NULL, FALSE); @@ -3194,8 +3128,7 @@ mm_3gpp_parse_cscs_test_response (const gchar *reply, /* Now parse each charset */ r = g_regex_new ("\\s*([^,\\)]+)\\s*", 0, 0, NULL); - if (!r) - return FALSE; + g_assert (r); if (g_regex_match (r, p, 0, &match_info)) { while (g_match_info_matches (match_info)) { @@ -3207,8 +3140,6 @@ mm_3gpp_parse_cscs_test_response (const gchar *reply, success = TRUE; } } - g_match_info_free (match_info); - g_regex_unref (r); if (success) *out_charsets = charsets; @@ -3222,8 +3153,8 @@ gboolean mm_3gpp_parse_clck_test_response (const gchar *reply, MMModem3gppFacility *out_facilities) { - GRegex *r; - GMatchInfo *match_info; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; g_return_val_if_fail (reply != NULL, FALSE); g_return_val_if_fail (out_facilities != NULL, FALSE); @@ -3252,8 +3183,6 @@ mm_3gpp_parse_clck_test_response (const gchar *reply, g_match_info_next (match_info, NULL); } } - g_match_info_free (match_info); - g_regex_unref (r); return (*out_facilities != MM_MODEM_3GPP_FACILITY_NONE); } @@ -3264,9 +3193,8 @@ gboolean mm_3gpp_parse_clck_write_response (const gchar *reply, gboolean *enabled) { - GRegex *r; - GMatchInfo *match_info; - gboolean success = FALSE; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; g_return_val_if_fail (reply != NULL, FALSE); g_return_val_if_fail (enabled != NULL, FALSE); @@ -3277,7 +3205,7 @@ mm_3gpp_parse_clck_write_response (const gchar *reply, g_assert (r != NULL); if (g_regex_match (r, reply, 0, &match_info)) { - gchar *str; + g_autofree gchar *str = NULL; str = g_match_info_fetch (match_info, 1); if (str) { @@ -3289,15 +3217,11 @@ mm_3gpp_parse_clck_write_response (const gchar *reply, *enabled = TRUE; else g_assert_not_reached (); - - g_free (str); - success = TRUE; + return TRUE; } } - g_match_info_free (match_info); - g_regex_unref (r); - return success; + return FALSE; } /*************************************************************************/ @@ -3530,10 +3454,10 @@ GHashTable * mm_3gpp_parse_cind_test_response (const gchar *reply, GError **error) { - GHashTable *hash; - GRegex *r; - GMatchInfo *match_info; - guint idx = 1; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GHashTable *hash; + guint idx = 1; g_return_val_if_fail (reply != NULL, NULL); @@ -3544,12 +3468,7 @@ mm_3gpp_parse_cind_test_response (const gchar *reply, reply++; r = g_regex_new ("\\(([^,]*),\\((\\d+)[-,](\\d+).*\\)", G_REGEX_UNGREEDY, 0, NULL); - if (!r) { - g_set_error_literal (error, - MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Could not parse scan results."); - return NULL; - } + g_assert (r); hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) cind_response_free); @@ -3578,8 +3497,6 @@ mm_3gpp_parse_cind_test_response (const gchar *reply, g_match_info_next (match_info, NULL); } } - g_match_info_free (match_info); - g_regex_unref (r); return hash; } @@ -3590,11 +3507,11 @@ GByteArray * mm_3gpp_parse_cind_read_response (const gchar *reply, GError **error) { - GByteArray *array = NULL; - GRegex *r = NULL; - GMatchInfo *match_info; - GError *inner_error = NULL; - guint8 t; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GByteArray *array = NULL; + GError *inner_error = NULL; + guint8 t; g_return_val_if_fail (reply != NULL, NULL); @@ -3614,7 +3531,7 @@ mm_3gpp_parse_cind_read_response (const gchar *reply, g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Could not parse the +CIND response '%s': didn't match", reply); - goto done; + return NULL; } array = g_byte_array_sized_new (g_match_info_get_match_count (match_info)); @@ -3625,10 +3542,9 @@ mm_3gpp_parse_cind_read_response (const gchar *reply, t = 0; g_byte_array_append (array, &t, 1); - while (!inner_error && - g_match_info_matches (match_info)) { - gchar *str; - guint val = 0; + while (!inner_error && g_match_info_matches (match_info)) { + g_autofree gchar *str = NULL; + guint val = 0; str = g_match_info_fetch (match_info, 1); if (mm_get_uint_from_str (str, &val) && val < 255) { @@ -3639,21 +3555,14 @@ mm_3gpp_parse_cind_read_response (const gchar *reply, "Could not parse the +CIND response: invalid index '%s'", str); } - - g_free (str); g_match_info_next (match_info, NULL); } if (inner_error) { g_propagate_error (error, inner_error); - g_byte_array_unref (array); - array = NULL; + g_clear_pointer (&array, g_byte_array_unref); } -done: - g_match_info_free (match_info); - g_regex_unref (r); - return array; } @@ -3755,12 +3664,12 @@ mm_3gpp_parse_cgev_indication_pdp (const gchar *str, guint *out_cid, GError **error) { - GRegex *r; - GMatchInfo *match_info = NULL; - GError *inner_error = NULL; - gchar *pdp_type = NULL; - gchar *pdp_addr = NULL; - guint cid = 0; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + gchar *pdp_type = NULL; + gchar *pdp_addr = NULL; + guint cid = 0; g_assert (type == MM_3GPP_CGEV_REJECT || type == MM_3GPP_CGEV_NW_REACT || @@ -3772,6 +3681,7 @@ mm_3gpp_parse_cgev_indication_pdp (const gchar *str, "NW REACT|" "NW DEACT|ME DEACT" ")\\s*([^,]*),\\s*([^,]*)(?:,\\s*([0-9]+))?", 0, 0, NULL); + g_assert (r); str = mm_strip_tag (str, "+CGEV:"); g_regex_match_full (r, str, strlen (str), 0, 0, &match_info, &inner_error); @@ -3802,10 +3712,6 @@ mm_3gpp_parse_cgev_indication_pdp (const gchar *str, } out: - if (match_info) - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { g_free (pdp_type); g_free (pdp_addr); @@ -3841,10 +3747,10 @@ mm_3gpp_parse_cgev_indication_primary (const gchar *str, guint *out_cid, GError **error) { - GRegex *r; - GMatchInfo *match_info = NULL; - GError *inner_error = NULL; - guint cid = 0; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + guint cid = 0; g_assert ((type == MM_3GPP_CGEV_NW_ACT_PRIMARY) || (type == MM_3GPP_CGEV_ME_ACT_PRIMARY) || @@ -3872,10 +3778,6 @@ mm_3gpp_parse_cgev_indication_primary (const gchar *str, } out: - if (match_info) - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { g_propagate_error (error, inner_error); return FALSE; @@ -3900,12 +3802,12 @@ mm_3gpp_parse_cgev_indication_secondary (const gchar *str, guint *out_event_type, GError **error) { - GRegex *r; - GMatchInfo *match_info = NULL; - GError *inner_error = NULL; - guint p_cid = 0; - guint cid = 0; - guint event_type = 0; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + guint p_cid = 0; + guint cid = 0; + guint event_type = 0; g_assert (type == MM_3GPP_CGEV_NW_ACT_SECONDARY || type == MM_3GPP_CGEV_ME_ACT_SECONDARY || @@ -3943,10 +3845,6 @@ mm_3gpp_parse_cgev_indication_secondary (const gchar *str, } out: - if (match_info) - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { g_propagate_error (error, inner_error); return FALSE; @@ -3980,10 +3878,10 @@ GList * mm_3gpp_parse_pdu_cmgl_response (const gchar *str, GError **error) { - GError *inner_error = NULL; - GList *list = NULL; - GMatchInfo *match_info; - GRegex *r; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *inner_error = NULL; + GList *list = NULL; /* * +CMGL: <index>, <status>, [<alpha>], <length> @@ -4016,9 +3914,6 @@ mm_3gpp_parse_pdu_cmgl_response (const gchar *str, } } - g_match_info_free (match_info); - g_regex_unref (r); - if (inner_error) { g_propagate_error (error, inner_error); mm_3gpp_pdu_info_list_free (list); @@ -4754,10 +4649,10 @@ mm_cdma_parse_crm_test_response (const gchar *reply, MMModemCdmaRmProtocol *max, GError **error) { - gboolean result = FALSE; - GRegex *r; - GMatchInfo *match_info = NULL; - GError *match_error = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + gboolean result = FALSE; + GError *match_error = NULL; /* Expected reply format is: * ---> AT+CRM=? @@ -4810,9 +4705,6 @@ mm_cdma_parse_crm_test_response (const gchar *reply, reply); } - g_match_info_free (match_info); - g_regex_unref (r); - return result; } @@ -5039,12 +4931,16 @@ mm_parse_cclk_response (const char *response, MMNetworkTimezone **tzp, GError **error) { - GRegex *r; - GMatchInfo *match_info = NULL; - GError *match_error = NULL; - guint year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0; - gint tz = 0; - gboolean ret = FALSE; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + GError *match_error = NULL; + guint year = 0; + guint month = 0; + guint day = 0; + guint hour = 0; + guint minute = 0; + guint second = 0; + gint tz = 0; g_assert (iso8601p || tzp); /* at least one */ @@ -5065,7 +4961,7 @@ mm_parse_cclk_response (const char *response, MM_CORE_ERROR_FAILED, "Couldn't match +CCLK reply: %s", response); } - goto out; + return FALSE; } /* Remember that g_match_info_get_match_count() includes match #0 */ @@ -5082,7 +4978,7 @@ mm_parse_cclk_response (const char *response, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Failed to parse +CCLK reply: %s", response); - goto out; + return FALSE; } /* Read optional time zone offset; if not given assume UTC (tz = 0). @@ -5094,7 +4990,7 @@ mm_parse_cclk_response (const char *response, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Failed to parse timezone in +CCLK reply: %s", response); - goto out; + return FALSE; } /* Adjust year to support YYYY format, as per +CSDF in 3GPP TS 27.007. Also, @@ -5112,22 +5008,16 @@ mm_parse_cclk_response (const char *response, mm_network_timezone_set_offset (*tzp, tz * 15); } - ret = TRUE; - if (iso8601p) { /* Return ISO-8601 format date/time string */ *iso8601p = mm_new_iso8601_time (year, month, day, hour, minute, second, TRUE, (tz * 15), error); - ret = (*iso8601p != NULL); + return (*iso8601p != NULL); } - out: - g_match_info_free (match_info); - g_regex_unref (r); - - return ret; + return TRUE; } /*****************************************************************************/ @@ -5139,12 +5029,12 @@ gint mm_parse_csim_response (const gchar *response, GError **error) { - GMatchInfo *match_info = NULL; - GRegex *r = NULL; - gchar *str_code = NULL; - gint retries = -1; - guint hex_code; - GError *inner_error = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + g_autofree gchar *str_code = NULL; + gint retries = -1; + guint hex_code; + GError *inner_error = NULL; r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*\".*([0-9a-fA-F]{4})\"", G_REGEX_RAW, 0, NULL); g_regex_match (r, response, 0, &match_info); @@ -5202,10 +5092,6 @@ mm_parse_csim_response (const gchar *response, retries = (gint)(hex_code - MM_MIN_SIM_RETRY_HEX); out: - g_regex_unref (r); - g_match_info_free (match_info); - g_free (str_code); - if (inner_error) { g_propagate_error (error, inner_error); return -1; diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c index 44c0fc92..88d01cf4 100644 --- a/src/mm-port-serial-at.c +++ b/src/mm-port-serial-at.c @@ -269,8 +269,8 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response) for (iter = self->priv->unsolicited_msg_handlers; iter; iter = iter->next) { MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data; - GMatchInfo *match_info; - gboolean matches; + g_autoptr(GMatchInfo) match_info = NULL; + gboolean matches; if (!handler->enable) continue; @@ -286,12 +286,10 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response) } } - g_match_info_free (match_info); - if (matches) { /* Remove matches */ - char *str; - int result_len = response->len; + g_autofree gchar *str = NULL; + gint result_len = response->len; str = g_regex_replace_eval (handler->regex, (const char *) response->data, @@ -301,7 +299,6 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response) g_byte_array_remove_range (response, 0, response->len); g_byte_array_append (response, (const guint8 *) str, result_len); - g_free (str); } } } diff --git a/src/mm-port-serial-gps.c b/src/mm-port-serial-gps.c index ea404994..fe8ec6a8 100644 --- a/src/mm-port-serial-gps.c +++ b/src/mm-port-serial-gps.c @@ -74,12 +74,12 @@ parse_response (MMPortSerial *port, GByteArray **parsed_response, GError **error) { - MMPortSerialGps *self = MM_PORT_SERIAL_GPS (port); - gboolean matches; - GMatchInfo *match_info; - gchar *str; - gint result_len; - guint i; + MMPortSerialGps *self = MM_PORT_SERIAL_GPS (port); + g_autoptr(GMatchInfo) match_info = NULL; + gboolean matches; + gchar *str; + gint result_len; + guint i; for (i = 0; i < response->len; i++) { /* If there is any content before the first $, @@ -110,8 +110,6 @@ parse_response (MMPortSerial *port, } } - g_match_info_free (match_info); - if (!matches) return MM_PORT_SERIAL_RESPONSE_NONE; diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c index fd01537d..a577faee 100644 --- a/src/mm-serial-parsers.c +++ b/src/mm-serial-parsers.c @@ -167,7 +167,7 @@ mm_serial_parser_v1_parse (gpointer data, GError **error) { MMSerialParserV1 *parser = (MMSerialParserV1 *) data; - GMatchInfo *match_info; + GMatchInfo *match_info = NULL; GError *local_error = NULL; gboolean found = FALSE; char *str = NULL; @@ -242,7 +242,7 @@ mm_serial_parser_v1_parse (gpointer data, local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object); goto done; } - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); } /* Numeric CME errors */ @@ -255,7 +255,7 @@ mm_serial_parser_v1_parse (gpointer data, local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object); goto done; } - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); /* Numeric CMS errors */ found = g_regex_match_full (parser->regex_cms_error, @@ -267,7 +267,7 @@ mm_serial_parser_v1_parse (gpointer data, local_error = mm_message_error_for_code (atoi (str), log_object); goto done; } - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); /* String CME errors */ found = g_regex_match_full (parser->regex_cme_error_str, @@ -279,7 +279,7 @@ mm_serial_parser_v1_parse (gpointer data, local_error = mm_mobile_equipment_error_for_string (str, log_object); goto done; } - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); /* String CMS errors */ found = g_regex_match_full (parser->regex_cms_error_str, @@ -291,7 +291,7 @@ mm_serial_parser_v1_parse (gpointer data, local_error = mm_message_error_for_string (str, log_object); goto done; } - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); /* Motorola EZX errors */ found = g_regex_match_full (parser->regex_ezx_error, @@ -303,7 +303,7 @@ mm_serial_parser_v1_parse (gpointer data, local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object); goto done; } - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); /* Last resort; unknown error */ found = g_regex_match_full (parser->regex_unknown_error, @@ -313,7 +313,7 @@ mm_serial_parser_v1_parse (gpointer data, local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object); goto done; } - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); /* Connection failures */ found = g_regex_match_full (parser->regex_connect_failed, @@ -341,7 +341,7 @@ mm_serial_parser_v1_parse (gpointer data, local_error = mm_connection_error_for_code (code, log_object); goto done; } - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); /* NA error */ found = g_regex_match_full (parser->regex_na, @@ -357,7 +357,8 @@ mm_serial_parser_v1_parse (gpointer data, done: g_free (str); - g_match_info_free (match_info); + g_clear_pointer (&match_info, g_match_info_free); + if (found) response_clean (response); diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 21ed2f20..01f4c910 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1129,15 +1129,19 @@ test_creg_match (const char *test, RegTestData *data, const CregResult *result) { - guint i; - GMatchInfo *info = NULL; - MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; - MMModemAccessTechnology access_tech = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; - gulong lac = 0, ci = 0; - GError *error = NULL; - gboolean success, cgreg = FALSE, cereg = FALSE, c5greg = FALSE; - guint regex_num = 0; - GPtrArray *array; + g_autoptr(GMatchInfo) info = NULL; + guint i; + MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; + MMModemAccessTechnology access_tech = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + gulong lac = 0; + gulong ci = 0; + GError *error = NULL; + gboolean success; + gboolean cgreg = FALSE; + gboolean cereg = FALSE; + gboolean c5greg = FALSE; + guint regex_num = 0; + GPtrArray *array; g_assert (reply); g_assert (test); @@ -1158,8 +1162,7 @@ test_creg_match (const char *test, regex_num = i; break; } - g_match_info_free (info); - info = NULL; + g_clear_pointer (&info, g_match_info_free); } g_debug (" regex_num (%u) == result->regex_num (%u)", @@ -1171,7 +1174,6 @@ test_creg_match (const char *test, success = mm_3gpp_parse_creg_response (info, NULL, &state, &lac, &ci, &access_tech, &cgreg, &cereg, &c5greg, &error); - g_match_info_free (info); g_assert (success); g_assert_no_error (error); g_assert_cmpuint (state, ==, result->state); @@ -3351,10 +3353,10 @@ common_parse_cds (const gchar *str, guint expected_pdu_len, const gchar *expected_pdu) { - GMatchInfo *match_info; - GRegex *regex; - gchar *pdu_len_str; - gchar *pdu; + g_autoptr(GMatchInfo) match_info = NULL; + g_autoptr(GRegex) regex = NULL; + g_autofree gchar *pdu_len_str = NULL; + g_autofree gchar *pdu = NULL; regex = mm_3gpp_cds_regex_get (); g_regex_match (regex, str, 0, &match_info); @@ -3368,12 +3370,6 @@ common_parse_cds (const gchar *str, g_assert (pdu != NULL); g_assert_cmpstr (pdu, ==, expected_pdu); - - g_free (pdu); - g_free (pdu_len_str); - - g_match_info_free (match_info); - g_regex_unref (regex); } static void @@ -4143,15 +4139,15 @@ static const ClipUrcTest clip_urc_tests[] = { static void test_clip_indication (void) { - GRegex *r; - guint i; + g_autoptr(GRegex) r = NULL; + guint i; r = mm_voice_clip_regex_get (); for (i = 0; i < G_N_ELEMENTS (clip_urc_tests); i++) { - GMatchInfo *match_info = NULL; - gchar *number; - guint type; + g_autoptr(GMatchInfo) match_info = NULL; + g_autofree gchar *number = NULL; + guint type; g_assert (g_regex_match (r, clip_urc_tests[i].str, 0, &match_info)); g_assert (g_match_info_matches (match_info)); @@ -4161,12 +4157,7 @@ test_clip_indication (void) g_assert (mm_get_uint_from_match_info (match_info, 2, &type)); g_assert_cmpuint (type, ==, clip_urc_tests[i].type); - - g_free (number); - g_match_info_free (match_info); } - - g_regex_unref (r); } /*****************************************************************************/ @@ -4188,16 +4179,16 @@ static const CcwaUrcTest ccwa_urc_tests[] = { static void test_ccwa_indication (void) { - GRegex *r; - guint i; + g_autoptr(GRegex) r = NULL; + guint i; r = mm_voice_ccwa_regex_get (); for (i = 0; i < G_N_ELEMENTS (ccwa_urc_tests); i++) { - GMatchInfo *match_info = NULL; - gchar *number; - guint type; - guint class; + g_autoptr(GMatchInfo) match_info = NULL; + g_autofree gchar *number = NULL; + guint type; + guint class; g_assert (g_regex_match (r, ccwa_urc_tests[i].str, 0, &match_info)); g_assert (g_match_info_matches (match_info)); @@ -4210,12 +4201,7 @@ test_ccwa_indication (void) g_assert (mm_get_uint_from_match_info (match_info, 3, &class)); g_assert_cmpuint (class, ==, ccwa_urc_tests[i].class); - - g_free (number); - g_match_info_free (match_info); } - - g_regex_unref (r); } /*****************************************************************************/ |