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:
@@ -1686,18 +1686,18 @@ mm_utils_hex2byte (const gchar *hex)
|
||||
return (a << 4) | b;
|
||||
}
|
||||
|
||||
gchar *
|
||||
guint8 *
|
||||
mm_utils_hexstr2bin (const gchar *hex,
|
||||
gssize len,
|
||||
gsize *out_len,
|
||||
GError **error)
|
||||
{
|
||||
const gchar *ipos = hex;
|
||||
g_autofree gchar *buf = NULL;
|
||||
g_autofree guint8 *buf = NULL;
|
||||
gsize i;
|
||||
gint a;
|
||||
gchar *opos
|
||||
;
|
||||
guint8 *opos;
|
||||
|
||||
if (len < 0)
|
||||
len = strlen (hex);
|
||||
|
||||
@@ -1723,7 +1723,7 @@ mm_utils_hexstr2bin (const gchar *hex,
|
||||
ipos[0], ipos[1]);
|
||||
return NULL;
|
||||
}
|
||||
*opos++ = a;
|
||||
*opos++ = (guint8)a;
|
||||
ipos += 2;
|
||||
}
|
||||
*out_len = len / 2;
|
||||
|
@@ -181,7 +181,7 @@ gchar *mm_get_string_unquoted_from_match_info (GMatchInfo *match_info,
|
||||
const gchar *mm_sms_delivery_state_get_string_extended (guint delivery_state);
|
||||
|
||||
gint mm_utils_hex2byte (const gchar *hex);
|
||||
gchar *mm_utils_hexstr2bin (const gchar *hex, gssize len, gsize *out_len, GError **error);
|
||||
guint8 *mm_utils_hexstr2bin (const gchar *hex, gssize len, gsize *out_len, GError **error);
|
||||
gchar *mm_utils_bin2hexstr (const guint8 *bin, gsize len);
|
||||
gboolean mm_utils_ishexstr (const gchar *hex);
|
||||
|
||||
|
@@ -173,7 +173,7 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error)
|
||||
guint pco_cid;
|
||||
g_autofree gchar *pco_id = NULL;
|
||||
g_autofree gchar *pco_payload = NULL;
|
||||
g_autofree gchar *pco_payload_bytes = NULL;
|
||||
g_autofree guint8 *pco_payload_bytes = NULL;
|
||||
gsize pco_payload_bytes_len;
|
||||
guint8 pco_prefix[6];
|
||||
GByteArray *pco_raw;
|
||||
@@ -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);
|
||||
|
@@ -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--;
|
||||
|
@@ -160,10 +160,11 @@ match_info_to_ip4_addr (GMatchInfo *match_info,
|
||||
guint match_index,
|
||||
guint *out_addr)
|
||||
{
|
||||
gchar *s, *bin = NULL;
|
||||
g_autofree gchar *s = NULL;
|
||||
g_autofree guint8 *bin = NULL;
|
||||
gchar buf[9];
|
||||
gsize len, bin_len;
|
||||
gboolean success = FALSE;
|
||||
gsize len;
|
||||
gsize bin_len;
|
||||
guint32 aux;
|
||||
|
||||
s = g_match_info_fetch (match_info, match_index);
|
||||
@@ -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
|
||||
|
@@ -1308,7 +1308,7 @@ parse_mnc_length (const gchar *response,
|
||||
(sw1 == 0x9f)) {
|
||||
gsize buflen = 0;
|
||||
guint32 mnc_len;
|
||||
g_autofree gchar *bin = NULL;
|
||||
g_autofree guint8 *bin = NULL;
|
||||
|
||||
/* Convert hex string to binary */
|
||||
bin = mm_utils_hexstr2bin (hex, -1, &buflen, error);
|
||||
@@ -1323,7 +1323,7 @@ parse_mnc_length (const gchar *response,
|
||||
}
|
||||
|
||||
/* MNC length is byte 4 of this SIM file */
|
||||
mnc_len = bin[3] & 0xFF;
|
||||
mnc_len = bin[3];
|
||||
if (mnc_len == 2 || mnc_len == 3)
|
||||
return mnc_len;
|
||||
|
||||
@@ -1413,7 +1413,7 @@ parse_spn (const gchar *response,
|
||||
(sw1 == 0x92) ||
|
||||
(sw1 == 0x9f)) {
|
||||
gsize buflen = 0;
|
||||
g_autofree gchar *bin = NULL;
|
||||
g_autofree guint8 *bin = NULL;
|
||||
|
||||
/* Convert hex string to binary */
|
||||
bin = mm_utils_hexstr2bin (hex, -1, &buflen, error);
|
||||
@@ -1423,11 +1423,11 @@ parse_spn (const gchar *response,
|
||||
}
|
||||
|
||||
/* Remove the FF filler at the end */
|
||||
while (buflen > 1 && bin[buflen - 1] == (char)0xff)
|
||||
while (buflen > 1 && bin[buflen - 1] == 0xff)
|
||||
buflen--;
|
||||
|
||||
/* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */
|
||||
return (gchar *)mm_charset_gsm_unpacked_to_utf8 ((guint8 *)bin + 1, buflen - 1);
|
||||
return (gchar *)mm_charset_gsm_unpacked_to_utf8 (bin + 1, buflen - 1);
|
||||
}
|
||||
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
|
@@ -158,7 +158,7 @@ mm_modem_charset_hex_to_utf8 (const gchar *src,
|
||||
MMModemCharset charset)
|
||||
{
|
||||
const gchar *iconv_from;
|
||||
g_autofree gchar *unconverted = NULL;
|
||||
g_autofree guint8 *unconverted = NULL;
|
||||
g_autofree gchar *converted = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
gsize unconverted_len = 0;
|
||||
@@ -176,7 +176,7 @@ mm_modem_charset_hex_to_utf8 (const gchar *src,
|
||||
if (charset == MM_MODEM_CHARSET_UTF8 || charset == MM_MODEM_CHARSET_IRA)
|
||||
return g_steal_pointer (&unconverted);
|
||||
|
||||
converted = g_convert (unconverted, unconverted_len,
|
||||
converted = g_convert ((const gchar *)unconverted, unconverted_len,
|
||||
"UTF-8//TRANSLIT", iconv_from,
|
||||
NULL, NULL, &error);
|
||||
if (!converted || error)
|
||||
|
@@ -1815,7 +1815,7 @@ mm_firmware_unique_id_to_qmi_unique_id (const gchar *unique_id,
|
||||
gsize tmp_len;
|
||||
|
||||
tmp_len = 0;
|
||||
tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, -1, &tmp_len, error);
|
||||
tmp = mm_utils_hexstr2bin (unique_id, -1, &tmp_len, error);
|
||||
if (!tmp) {
|
||||
g_prefix_error (error, "Unexpected character found in unique id: ");
|
||||
return NULL;
|
||||
|
@@ -4291,7 +4291,7 @@ mm_3gpp_parse_emergency_numbers (const char *raw, GError **error)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bin = (guint8 *) mm_utils_hexstr2bin (raw, -1, &binlen, error);
|
||||
bin = mm_utils_hexstr2bin (raw, -1, &binlen, error);
|
||||
if (!bin) {
|
||||
g_prefix_error (error, "invalid raw emergency numbers list contents: ");
|
||||
return NULL;
|
||||
|
@@ -343,7 +343,7 @@ mm_sms_part_3gpp_new_from_pdu (guint index,
|
||||
gsize pdu_len;
|
||||
|
||||
/* Convert PDU from hex to binary */
|
||||
pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error);
|
||||
pdu = mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error);
|
||||
if (!pdu) {
|
||||
g_prefix_error (error, "Couldn't convert 3GPP PDU from hex to binary: ");
|
||||
return NULL;
|
||||
|
@@ -321,7 +321,7 @@ mm_sms_part_cdma_new_from_pdu (guint index,
|
||||
gsize pdu_len;
|
||||
|
||||
/* Convert PDU from hex to binary */
|
||||
pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error);
|
||||
pdu = mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error);
|
||||
if (!pdu) {
|
||||
g_prefix_error (error, "Couldn't convert CDMA PDU from hex to binary: ");
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user