rearranged NeonServ code to be modular
[NeonServV5.git] / src / overall.h
1 /* overall.h - NeonServ v5.3
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17
18 #ifndef _overall_h
19 #define _overall_h
20 #include "../config.h"
21
22 #define NEONSERV_VERSION "5.3"
23 #define VERSION_PATCHLEVEL 543
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <ctype.h>
29 #ifdef WIN32
30 #include <windows.h>
31 #include <winsock2.h>
32 #include <malloc.h>
33 #else
34 #include <features.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <netinet/tcp.h>
39 #include <arpa/inet.h>
40 #include <netdb.h>
41 #include <sys/wait.h>
42 #endif
43 #include <unistd.h>
44 #include <getopt.h>
45 #include <stdarg.h>
46 #include <sys/time.h>
47 #include <time.h>
48 #ifdef HAVE_THREADS
49 #include <pthread.h>
50 #ifdef WIN32
51 #define pthread_self_tid() pthread_self().p
52 #else
53 #define pthread_self_tid() pthread_self()
54 #endif
55 #define THREAD_MUTEX_INIT(var) { \
56     pthread_mutexattr_t mutex_attr; \
57     pthread_mutexattr_init(&mutex_attr);\
58     pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE_NP);\
59     pthread_mutex_init(&var, &mutex_attr); \
60 }
61 #define THREAD_MUTEX_INIT_TYPE(var, type) { \
62     pthread_mutexattr_t mutex_attr; \
63     pthread_mutexattr_init(&mutex_attr);\
64     pthread_mutexattr_settype(&mutex_attr, type);\
65     pthread_mutex_init(&var, &mutex_attr); \
66 }
67 #define SYNCHRONIZE(var) pthread_mutex_lock(&var)
68 #define SET_SYNCHRONIZE(var) pthread_mutex_trylock(&var)
69 #define DESYNCHRONIZE(var) pthread_mutex_unlock(&var)
70 #else
71 #define THREAD_MUTEX_INIT(var)
72 #define SYNCHRONIZE(var)
73 #define DESYNCHRONIZE(var)
74 #endif
75
76 #if __GNUC__
77 #define PRINTF_LIKE(M,N) __attribute__((format (printf, M, N)))
78 #else
79 #define PRINTF_LIKE(M,N)
80 #endif
81
82 #if __GNUC__ >= 2
83 #define UNUSED_ARG(ARG) ARG __attribute__((unused))
84 #elif defined(S_SPLINT_S)
85 #define UNUSED_ARG(ARG) /*@unused@*/ ARG
86 #define const /*@observer@*/ /*@temp@*/
87 #else
88 #define UNUSED_ARG(ARG) ARG
89 #endif
90
91 #define STRINGIFY_(x) #x
92 #define STRINGIFY(x) STRINGIFY_(x)
93  
94 #if defined(__GNUC__)
95 #if defined(__GNUC_PATCHLEVEL__)
96 #define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__) "." STRINGIFY(__GNUC_PATCHLEVEL__)
97 #else
98 #define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__)
99 #endif
100 #elif defined (__IMAGECRAFT__)
101 #define COMPILER "ICCAVR"
102 #else
103 #define COMPILER "Unknown"
104 #endif
105
106 #ifdef ENABLE_MEMORY_DEBUG
107 #include "memoryDebug.h"
108 #endif
109
110 #define PID_FILE "neonserv.pid"
111 #define CONF_FILE "neonserv.conf"
112 #define LOG_FILE "neonserv.log"
113
114 #define SOCKET_SELECT_TIME    1
115 #define SOCKET_RECONNECT_TIME 20
116
117 #define NICKLEN         30
118 #define USERLEN         10
119 #define AUTHLEN         32
120 #define HOSTLEN         63
121 #define REALLEN         50
122 #define TOPICLEN        500
123 #define CHANNELLEN      200
124 #define MAXLEN          512
125 #define MAXLOGLEN       1024
126 #define TRIGGERLEN      50
127 #define MAXNUMPARAMS    200 /* maximum number of parameters in one line */
128 #define MAXLANGUAGES    5
129 #define MAXMODES        6
130 #define INVITE_TIMEOUT  30
131 #define BOTWAR_DETECTION_TIME 7
132 #define BOTWAR_DETECTION_EVENTS 6
133 #define REWHO_TIMEOUT   10 /* wait 10 seconds before WHO an unauthed user again */
134 #define TICKS_PER_SECOND 10
135
136 //valid nick chars
137 #define VALID_NICK_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890{|}~[\\]^-_`"
138 //the first char is a little bit different
139 //                              0        1         2         3         4         5          6
140 //                              1234567890123456789012345678901234567890123456789012345678 9012   62
141 #define VALID_NICK_CHARS_FIRST "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~[\\]^_`"
142 #define VALID_NICK_CHARS_FIRST_LEN 62
143
144 #define TEMPUSER_LIST_INDEX VALID_NICK_CHARS_FIRST_LEN
145
146 #define LOGLEVEL_INFO  0x01
147 #define LOGLEVEL_ERROR 0x02
148 #define LOGLEVEL_RAW   0x04
149 #define LOGLEVEL_MYSQL 0x08
150
151 #define timeval_is_bigger(x,y) ((x.tv_sec > y.tv_sec) || (x.tv_sec == y.tv_sec && x.tv_usec > y.tv_usec))
152
153 #define perror(errmsg) (putlog(LOGLEVEL_ERROR, "ERROR (%s:%d) %s", __FILE__, __LINE__, errmsg))
154
155 #define MODSTATE_RELOAD    0x01
156 #define MODSTATE_STARTSTOP 0x02
157 #define MODSTATE_REBIND    0x03
158
159 #endif