1 /* dircproxy 2 * Copyright (C) 2000-2003 Scott James Remnant <scott at netsplit dot com> 3 * 4 * Copyright (C) 2004-2008 Francois Harvey <contact at francoisharvey dot ca> 5 * 6 * Copyright (C) 2008-2009 Noel Shrum <noel dot w8tvi at gmail dot com> 7 * Francois Harvey <contact at francoisharvey dot ca> 8 * 9 * irc_net.h 10 * -- 11 * @(#) $Id: irc_net.h,v 1.55 2004/02/26 20:06:15 fharvey Exp $ 12 * 13 * This file is distributed according to the GNU General Public 14 * License. For full details, read the top of 'main.c' or the 15 * file called COPYING that was distributed with this code. 16 */ 17 18 #ifndef __DIRCPROXY_IRC_NET_H 19 #define __DIRCPROXY_IRC_NET_H 20 21 /* required includes */ 22 #include <stdio.h> 23 #include <sys/types.h> 24 #include <sys/socket.h> 25 #include <netinet/in.h> 26 #include <netdb.h> 27 #include <arpa/inet.h> 28 #include <time.h> 29 30 #include "irc_prot.h" 31 #include "stringex.h" 32 #include "net.h" 33 34 /* a log file - there are good reasons why this isn't defined in irc_log.h */ 35 typedef struct logfile { 36 int open, made; 37 char *filename; 38 FILE *file; 39 40 unsigned long nlines, maxlines; 41 42 int always; 43 } LogFile; 44 45 /* a description of an authorised connction */ 46 typedef struct ircconnclass { 47 char *server_port; 48 long server_retry; 49 long server_dnsretry; 50 long server_maxattempts; 51 long server_maxinitattempts; 52 int server_keepalive; 53 long server_pingtimeout; 54 long *server_throttle; 55 int server_autoconnect; 56 57 long channel_rejoin; 58 int channel_leave_on_detach; 59 int channel_rejoin_on_attach; 60 61 long idle_maxtime; 62 63 int disconnect_existing; 64 int disconnect_on_detach; 65 66 char *initial_modes; 67 char *drop_modes; 68 char *refuse_modes; 69 70 char *local_address; 71 72 char *away_message; 73 char *quit_message; 74 char *attach_message; 75 char *detach_message; 76 char *detach_nickname; 77 78 int nick_keep; 79 80 char *nickserv_password; 81 82 int ctcp_replies; 83 84 long log_timeoffset; 85 int log_events; 86 int log_timestamp; 87 int log_relativetime; 88 char *log_dir; 89 char *log_program; 90 91 int chan_log_enabled; 92 int chan_log_always; 93 long chan_log_maxsize; 94 long chan_log_recall; 95 96 int private_log_enabled; 97 int private_log_always; 98 long private_log_maxsize; 99 long private_log_recall; 100 101 int server_log_enabled; 102 int server_log_always; 103 long server_log_maxsize; 104 long server_log_recall; 105 106 int dcc_proxy_incoming; 107 int dcc_proxy_outgoing; 108 int *dcc_proxy_ports; 109 size_t dcc_proxy_ports_sz; 110 long dcc_proxy_timeout; 111 int dcc_proxy_sendreject; 112 113 int dcc_send_fast; 114 115 char *dcc_capture_directory; 116 int dcc_capture_always; 117 int dcc_capture_withnick; 118 long dcc_capture_maxsize; 119 120 char *dcc_tunnel_incoming; 121 char *dcc_tunnel_outgoing; 122 123 char *switch_user; 124 125 int motd_logo; 126 char *motd_file; 127 int motd_stats; 128 129 int allow_persist; 130 int allow_jump; 131 int allow_jump_new; 132 int allow_host; 133 int allow_die; 134 int allow_users; 135 int allow_kill; 136 int allow_notify; 137 138 char *password; 139 struct strlist *servers, *next_server; 140 struct strlist *masklist; 141 struct strlist *channels; 142 143 /* Most config file options can be changed by editing the config file and 144 HUP'ing dircproxy. One or two can be done from the /DIRCPROXY command 145 though. Always keep the originals. */ 146 147 /* EXPERIMENTAL 148 * allow dynamic enable GET and SET command to get and set configuration 149 * option in runtime. usefull if you want to put some configuration option 150 * inside your irc client. 151 */ 152 int allow_dynamic; 153 154 char *orig_local_address; 155 156 struct ircconnclass *next; 157 } IRCConnClass; 158 159 /* a channel someone is on */ 160 typedef struct ircchannel { 161 char *name; 162 char *key; 163 int inactive; 164 int unjoined; 165 struct logfile log; 166 167 struct ircchannel *next; 168 } IRCChannel; 169 170 /* a proxied connection */ 171 typedef struct ircproxy { 172 int dead; 173 struct ircconnclass *conn_class; 174 int die_on_close; 175 time_t start; 176 177 int client_sock; 178 int client_status; 179 SOCKADDR client_addr; 180 char *client_host; 181 182 int server_sock; 183 int server_status; 184 SOCKADDR server_addr; 185 long server_attempts; 186 187 char *nickname; 188 char *setnickname; 189 char *oldnickname; 190 191 char *username; 192 char *hostname; 193 char *realname; 194 char *servername; 195 char *serverver; 196 char *serverumodes; 197 char *servercmodes; 198 char *serverpassword; 199 struct strlist *serversupported; 200 201 char *password; 202 203 int allow_motd; 204 int allow_pong; 205 int squelch_411; 206 int expecting_nick; 207 struct strlist *squelch_modes; 208 209 char *ctcp_userinfo; 210 char *ctcp_finger; 211 char *awaymessage; 212 char *modes; 213 struct ircchannel *channels; 214 215 char *temp_logdir; 216 struct logfile private_log, server_log; 217 218 struct ircproxy *next; 219 } IRCProxy; 220 221 /* a dcc resume */ 222 struct dcc_resume { 223 int l_port; 224 int r_port; 225 char *id; 226 char *capfile; 227 char *rejmsg; 228 char *fullname; 229 #ifdef __APPLE__ 230 u_int32_t size; 231 #else 232 uint32_t size; 233 #endif 234 struct in_addr r_addr; 235 struct dcc_resume *next; 236 }; 237 238 /* states a client can be in */ 239 #define IRC_CLIENT_NONE 0x00 240 #define IRC_CLIENT_CONNECTED 0x01 241 #define IRC_CLIENT_GOTPASS 0x02 242 #define IRC_CLIENT_GOTNICK 0x04 243 #define IRC_CLIENT_GOTUSER 0x08 244 #define IRC_CLIENT_AUTHED 0x10 245 #define IRC_CLIENT_SENTWELCOME 0x20 246 #define IRC_CLIENT_ACTIVE 0x3d 247 248 /* Can we send data to the client? */ 249 #define IS_CLIENT_READY(_c) (((_c)->client_status & 0x1d) == 0x1d) 250 251 /* states a server can be in */ 252 #define IRC_SERVER_NONE 0x00 253 #define IRC_SERVER_CREATED 0x01 254 #define IRC_SERVER_SEEN 0x02 255 #define IRC_SERVER_CONNECTED 0x04 256 #define IRC_SERVER_INTRODUCED 0x08 257 #define IRC_SERVER_GOTWELCOME 0x10 258 #define IRC_SERVER_ACTIVE 0x1f 259 260 /* Can we send data to the server? */ 261 #define IS_SERVER_READY(_c) (((_c)->server_status & 0x0c) == 0x0c) 262 263 /* global variables */ 264 extern struct ircconnclass *connclasses; 265 266 /* functions */ 267 extern int ircnet_listen(const char *); 268 extern int ircnet_expunge_proxies(void); 269 extern void ircnet_flush(void); 270 extern void ircnet_flush_proxies(struct ircproxy **); 271 extern void ircnet_flush_connclasses(struct ircconnclass **); 272 extern void ircnet_freeconnclass(struct ircconnclass *); 273 extern int ircnet_hooksocket(int); 274 extern struct ircproxy *ircnet_fetchclass(struct ircconnclass *); 275 extern struct ircchannel *ircnet_fetchchannel(struct ircproxy *, const char *); 276 extern int ircnet_addchannel(struct ircproxy *, const char *); 277 extern int ircnet_delchannel(struct ircproxy *, const char *); 278 extern int ircnet_channel_mode(struct ircproxy *, struct ircchannel *, 279 struct ircmessage *, int); 280 extern struct ircchannel *ircnet_freechannel(struct ircchannel *); 281 extern int ircnet_rejoin(struct ircproxy *, const char *); 282 extern int ircnet_dedicate(struct ircproxy *); 283 extern int ircnet_announce_dedicated(struct ircproxy *); 284 extern int ircnet_announce_nolisten(struct ircproxy *); 285 extern int ircnet_announce_status(struct ircproxy *); 286 287 #endif /* __DIRCPROXY_IRC_NET_H */ 288