comparison cinst/mozilla.c @ 320:1628615d904e

Replaced snprintf and static buffers with xasprintf.
author Sascha Wilde <wilde@intevation.de>
date Fri, 04 Apr 2014 18:00:40 +0200
parents 46fd11699646
children e30c9fee111a
comparison
equal deleted inserted replaced
319:4077eff1dd39 320:1628615d904e
150 char *inifile_dirname; 150 char *inifile_dirname;
151 FILE *inifile; 151 FILE *inifile;
152 char line[LINEBUFLEN]; 152 char line[LINEBUFLEN];
153 char *key; 153 char *key;
154 char *value; 154 char *value;
155 char path[LINEBUFLEN]; 155 char *path = NULL;
156 char *fqpath; 156 char *fqpath;
157 bool inprofile = false; 157 bool inprofile = false;
158 bool relative_path = false; 158 bool relative_path = false;
159 159
160 if ((inifile = fopen(inifile_name, "r")) != NULL) 160 if ((inifile = fopen(inifile_name, "r")) != NULL)
180 value = strtok(NULL, "="); 180 value = strtok(NULL, "=");
181 str_trim(&value); 181 str_trim(&value);
182 if (str_equal(key, "Path")) 182 if (str_equal(key, "Path"))
183 { 183 {
184 if (relative_path) 184 if (relative_path)
185 snprintf(path, LINEBUFLEN, "%s/%s", inifile_dirname, value); 185 xasprintf(&path, "%s/%s", inifile_dirname, value);
186 else 186 else
187 strncpy(path, value, LINEBUFLEN); 187 xasprintf(&path, "%s", value); /* FIXME: LOOKS STUPID! */
188 if ((fqpath = port_realpath(path)) != NULL) 188 if ((fqpath = port_realpath(path)) != NULL)
189 { 189 {
190 DEBUGPRINTF("Found profile path: '%s'\n", fqpath); 190 DEBUGPRINTF("Found profile path: '%s'\n", fqpath);
191 strv_append(&dirs, fqpath, strlen(fqpath)); 191 strv_append(&dirs, fqpath, strlen(fqpath));
192 free (fqpath); 192 free (fqpath);
194 else 194 else
195 { 195 {
196 DEBUGPRINTF("WARN! Non existent profile path: '%s'\n", path); 196 DEBUGPRINTF("WARN! Non existent profile path: '%s'\n", path);
197 exit_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST; 197 exit_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST;
198 } 198 }
199 free(path);
199 } 200 }
200 else if (str_equal(key, "IsRelative") && 201 else if (str_equal(key, "IsRelative") &&
201 str_starts_with(value, "1")) 202 str_starts_with(value, "1"))
202 relative_path = true; 203 relative_path = true;
203 } 204 }
224 */ 225 */
225 static char ** 226 static char **
226 get_profile_inis () 227 get_profile_inis ()
227 { 228 {
228 char **inis = NULL; 229 char **inis = NULL;
229 char path[LINEBUFLEN]; 230 char *mozpath, *fqpath, *subpath, *ppath;
230 char *fqpath;
231 DIR *mozdir; 231 DIR *mozdir;
232 struct dirent *mozdirent; 232 struct dirent *mozdirent;
233 char *confbase = get_conf_basedir(); 233 char *confbase = get_conf_basedir();
234 const char *confdirs[] = { CONFDIRS, NULL }; 234 const char *confdirs[] = { CONFDIRS, NULL };
235 235
236 for (int i=0; confdirs[i] != NULL; i++) 236 for (int i=0; confdirs[i] != NULL; i++)
237 { 237 {
238 snprintf(path, LINEBUFLEN, "%s/%s", 238 xasprintf(&mozpath,"%s/%s", confbase, confdirs[i]);
239 confbase, 239 if ((mozdir = opendir(mozpath)) != NULL)
240 confdirs[i]);
241 if ((mozdir = opendir(path)) != NULL)
242 { 240 {
243 while ((mozdirent = readdir(mozdir)) != NULL) 241 while ((mozdirent = readdir(mozdir)) != NULL)
244 { 242 {
245 snprintf(path, LINEBUFLEN, "%s/%s/%s", 243 xasprintf(&subpath, "%s/%s/%s",
246 confbase, 244 confbase,
247 confdirs[i], 245 confdirs[i],
248 mozdirent->d_name); 246 mozdirent->d_name);
249 if (port_isdir(path) 247 if (port_isdir(subpath)
250 && (strcmp(mozdirent->d_name, "..") != 0)) 248 && (strcmp(mozdirent->d_name, "..") != 0))
251 { 249 {
252 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", 250 xasprintf(&ppath, "%s/%s/%s/%s",
253 confbase, 251 confbase,
254 confdirs[i], 252 confdirs[i],
255 mozdirent->d_name, 253 mozdirent->d_name,
256 "profiles.ini"); 254 "profiles.ini");
257 DEBUGPRINTF("checking for %s...\n", path); 255 DEBUGPRINTF("checking for %s...\n", ppath);
258 if ((fqpath = port_realpath(path)) != NULL) 256 if ((fqpath = port_realpath(ppath)) != NULL)
259 { 257 {
260 strv_append(&inis, fqpath, strlen(fqpath)); 258 strv_append(&inis, fqpath, strlen(fqpath));
261 DEBUGPRINTF("Found mozilla ini file: '%s'\n", fqpath); 259 DEBUGPRINTF("Found mozilla ini file: '%s'\n", fqpath);
262 free(fqpath); 260 free(fqpath);
263 } 261 }
262 free(ppath);
264 } 263 }
264 free(subpath);
265 } 265 }
266 closedir(mozdir); 266 closedir(mozdir);
267 } 267 }
268 else 268 else
269 { 269 {
270 DEBUGPRINTF("Could not open %s/%s\n", confbase, confdirs[i]); 270 DEBUGPRINTF("Could not open %s/%s\n", confbase, confdirs[i]);
271 } 271 }
272 free(mozpath);
272 } 273 }
273 if (inis == NULL) 274 if (inis == NULL)
274 { 275 {
275 DEBUGPRINTF("No ini files found - will do nothing!\n"); 276 DEBUGPRINTF("No ini files found - will do nothing!\n");
276 } 277 }
307 strv_free(mozinis); 308 strv_free(mozinis);
308 } 309 }
309 /* Search for NSS shared DB (used by Chrome/Chromium on GNU/Linux) */ 310 /* Search for NSS shared DB (used by Chrome/Chromium on GNU/Linux) */
310 if (TARGET_LINUX) 311 if (TARGET_LINUX)
311 { 312 {
312 char buf[LINEBUFLEN], *fqpath; 313 char *path, *fqpath, *sqlpath;
313 snprintf(buf, LINEBUFLEN, "%s/%s", 314 xasprintf(&path, "%s/%s", get_conf_basedir(), NSSSHARED);
314 get_conf_basedir(), NSSSHARED); 315 if ((fqpath = port_realpath(path)) != NULL)
315 if ((fqpath = port_realpath(buf)) != NULL) 316 {
316 { 317 xasprintf(&sqlpath, "sql:%s", fqpath);
317 snprintf(buf, LINEBUFLEN, "sql:%s", fqpath); 318 strv_append(&alldirs, sqlpath, strlen(sqlpath));
318 strv_append(&alldirs, buf, strlen(buf)); 319 free(sqlpath);
319 free(fqpath); 320 free(fqpath);
320 } 321 }
322 free(path);
321 } 323 }
322 return alldirs; 324 return alldirs;
323 } 325 }
324 326
325 #ifdef DEBUGOUTPUT 327 #ifdef DEBUGOUTPUT

http://wald.intevation.org/projects/trustbridge/