mirror of
https://github.com/lxsang/ant-http
synced 2024-12-26 00:38:21 +01:00
fix zoombie process & rename plugin handle method
This commit is contained in:
parent
a3b9970c36
commit
6fbf3d4984
2
Makefile
2
Makefile
@ -50,7 +50,7 @@ SERVERLIB= -ldl $(LIB_FLAG) $(DB_LIB) $(SSL_LIB) -lpthread
|
||||
SERVER_O=plugin_manager.o \
|
||||
http_server.o
|
||||
#-lsocket
|
||||
PLUGINS= pluginsman.$(EXT) wterm.$(EXT) nodedaemon.$(EXT) wsimg.$(EXT)
|
||||
PLUGINS= wterm.$(EXT) nodedaemon.$(EXT)
|
||||
|
||||
LIBOBJS = libs/ini.o \
|
||||
libs/handle.o \
|
||||
|
@ -508,7 +508,8 @@ dictionary decode_request(void* client,const char* method, char* url)
|
||||
int ws= 0;
|
||||
char* ws_key = NULL;
|
||||
char buf[BUFFLEN];
|
||||
|
||||
// ip address
|
||||
dput(xheader,"REMOTE_ADDR", (void*)strdup(((antd_client_t*)client)->ip ));
|
||||
//while((line = read_line(client)) && strcmp("\r\n",line))
|
||||
while((read_buf(client,buf,sizeof(buf))) && strcmp("\r\n",buf))
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#define FORM_URL_ENCODE "application/x-www-form-urlencoded"
|
||||
#define FORM_MULTI_PART "multipart/form-data"
|
||||
#define PLUGIN_HANDLER "handler"
|
||||
#define PLUGIN_HANDLER "handle"
|
||||
#define WS_MAGIC_STRING "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
||||
|
||||
|
||||
|
2
httpd.c
2
httpd.c
@ -234,9 +234,11 @@ int main(int argc, char* argv[])
|
||||
/*
|
||||
get the remote IP
|
||||
*/
|
||||
client->ip = NULL;
|
||||
if (client_name.sin_family == AF_INET)
|
||||
{
|
||||
client_ip = inet_ntoa(client_name.sin_addr);
|
||||
client->ip = strdup(client_ip);
|
||||
LOG("Client IP: %s\n", client_ip);
|
||||
}
|
||||
//return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
||||
|
@ -133,6 +133,7 @@ int antd_close(void* src)
|
||||
#endif
|
||||
//printf("Close sock %d\n", source->sock);
|
||||
int ret = close(source->sock);
|
||||
if(source->ip) free(source->ip);
|
||||
server_config.connection--;
|
||||
LOG("Remaining connection %d\n", server_config.connection);
|
||||
free(src);
|
||||
|
@ -51,6 +51,7 @@ typedef struct {
|
||||
typedef struct{
|
||||
int sock;
|
||||
void* ssl;
|
||||
char* ip;
|
||||
} antd_client_t;
|
||||
|
||||
int response(void*, const char*);
|
||||
|
@ -36,6 +36,6 @@ char* route(const char*);
|
||||
char* htdocs(const char*);
|
||||
char* config_dir();
|
||||
/*Default function for plugin*/
|
||||
void handler(void*, const char*,const char*,dictionary);
|
||||
void handle(void*, const char*,const char*,dictionary);
|
||||
void __release();
|
||||
#endif
|
||||
|
@ -1,91 +0,0 @@
|
||||
#include "../plugin.h"
|
||||
#define PEXT "dylib"
|
||||
#define MAXSIZE 500000
|
||||
|
||||
void execute(void* client,const char* method,dictionary rq)
|
||||
{
|
||||
//all plugin file
|
||||
DIR *d;
|
||||
struct dirent *dir;
|
||||
struct stat st;
|
||||
d = opendir(__plugin__.pdir);
|
||||
json(client);
|
||||
__t(client,"{ \"records\":[");
|
||||
int nrec = 0;
|
||||
if (d)
|
||||
{
|
||||
while ((dir = readdir(d)) != NULL)
|
||||
{
|
||||
if(strcmp(dir->d_name,".") == 0 ||
|
||||
strcmp(dir->d_name,"..")==0 || *(dir->d_name)=='.') continue;
|
||||
if( stat(__s("%s%s",__plugin__.pdir,dir->d_name), &st) == 0 )
|
||||
{
|
||||
if(nrec != 0)
|
||||
__t(client,",");
|
||||
__t(client,"{\"name\":\"%s\",\"size\":%d,\"changed\":\"%s\"}",
|
||||
dir->d_name,
|
||||
(int)st.st_size,
|
||||
__time(st.st_mtime)
|
||||
);
|
||||
nrec++;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
__t(client,"], \"total\":%d}",nrec);
|
||||
|
||||
}
|
||||
|
||||
void install(void* c, const char* m, dictionary rq)
|
||||
{
|
||||
char * result = "{\"result\":%d,\"msg\":\"%s\"}";
|
||||
json(c);
|
||||
if(IS_GET(m))
|
||||
{
|
||||
__t(c,result,0,"Bad request:GET");
|
||||
return;
|
||||
}
|
||||
if(R_INT(rq,"test") != NULL)
|
||||
LOG("Test is :%d \n",R_INT(rq,"test"));
|
||||
char * file_name = R_STR(rq,"pfile.file");
|
||||
char* file_ext = R_STR(rq,"pfile.ext");
|
||||
if(file_name == NULL)
|
||||
{
|
||||
__t(c,result,0,"Cannot send file to server");
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcasecmp(file_ext,PEXT) == 0)
|
||||
{
|
||||
int size = R_INT(rq,"pfile.size");
|
||||
if(size>MAXSIZE)
|
||||
{
|
||||
__t(c,result,0,"Cannot accept file more than 500Kb");
|
||||
return;
|
||||
}
|
||||
if(!upload(R_STR(rq,"pfile.tmp"),__s("%s/%s",__plugin__.pdir,file_name)))
|
||||
{
|
||||
__t(c,result,0,"Cannot move file to plugin dir");
|
||||
return;
|
||||
}
|
||||
__t(c,result,1,"OK");
|
||||
return;
|
||||
}
|
||||
|
||||
__t(c,result,0,"This is not a plugin file");
|
||||
}
|
||||
void handler(void* client, const char* method, const char* rqpth, dictionary rq)
|
||||
{
|
||||
if(EQU(rqpth,"default"))
|
||||
{
|
||||
execute(client,method,rq);
|
||||
}
|
||||
else if(EQU(rqpth,"install"))
|
||||
{
|
||||
install(client,method,rq);
|
||||
}
|
||||
else
|
||||
{
|
||||
unknow(client);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../plugin.h"
|
||||
|
||||
void pexit()
|
||||
{
|
||||
|
||||
}
|
||||
void handler(void* cl, const char* m, const char* rqp, dictionary rq)
|
||||
{
|
||||
char* path = NULL;
|
||||
int nimg = 19;
|
||||
ws_msg_header_t* h = NULL;
|
||||
char buff[1024];
|
||||
if(ws_enable(rq))
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
h = ws_read_header(cl);
|
||||
if(h)
|
||||
{
|
||||
if(h->mask == 0)
|
||||
{
|
||||
LOG("%s\n","data is not masked");
|
||||
ws_close(cl, 1012);
|
||||
break;
|
||||
}
|
||||
if(h->opcode == WS_CLOSE)
|
||||
{
|
||||
LOG("%s\n","Websocket: connection closed");
|
||||
ws_close(cl, 1011);
|
||||
break;
|
||||
}
|
||||
else if(h->opcode == WS_TEXT)
|
||||
{
|
||||
int l;
|
||||
if((l = ws_read_data(cl,h,sizeof(buff),buff)) > 0)
|
||||
{
|
||||
|
||||
//path = __s("%s/ws/img%d.jpg",__plugin__.htdocs,buff[0]);
|
||||
LOG("%s : %s\n", "send back data of", buff);
|
||||
//ws_f(cl,path);
|
||||
ws_t(cl,buff);
|
||||
free(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("%s\n","Invalid request");
|
||||
ws_close(cl, 1011);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG("%s\n", "EXIT Streaming..");
|
||||
}
|
@ -13,16 +13,16 @@ void pexit()
|
||||
{
|
||||
|
||||
}
|
||||
void handler(void* cl, const char* m, const char* rqp, dictionary rq)
|
||||
void handle(void* cl, const char* m, const char* rqp, dictionary rq)
|
||||
{
|
||||
ws_msg_header_t* h = NULL;
|
||||
if(ws_enable(rq))
|
||||
{
|
||||
|
||||
int fdm, fds;
|
||||
int rc;
|
||||
int rc, status;
|
||||
char buff[1024];
|
||||
|
||||
pid_t pid;
|
||||
// Check arguments
|
||||
fdm = posix_openpt(O_RDWR);
|
||||
if (fdm < 0)
|
||||
@ -52,7 +52,8 @@ void handler(void* cl, const char* m, const char* rqp, dictionary rq)
|
||||
fds = open(ptsname(fdm), O_RDWR);
|
||||
|
||||
// Create the child process
|
||||
if (fork())
|
||||
pid = fork();
|
||||
if (pid)
|
||||
{
|
||||
fd_set fd_in;
|
||||
|
||||
@ -75,7 +76,7 @@ void handler(void* cl, const char* m, const char* rqp, dictionary rq)
|
||||
case -1 :
|
||||
LOG("Error %d on select()\n", errno);
|
||||
ws_close(cl, 1011);
|
||||
return;
|
||||
goto wait_for_child;
|
||||
|
||||
default :
|
||||
{
|
||||
@ -90,14 +91,14 @@ void handler(void* cl, const char* m, const char* rqp, dictionary rq)
|
||||
LOG("%s\n","Data is not mask");
|
||||
write(fdm, "exit\n", 5);
|
||||
free(h);
|
||||
return;
|
||||
goto wait_for_child;;
|
||||
}
|
||||
if(h->opcode == WS_CLOSE)
|
||||
{
|
||||
LOG("%s\n","Websocket: connection closed");
|
||||
write(fdm, "exit\n", 5);
|
||||
free(h);
|
||||
return;
|
||||
goto wait_for_child;;
|
||||
}
|
||||
else if(h->opcode == WS_TEXT)
|
||||
{
|
||||
@ -183,7 +184,7 @@ void handler(void* cl, const char* m, const char* rqp, dictionary rq)
|
||||
LOG("Error %d on read standard input. Exit now\n", errno);
|
||||
write(fdm, "exit\n", 5);
|
||||
ws_close(cl,1011);
|
||||
return;
|
||||
goto wait_for_child;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,6 +192,8 @@ void handler(void* cl, const char* m, const char* rqp, dictionary rq)
|
||||
}
|
||||
} // End switch
|
||||
} // End while
|
||||
wait_for_child:
|
||||
waitpid(pid, &status, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user