xref: /illumos-gate/usr/src/cmd/lp/cmd/lpsched/disptab.c (revision cb6207858a9fcc2feaee22e626912fba281ac969)
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	"dispatch.h"
33 #include <syslog.h>
34 
35 static void		r_H(),
36 			r_HS();
37 
38 static DISPATCH			dispatch_table[] = {
39 /* R_BAD_MESSAGE            */  0,			D_BADMSG,
40 /* S_NEW_QUEUE              */  0,			D_BADMSG,
41 /* R_NEW_QUEUE              */  0,			D_BADMSG,
42 /* S_ALLOC_FILES            */  s_alloc_files,		0,
43 /* R_ALLOC_FILES            */  0,			D_BADMSG,
44 /* S_PRINT_REQUEST          */  s_print_request,	0,
45 /* R_PRINT_REQUEST          */  0,			D_BADMSG,
46 /* S_START_CHANGE_REQUEST   */  s_start_change_request,	0,
47 /* R_START_CHANGE_REQUEST   */  0,			D_BADMSG,
48 /* S_END_CHANGE_REQUEST     */  s_end_change_request,	0,
49 /* R_END_CHANGE_REQUEST     */  0,			D_BADMSG,
50 /* S_CANCEL_REQUEST         */  s_cancel_request,	0,
51 /* R_CANCEL_REQUEST         */  0,			D_BADMSG,
52 /* S_INQUIRE_REQUEST        */  0,			D_BADMSG,
53 /* R_INQUIRE_REQUEST        */  0,                      D_BADMSG,
54 /* S_LOAD_PRINTER           */  s_load_printer,		D_ADMIN,
55 /* R_LOAD_PRINTER           */  r_H,                    D_BADMSG,
56 /* S_UNLOAD_PRINTER         */  s_unload_printer,	D_ADMIN,
57 /* R_UNLOAD_PRINTER         */  r_H,                    D_BADMSG,
58 /* S_INQUIRE_PRINTER_STATUS */  s_inquire_printer_status, 0,
59 /* R_INQUIRE_PRINTER_STATUS */  0,                      D_BADMSG,
60 /* S_LOAD_CLASS             */  s_load_class,		D_ADMIN,
61 /* R_LOAD_CLASS             */  r_H,                    D_BADMSG,
62 /* S_UNLOAD_CLASS           */  s_unload_class,		D_ADMIN,
63 /* R_UNLOAD_CLASS           */  r_H,                    D_BADMSG,
64 /* S_INQUIRE_CLASS          */  s_inquire_class,	0,
65 /* R_INQUIRE_CLASS          */  0,                      D_BADMSG,
66 /* S_MOUNT                  */  s_mount,		D_ADMIN,
67 /* R_MOUNT                  */  r_H,                    D_BADMSG,
68 /* S_UNMOUNT                */  s_unmount,		D_ADMIN,
69 /* R_UNMOUNT                */  r_H,                    D_BADMSG,
70 /* S_MOVE_REQUEST           */  s_move_request,		D_ADMIN,
71 /* R_MOVE_REQUEST           */  r_H,                    D_BADMSG,
72 /* S_MOVE_DEST              */  s_move_dest,		D_ADMIN,
73 /* R_MOVE_DEST              */  r_HS,                   D_BADMSG,
74 /* S_ACCEPT_DEST            */  s_accept_dest,		D_ADMIN,
75 /* R_ACCEPT_DEST            */  r_H,                    D_BADMSG,
76 /* S_REJECT_DEST            */  s_reject_dest,		D_ADMIN,
77 /* R_REJECT_DEST            */  r_H,                    D_BADMSG,
78 /* S_ENABLE_DEST            */  s_enable_dest,		D_ADMIN,
79 /* R_ENABLE_DEST            */  r_H,                    D_BADMSG,
80 /* S_DISABLE_DEST           */  s_disable_dest,		D_ADMIN,
81 /* R_DISABLE_DEST           */  r_HS,                   D_BADMSG,
82 /* S_LOAD_FILTER_TABLE      */  s_load_filter_table,	D_ADMIN,
83 /* R_LOAD_FILTER_TABLE      */  r_H,                    D_BADMSG,
84 /* S_UNLOAD_FILTER_TABLE    */  s_unload_filter_table,	D_ADMIN,
85 /* R_UNLOAD_FILTER_TABLE    */  r_H,                    D_BADMSG,
86 /* S_LOAD_PRINTWHEEL        */  s_load_printwheel,	D_ADMIN,
87 /* R_LOAD_PRINTWHEEL        */  r_H,                    D_BADMSG,
88 /* S_UNLOAD_PRINTWHEEL      */  s_unload_printwheel,	D_ADMIN,
89 /* R_UNLOAD_PRINTWHEEL      */  r_H,                    D_BADMSG,
90 /* S_LOAD_USER_FILE         */  s_load_user_file,	D_ADMIN,
91 /* R_LOAD_USER_FILE         */  r_H,                    D_BADMSG,
92 /* S_UNLOAD_USER_FILE       */  s_unload_user_file,	D_ADMIN,
93 /* R_UNLOAD_USER_FILE       */  r_H,                    D_BADMSG,
94 /* S_LOAD_FORM              */  s_load_form,		D_ADMIN,
95 /* R_LOAD_FORM              */  r_H,                    D_BADMSG,
96 /* S_UNLOAD_FORM            */  s_unload_form,		D_ADMIN,
97 /* R_UNLOAD_FORM            */  r_H,                    D_BADMSG,
98 /* S_GETSTATUS              */  0,			D_ADMIN,
99 /* R_GETSTATUS              */  0,                      D_BADMSG,
100 /* S_QUIET_ALERT            */  s_quiet_alert,		D_ADMIN,
101 /* R_QUIET_ALERT            */  r_H,                    D_BADMSG,
102 /* S_SEND_FAULT             */  s_send_fault,		0,
103 /* R_SEND_FAULT             */  0,                      D_BADMSG,
104 /* S_SHUTDOWN               */  s_shutdown,		D_ADMIN,
105 /* R_SHUTDOWN               */  r_H,                    D_BADMSG,
106 /* S_GOODBYE		    */	0,			D_BADMSG,
107 /* S_CHILD_DONE		    */	s_child_done,		0,
108 /* I_GET_TYPE		    */	0,			D_BADMSG,
109 /* I_QUEUE_CHK		    */	0,			D_BADMSG,
110 /* R_CONNECT		    */	0,			D_BADMSG,
111 /* S_GET_STATUS		    */	0,			D_BADMSG,
112 /* R_GET_STATUS		    */	0,			D_BADMSG,
113 /* S_INQUIRE_REQUEST_RANK   */	s_inquire_request_rank,	0,
114 /* R_INQUIRE_REQUEST_RANK   */	0,			D_BADMSG,
115 /* S_CANCEL		    */	s_cancel,		0,
116 /* R_CANCEL		    */	0,			D_BADMSG,
117 /* S_NEW_CHILD		    */	0,			D_BADMSG,
118 /* R_NEW_CHILD		    */	0,			D_BADMSG,
119 /* S_SEND_JOB		    */	0,			D_BADMSG,
120 /* R_SEND_JOB		    */	0,			D_BADMSG,
121 /* S_JOB_COMPLETED	    */	0,			D_BADMSG,
122 /* R_JOB_COMPLETED	    */	0,			D_BADMSG,
123 /* S_INQUIRE_REMOTE_PRINTER */	0,			D_BADMSG,
124 /* R_INQUIRE_REMOTE_PRINTER */	0,			D_BADMSG,
125 /* S_LOAD_SYSTEM            */  0,			D_BADMSG,
126 /* R_LOAD_SYSTEM            */  0,	                D_BADMSG,
127 /* S_UNLOAD_SYSTEM          */  0,			D_BADMSG,
128 /* R_UNLOAD_SYSTEM          */  0,	                D_BADMSG,
129 /* S_CLEAR_FAULT            */  s_clear_fault,		0,
130 /* R_CLEAR_FAULT            */  0,                      D_BADMSG,
131 /* S_MOUNT_TRAY             */  s_mount_tray,		D_ADMIN,
132 /* R_MOUNT_TRAY             */  r_H,                    D_BADMSG,
133 /* S_UNMOUNT_TRAY           */  s_unmount_tray,		D_ADMIN,
134 /* R_UNMOUNT_TRAY           */  r_H,                    D_BADMSG,
135 /* S_MAX_TRAYS              */  s_max_trays,		D_ADMIN,
136 /* R_MAX_TRAYS              */  r_H,                    D_BADMSG,
137 /* S_PAPER_CHANGED          */  s_paper_changed,	0,
138 /* R_PAPER_CHANGED          */  0,			D_BADMSG,
139 /* S_PAPER_ALLOWED          */  s_paper_allowed,	0,
140 /* R_PAPER_ALLOWED          */  0,			D_BADMSG,
141 /* S_PASS_PEER_CONNECTION   */  s_pass_peer_connection,	0,
142 /* R_PASS_PEER_CONNECTION   */  0,			D_BADMSG,
143 };
144 
145 static char *			dispatch_names[] = {
146 "R_BAD_MESSAGE",
147 "S_NEW_QUEUE",
148 "R_NEW_QUEUE",
149 "S_ALLOC_FILES",
150 "R_ALLOC_FILES",
151 "S_PRINT_REQUEST",
152 "R_PRINT_REQUEST",
153 "S_START_CHANGE_REQUEST",
154 "R_START_CHANGE_REQUEST",
155 "S_END_CHANGE_REQUEST",
156 "R_END_CHANGE_REQUEST",
157 "S_CANCEL_REQUEST",
158 "R_CANCEL_REQUEST",
159 "S_INQUIRE_REQUEST",
160 "R_INQUIRE_REQUEST",
161 "S_LOAD_PRINTER",
162 "R_LOAD_PRINTER",
163 "S_UNLOAD_PRINTER",
164 "R_UNLOAD_PRINTER",
165 "S_INQUIRE_PRINTER_STATUS",
166 "R_INQUIRE_PRINTER_STATUS",
167 "S_LOAD_CLASS",
168 "R_LOAD_CLASS",
169 "S_UNLOAD_CLASS",
170 "R_UNLOAD_CLASS",
171 "S_INQUIRE_CLASS",
172 "R_INQUIRE_CLASS",
173 "S_MOUNT",
174 "R_MOUNT",
175 "S_UNMOUNT",
176 "R_UNMOUNT",
177 "S_MOVE_REQUEST",
178 "R_MOVE_REQUEST",
179 "S_MOVE_DEST",
180 "R_MOVE_DEST",
181 "S_ACCEPT_DEST",
182 "R_ACCEPT_DEST",
183 "S_REJECT_DEST",
184 "R_REJECT_DEST",
185 "S_ENABLE_DEST",
186 "R_ENABLE_DEST",
187 "S_DISABLE_DEST",
188 "R_DISABLE_DEST",
189 "S_LOAD_FILTER_TABLE",
190 "R_LOAD_FILTER_TABLE",
191 "S_UNLOAD_FILTER_TABLE",
192 "R_UNLOAD_FILTER_TABLE",
193 "S_LOAD_PRINTWHEEL",
194 "R_LOAD_PRINTWHEEL",
195 "S_UNLOAD_PRINTWHEEL",
196 "R_UNLOAD_PRINTWHEEL",
197 "S_LOAD_USER_FILE",
198 "R_LOAD_USER_FILE",
199 "S_UNLOAD_USER_FILE",
200 "R_UNLOAD_USER_FILE",
201 "S_LOAD_FORM",
202 "R_LOAD_FORM",
203 "S_UNLOAD_FORM",
204 "R_UNLOAD_FORM",
205 "S_GETSTATUS",
206 "R_GETSTATUS",
207 "S_QUIET_ALERT",
208 "R_QUIET_ALERT",
209 "S_SEND_FAULT",
210 "R_SEND_FAULT",
211 "S_SHUTDOWN",
212 "R_SHUTDOWN",
213 "S_GOODBYE",
214 "S_CHILD_DONE",
215 "I_GET_TYPE",
216 "I_QUEUE_CHK",
217 "R_CONNECT",
218 "S_GET_STATUS",
219 "R_GET_STATUS",
220 "S_INQUIRE_REQUEST_RANK",
221 "R_INQUIRE_REQUEST_RANK",
222 "S_CANCEL",
223 "R_CANCEL",
224 "S_NEW_CHILD",
225 "R_NEW_CHILD",
226 "S_SEND_JOB",
227 "R_SEND_JOB",
228 "S_JOB_COMPLETED",
229 "R_JOB_COMPLETED",
230 "S_INQUIRE_REMOTE_PRINTER",
231 "R_INQUIRE_REMOTE_PRINTER",
232 "S_LOAD_SYSTEM",
233 "R_LOAD_SYSTEM",
234 "S_UNLOAD_SYSTEM",
235 "R_UNLOAD_SYSTEM",
236 "S_CLEAR_FAULT",
237 "R_CLEAR_FAULT",
238 "S_MOUNT_TRAY",
239 "R_MOUNT_TRAY",
240 "S_UNMOUNT_TRAY",
241 "R_UNMOUNT_TRAY",
242 "S_MAX_TRAYS",
243 "R_MAX_TRAYS",
244 "S_PAPER_CHANGED",
245 "R_PAPER_CHANGED",
246 "S_PAPER_ALLOWED",
247 "R_PAPER_ALLOWED",
248 "S_PASS_PEER_CONNECTION",
249 "R_PASS_PEER_CONNECTION",
250 };
251 
252 /* see include/msgs.h */
253 static char *			status_names[] = {
254 "MOK",
255 "MOKMORE",
256 "MOKREMOTE",
257 "MMORERR",
258 "MNODEST",
259 "MERRDEST",
260 "MDENYDEST",
261 "MNOMEDIA",
262 "MDENYMEDIA",
263 "MNOFILTER",
264 "MNOINFO",
265 "MNOMEM",
266 "MNOMOUNT",
267 "MNOOPEN",
268 "MNOPERM",
269 "MNOSTART",
270 "MUNKNOWN",
271 "M2LATE",
272 "MNOSPACE",
273 "MBUSY",
274 "MTRANSMITERR",
275 "MNOMORE",
276 "MGONEREMOTE",
277 "MNOTRAY"
278 };
279 
280 #define LAST_STATUS 23
281 
282 /**
283  ** dispatchName() - ROUTINE TO GIVE ASCII DISPATCH NAME
284  **/
285 
286 char *
287 dispatchName(int type)
288 {
289 	if (type <= 0 || type > LAST_MESSAGE)
290 		type = 0;
291 	return (dispatch_names[type]);
292 }
293 
294 char *
295 statusName(int status)
296 {
297 	if (status < 0 || status > LAST_STATUS)
298 		return ("unknown");
299 	return (status_names[status]);
300 }
301 
302 /**
303  ** dispatch() - DISPATCH A ROUTINE TO HANDLE A MESSAGE
304  **/
305 
306 void
307 dispatch(int type, char *m, MESG *md)
308 {
309 	register DISPATCH	*pd	= &dispatch_table[type];
310 
311 	syslog(LOG_DEBUG, "dispatch(%s, %s, 0x%8.8x)",
312 			dispatchName(type), m, md);
313 
314 	if (type <= 0 || type > LAST_MESSAGE || pd->fncp == NULL)
315 		mputm (md, R_BAD_MESSAGE);
316 
317 	else if (!pd->fncp || pd->flags & D_BADMSG)
318 		mputm (md, R_BAD_MESSAGE);
319 
320 	else if (pd->flags & D_ADMIN && !md->admin)
321 		if ((++pd)->fncp)
322 			(*pd->fncp) (md, type+1);
323 		else
324 			mputm (md, R_BAD_MESSAGE);
325 
326 	else if (pd->flags & D_SYSTEM && md->type != MD_CHILD &&
327 		md->type != MD_BOUND)
328 		if ((++pd)->fncp)
329 			(*pd->fncp) (md, type+1);
330 		else
331 			mputm (md, R_BAD_MESSAGE);
332 
333 	else
334 		(*pd->fncp) (m, md);
335 }
336 
337 /**
338  ** r_H() - SEND MNOPERM RESPONSE MESSAGE
339  ** r_HS() - SEND MNOPERM RESPONSE MESSAGE
340  **/
341 
342 static void
343 r_H(MESG *md, int type)
344 {
345 	mputm (md, type, MNOPERM);
346 	return;
347 }
348 
349 static void
350 r_HS(MESG *md, int type)
351 {
352 	mputm (md, type, MNOPERM, "");
353 	return;
354 }
355