17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
50a44ef6jacobs * Common Development and Distribution License (the "License").
60a44ef6jacobs * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
220a44ef6jacobs * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bdstevel@tonic-gate/*	  All Rights Reserved  	*/
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#include "time.h"
317c478bdstevel@tonic-gate#include "dispatch.h"
327c478bdstevel@tonic-gate#include <syslog.h>
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate/**
367c478bdstevel@tonic-gate ** s_accept_dest()
377c478bdstevel@tonic-gate **/
387c478bdstevel@tonic-gate
397c478bdstevel@tonic-gatevoid
407c478bdstevel@tonic-gates_accept_dest(char *m, MESG *md)
417c478bdstevel@tonic-gate{
427c478bdstevel@tonic-gate	char			*destination;
437c478bdstevel@tonic-gate	ushort			status;
447c478bdstevel@tonic-gate	register PSTATUS	*pps;
4519d32b9Robert Mustacchi	register CLSTATUS	*pcs;
467c478bdstevel@tonic-gate
477c478bdstevel@tonic-gate	getmessage (m, S_ACCEPT_DEST, &destination);
487c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_accept_dest(%s)",
497c478bdstevel@tonic-gate	       (destination ? destination : "NULL"));
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gate	/*
527c478bdstevel@tonic-gate	 * Have we seen this destination as a printer?
537c478bdstevel@tonic-gate	 */
540a44ef6jacobs	if ((pps = search_pstatus(destination)))
557c478bdstevel@tonic-gate		if ((pps->status & PS_REJECTED) == 0)
567c478bdstevel@tonic-gate			status = MERRDEST;
577c478bdstevel@tonic-gate		else {
587c478bdstevel@tonic-gate			pps->status &= ~PS_REJECTED;
597c478bdstevel@tonic-gate			(void) time (&pps->rej_date);
607c478bdstevel@tonic-gate			dump_pstatus ();
617c478bdstevel@tonic-gate			status = MOK;
627c478bdstevel@tonic-gate		}
637c478bdstevel@tonic-gate
647c478bdstevel@tonic-gate	/*
657c478bdstevel@tonic-gate	 * Have we seen this destination as a class?
667c478bdstevel@tonic-gate	 */
670a44ef6jacobs	else if ((pcs = search_cstatus(destination)))
687c478bdstevel@tonic-gate		if ((pcs->status & CS_REJECTED) == 0)
697c478bdstevel@tonic-gate			status = MERRDEST;
707c478bdstevel@tonic-gate		else {
717c478bdstevel@tonic-gate			pcs->status &= ~CS_REJECTED;
727c478bdstevel@tonic-gate			(void) time (&pcs->rej_date);
737c478bdstevel@tonic-gate			dump_cstatus ();
747c478bdstevel@tonic-gate			status = MOK;
757c478bdstevel@tonic-gate		}
767c478bdstevel@tonic-gate
777c478bdstevel@tonic-gate	else
787c478bdstevel@tonic-gate		status = MNODEST;
797c478bdstevel@tonic-gate
807c478bdstevel@tonic-gate	mputm (md, R_ACCEPT_DEST, status);
817c478bdstevel@tonic-gate	return;
827c478bdstevel@tonic-gate}
837c478bdstevel@tonic-gate
847c478bdstevel@tonic-gate/**
857c478bdstevel@tonic-gate ** s_reject_dest()
867c478bdstevel@tonic-gate **/
877c478bdstevel@tonic-gate
887c478bdstevel@tonic-gatevoid
897c478bdstevel@tonic-gates_reject_dest(char *m, MESG *md)
907c478bdstevel@tonic-gate{
917c478bdstevel@tonic-gate	char			*destination,
927c478bdstevel@tonic-gate				*reason;
937c478bdstevel@tonic-gate	ushort			status;
947c478bdstevel@tonic-gate	register PSTATUS	*pps;
9519d32b9Robert Mustacchi	register CLSTATUS	*pcs;
967c478bdstevel@tonic-gate
977c478bdstevel@tonic-gate
987c478bdstevel@tonic-gate	getmessage (m, S_REJECT_DEST, &destination, &reason);
997c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_reject_dest(%s, %s)",
1007c478bdstevel@tonic-gate	       (destination ? destination : "NULL"),
1017c478bdstevel@tonic-gate	       (reason ? reason : "NULL"));
1027c478bdstevel@tonic-gate
1037c478bdstevel@tonic-gate	/*
1047c478bdstevel@tonic-gate	 * Have we seen this destination as a printer?
1057c478bdstevel@tonic-gate	 */
1060a44ef6jacobs	if ((pps = search_pstatus(destination)))
1077c478bdstevel@tonic-gate		if (pps->status & PS_REJECTED)
1087c478bdstevel@tonic-gate			status = MERRDEST;
1097c478bdstevel@tonic-gate		else {
1107c478bdstevel@tonic-gate			pps->status |= PS_REJECTED;
1117c478bdstevel@tonic-gate			(void) time (&pps->rej_date);
1127c478bdstevel@tonic-gate			load_str (&pps->rej_reason, reason);
1137c478bdstevel@tonic-gate			dump_pstatus ();
1147c478bdstevel@tonic-gate			status = MOK;
1157c478bdstevel@tonic-gate		}
1167c478bdstevel@tonic-gate
1177c478bdstevel@tonic-gate	/*
1187c478bdstevel@tonic-gate	 * Have we seen this destination as a class?
1197c478bdstevel@tonic-gate	 */
1200a44ef6jacobs	else if ((pcs = search_cstatus(destination)))
1217c478bdstevel@tonic-gate		if (pcs->status & CS_REJECTED)
1227c478bdstevel@tonic-gate			status = MERRDEST;
1237c478bdstevel@tonic-gate		else {
1247c478bdstevel@tonic-gate			pcs->status |= CS_REJECTED;
1257c478bdstevel@tonic-gate			(void) time (&pcs->rej_date);
1267c478bdstevel@tonic-gate			load_str (&pcs->rej_reason, reason);
1277c478bdstevel@tonic-gate			dump_cstatus ();
1287c478bdstevel@tonic-gate			status = MOK;
1297c478bdstevel@tonic-gate		}
1307c478bdstevel@tonic-gate
1317c478bdstevel@tonic-gate	else
1327c478bdstevel@tonic-gate		status = MNODEST;
1337c478bdstevel@tonic-gate
1347c478bdstevel@tonic-gate	mputm (md, R_REJECT_DEST, status);
1357c478bdstevel@tonic-gate	return;
1367c478bdstevel@tonic-gate}
1377c478bdstevel@tonic-gate
1387c478bdstevel@tonic-gate/**
1397c478bdstevel@tonic-gate ** s_enable_dest()
1407c478bdstevel@tonic-gate **/
1417c478bdstevel@tonic-gate
1427c478bdstevel@tonic-gatevoid
1437c478bdstevel@tonic-gates_enable_dest(char *m, MESG *md)
1447c478bdstevel@tonic-gate{
1457c478bdstevel@tonic-gate	char			*printer;
1467c478bdstevel@tonic-gate	ushort			status;
1477c478bdstevel@tonic-gate	register PSTATUS	*pps;
1487c478bdstevel@tonic-gate
1497c478bdstevel@tonic-gate
1507c478bdstevel@tonic-gate	getmessage (m, S_ENABLE_DEST, &printer);
1517c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_enable_dest(%s)", (printer ? printer : "NULL"));
1527c478bdstevel@tonic-gate
1537c478bdstevel@tonic-gate	/*
1547c478bdstevel@tonic-gate	 * Have we seen this printer before?
1557c478bdstevel@tonic-gate	 */
1560a44ef6jacobs	if ((pps = search_pstatus(printer)))
1577c478bdstevel@tonic-gate		if (enable(pps) == -1)
1587c478bdstevel@tonic-gate			status = MERRDEST;
1597c478bdstevel@tonic-gate		else
1607c478bdstevel@tonic-gate			status = MOK;
1617c478bdstevel@tonic-gate	else
1627c478bdstevel@tonic-gate		status = MNODEST;
1637c478bdstevel@tonic-gate
1647c478bdstevel@tonic-gate	mputm (md, R_ENABLE_DEST, status);
1657c478bdstevel@tonic-gate	return;
1667c478bdstevel@tonic-gate}
1677c478bdstevel@tonic-gate
1687c478bdstevel@tonic-gate/**
1697c478bdstevel@tonic-gate ** s_disable_dest()
1707c478bdstevel@tonic-gate **/
1717c478bdstevel@tonic-gate
1727c478bdstevel@tonic-gatevoid
1737c478bdstevel@tonic-gates_disable_dest(char *m, MESG *md)
1747c478bdstevel@tonic-gate{
1757c478bdstevel@tonic-gate	char			*destination,
1767c478bdstevel@tonic-gate				*reason,
1777c478bdstevel@tonic-gate				*req_id		= 0;
1787c478bdstevel@tonic-gate	ushort			when,
1797c478bdstevel@tonic-gate				status;
1807c478bdstevel@tonic-gate	register PSTATUS	*pps;
1817c478bdstevel@tonic-gate
1827c478bdstevel@tonic-gate	getmessage (m, S_DISABLE_DEST, &destination, &reason, &when);
1837c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_disable_dest(%s, %s, %d)",
1847c478bdstevel@tonic-gate	       (destination ? destination : "NULL"),
1857c478bdstevel@tonic-gate	       (reason ? reason : "NULL"), when);
1867c478bdstevel@tonic-gate
1877c478bdstevel@tonic-gate
1887c478bdstevel@tonic-gate	/*
1897c478bdstevel@tonic-gate	 * Have we seen this printer before?
1907c478bdstevel@tonic-gate	 */
1910a44ef6jacobs	if ((pps = search_pstatus(destination))) {
1927c478bdstevel@tonic-gate
1937c478bdstevel@tonic-gate		/*
1947c478bdstevel@tonic-gate		 * If we are to cancel a currently printing request,
1957c478bdstevel@tonic-gate		 * we will send back the request's ID.
1967c478bdstevel@tonic-gate		 * Save a copy of the ID before calling "disable()",
1977c478bdstevel@tonic-gate		 * in case the disabling loses it (e.g. the request
1987c478bdstevel@tonic-gate		 * might get attached to another printer). (Actually,
1997c478bdstevel@tonic-gate		 * the current implementation won't DETACH the request
2007c478bdstevel@tonic-gate		 * from this printer until the child process responds,
2017c478bdstevel@tonic-gate		 * but a future implementation might.)
2027c478bdstevel@tonic-gate		 */
2037c478bdstevel@tonic-gate		if (pps->request && when == 2)
2047c478bdstevel@tonic-gate			req_id = Strdup(pps->request->secure->req_id);
2057c478bdstevel@tonic-gate
2067c478bdstevel@tonic-gate		if (disable(pps, reason, (int)when) == -1) {
2077c478bdstevel@tonic-gate			if (req_id) {
2087c478bdstevel@tonic-gate				Free (req_id);
2097c478bdstevel@tonic-gate				req_id = 0;
2107c478bdstevel@tonic-gate			}
2117c478bdstevel@tonic-gate			status = MERRDEST;
2127c478bdstevel@tonic-gate		} else
2137c478bdstevel@tonic-gate			status = MOK;
2147c478bdstevel@tonic-gate
2157c478bdstevel@tonic-gate	} else
2167c478bdstevel@tonic-gate		status = MNODEST;
2177c478bdstevel@tonic-gate
2187c478bdstevel@tonic-gate	mputm (md, R_DISABLE_DEST, status, NB(req_id));
2197c478bdstevel@tonic-gate	if (req_id)
2207c478bdstevel@tonic-gate		Free (req_id);
2217c478bdstevel@tonic-gate
2227c478bdstevel@tonic-gate	return;
2237c478bdstevel@tonic-gate}
2247c478bdstevel@tonic-gate
2257c478bdstevel@tonic-gate/**
2267c478bdstevel@tonic-gate ** s_load_filter_table()
2277c478bdstevel@tonic-gate **/
2287c478bdstevel@tonic-gate
2297c478bdstevel@tonic-gatevoid
2307c478bdstevel@tonic-gates_load_filter_table(char *m, MESG *md)
2317c478bdstevel@tonic-gate{
2327c478bdstevel@tonic-gate	ushort			status;
2337c478bdstevel@tonic-gate
2347c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_load_filter_table()");
2357c478bdstevel@tonic-gate
2367c478bdstevel@tonic-gate	trash_filters ();
2377c478bdstevel@tonic-gate	if (Loadfilters((char *)0) == -1)
2387c478bdstevel@tonic-gate		status = MNOOPEN;
2397c478bdstevel@tonic-gate	else {
2407c478bdstevel@tonic-gate		/*
2417c478bdstevel@tonic-gate		 * This is what makes changing filters expensive!
2427c478bdstevel@tonic-gate		 */
2437c478bdstevel@tonic-gate		queue_check (qchk_filter);
2447c478bdstevel@tonic-gate
2457c478bdstevel@tonic-gate		status = MOK;
2467c478bdstevel@tonic-gate	}
2477c478bdstevel@tonic-gate
2487c478bdstevel@tonic-gate	mputm (md, R_LOAD_FILTER_TABLE, status);
2497c478bdstevel@tonic-gate	return;
2507c478bdstevel@tonic-gate}
2517c478bdstevel@tonic-gate
2527c478bdstevel@tonic-gate/**
2537c478bdstevel@tonic-gate ** s_unload_filter_table()
2547c478bdstevel@tonic-gate **/
2557c478bdstevel@tonic-gate
2567c478bdstevel@tonic-gatevoid
2577c478bdstevel@tonic-gates_unload_filter_table(char *m, MESG *md)
2587c478bdstevel@tonic-gate{
2597c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_unload_filter_table()");
2607c478bdstevel@tonic-gate
2617c478bdstevel@tonic-gate	trash_filters ();
2627c478bdstevel@tonic-gate
2637c478bdstevel@tonic-gate	/*
2647c478bdstevel@tonic-gate	 * This is what makes changing filters expensive!
2657c478bdstevel@tonic-gate	 */
2667c478bdstevel@tonic-gate	queue_check (qchk_filter);
2677c478bdstevel@tonic-gate
2687c478bdstevel@tonic-gate	mputm (md, R_UNLOAD_FILTER_TABLE, MOK);
2697c478bdstevel@tonic-gate	return;
2707c478bdstevel@tonic-gate}
2717c478bdstevel@tonic-gate
2727c478bdstevel@tonic-gate/**
2737c478bdstevel@tonic-gate ** s_load_user_file()
2747c478bdstevel@tonic-gate **/
2757c478bdstevel@tonic-gate
2767c478bdstevel@tonic-gatevoid
2777c478bdstevel@tonic-gates_load_user_file(char *m, MESG *md)
2787c478bdstevel@tonic-gate{
2797c478bdstevel@tonic-gate	/*
2807c478bdstevel@tonic-gate	 * The first call to "getuser()" will load the whole file.
2817c478bdstevel@tonic-gate	 */
2827c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_load_user_file()");
2837c478bdstevel@tonic-gate
2847c478bdstevel@tonic-gate	trashusers ();
2857c478bdstevel@tonic-gate
2867c478bdstevel@tonic-gate	mputm (md, R_LOAD_USER_FILE, MOK);
2877c478bdstevel@tonic-gate	return;
2887c478bdstevel@tonic-gate}
2897c478bdstevel@tonic-gate
2907c478bdstevel@tonic-gate/**
2917c478bdstevel@tonic-gate ** s_unload_user_file()
2927c478bdstevel@tonic-gate **/
2937c478bdstevel@tonic-gate
2947c478bdstevel@tonic-gatevoid
2957c478bdstevel@tonic-gates_unload_user_file(char *m, MESG *md)
2967c478bdstevel@tonic-gate{
2977c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_unload_user_file()");
2987c478bdstevel@tonic-gate
2997c478bdstevel@tonic-gate	trashusers ();	/* THIS WON'T DO TRUE UNLOAD, SORRY! */
3007c478bdstevel@tonic-gate
3017c478bdstevel@tonic-gate	mputm (md, R_UNLOAD_USER_FILE, MOK);
3027c478bdstevel@tonic-gate	return;
3037c478bdstevel@tonic-gate}
3047c478bdstevel@tonic-gate/**
3057c478bdstevel@tonic-gate ** s_shutdown()
3067c478bdstevel@tonic-gate **/
3077c478bdstevel@tonic-gate
3087c478bdstevel@tonic-gatevoid
3097c478bdstevel@tonic-gates_shutdown(char *m, MESG *md)
3107c478bdstevel@tonic-gate{
3117c478bdstevel@tonic-gate	ushort			immediate;
3127c478bdstevel@tonic-gate
3137c478bdstevel@tonic-gate	(void)getmessage (m, S_SHUTDOWN, &immediate);
3147c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_shutdown(%d)", immediate);
3157c478bdstevel@tonic-gate
3167c478bdstevel@tonic-gate	switch (md->type) {
3177c478bdstevel@tonic-gate	case MD_STREAM:
3187c478bdstevel@tonic-gate	case MD_SYS_FIFO:
3197c478bdstevel@tonic-gate	case MD_USR_FIFO:
3207c478bdstevel@tonic-gate		mputm (md, R_SHUTDOWN, MOK);
3217c478bdstevel@tonic-gate		lpshut (immediate);
3227c478bdstevel@tonic-gate		/*NOTREACHED*/
3237c478bdstevel@tonic-gate	default:
3247c478bdstevel@tonic-gate		syslog(LOG_DEBUG,
3257c478bdstevel@tonic-gate		       "Received S_SHUTDOWN on a type %d connection\n",
3267c478bdstevel@tonic-gate		       md->type);
3277c478bdstevel@tonic-gate	}
3287c478bdstevel@tonic-gate
3297c478bdstevel@tonic-gate	return;
3307c478bdstevel@tonic-gate}
3317c478bdstevel@tonic-gate
3327c478bdstevel@tonic-gate/**
3337c478bdstevel@tonic-gate ** s_quiet_alert()
3347c478bdstevel@tonic-gate **/
3357c478bdstevel@tonic-gate
3367c478bdstevel@tonic-gatevoid
3377c478bdstevel@tonic-gates_quiet_alert(char *m, MESG *md)
3387c478bdstevel@tonic-gate{
3397c478bdstevel@tonic-gate	char			*name;
3407c478bdstevel@tonic-gate	ushort			type,
3417c478bdstevel@tonic-gate				status;
3427c478bdstevel@tonic-gate	register FSTATUS	*pfs;
3437c478bdstevel@tonic-gate	register PSTATUS	*pps;
3447c478bdstevel@tonic-gate	register PWSTATUS	*ppws;
3457c478bdstevel@tonic-gate
3467c478bdstevel@tonic-gate
3477c478bdstevel@tonic-gate	/*
3487c478bdstevel@tonic-gate	 * We quiet an alert by cancelling it with "cancel_alert()"
3497c478bdstevel@tonic-gate	 * and then resetting the active flag. This effectively just
3507c478bdstevel@tonic-gate	 * terminates the process running the alert but tricks the
3517c478bdstevel@tonic-gate	 * rest of the Spooler into thinking it is still active.
3527c478bdstevel@tonic-gate	 * The alert will be reactivated only AFTER "cancel_alert()"
3537c478bdstevel@tonic-gate	 * has been called (to clear the active flag) and then "alert()"
3547c478bdstevel@tonic-gate	 * is called again. Thus:
3557c478bdstevel@tonic-gate	 *
3567c478bdstevel@tonic-gate	 * For printer faults the alert will be reactivated when:
3577c478bdstevel@tonic-gate	 *	- a fault is found after the current fault has been
3587c478bdstevel@tonic-gate	 *	  cleared (i.e. after successful print or after manually
3597c478bdstevel@tonic-gate	 *	  enabled).
3607c478bdstevel@tonic-gate	 *
3617c478bdstevel@tonic-gate	 * For forms/print-wheels the alert will be reactivated when:
3627c478bdstevel@tonic-gate	 *	- the form/print-wheel becomes mounted and then unmounted
3637c478bdstevel@tonic-gate	 *	  again, with too many requests still pending;
3647c478bdstevel@tonic-gate	 *	- the number of requests falls below the threshold and
3657c478bdstevel@tonic-gate	 *	  then rises above it again.
3667c478bdstevel@tonic-gate	 */
3677c478bdstevel@tonic-gate
3687c478bdstevel@tonic-gate	(void)getmessage (m, S_QUIET_ALERT, &name, &type);
3697c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_quiet_alert(%s, %d)", (name ? name : "NULL"),
3707c478bdstevel@tonic-gate	       type);
3717c478bdstevel@tonic-gate
3727c478bdstevel@tonic-gate	if (!*name)
3737c478bdstevel@tonic-gate		status = MNODEST;
3747c478bdstevel@tonic-gate
3757c478bdstevel@tonic-gate	else switch (type) {
3767c478bdstevel@tonic-gate	case QA_FORM:
3770a44ef6jacobs		if (!(pfs = search_fstatus(name)))
3787c478bdstevel@tonic-gate			status = MNODEST;
3797c478bdstevel@tonic-gate
3807c478bdstevel@tonic-gate		else if (!pfs->alert->active)
3817c478bdstevel@tonic-gate			status = MERRDEST;
3827c478bdstevel@tonic-gate
3837c478bdstevel@tonic-gate		else {
3847c478bdstevel@tonic-gate			cancel_alert (A_FORM, pfs);
3857c478bdstevel@tonic-gate			pfs->alert->active = 1;
3867c478bdstevel@tonic-gate			status = MOK;
3877c478bdstevel@tonic-gate		}
3887c478bdstevel@tonic-gate		break;
3897c478bdstevel@tonic-gate
3907c478bdstevel@tonic-gate	case QA_PRINTER:
3910a44ef6jacobs		if (!(pps = search_pstatus(name)))
3927c478bdstevel@tonic-gate			status = MNODEST;
3937c478bdstevel@tonic-gate
3947c478bdstevel@tonic-gate		else if (!pps->alert->active)
3957c478bdstevel@tonic-gate			status = MERRDEST;
3967c478bdstevel@tonic-gate
3977c478bdstevel@tonic-gate		else {
3987c478bdstevel@tonic-gate			cancel_alert (A_PRINTER, pps);
3997c478bdstevel@tonic-gate			pps->alert->active = 1;
4007c478bdstevel@tonic-gate			status = MOK;
4017c478bdstevel@tonic-gate		}
4027c478bdstevel@tonic-gate		break;
4037c478bdstevel@tonic-gate
4047c478bdstevel@tonic-gate	case QA_PRINTWHEEL:
4050a44ef6jacobs		if (!(ppws = search_pwstatus(name)))
4067c478bdstevel@tonic-gate			status = MNODEST;
4077c478bdstevel@tonic-gate
4087c478bdstevel@tonic-gate		else if (!ppws->alert->active)
4097c478bdstevel@tonic-gate			status = MERRDEST;
4107c478bdstevel@tonic-gate
4117c478bdstevel@tonic-gate		else {
4127c478bdstevel@tonic-gate			cancel_alert (A_PWHEEL, ppws);
4137c478bdstevel@tonic-gate			ppws->alert->active = 1;
4147c478bdstevel@tonic-gate			status = MOK;
4157c478bdstevel@tonic-gate		}
4167c478bdstevel@tonic-gate		break;
4177c478bdstevel@tonic-gate	}
4187c478bdstevel@tonic-gate
4197c478bdstevel@tonic-gate	mputm (md, R_QUIET_ALERT, status);
4207c478bdstevel@tonic-gate	return;
4217c478bdstevel@tonic-gate}
4227c478bdstevel@tonic-gate
4237c478bdstevel@tonic-gate/**
4247c478bdstevel@tonic-gate ** s_send_fault()
4257c478bdstevel@tonic-gate **/
4267c478bdstevel@tonic-gate
4277c478bdstevel@tonic-gatevoid
4287c478bdstevel@tonic-gates_send_fault(char *m, MESG *md)
4297c478bdstevel@tonic-gate{
4307c478bdstevel@tonic-gate	long			key;
4317c478bdstevel@tonic-gate	char			*printerOrForm, *alert_text;
4327c478bdstevel@tonic-gate	ushort			status;
4337c478bdstevel@tonic-gate	register PSTATUS	*pps;
4347c478bdstevel@tonic-gate
4357c478bdstevel@tonic-gate	getmessage (m, S_SEND_FAULT, &printerOrForm, &key, &alert_text);
4367c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_send_fault(%s, %x, %s)",
4377c478bdstevel@tonic-gate	       (printerOrForm ? printerOrForm : "NULL"), key,
4387c478bdstevel@tonic-gate	       (alert_text ? alert_text : "NULL"));
4397c478bdstevel@tonic-gate
4400a44ef6jacobs	if (!(pps = search_pstatus(printerOrForm)) || (!pps->exec) ||
4417c478bdstevel@tonic-gate		pps->exec->key != key || !pps->request) {
4427c478bdstevel@tonic-gate		status = MERRDEST;
4437c478bdstevel@tonic-gate	} else {
4447c478bdstevel@tonic-gate		printer_fault(pps, pps->request, alert_text, 0);
4457c478bdstevel@tonic-gate		status = MOK;
4467c478bdstevel@tonic-gate	}
4477c478bdstevel@tonic-gate
4487c478bdstevel@tonic-gate	mputm (md, R_SEND_FAULT, status);
4497c478bdstevel@tonic-gate}
4507c478bdstevel@tonic-gate
4517c478bdstevel@tonic-gate/*
4527c478bdstevel@tonic-gate * s_clear_fault()
4537c478bdstevel@tonic-gate */
4547c478bdstevel@tonic-gatevoid
4557c478bdstevel@tonic-gates_clear_fault(char *m, MESG *md)
4567c478bdstevel@tonic-gate{
4577c478bdstevel@tonic-gate	long	key;
4587c478bdstevel@tonic-gate	char	*printerOrForm, *alert_text;
4597c478bdstevel@tonic-gate	ushort	status;
4607c478bdstevel@tonic-gate	register PSTATUS	*pps;
4617c478bdstevel@tonic-gate
4627c478bdstevel@tonic-gate	getmessage(m, S_CLEAR_FAULT, &printerOrForm, &key, &alert_text);
4637c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_clear_fault(%s, %x, %s)",
4647c478bdstevel@tonic-gate	       (printerOrForm ? printerOrForm : "NULL"), key,
4657c478bdstevel@tonic-gate	       (alert_text ? alert_text : "NULL"));
4667c478bdstevel@tonic-gate
4677c478bdstevel@tonic-gate
4680a44ef6jacobs	if (! (pps = search_pstatus(printerOrForm)) || ((key > 0) &&
4697c478bdstevel@tonic-gate	    ((!pps->exec) || pps->exec->key != key || !pps->request ))) {
4707c478bdstevel@tonic-gate		status = MERRDEST;
4717c478bdstevel@tonic-gate	} else {
4727c478bdstevel@tonic-gate		clear_printer_fault(pps, alert_text);
4737c478bdstevel@tonic-gate		status = MOK;
4747c478bdstevel@tonic-gate	}
4757c478bdstevel@tonic-gate
4767c478bdstevel@tonic-gate	mputm (md, R_CLEAR_FAULT, status);
4777c478bdstevel@tonic-gate}
4787c478bdstevel@tonic-gate
4797c478bdstevel@tonic-gate
4807c478bdstevel@tonic-gate/*
4817c478bdstevel@tonic-gate * s_paper_changed()
4827c478bdstevel@tonic-gate */
4837c478bdstevel@tonic-gatevoid
4847c478bdstevel@tonic-gates_paper_changed(char *m, MESG *md)
4857c478bdstevel@tonic-gate{
4867c478bdstevel@tonic-gate	short			trayNum, mode, pagesPrinted;
4877c478bdstevel@tonic-gate	char			*printer, *paper;
4887c478bdstevel@tonic-gate	ushort			status;
4897c478bdstevel@tonic-gate	short			chgd = 0;
4907c478bdstevel@tonic-gate	register PSTATUS	*pps;
4917c478bdstevel@tonic-gate	register FSTATUS	*pfs,*pfsWas;
4927c478bdstevel@tonic-gate
4937c478bdstevel@tonic-gate	getmessage(m, S_PAPER_CHANGED, &printer, &trayNum, &paper, &mode,
4947c478bdstevel@tonic-gate		&pagesPrinted);
4957c478bdstevel@tonic-gate	syslog(LOG_DEBUG, "s_paper_changed(%s, %d, %s, %d, %d)",
4967c478bdstevel@tonic-gate	       (printer ? printer : "NULL"), trayNum, (paper ? paper : "NULL"),
4977c478bdstevel@tonic-gate	       mode, pagesPrinted);
4987c478bdstevel@tonic-gate
4990a44ef6jacobs	if (!(pps = search_pstatus(printer)))
5007c478bdstevel@tonic-gate		status = MNODEST;
5017c478bdstevel@tonic-gate	else if ((trayNum <=0) || (trayNum > pps->numForms))
5027c478bdstevel@tonic-gate		status = MNOTRAY;
5037c478bdstevel@tonic-gate	else {
5047c478bdstevel@tonic-gate		status = MOK;
5057c478bdstevel@tonic-gate		if (*paper && (pfsWas = pps->forms[trayNum-1].form) &&
5067c478bdstevel@tonic-gate		    (!STREQU(pfsWas->form->paper,paper))) {
5077c478bdstevel@tonic-gate			pfs = search_fptable(paper);
5087c478bdstevel@tonic-gate			if (pfs) {
5097c478bdstevel@tonic-gate				remount_form(pps, pfs, trayNum);
5107c478bdstevel@tonic-gate				chgd = 1;
5117c478bdstevel@tonic-gate			} else
5127c478bdstevel@tonic-gate				status = MNOMEDIA;
5137c478bdstevel@tonic-gate		}
5147c478bdstevel@tonic-gate		if ( status == MOK ) {
5157c478bdstevel@tonic-gate			pps->forms[trayNum].isAvailable = mode;
5160a44ef6jacobs			if ((chgd || !mode) && (!pagesPrinted) && pps->exec) {
5177c478bdstevel@tonic-gate				if (pps->request)
5187c478bdstevel@tonic-gate					pps->request->request->outcome |=
5197c478bdstevel@tonic-gate						RS_STOPPED;
5207c478bdstevel@tonic-gate				terminate(pps->exec);
5217c478bdstevel@tonic-gate				schedule(EV_LATER, 1, EV_INTERF, pps);
5227c478bdstevel@tonic-gate			}
5237c478bdstevel@tonic-gate		}
5247c478bdstevel@tonic-gate	}
5257c478bdstevel@tonic-gate	mputm(md, R_PAPER_CHANGED, status);
5267c478bdstevel@tonic-gate}
5277c478bdstevel@tonic-gate
528