1
0
mirror of https://github.com/lxsang/antd-cgi-plugin synced 2024-12-26 18:08:21 +01:00

fix to new api

This commit is contained in:
lxsang 2019-12-15 12:06:09 +01:00
parent f473bf695f
commit 8e1f92d004
2 changed files with 14 additions and 12 deletions

26
cgi.c
View File

@ -2,7 +2,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <antd/plugin.h> #include <antd/plugin.h>
#include "antd/ini.h" #include "antd/ini.h"
dictionary cgi_bin = NULL; dictionary_t cgi_bin = NULL;
static int ini_handle(void *user_data, const char *section, const char *name, static int ini_handle(void *user_data, const char *section, const char *name,
const char *value) const char *value)
@ -44,7 +44,7 @@ void destroy()
freedict(cgi_bin); freedict(cgi_bin);
} }
static void add_vars(list *l, char *k, char *v) static void add_vars(list_t *l, char *k, char *v)
{ {
if (!v || !l || !k) if (!v || !l || !k)
return; return;
@ -59,7 +59,7 @@ static void write_request_body(antd_request_t *rq, int fd)
if (!tmp || EQU(tmp, "GET") || EQU(tmp, "HEAD")) if (!tmp || EQU(tmp, "GET") || EQU(tmp, "HEAD"))
return; return;
int clen = -1; int clen = -1;
dictionary header = (dictionary)dvalue(rq->request, "REQUEST_HEADER"); dictionary_t header = (dictionary_t)dvalue(rq->request, "REQUEST_HEADER");
tmp = (char *)dvalue(header, "Content-Length"); tmp = (char *)dvalue(header, "Content-Length");
if (tmp) if (tmp)
clen = atoi(tmp); clen = atoi(tmp);
@ -93,14 +93,14 @@ static char *get_cgi_bin(antd_request_t *rq)
free(tmp); free(tmp);
return bin; return bin;
} }
static list get_env_vars(antd_request_t *rq) static list_t get_env_vars(antd_request_t *rq)
{ {
char *tmp = NULL; char *tmp = NULL;
char *sub = NULL; char *sub = NULL;
plugin_header_t *__plugin__ = meta(); plugin_header_t *__plugin__ = meta();
dictionary request = (dictionary)rq->request; dictionary_t request = (dictionary_t)rq->request;
dictionary header = (dictionary)dvalue(rq->request, "REQUEST_HEADER"); dictionary_t header = (dictionary_t)dvalue(rq->request, "REQUEST_HEADER");
list env_vars = list_init(); list_t env_vars = list_init();
add_vars(&env_vars, "GATEWAY_INTERFACE", "CGI/1.1"); add_vars(&env_vars, "GATEWAY_INTERFACE", "CGI/1.1");
add_vars(&env_vars, "SERVER_SOFTWARE", SERVER_NAME); add_vars(&env_vars, "SERVER_SOFTWARE", SERVER_NAME);
tmp = (char *)dvalue(request, "REQUEST_QUERY"); tmp = (char *)dvalue(request, "REQUEST_QUERY");
@ -143,7 +143,7 @@ static list get_env_vars(antd_request_t *rq)
add_vars(&env_vars, "SERVER_PORT", (char *)dvalue(header, "SERVER_PORT")); add_vars(&env_vars, "SERVER_PORT", (char *)dvalue(header, "SERVER_PORT"));
add_vars(&env_vars, "SERVER_PROTOCOL", "HTTP/1.1"); add_vars(&env_vars, "SERVER_PROTOCOL", "HTTP/1.1");
// add remaining header to the vars // add remaining header to the vars
association it; chain_t it;
for_each_assoc(it, header) for_each_assoc(it, header)
{ {
tmp = __s("HTTP_%s", it->key); tmp = __s("HTTP_%s", it->key);
@ -189,12 +189,12 @@ void *handle(void *data)
char buf[BUFFLEN]; char buf[BUFFLEN];
int status; int status;
antd_task_t *task = NULL; antd_task_t *task = NULL;
list env_vars = NULL; list_t env_vars = NULL;
char *bin = get_cgi_bin(rq); char *bin = get_cgi_bin(rq);
if (!bin) if (!bin)
{ {
LOG("No cgi bin found\n"); LOG("No cgi bin found\n");
unknow(cl); antd_error(cl,503, "Service unavailable");
task = antd_create_task(NULL, data, NULL,rq->client->last_io); task = antd_create_task(NULL, data, NULL,rq->client->last_io);
task->priority++; task->priority++;
return task; return task;
@ -202,7 +202,7 @@ void *handle(void *data)
env_vars = get_env_vars(rq); env_vars = get_env_vars(rq);
// now exec the cgi bin // now exec the cgi bin
LOG("Execute the cgi bin\n"); LOG("Execute the cgi bin\n");
item np = env_vars; item_t np = env_vars;
int size = list_size(env_vars); int size = list_size(env_vars);
char **envs = (char **)malloc((size + 1) * sizeof(*envs)); char **envs = (char **)malloc((size + 1) * sizeof(*envs));
envs[size] = NULL; envs[size] = NULL;
@ -241,7 +241,9 @@ void *handle(void *data)
// Now, we can write to outpipefd[1] and read from inpipefd[0] : // Now, we can write to outpipefd[1] and read from inpipefd[0] :
write_request_body(rq, outpipefd[1]); write_request_body(rq, outpipefd[1]);
set_status(cl, 200, "OK"); const char* stat_str = get_status_str(200);
__t(cl, "HTTP/1.1 %d %s", 200, stat_str);
//set_status(cl, 200, "OK");
//wpid = 0; //wpid = 0;
//waitpid(pid, &status, 0); // wait for the child finish //waitpid(pid, &status, 0); // wait for the child finish
// WNOHANG // WNOHANG

BIN
dist/cgi-1.0.0b.tar.gz vendored

Binary file not shown.