ekg2
|
00001 /* 00002 * (C) Copyright 2004-2005 Michal 'GiM' Spadlinski <gim at skrzynka dot pl> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License Version 2 as 00006 * published by the Free Software Foundation. 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00016 */ 00017 00018 #ifndef __EKG_PLUGINS_IRC_IRC_H 00019 #define __EKG_PLUGINS_IRC_IRC_H 00020 00021 #define DOT(a,x,y,z,error) \ 00022 print_info("__status", z, a, session_name(z), x, y->hostname, y->address, \ 00023 itoa(y->port < 0 ? \ 00024 session_int_get(z, "port") < 0 ? DEFPORT : session_int_get(z, "port") : y->port), \ 00025 itoa(y->family), error ? strerror(error) : "") 00026 00027 #include <ekg/dynstuff.h> 00028 #include <ekg/plugins.h> 00029 #include <ekg/protocol.h> /* XXX, protocol_uid() */ 00030 #include <ekg/sessions.h> 00031 #include <ekg/windows.h> 00032 00033 #include "irc-ssl.h" 00034 00035 /* irc_private->sopt */ 00036 enum { USERMODES=0, CHANMODES, _005_PREFIX, _005_CHANTYPES, 00037 _005_CHANMODES, _005_MODES, _005_CHANLIMIT, _005_NICKLEN, _005_IDCHAN, SERVOPTS }; 00038 00039 /* irc_private_t->casemapping values */ 00040 enum { IRC_CASEMAPPING_ASCII, IRC_CASEMAPPING_RFC1459, IRC_CASEMAPPING_RFC1459_STRICT, IRC_CASEMAPPING_COUNT }; 00041 00042 typedef struct _irc_private_t { 00043 int fd; /* connection's fd */ 00044 int autoreconnecting; /* are we in reconnecting mode now? */ 00045 int resolving; /* count of resolver threads. */ 00046 list_t bindlist, bindtmplist; 00047 list_t connlist, conntmplist; 00048 00049 watch_t *recv_watch; 00050 watch_t *send_watch; 00051 00052 char *nick; /* guess again ? ;> */ 00053 char *host_ident; /* ident+host */ 00054 00055 #ifdef IRC_HAVE_SSL 00056 unsigned char using_ssl : 2; 00057 SSL_SESSION ssl_session; 00058 string_t ssl_buf; 00059 #endif 00060 00061 list_t people; /* list of people_t */ 00062 list_t channels; /* list of people_chan_t */ 00063 list_t hilights; 00064 00065 char *sopt[SERVOPTS]; /* just a few options from 00066 * www.irc.org/tech_docs/005.html 00067 * server's response */ 00068 int casemapping; 00069 00070 list_t awaylog; 00071 00072 list_t auto_guess_encoding; 00073 list_t out_recodes; 00074 list_t recoded_channels; 00075 00076 void *conv_in; 00077 void *conv_out; 00078 } irc_private_t; 00079 00080 /* data for private->auto_guess_encoding */ 00081 typedef struct { 00082 void *conv_in; 00083 void *conv_out; 00084 } conv_in_out_t; 00085 00086 /* data for private->out_recodes */ 00087 typedef struct { 00088 char *name; /* encoding name */ 00089 void *conv_in; 00090 void *conv_out; 00091 } out_recodes_t; 00092 00093 /* data for private->recoded_channels */ 00094 typedef struct { 00095 char *name; /* channel or nick */ 00096 out_recodes_t *recode; 00097 } recoded_channels_t; 00098 00099 typedef struct _irc_awaylog_t { 00100 char *channame; /* channel name, (null if priv) */ 00101 char *uid; /* nickname who wrote to us */ 00102 char *msg; /* msg */ 00103 time_t t; /* time_t when we recv message */ 00104 } irc_awaylog_t; 00105 00106 #define SOP(x) (j->sopt[x]) 00107 00108 /* data for private->people */ 00109 typedef struct { 00110 char *nick; 00111 char *realname; 00112 char *host, *ident; 00113 list_t channels; 00114 } people_t; 00115 00116 /* data for private->channels */ 00117 typedef struct { 00118 char *name; 00119 int syncmode; 00120 struct timeval syncstart; 00121 int mode; 00122 char *topic, *topicby, *mode_str; 00123 window_t *window; 00124 list_t onchan; 00125 char *nickpad_str; 00126 int nickpad_len, nickpad_pos; 00127 int longest_nick; 00128 list_t banlist; 00129 /* needed ? 00130 list_t exclist; 00131 list_t invlist; */ 00132 list_t acclist; 00133 } channel_t; 00134 00135 /* data for private->people->channels */ 00136 typedef struct { 00137 int mode; /* bitfield */ 00138 char sign[2]; 00139 channel_t *chanp; 00140 } people_chan_t; 00141 00142 /* structure needed by resolver */ 00143 typedef struct { 00144 session_t *session; 00145 char *hostname; 00146 char *address; 00147 int port; 00148 int family; 00149 } connector_t; 00150 00151 typedef struct { 00152 char *session; 00153 list_t *plist; 00154 int isbind; 00155 } irc_resolver_t; 00156 00157 #define irc_private(s) ((irc_private_t*) session_private_get(s)) 00158 00159 /* DO NOT TOUCH THIS! */ 00160 #define IRC4 "irc:" 00161 #define irc_uid(target) protocol_uid("irc", target) 00162 00163 extern plugin_t irc_plugin; 00164 00165 void irc_handle_disconnect(session_t *s, const char *reason, int type); 00166 00167 /* checks if name is in format irc:something 00168 * checkcon is one of: 00169 * name is channel | nick 00170 * IRC_GC_CHAN - channame | NULL 00171 * IRC_GC_NOT_CHAN - NULL | nickname 00172 * IRC_GC_ANY - name if it's in proper format [irc:something] 00173 */ 00174 enum { IRC_GC_CHAN=0, IRC_GC_NOT_CHAN, IRC_GC_ANY }; 00175 00176 #define irc_write(s, args...) watch_write((s && s->priv) ? irc_private(s)->send_watch : NULL, args); 00177 00178 int irc_parse_line(session_t *s, char *buf, int fd); /* misc.c */ 00179 00180 extern int irc_config_experimental_chan_name_clean; 00181 00182 char *nickpad_string_create(channel_t *chan); 00183 char *nickpad_string_apply(channel_t *chan, const char *str); 00184 char *nickpad_string_restore(channel_t *chan); 00185 00186 char *clean_channel_names(session_t *session, char *channels); 00187 00188 #endif /* __EKG_PLUGINS_IRC_IRC_H */ 00189 00190 /* 00191 * Local Variables: 00192 * mode: c 00193 * c-file-style: "k&r" 00194 * c-basic-offset: 8 00195 * indent-tabs-mode: t 00196 * End: 00197 */