Skip to content

Commit

Permalink
Use cupsGetNamedDest for legacy printing APIs (Issue #5288)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Apr 9, 2018
1 parent d07cb8d commit 7271db1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 50 deletions.
59 changes: 10 additions & 49 deletions cups/util.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
* Printing utilities for CUPS.
*
* Copyright 2007-2017 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
* Copyright © 2007-2018 by Apple Inc.
* Copyright © 1997-2006 by Easy Software Products.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more information.
* Licensed under Apache License v2.0. See the file "LICENSE" for more
* information.
*/

/*
Expand All @@ -21,19 +22,6 @@
#endif /* WIN32 || __EMX__ */


/*
* Enumeration data and callback...
*/

typedef struct _cups_createdata_s
{
const char *name; /* Destination name */
cups_dest_t *dest; /* Matching destination */
} _cups_createdata_t;

static int cups_create_cb(_cups_createdata_t *data, unsigned flags, cups_dest_t *dest);


/*
* 'cupsCancelJob()' - Cancel a print job on the default server.
*
Expand Down Expand Up @@ -168,7 +156,7 @@ cupsCreateJob(
{
int job_id = 0; /* job-id value */
ipp_status_t status; /* Create-Job status */
_cups_createdata_t data; /* Enumeration data */
cups_dest_t *dest; /* Destination */
cups_dinfo_t *info; /* Destination information */


Expand All @@ -188,12 +176,7 @@ cupsCreateJob(
* Lookup the destination...
*/

data.name = name;
data.dest = NULL;

cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_create_cb, &data);

if (!data.dest)
if ((dest = cupsGetNamedDest(http, name, NULL)) == NULL)
{
DEBUG_puts("1cupsCreateJob: Destination not found.");
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOENT), 0);
Expand All @@ -205,18 +188,18 @@ cupsCreateJob(
*/

DEBUG_puts("1cupsCreateJob: Querying destination info.");
if ((info = cupsCopyDestInfo(http, data.dest)) == NULL)
if ((info = cupsCopyDestInfo(http, dest)) == NULL)
{
DEBUG_puts("1cupsCreateJob: Query failed.");
cupsFreeDests(1, data.dest);
cupsFreeDests(1, dest);
return (0);
}

status = cupsCreateDestJob(http, data.dest, info, &job_id, title, num_options, options);
status = cupsCreateDestJob(http, dest, info, &job_id, title, num_options, options);
DEBUG_printf(("1cupsCreateJob: cupsCreateDestJob returned %04x (%s)", status, ippErrorString(status)));

cupsFreeDestInfo(info);
cupsFreeDests(1, data.dest);
cupsFreeDests(1, dest);

/*
* Return the job...
Expand Down Expand Up @@ -968,25 +951,3 @@ cupsStartDocument(
return (status);
}


/*
* 'cups_create_cb()' - Find the destination for printing.
*/

static int /* O - 0 on match */
cups_create_cb(
_cups_createdata_t *data, /* I - Data from cupsCreateJob call */
unsigned flags, /* I - Enumeration flags */
cups_dest_t *dest) /* I - Destination */
{
DEBUG_printf(("2cups_create_cb(data=%p(%s), flags=%08x, dest=%p(%s))", (void *)data, data->name, flags, (void *)dest, dest->name));

(void)flags;

if (dest->instance || strcasecmp(data->name, dest->name))
return (1);

cupsCopyDest(dest, 0, &data->dest);

return (0);
}
6 changes: 5 additions & 1 deletion xcode/CUPS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7299,7 +7299,7 @@
72BF96371333042100B1EAD7 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = "Apple Inc.";
TargetAttributes = {
270695FD1CADF3E200FFE5FB = {
Expand Down Expand Up @@ -11368,10 +11368,12 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
Expand Down Expand Up @@ -11415,10 +11417,12 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
Expand Down

0 comments on commit 7271db1

Please sign in to comment.