File: server.h

package info (click to toggle)
ircii 20051015-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,996 kB
  • ctags: 3,193
  • sloc: ansic: 44,257; makefile: 1,144; sh: 522; perl: 127; lex: 26
file content (217 lines) | stat: -rw-r--r-- 7,892 bytes parent folder | download | duplicates (3)
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
/*
 * server.h: header for server.c 
 *
 * Written By Michael Sandrof
 *
 * Copyright (c) 1990 Michael Sandrof.
 * Copyright (c) 1991, 1992 Troy Rollo.
 * Copyright (c) 1992-2005 Matthew R. Green.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @(#)$eterna: server.h,v 1.69 2005/04/03 02:35:07 mrg Exp $
 */

#ifndef __server_h_
#define __server_h_
  
/* for ChannelList */
#include "names.h"

/*
 * type definition to distinguish different
 * server versions
 */
#define ServerICB	-5
#define Server2_5	0
#define Server2_6	1
#define Server2_7	2
#define Server2_8	3
#define Server2_9	4
#define Server2_10	5
#define Server2_11	6

/* Server: a structure for the server_list */
typedef	struct
{
	u_char	*name;			/* the name of the server */
	u_char	*itsname;		/* the server's idea of its name */
	u_char	*password;		/* password for that server */
	int	port;			/* port number on that server */
	u_char	*nickname;		/* nickname for this server */
	u_char	*away;			/* away message for this server */
	int	operator;		/* true if operator */
	int	version;		/* the version of the server -
					 * defined above */
	u_char	*version_string;	/* what is says */
	int	whois;			/* true if server sends numeric 318 */
	int	flags;			/* Various flags */
	int	connected;		/* true if connection is assured */
	int	write;			/* write descriptor */
	int	read;			/* read descriptior */
	pid_t	pid;			/* process id of server */
	int	eof;			/* eof flag for server */
	int	motd;			/* motd flag (used in notice.c) */
	int	sent;			/* set if something has been sent,
					 * used for redirect */
	u_char	*buffer;		/* buffer of what dgets() doesn't get */
	WhoisQueue	*WQ_head;	/* WHOIS Queue head */
	WhoisQueue	*WQ_tail;	/* WHOIS Queue tail */
	WhoisStuff	whois_stuff;	/* Whois Queue current collection buf */
	int	close_serv;		/* Server to close when LOGGED_IN */
	time_t	ctcp_last_reply_time;	/* used to limit flooding */
	time_t  ctcp_flood_time;
	int	ctcp_backlog_size;
        int     *ctcp_send_size;
	u_char	*group;			/* ICB group */
	u_char	*icbmode;		/* ICB initial mode */
	ChannelList	*chan_list;	/* list of channels for this server */
					/* pointer to parser for this server */
	void	(*parse_server)(u_char *);
	int	server_group;		/* group this server belongs to */
	int	attempting_to_connect;	/* are we trying to connect this server? */
	struct	addrinfo *res, *res0;	/* current lookup; for non blocking support */
	SOCKADDR_STORAGE *localaddr;	/* currently bound local port */
	int 	localaddrlen;		/* length of above */
}	Server;

/* SGroup: a structure for server groups. */
typedef struct ser_group_list
{
	struct ser_group_list	*next;
	u_char	*name;
	int	number;
}	SGroup;

typedef	unsigned	short	ServerType;

	int	find_server_group(u_char *, int);
	u_char *	find_server_group_name(int);
	void	add_to_server_list(u_char *, int, u_char *, u_char *,
				   int, int, int);
/* flags for add_to_server_list() */
#define SL_ADD_OVERWRITE	0x1
	void	build_server_list(u_char *);
	int	connect_to_server(u_char *, int, u_char *, int);
	void	get_connected(int);
	int	read_server_file(void);
	void	display_server_list(void);
	void	do_server(fd_set *, fd_set *);
	void	send_to_server(char *, ...);
	int	get_server_whois(int);

	WhoisStuff	*get_server_whois_stuff(int);
	WhoisQueue	*get_server_qhead(int);
	WhoisQueue	*get_server_qtail(int);

extern	int	save_chan_from;	/* to keep the channel list if all servers
				 * are lost */

extern	int	number_of_servers;
extern	int	connected_to_server;
extern	int	never_connected;
extern	int	using_server_process;
extern	int	primary_server;
/*
 * server we're currently interested in; set for window operations or
 * pretending to be on another server.
 */
extern	int	from_server;
/* set to the server we last got a message from */
extern	int	parsing_server_index;
extern	SGroup	*server_group_list;

	void	add_server_to_server_group(int, u_char *);
	void	servercmd(u_char *, u_char *, u_char *);
	u_char	*get_server_nickname(int);
	u_char	*get_server_name(int);
	u_char	*get_server_itsname(int);
	void	set_server_flag(int, int, int);
	int	find_in_server_list(u_char *, int, u_char *);
	u_char	*create_server_list(void);
	void	remove_from_server_list(int);
	void	set_server_motd(int, int);
	int	get_server_motd(int);
	int	get_server_operator(int);
	int	get_server_2_6_2(int);
	int	get_server_version(int);
	u_char	*get_server_password(int);
	u_char	*get_server_icbgroup(int);
	u_char	*get_server_icbmode(int);
	void	close_server(int, u_char *);
	void	MarkAllAway(u_char *, u_char *);
	int	is_server_connected(int);
	void	flush_server(void);
	int	get_server_flag(int, int);
	void	set_server_operator(int, int);
	void	server_is_connected(int, int);
	int	parse_server_index(u_char *);
	void	parse_server_info(u_char **, u_char **, u_char **,
				  u_char **, u_char **, u_char **, int *);
	void	set_server_bits(fd_set *, fd_set *);
	void	set_server_itsname(int, u_char *);
	void	set_server_version(int, int);
	int	is_server_open(int);
	int	get_server_port(int);
	u_char	*set_server_password(int, u_char *);
	void	set_server_nickname(int, u_char *);
	void	set_server_2_6_2(int, int);
	void	set_server_qhead(int, WhoisQueue *);
	void	set_server_qtail(int, WhoisQueue *);
	void	set_server_whois(int, int);
	void	set_server_icbgroup(int, u_char *);
	void	set_server_icbmode(int, u_char *);
	void	set_server_server_group(int, int);
	void	close_all_server(void);
	void	disconnectcmd(u_char *, u_char *, u_char *);
	void	ctcp_reply_backlog_change(int);
	SOCKADDR_STORAGE *get_server_localaddr(int);
	int	get_server_localaddrlen(int);
	int	 active_server_group(int sgroup);

	/* server_list: the list of servers that the user can connect to,etc */
	extern	Server	*server_list;

#define	USER_MODE_I	0x0001
#define	USER_MODE_W	0x0002
#define	USER_MODE_S	0x0004 /* obsolete */
#define	USER_MODE_R	0x0008
#define	USER_MODE_A	0x0010 /* away status, not really used */
#define	USER_MODE_Z	0x0020
#define	SERVER_2_6_2	0x0100
#define CLOSE_PENDING	0x0200	/* set for servers who are being switched
				away from, but have not yet connected. */
#define LOGGED_IN	0x0400
#define	CLEAR_PENDING	0x0800	/* set for servers whose channels are to be
				removed when a connect has been established. */
#define	SERVER_FAKE	0x1000	/* server is fake entry; not connected to yet.
				will be GCed after connect_to_server_*(). */

/* pick the default port if none is given. */
#define	CHOOSE_PORT(type) \
	(((type) == ServerICB || ((type) == -1 && client_default_icb)) \
		? icb_port : irc_port)

#endif /* __server_h_ */