Annotation of rpm2html/config.c, revision 1.30

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

Webmaster