1
0
mirror of https://github.com/lxsang/ant-http synced 2024-07-01 12:59:47 +02:00

rules now work on port

This commit is contained in:
lxsang 2019-12-20 19:26:45 +01:00
parent 85cfce134b
commit f0ecc62162
5 changed files with 41 additions and 34 deletions

View File

@ -1,8 +1,4 @@
[SERVER]
; server port
; use 443 if one want to use
; SSL
port=8080
; plugin directory
plugins=/opt/www/lib/
; plugin extension
@ -15,6 +11,8 @@ tmpdir=/opt/www/tmp/
server_log = /var/log/antd.log
; server error log
error_log = /var/log/antd_error.log
; max concurent connection
maxcon=200
; server backlocg
backlog=5000
; number of workers
@ -36,22 +34,7 @@ ssl.cipher=ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA
htdocs=/opt/www/htdocs
; enable or disable SSL
ssl.enable=1
[PORT:80]
htdocs=/opt/www/htdocs
; enable or disable SSL
ssl.enable=0
; This enable some plugins to be initialised at server startup
[AUTOSTART]
; to start a plugin at server statup use:
;plugin = plugin_name_1
;plugin = plugin_name_2, etc
; sever rules
[RULES]
; other config shoud be rules applied on this port
; For example the following rule will
; convert a request of type:
; name.example.com?rq=1
@ -62,6 +45,29 @@ ssl.enable=0
; ^([a-zA-Z][a-zA-Z0-9]*)\.[a-zA-Z0-9]+\..*$ = /<1><url>?<query>
; Sytax: [regular expression on the original request]=[new request rule]
[PORT:80]
htdocs=/opt/www/htdocs
; enable or disable SSL
ssl.enable=0
; other config shoud be rules applied on this port
; For example the following rule will
; convert a request of type:
; name.example.com?rq=1
;TO:
; example.com/name/?rq=1
; this is helpful to redirect many sub domains
; to a sub folder of the same server
; ^([a-zA-Z][a-zA-Z0-9]*)\.[a-zA-Z0-9]+\..*$ = /<1><url>?<query>
; Sytax: [regular expression on the original request]=[new request rule]
; This enable some plugins to be initialised at server startup
[AUTOSTART]
; to start a plugin at server statup use:
;plugin = plugin_name_1
;plugin = plugin_name_2, etc
[MIMES]
image/bmp=bmp
image/jpeg=jpg,jpeg

Binary file not shown.

View File

@ -74,7 +74,6 @@ void server_log(const char* fmt, ...)
#endif
void destroy_config()
{
list_free(&(server_config.rules));
freedict(server_config.handlers);
if (server_config.plugins_dir)
free(server_config.plugins_dir);
@ -111,6 +110,7 @@ void destroy_config()
{
close(cnf->sock);
}
list_free(&(cnf->rules));
}
freedict(server_config.ports);
}
@ -178,11 +178,6 @@ static int config_handler(void *conf, const char *section, const char *name,
pconfig->ssl_cipher = strdup(value);
}
#endif
else if (strcmp(section, "RULES") == 0)
{
list_put_s(&pconfig->rules, name);
list_put_s(&pconfig->rules, value);
}
else if (strcmp(section, "FILEHANDLER") == 0)
{
dput(pconfig->handlers, name, strdup(value));
@ -208,6 +203,7 @@ static int config_handler(void *conf, const char *section, const char *name,
p = (port_config_t*) malloc( sizeof(port_config_t));
p->htdocs = NULL;
p->sock = -1;
p->rules = list_init();
dput(pconfig->ports,buf, p);
p->port = atoi(buf);
}
@ -221,6 +217,12 @@ static int config_handler(void *conf, const char *section, const char *name,
if(p->usessl)
pconfig->enable_ssl = 1;
}
else
{
// other thing should be rules
list_put_s(&p->rules, name);
list_put_s(&p->rules, value);
}
}
else
{
@ -263,7 +265,6 @@ void load_config(const char *file)
server_config.tmpdir = "tmp/";
server_config.n_workers = 4;
server_config.backlog = 1000;
server_config.rules = list_init();
server_config.handlers = dict();
server_config.maxcon = 100;
server_config.connection = 0;
@ -694,7 +695,7 @@ int startup(unsigned *port)
return (httpd);
}
char *apply_rules(const char *host, char *url)
char *apply_rules(list_t rules, const char *host, char *url)
{
// rule check
char *query_string = url;
@ -706,12 +707,12 @@ char *apply_rules(const char *host, char *url)
query_string++;
}
//char* oldurl = strdup(url);
int size = list_size(server_config.rules);
int size = list_size(rules);
for (int i = 0; i < size; i += 2)
{
char *k, *v;
k = list_at(server_config.rules, i)->value.s;
v = list_at(server_config.rules, i + 1)->value.s;
k = list_at(rules, i)->value.s;
v = list_at(rules, i + 1)->value.s;
// 1 group
if (rule_check(k, v, host, url, query_string, url))
{
@ -777,7 +778,7 @@ void *decode_request_header(void *data)
memset(buf, 0, sizeof(buf));
strcat(buf, url);
LOG("Original query: %s", url);
query = apply_rules(host, buf);
query = apply_rules(rq->client->port_config->rules, host, buf);
LOG("Processed query: %s", query);
dput(rq->request, "RESOURCE_PATH", url_decode(buf));
if (query)

View File

@ -37,6 +37,7 @@ typedef struct {
int usessl;
char* htdocs;
int sock;
list_t rules;
} port_config_t;
typedef struct{
@ -73,7 +74,6 @@ typedef struct {
char *db_path;
//char* htdocs;
char* tmpdir;
list_t rules;
dictionary_t handlers;
int backlog;
int maxcon;

View File

@ -41,7 +41,7 @@ void __init_plugin__(const char* pl,config_t* conf){
__plugin__.name = strdup(pl);
__plugin__.dbpath= conf->db_path;
__plugin__.pdir = conf->plugins_dir;
__plugin__.tmpdir = = sconf->tmpdir;
__plugin__.tmpdir = conf->tmpdir;
__plugin__.raw_body = 0;
init();
};