Skip to content

Commit 913aaa2

Browse files
committed
Fix building of lpq command, other commands.
1 parent 03f4db8 commit 913aaa2

2 files changed

Lines changed: 65 additions & 80 deletions

File tree

commands/Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Commands makefile for cups-local.
33
#
4-
# Copyright © 2022-2023 by OpenPrinting.
4+
# Copyright © 2022-2024 by OpenPrinting.
55
#
66
# Licensed under Apache License v2.0. See the file "LICENSE" for more
77
# information.
@@ -15,21 +15,21 @@ TARGETS = \
1515
cupsaccept \
1616
lp \
1717
lpadmin \
18-
# lpc \
19-
# lpmove \
20-
lpoptions \
2118
lpq \
2219
lpstat
20+
# lpc
21+
# lpmove
22+
# lpoptions
2323
OBJS = \
2424
cancel.o \
2525
cupsaccept.o \
2626
lp.o \
2727
lpadmin.o \
28-
# lpc.o \
29-
# lpmove.o \
30-
lpoptions.o \
3128
lpq.o \
3229
lpstat.o
30+
# lpc.o
31+
# lpmove.o
32+
# lpoptions.o
3333

3434

3535
#
@@ -72,7 +72,7 @@ install:
7272
$(INSTALL_DIR) -m 755 $(BUILDROOT)$(bindir)
7373
$(INSTALL_BIN) cancel $(BUILDROOT)$(bindir)
7474
$(INSTALL_BIN) lp $(BUILDROOT)$(bindir)
75-
$(INSTALL_BIN) lpoptions $(BUILDROOT)$(bindir)
75+
# $(INSTALL_BIN) lpoptions $(BUILDROOT)$(bindir)
7676
$(INSTALL_BIN) lpstat $(BUILDROOT)$(bindir)
7777
$(RM) $(BUILDROOT)$(bindir)/lpq
7878
$(LN) lpstat $(BUILDROOT)$(bindir)/lpq

commands/lpq.c

Lines changed: 57 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// "lpq" command for CUPS.
33
//
4-
// Copyright © 2021-2023 by OpenPrinting.
4+
// Copyright © 2021-2024 by OpenPrinting.
55
// Copyright © 2007-2018 by Apple Inc.
66
// Copyright © 1997-2006 by Easy Software Products.
77
//
@@ -11,6 +11,7 @@
1111

1212
#include <config.h>
1313
#include <cups/cups.h>
14+
#include <ctype.h>
1415

1516

1617
//
@@ -284,8 +285,7 @@ connect_server(const char *command, // I - Command name
284285
{
285286
if (!http)
286287
{
287-
http = httpConnectEncrypt(cupsGetServer(), ippGetPort(),
288-
cupsEncryption());
288+
http = httpConnect(cupsGetServer(), ippGetPort(), /*addrlist*/NULL, AF_UNSPEC, cupsGetEncryption(), /*blocking*/true, /*msec*/30000, /*cancel*/NULL);
289289

290290
if (http == NULL)
291291
{
@@ -355,8 +355,8 @@ show_jobs(const char *command, // I - Command name
355355
return (0);
356356

357357
/*
358-
* Build an IPP_GET_JOBS or IPP_GET_JOB_ATTRIBUTES request, which requires
359-
* the following attributes:
358+
* Build an IPP_OP_GET_JOBS or IPP_OP_GET_JOB_ATTRIBUTES request, which
359+
* requires the following attributes:
360360
*
361361
* attributes-charset
362362
* attributes-natural-language
@@ -365,39 +365,31 @@ show_jobs(const char *command, // I - Command name
365365
* requesting-user-name
366366
*/
367367

368-
request = ippNewRequest(id ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS);
368+
request = ippNewRequest(id ? IPP_OP_GET_JOB_ATTRIBUTES : IPP_OP_GET_JOBS);
369369

370-
if (id)
371-
{
372-
snprintf(resource, sizeof(resource), "ipp://localhost/jobs/%d", id);
373-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
374-
NULL, resource);
375-
}
376-
else if (dest)
370+
if (dest)
377371
{
378-
httpAssembleURIf(HTTP_URI_CODING_ALL, resource, sizeof(resource), "ipp",
379-
NULL, "localhost", 0, "/printers/%s", dest);
372+
httpAssembleURIf(HTTP_URI_CODING_ALL, resource, sizeof(resource), "ipp", NULL, "localhost", 0, "/ipp/print/%s", dest);
380373

381-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
382-
NULL, resource);
374+
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, resource);
383375
}
384376
else
385-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
386-
NULL, "ipp://localhost/");
377+
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://localhost/ipp/print");
378+
379+
if (id)
380+
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", id);
387381

388382
if (user)
389383
{
390-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
391-
"requesting-user-name", NULL, user);
392-
ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
384+
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, user);
385+
ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", true);
393386
}
394387
else
395-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
396-
"requesting-user-name", NULL, cupsGetUser());
388+
{
389+
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsGetUser());
390+
}
397391

398-
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
399-
"requested-attributes",
400-
(int)(sizeof(jobattrs) / sizeof(jobattrs[0])), NULL, jobattrs);
392+
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", sizeof(jobattrs) / sizeof(jobattrs[0]), NULL, jobattrs);
401393

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

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

423-
for (attr = response->attrs; attr != NULL; attr = attr->next)
415+
for (attr = ippGetFirstAttribute(response); attr != NULL; attr = ippGetNextAttribute(response))
424416
{
425417
/*
426418
* Skip leading attributes until we hit a job...
427419
*/
428420

429-
while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
430-
attr = attr->next;
421+
while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_JOB)
422+
attr = ippGetNextAttribute(response);
431423

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

439431
jobid = 0;
440432
jobsize = 0;
441-
jobstate = IPP_JOB_PENDING;
433+
jobstate = IPP_JSTATE_PENDING;
442434
jobname = "unknown";
443435
jobuser = "unknown";
444436
jobdest = NULL;
445437
jobcopies = 1;
446438

447-
while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
439+
while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_JOB)
448440
{
449-
if (!strcmp(attr->name, "job-id") &&
450-
attr->value_tag == IPP_TAG_INTEGER)
451-
jobid = attr->values[0].integer;
441+
const char *name = ippGetName(attr);
442+
ipp_tag_t value_tag = ippGetValueTag(attr);
443+
444+
if (!strcmp(name, "job-id") && value_tag == IPP_TAG_INTEGER)
445+
jobid = ippGetInteger(attr, 0);
452446

453-
if (!strcmp(attr->name, "job-k-octets") &&
454-
attr->value_tag == IPP_TAG_INTEGER)
455-
jobsize = attr->values[0].integer;
447+
if (!strcmp(name, "job-k-octets") && value_tag == IPP_TAG_INTEGER)
448+
jobsize = ippGetInteger(attr, 0);
456449

457-
if (!strcmp(attr->name, "job-state") &&
458-
attr->value_tag == IPP_TAG_ENUM)
459-
jobstate = (ipp_jstate_t)attr->values[0].integer;
450+
if (!strcmp(name, "job-state") && value_tag == IPP_TAG_ENUM)
451+
jobstate = (ipp_jstate_t)ippGetInteger(attr, 0);
460452

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

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

470-
if (!strcmp(attr->name, "job-name") &&
471-
attr->value_tag == IPP_TAG_NAME)
472-
jobname = attr->values[0].string.text;
460+
if (!strcmp(name, "job-name") && value_tag == IPP_TAG_NAME)
461+
jobname = ippGetString(attr, 0, NULL);
473462

474-
if (!strcmp(attr->name, "copies") &&
475-
attr->value_tag == IPP_TAG_INTEGER)
476-
jobcopies = attr->values[0].integer;
463+
if (!strcmp(name, "copies") && value_tag == IPP_TAG_INTEGER)
464+
jobcopies = ippGetInteger(attr, 0);
477465

478-
attr = attr->next;
466+
attr = ippGetNextAttribute(response);
479467
}
480468

481469
/*
@@ -501,8 +489,8 @@ show_jobs(const char *command, // I - Command name
501489
* Display the job...
502490
*/
503491

504-
if (jobstate == IPP_JOB_PROCESSING)
505-
strlcpy(rankstr, "active", sizeof(rankstr));
492+
if (jobstate == IPP_JSTATE_PROCESSING)
493+
cupsCopyString(rankstr, "active", sizeof(rankstr));
506494
else
507495
{
508496
/*
@@ -526,7 +514,7 @@ show_jobs(const char *command, // I - Command name
526514
snprintf(namestr, sizeof(namestr), "%d copies of %s", jobcopies,
527515
jobname);
528516
else
529-
strlcpy(namestr, jobname, sizeof(namestr));
517+
cupsCopyString(namestr, jobname, sizeof(namestr));
530518

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

579567
/*
580-
* Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
568+
* Build an IPP_OP_GET_PRINTER_ATTRIBUTES request, which requires the following
581569
* attributes:
582570
*
583571
* attributes-charset
584572
* attributes-natural-language
585573
* printer-uri
586574
*/
587575

588-
request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
576+
request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
589577

590-
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
591-
"localhost", 0, "/printers/%s", dest);
592-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
593-
"printer-uri", NULL, uri);
578+
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/ipp/print/%s", dest);
579+
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
594580

595581
/*
596582
* Do the request and get back a response...
597583
*/
598584

599585
if ((response = cupsDoRequest(http, request, "/")) != NULL)
600586
{
601-
if (response->request.status.status_code > IPP_STATUS_OK_CONFLICTING)
587+
if (cupsGetError() > IPP_STATUS_OK_CONFLICTING)
602588
{
603589
cupsLangPrintf(stderr, "%s: %s", command, cupsGetErrorString());
604590
ippDelete(response);
605591
return;
606592
}
607593

608594
if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
609-
state = (ipp_pstate_t)attr->values[0].integer;
595+
state = (ipp_pstate_t)ippGetInteger(attr, 0);
610596
else
611-
state = IPP_PRINTER_STOPPED;
597+
state = IPP_PSTATE_STOPPED;
612598

613599
switch (state)
614600
{
615-
case IPP_PRINTER_IDLE :
601+
case IPP_PSTATE_IDLE :
616602
cupsLangPrintf(stdout, _("%s is ready"), dest);
617603
break;
618-
case IPP_PRINTER_PROCESSING :
619-
cupsLangPrintf(stdout, _("%s is ready and printing"),
620-
dest);
604+
case IPP_PSTATE_PROCESSING :
605+
cupsLangPrintf(stdout, _("%s is ready and printing"), dest);
621606
break;
622-
case IPP_PRINTER_STOPPED :
607+
case IPP_PSTATE_STOPPED :
623608
cupsLangPrintf(stdout, _("%s is not ready"), dest);
624609
break;
625610
}

0 commit comments

Comments
 (0)