Annotation of rpm2html/config.c, revision 1.41

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

Webmaster