isc.h 6.71 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
2
3
/*
** isc.h                        structures and defines used in a ISC server
**
Per Cederqvist's avatar
Per Cederqvist committed
4
** Copyright (C) 1991, 1996, 1998-1999, 2001 by Peter Eriksson and
Per Cederqvist's avatar
Per Cederqvist committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
** Per Cederqvist of the Lysator Academic Computer Association.
**
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Library General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This library 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
** Library General Public License for more details.
**
** You should have received a copy of the GNU Library General Public
** License along with this library; if not, write to the Free
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Per Cederqvist's avatar
Per Cederqvist committed
21
22
23
24
25
**
** history:
** 910306 pen      major overhaul
** 910307 pen      type name changes, changes in structs..
** 920207 pen      updated
Per Cederqvist's avatar
Per Cederqvist committed
26
** (See ChangeLog for recent history)
Per Cederqvist's avatar
Per Cederqvist committed
27
28
29
30
31
32
33
34
35
36
37
38
*/

#ifndef __ISC_H__
#define __ISC_H__

/*
** Give the poor user a chance to change it
*/
#ifndef ISC_UDGTYPE
#  define ISC_UDGTYPE void
#endif

39
40
41
/* Forward declarations. */
struct isc_mcb;
struct isc_scb;
Per Cederqvist's avatar
Per Cederqvist committed
42
43

/*
44
45
 * Callback function types.
 */
Per Cederqvist's avatar
Per Cederqvist committed
46

47
/* When a new TCP client conntects.  */
48
typedef void *isc_accept_callback(struct isc_scb *cb_accepting_session,
49
				  struct isc_scb *cb_new_session);
Per Cederqvist's avatar
Per Cederqvist committed
50

51
52
typedef void isc_write_error_cb(struct isc_scb *cb_session,
				int saved_errno);
Per Cederqvist's avatar
Per Cederqvist committed
53

54
typedef void isc_stale_output_cb(struct isc_scb *cb_session);
55

56
57
typedef void isc_write_queue_change_cb(int delta_bytes);

Per Cederqvist's avatar
Per Cederqvist committed
58
59
60
/*
** The different session states
*/
61
enum isc_session_state
Per Cederqvist's avatar
Per Cederqvist committed
62
63
64
65
{
  ISC_STATE_RUNNING,
  ISC_STATE_DISABLED,
  ISC_STATE_CLOSING,
66
67
  ISC_STATE_LISTENING,
};
Per Cederqvist's avatar
Per Cederqvist committed
68
69
70
71
72


/*
** Session control structure
*/
73
union isc_address;
74
struct isc_scb
Per Cederqvist's avatar
Per Cederqvist committed
75
76
{
  int                 fd;
77
78
  union isc_address *raddr;
  union isc_address *laddr;
Per Cederqvist's avatar
Per Cederqvist committed
79
80
81
  
  ISC_UDGTYPE       * udg;   /* User defined garbage :-) */

82
  struct isc_mcb      *master;
Per Cederqvist's avatar
Per Cederqvist committed
83
84
85
86
87
88
};




/*
89
** Setup a set of functions to handle memory allocation
Per Cederqvist's avatar
Per Cederqvist committed
90
*/
91
92
93
94
extern void
isc_setallocfn(void  * (*mallocfn)(size_t size),
               void  * (*reallocfn)(void  * buf, size_t size),
	       void    (*freefn)(void  * buf));
Per Cederqvist's avatar
Per Cederqvist committed
95
96
97
98

/*
** This routine will setup the ISC subsystem
*/
99
extern struct isc_mcb *
100
101
isc_initialize(oop_source *,
	       isc_write_queue_change_cb *);
Per Cederqvist's avatar
Per Cederqvist committed
102

103
104
extern void
isc_cfg_fd_relocate(struct isc_mcb *, int fd_relocate);
Per Cederqvist's avatar
Per Cederqvist committed
105

106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
** Configure timeouts for when a client will be disconnected.  If the
** output buffer is full and nothing can be written to the cilent for
** a period longer than STALE the client will be disconnected.  If
** nothing is written to it for a period longer than DEFAULT_IDLE, it
** will be disconnected.  DEFAULT_IDLE must always be larger than
** STALE.
**
** The client is actually not disconnected by ISC.  Instead, one of
** the callback functions stale_output_cb and idle_cb, registered with
** isc_set_read_callback(), will be called when the condition occurs.
** It should make sure that the client is closed (but it need not do
** so right away).
*/
120
extern void
121
122
123
isc_cfg_stale_timeout(struct isc_mcb *,
		      struct timeval stale,
		      struct timeval default_idle);
124

125
126
127
128
129
130
131
extern void
isc_cfg_queue_size(struct isc_mcb *,
		   int max_queue_size_bytes,
		   int max_msg_size,
		   int max_queue_size_msgs,
		   int max_dequeue_msgs);

Per Cederqvist's avatar
Per Cederqvist committed
132
133
134
135
136
137

/*
** Shut down all sessions associated with an ISC Master Control Block
** and deallocate all storage used by the MCB.
*/
extern void
138
isc_shutdown(struct isc_mcb  * mcb);
Per Cederqvist's avatar
Per Cederqvist committed
139
140
141
142
143
144
145



/*
** Establish a TCP port to listen for connections at
*/

146
147
148
149
150
extern struct isc_scb *
isc_listentcp(struct isc_mcb   * mcb,
	      const char  * address,
	      const char  * service,
	      isc_accept_callback *cb);
Per Cederqvist's avatar
Per Cederqvist committed
151
152

/*
153
154
155
** The callback function supplied to isc_listentcp can call this
** function to install a callback that will be called when data is
** available on the new socket.
Per Cederqvist's avatar
Per Cederqvist committed
156
157
*/
extern void
158
159
160
isc_set_read_callback(struct isc_scb *session,
		      oop_call_fd *data_available_cb,
		      isc_write_error_cb *write_error_cb,
161
		      isc_stale_output_cb *stale_output_cb,
162
		      isc_stale_output_cb *idle_cb);
Per Cederqvist's avatar
Per Cederqvist committed
163

164
165
166
167
168
/*
** Dynamically change the acceptable idle timeout of a session.  This
** can be used to increase the timeout once the initial handshake is
** complete, or once the user has logged on.  (It could even be used
** to lower it if a certain person logs on... -- I'm talking about
169
** robots whose sessions should be short-lived, of course.)
170
171
172
173
174
*/
extern void
isc_set_acceptable_idle(struct isc_scb *session,
			struct timeval acceptable);

Per Cederqvist's avatar
Per Cederqvist committed
175
extern int
176
isc_destroy(struct isc_mcb  * mcb, struct isc_scb  * scb);
Per Cederqvist's avatar
Per Cederqvist committed
177
178

/*
179
180
** Read data from a session into the end of a string.  The first
** UNUSED bytes of the string are unused, and may be reused.
Per Cederqvist's avatar
Per Cederqvist committed
181
*/
182
183
184
185
186
187
188
enum isc_read_result {
    ISC_READ_DATA,
    ISC_READ_LOGOUT,
    ISC_READ_WOULDBLOCK,
    ISC_READ_ERROR,		/* read() failed unexpectedly -- see errno. */
    ISC_READ_NOMEM,		/* out of memory. */
};
Per Cederqvist's avatar
Per Cederqvist committed
189

190
191
192
193
extern enum isc_read_result
isc_read_data(struct isc_scb *scb,
	      String *result,
	      String_size *unused);
Per Cederqvist's avatar
Per Cederqvist committed
194
195


Per Cederqvist's avatar
Per Cederqvist committed
196
 
Per Cederqvist's avatar
Per Cederqvist committed
197
/*
198
199
200
** Flush the transmit queue for a specific session.
** Unless this function is called, the output might remain in the
** output buffer forever.
Per Cederqvist's avatar
Per Cederqvist committed
201
202
*/
extern void
203
isc_flush(struct isc_scb  * scb);
Per Cederqvist's avatar
Per Cederqvist committed
204
205
206
207
208

/*
** Put a buffer on the transmit queue for a session
*/
extern int
209
isc_write(struct isc_scb *scb,
Per Cederqvist's avatar
Per Cederqvist committed
210
211
212
213
214
215
216
217
218
219
	  const void  * buffer,
	  size_t        length);



/*
** Put a single character on the transmit queue
*/
extern int
isc_putc(int           chr,
220
	 struct isc_scb *scb);
Per Cederqvist's avatar
Per Cederqvist committed
221

Per Cederqvist's avatar
Per Cederqvist committed
222
223
224
225
226
/*
** Put a NUL-terminated string on the transmit queue (the NUL is not sent).
*/
extern int
isc_puts(const char *str,
227
	 struct isc_scb *scb);
Per Cederqvist's avatar
Per Cederqvist committed
228
229
230
231

/*
** Put a decimal representation of ``nr'' on the transmit queue.
*/
232
extern int isc_putul(unsigned long nr, struct isc_scb *scb);
Per Cederqvist's avatar
Per Cederqvist committed
233
234
235
236
237

/*
** Enable a previously disabled session
*/
extern int
238
isc_enable(struct isc_scb *scb);
Per Cederqvist's avatar
Per Cederqvist committed
239
240

/*
241
242
** Disable a session. The session will not generate read events, but
** any enqueued output will still be sent to the remote host.
Per Cederqvist's avatar
Per Cederqvist committed
243
244
*/
extern int
245
isc_disable(struct isc_scb *scb);
Per Cederqvist's avatar
Per Cederqvist committed
246

247
248
249
250
union isc_address *
isc_mktcpaddress(const char *address,
		 const char *service);

251
int
252
253
isc_addressfamily(union isc_address *);

254
int
255
256
257
258
isc_addresssize(union isc_address *);

struct sockaddr *
isc_addresspointer(union isc_address *ia);
Per Cederqvist's avatar
Per Cederqvist committed
259
260

extern void
261
isc_freeaddress(union isc_address *addr);
Per Cederqvist's avatar
Per Cederqvist committed
262
263

extern char *
264
isc_getipnum(union isc_address *ia,
Per Cederqvist's avatar
Per Cederqvist committed
265
266
267
268
	     char *address,
	     int len);

extern char *
269
isc_gethostname(union isc_address *ia,
Per Cederqvist's avatar
Per Cederqvist committed
270
271
272
273
		char *address,
		int len);


274
275
extern int
isc_getportnum(union isc_address *ia);
Per Cederqvist's avatar
Per Cederqvist committed
276

277
278
279
extern oop_source *
isc_getoopsource(struct isc_scb *scb);

Per Cederqvist's avatar
Per Cederqvist committed
280
#endif /* __ISC_H__ */