"Fossies" - the Fresh Open Source Software Archive

Member "rpm2html-1.11.2/config.c" (9 Nov 2010, 22158 Bytes) of package /linux/privat/rpm2html-1.11.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "config.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * config.c : handle the configuration file.
    3  *
    4  * See Copyright for the status of this software.
    5  *
    6  * $Id: config.c,v 1.52 2010/11/09 22:16:29 hany Exp $
    7  */
    8 
    9 #include <config.h>
   10 #include <sys/types.h>
   11 #include <sys/stat.h>
   12 #ifdef HAVE_FCNTL_H
   13 #include <fcntl.h>
   14 #endif
   15 #include <stdio.h>
   16 #include <stdlib.h>
   17 #include <string.h>
   18 #include <errno.h>
   19 #ifdef HAVE_UNISTD_H
   20 #include <unistd.h>
   21 #endif
   22 
   23 #include "rpm2html.h"
   24 #include "rpmdata.h"
   25 #ifdef WITH_SQL
   26 #include "sql.h"
   27 #endif
   28 
   29 /*
   30  * configuration variables for rpm2html
   31  */
   32 
   33 char *rpm2html_rpm2html_name    = RPM2HTML_NAME;
   34 char *rpm2html_rpm2html_ver = RPM2HTML_VER;
   35 char *rpm2html_rpm2html_url = RPM2HTML_URL;
   36 char *rpm2html_rpm2html_thishost= NULL;
   37 char *rpm2html_maint        = RPM2HTML_MAINT;
   38 char *rpm2html_mail     = RPM2HTML_MAIL;
   39 char *rpm2html_help     = NULL;
   40 char *rpm2html_dir      = NULL;
   41 char *rpm2html_name     = NULL;
   42 char *rpm2html_url      = NULL;
   43 #ifdef WITH_SQL
   44 char *rpm2html_search       = "/linux/rpm2html/search.php";
   45 #endif
   46 char *rpm2html_ftp      = NULL;
   47 char *rpm2html_ftpsrc       = NULL;
   48 char *rpm2html_host     = NULL;
   49 int   rpm2html_build_tree   = 0;
   50 int   rpm2html_cve_linking      = 1;
   51 #ifdef HAVE_LIBTEMPLATE
   52 char *rpm2html_html_template    = "rpm2html.tpl";
   53 #endif
   54 int   rpm2html_dump_html    = 1;
   55 int   rpm2html_dump_html_only_if_rpm_newer = 0;
   56 int   rpm2html_dump_rdf     = 0;
   57 int   rpm2html_dump_rdf_resources= 0;
   58 char *rpm2html_rdf_dir      = NULL;
   59 char *rpm2html_rdf_resources_dir= NULL;
   60 int   rpm2html_rdf_count_limit  = DEFAULT_RDF_COUNT_LIMIT;
   61 
   62 int  rpm2html_files = 0;
   63 int  rpm2html_size = 0;
   64 
   65 int  rpm2html_no_sql = 0;
   66 int  rpm2html_install_files = 0;
   67 int  rpm2html_install_size = 0;
   68 int  rpm2html_protect_emails = 0;
   69 
   70 char *rpm2html_headers_name[MAX_EXTRA_HEADERS];
   71 char *rpm2html_headers_url[MAX_EXTRA_HEADERS];
   72 int   rpm2html_nb_extra_headers = 0; 
   73 
   74 int   nb_metadata_mirrors = 0;
   75 int   max_metadata_mirrors = 0;
   76 char **metadata_mirrors = NULL;
   77 
   78 void addHeader(char *value);
   79 
   80 #ifdef HAVE_STRNDUP
   81 extern char *strndup (const char *source, size_t len);
   82 #else /* ! HAVE_STRNDUP */
   83 /*
   84  * 
   85  */
   86 char *strndup (const char *source, size_t len) {
   87     char* tmp = NULL;
   88 
   89     if ((source == NULL) || (len < 0)) return(NULL);
   90     if (len <= strlen(source)) return xmlStrdup(source);
   91 
   92     tmp = xmlMalloc(len+1);
   93     strncpy(tmp, source, len);
   94     tmp[len] = '\0';
   95 
   96     return(tmp);
   97 }
   98 #endif /* HAVE_STRNDUP */
   99 
  100 /*
  101  * free a directory structure.
  102  */
  103 
  104 void rpmDirFree(rpmDirPtr dir) {
  105     int i;
  106 
  107     if (dir->color) xmlFree(dir->color);
  108     if (dir->dir != NULL) xmlFree(dir->dir);
  109     if (dir->ftp != NULL) xmlFree(dir->ftp);
  110     if (dir->ftpsrc != NULL) xmlFree(dir->ftpsrc);
  111     if (dir->host != NULL) xmlFree(dir->host);
  112     if (dir->mail != NULL) xmlFree(dir->mail);
  113     if (dir->maint != NULL) xmlFree(dir->maint);
  114     if (dir->name != NULL) xmlFree(dir->name);
  115     if (dir->url != NULL) xmlFree(dir->url);
  116     if (dir->subdir != NULL) xmlFree(dir->subdir);
  117     for (i = 0;i < dir->nb_mirrors ; i++)
  118         if (dir->mirrors[i] != NULL) xmlFree(dir->mirrors[i]);
  119     if (dir->mirrors != NULL) xmlFree(dir->mirrors);
  120     if (dir->trust != NULL) xmlFree(dir->trust);
  121     if (dir->rpmdir != NULL) xmlFree(dir->rpmdir);
  122     if (dir->dbpath != NULL) xmlFree(dir->dbpath);   /* Added by A. Gibert */
  123     dir->next = NULL;
  124     memset(dir, 0, sizeof(rpmDir));
  125     xmlFree(dir);
  126 }
  127 
  128 /*
  129  * free a directory list.
  130  */
  131 
  132 void rpmDirListFree(rpmDirPtr *base) {
  133     rpmDirPtr dir = *base, next;
  134 
  135     while (dir != NULL) {
  136         next = dir->next;
  137     rpmDirFree(dir);
  138     dir = next;
  139     }
  140     *base = NULL;
  141 }
  142 
  143 /*
  144  * free an RPM structure.
  145  */
  146 
  147 void rpmDataFree(rpmDataPtr rpm) {
  148     if (rpm->filename) xmlFree(rpm->filename);
  149     if (rpm->name != NULL) stringFree(rpm->name);
  150     if (rpm->version != NULL) stringFree(rpm->version);
  151     if (rpm->release != NULL) stringFree(rpm->release);
  152     if (rpm->url != NULL) xmlFree(rpm->url);
  153     if (rpm->arch != NULL) stringFree(rpm->arch);
  154     if (rpm->os != NULL) stringFree(rpm->os);
  155     if (rpm->distribution != NULL) stringFree(rpm->distribution);
  156     if (rpm->vendor != NULL) stringFree(rpm->vendor);
  157     if (rpm->group != NULL) stringFree(rpm->group);
  158     if (rpm->summary != NULL) xmlFree(rpm->summary);
  159     if (rpm->subdir != NULL) stringFree(rpm->subdir);
  160     rpmDataListFree(&(rpm->nextArch));
  161     memset(rpm, 0, sizeof(rpmData));
  162     xmlFree(rpm);
  163 }
  164 
  165 /*
  166  * free an RPM list.
  167  */
  168 
  169 void rpmDataListFree(rpmDataPtr *base) {
  170     rpmDataPtr rpm = *base, next;
  171 
  172     while (rpm != NULL) {
  173         next = rpm->nextSoft;
  174     rpmDataFree(rpm);
  175     rpm = next;
  176     }
  177     *base = NULL;
  178 }
  179 
  180 /*
  181  * free a resource structure.
  182  */
  183 
  184 void rpmRessFree(rpmRessPtr res) {
  185     if (res->name != NULL) xmlFree(res->name);
  186     if (res->version != NULL) xmlFree(res->version);
  187     if (res->provider != NULL) xmlFree(res->provider);
  188     memset(res, 0, sizeof(rpmRess));
  189     xmlFree(res);
  190 }
  191 
  192 /*
  193  * free a resource list.
  194  */
  195 
  196 void rpmRessListFree(rpmRessPtr *base) {
  197     rpmRessPtr res = *base, next;
  198 
  199     while (res != NULL) {
  200         next = res->next;
  201     rpmRessFree(res);
  202     res = next;
  203     }
  204     *base = NULL;
  205 }
  206 
  207 /*
  208  * Search a directory in the list. If not found, create a new one.
  209  */
  210 
  211 rpmDirPtr rpmDirSearch(char *dirname) {
  212     rpmDirPtr cur = dirList;
  213 
  214     while (cur != NULL) {
  215         if (!strcmp(dirname, cur->rpmdir)) return(cur);
  216     cur = cur->next;
  217     }
  218     cur = (rpmDirPtr) xmlMalloc(sizeof(rpmDir));
  219     if (cur == NULL) {
  220         fprintf(stderr, "rpmDirSearch : ran out of memory!\n");
  221     exit(1);
  222     }
  223     memset(cur, 0, sizeof(rpmDir));
  224     cur->max_mirrors = 5;
  225     cur->mirrors = (char **) xmlMalloc(cur->max_mirrors * sizeof(char *));
  226     cur->color = xmlStrdup("#ffffff");
  227     cur->dir = NULL;
  228     cur->files = 0;
  229     cur->html = 1;
  230     cur->ftp = NULL;
  231     cur->ftpsrc = NULL;
  232     cur->host = NULL;
  233     cur->mail = NULL;
  234     cur->maint = NULL;
  235     cur->name = NULL;
  236     cur->nb_mirrors = 0;
  237     cur->mirrors[0] = NULL;
  238     cur->rpmdir = xmlStrdup(dirname);
  239     cur->size = 0;
  240     cur->trust = "1.0";
  241     cur->trust = NULL;
  242     cur->url = NULL;
  243     cur->build_tree = rpm2html_build_tree;
  244     cur->follow_symlinks = 0;
  245     cur->rpm_symlinks = 0;
  246 
  247     if (strncmp(dirname, "localbase", 9))   /* Added by A. Gibert */
  248         cur->installbase = 0;
  249     else
  250         cur->installbase = 1;
  251 
  252     cur->next = dirList;
  253     dirList = cur;
  254     return(cur);
  255 }
  256 
  257 /*
  258  * addConfigEntry : an entry in the config file has just been read.
  259  */
  260 void addConfigEntry(char *rpmdir, char *name, char *value) {
  261     rpmDirPtr cur;
  262     char *temp;
  263 
  264     if (rpm2htmlVerbose > 1)
  265     printf("addConfigEntry(\"%s\", \"%s\", \"%s\")\n", rpmdir, name, value);
  266 
  267     /*
  268      * case of global option for rpm2html.
  269      */
  270     if (!strcasecmp(rpmdir, RPM2HTML_NAME)) {
  271         if (!strcasecmp(name, "url")) {
  272         rpm2html_url = xmlStrdup(value);
  273     } else if (!strcasecmp(name, "maint")) {
  274         rpm2html_maint = xmlStrdup(value);
  275     } else if (!strcasecmp(name, "help")) {
  276         rpm2html_help = xmlStrdup(value);
  277     } else if (!strcasecmp(name, "mail")) {
  278         rpm2html_mail = xmlStrdup(value);
  279     } else if (!strcasecmp(name, "dir")) {
  280         rpm2html_dir = xmlStrdup(value);
  281     } else if (!strcasecmp(name, "ftp")) {
  282         rpm2html_ftp = xmlStrdup(value);
  283     } else if (!strcasecmp(name, "ftpsrc")) {
  284         rpm2html_ftpsrc = xmlStrdup(value);
  285     } else if (!strcasecmp(name, "name")) {
  286         rpm2html_name = xmlStrdup(value);
  287     } else if (!strcasecmp(name, "host")) {
  288         rpm2html_host = xmlStrdup(value);
  289     } else if (!strcasecmp(name, "tree")) {
  290         if ((!strcasecmp(value, "true")) ||
  291             (!strcasecmp(value, "yes"))) {
  292             rpm2html_build_tree = 1;
  293         } else if ((!strcasecmp(value, "false")) ||
  294             (!strcasecmp(value, "no"))) {
  295             rpm2html_build_tree = 0;
  296         } else {
  297         printf("Config file : %s global entry ignored,\n", name);
  298         printf("\tuse \"tree=true\" or \"tree=false\"\n");
  299         }
  300     } else if (!strcasecmp(name, "rdf")) {
  301         if ((!strcasecmp(value, "true")) ||
  302             (!strcasecmp(value, "yes"))) {
  303             rpm2html_dump_rdf = 1;
  304         } else if ((!strcasecmp(value, "false")) ||
  305             (!strcasecmp(value, "no"))) {
  306             rpm2html_dump_rdf = 0;
  307         } else {
  308         printf("Config file : %s global entry ignored,\n", name);
  309         printf("\tuse \"rdf=true\" or \"rdf=false\"\n");
  310         }
  311     } else if (!strcasecmp(name, "rdf_dir")) {
  312         rpm2html_rdf_dir = xmlStrdup(value);
  313     } else if (!strcasecmp(name, "rdf_resources")) {
  314         if ((!strcasecmp(value, "true")) ||
  315             (!strcasecmp(value, "yes"))) {
  316             rpm2html_dump_rdf_resources = 1;
  317         } else if ((!strcasecmp(value, "false")) ||
  318             (!strcasecmp(value, "no"))) {
  319             rpm2html_dump_rdf_resources = 0;
  320         } else {
  321         printf("Config file : %s global entry ignored,\n", name);
  322         printf("\tuse \"rdf_resources=true\" or \"rdf_resources=false\"\n");
  323         }
  324     } else if (!strcasecmp(name, "rdf_resources_dir")) {
  325         rpm2html_rdf_resources_dir = xmlStrdup(value);
  326     } else if (!strcasecmp(name, "rdf_count_limit")) {
  327         rpm2html_rdf_count_limit = strtol(value, &temp, 10);
  328         if ((*value == '\0') || (*temp != '\0')) {
  329         printf("Config file : %s global entry ignored,\n", name);
  330         printf("\tuse \"rdf_count_limit=<number>\"\n");
  331         rpm2html_rdf_count_limit = DEFAULT_RDF_COUNT_LIMIT;
  332         }
  333     } else if (!strcasecmp(name, "html")) {
  334         if ((!strcasecmp(value, "true")) ||
  335             (!strcasecmp(value, "yes"))) {
  336             rpm2html_dump_html = 1;
  337         } else if ((!strcasecmp(value, "false")) ||
  338             (!strcasecmp(value, "no"))) {
  339             rpm2html_dump_html = 0;
  340         } else {
  341         printf("Config file : %s global entry ignored,\n", name);
  342         printf("\tuse \"html=true\" or \"html=false\"\n");
  343         }
  344         #ifdef HAVE_LIBTEMPLATE
  345     } else if (!strcasecmp(name, "html_template")) {
  346         rpm2html_html_template = xmlStrdup(value);
  347         #endif
  348     } else if (!strcasecmp(name, "protectemails")) {
  349         if ((!strcasecmp(value, "true")) ||
  350             (!strcasecmp(value, "yes"))) {
  351             rpm2html_protect_emails = 1;
  352         } else if ((!strcasecmp(value, "false")) ||
  353             (!strcasecmp(value, "no"))) {
  354             rpm2html_protect_emails = 0;
  355         } else {
  356         printf("Config file : %s global entry ignored,\n", name);
  357         printf("\tuse \"protectemails=true\" or \"protectemails=false\"\n");
  358         }
  359     } else if (!strcasecmp(name, "cve_linking")) {
  360         if ((!strcasecmp(value, "true")) ||
  361             (!strcasecmp(value, "yes"))) {
  362             rpm2html_cve_linking = 1;
  363         } else if ((!strcasecmp(value, "false")) ||
  364             (!strcasecmp(value, "no"))) {
  365             rpm2html_cve_linking = 0;
  366         } else {
  367         printf("Config file : %s global entry ignored,\n", name);
  368         printf("\tuse \"cve_linking=true\" or \"cve_linking=false\"\n");
  369         }
  370     } else if (!strcasecmp(name, "header")) {
  371         addHeader(value);
  372     } else if (!strcasecmp(name, "dump_html_only_if_rpm_newer")) {
  373         if ((!strcasecmp(value, "true")) ||
  374             (!strcasecmp(value, "yes"))) {
  375             rpm2html_dump_html_only_if_rpm_newer = 1;
  376         } else if ((!strcasecmp(value, "false")) ||
  377             (!strcasecmp(value, "no"))) {
  378             rpm2html_dump_html_only_if_rpm_newer = 0;
  379         } else {
  380         printf("Config file : %s global entry ignored,\n", name);
  381         printf("\tuse \"dump_html_only_if_rpm_newer=true\" or \"dump_html_only_if_rpm_newer=false\"\n");
  382         }
  383         } else {
  384         printf("Config file : %s global entry ignored\n", name);
  385     }
  386     return;
  387     }
  388 
  389     /*
  390      * Options for the metadata mirrors.
  391      */
  392     if (!strcasecmp(rpmdir, "metadata")) {
  393     if (!strcasecmp(name, "mirror")) {
  394         /*
  395          * all "mirrors" values are collected in the metadata_mirrors array.
  396          */
  397         if (metadata_mirrors == NULL) {
  398             max_metadata_mirrors = 10;
  399         nb_metadata_mirrors = 0;
  400         metadata_mirrors = (char **)
  401                   xmlMalloc(max_metadata_mirrors * sizeof(char *));
  402         if (metadata_mirrors == NULL) {
  403             fprintf(stderr, "addConfigEntry : ran out of memory!\n");
  404             exit(1);
  405         }
  406         }
  407         if (nb_metadata_mirrors >= max_metadata_mirrors) {
  408         max_metadata_mirrors *= 2;
  409         metadata_mirrors = (char **) xmlRealloc(metadata_mirrors,
  410                        max_metadata_mirrors * sizeof(char *));
  411         if (metadata_mirrors == NULL) {
  412             fprintf(stderr, "addConfigEntry : ran out of memory!\n");
  413             exit(1);
  414         }
  415         }
  416         metadata_mirrors[nb_metadata_mirrors++] = xmlStrdup(value);
  417     } else {
  418         printf("Config file : %s entry for [metadata] ignored\n", name);
  419     }
  420     return;
  421     }
  422 
  423     /*
  424      * option for a directory.
  425      */
  426     cur = rpmDirSearch(rpmdir);
  427     if (!strcasecmp(name, "name")) {
  428     cur->name = xmlStrdup(value);
  429     } else if (!strcasecmp(name, "dir")) {
  430     cur->dir = xmlStrdup(value);
  431     } else if (!strcasecmp(name, "subdir")) {
  432     cur->subdir = xmlStrdup(value);
  433     } else if (!strcasecmp(name, "dbpath")) {   /* Added by A. Gibert */
  434        cur->dbpath = xmlStrdup(value);   /* Added by A. Gibert */
  435     } else if (!strcasecmp(name, "url")) {
  436     cur->url = xmlStrdup(value);
  437     } else if (!strcasecmp(name, "ftp")) {
  438     cur->ftp = xmlStrdup(value);
  439     } else if (!strcasecmp(name, "ftpsrc")) {
  440     cur->ftpsrc = xmlStrdup(value);
  441     } else if (!strcasecmp(name, "color")) {
  442     if (cur->color != NULL) xmlFree(cur->color);
  443     cur->color = xmlStrdup(value);
  444     } else if (!strcasecmp(name, "trust")) {
  445     if (cur->trust != NULL) xmlFree(cur->color);
  446     cur->trust = xmlStrdup(value);
  447     } else if (!strcasecmp(name, "host")) {
  448     rpm2html_host = xmlStrdup(value);
  449     } else if (!strcasecmp(name, "rdf_dir")) {
  450     rpm2html_rdf_dir = xmlStrdup(value);
  451     } else if (!strcasecmp(name, "html")) {
  452     if ((!strcasecmp(value, "true")) ||
  453         (!strcasecmp(value, "yes"))) {
  454         cur->html = 1;
  455     } else if ((!strcasecmp(value, "false")) ||
  456         (!strcasecmp(value, "no"))) {
  457         cur->html = 0;
  458     } else {
  459         printf("Config file : %s directory entry ignored,\n", name);
  460         printf("\tuse \"html=true\" or \"html=false\"\n");
  461     }
  462     } else if (!strcasecmp(name, "tree")) {
  463     if ((!strcasecmp(value, "true")) ||
  464         (!strcasecmp(value, "yes"))) {
  465         cur->build_tree = 1;
  466     } else if ((!strcasecmp(value, "false")) ||
  467         (!strcasecmp(value, "no"))) {
  468         cur->build_tree = 0;
  469     } else {
  470         printf("Config file : %s directory entry ignored,\n", name);
  471         printf("\tuse \"tree=true\" or \"tree=false\"\n");
  472     }
  473     } else if (!strcasecmp(name, "followsymlinks")) {
  474     if ((!strcasecmp(value, "true")) ||
  475         (!strcasecmp(value, "yes"))) {
  476         cur->follow_symlinks = 1;
  477     } else if ((!strcasecmp(value, "false")) ||
  478         (!strcasecmp(value, "no"))) {
  479         cur->follow_symlinks = 0;
  480     } else {
  481         printf("Config file : %s directory entry ignored,\n", name);
  482         printf("\tuse \"tree=true\" or \"tree=false\"\n");
  483     }
  484     } else if (!strcasecmp(name, "rpmsymlinks")) {
  485     if ((!strcasecmp(value, "true")) ||
  486         (!strcasecmp(value, "yes"))) {
  487         cur->rpm_symlinks = 1;
  488     } else if ((!strcasecmp(value, "false")) ||
  489         (!strcasecmp(value, "no"))) {
  490         cur->rpm_symlinks = 0;
  491     } else {
  492         printf("Config file : %s directory entry ignored,\n", name);
  493         printf("\tuse \"tree=true\" or \"tree=false\"\n");
  494     }
  495     } else if (!strcasecmp(name, "mirror")) {
  496         /*
  497      * all "mirrors" values are collected in the mirrors array.
  498      */
  499     if (cur->nb_mirrors >= cur->max_mirrors) {
  500         cur->max_mirrors *= 2;
  501         cur->mirrors = (char **) xmlRealloc(cur->mirrors,
  502                                    cur->max_mirrors * sizeof(char *));
  503         if (cur->mirrors == NULL) {
  504             fprintf(stderr, "addConfigEntry : ran out of memory!\n");
  505         exit(1);
  506         }
  507     }
  508     cur->mirrors[cur->nb_mirrors++] = xmlStrdup(value);
  509     } else {
  510     printf("Config file : %s entry for [%s] ignored\n", name, rpmdir);
  511     }
  512 }
  513 
  514 /****************************************************************
  515  *                              *
  516  *      The configuration file parser           *
  517  *                              *
  518  ****************************************************************/
  519 
  520 /*
  521  * A few macro needed to help building the parser
  522  */
  523 
  524 #define IS_BLANK(ptr) \
  525      (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
  526       ((*(ptr)) == '\n') || ((*(ptr)) == '\r'))
  527 #define SKIP_BLANK(ptr) \
  528      { while (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
  529               ((*(ptr)) == '\n') || ((*(ptr)) == '\r')) ptr++; }
  530 #define GOTO_EQL(ptr) \
  531      { while (((*(ptr)) != '\0') && ((*(ptr)) != '=') && \
  532               ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
  533 #define GOTO_EOL(ptr) \
  534      { while (((*(ptr)) != '\0') && \
  535               ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
  536 
  537 /*
  538  * addHeader : parse an Header entry, we expect the first
  539  *             part to be an URL and the end of the line is the name.
  540  *
  541  * e.g: "help.html Get Help"
  542  */
  543 void addHeader(char *value) {
  544     char *url;
  545     char *name;
  546     char save;
  547 
  548     /*
  549      * Check for more room in the header arrays.
  550      * Yes I'm lazy ...
  551      */
  552     if (rpm2html_nb_extra_headers >= MAX_EXTRA_HEADERS) {
  553         fprintf(stderr, "Too many headers, increase MAX_EXTRA_HEADERS\n");
  554     return;
  555     }
  556 
  557     /*
  558      * Check the url, parse until finding a blank.
  559      */
  560     name = value;
  561     while (!IS_BLANK(name)) name++;
  562     save = *name;
  563     *name = 0;
  564     url = xmlStrdup(value);
  565     *name = save;
  566     if (url == NULL) {
  567         fprintf(stderr, "strndup \"%s\" failed\n", value);
  568     exit(1);
  569     }
  570     SKIP_BLANK(name);
  571     if (*name == '\0') {
  572         fprintf(stderr, "Config file : expecting \"header URL description\"\n");
  573         fprintf(stderr, "\tfound \"header: %s\", ignored\n", value);
  574     xmlFree(url);
  575     return;
  576     }
  577 
  578     /*
  579      * Store the values in global variables.
  580      */
  581     rpm2html_headers_name[rpm2html_nb_extra_headers] = xmlStrdup(name);
  582     rpm2html_headers_url[rpm2html_nb_extra_headers] = url;
  583     rpm2html_nb_extra_headers++;
  584 }
  585 
  586 
  587 /*
  588  * read config file: parse a configuration file.
  589  */
  590 int readConfigFile(char *filename)
  591 {
  592    FILE *input;
  593    char *str, *base;
  594    char string[1000];
  595    char rpmdir[1000] = "rpm2html";
  596    char *name;
  597    char *value;
  598    int errors = 0;
  599 
  600    rpm2html_host = rpm2html_rpm2html_thishost;
  601    input = fopen (filename, "r");
  602    if (input == NULL)
  603      {
  604     fprintf (stderr, "Cannot read config from %s :\n", filename);
  605     perror ("fopen failed");
  606     return -1;
  607      }
  608 
  609    while (1)
  610      {
  611     /*
  612      * read one line in string buffer.
  613      */
  614     if (fgets (&string[0], sizeof (string) - 1, input) == NULL)
  615        break;
  616 
  617     str = &string[0];
  618     SKIP_BLANK (str)
  619     string[sizeof (string) - 1] = '\0';
  620 
  621     /*
  622      * Comment starts with a semicolumn.
  623      */
  624     if (*str == ';')
  625        continue;
  626     if (*str == '\0')
  627        continue;
  628 
  629     /*
  630      * sections are indicated between brackets, e.g. [amaya]
  631      */
  632     if (*str == '[')
  633       {
  634          str++;
  635          SKIP_BLANK (str)
  636          base = str;
  637          while ((*str != '\0') && (*str != ']'))
  638         str++;
  639          if (*str == '\0')
  640            {
  641           fprintf (stderr, "config file %s corrupted :\n\t\"%s\"\n",
  642                filename, string);
  643           break;
  644            }
  645          *str = '\0';
  646          strcpy (&rpmdir[0], base);
  647          if (strcasecmp(rpmdir, "metadata"))
  648          rpmDirSearch(rpmdir);
  649 
  650          if (rpm2htmlVerbose > 1)
  651          fprintf (stderr, "readConfigFile section [%s]\n", rpmdir);
  652 
  653          continue;
  654       }
  655 
  656     /*
  657      * entries have the following form :
  658      *    name=value
  659      */
  660     name = str;
  661     GOTO_EQL (str)
  662     if (*str != '=') {
  663        errors++;
  664        if (errors >= 30) {
  665            fprintf (stderr, "config file %s seems invalid\n", filename);
  666            exit(1);
  667        }
  668        continue;
  669     }
  670     *str++ = '\0';
  671     SKIP_BLANK (str)
  672     value = str;
  673     GOTO_EOL (str)
  674     *str = '\0';
  675     addConfigEntry(rpmdir, name, value);
  676 #ifdef WITH_SQL
  677     /*
  678      * Duplicate the info in the SQL base
  679      */
  680     sqlConfigEntry(rpmdir, name, value);
  681 #endif
  682      }
  683 
  684    fclose (input);
  685    return(0);
  686 }
  687 
  688 /*
  689  * reinitialize the base setup.
  690  */
  691 void reinitialize(void) {
  692     if (rpm2html_dir) {
  693         xmlFree(rpm2html_dir);
  694     rpm2html_dir = NULL;
  695     }
  696     if (rpm2html_name) {
  697         xmlFree(rpm2html_name);
  698     rpm2html_name = NULL;
  699     }
  700     if (rpm2html_url) {
  701         xmlFree(rpm2html_url);
  702     rpm2html_url = NULL;
  703     }
  704     if (rpm2html_ftp) {
  705         xmlFree(rpm2html_ftp);
  706     rpm2html_ftp = NULL;
  707     }
  708     if (rpm2html_ftpsrc) {
  709         xmlFree(rpm2html_ftpsrc);
  710     rpm2html_ftpsrc = NULL;
  711     }
  712     if ((rpm2html_rpm2html_name != NULL) &&
  713         (strcmp(rpm2html_rpm2html_name, RPM2HTML_NAME))) {
  714         xmlFree(rpm2html_rpm2html_name);
  715     }
  716     rpm2html_rpm2html_name = RPM2HTML_NAME;
  717     if ((rpm2html_rpm2html_ver != NULL) &&
  718         (strcmp(rpm2html_rpm2html_ver, RPM2HTML_VER))) {
  719         xmlFree(rpm2html_rpm2html_ver);
  720     }
  721     rpm2html_rpm2html_ver = RPM2HTML_VER;
  722     if ((rpm2html_rpm2html_url != NULL) &&
  723         (strcmp(rpm2html_rpm2html_url, RPM2HTML_URL))) {
  724         xmlFree(rpm2html_rpm2html_url);
  725     }
  726     rpm2html_rpm2html_url = RPM2HTML_URL;
  727     if ((rpm2html_maint != NULL) && (strcmp(rpm2html_maint, RPM2HTML_MAINT))) {
  728         xmlFree(rpm2html_maint);
  729     }
  730     rpm2html_maint = RPM2HTML_MAINT;
  731     if ((rpm2html_mail != NULL) && (strcmp(rpm2html_mail, RPM2HTML_MAIL))) {
  732         xmlFree(rpm2html_mail);
  733     }
  734     rpm2html_mail = RPM2HTML_MAIL;
  735     rpm2html_dir = NULL;
  736     rpm2html_name = NULL;
  737     rpm2html_url = NULL;
  738     rpm2html_ftp = NULL;
  739     rpm2html_ftpsrc = NULL;
  740     if (rpm2html_host != NULL && rpm2html_host != rpm2html_rpm2html_thishost) xmlFree(rpm2html_host);
  741     rpm2html_host = rpm2html_rpm2html_thishost;
  742     rpm2html_build_tree = 0;
  743     rpm2html_dump_rdf = 0;
  744     rpm2html_dump_rdf_resources = 0;
  745     rpm2html_dump_html = 1;
  746     #ifdef HAVE_LIBTEMPLATE
  747     if (rpm2html_html_template != NULL) xmlFree(rpm2html_html_template);
  748     rpm2html_html_template = "rpm2html.tpl";
  749     #endif
  750     if (rpm2html_rdf_dir != NULL) xmlFree(rpm2html_rdf_dir);
  751     rpm2html_rdf_dir = NULL;
  752     if (rpm2html_rdf_resources_dir != NULL) xmlFree(rpm2html_rdf_resources_dir);
  753     rpm2html_rdf_resources_dir = NULL;
  754 
  755     for (;rpm2html_nb_extra_headers > 0;) {
  756     rpm2html_nb_extra_headers--;
  757         xmlFree(rpm2html_headers_name[rpm2html_nb_extra_headers]);
  758     rpm2html_headers_name[rpm2html_nb_extra_headers] = NULL;
  759     xmlFree(rpm2html_headers_url[rpm2html_nb_extra_headers]);
  760     rpm2html_headers_url[rpm2html_nb_extra_headers] = NULL;
  761     }
  762     rpm2html_nb_extra_headers = 0;
  763 
  764     /*
  765      * Cleanup of other modules.
  766      */
  767     rpmdataCleanup();
  768     htmlCleanup();
  769     rpmopenCleanup();
  770     #ifdef HAVE_LIBTEMPLATE
  771     destroyTemplateEngine();
  772     #endif
  773 }
  774