request body can be decode directly or delegated to plugin

This commit is contained in:
lxsang 2018-10-08 19:32:23 +02:00
parent 6b51621f98
commit 03a0a9deea
6 changed files with 481 additions and 430 deletions

File diff suppressed because it is too large Load Diff

View File

@ -12,8 +12,6 @@
#include "libs/scheduler.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 WS_MAGIC_STRING "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0

23
httpd.c
View File

@ -28,9 +28,9 @@ SSL_CTX *create_context()
ctx = SSL_CTX_new(method);
if (!ctx) {
perror("Unable to create SSL context");
ERR_print_errors_fp(stderr);
exit(EXIT_FAILURE);
perror("Unable to create SSL context");
ERR_print_errors_fp(stderr);
exit(EXIT_FAILURE);
}
return ctx;
@ -145,10 +145,8 @@ int main(int argc, char* argv[])
client_ip = inet_ntoa(client_name.sin_addr);
client->ip = strdup(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_nonblock(client_sock);
@ -163,8 +161,6 @@ int main(int argc, char* argv[])
perror("setsockopt failed\n");
*/
client->sock = client_sock;
// 100 times retry connection before abort
//LOG("Unclosed connection: %d\n", server_config->connection);
#ifdef USE_OPENSSL
client->ssl = NULL;
client->status = 0;
@ -184,17 +180,6 @@ int main(int argc, char* argv[])
#endif
// create callback for the server
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);

View File

@ -24,7 +24,8 @@
#define R_FLOAT(d,k) ((double)atof(dvalue(d,k)))
#define R_PTR(d,k) (dvalue(d,k))
#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
int __attribute__((weak)) usessl();
@ -64,6 +65,19 @@ typedef struct {
char* sslkey;
#endif
}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_block(int socket);
int response(void*, const char*);

View File

@ -11,9 +11,13 @@ void __init_plugin__(const char* pl,config_t* conf){
#ifdef USE_OPENSSL
__plugin__.usessl = conf->usessl;
#endif
__plugin__.raw_body = 0;
init();
};
void use_raw_body()
{
__plugin__.raw_body = 1;
}
#ifdef USE_DB
sqldb __getdb(char *name)
{

View File

@ -7,17 +7,6 @@
#include "ws.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)();
@ -40,4 +29,5 @@ void init();
void destroy();
void* handle(void*);
plugin_header_t* meta();
void use_raw_body();
#endif