17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0a44ef6dSjacobs * Common Development and Distribution License (the "License").
6*0a44ef6dSjacobs * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*0a44ef6dSjacobs
22*0a44ef6dSjacobs /*
23*0a44ef6dSjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24*0a44ef6dSjacobs * Use is subject to license terms.
25*0a44ef6dSjacobs */
26*0a44ef6dSjacobs
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
337c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include "lpsched.h"
367c478bd9Sstevel@tonic-gate #include <syslog.h>
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate static char *
shortenReason(char * reason)397c478bd9Sstevel@tonic-gate shortenReason(char *reason)
407c478bd9Sstevel@tonic-gate {
417c478bd9Sstevel@tonic-gate register char *ptr, *pe;
427c478bd9Sstevel@tonic-gate int peLen;
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate if (strncmp(reason,"%%[",3) == 0)
457c478bd9Sstevel@tonic-gate reason += 3;
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate while (*reason == ' ')
487c478bd9Sstevel@tonic-gate reason++;
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate pe = "PrinterError:";
517c478bd9Sstevel@tonic-gate peLen = strlen(pe);
527c478bd9Sstevel@tonic-gate if (strncmp(reason,pe,peLen) == 0)
537c478bd9Sstevel@tonic-gate reason += peLen;
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate if (((ptr = strchr(reason,']')) != NULL) && (strncmp(ptr,"]%%",3) == 0))
567c478bd9Sstevel@tonic-gate *ptr = 0;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate pe = reason + strlen(reason) -1;
597c478bd9Sstevel@tonic-gate pe = reason;
607c478bd9Sstevel@tonic-gate while (pe = strchr(pe,'\n'))
617c478bd9Sstevel@tonic-gate *pe = ' ';
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate pe = reason + strlen(reason) -1;
647c478bd9Sstevel@tonic-gate while ((pe > reason) && (*pe == ' ')) {
657c478bd9Sstevel@tonic-gate *pe = 0;
667c478bd9Sstevel@tonic-gate pe--;
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate return(reason);
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate /**
727c478bd9Sstevel@tonic-gate ** printer_fault() - RECOGNIZE PRINTER FAULT
737c478bd9Sstevel@tonic-gate **/
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate void
printer_fault(register PSTATUS * pps,register RSTATUS * prs,char * alert_text,int err)767c478bd9Sstevel@tonic-gate printer_fault(register PSTATUS *pps, register RSTATUS *prs, char *alert_text,
777c478bd9Sstevel@tonic-gate int err)
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate register char *why,*shortWhy;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate pps->status |= PS_FAULTED;
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate /* -F wait */
847c478bd9Sstevel@tonic-gate if (STREQU(pps->printer->fault_rec, NAME_WAIT))
857c478bd9Sstevel@tonic-gate disable (pps, CUZ_FAULT, DISABLE_STOP);
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate /* -F beginning */
887c478bd9Sstevel@tonic-gate else if (STREQU(pps->printer->fault_rec, NAME_BEGINNING))
897c478bd9Sstevel@tonic-gate terminate (pps->exec);
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate /* -F continue AND the interface program died */
927c478bd9Sstevel@tonic-gate else if (!(pps->status & PS_LATER) && !pps->request) {
937c478bd9Sstevel@tonic-gate load_str (&pps->dis_reason, CUZ_STOPPED);
947c478bd9Sstevel@tonic-gate schedule (EV_LATER, WHEN_PRINTER, EV_ENABLE, pps);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate if (err) {
987c478bd9Sstevel@tonic-gate errno = err;
997c478bd9Sstevel@tonic-gate why = makestr(alert_text, "(", PERROR, ")\n", (char *)0);
1007c478bd9Sstevel@tonic-gate } else if (! alert_text)
1017c478bd9Sstevel@tonic-gate why = makestr("exec exit fault", (char *) 0);
1027c478bd9Sstevel@tonic-gate else
1037c478bd9Sstevel@tonic-gate why = makestr(alert_text, (char *) 0);
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate if (!why)
1067c478bd9Sstevel@tonic-gate why = alert_text;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate shortWhy = (why != alert_text ? shortenReason(why) : why);
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate load_str (&pps->fault_reason, shortWhy);
1117c478bd9Sstevel@tonic-gate dump_fault_status (pps);
1127c478bd9Sstevel@tonic-gate if (STREQU(pps->printer->fault_alert.shcmd,"show fault"))
1137c478bd9Sstevel@tonic-gate pps->status |= PS_SHOW_FAULT;
1147c478bd9Sstevel@tonic-gate else
1157c478bd9Sstevel@tonic-gate pps->status &= ~PS_SHOW_FAULT;
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate note("printer fault. type: %s, status: %x\nmsg: (%s)\n",
1187c478bd9Sstevel@tonic-gate (pps->printer->fault_alert.shcmd ?
1197c478bd9Sstevel@tonic-gate pps->printer->fault_alert.shcmd : "??"),
1207c478bd9Sstevel@tonic-gate pps->status, shortWhy);
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate if (pps->status & PS_SHOW_FAULT)
1237c478bd9Sstevel@tonic-gate schedule (EV_MESSAGE, pps);
1247c478bd9Sstevel@tonic-gate else {
1257c478bd9Sstevel@tonic-gate alert(A_PRINTER, pps, prs, shortWhy);
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate if (why != alert_text)
1287c478bd9Sstevel@tonic-gate Free (why);
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate /**
1327c478bd9Sstevel@tonic-gate ** clear_printer_fault() - RECOGNIZE PRINTER FAULT
1337c478bd9Sstevel@tonic-gate **/
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate void
clear_printer_fault(register PSTATUS * pps,char * alert_text)1367c478bd9Sstevel@tonic-gate clear_printer_fault(register PSTATUS *pps, char *alert_text)
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate register char *why, *shortWhy;
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate pps->status &= ~PS_FAULTED;
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate why = makestr(alert_text, (char *) 0);
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate shortWhy = (why ? shortenReason(why) : alert_text);
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate load_str (&pps->fault_reason, shortWhy);
1477c478bd9Sstevel@tonic-gate dump_fault_status (pps);
1487c478bd9Sstevel@tonic-gate if (STREQU(pps->printer->fault_alert.shcmd,"show fault"))
1497c478bd9Sstevel@tonic-gate pps->status |= PS_SHOW_FAULT;
1507c478bd9Sstevel@tonic-gate else
1517c478bd9Sstevel@tonic-gate pps->status &= ~PS_SHOW_FAULT;
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate if (pps->status & PS_SHOW_FAULT)
1547c478bd9Sstevel@tonic-gate schedule (EV_MESSAGE, pps);
1557c478bd9Sstevel@tonic-gate if (why != alert_text)
1567c478bd9Sstevel@tonic-gate Free(why);
1577c478bd9Sstevel@tonic-gate schedule(EV_ENABLE, pps);
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate /**
1617c478bd9Sstevel@tonic-gate ** dial_problem() - ADDRESS DIAL-OUT PROBLEM
1627c478bd9Sstevel@tonic-gate **/
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate void
dial_problem(register PSTATUS * pps,RSTATUS * prs,int rc)1657c478bd9Sstevel@tonic-gate dial_problem(register PSTATUS *pps, RSTATUS *prs, int rc)
1667c478bd9Sstevel@tonic-gate {
1677c478bd9Sstevel@tonic-gate static struct problem {
1687c478bd9Sstevel@tonic-gate char *reason;
1697c478bd9Sstevel@tonic-gate int retry_max,
1707c478bd9Sstevel@tonic-gate dial_error;
1717c478bd9Sstevel@tonic-gate } problems[] = {
1727c478bd9Sstevel@tonic-gate "DIAL FAILED", 10, 2, /* D_HUNG */
1737c478bd9Sstevel@tonic-gate "CALLER SCRIPT FAILED", 10, 3, /* NO_ANS */
1747c478bd9Sstevel@tonic-gate "CAN'T ACCESS DEVICE", 0, 6, /* L_PROB */
1757c478bd9Sstevel@tonic-gate "DEVICE LOCKED", 20, 8, /* DV_NT_A */
1767c478bd9Sstevel@tonic-gate "NO DEVICES AVAILABLE", 0, 10, /* NO_BD_A */
1777c478bd9Sstevel@tonic-gate "SYSTEM NOT IN Systems FILE", 0, 13, /* BAD_SYS */
1787c478bd9Sstevel@tonic-gate "UNKNOWN dial() FAILURE", 0, 0
1797c478bd9Sstevel@tonic-gate };
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate register struct problem *p;
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate register char *msg;
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate #define PREFIX "Connect problem: "
1867c478bd9Sstevel@tonic-gate #define SUFFIX "This problem has occurred several times.\nPlease check the dialing instructions for this printer.\n"
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate for (p = problems; p->dial_error; p++)
1907c478bd9Sstevel@tonic-gate if (p->dial_error == rc)
1917c478bd9Sstevel@tonic-gate break;
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate if (!p->retry_max) {
1947c478bd9Sstevel@tonic-gate msg = Malloc(strlen(PREFIX) + strlen(p->reason) + 2);
1957c478bd9Sstevel@tonic-gate sprintf (msg, "%s%s\n", PREFIX, p->reason);
1967c478bd9Sstevel@tonic-gate printer_fault (pps, prs, msg, 0);
1977c478bd9Sstevel@tonic-gate Free (msg);
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate } else if (pps->last_dial_rc != rc) {
2007c478bd9Sstevel@tonic-gate pps->nretry = 1;
2017c478bd9Sstevel@tonic-gate pps->last_dial_rc = (short)rc;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate } else if (pps->nretry++ > p->retry_max) {
2047c478bd9Sstevel@tonic-gate pps->nretry = 0;
2057c478bd9Sstevel@tonic-gate pps->last_dial_rc = (short)rc;
2067c478bd9Sstevel@tonic-gate msg = Malloc(
2077c478bd9Sstevel@tonic-gate strlen(PREFIX) + strlen(p->reason) + strlen(SUFFIX) + 2
2087c478bd9Sstevel@tonic-gate );
2097c478bd9Sstevel@tonic-gate sprintf (msg, "%s%s%s\n", PREFIX, p->reason, SUFFIX);
2107c478bd9Sstevel@tonic-gate printer_fault (pps, prs, msg, 0);
2117c478bd9Sstevel@tonic-gate Free (msg);
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate if (!(pps->status & PS_FAULTED)) {
2157c478bd9Sstevel@tonic-gate load_str (&pps->dis_reason, p->reason);
2167c478bd9Sstevel@tonic-gate schedule (EV_LATER, WHEN_PRINTER, EV_ENABLE, pps);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate return;
2207c478bd9Sstevel@tonic-gate }
221