]>
Commit | Line | Data |
---|---|---|
db137867 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * commio.h: A header for the network subsystem. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
22 | * USA | |
23 | * | |
3202e249 | 24 | * $Id: rb_commio.h 26092 2008-09-19 15:13:52Z androsyn $ |
db137867 | 25 | */ |
3202e249 | 26 | |
db137867 | 27 | #ifndef RB_LIB_H |
3202e249 | 28 | # error "Do not use commio.h directly" |
db137867 AC |
29 | #endif |
30 | ||
31 | #ifndef INCLUDED_commio_h | |
32 | #define INCLUDED_commio_h | |
33 | ||
34 | ||
3202e249 | 35 | struct sockaddr; |
db137867 AC |
36 | struct _fde; |
37 | typedef struct _fde rb_fde_t; | |
38 | ||
39 | /* Callback for completed IO events */ | |
40 | typedef void PF(rb_fde_t *, void *); | |
41 | ||
42 | /* Callback for completed connections */ | |
43 | /* int fd, int status, void * */ | |
44 | typedef void CNCB(rb_fde_t *, int, void *); | |
45 | /* callback for fd table dumps */ | |
46 | typedef void DUMPCB(int, const char *desc, void *); | |
47 | /* callback for accept callbacks */ | |
48 | typedef void ACCB(rb_fde_t *, int status, struct sockaddr *addr, rb_socklen_t len, void *); | |
49 | /* callback for pre-accept callback */ | |
50 | typedef int ACPRE(rb_fde_t *, struct sockaddr *addr, rb_socklen_t len, void *); | |
51 | ||
52 | enum | |
53 | { | |
54 | RB_OK, | |
55 | RB_ERR_BIND, | |
56 | RB_ERR_DNS, | |
57 | RB_ERR_TIMEOUT, | |
58 | RB_ERR_CONNECT, | |
59 | RB_ERROR, | |
60 | RB_ERROR_SSL, | |
61 | RB_ERR_MAX | |
62 | }; | |
63 | ||
64 | #define RB_FD_NONE 0x01 | |
65 | #define RB_FD_FILE 0x02 | |
66 | #define RB_FD_SOCKET 0x04 | |
3202e249 | 67 | #ifndef _WIN32 |
db137867 AC |
68 | #define RB_FD_PIPE 0x08 |
69 | #else | |
70 | #define RB_FD_PIPE RB_FD_SOCKET | |
71 | #endif | |
72 | #define RB_FD_LISTEN 0x10 | |
73 | #define RB_FD_SSL 0x20 | |
74 | #define RB_FD_UNKNOWN 0x40 | |
75 | ||
76 | #define RB_RW_IO_ERROR -1 /* System call error */ | |
77 | #define RB_RW_SSL_ERROR -2 /* SSL Error */ | |
78 | #define RB_RW_SSL_NEED_READ -3 /* SSL Needs read */ | |
79 | #define RB_RW_SSL_NEED_WRITE -4 /* SSL Needs write */ | |
80 | ||
81 | ||
82 | struct rb_iovec | |
83 | { | |
84 | void *iov_base; | |
85 | size_t iov_len; | |
86 | }; | |
87 | ||
88 | ||
89 | void rb_fdlist_init(int closeall, int maxfds, size_t heapsize); | |
90 | ||
3202e249 | 91 | rb_fde_t *rb_open(int, uint8_t, const char *); |
db137867 AC |
92 | void rb_close(rb_fde_t *); |
93 | void rb_dump_fd(DUMPCB *, void *xdata); | |
94 | void rb_note(rb_fde_t *, const char *); | |
95 | ||
96 | /* Type of IO */ | |
97 | #define RB_SELECT_READ 0x1 | |
98 | #define RB_SELECT_WRITE 0x2 | |
99 | ||
100 | #define RB_SELECT_ACCEPT RB_SELECT_READ | |
101 | #define RB_SELECT_CONNECT RB_SELECT_WRITE | |
102 | ||
7247337a JT |
103 | #define RB_SSL_CERTFP_LEN 20 |
104 | ||
db137867 AC |
105 | int rb_set_nb(rb_fde_t *); |
106 | int rb_set_buffers(rb_fde_t *, int); | |
107 | ||
108 | int rb_get_sockerr(rb_fde_t *); | |
109 | ||
110 | void rb_settimeout(rb_fde_t *, time_t, PF *, void *); | |
111 | void rb_checktimeouts(void *); | |
3202e249 VY |
112 | void rb_connect_tcp(rb_fde_t *, struct sockaddr *, struct sockaddr *, int, CNCB *, void *, int); |
113 | void rb_connect_tcp_ssl(rb_fde_t *, struct sockaddr *, struct sockaddr *, int, CNCB *, void *, int); | |
db137867 AC |
114 | int rb_connect_sockaddr(rb_fde_t *, struct sockaddr *addr, int len); |
115 | ||
116 | const char *rb_errstr(int status); | |
117 | rb_fde_t *rb_socket(int family, int sock_type, int proto, const char *note); | |
3202e249 VY |
118 | int rb_socketpair(int family, int sock_type, int proto, rb_fde_t **F1, rb_fde_t **F2, |
119 | const char *note); | |
db137867 | 120 | |
3202e249 | 121 | void rb_accept_tcp(rb_fde_t *, ACPRE * precb, ACCB * callback, void *data); |
db137867 AC |
122 | ssize_t rb_write(rb_fde_t *, const void *buf, int count); |
123 | ssize_t rb_writev(rb_fde_t *, struct rb_iovec *vector, int count); | |
124 | ||
125 | ssize_t rb_read(rb_fde_t *, void *buf, int count); | |
126 | int rb_pipe(rb_fde_t **, rb_fde_t **, const char *desc); | |
127 | ||
128 | int rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile); | |
aa4737a0 AC |
129 | int rb_ssl_listen(rb_fde_t *, int backlog, int defer_accept); |
130 | int rb_listen(rb_fde_t *, int backlog, int defer_accept); | |
db137867 AC |
131 | |
132 | const char *rb_inet_ntop(int af, const void *src, char *dst, unsigned int size); | |
133 | int rb_inet_pton(int af, const char *src, void *dst); | |
134 | const char *rb_inet_ntop_sock(struct sockaddr *src, char *dst, unsigned int size); | |
135 | int rb_inet_pton_sock(const char *src, struct sockaddr *dst); | |
136 | int rb_getmaxconnect(void); | |
137 | int rb_ignore_errno(int); | |
138 | ||
139 | /* Generic wrappers */ | |
140 | void rb_setselect(rb_fde_t *, unsigned int type, PF * handler, void *client_data); | |
141 | void rb_init_netio(void); | |
142 | int rb_select(unsigned long); | |
143 | int rb_fd_ssl(rb_fde_t *F); | |
144 | int rb_get_fd(rb_fde_t *F); | |
145 | const char *rb_get_ssl_strerror(rb_fde_t *F); | |
7247337a | 146 | int rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN]); |
db137867 AC |
147 | |
148 | rb_fde_t *rb_get_fde(int fd); | |
149 | ||
3202e249 | 150 | int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid); |
db137867 AC |
151 | int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int count); |
152 | ||
a9fb3ed0 VY |
153 | void rb_set_type(rb_fde_t *F, uint8_t type); |
154 | uint8_t rb_get_type(rb_fde_t *F); | |
db137867 AC |
155 | |
156 | const char *rb_get_iotype(void); | |
157 | ||
3202e249 VY |
158 | typedef enum |
159 | { | |
db137867 | 160 | RB_PRNG_FILE, |
3202e249 | 161 | #ifdef _WIN32 |
db137867 AC |
162 | RB_PRNGWIN32, |
163 | #endif | |
164 | RB_PRNG_DEFAULT, | |
165 | } prng_seed_t; | |
166 | ||
167 | int rb_init_prng(const char *path, prng_seed_t seed_type); | |
168 | int rb_get_random(void *buf, size_t len); | |
a9fb3ed0 | 169 | int rb_get_pseudo_random(void *buf, size_t len); |
3202e249 VY |
170 | void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout); |
171 | void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout); | |
db137867 AC |
172 | int rb_supports_ssl(void); |
173 | ||
c2ac22cc VY |
174 | unsigned int rb_ssl_handshake_count(rb_fde_t *F); |
175 | void rb_ssl_clear_handshake_count(rb_fde_t *F); | |
3202e249 VY |
176 | |
177 | ||
178 | int rb_pass_fd_to_process(rb_fde_t *, pid_t, rb_fde_t *); | |
179 | rb_fde_t *rb_recv_fd(rb_fde_t *); | |
180 | ||
db137867 | 181 | #endif /* INCLUDED_commio_h */ |