2 ctrlproxy: A modular IRC proxy
3 (c) 2002-2005 Jelmer Vernooij <jelmer@nl.linux.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __CTRLPROXY_NETWORK_H__
21 #define __CTRLPROXY_NETWORK_H__
25 * @brief Network functions
30 #ifndef G_MODULE_EXPORT
31 #define G_MODULE_EXPORT
36 #include <sys/socket.h>
38 #define DEFAULT_NETWORK_CHARSET NULL
44 struct linestack_context;
46 enum irc_network_connection_state {
47 NETWORK_CONNECTION_STATE_NOT_CONNECTED = 0,
48 NETWORK_CONNECTION_STATE_RECONNECT_PENDING,
49 NETWORK_CONNECTION_STATE_CONNECTING,
50 NETWORK_CONNECTION_STATE_CONNECTED,
51 NETWORK_CONNECTION_STATE_LOGIN_SENT,
52 NETWORK_CONNECTION_STATE_MOTD_RECVD,
56 * Information about the connection to a network.
58 struct irc_network_connection {
59 enum irc_network_connection_state state;
61 /** Time the last line was sent to this network. */
62 time_t last_line_sent;
63 /** Time the last line was received from this network. */
64 time_t last_line_recvd;
66 struct irc_transport *transport;
69 /** Configuration for TCP/IP server currently connected to. */
70 struct tcp_server_config *current_server;
71 /** Name of remote server. */
72 struct sockaddr *remote_name;
73 /** Name of local host used for connection. */
74 struct sockaddr *local_name;
75 /** Socket name length for remote_name and local_name. */
77 /** Last reason for disconnect. */
78 char *last_disconnect_reason;
79 /** Source ID for function that regularly pings the network. */
81 /** Source ID for function that finishes connect. */
87 struct virtual_network_ops {
89 gboolean not_disconnectable;
90 gboolean (*init) (struct irc_network *);
91 gboolean (*to_server) (struct irc_network *, struct irc_client *c, const struct irc_line *);
92 void (*fini) (struct irc_network *);
98 typedef void (*network_log_fn) (enum log_level, const struct irc_network *, const char *);
100 struct irc_network_callbacks {
102 struct irc_login_details *(*get_login_details) (struct irc_network *);
103 gboolean (*process_from_server) (struct irc_network *, const struct irc_line *);
104 gboolean (*process_to_server) (struct irc_network *, const struct irc_line *);
105 void (*disconnect) (struct irc_network *);
106 void (*state_set) (struct irc_network *);
116 struct global *global;
121 /** Number of references that exist to this network. */
124 /** Clients connected to this network.*/
128 gpointer ssl_credentials;
130 int reconnect_interval;
132 /** External network state, when connected. */
133 struct irc_network_state *external_state;
135 /** Internal network state, as used by clients */
136 struct irc_network_state *internal_state;
138 /** Network information. */
139 struct irc_network_info *info;
141 struct irc_network_connection connection;
143 /** Linestack context. */
144 struct linestack_context *linestack;
146 /** How many linestack errors have occurred so far */
147 guint linestack_errors;
149 const struct irc_network_callbacks *callbacks;
151 struct query_stack *queries;
155 G_MODULE_EXPORT gboolean network_set_charset(struct irc_network *n, const char *name);
156 G_MODULE_EXPORT gboolean autoconnect_networks(GList *);
157 G_MODULE_EXPORT struct irc_network *irc_network_new(const struct irc_network_callbacks *callbacks, void *private_data);
158 G_MODULE_EXPORT gboolean connect_network(struct irc_network *);
159 G_MODULE_EXPORT void irc_network_select_next_server(struct irc_network *n);
160 G_MODULE_EXPORT gboolean disconnect_network(struct irc_network *s);
161 G_MODULE_EXPORT gboolean network_send_line(struct irc_network *s, struct irc_client *c, const struct irc_line *);
162 G_MODULE_EXPORT gboolean network_send_args(struct irc_network *s, ...);
163 G_MODULE_EXPORT void register_virtual_network(struct virtual_network_ops *);
164 G_MODULE_EXPORT struct virtual_network_ops *find_virtual_network(const char *name);
165 G_MODULE_EXPORT struct irc_network *find_network(GList *gl, const char *);
166 G_MODULE_EXPORT gboolean virtual_network_recv_line(struct irc_network *l, struct irc_line *);
167 G_MODULE_EXPORT gboolean virtual_network_recv_args(struct irc_network *l, const char *origin, ...);
168 G_MODULE_EXPORT gboolean virtual_network_recv_response(struct irc_network *n, int num, ...);
169 struct ctrlproxy_config;
170 G_MODULE_EXPORT G_GNUC_MALLOC struct linestack_context *new_linestack(struct irc_network *network, struct ctrlproxy_config *settings);
171 G_MODULE_EXPORT G_GNUC_MALLOC char *network_generate_feature_string(struct irc_network *n);
172 G_MODULE_EXPORT struct irc_network *irc_network_ref(struct irc_network *);
173 G_MODULE_EXPORT void irc_network_unref(struct irc_network *);
174 G_MODULE_EXPORT void unregister_virtual_networks(void);
176 #endif /* __CTRLPROXY_NETWORK_H__ */