]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/dest-options.c
Full sweep of all Clang warnings, plus some bug fixes for incorrect memcpy usage.
[thirdparty/cups.git] / cups / dest-options.c
1 /*
2 * "$Id$"
3 *
4 * Destination option/media support for CUPS.
5 *
6 * Copyright 2012-2014 by Apple Inc.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
13 *
14 * This file is subject to the Apple OS-Developed Software exception.
15 */
16
17 /*
18 * Include necessary headers...
19 */
20
21 #include "cups-private.h"
22
23
24 /*
25 * Local constants...
26 */
27
28 #define _CUPS_MEDIA_READY_TTL 30 /* Life of xxx-ready values */
29
30
31 /*
32 * Local functions...
33 */
34
35 static void cups_add_dconstres(cups_array_t *a, ipp_t *collection);
36 static int cups_compare_dconstres(_cups_dconstres_t *a,
37 _cups_dconstres_t *b);
38 static int cups_compare_media_db(_cups_media_db_t *a,
39 _cups_media_db_t *b);
40 static _cups_media_db_t *cups_copy_media_db(_cups_media_db_t *mdb);
41 static void cups_create_cached(http_t *http, cups_dinfo_t *dinfo,
42 unsigned flags);
43 static void cups_create_constraints(cups_dinfo_t *dinfo);
44 static void cups_create_defaults(cups_dinfo_t *dinfo);
45 static void cups_create_media_db(cups_dinfo_t *dinfo,
46 unsigned flags);
47 static void cups_free_media_db(_cups_media_db_t *mdb);
48 static int cups_get_media_db(http_t *http, cups_dinfo_t *dinfo,
49 pwg_media_t *pwg, unsigned flags,
50 cups_size_t *size);
51 static int cups_is_close_media_db(_cups_media_db_t *a,
52 _cups_media_db_t *b);
53 static cups_array_t *cups_test_constraints(cups_dinfo_t *dinfo,
54 const char *new_option,
55 const char *new_value,
56 int num_options,
57 cups_option_t *options,
58 int *num_conflicts,
59 cups_option_t **conflicts);
60 static void cups_update_ready(http_t *http, cups_dinfo_t *dinfo);
61
62
63 /*
64 * 'cupsCheckDestSupported()' - Check that the option and value are supported
65 * by the destination.
66 *
67 * Returns 1 if supported, 0 otherwise.
68 *
69 * @since CUPS 1.6/OS X 10.8@
70 */
71
72 int /* O - 1 if supported, 0 otherwise */
73 cupsCheckDestSupported(
74 http_t *http, /* I - Connection to destination */
75 cups_dest_t *dest, /* I - Destination */
76 cups_dinfo_t *dinfo, /* I - Destination information */
77 const char *option, /* I - Option */
78 const char *value) /* I - Value */
79 {
80 int i; /* Looping var */
81 char temp[1024]; /* Temporary string */
82 int int_value; /* Integer value */
83 int xres_value, /* Horizontal resolution */
84 yres_value; /* Vertical resolution */
85 ipp_res_t units_value; /* Resolution units */
86 ipp_attribute_t *attr; /* Attribute */
87 _ipp_value_t *attrval; /* Current attribute value */
88
89
90 /*
91 * Range check input...
92 */
93
94 if (!http || !dest || !dinfo || !option || !value)
95 return (0);
96
97 /*
98 * Lookup the attribute...
99 */
100
101 if (strstr(option, "-supported"))
102 attr = ippFindAttribute(dinfo->attrs, option, IPP_TAG_ZERO);
103 else
104 {
105 snprintf(temp, sizeof(temp), "%s-supported", option);
106 attr = ippFindAttribute(dinfo->attrs, temp, IPP_TAG_ZERO);
107 }
108
109 if (!attr)
110 return (0);
111
112 /*
113 * Compare values...
114 */
115
116 if (!strcmp(option, "media") && !strncmp(value, "custom_", 7))
117 {
118 /*
119 * Check range of custom media sizes...
120 */
121
122 pwg_media_t *pwg; /* Current PWG media size info */
123 int min_width, /* Minimum width */
124 min_length, /* Minimum length */
125 max_width, /* Maximum width */
126 max_length; /* Maximum length */
127
128 /*
129 * Get the minimum and maximum size...
130 */
131
132 min_width = min_length = INT_MAX;
133 max_width = max_length = 0;
134
135 for (i = attr->num_values, attrval = attr->values;
136 i > 0;
137 i --, attrval ++)
138 {
139 if (!strncmp(attrval->string.text, "custom_min_", 11) &&
140 (pwg = pwgMediaForPWG(attrval->string.text)) != NULL)
141 {
142 min_width = pwg->width;
143 min_length = pwg->length;
144 }
145 else if (!strncmp(attrval->string.text, "custom_max_", 11) &&
146 (pwg = pwgMediaForPWG(attrval->string.text)) != NULL)
147 {
148 max_width = pwg->width;
149 max_length = pwg->length;
150 }
151 }
152
153 /*
154 * Check the range...
155 */
156
157 if (min_width < INT_MAX && max_width > 0 &&
158 (pwg = pwgMediaForPWG(value)) != NULL &&
159 pwg->width >= min_width && pwg->width <= max_width &&
160 pwg->length >= min_length && pwg->length <= max_length)
161 return (1);
162 }
163 else
164 {
165 /*
166 * Check literal values...
167 */
168
169 switch (attr->value_tag)
170 {
171 case IPP_TAG_INTEGER :
172 case IPP_TAG_ENUM :
173 int_value = atoi(value);
174
175 for (i = 0; i < attr->num_values; i ++)
176 if (attr->values[i].integer == int_value)
177 return (1);
178 break;
179
180 case IPP_TAG_BOOLEAN :
181 return (attr->values[0].boolean);
182
183 case IPP_TAG_RANGE :
184 int_value = atoi(value);
185
186 for (i = 0; i < attr->num_values; i ++)
187 if (int_value >= attr->values[i].range.lower &&
188 int_value <= attr->values[i].range.upper)
189 return (1);
190 break;
191
192 case IPP_TAG_RESOLUTION :
193 if (sscanf(value, "%dx%d%15s", &xres_value, &yres_value, temp) != 3)
194 {
195 if (sscanf(value, "%d%15s", &xres_value, temp) != 2)
196 return (0);
197
198 yres_value = xres_value;
199 }
200
201 if (!strcmp(temp, "dpi"))
202 units_value = IPP_RES_PER_INCH;
203 else if (!strcmp(temp, "dpc") || !strcmp(temp, "dpcm"))
204 units_value = IPP_RES_PER_CM;
205 else
206 return (0);
207
208 for (i = attr->num_values, attrval = attr->values;
209 i > 0;
210 i --, attrval ++)
211 {
212 if (attrval->resolution.xres == xres_value &&
213 attrval->resolution.yres == yres_value &&
214 attrval->resolution.units == units_value)
215 return (1);
216 }
217 break;
218
219 case IPP_TAG_TEXT :
220 case IPP_TAG_NAME :
221 case IPP_TAG_KEYWORD :
222 case IPP_TAG_CHARSET :
223 case IPP_TAG_URI :
224 case IPP_TAG_URISCHEME :
225 case IPP_TAG_MIMETYPE :
226 case IPP_TAG_LANGUAGE :
227 case IPP_TAG_TEXTLANG :
228 case IPP_TAG_NAMELANG :
229 for (i = 0; i < attr->num_values; i ++)
230 if (!strcmp(attr->values[i].string.text, value))
231 return (1);
232 break;
233
234 default :
235 break;
236 }
237 }
238
239 /*
240 * If we get there the option+value is not supported...
241 */
242
243 return (0);
244 }
245
246
247 /*
248 * 'cupsCopyDestConflicts()' - Get conflicts and resolutions for a new
249 * option/value pair.
250 *
251 * "num_options" and "options" represent the currently selected options by the
252 * user. "new_option" and "new_value" are the setting the user has just
253 * changed.
254 *
255 * Returns 1 if there is a conflict, 0 if there are no conflicts, and -1 if
256 * there was an unrecoverable error such as a resolver loop.
257 *
258 * If "num_conflicts" and "conflicts" are not @code NULL@, they are set to
259 * contain the list of conflicting option/value pairs. Similarly, if
260 * "num_resolved" and "resolved" are not @code NULL@ they will be set to the
261 * list of changes needed to resolve the conflict.
262 *
263 * If cupsCopyDestConflicts returns 1 but "num_resolved" and "resolved" are set
264 * to 0 and @code NULL@, respectively, then the conflict cannot be resolved.
265 *
266 * @since CUPS 1.6/OS X 10.8@
267 */
268
269 int /* O - 1 if there is a conflict, 0 if none, -1 on error */
270 cupsCopyDestConflicts(
271 http_t *http, /* I - Connection to destination */
272 cups_dest_t *dest, /* I - Destination */
273 cups_dinfo_t *dinfo, /* I - Destination information */
274 int num_options, /* I - Number of current options */
275 cups_option_t *options, /* I - Current options */
276 const char *new_option, /* I - New option */
277 const char *new_value, /* I - New value */
278 int *num_conflicts, /* O - Number of conflicting options */
279 cups_option_t **conflicts, /* O - Conflicting options */
280 int *num_resolved, /* O - Number of options to resolve */
281 cups_option_t **resolved) /* O - Resolved options */
282 {
283 int i, /* Looping var */
284 have_conflicts = 0, /* Do we have conflicts? */
285 changed, /* Did we change something? */
286 tries, /* Number of tries for resolution */
287 num_myconf = 0, /* My number of conflicting options */
288 num_myres = 0; /* My number of resolved options */
289 cups_option_t *myconf = NULL, /* My conflicting options */
290 *myres = NULL, /* My resolved options */
291 *myoption, /* My current option */
292 *option; /* Current option */
293 cups_array_t *active = NULL, /* Active conflicts */
294 *pass = NULL, /* Resolvers for this pass */
295 *resolvers = NULL, /* Resolvers we have used */
296 *test; /* Test array for conflicts */
297 _cups_dconstres_t *c, /* Current constraint */
298 *r; /* Current resolver */
299 ipp_attribute_t *attr; /* Current attribute */
300 char value[2048]; /* Current attribute value as string */
301 const char *myvalue; /* Current value of an option */
302
303
304 /*
305 * Clear returned values...
306 */
307
308 if (num_conflicts)
309 *num_conflicts = 0;
310
311 if (conflicts)
312 *conflicts = NULL;
313
314 if (num_resolved)
315 *num_resolved = 0;
316
317 if (resolved)
318 *resolved = NULL;
319
320 /*
321 * Range check input...
322 */
323
324 if (!http || !dest || !dinfo ||
325 (num_conflicts != NULL) != (conflicts != NULL) ||
326 (num_resolved != NULL) != (resolved != NULL))
327 return (0);
328
329 /*
330 * Load constraints as needed...
331 */
332
333 if (!dinfo->constraints)
334 cups_create_constraints(dinfo);
335
336 if (cupsArrayCount(dinfo->constraints) == 0)
337 return (0);
338
339 if (!dinfo->num_defaults)
340 cups_create_defaults(dinfo);
341
342 /*
343 * If we are resolving, create a shadow array...
344 */
345
346 if (num_resolved)
347 {
348 for (i = num_options, option = options; i > 0; i --, option ++)
349 num_myres = cupsAddOption(option->name, option->value, num_myres, &myres);
350
351 if (new_option && new_value)
352 num_myres = cupsAddOption(new_option, new_value, num_myres, &myres);
353 }
354 else
355 {
356 num_myres = num_options;
357 myres = options;
358 }
359
360 /*
361 * Check for any conflicts...
362 */
363
364 if (num_resolved)
365 pass = cupsArrayNew((cups_array_func_t)cups_compare_dconstres, NULL);
366
367 for (tries = 0; tries < 100; tries ++)
368 {
369 /*
370 * Check for any conflicts...
371 */
372
373 if (num_conflicts || num_resolved)
374 {
375 cupsFreeOptions(num_myconf, myconf);
376
377 num_myconf = 0;
378 myconf = NULL;
379 active = cups_test_constraints(dinfo, new_option, new_value,
380 num_myres, myres, &num_myconf,
381 &myconf);
382 }
383 else
384 active = cups_test_constraints(dinfo, new_option, new_value, num_myres,
385 myres, NULL, NULL);
386
387 have_conflicts = (active != NULL);
388
389 if (!active || !num_resolved)
390 break; /* All done */
391
392 /*
393 * Scan the constraints that were triggered to apply resolvers...
394 */
395
396 if (!resolvers)
397 resolvers = cupsArrayNew((cups_array_func_t)cups_compare_dconstres, NULL);
398
399 for (c = (_cups_dconstres_t *)cupsArrayFirst(active), changed = 0;
400 c;
401 c = (_cups_dconstres_t *)cupsArrayNext(active))
402 {
403 if (cupsArrayFind(pass, c))
404 continue; /* Already applied this resolver... */
405
406 if (cupsArrayFind(resolvers, c))
407 {
408 DEBUG_printf(("1cupsCopyDestConflicts: Resolver loop with %s.",
409 c->name));
410 have_conflicts = -1;
411 goto cleanup;
412 }
413
414 if ((r = cupsArrayFind(dinfo->resolvers, c)) == NULL)
415 {
416 DEBUG_printf(("1cupsCopyDestConflicts: Resolver %s not found.",
417 c->name));
418 have_conflicts = -1;
419 goto cleanup;
420 }
421
422 /*
423 * Add the options from the resolver...
424 */
425
426 cupsArrayAdd(pass, r);
427 cupsArrayAdd(resolvers, r);
428
429 for (attr = ippFirstAttribute(r->collection);
430 attr;
431 attr = ippNextAttribute(r->collection))
432 {
433 if (new_option && !strcmp(attr->name, new_option))
434 continue; /* Ignore this if we just changed it */
435
436 if (ippAttributeString(attr, value, sizeof(value)) >= sizeof(value))
437 continue; /* Ignore if the value is too long */
438
439 if ((test = cups_test_constraints(dinfo, attr->name, value, num_myres,
440 myres, NULL, NULL)) == NULL)
441 {
442 /*
443 * That worked, flag it...
444 */
445
446 changed = 1;
447 }
448 else
449 cupsArrayDelete(test);
450
451 /*
452 * Add the option/value from the resolver regardless of whether it
453 * worked; this makes sure that we can cascade several changes to
454 * make things resolve...
455 */
456
457 num_myres = cupsAddOption(attr->name, value, num_myres, &myres);
458 }
459 }
460
461 if (!changed)
462 {
463 DEBUG_puts("1cupsCopyDestConflicts: Unable to resolve constraints.");
464 have_conflicts = -1;
465 goto cleanup;
466 }
467
468 cupsArrayClear(pass);
469
470 cupsArrayDelete(active);
471 active = NULL;
472 }
473
474 if (tries >= 100)
475 {
476 DEBUG_puts("1cupsCopyDestConflicts: Unable to resolve after 100 tries.");
477 have_conflicts = -1;
478 goto cleanup;
479 }
480
481 /*
482 * Copy resolved options as needed...
483 */
484
485 if (num_resolved)
486 {
487 for (i = num_myres, myoption = myres; i > 0; i --, myoption ++)
488 {
489 if ((myvalue = cupsGetOption(myoption->name, num_options,
490 options)) == NULL ||
491 strcmp(myvalue, myoption->value))
492 {
493 if (new_option && !strcmp(new_option, myoption->name) &&
494 new_value && !strcmp(new_value, myoption->value))
495 continue;
496
497 *num_resolved = cupsAddOption(myoption->name, myoption->value,
498 *num_resolved, resolved);
499 }
500 }
501 }
502
503 /*
504 * Clean up...
505 */
506
507 cleanup:
508
509 cupsArrayDelete(active);
510 cupsArrayDelete(pass);
511 cupsArrayDelete(resolvers);
512
513 if (num_resolved)
514 {
515 /*
516 * Free shadow copy of options...
517 */
518
519 cupsFreeOptions(num_myres, myres);
520 }
521
522 if (num_conflicts)
523 {
524 /*
525 * Return conflicting options to caller...
526 */
527
528 *num_conflicts = num_myconf;
529 *conflicts = myconf;
530 }
531 else
532 {
533 /*
534 * Free conflicting options...
535 */
536
537 cupsFreeOptions(num_myconf, myconf);
538 }
539
540 return (have_conflicts);
541 }
542
543
544 /*
545 * 'cupsCopyDestInfo()' - Get the supported values/capabilities for the
546 * destination.
547 *
548 * The caller is responsible for calling @link cupsFreeDestInfo@ on the return
549 * value. @code NULL@ is returned on error.
550 *
551 * @since CUPS 1.6/OS X 10.8@
552 */
553
554 cups_dinfo_t * /* O - Destination information */
555 cupsCopyDestInfo(
556 http_t *http, /* I - Connection to destination */
557 cups_dest_t *dest) /* I - Destination */
558 {
559 cups_dinfo_t *dinfo; /* Destination information */
560 ipp_t *request, /* Get-Printer-Attributes request */
561 *response; /* Supported attributes */
562 int tries, /* Number of tries so far */
563 delay, /* Current retry delay */
564 prev_delay; /* Next retry delay */
565 const char *uri; /* Printer URI */
566 char resource[1024]; /* Resource path */
567 int version; /* IPP version */
568 ipp_status_t status; /* Status of request */
569 static const char * const requested_attrs[] =
570 { /* Requested attributes */
571 "job-template",
572 "media-col-database",
573 "printer-description"
574 };
575
576
577 DEBUG_printf(("cupsCopyDestSupported(http=%p, dest=%p(%s))", http, dest,
578 dest ? dest->name : ""));
579
580 /*
581 * Range check input...
582 */
583
584 if (!http || !dest)
585 return (NULL);
586
587 /*
588 * Get the printer URI and resource path...
589 */
590
591 if ((uri = _cupsGetDestResource(dest, resource, sizeof(resource))) == NULL)
592 return (NULL);
593
594 /*
595 * Get the supported attributes...
596 */
597
598 delay = 1;
599 prev_delay = 1;
600 tries = 0;
601 version = 20;
602
603 do
604 {
605 /*
606 * Send a Get-Printer-Attributes request...
607 */
608
609 request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
610 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
611 uri);
612 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
613 "requesting-user-name", NULL, cupsUser());
614 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
615 "requested-attributes",
616 (int)(sizeof(requested_attrs) / sizeof(requested_attrs[0])),
617 NULL, requested_attrs);
618 response = cupsDoRequest(http, request, resource);
619 status = cupsLastError();
620
621 if (status > IPP_STATUS_OK_IGNORED_OR_SUBSTITUTED)
622 {
623 DEBUG_printf(("cupsCopyDestSupported: Get-Printer-Attributes for '%s' "
624 "returned %s (%s)", dest->name, ippErrorString(status),
625 cupsLastErrorString()));
626
627 ippDelete(response);
628 response = NULL;
629
630 if (status == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED && version > 11)
631 version = 11;
632 else if (status == IPP_STATUS_ERROR_BUSY)
633 {
634 sleep((unsigned)delay);
635
636 delay = _cupsNextDelay(delay, &prev_delay);
637 }
638 else
639 return (NULL);
640 }
641
642 tries ++;
643 }
644 while (!response && tries < 10);
645
646 if (!response)
647 return (NULL);
648
649 /*
650 * Allocate a cups_dinfo_t structure and return it...
651 */
652
653 if ((dinfo = calloc(1, sizeof(cups_dinfo_t))) == NULL)
654 {
655 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
656 ippDelete(response);
657 return (NULL);
658 }
659
660 dinfo->version = version;
661 dinfo->uri = uri;
662 dinfo->resource = _cupsStrAlloc(resource);
663 dinfo->attrs = response;
664
665 return (dinfo);
666 }
667
668
669 /*
670 * 'cupsFindDestDefault()' - Find the default value(s) for the given option.
671 *
672 * The returned value is an IPP attribute. Use the @code ippGetBoolean@,
673 * @code ippGetCollection@, @code ippGetCount@, @code ippGetDate@,
674 * @code ippGetInteger@, @code ippGetOctetString@, @code ippGetRange@,
675 * @code ippGetResolution@, @code ippGetString@, and @code ippGetValueTag@
676 * functions to inspect the default value(s) as needed.
677 *
678 * @since CUPS 1.7/OS X 10.9@
679 */
680
681 ipp_attribute_t * /* O - Default attribute or @code NULL@ for none */
682 cupsFindDestDefault(
683 http_t *http, /* I - Connection to destination */
684 cups_dest_t *dest, /* I - Destination */
685 cups_dinfo_t *dinfo, /* I - Destination information */
686 const char *option) /* I - Option/attribute name */
687 {
688 char name[IPP_MAX_NAME]; /* Attribute name */
689
690
691 /*
692 * Range check input...
693 */
694
695 if (!http || !dest || !dinfo || !option)
696 {
697 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
698 return (NULL);
699 }
700
701 /*
702 * Find and return the attribute...
703 */
704
705 snprintf(name, sizeof(name), "%s-default", option);
706 return (ippFindAttribute(dinfo->attrs, name, IPP_TAG_ZERO));
707 }
708
709 /*
710 * 'cupsFindDestReady()' - Find the default value(s) for the given option.
711 *
712 * The returned value is an IPP attribute. Use the @code ippGetBoolean@,
713 * @code ippGetCollection@, @code ippGetCount@, @code ippGetDate@,
714 * @code ippGetInteger@, @code ippGetOctetString@, @code ippGetRange@,
715 * @code ippGetResolution@, @code ippGetString@, and @code ippGetValueTag@
716 * functions to inspect the default value(s) as needed.
717 *
718 * @since CUPS 1.7/OS X 10.9@
719 */
720
721 ipp_attribute_t * /* O - Default attribute or @code NULL@ for none */
722 cupsFindDestReady(
723 http_t *http, /* I - Connection to destination */
724 cups_dest_t *dest, /* I - Destination */
725 cups_dinfo_t *dinfo, /* I - Destination information */
726 const char *option) /* I - Option/attribute name */
727 {
728 char name[IPP_MAX_NAME]; /* Attribute name */
729
730
731 /*
732 * Range check input...
733 */
734
735 if (!http || !dest || !dinfo || !option)
736 {
737 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
738 return (NULL);
739 }
740
741 /*
742 * Find and return the attribute...
743 */
744
745 cups_update_ready(http, dinfo);
746
747 snprintf(name, sizeof(name), "%s-ready", option);
748 return (ippFindAttribute(dinfo->ready_attrs, name, IPP_TAG_ZERO));
749 }
750
751 /*
752 * 'cupsFindDestSupported()' - Find the default value(s) for the given option.
753 *
754 * The returned value is an IPP attribute. Use the @code ippGetBoolean@,
755 * @code ippGetCollection@, @code ippGetCount@, @code ippGetDate@,
756 * @code ippGetInteger@, @code ippGetOctetString@, @code ippGetRange@,
757 * @code ippGetResolution@, @code ippGetString@, and @code ippGetValueTag@
758 * functions to inspect the default value(s) as needed.
759 *
760 * @since CUPS 1.7/OS X 10.9@
761 */
762
763 ipp_attribute_t * /* O - Default attribute or @code NULL@ for none */
764 cupsFindDestSupported(
765 http_t *http, /* I - Connection to destination */
766 cups_dest_t *dest, /* I - Destination */
767 cups_dinfo_t *dinfo, /* I - Destination information */
768 const char *option) /* I - Option/attribute name */
769 {
770 char name[IPP_MAX_NAME]; /* Attribute name */
771
772
773 /*
774 * Range check input...
775 */
776
777 if (!http || !dest || !dinfo || !option)
778 {
779 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
780 return (NULL);
781 }
782
783 /*
784 * Find and return the attribute...
785 */
786
787 snprintf(name, sizeof(name), "%s-supported", option);
788 return (ippFindAttribute(dinfo->attrs, name, IPP_TAG_ZERO));
789 }
790
791
792 /*
793 * 'cupsFreeDestInfo()' - Free destination information obtained using
794 * @link cupsCopyDestInfo@.
795 */
796
797 void
798 cupsFreeDestInfo(cups_dinfo_t *dinfo) /* I - Destination information */
799 {
800 /*
801 * Range check input...
802 */
803
804 if (!dinfo)
805 return;
806
807 /*
808 * Free memory and return...
809 */
810
811 _cupsStrFree(dinfo->resource);
812
813 cupsArrayDelete(dinfo->constraints);
814 cupsArrayDelete(dinfo->resolvers);
815
816 cupsArrayDelete(dinfo->localizations);
817
818 cupsArrayDelete(dinfo->media_db);
819
820 cupsArrayDelete(dinfo->cached_db);
821
822 ippDelete(dinfo->ready_attrs);
823 cupsArrayDelete(dinfo->ready_db);
824
825 ippDelete(dinfo->attrs);
826
827 free(dinfo);
828 }
829
830
831 /*
832 * 'cupsGetDestMediaByIndex()' - Get a media name, dimension, and margins for a
833 * specific size.
834 *
835 * The @code flags@ parameter determines which set of media are indexed. For
836 * example, passing @code CUPS_MEDIA_FLAGS_BORDERLESS@ will get the Nth
837 * borderless size supported by the printer.
838 *
839 * @since CUPS 1.7/OS X 10.9@
840 */
841
842 int /* O - 1 on success, 0 on failure */
843 cupsGetDestMediaByIndex(
844 http_t *http, /* I - Connection to destination */
845 cups_dest_t *dest, /* I - Destination */
846 cups_dinfo_t *dinfo, /* I - Destination information */
847 int n, /* I - Media size number (0-based) */
848 unsigned flags, /* I - Media flags */
849 cups_size_t *size) /* O - Media size information */
850 {
851 cups_size_t *nsize; /* Size for N */
852
853
854 /*
855 * Range check input...
856 */
857
858 if (size)
859 memset(size, 0, sizeof(cups_size_t));
860
861 if (!http || !dest || !dinfo || n < 0 || !size)
862 {
863 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
864 return (0);
865 }
866
867 /*
868 * Load media list as needed...
869 */
870
871 if (flags & CUPS_MEDIA_FLAGS_READY)
872 cups_update_ready(http, dinfo);
873
874 if (!dinfo->cached_db || dinfo->cached_flags != flags)
875 cups_create_cached(http, dinfo, flags);
876
877 /*
878 * Copy the size over and return...
879 */
880
881 if ((nsize = (cups_size_t *)cupsArrayIndex(dinfo->cached_db, n)) == NULL)
882 {
883 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
884 return (0);
885 }
886
887 memcpy(size, nsize, sizeof(cups_size_t));
888
889 return (1);
890 }
891
892
893 /*
894 * 'cupsGetDestMediaByName()' - Get media names, dimensions, and margins.
895 *
896 * The "media" string is a PWG media name. "Flags" provides some matching
897 * guidance (multiple flags can be combined):
898 *
899 * CUPS_MEDIA_FLAGS_DEFAULT = find the closest size supported by the printer,
900 * CUPS_MEDIA_FLAGS_BORDERLESS = find a borderless size,
901 * CUPS_MEDIA_FLAGS_DUPLEX = find a size compatible with 2-sided printing,
902 * CUPS_MEDIA_FLAGS_EXACT = find an exact match for the size, and
903 * CUPS_MEDIA_FLAGS_READY = if the printer supports media sensing, find the
904 * size amongst the "ready" media.
905 *
906 * The matching result (if any) is returned in the "cups_size_t" structure.
907 *
908 * Returns 1 when there is a match and 0 if there is not a match.
909 *
910 * @since CUPS 1.6/OS X 10.8@
911 */
912
913 int /* O - 1 on match, 0 on failure */
914 cupsGetDestMediaByName(
915 http_t *http, /* I - Connection to destination */
916 cups_dest_t *dest, /* I - Destination */
917 cups_dinfo_t *dinfo, /* I - Destination information */
918 const char *media, /* I - Media name */
919 unsigned flags, /* I - Media matching flags */
920 cups_size_t *size) /* O - Media size information */
921 {
922 pwg_media_t *pwg; /* PWG media info */
923
924
925 /*
926 * Range check input...
927 */
928
929 if (size)
930 memset(size, 0, sizeof(cups_size_t));
931
932 if (!http || !dest || !dinfo || !media || !size)
933 {
934 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
935 return (0);
936 }
937
938 /*
939 * Lookup the media size name...
940 */
941
942 if ((pwg = pwgMediaForPWG(media)) == NULL)
943 if ((pwg = pwgMediaForLegacy(media)) == NULL)
944 {
945 DEBUG_printf(("1cupsGetDestMediaByName: Unknown size '%s'.", media));
946 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unknown media size name."), 1);
947 return (0);
948 }
949
950 /*
951 * Lookup the size...
952 */
953
954 return (cups_get_media_db(http, dinfo, pwg, flags, size));
955 }
956
957
958 /*
959 * 'cupsGetDestMediaBySize()' - Get media names, dimensions, and margins.
960 *
961 * "Width" and "length" are the dimensions in hundredths of millimeters.
962 * "Flags" provides some matching guidance (multiple flags can be combined):
963 *
964 * CUPS_MEDIA_FLAGS_DEFAULT = find the closest size supported by the printer,
965 * CUPS_MEDIA_FLAGS_BORDERLESS = find a borderless size,
966 * CUPS_MEDIA_FLAGS_DUPLEX = find a size compatible with 2-sided printing,
967 * CUPS_MEDIA_FLAGS_EXACT = find an exact match for the size, and
968 * CUPS_MEDIA_FLAGS_READY = if the printer supports media sensing, find the
969 * size amongst the "ready" media.
970 *
971 * The matching result (if any) is returned in the "cups_size_t" structure.
972 *
973 * Returns 1 when there is a match and 0 if there is not a match.
974 *
975 * @since CUPS 1.6/OS X 10.8@
976 */
977
978 int /* O - 1 on match, 0 on failure */
979 cupsGetDestMediaBySize(
980 http_t *http, /* I - Connection to destination */
981 cups_dest_t *dest, /* I - Destination */
982 cups_dinfo_t *dinfo, /* I - Destination information */
983 int width, /* I - Media width in hundredths of
984 * of millimeters */
985 int length, /* I - Media length in hundredths of
986 * of millimeters */
987 unsigned flags, /* I - Media matching flags */
988 cups_size_t *size) /* O - Media size information */
989 {
990 pwg_media_t *pwg; /* PWG media info */
991
992
993 /*
994 * Range check input...
995 */
996
997 if (size)
998 memset(size, 0, sizeof(cups_size_t));
999
1000 if (!http || !dest || !dinfo || width <= 0 || length <= 0 || !size)
1001 {
1002 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
1003 return (0);
1004 }
1005
1006 /*
1007 * Lookup the media size name...
1008 */
1009
1010 if ((pwg = pwgMediaForSize(width, length)) == NULL)
1011 {
1012 DEBUG_printf(("1cupsGetDestMediaBySize: Invalid size %dx%d.", width,
1013 length));
1014 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Invalid media size."), 1);
1015 return (0);
1016 }
1017
1018 /*
1019 * Lookup the size...
1020 */
1021
1022 return (cups_get_media_db(http, dinfo, pwg, flags, size));
1023 }
1024
1025
1026 /*
1027 * 'cupsGetDestMediaCount()' - Get the number of sizes supported by a
1028 * destination.
1029 *
1030 * The @code flags@ parameter determines the set of media sizes that are
1031 * counted. For example, passing @code CUPS_MEDIA_FLAGS_BORDERLESS@ will return
1032 * the number of borderless sizes.
1033 *
1034 * @since CUPS 1.7/OS X 10.9@
1035 */
1036
1037 int /* O - Number of sizes */
1038 cupsGetDestMediaCount(
1039 http_t *http, /* I - Connection to destination */
1040 cups_dest_t *dest, /* I - Destination */
1041 cups_dinfo_t *dinfo, /* I - Destination information */
1042 unsigned flags) /* I - Media flags */
1043 {
1044 /*
1045 * Range check input...
1046 */
1047
1048 if (!http || !dest || !dinfo)
1049 {
1050 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
1051 return (0);
1052 }
1053
1054 /*
1055 * Load media list as needed...
1056 */
1057
1058 if (flags & CUPS_MEDIA_FLAGS_READY)
1059 cups_update_ready(http, dinfo);
1060
1061 if (!dinfo->cached_db || dinfo->cached_flags != flags)
1062 cups_create_cached(http, dinfo, flags);
1063
1064 return (cupsArrayCount(dinfo->cached_db));
1065 }
1066
1067
1068 /*
1069 * 'cupsGetDestMediaDefault()' - Get the default size for a destination.
1070 *
1071 * The @code flags@ parameter determines which default size is returned. For
1072 * example, passing @code CUPS_MEDIA_FLAGS_BORDERLESS@ will return the default
1073 * borderless size, typically US Letter or A4, but sometimes 4x6 photo media.
1074 *
1075 * @since CUPS 1.7/OS X 10.9@
1076 */
1077
1078 int /* O - 1 on success, 0 on failure */
1079 cupsGetDestMediaDefault(
1080 http_t *http, /* I - Connection to destination */
1081 cups_dest_t *dest, /* I - Destination */
1082 cups_dinfo_t *dinfo, /* I - Destination information */
1083 unsigned flags, /* I - Media flags */
1084 cups_size_t *size) /* O - Media size information */
1085 {
1086 const char *media; /* Default media size */
1087
1088
1089 /*
1090 * Range check input...
1091 */
1092
1093 if (size)
1094 memset(size, 0, sizeof(cups_size_t));
1095
1096 if (!http || !dest || !dinfo || !size)
1097 {
1098 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
1099 return (0);
1100 }
1101
1102 /*
1103 * Get the default media size, if any...
1104 */
1105
1106 if ((media = cupsGetOption("media", dest->num_options,
1107 dest->options)) == NULL)
1108 media = "na_letter_8.5x11in";
1109
1110 if (cupsGetDestMediaByName(http, dest, dinfo, media, flags, size))
1111 return (1);
1112
1113 if (strcmp(media, "na_letter_8.5x11in") &&
1114 cupsGetDestMediaByName(http, dest, dinfo, "iso_a4_210x297mm", flags,
1115 size))
1116 return (1);
1117
1118 if (strcmp(media, "iso_a4_210x297mm") &&
1119 cupsGetDestMediaByName(http, dest, dinfo, "na_letter_8.5x11in", flags,
1120 size))
1121 return (1);
1122
1123 if ((flags & CUPS_MEDIA_FLAGS_BORDERLESS) &&
1124 cupsGetDestMediaByName(http, dest, dinfo, "na_index_4x6in", flags, size))
1125 return (1);
1126
1127 /*
1128 * Fall back to the first matching media size...
1129 */
1130
1131 return (cupsGetDestMediaByIndex(http, dest, dinfo, 0, flags, size));
1132 }
1133
1134
1135 /*
1136 * 'cups_add_dconstres()' - Add a constraint or resolver to an array.
1137 */
1138
1139 static void
1140 cups_add_dconstres(
1141 cups_array_t *a, /* I - Array */
1142 ipp_t *collection) /* I - Collection value */
1143 {
1144 ipp_attribute_t *attr; /* Attribute */
1145 _cups_dconstres_t *temp; /* Current constraint/resolver */
1146
1147
1148 if ((attr = ippFindAttribute(collection, "resolver-name",
1149 IPP_TAG_NAME)) == NULL)
1150 return;
1151
1152 if ((temp = calloc(1, sizeof(_cups_dconstres_t))) == NULL)
1153 return;
1154
1155 temp->name = attr->values[0].string.text;
1156 temp->collection = collection;
1157
1158 cupsArrayAdd(a, temp);
1159 }
1160
1161
1162 /*
1163 * 'cups_compare_dconstres()' - Compare to resolver entries.
1164 */
1165
1166 static int /* O - Result of comparison */
1167 cups_compare_dconstres(
1168 _cups_dconstres_t *a, /* I - First resolver */
1169 _cups_dconstres_t *b) /* I - Second resolver */
1170 {
1171 return (strcmp(a->name, b->name));
1172 }
1173
1174
1175 /*
1176 * 'cups_compare_media_db()' - Compare two media entries.
1177 */
1178
1179 static int /* O - Result of comparison */
1180 cups_compare_media_db(
1181 _cups_media_db_t *a, /* I - First media entries */
1182 _cups_media_db_t *b) /* I - Second media entries */
1183 {
1184 int result; /* Result of comparison */
1185
1186
1187 if ((result = a->width - b->width) == 0)
1188 result = a->length - b->length;
1189
1190 return (result);
1191 }
1192
1193
1194 /*
1195 * 'cups_copy_media_db()' - Copy a media entry.
1196 */
1197
1198 static _cups_media_db_t * /* O - New media entry */
1199 cups_copy_media_db(
1200 _cups_media_db_t *mdb) /* I - Media entry to copy */
1201 {
1202 _cups_media_db_t *temp; /* New media entry */
1203
1204
1205 if ((temp = calloc(1, sizeof(_cups_media_db_t))) == NULL)
1206 return (NULL);
1207
1208 if (mdb->color)
1209 temp->color = _cupsStrAlloc(mdb->color);
1210 if (mdb->key)
1211 temp->key = _cupsStrAlloc(mdb->key);
1212 if (mdb->info)
1213 temp->info = _cupsStrAlloc(mdb->info);
1214 if (mdb->size_name)
1215 temp->size_name = _cupsStrAlloc(mdb->size_name);
1216 if (mdb->source)
1217 temp->source = _cupsStrAlloc(mdb->source);
1218 if (mdb->type)
1219 temp->type = _cupsStrAlloc(mdb->type);
1220
1221 temp->width = mdb->width;
1222 temp->length = mdb->length;
1223 temp->bottom = mdb->bottom;
1224 temp->left = mdb->left;
1225 temp->right = mdb->right;
1226 temp->top = mdb->top;
1227
1228 return (temp);
1229 }
1230
1231
1232 /*
1233 * 'cups_create_cached()' - Create the media selection cache.
1234 */
1235
1236 static void
1237 cups_create_cached(http_t *http, /* I - Connection to destination */
1238 cups_dinfo_t *dinfo, /* I - Destination information */
1239 unsigned flags) /* I - Media selection flags */
1240 {
1241 cups_array_t *db; /* Media database array to use */
1242 _cups_media_db_t *mdb, /* Media database entry */
1243 *first; /* First entry this size */
1244
1245
1246 if (dinfo->cached_db)
1247 cupsArrayDelete(dinfo->cached_db);
1248
1249 dinfo->cached_db = cupsArrayNew(NULL, NULL);
1250 dinfo->cached_flags = flags;
1251
1252 if (flags & CUPS_MEDIA_FLAGS_READY)
1253 {
1254 cups_update_ready(http, dinfo);
1255 db = dinfo->ready_db;
1256 }
1257 else
1258 {
1259 if (!dinfo->media_db)
1260 cups_create_media_db(dinfo, CUPS_MEDIA_FLAGS_DEFAULT);
1261
1262 db = dinfo->media_db;
1263 }
1264
1265 for (mdb = (_cups_media_db_t *)cupsArrayFirst(db), first = mdb;
1266 mdb;
1267 mdb = (_cups_media_db_t *)cupsArrayNext(db))
1268 {
1269 if (flags & CUPS_MEDIA_FLAGS_BORDERLESS)
1270 {
1271 if (!mdb->left && !mdb->right && !mdb->top && !mdb->bottom)
1272 cupsArrayAdd(dinfo->cached_db, mdb);
1273 }
1274 else if (flags & CUPS_MEDIA_FLAGS_DUPLEX)
1275 {
1276 if (first->width != mdb->width || first->length != mdb->length)
1277 {
1278 cupsArrayAdd(dinfo->cached_db, first);
1279 first = mdb;
1280 }
1281 else if (mdb->left >= first->left && mdb->right >= first->right &&
1282 mdb->top >= first->top && mdb->bottom >= first->bottom)
1283 first = mdb;
1284 }
1285 }
1286
1287 if (flags & CUPS_MEDIA_FLAGS_DUPLEX)
1288 cupsArrayAdd(dinfo->cached_db, first);
1289 }
1290
1291
1292 /*
1293 * 'cups_create_constraints()' - Create the constraints and resolvers arrays.
1294 */
1295
1296 static void
1297 cups_create_constraints(
1298 cups_dinfo_t *dinfo) /* I - Destination information */
1299 {
1300 int i; /* Looping var */
1301 ipp_attribute_t *attr; /* Attribute */
1302 _ipp_value_t *val; /* Current value */
1303
1304
1305 dinfo->constraints = cupsArrayNew3(NULL, NULL, NULL, 0, NULL,
1306 (cups_afree_func_t)free);
1307 dinfo->resolvers = cupsArrayNew3((cups_array_func_t)cups_compare_dconstres,
1308 NULL, NULL, 0, NULL,
1309 (cups_afree_func_t)free);
1310
1311 if ((attr = ippFindAttribute(dinfo->attrs, "job-constraints-supported",
1312 IPP_TAG_BEGIN_COLLECTION)) != NULL)
1313 {
1314 for (i = attr->num_values, val = attr->values; i > 0; i --, val ++)
1315 cups_add_dconstres(dinfo->constraints, val->collection);
1316 }
1317
1318 if ((attr = ippFindAttribute(dinfo->attrs, "job-resolvers-supported",
1319 IPP_TAG_BEGIN_COLLECTION)) != NULL)
1320 {
1321 for (i = attr->num_values, val = attr->values; i > 0; i --, val ++)
1322 cups_add_dconstres(dinfo->resolvers, val->collection);
1323 }
1324 }
1325
1326
1327 /*
1328 * 'cups_create_defaults()' - Create the -default option array.
1329 *
1330 * TODO: Need to support collection defaults...
1331 */
1332
1333 static void
1334 cups_create_defaults(
1335 cups_dinfo_t *dinfo) /* I - Destination information */
1336 {
1337 ipp_attribute_t *attr; /* Current attribute */
1338 char name[IPP_MAX_NAME + 1],
1339 /* Current name */
1340 *nameptr, /* Pointer into current name */
1341 value[2048]; /* Current value */
1342
1343
1344 /*
1345 * Iterate through the printer attributes looking for xxx-default and adding
1346 * xxx=value to the defaults option array.
1347 */
1348
1349 for (attr = ippFirstAttribute(dinfo->attrs);
1350 attr;
1351 attr = ippNextAttribute(dinfo->attrs))
1352 {
1353 if (!attr->name || attr->group_tag != IPP_TAG_PRINTER)
1354 continue;
1355
1356 if (attr->value_tag == IPP_TAG_BEGIN_COLLECTION)
1357 continue; /* TODO: STR #4096 */
1358
1359 if ((nameptr = attr->name + strlen(attr->name) - 8) <= attr->name ||
1360 strcmp(nameptr, "-default"))
1361 continue;
1362
1363 strlcpy(name, attr->name, sizeof(name));
1364 if ((nameptr = name + strlen(name) - 8) <= name ||
1365 strcmp(nameptr, "-default"))
1366 continue;
1367
1368 *nameptr = '\0';
1369
1370 if (ippAttributeString(attr, value, sizeof(value)) >= sizeof(value))
1371 continue;
1372
1373 dinfo->num_defaults = cupsAddOption(name, value, dinfo->num_defaults,
1374 &dinfo->defaults);
1375 }
1376 }
1377
1378
1379 /*
1380 * 'cups_create_media_db()' - Create the media database.
1381 */
1382
1383 static void
1384 cups_create_media_db(
1385 cups_dinfo_t *dinfo, /* I - Destination information */
1386 unsigned flags) /* I - Media flags */
1387 {
1388 int i; /* Looping var */
1389 _ipp_value_t *val; /* Current value */
1390 ipp_attribute_t *media_col_db, /* media-col-database */
1391 *media_attr, /* media-xxx */
1392 *x_dimension, /* x-dimension */
1393 *y_dimension; /* y-dimension */
1394 pwg_media_t *pwg; /* PWG media info */
1395 cups_array_t *db; /* New media database array */
1396 _cups_media_db_t mdb; /* Media entry */
1397
1398
1399 db = cupsArrayNew3((cups_array_func_t)cups_compare_media_db,
1400 NULL, NULL, 0,
1401 (cups_acopy_func_t)cups_copy_media_db,
1402 (cups_afree_func_t)cups_free_media_db);
1403
1404 if (flags == CUPS_MEDIA_FLAGS_READY)
1405 {
1406 dinfo->ready_db = db;
1407
1408 media_col_db = ippFindAttribute(dinfo->ready_attrs, "media-col-ready",
1409 IPP_TAG_BEGIN_COLLECTION);
1410 media_attr = ippFindAttribute(dinfo->ready_attrs, "media-ready",
1411 IPP_TAG_ZERO);
1412 }
1413 else
1414 {
1415 dinfo->media_db = db;
1416 dinfo->min_size.width = INT_MAX;
1417 dinfo->min_size.length = INT_MAX;
1418 dinfo->max_size.width = 0;
1419 dinfo->max_size.length = 0;
1420
1421 media_col_db = ippFindAttribute(dinfo->attrs, "media-col-database",
1422 IPP_TAG_BEGIN_COLLECTION);
1423 media_attr = ippFindAttribute(dinfo->attrs, "media-supported",
1424 IPP_TAG_ZERO);
1425 }
1426
1427 if (media_col_db)
1428 {
1429 _ipp_value_t *custom = NULL; /* Custom size range value */
1430
1431 for (i = media_col_db->num_values, val = media_col_db->values;
1432 i > 0;
1433 i --, val ++)
1434 {
1435 memset(&mdb, 0, sizeof(mdb));
1436
1437 if ((media_attr = ippFindAttribute(val->collection, "media-size",
1438 IPP_TAG_BEGIN_COLLECTION)) != NULL)
1439 {
1440 ipp_t *media_size = media_attr->values[0].collection;
1441 /* media-size collection value */
1442
1443 if ((x_dimension = ippFindAttribute(media_size, "x-dimension",
1444 IPP_TAG_INTEGER)) != NULL &&
1445 (y_dimension = ippFindAttribute(media_size, "y-dimension",
1446 IPP_TAG_INTEGER)) != NULL)
1447 {
1448 /*
1449 * Fixed size...
1450 */
1451
1452 mdb.width = x_dimension->values[0].integer;
1453 mdb.length = y_dimension->values[0].integer;
1454 }
1455 else if ((x_dimension = ippFindAttribute(media_size, "x-dimension",
1456 IPP_TAG_INTEGER)) != NULL &&
1457 (y_dimension = ippFindAttribute(media_size, "y-dimension",
1458 IPP_TAG_RANGE)) != NULL)
1459 {
1460 /*
1461 * Roll limits...
1462 */
1463
1464 mdb.width = x_dimension->values[0].integer;
1465 mdb.length = y_dimension->values[0].range.upper;
1466 }
1467 else if (flags != CUPS_MEDIA_FLAGS_READY &&
1468 (x_dimension = ippFindAttribute(media_size, "x-dimension",
1469 IPP_TAG_RANGE)) != NULL &&
1470 (y_dimension = ippFindAttribute(media_size, "y-dimension",
1471 IPP_TAG_RANGE)) != NULL)
1472 {
1473 /*
1474 * Custom size range; save this as the custom size value with default
1475 * margins, then continue; we'll capture the real margins below...
1476 */
1477
1478 custom = val;
1479
1480 dinfo->min_size.width = x_dimension->values[0].range.lower;
1481 dinfo->min_size.length = y_dimension->values[0].range.lower;
1482 dinfo->min_size.left =
1483 dinfo->min_size.right = 635; /* Default 1/4" side margins */
1484 dinfo->min_size.top =
1485 dinfo->min_size.bottom = 1270; /* Default 1/2" top/bottom margins */
1486
1487 dinfo->max_size.width = x_dimension->values[0].range.upper;
1488 dinfo->max_size.length = y_dimension->values[0].range.upper;
1489 dinfo->max_size.left =
1490 dinfo->max_size.right = 635; /* Default 1/4" side margins */
1491 dinfo->max_size.top =
1492 dinfo->max_size.bottom = 1270; /* Default 1/2" top/bottom margins */
1493 continue;
1494 }
1495 }
1496
1497 if ((media_attr = ippFindAttribute(val->collection, "media-color",
1498 IPP_TAG_ZERO)) != NULL &&
1499 (media_attr->value_tag == IPP_TAG_NAME ||
1500 media_attr->value_tag == IPP_TAG_NAMELANG ||
1501 media_attr->value_tag == IPP_TAG_KEYWORD))
1502 mdb.color = media_attr->values[0].string.text;
1503
1504 if ((media_attr = ippFindAttribute(val->collection, "media-info",
1505 IPP_TAG_TEXT)) != NULL)
1506 mdb.info = media_attr->values[0].string.text;
1507
1508 if ((media_attr = ippFindAttribute(val->collection, "media-key",
1509 IPP_TAG_ZERO)) != NULL &&
1510 (media_attr->value_tag == IPP_TAG_NAME ||
1511 media_attr->value_tag == IPP_TAG_NAMELANG ||
1512 media_attr->value_tag == IPP_TAG_KEYWORD))
1513 mdb.key = media_attr->values[0].string.text;
1514
1515 if ((media_attr = ippFindAttribute(val->collection, "media-size-name",
1516 IPP_TAG_ZERO)) != NULL &&
1517 (media_attr->value_tag == IPP_TAG_NAME ||
1518 media_attr->value_tag == IPP_TAG_NAMELANG ||
1519 media_attr->value_tag == IPP_TAG_KEYWORD))
1520 mdb.size_name = media_attr->values[0].string.text;
1521
1522 if ((media_attr = ippFindAttribute(val->collection, "media-source",
1523 IPP_TAG_ZERO)) != NULL &&
1524 (media_attr->value_tag == IPP_TAG_NAME ||
1525 media_attr->value_tag == IPP_TAG_NAMELANG ||
1526 media_attr->value_tag == IPP_TAG_KEYWORD))
1527 mdb.source = media_attr->values[0].string.text;
1528
1529 if ((media_attr = ippFindAttribute(val->collection, "media-type",
1530 IPP_TAG_ZERO)) != NULL &&
1531 (media_attr->value_tag == IPP_TAG_NAME ||
1532 media_attr->value_tag == IPP_TAG_NAMELANG ||
1533 media_attr->value_tag == IPP_TAG_KEYWORD))
1534 mdb.type = media_attr->values[0].string.text;
1535
1536 if ((media_attr = ippFindAttribute(val->collection, "media-bottom-margin",
1537 IPP_TAG_INTEGER)) != NULL)
1538 mdb.bottom = media_attr->values[0].integer;
1539
1540 if ((media_attr = ippFindAttribute(val->collection, "media-left-margin",
1541 IPP_TAG_INTEGER)) != NULL)
1542 mdb.left = media_attr->values[0].integer;
1543
1544 if ((media_attr = ippFindAttribute(val->collection, "media-right-margin",
1545 IPP_TAG_INTEGER)) != NULL)
1546 mdb.right = media_attr->values[0].integer;
1547
1548 if ((media_attr = ippFindAttribute(val->collection, "media-top-margin",
1549 IPP_TAG_INTEGER)) != NULL)
1550 mdb.top = media_attr->values[0].integer;
1551
1552 cupsArrayAdd(db, &mdb);
1553 }
1554
1555 if (custom)
1556 {
1557 if ((media_attr = ippFindAttribute(custom->collection,
1558 "media-bottom-margin",
1559 IPP_TAG_INTEGER)) != NULL)
1560 {
1561 dinfo->min_size.top =
1562 dinfo->max_size.top = media_attr->values[0].integer;
1563 }
1564
1565 if ((media_attr = ippFindAttribute(custom->collection,
1566 "media-left-margin",
1567 IPP_TAG_INTEGER)) != NULL)
1568 {
1569 dinfo->min_size.left =
1570 dinfo->max_size.left = media_attr->values[0].integer;
1571 }
1572
1573 if ((media_attr = ippFindAttribute(custom->collection,
1574 "media-right-margin",
1575 IPP_TAG_INTEGER)) != NULL)
1576 {
1577 dinfo->min_size.right =
1578 dinfo->max_size.right = media_attr->values[0].integer;
1579 }
1580
1581 if ((media_attr = ippFindAttribute(custom->collection,
1582 "media-top-margin",
1583 IPP_TAG_INTEGER)) != NULL)
1584 {
1585 dinfo->min_size.top =
1586 dinfo->max_size.top = media_attr->values[0].integer;
1587 }
1588 }
1589 }
1590 else if (media_attr &&
1591 (media_attr->value_tag == IPP_TAG_NAME ||
1592 media_attr->value_tag == IPP_TAG_NAMELANG ||
1593 media_attr->value_tag == IPP_TAG_KEYWORD))
1594 {
1595 memset(&mdb, 0, sizeof(mdb));
1596
1597 mdb.left =
1598 mdb.right = 635; /* Default 1/4" side margins */
1599 mdb.top =
1600 mdb.bottom = 1270; /* Default 1/2" top/bottom margins */
1601
1602 for (i = media_attr->num_values, val = media_attr->values;
1603 i > 0;
1604 i --, val ++)
1605 {
1606 if ((pwg = pwgMediaForPWG(val->string.text)) == NULL)
1607 if ((pwg = pwgMediaForLegacy(val->string.text)) == NULL)
1608 {
1609 DEBUG_printf(("3cups_create_media_db: Ignoring unknown size '%s'.",
1610 val->string.text));
1611 continue;
1612 }
1613
1614 mdb.width = pwg->width;
1615 mdb.length = pwg->length;
1616
1617 if (flags != CUPS_MEDIA_FLAGS_READY &&
1618 !strncmp(val->string.text, "custom_min_", 11))
1619 {
1620 mdb.size_name = NULL;
1621 dinfo->min_size = mdb;
1622 }
1623 else if (flags != CUPS_MEDIA_FLAGS_READY &&
1624 !strncmp(val->string.text, "custom_max_", 11))
1625 {
1626 mdb.size_name = NULL;
1627 dinfo->max_size = mdb;
1628 }
1629 else
1630 {
1631 mdb.size_name = val->string.text;
1632
1633 cupsArrayAdd(db, &mdb);
1634 }
1635 }
1636 }
1637 }
1638
1639
1640 /*
1641 * 'cups_free_media_cb()' - Free a media entry.
1642 */
1643
1644 static void
1645 cups_free_media_db(
1646 _cups_media_db_t *mdb) /* I - Media entry to free */
1647 {
1648 if (mdb->color)
1649 _cupsStrFree(mdb->color);
1650 if (mdb->key)
1651 _cupsStrFree(mdb->key);
1652 if (mdb->info)
1653 _cupsStrFree(mdb->info);
1654 if (mdb->size_name)
1655 _cupsStrFree(mdb->size_name);
1656 if (mdb->source)
1657 _cupsStrFree(mdb->source);
1658 if (mdb->type)
1659 _cupsStrFree(mdb->type);
1660
1661 free(mdb);
1662 }
1663
1664
1665 /*
1666 * 'cups_get_media_db()' - Lookup the media entry for a given size.
1667 */
1668
1669 static int /* O - 1 on match, 0 on failure */
1670 cups_get_media_db(http_t *http, /* I - Connection to destination */
1671 cups_dinfo_t *dinfo, /* I - Destination information */
1672 pwg_media_t *pwg, /* I - PWG media info */
1673 unsigned flags, /* I - Media matching flags */
1674 cups_size_t *size) /* O - Media size/margin/name info */
1675 {
1676 cups_array_t *db; /* Which media database to query */
1677 _cups_media_db_t *mdb, /* Current media database entry */
1678 *best = NULL, /* Best matching entry */
1679 key; /* Search key */
1680
1681
1682 /*
1683 * Create the media database as needed...
1684 */
1685
1686 if (flags & CUPS_MEDIA_FLAGS_READY)
1687 {
1688 cups_update_ready(http, dinfo);
1689 db = dinfo->ready_db;
1690 }
1691 else
1692 {
1693 if (!dinfo->media_db)
1694 cups_create_media_db(dinfo, CUPS_MEDIA_FLAGS_DEFAULT);
1695
1696 db = dinfo->media_db;
1697 }
1698
1699 /*
1700 * Find a match...
1701 */
1702
1703 memset(&key, 0, sizeof(key));
1704 key.width = pwg->width;
1705 key.length = pwg->length;
1706
1707 if ((mdb = cupsArrayFind(db, &key)) != NULL)
1708 {
1709 /*
1710 * Found an exact match, let's figure out the best margins for the flags
1711 * supplied...
1712 */
1713
1714 best = mdb;
1715
1716 if (flags & CUPS_MEDIA_FLAGS_BORDERLESS)
1717 {
1718 /*
1719 * Look for the smallest margins...
1720 */
1721
1722 if (best->left != 0 || best->right != 0 || best->top != 0 ||
1723 best->bottom != 0)
1724 {
1725 for (mdb = (_cups_media_db_t *)cupsArrayNext(db);
1726 mdb && !cups_compare_media_db(mdb, &key);
1727 mdb = (_cups_media_db_t *)cupsArrayNext(db))
1728 {
1729 if (mdb->left <= best->left && mdb->right <= best->right &&
1730 mdb->top <= best->top && mdb->bottom <= best->bottom)
1731 {
1732 best = mdb;
1733 if (mdb->left == 0 && mdb->right == 0 && mdb->bottom == 0 &&
1734 mdb->top == 0)
1735 break;
1736 }
1737 }
1738 }
1739
1740 /*
1741 * If we need an exact match, return no-match if the size is not
1742 * borderless.
1743 */
1744
1745 if ((flags & CUPS_MEDIA_FLAGS_EXACT) &&
1746 (best->left || best->right || best->top || best->bottom))
1747 return (0);
1748 }
1749 else if (flags & CUPS_MEDIA_FLAGS_DUPLEX)
1750 {
1751 /*
1752 * Look for the largest margins...
1753 */
1754
1755 for (mdb = (_cups_media_db_t *)cupsArrayNext(db);
1756 mdb && !cups_compare_media_db(mdb, &key);
1757 mdb = (_cups_media_db_t *)cupsArrayNext(db))
1758 {
1759 if (mdb->left >= best->left && mdb->right >= best->right &&
1760 mdb->top >= best->top && mdb->bottom >= best->bottom)
1761 best = mdb;
1762 }
1763 }
1764 else
1765 {
1766 /*
1767 * Look for the smallest non-zero margins...
1768 */
1769
1770 for (mdb = (_cups_media_db_t *)cupsArrayNext(db);
1771 mdb && !cups_compare_media_db(mdb, &key);
1772 mdb = (_cups_media_db_t *)cupsArrayNext(db))
1773 {
1774 if (((mdb->left > 0 && mdb->left <= best->left) || best->left == 0) &&
1775 ((mdb->right > 0 && mdb->right <= best->right) ||
1776 best->right == 0) &&
1777 ((mdb->top > 0 && mdb->top <= best->top) || best->top == 0) &&
1778 ((mdb->bottom > 0 && mdb->bottom <= best->bottom) ||
1779 best->bottom == 0))
1780 best = mdb;
1781 }
1782 }
1783 }
1784 else if (flags & CUPS_MEDIA_FLAGS_EXACT)
1785 {
1786 /*
1787 * See if we can do this as a custom size...
1788 */
1789
1790 if (pwg->width < dinfo->min_size.width ||
1791 pwg->width > dinfo->max_size.width ||
1792 pwg->length < dinfo->min_size.length ||
1793 pwg->length > dinfo->max_size.length)
1794 return (0); /* Out of range */
1795
1796 if ((flags & CUPS_MEDIA_FLAGS_BORDERLESS) &&
1797 (dinfo->min_size.left > 0 || dinfo->min_size.right > 0 ||
1798 dinfo->min_size.top > 0 || dinfo->min_size.bottom > 0))
1799 return (0); /* Not borderless */
1800
1801 key.size_name = (char *)pwg->pwg;
1802 key.bottom = dinfo->min_size.bottom;
1803 key.left = dinfo->min_size.left;
1804 key.right = dinfo->min_size.right;
1805 key.top = dinfo->min_size.top;
1806
1807 best = &key;
1808 }
1809 else if (pwg->width >= dinfo->min_size.width &&
1810 pwg->width <= dinfo->max_size.width &&
1811 pwg->length >= dinfo->min_size.length &&
1812 pwg->length <= dinfo->max_size.length)
1813 {
1814 /*
1815 * Map to custom size...
1816 */
1817
1818 key.size_name = (char *)pwg->pwg;
1819 key.bottom = dinfo->min_size.bottom;
1820 key.left = dinfo->min_size.left;
1821 key.right = dinfo->min_size.right;
1822 key.top = dinfo->min_size.top;
1823
1824 best = &key;
1825 }
1826 else
1827 {
1828 /*
1829 * Find a close size...
1830 */
1831
1832 for (mdb = (_cups_media_db_t *)cupsArrayFirst(db);
1833 mdb;
1834 mdb = (_cups_media_db_t *)cupsArrayNext(db))
1835 if (cups_is_close_media_db(mdb, &key))
1836 break;
1837
1838 if (!mdb)
1839 return (0);
1840
1841 best = mdb;
1842
1843 if (flags & CUPS_MEDIA_FLAGS_BORDERLESS)
1844 {
1845 /*
1846 * Look for the smallest margins...
1847 */
1848
1849 if (best->left != 0 || best->right != 0 || best->top != 0 ||
1850 best->bottom != 0)
1851 {
1852 for (mdb = (_cups_media_db_t *)cupsArrayNext(db);
1853 mdb && cups_is_close_media_db(mdb, &key);
1854 mdb = (_cups_media_db_t *)cupsArrayNext(db))
1855 {
1856 if (mdb->left <= best->left && mdb->right <= best->right &&
1857 mdb->top <= best->top && mdb->bottom <= best->bottom)
1858 {
1859 best = mdb;
1860 if (mdb->left == 0 && mdb->right == 0 && mdb->bottom == 0 &&
1861 mdb->top == 0)
1862 break;
1863 }
1864 }
1865 }
1866 }
1867 else if (flags & CUPS_MEDIA_FLAGS_DUPLEX)
1868 {
1869 /*
1870 * Look for the largest margins...
1871 */
1872
1873 for (mdb = (_cups_media_db_t *)cupsArrayNext(db);
1874 mdb && cups_is_close_media_db(mdb, &key);
1875 mdb = (_cups_media_db_t *)cupsArrayNext(db))
1876 {
1877 if (mdb->left >= best->left && mdb->right >= best->right &&
1878 mdb->top >= best->top && mdb->bottom >= best->bottom)
1879 best = mdb;
1880 }
1881 }
1882 else
1883 {
1884 /*
1885 * Look for the smallest non-zero margins...
1886 */
1887
1888 for (mdb = (_cups_media_db_t *)cupsArrayNext(db);
1889 mdb && cups_is_close_media_db(mdb, &key);
1890 mdb = (_cups_media_db_t *)cupsArrayNext(db))
1891 {
1892 if (((mdb->left > 0 && mdb->left <= best->left) || best->left == 0) &&
1893 ((mdb->right > 0 && mdb->right <= best->right) ||
1894 best->right == 0) &&
1895 ((mdb->top > 0 && mdb->top <= best->top) || best->top == 0) &&
1896 ((mdb->bottom > 0 && mdb->bottom <= best->bottom) ||
1897 best->bottom == 0))
1898 best = mdb;
1899 }
1900 }
1901 }
1902
1903 if (best)
1904 {
1905 /*
1906 * Return the matching size...
1907 */
1908
1909 if (best->size_name)
1910 strlcpy(size->media, best->size_name, sizeof(size->media));
1911 else if (best->key)
1912 strlcpy(size->media, best->key, sizeof(size->media));
1913 else
1914 strlcpy(size->media, pwg->pwg, sizeof(size->media));
1915
1916 size->width = best->width;
1917 size->length = best->length;
1918 size->bottom = best->bottom;
1919 size->left = best->left;
1920 size->right = best->right;
1921 size->top = best->top;
1922
1923 return (1);
1924 }
1925
1926 return (0);
1927 }
1928
1929
1930 /*
1931 * 'cups_is_close_media_db()' - Compare two media entries to see if they are
1932 * close to the same size.
1933 *
1934 * Currently we use 5 points (from PostScript) as the matching range...
1935 */
1936
1937 static int /* O - 1 if the sizes are close */
1938 cups_is_close_media_db(
1939 _cups_media_db_t *a, /* I - First media entries */
1940 _cups_media_db_t *b) /* I - Second media entries */
1941 {
1942 int dwidth, /* Difference in width */
1943 dlength; /* Difference in length */
1944
1945
1946 dwidth = a->width - b->width;
1947 dlength = a->length - b->length;
1948
1949 return (dwidth >= -176 && dwidth <= 176 &&
1950 dlength >= -176 && dlength <= 176);
1951 }
1952
1953
1954 /*
1955 * 'cups_test_constraints()' - Test constraints.
1956 *
1957 * TODO: STR #4096 - Need to properly support media-col contraints...
1958 */
1959
1960 static cups_array_t * /* O - Active constraints */
1961 cups_test_constraints(
1962 cups_dinfo_t *dinfo, /* I - Destination information */
1963 const char *new_option, /* I - Newly selected option */
1964 const char *new_value, /* I - Newly selected value */
1965 int num_options, /* I - Number of options */
1966 cups_option_t *options, /* I - Options */
1967 int *num_conflicts, /* O - Number of conflicting options */
1968 cups_option_t **conflicts) /* O - Conflicting options */
1969 {
1970 int i, /* Looping var */
1971 match; /* Value matches? */
1972 int num_matching; /* Number of matching options */
1973 cups_option_t *matching; /* Matching options */
1974 _cups_dconstres_t *c; /* Current constraint */
1975 cups_array_t *active = NULL; /* Active constraints */
1976 ipp_attribute_t *attr; /* Current attribute */
1977 _ipp_value_t *attrval; /* Current attribute value */
1978 const char *value; /* Current value */
1979 char temp[1024]; /* Temporary string */
1980 int int_value; /* Integer value */
1981 int xres_value, /* Horizontal resolution */
1982 yres_value; /* Vertical resolution */
1983 ipp_res_t units_value; /* Resolution units */
1984
1985
1986 for (c = (_cups_dconstres_t *)cupsArrayFirst(dinfo->constraints);
1987 c;
1988 c = (_cups_dconstres_t *)cupsArrayNext(dinfo->constraints))
1989 {
1990 num_matching = 0;
1991 matching = NULL;
1992
1993 for (attr = ippFirstAttribute(c->collection);
1994 attr;
1995 attr = ippNextAttribute(c->collection))
1996 {
1997 if (attr->value_tag == IPP_TAG_BEGIN_COLLECTION)
1998 break; /* TODO: STR #4096 */
1999
2000 /*
2001 * Get the value for the current attribute in the constraint...
2002 */
2003
2004 if (new_option && new_value && !strcmp(attr->name, new_option))
2005 value = new_value;
2006 else if ((value = cupsGetOption(attr->name, num_options,
2007 options)) == NULL)
2008 value = cupsGetOption(attr->name, dinfo->num_defaults, dinfo->defaults);
2009
2010 if (!value)
2011 {
2012 /*
2013 * Not set so this constraint does not apply...
2014 */
2015
2016 break;
2017 }
2018
2019 match = 0;
2020
2021 switch (attr->value_tag)
2022 {
2023 case IPP_TAG_INTEGER :
2024 case IPP_TAG_ENUM :
2025 int_value = atoi(value);
2026
2027 for (i = attr->num_values, attrval = attr->values;
2028 i > 0;
2029 i --, attrval ++)
2030 {
2031 if (attrval->integer == int_value)
2032 {
2033 match = 1;
2034 break;
2035 }
2036 }
2037 break;
2038
2039 case IPP_TAG_BOOLEAN :
2040 int_value = !strcmp(value, "true");
2041
2042 for (i = attr->num_values, attrval = attr->values;
2043 i > 0;
2044 i --, attrval ++)
2045 {
2046 if (attrval->boolean == int_value)
2047 {
2048 match = 1;
2049 break;
2050 }
2051 }
2052 break;
2053
2054 case IPP_TAG_RANGE :
2055 int_value = atoi(value);
2056
2057 for (i = attr->num_values, attrval = attr->values;
2058 i > 0;
2059 i --, attrval ++)
2060 {
2061 if (int_value >= attrval->range.lower &&
2062 int_value <= attrval->range.upper)
2063 {
2064 match = 1;
2065 break;
2066 }
2067 }
2068 break;
2069
2070 case IPP_TAG_RESOLUTION :
2071 if (sscanf(value, "%dx%d%15s", &xres_value, &yres_value, temp) != 3)
2072 {
2073 if (sscanf(value, "%d%15s", &xres_value, temp) != 2)
2074 break;
2075
2076 yres_value = xres_value;
2077 }
2078
2079 if (!strcmp(temp, "dpi"))
2080 units_value = IPP_RES_PER_INCH;
2081 else if (!strcmp(temp, "dpc") || !strcmp(temp, "dpcm"))
2082 units_value = IPP_RES_PER_CM;
2083 else
2084 break;
2085
2086 for (i = attr->num_values, attrval = attr->values;
2087 i > 0;
2088 i --, attrval ++)
2089 {
2090 if (attrval->resolution.xres == xres_value &&
2091 attrval->resolution.yres == yres_value &&
2092 attrval->resolution.units == units_value)
2093 {
2094 match = 1;
2095 break;
2096 }
2097 }
2098 break;
2099
2100 case IPP_TAG_TEXT :
2101 case IPP_TAG_NAME :
2102 case IPP_TAG_KEYWORD :
2103 case IPP_TAG_CHARSET :
2104 case IPP_TAG_URI :
2105 case IPP_TAG_URISCHEME :
2106 case IPP_TAG_MIMETYPE :
2107 case IPP_TAG_LANGUAGE :
2108 case IPP_TAG_TEXTLANG :
2109 case IPP_TAG_NAMELANG :
2110 for (i = attr->num_values, attrval = attr->values;
2111 i > 0;
2112 i --, attrval ++)
2113 {
2114 if (!strcmp(attrval->string.text, value))
2115 {
2116 match = 1;
2117 break;
2118 }
2119 }
2120 break;
2121
2122 default :
2123 break;
2124 }
2125
2126 if (!match)
2127 break;
2128
2129 num_matching = cupsAddOption(attr->name, value, num_matching, &matching);
2130 }
2131
2132 if (!attr)
2133 {
2134 if (!active)
2135 active = cupsArrayNew(NULL, NULL);
2136
2137 cupsArrayAdd(active, c);
2138
2139 if (num_conflicts && conflicts)
2140 {
2141 cups_option_t *moption; /* Matching option */
2142
2143 for (i = num_matching, moption = matching; i > 0; i --, moption ++)
2144 *num_conflicts = cupsAddOption(moption->name, moption->value,
2145 *num_conflicts, conflicts);
2146 }
2147 }
2148
2149 cupsFreeOptions(num_matching, matching);
2150 }
2151
2152 return (active);
2153 }
2154
2155
2156 /*
2157 * 'cups_update_ready()' - Update xxx-ready attributes for the printer.
2158 */
2159
2160 static void
2161 cups_update_ready(http_t *http, /* I - Connection to destination */
2162 cups_dinfo_t *dinfo) /* I - Destination information */
2163 {
2164 ipp_t *request; /* Get-Printer-Attributes request */
2165 static const char * const pattrs[] = /* Printer attributes we want */
2166 {
2167 "finishings-col-ready",
2168 "finishings-ready",
2169 "job-finishings-col-ready",
2170 "job-finishings-ready",
2171 "media-col-ready",
2172 "media-ready"
2173 };
2174
2175
2176 /*
2177 * Don't update more than once every 30 seconds...
2178 */
2179
2180 if ((time(NULL) - dinfo->ready_time) < _CUPS_MEDIA_READY_TTL)
2181 return;
2182
2183 /*
2184 * Free any previous results...
2185 */
2186
2187 if (dinfo->cached_flags & CUPS_MEDIA_FLAGS_READY)
2188 {
2189 cupsArrayDelete(dinfo->cached_db);
2190 dinfo->cached_db = NULL;
2191 dinfo->cached_flags = CUPS_MEDIA_FLAGS_DEFAULT;
2192 }
2193
2194 ippDelete(dinfo->ready_attrs);
2195 dinfo->ready_attrs = NULL;
2196
2197 cupsArrayDelete(dinfo->ready_db);
2198 dinfo->ready_db = NULL;
2199
2200 /*
2201 * Query the xxx-ready values...
2202 */
2203
2204 request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
2205 ippSetVersion(request, dinfo->version / 10, dinfo->version % 10);
2206
2207 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
2208 dinfo->uri);
2209 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
2210 NULL, cupsUser());
2211 ippAddStrings(request, IPP_TAG_OPERATION, IPP_CONST_TAG(IPP_TAG_KEYWORD), "requested-attributes", (int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
2212
2213 dinfo->ready_attrs = cupsDoRequest(http, request, dinfo->resource);
2214
2215 /*
2216 * Update the ready media database...
2217 */
2218
2219 cups_create_media_db(dinfo, CUPS_MEDIA_FLAGS_READY);
2220
2221 /*
2222 * Update last lookup time and return...
2223 */
2224
2225 dinfo->ready_time = time(NULL);
2226 }
2227
2228
2229 /*
2230 * End of "$Id$".
2231 */