# HG changeset patch # User Sascha Wilde # Date 1395999955 -3600 # Node ID c342b93c5bd141591773938a3f1ed28f45aefbc9 # Parent 92b1e5ed2d5f2ef6baedee4611f04098806c0069 Refactoring. diff -r 92b1e5ed2d5f -r c342b93c5bd1 cinst/mozilla.c --- a/cinst/mozilla.c Fri Mar 28 10:32:55 2014 +0100 +++ b/cinst/mozilla.c Fri Mar 28 10:45:55 2014 +0100 @@ -265,6 +265,37 @@ } /** + * @brief Collect all mozilla profile directories of current user. + * @return NULL terminated array of strings containing the absolute + * path of the profile directories. The array needs to be freed by the + * caller. + */ +static char** +get_all_profile_dirs() +{ + char **mozinis, **pdirs; + char **alldirs = NULL; + if ((mozinis = get_profile_inis()) != NULL) + { + for (int i=0; mozinis[i] != NULL; i++) + { + pdirs = + get_profile_dirs(mozinis[i]); + if (pdirs != NULL) + { + for (int i=0; pdirs[i] != NULL; i++) + { + strv_append(&alldirs, pdirs[i], strlen(pdirs[i])); + } + strv_free(pdirs); + } + } + strv_free(mozinis); + } + return alldirs; +} + +/** * @brief list certificates from nss certificate store * @param[in] confdir the directory with the certificate store */ @@ -296,22 +327,17 @@ int main () { - int y = 0; - char **mozinis, **pdirs; - if ((mozinis = get_profile_inis()) != NULL) - while (mozinis[y] != NULL) - { - pdirs = - get_profile_dirs(mozinis[y++]); - if (pdirs != NULL) - { - for (int x=0; pdirs[x] != NULL; x++) - { - puts(pdirs[x]); - nss_list_certs(pdirs[x]); - } - strv_free(pdirs); - } - } + char **pdirs; + pdirs = + get_all_profile_dirs(); + if (pdirs != NULL) + { + for (int i=0; pdirs[i] != NULL; i++) + { + puts(pdirs[i]); + nss_list_certs(pdirs[i]); + } + strv_free(pdirs); + } exit(return_code); }