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