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