/*
- * "$Id$"
+ * "lpc" command for CUPS.
*
- * "lpc" command for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
*
- * Copyright 1997-2006 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Easy Software Products 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 please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
- *
- * Contents:
- *
- * main() - Parse options and commands.
- * compare_strings() - Compare two command-line strings.
- * do_command() - Do an lpc command...
- * show_help() - Show help messages.
- * show_status() - Show printers.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
*/
/*
* Include necessary headers...
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
-#include <cups/debug.h>
-#include <cups/string.h>
+#include <cups/cups-private.h>
/*
* Local functions...
*/
-static int compare_strings(const char *, const char *, int);
+static int compare_strings(const char *, const char *, size_t);
static void do_command(http_t *, const char *, const char *);
static void show_help(const char *);
static void show_status(http_t *, const char *);
*params; /* Pointer to parameters */
+ _cupsSetLocale(argv);
+
/*
* Connect to the scheduler...
*/
* Do the command prompt thing...
*/
- _cupsLangPuts(stdout, _("lpc> "));
+ _cupsLangPuts(stdout, _("lpc> ")); /* TODO: Need no-newline version */
while (fgets(line, sizeof(line), stdin) != NULL)
{
/*
* Nothing left, just show a prompt...
*/
- _cupsLangPuts(stdout, _("lpc> "));
+ _cupsLangPuts(stdout, _("lpc> ")); /* TODO: Need no newline version */
continue;
}
* Put another prompt out to the user...
*/
- _cupsLangPuts(stdout, _("lpc> "));
+ _cupsLangPuts(stdout, _("lpc> ")); /* TODO: Need no newline version */
}
}
static int /* O - -1 or 1 = no match, 0 = match */
compare_strings(const char *s, /* I - Command-line string */
const char *t, /* I - Option string */
- int tmin) /* I - Minimum number of unique chars in option */
+ size_t tmin) /* I - Minimum number of unique chars in option */
{
- int slen; /* Length of command-line string */
+ size_t slen; /* Length of command-line string */
slen = strlen(s);
show_help(params);
else
_cupsLangPrintf(stdout,
- _("%s is not implemented by the CUPS version of lpc.\n"),
+ _("%s is not implemented by the CUPS version of lpc."),
command);
}
_cupsLangPrintf(stdout,
_("Commands may be abbreviated. Commands are:\n"
"\n"
- "exit help quit status ?\n"));
+ "exit help quit status ?"));
}
else if (!compare_strings(command, "help", 1) || !strcmp(command, "?"))
- _cupsLangPrintf(stdout, _("help\t\tget help on commands\n"));
+ _cupsLangPrintf(stdout, _("help\t\tGet help on commands."));
else if (!compare_strings(command, "status", 4))
- _cupsLangPrintf(stdout, _("status\t\tshow status of daemon and queue\n"));
+ _cupsLangPrintf(stdout, _("status\t\tShow status of daemon and queue."));
else
- _cupsLangPrintf(stdout, _("?Invalid help command unknown\n"));
+ _cupsLangPrintf(stdout, _("?Invalid help command unknown."));
}
const char *dests) /* I - Destinations */
{
ipp_t *request, /* IPP Request */
- *response, /* IPP Response */
- *jobs; /* IPP Get Jobs response */
- ipp_attribute_t *attr, /* Current attribute */
- *jattr; /* Current job attribute */
- cups_lang_t *language; /* Default language */
+ *response; /* IPP Response */
+ ipp_attribute_t *attr; /* Current attribute */
char *printer, /* Printer name */
*device, /* Device URI */
*delimiter; /* Char search result */
const char *dptr, /* Pointer into destination list */
*ptr; /* Pointer into printer name */
int match; /* Non-zero if this job matches */
- char printer_uri[HTTP_MAX_URI];
- /* Printer URI */
static const char *requested[] = /* Requested attributes */
{
- "printer-name",
"device-uri",
+ "printer-is-accepting-jobs",
+ "printer-name",
"printer-state",
- "printer-is-accepting-jobs"
+ "queued-job-count"
};
- DEBUG_printf(("show_status(http=%p, dests=\"%s\")\n", http, dests));
-
if (http == NULL)
return;
* attributes-natural-language
*/
- request = ippNew();
-
- request->request.op.operation_id = CUPS_GET_PRINTERS;
- request->request.op.request_id = 1;
-
- language = cupsLangDefault();
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL, cupsLangEncoding(language));
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL, language->language);
+ request = ippNewRequest(CUPS_GET_PRINTERS);
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", sizeof(requested) / sizeof(requested[0]),
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
- DEBUG_puts("show_status: request succeeded...");
-
/*
* Loop through the printers returned in the list and display
* their status...
while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
{
- if (!strcmp(attr->name, "printer-name") &&
- attr->value_tag == IPP_TAG_NAME)
- printer = attr->values[0].string.text;
-
if (!strcmp(attr->name, "device-uri") &&
attr->value_tag == IPP_TAG_URI)
device = attr->values[0].string.text;
-
- if (!strcmp(attr->name, "printer-state") &&
- attr->value_tag == IPP_TAG_ENUM)
- pstate = (ipp_pstate_t)attr->values[0].integer;
-
- if (!strcmp(attr->name, "printer-is-accepting-jobs") &&
- attr->value_tag == IPP_TAG_BOOLEAN)
+ else if (!strcmp(attr->name, "printer-is-accepting-jobs") &&
+ attr->value_tag == IPP_TAG_BOOLEAN)
accepting = attr->values[0].boolean;
+ else if (!strcmp(attr->name, "printer-name") &&
+ attr->value_tag == IPP_TAG_NAME)
+ printer = attr->values[0].string.text;
+ else if (!strcmp(attr->name, "printer-state") &&
+ attr->value_tag == IPP_TAG_ENUM)
+ pstate = (ipp_pstate_t)attr->values[0].integer;
+ else if (!strcmp(attr->name, "queued-job-count") &&
+ attr->value_tag == IPP_TAG_INTEGER)
+ jobcount = attr->values[0].integer;
attr = attr->next;
}
for (ptr = printer;
*ptr != '\0' && *dptr != '\0' && *ptr == *dptr;
- ptr ++, dptr ++);
+ ptr ++, dptr ++)
+ /* do nothing */;
- if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' || isspace(*dptr & 255)))
+ if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' ||
+ isspace(*dptr & 255)))
{
match = 1;
break;
if (match)
{
- /*
- * Build an IPP_GET_JOBS request, which requires the following
- * attributes:
- *
- * attributes-charset
- * attributes-natural-language
- * printer-uri
- * limit
- */
-
- request = ippNew();
-
- request->request.op.operation_id = IPP_GET_JOBS;
- request->request.op.request_id = 1;
-
- language = cupsLangDefault();
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL,
- cupsLangEncoding(language));
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL,
- language->language);
-
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
- "ipp", NULL, "localhost", 631, "/printers/%s",
- printer);
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, printer_uri);
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
- "requested-attributes", NULL, "job-id");
-
- if ((jobs = cupsDoRequest(http, request, "/")) != NULL)
- {
- /*
- * Grab the number of jobs for the printer.
- */
-
- for (jattr = jobs->attrs; jattr != NULL; jattr = jattr->next)
- if (jattr->name && !strcmp(jattr->name, "job-id"))
- jobcount ++;
-
- ippDelete(jobs);
- }
-
/*
* Display it...
*/
printf("%s:\n", printer);
if (!strncmp(device, "file:", 5))
_cupsLangPrintf(stdout,
- _("\tprinter is on device \'%s\' speed -1\n"),
+ _("\tprinter is on device \'%s\' speed -1"),
device + 5);
else
{
{
*delimiter = '\0';
_cupsLangPrintf(stdout,
- _("\tprinter is on device \'%s\' speed -1\n"),
+ _("\tprinter is on device \'%s\' speed -1"),
device);
}
}
if (accepting)
- _cupsLangPuts(stdout, _("\tqueuing is enabled\n"));
+ _cupsLangPuts(stdout, _("\tqueuing is enabled"));
else
- _cupsLangPuts(stdout, _("\tqueuing is disabled\n"));
+ _cupsLangPuts(stdout, _("\tqueuing is disabled"));
if (pstate != IPP_PRINTER_STOPPED)
- _cupsLangPuts(stdout, _("\tprinting is enabled\n"));
+ _cupsLangPuts(stdout, _("\tprinting is enabled"));
else
- _cupsLangPuts(stdout, _("\tprinting is disabled\n"));
+ _cupsLangPuts(stdout, _("\tprinting is disabled"));
if (jobcount == 0)
- _cupsLangPuts(stdout, _("\tno entries\n"));
+ _cupsLangPuts(stdout, _("\tno entries"));
else
- _cupsLangPrintf(stdout, _("\t%d entries\n"), jobcount);
+ _cupsLangPrintf(stdout, _("\t%d entries"), jobcount);
- _cupsLangPuts(stdout, _("\tdaemon present\n"));
+ _cupsLangPuts(stdout, _("\tdaemon present"));
}
if (attr == NULL)
ippDelete(response);
}
}
-
-
-/*
- * End of "$Id$".
- */