Lines Matching +full:command +full:- +full:and +full:- +full:control
4 * Copyright © 2007-2019 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
15 #include <cups/http-private.h>
16 #include "backend-private.h"
41 static int abort_job = 0; /* Non-zero if we get SIGTERM */
53 * The order for control and data files in LPD requests...
56 #define ORDER_CONTROL_DATA 0 /* Control file first, then data */
57 #define ORDER_DATA_CONTROL 1 /* Data file first, then control */
65 #define RESERVE_RFC1179 1 /* Reserve port 721-731 */
66 #define RESERVE_ANY 2 /* Reserve port 1-1023 */
85 * 'main()' - Send a file to the printer or server.
89 * printer-uri job-id user title copies options [file]
92 int /* O - Exit status */
93 main(int argc, /* I - Number of command-line arguments (6 or 7) */ in main()
94 char *argv[]) /* I - Command-line arguments */ in main()
116 int order; /* Order of control/data files */ in main()
139 * Ignore SIGPIPE and catch SIGTERM signals... in main()
160 * Check command-line... in main()
172 _("Usage: %s job-id user title copies options [file]"), in main()
180 * Extract the hostname and printer name from the URI... in main()
223 * We want to pass UTF-8 characters by default, not re-map them (3071945) in main()
229 * Otherwise we want to re-map UTF-8 to "safe" characters by default... in main()
238 * Yup, terminate the device name string and move to the first in main()
308 * Set control/data order... in main()
322 * Set control/data order... in main()
325 if (!_cups_strcasecmp(value, "control,data")) in main()
327 else if (!_cups_strcasecmp(value, "data,control")) in main()
414 snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family); in main()
416 snmp_fd = -1; in main()
424 if (!backendWaitLoop(snmp_fd, &(addrlist->addr), 0, backendNetworkSideCB)) in main()
432 * If we have 7 arguments, print the file named on the command-line. in main()
433 * Otherwise, copy stdin to a temporary file and print the temporary in main()
454 backendRunLoop(-1, fd, snmp_fd, &(addrlist->addr), 0, 0, in main()
471 if (fd == -1) in main()
518 cupsGetOption("job-originating-host-name", num_jobopts, in main()
528 cupsGetOption("job-originating-host-name", num_jobopts, in main()
553 * 'cups_rresvport()' - A simple implementation of rresvport_af().
556 static int /* O - Socket or -1 on error */
557 cups_rresvport(int *port, /* IO - Port number to bind to */ in cups_rresvport()
558 int family) /* I - Address family */ in cups_rresvport()
569 return (-1); in cups_rresvport()
605 return (-1); in cups_rresvport()
612 (*port)--; in cups_rresvport()
616 * Wasn't able to bind to a reserved port, so close the socket and return in cups_rresvport()
617 * -1... in cups_rresvport()
626 return (-1); in cups_rresvport()
631 * 'lpd_command()' - Send an LPR command sequence and wait for a reply.
634 static int /* O - Status of command */
635 lpd_command(int fd, /* I - Socket connection to LPD host */ in lpd_command()
636 char *format, /* I - printf()-style format string */ in lpd_command()
637 ...) /* I - Additional args as necessary */ in lpd_command()
642 char status; /* Status from command */ in lpd_command()
650 return (-1); in lpd_command()
663 * Send the command... in lpd_command()
666 fprintf(stderr, "DEBUG: Sending command string (" CUPS_LLFMT " bytes)...\n", CUPS_LLCAST bytes); in lpd_command()
670 perror("DEBUG: Unable to send LPD command"); in lpd_command()
671 return (-1); in lpd_command()
675 * Read back the status from the command and return it... in lpd_command()
678 fputs("DEBUG: Reading command status...\n", stderr); in lpd_command()
693 * 'lpd_queue()' - Queue a file using the Line Printer Daemon protocol.
696 static int /* O - Zero on success, non-zero on failure */
697 lpd_queue(const char *hostname, /* I - Host to connect to */ in lpd_queue()
698 http_addrlist_t *addrlist, /* I - List of host addresses */ in lpd_queue()
699 const char *printer, /* I - Printer/queue name */ in lpd_queue()
700 int print_fd, /* I - File to print */ in lpd_queue()
701 int snmp_fd, /* I - SNMP socket */ in lpd_queue()
702 int mode, /* I - Print mode */ in lpd_queue()
703 const char *user, /* I - Requesting user */ in lpd_queue()
704 const char *title, /* I - Job title */ in lpd_queue()
705 int copies, /* I - Number of copies */ in lpd_queue()
706 int banner, /* I - Print LPD banner? */ in lpd_queue()
707 int format, /* I - Format specifier */ in lpd_queue()
708 int order, /* I - Order of data/control files */ in lpd_queue()
709 int reserve, /* I - Reserve ports? */ in lpd_queue()
710 int manual_copies,/* I - Do copies by hand... */ in lpd_queue()
711 int timeout, /* I - Timeout... */ in lpd_queue()
712 int contimeout, /* I - Connection timeout */ in lpd_queue()
713 const char *orighost) /* I - job-originating-host-name */ in lpd_queue()
720 char control[10240], /* LPD control 'file' */ in lpd_queue() local
721 *cptr; /* Pointer into control file string */ in lpd_queue()
722 char status; /* Status byte from command */ in lpd_queue()
735 struct timeval tv; /* Timeout in secs and usecs */ in lpd_queue()
756 httpAddrPort(&(addrlist->addr)), printer); in lpd_queue()
761 addr = addr->next) in lpd_queue()
777 lport --; in lpd_queue()
794 if ((fd = socket(addr->addr.addr.sa_family, SOCK_STREAM, 0)) < 0) in lpd_queue()
807 * We're running as root and want to comply with RFC 1179. Reserve a in lpd_queue()
808 * priviledged lport between 721 and 731... in lpd_queue()
811 if ((fd = cups_rresvport(&lport, addr->addr.addr.sa_family)) < 0) in lpd_queue()
831 if (!connect(fd, &(addr->addr.addr), (socklen_t)httpAddrLength(&(addr->addr)))) in lpd_queue()
837 if (addr->next) in lpd_queue()
844 * to a class and not to a specific queue. In this case, we want in lpd_queue()
866 if (contimeout && (time(NULL) - start_time) > contimeout) in lpd_queue()
932 fputs("STATE: -connecting-to-device\n", stderr); in lpd_queue()
936 httpAddrString(&(addr->addr), addrname, sizeof(addrname)), in lpd_queue()
937 httpAddrPort(&(addr->addr)), lport); in lpd_queue()
944 have_supplies = !backendSNMPSupplies(snmp_fd, &(addrlist->addr), NULL, in lpd_queue()
950 * Check for side-channel requests... in lpd_queue()
953 backendCheckSideChannel(snmp_fd, &(addrlist->addr)); in lpd_queue()
956 * Next, open the print file and figure out its size... in lpd_queue()
990 * Send a job header to the printer, specifying no banner page and in lpd_queue()
1006 snprintf(control, sizeof(control), in lpd_queue()
1007 "H%.31s\n" /* RFC 1179, Section 7.2 - host name <= 31 chars */ in lpd_queue()
1008 "P%.31s\n" /* RFC 1179, Section 7.2 - user name <= 31 chars */ in lpd_queue()
1009 "J%.99s\n", /* RFC 1179, Section 7.2 - job name <= 99 chars */ in lpd_queue()
1011 cptr = control + strlen(control); in lpd_queue()
1015 snprintf(cptr, sizeof(control) - (size_t)(cptr - control), in lpd_queue()
1016 "C%.31s\n" /* RFC 1179, Section 7.2 - class name <= 31 chars */ in lpd_queue()
1024 snprintf(cptr, sizeof(control) - (size_t)(cptr - control), "%cdfA%03d%.15s\n", in lpd_queue()
1027 copies --; in lpd_queue()
1030 snprintf(cptr, sizeof(control) - (size_t)(cptr - control), in lpd_queue()
1032 "N%.131s\n", /* RFC 1179, Section 7.2 - sourcefile name <= 131 chars */ in lpd_queue()
1035 fprintf(stderr, "DEBUG: Control file is:\n%s", control); in lpd_queue()
1040 * Check for side-channel requests... in lpd_queue()
1043 backendCheckSideChannel(snmp_fd, &(addr->addr)); in lpd_queue()
1046 * Send the control file... in lpd_queue()
1049 if (lpd_command(fd, "\002%d cfA%03d%.15s\n", (int)strlen(control), in lpd_queue()
1057 fprintf(stderr, "DEBUG: Sending control file (%u bytes)\n", in lpd_queue()
1058 (unsigned)strlen(control)); in lpd_queue()
1060 if ((size_t)lpd_write(fd, control, strlen(control) + 1) < (strlen(control) + 1)) in lpd_queue()
1063 perror("DEBUG: Unable to write control file"); in lpd_queue()
1078 _("Remote host did not accept control file (%d)."), in lpd_queue()
1082 _("Control file sent successfully.")); in lpd_queue()
1090 * Check for side-channel requests... in lpd_queue()
1093 backendCheckSideChannel(snmp_fd, &(addr->addr)); in lpd_queue()
1146 * we know the printer got the whole file and we don't necessarily in lpd_queue()
1147 * want to requeue it over and over... in lpd_queue()
1173 * Check for side-channel requests... in lpd_queue()
1176 backendCheckSideChannel(snmp_fd, &(addr->addr)); in lpd_queue()
1179 * Send control file... in lpd_queue()
1182 if (lpd_command(fd, "\002%d cfA%03d%.15s\n", (int)strlen(control), in lpd_queue()
1190 fprintf(stderr, "DEBUG: Sending control file (%lu bytes)\n", in lpd_queue()
1191 (unsigned long)strlen(control)); in lpd_queue()
1193 if ((size_t)lpd_write(fd, control, strlen(control) + 1) < (strlen(control) + 1)) in lpd_queue()
1196 perror("DEBUG: Unable to write control file"); in lpd_queue()
1210 _("Remote host did not accept control file (%d)."), in lpd_queue()
1214 _("Control file sent successfully.")); in lpd_queue()
1217 fputs("STATE: +cups-waiting-for-job-completed\n", stderr); in lpd_queue()
1224 backendSNMPSupplies(snmp_fd, &(addr->addr), NULL, NULL); in lpd_queue()
1227 * Close the socket connection and input file... in lpd_queue()
1251 * 'lpd_write()' - Write a buffer of data to an LPD server.
1254 static ssize_t /* O - Number of bytes written or -1 on error */
1255 lpd_write(int lpd_fd, /* I - LPD socket */ in lpd_write()
1256 char *buffer, /* I - Buffer to write */ in lpd_write()
1257 size_t length) /* I - Number of bytes to write */ in lpd_write()
1264 return (-1); in lpd_write()
1267 while ((bytes = send(lpd_fd, buffer, length - (size_t)total, 0)) >= 0) in lpd_write()
1277 return (-1); in lpd_write()
1284 * 'sigterm_handler()' - Handle 'terminate' signals that stop the backend.
1288 sigterm_handler(int sig) /* I - Signal */ in sigterm_handler()