From: msweet Date: Mon, 8 Jul 2013 11:20:33 +0000 (+0000) Subject: cups.org: cupsGetNamedDest returns the wrong default printe... X-Git-Tag: release-1.7rc1~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c606bcae4e922757fea8e87faf5e3cbbee06a4d4;p=thirdparty%2Fcups.git cups.org: cupsGetNamedDest returns the wrong default printer, lpr/lpq/lp/lpstat use different defaults! git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11101 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/CHANGES-1.6.txt b/CHANGES-1.6.txt index 80775a7977..e564c9d930 100644 --- a/CHANGES-1.6.txt +++ b/CHANGES-1.6.txt @@ -5,12 +5,14 @@ CHANGES IN CUPS V1.6.3 - The configure script now prefers Clang over GCC. - Fixed a compile problem on AIX (STR #4307) - - httpStatus(HTTP_ERROR) did not return a useful error message - () + - The lp, lpq, lpr, and lpstat now display an error message advising the + use of the /version=1.1 ServerName option () - Added documentation about the /version=1.1 option to ServerName in client.conf () - - The lp and lpr commands incorrectly ignored the default printer set - in the lpoptions file () + - httpStatus(HTTP_ERROR) did not return a useful error message + () + - The lp, lpq, lpr, and lpstat commands incorrectly ignored the default + printer set in the lpoptions file () - Fixed a URI encoding issue for hostnames containing the ` (backquote) character () - Added support for RFC 6874's IPv6 link local address format in URIs diff --git a/berkeley/lpq.c b/berkeley/lpq.c index dcce2c0ed9..7e8d8baaa0 100644 --- a/berkeley/lpq.c +++ b/berkeley/lpq.c @@ -3,7 +3,7 @@ * * "lpq" command for CUPS. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -60,8 +60,7 @@ main(int argc, /* I - Number of command-line arguments */ all, /* All printers */ interval, /* Reporting interval */ longstatus; /* Show file details */ - int num_dests; /* Number of destinations */ - cups_dest_t *dests; /* Destinations */ + cups_dest_t *named_dest; /* Named destination */ _cupsSetLocale(argv); @@ -77,8 +76,6 @@ main(int argc, /* I - Number of command-line arguments */ interval = 0; longstatus = 0; all = 0; - num_dests = 0; - dests = NULL; for (i = 1; i < argc; i ++) if (argv[i][0] == '+') @@ -127,7 +124,6 @@ main(int argc, /* I - Number of command-line arguments */ if (i >= argc) { httpClose(http); - cupsFreeDests(num_dests, dests); usage(); } @@ -140,12 +136,14 @@ main(int argc, /* I - Number of command-line arguments */ http = connect_server(argv[0], http); - if (num_dests == 0) - num_dests = cupsGetDests2(http, &dests); - - if (cupsGetDest(dest, instance, num_dests, dests) == NULL) + if ((named_dest = cupsGetNamedDest(http, dest, instance)) == NULL) { - if (instance) + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + else if (instance) _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s/%s\"."), argv[0], dest, instance); @@ -155,6 +153,8 @@ main(int argc, /* I - Number of command-line arguments */ return (1); } + + cupsFreeDests(1, named_dest); break; case 'a' : /* All printers */ @@ -192,7 +192,6 @@ main(int argc, /* I - Number of command-line arguments */ default : httpClose(http); - cupsFreeDests(num_dests, dests); usage(); break; @@ -207,15 +206,17 @@ main(int argc, /* I - Number of command-line arguments */ if (dest == NULL && !all) { - if (num_dests == 0) - num_dests = cupsGetDests2(http, &dests); - - for (i = 0; i < num_dests; i ++) - if (dests[i].is_default) - dest = dests[i].name; - - if (dest == NULL) + if ((named_dest = cupsGetNamedDest(http, NULL, NULL)) == NULL) { + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server name."), + argv[0]); + return (1); + } + val = NULL; if ((dest = getenv("LPDEST")) == NULL) @@ -231,7 +232,7 @@ main(int argc, /* I - Number of command-line arguments */ else val = "LPDEST"; - if (dest && !cupsGetDest(dest, NULL, num_dests, dests)) + if (dest && val) _cupsLangPrintf(stderr, _("%s: Error - %s environment variable names " "non-existent destination \"%s\"."), argv[0], val, @@ -241,9 +242,10 @@ main(int argc, /* I - Number of command-line arguments */ _("%s: Error - no default destination available."), argv[0]); httpClose(http); - cupsFreeDests(num_dests, dests); return (1); } + + dest = named_dest->name; } /* @@ -270,7 +272,6 @@ main(int argc, /* I - Number of command-line arguments */ * Close the connection to the server and return... */ - cupsFreeDests(num_dests, dests); httpClose(http); return (0); diff --git a/berkeley/lpr.c b/berkeley/lpr.c index 6e36beed7f..4b8957ffe1 100644 --- a/berkeley/lpr.c +++ b/berkeley/lpr.c @@ -3,7 +3,7 @@ * * "lpr" command for CUPS. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2007 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -61,6 +61,7 @@ main(int argc, /* I - Number of command-line arguments */ for (i = 1; i < argc; i ++) if (argv[i][0] == '-') + { switch (ch = argv[i][1]) { case 'E' : /* Encrypt */ @@ -226,6 +227,14 @@ main(int argc, /* I - Number of command-line arguments */ dest->options[j].value, num_options, &options); } + else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } break; case '#' : /* Number of copies */ @@ -275,6 +284,7 @@ main(int argc, /* I - Number of command-line arguments */ argv[i][1]); return (1); } + } else if (num_files < 1000) { /* @@ -320,6 +330,14 @@ main(int argc, /* I - Number of command-line arguments */ dest->options[j].value, num_options, &options); } + else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } } if (printer == NULL) diff --git a/cups/dest.c b/cups/dest.c index 2579d16a3a..36481f8082 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -1907,18 +1907,7 @@ cupsGetNamedDest(http_t *http, /* I - Connection to server or @code CUPS_HTT */ if (!_cupsGetDests(http, op, name, &dest, 0, 0)) - { - if (op == IPP_OP_CUPS_GET_DEFAULT || (name && !set_as_default)) - return (NULL); - - /* - * The default printer from environment variables or from a - * configuration file does not exist. Find out the real default. - */ - - if (!_cupsGetDests(http, IPP_OP_CUPS_GET_DEFAULT, NULL, &dest, 0, 0)) - return (NULL); - } + return (NULL); if (instance) dest->instance = _cupsStrAlloc(instance); diff --git a/systemv/lp.c b/systemv/lp.c index 96728b26ea..8f95966b4f 100644 --- a/systemv/lp.c +++ b/systemv/lp.c @@ -146,7 +146,8 @@ main(int argc, /* I - Number of command-line arguments */ if ((instance = strrchr(printer, '/')) != NULL) *instance++ = '\0'; - if ((dest = cupsGetNamedDest(NULL, printer, instance)) != NULL) + if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, + instance)) != NULL) { for (j = 0; j < dest->num_options; j ++) if (cupsGetOption(dest->options[j].name, num_options, @@ -155,6 +156,14 @@ main(int argc, /* I - Number of command-line arguments */ dest->options[j].value, num_options, &options); } + else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } break; case 'f' : /* Form */ @@ -567,6 +576,14 @@ main(int argc, /* I - Number of command-line arguments */ dest->options[j].value, num_options, &options); } + else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } } if (printer == NULL) @@ -679,7 +696,15 @@ restart_job(const char *command, /* I - Command name */ ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/jobs")); - if (cupsLastError() > IPP_OK_CONFLICT) + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), command); + return (1); + } + else if (cupsLastError() > IPP_OK_CONFLICT) { _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString()); return (1); @@ -720,7 +745,15 @@ set_job_attrs(const char *command, /* I - Command name */ ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/jobs")); - if (cupsLastError() > IPP_OK_CONFLICT) + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), command); + return (1); + } + else if (cupsLastError() > IPP_OK_CONFLICT) { _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString()); return (1); diff --git a/systemv/lpstat.c b/systemv/lpstat.c index 4d6495637f..8ead3f143f 100644 --- a/systemv/lpstat.c +++ b/systemv/lpstat.c @@ -3,7 +3,7 @@ * * "lpstat" command for CUPS. * - * Copyright 2007-2011 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -199,6 +199,16 @@ main(int argc, /* I - Number of command-line arguments */ { cupsFreeDests(num_dests, dests); num_dests = cupsGetDests(&dests); + + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } } status |= show_accepting(NULL, num_dests, dests); @@ -235,6 +245,16 @@ main(int argc, /* I - Number of command-line arguments */ dests = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); num_dests = dests ? 1 : 0; + + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } } show_default(dests); @@ -316,6 +336,16 @@ main(int argc, /* I - Number of command-line arguments */ { cupsFreeDests(num_dests, dests); num_dests = cupsGetDests(&dests); + + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } } status |= show_printers(NULL, num_dests, dests, long_status); @@ -335,6 +365,16 @@ main(int argc, /* I - Number of command-line arguments */ { cupsFreeDests(num_dests, dests); num_dests = cupsGetDests(&dests); + + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } } show_default(cupsGetDest(NULL, NULL, num_dests, dests)); @@ -349,6 +389,16 @@ main(int argc, /* I - Number of command-line arguments */ { cupsFreeDests(num_dests, dests); num_dests = cupsGetDests(&dests); + + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } } show_scheduler(); @@ -398,6 +448,16 @@ main(int argc, /* I - Number of command-line arguments */ { cupsFreeDests(num_dests, dests); num_dests = cupsGetDests(&dests); + + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); + return (1); + } } status |= show_devices(NULL, num_dests, dests); @@ -457,9 +517,16 @@ check_dest(const char *command, /* I - Command name */ if ((*dests = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, pptr)) == NULL) { - _cupsLangPrintf(stderr, - _("%s: Invalid destination name in list \"%s\"."), - command, name); + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server name."), + command); + else + _cupsLangPrintf(stderr, + _("%s: Invalid destination name in list \"%s\"."), + command, name); + exit(1); } else @@ -511,8 +578,15 @@ check_dest(const char *command, /* I - Command name */ if (!cupsGetDest(printer, NULL, *num_dests, *dests)) { - _cupsLangPrintf(stderr, - _("%s: Unknown destination \"%s\"."), command, printer); + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server name."), + command); + else + _cupsLangPrintf(stderr, + _("%s: Unknown destination \"%s\"."), command, printer); + exit(1); } } @@ -627,16 +701,27 @@ show_accepting(const char *printers, /* I - Destinations */ * Do the request and get back a response... */ - if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/")) != NULL) + response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); + + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) { - DEBUG_puts("show_accepting: request succeeded..."); + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server name."), + "lpstat"); + ippDelete(response); + return (1); + } + else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) + { + _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); + ippDelete(response); + return (1); + } - if (response->request.status.status_code > IPP_OK_CONFLICT) - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - ippDelete(response); - return (1); - } + if (response) + { + DEBUG_puts("show_accepting: request succeeded..."); /* * Loop through the printers returned in the list and display @@ -739,11 +824,6 @@ show_accepting(const char *printers, /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -806,7 +886,25 @@ show_classes(const char *dests) /* I - Destinations */ * Do the request and get back a response... */ - if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/")) != NULL) + response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); + + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server name."), + "lpstat"); + ippDelete(response); + return (1); + } + else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) + { + _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); + ippDelete(response); + return (1); + } + + if (response) { DEBUG_puts("show_classes: request succeeded..."); @@ -944,11 +1042,6 @@ show_classes(const char *dests) /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -1054,16 +1147,27 @@ show_devices(const char *printers, /* I - Destinations */ * Do the request and get back a response... */ - if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/")) != NULL) + response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); + + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) { - DEBUG_puts("show_devices: request succeeded..."); + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server name."), + "lpstat"); + ippDelete(response); + return (1); + } + else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) + { + _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); + ippDelete(response); + return (1); + } - if (response->request.status.status_code > IPP_OK_CONFLICT) - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - ippDelete(response); - return (1); - } + if (response) + { + DEBUG_puts("show_devices: request succeeded..."); /* * Loop through the printers returned in the list and display @@ -1203,11 +1307,6 @@ show_devices(const char *printers, /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -1291,19 +1390,30 @@ show_jobs(const char *dests, /* I - Destinations */ * Do the request and get back a response... */ - if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/")) != NULL) + response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); + + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + { + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server name."), + "lpstat"); + ippDelete(response); + return (1); + } + else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) + { + _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); + ippDelete(response); + return (1); + } + + if (response) { /* * Loop through the job list and display them... */ - if (response->request.status.status_code > IPP_OK_CONFLICT) - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - ippDelete(response); - return (1); - } - rank = -1; for (attr = response->attrs; attr != NULL; attr = attr->next) @@ -1449,11 +1559,6 @@ show_jobs(const char *dests, /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -1544,16 +1649,27 @@ show_printers(const char *printers, /* I - Destinations */ * Do the request and get back a response... */ - if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/")) != NULL) + response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); + + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) { - DEBUG_puts("show_printers: request succeeded..."); + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server name."), + "lpstat"); + ippDelete(response); + return (1); + } + else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) + { + _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); + ippDelete(response); + return (1); + } - if (response->request.status.status_code > IPP_OK_CONFLICT) - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - ippDelete(response); - return (1); - } + if (response) + { + DEBUG_puts("show_printers: request succeeded..."); /* * Loop through the printers returned in the list and display @@ -1975,11 +2091,6 @@ show_printers(const char *printers, /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); }