# HG changeset patch # User Sascha Wilde # Date 1395760804 -3600 # Node ID a9e4454dee97d7ed74cfb7f148cfb41cbd673e5b # Parent 7b9545ad76f67c23e3ffb9ef789c0df07dcd4f9a Implemented searching $HOME/.mozilla for profiles.ini on Linux. diff -r 7b9545ad76f6 -r a9e4454dee97 cinst/mozilla.c --- a/cinst/mozilla.c Tue Mar 25 15:20:06 2014 +0100 +++ b/cinst/mozilla.c Tue Mar 25 16:20:04 2014 +0100 @@ -48,19 +48,22 @@ * encoded. * */ +#include #include #include #include #include +#include +#include #include #include #include #ifndef _WIN32 -#define UNIX 1 +#define LINUX 1 #else -#define UNIX 0 +#define LINUX 0 #endif #define LINEBUFLEN 1000 @@ -146,20 +149,92 @@ return dirs; } +/** + * @brief Search for mozilla profiles.ini files + * + * Use well known paths and heuristics to find the current users + * profiles.ini files on GNU/Linux and Windows systems. + * + * @return NULL terminated array of strings containing the absolute + * path of the profiles.ini files. The array needs to be freed by the + * caller. + */ +static char ** +get_profile_inis () +{ + char **inis = NULL; + char path[LINEBUFLEN]; + char *fqpath; + DIR *mozdir; + struct dirent *mozdirent; + + if (LINUX) + { + /* Search in $HOME/.mozilla */ + char *home; + + if ((home = getenv("HOME")) == NULL) + { + DEBUGFPRINT("DEBUG: FATAL! No HOME in environment.\n") + exit(ERR_MOZ_HOMELESS); + } + + snprintf(path, LINEBUFLEN, "%s/%s", home, "/.mozilla"); + if ((mozdir = opendir(path)) != NULL) + { + while ((mozdirent = readdir(mozdir)) != NULL) + { + if (mozdirent->d_type == DT_DIR) + { + snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", + home, + "/.mozilla", + mozdirent->d_name, + "profiles.ini"); + DEBUGFPRINT("DEBUG: checking for %s...\n", path); + if ((fqpath = port_realpath(path)) != NULL) + { + strv_append(&inis, fqpath, strlen(fqpath)); + DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath); + free(fqpath); + } + } + } + closedir(mozdir); + } + else + { + DEBUGFPRINT("DEBUG: Could not open %s/.mozilla\n", home) + exit(WARN_MOZ_NO_PROFILES); + } + } + else + { + /* Windows */ + fprintf(stderr, "Windows not yet supported"); + abort(); + } + return inis; +} + + int -main (int argc, char *argv[]) +main () { int x = 0; - if (argc == 2) - { - char **pdirs = - get_profile_dirs(argv[1]); - if (pdirs != NULL) - { - while (pdirs[x] != NULL) - puts(pdirs[x++]); - strv_free(pdirs); - } - } + 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) + { + while (pdirs[x] != NULL) + puts(pdirs[x++]); + strv_free(pdirs); + } + } exit(return_code); } diff -r 7b9545ad76f6 -r a9e4454dee97 common/errorcodes.h --- a/common/errorcodes.h Tue Mar 25 15:20:06 2014 +0100 +++ b/common/errorcodes.h Tue Mar 25 16:20:04 2014 +0100 @@ -27,9 +27,14 @@ * Warnings might be ORed together ... */ +/* Error: could not determine current users HOME */ +#define ERR_MOZ_HOMELESS 0x0081 + /* Warning: Failed to read profile.ini */ #define WARN_MOZ_FAILED_TO_OPEN_INI 0x0091 /* Warning: Some profile paths from profile.ini don't exist */ #define WARN_MOZ_PROFILE_DOES_NOT_EXIST 0x0092 +/* Warning: no profiles found */ +#define WARN_MOZ_NO_PROFILES 0x0094 #endif