/*
- * "$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-2011 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/".
*/
/*
_cupsLangPuts(stdout, cupsServer());
else
_cupsLangPrintf(stdout, "%s:%d", cupsServer(), ippPort());
+ op = 'H';
break;
case 'P' : /* Show paper types */
{
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';
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);
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 */
{
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);
{
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));
{
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();
{
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);
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
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);
}
}
* 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
ippDelete(response);
}
- else
- {
- _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
- return (1);
- }
return (0);
}
* 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...");
ippDelete(response);
}
- else
- {
- _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
- return (1);
- }
return (0);
}
* 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
ippDelete(response);
}
- else
- {
- _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
- return (1);
- }
return (0);
}
* 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)
ippDelete(response);
}
- else
- {
- _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
- return (1);
- }
return (0);
}
* 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
ippDelete(response);
}
- else
- {
- _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
- return (1);
- }
return (0);
}
/*
- * 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 $".
*/