Fix SASL on some networks
[rofl0r-ixchat.git] / src / common / xchat.h
blob5c969462eb595ff467a374c7ebe9635a31b12053
1 #ifndef XCHAT_H
2 #define XCHAT_H
4 #include <glib.h>
5 #include <time.h> /* need time_t */
7 #include "version.h"
8 #include "history.h"
10 #define N_(String) (String)
11 #define _(x) (x)
13 #ifdef USE_DEBUG
14 #define malloc(n) xchat_malloc(n, __FILE__, __LINE__)
15 #define realloc(n, m) xchat_realloc(n, m, __FILE__, __LINE__)
16 #define free(n) xchat_dfree(n, __FILE__, __LINE__)
17 #define strdup(n) xchat_strdup(n, __FILE__, __LINE__)
18 void *xchat_malloc (int size, char *file, int line);
19 void *xchat_strdup (char *str, char *file, int line);
20 void xchat_dfree (void *buf, char *file, int line);
21 void *xchat_realloc (char *old, int len, char *file, int line);
22 #endif
24 #include <openssl/ssl.h> /* SSL_() */
26 /* force a 32bit CMP.L */
27 #define CMPL(a, c0, c1, c2, c3) (a == (guint32)(c0 | (c1 << 8) | (c2 << 16) | (c3 << 24)))
28 #define WORDL(c0, c1, c2, c3) (guint32)(c0 | (c1 << 8) | (c2 << 16) | (c3 << 24))
29 #define WORDW(c0, c1) (guint16)(c0 | (c1 << 8))
31 #define OFLAGS 0
33 #define FONTNAMELEN 127
34 #define PATHLEN 255
35 #define DOMAINLEN 100
36 #define NICKLEN 64 /* including the NULL, so 63 really */
37 #define CHANLEN 300
38 #define PDIWORDS 32
39 #define USERNAMELEN 10
40 #define HIDDEN_CHAR 8 /* invisible character for xtext */
42 struct nbexec
44 int myfd;
45 int childpid;
46 int tochannel; /* making this int keeps the struct 4-byte aligned */
47 int iotag;
48 char *linebuf;
49 int buffill;
50 struct session *sess;
53 struct xchatprefs
55 char nick1[NICKLEN];
56 char nick2[NICKLEN];
57 char nick3[NICKLEN];
58 char realname[127];
59 char username[127];
60 char nick_suffix[4]; /* Only ever holds a one-character string. */
61 char awayreason[256];
62 char quitreason[256];
63 char partreason[256];
64 char font_normal[FONTNAMELEN + 1];
65 char doubleclickuser[256];
66 char sounddir[PATHLEN + 1];
67 char soundcmd[PATHLEN + 1];
68 char background[PATHLEN + 1];
69 char dccdir[PATHLEN + 1];
70 char dcc_completed_dir[PATHLEN + 1];
71 char irc_extra_hilight[300];
72 char irc_no_hilight[300];
73 char irc_nick_hilight[300];
74 char dnsprogram[72];
75 char hostname[127];
76 char cmdchar[4];
77 char logmask[256];
78 char stamp_format[64];
79 char timestamp_log_format[64];
80 char irc_id_ytext[64];
81 char irc_id_ntext[64];
83 char proxy_host[64];
84 int proxy_port;
85 int proxy_type; /* 0=disabled, 1=wingate 2=socks4, 3=socks5, 4=http */
86 int proxy_use; /* 0=all 1=IRC_ONLY 2=DCC_ONLY */
87 unsigned int proxy_auth;
88 char proxy_user[32];
89 char proxy_pass[32];
91 int first_dcc_send_port;
92 int last_dcc_send_port;
94 int tint_red;
95 int tint_green;
96 int tint_blue;
98 int away_timeout;
99 int away_size_max;
101 int gui_pane_left_size;
102 int gui_pane_right_size;
104 int gui_ulist_pos;
105 int tab_pos;
107 int _tabs_position;
108 int tab_layout;
109 int max_auto_indent;
110 int dcc_blocksize;
111 int max_lines;
112 int notify_timeout;
113 int dcctimeout;
114 int dccstalltimeout;
115 int dcc_global_max_get_cps;
116 int dcc_global_max_send_cps;
117 int dcc_max_get_cps;
118 int dcc_max_send_cps;
119 int mainwindow_left;
120 int mainwindow_top;
121 int mainwindow_width;
122 int mainwindow_height;
123 int completion_sort;
124 int gui_win_state;
125 int gui_url_mod;
126 int gui_usermenu;
127 int gui_join_dialog;
128 int gui_quit_dialog;
129 int dialog_left;
130 int dialog_top;
131 int dialog_width;
132 int dialog_height;
133 int dccpermissions;
134 int recon_delay;
135 int bantype;
136 int userlist_sort;
137 guint32 local_ip;
138 guint32 dcc_ip;
139 char dcc_ip_str[DOMAINLEN + 1];
141 unsigned int tab_small;
142 unsigned int tab_sort;
143 unsigned int mainwindow_save;
144 unsigned int perc_color;
145 unsigned int perc_ascii;
146 unsigned int autosave;
147 unsigned int autodialog;
148 unsigned int autosave_url;
149 unsigned int autoreconnect;
150 unsigned int autoreconnectonfail;
151 unsigned int invisible;
152 unsigned int servernotice;
153 unsigned int wallops;
154 unsigned int skipmotd;
155 unsigned int autorejoin;
156 unsigned int colorednicks;
157 unsigned int chanmodebuttons;
158 unsigned int userlistbuttons;
159 unsigned int showhostname_in_userlist;
160 unsigned int nickcompletion;
161 unsigned int completion_amount;
162 unsigned int tabchannels;
163 unsigned int paned_userlist;
164 unsigned int autodccchat;
165 unsigned int autodccsend;
166 unsigned int autoresume;
167 unsigned int autoopendccsendwindow;
168 unsigned int autoopendccrecvwindow;
169 unsigned int autoopendccchatwindow;
170 unsigned int transparent;
171 unsigned int stripcolor;
172 unsigned int timestamp;
173 unsigned int fastdccsend;
174 unsigned int dcc_send_fillspaces;
175 unsigned int dcc_remove;
176 unsigned int slist_fav;
177 unsigned int slist_skip;
178 unsigned int slist_select;
179 unsigned int filterbeep;
181 unsigned int input_balloon_chans;
182 unsigned int input_balloon_hilight;
183 unsigned int input_balloon_priv;
184 unsigned int input_balloon_time;
186 unsigned int input_beep_chans;
187 unsigned int input_beep_hilight;
188 unsigned int input_beep_priv;
190 unsigned int input_flash_chans;
191 unsigned int input_flash_hilight;
192 unsigned int input_flash_priv;
194 unsigned int input_tray_chans;
195 unsigned int input_tray_hilight;
196 unsigned int input_tray_priv;
198 unsigned int truncchans;
199 unsigned int privmsgtab;
200 unsigned int irc_join_delay;
201 unsigned int logging;
202 unsigned int timestamp_logs;
203 unsigned int newtabstofront;
204 unsigned int dccwithnick;
205 unsigned int hidever;
206 unsigned int ip_from_server;
207 unsigned int raw_modes;
208 unsigned int show_away_once;
209 unsigned int show_away_message;
210 unsigned int auto_unmark_away;
211 unsigned int away_track;
212 unsigned int userhost;
213 unsigned int irc_whois_front;
214 unsigned int use_server_tab;
215 unsigned int notices_tabs;
216 unsigned int style_namelistgad;
217 unsigned int style_inputbox;
218 unsigned int windows_as_tabs;
219 unsigned int indent_nicks;
220 unsigned int text_replay;
221 unsigned int show_marker;
222 unsigned int show_separator;
223 unsigned int thin_separator;
224 unsigned int auto_indent;
225 unsigned int wordwrap;
226 unsigned int gui_input_spell;
227 unsigned int gui_tray;
228 unsigned int gui_tray_flags;
229 unsigned int gui_tweaks;
230 unsigned int _gui_ulist_left;
231 unsigned int throttle;
232 unsigned int topicbar;
233 unsigned int hideuserlist;
234 unsigned int hidemenu;
235 unsigned int perlwarnings;
236 unsigned int lagometer;
237 unsigned int throttlemeter;
238 unsigned int pingtimeout;
239 unsigned int whois_on_notifyonline;
240 unsigned int wait_on_exit;
241 unsigned int confmode;
242 unsigned int utf8_locale;
243 unsigned int identd;
245 unsigned int ctcp_number_limit; /*flood */
246 unsigned int ctcp_time_limit; /*seconds of floods */
248 unsigned int msg_number_limit; /*same deal */
249 unsigned int msg_time_limit;
251 unsigned int url_grabber;
252 unsigned int url_grabber_limit;
253 /* Tells us if we need to save, only when they've been edited.
254 This is so that we continue using internal defaults (which can
255 change in the next release) until the user edits them. */
256 unsigned int save_pevents:1;
259 /* Session types */
260 #define SESS_SERVER 1
261 #define SESS_CHANNEL 2
262 #define SESS_DIALOG 3
263 #define SESS_NOTICES 4
264 #define SESS_SNOTICES 5
266 /* Per-Channel Settings */
267 #define SET_OFF 0
268 #define SET_ON 1
269 #define SET_DEFAULT 2 /* use global setting */
271 typedef struct session
273 /* Per-Channel Alerts */
274 /* use a byte, because we need a pointer to each element */
275 guint8 alert_beep;
276 guint8 alert_taskbar;
277 guint8 alert_tray;
279 /* Per-Channel Settings */
280 guint8 text_hidejoinpart;
281 guint8 text_logging;
282 guint8 text_scrollback;
284 struct server *server;
285 void *usertree_alpha; /* pure alphabetical tree */
286 void *usertree; /* ordered with Ops first */
287 struct User *me; /* points to myself in the usertree */
288 char channel[CHANLEN];
289 char waitchannel[CHANLEN]; /* waiting to join channel (/join sent) */
290 char willjoinchannel[CHANLEN]; /* will issue /join for this channel */
291 char channelkey[64]; /* XXX correct max length? */
292 int limit; /* channel user limit */
293 int logfd;
294 int scrollfd; /* scrollback filedes */
295 int scrollwritten; /* number of lines written */
297 char lastnick[NICKLEN]; /* last nick you /msg'ed */
299 struct history history;
301 int ops; /* num. of ops in channel */
302 int hops; /* num. of half-oped users */
303 int voices; /* num. of voiced people */
304 int total; /* num. of users in channel */
306 char *quitreason;
307 char *topic;
308 char *current_modes; /* free() me */
310 int mode_timeout_tag;
312 struct session *lastlog_sess;
313 struct nbexec *running_exec;
315 struct session_gui *gui; /* initialized by fe_new_window */
316 struct restore_gui *res;
318 int type; /* SESS_* */
320 int new_data:1; /* new data avail? (purple tab) */
321 int nick_said:1; /* your nick mentioned? (blue tab) */
322 int msg_said:1; /* new msg available? (red tab) */
324 int ignore_date:1;
325 int ignore_mode:1;
326 int ignore_names:1;
327 int end_of_names:1;
328 int doing_who:1; /* /who sent on this channel */
329 int done_away_check:1; /* done checking for away status changes */
330 unsigned int lastlog_regexp:1; /* this is a lastlog and using regexp */
331 } session;
333 struct msproxy_state_t
335 gint32 clientid;
336 gint32 serverid;
337 unsigned char seq_recv; /* seq number of last packet recv. */
338 unsigned char seq_sent; /* seq number of last packet sent. */
341 /* SASL Mechanisms */
342 #define MECH_PLAIN 0
343 #define MECH_BLOWFISH 1
344 #define MECH_AES 2
345 #define MECH_EXTERNAL 3
347 typedef struct server
349 /* server control operations (in server*.c) */
350 void (*connect)(struct server *, char *hostname, int port, int no_login);
351 void (*disconnect)(struct session *, int sendquit, int err);
352 int (*cleanup)(struct server *);
353 void (*flush_queue)(struct server *);
354 void (*auto_reconnect)(struct server *, int send_quit, int err);
355 /* irc protocol functions (in proto*.c) */
356 void (*p_inline)(struct server *, char *buf, int len);
357 void (*p_invite)(struct server *, char *channel, char *nick);
358 void (*p_cycle)(struct server *, char *channel, char *key);
359 void (*p_ctcp)(struct server *, char *to, char *msg);
360 void (*p_nctcp)(struct server *, char *to, char *msg);
361 void (*p_quit)(struct server *, char *reason);
362 void (*p_kick)(struct server *, char *channel, char *nick, char *reason);
363 void (*p_part)(struct server *, char *channel, char *reason);
364 void (*p_ns_identify)(struct server *, char *pass);
365 void (*p_ns_ghost)(struct server *, char *usname, char *pass);
366 void (*p_join)(struct server *, char *channel, char *key);
367 void (*p_join_list)(struct server *, GSList *channels, GSList *keys);
368 void (*p_login)(struct server *, char *user, char *realname);
369 void (*p_join_info)(struct server *, char *channel);
370 void (*p_mode)(struct server *, char *target, char *mode);
371 void (*p_user_list)(struct server *, char *channel);
372 void (*p_away_status)(struct server *, char *channel);
373 void (*p_whois)(struct server *, char *nicks);
374 void (*p_get_ip)(struct server *, char *nick);
375 void (*p_get_ip_uh)(struct server *, char *nick);
376 void (*p_set_back)(struct server *);
377 void (*p_set_away)(struct server *, char *reason);
378 void (*p_message)(struct server *, char *channel, char *text);
379 void (*p_action)(struct server *, char *channel, char *act);
380 void (*p_notice)(struct server *, char *channel, char *text);
381 void (*p_topic)(struct server *, char *channel, char *topic);
382 void (*p_list_channels)(struct server *, char *arg, int min_users);
383 void (*p_change_nick)(struct server *, char *new_nick);
384 void (*p_names)(struct server *, char *channel);
385 void (*p_ping)(struct server *, char *to, char *timestring);
386 /* void (*p_set_away)(struct server *);*/
387 int (*p_raw)(struct server *, char *raw);
388 int (*p_cmp)(const char *s1, const char *s2);
390 int port;
391 int sok; /* is equal to sok4 or sok6 (the one we are using) */
392 int sok4; /* tcp4 socket */
393 int sok6; /* tcp6 socket */
394 int proxy_type;
395 int proxy_sok; /* Additional information for MS Proxy beast */
396 int proxy_sok4;
397 int proxy_sok6;
398 struct msproxy_state_t msp_state;
399 int id; /* unique ID number (for plugin API) */
400 #ifdef USE_OPENSSL
401 SSL *ssl;
402 int ssl_do_connect_tag;
403 #else
404 void *ssl;
405 #endif
406 int childread;
407 int childwrite;
408 int childpid;
409 int iotag;
410 int recondelay_tag; /* reconnect delay timeout */
411 int joindelay_tag; /* waiting before we send JOIN */
412 char hostname[128]; /* real ip number */
413 char servername[128]; /* what the server says is its name */
414 char password[86];
415 char nick[NICKLEN];
416 char linebuf[2048]; /* RFC says 512 chars including \r\n */
417 char *last_away_reason;
418 int pos; /* current position in linebuf */
419 int nickcount;
420 int loginmethod; /* see login_types[] */
422 char *chantypes; /* for 005 numeric - free me */
423 char *chanmodes; /* for 005 numeric - free me */
424 char *nick_prefixes; /* e.g. "*@%+" */
425 char *nick_modes; /* e.g. "aohv" */
426 char *bad_nick_prefixes; /* for ircd that doesn't give the modes */
427 int modes_per_line; /* 6 on undernet, 4 on efnet etc... */
429 void *network; /* points to entry in servlist.c or NULL! */
431 GSList *outbound_queue;
432 time_t next_send; /* cptr->since in ircu */
433 time_t prev_now; /* previous now-time */
434 int sendq_len; /* queue size */
435 int lag; /* milliseconds */
437 struct session *front_session; /* front-most window/tab */
438 struct session *server_session; /* server window/tab */
440 struct server_gui *gui; /* initialized by fe_new_server */
442 unsigned int ctcp_counter; /*flood */
443 time_t ctcp_last_time;
445 unsigned int msg_counter; /*counts the msg tab opened in a certain time */
446 time_t msg_last_time;
448 /*time_t connect_time;*/ /* when did it connect? */
449 time_t lag_sent;
450 time_t ping_recv; /* when we last got a ping reply */
451 time_t away_time; /* when we were marked away */
453 char *encoding; /* NULL for system */
454 char *autojoin; /* list of channels & keys to join */
456 unsigned int motd_skipped:1;
457 unsigned int connected:1;
458 unsigned int connecting:1;
459 unsigned int no_login:1;
460 unsigned int skip_next_userhost:1;/* used for "get my ip from server" */
461 unsigned int skip_next_whois:1; /* hide whois output */
462 unsigned int inside_whois:1;
463 unsigned int doing_dns:1; /* /dns has been done */
464 unsigned int retry_sasl:1; /* retrying another sasl mech */
465 unsigned int end_of_motd:1; /* end of motd reached (logged in) */
466 unsigned int sent_quit:1; /* sent a QUIT already? */
467 unsigned int use_listargs:1; /* undernet and dalnet need /list >0,<10000 */
468 unsigned int is_away:1;
469 unsigned int reconnect_away:1; /* whether to reconnect in is_away state */
470 unsigned int dont_use_proxy:1; /* to proxy or not to proxy */
471 unsigned int supports_watch:1; /* supports the WATCH command */
472 unsigned int supports_monitor:1; /* supports the MONITOR command */
473 unsigned int bad_prefix:1; /* gave us a bad PREFIX= 005 number */
474 unsigned int have_namesx:1; /* 005 tokens NAMESX and UHNAMES */
475 unsigned int have_awaynotify:1;
476 unsigned int have_uhnames:1;
477 unsigned int have_whox:1; /* have undernet's WHOX features */
478 unsigned int have_idmsg:1; /* freenode's IDENTIFY-MSG */
479 unsigned int have_accnotify:1; /* cap account-notify */
480 unsigned int have_extjoin:1; /* cap extended-join */
481 unsigned int have_server_time:1; /* cap server-time */
482 unsigned int have_sasl:1; /* SASL capability */
483 unsigned int have_except:1; /* ban exemptions +e */
484 unsigned int have_cert:1; /* have loaded a cert */
485 unsigned int using_cp1255:1; /* encoding is CP1255/WINDOWS-1255? */
486 unsigned int using_irc:1; /* encoding is "IRC" (CP1252/UTF-8 hybrid)? */
487 unsigned int use_who:1; /* whether to use WHO command to get dcc_ip */
488 unsigned int sasl_mech; /* mechanism for sasl auth */
489 unsigned int sent_saslauth:1; /* have sent AUTHENICATE yet */
490 unsigned int sent_capend:1; /* have sent CAP END yet */
491 unsigned int use_ssl:1; /* is server SSL capable? */
492 unsigned int accept_invalid_cert:1;/* ignore result of server's cert. verify */
493 } server;
495 typedef int (*cmd_callback) (struct session * sess, char *tbuf, char *word[],
496 char *word_eol[]);
498 struct commands
500 char *name;
501 cmd_callback callback;
502 char needserver;
503 char needchannel;
504 gint16 handle_quotes;
505 char *help;
508 struct away_msg
510 struct server *server;
511 char nick[NICKLEN];
512 char *message;
515 /* not just for popups, but used for usercommands, ctcp replies,
516 userlist buttons etc */
518 struct popup
520 char *cmd;
521 char *name;
524 /* CL: get a random int in the range [0..n-1]. DON'T use rand() % n, it gives terrible results. */
525 #define RAND_INT(n) ((int)(rand() / (RAND_MAX + 1.0) * (n)))
527 #define xchat_filename_from_utf8 g_locale_from_utf8
528 #define xchat_filename_to_utf8 g_locale_to_utf8
530 #endif