| 105 | */ |
| 106 | |
| 107 | int /* O - -1 on error, 0 on success */ |
| 108 | backendNetworkSideCB( |
| 109 | int print_fd, /* I - Print file or -1 */ |
| 110 | int device_fd, /* I - Device file or -1 */ |
| 111 | int snmp_fd, /* I - SNMP socket */ |
| 112 | http_addr_t *addr, /* I - Address of device */ |
| 113 | int use_bc) /* I - Use back-channel data? */ |
| 114 | { |
| 115 | cups_sc_command_t command; /* Request command */ |
| 116 | cups_sc_status_t status; /* Request/response status */ |
| 117 | char data[65536]; /* Request/response data */ |
| 118 | int datalen; /* Request/response data size */ |
| 119 | const char *device_id; /* 1284DEVICEID env var */ |
| 120 | |
| 121 | |
| 122 | datalen = sizeof(data); |
| 123 | |
| 124 | if (cupsSideChannelRead(&command, &status, data, &datalen, 1.0)) |
| 125 | return (-1); |
| 126 | |
| 127 | switch (command) |
| 128 | { |
| 129 | case CUPS_SC_CMD_DRAIN_OUTPUT : |
| 130 | /* |
| 131 | * Our sockets disable the Nagle algorithm and data is sent immediately. |
| 132 | */ |
| 133 | |
| 134 | if (device_fd < 0) |
| 135 | status = CUPS_SC_STATUS_NOT_IMPLEMENTED; |
| 136 | else if (backendDrainOutput(print_fd, device_fd)) |
| 137 | status = CUPS_SC_STATUS_IO_ERROR; |
| 138 | else |
| 139 | status = CUPS_SC_STATUS_OK; |
| 140 | |
| 141 | datalen = 0; |
| 142 | break; |
| 143 | |
| 144 | case CUPS_SC_CMD_GET_BIDI : |
| 145 | status = CUPS_SC_STATUS_OK; |
| 146 | data[0] = (char)use_bc; |
| 147 | datalen = 1; |
| 148 | break; |
| 149 | |
| 150 | case CUPS_SC_CMD_SNMP_GET : |
| 151 | case CUPS_SC_CMD_SNMP_GET_NEXT : |
| 152 | fprintf(stderr, "DEBUG: CUPS_SC_CMD_SNMP_%s: %d (%s)\n", |
| 153 | command == CUPS_SC_CMD_SNMP_GET ? "GET" : "GET_NEXT", datalen, |
| 154 | data); |
| 155 | |
| 156 | if (datalen < 2) |
| 157 | { |
| 158 | status = CUPS_SC_STATUS_BAD_MESSAGE; |
| 159 | datalen = 0; |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | if (snmp_fd >= 0) |
| 164 | { |
no test coverage detected