]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
503b54c9 | 2 | * "lprm" command for CUPS. |
ef416fc2 | 3 | * |
bdbfacc7 | 4 | * Copyright 2007-2016 by Apple Inc. |
503b54c9 | 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 | ||
25 | int /* O - Exit status */ | |
26 | main(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 */ |
bdbfacc7 MS |
32 | char *instance, /* Pointer to instance name */ |
33 | *opt; /* Option pointer */ | |
5a738aea | 34 | cups_dest_t *dest, /* Destination */ |
8ca02f3c | 35 | *defdest; /* Default destination */ |
5a738aea | 36 | int did_cancel; /* Did we cancel something? */ |
ef416fc2 | 37 | |
38 | ||
07725fee | 39 | _cupsSetLocale(argv); |
d09495fa | 40 | |
ef416fc2 | 41 | /* |
42 | * Setup to cancel individual print jobs... | |
43 | */ | |
44 | ||
5a738aea MS |
45 | did_cancel = 0; |
46 | defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); | |
47 | name = defdest ? defdest->name : NULL; | |
8ca02f3c | 48 | |
ef416fc2 | 49 | /* |
50 | * Process command-line arguments... | |
51 | */ | |
52 | ||
53 | for (i = 1; i < argc; i ++) | |
bdbfacc7 | 54 | { |
ef416fc2 | 55 | if (argv[i][0] == '-' && argv[i][1] != '\0') |
bdbfacc7 MS |
56 | { |
57 | for (opt = argv[i] + 1; *opt; opt ++) | |
ef416fc2 | 58 | { |
bdbfacc7 MS |
59 | switch (*opt) |
60 | { | |
61 | case 'E' : /* Encrypt */ | |
ef416fc2 | 62 | #ifdef HAVE_SSL |
bdbfacc7 | 63 | cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); |
ef416fc2 | 64 | #else |
bdbfacc7 | 65 | _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); |
ef416fc2 | 66 | #endif /* HAVE_SSL */ |
bdbfacc7 MS |
67 | break; |
68 | ||
69 | case 'P' : /* Cancel jobs on a printer */ | |
70 | if (opt[1] != '\0') | |
fa73b229 | 71 | { |
bdbfacc7 MS |
72 | name = opt + 1; |
73 | opt += strlen(opt) - 1; | |
74 | } | |
75 | else | |
76 | { | |
77 | i ++; | |
78 | name = argv[i]; | |
fa73b229 | 79 | } |
80 | ||
bdbfacc7 MS |
81 | if ((instance = strchr(name, '/')) != NULL) |
82 | *instance = '\0'; | |
fa73b229 | 83 | |
bdbfacc7 | 84 | if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name, NULL)) == NULL) |
fa73b229 | 85 | { |
bdbfacc7 | 86 | _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s\"."), argv[0], name); |
5a738aea | 87 | goto error; |
bdbfacc7 MS |
88 | } |
89 | ||
90 | cupsFreeDests(1, dest); | |
91 | break; | |
92 | ||
93 | case 'U' : /* Username */ | |
94 | if (opt[1] != '\0') | |
95 | { | |
96 | cupsSetUser(opt + 1); | |
97 | opt += strlen(opt) - 1; | |
98 | } | |
99 | else | |
100 | { | |
101 | i ++; | |
102 | if (i >= argc) | |
103 | { | |
104 | _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]); | |
105 | goto error; | |
106 | } | |
107 | ||
108 | cupsSetUser(argv[i]); | |
109 | } | |
110 | break; | |
111 | ||
112 | case 'h' : /* Connect to host */ | |
113 | if (opt[1] != '\0') | |
114 | { | |
115 | cupsSetServer(opt + 1); | |
116 | opt += strlen(opt) - 1; | |
117 | } | |
fa73b229 | 118 | else |
bdbfacc7 MS |
119 | { |
120 | i ++; | |
121 | ||
122 | if (i >= argc) | |
123 | { | |
124 | _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]); | |
125 | goto error; | |
126 | } | |
127 | else | |
128 | cupsSetServer(argv[i]); | |
129 | } | |
8ca02f3c | 130 | |
bdbfacc7 MS |
131 | if (defdest) |
132 | cupsFreeDests(1, defdest); | |
8ca02f3c | 133 | |
bdbfacc7 MS |
134 | defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); |
135 | name = defdest ? defdest->name : NULL; | |
136 | break; | |
fa73b229 | 137 | |
bdbfacc7 MS |
138 | default : |
139 | _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], *opt); | |
140 | goto error; | |
141 | } | |
ef416fc2 | 142 | } |
bdbfacc7 | 143 | } |
ef416fc2 | 144 | else |
145 | { | |
146 | /* | |
147 | * Cancel a job or printer... | |
148 | */ | |
149 | ||
5a738aea MS |
150 | if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[i], NULL)) != NULL) |
151 | cupsFreeDests(1, dest); | |
152 | ||
153 | if (dest) | |
ef416fc2 | 154 | { |
5a738aea MS |
155 | name = argv[i]; |
156 | job_id = 0; | |
157 | } | |
158 | else if (isdigit(argv[i][0] & 255)) | |
159 | { | |
160 | name = NULL; | |
ef416fc2 | 161 | job_id = atoi(argv[i]); |
162 | } | |
fa73b229 | 163 | else if (!strcmp(argv[i], "-")) |
ef416fc2 | 164 | { |
165 | /* | |
166 | * Cancel all jobs | |
167 | */ | |
168 | ||
5a738aea | 169 | job_id = -1; |
ef416fc2 | 170 | } |
171 | else | |
172 | { | |
0837b7e8 | 173 | _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s\"."), |
5a738aea MS |
174 | argv[0], argv[i]); |
175 | goto error; | |
ef416fc2 | 176 | } |
177 | ||
5a738aea | 178 | if (cupsCancelJob2(CUPS_HTTP_DEFAULT, name, job_id, 0) != IPP_OK) |
ef416fc2 | 179 | { |
0837b7e8 | 180 | _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString()); |
5a738aea | 181 | goto error; |
ef416fc2 | 182 | } |
5a738aea MS |
183 | |
184 | did_cancel = 1; | |
ef416fc2 | 185 | } |
bdbfacc7 | 186 | } |
ef416fc2 | 187 | |
188 | /* | |
d09495fa | 189 | * If nothing has been canceled yet, cancel the current job on the specified |
ef416fc2 | 190 | * (or default) printer... |
191 | */ | |
192 | ||
5a738aea | 193 | if (!did_cancel && cupsCancelJob2(CUPS_HTTP_DEFAULT, name, 0, 0) != IPP_OK) |
ef416fc2 | 194 | { |
0837b7e8 | 195 | _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString()); |
5a738aea | 196 | goto error; |
ef416fc2 | 197 | } |
198 | ||
5a738aea MS |
199 | if (defdest) |
200 | cupsFreeDests(1, defdest); | |
ef416fc2 | 201 | |
202 | return (0); | |
5a738aea MS |
203 | |
204 | /* | |
205 | * If we get here there was an error, so clean up... | |
206 | */ | |
207 | ||
208 | error: | |
209 | ||
210 | if (defdest) | |
211 | cupsFreeDests(1, defdest); | |
212 | ||
213 | return (1); | |
ef416fc2 | 214 | } |