modem-helpers: rework the +CGEV indication parser

We setup all output variables with g_autofree and then use
g_steal_pointer() to return the needed ones.
This commit is contained in:
Aleksander Morgado
2022-08-24 16:50:34 +00:00
parent e6c40349b8
commit 9bbc768666

View File

@@ -3642,8 +3642,8 @@ mm_3gpp_parse_cgev_indication_pdp (const gchar *str,
g_autoptr(GRegex) r = NULL; g_autoptr(GRegex) r = NULL;
g_autoptr(GMatchInfo) match_info = NULL; g_autoptr(GMatchInfo) match_info = NULL;
GError *inner_error = NULL; GError *inner_error = NULL;
gchar *pdp_type = NULL; g_autofree gchar *pdp_type = NULL;
gchar *pdp_addr = NULL; g_autofree gchar *pdp_addr = NULL;
guint cid = 0; guint cid = 0;
g_assert (type == MM_3GPP_CGEV_REJECT || g_assert (type == MM_3GPP_CGEV_REJECT ||
@@ -3660,44 +3660,38 @@ mm_3gpp_parse_cgev_indication_pdp (const gchar *str,
str = mm_strip_tag (str, "+CGEV:"); str = mm_strip_tag (str, "+CGEV:");
g_regex_match_full (r, str, strlen (str), 0, 0, &match_info, &inner_error); g_regex_match_full (r, str, strlen (str), 0, 0, &match_info, &inner_error);
if (inner_error) if (inner_error) {
goto out; g_propagate_error (error, inner_error);
return FALSE;
}
if (!g_match_info_matches (match_info)) { if (!g_match_info_matches (match_info)) {
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't match response"); g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't match response");
goto out; return FALSE;
} }
if (out_pdp_type && !(pdp_type = mm_get_string_unquoted_from_match_info (match_info, 1))) { if (out_pdp_type && !(pdp_type = mm_get_string_unquoted_from_match_info (match_info, 1))) {
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP type"); g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP type");
goto out; return FALSE;
} }
if (out_pdp_addr && !(pdp_addr = mm_get_string_unquoted_from_match_info (match_info, 2))) { if (out_pdp_addr && !(pdp_addr = mm_get_string_unquoted_from_match_info (match_info, 2))) {
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP addr"); g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing PDP addr");
goto out; return FALSE;
} }
/* CID is optional */ /* CID is optional */
if (out_cid && if (out_cid &&
(g_match_info_get_match_count (match_info) >= 4) && (g_match_info_get_match_count (match_info) >= 4) &&
!mm_get_uint_from_match_info (match_info, 3, &cid)) { !mm_get_uint_from_match_info (match_info, 3, &cid)) {
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing CID"); g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error parsing CID");
goto out;
}
out:
if (inner_error) {
g_free (pdp_type);
g_free (pdp_addr);
g_propagate_error (error, inner_error);
return FALSE; return FALSE;
} }
if (out_pdp_type) if (out_pdp_type)
*out_pdp_type = pdp_type; *out_pdp_type = g_steal_pointer (&pdp_type);
if (out_pdp_addr) if (out_pdp_addr)
*out_pdp_addr = pdp_addr; *out_pdp_addr = g_steal_pointer (&pdp_addr);
if (out_cid) if (out_cid)
*out_cid = cid; *out_cid = cid;
return TRUE; return TRUE;