libmm-glib,common-helpers: make hexstr2bin() return a guint8 array

It makes much more sense than returning a gchar array, as gchar is
signed.
This commit is contained in:
Aleksander Morgado
2021-02-23 11:35:11 +00:00
parent 6d8610d63e
commit 34de613dea
11 changed files with 48 additions and 52 deletions
+9 -9
View File
@@ -170,14 +170,14 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error)
}
while (g_match_info_matches (match_info)) {
guint pco_cid;
g_autofree gchar *pco_id = NULL;
g_autofree gchar *pco_payload = NULL;
g_autofree gchar *pco_payload_bytes = NULL;
gsize pco_payload_bytes_len;
guint8 pco_prefix[6];
GByteArray *pco_raw;
gsize pco_raw_len;
guint pco_cid;
g_autofree gchar *pco_id = NULL;
g_autofree gchar *pco_payload = NULL;
g_autofree guint8 *pco_payload_bytes = NULL;
gsize pco_payload_bytes_len;
guint8 pco_prefix[6];
GByteArray *pco_raw;
gsize pco_raw_len;
if (!mm_get_uint_from_match_info (match_info, 1, &pco_cid)) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
@@ -246,7 +246,7 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error)
pco_raw = g_byte_array_sized_new (pco_raw_len);
g_byte_array_append (pco_raw, pco_prefix, sizeof (pco_prefix));
g_byte_array_append (pco_raw, (guint8 *)pco_payload_bytes, pco_payload_bytes_len);
g_byte_array_append (pco_raw, pco_payload_bytes, pco_payload_bytes_len);
pco = mm_pco_new ();
mm_pco_set_session_id (pco, pco_cid);
+2 -2
View File
@@ -2330,7 +2330,7 @@ decode (MMIfaceModem3gppUssd *self,
const gchar *reply,
GError **error)
{
g_autofree gchar *bin = NULL;
g_autofree guint8 *bin = NULL;
g_autofree guint8 *unpacked = NULL;
gsize bin_len = 0;
guint32 unpacked_len;
@@ -2339,7 +2339,7 @@ decode (MMIfaceModem3gppUssd *self,
if (!bin)
return NULL;
unpacked = mm_charset_gsm_unpack ((guint8*) bin, (bin_len * 8) / 7, 0, &unpacked_len);
unpacked = mm_charset_gsm_unpack (bin, (bin_len * 8) / 7, 0, &unpacked_len);
/* if the last character in a 7-byte block is padding, then drop it */
if ((bin_len % 7 == 0) && (unpacked[unpacked_len - 1] == 0x0d))
unpacked_len--;
+13 -17
View File
@@ -157,14 +157,15 @@ mm_huawei_parse_ndisstatqry_response (const gchar *response,
static gboolean
match_info_to_ip4_addr (GMatchInfo *match_info,
guint match_index,
guint *out_addr)
guint match_index,
guint *out_addr)
{
gchar *s, *bin = NULL;
gchar buf[9];
gsize len, bin_len;
gboolean success = FALSE;
guint32 aux;
g_autofree gchar *s = NULL;
g_autofree guint8 *bin = NULL;
gchar buf[9];
gsize len;
gsize bin_len;
guint32 aux;
s = g_match_info_fetch (match_info, match_index);
g_return_val_if_fail (s != NULL, FALSE);
@@ -172,11 +173,11 @@ match_info_to_ip4_addr (GMatchInfo *match_info,
len = strlen (s);
if (len == 1 && s[0] == '0') {
*out_addr = 0;
success = TRUE;
goto done;
return TRUE;
}
if (len < 7 || len > 8)
goto done;
return FALSE;
/* Handle possibly missing leading zero */
memset (buf, 0, sizeof (buf));
@@ -190,16 +191,11 @@ match_info_to_ip4_addr (GMatchInfo *match_info,
bin = mm_utils_hexstr2bin (buf, -1, &bin_len, NULL);
if (!bin || bin_len != 4)
goto done;
return FALSE;
memcpy (&aux, bin, 4);
*out_addr = GUINT32_SWAP_LE_BE (aux);
success = TRUE;
done:
g_free (s);
g_free (bin);
return success;
return TRUE;
}
gboolean