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.
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.
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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 # include <sys/types.h>
37 #if !defined(_LP_MSGS_H)
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)
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
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
116 ** These are for use by the scheduler only
118 # define I_GET_TYPE 69
119 # define I_QUEUE_CHK 70
120 /* # define R_CONNECT 71 DEFUNCT */
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
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 */
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
157 ** Last available message
159 # define LAST_MESSAGE 104
162 ** These are the possible status codes returned by the scheduler
172 # define MDENYMEDIA 8
184 # define MTRANSMITERR 20
186 # define MGONEREMOTE 22
190 ** Offsets and lengths of the various elements of the message header.
192 ** Macro Data Type Size Comment
194 ** HEAD_RESYNC 2 bytes (2) *
195 ** HEAD_AUTHCODE short + long (6) *
197 ** HEAD_SIZE 4 bytes (4) \
198 ** HEAD_TYPE 4 bytes (4) > message propper
199 ** HEAD_DATA n bytes (n) /
201 ** TAIL_CHKSUM 4 bytes (4) *
202 ** TAIL_ENDSYNC 2 bytes (2) *
204 ** Items marked with an asterisk are only used with the 3.2
209 ** 3.2 Protocol Header Information:
210 ** 2-byte message introduction
211 ** 6-byte client authorization data
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))
219 ** 3.2 Protocol Message Information:
220 ** 4-byte message size
221 ** 4-byte message type
222 ** n-byte message data
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)
231 ** 3.2 Protocol Size of non-data header information
233 #define HEAD_LEN HEAD_DATA
236 ** Equivalents for 4.0 protocol
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)
244 #define MESG_LEN MESG_DATA
247 ** 3.2 Protocol Trailer Information:
248 ** 4-byte message check sum
249 ** 2-byte message closing identifier
251 ** "N" is the decoded value of buffer[HEAD_SIZE]. This must
252 ** be provided because messages are variable length.
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)
260 ** 3.2 Protocol Size of non-data trailer information
262 #define TAIL_LEN (TAIL_CHKSUM_LEN + TAIL_ENDSYNC_LEN)
265 ** 3.2 Protocol Size of all non-data information
266 ** (This is also the minimum size for 3.2 protocol messages)
268 #define CONTROL_LEN (HEAD_LEN + TAIL_LEN)
271 ** Size of excess data induced by 3.2 Protocol.
272 ** (This is also the size differance between 3.2 & 4.0 protocols)
274 #define EXCESS_3_2_LEN (HEAD_SIZE + TAIL_LEN)
278 #define CALC_CHKSUM(B,SZ,RC) \
279 if (SZ >= CONTROL_LEN) \
281 register unsigned char *p = (unsigned char *)B, \
282 *pend = p + SZ - TAIL_LEN; \
285 RC += *p++; /* let it overflow */ \
288 return ((errno = EINVAL, -1))
291 ** Largest size permitted for any given message
296 ** Possible values of the type field of S_QUIET_ALERT
299 # define QA_PRINTER 2
300 # define QA_PRINTWHEEL 3
302 typedef struct strbuf strbuf_t
; /* STREAMS buffer */
311 ** Definition of a message descriptor
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 */
330 # define MDSIZE (sizeof(MESG))
333 ** Possible values of MESG.state
337 # define MDS_32PROTO 320
338 # define MDS_32CONNECT 321
341 ** Possible values of MESG.type
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 */
352 ** Definition for a FIFO buffer (used
364 ** Definitions for the rest of the world and lint
367 ** Server functions in order of usage
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
* );
378 ** Client functions in order of typical usage
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
* );
390 ** This may be called to deallocate internal buffers allocated
391 ** by mgetm and mputm. Probably not useful except right before
394 void __mbfree ( void );
397 ** Client functions for pre-4.0 compatability
402 int mrecv ( char *, int );
403 int msend ( char * );
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);
415 ** General purpose message manipulating functions
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, ... );
427 ** This will yield the type of a message
429 # define mtype(buffer) (getmessage(buffer, I_GET_TYPE))
432 ** This will yeild the size of a message
434 # define msize(buffer) (stoh(buffer))
437 ** Pass this for the request-id argument of S_CANCEL
438 ** to obtain the effect of the 3.2 S_CANCEL_REQUEST.
440 # define CURRENT_REQ "current"
442 #endif /* !defined (_LP_MSGS_H) */