summaryrefslogtreecommitdiff
path: root/uhttpd-utils.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-10-15 20:09:55 +0300
committerJo-Philipp Wich <jow@openwrt.org>2012-10-15 20:09:55 +0300
commit76d15b63c7f1a29fa994b2f056387101e1126e0a (patch)
tree58fed08d435a14f79d95b9659e487849479ef994 /uhttpd-utils.c
parentfa43d1a62864f912e4450affb9c86f3accbe026a (diff)
downloaduhttpd-76d15b63c7f1a29fa994b2f056387101e1126e0a.tar.gz
support multiple index files in the configuration and the command line args
Diffstat (limited to 'uhttpd-utils.c')
-rw-r--r--uhttpd-utils.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/uhttpd-utils.c b/uhttpd-utils.c
index 1e1ac80..ad8813e 100644
--- a/uhttpd-utils.c
+++ b/uhttpd-utils.c
@@ -24,14 +24,6 @@
#endif
-static char *uh_index_files[] = {
- "index.html",
- "index.htm",
- "default.html",
- "default.htm"
-};
-
-
const char * sa_straddr(void *sa)
{
static char str[INET6_ADDRSTRLEN];
@@ -553,6 +545,25 @@ static char * canonpath(const char *path, char *path_resolved)
return NULL;
}
+
+struct index_file *uh_index_files = NULL;
+
+struct index_file * uh_index_add(const char *filename)
+{
+ struct index_file *new = NULL;
+
+ if ((filename != NULL) && (new = malloc(sizeof(*new))) != NULL)
+ {
+ new->name = filename;
+ new->next = uh_index_files;
+
+ uh_index_files = new;
+ }
+
+ return new;
+}
+
+
/* Returns NULL on error.
** NB: improperly encoded URL should give client 400 [Bad Syntax]; returning
** NULL here causes 404 [Not Found], but that's not too unreasonable. */
@@ -570,6 +581,7 @@ struct path_info * uh_path_lookup(struct client *cl, const char *url)
int no_sym = cl->server->conf->no_symlinks;
int i = 0;
struct stat s;
+ struct index_file *idx;
/* back out early if url is undefined */
if (url == NULL)
@@ -680,21 +692,11 @@ struct path_info * uh_path_lookup(struct client *cl, const char *url)
p.redirected = 1;
}
- else if (cl->server->conf->index_file)
- {
- strncat(buffer, cl->server->conf->index_file, sizeof(buffer));
-
- if (!stat(buffer, &s) && (s.st_mode & S_IFREG))
- {
- memcpy(path_phys, buffer, sizeof(path_phys));
- memcpy(&p.stat, &s, sizeof(p.stat));
- }
- }
else
{
- for (i = 0; i < array_size(uh_index_files); i++)
+ for (idx = uh_index_files; idx; idx = idx->next)
{
- strncat(buffer, uh_index_files[i], sizeof(buffer));
+ strncat(buffer, idx->name, sizeof(buffer));
if (!stat(buffer, &s) && (s.st_mode & S_IFREG))
{