4 * Common network APIs for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 2006-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * "LICENSE" which should have been included with this file. If this
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * backendCheckSideChannel() - Check the side-channel for pending requests.
20 * backendNetworkSideCB() - Handle common network side-channel commands.
24 * Include necessary headers.
27 #include "backend-private.h"
30 # include <sys/time.h>
32 # include <sys/select.h>
43 * 'backendCheckSideChannel()' - Check the side-channel for pending requests.
48 backendCheckSideChannel(
49 int snmp_fd
, /* I - SNMP socket */
50 http_addr_t
*addr
) /* I - Address of device */
52 fd_set input
; /* Select input set */
53 struct timeval timeout
; /* Select timeout */
57 FD_SET(CUPS_SC_FD
, &input
);
59 timeout
.tv_sec
= timeout
.tv_usec
= 0;
61 if (select(CUPS_SC_FD
+ 1, &input
, NULL
, NULL
, &timeout
) > 0)
62 backendNetworkSideCB(-1, -1, snmp_fd
, addr
, 0);
67 * 'backendNetworkSideCB()' - Handle common network side-channel commands.
72 int print_fd
, /* I - Print file or -1 */
73 int device_fd
, /* I - Device file or -1 */
74 int snmp_fd
, /* I - SNMP socket */
75 http_addr_t
*addr
, /* I - Address of device */
76 int use_bc
) /* I - Use back-channel data? */
78 cups_sc_command_t command
; /* Request command */
79 cups_sc_status_t status
; /* Request/response status */
80 char data
[2048]; /* Request/response data */
81 int datalen
; /* Request/response data size */
82 const char *device_id
; /* 1284DEVICEID env var */
85 datalen
= sizeof(data
);
87 if (cupsSideChannelRead(&command
, &status
, data
, &datalen
, 1.0))
89 _cupsLangPuts(stderr
, _("WARNING: Failed to read side-channel request!\n"));
95 case CUPS_SC_CMD_DRAIN_OUTPUT
:
97 * Our sockets disable the Nagle algorithm and data is sent immediately.
101 status
= CUPS_SC_STATUS_NOT_IMPLEMENTED
;
102 else if (backendDrainOutput(print_fd
, device_fd
))
103 status
= CUPS_SC_STATUS_IO_ERROR
;
105 status
= CUPS_SC_STATUS_OK
;
110 case CUPS_SC_CMD_GET_BIDI
:
115 case CUPS_SC_CMD_GET_DEVICE_ID
:
118 cups_snmp_t packet
; /* Packet from printer */
119 static const int ppmPrinterIEEE1284DeviceId
[] =
120 { CUPS_OID_ppmPrinterIEEE1284DeviceId
,1,-1 };
122 if (_cupsSNMPWrite(snmp_fd
, addr
, 1, _cupsSNMPDefaultCommunity(),
123 CUPS_ASN1_GET_REQUEST
, 1,
124 ppmPrinterIEEE1284DeviceId
))
126 if (_cupsSNMPRead(snmp_fd
, &packet
, 1.0) &&
127 packet
.object_type
== CUPS_ASN1_OCTET_STRING
)
129 strlcpy(data
, packet
.object_value
.string
, sizeof(data
));
130 datalen
= (int)strlen(data
);
136 if ((device_id
= getenv("1284DEVICEID")) != NULL
)
138 strlcpy(data
, device_id
, sizeof(data
));
139 datalen
= (int)strlen(data
);
144 status
= CUPS_SC_STATUS_NOT_IMPLEMENTED
;
149 cupsSideChannelWrite(command
, status
, data
, datalen
, 1.0);