config.root.dir_count = 0;
config.root.icon_count = 0;
config.root.index_count = 0;
+ config.root.readme_count = 0;
config.vhost_count = 0;
config.module_count = 0;
config.extension = NULL;
current->mime_count = 0;
current->icon_count = 0;
current->index_count = 0;
+ current->readme_count = 0;
int i;
current->name = cm_strdup(vhost);
current->port = -1;
for(i = 1; r[i] != NULL; i++) {
current->indexes[current->index_count++] = cm_strdup(r[i]);
}
+ } else if(cm_strcaseequ(r[0], "Readme")) {
+ for(i = 1; r[i] != NULL; i++) {
+ current->readmes[current->readme_count++] = cm_strdup(r[i]);
+ }
} else {
if(r[0] != NULL) {
cm_log("Config", "Unknown directive `%s' at line %d", r[0], ln);
addstring(&str, " <th>MIME</th>\n");
addstring(&str, " <th>Size</th>\n");
addstring(&str, " </tr>\n");
+ int readme = -1;
+ char** readmes = vhost_entry->readme_count == 0 ? config.root.readmes : vhost_entry->readmes;
+ int readme_count = vhost_entry->readme_count == 0 ? config.root.readme_count : vhost_entry->readme_count;
if(items != NULL) {
int phase = 0;
doit:
for(i = 0; items[i] != NULL; i++) {
+ int j;
char* fpth = cm_strcat3(path, "/", items[i]);
struct stat s;
char size[512];
free(fpth);
continue;
}
+ if(readme == -1) {
+ for(j = 0; j < readme_count; j++) {
+ if(strcmp(items[i], readmes[j]) == 0) {
+ readme = j;
+ break;
+ }
+ }
+ if(readme != -1) {
+ free(fpth);
+ continue;
+ }
+ }
if(s.st_size < 1024ULL) {
sprintf(size, "%d", (int)s.st_size);
} else if(s.st_size < 1024ULL * 1024) {
free(fpth);
char* ext = NULL;
- int j;
for(j = strlen(items[i]) - 1; j >= 0; j--) {
if(items[i][j] == '.') {
ext = cm_strdup(items[i] + j);
free(items);
}
addstring(&str, " </table>\n");
+ if(readme != -1) {
+ addstring(&str, "<hr>\n");
+ char* fpth = cm_strcat3(path, "/", readmes[readme]);
+ struct stat s;
+ stat(fpth, &s);
+ FILE* fr = fopen(fpth, "r");
+ if(fr != NULL) {
+ char* rmbuf = malloc(s.st_size + 1);
+ rmbuf[s.st_size] = 0;
+ fread(rmbuf, s.st_size, 1, fr);
+ addstring(&str, "<pre><code>%h</code></pre>\n", rmbuf);
+ fclose(fr);
+ }
+ }
addstring(&str, " <hr>\n");
addstring(&str, " <address>%s Server at %s Port %d</address>\n", tw_server, name, port);
addstring(&str, " </body>\n");