mirror of
https://github.com/lxsang/ant-http
synced 2024-12-26 16:58:22 +01:00
add rules supports (alpha)
This commit is contained in:
parent
c544976c04
commit
60deb84111
2
config.h
2
config.h
@ -1,4 +1,5 @@
|
|||||||
#define CONFIG "config.ini"
|
#define CONFIG "config.ini"
|
||||||
|
#include "plugins/dictionary.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int port;
|
int port;
|
||||||
@ -7,6 +8,7 @@ typedef struct {
|
|||||||
char *db_path;
|
char *db_path;
|
||||||
char* htdocs;
|
char* htdocs;
|
||||||
char* tmpdir;
|
char* tmpdir;
|
||||||
|
dictionary rules;
|
||||||
}config_t;
|
}config_t;
|
||||||
|
|
||||||
extern config_t server_config;
|
extern config_t server_config;
|
@ -10,7 +10,9 @@ void accept_request(int client)
|
|||||||
int numchars;
|
int numchars;
|
||||||
char method[255];
|
char method[255];
|
||||||
char url[4096];
|
char url[4096];
|
||||||
char path[512];
|
char path[1024];
|
||||||
|
char* token;
|
||||||
|
char *line;
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
@ -28,8 +30,8 @@ void accept_request(int client)
|
|||||||
{
|
{
|
||||||
printf("METHOD NOT FOUND %s\n", method);
|
printf("METHOD NOT FOUND %s\n", method);
|
||||||
// unimplemented
|
// unimplemented
|
||||||
|
//while(get_line(client, buf, sizeof(buf)) > 0) printf("%s\n",buf );
|
||||||
unimplemented(client);
|
unimplemented(client);
|
||||||
while(get_line(client, buf, sizeof(buf)) > 0) printf("%s\n",buf );
|
|
||||||
close(client);
|
close(client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -57,10 +59,27 @@ void accept_request(int client)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the HOST header
|
||||||
|
line = read_line(client);
|
||||||
|
trim(line, '\n');
|
||||||
|
trim(line, '\r');
|
||||||
|
token = strsep(&line,":");
|
||||||
|
trim(token,' ');
|
||||||
|
trim(line,' ');
|
||||||
|
if(strcasecmp(token, "HOST"))
|
||||||
|
{
|
||||||
|
badrequest(client);
|
||||||
|
close(client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// perform rule check in domain
|
||||||
|
|
||||||
|
|
||||||
sprintf(path, server_config.htdocs);
|
sprintf(path, server_config.htdocs);
|
||||||
strcat(path, url);
|
strcat(path, url);
|
||||||
if (path[strlen(path) - 1] == '/')
|
//if (path[strlen(path) - 1] == '/')
|
||||||
strcat(path, "index.html");
|
// strcat(path, "index.html");
|
||||||
if (stat(path, &st) == -1) {
|
if (stat(path, &st) == -1) {
|
||||||
if(execute_plugin(client,url,method,query_string) < 0)
|
if(execute_plugin(client,url,method,query_string) < 0)
|
||||||
not_found(client);
|
not_found(client);
|
||||||
@ -293,6 +312,14 @@ void unimplemented(int client)
|
|||||||
__t(client, "</BODY></HTML>");
|
__t(client, "</BODY></HTML>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void badrequest(int client)
|
||||||
|
{
|
||||||
|
set_status(client,400,"Bad Request");
|
||||||
|
__t(client,SERVER_STRING);
|
||||||
|
__t(client,"Content-Type: text/html");
|
||||||
|
response(client,"");
|
||||||
|
__t(client,"The request could not be understood by the server due to malformed syntax.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include "plugins/dictionary.h"
|
|
||||||
#include "plugins/handle.h"
|
#include "plugins/handle.h"
|
||||||
#include "plugin_manager.h"
|
#include "plugin_manager.h"
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ void not_found(int);
|
|||||||
void serve_file(int, const char *);
|
void serve_file(int, const char *);
|
||||||
int startup(unsigned *);
|
int startup(unsigned *);
|
||||||
void unimplemented(int);
|
void unimplemented(int);
|
||||||
|
void badrequest(int);
|
||||||
void ws_confirm_request(int, const char*);
|
void ws_confirm_request(int, const char*);
|
||||||
char* post_url_decode(int client,int len);
|
char* post_url_decode(int client,int len);
|
||||||
dictionary decode_url_request(const char* query);
|
dictionary decode_url_request(const char* query);
|
||||||
|
8
httpd.c
8
httpd.c
@ -22,7 +22,12 @@ static int config_handler(void* conf, const char* section, const char* name,
|
|||||||
pconfig->htdocs = strdup(value);
|
pconfig->htdocs = strdup(value);
|
||||||
} else if(MATCH("SERVER", "tmpdir")) {
|
} else if(MATCH("SERVER", "tmpdir")) {
|
||||||
pconfig->tmpdir = strdup(value);
|
pconfig->tmpdir = strdup(value);
|
||||||
}else if(strcmp(section,"AUTOSTART")==0){
|
}
|
||||||
|
else if (strcmp(section, "RULES") == 0)
|
||||||
|
{
|
||||||
|
dput( pconfig->rules, strdup(name),strdup(value));
|
||||||
|
}
|
||||||
|
else if(strcmp(section,"AUTOSTART")==0){
|
||||||
// The server section must be added before the autostart section
|
// The server section must be added before the autostart section
|
||||||
// auto start plugin
|
// auto start plugin
|
||||||
plugin_load(value);
|
plugin_load(value);
|
||||||
@ -56,6 +61,7 @@ void load_config(const char* file)
|
|||||||
server_config.db_path = "databases/";
|
server_config.db_path = "databases/";
|
||||||
server_config.htdocs = "htdocs";
|
server_config.htdocs = "htdocs";
|
||||||
server_config.tmpdir = "tmp";
|
server_config.tmpdir = "tmp";
|
||||||
|
server_config.rules = dict();
|
||||||
if (ini_parse(file, config_handler, &server_config) < 0) {
|
if (ini_parse(file, config_handler, &server_config) < 0) {
|
||||||
LOG("Can't load '%s'\n. Used defaut configuration", file);
|
LOG("Can't load '%s'\n. Used defaut configuration", file);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user