Skip to content

Commit

Permalink
Fix building of lpq command, other commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Mar 26, 2024
1 parent 03f4db8 commit 913aaa2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 80 deletions.
16 changes: 8 additions & 8 deletions commands/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Commands makefile for cups-local.
#
# Copyright © 2022-2023 by OpenPrinting.
# Copyright © 2022-2024 by OpenPrinting.
#
# Licensed under Apache License v2.0. See the file "LICENSE" for more
# information.
Expand All @@ -15,21 +15,21 @@ TARGETS = \
cupsaccept \
lp \
lpadmin \
# lpc \
# lpmove \
lpoptions \
lpq \
lpstat
# lpc
# lpmove
# lpoptions
OBJS = \
cancel.o \
cupsaccept.o \
lp.o \
lpadmin.o \
# lpc.o \
# lpmove.o \
lpoptions.o \
lpq.o \
lpstat.o
# lpc.o
# lpmove.o
# lpoptions.o


#
Expand Down Expand Up @@ -72,7 +72,7 @@ install:
$(INSTALL_DIR) -m 755 $(BUILDROOT)$(bindir)
$(INSTALL_BIN) cancel $(BUILDROOT)$(bindir)
$(INSTALL_BIN) lp $(BUILDROOT)$(bindir)
$(INSTALL_BIN) lpoptions $(BUILDROOT)$(bindir)
# $(INSTALL_BIN) lpoptions $(BUILDROOT)$(bindir)
$(INSTALL_BIN) lpstat $(BUILDROOT)$(bindir)
$(RM) $(BUILDROOT)$(bindir)/lpq
$(LN) lpstat $(BUILDROOT)$(bindir)/lpq
Expand Down
129 changes: 57 additions & 72 deletions commands/lpq.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// "lpq" command for CUPS.
//
// Copyright © 2021-2023 by OpenPrinting.
// Copyright © 2021-2024 by OpenPrinting.
// Copyright © 2007-2018 by Apple Inc.
// Copyright © 1997-2006 by Easy Software Products.
//
Expand All @@ -11,6 +11,7 @@

#include <config.h>
#include <cups/cups.h>
#include <ctype.h>


//
Expand Down Expand Up @@ -284,8 +285,7 @@ connect_server(const char *command, // I - Command name
{
if (!http)
{
http = httpConnectEncrypt(cupsGetServer(), ippGetPort(),
cupsEncryption());
http = httpConnect(cupsGetServer(), ippGetPort(), /*addrlist*/NULL, AF_UNSPEC, cupsGetEncryption(), /*blocking*/true, /*msec*/30000, /*cancel*/NULL);

if (http == NULL)
{
Expand Down Expand Up @@ -355,8 +355,8 @@ show_jobs(const char *command, // I - Command name
return (0);

/*
* Build an IPP_GET_JOBS or IPP_GET_JOB_ATTRIBUTES request, which requires
* the following attributes:
* Build an IPP_OP_GET_JOBS or IPP_OP_GET_JOB_ATTRIBUTES request, which
* requires the following attributes:
*
* attributes-charset
* attributes-natural-language
Expand All @@ -365,39 +365,31 @@ show_jobs(const char *command, // I - Command name
* requesting-user-name
*/

request = ippNewRequest(id ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS);
request = ippNewRequest(id ? IPP_OP_GET_JOB_ATTRIBUTES : IPP_OP_GET_JOBS);

if (id)
{
snprintf(resource, sizeof(resource), "ipp://localhost/jobs/%d", id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
NULL, resource);
}
else if (dest)
if (dest)
{
httpAssembleURIf(HTTP_URI_CODING_ALL, resource, sizeof(resource), "ipp",
NULL, "localhost", 0, "/printers/%s", dest);
httpAssembleURIf(HTTP_URI_CODING_ALL, resource, sizeof(resource), "ipp", NULL, "localhost", 0, "/ipp/print/%s", dest);

ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, resource);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, resource);
}
else
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, "ipp://localhost/");
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://localhost/ipp/print");

if (id)
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", id);

if (user)
{
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, user);
ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, user);
ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", true);
}
else
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, cupsGetUser());
{
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsGetUser());
}

ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes",
(int)(sizeof(jobattrs) / sizeof(jobattrs[0])), NULL, jobattrs);
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", sizeof(jobattrs) / sizeof(jobattrs[0]), NULL, jobattrs);

/*
* Do the request and get back a response...
Expand All @@ -407,7 +399,7 @@ show_jobs(const char *command, // I - Command name

if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
if (response->request.status.status_code > IPP_STATUS_OK_CONFLICTING)
if (ippGetStatusCode(response) > IPP_STATUS_OK_CONFLICTING)
{
cupsLangPrintf(stderr, "%s: %s", command, cupsGetErrorString());
ippDelete(response);
Expand All @@ -420,14 +412,14 @@ show_jobs(const char *command, // I - Command name
* Loop through the job list and display them...
*/

for (attr = response->attrs; attr != NULL; attr = attr->next)
for (attr = ippGetFirstAttribute(response); attr != NULL; attr = ippGetNextAttribute(response))
{
/*
* Skip leading attributes until we hit a job...
*/

while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
attr = attr->next;
while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_JOB)
attr = ippGetNextAttribute(response);

if (attr == NULL)
break;
Expand All @@ -438,44 +430,40 @@ show_jobs(const char *command, // I - Command name

jobid = 0;
jobsize = 0;
jobstate = IPP_JOB_PENDING;
jobstate = IPP_JSTATE_PENDING;
jobname = "unknown";
jobuser = "unknown";
jobdest = NULL;
jobcopies = 1;

while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_JOB)
{
if (!strcmp(attr->name, "job-id") &&
attr->value_tag == IPP_TAG_INTEGER)
jobid = attr->values[0].integer;
const char *name = ippGetName(attr);
ipp_tag_t value_tag = ippGetValueTag(attr);

if (!strcmp(name, "job-id") && value_tag == IPP_TAG_INTEGER)
jobid = ippGetInteger(attr, 0);

if (!strcmp(attr->name, "job-k-octets") &&
attr->value_tag == IPP_TAG_INTEGER)
jobsize = attr->values[0].integer;
if (!strcmp(name, "job-k-octets") && value_tag == IPP_TAG_INTEGER)
jobsize = ippGetInteger(attr, 0);

if (!strcmp(attr->name, "job-state") &&
attr->value_tag == IPP_TAG_ENUM)
jobstate = (ipp_jstate_t)attr->values[0].integer;
if (!strcmp(name, "job-state") && value_tag == IPP_TAG_ENUM)
jobstate = (ipp_jstate_t)ippGetInteger(attr, 0);

if (!strcmp(attr->name, "job-printer-uri") &&
attr->value_tag == IPP_TAG_URI)
if ((jobdest = strrchr(attr->values[0].string.text, '/')) != NULL)
if (!strcmp(name, "job-printer-uri") && value_tag == IPP_TAG_URI)
if ((jobdest = strrchr(ippGetString(attr, 0, NULL), '/')) != NULL)
jobdest ++;

if (!strcmp(attr->name, "job-originating-user-name") &&
attr->value_tag == IPP_TAG_NAME)
jobuser = attr->values[0].string.text;
if (!strcmp(name, "job-originating-user-name") && value_tag == IPP_TAG_NAME)
jobuser = ippGetString(attr, 0, NULL);

if (!strcmp(attr->name, "job-name") &&
attr->value_tag == IPP_TAG_NAME)
jobname = attr->values[0].string.text;
if (!strcmp(name, "job-name") && value_tag == IPP_TAG_NAME)
jobname = ippGetString(attr, 0, NULL);

if (!strcmp(attr->name, "copies") &&
attr->value_tag == IPP_TAG_INTEGER)
jobcopies = attr->values[0].integer;
if (!strcmp(name, "copies") && value_tag == IPP_TAG_INTEGER)
jobcopies = ippGetInteger(attr, 0);

attr = attr->next;
attr = ippGetNextAttribute(response);
}

/*
Expand All @@ -501,8 +489,8 @@ show_jobs(const char *command, // I - Command name
* Display the job...
*/

if (jobstate == IPP_JOB_PROCESSING)
strlcpy(rankstr, "active", sizeof(rankstr));
if (jobstate == IPP_JSTATE_PROCESSING)
cupsCopyString(rankstr, "active", sizeof(rankstr));
else
{
/*
Expand All @@ -526,7 +514,7 @@ show_jobs(const char *command, // I - Command name
snprintf(namestr, sizeof(namestr), "%d copies of %s", jobcopies,
jobname);
else
strlcpy(namestr, jobname, sizeof(namestr));
cupsCopyString(namestr, jobname, sizeof(namestr));

cupsLangPrintf(stdout, _("%s: %-33.33s [job %d localhost]"),
jobuser, rankstr, jobid);
Expand Down Expand Up @@ -577,49 +565,46 @@ show_printer(const char *command, // I - Command name
return;

/*
* Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
* Build an IPP_OP_GET_PRINTER_ATTRIBUTES request, which requires the following
* attributes:
*
* attributes-charset
* attributes-natural-language
* printer-uri
*/

request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);

httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
"localhost", 0, "/printers/%s", dest);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/ipp/print/%s", dest);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);

/*
* Do the request and get back a response...
*/

if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
if (response->request.status.status_code > IPP_STATUS_OK_CONFLICTING)
if (cupsGetError() > IPP_STATUS_OK_CONFLICTING)
{
cupsLangPrintf(stderr, "%s: %s", command, cupsGetErrorString());
ippDelete(response);
return;
}

if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
state = (ipp_pstate_t)attr->values[0].integer;
state = (ipp_pstate_t)ippGetInteger(attr, 0);
else
state = IPP_PRINTER_STOPPED;
state = IPP_PSTATE_STOPPED;

switch (state)
{
case IPP_PRINTER_IDLE :
case IPP_PSTATE_IDLE :
cupsLangPrintf(stdout, _("%s is ready"), dest);
break;
case IPP_PRINTER_PROCESSING :
cupsLangPrintf(stdout, _("%s is ready and printing"),
dest);
case IPP_PSTATE_PROCESSING :
cupsLangPrintf(stdout, _("%s is ready and printing"), dest);
break;
case IPP_PRINTER_STOPPED :
case IPP_PSTATE_STOPPED :
cupsLangPrintf(stdout, _("%s is not ready"), dest);
break;
}
Expand Down

0 comments on commit 913aaa2

Please sign in to comment.