From 913aaa215a4972a7371e2638f3c33faff0688c2c Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 26 Mar 2024 12:17:41 -0400 Subject: [PATCH] Fix building of lpq command, other commands. --- commands/Makefile | 16 +++--- commands/lpq.c | 129 ++++++++++++++++++++-------------------------- 2 files changed, 65 insertions(+), 80 deletions(-) diff --git a/commands/Makefile b/commands/Makefile index 48619df..7dd0885 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -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. @@ -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 # @@ -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 diff --git a/commands/lpq.c b/commands/lpq.c index 6ee3f61..6b50ca6 100644 --- a/commands/lpq.c +++ b/commands/lpq.c @@ -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. // @@ -11,6 +11,7 @@ #include #include +#include // @@ -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) { @@ -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 @@ -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... @@ -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); @@ -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; @@ -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); } /* @@ -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 { /* @@ -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); @@ -577,7 +565,7 @@ 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 @@ -585,12 +573,10 @@ show_printer(const char *command, // I - Command name * 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... @@ -598,7 +584,7 @@ show_printer(const char *command, // I - Command name 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); @@ -606,20 +592,19 @@ show_printer(const char *command, // I - Command name } 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; }