mirror of
https://github.com/lxsang/antd-cgi-plugin
synced 2024-12-27 10:28:22 +01:00
fix
This commit is contained in:
parent
7a50a09944
commit
085127338f
30
cgi.c
30
cgi.c
@ -14,7 +14,7 @@ static int ini_handle(void *user_data, const char *section, const char *name,
|
|||||||
if (EQU(section, "CGI"))
|
if (EQU(section, "CGI"))
|
||||||
{
|
{
|
||||||
dput(cgi_bin, name, strdup(value));
|
dput(cgi_bin, name, strdup(value));
|
||||||
LOG("put %s for %s\n", value, name);
|
LOG("put %s for %s", value, name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -32,11 +32,11 @@ void init()
|
|||||||
// read ini file
|
// read ini file
|
||||||
if (ini_parse(file, ini_handle, NULL) < 0)
|
if (ini_parse(file, ini_handle, NULL) < 0)
|
||||||
{
|
{
|
||||||
LOG("Can't load '%s'\n", file);
|
ERROR("Can't load '%s'", file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG("CGI config loaded\n");
|
LOG("CGI config loaded");
|
||||||
}
|
}
|
||||||
free(cnf);
|
free(cnf);
|
||||||
free(file);
|
free(file);
|
||||||
@ -91,7 +91,7 @@ static char *get_cgi_bin(antd_request_t *rq)
|
|||||||
if (!tmp)
|
if (!tmp)
|
||||||
return NULL;
|
return NULL;
|
||||||
char *bin = (char *)dvalue(cgi_bin, tmp);
|
char *bin = (char *)dvalue(cgi_bin, tmp);
|
||||||
LOG("CGI CMD: %s\n", bin);
|
LOG("CGI CMD: %s", bin);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
return bin;
|
return bin;
|
||||||
}
|
}
|
||||||
@ -208,8 +208,13 @@ int read_line(int fn, char*buf,int size)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if(i == 0)
|
||||||
|
i = n;
|
||||||
c = '\n';
|
c = '\n';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(i >= 0)
|
||||||
buf[i] = '\0';
|
buf[i] = '\0';
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -290,7 +295,15 @@ void *handle(void *data)
|
|||||||
while ( waitpid(pid, &status, WNOHANG) == 0)
|
while ( waitpid(pid, &status, WNOHANG) == 0)
|
||||||
{
|
{
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
ssize_t count = read(inpipefd[0], buf, BUFFLEN - 1);
|
ssize_t count;
|
||||||
|
if(beg)
|
||||||
|
{
|
||||||
|
count = read_line(inpipefd[0], buf, BUFFLEN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count = read(inpipefd[0], buf, BUFFLEN);
|
||||||
|
}
|
||||||
if (count == -1)
|
if (count == -1)
|
||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
@ -312,6 +325,11 @@ void *handle(void *data)
|
|||||||
sub = buf;
|
sub = buf;
|
||||||
if(beg)
|
if(beg)
|
||||||
{
|
{
|
||||||
|
if(!regex_match("^[a-zA-Z0-9\\-]+\\s*:\\s*.*$",buf,0,NULL))
|
||||||
|
{
|
||||||
|
LOG("<CGI invalid header> %s", buf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(regex_match("\\s*Status\\s*:\\s+([0-9]{3}\\s+[a-zA-Z0-9 ]*)",buf,2,matches))
|
if(regex_match("\\s*Status\\s*:\\s+([0-9]{3}\\s+[a-zA-Z0-9 ]*)",buf,2,matches))
|
||||||
{
|
{
|
||||||
memcpy(statusbuf, buf + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
|
memcpy(statusbuf, buf + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
|
||||||
@ -326,13 +344,11 @@ void *handle(void *data)
|
|||||||
beg = 0;
|
beg = 0;
|
||||||
}
|
}
|
||||||
antd_send(cl, sub, count);
|
antd_send(cl, sub, count);
|
||||||
//printf("sent: %d with count: %d\n", sent, count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//kill(pid, SIGKILL);
|
//kill(pid, SIGKILL);
|
||||||
//waitpid(pid, &status, 0);
|
//waitpid(pid, &status, 0);
|
||||||
//printf("End cgi\n");
|
//printf("End cgi\n");
|
||||||
free(envs);
|
|
||||||
list_free(&env_vars);
|
list_free(&env_vars);
|
||||||
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++;
|
||||||
|
BIN
dist/cgi-1.0.0b.tar.gz
vendored
BIN
dist/cgi-1.0.0b.tar.gz
vendored
Binary file not shown.
Loading…
Reference in New Issue
Block a user