sim: Drop glib use from sim_efli_format
PATCH 1/6 sim: Drop glib use from sim_efli_format
Change the return signature to use bool instead of gboolean. Also, change g_ascii_isalpha use to l_ascii_isalpha. While here, also update array subscripts to follow the coding style, item M3
--- src/sim.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
src/sim.c +9 -9
@@ -2155,15 +2155,15 @@ static void sim_efli_read_cb(int ok, int length, int record, }/* Detect whether the file is in EFli format, as opposed to 51.011 EFlp */ -static gboolean sim_efli_format (const unsigned char *ef,int length) +static bool sim_efli_format (const unsigned char *ef,int length) {int i;if (length &1 ) -return FALSE; +return false;for (i =0 ; i < length; i +=2 ) { -if (ef[i] ==0xff && ef[i+1 ] ==0xff ) +if (ef[i] ==0xff && ef[i +1 ] ==0xff )continue ;/*
@@ -2171,14 +2171,14 @@ static gboolean sim_efli_format(const unsigned char *ef, int length)* characters while CB DCS language codes are in ranges * (0 - 15) or (32 - 47), so the ranges don't overlap */ -if (g_ascii_isalpha (ef[i]) ==0 ) -return FALSE; +if (l_ascii_isalpha (ef[i]) ==0 ) +return false; -if (g_ascii_isalpha (ef[i+1 ]) ==0 ) -return FALSE; +if (l_ascii_isalpha (ef[i +1 ]) ==0 ) +return false; } -return TRUE; +return true; }static GSList *parse_language_list (const unsigned char *ef,int length)
@@ -2261,7 +2261,7 @@ static void sim_efpl_read_cb(int ok, int length, int record,struct ofono_sim *sim = userdata;const char *path =__ofono_atom_get_path (sim->atom);DBusConnection *conn =ofono_dbus_get_connection (); -gboolean efli_format = TRUE; +bool efli_format = true;GSList *efli =NULL ;GSList *efpl =NULL ;
Signature · 1 line
2.43.0
PATCH 2/6 smsutil: Move iso639_2_from_language to util
Also while here, convert to using stdbool instead of gboolean
--- src/sim.c | 2 +- src/smsutil.c | 111 -------------------------------------------------- src/smsutil.h | 27 +----------- src/util.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 26 ++++++++++++ 5 files changed, 140 insertions(+), 137 deletions(-)
src/sim.c +1 -1
@@ -2211,7 +2211,7 @@ static GSList *parse_eflp(const unsigned char *eflp, int length)GSList *ret =NULL ;for (i =0 ; i < length; i++) { -if (iso639_2_from_language (eflp[i], code) == FALSE) +if (!iso639_2_from_language (eflp[i], code))continue ; ret =g_slist_prepend (ret,g_strdup (code));
src/smsutil.c +0 -111
117 lines not on this page · raw message
src/smsutil.h +2 -25
@@ -19,6 +19,8 @@* */ +enum cbs_language ; +#define CBS_MAX_GSM_CHARS 93#define SMS_MSGID_LEN 20
@@ -196,30 +198,6 @@ enum sms_pid_type { SMS_PID_TYPE_USIM_DOWNLOAD = 0x7f, }; -enum cbs_language { -CBS_LANGUAGE_GERMAN =0x0 , -CBS_LANGUAGE_ENGLISH =0x1 , -CBS_LANGUAGE_ITALIAN =0x2 , -CBS_LANGUAGE_FRENCH =0x3 , -CBS_LANGUAGE_SPANISH =0x4 , -CBS_LANGUAGE_DUTCH =0x5 , -CBS_LANGUAGE_SWEDISH =0x6 , -CBS_LANGUAGE_DANISH =0x7 , -CBS_LANGUAGE_PORTUGESE =0x8 , -CBS_LANGUAGE_FINNISH =0x9 , -CBS_LANGUAGE_NORWEGIAN =0xA , -CBS_LANGUAGE_GREEK =0xB , -CBS_LANGUAGE_TURKISH =0xC , -CBS_LANGUAGE_HUNGARIAN =0xD , -CBS_LANGUAGE_POLISH =0xE , -CBS_LANGUAGE_UNSPECIFIED =0xF , -CBS_LANGUAGE_CZECH =0x20 , -CBS_LANGUAGE_HEBREW =0x21 , -CBS_LANGUAGE_ARABIC =0x22 , -CBS_LANGUAGE_RUSSIAN =0x23 , -CBS_LANGUAGE_ICELANDIC =0x24 -}; -enum cbs_geo_scope {CBS_GEO_SCOPE_CELL_IMMEDIATE ,CBS_GEO_SCOPE_PLMN ,
@@ -576,7 +554,6 @@ gboolean cbs_dcs_decode(guint8 dcs, gboolean *udhi, enum sms_class *cls, enum sms_charset *charset, gboolean *compressed, enum cbs_language *language, gboolean *iso639); -gboolean iso639_2_from_language (enum cbs_language lang,char *iso639);gboolean cbs_decode (const unsigned char *pdu,int len,struct cbs *out);gboolean cbs_encode (const struct cbs *cbs,int *len,unsigned char *pdu); gboolean cbs_extract_app_port(const struct cbs *cbs, int *dst, int *src,
src/util.c +111 -0
114 lines not on this page · raw message
src/util.h +26 -0
@@ -38,6 +38,30 @@ enum gsm_dialect { GSM_DIALECT_URDU, }; +enum cbs_language { +CBS_LANGUAGE_GERMAN =0x0 , +CBS_LANGUAGE_ENGLISH =0x1 , +CBS_LANGUAGE_ITALIAN =0x2 , +CBS_LANGUAGE_FRENCH =0x3 , +CBS_LANGUAGE_SPANISH =0x4 , +CBS_LANGUAGE_DUTCH =0x5 , +CBS_LANGUAGE_SWEDISH =0x6 , +CBS_LANGUAGE_DANISH =0x7 , +CBS_LANGUAGE_PORTUGESE =0x8 , +CBS_LANGUAGE_FINNISH =0x9 , +CBS_LANGUAGE_NORWEGIAN =0xA , +CBS_LANGUAGE_GREEK =0xB , +CBS_LANGUAGE_TURKISH =0xC , +CBS_LANGUAGE_HUNGARIAN =0xD , +CBS_LANGUAGE_POLISH =0xE , +CBS_LANGUAGE_UNSPECIFIED =0xF , +CBS_LANGUAGE_CZECH =0x20 , +CBS_LANGUAGE_HEBREW =0x21 , +CBS_LANGUAGE_ARABIC =0x22 , +CBS_LANGUAGE_RUSSIAN =0x23 , +CBS_LANGUAGE_ICELANDIC =0x24 +}; +char *convert_gsm_to_utf8 (const unsigned char *text,long len,long *items_read,long *items_written,unsigned char terminator);
@@ -105,3 +129,5 @@ unsigned char *convert_ucs2_to_gsm_with_lang(const unsigned char *text,unsigned char *convert_ucs2_to_gsm (const unsigned char *text,long len,long *items_read,long *items_written,unsigned char terminator); + +bool iso639_2_from_language (enum cbs_language lang,char *iso639);
Signature · 1 line
2.43.0
PATCH 3/6 sim: Move EFli and EFlp parsers to simutil
In reply to Denis KenziorWhile here, convert from using g_slist to l_strv utilities and remove other GLib usage.
--- src/sim.c | 105 ++++++++++++++------------------------------------ src/simutil.c | 62 +++++++++++++++++++++++++++++ src/simutil.h | 3 ++ 3 files changed, 93 insertions(+), 77 deletions(-)
src/sim.c +28 -77
@@ -2181,76 +2181,33 @@ static bool sim_efli_format(const unsigned char *ef, int length)return true; } -static GSList *parse_language_list (const unsigned char *ef,int length) +static char **concat_lang_prefs (char **a,char **b) { -int i; -GSList *ret =NULL ; - -for (i =0 ; i < length; i +=2 ) { -if (ef[i] >0x7f || ef[i+1 ] >0x7f ) -continue ; - -/* -* ISO 639 codes contain only characters that are coded -* identically in SMS 7 bit charset, ASCII or UTF8 so -* no conversion. -*/ - ret =g_slist_prepend (ret,g_ascii_strdown ((char *)ef + i,2 )); - } - -if (ret) - ret =g_slist_reverse (ret); - -return ret; -} - -static GSList *parse_eflp (const unsigned char *eflp,int length) -{ -int i; -char code[3 ]; -GSList *ret =NULL ; - -for (i =0 ; i < length; i++) { -if (!iso639_2_from_language (eflp[i], code)) -continue ; - - ret =g_slist_prepend (ret,g_strdup (code)); - } - -if (ret) - ret =g_slist_reverse (ret); - -return ret; -} - -static char **concat_lang_prefs (GSList *a,GSList *b) -{ -GSList *l, *k;char **ret; -int i =0 ; -int total =g_slist_length (a) +g_slist_length (b); +int i; +int j; +int total =l_strv_length (a) +l_strv_length (b);if (total ==0 )return NULL ; - ret = g_new0(char *, total + 1); - -for (l = a; l; l = l->next) - ret[i++] =g_strdup (l->data); - -for (l = b; l; l = l->next) { -gboolean duplicate = FALSE; + ret = l_new(char *, total + 1); -for (k = a; k; k = k->next) -if (!strcmp (k->data, l->data)) - duplicate = TRUE; +for (i =0 ; a && a[i]; i++) + ret[i] = a[i]; -if (duplicate) +for (j =0 ; b && b[j]; j++) { +if (l_strv_contains (a, b[j])) { +l_free (b[j]);continue ; + } - ret[i++] =g_strdup (l->data); + ret[i++] = b[j]; } +l_free (a); +l_free (b); +return ret; }
@@ -2262,22 +2219,23 @@ static void sim_efpl_read_cb(int ok, int length, int record,const char *path =__ofono_atom_get_path (sim->atom);DBusConnection *conn =ofono_dbus_get_connection ();bool efli_format = true; -GSList *efli =NULL ; -GSList *efpl =NULL ; +char **efli =NULL ; +char **efpl =NULL ;if (!ok || length <2 ) goto skip_efpl; - efpl =parse_language_list (data, length); + efpl =sim_parse_language_list (data, length); skip_efpl:if (sim->efli && sim->efli_length >0 ) { efli_format =sim_efli_format (sim->efli, sim->efli_length);if (efli_format) - efli =parse_language_list (sim->efli, sim->efli_length); + efli =sim_parse_language_list (sim->efli, + sim->efli_length);else - efli =parse_eflp (sim->efli, sim->efli_length); + efli =sim_parse_eflp (sim->efli, sim->efli_length); }/*
@@ -2293,13 +2251,14 @@ skip_efpl:*/ if (efli_format) {if (sim->efli_length >=2 && sim->efli[0 ] ==0xff && - sim->efli[1 ] ==0xff ) - sim->language_prefs =concat_lang_prefs (NULL , efpl); -else - sim->language_prefs =concat_lang_prefs (efli, efpl); - }else { + sim->efli[1 ] ==0xff ) { +l_strfreev (efli); + efli =NULL ; + } + + sim->language_prefs =concat_lang_prefs (efli, efpl); + }else sim->language_prefs =concat_lang_prefs (efpl, efli); - }if (sim->efli) {g_free (sim->efli);
@@ -2307,14 +2266,6 @@ skip_efpl: sim->efli_length =0 ; } -if (efli) { -g_slist_free_full (efli, g_free); - } - -if (efpl) { -g_slist_free_full (efpl, g_free); - } -if (sim->language_prefs !=NULL ) ofono_dbus_signal_array_property_changed(conn, path, OFONO_SIM_MANAGER_INTERFACE,
src/simutil.c +62 -0
65 lines not on this page · raw message
src/simutil.h +3 -0
@@ -541,3 +541,6 @@ gboolean sim_parse_umts_authenticate(const unsigned char *buffer, int len,gboolean sim_parse_gsm_authenticate (const unsigned char *buffer,int len,const unsigned char **sres,const unsigned char **kc); + +char **sim_parse_language_list (const unsigned char *ef,int length); +char **sim_parse_eflp (const unsigned char *eflp,int length);
Signature · 1 line
2.43.0
PATCH 4/6 unit: Add unit tests for language list parsers
In reply to Denis KenziorAdd unit tests for the newly moved sim_parse_language_list and sim_parse_eflp functions.
--- unit/test-simutil.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
unit/test-simutil.c +57 -0
@@ -695,6 +695,59 @@ static void test_auth_build_parse(void)g_assert (!memcmp (kc_b.data, kc,sizeof (kc))); } +static void test_parse_language_list (void ) +{ +static const unsigned char empty[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff + }; +static const unsigned char efpl[] = { +'e' ,'n' ,0xff ,0xff ,'d' ,'e' ,'f' ,'r' ,0xff ,0xff ,'n' ,'l' + }; + +char **parsed; +char *joined; + + parsed =sim_parse_language_list (empty,sizeof (empty)); +assert (!parsed); + + parsed =sim_parse_language_list (efpl,sizeof (efpl)); +assert (parsed); + joined =l_strjoinv (parsed,':' ); +assert (!strcmp (joined,"en:de:fr:nl" )); +l_strfreev (parsed); +l_free (joined); + + parsed =sim_parse_language_list (efpl,sizeof (efpl) -1 ); +assert (parsed); + joined =l_strjoinv (parsed,':' ); +assert (!strcmp (joined,"en:de:fr" )); +l_strfreev (parsed); +l_free (joined); +} + +static void test_parse_eflp (void ) +{ +static const unsigned char empty[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff + }; +static const unsigned char eflp[] = { +0x00 ,0x01 ,0x02 ,0x03 ,0x04 ,0x05 + }; + +char **parsed; +char *joined; + + parsed =sim_parse_eflp (empty,sizeof (empty)); +assert (!parsed); + + parsed =sim_parse_eflp (eflp,sizeof (eflp)); +assert (parsed); + joined =l_strjoinv (parsed,':' ); +assert (!strcmp (joined,"de:en:it:fr:es:nl" )); +l_strfreev (parsed); +l_free (joined); +} +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
@@ -716,5 +769,9 @@ int main(int argc, char **argv)g_test_add_func ("/testsimutil/2G path" , test_get_2g_path);g_test_add_func ("/testsimutil/auth build parse" , test_auth_build_parse); +g_test_add_func ("/testsimutil/parse_language_list" , + test_parse_language_list); +g_test_add_func ("/testsimutil/parse_efpl" , test_parse_eflp); +return g_test_run (); }
Signature · 1 line
2.43.0
PATCH 5/6 common: Convert use of g_ascii* to ell
In reply to Denis KenziorAlso remove the glib header include since no other GLib use remains.
--- src/common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
src/common.c +2 -3
@@ -27,7 +27,6 @@#include <string.h> #include <errno.h> -#include <glib.h> #include <ell/ell.h> #include <ofono/types.h>
@@ -561,7 +560,7 @@ gboolean parse_ss_control_string(char *str, int *ss_type, goto out;for (i =0 ; i <strlen (*sc); i++) -if (!g_ascii_isdigit ((*sc)[i])) +if (!l_ascii_isdigit ((*sc)[i])) goto out;NEXT_FIELD (c, *sia);
@@ -681,7 +680,7 @@ gboolean is_valid_apn(const char *apn)return FALSE;for (i =0 ; apn[i] !='\0' ; i++) { -if (g_ascii_isalnum (apn[i])) +if (l_ascii_isalnum (apn[i]))continue ;if (apn[i] =='-' )
Signature · 1 line
2.43.0
PATCH 6/6 voicecall: Convert use of g_ascii* to ell
In reply to Denis Kenzior--- src/voicecall.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
src/voicecall.c +4 -6
@@ -340,7 +340,7 @@ static int tone_queue(struct ofono_voicecall *vc, const char *tone_str,* and p for Pause. */ for (i =0 ; tone_str[i]; i++) -if (!g_ascii_isdigit (tone_str[i]) && tone_str[i] !='p' && +if (!l_ascii_isdigit (tone_str[i]) && tone_str[i] !='p' && tone_str[i] !='P' && tone_str[i] !='*' && tone_str[i] !='#' && (tone_str[i] <'A' || tone_str[i] >'D' ))
@@ -2196,11 +2196,9 @@ static DBusMessage *manager_tone(DBusConnection *conn,if (len ==0 )return __ofono_error_invalid_format (msg); - tones =g_ascii_strup (in_tones, len); - + tones =l_ascii_strup (in_tones, len); err =tone_queue (vc, tones, tone_callback, vc,NULL ); - -g_free (tones); +l_free (tones);if (err <0 )return __ofono_error_invalid_format (msg);
@@ -3440,7 +3438,7 @@ static void emulator_vts_cb(struct ofono_emulator *em,if (str ==NULL )break ; -if (!g_ascii_isdigit (str[0 ]) && str[0 ] !='*' && +if (!l_ascii_isdigit (str[0 ]) && str[0 ] !='*' && str[0 ] !='#' && (str[0 ] <'A' || str[0 ] >'D' ))break ;
Signature · 1 line
2.43.0
This series was applied to ofono.git (master) by Denis Kenzior <[email protected]>:
Hello:
This series was applied to ofono.git (master)
by Denis Kenzior <[email protected]>:
Quoted 7 lines · On Tue, 13 Feb 2024 09:35:05 -0600 you wrote:
Change the return signature to use bool instead of gboolean. Also, change
g_ascii_isalphause tol_ascii_isalpha. While here, also update array subscripts to follow the coding style, item M3--- src/sim.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
Here is the summary with links:
- [1/6] sim: Drop glib use from sim_efli_format
https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=085637842bf1 - [2/6] smsutil: Move iso639_2_from_language to util https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=f7fc3fb342e7 - [3/6] sim: Move EFli and EFlp parsers to simutil https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=dcc67adb9a01 - [4/6] unit: Add unit tests for language list parsers https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=43989a59566a - [5/6] common: Convert use of g_ascii* to ell https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=ad10d7b0189c - [6/6] voicecall: Convert use of g_ascii* to ell https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=a1e492c39bae
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html