X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=systemv%2Flpstat.c;h=6c52e2dd8d99a5856ef2de0ab627d8a864aa99a7;hb=61515785f7de12d8b2a29090020e684988f89977;hp=445588c014eaf475af024426d894c61597ea957a;hpb=0837b7e828b9fc312fcf8f5741d2ba9683742672;p=thirdparty%2Fcups.git diff --git a/systemv/lpstat.c b/systemv/lpstat.c index 445588c01..6c52e2dd8 100644 --- a/systemv/lpstat.c +++ b/systemv/lpstat.c @@ -1,30 +1,16 @@ /* - * "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $" + * "$Id: lpstat.c 11395 2013-11-06 20:06:50Z msweet $" * - * "lpstat" command for CUPS. + * "lpstat" command for CUPS. * - * Copyright 2007-2010 by Apple Inc. - * Copyright 1997-2006 by Easy Software Products. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2006 by Easy Software Products. * - * 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/". - * - * Contents: - * - * main() - Parse options and show status information. - * check_dest() - Verify that the named destination(s) exists. - * match_list() - Match a name from a list of comma or space-separated - * names. - * show_accepting() - Show acceptance status. - * show_classes() - Show printer classes. - * show_default() - Show default destination. - * show_devices() - Show printer devices. - * show_jobs() - Show active print jobs. - * show_printers() - Show printers. - * show_scheduler() - Show scheduler status. + * 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/". */ /* @@ -109,6 +95,7 @@ main(int argc, /* I - Number of command-line arguments */ _cupsLangPuts(stdout, cupsServer()); else _cupsLangPrintf(stdout, "%s:%d", cupsServer(), ippPort()); + op = 'H'; break; case 'P' : /* Show paper types */ @@ -143,7 +130,7 @@ main(int argc, /* I - Number of command-line arguments */ cupsSetUser(argv[i]); } break; - + case 'W' : /* Show which jobs? */ if (argv[i][2]) which = argv[i] + 2; @@ -199,44 +186,22 @@ 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); } break; -#ifdef __sgi - case 'b' : /* Show both the local and remote status */ - op = 'b'; - - if (argv[i][2]) - { - /* - * The local and remote status are separated by a blank line; - * since all CUPS jobs are networked, we only output the - * second list for now... In the future, we might further - * emulate this by listing the remote server's queue, but - * for now this is enough to make the SGI printstatus program - * happy... - */ - - check_dest(argv[0], argv[i] + 2, &num_dests, &dests); - - puts(""); - status |= show_jobs(argv[i] + 2, NULL, 3, ranking, which); - } - else - { - _cupsLangPrintf(stderr, - _("%s: Error - expected destination after " - "\"-b\" option."), - argv[0]); - - return (1); - } - break; -#endif /* __sgi */ - case 'c' : /* Show classes and members */ op = 'c'; @@ -267,6 +232,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); @@ -299,18 +274,7 @@ main(int argc, /* I - Number of command-line arguments */ break; case 'l' : /* Long status or long job status */ -#ifdef __sgi - op = 'l'; - - if (argv[i][2]) - { - check_dest(argv[0], argv[i] + 2, &num_dests, &dests); - - status |= show_jobs(argv[i] + 2, NULL, 3, ranking, which); - } - else -#endif /* __sgi */ - long_status = 2; + long_status = 2; break; case 'o' : /* Show jobs by destination */ @@ -359,6 +323,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); @@ -378,6 +352,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)); @@ -392,6 +376,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(); @@ -441,6 +435,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); @@ -500,9 +504,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 @@ -517,7 +528,7 @@ check_dest(const char *command, /* I - Command name */ * Scan the name string for printer/class name(s)... */ - for (dptr = name; *dptr;) + for (dptr = name; *dptr;) { /* * Skip leading whitespace and commas... @@ -554,8 +565,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); } } @@ -580,6 +598,9 @@ match_list(const char *list, /* I - List of names */ if (!list || !*list) return (1); + if (!name) + return (0); + while (*list) { /* @@ -667,16 +688,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 @@ -756,7 +788,7 @@ show_accepting(const char *printers, /* I - Destinations */ } for (i = 0; i < num_dests; i ++) - if (!strcasecmp(dests[i].name, printer) && dests[i].instance) + if (!_cups_strcasecmp(dests[i].name, printer) && dests[i].instance) { if (accepting) _cupsLangPrintf(stdout, _("%s/%s accepting requests since %s"), @@ -779,11 +811,6 @@ show_accepting(const char *printers, /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -846,7 +873,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..."); @@ -911,7 +956,7 @@ show_classes(const char *dests) /* I - Destinations */ username, sizeof(username), server, sizeof(server), &port, resource, sizeof(resource)); - if (!strcasecmp(server, cupsServer())) + if (!_cups_strcasecmp(server, cupsServer())) http2 = CUPS_HTTP_DEFAULT; else http2 = httpConnectEncrypt(server, port, cupsEncryption()); @@ -984,11 +1029,6 @@ show_classes(const char *dests) /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -1094,16 +1134,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 @@ -1193,7 +1244,7 @@ show_devices(const char *printers, /* I - Destinations */ printer, device); for (i = 0; i < num_dests; i ++) - if (!strcasecmp(printer, dests[i].name) && dests[i].instance) + if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance) { if (device == NULL) _cupsLangPrintf(stdout, @@ -1222,7 +1273,7 @@ show_devices(const char *printers, /* I - Destinations */ printer, device); for (i = 0; i < num_dests; i ++) - if (!strcasecmp(printer, dests[i].name) && dests[i].instance) + if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance) { if (device == NULL) _cupsLangPrintf(stdout, _("device for %s/%s: %s"), @@ -1243,11 +1294,6 @@ show_devices(const char *printers, /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -1271,7 +1317,8 @@ show_jobs(const char *dests, /* I - Destinations */ *reasons; /* Job state reasons attribute */ const char *dest, /* Pointer into job-printer-uri */ *username, /* Pointer to job-originating-user-name */ - *title; /* Pointer to job-name */ + *title, /* Pointer to job-name */ + *message; /* Pointer to job-printer-state-message */ int rank, /* Rank in queue */ jobid, /* job-id */ size; /* job-k-octets */ @@ -1285,6 +1332,7 @@ show_jobs(const char *dests, /* I - Destinations */ "job-k-octets", "job-name", "job-originating-user-name", + "job-printer-state-message", "job-printer-uri", "job-state-reasons", "time-at-creation" @@ -1329,19 +1377,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) @@ -1366,6 +1425,7 @@ show_jobs(const char *dests, /* I - Destinations */ dest = NULL; jobtime = 0; title = "no title"; + message = NULL; reasons = NULL; while (attr != NULL && attr->group_tag == IPP_TAG_JOB) @@ -1373,30 +1433,29 @@ show_jobs(const char *dests, /* I - Destinations */ if (!strcmp(attr->name, "job-id") && attr->value_tag == IPP_TAG_INTEGER) jobid = attr->values[0].integer; - - if (!strcmp(attr->name, "job-k-octets") && - attr->value_tag == IPP_TAG_INTEGER) + else if (!strcmp(attr->name, "job-k-octets") && + attr->value_tag == IPP_TAG_INTEGER) size = attr->values[0].integer; - - if (!strcmp(attr->name, "time-at-creation") && - attr->value_tag == IPP_TAG_INTEGER) + else if (!strcmp(attr->name, "time-at-creation") && + attr->value_tag == IPP_TAG_INTEGER) jobtime = attr->values[0].integer; - - if (!strcmp(attr->name, "job-printer-uri") && - attr->value_tag == IPP_TAG_URI) + else if (!strcmp(attr->name, "job-printer-state-message") && + attr->value_tag == IPP_TAG_TEXT) + message = attr->values[0].string.text; + else if (!strcmp(attr->name, "job-printer-uri") && + attr->value_tag == IPP_TAG_URI) + { if ((dest = strrchr(attr->values[0].string.text, '/')) != NULL) dest ++; - - if (!strcmp(attr->name, "job-originating-user-name") && - attr->value_tag == IPP_TAG_NAME) + } + else if (!strcmp(attr->name, "job-originating-user-name") && + attr->value_tag == IPP_TAG_NAME) username = attr->values[0].string.text; - - if (!strcmp(attr->name, "job-name") && - attr->value_tag == IPP_TAG_NAME) + else if (!strcmp(attr->name, "job-name") && + attr->value_tag == IPP_TAG_NAME) title = attr->values[0].string.text; - - if (!strcmp(attr->name, "job-state-reasons") && - attr->value_tag == IPP_TAG_KEYWORD) + else if (!strcmp(attr->name, "job-state-reasons") && + attr->value_tag == IPP_TAG_KEYWORD) reasons = attr; attr = attr->next; @@ -1432,7 +1491,7 @@ show_jobs(const char *dests, /* I - Destinations */ */ if (!strftime(date, sizeof(date), "%b %d %H:%M", jobdate)) - strcpy(date, "Unknown"); + strlcpy(date, "Unknown", sizeof(date)); _cupsLangPrintf(stdout, "%s;%s;%d;%s;%s", temp, username ? username : "unknown", @@ -1441,7 +1500,7 @@ show_jobs(const char *dests, /* I - Destinations */ else { if (!strftime(date, sizeof(date), "%c", jobdate)) - strcpy(date, "Unknown"); + strlcpy(date, "Unknown", sizeof(date)); if (ranking) _cupsLangPrintf(stdout, "%3d %-21s %-13s %8.0f %s", @@ -1453,6 +1512,9 @@ show_jobs(const char *dests, /* I - Destinations */ 1024.0 * size, date); if (long_status) { + if (message) + _cupsLangPrintf(stdout, _("\tStatus: %s"), message); + if (reasons) { char alerts[1024], /* Alerts string */ @@ -1484,11 +1546,6 @@ show_jobs(const char *dests, /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -1579,16 +1636,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 @@ -1878,7 +1946,7 @@ show_printers(const char *printers, /* I - Destinations */ } for (i = 0; i < num_dests; i ++) - if (!strcasecmp(printer, dests[i].name) && dests[i].instance) + if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance) { switch (pstate) { @@ -2010,11 +2078,6 @@ show_printers(const char *printers, /* I - Destinations */ ippDelete(response); } - else - { - _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); - return (1); - } return (0); } @@ -2042,5 +2105,5 @@ show_scheduler(void) /* - * End of "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $". + * End of "$Id: lpstat.c 11395 2013-11-06 20:06:50Z msweet $". */