Annotation of rpm2html/config.c, revision 1.39

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

Webmaster