xref: /titanic_51/usr/src/cmd/lp/include/msgs.h (revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.18	*/
32 
33 # include	<sys/types.h>
34 # include	<poll.h>
35 # include	<stdarg.h>
36 # include	<stropts.h>
37 
38 #if	!defined(_LP_MSGS_H)
39 # define	_LP_MSGS_H
40 
41 /*
42  * THE DISPATCH TABLE DEPENDS ON EACH R_... MESSAGE FOLLOWING
43  * IMMEDIATELY AFTER ITS CORRESPONDING S_... COUNTERPART.
44  * I.E R_... MESSAGE FOR A S_... MESSAGE IS (S_... + 1)
45  */
46 # define	R_BAD_MESSAGE			0
47 # define	S_NEW_QUEUE			1
48 # define	R_NEW_QUEUE			2
49 # define	S_ALLOC_FILES			3
50 # define	R_ALLOC_FILES			4
51 # define	S_PRINT_REQUEST			5
52 # define	R_PRINT_REQUEST			6
53 # define	S_START_CHANGE_REQUEST		7
54 # define	R_START_CHANGE_REQUEST		8
55 # define	S_END_CHANGE_REQUEST		9
56 # define	R_END_CHANGE_REQUEST		10
57 # define	S_CANCEL_REQUEST		11
58 # define	R_CANCEL_REQUEST		12
59 # define	S_INQUIRE_REQUEST		13
60 # define	R_INQUIRE_REQUEST		14
61 # define	S_LOAD_PRINTER			15
62 # define	R_LOAD_PRINTER			16
63 # define	S_UNLOAD_PRINTER		17
64 # define	R_UNLOAD_PRINTER		18
65 # define	S_INQUIRE_PRINTER_STATUS	19
66 # define	R_INQUIRE_PRINTER_STATUS	20
67 # define	S_LOAD_CLASS			21
68 # define	R_LOAD_CLASS			22
69 # define	S_UNLOAD_CLASS			23
70 # define	R_UNLOAD_CLASS			24
71 # define	S_INQUIRE_CLASS			25
72 # define	R_INQUIRE_CLASS			26
73 # define	S_MOUNT				27
74 # define	R_MOUNT				28
75 # define	S_UNMOUNT			29
76 # define	R_UNMOUNT			30
77 # define	S_MOVE_REQUEST			31
78 # define	R_MOVE_REQUEST			32
79 # define	S_MOVE_DEST			33
80 # define	R_MOVE_DEST			34
81 # define	S_ACCEPT_DEST			35
82 # define	R_ACCEPT_DEST			36
83 # define	S_REJECT_DEST			37
84 # define	R_REJECT_DEST			38
85 # define	S_ENABLE_DEST			39
86 # define	R_ENABLE_DEST			40
87 # define	S_DISABLE_DEST			41
88 # define	R_DISABLE_DEST			42
89 # define	S_LOAD_FILTER_TABLE		43
90 # define	R_LOAD_FILTER_TABLE		44
91 # define	S_UNLOAD_FILTER_TABLE		45
92 # define	R_UNLOAD_FILTER_TABLE		46
93 # define	S_LOAD_PRINTWHEEL		47
94 # define	R_LOAD_PRINTWHEEL		48
95 # define	S_UNLOAD_PRINTWHEEL		49
96 # define	R_UNLOAD_PRINTWHEEL		50
97 # define	S_LOAD_USER_FILE		51
98 # define	R_LOAD_USER_FILE		52
99 # define	S_UNLOAD_USER_FILE		53
100 # define	R_UNLOAD_USER_FILE		54
101 # define	S_LOAD_FORM			55
102 # define	R_LOAD_FORM			56
103 # define	S_UNLOAD_FORM			57
104 # define	R_UNLOAD_FORM			58
105 # define	S_GETSTATUS			59
106 # define	R_GETSTATUS			60
107 # define	S_QUIET_ALERT			61
108 # define	R_QUIET_ALERT			62
109 # define	S_SEND_FAULT			63
110 # define	R_SEND_FAULT			64
111 # define	S_SHUTDOWN			65
112 # define	R_SHUTDOWN			66
113 # define	S_GOODBYE			67
114 # define	S_CHILD_DONE			68
115 
116 /*
117 **	These are for use by the scheduler only
118 */
119 # define	I_GET_TYPE			69
120 # define	I_QUEUE_CHK			70
121 # define	R_CONNECT			71
122 
123 # define	S_GET_STATUS			72
124 # define	R_GET_STATUS			73
125 # define	S_INQUIRE_REQUEST_RANK		74
126 # define	R_INQUIRE_REQUEST_RANK		75
127 # define	S_CANCEL			76
128 # define	R_CANCEL			77
129 # define	S_NEW_CHILD			78
130 # define	R_NEW_CHILD			79
131 # define	S_SEND_JOB			80
132 # define	R_SEND_JOB			81
133 # define	S_JOB_COMPLETED			82
134 # define	R_JOB_COMPLETED			83
135 # define	S_INQUIRE_REMOTE_PRINTER	84
136 # define	R_INQUIRE_REMOTE_PRINTER	20
137 # define	S_CHILD_SYNC			85
138 # define	S_LOAD_SYSTEM			86
139 # define	R_LOAD_SYSTEM			87
140 # define	S_UNLOAD_SYSTEM			88
141 # define	R_UNLOAD_SYSTEM			89
142 /* new messages */
143 # define	S_CLEAR_FAULT			90
144 # define	R_CLEAR_FAULT			91
145 # define	S_MOUNT_TRAY			92
146 # define	R_MOUNT_TRAY			93
147 # define	S_UNMOUNT_TRAY			94
148 # define	R_UNMOUNT_TRAY			95
149 # define	S_MAX_TRAYS			96
150 # define	R_MAX_TRAYS			97
151 # define	S_PAPER_CHANGED			98
152 # define	R_PAPER_CHANGED			99
153 # define	S_PAPER_ALLOWED			100
154 # define	R_PAPER_ALLOWED			101
155 /*
156 **	Last available message
157 */
158 # define	LAST_MESSAGE			102
159 
160 /*
161 **      These are the possible status codes returned by the scheduler
162 */
163 # define	MOK		 0
164 # define	MOKMORE		 1
165 # define	MOKREMOTE	 2
166 # define	MMORERR		 3
167 # define	MNODEST		 4
168 # define	MERRDEST	 5
169 # define	MDENYDEST	 6
170 # define	MNOMEDIA	 7
171 # define	MDENYMEDIA	 8
172 # define	MNOFILTER	 9
173 # define	MNOINFO		10
174 # define	MNOMEM		11
175 # define	MNOMOUNT	12
176 # define	MNOOPEN		13
177 # define	MNOPERM		14
178 # define	MNOSTART	15
179 # define	MUNKNOWN	16
180 # define	M2LATE		17
181 # define	MNOSPACE	18
182 # define	MBUSY		19
183 # define	MTRANSMITERR	20
184 # define	MNOMORE		21
185 # define	MGONEREMOTE	22
186 # define	MNOTRAY		23
187 
188 /*
189 ** Offsets and lengths of the various elements of the message header.
190 **
191 **	Macro		Data Type	Size	Comment
192 **
193 **	HEAD_RESYNC	2 bytes		(2)	*
194 **	HEAD_AUTHCODE	short + long	(6)	*
195 **
196 **	HEAD_SIZE	4 bytes		(4)	\
197 **	HEAD_TYPE	4 bytes		(4)	 > message propper
198 **	HEAD_DATA	n bytes		(n)	/
199 **
200 **	TAIL_CHKSUM	4 bytes		(4)	*
201 **	TAIL_ENDSYNC	2 bytes		(2)	*
202 **
203 **	Items marked with an asterisk are only used with the 3.2
204 **	Spooler protocol.
205 */
206 
207 /*
208 **	3.2 Protocol Header Information:
209 **		2-byte message introduction
210 **		6-byte client authorization data
211 */
212 #define	HEAD_RESYNC		(0)
213 #define HEAD_RESYNC_LEN		2
214 #define HEAD_AUTHCODE		(HEAD_RESYNC + HEAD_RESYNC_LEN)
215 #define HEAD_AUTHCODE_LEN		(sizeof(short) + sizeof(long))
216 
217 /*
218 **	3.2 Protocol Message Information:
219 **		4-byte message size
220 **		4-byte message type
221 **		n-byte message data
222 */
223 #define HEAD_SIZE		(HEAD_AUTHCODE + HEAD_AUTHCODE_LEN)
224 #define HEAD_SIZE_LEN			4
225 #define HEAD_TYPE		(HEAD_SIZE + HEAD_SIZE_LEN)
226 #define HEAD_TYPE_LEN			4
227 #define HEAD_DATA		(HEAD_TYPE + HEAD_TYPE_LEN)
228 
229 /*
230 **	3.2 Protocol Size of non-data header information
231 */
232 #define HEAD_LEN		HEAD_DATA
233 
234 /*
235 **	Equivalents for 4.0 protocol
236 */
237 #define MESG_SIZE		(0)
238 #define MESG_SIZE_LEN			4
239 #define MESG_TYPE		(MESG_SIZE + MESG_SIZE_LEN)
240 #define MESG_TYPE_LEN			4
241 #define MESG_DATA		(MESG_TYPE + MESG_TYPE_LEN)
242 
243 #define MESG_LEN		MESG_DATA
244 
245 /*
246 **	3.2 Protocol Trailer Information:
247 **		4-byte message check sum
248 **		2-byte message closing identifier
249 **
250 **	"N" is the decoded value of buffer[HEAD_SIZE].  This must
251 **	be provided because messages are variable length.
252 */
253 #define	TAIL_ENDSYNC_LEN		2
254 #define	TAIL_ENDSYNC(N)		(N - TAIL_ENDSYNC_LEN)
255 #define TAIL_CHKSUM_LEN			4
256 #define TAIL_CHKSUM(N)		(TAIL_ENDSYNC(N) - TAIL_CHKSUM_LEN)
257 
258 /*
259 **	3.2 Protocol Size of non-data trailer information
260 */
261 #define	TAIL_LEN		(TAIL_CHKSUM_LEN + TAIL_ENDSYNC_LEN)
262 
263 /*
264 **	3.2 Protocol Size of all non-data information
265 **	(This is also the minimum size for 3.2 protocol messages)
266 */
267 #define	CONTROL_LEN		(HEAD_LEN + TAIL_LEN)
268 
269 /*
270 **	Size of excess data induced by 3.2 Protocol.
271 **	(This is also the size differance between 3.2 & 4.0 protocols)
272 */
273 #define	EXCESS_3_2_LEN		(HEAD_SIZE + TAIL_LEN)
274 /**
275  ** Checksum:
276  **/
277 #define CALC_CHKSUM(B,SZ,RC) \
278 if (SZ >= CONTROL_LEN) \
279 { \
280     register unsigned char	*p = (unsigned char *)B, \
281 			    *pend = p + SZ - TAIL_LEN; \
282     RC = 0; \
283     while (p < pend) \
284 	RC += *p++;  /* let it overflow */ \
285 } \
286 else \
287     return ((errno = EINVAL, -1))
288 
289 /*
290 **      Largest size permitted for any given message
291 */
292 # define	MSGMAX		2048
293 
294 /*
295 **      Possible values of the type field of S_QUIET_ALERT
296 */
297 # define	QA_FORM		1
298 # define	QA_PRINTER	2
299 # define	QA_PRINTWHEEL	3
300 
301 typedef	struct	strbuf	strbuf_t;	/*  STREAMS buffer */
302 
303 typedef	struct mque
304 {
305     struct mque	  *next;
306     struct strbuf *dat;
307 } MQUE;
308 
309 /*
310 **	Definition of a message descriptor
311 */
312 typedef struct
313 {
314     short	type;			/* type of connection */
315     int		readfd;			/* STREAM fd to read from */
316     int		writefd;		/* STREAM fd to write to */
317     int		wait;			/* number of systems waiting for */
318     char	*file;			/* pipe name if type==MD_FIFO */
319     short	state;			/* Current state of client */
320     short	admin;			/* Non zero if admin  */
321     short	event;			/* Event returned from poll */
322     MQUE *	mque;			/* backlogged message ptr */
323     uid_t	uid;			/* Clients UID */
324     gid_t	gid;			/* Clients GID */
325     void	(**on_discon)();	/* Clean up functions */
326 } MESG;
327 
328 # define	MDSIZE	(sizeof(MESG))
329 
330 /*
331 **	Possible values of MESG.state
332 */
333 # define	MDS_IDLE	0
334 
335 # define	MDS_32PROTO	320
336 # define	MDS_32CONNECT	321
337 
338 /*
339 **	Possible values of MESG.type
340 */
341 # define	MD_UNKNOWN	0	/* We don't know just yet */
342 # define	MD_STREAM	1	/* 4.0 STREAMS pipe protocol */
343 # define	MD_BOUND	2	/* 4.0 STREAMS fd protocol */
344 # define	MD_SYS_FIFO	3	/* 3.2 named-pipe protocol */
345 # define	MD_USR_FIFO	4	/* 3.2 named-pipe protocol */
346 # define	MD_MASTER	5	/* MD_STREAM used by lpsched */
347 # define	MD_CHILD	6	/* MD_STREAM to a child process */
348 
349 /*
350 **	Definition for a FIFO buffer (used
351 **	in read_fifo.
352 */
353 typedef struct
354 {
355 	int	full;
356 	char	save [MSGMAX],
357 		*psave,
358 		*psave_end;
359 } fifobuffer_t;
360 
361 /*
362 **      Definitions for the rest of the world and lint
363 */
364 /*
365 **	Server functions in order of usage
366 */
367 MESG		* mcreate ( char * );
368 int		mlisteninit ( MESG * );
369 MESG		* mlisten ( void );
370 int		mlistenadd ( MESG *, short );
371 int		mon_discon ( MESG *, void (*)());
372 MESG		* mlistenreset ( void );
373 int		mdestroy ( MESG * );
374 
375 /*
376 **	Client functions in order of typical usage
377 */
378 MESG		* mconnect ( char *, int, int );
379 int		mgetm ( MESG *, int, ... );
380 int		mwrite ( MESG *, char * );
381 int		mputm ( MESG *, int, ... );
382 int		mread ( MESG *, char *, int );
383 short		msize ( char * );
384 short		mpeek ( MESG * );
385 int		mdisconnect ( MESG * );
386 
387 /*
388 **	This may be called to deallocate internal buffers allocated
389 **	by mgetm and mputm.  Probably not useful except right before
390 **	a fork().
391 */
392 void		__mbfree ( void );
393 
394 /*
395 **	Client functions for pre-4.0 compatability
396 */
397 int		mclose ( void );
398 int		mneeds ( void );
399 int		mopen ( void );
400 int		mrecv ( char *, int );
401 int		msend ( char * );
402 
403 int		Putmsg (MESG *, strbuf_t *, strbuf_t *, int);
404 int		Getmsg (MESG *, strbuf_t *, strbuf_t *, int *);
405 int		read3_2 (MESG * md, char *msgbuf, int size);
406 int		write3_2 (MESG *, char *, int);
407 int		read_fifo (int, char *, unsigned int);
408 int		write_fifo (int, char *, unsigned int);
409 int		ResetFifoBuffer (int);
410 fifobuffer_t	*GetFifoBuffer (int);
411 
412 /*
413 **	General purpose message manipulating functions
414 */
415 char		* htos ( char *, unsigned short );
416 char		* ltos ( char *, unsigned long );
417 unsigned long	stol ( char * );
418 unsigned short	stoh ( char * );
419 int		_getmessage ( char *, short, va_list );
420 int		_putmessage ( char *, short, va_list );
421 int		getmessage ( char *, short, ... );
422 int		putmessage ( char *, short, ... );
423 
424 /*
425 **	This will yield the type of a message
426 */
427 # define	mtype(buffer)	(getmessage(buffer, I_GET_TYPE))
428 
429 /*
430 **	This will yeild the size of a message
431 */
432 # define	msize(buffer)	(stoh(buffer))
433 
434 /*
435 **	Pass this for the request-id argument of S_CANCEL
436 **	to obtain the effect of the 3.2 S_CANCEL_REQUEST.
437 */
438 # define	CURRENT_REQ	"current"
439 
440 #endif	/* !defined (_LP_MSGS_H) */
441