00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CTRLPROXY_NETWORK_H__
00021 #define __CTRLPROXY_NETWORK_H__
00022
00028 #include <glib.h>
00029
00030 #ifndef G_MODULE_EXPORT
00031 #define G_MODULE_EXPORT
00032 #endif
00033
00034 #include "state.h"
00035 #include "isupport.h"
00036 #include <sys/socket.h>
00037
00038 #define DEFAULT_NETWORK_CHARSET NULL
00039
00040 struct global;
00041 struct irc_network;
00042 struct irc_client;
00043 struct irc_line;
00044 struct linestack_context;
00045
00046 enum network_connection_state {
00047 NETWORK_CONNECTION_STATE_NOT_CONNECTED = 0,
00048 NETWORK_CONNECTION_STATE_RECONNECT_PENDING,
00049 NETWORK_CONNECTION_STATE_CONNECTING,
00050 NETWORK_CONNECTION_STATE_CONNECTED,
00051 NETWORK_CONNECTION_STATE_LOGIN_SENT,
00052 NETWORK_CONNECTION_STATE_MOTD_RECVD,
00053 };
00054
00058 struct network_connection {
00059 enum network_connection_state state;
00060
00062 time_t last_line_sent;
00064 time_t last_line_recvd;
00065
00066 struct irc_transport *transport;
00067 union {
00068 struct {
00070 struct tcp_server_config *current_server;
00072 struct sockaddr *remote_name;
00074 struct sockaddr *local_name;
00076 socklen_t namelen;
00078 char *last_disconnect_reason;
00080 gint ping_id;
00082 gint connect_id;
00083 } tcp;
00084
00085 struct {
00086 void *private_data;
00087 struct virtual_network_ops {
00088 char *name;
00089 gboolean not_disconnectable;
00090 gboolean (*init) (struct irc_network *);
00091 gboolean (*to_server) (struct irc_network *, struct irc_client *c, const struct irc_line *);
00092 void (*fini) (struct irc_network *);
00093 } *ops;
00094 } virtual;
00095 } data;
00096 };
00097
00098 typedef void (*network_log_fn) (enum log_level, void *, const char *);
00099
00103 struct irc_network {
00105 struct global *global;
00106
00108 struct network_config *config;
00109
00111 int references;
00112
00114 GList *clients;
00115 guint reconnect_id;
00116
00117 gpointer ssl_credentials;
00118
00120 struct irc_network_state *state;
00121
00123 struct irc_network_info *info;
00124 struct network_connection connection;
00125
00127 struct linestack_context *linestack;
00128
00129 void *userdata;
00130 network_log_fn log;
00131
00132 int reconnect_interval;
00133
00134 gboolean (*process_from_server) (struct irc_network *, const struct irc_line *);
00135 };
00136
00137
00138 G_MODULE_EXPORT gboolean network_set_charset(struct irc_network *n, const char *name);
00139 G_MODULE_EXPORT gboolean autoconnect_networks(GList *);
00140 G_MODULE_EXPORT struct irc_network *irc_network_new(gboolean (*process_from_server) (struct irc_network *, const struct irc_line *), struct network_config *sc);
00141 G_MODULE_EXPORT gboolean connect_network(struct irc_network *);
00142 G_MODULE_EXPORT void network_select_next_server(struct irc_network *n);
00143 G_MODULE_EXPORT gboolean disconnect_network(struct irc_network *s);
00144 G_MODULE_EXPORT gboolean network_send_line(struct irc_network *s, struct irc_client *c, const struct irc_line *, gboolean);
00145 G_MODULE_EXPORT gboolean network_send_args(struct irc_network *s, ...);
00146 G_MODULE_EXPORT void register_virtual_network(struct virtual_network_ops *);
00147 G_MODULE_EXPORT struct irc_network *find_network(GList *gl, const char *);
00148 G_MODULE_EXPORT gboolean virtual_network_recv_line(struct irc_network *l, struct irc_line *);
00149 G_MODULE_EXPORT gboolean virtual_network_recv_args(struct irc_network *l, const char *origin, ...);
00150 G_MODULE_EXPORT gboolean virtual_network_recv_response(struct irc_network *n, int num, ...);
00151 G_MODULE_EXPORT G_GNUC_MALLOC struct linestack_context *new_linestack(struct irc_network *network);
00152 G_MODULE_EXPORT G_GNUC_MALLOC char *network_generate_feature_string(struct irc_network *n);
00153 G_MODULE_EXPORT struct irc_network *network_ref(struct irc_network *);
00154 G_MODULE_EXPORT void network_unref(struct irc_network *);
00155 G_MODULE_EXPORT void network_set_log_fn(struct irc_network *s,
00156 network_log_fn, void *userdata);
00157
00158 #endif