Mercurial > trustbridge
comparison cinst/mozilla.c @ 173:a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Tue, 25 Mar 2014 16:20:04 +0100 |
parents | a46a4b443410 |
children | 6eb9149b65e1 |
comparison
equal
deleted
inserted
replaced
172:7b9545ad76f6 | 173:a9e4454dee97 |
---|---|
46 * | 46 * |
47 * Mozilla also accepts the ini file on Windows even if it is UTF-16 | 47 * Mozilla also accepts the ini file on Windows even if it is UTF-16 |
48 * encoded. | 48 * encoded. |
49 * */ | 49 * */ |
50 | 50 |
51 #include <dirent.h> | |
51 #include <stdbool.h> | 52 #include <stdbool.h> |
52 #include <stdio.h> | 53 #include <stdio.h> |
53 #include <stdlib.h> | 54 #include <stdlib.h> |
54 #include <string.h> | 55 #include <string.h> |
55 | 56 #include <sys/types.h> |
57 | |
58 #include <debug.h> | |
56 #include <errorcodes.h> | 59 #include <errorcodes.h> |
57 #include <portpath.h> | 60 #include <portpath.h> |
58 #include <strhelp.h> | 61 #include <strhelp.h> |
59 | 62 |
60 #ifndef _WIN32 | 63 #ifndef _WIN32 |
61 #define UNIX 1 | 64 #define LINUX 1 |
62 #else | 65 #else |
63 #define UNIX 0 | 66 #define LINUX 0 |
64 #endif | 67 #endif |
65 | 68 |
66 #define LINEBUFLEN 1000 | 69 #define LINEBUFLEN 1000 |
67 | 70 |
68 /** | 71 /** |
144 return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; | 147 return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; |
145 } | 148 } |
146 return dirs; | 149 return dirs; |
147 } | 150 } |
148 | 151 |
152 /** | |
153 * @brief Search for mozilla profiles.ini files | |
154 * | |
155 * Use well known paths and heuristics to find the current users | |
156 * profiles.ini files on GNU/Linux and Windows systems. | |
157 * | |
158 * @return NULL terminated array of strings containing the absolute | |
159 * path of the profiles.ini files. The array needs to be freed by the | |
160 * caller. | |
161 */ | |
162 static char ** | |
163 get_profile_inis () | |
164 { | |
165 char **inis = NULL; | |
166 char path[LINEBUFLEN]; | |
167 char *fqpath; | |
168 DIR *mozdir; | |
169 struct dirent *mozdirent; | |
170 | |
171 if (LINUX) | |
172 { | |
173 /* Search in $HOME/.mozilla */ | |
174 char *home; | |
175 | |
176 if ((home = getenv("HOME")) == NULL) | |
177 { | |
178 DEBUGFPRINT("DEBUG: FATAL! No HOME in environment.\n") | |
179 exit(ERR_MOZ_HOMELESS); | |
180 } | |
181 | |
182 snprintf(path, LINEBUFLEN, "%s/%s", home, "/.mozilla"); | |
183 if ((mozdir = opendir(path)) != NULL) | |
184 { | |
185 while ((mozdirent = readdir(mozdir)) != NULL) | |
186 { | |
187 if (mozdirent->d_type == DT_DIR) | |
188 { | |
189 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", | |
190 home, | |
191 "/.mozilla", | |
192 mozdirent->d_name, | |
193 "profiles.ini"); | |
194 DEBUGFPRINT("DEBUG: checking for %s...\n", path); | |
195 if ((fqpath = port_realpath(path)) != NULL) | |
196 { | |
197 strv_append(&inis, fqpath, strlen(fqpath)); | |
198 DEBUGFPRINT("DEBUG: Found mozilla ini file: '%s'\n", fqpath); | |
199 free(fqpath); | |
200 } | |
201 } | |
202 } | |
203 closedir(mozdir); | |
204 } | |
205 else | |
206 { | |
207 DEBUGFPRINT("DEBUG: Could not open %s/.mozilla\n", home) | |
208 exit(WARN_MOZ_NO_PROFILES); | |
209 } | |
210 } | |
211 else | |
212 { | |
213 /* Windows */ | |
214 fprintf(stderr, "Windows not yet supported"); | |
215 abort(); | |
216 } | |
217 return inis; | |
218 } | |
219 | |
220 | |
149 int | 221 int |
150 main (int argc, char *argv[]) | 222 main () |
151 { | 223 { |
152 int x = 0; | 224 int x = 0; |
153 if (argc == 2) | 225 int y = 0; |
154 { | 226 char **mozinis, **pdirs; |
155 char **pdirs = | 227 if ((mozinis = get_profile_inis()) != NULL) |
156 get_profile_dirs(argv[1]); | 228 while (mozinis[y] != NULL) |
157 if (pdirs != NULL) | 229 { |
158 { | 230 pdirs = |
159 while (pdirs[x] != NULL) | 231 get_profile_dirs(mozinis[y++]); |
160 puts(pdirs[x++]); | 232 if (pdirs != NULL) |
161 strv_free(pdirs); | 233 { |
162 } | 234 while (pdirs[x] != NULL) |
163 } | 235 puts(pdirs[x++]); |
236 strv_free(pdirs); | |
237 } | |
238 } | |
164 exit(return_code); | 239 exit(return_code); |
165 } | 240 } |