Skip to content

Commit

Permalink
lpstat.c: Implement successful filter for jobs
Browse files Browse the repository at this point in the history
Introduce a new argument value 'successful' in lpstat to get jobs which completed successfully without introducing a new IPP value for IPP attribute 'which-jobs'

Together with #832 fixes #828 .
  • Loading branch information
zdohnal authored Nov 24, 2023
2 parents 17985bb + b97301d commit 7ba5634
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/help/man-lpstat.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h2 id="lpstat-1.options">Options</h2>
Specifies an alternate username.
</p>
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>-W </strong><em>which-jobs</em><br>
Specifies which jobs to show, &quot;completed&quot; or &quot;not-completed&quot; (the default).
Specifies which jobs to show, &quot;all&quot;, &quot;successful&quot;, &quot;completed&quot; or &quot;not-completed&quot; (the default).
This option <em>must</em> appear before the <em>-o</em> option and/or any printer names, otherwise the default (&quot;not-completed&quot;) value will be used in the request to the scheduler.
</p>
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>-a </strong>[<em>printer(s)</em>]<br>
Expand Down
2 changes: 1 addition & 1 deletion man/lpstat.1
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Shows the ranking of print jobs.
Specifies an alternate username.
.TP 5
\fB\-W \fIwhich-jobs\fR
Specifies which jobs to show, "completed" or "not-completed" (the default).
Specifies which jobs to show, "all, "successful", "completed" or "not-completed" (the default).
This option \fImust\fR appear before the \fI-o\fR option and/or any printer names, otherwise the default ("not-completed") value will be used in the request to the scheduler.
.TP 5
\fB\-a \fR[\fIprinter(s)\fR]
Expand Down
17 changes: 11 additions & 6 deletions systemv/lpstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ main(int argc, /* I - Number of command-line arguments */

if (i >= argc)
{
_cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv[0]);
_cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", \"successful\", or \"all\" after \"-W\" option."), argv[0]);
usage();
}

which = argv[i];
}

if (strcmp(which, "completed") && strcmp(which, "not-completed") && strcmp(which, "all"))
if (strcmp(which, "completed") && strcmp(which, "not-completed") && strcmp(which, "all") && strcmp(which, "successful"))
{
_cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv[0]);
_cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", \"successful\", or \"all\" after \"-W\" option."), argv[0]);
usage();
}
break;
Expand Down Expand Up @@ -1358,7 +1358,7 @@ show_jobs(const char *dests, /* I - Destinations */
NULL, cupsGetUser());

ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs",
NULL, which);
NULL, !strcmp(which, "successful") ? "completed" : which);

/*
* Do the request and get back a response...
Expand Down Expand Up @@ -1396,6 +1396,7 @@ show_jobs(const char *dests, /* I - Destinations */

if (!strcmp(which, "aborted") ||
!strcmp(which, "canceled") ||
!strcmp(which, "successful") ||
!strcmp(which, "completed"))
time_at = "time-at-completed";
else
Expand Down Expand Up @@ -1476,7 +1477,11 @@ show_jobs(const char *dests, /* I - Destinations */

if (match_list(dests, dest) && match_list(users, username))
{
snprintf(temp, sizeof(temp), "%s-%d", dest, jobid);
if (!strcmp(which, "successful") && (!reasons || (reasons &&
strcmp(reasons->values[0].string.text, "job-completed-successfully"))))
continue;

snprintf(temp, sizeof(temp), "%s-%d", dest, jobid);

_cupsStrDate(date, sizeof(date), jobtime);

Expand Down Expand Up @@ -1557,7 +1562,7 @@ show_printers(const char *printers, /* I - Destinations */
int jobid; /* Job ID of current job */
char printer_uri[HTTP_MAX_URI],
/* Printer URI */
printer_state_time[255];/* Printer state time */
printer_state_time[255];/* Printer state time */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
static const char *pattrs[] = /* Attributes we need for printers... */
{
Expand Down

0 comments on commit 7ba5634

Please sign in to comment.