• Home
  • Raw
  • Download

Lines Matching +full:set +full:- +full:job +full:- +full:env +full:- +full:vars

4  * Copyright © 2021-2025 by OpenPrinting
5 * Copyright © 2007-2021 by Apple Inc.
6 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
12 #include "backend-private.h"
13 #include <cups/ppd-private.h>
14 #include <cups/array-private.h>
29 * Bits for job-state-reasons we care about...
54 job_id, /* Job ID for submitted job */
55 job_reasons, /* Job state reasons bits */
56 create_job, /* Support Create-Job? */
57 get_job_attrs; /* Support Get-Job-Attributes? */
58 const char *job_name; /* Job name for submitted job */
60 ipp_jstate_t job_state; /* Current job state */
62 int retryable; /* Is this a job that should be retried? */
72 static const char * const jattrs[] = /* Job attributes we want */
74 "job-id",
75 "job-impressions-completed",
76 "job-media-sheets-completed",
77 "job-name",
78 "job-originating-user-name",
79 "job-state",
80 "job-state-reasons"
83 /* Job cancelled? */
93 "compression-supported",
95 "copies-supported",
96 "cups-version",
97 "document-format-supported",
98 "job-password-encryption-supported",
99 "marker-colors",
100 "marker-high-levels",
101 "marker-levels",
102 "marker-low-levels",
103 "marker-message",
104 "marker-names",
105 "marker-types",
106 "media-col-supported",
107 "multiple-document-handling-supported",
108 "operations-supported",
109 "print-color-mode-supported",
110 "print-scaling-supported",
111 "printer-alert",
112 "printer-alert-description",
113 "printer-is-accepting-jobs",
114 "printer-mandatory-job-attributes",
115 "printer-state",
116 "printer-state-message",
117 "printer-state-reasons"
120 { /* Remote job state keywords */
121 "+cups-remote-pending",
122 "+cups-remote-pending-held",
123 "+cups-remote-processing",
124 "+cups-remote-stopped",
125 "+cups-remote-canceled",
126 "+cups-remote-aborted",
127 "+cups-remote-completed"
135 static cups_array_t *state_reasons; /* Array of printe-state-reasons keywords */
181 * 'main()' - Send a file to the printer or server.
185 * printer-uri job-id user title copies options [file]
188 int /* O - Exit status */
189 main(int argc, /* I - Number of command-line args */ in main()
190 char *argv[]) /* I - Command-line arguments */ in main()
193 int send_options; /* Send job options? */ in main()
218 char print_job_name[256]; /* Update job-name for Print-Job */ in main()
224 *supported; /* get-printer-attributes response */ in main()
230 int waitjob, /* Wait for job complete? */ in main()
234 ipp_attribute_t *job_id_attr; /* job-id attribute */ in main()
235 int job_id; /* job-id value */ in main()
236 ipp_attribute_t *job_sheets; /* job-media-sheets-completed */ in main()
237 ipp_attribute_t *job_state; /* job-state */ in main()
239 ipp_attribute_t *compression_sup; /* compression-supported */ in main()
241 ipp_attribute_t *copies_sup; /* copies-supported */ in main()
242 ipp_attribute_t *cups_version; /* cups-version */ in main()
243 ipp_attribute_t *encryption_sup; /* job-password-encryption-supported */ in main()
244 ipp_attribute_t *format_sup; /* document-format-supported */ in main()
245 ipp_attribute_t *job_auth; /* job-authorization-uri */ in main()
246 ipp_attribute_t *media_col_sup; /* media-col-supported */ in main()
247 ipp_attribute_t *operations_sup; /* operations-supported */ in main()
248 ipp_attribute_t *doc_handling_sup; /* multiple-document-handling-supported */ in main()
249 ipp_attribute_t *printer_state; /* printer-state attribute */ in main()
250 ipp_attribute_t *printer_accepting; /* printer-is-accepting-jobs */ in main()
251 ipp_attribute_t *print_color_mode_sup;/* Does printer support print-color-mode? */ in main()
252 ipp_attribute_t *print_scaling_sup; /* print-scaling-supported */ in main()
253 int create_job = 0, /* Does printer support Create-Job? */ in main()
254 get_job_attrs = 0, /* Does printer support Get-Job-Attributes? */ in main()
255 send_document = 0, /* Does printer support Send-Document? */ in main()
256 validate_job = 0, /* Does printer support Validate-Job? */ in main()
257 validate_retried = 0, /* Was Validate-Job request retried? */ in main()
258 copies, /* Number of copies for job */ in main()
260 const char *auth_info_required, /* New auth-info-required value */ in main()
263 *document_format; /* document-format value */ in main()
273 fd_set input; /* Input set for select() */ in main()
304 * Check command-line... in main()
324 _("Usage: %s job-id user title copies options [file]"), in main()
397 content_type = "application/octet-stream"; in main()
404 final_content_type = "application/vnd.cups-raw"; in main()
431 _("IP address is not allowed as hostname when using Negotiate - use FQDN.")); in main()
432 update_reasons(NULL, "-connecting-to-device"); in main()
497 * Wait for job completion? in main()
583 * Set the connection timeout... in main()
603 * If we have 7 arguments, print the file named on the command-line. in main()
613 !_cups_strcasecmp(final_content_type, "application/vnd.cups-pdf") || in main()
616 fputs("DEBUG: Sending stdin for job...\n", stderr); in main()
621 * Point to the files on the command-line... in main()
624 num_files = argc - 6; in main()
628 fprintf(stderr, "DEBUG: %d files to send in job...\n", num_files); in main()
632 * Set the authentication info, if any... in main()
683 snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family); in main()
685 snmp_fd = -1; in main()
688 have_supplies = !backendSNMPSupplies(snmp_fd, &(addrlist->addr), in main()
699 if (!backendWaitLoop(snmp_fd, &(addrlist->addr), 0, backendNetworkSideCB)) in main()
720 if (http->status == HTTP_STATUS_CUPS_PKI_ERROR) in main()
721 update_reasons(NULL, "+cups-certificate-error"); in main()
729 * If the CLASS environment variable is set, the job was submitted in main()
731 * to abort immediately so that the job can be requeued on the next in main()
740 * Sleep 5 seconds to keep the job from requeuing too rapidly... in main()
745 update_reasons(NULL, "-connecting-to-device"); in main()
754 if (contimeout && (time(NULL) - start_time) > contimeout) in main()
758 update_reasons(NULL, "-connecting-to-device"); in main()
798 update_reasons(NULL, "-cups-certificate-error"); in main()
800 while (http->fd < 0); in main()
816 … char * const trusts[] = { NULL, "+cups-pki-invalid", "+cups-pki-changed", "+cups-pki-expired", NU… in main()
846 update_reasons(NULL, "-cups-pki-invalid,cups-pki-changed,cups-pki-expired,cups-pki-unknown"); in main()
871 update_reasons(NULL, "cups-pki-unknown"); in main()
876 update_reasons(NULL, "-connecting-to-device"); in main()
880 httpAddrString(http->hostaddr, addrname, sizeof(addrname)), in main()
881 httpAddrPort(http->hostaddr)); in main()
914 * Check for side-channel requests... in main()
917 backendCheckSideChannel(snmp_fd, http->hostaddr); in main()
925 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", in main()
929 "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]), in main()
938 if (http->version < HTTP_VERSION_1_1) in main()
941 http->version / 100, http->version % 100); in main()
942 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
943 "cups-ipp-wrong-http-version"); in main()
949 fprintf(stderr, "DEBUG: Get-Printer-Attributes: %s (%s)\n", in main()
956 fprintf(stderr, "DEBUG: Get-Printer-Attributes returned %s.\n", in main()
962 if (contimeout && (time(NULL) - start_time) > contimeout) in main()
1017 /* WWW-Authenticate field value */ in main()
1024 fprintf(stderr, "ATTR: auth-info-required=%s\n", auth_info_required); in main()
1044 * Check printer-is-accepting-jobs = false and printer-state-reasons for the in main()
1045 * "spool-area-full" keyword... in main()
1051 "printer-is-accepting-jobs", in main()
1053 !printer_accepting->values[0].boolean) in main()
1056 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1057 "cups-ipp-missing-printer-is-accepting-jobs"); in main()
1060 "printer-state-reasons", in main()
1063 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1064 "cups-ipp-missing-printer-state-reasons"); in main()
1068 for (i = 0; i < printer_state->num_values; i ++) in main()
1070 if (!strcmp(printer_state->values[0].string.text, in main()
1071 "spool-area-full") || in main()
1072 !strncmp(printer_state->values[0].string.text, "spool-area-full-", in main()
1103 if ((compression_sup = ippFindAttribute(supported, "compression-supported", in main()
1117 …else if (!compression && (!strcmp(final_content_type, "image/pwg-raster") || !strcmp(final_content… in main()
1131 if ((copies_sup = ippFindAttribute(supported, "copies-supported", in main()
1135 * Has the "copies-supported" attribute - does it have an upper in main()
1139 fprintf(stderr, "DEBUG: copies-supported=%d-%d\n", in main()
1140 copies_sup->values[0].range.lower, in main()
1141 copies_sup->values[0].range.upper); in main()
1143 if (copies_sup->values[0].range.upper <= 1) in main()
1147 if ((cups_version = ippFindAttribute(supported, "cups-version", IPP_TAG_TEXT)) != NULL) in main()
1151 fprintf(stderr, "DEBUG: cups-version = \"%s\"\n", val); in main()
1152 if (!strcmp(val, "cups-version")) in main()
1153 cups_version = NULL; /* Bogus cups-version value returned by buggy printers! */ in main()
1156 …encryption_sup = ippFindAttribute(supported, "job-password-encryption-supported", IPP_TAG_KEYWORD); in main()
1158 if ((format_sup = ippFindAttribute(supported, "document-format-supported", in main()
1161 fprintf(stderr, "DEBUG: document-format-supported (%d values)\n", in main()
1162 format_sup->num_values); in main()
1163 for (i = 0; i < format_sup->num_values; i ++) in main()
1165 format_sup->values[i].string.text); in main()
1168 if ((media_col_sup = ippFindAttribute(supported, "media-col-supported", in main()
1171 fprintf(stderr, "DEBUG: media-col-supported (%d values)\n", in main()
1172 media_col_sup->num_values); in main()
1173 for (i = 0; i < media_col_sup->num_values; i ++) in main()
1175 media_col_sup->values[i].string.text); in main()
1178 … print_color_mode_sup = ippFindAttribute(supported, "print-color-mode-supported", IPP_TAG_KEYWORD); in main()
1180 …if ((print_scaling_sup = ippFindAttribute(supported, "print-scaling-supported", IPP_TAG_KEYWORD)) … in main()
1184 fprintf(stderr, "DEBUG: print-scaling-supported (%d values)\n", count); in main()
1189 if ((operations_sup = ippFindAttribute(supported, "operations-supported", in main()
1192 fprintf(stderr, "DEBUG: operations-supported (%d values)\n", in main()
1193 operations_sup->num_values); in main()
1194 for (i = 0; i < operations_sup->num_values; i ++) in main()
1196 ippOpString(operations_sup->values[i].integer)); in main()
1198 for (i = 0; i < operations_sup->num_values; i ++) in main()
1199 if (operations_sup->values[i].integer == IPP_OP_PRINT_JOB) in main()
1202 if (i >= operations_sup->num_values) in main()
1203 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1204 "cups-ipp-missing-print-job"); in main()
1206 for (i = 0; i < operations_sup->num_values; i ++) in main()
1207 if (operations_sup->values[i].integer == IPP_OP_CANCEL_JOB) in main()
1210 if (i >= operations_sup->num_values) in main()
1211 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1212 "cups-ipp-missing-cancel-job"); in main()
1214 for (i = 0; i < operations_sup->num_values; i ++) in main()
1215 if (operations_sup->values[i].integer == IPP_OP_GET_JOB_ATTRIBUTES) in main()
1218 if (i >= operations_sup->num_values) in main()
1219 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1220 "cups-ipp-missing-get-job-attributes"); in main()
1222 for (i = 0; i < operations_sup->num_values; i ++) in main()
1223 if (operations_sup->values[i].integer == IPP_OP_GET_PRINTER_ATTRIBUTES) in main()
1226 if (i >= operations_sup->num_values) in main()
1227 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1228 "cups-ipp-missing-get-printer-attributes"); in main()
1230 for (i = 0; i < operations_sup->num_values; i ++) in main()
1232 if (operations_sup->values[i].integer == IPP_OP_VALIDATE_JOB) in main()
1234 else if (operations_sup->values[i].integer == IPP_OP_CREATE_JOB) in main()
1236 else if (operations_sup->values[i].integer == IPP_OP_SEND_DOCUMENT) in main()
1238 else if (operations_sup->values[i].integer == IPP_OP_GET_JOB_ATTRIBUTES) in main()
1244 fputs("DEBUG: Printer supports Create-Job but not Send-Document.\n", in main()
1248 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1249 "cups-ipp-missing-send-document"); in main()
1253 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1254 "cups-ipp-missing-validate-job"); in main()
1257 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1258 "cups-ipp-missing-operations-supported"); in main()
1261 "multiple-document-handling-supported", in main()
1273 * condition is true and we are printing to a class, requeue the job... in main()
1278 printer_state = ippFindAttribute(supported, "printer-state", in main()
1280 printer_accepting = ippFindAttribute(supported, "printer-is-accepting-jobs", in main()
1284 (printer_state->values[0].integer > IPP_PSTATE_PROCESSING && in main()
1287 !printer_accepting->values[0].boolean) in main()
1290 * If the CLASS environment variable is set, the job was submitted in main()
1292 * to abort immediately so that the job can be requeued on the next in main()
1304 * Sleep 5 seconds to keep the job from requeuing too rapidly... in main()
1349 strlcpy(mandatory_attrs, mandatory->value, sizeof(mandatory_attrs)); in main()
1353 * Validate job-password/-encryption... in main()
1356 if (cupsGetOption("job-password", num_options, options)) in main()
1358 const char *keyword; /* job-password-encryption value */ in main()
1361 "sha-512", in main()
1362 "sha-384", in main()
1363 "sha-512_256", in main()
1364 "sha-512-224", in main()
1365 "sha-256", in main()
1366 "sha-224", in main()
1371 …if ((keyword = cupsGetOption("job-password-encryption", num_options, options)) == NULL || !ippCont… in main()
1374 * Either no job-password-encryption or the value isn't supported by in main()
1382 … num_options = cupsAddOption("job-password-encryption", hashes[j], num_options, &options); in main()
1397 else if (ippContainsString(format_sup, "application/octet-stream")) in main()
1398 document_format = "application/octet-stream"; in main()
1411 if (http->version < HTTP_VERSION_1_1 && num_files == 0) in main()
1427 if ((bytes = backendRunLoop(-1, fd, snmp_fd, &(addrlist->addr), 0, 0, in main()
1439 else if (http->version < HTTP_VERSION_1_1 && num_files == 1) in main()
1449 * included version=1.0 in the URI, then do not try to use Create-Job or in main()
1450 * Send-Document. This is another dreaded compatibility hack, but in main()
1474 …monitor.retryable = argc == 6 && document_format && strcmp(document_format, "image/pwg-raster"… in main()
1485 * TODO: make this compatible with UTF-8 - possible UTF-8 truncation here.. in main()
1488 snprintf(print_job_name, sizeof(print_job_name), "%s - %s", argv[1], in main()
1510 fprintf(stderr, "DEBUG: Validate-Job: %s (%s)\n", in main()
1514 if ((job_auth = ippFindAttribute(response, "job-authorization-uri", in main()
1516 num_options = cupsAddOption("job-authorization-uri", in main()
1529 * The sides value is not supported, revert to one-sided as needed... in main()
1534 if (!sides || !strncmp(sides, "two-sided-", 10)) in main()
1536 fputs("DEBUG: Unable to do two-sided printing, setting sides to 'one-sided'.\n", stderr); in main()
1537 num_options = cupsAddOption("sides", "one-sided", num_options, &options); in main()
1565 /* WWW-Authenticate field value */ in main()
1580 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1581 "cups-ipp-missing-validate-job"); in main()
1591 // Retry Validate-Job operation once, to work around known printer bug... in main()
1602 * Then issue the print-job request... in main()
1610 * Check for side-channel requests... in main()
1613 backendCheckSideChannel(snmp_fd, http->hostaddr); in main()
1616 * Build the IPP job creation request... in main()
1641 fputs("DEBUG: Sending file using HTTP/1.0 Content-Length...\n", stderr); in main()
1648 if (http_status == HTTP_STATUS_CONTINUE && request->state == IPP_STATE_DATA) in main()
1671 * Check for side-channel requests and more print data... in main()
1683 backendCheckSideChannel(snmp_fd, http->hostaddr); in main()
1702 "Print-Job: %s\n", strerror(httpError(http))); in main()
1715 (num_files > 1 || create_job) ? "Create-Job" : "Print-Job", in main()
1736 * We can't re-submit when we have no files to print, so exit in main()
1754 * Update auth-info-required as needed... in main()
1758 _("Print job was not accepted.")); in main()
1764 /* WWW-Authenticate field value */ in main()
1774 * Print file is too large, abort this job... in main()
1785 * We can't re-submit when we have no files to print, so exit in main()
1793 else if ((job_id_attr = ippFindAttribute(response, "job-id", in main()
1796 fputs("DEBUG: Print job accepted - job ID unknown.\n", stderr); in main()
1797 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
1798 "cups-ipp-missing-job-id"); in main()
1804 monitor.job_id = job_id = job_id_attr->values[0].integer; in main()
1805 fprintf(stderr, "DEBUG: Print job accepted - job ID %d.\n", job_id); in main()
1818 * Check for side-channel requests... in main()
1821 backendCheckSideChannel(snmp_fd, http->hostaddr); in main()
1824 * Send the next file in the job... in main()
1830 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", in main()
1833 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", in main()
1838 "requesting-user-name", NULL, argv[2]); in main()
1840 ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", in main()
1845 "document-format", NULL, document_format); in main()
1856 if (http_status == HTTP_STATUS_CONTINUE && request->state == IPP_STATE_DATA) in main()
1876 fd = -1; in main()
1889 * Check for side-channel requests... in main()
1892 backendCheckSideChannel(snmp_fd, http->hostaddr); in main()
1902 "Send-Document: %s\n", strerror(httpError(http))); in main()
1907 …fprintf(stderr, "DEBUG: Send-Document: %s (%s)\n", ippErrorString(cupsLastError()), cupsLastErrorS… in main()
1912 ipp_attribute_t *reasons = ippFindAttribute(response, "job-state-reasons", IPP_TAG_KEYWORD); in main()
1913 /* job-state-reasons values */ in main()
1917 if (ippContainsString(reasons, "document-format-error")) in main()
1919 else if (ippContainsString(reasons, "document-unprintable-error")) in main()
1923 _cupsLangPrintFilter(stderr, "ERROR", _("Unable to add document to print job.")); in main()
1944 copies_remaining --; in main()
1948 …document_format && strcmp(document_format, "image/pwg-raster") && strcmp(document_format, "image/u… in main()
1951 * Need to reprocess the job as raster... in main()
1954 fputs("JOBSTATE: cups-retry-as-raster\n", stderr); in main()
1967 * Need to reprocess the entire job; if we have a job ID, cancel the in main()
1968 * job first... in main()
1988 * Print file is too large, job was canceled, we need new in main()
1997 * Server is configured incorrectly; the policy for Create-Job and in main()
1998 * Send-Document has to be the same (auth or no auth, encryption or in main()
2005 fputs("DEBUG: The policy for Create-Job and Send-Document must have the " in main()
2018 * Printer does not actually implement support for Create-Job/ in main()
2019 * Send-Document, so log the conformance issue and stop the printer. in main()
2022 fputs("DEBUG: This printer claims to support Create-Job and " in main()
2023 "Send-Document, but those operations failed.\n", stderr); in main()
2026 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
2027 "cups-ipp-missing-send-document"); in main()
2034 copies_remaining --; in main()
2037 * Wait for the job to complete... in main()
2043 fputs("STATE: +cups-waiting-for-job-completed\n", stderr); in main()
2045 _cupsLangPrintFilter(stderr, "INFO", _("Waiting for job to complete.")); in main()
2050 * Check for side-channel requests... in main()
2053 backendCheckSideChannel(snmp_fd, http->hostaddr); in main()
2071 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", in main()
2074 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", in main()
2079 "requesting-user-name", NULL, argv[2]); in main()
2082 "requested-attributes", sizeof(jattrs) / sizeof(jattrs[0]), in main()
2099 * Job has gone away and/or the server has no job history... in main()
2102 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
2103 "cups-ipp-missing-job-history"); in main()
2110 fprintf(stderr, "DEBUG: Get-Job-Attributes: %s (%s)\n", in main()
2140 if ((job_state = ippFindAttribute(response, "job-state", in main()
2144 * Reflect the remote job state in the local queue... in main()
2148 job_state->values[0].integer >= IPP_JSTATE_PENDING && in main()
2149 job_state->values[0].integer <= IPP_JSTATE_COMPLETED) in main()
2151 remote_job_states[job_state->values[0].integer - in main()
2154 …if ((job_sheets = ippFindAttribute(response, "job-impressions-completed", IPP_TAG_INTEGER)) == NUL… in main()
2155 job_sheets = ippFindAttribute(response, "job-media-sheets-completed", IPP_TAG_INTEGER); in main()
2159 job_sheets->values[0].integer); in main()
2162 * Stop polling if the job is finished or pending-held... in main()
2165 …if (job_state->values[0].integer > IPP_JSTATE_STOPPED || job_state->values[0].integer == IPP_JSTAT… in main()
2176 * If the printer does not return a job-state attribute, it does not in main()
2177 * conform to the IPP specification - break out immediately and fail in main()
2178 * the job... in main()
2181 update_reasons(NULL, "+cups-ipp-conformance-failure-report," in main()
2182 "cups-ipp-missing-job-state"); in main()
2201 * Cancel the job as needed... in main()
2209 _cupsLangPrintFilter(stderr, "ERROR", _("Unable to cancel print job.")); in main()
2226 !backendSNMPSupplies(snmp_fd, &(http->addrlist->addr), &page_count, in main()
2229 fprintf(stderr, "PAGE: total %d\n", page_count - start_count); in main()
2236 if (http->gssctx) in main()
2268 fprintf(stderr, "ATTR: auth-info-required=%s\n", auth_info_required); in main()
2271 fputs("JOBSTATE: account-info-needed\n", stderr); in main()
2273 fputs("JOBSTATE: account-closed\n", stderr); in main()
2275 fputs("JOBSTATE: account-limit-reached\n", stderr); in main()
2277 fputs("JOBSTATE: account-authorization-failed\n", stderr); in main()
2279 // job_canceled can be -1 which should not be treated as CUPS_BACKEND_OK in main()
2298 _cupsLangPrintFilter(stderr, "ERROR", _("Print job too large.")); in main()
2306 _cupsLangPrintFilter(stderr, "ERROR", _("Print job canceled at printer.")); in main()
2318 * 'adjust_options()' - Adjust options which have the same meaning.
2328 adjust_options(int num_options, /* I - Number of options */ in adjust_options()
2329 cups_option_t *options) /* I - Array of job options */ in adjust_options()
2344 * PPD option ColorModel and IPP attribute print-color-mode in adjust_options()
2348 ipp_attr_value = cupsGetOption("print-color-mode", num_options, options); in adjust_options()
2357 fprintf(stderr, "DEBUG: adjust_options(): Adjusting print-color-mode to monochrome.\n"); in adjust_options()
2358 num_options = cupsAddOption("print-color-mode", "monochrome", num_options, &options); in adjust_options()
2364 fprintf(stderr, "DEBUG: adjust_options(): Adjusting print-color-mode to color.\n"); in adjust_options()
2365 num_options = cupsAddOption("print-color-mode", "color", num_options, &options); in adjust_options()
2371 * 'cancel_job()' - Cancel a print job.
2375 cancel_job(http_t *http, /* I - HTTP connection */ in cancel_job()
2376 const char *uri, /* I - printer-uri */ in cancel_job()
2377 int id, /* I - job-id */ in cancel_job()
2378 const char *resource, /* I - Resource path */ in cancel_job()
2379 const char *user, /* I - requesting-user-name */ in cancel_job()
2380 int version) /* I - IPP version */ in cancel_job()
2382 ipp_t *request; /* Cancel-Job request */ in cancel_job()
2385 _cupsLangPrintFilter(stderr, "INFO", _("Canceling print job.")); in cancel_job()
2390 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", in cancel_job()
2392 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", id); in cancel_job()
2396 "requesting-user-name", NULL, user); in cancel_job()
2407 * 'check_printer_state()' - Check the printer state.
2410 static ipp_pstate_t /* O - Current printer-state */
2412 http_t *http, /* I - HTTP connection */ in check_printer_state()
2413 const char *uri, /* I - Printer URI */ in check_printer_state()
2414 const char *resource, /* I - Resource path */ in check_printer_state()
2415 const char *user, /* I - Username, if any */ in check_printer_state()
2416 int version) /* I - IPP version */ in check_printer_state()
2422 /* Current printer-state */ in check_printer_state()
2426 * Send a Get-Printer-Attributes request and log the results... in check_printer_state()
2432 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", in check_printer_state()
2437 "requesting-user-name", NULL, user); in check_printer_state()
2440 "requested-attributes", in check_printer_state()
2450 if ((attr = ippFindAttribute(response, "printer-state", in check_printer_state()
2452 printer_state = (ipp_pstate_t)attr->values[0].integer; in check_printer_state()
2455 fprintf(stderr, "DEBUG: Get-Printer-Attributes: %s (%s)\n", in check_printer_state()
2461 * Return the printer-state value... in check_printer_state()
2469 * 'debug_attributes()' - Print out the request or response attributes as DEBUG
2474 debug_attributes(ipp_t *ipp) /* I - Request or response message */ in debug_attributes()
2496 fprintf(stderr, "DEBUG: ---- %s ----\n", ippTagString(group)); in debug_attributes()
2499 if (!strcmp(name, "job-password")) in debug_attributes()
2500 strlcpy(buffer, "---", sizeof(buffer)); in debug_attributes()
2509 fprintf(stderr, "DEBUG: ---- %s ----\n", ippTagString(IPP_TAG_END)); in debug_attributes()
2514 * 'monitor_printer()' - Monitor the printer state.
2517 static void * /* O - Thread exit code */
2519 _cups_monitor_t *monitor) /* I - Monitoring data */ in monitor_printer()
2528 int job_id; /* Job ID */ in monitor_printer()
2529 const char *job_name; /* Job name */ in monitor_printer()
2530 ipp_jstate_t job_state; /* Job state */ in monitor_printer()
2531 const char *job_user; /* Job originating user name */ in monitor_printer()
2539 http = httpConnect2(monitor->hostname, monitor->port, NULL, AF_UNSPEC, in monitor_printer()
2540 monitor->encryption, 1, 0, NULL); in monitor_printer()
2548 * Loop until the job is canceled, aborted, or completed. in monitor_printer()
2553 monitor->job_reasons = 0; in monitor_printer()
2555 while (monitor->job_state < IPP_JSTATE_CANCELED && !job_canceled) in monitor_printer()
2570 monitor->printer_state = check_printer_state(http, monitor->uri, in monitor_printer()
2571 monitor->resource, in monitor_printer()
2572 monitor->user, in monitor_printer()
2573 monitor->version); in monitor_printer()
2577 if (monitor->job_id == 0 && monitor->create_job) in monitor_printer()
2580 * No job-id yet, so continue... in monitor_printer()
2587 * Check the status of the job itself... in monitor_printer()
2590 job_op = (monitor->job_id > 0 && monitor->get_job_attrs) ? in monitor_printer()
2593 ippSetVersion(request, monitor->version / 10, monitor->version % 10); in monitor_printer()
2595 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", in monitor_printer()
2596 NULL, monitor->uri); in monitor_printer()
2598 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", in monitor_printer()
2599 monitor->job_id); in monitor_printer()
2601 if (monitor->user && monitor->user[0]) in monitor_printer()
2603 "requesting-user-name", NULL, monitor->user); in monitor_printer()
2606 "requested-attributes", in monitor_printer()
2613 response = cupsDoRequest(http, request, monitor->resource); in monitor_printer()
2623 if ((attr = ippFindAttribute(response, "job-state", in monitor_printer()
2625 monitor->job_state = (ipp_jstate_t)attr->values[0].integer; in monitor_printer()
2627 monitor->job_state = IPP_JSTATE_COMPLETED; in monitor_printer()
2631 for (attr = response->attrs; attr; attr = attr->next) in monitor_printer()
2638 while (attr && attr->group_tag != IPP_TAG_JOB) in monitor_printer()
2639 attr = attr->next; in monitor_printer()
2644 while (attr && attr->group_tag == IPP_TAG_JOB) in monitor_printer()
2646 if (!strcmp(attr->name, "job-id") && in monitor_printer()
2647 attr->value_tag == IPP_TAG_INTEGER) in monitor_printer()
2648 job_id = attr->values[0].integer; in monitor_printer()
2649 else if (!strcmp(attr->name, "job-name") && in monitor_printer()
2650 (attr->value_tag == IPP_TAG_NAME || in monitor_printer()
2651 attr->value_tag == IPP_TAG_NAMELANG)) in monitor_printer()
2652 job_name = attr->values[0].string.text; in monitor_printer()
2653 else if (!strcmp(attr->name, "job-state") && in monitor_printer()
2654 attr->value_tag == IPP_TAG_ENUM) in monitor_printer()
2655 job_state = (ipp_jstate_t)attr->values[0].integer; in monitor_printer()
2656 else if (!strcmp(attr->name, "job-originating-user-name") && in monitor_printer()
2657 (attr->value_tag == IPP_TAG_NAME || in monitor_printer()
2658 attr->value_tag == IPP_TAG_NAMELANG)) in monitor_printer()
2659 job_user = attr->values[0].string.text; in monitor_printer()
2661 attr = attr->next; in monitor_printer()
2664 if (job_id > 0 && job_name && !strcmp(job_name, monitor->job_name) && in monitor_printer()
2665 job_user && monitor->user && !strcmp(job_user, monitor->user)) in monitor_printer()
2667 monitor->job_id = job_id; in monitor_printer()
2668 monitor->job_state = job_state; in monitor_printer()
2677 …fprintf(stderr, "DEBUG: (monitor) job-state = %s\n", ippEnumString("job-state", (int)monitor->job_… in monitor_printer()
2680 (monitor->job_state == IPP_JSTATE_CANCELED || in monitor_printer()
2681 monitor->job_state == IPP_JSTATE_ABORTED)) in monitor_printer()
2683 job_canceled = -1; in monitor_printer()
2684 fprintf(stderr, "DEBUG: (monitor) job_canceled = -1\n"); in monitor_printer()
2687 if ((attr = ippFindAttribute(response, "job-state-reasons", in monitor_printer()
2692 for (i = 0; i < attr->num_values; i ++) in monitor_printer()
2694 if (!strcmp(attr->values[i].string.text, "account-authorization-failed")) in monitor_printer()
2696 else if (!strcmp(attr->values[i].string.text, "account-closed")) in monitor_printer()
2698 else if (!strcmp(attr->values[i].string.text, "account-info-needed")) in monitor_printer()
2700 else if (!strcmp(attr->values[i].string.text, "account-limit-reached")) in monitor_printer()
2702 else if (!strcmp(attr->values[i].string.text, "job-password-wait")) in monitor_printer()
2704 else if (!strcmp(attr->values[i].string.text, "job-release-wait")) in monitor_printer()
2706 else if (!strcmp(attr->values[i].string.text, "document-format-error")) in monitor_printer()
2708 else if (!strcmp(attr->values[i].string.text, "document-unprintable-error")) in monitor_printer()
2711 …_canceled && (!strncmp(attr->values[i].string.text, "job-canceled-", 13) || !strcmp(attr->values[i… in monitor_printer()
2715 if (new_reasons != monitor->job_reasons) in monitor_printer()
2718 fputs("JOBSTATE: account-authorization-failed\n", stderr); in monitor_printer()
2720 fputs("JOBSTATE: account-closed\n", stderr); in monitor_printer()
2722 fputs("JOBSTATE: account-info-needed\n", stderr); in monitor_printer()
2724 fputs("JOBSTATE: account-limit-reached\n", stderr); in monitor_printer()
2726 fputs("JOBSTATE: job-password-wait\n", stderr); in monitor_printer()
2728 fputs("JOBSTATE: job-release-wait\n", stderr); in monitor_printer()
2731 if (monitor->retryable) in monitor_printer()
2738 fputs("JOBSTATE: cups-retry-as-raster\n", stderr); in monitor_printer()
2742 fputs("JOBSTATE: document-format-error\n", stderr); in monitor_printer()
2746 fputs("JOBSTATE: document-unprintable\n", stderr); in monitor_printer()
2750 fputs("JOBSTATE: job-printing\n", stderr); in monitor_printer()
2752 monitor->job_reasons = new_reasons; in monitor_printer()
2758 …fprintf(stderr, "DEBUG: (monitor) job-state = %s\n", ippEnumString("job-state", (int)monitor->job_… in monitor_printer()
2761 (monitor->job_state == IPP_JSTATE_CANCELED || in monitor_printer()
2762 monitor->job_state == IPP_JSTATE_ABORTED)) in monitor_printer()
2763 job_canceled = -1; in monitor_printer()
2778 * Cancel the job if necessary... in monitor_printer()
2781 if (job_canceled > 0 && monitor->job_id > 0) in monitor_printer()
2788 cancel_job(http, monitor->uri, monitor->job_id, monitor->resource, in monitor_printer()
2789 monitor->user, monitor->version); in monitor_printer()
2794 _cupsLangPrintFilter(stderr, "ERROR", _("Unable to cancel print job.")); in monitor_printer()
2810 * 'new_request()' - Create a new print creation or validation request.
2813 static ipp_t * /* O - Request data */
2815 ipp_op_t op, /* I - IPP operation code */ in new_request()
2816 int version, /* I - IPP version number */ in new_request()
2817 const char *uri, /* I - printer-uri value */ in new_request()
2818 const char *user, /* I - requesting-user-name value */ in new_request()
2819 const char *title, /* I - job-name value */ in new_request()
2820 int num_options, /* I - Number of options to send */ in new_request()
2821 cups_option_t *options, /* I - Options to send */ in new_request()
2822 const char *compression, /* I - compression value or NULL */ in new_request()
2823 int copies, /* I - copies value or 0 */ in new_request()
2824 const char *format, /* I - document-format value or NULL */ in new_request()
2825 _ppd_cache_t *pc, /* I - PPD cache and mapping data */ in new_request()
2826 ppd_file_t *ppd, /* I - PPD file data */ in new_request()
2827 ipp_attribute_t *media_col_sup, /* I - media-col-supported values */ in new_request()
2828 ipp_attribute_t *doc_handling_sup, /* I - multiple-document-handling-supported values */ in new_request()
2830 /* I - Printer supports print-color-mode? */ in new_request()
2831 ipp_attribute_t *print_scaling_sup) /* I - print-scaling-supported values */ in new_request()
2845 ippOpString(request->request.op.operation_id), in new_request()
2846 request->request.op.version[0], in new_request()
2847 request->request.op.version[1]); in new_request()
2853 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); in new_request()
2854 fprintf(stderr, "DEBUG: printer-uri=\"%s\"\n", uri); in new_request()
2858 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, user); in new_request()
2859 fprintf(stderr, "DEBUG: requesting-user-name=\"%s\"\n", user); in new_request()
2864 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL, title); in new_request()
2865 fprintf(stderr, "DEBUG: job-name=\"%s\"\n", title); in new_request()
2870 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, format); in new_request()
2871 fprintf(stderr, "DEBUG: document-format=\"%s\"\n", format); in new_request()
2883 * Handle options on the command-line... in new_request()
2894 fputs("DEBUG: Adding standard IPP operation/job attributes.\n", stderr); in new_request()
2898 …if ((keyword = cupsGetOption("print-scaling", num_options, options)) != NULL && ippContainsString(… in new_request()
2899 ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "print-scaling", NULL, keyword); in new_request()
2911 static const char * const allowed = "0123456789#*-+.()pw"; in new_request()
2949 ippAddString(destination, IPP_TAG_JOB, IPP_TAG_URI, "destination-uri", NULL, tel_uri); in new_request()
2950 fprintf(stderr, "DEBUG: Faxing to phone %s; destination-uri: %s\n", phone, tel_uri); in new_request()
2954 char predial[1024]; /* Pre-dial string */ in new_request()
2964 ippAddString(destination, IPP_TAG_JOB, IPP_TAG_TEXT, "pre-dial-string", NULL, ptr); in new_request()
2965 fprintf(stderr, "DEBUG: Pre-dialing %s; pre-dial-string: %s\n", ptr, ptr); in new_request()
2968 …fprintf(stderr, "WARNING: Pre-dial number for fax not valid! Sending fax without pre-dial number.\… in new_request()
2971 ippAddCollection(request, IPP_TAG_JOB, "destination-uris", destination); in new_request()
2984 fputs("DEBUG: Adding all operation/job attributes.\n", stderr); in new_request()
2987 if (format && (!strcmp(format, "image/pwg-raster") || !strcmp(format, "image/urf"))) in new_request()
2994 if (copies > 1 && (!pc || copies <= pc->max_copies)) in new_request()
3006 * 'password_cb()' - Disable the password prompt for cupsDoFileRequest().
3009 static const char * /* O - Password */
3010 password_cb(const char *prompt, /* I - Prompt (not used) */ in password_cb()
3011 http_t *http, /* I - Connection */ in password_cb()
3012 const char *method, /* I - Request method (not used) */ in password_cb()
3013 const char *resource, /* I - Resource path (not used) */ in password_cb()
3014 int *password_tries) /* I - Password tries */ in password_cb()
3040 fprintf(stderr, "ATTR: auth-info-default=%s,\n", in password_cb()
3065 * 'quote_string()' - Quote a string value.
3068 static const char * /* O - Quoted string */
3069 quote_string(const char *s, /* I - String */ in quote_string()
3070 char *q, /* I - Quoted string buffer */ in quote_string()
3071 size_t qsize) /* I - Size of quoted string buffer */ in quote_string()
3078 qend = q + qsize - 5; in quote_string()
3093 if (qptr < (qend - 4)) in quote_string()
3115 * 'report_attr()' - Report an IPP attribute value.
3119 report_attr(ipp_attribute_t *attr) /* I - Attribute */ in report_attr()
3132 i < attr->num_values && valptr < (value + sizeof(value) - 10); in report_attr()
3138 switch (attr->value_tag) in report_attr()
3142 snprintf(valptr, sizeof(value) - (size_t)(valptr - value), "%d", attr->values[i].integer); in report_attr()
3149 … quote_string(attr->values[i].string.text, valptr, (size_t)(value + sizeof(value) - valptr)); in report_attr()
3166 if ((cached = cupsGetOption(attr->name, num_attr_cache, in report_attr()
3173 num_attr_cache = cupsAddOption(attr->name, value, num_attr_cache, in report_attr()
3175 fprintf(stderr, "ATTR: %s=%s\n", attr->name, value); in report_attr()
3183 * 'report_printer_state()' - Report the printer state.
3187 report_printer_state(ipp_t *ipp) /* I - IPP response */ in report_printer_state()
3189 ipp_attribute_t *pa, /* printer-alert */ in report_printer_state()
3190 *pam, /* printer-alert-message */ in report_printer_state()
3191 *pmja, /* printer-mandatory-job-attributes */ in report_printer_state()
3192 *psm, /* printer-state-message */ in report_printer_state()
3193 *reasons, /* printer-state-reasons */ in report_printer_state()
3194 *marker; /* marker-* attributes */ in report_printer_state()
3197 static int ipp_supplies = -1; in report_printer_state()
3205 if ((pa = ippFindAttribute(ipp, "printer-alert", IPP_TAG_STRING)) != NULL) in report_printer_state()
3208 if ((pam = ippFindAttribute(ipp, "printer-alert-message", in report_printer_state()
3212 if ((pmja = ippFindAttribute(ipp, "printer-mandatory-job-attributes", IPP_TAG_KEYWORD)) != NULL) in report_printer_state()
3220 … snprintf(valptr, sizeof(value) - (size_t)(valptr - value), " %s", ippGetString(pmja, i, NULL)); in report_printer_state()
3232 if ((psm = ippFindAttribute(ipp, "printer-state-message", in report_printer_state()
3239 for (ptr = psm->values[0].string.text, valptr = value + 6; in report_printer_state()
3240 *ptr && valptr < (value + sizeof(value) - 6); in report_printer_state()
3249 snprintf(valptr, sizeof(value) - (size_t)(valptr - value), "<%02X>", *ptr); in report_printer_state()
3263 * Now report printer-state-reasons, filtering out some of the reasons we never in report_printer_state()
3264 * want to set... in report_printer_state()
3267 if ((reasons = ippFindAttribute(ipp, "printer-state-reasons", in report_printer_state()
3274 * Relay the current marker-* attribute values... in report_printer_state()
3284 ppdattr->value && _cups_strcasecmp(ppdattr->value, "true")) in report_printer_state()
3294 if ((marker = ippFindAttribute(ipp, "marker-colors", IPP_TAG_NAME)) != NULL) in report_printer_state()
3296 if ((marker = ippFindAttribute(ipp, "marker-high-levels", in report_printer_state()
3299 if ((marker = ippFindAttribute(ipp, "marker-levels", in report_printer_state()
3302 if ((marker = ippFindAttribute(ipp, "marker-low-levels", in report_printer_state()
3305 if ((marker = ippFindAttribute(ipp, "marker-message", in report_printer_state()
3308 if ((marker = ippFindAttribute(ipp, "marker-names", IPP_TAG_NAME)) != NULL) in report_printer_state()
3310 if ((marker = ippFindAttribute(ipp, "marker-types", in report_printer_state()
3319 * 'run_as_user()' - Run the IPP backend as the printing user.
3321 * This function uses an XPC-based user agent to run the backend as the printing
3326 static int /* O - Exit status */
3327 run_as_user(char *argv[], /* I - Command-line arguments */ in run_as_user()
3328 uid_t uid, /* I - User ID */ in run_as_user()
3329 const char *device_uri, /* I - Device URI */ in run_as_user()
3330 int fd) /* I - File to print */ in run_as_user()
3332 const char *auth_negotiate,/* AUTH_NEGOTIATE env var */ in run_as_user()
3333 *content_type, /* [FINAL_]CONTENT_TYPE env vars */ in run_as_user()
3334 *auth_info_required; /* New auth-info-required value */ in run_as_user()
3386 xpc_dictionary_set_string(request, "device-uri", device_uri); in run_as_user()
3387 xpc_dictionary_set_string(request, "job-id", argv[1]); in run_as_user()
3393 xpc_dictionary_set_string(request, "auth-info-required", in run_as_user()
3396 xpc_dictionary_set_string(request, "auth-negotiate", auth_negotiate); in run_as_user()
3398 xpc_dictionary_set_string(request, "content-type", content_type); in run_as_user()
3400 xpc_dictionary_set_string(request, "final-content-type", content_type); in run_as_user()
3403 xpc_dictionary_set_fd(request, "side-channel", CUPS_SC_FD); in run_as_user()
3411 child_pid = (pid_t)xpc_dictionary_get_int64(response, "child-pid"); in run_as_user()
3484 * 'sigterm_handler()' - Handle 'terminate' signals that stop the backend.
3488 sigterm_handler(int sig) /* I - Signal */ in sigterm_handler()
3505 * Flag that the job should be canceled... in sigterm_handler()
3527 * 'timeout_cb()' - Handle HTTP timeouts.
3530 static int /* O - 1 to continue, 0 to cancel */
3531 timeout_cb(http_t *http, /* I - Connection to server (unused) */ in timeout_cb()
3532 void *user_data) /* I - User data (unused) */ in timeout_cb()
3542 * 'update_reasons()' - Update the printer-state-reasons values.
3546 update_reasons(ipp_attribute_t *attr, /* I - printer-state-reasons or NULL */ in update_reasons()
3547 const char *s) /* I - STATE: string or NULL */ in update_reasons()
3549 char op; /* Add (+), remove (-), replace (\0) */ in update_reasons()
3561 attr ? attr->num_values : 0, attr ? attr->values[0].string.text : "", in update_reasons()
3562 attr && attr->num_values > 1 ? ",..." : "", s ? s : "(null)"); in update_reasons()
3575 for (i = 0; i < attr->num_values; i ++) in update_reasons()
3577 reason = attr->values[i].string.text; in update_reasons()
3580 strcmp(reason, "none-report") && in update_reasons()
3582 strncmp(reason, "spool-area-full", 15) && in update_reasons()
3583 strcmp(reason, "com.apple.print.recoverable-warning") && in update_reasons()
3584 strncmp(reason, "cups-", 5)) in update_reasons()
3590 if (*s == '+' || *s == '-') in update_reasons()
3608 remprefix = "STATE: -"; in update_reasons()
3629 if (!strncmp(reason, "cups-remote-", 12)) in update_reasons()
3632 * If we are setting cups-remote-xxx, remove all other cups-remote-xxx in update_reasons()
3643 if (!strncmp(temp, "cups-remote-", 12)) in update_reasons()
3645 snprintf(remptr, sizeof(rem) - (size_t)(remptr - rem), "%s%s", remprefix, temp); in update_reasons()
3658 snprintf(addptr, sizeof(add) - (size_t)(addptr - add), "%s%s", addprefix, reason); in update_reasons()
3664 else if (op == '-') in update_reasons()
3676 snprintf(remptr, sizeof(rem) - (size_t)(remptr - rem), "%s%s", remprefix, reason); in update_reasons()
3694 if (strncmp(reason, "cups-", 5) && !cupsArrayFind(new_reasons, reason)) in update_reasons()
3696 snprintf(remptr, sizeof(rem) - (size_t)(remptr - rem), "%s%s", remprefix, reason); in update_reasons()
3712 snprintf(addptr, sizeof(add) - (size_t)(addptr - add), "%s%s", addprefix, reason); in update_reasons()