diff --git a/http_server.c b/http_server.c index af91a2d..2dd8c10 100644 --- a/http_server.c +++ b/http_server.c @@ -73,11 +73,32 @@ void accept_request(void* client) { if (S_ISDIR(st.st_mode)) { + int l = strlen(path); + int ul = strlen(url); strcat(path, "/index.html"); if(stat(path, &st) == -1) { - not_found(client); - goto end; + association it; + for_each_assoc(it, server_config.handlers) + { + path[l] = '\0'; + url[ul] = '\0'; + strcat(url,"/index."); + strcat(path, "/index."); + strcat(url,it->key); + strcat(path, it->key); + if(stat(path, &st) == 0) + { + l = -1; + i = HASHSIZE; + break; + } + } + if(l!= -1) + { + not_found(client); + goto end; + } } } // check if the mime is supported @@ -87,10 +108,17 @@ void accept_request(void* client) char* mime_type = mime(path); if(strcmp(mime_type,"application/octet-stream") == 0) { - sprintf(buf,"/%s-api%s",ext(path),url); - LOG("WARNING::::Access octetstream via handler %s\n", buf); - if(execute_plugin(client,buf,method,rq) < 0) - cannot_execute(client); + char* h = dvalue(server_config.handlers,ext(path)); + if(h) + { + sprintf(buf,"/%s%s",h,url); + LOG("WARNING::::Access octetstream via handler %s\n", buf); + if(execute_plugin(client,buf,method,rq) < 0) + cannot_execute(client); + } + else + unknow(client); + } else { diff --git a/httpd.c b/httpd.c index 12bf296..0163970 100644 --- a/httpd.c +++ b/httpd.c @@ -99,6 +99,10 @@ static int config_handler(void* conf, const char* section, const char* name, else if (strcmp(section, "RULES") == 0) { dput( pconfig->rules, strdup(name),strdup(value)); + } + else if (strcmp(section, "FILEHANDLER") == 0) + { + dput( pconfig->handlers, strdup(name),strdup(value)); } else if(strcmp(section,"AUTOSTART")==0){ // The server section must be added before the autostart section @@ -136,6 +140,7 @@ void load_config(const char* file) server_config.tmpdir = "tmp"; server_config.backlog = 100; server_config.rules = dict(); + server_config.handlers = dict(); #ifdef USE_OPENSSL server_config.usessl = 0; server_config.sslcert = "cert.pem"; @@ -157,6 +162,7 @@ void load_config(const char* file) } void stop_serve(int dummy) { free(server_config.rules); + free(server_config.handlers); unload_all_plugin(); } int main(int argc, char* argv[]) diff --git a/libs/handle.h b/libs/handle.h index 9233ccd..84de8f0 100644 --- a/libs/handle.h +++ b/libs/handle.h @@ -37,6 +37,7 @@ typedef struct { char* htdocs; char* tmpdir; dictionary rules; + dictionary handlers; int backlog; #ifdef USE_OPENSSL int usessl;