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