]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
1f6f3dbc | 2 | * "$Id$" |
ef416fc2 | 3 | * |
61cf44e2 | 4 | * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for |
71e16022 | 5 | * CUPS. |
ef416fc2 | 6 | * |
71e16022 | 7 | * Copyright 2007-2010 by Apple Inc. |
ef416fc2 | 8 | * Copyright 1997-2006 by Easy Software Products. |
9 | * | |
10 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 11 | * property of Apple Inc. and are protected by Federal copyright |
12 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
13 | * which should have been included with this file. If this file is | |
14 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 15 | * |
16 | * Contents: | |
17 | * | |
18 | * main() - Parse options and accept/reject jobs or disable/enable printers. | |
19 | */ | |
20 | ||
21 | /* | |
22 | * Include necessary headers... | |
23 | */ | |
24 | ||
71e16022 | 25 | #include <cups/cups-private.h> |
ef416fc2 | 26 | |
27 | ||
28 | /* | |
29 | * 'main()' - Parse options and accept/reject jobs or disable/enable printers. | |
30 | */ | |
31 | ||
32 | int /* O - Exit status */ | |
33 | main(int argc, /* I - Number of command-line arguments */ | |
34 | char *argv[]) /* I - Command-line arguments */ | |
35 | { | |
ef416fc2 | 36 | int i; /* Looping var */ |
37 | char *command, /* Command to do */ | |
38 | uri[1024], /* Printer URI */ | |
39 | *reason; /* Reason for reject/disable */ | |
40 | ipp_t *request; /* IPP request */ | |
ef416fc2 | 41 | ipp_op_t op; /* Operation */ |
ef416fc2 | 42 | int cancel; /* Cancel jobs? */ |
43 | ||
44 | ||
07725fee | 45 | _cupsSetLocale(argv); |
d09495fa | 46 | |
ef416fc2 | 47 | /* |
48 | * See what operation we're supposed to do... | |
49 | */ | |
50 | ||
51 | if ((command = strrchr(argv[0], '/')) != NULL) | |
52 | command ++; | |
53 | else | |
54 | command = argv[0]; | |
55 | ||
fa73b229 | 56 | cancel = 0; |
ef416fc2 | 57 | |
49d87452 | 58 | if (!strcmp(command, "cupsaccept") || !strcmp(command, "accept")) |
ef416fc2 | 59 | op = CUPS_ACCEPT_JOBS; |
49d87452 | 60 | else if (!strcmp(command, "cupsreject") || !strcmp(command, "reject")) |
ef416fc2 | 61 | op = CUPS_REJECT_JOBS; |
bd7854cb | 62 | else if (!strcmp(command, "cupsdisable") || !strcmp(command, "disable")) |
ef416fc2 | 63 | op = IPP_PAUSE_PRINTER; |
bd7854cb | 64 | else if (!strcmp(command, "cupsenable") || !strcmp(command, "enable")) |
ef416fc2 | 65 | op = IPP_RESUME_PRINTER; |
66 | else | |
67 | { | |
0837b7e8 | 68 | _cupsLangPrintf(stderr, _("%s: Don't know what to do."), command); |
ef416fc2 | 69 | return (1); |
70 | } | |
71 | ||
ef416fc2 | 72 | reason = NULL; |
73 | ||
74 | /* | |
75 | * Process command-line arguments... | |
76 | */ | |
77 | ||
78 | for (i = 1; i < argc; i ++) | |
79 | if (argv[i][0] == '-') | |
61cf44e2 | 80 | { |
ef416fc2 | 81 | switch (argv[i][1]) |
82 | { | |
83 | case 'E' : /* Encrypt */ | |
84 | #ifdef HAVE_SSL | |
85 | cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); | |
ef416fc2 | 86 | #else |
fa73b229 | 87 | _cupsLangPrintf(stderr, |
0837b7e8 | 88 | _("%s: Sorry, no encryption support."), command); |
ef416fc2 | 89 | #endif /* HAVE_SSL */ |
90 | break; | |
91 | ||
fa73b229 | 92 | case 'U' : /* Username */ |
93 | if (argv[i][2] != '\0') | |
94 | cupsSetUser(argv[i] + 2); | |
95 | else | |
96 | { | |
97 | i ++; | |
98 | if (i >= argc) | |
99 | { | |
100 | _cupsLangPrintf(stderr, | |
101 | _("%s: Error - expected username after " | |
0837b7e8 | 102 | "\"-U\" option."), command); |
fa73b229 | 103 | return (1); |
104 | } | |
105 | ||
106 | cupsSetUser(argv[i]); | |
107 | } | |
108 | break; | |
109 | ||
ef416fc2 | 110 | case 'c' : /* Cancel jobs */ |
111 | cancel = 1; | |
112 | break; | |
113 | ||
114 | case 'h' : /* Connect to host */ | |
ef416fc2 | 115 | if (argv[i][2] != '\0') |
116 | cupsSetServer(argv[i] + 2); | |
117 | else | |
118 | { | |
119 | i ++; | |
120 | if (i >= argc) | |
121 | { | |
fa73b229 | 122 | _cupsLangPrintf(stderr, |
123 | _("%s: Error - expected hostname after " | |
0837b7e8 | 124 | "\"-h\" option."), command); |
ef416fc2 | 125 | return (1); |
126 | } | |
127 | ||
128 | cupsSetServer(argv[i]); | |
129 | } | |
130 | break; | |
131 | ||
132 | case 'r' : /* Reason for cancellation */ | |
133 | if (argv[i][2] != '\0') | |
134 | reason = argv[i] + 2; | |
135 | else | |
136 | { | |
137 | i ++; | |
138 | if (i >= argc) | |
139 | { | |
fa73b229 | 140 | _cupsLangPrintf(stderr, |
141 | _("%s: Error - expected reason text after " | |
0837b7e8 | 142 | "\"-r\" option."), command); |
ef416fc2 | 143 | return (1); |
144 | } | |
145 | ||
146 | reason = argv[i]; | |
147 | } | |
148 | break; | |
149 | ||
61cf44e2 MS |
150 | case '-' : |
151 | if (!strcmp(argv[i], "--hold")) | |
152 | op = IPP_HOLD_NEW_JOBS; | |
153 | else if (!strcmp(argv[i], "--release")) | |
154 | op = IPP_RELEASE_HELD_NEW_JOBS; | |
155 | else | |
156 | { | |
0837b7e8 | 157 | _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."), |
61cf44e2 MS |
158 | command, argv[i]); |
159 | return (1); | |
160 | } | |
161 | break; | |
162 | ||
ef416fc2 | 163 | default : |
0837b7e8 | 164 | _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), |
ef416fc2 | 165 | command, argv[i][1]); |
166 | return (1); | |
167 | } | |
61cf44e2 | 168 | } |
ef416fc2 | 169 | else |
170 | { | |
171 | /* | |
172 | * Accept/disable/enable/reject a destination... | |
173 | */ | |
174 | ||
fa73b229 | 175 | request = ippNewRequest(op); |
ef416fc2 | 176 | |
a4d04587 | 177 | httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, |
178 | "localhost", 0, "/printers/%s", argv[i]); | |
ef416fc2 | 179 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, |
180 | "printer-uri", NULL, uri); | |
181 | ||
fa73b229 | 182 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, |
183 | "requesting-user-name", NULL, cupsUser()); | |
184 | ||
ef416fc2 | 185 | if (reason != NULL) |
186 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT, | |
187 | "printer-state-message", NULL, reason); | |
188 | ||
189 | /* | |
190 | * Do the request and get back a response... | |
191 | */ | |
192 | ||
61cf44e2 MS |
193 | ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/admin/")); |
194 | ||
195 | if (cupsLastError() > IPP_OK_CONFLICT) | |
ef416fc2 | 196 | { |
61cf44e2 | 197 | _cupsLangPrintf(stderr, |
0837b7e8 | 198 | _("%s: Operation failed: %s"), |
61cf44e2 | 199 | command, ippErrorString(cupsLastError())); |
ef416fc2 | 200 | return (1); |
201 | } | |
202 | ||
203 | /* | |
204 | * Cancel all jobs if requested... | |
205 | */ | |
206 | ||
207 | if (cancel) | |
208 | { | |
209 | /* | |
210 | * Build an IPP_PURGE_JOBS request, which requires the following | |
211 | * attributes: | |
212 | * | |
213 | * attributes-charset | |
214 | * attributes-natural-language | |
215 | * printer-uri | |
216 | */ | |
217 | ||
fa73b229 | 218 | request = ippNewRequest(IPP_PURGE_JOBS); |
ef416fc2 | 219 | |
220 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, | |
221 | "printer-uri", NULL, uri); | |
222 | ||
61cf44e2 | 223 | ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/admin/")); |
ef416fc2 | 224 | |
61cf44e2 | 225 | if (cupsLastError() > IPP_OK_CONFLICT) |
ef416fc2 | 226 | { |
0837b7e8 | 227 | _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString()); |
ef416fc2 | 228 | return (1); |
229 | } | |
230 | } | |
231 | } | |
232 | ||
ef416fc2 | 233 | return (0); |
234 | } | |
235 | ||
236 | ||
237 | /* | |
1f6f3dbc | 238 | * End of "$Id$". |
ef416fc2 | 239 | */ |