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