/*
- * "$Id$"
+ * Destination option/media support for CUPS.
*
- * Destination option/media support for CUPS.
+ * Copyright 2012-2016 by Apple Inc.
*
- * Copyright 2012-2013 by Apple Inc.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * missing or damaged, see the license at "http://www.cups.org/".
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * cupsCheckDestSupported() - Check that the option and value are supported
- * by the destination.
- * cupsCopyDestConflicts() - Get conflicts and resolutions for a new
- * option/value pair.
- * cupsCopyDestInfo() - Get the supported values/capabilities for the
- * destination.
- * cupsFindDestDefault() - Find the default value(s) for the given
- * option.
- * cupsFindDestReady() - Find the default value(s) for the given
- * option.
- * cupsFindDestSupported() - Find the default value(s) for the given
- * option.
- * cupsFreeDestInfo() - Free destination information obtained using
- * @link cupsCopyDestInfo@.
- * cupsGetDestMediaByIndex() - Get a media name, dimension, and margins for a
- * specific size.
- * cupsGetDestMediaByName() - Get media names, dimensions, and margins.
- * cupsGetDestMediaBySize() - Get media names, dimensions, and margins.
- * cupsGetDestMediaCount() - Get the number of sizes supported by a
- * destination.
- * cupsGetDestMediaDefault() - Get the default size for a destination.
- * cups_add_dconstres() - Add a constraint or resolver to an array.
- * cups_compare_dconstres() - Compare to resolver entries.
- * cups_compare_media_db() - Compare two media entries.
- * cups_copy_media_db() - Copy a media entry.
- * cups_create_cached() - Create the media selection cache.
- * cups_create_constraints() - Create the constraints and resolvers arrays.
- * cups_create_defaults() - Create the -default option array.
- * cups_create_media_db() - Create the media database.
- * cups_free_media_cb() - Free a media entry.
- * cups_get_media_db() - Lookup the media entry for a given size.
- * cups_is_close_media_db() - Compare two media entries to see if they are
- * close to the same size.
- * cups_test_constraints() - Test constraints.
- * cups_update_ready() - Update xxx-ready attributes for the printer.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
*
* Returns 1 if supported, 0 otherwise.
*
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
*/
int /* O - 1 if supported, 0 otherwise */
* If cupsCopyDestConflicts returns 1 but "num_resolved" and "resolved" are set
* to 0 and @code NULL@, respectively, then the conflict cannot be resolved.
*
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
*/
int /* O - 1 if there is a conflict, 0 if none, -1 on error */
*myres = NULL, /* My resolved options */
*myoption, /* My current option */
*option; /* Current option */
- cups_array_t *active, /* Active conflicts */
+ cups_array_t *active = NULL, /* Active conflicts */
*pass = NULL, /* Resolvers for this pass */
*resolvers = NULL, /* Resolvers we have used */
*test; /* Test array for conflicts */
* The caller is responsible for calling @link cupsFreeDestInfo@ on the return
* value. @code NULL@ is returned on error.
*
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
*/
cups_dinfo_t * /* O - Destination information */
};
- DEBUG_printf(("cupsCopyDestSupported(http=%p, dest=%p(%s))", http, dest,
- dest ? dest->name : ""));
+ DEBUG_printf(("cupsCopyDestSupported(http=%p, dest=%p(%s))", (void *)http, (void *)dest, dest ? dest->name : ""));
/*
* Range check input...
version = 11;
else if (status == IPP_STATUS_ERROR_BUSY)
{
- sleep(delay);
+ sleep((unsigned)delay);
delay = _cupsNextDelay(delay, &prev_delay);
}
* @code ippGetResolution@, @code ippGetString@, and @code ippGetValueTag@
* functions to inspect the default value(s) as needed.
*
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
*/
ipp_attribute_t * /* O - Default attribute or @code NULL@ for none */
return (ippFindAttribute(dinfo->attrs, name, IPP_TAG_ZERO));
}
+
/*
* 'cupsFindDestReady()' - Find the default value(s) for the given option.
*
* @code ippGetResolution@, @code ippGetString@, and @code ippGetValueTag@
* functions to inspect the default value(s) as needed.
*
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
*/
ipp_attribute_t * /* O - Default attribute or @code NULL@ for none */
return (ippFindAttribute(dinfo->ready_attrs, name, IPP_TAG_ZERO));
}
+
/*
* 'cupsFindDestSupported()' - Find the default value(s) for the given option.
*
* @code ippGetResolution@, @code ippGetString@, and @code ippGetValueTag@
* functions to inspect the default value(s) as needed.
*
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
*/
ipp_attribute_t * /* O - Default attribute or @code NULL@ for none */
* example, passing @code CUPS_MEDIA_FLAGS_BORDERLESS@ will get the Nth
* borderless size supported by the printer.
*
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
*/
int /* O - 1 on success, 0 on failure */
unsigned flags, /* I - Media flags */
cups_size_t *size) /* O - Media size information */
{
- cups_size_t *nsize; /* Size for N */
+ _cups_media_db_t *nsize; /* Size for N */
+ pwg_media_t *pwg; /* PWG media name for size */
/*
* Copy the size over and return...
*/
- if ((nsize = (cups_size_t *)cupsArrayIndex(dinfo->cached_db, n)) == NULL)
+ if ((nsize = (_cups_media_db_t *)cupsArrayIndex(dinfo->cached_db, n)) == NULL)
+ {
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
+ return (0);
+ }
+
+ if (nsize->size_name)
+ strlcpy(size->media, nsize->size_name, sizeof(size->media));
+ else if (nsize->key)
+ strlcpy(size->media, nsize->key, sizeof(size->media));
+ else if ((pwg = pwgMediaForSize(nsize->width, nsize->length)) != NULL)
+ strlcpy(size->media, pwg->pwg, sizeof(size->media));
+ else
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
return (0);
}
- memcpy(size, nsize, sizeof(cups_size_t));
+ size->width = nsize->width;
+ size->length = nsize->length;
+ size->bottom = nsize->bottom;
+ size->left = nsize->left;
+ size->right = nsize->right;
+ size->top = nsize->top;
return (1);
}
*
* Returns 1 when there is a match and 0 if there is not a match.
*
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
*/
int /* O - 1 on match, 0 on failure */
*
* Returns 1 when there is a match and 0 if there is not a match.
*
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
*/
int /* O - 1 on match, 0 on failure */
* counted. For example, passing @code CUPS_MEDIA_FLAGS_BORDERLESS@ will return
* the number of borderless sizes.
*
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
*/
int /* O - Number of sizes */
* example, passing @code CUPS_MEDIA_FLAGS_BORDERLESS@ will return the default
* borderless size, typically US Letter or A4, but sometimes 4x6 photo media.
*
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
*/
int /* O - 1 on success, 0 on failure */
* Fall back to the first matching media size...
*/
- return (cupsGetDestMediaByIndex(http, dest, dinfo, flags, 0, size));
+ return (cupsGetDestMediaByIndex(http, dest, dinfo, 0, flags, size));
}
*first; /* First entry this size */
+ DEBUG_printf(("3cups_create_cached(http=%p, dinfo=%p, flags=%u)", (void *)http, (void *)dinfo, flags));
+
if (dinfo->cached_db)
cupsArrayDelete(dinfo->cached_db);
if (flags & CUPS_MEDIA_FLAGS_READY)
{
+ DEBUG_puts("4cups_create_cached: ready media");
+
cups_update_ready(http, dinfo);
db = dinfo->ready_db;
}
else
{
+ DEBUG_puts("4cups_create_cached: supported media");
+
if (!dinfo->media_db)
cups_create_media_db(dinfo, CUPS_MEDIA_FLAGS_DEFAULT);
mdb;
mdb = (_cups_media_db_t *)cupsArrayNext(db))
{
+ DEBUG_printf(("4cups_create_cached: %p key=\"%s\", type=\"%s\", %dx%d, B%d L%d R%d T%d", (void *)mdb, mdb->key, mdb->type, mdb->width, mdb->length, mdb->bottom, mdb->left, mdb->right, mdb->top));
+
if (flags & CUPS_MEDIA_FLAGS_BORDERLESS)
{
if (!mdb->left && !mdb->right && !mdb->top && !mdb->bottom)
+ {
+ DEBUG_printf(("4cups_create_cached: add %p", (void *)mdb));
cupsArrayAdd(dinfo->cached_db, mdb);
+ }
}
else if (flags & CUPS_MEDIA_FLAGS_DUPLEX)
{
if (first->width != mdb->width || first->length != mdb->length)
{
+ DEBUG_printf(("4cups_create_cached: add %p", (void *)first));
cupsArrayAdd(dinfo->cached_db, first);
first = mdb;
}
- else if (mdb->left >= first->left && mdb->right >= first->right &&
- mdb->top >= first->top && mdb->bottom >= first->bottom)
+ else if (mdb->left >= first->left && mdb->right >= first->right && mdb->top >= first->top && mdb->bottom >= first->bottom &&
+ (mdb->left != first->left || mdb->right != first->right || mdb->top != first->top || mdb->bottom != first->bottom))
first = mdb;
}
+ else
+ {
+ DEBUG_printf(("4cups_create_cached: add %p", (void *)mdb));
+ cupsArrayAdd(dinfo->cached_db, mdb);
+ }
}
if (flags & CUPS_MEDIA_FLAGS_DUPLEX)
+ {
+ DEBUG_printf(("4cups_create_cached: add %p", (void *)first));
cupsArrayAdd(dinfo->cached_db, first);
+ }
}
* Look for the smallest margins...
*/
- if (best->left != 0 || best->right != 0 || best->top != 0 ||
- best->bottom != 0)
+ if (best->left != 0 || best->right != 0 || best->top != 0 || best->bottom != 0)
{
for (mdb = (_cups_media_db_t *)cupsArrayNext(db);
mdb && !cups_compare_media_db(mdb, &key);
mdb = (_cups_media_db_t *)cupsArrayNext(db))
{
if (mdb->left >= best->left && mdb->right >= best->right &&
- mdb->top >= best->top && mdb->bottom >= best->bottom)
+ mdb->top >= best->top && mdb->bottom >= best->bottom &&
+ (mdb->bottom != best->bottom || mdb->left != best->left || mdb->right != best->right || mdb->top != best->top))
best = mdb;
}
}
mdb = (_cups_media_db_t *)cupsArrayNext(db))
{
if (((mdb->left > 0 && mdb->left <= best->left) || best->left == 0) &&
- ((mdb->right > 0 && mdb->right <= best->right) ||
- best->right == 0) &&
+ ((mdb->right > 0 && mdb->right <= best->right) || best->right == 0) &&
((mdb->top > 0 && mdb->top <= best->top) || best->top == 0) &&
- ((mdb->bottom > 0 && mdb->bottom <= best->bottom) ||
- best->bottom == 0))
+ ((mdb->bottom > 0 && mdb->bottom <= best->bottom) || best->bottom == 0) &&
+ (mdb->bottom != best->bottom || mdb->left != best->left || mdb->right != best->right || mdb->top != best->top))
best = mdb;
}
}
mdb = (_cups_media_db_t *)cupsArrayNext(db))
{
if (mdb->left <= best->left && mdb->right <= best->right &&
- mdb->top <= best->top && mdb->bottom <= best->bottom)
+ mdb->top <= best->top && mdb->bottom <= best->bottom &&
+ (mdb->bottom != best->bottom || mdb->left != best->left || mdb->right != best->right || mdb->top != best->top))
{
best = mdb;
if (mdb->left == 0 && mdb->right == 0 && mdb->bottom == 0 &&
mdb = (_cups_media_db_t *)cupsArrayNext(db))
{
if (mdb->left >= best->left && mdb->right >= best->right &&
- mdb->top >= best->top && mdb->bottom >= best->bottom)
+ mdb->top >= best->top && mdb->bottom >= best->bottom &&
+ (mdb->bottom != best->bottom || mdb->left != best->left || mdb->right != best->right || mdb->top != best->top))
best = mdb;
}
}
best->right == 0) &&
((mdb->top > 0 && mdb->top <= best->top) || best->top == 0) &&
((mdb->bottom > 0 && mdb->bottom <= best->bottom) ||
- best->bottom == 0))
+ best->bottom == 0) &&
+ (mdb->bottom != best->bottom || mdb->left != best->left || mdb->right != best->right || mdb->top != best->top))
best = mdb;
}
}
dinfo->uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, cupsUser());
- ippAddStrings(request, IPP_TAG_OPERATION,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST, "requested-attributes",
- (int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
+ ippAddStrings(request, IPP_TAG_OPERATION, IPP_CONST_TAG(IPP_TAG_KEYWORD), "requested-attributes", (int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
dinfo->ready_attrs = cupsDoRequest(http, request, dinfo->resource);
dinfo->ready_time = time(NULL);
}
-
-
-/*
- * End of "$Id$".
- */