ant-http/lib/handle.h

138 lines
3.0 KiB
C
Raw Normal View History

2017-07-29 22:00:34 +02:00
#ifndef HANDLE_H
#define HANDLE_H
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
2019-11-18 11:13:30 +01:00
#include <errno.h>
2018-02-10 11:22:41 +01:00
//open ssl
#ifdef USE_OPENSSL
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif
2020-01-08 19:17:51 +01:00
#ifdef USE_ZLIB
#include <zlib.h>
#endif
2017-07-29 22:00:34 +02:00
#ifdef USE_DB
#include "dbhelper.h"
#endif
2020-01-08 19:17:51 +01:00
2018-10-07 01:03:05 +02:00
#include <fcntl.h>
2019-12-15 12:10:06 +01:00
#include <stdlib.h>
2017-07-29 22:00:34 +02:00
#include "dictionary.h"
#include "list.h"
#include "ini.h"
#define SERVER_NAME "Antd"
2017-07-29 22:00:34 +02:00
#define IS_POST(method) (strcmp(method,"POST")== 0)
#define IS_GET(method) (strcmp(method,"GET")== 0)
#define R_STR(d,k) ((char*)dvalue(d,k))
#define R_INT(d,k) (atoi(dvalue(d,k)))
#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"
2019-12-21 15:02:33 +01:00
#define MAX_IO_WAIT_TIME 5 // second
2019-12-20 16:49:41 +01:00
2020-01-08 19:17:51 +01:00
typedef enum {ANTD_CGZ, ANTD_CDEFL, ANTD_CNONE} antd_compress_t;
//extern config_t server_config;
2019-12-20 16:49:41 +01:00
typedef struct {
unsigned int port;
int usessl;
char* htdocs;
int sock;
2019-12-22 17:33:35 +01:00
dictionary_t rules;
2019-12-20 16:49:41 +01:00
} port_config_t;
typedef struct{
int sock;
void* ssl;
2018-10-07 01:03:05 +02:00
int status;
2019-07-31 15:11:59 +02:00
time_t last_io;
2020-01-08 19:17:51 +01:00
// compress
antd_compress_t z_level;
void* zstream;
} antd_client_t;
typedef struct {
antd_client_t* client;
2019-12-15 12:10:06 +01:00
dictionary_t request;
} antd_request_t;
2019-12-15 12:10:06 +01:00
typedef struct
{
dictionary_t header;
list_t cookie;
int status;
} antd_response_header_t;
2018-02-10 11:22:41 +01:00
2019-12-20 16:49:41 +01:00
2018-02-10 11:22:41 +01:00
typedef struct {
2019-12-20 16:49:41 +01:00
//int port;
2018-02-10 11:22:41 +01:00
char *plugins_dir;
char *plugins_ext;
char *db_path;
2019-12-20 16:49:41 +01:00
//char* htdocs;
2018-02-10 11:22:41 +01:00
char* tmpdir;
2019-12-15 12:10:06 +01:00
dictionary_t handlers;
2018-02-10 11:22:41 +01:00
int backlog;
2018-03-08 11:39:44 +01:00
int maxcon;
int connection;
int n_workers;
2019-12-22 00:11:26 +01:00
int max_upload_size;
2020-01-08 19:17:51 +01:00
// ssl
2019-12-20 16:49:41 +01:00
int enable_ssl;
2018-02-10 11:22:41 +01:00
char* sslcert;
char* sslkey;
2019-12-15 12:10:06 +01:00
char* ssl_cipher;
2020-01-08 19:17:51 +01:00
int gzip_enable;
list_t gzip_types;
2019-12-15 12:10:06 +01:00
dictionary_t mimes;
2019-12-20 16:49:41 +01:00
dictionary_t ports;
2019-12-12 18:35:00 +01:00
// #endif
2018-02-10 11:22:41 +01:00
}config_t;
typedef struct {
2020-01-08 19:17:51 +01:00
char name[128];
char dbpath[512];
char tmpdir[512];
char pdir[512];
int raw_body;
} plugin_header_t;
2020-01-03 10:14:04 +01:00
int __attribute__((weak)) require_plugin(const char*);
2020-01-08 19:17:51 +01:00
void __attribute__((weak)) htdocs(antd_request_t* rq, char* dest);
void __attribute__((weak)) dbdir(char* dest);
void __attribute__((weak)) tmpdir(char* dest);
void __attribute__((weak)) plugindir(char* dest);
2020-01-03 10:14:04 +01:00
2020-01-08 19:17:51 +01:00
int __attribute__((weak)) compressable(char* ctype);
2020-01-03 10:14:04 +01:00
2018-10-07 01:03:05 +02:00
void set_nonblock(int socket);
2018-10-07 14:20:36 +02:00
//void set_block(int socket);
2019-12-15 12:10:06 +01:00
void antd_send_header(void*,antd_response_header_t*);
const char* get_status_str(int stat);
2018-02-10 11:22:41 +01:00
int __t(void*, const char*,...);
int __b(void*, const unsigned char*, int);
int __f(void*, const char*);
2019-12-15 12:10:06 +01:00
2017-07-29 22:00:34 +02:00
int upload(const char*, const char*);
/*Default function for plugin*/
2019-12-15 12:10:06 +01:00
void antd_error(void* client, int status, const char* msg);
int ws_enable(dictionary_t);
2018-02-10 11:22:41 +01:00
int read_buf(void* sock,char* buf,int i);
2018-05-03 15:10:44 +02:00
int antd_send( void *source, const void* data, int len);
int antd_recv( void *source, void* data, int len);
2018-02-10 11:22:41 +01:00
int antd_close(void* source);
void destroy_request(void *data);
2017-07-29 22:00:34 +02:00
#endif