aboutsummaryrefslogtreecommitdiffstats
path: root/irc.h
blob: b1d8b6efcee5e44710c488e780df323c941a1ce1 (plain)
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
  /********************************************************************\
  * BitlBee -- An IRC to other IM-networks gateway                     *
  *                                                                    *
  * Copyright 2002-2004 Wilmer van der Gaast and others                *
  \********************************************************************/

/* The IRC-based UI (for now the only one)                              */

/*
  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 with
  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef _IRC_H
#define _IRC_H

#define IRC_MAX_LINE 512
#define IRC_MAX_ARGS 8

#define IRC_LOGIN_TIMEOUT 60
#define IRC_PING_STRING "PinglBee"

#define UMODES "abisw"     /* Allowed umodes (although they mostly do nothing) */
#define UMODES_PRIV "Ro"   /* Allowed, but not by user directly */
#define UMODES_KEEP "R"    /* Don't allow unsetting using /MODE */
#define CMODES "nt"        /* Allowed modes */
#define CMODE "t"          /* Default mode */
#define UMODE "s"          /* Default mode */

#define CTYPES "&#"        /* Valid channel name prefixes */

typedef enum
{
	USTATUS_OFFLINE = 0,
	USTATUS_AUTHORIZED = 1,
	USTATUS_LOGGED_IN = 2,
	USTATUS_IDENTIFIED = 4,
	USTATUS_SHUTDOWN = 8
} irc_status_t;

struct irc_user;

typedef struct irc
{
	int fd;
	irc_status_t status;
	double last_pong;
	int pinging;
	char *sendbuffer;
	char *readbuffer;
	GIConv iconv, oconv;

	struct irc_user *root;
	struct irc_user *user;
	
	char *last_root_cmd;

	char *password; /* HACK: Used to save the user's password, but before
	                   logging in, this may contain a password we should
	                   send to identify after USER/NICK are received. */

	char umode[8];
	
	struct query *queries;
	struct account *accounts;
	GSList *file_transfers;
	
	GSList *users, *channels;
	GHashTable *nick_user_hash;
	GHashTable *watches;

	gint r_watch_source_id;
	gint w_watch_source_id;
	gint ping_source_id;
	
	struct bee *b;
} irc_t;

typedef enum
{
	IRC_USER_PRIVATE = 1,
} irc_user_flags_t;

typedef struct irc_user
{
	irc_t *irc;
	
	char *nick;
	char *user;
	char *host;
	char *fullname;
	
	/* Nickname in lowercase for case sensitive searches */
	char *key;
	
	irc_user_flags_t flags;
	
	char *sendbuf;
	int sendbuf_len;
	guint sendbuf_timer;
	//int sendbuf_flags;
	
	//struct user *b;
	
	const struct irc_user_funcs *f;
} irc_user_t;

struct irc_user_funcs
{
	gboolean (*privmsg)( irc_user_t *iu, const char *msg );
};

extern const struct irc_user_funcs irc_user_root_funcs;
extern const struct irc_user_funcs irc_user_self_funcs;

typedef enum
{
	IRC_CHANNEL_JOINED = 1,
} irc_channel_flags_t;

typedef struct irc_channel
{
	irc_t *irc;
	char *name;
	char mode[8];
	int flags;
	
	char *topic;
	char *topic_who;
	time_t topic_time;
	
	GSList *users;
	struct set *set;
	
	const struct irc_channel_funcs *f;
} irc_channel_t;

struct irc_channel_funcs
{
	gboolean (*privmsg)( irc_channel_t *iu, const char *msg );
};

#include "user.h"

/* irc.c */
extern GSList *irc_connection_list;

irc_t *irc_new( int fd );
void irc_abort( irc_t *irc, int immed, char *format, ... ) G_GNUC_PRINTF( 3, 4 );
void irc_free( irc_t *irc );

void irc_process( irc_t *irc );
char **irc_parse_line( char *line );
char *irc_build_line( char **cmd );

void irc_write( irc_t *irc, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
void irc_write_all( int now, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
void irc_vawrite( irc_t *irc, char *format, va_list params );

int irc_check_login( irc_t *irc );

void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv );

/* irc_channel.c */
irc_channel_t *irc_channel_new( irc_t *irc, const char *name );
irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name );
int irc_channel_free( irc_channel_t *ic );
int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu );
int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu );
int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who );
gboolean irc_channel_name_ok( const char *name );

/* irc_commands.c */
void irc_exec( irc_t *irc, char **cmd );

/* irc_send.c */
void irc_send_num( irc_t *irc, int code, char *format, ... ) G_GNUC_PRINTF( 3, 4 );
void irc_send_login( irc_t *irc );
void irc_send_motd( irc_t *irc );
void irc_usermsg( irc_t *irc, char *format, ... );
void irc_send_join( irc_channel_t *ic, irc_user_t *iu );
void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason );
void irc_send_names( irc_channel_t *ic );
void irc_send_topic( irc_channel_t *ic, gboolean topic_change );
void irc_send_whois( irc_user_t *iu );
void irc_send_who( irc_t *irc, GSList *l, const char *channel );
void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix );
void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const char *msg );

/* irc_user.c */
irc_user_t *irc_user_new( irc_t *irc, const char *nick );
int irc_user_free( irc_t *irc, const char *nick );
irc_user_t *irc_user_by_name( irc_t *irc, const char *nick );
int irc_user_rename( irc_t *irc, const char *old, const char *new );
gint irc_user_cmp( gconstpointer a_, gconstpointer b_ );

#endif