1 /*
2    3APA3A simpliest proxy server
3    (c) 2002-2016 by Vladimir Dubrovin <3proxy@3proxy.ru>
4 
5    please read License Agreement
6 
7 */
8 
9 #ifndef _STRUCTURES_H_
10 #define _STRUCTURES_H_
11 
12 #include <time.h>
13 #include <stdio.h>
14 #include <fcntl.h>
15 #include <stdint.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <stdint.h>
19 #ifndef PRINTF_INT64_MODIFIER
20 #define PRINTF_INT64_MODIFIER "ll"
21 #endif
22 #ifdef  __cplusplus
23 extern "C" {
24 #endif
25 
26 
27 #ifndef _WIN32
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30 #include <netinet/ip.h>
31 #include <netinet/tcp.h>
32 #include <arpa/inet.h>
33 #include <netdb.h>
34 #include <pthread.h>
35 #define SASIZETYPE socklen_t
36 #define SOCKET int
37 #define INVALID_SOCKET  (-1)
38 #ifdef WITH_LINUX_FUTEX
39 #define _GNU_SOURCE
40 #include <unistd.h>
41 #include <sys/syscall.h>
42 #include <linux/kernel.h>
43 #include <linux/futex.h>
44 #define pthread_mutex_t int
45 #define pthread_mutex_init(x, y) (*(x)=0)
46 #define pthread_mutex_destroy(x) (*(x)=0)
47 #define pthread_mutex_lock(x) mutex_lock(x)
48 #define pthread_mutex_unlock(x) mutex_unlock(x)
49 int mutex_lock(int *val);
50 int mutex_unlock(int *val);
51 #else
52 #endif
53 #else
54 #include <winsock2.h>
55 #include <Ws2tcpip.h>
56 #define pthread_mutex_t CRITICAL_SECTION
57 #define pthread_mutex_init(x, y) InitializeCriticalSection(x)
58 #define pthread_mutex_lock(x) EnterCriticalSection(x)
59 #define pthread_mutex_unlock(x) LeaveCriticalSection(x)
60 #define pthread_mutex_destroy(x) DeleteCriticalSection(x)
61 #ifdef MSVC
62 #pragma warning (disable : 4996)
63 #endif
64 #endif
65 #define MAXBANDLIMS 10
66 
67 #ifdef WITH_POLL
68 #include <poll.h>
69 #else
70 #ifdef WITH_WSAPOLL
71 
72 #define poll(A,B,C) WSAPoll(A,B,C)
73 
74 #else
75 struct mypollfd {
76  SOCKET    fd;       /* file descriptor */
77  short  events;   /* events to look for */
78  short  revents;  /* events returned */
79 };
80 #define pollfd mypollfd
81 int
82 #ifdef _WIN32
83   WINAPI
84 #endif
85    mypoll(struct mypollfd *fds, unsigned int nfds, int timeout);
86 #ifndef POLLIN
87 #define POLLIN 1
88 #endif
89 #ifndef POLLOUT
90 #define POLLOUT 2
91 #endif
92 #ifndef POLLPRI
93 #define POLLPRI 4
94 #endif
95 #ifndef POLLERR
96 #define POLLERR 8
97 #endif
98 #ifndef POLLHUP
99 #define POLLHUP 16
100 #endif
101 #ifndef POLLNVAL
102 #define POLLNVAL 32
103 #endif
104 #endif
105 #endif
106 
107 
108 #define ALLOW		0
109 #define DENY		1
110 #define REDIRECT	2
111 #define BANDLIM		3
112 #define NOBANDLIM	4
113 #define COUNTIN		5
114 #define NOCOUNTIN	6
115 #define COUNTOUT	7
116 #define NOCOUNTOUT	8
117 #define CONNLIM		9
118 #define NOCONNLIM	10
119 #define COUNTALL	11
120 #define NOCOUNTALL	12
121 
122 #define CONNECT 	0x00000001
123 #define BIND		0x00000002
124 #define UDPASSOC	0x00000004
125 #define ICMPASSOC	0x00000008	/* reserved */
126 #define HTTP_GET	0x00000100
127 #define HTTP_PUT	0x00000200
128 #define HTTP_POST	0x00000400
129 #define HTTP_HEAD	0x00000800
130 #define HTTP_CONNECT	0x00001000
131 #define HTTP_OTHER	0x00008000
132 #define HTTP		0x0000EF00	/* all except HTTP_CONNECT */
133 #define HTTPS		HTTP_CONNECT
134 #define FTP_GET		0x00010000
135 #define FTP_PUT		0x00020000
136 #define FTP_LIST	0x00040000
137 #define FTP_DATA	0x00080000
138 #define FTP		0x000F0000
139 #define DNSRESOLVE	0x00100000
140 #define ADMIN		0x01000000
141 
142 
143 #define SAFAMILY(sa) (&(((struct sockaddr_in *)sa)->sin_family))
144 
145 #ifndef NOIPV6
146 #define SAPORT(sa)  (((struct sockaddr_in *)sa)->sin_family == AF_INET6? &((struct sockaddr_in6 *)sa)->sin6_port : &((struct sockaddr_in *)sa)->sin_port)
147 #define SAADDR(sa)  (((struct sockaddr_in *)sa)->sin_family == AF_INET6? (unsigned char *)&((struct sockaddr_in6 *)sa)->sin6_addr : (unsigned char *)&((struct sockaddr_in *)sa)->sin_addr.s_addr)
148 #define SAADDRLEN(sa) (((struct sockaddr_in *)sa)->sin_family == AF_INET6? 16:4)
149 #define SASOCK(sa) (((struct sockaddr_in *)sa)->sin_family == AF_INET6? PF_INET6:PF_INET)
150 #define SASIZE(sa) (((struct sockaddr_in *)sa)->sin_family == AF_INET6? sizeof(struct sockaddr_in6):sizeof(struct sockaddr_in))
151 #define SAISNULL(sa) (!memcmp(((struct sockaddr_in *)sa)->sin_family == AF_INET6? (unsigned char *)&((struct sockaddr_in6 *)sa)->sin6_addr : (unsigned char *)&((struct sockaddr_in *)sa)->sin_addr.s_addr, NULLADDR,  (((struct sockaddr_in *)sa)->sin_family == AF_INET6? 16:4)))
152 #else
153 #define SAPORT(sa)  (&((struct sockaddr_in *)sa)->sin_port)
154 #define SAADDR(sa)  ((unsigned char *)&((struct sockaddr_in *)sa)->sin_addr.s_addr)
155 #define SAADDRLEN(sa) (4)
156 #define SASOCK(sa) (PF_INET)
157 #define SASIZE(sa) (sizeof(struct sockaddr_in))
158 #define SAISNULL(sa) (((struct sockaddr_in *)sa)->sin_addr.s_addr == 0)
159 #endif
160 
161 extern char* NULLADDR;
162 typedef enum {
163 	CLIENT,
164 	SERVER
165 } DIRECTION;
166 
167 
168 typedef enum {
169 	S_NOSERVICE,
170 	S_PROXY,
171 	S_TCPPM,
172 	S_POP3P,
173 	S_SOCKS4 = 4,	/* =4 */
174 	S_SOCKS5 = 5,	/* =5 */
175 	S_UDPPM,
176 	S_SOCKS,
177 	S_SOCKS45,
178 	S_ADMIN,
179 	S_DNSPR,
180 	S_FTPPR,
181 	S_SMTPP,
182 	S_REVLI,
183 	S_REVCO,
184 	S_ZOMBIE
185 }PROXYSERVICE;
186 
187 struct clientparam;
188 struct node;
189 struct symbol;
190 struct pluginlink;
191 struct srvparam;
192 
193 typedef void (*LOGFUNC)(struct clientparam * param, const unsigned char *);
194 typedef int (*AUTHFUNC)(struct clientparam * param);
195 typedef void * (*REDIRECTFUNC)(struct clientparam * param);
196 typedef unsigned long (*RESOLVFUNC)(int af, unsigned char *name, unsigned char *value);
197 typedef unsigned (*BANDLIMFUNC)(struct clientparam * param, unsigned nbytesin, unsigned nbytesout);
198 typedef void (*TRAFCOUNTFUNC)(struct clientparam * param);
199 typedef void * (*EXTENDFUNC) (struct node *node);
200 typedef void (*CBFUNC)(void *cb, char * buf, int inbuf);
201 typedef void (*PRINTFUNC) (struct node *node, CBFUNC cbf, void*cb);
202 
203 #ifdef WIN32
204 
205 #define PLUGINAPI __declspec(dllexport)
206 typedef int (__cdecl *PLUGINFUNC) (struct pluginlink *pluginlink, int argc, char** argv);
207 #define PLUGINCALL __cdecl
208 
209 #else
210 
211 #define PLUGINCALL
212 #define PLUGINAPI
213 typedef int (*PLUGINFUNC)(struct pluginlink *pluginlink, int argc, char** argv);
214 
215 #endif
216 
217 
218 struct auth {
219 	struct auth *next;
220 	AUTHFUNC authenticate;
221 	AUTHFUNC authorize;
222 	char * desc;
223 };
224 
225 struct iplist {
226 	struct iplist *next;
227 	int family;
228 #ifndef NOIPV6
229 	struct in6_addr ip_from;
230 	struct in6_addr ip_to;
231 #else
232 	struct in_addr ip_from;
233 	struct in_addr ip_to;
234 #endif
235 };
236 
237 struct portlist {
238 	struct portlist * next;
239 	unsigned short startport;
240 	unsigned short endport;
241 };
242 
243 struct userlist {
244 	struct userlist * next;
245 	unsigned char * user;
246 };
247 
248 typedef enum {
249 	SYS,
250 	CL,
251 	CR,
252 	NT,
253 	LM,
254 	UN
255 }PWTYPE;
256 
257 struct passwords {
258 	struct passwords *next;
259 	unsigned char * user;
260 	unsigned char * password;
261 	int pwtype;
262 };
263 
264 typedef enum {
265 	R_TCP,
266 	R_CONNECT,
267 	R_SOCKS4,
268 	R_SOCKS5,
269 	R_HTTP,
270 	R_POP3,
271 	R_SMTP,
272 	R_FTP,
273 	R_CONNECTP,
274 	R_SOCKS4P,
275 	R_SOCKS5P,
276 	R_SOCKS4B,
277 	R_SOCKS5B,
278 	R_ADMIN,
279 	R_EXTIP
280 } REDIRTYPE;
281 
282 struct chain {
283 	struct chain * next;
284 	int type;
285 #ifndef NOIPV6
286 	struct sockaddr_in6 addr;
287 #else
288 	struct sockaddr_in addr;
289 #endif
290 	unsigned char * exthost;
291 	unsigned char * extuser;
292 	unsigned char * extpass;
293 	unsigned short weight;
294 	unsigned short cidr;
295 };
296 
297 struct period {
298 	struct period *next;
299 	int fromtime;
300 	int totime;
301 };
302 
303 #define MATCHBEGIN 1
304 #define MATCHEND 2
305 
306 struct hostname {
307 	struct hostname *next;
308 	unsigned char * name;
309 	int matchtype;
310 };
311 
312 struct ace {
313 	struct ace *next;
314 	int action;
315 	int operation;
316 	int wdays;
317 	int weight;
318 	int nolog;
319 	struct period *periods;
320 	struct userlist *users;
321 	struct iplist *src, *dst;
322 	struct hostname *dstnames;
323 	struct portlist *ports;
324 	struct chain *chains;
325 };
326 
327 struct bandlim {
328 	struct bandlim *next;
329 	struct ace *ace;
330 	time_t basetime;
331 	unsigned nexttime;
332 	unsigned rate;
333 };
334 
335 struct connlim {
336 	struct connlim *next;
337 	struct ace *ace;
338 	time_t basetime;
339 	uint64_t rating;
340 	unsigned period;
341 	unsigned rate;
342 };
343 
344 
345 typedef enum {NONE, MINUTELY, HOURLY, DAILY, WEEKLY, MONTHLY, ANNUALLY, NEVER} ROTATION;
346 
347 struct schedule {
348 	struct schedule *next;
349 	ROTATION type;
350 	void *data;
351 	int (*function)(void *);
352 	time_t start_time;
353 };
354 
355 
356 struct trafcount {
357 	struct trafcount *next;
358 	struct ace *ace;
359 	unsigned number;
360 	ROTATION type;
361 	uint64_t traf64;
362 	uint64_t traflim64;
363 	char * comment;
364 	int disabled;
365 	time_t cleared;
366 	time_t updated;
367 };
368 
369 struct nserver {
370 #ifndef NOIPV6
371 	struct sockaddr_in6 addr;
372 #else
373 	struct sockaddr_in addr;
374 #endif
375 	int usetcp;
376 };
377 extern int numservers;
378 
379 typedef void * (* PROXYFUNC)(struct clientparam *);
380 
381 typedef enum {
382 	PASS,
383 	CONTINUE,
384 	HANDLED,
385 	REJECT,
386 	REMOVE
387 } FILTER_ACTION;
388 
389 typedef	void*	 	FILTER_OPEN(void * idata, struct srvparam * param);
390 typedef	FILTER_ACTION 	FILTER_CLIENT(void *fo, struct clientparam * param, void** fc);
391 typedef	FILTER_ACTION	FILTER_PREDATA(void *fc, struct clientparam * param);
392 typedef	FILTER_ACTION	FILTER_BUFFER(void *fc, struct clientparam * param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p);
393 typedef	void		FILTER_CLOSE(void *fo);
394 
395 struct filter {
396 	struct filter * next;
397 	char * instance;
398 	void * data;
399 	FILTER_OPEN *filter_open;
400 	FILTER_CLIENT *filter_client;
401 	FILTER_BUFFER *filter_request;
402 	FILTER_BUFFER *filter_header_cli;
403 	FILTER_BUFFER *filter_header_srv;
404 	FILTER_PREDATA *filter_predata;
405 	FILTER_BUFFER *filter_data_cli;
406 	FILTER_BUFFER *filter_data_srv;
407 	FILTER_CLOSE *filter_clear;
408 	FILTER_CLOSE *filter_close;
409 };
410 
411 struct filterp {
412 	struct filter *filter;
413 	void *data;
414 };
415 
416 #define MAX_FILTERS 16
417 
418 struct srvparam {
419 	struct srvparam *next;
420 	struct srvparam *prev;
421 	struct clientparam *child;
422 	PROXYSERVICE service;
423 	LOGFUNC logfunc;
424 	AUTHFUNC authfunc;
425 	PROXYFUNC pf;
426 	SOCKET srvsock, cbsock;
427 	int childcount;
428 	int maxchild;
429 	int paused, version;
430 	int singlepacket;
431 	int usentlm;
432 	int needuser;
433 	int silent;
434 	int transparent;
435 	int nfilters, nreqfilters, nhdrfilterscli, nhdrfilterssrv, npredatfilters, ndatfilterscli, ndatfilterssrv;
436 	int family;
437 	int stacksize;
438 	int noforce;
439 	int anonymous;
440 	int clisockopts, srvsockopts, lissockopts, cbcsockopts, cbssockopts;
441 #ifdef WITHSPLICE
442 	int usesplice;
443 #endif
444 	unsigned bufsize;
445 	unsigned logdumpsrv, logdumpcli;
446 #ifndef NOIPV6
447 	struct sockaddr_in6 intsa;
448 	struct sockaddr_in6 extsa6;
449 	struct sockaddr_in6 extsa;
450 	struct sockaddr_in6 extNat;
451 #else
452 	struct sockaddr_in intsa;
453 	struct sockaddr_in extsa;
454 	struct sockaddr_in extNat;
455 #endif
456 	pthread_mutex_t counter_mutex;
457 	struct pollfd fds;
458 	FILE *stdlog;
459 	unsigned char * target;
460 #ifdef SO_BINDTODEVICE
461 	char * ibindtodevice;
462 	char * obindtodevice;
463 #endif
464 	struct auth *authenticate;
465 	struct pollfd * srvfds;
466 	struct ace *acl;
467 	struct auth *authfuncs;
468 	struct filter *filter;
469 	unsigned char * logformat;
470 	unsigned char * logtarget;
471 	unsigned char * nonprintable;
472 	unsigned short targetport;
473 	unsigned char replace;
474 	time_t time_start;
475 };
476 
477 struct clientparam {
478 	struct clientparam	*next,
479 				*prev;
480 	struct srvparam *srv;
481 	REDIRECTFUNC redirectfunc;
482 	BANDLIMFUNC bandlimfunc;
483 	TRAFCOUNTFUNC trafcountfunc;
484 
485 
486 	struct filterp	*filters,
487 			**reqfilters,
488 			**hdrfilterscli, **hdrfilterssrv,
489 			**predatfilters, **datfilterscli, **datfilterssrv;
490 
491 	PROXYSERVICE service;
492 
493 	SOCKET	clisock,
494 		remsock,
495 		ctrlsock,
496 		ctrlsocksrv;
497 
498 	REDIRTYPE redirtype;
499 
500 	uint64_t	waitclient64,
501 			waitserver64,
502 			cycles;
503 
504 	int	redirected,
505 		operation,
506 		nfilters, nreqfilters, nhdrfilterscli, nhdrfilterssrv, npredatfilters, ndatfilterscli, ndatfilterssrv,
507 		unsafefilter,
508 		bandlimver;
509 
510 	int	res,
511 		status;
512 #if defined(__DragonFly__)
513 	int	pwtype;
514 	uintptr_t threadid;
515 	int	weight,
516 #else
517 	int	pwtype,
518 		threadid,
519 		weight,
520 #endif
521 		nolog,
522 		nolongdatfilter,
523 		nooverwritefilter,
524 		transparent,
525 		chunked,
526 		paused,
527 		version;
528 
529 	unsigned char 	*hostname,
530 			*username,
531 			*password,
532 			*extusername,
533 			*extpassword,
534 			*clibuf,
535 			*srvbuf;
536 
537 	unsigned 	cliinbuf,
538 			srvinbuf,
539 			clioffset,
540 			srvoffset,
541 			clibufsize,
542 			srvbufsize,
543 			msec_start;
544 	uint64_t
545 			maxtrafin64,
546 			maxtrafout64;
547 #ifndef NOIPV6
548 	struct sockaddr_in6	sincl, sincr, sinsl, sinsr, req;
549 #else
550 	struct sockaddr_in	sincl, sincr, sinsl, sinsr, req;
551 #endif
552 
553 	uint64_t	statscli64,
554 			statssrv64;
555 	unsigned long
556 			nreads,
557 			nwrites,
558 			nconnects;
559 
560 	struct bandlim	*bandlims[MAXBANDLIMS],
561 			*bandlimsout[MAXBANDLIMS];
562 
563 	time_t time_start;
564 };
565 
566 struct filemon {
567 	char * path;
568 	struct stat sb;
569 	struct filemon *next;
570 };
571 
572 
573 struct extparam {
574 	int timeouts[12];
575 	struct ace * acl;
576 	char * conffile;
577 	struct bandlim * bandlimiter,  *bandlimiterout;
578 	struct connlim * connlimiter;
579 	struct trafcount * trafcounter;
580 	struct srvparam *services;
581 	int stacksize,
582 		threadinit, counterd, haveerror, rotate, paused, archiverc,
583 		demon, maxchild, needreload, timetoexit, version, noforce, bandlimver, parentretries;
584 	int authcachetype, authcachetime;
585 	int filtermaxsize;
586 	unsigned char *logname, **archiver;
587 	ROTATION logtype, countertype;
588 	char * counterfile;
589 #ifndef NOIPV6
590 	struct sockaddr_in6 intsa;
591 	struct sockaddr_in6 extsa6;
592 	struct sockaddr_in6 extsa;
593 #else
594 	struct sockaddr_in intsa;
595 	struct sockaddr_in extsa;
596 #endif
597 	struct passwords *pwl;
598 	struct auth * authenticate;
599 	AUTHFUNC authfunc;
600 	LOGFUNC logfunc;
601 	BANDLIMFUNC bandlimfunc;
602 	TRAFCOUNTFUNC trafcountfunc;
603 	unsigned char *logtarget, *logformat;
604 	struct filemon * fmon;
605 	struct filter * filters;
606 	struct auth *authfuncs;
607 	FILE *stdlog;
608 	char* demanddialprog;
609 	unsigned char **stringtable;
610 	time_t logtime, time;
611 	unsigned logdumpsrv, logdumpcli;
612 	char delimchar;
613 };
614 
615 struct property {
616 	struct property * next;
617 	char * name;
618 	EXTENDFUNC e_f;
619 	int type;
620 	char * description;
621 };
622 
623 struct datatype {
624 	char * type;
625 	EXTENDFUNC i_f;
626 	PRINTFUNC p_f;
627 	struct property * properties;
628 };
629 
630 struct node {
631 	void * value;
632 	void * iteration;
633 	struct node * parent;
634 	int type;
635 };
636 
637 struct dictionary {
638 	char * name;
639 	struct node * node;
640 	EXTENDFUNC array_f;
641 	int arraysize;
642 };
643 
644 struct commands {
645 	struct commands *next;
646 	char * command;
647 	int (* handler)(int argc, unsigned char ** argv);
648 	int minargs;
649 	int maxargs;
650 };
651 
652 
653 struct symbol {
654 	struct symbol *next;
655 	char * name;
656 	void * value;
657 };
658 
659 struct proxydef {
660 	PROXYFUNC pf;
661 	unsigned short port;
662 	int isudp;
663 	int service;
664 	char * helpmessage;
665 };
666 
667 extern struct proxydef childdef;
668 
669 struct child {
670 	int argc;
671 	unsigned char **argv;
672 };
673 
674 struct hashentry {
675 	unsigned char hash[sizeof(unsigned)*4];
676 	time_t expires;
677 	struct hashentry *next;
678 	char value[4];
679 };
680 
681 struct hashtable {
682 	unsigned hashsize;
683 	unsigned recsize;
684 	unsigned rnd[4];
685 	struct hashentry ** hashtable;
686 	void * hashvalues;
687 	struct hashentry * hashempty;
688 };
689 
690 extern struct hashtable dns_table;
691 extern struct hashtable dns6_table;
692 
693 struct sockfuncs {
694 #ifdef _WIN32
695 	SOCKET (WINAPI *_socket)(int domain, int type, int protocol);
696 	SOCKET (WINAPI *_accept)(SOCKET s, struct sockaddr * addr, int * addrlen);
697 	int (WINAPI *_bind)(SOCKET s, const struct sockaddr *addr, int addrlen);
698 	int (WINAPI *_listen)(SOCKET s, int backlog);
699 	int (WINAPI *_connect)(SOCKET s, const struct sockaddr *name, int namelen);
700 	int (WINAPI *_getpeername)(SOCKET s, struct sockaddr * name, int * namelen);
701 	int (WINAPI *_getsockname)(SOCKET s, struct sockaddr * name, int * namelen);
702    	int (WINAPI *_getsockopt)(SOCKET s, int level, int optname, char * optval, int * optlen);
703 	int (WINAPI *_setsockopt)(SOCKET s, int level, int optname, const char *optval, int optlen);
704 	int (WINAPI *_poll)(struct pollfd *fds, unsigned int nfds, int timeout);
705 	int (WINAPI *_send)(SOCKET s, const char *msg, int len, int flags);
706 	int  (WINAPI *_sendto)(SOCKET s, const char *msg, int len, int flags, const struct sockaddr *to, int tolen);
707 	int  (WINAPI *_recv)(SOCKET s, char *buf, int len, int flags);
708 	int  (WINAPI *_recvfrom)(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen);
709 	int (WINAPI *_shutdown)(SOCKET s, int how);
710 	int (WINAPI *_closesocket)(SOCKET s);
711 #else
712 	SOCKET (*_socket)(int domain, int type, int protocol);
713 	SOCKET (*_accept)(SOCKET s, struct sockaddr * addr, socklen_t * addrlen);
714 	int (*_bind)(SOCKET s, const struct sockaddr *addr, socklen_t addrlen);
715 	int (*_listen)(SOCKET s, int backlog);
716 	int (*_connect)(SOCKET s, const struct sockaddr *name, socklen_t namelen);
717 	int (*_getpeername)(SOCKET s, struct sockaddr * name, socklen_t * namelen);
718 	int (*_getsockname)(SOCKET s, struct sockaddr * name, socklen_t * namelen);
719    	int (*_getsockopt)(SOCKET s, int level, int optname, void * optval, socklen_t * optlen);
720 	int (*_setsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen);
721 	int (*_poll)(struct pollfd *fds, unsigned int nfds, int timeout);
722 	size_t (*_send)(SOCKET s, const void *msg, size_t len, int flags);
723 	size_t (*_sendto)(SOCKET s, const void *msg, size_t len, int flags, const struct sockaddr *to, SASIZETYPE tolen);
724 	size_t (*_recv)(SOCKET s, void *buf, size_t len, int flags);
725 	size_t (*_recvfrom)(SOCKET s, void * buf, size_t len, int flags, struct sockaddr * from, SASIZETYPE * fromlen);
726 	int (*_shutdown)(SOCKET s, int how);
727 	int (*_closesocket)(SOCKET s);
728 #endif
729 };
730 
731 extern struct sockfuncs so;
732 struct pluginlink {
733 	struct symbol symbols;
734 	struct extparam *conf;
735 	struct nserver *nservers;
736 	int * linenum;
737 	struct auth *authfuncs;
738 	struct commands * commandhandlers;
739 	void * (*findbyname)(const char *name);
740 	int (*socksend)(SOCKET sock, unsigned char * buf, int bufsize, int to);
741 	int (*socksendto)(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
742 	int (*sockrecvfrom)(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);
743 	int (*sockgetcharcli)(struct clientparam * param, int timeosec, int timeousec);
744 	int (*sockgetcharsrv)(struct clientparam * param, int timeosec, int timeousec);
745 	int (*sockgetlinebuf)(struct clientparam * param, DIRECTION which, unsigned char * buf, int bufsize, int delim, int to);
746 	int (*myinet_ntop)(int af, void *src, char *dst, socklen_t size);
747 	int (*dobuf)(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec);
748 	int (*dobuf2)(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec, struct tm* tm, char * format);
749 	int (*scanaddr)(const unsigned char *s, unsigned long * ip, unsigned long * mask);
750 	unsigned long (*getip46)(int family, unsigned char *name,  struct sockaddr *sa);
751 	int (*sockmap)(struct clientparam * param, int timeo, int usesplice);
752 	int (*ACLMatches)(struct ace* acentry, struct clientparam * param);
753 	int (*alwaysauth)(struct clientparam * param);
754 	int (*checkACL)(struct clientparam * param);
755 	void (*nametohash)(const unsigned char * name, unsigned char *hash);
756 	unsigned (*hashindex)(const unsigned char* hash);
757 	unsigned char* (*en64)(const unsigned char *in, unsigned char *out, int inlen);
758 	int (*de64)(const unsigned char *in, unsigned char *out, int maxlen);
759 	void (*tohex)(unsigned char *in, unsigned char *out, int len);
760 	void (*fromhex)(unsigned char *in, unsigned char *out, int len);
761 	void (*decodeurl)(unsigned char *s, int allowcr);
762 	int (*parsestr) (unsigned char *str, unsigned char **argm, int nitems, unsigned char ** buff, int *inbuf, int *bufsize);
763 	struct ace * (*make_ace) (int argc, unsigned char ** argv);
764 	void * (*mallocfunc)(size_t size);
765 	void (*freefunc)(void *ptr);
766 	void *(*reallocfunc)(void *ptr, size_t size);
767 	char * (*strdupfunc)(const char *str);
768 	TRAFCOUNTFUNC trafcountfunc;
769 	char ** proxy_table;
770 	struct schedule ** schedule;
771 	void (*freeacl)(struct ace*);
772 	char ** admin_table;
773 	struct proxydef * childdef;
774 	int (*start_proxy_thread)(struct child * chp);
775 	void (*freeparam)(struct clientparam * param);
776 	int (*parsehostname)(char *hostname, struct clientparam *param, unsigned short port);
777 	int (*parseusername)(char *username, struct clientparam *param, int extpasswd);
778 	int (*parseconnusername)(char *username, struct clientparam *param, int extpasswd, unsigned short port);
779 	struct sockfuncs *so;
780 	unsigned char * (*dologname) (unsigned char *buf, unsigned char *name, const unsigned char *ext, ROTATION lt, time_t t);
781 };
782 
783 struct counter_header {
784 	unsigned char sig[4];
785 	time_t updated;
786 };
787 
788 struct counter_record {
789 	uint64_t traf64;
790 	time_t cleared;
791 	time_t updated;
792 };
793 
794 extern struct pluginlink pluginlink;
795 extern char *rotations[];
796 
797 typedef enum {
798 	SINGLEBYTE_S,
799 	SINGLEBYTE_L,
800 	STRING_S,
801 	STRING_L,
802 	CONNECTION_S,
803 	CONNECTION_L,
804 	DNS_TO,
805 	CHAIN_TO,
806 	CONNECT_TO,
807 	CONNBACK_TO
808 }TIMEOUT;
809 
810 typedef enum {
811 	TYPE_INTEGER,
812 	TYPE_SHORT,
813 	TYPE_CHAR,
814 	TYPE_UNSIGNED,
815 	TYPE_UNSIGNED64,
816 	TYPE_TRAFFIC,
817 	TYPE_PORT,
818 	TYPE_IP,
819 	TYPE_SA,
820 	TYPE_CIDR,
821 	TYPE_STRING,
822 	TYPE_DATETIME,
823 	TYPE_OPERATIONS,
824 	TYPE_ROTATION,
825 	TYPE_PORTLIST,
826 	TYPE_IPLIST,
827 	TYPE_USERLIST,
828 	TYPE_PWLIST,
829 	TYPE_CHAIN,
830 	TYPE_ACE,
831 	TYPE_BANDLIMIT,
832 	TYPE_TRAFCOUNTER,
833 	TYPE_CLIENT,
834 	TYPE_WEEKDAYS,
835 	TYPE_TIME,
836 	TYPE_PERIOD,
837 	TYPE_SERVER
838 }DATA_TYPE;
839 
840 #ifdef  __cplusplus
841 }
842 #endif
843 
844 #endif
845