# HG changeset patch # User Sascha Wilde # Date 1395506772 -3600 # Node ID 24ca8e2ceecf8fbb53458c646132d1ed6081bde1 # Parent d6a74464430b961dd67ad16bd0d57d2765e2e0c1 First step of simple mozilla ini parser extracts profile path configuration lines and prints them to stdout for debugging.. diff -r d6a74464430b -r 24ca8e2ceecf cinst/mozilla.c --- a/cinst/mozilla.c Sat Mar 22 17:28:55 2014 +0100 +++ b/cinst/mozilla.c Sat Mar 22 17:46:12 2014 +0100 @@ -46,8 +46,13 @@ * encoded. * */ +#include +#include +#include +#include + #include -#include +#include #ifndef _WIN32 #define UNIX 1 @@ -55,9 +60,18 @@ #define UNIX 0 #endif +/** + * @brief Global Return Code + * + * This will be retuned by the programm and might be set to an + * error code on fatal errors and to and warning code on non-fatal + * errors. In case of mor than one warning the warning codes will be + * ORed together. + */ +int return_code = 0; /** - * @brief Get a list of all mozilla profile directories + * @brief Get a list of all mozilla profile directories * * Read the profiles.ini and extract all profile paths from that. * @@ -66,12 +80,43 @@ * absolute path of the profile directories. The array needs to * be freed by the caller. */ -//char** -//get_profile_dirs(char* inifile) +static char ** +get_profile_dirs (char *inifile_name) +{ + char **dirs = NULL; + FILE *inifile; + char line[1000]; + bool inprofile = false; + if ((inifile = fopen(inifile_name, "r")) != NULL) + { + while (fgets(line, 1000, inifile) != NULL) + { + if (strncmp(line, "[Profile", 8) == 0) + inprofile = true; + else if (line[0] == '[') + inprofile = false; + if (inprofile && + (strncmp(line, "Path=", 5) == 0)) + strv_append(&dirs, line, strlen(line)); + } + } + else + { + return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; + } + + return dirs; +} int -main() +main () { - exit(0); + int x = 0; + char **pdirs = + get_profile_dirs("/home/wilde/.mozilla/firefox/profiles.ini"); + while (pdirs[x] != NULL) + puts(pdirs[x++]); + strv_free(pdirs); + exit(return_code); }