1 /**********************************************************
2  * File: qipcng.h
3  * Created at Wed Apr  4 00:05:05 2001 by lev // lev@serebryakov.spb.ru
4  *
5  * $Id: qipcng.h,v 1.8 2002/03/16 15:59:38 lev Exp $
6  **********************************************************/
7 #ifndef __QIPCNG_H__
8 #define __QIPCNG_H__
9 
10 #define LOG_BUFFER_SIZE 10
11 #define LINE_TIMEOUT	240
12 
13 /* Stream DES context */
14 typedef struct _SESSENCCONTEXT {
15 	CHAR iv[8];
16 	descontext_t cx;
17 } sessenccontext_t;
18 
19 /* One UI client -- next one, socket (and it is unique ID), encryption context */
20 typedef struct _UICLIENT {
21 	struct _UICLIENT *next;
22 	int socket;
23 	sessenccontext_t cx;
24 } uiclient_t;
25 
26 /* One UI <-mask-> Line relation */
27 typedef struct _LINE2UI {
28 	struct _LINE2UI *next;
29 	uiclient_t *client;
30 	UINT32 mask;
31 } line2ui_t;
32 
33 /* State of file transfer */
34 typedef struct _TRANSFERSTATE {
35 	CHAR phase;				/* Phase of process */
36 #define TXRX_PHASE_HSHAKE	'h'		/* Handhaske in progress */
37 #define TXRX_PHASE_LOOP		'l'		/* File loop */
38 #define TXRX_PHASE_FINISH	'f'		/* Finishing */
39 #define TXRX_PHASE_EOB		'\x00'	/* Batch was finished or not started yet */
40 	CHAR filephase;			/* Phase of LOOP */
41 #define TXRX_FILE_HSHAKE	'h'		/* File handshake in progress */
42 #define TXRX_FILE_DATA		'd'		/* Data sending/receiving */
43 #define TXRX_FILE_EOF		'\x00'	/* No files in processing */
44 	CHAR lastfilestat;		/* Last file status */
45 #define TXRX_FILESTAT_OK			'o'		/* Ok */
46 #define TXRX_FILESTAT_SKIPPED		's'		/* Skipped */
47 #define TXRX_FILESTAT_REFUSED		'r'		/* Refuse */
48 #define TXRX_FILESTAT_ERROR			'e'		/* Error */
49 	UINT32 maxblock;		/* Maximum block size */
50 	UINT32 curblock;		/* Current block size */
51 	UINT32 crcsize;			/* Size of CRC control sum in bits */
52 	UINT32 filesize;		/* Current file size */
53 	UINT32 totalsize;		/* Total transfer size */
54 	UINT32 filepos;			/* Current file pos (bytes have been sent) */
55 	UINT32 totalpos;		/* Total stream pos (bytes have been sent) */
56 	UINT32 filenum;			/* Number of current file, from 1 */
57 	UINT32 totalfiles;		/* Number of files to transfer */
58 	UINT32 filestarted;		/* UNIX time of file transfer start time */
59 	UINT32 transferstarted;	/* UNIX time of transfer starts */
60 	CHAR *file;				/* Name of current file */
61 } txrxstate_t;
62 
63 /* Information about one line */
64 typedef struct _LINESTATE {
65 	struct _LINESTATE *next;
66 	CHAR phase;				/* Phase of session */
67 #define SESS_PHASE_NOPROC		'\x00'
68 #define SESS_PHASE_BEGIN		'b'
69 #define SESS_PHASE_CONNECT		'c'
70 #define SESS_PHASE_HSHAKEOUT	'o'
71 #define SESS_PHASE_HSHAKEIN		'i'
72 #define SESS_PHASE_INPROCESS	'p'
73 	CHAR mode;
74 	UINT32 flags;			/* Different flags, see opts.h */
75 	UINT32 type;			/* Type of session */
76 	UINT32 proto;			/* Used protocol */
77 	txrxstate_t send;
78 	txrxstate_t recv;
79 	ninfo_t remote;
80 	CHAR *tty;
81 	UINT32 speed;
82 	CHAR *connect;
83 	CHAR *cid;
84 	CHAR *log_buffer[LOG_BUFFER_SIZE];
85 	CHAR *chat_buffer[LOG_BUFFER_SIZE];
86 	/* Internal variables */
87 	int log_head,log_tail,chat_head,chat_tail;
88 	pid_t pid;
89 	struct sockaddr_in from;
90 	time_t lastevent;
91 	anylist_t *clients;		/* Head of registered for this line clients */
92 } linestate_t;
93 
94 /* Generic event structure -- for typecasting */
95 typedef struct _EVTANY {
96 	UINT32 fulllength;			/* Full length of following data  */
97 	CHAR data[];				/* Data for event */
98 } evtany_t;
99 
100 /* Line-to-manager and manager-to-line event structure */
101 typedef struct _EVTLAM {
102 	UINT32 fulllength;			/* Full length of following data  */
103 	CHAR password[8];			/* Password, zero-padded */
104 	/* Retranslated data begins here */
105 	UINT32 pid;					/* Line PID */
106 	CHAR tty[16];				/* '' if it is IP line (dynamic), name of tty if fixed (tty) one */
107 	UINT8 type;					/* See EVTL2M_XXXX / EVTM2L_XXXX */
108 	CHAR data[];				/* Data for event */
109 } evtlam_t;
110 
111 /* Manager-to-UI and UI-to-manager event structure */
112 typedef struct _EVTUAM {
113 	UINT32 fulllength;			/* Full length of following data  */
114 	UINT8 type;					/* See EVTU2M_XXXX / EVTM2U_XXXX */
115 	CHAR data[];				/* Data for event */
116 } evtlau_t;
117 
118 
119 typedef int (*event_handler)(linestat_t *line, evtlam_t *event);
120 
121 /* Events from lines to manager */
122 #define EVTL2M_GROUP_GLOBAL		0x10	/* Very global event */
123 #define EVTL2M_REGISTER			0x11	/* Register new line, set mode -- answer or call */
124 /* Signature: "c" -- [A]NSWER/[C]ALL. */
125 #define EVTL2M_CLOSE			0x12	/* Unregister line and delete it */
126 /* Signature: "" */
127 
128 #define EVTL2M_GROUP_SESSION	0x20	/* Session related events */
129 #define EVTL2M_STAT_CONNECT		0x21	/* Modem connected, carrier detected. Speed and CID */
130 /* Signature: "ss"  -- CONNECT,CID*/
131 #define EVTL2M_STAT_DETECTED	0x22	/* Mailer detected. Session type. */
132 /* Signature: "d"  -- SESSION TYPE */
133 #define EVTL2M_STAT_DATAGOT		0x23	/* We know about remote node. node_t info */
134 /* Signature: "n" -- REMOTE NODE INFO */
135 #define EVTL2M_STAT_DATASENT	0x24	/* Remote know about us */
136 /* Signature: "" */
137 #define EVTL2M_STAT_HANDSHAKED	0x25	/* Handshake finished. Protocols and options */
138 /* Signature: "dd" -- PROTOCOL,FINAL OPTIONS*/
139 
140 #define EVTL2M_GROUP_BATCH		0x30	/* Batch related events */
141 #define EVTL2M_BATCH_START		0x31	/* Batch starts */
142 /* Signature: "c" -- DIRECTION */
143 #define EVTL2M_BATCH_HSHAKED	0x32	/* Batch handshaked */
144 /* Signature: "c" -- DIRECTION */
145 #define EVTL2M_BATCH_CLOSE		0x33	/* Batch finishing */
146 /* Signature: "c" -- DIRECTION */
147 #define EVTL2M_BATCH_CLOSED		0x34	/* Batch finished */
148 /* Signature: "c" -- DIRECTION */
149 #define EVTL2M_BATCH_INFO		0x35	/* Batch info -- async */
150 /* Signature: "cdddd" -- DIRECTION,MAX BLOCK,CRC,FILES,TOTAL SIZE */
151 
152 #define EVTL2M_GROUP_RECVSEND	0x40	/* File send/receive related events */
153 #define EVTL2M_FILE_START		0x41	/* Start new file */
154 /* Signature: "c" -- DIRECTION  */
155 #define EVTL2M_FILE_INFO		0x42	/* Info about new file sending/received -- async */
156 /* Signature: "csddd" -- DIRECTION,NAME,CRC,SIZE,TIME  */
157 #define EVTL2M_FILE_DATA		0x43	/* Info was ACKed and we wait for data exchange */
158 /* Signature: "c" -- DIRECTION  */
159 #define EVTL2M_FILE_BLOCK		0x44	/* Block sended/received */
160 /* Signature: "cdd" -- DIRECTION,POS,SIZE  */
161 #define EVTL2M_FILE_REPOS		0x45	/* Repos */
162 /* Signature: "cd" -- DIRECTION,POS  */
163 #define EVTL2M_FILE_END			0x46	/* File finished */
164 /* Signature: "cc" -- DIRECTION,REASON  */
165 
166 
167 #define EVTL2M_GROUP_CHAT		0x50	/* Chat related events */
168 #define EVTL2M_CHAT_INIT		0x51	/* Remote request for chat */
169 /* Signature: "" */
170 #define EVTL2M_CHAT_LINE		0x52	/* Chat string received */
171 /* Signature: "s" -- LINE */
172 #define EVTL2M_CHAT_CLOSE		0x53	/* Remote close chat */
173 /* Signature: "" */
174 
175 #define EVTL2M_GROUP_LOG		0x60	/* Logging related events */
176 #define EVTL2M_SLINE			0x61	/* Status line */
177 /* Signature: "s" -- LINE */
178 #define EVTL2M_LOG				0x62	/* Log string */
179 /* Signature: "s" -- LINE */
180 
181 /* Events from manager to line */
182 #define EVTM2L_HANGUP			0		/* Hang up now */
183 /* Signature: "" */
184 #define EVTM2L_SKIP				1		/* Skip current file */
185 /* Signature: "" */
186 #define EVTM2L_SUSPEND			2		/* Suspend current file */
187 /* Signature: "" */
188 #define EVTM2L_CHAT_INIT		3		/* Start chat with remote */
189 /* Signature: "" */
190 #define EVTM2L_CHAT_LINE		4		/* Send line to remote chat window */
191 /* Signature: "s" -- LINE */
192 #define EVTM2L_CHAT_CLOSE		5		/* Close chat with remote */
193 /* Signature: "" */
194 
195 /* Events and requests from UI to manager */
196 #define EVTU2M_GROUP_GLOBAL			0x10	/* Global events */
197 #define EVTU2M_LOGIN				0x11	/* New UI want to connect */
198 /* Signature: "s" -- PASSWORD */
199 #define EVTU2M_LOGOUT				0x12	/* UI is closed */
200 /* Signature: "" */
201 #define EVTU2M_QUIT					0x13	/* Quit manager */
202 /* Signature: "" */
203 
204 #define EVTU2M_GROUP_CONFIG			0x20	/* Configuration and line presense requests */
205 #define EVTU2M_CONFIG_STATION		0x21	/* Request for station (EMSI) info */
206 /* Signature: "" */
207 #define EVTU2M_CONFIG_TTYS			0x22	/* Request for list of configured ttys (lines) */
208 /* Signature: "" */
209 #define EVTU2M_CONFIG_TIME			0x23	/* Request for current time and timezone */
210 /* Signature: "" */
211 #define EVTU2M_CONFIG_MAILONLY		0x24	/* Request for mail-only time intervals */
212 /* Signature: "" */
213 #define EVTU2M_CONFIG_LINES			0x2f	/* Lines, which are active right now (with TCP/IP ones) */
214 /* Signature: "" */
215 
216 #define EVTU2M_GROUP_LINE			0x30	/* Line related events and requests */
217 #define EVTU2M_LINE_FULL_STATUS		0x31	/* Request for full line status */
218 /* Signature: "d" -- PID OF LINE */
219 #define EVTU2M_LINE_CONNECT_STATUS	0x32	/* Request for connect status */
220 /* Signature: "d" -- PID OF LINE */
221 #define EVTU2M_LINE_REMOTE_STATUS	0x33	/* Request for remote node info */
222 /* Signature: "d" -- PID OF LINE */
223 #define EVTU2M_LINE_RXTX_STATUS		0x34	/* Request for sending/receiving status */
224 /* Signature: "dc" -- PID OF LINE,DIRECTION */
225 #define EVTU2M_LINE_CHAT_STATUS		0x35	/* Request for chat status -- enabled/disabled on/off */
226 /* Signature: "d" -- PID OF LINE */
227 #define EVTU2M_LINE_HANGUP			0x3d	/* Hang up line */
228 /* Signature: "d" -- PID OF LINE */
229 #define EVTU2M_LINE_SKIP			0x3e	/* Skip current file */
230 /* Signature: "d" -- PID OF LINE */
231 #define EVTU2M_LINE_SUSPEND			0x3f	/* Suspend current file */
232 /* Signature: "d" -- PID OF LINE */
233 
234 #define EVTU2M_GROUP_QUEUE			0x40	/* Common queue related events and requests */
235 #define EVTU2M_QUEUE_GET			0x41	/* Request for outbound list */
236 /* Signature: ""  */
237 #define EVTU2M_QUEUE_RESCAN			0x42	/* Force rescan of queue */
238 /* Signature: ""  */
239 
240 #define EVTU2M_GROUP_NODE			0x50	/* Single node operations group */
241 #define EVTU2M_NODE_POLL			0x51	/* Poll node */
242 /* Signature: "ac" -- ADDRESS,STATUS  */
243 #define EVTU2M_NODE_CHANGE_STATUS	0x52	/* Change status of node */
244 /* Signature: "ac" -- ADDRESS,STATUS  */
245 #define EVTU2M_NODE_ATTACH			0x53	/* Attach files(s) to node */
246 /* Signature: "acs" -- ADDRESS,STATUS.PATH  */
247 #define EVTU2M_NODE_KILL			0x54	/* Kill outbound for node */
248 /* Signature: "a" -- ADDRESS  */
249 #define EVTU2M_NODE_CALL			0x55	/* Call node on given (or any free) line */
250 /* Signature: "acs" -- ADDRESS,CHECK TIME,TTY  */
251 #define EVTU2M_NODE_INFO			0x56	/* Get nodelist info about node */
252 /* Signature: "a" -- ADDRESS  */
253 #define EVTU2M_NODE_QUEUE			0x57	/* Get list of files for node */
254 /* Signature: "a" -- ADDRESS  */
255 
256 #define EVTU2M_GROUP_CHAT			0x60	/* Chat-related eventts */
257 #define EVTU2M_CHAT_INIT			0x61	/* Start chat with remote */
258 /* Signature: "d" -- PID OF LINE  */
259 #define EVTU2M_CHAT_LINE			0x62	/* Send chat line to remote */
260 /* Signature: "ds" -- PID OF LINE,LINE  */
261 #define EVTU2M_CHAT_CLOSE			0x63	/* Finish chat with remote */
262 /* Signature: "d" -- PID OF LINE  */
263 #define EVTU2M_CHAT_BUFFER			0x64	/* Request for current chat buffer */
264 /* Signature: "d" -- PID OF LINE  */
265 
266 #define EVTU2M_GROUP_LOG			0x70	/* Log-related events */
267 #define EVTU2M_LOG_BUFFER			0x71	/* Request for log buffer */
268 /* Signature: "d" -- PID OF LINE (may be 0 for manager)  */
269 #define EVTU2M_LOG_SLINE			0x72	/* Request for current status line */
270 /* Signature: "d" -- PID OF LINE (may be 0 for manager)  */
271 
272 #define EVTU2M_GROUP_REGISTER		0xf0	/* Group for registration requests */
273 #define EVTU2M_REG_REGMASK			0xf1	/* Register for events -- binary string for register  */
274 /* Signature: "dd" -- PID OF LINE,BIT MASK  */
275 #define EVTU2M_REG_UNREGMASK		0xf2	/* Unregister for events -- binary string for unregister */
276 /* Signature: "dd" -- PID OF LINE,BIT MASK  */
277 
278 /* Events and information from manager to UI */
279 #define EVTM2U_GROUP_GLOBAL			0x10	/* Answers on global requests */
280 #define EVTM2U_HELLO				0x11	/* Login result */
281 /* Signature: "cs" -- RESULT,HELLO STRING  */
282 #define EVTM2U_GOODBYE				0x12	/* Answer on LOGOUT */
283 /* Signature: ""  */
284 #define EVTM2U_OK					0x13	/* Command completed Ok (may be with warning) */
285 /* Signature: "s" -- WARNING (may be empty)  */
286 #define EVTM2U_ERROR				0x14	/* Command WAS NOT completed (with error message) */
287 /* Signature: "s" -- ERROR  */
288 #define EVTM2U_LINE_EVENT			0x15	/* Retranslation of line event */
289 /* Signature: "dd..." -- PID,LINE EVENT,line event data */
290 
291 #define EVTM2U_GROUP_CONFIG			0x20	/* Configuration and line presence info */
292 #define EVTM2U_CONFIG_STATION		0x21	/* Station (EMSI) info */
293 /* Signature: "ssssdsss" -- STATION,PLACE,SYSOP,PHONE,SPEED,FLAGS,WORK TIME,FREQ TIME */
294 #define EVTM2U_CONFIG_TTYS			0x22	/* List of configured ttys (lines) */
295 /* Signature: "s..." -- TTY1,... */
296 #define EVTM2U_CONFIG_TIME			0x23	/* Current time and timezone */
297 /* Signature: "dd" -- UNIX TIME,SECONDS TO GMT */
298 #define EVTM2U_CONFIG_MAILONLY		0x24	/* Mail-only time intervals */
299 /* Signature: "s" -- MAIL-ONLY TIMES */
300 #define EVTM2U_CONFIG_LINES			0x2f	/* Lines, which are active right now (with TCP/IP ones) */
301 /* Signature: "sd..." -- TTY/IP,PID,... */
302 
303 #define EVTM2U_GROUP_LINE			0x30	/* Line related events and answers */
304 #define EVTM2U_LINE_CONNECT_STATUS	0x31	/* Connect status */
305 /* Signature: "ss" -- CONNECT,CID (may be empty, empty CONNECT, if disconnected) */
306 #define EVTM2U_LINE_REMOTE_STATUS	0x32	/* Remote node info */
307 #define EVTM2U_LINE_RXTX_STATUS		0x34	/* Sending/Receiving status */
308 #define EVTM2U_LINE_CHAT_STATUS		0x35	/* Chat status */
309 
310 #define EVTM2U_GROUP_QUEUE			0x40	/* Common queue related events and requests */
311 #define EVTM2U_QUEUE_START			0x41	/* Start of queue sending */
312 #define EVTM2U_QUEUE_ITEM			0x42	/* Queue item */
313 #define EVTM2U_QUEUE_FINISH			0x43	/* Queue finished */
314 
315 #define EVTM2U_GROUP_NODE			0x50	/* Single node operations group */
316 #define EVTM2U_NODE_INFO			0x51	/* Nodelist info about node */
317 #define EVTM2U_NODE_QUEUE_STRAT		0x52	/* List of files for node starts */
318 #define EVTM2U_NODE_QUEUE_ITEM		0x53	/* One file */
319 #define EVTM2U_NODE_QUEUE_FINISH	0x54	/* List of files for node finihs */
320 
321 #endif
322