mirror of
https://github.com/lxsang/ant-http
synced 2024-12-26 16:58:22 +01:00
request body can be decode directly or delegated to plugin
This commit is contained in:
parent
6b51621f98
commit
03a0a9deea
852
http_server.c
852
http_server.c
File diff suppressed because it is too large
Load Diff
@ -12,8 +12,6 @@
|
|||||||
#include "libs/scheduler.h"
|
#include "libs/scheduler.h"
|
||||||
#include "plugin_manager.h"
|
#include "plugin_manager.h"
|
||||||
|
|
||||||
#define FORM_URL_ENCODE "application/x-www-form-urlencoded"
|
|
||||||
#define FORM_MULTI_PART "multipart/form-data"
|
|
||||||
#define PLUGIN_HANDLER "handle"
|
#define PLUGIN_HANDLER "handle"
|
||||||
#define WS_MAGIC_STRING "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
#define WS_MAGIC_STRING "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
||||||
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
|
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
|
||||||
|
23
httpd.c
23
httpd.c
@ -28,9 +28,9 @@ SSL_CTX *create_context()
|
|||||||
|
|
||||||
ctx = SSL_CTX_new(method);
|
ctx = SSL_CTX_new(method);
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
perror("Unable to create SSL context");
|
perror("Unable to create SSL context");
|
||||||
ERR_print_errors_fp(stderr);
|
ERR_print_errors_fp(stderr);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
@ -145,10 +145,8 @@ int main(int argc, char* argv[])
|
|||||||
client_ip = inet_ntoa(client_name.sin_addr);
|
client_ip = inet_ntoa(client_name.sin_addr);
|
||||||
client->ip = strdup(client_ip);
|
client->ip = strdup(client_ip);
|
||||||
LOG("Client IP: %s\n", client_ip);
|
LOG("Client IP: %s\n", client_ip);
|
||||||
LOG("socket: %d\n", client_sock);
|
//LOG("socket: %d\n", client_sock);
|
||||||
}
|
}
|
||||||
//return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
|
||||||
/* accept_request(client_sock); */
|
|
||||||
|
|
||||||
// set timeout to socket
|
// set timeout to socket
|
||||||
set_nonblock(client_sock);
|
set_nonblock(client_sock);
|
||||||
@ -163,8 +161,6 @@ int main(int argc, char* argv[])
|
|||||||
perror("setsockopt failed\n");
|
perror("setsockopt failed\n");
|
||||||
*/
|
*/
|
||||||
client->sock = client_sock;
|
client->sock = client_sock;
|
||||||
// 100 times retry connection before abort
|
|
||||||
//LOG("Unclosed connection: %d\n", server_config->connection);
|
|
||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
client->ssl = NULL;
|
client->ssl = NULL;
|
||||||
client->status = 0;
|
client->status = 0;
|
||||||
@ -184,17 +180,6 @@ int main(int argc, char* argv[])
|
|||||||
#endif
|
#endif
|
||||||
// create callback for the server
|
// create callback for the server
|
||||||
antd_add_task(&scheduler, antd_create_task(accept_request,(void*)request, finish_request ));
|
antd_add_task(&scheduler, antd_create_task(accept_request,(void*)request, finish_request ));
|
||||||
/*if (pthread_create(&newthread , NULL,(void *(*)(void *))accept_request, (void *)client) != 0)
|
|
||||||
{
|
|
||||||
perror("pthread_create");
|
|
||||||
antd_close(client);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//reclaim the stack data when thread finish
|
|
||||||
pthread_detach(newthread) ;
|
|
||||||
}*/
|
|
||||||
//accept_request(&client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(server_sock);
|
close(server_sock);
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
#define R_FLOAT(d,k) ((double)atof(dvalue(d,k)))
|
#define R_FLOAT(d,k) ((double)atof(dvalue(d,k)))
|
||||||
#define R_PTR(d,k) (dvalue(d,k))
|
#define R_PTR(d,k) (dvalue(d,k))
|
||||||
#define __RESULT__ "{\"result\":%d,\"msg\":\"%s\"}"
|
#define __RESULT__ "{\"result\":%d,\"msg\":\"%s\"}"
|
||||||
|
#define FORM_URL_ENCODE "application/x-www-form-urlencoded"
|
||||||
|
#define FORM_MULTI_PART "multipart/form-data"
|
||||||
|
|
||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
int __attribute__((weak)) usessl();
|
int __attribute__((weak)) usessl();
|
||||||
@ -64,6 +65,19 @@ typedef struct {
|
|||||||
char* sslkey;
|
char* sslkey;
|
||||||
#endif
|
#endif
|
||||||
}config_t;
|
}config_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
char *dbpath;
|
||||||
|
char * htdocs;
|
||||||
|
char*pdir;
|
||||||
|
int sport;
|
||||||
|
int raw_body;
|
||||||
|
#ifdef USE_OPENSSL
|
||||||
|
int usessl;
|
||||||
|
#endif
|
||||||
|
} plugin_header_t;
|
||||||
|
|
||||||
void set_nonblock(int socket);
|
void set_nonblock(int socket);
|
||||||
//void set_block(int socket);
|
//void set_block(int socket);
|
||||||
int response(void*, const char*);
|
int response(void*, const char*);
|
||||||
|
@ -11,9 +11,13 @@ void __init_plugin__(const char* pl,config_t* conf){
|
|||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
__plugin__.usessl = conf->usessl;
|
__plugin__.usessl = conf->usessl;
|
||||||
#endif
|
#endif
|
||||||
|
__plugin__.raw_body = 0;
|
||||||
init();
|
init();
|
||||||
};
|
};
|
||||||
|
void use_raw_body()
|
||||||
|
{
|
||||||
|
__plugin__.raw_body = 1;
|
||||||
|
}
|
||||||
#ifdef USE_DB
|
#ifdef USE_DB
|
||||||
sqldb __getdb(char *name)
|
sqldb __getdb(char *name)
|
||||||
{
|
{
|
||||||
|
@ -7,17 +7,6 @@
|
|||||||
#include "ws.h"
|
#include "ws.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *name;
|
|
||||||
char *dbpath;
|
|
||||||
char * htdocs;
|
|
||||||
char*pdir;
|
|
||||||
int sport;
|
|
||||||
#ifdef USE_OPENSSL
|
|
||||||
int usessl;
|
|
||||||
#endif
|
|
||||||
} plugin_header_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//typedef void(*call)();
|
//typedef void(*call)();
|
||||||
@ -40,4 +29,5 @@ void init();
|
|||||||
void destroy();
|
void destroy();
|
||||||
void* handle(void*);
|
void* handle(void*);
|
||||||
plugin_header_t* meta();
|
plugin_header_t* meta();
|
||||||
|
void use_raw_body();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user