File: libirc.h

package info (click to toggle)
ayttm 0.6.3-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 8,372 kB
  • ctags: 8,851
  • sloc: ansic: 65,755; sh: 10,810; cpp: 3,092; makefile: 564; yacc: 294; lex: 53; sed: 16
file content (513 lines) | stat: -rw-r--r-- 14,436 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/*
 * IRC protocol Implementation
 *
 * Copyright (C) 2008, Siddhesh Poyarekar and the Ayttm Team
 *
 * Some code Copyright (C) 2001, Erik Inge Bolso <knan@mo.himolde.no>
 *                     and others
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef _LIB_IRC_H_
#define _LIB_IRC_H_

#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

#include "intl.h"

#ifdef __MINGW32__
#define __IN_PLUGIN__ 1
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#endif

/* RFC1459 and RFC2812 defines max message size
   including \n == 512 bytes, but being tolerant of
   violations is nice nevertheless. */
#define BUF_LEN 512*2

enum {
	IRC_NOECHO = 1,
	IRC_ECHO_ACTION,
	IRC_ECHO_KICK
};

/* from util.c :
 *
 * The last state in the list of states will be the OFFLINE state
 * The first state in the list will be the ONLINE states
 * The rest of the states are the various AWAY states
 */

enum {
	IRC_ONLINE = 0,
	IRC_AWAY,
	IRC_INVISIBLE,
	IRC_OFFLINE,
	IRC_STATE_COUNT
};

enum {
	IRC_SIGNON_ONLINE = 0,
	IRC_SIGNON_INVISIBLE = 8
};

/* User modes */
enum {
	IRC_USER_MODE_AWAY = 1,
	IRC_USER_MODE_INVISIBLE = 1 << 1,
	IRC_USER_MODE_RECEIVE_WALLOPS = 1 << 2,
	IRC_USER_MODE_RESTRICT_USER_CONNECTION = 1 << 3,
	IRC_USER_MODE_OPER = 1 << 4,
	IRC_USER_MODE_LOCAL_OPER = 1 << 5,
	IRC_USER_MODE_RECEIVE_SERVER_NOTICES = 1 << 6
};

/* Message Prefix */
typedef struct {
	char *nick;
	char *servername;
	char *user;
	char *hostname;
} irc_message_prefix;

/* Parameter List element */
typedef struct _irc_param_list {
	char *param;
	struct _irc_param_list *next;
} irc_param_list;

struct _irc_callbacks;

typedef struct {
	char connect_address[255];
	char port[16];
	char *nick;
	char *servername;
	char *hostname;
	char *user;
	int fd;

	int status;
	char *usermodes;
	char *channelmodes;

	struct _irc_callbacks *callbacks;

	/* Store partial messages in this */
	char buf[BUF_LEN];
	int len;

	void *data;
} irc_account;

typedef struct _namelist {
	char *name;
	char attribute;
	struct _namelist *next;
} irc_name_list;

typedef struct _irc_callbacks {

	void (*incoming_notice) (const char *to,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*buddy_quit) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*buddy_join) (const char *channel,
		irc_message_prefix *prefix, irc_account *ia);

	void (*buddy_part) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_invite) (const char *to,
		const char *channel,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_kick) (const char *to,
		const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*nick_change) (const char *newnick,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_privmsg) (const char *recipient,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_ping) (const char *server, irc_account *ia);

	void (*got_welcome) (const char *nick,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_yourhost) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_created) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_myinfo) (const char *servername,
		const char *version,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_channel_list) (const char *me,
		const char *channel,
		int users,
		const char *topic, irc_message_prefix *prefix, irc_account *ia);

	void (*got_channel_listend) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_away) (const char *from,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_unaway) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_nowaway) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_ison) (const char *userlist,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_whoisidle) (const char *from,
		int since,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_whoisuser) (const char *nick,
		const char *user,
		const char *host,
		const char *real_name,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_whoisserver) (const char *nick,
		const char *server,
		const char *info, irc_message_prefix *prefix, irc_account *ia);

	void (*got_whoisop) (const char *nick,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_whowasuser) (const char *nick,
		const char *user,
		const char *host,
		const char *real_name,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_endofwhois) (const char *nicks,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_endofwhowas) (const char *nicks,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_notopic) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_topic) (const char *channel,
		const char *topic, irc_message_prefix *prefix, irc_account *ia);

	void (*got_topicsetby) (const char *channel,
		const char *nickname,
		const char *time, irc_message_prefix *prefix, irc_account *ia);

	void (*inviting) (const char *channel,
		const char *nick, irc_message_prefix *prefix, irc_account *ia);

	void (*summoning) (const char *user,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_version) (const char *version,
		const char *debuglevel,
		const char *server,
		const char *comments,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_info) (const char *info,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_endinfo) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*motd_start) (const char *server,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_motd) (const char *motd,
		irc_message_prefix *prefix, irc_account *ia);

	void (*endofmotd) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_endofwho) (const char *name,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_endofnames) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*youreoper) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_namelist) (irc_name_list *list,
		const char *channel,
		irc_message_prefix *prefix, irc_account *ia);

	void (*got_time) (const char *time,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_send_data) (void *buf, int len, irc_account *ia);

	void (*irc_error) (const char *message, void *data);

	void (*irc_warning) (const char *message, void *data);

	void (*client_quit) (irc_account *ia);

	/* ERROR HANDLERS */

	void (*irc_no_such_nick) (const char *nick,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_such_server) (const char *server,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_such_channel) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_cant_sendto_chnl) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_was_no_such_nick) (const char *nick,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_too_many_chnl) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_too_many_targets) (const char *target,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_origin) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_recipient) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_text_to_send) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_toplevel) (const char *mask,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_wild_toplevel) (const char *mask,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_unknown_cmd) (const char *command,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_motd) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_admininfo) (const char *server,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_file_error) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_nick_given) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_erroneous_nick) (const char *nick,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_nick_in_use) (const char *nick,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_nick_collision) (const char *nick,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_user_not_in_chnl) (const char *nick,
		const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_not_on_chnl) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_on_chnl) (const char *user,
		const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_nologin) (const char *nick,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_summon_disabled) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_user_disabled) (const char *user_disabled,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_not_registered) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_need_more_params) (const char *cmd,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_already_registered) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_perm_for_host) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_password_mismatch) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_banned) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_chnl_key_set) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_channel_full) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_unknown_mode) (const char *mode,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_invite_only) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_banned_from_chnl) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_bad_chnl_key) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_privileges) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_chnlop_privs_needed) (const char *channel,
		const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_cant_kill_server) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_no_o_per_host) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_mode_unknown) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

	void (*irc_user_dont_match) (const char *message,
		irc_message_prefix *prefix, irc_account *ia);

} irc_callbacks;

void irc_message_parse(char *incoming, irc_account *ia);

/* Local prototypes */

void irc_login(const char *password, int mode, irc_account *ia);
void irc_logout(irc_account *ia);

int irc_send_privmsg(const char *recipient, char *message, irc_account *ia);
void irc_send_notice(const char *recipient, char *message, irc_account *ia);

void irc_send_whois(const char *target, const char *mask, irc_account *ia);

void irc_get_names_list(const char *channel, irc_account *ia);

void irc_process_privmsg(const char *to, const char *message,
	irc_message_prefix *prefix, irc_account *ia);
void irc_process_notice(const char *to, const char *message,
	irc_message_prefix *prefix, irc_account *ia);

void irc_set_away(char *message, irc_account *ia);
void irc_set_mode(int irc_mode, irc_account *ia);
void irc_unset_mode(int irc_mode, irc_account *ia);
void irc_join(const char *room, irc_account *ia);
void irc_leave_chat_room(const char *room, irc_account *ia);
void irc_send_invite(const char *user, const char *room,
	const char *message, irc_account *ia);
void irc_send_pong(const char *servername, irc_account *ia);

/* Add and return the new head of list */
irc_param_list *irc_param_list_add(irc_param_list *param_list,
	const char *param);
char *irc_param_list_get_at(irc_param_list *param_list, int position);

/* Get the parameter at */
char *irc_param_list_get_at(irc_param_list *list, int offset);

void irc_param_list_free(irc_param_list *param_list);

irc_name_list *irc_gen_name_list(char *message);

int irc_recv(irc_account *ia, char *buf, int len);

int irc_get_command_string(char *out, const char *recipient, char *command,
	char *params, irc_account *ia);

void irc_request_list(const char *channel, const char *target, irc_account *ia);

#endif