Merge branch 'development'
[NeonServV5.git] / src / overall.h
1 /* overall.h - NeonServ v5.6
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.6"
23 #define VERSION_PATCHLEVEL 736
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 #ifdef HAVE_FEATURES_H
35 #include <features.h>
36 #endif
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/tcp.h>
41 #include <arpa/inet.h>
42 #include <netdb.h>
43 #include <sys/wait.h>
44 #include <errno.h>
45 #endif
46 #include <unistd.h>
47 #include <getopt.h>
48 #include <stdarg.h>
49 #include <sys/time.h>
50 #include <time.h>
51 #include <signal.h>
52 #ifdef SYNCHRONIZE
53 //some winnt machines do already have a SYNCHRONIZE macro defined...
54 #undef SYNCHRONIZE
55 #endif
56 #ifdef HAVE_THREADS
57 #include <pthread.h>
58 #ifdef WIN32
59 #define pthread_self_tid() pthread_self().p
60 #else
61 #define pthread_self_tid() pthread_self()
62 #endif
63 #ifdef PTHREAD_MUTEX_RECURSIVE_NP
64 #define PTHREAD_MUTEX_RECURSIVE_VAL PTHREAD_MUTEX_RECURSIVE_NP
65 #else
66 #define PTHREAD_MUTEX_RECURSIVE_VAL PTHREAD_MUTEX_RECURSIVE
67 #endif
68 #define THREAD_MUTEX_INIT(var) { \
69     pthread_mutexattr_t mutex_attr; \
70     pthread_mutexattr_init(&mutex_attr);\
71     pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE_VAL);\
72     pthread_mutex_init(&var, &mutex_attr); \
73 }
74 #define THREAD_MUTEX_INIT_TYPE(var, type) { \
75     pthread_mutexattr_t mutex_attr; \
76     pthread_mutexattr_init(&mutex_attr);\
77     pthread_mutexattr_settype(&mutex_attr, type);\
78     pthread_mutex_init(&var, &mutex_attr); \
79 }
80 #ifdef ENABLE_MUTEX_DEBUG
81 #include "mutexDebug.h"
82 #define SYNCHRONIZE(var) xmutex(1, &var, __FILE__, __LINE__); pthread_mutex_lock(&var)
83 #define DESYNCHRONIZE(var) xmutex(0, &var, __FILE__, __LINE__); pthread_mutex_unlock(&var)
84 #else
85 #define SYNCHRONIZE(var) pthread_mutex_lock(&var)
86 #define DESYNCHRONIZE(var) pthread_mutex_unlock(&var)
87 #endif
88 #else
89 #define THREAD_MUTEX_INIT(var)
90 #define SYNCHRONIZE(var)
91 #define DESYNCHRONIZE(var)
92 #ifdef ENABLE_MUTEX_DEBUG
93 #undef ENABLE_MUTEX_DEBUG
94 #endif
95 #endif
96
97 #if __GNUC__
98 #define PRINTF_LIKE(M,N) __attribute__((format (printf, M, N)))
99 #else
100 #define PRINTF_LIKE(M,N)
101 #endif
102
103 #if __GNUC__ >= 2
104 #define UNUSED_ARG(ARG) ARG __attribute__((unused))
105 #elif defined(S_SPLINT_S)
106 #define UNUSED_ARG(ARG) /*@unused@*/ ARG
107 #define const /*@observer@*/ /*@temp@*/
108 #else
109 #define UNUSED_ARG(ARG) ARG
110 #endif
111
112 #define STRINGIFY_(x) #x
113 #define STRINGIFY(x) STRINGIFY_(x)
114  
115 #if defined(__GNUC__)
116 #if defined(__GNUC_PATCHLEVEL__)
117 #define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__) "." STRINGIFY(__GNUC_PATCHLEVEL__)
118 #else
119 #define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__)
120 #endif
121 #elif defined (__IMAGECRAFT__)
122 #define COMPILER "ICCAVR"
123 #else
124 #define COMPILER "Unknown"
125 #endif
126
127 #ifdef ENABLE_MEMORY_DEBUG
128 #include "memoryDebug.h"
129 #endif
130
131 #define SOCKET_SELECT_TIME    1
132 #define SOCKET_RECONNECT_TIME 20
133
134 #define NICKLEN         30
135 #define USERLEN         10
136 #define AUTHLEN         32
137 #define HOSTLEN         63
138 #define REALLEN         50
139 #define TOPICLEN        500
140 #define CHANNELLEN      200
141 #define MAXLEN          512
142 #define MAXLOGLEN       1024
143 #define TRIGGERLEN      50
144 #define MAXNUMPARAMS    200 /* maximum number of parameters in one line */
145 #define MAXLANGUAGES    15
146 #define MAXMODES        6
147 #define INVITE_TIMEOUT  30
148 #define BOTWAR_DETECTION_TIME 7
149 #define BOTWAR_DETECTION_EVENTS 6
150 #define REWHO_TIMEOUT   10 /* wait 10 seconds before WHO an unauthed user again */
151 #define CLEAR_CACHE_INTERVAL 10
152
153 //valid nick chars
154 #define VALID_NICK_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890{|}~[\\]^-_`"
155 //the first char is a little bit different
156 //                              0        1         2         3         4         5          6
157 //                              1234567890123456789012345678901234567890123456789012345678 9012   62
158 #define VALID_NICK_CHARS_FIRST "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~[\\]^_`"
159 #define VALID_NICK_CHARS_FIRST_LEN 62
160
161 #define TEMPUSER_LIST_INDEX VALID_NICK_CHARS_FIRST_LEN
162
163 #define LOGLEVEL_INFO  0x01
164 #define LOGLEVEL_ERROR 0x02
165 #define LOGLEVEL_RAW   0x04
166 #define LOGLEVEL_MYSQL 0x08
167
168 #define timeval_is_bigger(x,y) ((x.tv_sec > y.tv_sec) || (x.tv_sec == y.tv_sec && x.tv_usec > y.tv_usec))
169
170 #define MODSTATE_RELOAD    0x01
171 #define MODSTATE_STARTSTOP 0x02
172 #define MODSTATE_REBIND    0x03
173
174 #endif