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 */
189 if(rename(tempfile
, destfile
)) {
190 pm_printf(ALPM_LOG_ERROR
, _("could not rename %s to %s (%s)\n"),
191 tempfile
, destfile
, strerror(errno
));
198 /* restore the old cwd if we have it */
199 if(restore_cwd
&& chdir(cwd
) != 0) {
200 pm_printf(ALPM_LOG_ERROR
, _("could not change directory to %s (%s)\n"),
201 cwd
, strerror(errno
));
205 /* hack to let an user the time to cancel a download */
216 int config_set_arch(const char *arch
)
218 if(strcmp(arch
, "auto") == 0) {
221 config
->arch
= strdup(un
.machine
);
223 config
->arch
= strdup(arch
);
225 pm_printf(ALPM_LOG_DEBUG
, "config: arch: %s\n", config
->arch
);
230 * Parse a signature verification level line.
231 * @param values the list of parsed option values
232 * @param storage location to store the derived signature level; any existing
233 * value here is used as a starting point
234 * @return 0 on success, 1 on any parsing error
236 static int process_siglevel(alpm_list_t
*values
, alpm_siglevel_t
*storage
)
238 alpm_siglevel_t level
= *storage
;
242 /* Collapse the option names into a single bitmasked value */
243 for(i
= values
; i
; i
= alpm_list_next(i
)) {
244 const char *original
= i
->data
, *value
;
245 int package
= 0, database
= 0;
247 if (strncmp(original
, "Package", strlen("Package")) == 0) {
248 /* only packages are affected, don't flip flags for databases */
249 value
= original
+ strlen("Package");
251 } else if (strncmp(original
, "Database", strlen("Database")) == 0) {
252 /* only databases are affected, don't flip flags for packages */
253 value
= original
+ strlen("Database");
256 /* no prefix, so anything found will affect both packages and dbs */
258 package
= database
= 1;
261 /* now parse out and store actual flag if it is valid */
262 if(strcmp(value
, "Never") == 0) {
264 level
&= ~ALPM_SIG_PACKAGE
;
267 level
&= ~ALPM_SIG_DATABASE
;
269 } else if(strcmp(value
, "Optional") == 0) {
271 level
|= ALPM_SIG_PACKAGE
;
272 level
|= ALPM_SIG_PACKAGE_OPTIONAL
;
275 level
|= ALPM_SIG_DATABASE
;
276 level
|= ALPM_SIG_DATABASE_OPTIONAL
;
278 } else if(strcmp(value
, "Required") == 0) {
280 level
|= ALPM_SIG_PACKAGE
;
281 level
&= ~ALPM_SIG_PACKAGE_OPTIONAL
;
284 level
|= ALPM_SIG_DATABASE
;
285 level
&= ~ALPM_SIG_DATABASE_OPTIONAL
;
287 } else if(strcmp(value
, "TrustedOnly") == 0) {
289 level
&= ~ALPM_SIG_PACKAGE_MARGINAL_OK
;
290 level
&= ~ALPM_SIG_PACKAGE_UNKNOWN_OK
;
293 level
&= ~ALPM_SIG_DATABASE_MARGINAL_OK
;
294 level
&= ~ALPM_SIG_DATABASE_UNKNOWN_OK
;
296 } else if(strcmp(value
, "TrustAll") == 0) {
298 level
|= ALPM_SIG_PACKAGE_MARGINAL_OK
;
299 level
|= ALPM_SIG_PACKAGE_UNKNOWN_OK
;
302 level
|= ALPM_SIG_DATABASE_MARGINAL_OK
;
303 level
|= ALPM_SIG_DATABASE_UNKNOWN_OK
;
306 pm_printf(ALPM_LOG_ERROR
, _("invalid value for 'SigLevel' : '%s'\n"),
310 level
&= ~ALPM_SIG_USE_DEFAULT
;
319 static int process_cleanmethods(alpm_list_t
*values
) {
321 for(i
= values
; i
; i
= alpm_list_next(i
)) {
322 const char *value
= i
->data
;
323 if(strcmp(value
, "KeepInstalled") == 0) {
324 config
->cleanmethod
|= PM_CLEAN_KEEPINST
;
325 } else if(strcmp(value
, "KeepCurrent") == 0) {
326 config
->cleanmethod
|= PM_CLEAN_KEEPCUR
;
328 pm_printf(ALPM_LOG_ERROR
, _("invalid value for 'CleanMethod' : '%s'\n"),
336 /** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm
337 * settings. Refactored out of the parseconfig code since all of them did
338 * the exact same thing and duplicated code.
339 * @param ptr a pointer to the start of the multiple options
340 * @param option the string (friendly) name of the option, used for messages
341 * @param list the list to add the option to
343 static void setrepeatingoption(char *ptr
, const char *option
,
348 while((q
= strchr(ptr
, ' '))) {
350 *list
= alpm_list_add(*list
, strdup(ptr
));
351 pm_printf(ALPM_LOG_DEBUG
, "config: %s: %s\n", option
, ptr
);
355 *list
= alpm_list_add(*list
, strdup(ptr
));
356 pm_printf(ALPM_LOG_DEBUG
, "config: %s: %s\n", option
, ptr
);
359 static int _parse_options(const char *key
, char *value
,
360 const char *file
, int linenum
)
363 /* options without settings */
364 if(strcmp(key
, "UseSyslog") == 0) {
365 config
->usesyslog
= 1;
366 pm_printf(ALPM_LOG_DEBUG
, "config: usesyslog\n");
367 } else if(strcmp(key
, "ILoveCandy") == 0) {
369 pm_printf(ALPM_LOG_DEBUG
, "config: chomp\n");
370 } else if(strcmp(key
, "VerbosePkgLists") == 0) {
371 config
->verbosepkglists
= 1;
372 pm_printf(ALPM_LOG_DEBUG
, "config: verbosepkglists\n");
373 } else if(strcmp(key
, "UseDelta") == 0) {
374 config
->usedelta
= 1;
375 pm_printf(ALPM_LOG_DEBUG
, "config: usedelta\n");
376 } else if(strcmp(key
, "TotalDownload") == 0) {
377 config
->totaldownload
= 1;
378 pm_printf(ALPM_LOG_DEBUG
, "config: totaldownload\n");
379 } else if(strcmp(key
, "CheckSpace") == 0) {
380 config
->checkspace
= 1;
382 pm_printf(ALPM_LOG_WARNING
,
383 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
384 file
, linenum
, key
, "options");
387 /* options with settings */
388 if(strcmp(key
, "NoUpgrade") == 0) {
389 setrepeatingoption(value
, "NoUpgrade", &(config
->noupgrade
));
390 } else if(strcmp(key
, "NoExtract") == 0) {
391 setrepeatingoption(value
, "NoExtract", &(config
->noextract
));
392 } else if(strcmp(key
, "IgnorePkg") == 0) {
393 setrepeatingoption(value
, "IgnorePkg", &(config
->ignorepkg
));
394 } else if(strcmp(key
, "IgnoreGroup") == 0) {
395 setrepeatingoption(value
, "IgnoreGroup", &(config
->ignoregrp
));
396 } else if(strcmp(key
, "HoldPkg") == 0) {
397 setrepeatingoption(value
, "HoldPkg", &(config
->holdpkg
));
398 } else if(strcmp(key
, "SyncFirst") == 0) {
399 setrepeatingoption(value
, "SyncFirst", &(config
->syncfirst
));
400 } else if(strcmp(key
, "CacheDir") == 0) {
401 setrepeatingoption(value
, "CacheDir", &(config
->cachedirs
));
402 } else if(strcmp(key
, "Architecture") == 0) {
404 config_set_arch(value
);
406 } else if(strcmp(key
, "DBPath") == 0) {
407 /* don't overwrite a path specified on the command line */
408 if(!config
->dbpath
) {
409 config
->dbpath
= strdup(value
);
410 pm_printf(ALPM_LOG_DEBUG
, "config: dbpath: %s\n", value
);
412 } else if(strcmp(key
, "RootDir") == 0) {
413 /* don't overwrite a path specified on the command line */
414 if(!config
->rootdir
) {
415 config
->rootdir
= strdup(value
);
416 pm_printf(ALPM_LOG_DEBUG
, "config: rootdir: %s\n", value
);
418 } else if(strcmp(key
, "GPGDir") == 0) {
419 if(!config
->gpgdir
) {
420 config
->gpgdir
= strdup(value
);
421 pm_printf(ALPM_LOG_DEBUG
, "config: gpgdir: %s\n", value
);
423 } else if(strcmp(key
, "LogFile") == 0) {
424 if(!config
->logfile
) {
425 config
->logfile
= strdup(value
);
426 pm_printf(ALPM_LOG_DEBUG
, "config: logfile: %s\n", value
);
428 } else if(strcmp(key
, "XferCommand") == 0) {
429 config
->xfercommand
= strdup(value
);
430 pm_printf(ALPM_LOG_DEBUG
, "config: xfercommand: %s\n", value
);
431 } else if(strcmp(key
, "CleanMethod") == 0) {
432 alpm_list_t
*methods
= NULL
;
433 setrepeatingoption(value
, "CleanMethod", &methods
);
434 if(process_cleanmethods(methods
)) {
439 } else if(strcmp(key
, "SigLevel") == 0) {
440 alpm_list_t
*values
= NULL
;
441 setrepeatingoption(value
, "SigLevel", &values
);
442 if(process_siglevel(values
, &(config
->siglevel
))) {
448 pm_printf(ALPM_LOG_WARNING
,
449 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
450 file
, linenum
, key
, "options");
457 static int _add_mirror(alpm_db_t
*db
, char *value
)
459 const char *dbname
= alpm_db_get_name(db
);
460 /* let's attempt a replacement for the current repo */
461 char *temp
= strreplace(value
, "$repo", dbname
);
462 /* let's attempt a replacement for the arch */
463 const char *arch
= config
->arch
;
466 server
= strreplace(temp
, "$arch", arch
);
469 if(strstr(temp
, "$arch")) {
471 pm_printf(ALPM_LOG_ERROR
, _("The mirror '%s' contains the $arch"
472 " variable, but no Architecture is defined.\n"), value
);
478 if(alpm_db_add_server(db
, server
) != 0) {
479 /* pm_errno is set by alpm_db_setserver */
480 pm_printf(ALPM_LOG_ERROR
, _("could not add server URL to database '%s': %s (%s)\n"),
481 dbname
, server
, alpm_strerror(alpm_errno(config
->handle
)));
490 /** Sets up libalpm global stuff in one go. Called after the command line
491 * and inital config file parsing. Once this is complete, we can see if any
492 * paths were defined. If a rootdir was defined and nothing else, we want all
493 * of our paths to live under the rootdir that was specified. Safe to call
494 * multiple times (will only do anything the first time).
496 static int setup_libalpm(void)
499 enum _alpm_errno_t err
;
500 alpm_handle_t
*handle
;
502 pm_printf(ALPM_LOG_DEBUG
, "setup_libalpm called\n");
504 /* Configure root path first. If it is set and dbpath/logfile were not
505 * set, then set those as well to reside under the root. */
506 if(config
->rootdir
) {
508 if(!config
->dbpath
) {
509 snprintf(path
, PATH_MAX
, "%s/%s", config
->rootdir
, DBPATH
+ 1);
510 config
->dbpath
= strdup(path
);
512 if(!config
->logfile
) {
513 snprintf(path
, PATH_MAX
, "%s/%s", config
->rootdir
, LOGFILE
+ 1);
514 config
->logfile
= strdup(path
);
517 config
->rootdir
= strdup(ROOTDIR
);
518 if(!config
->dbpath
) {
519 config
->dbpath
= strdup(DBPATH
);
523 /* initialize library */
524 handle
= alpm_initialize(config
->rootdir
, config
->dbpath
, &err
);
526 pm_printf(ALPM_LOG_ERROR
, _("failed to initialize alpm library (%s)\n"),
528 if(err
== ALPM_ERR_DB_VERSION
) {
529 pm_printf(ALPM_LOG_ERROR
, _(" try running pacman-db-upgrade\n"));
533 config
->handle
= handle
;
535 alpm_option_set_logcb(handle
, cb_log
);
536 alpm_option_set_dlcb(handle
, cb_dl_progress
);
537 alpm_option_set_eventcb(handle
, cb_event
);
538 alpm_option_set_questioncb(handle
, cb_question
);
539 alpm_option_set_progresscb(handle
, cb_progress
);
541 config
->logfile
= config
->logfile
? config
->logfile
: strdup(LOGFILE
);
542 ret
= alpm_option_set_logfile(handle
, config
->logfile
);
544 pm_printf(ALPM_LOG_ERROR
, _("problem setting logfile '%s' (%s)\n"),
545 config
->logfile
, alpm_strerror(alpm_errno(handle
)));
549 /* Set GnuPG's home directory. This is not relative to rootdir, even if
550 * rootdir is defined. Reasoning: gpgdir contains configuration data. */
551 config
->gpgdir
= config
->gpgdir
? config
->gpgdir
: strdup(GPGDIR
);
552 ret
= alpm_option_set_gpgdir(handle
, config
->gpgdir
);
554 pm_printf(ALPM_LOG_ERROR
, _("problem setting gpgdir '%s' (%s)\n"),
555 config
->gpgdir
, alpm_strerror(alpm_errno(handle
)));
559 /* add a default cachedir if one wasn't specified */
560 if(config
->cachedirs
== NULL
) {
561 alpm_option_add_cachedir(handle
, CACHEDIR
);
563 alpm_option_set_cachedirs(handle
, config
->cachedirs
);
566 if(config
->siglevel
!= ALPM_SIG_USE_DEFAULT
) {
567 alpm_option_set_default_siglevel(handle
, config
->siglevel
);
569 /* retrieve the set or default siglevel from the backend at this point;
570 * this way all future DB settings base their setting off this value */
571 config
->siglevel
= alpm_option_get_default_siglevel(handle
);
573 if(config
->xfercommand
) {
574 alpm_option_set_fetchcb(handle
, download_with_xfercommand
);
577 if(config
->totaldownload
) {
578 alpm_option_set_totaldlcb(handle
, cb_dl_total
);
581 alpm_option_set_arch(handle
, config
->arch
);
582 alpm_option_set_checkspace(handle
, config
->checkspace
);
583 alpm_option_set_usesyslog(handle
, config
->usesyslog
);
584 alpm_option_set_usedelta(handle
, config
->usedelta
);
586 alpm_option_set_ignorepkgs(handle
, config
->ignorepkg
);
587 alpm_option_set_ignoregroups(handle
, config
->ignoregrp
);
588 alpm_option_set_noupgrades(handle
, config
->noupgrade
);
589 alpm_option_set_noextracts(handle
, config
->noextract
);
595 * Allows parsing in advance of an entire config section before we start
596 * calling library methods.
599 /* useful for all sections */
602 /* db section option gathering */
603 alpm_siglevel_t siglevel
;
604 alpm_list_t
*servers
;
608 * Wrap up a section once we have reached the end of it. This should be called
609 * when a subsequent section is encountered, or when we have reached the end of
610 * the root config file. Once called, all existing saved config pieces on the
611 * section struct are freed.
612 * @param section the current parsed and saved section data
613 * @param parse_options whether we are parsing options or repo data
614 * @return 0 on success, 1 on failure
616 static int finish_section(struct section_t
*section
, int parse_options
)
622 pm_printf(ALPM_LOG_DEBUG
, "config: finish section '%s'\n", section
->name
);
624 /* parsing options (or nothing)- nothing to do except free the pieces */
625 if(!section
->name
|| parse_options
|| section
->is_options
) {
629 /* if we are not looking at options sections only, register a db */
630 db
= alpm_db_register_sync(config
->handle
, section
->name
, section
->siglevel
);
632 pm_printf(ALPM_LOG_ERROR
, _("could not register '%s' database (%s)\n"),
633 section
->name
, alpm_strerror(alpm_errno(config
->handle
)));
638 for(i
= section
->servers
; i
; i
= alpm_list_next(i
)) {
639 char *value
= alpm_list_getdata(i
);
640 if(_add_mirror(db
, value
) != 0) {
641 pm_printf(ALPM_LOG_ERROR
,
642 _("could not add mirror '%s' to database '%s' (%s)\n"),
643 value
, section
->name
, alpm_strerror(alpm_errno(config
->handle
)));
651 alpm_list_free(section
->servers
);
652 section
->servers
= NULL
;
653 section
->siglevel
= ALPM_SIG_USE_DEFAULT
;
655 section
->name
= NULL
;
659 /** The "real" parseconfig. Each "Include" directive will recall this method so
660 * recursion and stack depth are limited to 10 levels. The publicly visible
661 * parseconfig calls this with a NULL section argument so we can recall from
662 * within ourself on an include.
663 * @param file path to the config file
664 * @param section the current active section
665 * @param parse_options whether to parse and call methods for the options
666 * section; if 0, parse and call methods for the repos sections
667 * @param depth the current recursion depth
668 * @return 0 on success, 1 on failure
670 static int _parseconfig(const char *file
, struct section_t
*section
,
671 int parse_options
, int depth
)
677 const int max_depth
= 10;
679 if(depth
>= max_depth
) {
680 pm_printf(ALPM_LOG_ERROR
,
681 _("config parsing exceeded max recursion depth of %d.\n"), max_depth
);
686 pm_printf(ALPM_LOG_DEBUG
, "config: attempting to read file %s\n", file
);
687 fp
= fopen(file
, "r");
689 pm_printf(ALPM_LOG_ERROR
, _("config file %s could not be read.\n"), file
);
694 while(fgets(line
, PATH_MAX
, fp
)) {
695 char *key
, *value
, *ptr
;
700 line_len
= strlen(line
);
702 /* ignore whole line and end of line comments */
703 if(line_len
== 0 || line
[0] == '#') {
706 if((ptr
= strchr(line
, '#'))) {
710 if(line
[0] == '[' && line
[line_len
- 1] == ']') {
712 /* only possibility here is a line == '[]' */
714 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: bad section name.\n"),
719 /* new config section, skip the '[' */
720 name
= strdup(line
+ 1);
721 name
[line_len
- 2] = '\0';
722 /* we're at a new section; perform any post-actions for the prior */
723 if(finish_section(section
, parse_options
)) {
727 pm_printf(ALPM_LOG_DEBUG
, "config: new section '%s'\n", name
);
728 section
->name
= name
;
729 section
->is_options
= (strcmp(name
, "options") == 0);
734 /* strsep modifies the 'line' string: 'key \0 value' */
742 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: syntax error in config file- missing key.\n"),
747 /* For each directive, compare to the camelcase string. */
748 if(section
->name
== NULL
) {
749 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: All directives must belong to a section.\n"),
754 /* Include is allowed in both options and repo sections */
755 if(strcmp(key
, "Include") == 0) {
761 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: directive '%s' needs a value\n"),
766 /* Ignore include failures... assume non-critical */
767 globret
= glob(value
, GLOB_NOCHECK
, NULL
, &globbuf
);
770 pm_printf(ALPM_LOG_DEBUG
,
771 "config file %s, line %d: include globbing out of space\n",
775 pm_printf(ALPM_LOG_DEBUG
,
776 "config file %s, line %d: include globbing read error for %s\n",
777 file
, linenum
, value
);
780 pm_printf(ALPM_LOG_DEBUG
,
781 "config file %s, line %d: no include found for %s\n",
782 file
, linenum
, value
);
785 for(gindex
= 0; gindex
< globbuf
.gl_pathc
; gindex
++) {
786 pm_printf(ALPM_LOG_DEBUG
, "config file %s, line %d: including %s\n",
787 file
, linenum
, globbuf
.gl_pathv
[gindex
]);
788 _parseconfig(globbuf
.gl_pathv
[gindex
], section
, parse_options
, depth
+ 1);
795 if(parse_options
&& section
->is_options
) {
796 /* we are either in options ... */
797 if((ret
= _parse_options(key
, value
, file
, linenum
)) != 0) {
800 } else if (!parse_options
&& !section
->is_options
) {
801 /* ... or in a repo section */
802 if(strcmp(key
, "Server") == 0) {
804 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: directive '%s' needs a value\n"),
809 section
->servers
= alpm_list_add(section
->servers
, strdup(value
));
810 } else if(strcmp(key
, "SigLevel") == 0) {
811 alpm_list_t
*values
= NULL
;
812 setrepeatingoption(value
, "SigLevel", &values
);
814 if(section
->siglevel
== ALPM_SIG_USE_DEFAULT
) {
815 section
->siglevel
= config
->siglevel
;
817 if(process_siglevel(values
, &(section
->siglevel
))) {
825 pm_printf(ALPM_LOG_WARNING
,
826 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
827 file
, linenum
, key
, section
->name
);
833 ret
= finish_section(section
, parse_options
);
840 pm_printf(ALPM_LOG_DEBUG
, "config: finished parsing %s\n", file
);
844 /** Parse a configuration file.
845 * @param file path to the config file
846 * @return 0 on success, non-zero on error
848 int parseconfig(const char *file
)
851 struct section_t section
;
852 memset(§ion
, 0, sizeof(struct section_t
));
853 section
.siglevel
= ALPM_SIG_USE_DEFAULT
;
854 /* the config parse is a two-pass affair. We first parse the entire thing for
855 * the [options] section so we can get all default and path options set.
856 * Next, we go back and parse everything but [options]. */
858 /* call the real parseconfig function with a null section & db argument */
859 pm_printf(ALPM_LOG_DEBUG
, "parseconfig: options pass\n");
860 if((ret
= _parseconfig(file
, §ion
, 1, 0))) {
863 if((ret
= setup_libalpm())) {
866 /* second pass, repo section parsing */
867 pm_printf(ALPM_LOG_DEBUG
, "parseconfig: repo pass\n");
868 return _parseconfig(file
, §ion
, 0, 0);
871 /* vim: set ts=2 sw=2 noet: */