/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <libintl.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <syslog.h>
#include "netpr.h"
static int netpr_send_message(int, char *, ...);
static int xfer_cfAfile(int, char *, char *, uint);
int
{
int filesize;
int xfer;
int net;
bsdjob->np_printer) != 0) {
return (NETWORK_ERROR_SEND_RESPONSE);
}
/*
* control file
*/
bsdjob->np_cfAfilesize)) != 0) {
gettext("Netpr: Error sending control file\n"));
return (NETWORK_ERROR_UNKNOWN);
}
}
/* send msg - get ready for transfer */
return (NETWORK_ERROR_SEND_RESPONSE);
}
/*
* send the file
*/
return (xfer);
}
/* send msg - done */
gettext("Netpr: network error transfering %s returns: %d\n"),
"network error transfering %s returns: %d",
return (NETWORK_ERROR_WRITE_FAILED);
}
/*
* control file
*/
bsdjob->np_cfAfilesize)) != 0) {
gettext("Netpr: Error sending control file\n"));
return (NETWORK_ERROR_UNKNOWN);
}
}
return (0);
}
int
{
int ctr;
int timeout;
int nw;
int error_msg = 0;
int pause = 0;
/* send file */
while (ctr > 0) {
(void) alarm(10);
(void) alarm(0);
timeout *= 2;
timeout *= 2;
/*
* Send message to user once
*/
if (error_msg == 0) {
error_msg++;
gettext("Printer not accepting input;"
"possibly offline or out of paper."));
}
if (pause++ > 3)
}
} else {
if (error_msg) {
error_msg = 0;
pause = 0;
}
}
}
return (E_SUCCESS);
}
static int
{
int ctr;
int nw = 0;
int timeout;
int printererr;
return (NETWORK_ERROR_MSG_FAILED);
}
/* send the control file */
/* send control file */
printererr = 0;
while (ctr > 0) {
(void) alarm(2);
(void) alarm(0);
if (nw <= 0) {
if (timeout < 16) {
timeout *= 2;
} else if (timeout == 16) {
/* talk with the printer and see what's happening */
/* send message back to caller */
timeout *= 2;
printererr = 1;
gettext("Printer not accepting input;"
"possibly offline or out of paper."));
} else if (timeout > 16) {
}
}
}
if (printererr == 1) {
}
/* send msg - done */
return (NETWORK_ERROR_MSG_FAILED);
}
return (0);
}
/*
* netpr_response() reads in a byte from the network printer
*/
static int
{
char c;
int msg_given = 0;
int firstloop = 0;
(void) alarm(2);
while (1) {
errno = 0;
if (firstloop == 0) {
(void) alarm(0);
firstloop++;
}
if (msg_given == 0) {
gettext("Printer not responding;"
"Either warming up or needs attention"));
msg_given++;
"read hanging in netpr_response: %m");
}
} else {
"read in netpr_response failed: %m");
return (NETWORK_READ_RESPONSE_FAILED);
}
} else {
if (c) {
"Printer returned error: %m");
return (NETWORK_PRINTER_REFUSED_CONN);
} else {
if (msg_given)
return (0);
}
}
}
}
static int
{
int ctr;
char * pa;
int nw;
int err_msg = 0;
while (ctr > 0) {
(void) alarm(2);
(void) alarm(0);
if (nw <= 0) {
if (timeout < 16) {
timeout *= 2;
} else if (timeout == 16) {
timeout *= 2;
if (err_msg == 0) {
err_msg++;
gettext("Printer not accepting input;"
"possibly offline or out of paper."));
}
} else
} else {
if (err_msg)
}
}
return (netpr_response(nd));
}
/*
* null() is to be used as a signal handler that does nothing. It is used in
* place of SIG_IGN, because we want the signal to be delivered and
* interupt the current system call.
*/
/*ARGSUSED*/
void
null_sighandler(int i)
{
}