]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
7e86f2f6 | 2 | * "lp" command for CUPS. |
ef416fc2 | 3 | * |
7e86f2f6 MS |
4 | * Copyright 2007-2014 by Apple Inc. |
5 | * Copyright 1997-2007 by Easy Software Products. | |
ef416fc2 | 6 | * |
7e86f2f6 MS |
7 | * These coded instructions, statements, and computer programs are the |
8 | * property of Apple Inc. and are protected by Federal copyright | |
9 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
10 | * which should have been included with this file. If this file is | |
11 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 12 | */ |
13 | ||
14 | /* | |
15 | * Include necessary headers... | |
16 | */ | |
17 | ||
71e16022 | 18 | #include <cups/cups-private.h> |
ef416fc2 | 19 | |
20 | ||
ef416fc2 | 21 | /* |
22 | * Local functions. | |
23 | */ | |
24 | ||
fa73b229 | 25 | int restart_job(const char *command, int job_id); |
26 | int set_job_attrs(const char *command, int job_id, int num_options, | |
27 | cups_option_t *options); | |
ef416fc2 | 28 | |
29 | ||
ef416fc2 | 30 | /* |
31 | * 'main()' - Parse options and send files for printing. | |
32 | */ | |
33 | ||
34 | int | |
35 | main(int argc, /* I - Number of command-line arguments */ | |
36 | char *argv[]) /* I - Command-line arguments */ | |
37 | { | |
38 | int i, j; /* Looping vars */ | |
39 | int job_id; /* Job ID */ | |
40 | char *printer, /* Printer name */ | |
a29fd7dd | 41 | *instance, /* Instance name */ |
ef416fc2 | 42 | *val, /* Option value */ |
43 | *title; /* Job title */ | |
44 | int priority; /* Job priority (1-100) */ | |
45 | int num_copies; /* Number of copies per file */ | |
46 | int num_files; /* Number of files to print */ | |
47 | const char *files[1000]; /* Files to print */ | |
a4924f6c | 48 | cups_dest_t *dest; /* Selected destination */ |
ef416fc2 | 49 | int num_options; /* Number of options */ |
50 | cups_option_t *options; /* Options */ | |
fa73b229 | 51 | int end_options; /* No more options? */ |
ef416fc2 | 52 | int silent; /* Silent or verbose output? */ |
53 | char buffer[8192]; /* Copy buffer */ | |
ef416fc2 | 54 | |
55 | ||
56 | #ifdef __sun | |
57 | /* | |
58 | * Solaris does some rather strange things to re-queue remote print | |
59 | * jobs. On bootup, the "lp" command is run as "printd" to re-spool | |
60 | * any remote jobs in /var/spool/print. Since CUPS doesn't need this | |
61 | * nonsense, we just need to add the necessary check here to prevent | |
62 | * lp from causing boot problems... | |
63 | */ | |
64 | ||
65 | if ((val = strrchr(argv[0], '/')) != NULL) | |
66 | val ++; | |
67 | else | |
68 | val = argv[0]; | |
69 | ||
70 | if (!strcmp(val, "printd")) | |
71 | return (0); | |
72 | #endif /* __sun */ | |
73 | ||
07725fee | 74 | _cupsSetLocale(argv); |
d09495fa | 75 | |
ef416fc2 | 76 | silent = 0; |
77 | printer = NULL; | |
a4924f6c | 78 | dest = NULL; |
ef416fc2 | 79 | num_options = 0; |
80 | options = NULL; | |
81 | num_files = 0; | |
82 | title = NULL; | |
83 | job_id = 0; | |
fa73b229 | 84 | end_options = 0; |
ef416fc2 | 85 | |
86 | for (i = 1; i < argc; i ++) | |
fa73b229 | 87 | if (argv[i][0] == '-' && argv[i][1] && !end_options) |
ef416fc2 | 88 | switch (argv[i][1]) |
89 | { | |
90 | case 'E' : /* Encrypt */ | |
91 | #ifdef HAVE_SSL | |
92 | cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); | |
93 | #else | |
0837b7e8 | 94 | _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), |
ef416fc2 | 95 | argv[0]); |
96 | #endif /* HAVE_SSL */ | |
97 | break; | |
98 | ||
fa73b229 | 99 | case 'U' : /* Username */ |
100 | if (argv[i][2] != '\0') | |
101 | cupsSetUser(argv[i] + 2); | |
102 | else | |
103 | { | |
104 | i ++; | |
105 | if (i >= argc) | |
106 | { | |
107 | _cupsLangPrintf(stderr, | |
0837b7e8 MS |
108 | _("%s: Error - expected username after \"-U\" " |
109 | "option."), argv[0]); | |
fa73b229 | 110 | return (1); |
111 | } | |
112 | ||
113 | cupsSetUser(argv[i]); | |
114 | } | |
115 | break; | |
a29fd7dd | 116 | |
ef416fc2 | 117 | case 'c' : /* Copy to spool dir (always enabled) */ |
118 | break; | |
119 | ||
120 | case 'd' : /* Destination printer or class */ | |
121 | if (argv[i][2] != '\0') | |
122 | printer = argv[i] + 2; | |
123 | else | |
124 | { | |
125 | i ++; | |
126 | ||
127 | if (i >= argc) | |
128 | { | |
fa73b229 | 129 | _cupsLangPrintf(stderr, |
130 | _("%s: Error - expected destination after " | |
0837b7e8 | 131 | "\"-d\" option."), argv[0]); |
ef416fc2 | 132 | return (1); |
133 | } | |
134 | ||
135 | printer = argv[i]; | |
136 | } | |
137 | ||
138 | if ((instance = strrchr(printer, '/')) != NULL) | |
139 | *instance++ = '\0'; | |
140 | ||
c606bcae MS |
141 | if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, |
142 | instance)) != NULL) | |
ef416fc2 | 143 | { |
144 | for (j = 0; j < dest->num_options; j ++) | |
0837b7e8 MS |
145 | if (cupsGetOption(dest->options[j].name, num_options, |
146 | options) == NULL) | |
ef416fc2 | 147 | num_options = cupsAddOption(dest->options[j].name, |
148 | dest->options[j].value, | |
149 | num_options, &options); | |
150 | } | |
c606bcae MS |
151 | else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || |
152 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
153 | { | |
154 | _cupsLangPrintf(stderr, | |
155 | _("%s: Error - add '/version=1.1' to server " | |
156 | "name."), argv[0]); | |
157 | return (1); | |
158 | } | |
ef416fc2 | 159 | break; |
160 | ||
161 | case 'f' : /* Form */ | |
162 | if (!argv[i][2]) | |
163 | { | |
164 | i ++; | |
165 | ||
166 | if (i >= argc) | |
167 | { | |
fa73b229 | 168 | _cupsLangPrintf(stderr, |
0837b7e8 MS |
169 | _("%s: Error - expected form after \"-f\" " |
170 | "option."), | |
fa73b229 | 171 | argv[0]); |
ef416fc2 | 172 | return (1); |
173 | } | |
174 | } | |
175 | ||
0837b7e8 | 176 | _cupsLangPrintf(stderr, _("%s: Warning - form option ignored."), |
fa73b229 | 177 | argv[0]); |
ef416fc2 | 178 | break; |
179 | ||
180 | case 'h' : /* Destination host */ | |
181 | if (argv[i][2] != '\0') | |
182 | cupsSetServer(argv[i] + 2); | |
183 | else | |
184 | { | |
185 | i ++; | |
186 | ||
187 | if (i >= argc) | |
188 | { | |
fa73b229 | 189 | _cupsLangPrintf(stderr, |
190 | _("%s: Error - expected hostname after " | |
0837b7e8 | 191 | "\"-h\" option."), argv[0]); |
ef416fc2 | 192 | return (1); |
193 | } | |
194 | ||
195 | cupsSetServer(argv[i]); | |
196 | } | |
197 | break; | |
198 | ||
199 | case 'i' : /* Change job */ | |
200 | if (argv[i][2]) | |
201 | val = argv[i] + 2; | |
202 | else | |
203 | { | |
204 | i ++; | |
205 | ||
206 | if (i >= argc) | |
207 | { | |
fa73b229 | 208 | _cupsLangPrintf(stderr, |
0837b7e8 | 209 | _("%s: Expected job ID after \"-i\" option."), |
fa73b229 | 210 | argv[0]); |
ef416fc2 | 211 | return (1); |
212 | } | |
213 | ||
214 | val = argv[i]; | |
215 | } | |
216 | ||
217 | if (num_files > 0) | |
218 | { | |
fa73b229 | 219 | _cupsLangPrintf(stderr, |
220 | _("%s: Error - cannot print files and alter " | |
0837b7e8 | 221 | "jobs simultaneously."), argv[0]); |
ef416fc2 | 222 | return (1); |
223 | } | |
224 | ||
225 | if (strrchr(val, '-') != NULL) | |
226 | job_id = atoi(strrchr(val, '-') + 1); | |
227 | else | |
228 | job_id = atoi(val); | |
229 | ||
230 | if (job_id < 0) | |
231 | { | |
0837b7e8 | 232 | _cupsLangPrintf(stderr, _("%s: Error - bad job ID."), argv[0]); |
ef416fc2 | 233 | break; |
234 | } | |
235 | break; | |
236 | ||
237 | case 'm' : /* Send email when job is done */ | |
238 | #ifdef __sun | |
239 | case 'p' : /* Notify on completion */ | |
240 | #endif /* __sun */ | |
241 | case 'w' : /* Write to console or email */ | |
fa73b229 | 242 | { |
243 | char email[1024]; /* EMail address */ | |
244 | ||
245 | ||
246 | snprintf(email, sizeof(email), "mailto:%s@%s", cupsUser(), | |
757d2cad | 247 | httpGetHostname(NULL, buffer, sizeof(buffer))); |
7594b224 | 248 | num_options = cupsAddOption("notify-recipient-uri", email, |
fa73b229 | 249 | num_options, &options); |
250 | } | |
251 | ||
252 | silent = 1; | |
ef416fc2 | 253 | break; |
254 | ||
255 | case 'n' : /* Number of copies */ | |
256 | if (argv[i][2] != '\0') | |
257 | num_copies = atoi(argv[i] + 2); | |
258 | else | |
259 | { | |
260 | i ++; | |
261 | ||
262 | if (i >= argc) | |
263 | { | |
fa73b229 | 264 | _cupsLangPrintf(stderr, |
265 | _("%s: Error - expected copies after " | |
0837b7e8 | 266 | "\"-n\" option."), argv[0]); |
ef416fc2 | 267 | return (1); |
268 | } | |
269 | ||
270 | num_copies = atoi(argv[i]); | |
271 | } | |
272 | ||
273 | sprintf(buffer, "%d", num_copies); | |
0837b7e8 MS |
274 | num_options = cupsAddOption("copies", buffer, num_options, |
275 | &options); | |
ef416fc2 | 276 | break; |
277 | ||
278 | case 'o' : /* Option */ | |
279 | if (argv[i][2] != '\0') | |
0837b7e8 MS |
280 | num_options = cupsParseOptions(argv[i] + 2, num_options, |
281 | &options); | |
ef416fc2 | 282 | else |
283 | { | |
284 | i ++; | |
285 | ||
286 | if (i >= argc) | |
287 | { | |
fa73b229 | 288 | _cupsLangPrintf(stderr, |
84315f46 | 289 | _("%s: Error - expected option=value after " |
0837b7e8 | 290 | "\"-o\" option."), argv[0]); |
ef416fc2 | 291 | return (1); |
292 | } | |
293 | ||
294 | num_options = cupsParseOptions(argv[i], num_options, &options); | |
295 | } | |
296 | break; | |
297 | ||
298 | #ifndef __sun | |
299 | case 'p' : /* Queue priority */ | |
300 | #endif /* !__sun */ | |
301 | case 'q' : /* Queue priority */ | |
302 | if (argv[i][2] != '\0') | |
303 | priority = atoi(argv[i] + 2); | |
304 | else | |
305 | { | |
306 | if ((i + 1) >= argc) | |
307 | { | |
fa73b229 | 308 | _cupsLangPrintf(stderr, |
309 | _("%s: Error - expected priority after " | |
0837b7e8 | 310 | "\"-%c\" option."), argv[0], argv[i][1]); |
ef416fc2 | 311 | return (1); |
312 | } | |
313 | ||
314 | i ++; | |
315 | ||
316 | priority = atoi(argv[i]); | |
317 | } | |
318 | ||
319 | /* | |
320 | * For 100% Solaris compatibility, need to add: | |
321 | * | |
322 | * priority = 99 * (39 - priority) / 39 + 1; | |
323 | * | |
324 | * However, to keep CUPS lp the same across all platforms | |
325 | * we will break compatibility this far... | |
326 | */ | |
327 | ||
328 | if (priority < 1 || priority > 100) | |
329 | { | |
fa73b229 | 330 | _cupsLangPrintf(stderr, |
331 | _("%s: Error - priority must be between 1 and " | |
0837b7e8 | 332 | "100."), argv[0]); |
ef416fc2 | 333 | return (1); |
334 | } | |
335 | ||
336 | sprintf(buffer, "%d", priority); | |
0837b7e8 MS |
337 | num_options = cupsAddOption("job-priority", buffer, num_options, |
338 | &options); | |
ef416fc2 | 339 | break; |
340 | ||
341 | case 's' : /* Silent */ | |
342 | silent = 1; | |
343 | break; | |
344 | ||
345 | case 't' : /* Title */ | |
346 | if (argv[i][2] != '\0') | |
347 | title = argv[i] + 2; | |
348 | else | |
349 | { | |
350 | i ++; | |
351 | ||
352 | if (i >= argc) | |
353 | { | |
fa73b229 | 354 | _cupsLangPrintf(stderr, |
355 | _("%s: Error - expected title after " | |
0837b7e8 | 356 | "\"-t\" option."), argv[0]); |
ef416fc2 | 357 | return (1); |
358 | } | |
359 | ||
360 | title = argv[i]; | |
361 | } | |
362 | break; | |
363 | ||
364 | case 'y' : /* mode-list */ | |
365 | if (!argv[i][2]) | |
366 | { | |
367 | i ++; | |
368 | ||
369 | if (i >= argc) | |
370 | { | |
fa73b229 | 371 | _cupsLangPrintf(stderr, |
372 | _("%s: Error - expected mode list after " | |
0837b7e8 | 373 | "\"-y\" option."), argv[0]); |
ef416fc2 | 374 | return (1); |
375 | } | |
376 | } | |
377 | ||
fa73b229 | 378 | _cupsLangPrintf(stderr, |
0837b7e8 | 379 | _("%s: Warning - mode option ignored."), argv[0]); |
ef416fc2 | 380 | break; |
381 | ||
382 | case 'H' : /* Hold job */ | |
383 | if (argv[i][2]) | |
384 | val = argv[i] + 2; | |
385 | else | |
386 | { | |
387 | i ++; | |
388 | ||
389 | if (i >= argc) | |
390 | { | |
fa73b229 | 391 | _cupsLangPrintf(stderr, |
392 | _("%s: Error - expected hold name after " | |
0837b7e8 | 393 | "\"-H\" option."), argv[0]); |
ef416fc2 | 394 | return (1); |
395 | } | |
396 | ||
397 | val = argv[i]; | |
398 | } | |
399 | ||
400 | if (!strcmp(val, "hold")) | |
401 | num_options = cupsAddOption("job-hold-until", "indefinite", | |
402 | num_options, &options); | |
403 | else if (!strcmp(val, "resume") || | |
404 | !strcmp(val, "release")) | |
405 | num_options = cupsAddOption("job-hold-until", "no-hold", | |
406 | num_options, &options); | |
407 | else if (!strcmp(val, "immediate")) | |
52f6f666 MS |
408 | { |
409 | num_options = cupsAddOption("job-hold-until", "no-hold", | |
410 | num_options, &options); | |
ef416fc2 | 411 | num_options = cupsAddOption("job-priority", "100", |
412 | num_options, &options); | |
52f6f666 | 413 | } |
ef416fc2 | 414 | else if (!strcmp(val, "restart")) |
415 | { | |
416 | if (job_id < 1) | |
417 | { | |
fa73b229 | 418 | _cupsLangPrintf(stderr, |
0837b7e8 MS |
419 | _("%s: Need job ID (\"-i jobid\") before " |
420 | "\"-H restart\"."), argv[0]); | |
ef416fc2 | 421 | return (1); |
422 | } | |
423 | ||
fa73b229 | 424 | if (restart_job(argv[0], job_id)) |
ef416fc2 | 425 | return (1); |
426 | } | |
427 | else | |
428 | num_options = cupsAddOption("job-hold-until", val, | |
429 | num_options, &options); | |
430 | break; | |
431 | ||
432 | case 'P' : /* Page list */ | |
433 | if (argv[i][2]) | |
434 | val = argv[i] + 2; | |
435 | else | |
436 | { | |
437 | i ++; | |
438 | ||
439 | if (i >= argc) | |
440 | { | |
fa73b229 | 441 | _cupsLangPrintf(stderr, |
442 | _("%s: Error - expected page list after " | |
0837b7e8 | 443 | "\"-P\" option."), argv[0]); |
ef416fc2 | 444 | return (1); |
445 | } | |
446 | ||
447 | val = argv[i]; | |
448 | } | |
449 | ||
450 | num_options = cupsAddOption("page-ranges", val, num_options, | |
451 | &options); | |
452 | break; | |
453 | ||
454 | case 'S' : /* character set */ | |
455 | if (!argv[i][2]) | |
456 | { | |
457 | i ++; | |
458 | ||
459 | if (i >= argc) | |
460 | { | |
fa73b229 | 461 | _cupsLangPrintf(stderr, |
462 | _("%s: Error - expected character set after " | |
0837b7e8 | 463 | "\"-S\" option."), argv[0]); |
ef416fc2 | 464 | return (1); |
465 | } | |
466 | } | |
467 | ||
fa73b229 | 468 | _cupsLangPrintf(stderr, |
0837b7e8 | 469 | _("%s: Warning - character set option ignored."), |
fa73b229 | 470 | argv[0]); |
ef416fc2 | 471 | break; |
472 | ||
473 | case 'T' : /* Content-Type */ | |
474 | if (!argv[i][2]) | |
475 | { | |
476 | i ++; | |
477 | ||
478 | if (i >= argc) | |
479 | { | |
fa73b229 | 480 | _cupsLangPrintf(stderr, |
481 | _("%s: Error - expected content type after " | |
0837b7e8 | 482 | "\"-T\" option."), argv[0]); |
ef416fc2 | 483 | return (1); |
484 | } | |
485 | } | |
486 | ||
fa73b229 | 487 | _cupsLangPrintf(stderr, |
0837b7e8 | 488 | _("%s: Warning - content type option ignored."), |
fa73b229 | 489 | argv[0]); |
490 | break; | |
491 | ||
492 | case '-' : /* Stop processing options */ | |
db8b865d MS |
493 | if (argv[i][2]) |
494 | { | |
495 | _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."), | |
496 | argv[0], argv[i]); | |
497 | return (1); | |
498 | } | |
499 | ||
fa73b229 | 500 | end_options = 1; |
ef416fc2 | 501 | break; |
502 | ||
503 | default : | |
0837b7e8 | 504 | _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), |
fa73b229 | 505 | argv[0], argv[i][1]); |
ef416fc2 | 506 | return (1); |
507 | } | |
508 | else if (!strcmp(argv[i], "-")) | |
509 | { | |
510 | if (num_files || job_id) | |
511 | { | |
fa73b229 | 512 | _cupsLangPrintf(stderr, |
513 | _("%s: Error - cannot print from stdin if files or a " | |
0837b7e8 | 514 | "job ID are provided."), argv[0]); |
ef416fc2 | 515 | return (1); |
516 | } | |
517 | ||
518 | break; | |
519 | } | |
520 | else if (num_files < 1000 && job_id == 0) | |
521 | { | |
522 | /* | |
523 | * Print a file... | |
524 | */ | |
525 | ||
526 | if (access(argv[i], R_OK) != 0) | |
527 | { | |
0837b7e8 | 528 | _cupsLangPrintf(stderr, _("%s: Error - unable to access \"%s\" - %s"), |
fa73b229 | 529 | argv[0], argv[i], strerror(errno)); |
ef416fc2 | 530 | return (1); |
531 | } | |
532 | ||
533 | files[num_files] = argv[i]; | |
534 | num_files ++; | |
535 | ||
536 | if (title == NULL) | |
537 | { | |
538 | if ((title = strrchr(argv[i], '/')) != NULL) | |
539 | title ++; | |
540 | else | |
541 | title = argv[i]; | |
542 | } | |
543 | } | |
544 | else | |
0837b7e8 | 545 | _cupsLangPrintf(stderr, _("%s: Error - too many files - \"%s\"."), |
fa73b229 | 546 | argv[0], argv[i]); |
ef416fc2 | 547 | |
548 | /* | |
549 | * See if we are altering an existing job... | |
550 | */ | |
551 | ||
552 | if (job_id) | |
fa73b229 | 553 | return (set_job_attrs(argv[0], job_id, num_options, options)); |
ef416fc2 | 554 | |
555 | /* | |
556 | * See if we have any files to print; if not, print from stdin... | |
557 | */ | |
558 | ||
559 | if (printer == NULL) | |
560 | { | |
a4924f6c | 561 | if ((dest = cupsGetNamedDest(NULL, NULL, NULL)) != NULL) |
ef416fc2 | 562 | { |
563 | printer = dest->name; | |
564 | ||
565 | for (j = 0; j < dest->num_options; j ++) | |
566 | if (cupsGetOption(dest->options[j].name, num_options, options) == NULL) | |
567 | num_options = cupsAddOption(dest->options[j].name, | |
568 | dest->options[j].value, | |
569 | num_options, &options); | |
570 | } | |
c606bcae MS |
571 | else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || |
572 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
573 | { | |
574 | _cupsLangPrintf(stderr, | |
575 | _("%s: Error - add '/version=1.1' to server " | |
576 | "name."), argv[0]); | |
577 | return (1); | |
578 | } | |
ef416fc2 | 579 | } |
580 | ||
581 | if (printer == NULL) | |
582 | { | |
583 | val = NULL; | |
584 | ||
585 | if ((printer = getenv("LPDEST")) == NULL) | |
586 | { | |
587 | if ((printer = getenv("PRINTER")) != NULL) | |
588 | { | |
589 | if (!strcmp(printer, "lp")) | |
590 | printer = NULL; | |
591 | else | |
592 | val = "PRINTER"; | |
593 | } | |
594 | } | |
595 | else | |
596 | val = "LPDEST"; | |
597 | ||
a4924f6c | 598 | if (printer && !cupsGetNamedDest(NULL, printer, NULL)) |
fa73b229 | 599 | _cupsLangPrintf(stderr, |
600 | _("%s: Error - %s environment variable names " | |
0837b7e8 MS |
601 | "non-existent destination \"%s\"."), argv[0], val, |
602 | printer); | |
ef416fc2 | 603 | else if (cupsLastError() == IPP_NOT_FOUND) |
fa73b229 | 604 | _cupsLangPrintf(stderr, |
0837b7e8 | 605 | _("%s: Error - no default destination available."), |
fa73b229 | 606 | argv[0]); |
ef416fc2 | 607 | else |
0837b7e8 | 608 | _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."), |
fa73b229 | 609 | argv[0]); |
ef416fc2 | 610 | |
611 | return (1); | |
612 | } | |
613 | ||
614 | if (num_files > 0) | |
615 | job_id = cupsPrintFiles(printer, num_files, files, title, num_options, options); | |
3d052e43 MS |
616 | else if ((job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, printer, |
617 | title ? title : "(stdin)", | |
618 | num_options, options)) > 0) | |
ef416fc2 | 619 | { |
3d052e43 MS |
620 | http_status_t status; /* Write status */ |
621 | const char *format; /* Document format */ | |
622 | ssize_t bytes; /* Bytes read */ | |
ef416fc2 | 623 | |
3d052e43 MS |
624 | if (cupsGetOption("raw", num_options, options)) |
625 | format = CUPS_FORMAT_RAW; | |
626 | else if ((format = cupsGetOption("document-format", num_options, | |
627 | options)) == NULL) | |
628 | format = CUPS_FORMAT_AUTO; | |
629 | ||
630 | status = cupsStartDocument(CUPS_HTTP_DEFAULT, printer, job_id, NULL, | |
631 | format, 1); | |
ef416fc2 | 632 | |
3d052e43 MS |
633 | while (status == HTTP_CONTINUE && |
634 | (bytes = read(0, buffer, sizeof(buffer))) > 0) | |
7e86f2f6 | 635 | status = cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, (size_t)bytes); |
3d052e43 MS |
636 | |
637 | if (status != HTTP_CONTINUE) | |
ef416fc2 | 638 | { |
0837b7e8 | 639 | _cupsLangPrintf(stderr, _("%s: Error - unable to queue from stdin - %s."), |
3d052e43 | 640 | argv[0], httpStatus(status)); |
12f89d24 MS |
641 | cupsFinishDocument(CUPS_HTTP_DEFAULT, printer); |
642 | cupsCancelJob2(CUPS_HTTP_DEFAULT, printer, job_id, 0); | |
ef416fc2 | 643 | return (1); |
644 | } | |
645 | ||
3d052e43 | 646 | if (cupsFinishDocument(CUPS_HTTP_DEFAULT, printer) != IPP_OK) |
12f89d24 | 647 | { |
a29fd7dd | 648 | _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString()); |
12f89d24 | 649 | cupsCancelJob2(CUPS_HTTP_DEFAULT, printer, job_id, 0); |
a29fd7dd | 650 | return (1); |
12f89d24 | 651 | } |
ef416fc2 | 652 | } |
653 | ||
654 | if (job_id < 1) | |
655 | { | |
0837b7e8 | 656 | _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString()); |
ef416fc2 | 657 | return (1); |
658 | } | |
659 | else if (!silent) | |
0837b7e8 | 660 | _cupsLangPrintf(stdout, _("request id is %s-%d (%d file(s))"), |
ef416fc2 | 661 | printer, job_id, num_files); |
662 | ||
663 | return (0); | |
664 | } | |
665 | ||
666 | ||
667 | /* | |
668 | * 'restart_job()' - Restart a job. | |
669 | */ | |
670 | ||
671 | int /* O - Exit status */ | |
fa73b229 | 672 | restart_job(const char *command, /* I - Command name */ |
673 | int job_id) /* I - Job ID */ | |
ef416fc2 | 674 | { |
fa73b229 | 675 | ipp_t *request; /* IPP request */ |
ef416fc2 | 676 | char uri[HTTP_MAX_URI]; /* URI for job */ |
677 | ||
678 | ||
fa73b229 | 679 | request = ippNewRequest(IPP_RESTART_JOB); |
ef416fc2 | 680 | |
681 | sprintf(uri, "ipp://localhost/jobs/%d", job_id); | |
682 | ||
683 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, | |
684 | "job-uri", NULL, uri); | |
685 | ||
686 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, | |
687 | "requesting-user-name", NULL, cupsUser()); | |
688 | ||
3d052e43 | 689 | ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/jobs")); |
ef416fc2 | 690 | |
c606bcae MS |
691 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || |
692 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
693 | { | |
694 | _cupsLangPrintf(stderr, | |
695 | _("%s: Error - add '/version=1.1' to server " | |
696 | "name."), command); | |
697 | return (1); | |
698 | } | |
699 | else if (cupsLastError() > IPP_OK_CONFLICT) | |
ef416fc2 | 700 | { |
0837b7e8 | 701 | _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString()); |
ef416fc2 | 702 | return (1); |
703 | } | |
704 | ||
705 | return (0); | |
706 | } | |
707 | ||
708 | ||
709 | /* | |
710 | * 'set_job_attrs()' - Set job attributes. | |
711 | */ | |
712 | ||
713 | int /* O - Exit status */ | |
fa73b229 | 714 | set_job_attrs(const char *command, /* I - Command name */ |
715 | int job_id, /* I - Job ID */ | |
ef416fc2 | 716 | int num_options,/* I - Number of options */ |
717 | cups_option_t *options) /* I - Options */ | |
718 | { | |
fa73b229 | 719 | ipp_t *request; /* IPP request */ |
ef416fc2 | 720 | char uri[HTTP_MAX_URI]; /* URI for job */ |
721 | ||
722 | ||
723 | if (num_options == 0) | |
724 | return (0); | |
725 | ||
fa73b229 | 726 | request = ippNewRequest(IPP_SET_JOB_ATTRIBUTES); |
ef416fc2 | 727 | |
728 | sprintf(uri, "ipp://localhost/jobs/%d", job_id); | |
729 | ||
730 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, | |
731 | "job-uri", NULL, uri); | |
732 | ||
733 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, | |
734 | "requesting-user-name", NULL, cupsUser()); | |
735 | ||
736 | cupsEncodeOptions(request, num_options, options); | |
737 | ||
3d052e43 | 738 | ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/jobs")); |
ef416fc2 | 739 | |
c606bcae MS |
740 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || |
741 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
742 | { | |
743 | _cupsLangPrintf(stderr, | |
744 | _("%s: Error - add '/version=1.1' to server " | |
745 | "name."), command); | |
746 | return (1); | |
747 | } | |
748 | else if (cupsLastError() > IPP_OK_CONFLICT) | |
ef416fc2 | 749 | { |
0837b7e8 | 750 | _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString()); |
ef416fc2 | 751 | return (1); |
752 | } | |
753 | ||
754 | return (0); | |
755 | } |