]> git.ipfire.org Git - thirdparty/cups.git/blame - berkeley/lprm.c
Improve performance of web interface with large numbers of jobs (Issue #3819)
[thirdparty/cups.git] / berkeley / lprm.c
CommitLineData
ef416fc2 1/*
503b54c9 2 * "lprm" command for CUPS.
ef416fc2 3 *
503b54c9
MS
4 * Copyright 2007-2010 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 6 *
503b54c9
MS
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 12 */
13
14/*
15 * Include necessary headers...
16 */
17
71e16022 18#include <cups/cups-private.h>
ef416fc2 19
20
21/*
22 * 'main()' - Parse options and cancel jobs.
23 */
24
25int /* O - Exit status */
26main(int argc, /* I - Number of command-line arguments */
27 char *argv[]) /* I - Command-line arguments */
28{
ef416fc2 29 int i; /* Looping var */
30 int job_id; /* Job ID */
5a738aea 31 const char *name; /* Destination printer */
ef416fc2 32 char *instance; /* Pointer to instance name */
5a738aea 33 cups_dest_t *dest, /* Destination */
8ca02f3c 34 *defdest; /* Default destination */
5a738aea 35 int did_cancel; /* Did we cancel something? */
ef416fc2 36
37
07725fee 38 _cupsSetLocale(argv);
d09495fa 39
ef416fc2 40 /*
41 * Setup to cancel individual print jobs...
42 */
43
5a738aea
MS
44 did_cancel = 0;
45 defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
46 name = defdest ? defdest->name : NULL;
8ca02f3c 47
ef416fc2 48 /*
49 * Process command-line arguments...
50 */
51
52 for (i = 1; i < argc; i ++)
53 if (argv[i][0] == '-' && argv[i][1] != '\0')
54 switch (argv[i][1])
55 {
56 case 'E' : /* Encrypt */
57#ifdef HAVE_SSL
5a738aea 58 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
ef416fc2 59#else
fa73b229 60 _cupsLangPrintf(stderr,
0837b7e8 61 _("%s: Sorry, no encryption support."), argv[0]);
ef416fc2 62#endif /* HAVE_SSL */
63 break;
64
65 case 'P' : /* Cancel jobs on a printer */
66 if (argv[i][2])
5a738aea 67 name = argv[i] + 2;
ef416fc2 68 else
69 {
70 i ++;
5a738aea 71 name = argv[i];
ef416fc2 72 }
73
5a738aea 74 if ((instance = strchr(name, '/')) != NULL)
ef416fc2 75 *instance = '\0';
76
5a738aea
MS
77 if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name,
78 NULL)) == NULL)
ef416fc2 79 {
fa73b229 80 _cupsLangPrintf(stderr,
0837b7e8 81 _("%s: Error - unknown destination \"%s\"."),
5a738aea
MS
82 argv[0], name);
83 goto error;
ef416fc2 84 }
5a738aea
MS
85
86 cupsFreeDests(1, dest);
ef416fc2 87 break;
88
fa73b229 89 case 'U' : /* Username */
90 if (argv[i][2] != '\0')
91 cupsSetUser(argv[i] + 2);
92 else
93 {
94 i ++;
95 if (i >= argc)
96 {
97 _cupsLangPrintf(stderr,
98 _("%s: Error - expected username after "
0837b7e8 99 "\"-U\" option."), argv[0]);
5a738aea 100 goto error;
fa73b229 101 }
102
103 cupsSetUser(argv[i]);
104 }
105 break;
503b54c9 106
fa73b229 107 case 'h' : /* Connect to host */
fa73b229 108 if (argv[i][2] != '\0')
109 cupsSetServer(argv[i] + 2);
110 else
111 {
112 i ++;
113
114 if (i >= argc)
115 {
116 _cupsLangPrintf(stderr,
117 _("%s: Error - expected hostname after "
0837b7e8 118 "\"-h\" option."), argv[0]);
5a738aea 119 goto error;
fa73b229 120 }
121 else
122 cupsSetServer(argv[i]);
123 }
8ca02f3c 124
5a738aea
MS
125 if (defdest)
126 cupsFreeDests(1, defdest);
8ca02f3c 127
5a738aea
MS
128 defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
129 name = defdest ? defdest->name : NULL;
fa73b229 130 break;
131
ef416fc2 132 default :
0837b7e8 133 _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."),
fa73b229 134 argv[0], argv[i][1]);
5a738aea 135 goto error;
ef416fc2 136 }
137 else
138 {
139 /*
140 * Cancel a job or printer...
141 */
142
5a738aea
MS
143 if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[i], NULL)) != NULL)
144 cupsFreeDests(1, dest);
145
146 if (dest)
ef416fc2 147 {
5a738aea
MS
148 name = argv[i];
149 job_id = 0;
150 }
151 else if (isdigit(argv[i][0] & 255))
152 {
153 name = NULL;
ef416fc2 154 job_id = atoi(argv[i]);
155 }
fa73b229 156 else if (!strcmp(argv[i], "-"))
ef416fc2 157 {
158 /*
159 * Cancel all jobs
160 */
161
5a738aea 162 job_id = -1;
ef416fc2 163 }
164 else
165 {
0837b7e8 166 _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s\"."),
5a738aea
MS
167 argv[0], argv[i]);
168 goto error;
ef416fc2 169 }
170
5a738aea 171 if (cupsCancelJob2(CUPS_HTTP_DEFAULT, name, job_id, 0) != IPP_OK)
ef416fc2 172 {
0837b7e8 173 _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString());
5a738aea 174 goto error;
ef416fc2 175 }
5a738aea
MS
176
177 did_cancel = 1;
ef416fc2 178 }
179
180 /*
d09495fa 181 * If nothing has been canceled yet, cancel the current job on the specified
ef416fc2 182 * (or default) printer...
183 */
184
5a738aea 185 if (!did_cancel && cupsCancelJob2(CUPS_HTTP_DEFAULT, name, 0, 0) != IPP_OK)
ef416fc2 186 {
0837b7e8 187 _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString());
5a738aea 188 goto error;
ef416fc2 189 }
190
5a738aea
MS
191 if (defdest)
192 cupsFreeDests(1, defdest);
ef416fc2 193
194 return (0);
5a738aea
MS
195
196 /*
197 * If we get here there was an error, so clean up...
198 */
199
200 error:
201
202 if (defdest)
203 cupsFreeDests(1, defdest);
204
205 return (1);
ef416fc2 206}