| 631 | */ |
| 632 | |
| 633 | static int /* O - Status of command */ |
| 634 | lpd_command(int fd, /* I - Socket connection to LPD host */ |
| 635 | char *format, /* I - printf()-style format string */ |
| 636 | ...) /* I - Additional args as necessary */ |
| 637 | { |
| 638 | va_list ap; /* Argument pointer */ |
| 639 | char buf[1024]; /* Output buffer */ |
| 640 | ssize_t bytes; /* Number of bytes to output */ |
| 641 | char status; /* Status from command */ |
| 642 | |
| 643 | |
| 644 | /* |
| 645 | * Don't try to send commands if the job has been canceled... |
| 646 | */ |
| 647 | |
| 648 | if (abort_job) |
| 649 | return (-1); |
| 650 | |
| 651 | /* |
| 652 | * Format the string... |
| 653 | */ |
| 654 | |
| 655 | va_start(ap, format); |
| 656 | bytes = vsnprintf(buf, sizeof(buf), format, ap); |
| 657 | va_end(ap); |
| 658 | |
| 659 | fprintf(stderr, "DEBUG: lpd_command %2.2x %s", buf[0], buf + 1); |
| 660 | |
| 661 | /* |
| 662 | * Send the command... |
| 663 | */ |
| 664 | |
| 665 | fprintf(stderr, "DEBUG: Sending command string (" CUPS_LLFMT " bytes)...\n", CUPS_LLCAST bytes); |
| 666 | |
| 667 | if (lpd_write(fd, buf, (size_t)bytes) < bytes) |
| 668 | { |
| 669 | perror("DEBUG: Unable to send LPD command"); |
| 670 | return (-1); |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | * Read back the status from the command and return it... |
| 675 | */ |
| 676 | |
| 677 | fputs("DEBUG: Reading command status...\n", stderr); |
| 678 | |
| 679 | if (recv(fd, &status, 1, 0) < 1) |
| 680 | { |
| 681 | _cupsLangPrintFilter(stderr, "WARNING", _("The printer did not respond.")); |
| 682 | status = (char)errno; |
| 683 | } |
| 684 | |
| 685 | fprintf(stderr, "DEBUG: lpd_command returning %d\n", status); |
| 686 | |
| 687 | return (status); |
| 688 | } |
| 689 | |
| 690 |
no test coverage detected