]> jfr.im git - irc/rqf/shadowircd.git/blob - libratbox/include/ratbox_lib.h
Cope with OPENSSL_VERSION_NUMBER not being a long.
[irc/rqf/shadowircd.git] / libratbox / include / ratbox_lib.h
1 /*
2 */
3
4 #ifndef RB_LIB_H
5 #define RB_LIB_H 1
6
7 #include <librb-config.h>
8 #include <stdio.h>
9 #include <limits.h>
10 #include <stdarg.h>
11 #include <assert.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <ctype.h>
15
16 #ifdef __GNUC__
17 #undef alloca
18 #define alloca __builtin_alloca
19 #else
20 # ifdef _MSC_VER
21 # include <malloc.h>
22 # define alloca _alloca
23 # else
24 # if RB_HAVE_ALLOCA_H
25 # include <alloca.h>
26 # else
27 # ifdef _AIX
28 #pragma alloca
29 # else
30 # ifndef alloca /* predefined by HP cc +Olibcalls */
31 char *alloca();
32 # endif
33 # endif
34 # endif
35 # endif
36 #endif /* __GNUC__ */
37
38 #ifdef __GNUC__
39
40 #ifdef rb_likely
41 #undef rb_likely
42 #endif
43 #ifdef rb_unlikely
44 #undef rb_unlikely
45 #endif
46
47 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
48 # define __builtin_expect(x, expected_value) (x)
49 #endif
50
51 #define rb_likely(x) __builtin_expect(!!(x), 1)
52 #define rb_unlikely(x) __builtin_expect(!!(x), 0)
53
54 #else /* !__GNUC__ */
55
56 #define UNUSED(x) x
57
58 #ifdef rb_likely
59 #undef rb_likely
60 #endif
61 #ifdef rb_unlikely
62 #undef rb_unlikely
63 #endif
64 #define rb_likely(x) (x)
65 #define rb_unlikely(x) (x)
66 #endif
67
68
69
70 #ifdef _WIN32
71 #include <process.h>
72
73 #ifndef MAXPATHLEN
74 #define MAXPATHLEN 128
75 #endif
76
77 #ifdef strerror
78 #undef strerror
79 #endif
80
81 #define strerror(x) rb_strerror(x)
82 char *rb_strerror(int error);
83
84
85 #define ENOBUFS WSAENOBUFS
86 #define EINPROGRESS WSAEINPROGRESS
87 #define EWOULDBLOCK WSAEWOULDBLOCK
88 #define EMSGSIZE WSAEMSGSIZE
89 #define EALREADY WSAEALREADY
90 #define EISCONN WSAEISCONN
91 #define EADDRINUSE WSAEADDRINUSE
92 #define EAFNOSUPPORT WSAEAFNOSUPPORT
93
94 #define pipe(x) _pipe(x, 1024, O_BINARY)
95 #define ioctl(x,y,z) ioctlsocket(x,y, (u_long *)z)
96
97 #define WNOHANG 1
98
99 #ifndef SIGKILL
100 #define SIGKILL SIGTERM
101 #endif
102
103 #endif /* _WIN32 */
104
105
106
107 #ifndef HOSTIPLEN
108 #define HOSTIPLEN 53
109 #endif
110
111 #ifdef __GNUC__
112 #define slrb_assert(expr) do \
113 if(rb_unlikely(!(expr))) { \
114 rb_lib_log( \
115 "file: %s line: %d (%s): Assertion failed: (%s)", \
116 __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
117 } \
118 while(0)
119 #else
120 #define slrb_assert(expr) do \
121 if(rb_unlikely(!(expr))) { \
122 rb_lib_log(L_MAIN, \
123 "file: %s line: %d: Assertion failed: (%s)", \
124 __FILE__, __LINE__, #expr); \
125 } \
126 while(0)
127 #endif
128
129 #ifdef SOFT_ASSERT
130 #define lrb_assert(expr) slrb_assert(expr)
131 #else
132 #define lrb_assert(expr) do { slrb_assert(expr); assert(expr); } while(0)
133 #endif
134
135 #ifdef RB_SOCKADDR_HAS_SA_LEN
136 #define ss_len sa_len
137 #endif
138
139 #define GET_SS_FAMILY(x) (((const struct sockaddr *)(x))->sa_family)
140 #define SET_SS_FAMILY(x, y) ((((struct sockaddr *)(x))->sa_family) = y)
141 #ifdef RB_SOCKADDR_HAS_SA_LEN
142 #define SET_SS_LEN(x, y) do { \
143 struct sockaddr *storage; \
144 storage = ((struct sockaddr *)(x));\
145 storage->sa_len = (y); \
146 } while (0)
147 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len)
148 #else /* !RB_SOCKADDR_HAS_SA_LEN */
149 #define SET_SS_LEN(x, y) (((struct sockaddr *)(x))->sa_family = ((struct sockaddr *)(x))->sa_family)
150 #ifdef RB_IPV6
151 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
152 #else
153 #define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : 0)
154 #endif
155 #endif
156
157 #ifndef INADDRSZ
158 #define INADDRSZ 4
159 #endif
160
161 #ifndef IN6ADDRSZ
162 #define IN6ADDRSZ 16
163 #endif
164
165 #ifndef INT16SZ
166 #define INT16SZ 2
167 #endif
168
169
170 typedef void log_cb(const char *buffer);
171 typedef void restart_cb(const char *buffer);
172 typedef void die_cb(const char *buffer);
173
174 char *rb_ctime(const time_t, char *, size_t);
175 char *rb_date(const time_t, char *, size_t);
176 void rb_lib_log(const char *, ...);
177 void rb_lib_restart(const char *, ...);
178 void rb_lib_die(const char *, ...);
179 void rb_set_time(void);
180 const char *rb_lib_version(void);
181
182 void rb_lib_init(log_cb * xilog, restart_cb * irestart, die_cb * idie, int closeall, int maxfds,
183 size_t dh_size, size_t fd_heap_size);
184 void rb_lib_loop(long delay);
185
186 time_t rb_current_time(void);
187 const struct timeval *rb_current_time_tv(void);
188 pid_t rb_spawn_process(const char *, const char **);
189
190 char *rb_strtok_r(char *, const char *, char **);
191
192 int rb_gettimeofday(struct timeval *, void *);
193
194 void rb_sleep(unsigned int seconds, unsigned int useconds);
195 char *rb_crypt(const char *, const char *);
196
197 unsigned char *rb_base64_encode(const unsigned char *str, int length);
198 unsigned char *rb_base64_decode(const unsigned char *str, int length, int *ret);
199 int rb_kill(pid_t, int);
200 char *rb_strerror(int);
201
202 int rb_setenv(const char *, const char *, int);
203
204 pid_t rb_waitpid(pid_t pid, int *status, int options);
205 pid_t rb_getpid(void);
206 //unsigned int rb_geteuid(void);
207
208
209 #include <rb_tools.h>
210 #include <rb_memory.h>
211 #include <rb_commio.h>
212 #include <rb_balloc.h>
213 #include <rb_linebuf.h>
214 #include <rb_snprintf.h>
215 #include <rb_event.h>
216 #include <rb_helper.h>
217 #include <rb_rawbuf.h>
218 #include <rb_patricia.h>
219
220 #endif