# HG changeset patch # User Sascha Wilde # Date 1395833890 -3600 # Node ID 56ae02b4a0fc1dd7ba81d49cd0d59f5850ddbf92 # Parent 5d380b6621983eee7df436d72d8523dff161d9af# Parent 17eb8ad43984def9166784649013f5b818531bcf Merged diff -r 17eb8ad43984 -r 56ae02b4a0fc cinst/CMakeLists.txt --- a/cinst/CMakeLists.txt Wed Mar 26 12:22:24 2014 +0100 +++ b/cinst/CMakeLists.txt Wed Mar 26 12:38:10 2014 +0100 @@ -32,4 +32,6 @@ ${POLARSSL_LIBRARIES} ${PROFILING_LIBS}) +set_target_properties(mozilla PROPERTIES COMPILE_FLAGS "-std=c99") + install(TARGETS mozilla DESTINATION bin) diff -r 17eb8ad43984 -r 56ae02b4a0fc cinst/mozilla.c --- a/cinst/mozilla.c Wed Mar 26 12:22:24 2014 +0100 +++ b/cinst/mozilla.c Wed Mar 26 12:38:10 2014 +0100 @@ -61,8 +61,10 @@ #include #ifndef _WIN32 +#define CONFDIRS ".mozilla", ".thunderbird" #define LINUX 1 #else +#define CONFDIRS "Mozilla", "Thunderbird" #define LINUX 0 #endif @@ -79,44 +81,28 @@ int return_code = 0; /** - * @brief Return users home path, on windows including drive letter - * @returns a pointer to a string containing the home path, it should - * be freed by the caller. + * @brief Return configuration base directory. + * @returns A pointer to a string containing the path to the base + * directory holding the configuration directories for e.g. mozilla + * and thunderbird. */ static char * -get_home() +get_conf_basedir() { - char *home, *homevar, *fqhome; - char *homedrive = NULL; + char *cdir, *envvar; - size_t len; if (LINUX) - homevar = "HOME"; + envvar = "HOME" ; else - homevar = "HOMEPATH"; + envvar = "APPDATA"; - if ((home = getenv(homevar)) == NULL) + if ((cdir = getenv(envvar)) != NULL) + return cdir; + else { - DEBUGFPRINT("DEBUG: FATAL! No HOME in environment.\n"); + DEBUGFPRINT("DEBUG: FATAL! No %s in environment.\n", envvar); exit(ERR_MOZ_HOMELESS); } - - len = strlen(home); - if (!LINUX) - homedrive = getenv("HOMEDRIVE"); - - if (homedrive != NULL) - len += strlen(homedrive); - - len++; /* Room for \0 */ - fqhome = xmalloc(len); - - if (homedrive == NULL) - snprintf(fqhome, len, "%s", home); - else - snprintf(fqhome, len, "%s%s", homedrive, home); - - return fqhome; } /** @@ -214,50 +200,51 @@ char **inis = NULL; char path[LINEBUFLEN]; char *fqpath; - char *mozdirname; DIR *mozdir; struct dirent *mozdirent; - char *home = get_home(); + char *confbase = get_conf_basedir(); + const char *confdirs[] = { CONFDIRS, NULL }; - if (LINUX) + for (int i=0; confdirs[i] != NULL; i++) { - mozdirname = ".mozilla"; - } - else - { - mozdirname = "AppData/Roaming/Mozilla"; - } - - snprintf(path, LINEBUFLEN, "%s/%s", home, mozdirname); - if ((mozdir = opendir(path)) != NULL) - { - while ((mozdirent = readdir(mozdir)) != NULL) + snprintf(path, LINEBUFLEN, "%s/%s", + confbase, + confdirs[i]); + if ((mozdir = opendir(path)) != NULL) { - snprintf(path, LINEBUFLEN, "%s/%s/%s", - home, - mozdirname, - mozdirent->d_name); - if (port_isdir(path)) + while ((mozdirent = readdir(mozdir)) != NULL) { - snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", - home, - mozdirname, - mozdirent->d_name, - "profiles.ini"); - DEBUGFPRINT("DEBUG: checking for %s...\n", path); - if ((fqpath = port_realpath(path)) != NULL) + snprintf(path, LINEBUFLEN, "%s/%s/%s", + confbase, + confdirs[i], + mozdirent->d_name); + if (port_isdir(path) + && (strcmp(mozdirent->d_name, "..") != 0)) { - strv_append(&inis, fqpath, strlen(fqpath)); - DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath); - free(fqpath); + snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", + confbase, + confdirs[i], + 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); } - closedir(mozdir); + else + { + DEBUGFPRINT("DEBUG: Could not open %s/%s\n", confbase, confdirs[i]); + } } - else + if (inis == NULL) { - DEBUGFPRINT("DEBUG: Could not open %s/%s\n", home, mozdirname); + DEBUGFPRINT("DEBUG: No ini files found - will do nothing!\n"); exit(WARN_MOZ_NO_PROFILES); } return inis; @@ -277,6 +264,7 @@ get_profile_dirs(mozinis[y++]); if (pdirs != NULL) { + x = 0; while (pdirs[x] != NULL) puts(pdirs[x++]); strv_free(pdirs);