4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include <string.h> /* strdup */
30 #include <sys/utsname.h> /* uname */
39 /* global config variable */
40 config_t
*config
= NULL
;
42 config_t
*config_new(void)
44 config_t
*newconfig
= calloc(1, sizeof(config_t
));
46 pm_fprintf(stderr
, ALPM_LOG_ERROR
,
47 _("malloc failure: could not allocate %zd bytes\n"),
51 /* defaults which may get overridden later */
52 newconfig
->op
= PM_OP_MAIN
;
53 newconfig
->logmask
= ALPM_LOG_ERROR
| ALPM_LOG_WARNING
;
54 newconfig
->configfile
= strdup(CONFFILE
);
55 newconfig
->siglevel
= ALPM_SIG_USE_DEFAULT
;
60 int config_free(config_t
*oldconfig
)
62 if(oldconfig
== NULL
) {
66 FREELIST(oldconfig
->holdpkg
);
67 FREELIST(oldconfig
->syncfirst
);
68 FREELIST(oldconfig
->ignorepkg
);
69 FREELIST(oldconfig
->ignoregrp
);
70 FREELIST(oldconfig
->noupgrade
);
71 FREELIST(oldconfig
->noextract
);
72 free(oldconfig
->configfile
);
73 free(oldconfig
->rootdir
);
74 free(oldconfig
->dbpath
);
75 free(oldconfig
->logfile
);
76 free(oldconfig
->gpgdir
);
77 FREELIST(oldconfig
->cachedirs
);
78 free(oldconfig
->xfercommand
);
79 free(oldconfig
->print_format
);
80 free(oldconfig
->arch
);
87 /** Helper function for download_with_xfercommand() */
88 static char *get_filename(const char *url
) {
89 char *filename
= strrchr(url
, '/');
90 if(filename
!= NULL
) {
96 /** Helper function for download_with_xfercommand() */
97 static char *get_destfile(const char *path
, const char *filename
) {
99 /* len = localpath len + filename len + null */
100 size_t len
= strlen(path
) + strlen(filename
) + 1;
101 destfile
= calloc(len
, sizeof(char));
102 snprintf(destfile
, len
, "%s%s", path
, filename
);
107 /** Helper function for download_with_xfercommand() */
108 static char *get_tempfile(const char *path
, const char *filename
) {
110 /* len = localpath len + filename len + '.part' len + null */
111 size_t len
= strlen(path
) + strlen(filename
) + 6;
112 tempfile
= calloc(len
, sizeof(char));
113 snprintf(tempfile
, len
, "%s%s.part", path
, filename
);
118 /** External fetch callback */
119 static int download_with_xfercommand(const char *url
, const char *localpath
,
125 char *parsedcmd
,*tempcmd
;
128 char *destfile
, *tempfile
, *filename
;
130 if(!config
->xfercommand
) {
134 filename
= get_filename(url
);
138 destfile
= get_destfile(localpath
, filename
);
139 tempfile
= get_tempfile(localpath
, filename
);
141 if(force
&& stat(tempfile
, &st
) == 0) {
144 if(force
&& stat(destfile
, &st
) == 0) {
148 tempcmd
= strdup(config
->xfercommand
);
149 /* replace all occurrences of %o with fn.part */
150 if(strstr(tempcmd
, "%o")) {
152 parsedcmd
= strreplace(tempcmd
, "%o", tempfile
);
156 /* replace all occurrences of %u with the download URL */
157 parsedcmd
= strreplace(tempcmd
, "%u", url
);
160 /* save the cwd so we can restore it later */
161 if(getcwd(cwd
, PATH_MAX
) == NULL
) {
162 pm_printf(ALPM_LOG_ERROR
, _("could not get current working directory\n"));
167 /* cwd to the download directory */
168 if(chdir(localpath
)) {
169 pm_printf(ALPM_LOG_WARNING
, _("could not chdir to download directory %s\n"), localpath
);
173 /* execute the parsed command via /bin/sh -c */
174 pm_printf(ALPM_LOG_DEBUG
, "running command: %s\n", parsedcmd
);
175 retval
= system(parsedcmd
);
178 pm_printf(ALPM_LOG_WARNING
, _("running XferCommand: fork failed!\n"));
180 } else if(retval
!= 0) {
181 /* download failed */
182 pm_printf(ALPM_LOG_DEBUG
, "XferCommand command returned non-zero status "
183 "code (%d)\n", retval
);
186 /* download was successful */
188 rename(tempfile
, destfile
);
194 /* restore the old cwd if we have it */
195 if(restore_cwd
&& chdir(cwd
) != 0) {
196 pm_printf(ALPM_LOG_ERROR
, _("could not change directory to %s (%s)\n"),
197 cwd
, strerror(errno
));
201 /* hack to let an user the time to cancel a download */
212 int config_set_arch(const char *arch
)
214 if(strcmp(arch
, "auto") == 0) {
217 config
->arch
= strdup(un
.machine
);
219 config
->arch
= strdup(arch
);
221 pm_printf(ALPM_LOG_DEBUG
, "config: arch: %s\n", config
->arch
);
226 * Parse a signature verification level line.
227 * @param values the list of parsed option values
228 * @param storage location to store the derived signature level; any existing
229 * value here is used as a starting point
230 * @return 0 on success, 1 on any parsing error
232 static int process_siglevel(alpm_list_t
*values
, alpm_siglevel_t
*storage
)
234 alpm_siglevel_t level
= *storage
;
238 /* Collapse the option names into a single bitmasked value */
239 for(i
= values
; i
; i
= alpm_list_next(i
)) {
240 const char *original
= i
->data
, *value
;
241 int package
= 0, database
= 0;
243 if (strncmp(original
, "Package", strlen("Package")) == 0) {
244 /* only packages are affected, don't flip flags for databases */
245 value
= original
+ strlen("Package");
247 } else if (strncmp(original
, "Database", strlen("Database")) == 0) {
248 /* only databases are affected, don't flip flags for packages */
249 value
= original
+ strlen("Database");
252 /* no prefix, so anything found will affect both packages and dbs */
254 package
= database
= 1;
257 /* now parse out and store actual flag if it is valid */
258 if(strcmp(value
, "Never") == 0) {
260 level
&= ~ALPM_SIG_PACKAGE
;
263 level
&= ~ALPM_SIG_DATABASE
;
265 } else if(strcmp(value
, "Optional") == 0) {
267 level
|= ALPM_SIG_PACKAGE
;
268 level
|= ALPM_SIG_PACKAGE_OPTIONAL
;
271 level
|= ALPM_SIG_DATABASE
;
272 level
|= ALPM_SIG_DATABASE_OPTIONAL
;
274 } else if(strcmp(value
, "Required") == 0) {
276 level
|= ALPM_SIG_PACKAGE
;
277 level
&= ~ALPM_SIG_PACKAGE_OPTIONAL
;
280 level
|= ALPM_SIG_DATABASE
;
281 level
&= ~ALPM_SIG_DATABASE_OPTIONAL
;
283 } else if(strcmp(value
, "TrustedOnly") == 0) {
285 level
&= ~ALPM_SIG_PACKAGE_MARGINAL_OK
;
286 level
&= ~ALPM_SIG_PACKAGE_UNKNOWN_OK
;
289 level
&= ~ALPM_SIG_DATABASE_MARGINAL_OK
;
290 level
&= ~ALPM_SIG_DATABASE_UNKNOWN_OK
;
292 } else if(strcmp(value
, "TrustAll") == 0) {
294 level
|= ALPM_SIG_PACKAGE_MARGINAL_OK
;
295 level
|= ALPM_SIG_PACKAGE_UNKNOWN_OK
;
298 level
|= ALPM_SIG_DATABASE_MARGINAL_OK
;
299 level
|= ALPM_SIG_DATABASE_UNKNOWN_OK
;
302 pm_printf(ALPM_LOG_ERROR
, _("invalid value for 'SigLevel' : '%s'\n"),
306 level
&= ~ALPM_SIG_USE_DEFAULT
;
315 static int process_cleanmethods(alpm_list_t
*values
) {
317 for(i
= values
; i
; i
= alpm_list_next(i
)) {
318 const char *value
= i
->data
;
319 if(strcmp(value
, "KeepInstalled") == 0) {
320 config
->cleanmethod
|= PM_CLEAN_KEEPINST
;
321 } else if(strcmp(value
, "KeepCurrent") == 0) {
322 config
->cleanmethod
|= PM_CLEAN_KEEPCUR
;
324 pm_printf(ALPM_LOG_ERROR
, _("invalid value for 'CleanMethod' : '%s'\n"),
332 /** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm
333 * settings. Refactored out of the parseconfig code since all of them did
334 * the exact same thing and duplicated code.
335 * @param ptr a pointer to the start of the multiple options
336 * @param option the string (friendly) name of the option, used for messages
337 * @param list the list to add the option to
339 static void setrepeatingoption(char *ptr
, const char *option
,
344 while((q
= strchr(ptr
, ' '))) {
346 *list
= alpm_list_add(*list
, strdup(ptr
));
347 pm_printf(ALPM_LOG_DEBUG
, "config: %s: %s\n", option
, ptr
);
351 *list
= alpm_list_add(*list
, strdup(ptr
));
352 pm_printf(ALPM_LOG_DEBUG
, "config: %s: %s\n", option
, ptr
);
355 static int _parse_options(const char *key
, char *value
,
356 const char *file
, int linenum
)
359 /* options without settings */
360 if(strcmp(key
, "UseSyslog") == 0) {
361 config
->usesyslog
= 1;
362 pm_printf(ALPM_LOG_DEBUG
, "config: usesyslog\n");
363 } else if(strcmp(key
, "ILoveCandy") == 0) {
365 pm_printf(ALPM_LOG_DEBUG
, "config: chomp\n");
366 } else if(strcmp(key
, "VerbosePkgLists") == 0) {
367 config
->verbosepkglists
= 1;
368 pm_printf(ALPM_LOG_DEBUG
, "config: verbosepkglists\n");
369 } else if(strcmp(key
, "UseDelta") == 0) {
370 config
->usedelta
= 1;
371 pm_printf(ALPM_LOG_DEBUG
, "config: usedelta\n");
372 } else if(strcmp(key
, "TotalDownload") == 0) {
373 config
->totaldownload
= 1;
374 pm_printf(ALPM_LOG_DEBUG
, "config: totaldownload\n");
375 } else if(strcmp(key
, "CheckSpace") == 0) {
376 config
->checkspace
= 1;
378 pm_printf(ALPM_LOG_WARNING
,
379 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
380 file
, linenum
, key
, "options");
383 /* options with settings */
384 if(strcmp(key
, "NoUpgrade") == 0) {
385 setrepeatingoption(value
, "NoUpgrade", &(config
->noupgrade
));
386 } else if(strcmp(key
, "NoExtract") == 0) {
387 setrepeatingoption(value
, "NoExtract", &(config
->noextract
));
388 } else if(strcmp(key
, "IgnorePkg") == 0) {
389 setrepeatingoption(value
, "IgnorePkg", &(config
->ignorepkg
));
390 } else if(strcmp(key
, "IgnoreGroup") == 0) {
391 setrepeatingoption(value
, "IgnoreGroup", &(config
->ignoregrp
));
392 } else if(strcmp(key
, "HoldPkg") == 0) {
393 setrepeatingoption(value
, "HoldPkg", &(config
->holdpkg
));
394 } else if(strcmp(key
, "SyncFirst") == 0) {
395 setrepeatingoption(value
, "SyncFirst", &(config
->syncfirst
));
396 } else if(strcmp(key
, "CacheDir") == 0) {
397 setrepeatingoption(value
, "CacheDir", &(config
->cachedirs
));
398 } else if(strcmp(key
, "Architecture") == 0) {
400 config_set_arch(value
);
402 } else if(strcmp(key
, "DBPath") == 0) {
403 /* don't overwrite a path specified on the command line */
404 if(!config
->dbpath
) {
405 config
->dbpath
= strdup(value
);
406 pm_printf(ALPM_LOG_DEBUG
, "config: dbpath: %s\n", value
);
408 } else if(strcmp(key
, "RootDir") == 0) {
409 /* don't overwrite a path specified on the command line */
410 if(!config
->rootdir
) {
411 config
->rootdir
= strdup(value
);
412 pm_printf(ALPM_LOG_DEBUG
, "config: rootdir: %s\n", value
);
414 } else if(strcmp(key
, "GPGDir") == 0) {
415 if(!config
->gpgdir
) {
416 config
->gpgdir
= strdup(value
);
417 pm_printf(ALPM_LOG_DEBUG
, "config: gpgdir: %s\n", value
);
419 } else if(strcmp(key
, "LogFile") == 0) {
420 if(!config
->logfile
) {
421 config
->logfile
= strdup(value
);
422 pm_printf(ALPM_LOG_DEBUG
, "config: logfile: %s\n", value
);
424 } else if(strcmp(key
, "XferCommand") == 0) {
425 config
->xfercommand
= strdup(value
);
426 pm_printf(ALPM_LOG_DEBUG
, "config: xfercommand: %s\n", value
);
427 } else if(strcmp(key
, "CleanMethod") == 0) {
428 alpm_list_t
*methods
= NULL
;
429 setrepeatingoption(value
, "CleanMethod", &methods
);
430 if(process_cleanmethods(methods
)) {
435 } else if(strcmp(key
, "SigLevel") == 0) {
436 alpm_list_t
*values
= NULL
;
437 setrepeatingoption(value
, "SigLevel", &values
);
438 if(process_siglevel(values
, &(config
->siglevel
))) {
444 pm_printf(ALPM_LOG_WARNING
,
445 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
446 file
, linenum
, key
, "options");
453 static int _add_mirror(alpm_db_t
*db
, char *value
)
455 const char *dbname
= alpm_db_get_name(db
);
456 /* let's attempt a replacement for the current repo */
457 char *temp
= strreplace(value
, "$repo", dbname
);
458 /* let's attempt a replacement for the arch */
459 const char *arch
= config
->arch
;
462 server
= strreplace(temp
, "$arch", arch
);
465 if(strstr(temp
, "$arch")) {
467 pm_printf(ALPM_LOG_ERROR
, _("The mirror '%s' contains the $arch"
468 " variable, but no Architecture is defined.\n"), value
);
474 if(alpm_db_add_server(db
, server
) != 0) {
475 /* pm_errno is set by alpm_db_setserver */
476 pm_printf(ALPM_LOG_ERROR
, _("could not add server URL to database '%s': %s (%s)\n"),
477 dbname
, server
, alpm_strerror(alpm_errno(config
->handle
)));
486 /** Sets up libalpm global stuff in one go. Called after the command line
487 * and inital config file parsing. Once this is complete, we can see if any
488 * paths were defined. If a rootdir was defined and nothing else, we want all
489 * of our paths to live under the rootdir that was specified. Safe to call
490 * multiple times (will only do anything the first time).
492 static int setup_libalpm(void)
495 enum _alpm_errno_t err
;
496 alpm_handle_t
*handle
;
498 pm_printf(ALPM_LOG_DEBUG
, "setup_libalpm called\n");
500 /* Configure root path first. If it is set and dbpath/logfile were not
501 * set, then set those as well to reside under the root. */
502 if(config
->rootdir
) {
504 if(!config
->dbpath
) {
505 snprintf(path
, PATH_MAX
, "%s/%s", config
->rootdir
, DBPATH
+ 1);
506 config
->dbpath
= strdup(path
);
508 if(!config
->logfile
) {
509 snprintf(path
, PATH_MAX
, "%s/%s", config
->rootdir
, LOGFILE
+ 1);
510 config
->logfile
= strdup(path
);
513 config
->rootdir
= strdup(ROOTDIR
);
514 if(!config
->dbpath
) {
515 config
->dbpath
= strdup(DBPATH
);
519 /* initialize library */
520 handle
= alpm_initialize(config
->rootdir
, config
->dbpath
, &err
);
522 pm_printf(ALPM_LOG_ERROR
, _("failed to initialize alpm library (%s)\n"),
524 if(err
== ALPM_ERR_DB_VERSION
) {
525 pm_printf(ALPM_LOG_ERROR
, _(" try running pacman-db-upgrade\n"));
529 config
->handle
= handle
;
531 alpm_option_set_logcb(handle
, cb_log
);
532 alpm_option_set_dlcb(handle
, cb_dl_progress
);
534 config
->logfile
= config
->logfile
? config
->logfile
: strdup(LOGFILE
);
535 ret
= alpm_option_set_logfile(handle
, config
->logfile
);
537 pm_printf(ALPM_LOG_ERROR
, _("problem setting logfile '%s' (%s)\n"),
538 config
->logfile
, alpm_strerror(alpm_errno(handle
)));
542 /* Set GnuPG's home directory. This is not relative to rootdir, even if
543 * rootdir is defined. Reasoning: gpgdir contains configuration data. */
544 config
->gpgdir
= config
->gpgdir
? config
->gpgdir
: strdup(GPGDIR
);
545 ret
= alpm_option_set_gpgdir(handle
, config
->gpgdir
);
547 pm_printf(ALPM_LOG_ERROR
, _("problem setting gpgdir '%s' (%s)\n"),
548 config
->gpgdir
, alpm_strerror(alpm_errno(handle
)));
552 /* add a default cachedir if one wasn't specified */
553 if(config
->cachedirs
== NULL
) {
554 alpm_option_add_cachedir(handle
, CACHEDIR
);
556 alpm_option_set_cachedirs(handle
, config
->cachedirs
);
559 if(config
->siglevel
!= ALPM_SIG_USE_DEFAULT
) {
560 alpm_option_set_default_siglevel(handle
, config
->siglevel
);
563 if(config
->xfercommand
) {
564 alpm_option_set_fetchcb(handle
, download_with_xfercommand
);
567 if(config
->totaldownload
) {
568 alpm_option_set_totaldlcb(handle
, cb_dl_total
);
571 alpm_option_set_arch(handle
, config
->arch
);
572 alpm_option_set_checkspace(handle
, config
->checkspace
);
573 alpm_option_set_usesyslog(handle
, config
->usesyslog
);
574 alpm_option_set_usedelta(handle
, config
->usedelta
);
576 alpm_option_set_ignorepkgs(handle
, config
->ignorepkg
);
577 alpm_option_set_ignoregroups(handle
, config
->ignoregrp
);
578 alpm_option_set_noupgrades(handle
, config
->noupgrade
);
579 alpm_option_set_noextracts(handle
, config
->noextract
);
585 * Allows parsing in advance of an entire config section before we start
586 * calling library methods.
589 /* useful for all sections */
592 /* db section option gathering */
593 alpm_siglevel_t siglevel
;
594 alpm_list_t
*servers
;
598 * Wrap up a section once we have reached the end of it. This should be called
599 * when a subsequent section is encountered, or when we have reached the end of
600 * the root config file. Once called, all existing saved config pieces on the
601 * section struct are freed.
602 * @param section the current parsed and saved section data
603 * @param parse_options whether we are parsing options or repo data
604 * @return 0 on success, 1 on failure
606 static int finish_section(struct section_t
*section
, int parse_options
)
612 pm_printf(ALPM_LOG_DEBUG
, "config: finish section '%s'\n", section
->name
);
614 /* parsing options (or nothing)- nothing to do except free the pieces */
615 if(!section
->name
|| parse_options
|| section
->is_options
) {
619 /* if we are not looking at options sections only, register a db */
620 db
= alpm_db_register_sync(config
->handle
, section
->name
, section
->siglevel
);
622 pm_printf(ALPM_LOG_ERROR
, _("could not register '%s' database (%s)\n"),
623 section
->name
, alpm_strerror(alpm_errno(config
->handle
)));
628 for(i
= section
->servers
; i
; i
= alpm_list_next(i
)) {
629 char *value
= alpm_list_getdata(i
);
630 if(_add_mirror(db
, value
) != 0) {
631 pm_printf(ALPM_LOG_ERROR
,
632 _("could not add mirror '%s' to database '%s' (%s)\n"),
633 value
, section
->name
, alpm_strerror(alpm_errno(config
->handle
)));
641 alpm_list_free(section
->servers
);
642 section
->servers
= NULL
;
643 section
->siglevel
= ALPM_SIG_USE_DEFAULT
;
645 section
->name
= NULL
;
649 /** The "real" parseconfig. Each "Include" directive will recall this method so
650 * recursion and stack depth are limited to 10 levels. The publicly visible
651 * parseconfig calls this with a NULL section argument so we can recall from
652 * within ourself on an include.
653 * @param file path to the config file
654 * @param section the current active section
655 * @param parse_options whether to parse and call methods for the options
656 * section; if 0, parse and call methods for the repos sections
657 * @param depth the current recursion depth
658 * @return 0 on success, 1 on failure
660 static int _parseconfig(const char *file
, struct section_t
*section
,
661 int parse_options
, int depth
)
667 const int max_depth
= 10;
669 if(depth
>= max_depth
) {
670 pm_printf(ALPM_LOG_ERROR
,
671 _("config parsing exceeded max recursion depth of %d.\n"), max_depth
);
676 pm_printf(ALPM_LOG_DEBUG
, "config: attempting to read file %s\n", file
);
677 fp
= fopen(file
, "r");
679 pm_printf(ALPM_LOG_ERROR
, _("config file %s could not be read.\n"), file
);
684 while(fgets(line
, PATH_MAX
, fp
)) {
685 char *key
, *value
, *ptr
;
690 line_len
= strlen(line
);
692 /* ignore whole line and end of line comments */
693 if(line_len
== 0 || line
[0] == '#') {
696 if((ptr
= strchr(line
, '#'))) {
700 if(line
[0] == '[' && line
[line_len
- 1] == ']') {
702 /* only possibility here is a line == '[]' */
704 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: bad section name.\n"),
709 /* new config section, skip the '[' */
710 name
= strdup(line
+ 1);
711 name
[line_len
- 2] = '\0';
712 /* we're at a new section; perform any post-actions for the prior */
713 if(finish_section(section
, parse_options
)) {
717 pm_printf(ALPM_LOG_DEBUG
, "config: new section '%s'\n", name
);
718 section
->name
= name
;
719 section
->is_options
= (strcmp(name
, "options") == 0);
724 /* strsep modifies the 'line' string: 'key \0 value' */
732 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: syntax error in config file- missing key.\n"),
737 /* For each directive, compare to the camelcase string. */
738 if(section
->name
== NULL
) {
739 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: All directives must belong to a section.\n"),
744 /* Include is allowed in both options and repo sections */
745 if(strcmp(key
, "Include") == 0) {
751 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: directive '%s' needs a value\n"),
756 /* Ignore include failures... assume non-critical */
757 globret
= glob(value
, GLOB_NOCHECK
, NULL
, &globbuf
);
760 pm_printf(ALPM_LOG_DEBUG
,
761 "config file %s, line %d: include globbing out of space\n",
765 pm_printf(ALPM_LOG_DEBUG
,
766 "config file %s, line %d: include globbing read error for %s\n",
767 file
, linenum
, value
);
770 pm_printf(ALPM_LOG_DEBUG
,
771 "config file %s, line %d: no include found for %s\n",
772 file
, linenum
, value
);
775 for(gindex
= 0; gindex
< globbuf
.gl_pathc
; gindex
++) {
776 pm_printf(ALPM_LOG_DEBUG
, "config file %s, line %d: including %s\n",
777 file
, linenum
, globbuf
.gl_pathv
[gindex
]);
778 _parseconfig(globbuf
.gl_pathv
[gindex
], section
, parse_options
, depth
+ 1);
785 if(parse_options
&& section
->is_options
) {
786 /* we are either in options ... */
787 if((ret
= _parse_options(key
, value
, file
, linenum
)) != 0) {
790 } else if (!parse_options
&& !section
->is_options
) {
791 /* ... or in a repo section */
792 if(strcmp(key
, "Server") == 0) {
794 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: directive '%s' needs a value\n"),
799 section
->servers
= alpm_list_add(section
->servers
, strdup(value
));
800 } else if(strcmp(key
, "SigLevel") == 0) {
801 alpm_list_t
*values
= NULL
;
802 setrepeatingoption(value
, "SigLevel", &values
);
804 if(section
->siglevel
== ALPM_SIG_USE_DEFAULT
) {
805 section
->siglevel
= config
->siglevel
;
807 if(process_siglevel(values
, &(section
->siglevel
))) {
815 pm_printf(ALPM_LOG_WARNING
,
816 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
817 file
, linenum
, key
, section
->name
);
823 ret
= finish_section(section
, parse_options
);
830 pm_printf(ALPM_LOG_DEBUG
, "config: finished parsing %s\n", file
);
834 /** Parse a configuration file.
835 * @param file path to the config file
836 * @return 0 on success, non-zero on error
838 int parseconfig(const char *file
)
841 struct section_t section
;
842 memset(§ion
, 0, sizeof(struct section_t
));
843 section
.siglevel
= ALPM_SIG_USE_DEFAULT
;
844 /* the config parse is a two-pass affair. We first parse the entire thing for
845 * the [options] section so we can get all default and path options set.
846 * Next, we go back and parse everything but [options]. */
848 /* call the real parseconfig function with a null section & db argument */
849 pm_printf(ALPM_LOG_DEBUG
, "parseconfig: options pass\n");
850 if((ret
= _parseconfig(file
, §ion
, 1, 0))) {
853 if((ret
= setup_libalpm())) {
856 /* second pass, repo section parsing */
857 pm_printf(ALPM_LOG_DEBUG
, "parseconfig: repo pass\n");
858 return _parseconfig(file
, §ion
, 0, 0);
861 /* vim: set ts=2 sw=2 noet: */