- /*
- * Trim trailing slash, just in case.
- */
- pathlen = strlen(querydir);
- if (pathlen > 0 && querydir[pathlen-1] == pathsep)
- querydir[--pathlen] = '\0';
-
- xi = trie_before(mappedfile, querydir);
- cfg.format = NULL;
- cfg.autoage = htmlautoagerange;
- cfg.oldest = htmloldest;
- cfg.newest = htmlnewest;
- html = html_query(mappedfile, xi, &cfg);
- fputs(html, stdout);
- } else if (mode == DUMP) {
- size_t maxpathlen;
- char *buf;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "%s: %s: open: %s\n", PNAME, filename,
- strerror(errno));
- return 1;
- }
- if (fstat(fd, &st) < 0) {
- perror("agedu: fstat");
- return 1;
- }
- totalsize = st.st_size;
- mappedfile = mmap(NULL, totalsize, PROT_READ, MAP_SHARED, fd, 0);
- if (!mappedfile) {
- perror("agedu: mmap");
- return 1;
- }
- pathsep = trie_pathsep(mappedfile);
-
- maxpathlen = trie_maxpathlen(mappedfile);
- buf = snewn(maxpathlen, char);
-
- printf("agedu dump file. pathsep=%02x\n", (unsigned char)pathsep);
- tw = triewalk_new(mappedfile);
- while ((tf = triewalk_next(tw, buf)) != NULL)
- dump_line(buf, tf);
- triewalk_free(tw);
- } else if (mode == HTTPD) {
- struct html_config pcfg;
- struct httpd_config dcfg;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "%s: %s: open: %s\n", PNAME, filename,
- strerror(errno));
- return 1;
- }
- if (fstat(fd, &st) < 0) {
- perror("agedu: fstat");
- return 1;
- }
- totalsize = st.st_size;
- mappedfile = mmap(NULL, totalsize, PROT_READ, MAP_SHARED, fd, 0);
- if (!mappedfile) {
- perror("agedu: mmap");
- return 1;
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "%s: %s: open: %s\n", PNAME, filename,
+ strerror(errno));
+ return 1;
+ }
+ if (fstat(fd, &st) < 0) {
+ perror("agedu: fstat");
+ return 1;
+ }
+ totalsize = st.st_size;
+ mappedfile = mmap(NULL, totalsize, PROT_READ, MAP_SHARED, fd, 0);
+ if (!mappedfile) {
+ perror("agedu: mmap");
+ return 1;
+ }
+ pathsep = trie_pathsep(mappedfile);
+
+ dcfg.address = httpserveraddr;
+ dcfg.port = httpserverport;
+ dcfg.basicauthdata = httpauthdata;
+ pcfg.format = NULL;
+ pcfg.autoage = htmlautoagerange;
+ pcfg.oldest = htmloldest;
+ pcfg.newest = htmlnewest;
+ run_httpd(mappedfile, auth, &dcfg, &pcfg);