3proxy/src/structures.h

872 lines
20 KiB
C
Raw Normal View History

2016-12-20 20:47:02 +08:00
/*
3APA3A simpliest proxy server
(c) 2002-2016 by Vladimir Dubrovin <3proxy@3proxy.ru>
please read License Agreement
*/
2014-04-08 17:03:21 +08:00
#ifndef _STRUCTURES_H_
#define _STRUCTURES_H_
#include <time.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
2018-04-21 00:32:49 +08:00
#include <stdint.h>
2020-10-30 16:17:28 +08:00
#include <inttypes.h>
2014-04-08 17:03:21 +08:00
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _WIN32
#include <sys/socket.h>
#include <netinet/in.h>
2018-04-15 04:52:38 +08:00
#include <netinet/ip.h>
#include <netinet/tcp.h>
2014-04-08 17:03:21 +08:00
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>
#define SASIZETYPE socklen_t
#define SOCKET int
#define INVALID_SOCKET (-1)
#ifdef WITH_LINUX_FUTEX
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/kernel.h>
#include <linux/futex.h>
#define pthread_mutex_t int
#define pthread_mutex_init(x, y) (*(x)=0)
#define pthread_mutex_destroy(x) (*(x)=0)
#define pthread_mutex_lock(x) mutex_lock(x)
#define pthread_mutex_unlock(x) mutex_unlock(x)
int mutex_lock(int *val);
int mutex_unlock(int *val);
#else
#endif
2014-04-08 17:03:21 +08:00
#else
#include <winsock2.h>
#include <Ws2tcpip.h>
2014-04-08 17:03:21 +08:00
#define pthread_mutex_t CRITICAL_SECTION
#define pthread_mutex_init(x, y) InitializeCriticalSection(x)
#define pthread_mutex_lock(x) EnterCriticalSection(x)
#define pthread_mutex_unlock(x) LeaveCriticalSection(x)
#define pthread_mutex_destroy(x) DeleteCriticalSection(x)
#ifdef MSVC
#pragma warning (disable : 4996)
#endif
#ifndef PRIu64
#define PRIu64 "I64u"
#endif
#ifndef PRIi64
#define PRIi64 "I64i"
#endif
#ifndef SCNx64
#define SCNx64 "I64x"
#endif
2014-04-08 17:03:21 +08:00
#endif
#define MAXBANDLIMS 10
#ifdef WITH_POLL
#include <poll.h>
#else
#ifdef WITH_WSAPOLL
#define poll(A,B,C) WSAPoll(A,B,C)
2014-04-08 17:03:21 +08:00
#else
struct mypollfd {
SOCKET fd; /* file descriptor */
short events; /* events to look for */
short revents; /* events returned */
};
#define pollfd mypollfd
int
#ifdef _WIN32
WINAPI
#endif
mypoll(struct mypollfd *fds, unsigned int nfds, int timeout);
#ifndef POLLIN
#define POLLIN 1
#endif
#ifndef POLLOUT
#define POLLOUT 2
#endif
#ifndef POLLPRI
#define POLLPRI 4
#endif
#ifndef POLLERR
#define POLLERR 8
#endif
#ifndef POLLHUP
#define POLLHUP 16
#endif
#ifndef POLLNVAL
#define POLLNVAL 32
#endif
#endif
2014-04-08 17:03:21 +08:00
#endif
2018-04-06 22:45:18 +08:00
#define ALLOW 0
#define DENY 1
#define REDIRECT 2
#define BANDLIM 3
#define NOBANDLIM 4
#define COUNTIN 5
#define NOCOUNTIN 6
#define COUNTOUT 7
#define NOCOUNTOUT 8
#define CONNLIM 9
#define NOCONNLIM 10
2020-10-06 19:29:08 +08:00
#define COUNTALL 11
#define NOCOUNTALL 12
2018-04-06 22:45:18 +08:00
2014-04-08 17:03:21 +08:00
#define CONNECT 0x00000001
#define BIND 0x00000002
#define UDPASSOC 0x00000004
#define ICMPASSOC 0x00000008 /* reserved */
#define HTTP_GET 0x00000100
#define HTTP_PUT 0x00000200
#define HTTP_POST 0x00000400
#define HTTP_HEAD 0x00000800
#define HTTP_CONNECT 0x00001000
#define HTTP_OTHER 0x00008000
#define HTTP 0x0000EF00 /* all except HTTP_CONNECT */
#define HTTPS HTTP_CONNECT
#define FTP_GET 0x00010000
#define FTP_PUT 0x00020000
#define FTP_LIST 0x00040000
#define FTP_DATA 0x00080000
#define FTP 0x000F0000
#define DNSRESOLVE 0x00100000
#define ADMIN 0x01000000
2014-05-11 05:39:02 +08:00
#define SAFAMILY(sa) (&(((struct sockaddr_in *)sa)->sin_family))
#ifndef NOIPV6
#define SAPORT(sa) (((struct sockaddr_in *)sa)->sin_family == AF_INET6? &((struct sockaddr_in6 *)sa)->sin6_port : &((struct sockaddr_in *)sa)->sin_port)
2020-10-30 22:25:27 +08:00
#define SAADDR(sa) (((struct sockaddr_in *)sa)->sin_family == AF_INET6? (char *)&((struct sockaddr_in6 *)sa)->sin6_addr : (char *)&((struct sockaddr_in *)sa)->sin_addr.s_addr)
2014-05-11 05:39:02 +08:00
#define SAADDRLEN(sa) (((struct sockaddr_in *)sa)->sin_family == AF_INET6? 16:4)
#define SASOCK(sa) (((struct sockaddr_in *)sa)->sin_family == AF_INET6? PF_INET6:PF_INET)
#define SASIZE(sa) (((struct sockaddr_in *)sa)->sin_family == AF_INET6? sizeof(struct sockaddr_in6):sizeof(struct sockaddr_in))
2020-10-30 22:25:27 +08:00
#define SAISNULL(sa) (!memcmp(((struct sockaddr_in *)sa)->sin_family == AF_INET6? (char *)&((struct sockaddr_in6 *)sa)->sin6_addr : (char *)&((struct sockaddr_in *)sa)->sin_addr.s_addr, NULLADDR, (((struct sockaddr_in *)sa)->sin_family == AF_INET6? 16:4)))
2014-05-11 05:39:02 +08:00
#else
#define SAPORT(sa) (&((struct sockaddr_in *)sa)->sin_port)
2020-10-30 22:25:27 +08:00
#define SAADDR(sa) ((char *)&((struct sockaddr_in *)sa)->sin_addr.s_addr)
2014-05-11 05:39:02 +08:00
#define SAADDRLEN(sa) (4)
#define SASOCK(sa) (PF_INET)
#define SASIZE(sa) (sizeof(struct sockaddr_in))
#define SAISNULL(sa) (((struct sockaddr_in *)sa)->sin_addr.s_addr == 0)
2014-05-11 05:39:02 +08:00
#endif
extern char* NULLADDR;
2014-04-08 17:03:21 +08:00
typedef enum {
CLIENT,
SERVER
} DIRECTION;
typedef enum {
S_NOSERVICE,
S_PROXY,
S_TCPPM,
S_POP3P,
S_SOCKS4 = 4, /* =4 */
S_SOCKS5 = 5, /* =5 */
S_UDPPM,
S_SOCKS,
S_SOCKS45,
S_ADMIN,
S_DNSPR,
S_FTPPR,
S_SMTPP,
S_REVLI,
S_REVCO,
2014-04-08 17:03:21 +08:00
S_ZOMBIE
}PROXYSERVICE;
struct clientparam;
struct node;
struct symbol;
struct pluginlink;
struct srvparam;
2020-10-14 21:10:35 +08:00
struct LOGFUNC;
2020-10-30 16:17:28 +08:00
struct LOGGER;
2014-04-08 17:03:21 +08:00
typedef int (*AUTHFUNC)(struct clientparam * param);
typedef void * (*REDIRECTFUNC)(struct clientparam * param);
2020-10-30 22:25:27 +08:00
typedef unsigned long (*RESOLVFUNC)(int af, char *name, char *value);
2014-04-08 17:03:21 +08:00
typedef unsigned (*BANDLIMFUNC)(struct clientparam * param, unsigned nbytesin, unsigned nbytesout);
typedef void (*TRAFCOUNTFUNC)(struct clientparam * param);
typedef void * (*EXTENDFUNC) (struct node *node);
typedef void (*CBFUNC)(void *cb, char * buf, int inbuf);
typedef void (*PRINTFUNC) (struct node *node, CBFUNC cbf, void*cb);
#ifdef WIN32
#define PLUGINAPI __declspec(dllexport)
typedef int (__cdecl *PLUGINFUNC) (struct pluginlink *pluginlink, int argc, char** argv);
#define PLUGINCALL __cdecl
#else
#define PLUGINCALL
#define PLUGINAPI
typedef int (*PLUGINFUNC)(struct pluginlink *pluginlink, int argc, char** argv);
#endif
2014-04-08 17:03:21 +08:00
struct auth {
struct auth *next;
AUTHFUNC preauthorize;
2014-04-08 17:03:21 +08:00
AUTHFUNC authenticate;
AUTHFUNC authorize;
char * desc;
};
struct iplist {
struct iplist *next;
int family;
#ifndef NOIPV6
struct in6_addr ip_from;
struct in6_addr ip_to;
#else
struct in_addr ip_from;
struct in_addr ip_to;
#endif
2014-04-08 17:03:21 +08:00
};
struct portlist {
struct portlist * next;
unsigned short startport;
unsigned short endport;
};
struct userlist {
struct userlist * next;
2020-10-30 22:25:27 +08:00
char * user;
2014-04-08 17:03:21 +08:00
};
typedef enum {
SYS,
CL,
CR,
NT,
LM,
UN
}PWTYPE;
struct passwords {
struct passwords *next;
2020-10-30 22:25:27 +08:00
char * user;
char * password;
2014-04-08 17:03:21 +08:00
int pwtype;
};
typedef enum {
R_TCP,
R_CONNECT,
R_SOCKS4,
R_SOCKS5,
R_HTTP,
R_POP3,
R_SMTP,
2014-04-08 17:03:21 +08:00
R_FTP,
R_CONNECTP,
R_SOCKS4P,
R_SOCKS5P,
R_SOCKS4B,
R_SOCKS5B,
R_ADMIN,
R_EXTIP
2014-04-08 17:03:21 +08:00
} REDIRTYPE;
struct chain {
struct chain * next;
int type;
#ifndef NOIPV6
struct sockaddr_in6 addr;
#else
struct sockaddr_in addr;
#endif
2014-04-08 17:03:21 +08:00
unsigned short weight;
2020-10-30 22:25:27 +08:00
char * exthost;
char * extuser;
char * extpass;
2014-04-08 17:03:21 +08:00
};
struct period {
struct period *next;
int fromtime;
int totime;
};
#define MATCHBEGIN 1
#define MATCHEND 2
struct hostname {
struct hostname *next;
2020-10-30 22:25:27 +08:00
char * name;
2014-04-08 17:03:21 +08:00
int matchtype;
};
struct ace {
struct ace *next;
int action;
int operation;
int wdays;
int weight;
int nolog;
struct period *periods;
struct userlist *users;
struct iplist *src, *dst;
struct hostname *dstnames;
struct portlist *ports;
struct chain *chains;
};
struct bandlim {
struct bandlim *next;
struct ace *ace;
time_t basetime;
2014-04-08 17:03:21 +08:00
unsigned nexttime;
unsigned rate;
2014-04-08 17:03:21 +08:00
};
struct connlim {
struct connlim *next;
struct ace *ace;
time_t basetime;
uint64_t rating;
unsigned period;
unsigned rate;
};
2014-04-08 17:03:21 +08:00
typedef enum {NONE, MINUTELY, HOURLY, DAILY, WEEKLY, MONTHLY, ANNUALLY, NEVER} ROTATION;
struct schedule {
struct schedule *next;
ROTATION type;
void *data;
int (*function)(void *);
time_t start_time;
};
struct trafcount {
struct trafcount *next;
struct ace *ace;
unsigned number;
ROTATION type;
uint64_t traf64;
uint64_t traflim64;
2014-04-08 17:03:21 +08:00
char * comment;
int disabled;
time_t cleared;
time_t updated;
};
2020-10-14 21:10:35 +08:00
struct LOGFUNC {
struct LOGFUNC* next;
int (*init)(struct LOGGER *logger);
2020-10-30 22:25:27 +08:00
int (*dobuf)(struct clientparam * param, char * buf, int bufsize, const char *s);
void (*log)(const char * buf, int len, struct LOGGER *logger);
void (*rotate)(struct LOGGER *logger);
2020-10-30 16:17:28 +08:00
void (*flush)(struct LOGGER *logger);
void (*close)(struct LOGGER *logger);
2020-10-14 21:10:35 +08:00
char* prefix;
};
extern struct LOGFUNC *logfuncs;
2020-10-30 16:17:28 +08:00
extern void(*prelog)(struct clientparam * param);
2020-10-14 21:10:35 +08:00
struct LOGGER {
struct LOGGER *next;
2020-10-30 16:17:28 +08:00
struct LOGGER *prev;
2020-10-14 21:10:35 +08:00
char * selector;
void * data;
struct LOGFUNC *logfunc;
int rotate;
time_t rotated;
int registered;
2020-10-14 21:10:35 +08:00
};
struct LOGGER * registerlog(const char * logstring, int logtype);
void unregisterlog (struct LOGGER * log);
2020-10-30 16:17:28 +08:00
void flushlogs(void);
struct nserver {
2014-12-13 08:56:01 +08:00
#ifndef NOIPV6
struct sockaddr_in6 addr;
#else
struct sockaddr_in addr;
#endif
int usetcp;
};
2014-12-13 08:56:01 +08:00
extern int numservers;
2014-04-08 17:03:21 +08:00
typedef void * (* PROXYFUNC)(struct clientparam *);
typedef enum {
PASS,
CONTINUE,
HANDLED,
REJECT,
REMOVE
} FILTER_ACTION;
typedef void* FILTER_OPEN(void * idata, struct srvparam * param);
typedef FILTER_ACTION FILTER_CLIENT(void *fo, struct clientparam * param, void** fc);
typedef FILTER_ACTION FILTER_PREDATA(void *fc, struct clientparam * param);
2020-10-30 22:25:27 +08:00
typedef FILTER_ACTION FILTER_BUFFER(void *fc, struct clientparam * param, char ** buf_p, int * bufsize_p, int offset, int * length_p);
2014-04-08 17:03:21 +08:00
typedef void FILTER_CLOSE(void *fo);
struct filter {
struct filter * next;
char * instance;
void * data;
FILTER_OPEN *filter_open;
FILTER_CLIENT *filter_client;
FILTER_BUFFER *filter_request;
FILTER_BUFFER *filter_header_cli;
FILTER_BUFFER *filter_header_srv;
FILTER_PREDATA *filter_predata;
FILTER_BUFFER *filter_data_cli;
FILTER_BUFFER *filter_data_srv;
FILTER_CLOSE *filter_clear;
FILTER_CLOSE *filter_close;
};
struct filterp {
struct filter *filter;
void *data;
};
#define MAX_FILTERS 16
struct srvparam {
struct srvparam *next;
struct srvparam *prev;
struct clientparam *child;
PROXYSERVICE service;
AUTHFUNC authfunc;
PROXYFUNC pf;
SOCKET srvsock, cbsock;
2014-04-08 17:03:21 +08:00
int childcount;
int maxchild;
2016-03-28 22:49:27 +08:00
int paused, version;
2014-04-08 17:03:21 +08:00
int singlepacket;
int usentlm;
2016-01-15 20:29:57 +08:00
int needuser;
2014-04-08 17:03:21 +08:00
int silent;
int transparent;
int nfilters, nreqfilters, nhdrfilterscli, nhdrfilterssrv, npredatfilters, ndatfilterscli, ndatfilterssrv;
int family;
int stacksize;
2016-04-02 16:43:25 +08:00
int noforce;
int anonymous;
int logtype;
int clisockopts, srvsockopts, lissockopts, cbcsockopts, cbssockopts;
#ifdef WITHSPLICE
int usesplice;
#endif
2014-04-08 17:03:21 +08:00
unsigned bufsize;
unsigned logdumpsrv, logdumpcli;
2014-05-11 05:39:02 +08:00
#ifndef NOIPV6
struct sockaddr_in6 intsa;
struct sockaddr_in6 extsa6;
struct sockaddr_in6 extsa;
2020-10-07 16:21:01 +08:00
struct sockaddr_in6 extNat;
2014-05-11 05:39:02 +08:00
#else
struct sockaddr_in intsa;
struct sockaddr_in extsa;
2020-10-07 16:21:01 +08:00
struct sockaddr_in extNat;
#endif
2014-04-08 17:03:21 +08:00
pthread_mutex_t counter_mutex;
struct pollfd fds;
FILE *stdlog;
2020-10-30 22:25:27 +08:00
char * target;
#ifdef SO_BINDTODEVICE
char * ibindtodevice;
char * obindtodevice;
#endif
2014-04-08 17:03:21 +08:00
struct auth *authenticate;
struct pollfd * srvfds;
struct ace *preacl, *acl;
2014-04-08 17:03:21 +08:00
struct auth *authfuncs;
struct filter *filter;
2020-10-30 22:25:27 +08:00
char * logtarget;
char * logformat;
char * nonprintable;
struct LOGGER *log;
2014-04-08 17:03:21 +08:00
unsigned short targetport;
2020-10-30 22:25:27 +08:00
char replace;
2014-04-08 17:03:21 +08:00
time_t time_start;
};
struct clientparam {
struct clientparam *next,
*prev;
struct srvparam *srv;
REDIRECTFUNC redirectfunc;
BANDLIMFUNC bandlimfunc;
TRAFCOUNTFUNC trafcountfunc;
struct filterp *filters,
**reqfilters,
**hdrfilterscli, **hdrfilterssrv,
**predatfilters, **datfilterscli, **datfilterssrv;
PROXYSERVICE service;
SOCKET clisock,
remsock,
ctrlsock,
ctrlsocksrv;
REDIRTYPE redirtype;
uint64_t waitclient64,
waitserver64,
cycles;
2014-04-08 17:03:21 +08:00
int redirected,
operation,
nfilters, nreqfilters, nhdrfilterscli, nhdrfilterssrv, npredatfilters, ndatfilterscli, ndatfilterssrv,
unsafefilter,
preauthorized,
bandlimver;
2014-04-08 17:03:21 +08:00
int res,
status;
int pwtype,
threadid,
weight,
nolog,
nolongdatfilter,
nooverwritefilter,
transparent,
2016-03-28 22:49:27 +08:00
chunked,
paused,
version;
2014-04-08 17:03:21 +08:00
2020-10-30 22:25:27 +08:00
char *hostname,
2014-04-08 17:03:21 +08:00
*username,
*password,
*extusername,
*extpassword,
*clibuf,
*srvbuf;
unsigned cliinbuf,
srvinbuf,
clioffset,
srvoffset,
clibufsize,
srvbufsize,
msec_start;
uint64_t
maxtrafin64,
maxtrafout64;
#ifndef NOIPV6
struct sockaddr_in6 sincl, sincr, sinsl, sinsr, req;
#else
struct sockaddr_in sincl, sincr, sinsl, sinsr, req;
#endif
2014-04-08 17:03:21 +08:00
uint64_t statscli64,
statssrv64;
unsigned long
2014-04-08 17:03:21 +08:00
nreads,
nwrites,
nconnects;
2014-04-08 17:03:21 +08:00
struct bandlim *bandlims[MAXBANDLIMS],
*bandlimsout[MAXBANDLIMS];
time_t time_start;
};
struct filemon {
char * path;
struct stat sb;
struct filemon *next;
};
struct extparam {
int timeouts[12];
2014-04-08 17:03:21 +08:00
struct ace * acl;
char * conffile;
struct bandlim * bandlimiter, *bandlimiterout;
struct connlim * connlimiter;
2014-04-08 17:03:21 +08:00
struct trafcount * trafcounter;
struct srvparam *services;
int stacksize,
threadinit, counterd, haveerror, rotate, paused, archiverc,
2020-11-03 07:05:18 +08:00
demon, maxchild, needreload, timetoexit, version, noforce, bandlimver;
2014-04-08 17:03:21 +08:00
int authcachetype, authcachetime;
int filtermaxsize;
2020-10-30 22:25:27 +08:00
char **archiver;
2014-04-08 17:03:21 +08:00
ROTATION logtype, countertype;
char * counterfile;
2014-05-11 05:39:02 +08:00
#ifndef NOIPV6
struct sockaddr_in6 intsa;
struct sockaddr_in6 extsa6;
struct sockaddr_in6 extsa;
2014-05-11 05:39:02 +08:00
#else
struct sockaddr_in intsa;
struct sockaddr_in extsa;
#endif
2014-04-08 17:03:21 +08:00
struct passwords *pwl;
struct auth * authenticate;
AUTHFUNC authfunc;
BANDLIMFUNC bandlimfunc;
TRAFCOUNTFUNC trafcountfunc;
2020-10-30 19:51:07 +08:00
void (*prelog)(struct clientparam * param);
2020-10-30 22:25:27 +08:00
char *logtarget, *logformat;
2014-04-08 17:03:21 +08:00
struct filemon * fmon;
struct filter * filters;
struct auth *authfuncs;
char* demanddialprog;
2020-10-30 22:25:27 +08:00
char **stringtable;
time_t time;
2014-04-08 17:03:21 +08:00
unsigned logdumpsrv, logdumpcli;
char delimchar;
};
struct property {
struct property * next;
char * name;
EXTENDFUNC e_f;
int type;
char * description;
};
struct datatype {
char * type;
EXTENDFUNC i_f;
PRINTFUNC p_f;
struct property * properties;
};
struct node {
void * value;
void * iteration;
struct node * parent;
int type;
};
struct dictionary {
char * name;
struct node * node;
EXTENDFUNC array_f;
int arraysize;
};
struct commands {
struct commands *next;
char * command;
2020-10-30 22:25:27 +08:00
int (* handler)(int argc, char ** argv);
2014-04-08 17:03:21 +08:00
int minargs;
int maxargs;
};
struct symbol {
struct symbol *next;
char * name;
void * value;
};
struct proxydef {
PROXYFUNC pf;
unsigned short port;
int isudp;
int service;
char * helpmessage;
};
extern struct proxydef childdef;
struct child {
int argc;
2020-10-30 22:25:27 +08:00
char **argv;
2014-04-08 17:03:21 +08:00
};
2014-04-15 03:58:11 +08:00
struct hashentry {
2020-10-30 22:25:27 +08:00
char hash[sizeof(unsigned)*4];
2014-04-15 03:58:11 +08:00
time_t expires;
struct hashentry *next;
char value[4];
2014-04-15 03:58:11 +08:00
};
struct hashtable {
unsigned hashsize;
unsigned recsize;
2014-12-14 05:46:03 +08:00
unsigned rnd[4];
2014-04-15 03:58:11 +08:00
struct hashentry ** hashtable;
void * hashvalues;
2014-04-15 03:58:11 +08:00
struct hashentry * hashempty;
};
extern struct hashtable dns_table;
2014-12-14 05:46:03 +08:00
extern struct hashtable dns6_table;
2014-04-15 03:58:11 +08:00
2014-04-08 17:03:21 +08:00
struct sockfuncs {
#ifdef _WIN32
SOCKET (WINAPI *_socket)(int domain, int type, int protocol);
SOCKET (WINAPI *_accept)(SOCKET s, struct sockaddr * addr, int * addrlen);
int (WINAPI *_bind)(SOCKET s, const struct sockaddr *addr, int addrlen);
int (WINAPI *_listen)(SOCKET s, int backlog);
int (WINAPI *_connect)(SOCKET s, const struct sockaddr *name, int namelen);
int (WINAPI *_getpeername)(SOCKET s, struct sockaddr * name, int * namelen);
int (WINAPI *_getsockname)(SOCKET s, struct sockaddr * name, int * namelen);
2016-02-16 20:29:51 +08:00
int (WINAPI *_getsockopt)(SOCKET s, int level, int optname, char * optval, int * optlen);
int (WINAPI *_setsockopt)(SOCKET s, int level, int optname, const char *optval, int optlen);
2014-04-08 17:03:21 +08:00
int (WINAPI *_poll)(struct pollfd *fds, unsigned int nfds, int timeout);
2016-02-16 20:29:51 +08:00
int (WINAPI *_send)(SOCKET s, const char *msg, int len, int flags);
int (WINAPI *_sendto)(SOCKET s, const char *msg, int len, int flags, const struct sockaddr *to, int tolen);
int (WINAPI *_recv)(SOCKET s, char *buf, int len, int flags);
int (WINAPI *_recvfrom)(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen);
2014-04-08 17:03:21 +08:00
int (WINAPI *_shutdown)(SOCKET s, int how);
int (WINAPI *_closesocket)(SOCKET s);
#else
SOCKET (*_socket)(int domain, int type, int protocol);
SOCKET (*_accept)(SOCKET s, struct sockaddr * addr, socklen_t * addrlen);
int (*_bind)(SOCKET s, const struct sockaddr *addr, socklen_t addrlen);
int (*_listen)(SOCKET s, int backlog);
int (*_connect)(SOCKET s, const struct sockaddr *name, socklen_t namelen);
int (*_getpeername)(SOCKET s, struct sockaddr * name, socklen_t * namelen);
int (*_getsockname)(SOCKET s, struct sockaddr * name, socklen_t * namelen);
int (*_getsockopt)(SOCKET s, int level, int optname, void * optval, socklen_t * optlen);
int (*_setsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen);
int (*_poll)(struct pollfd *fds, unsigned int nfds, int timeout);
size_t (*_send)(SOCKET s, const void *msg, size_t len, int flags);
size_t (*_sendto)(SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, SASIZETYPE tolen);
size_t (*_recv)(SOCKET s, void *buf, size_t len, int flags);
size_t (*_recvfrom)(SOCKET s, void * buf, size_t len, int flags, struct sockaddr * from, SASIZETYPE * fromlen);
int (*_shutdown)(SOCKET s, int how);
int (*_closesocket)(SOCKET s);
#endif
};
extern struct sockfuncs so;
struct pluginlink {
struct symbol symbols;
struct extparam *conf;
struct nserver *nservers;
2014-04-08 17:03:21 +08:00
int * linenum;
struct auth *authfuncs;
struct commands * commandhandlers;
void * (*findbyname)(const char *name);
2020-10-30 22:25:27 +08:00
int (*socksend)(SOCKET sock, char * buf, int bufsize, int to);
int (*socksendto)(SOCKET sock, struct sockaddr * sin, char * buf, int bufsize, int to);
int (*sockrecvfrom)(SOCKET sock, struct sockaddr * sin, char * buf, int bufsize, int to);
2014-04-08 17:03:21 +08:00
int (*sockgetcharcli)(struct clientparam * param, int timeosec, int timeousec);
int (*sockgetcharsrv)(struct clientparam * param, int timeosec, int timeousec);
2020-10-30 22:25:27 +08:00
int (*sockgetlinebuf)(struct clientparam * param, DIRECTION which, char * buf, int bufsize, int delim, int to);
2014-06-11 05:26:07 +08:00
int (*myinet_ntop)(int af, void *src, char *dst, socklen_t size);
2020-10-30 22:25:27 +08:00
int (*dobuf)(struct clientparam * param, char * buf, int bufsize, const char *s, const char * doublec);
int (*dobuf2)(struct clientparam * param, char * buf, int bufsize, const char *s, const char * doublec, struct tm* tm, char * format);
int (*scanaddr)(const char *s, unsigned long * ip, unsigned long * mask);
unsigned long (*getip46)(int family, char *name, struct sockaddr *sa);
int (*sockmap)(struct clientparam * param, int timeo, int usesplice);
2014-04-08 17:03:21 +08:00
int (*ACLMatches)(struct ace* acentry, struct clientparam * param);
int (*alwaysauth)(struct clientparam * param);
int (*checkACL)(struct clientparam * param);
int (*checkpreACL)(struct clientparam * param);
2020-10-30 22:25:27 +08:00
void (*nametohash)(const char * name, char *hash);
unsigned (*hashindex)(const char* hash);
char* (*en64)(const char *in, char *out, int inlen);
int (*de64)(const char *in, char *out, int maxlen);
void (*tohex)(char *in, char *out, int len);
void (*fromhex)(char *in, char *out, int len);
void (*decodeurl)(char *s, int allowcr);
int (*parsestr) (char *str, char **argm, int nitems, char ** buff, int *inbuf, int *bufsize);
struct ace * (*make_ace) (int argc, char ** argv);
2019-09-04 01:46:47 +08:00
void * (*mallocfunc)(size_t size);
void (*freefunc)(void *ptr);
void *(*reallocfunc)(void *ptr, size_t size);
char * (*strdupfunc)(const char *str);
2014-04-08 17:03:21 +08:00
TRAFCOUNTFUNC trafcountfunc;
char ** proxy_table;
struct schedule ** schedule;
void (*freeacl)(struct ace*);
char ** admin_table;
struct proxydef * childdef;
int (*start_proxy_thread)(struct child * chp);
void (*freeparam)(struct clientparam * param);
int (*parsehostname)(char *hostname, struct clientparam *param, unsigned short port);
int (*parseusername)(char *username, struct clientparam *param, int extpasswd);
int (*parseconnusername)(char *username, struct clientparam *param, int extpasswd, unsigned short port);
struct sockfuncs *so;
2020-10-30 22:25:27 +08:00
char * (*dologname) (char *buf, int bufsize, char *name, const char *ext, ROTATION lt, time_t t);
2014-04-08 17:03:21 +08:00
};
struct counter_header {
2020-10-30 22:25:27 +08:00
char sig[4];
time_t updated;
};
struct counter_record {
uint64_t traf64;
time_t cleared;
time_t updated;
};
2014-04-08 17:03:21 +08:00
extern struct pluginlink pluginlink;
extern char *rotations[];
typedef enum {
SINGLEBYTE_S,
SINGLEBYTE_L,
STRING_S,
STRING_L,
CONNECTION_S,
CONNECTION_L,
DNS_TO,
CHAIN_TO,
CONNECT_TO,
CONNBACK_TO
2014-04-08 17:03:21 +08:00
}TIMEOUT;
typedef enum {
TYPE_INTEGER,
TYPE_SHORT,
TYPE_CHAR,
TYPE_UNSIGNED,
TYPE_UNSIGNED64,
2014-04-08 17:03:21 +08:00
TYPE_TRAFFIC,
TYPE_PORT,
TYPE_IP,
TYPE_SA,
2014-04-08 17:03:21 +08:00
TYPE_CIDR,
TYPE_STRING,
TYPE_DATETIME,
TYPE_OPERATIONS,
TYPE_ROTATION,
TYPE_PORTLIST,
TYPE_IPLIST,
TYPE_USERLIST,
TYPE_PWLIST,
TYPE_CHAIN,
TYPE_ACE,
TYPE_BANDLIMIT,
TYPE_TRAFCOUNTER,
TYPE_CLIENT,
TYPE_WEEKDAYS,
TYPE_TIME,
TYPE_PERIOD,
TYPE_SERVER
}DATA_TYPE;
#ifdef __cplusplus
}
#endif
#endif