4 * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
7 * Copyright 2007-2010 by Apple Inc.
8 * Copyright 1997-2006 by Easy Software Products.
10 * These coded instructions, statements, and computer programs are the
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/".
18 * main() - Parse options and accept/reject jobs or disable/enable printers.
22 * Include necessary headers...
25 #include <cups/cups-private.h>
29 * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
32 int /* O - Exit status */
33 main(int argc
, /* I - Number of command-line arguments */
34 char *argv
[]) /* I - Command-line arguments */
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 */
41 ipp_op_t op
; /* Operation */
42 int cancel
; /* Cancel jobs? */
48 * See what operation we're supposed to do...
51 if ((command
= strrchr(argv
[0], '/')) != NULL
)
58 if (!strcmp(command
, "cupsaccept") || !strcmp(command
, "accept"))
59 op
= CUPS_ACCEPT_JOBS
;
60 else if (!strcmp(command
, "cupsreject") || !strcmp(command
, "reject"))
61 op
= CUPS_REJECT_JOBS
;
62 else if (!strcmp(command
, "cupsdisable") || !strcmp(command
, "disable"))
63 op
= IPP_PAUSE_PRINTER
;
64 else if (!strcmp(command
, "cupsenable") || !strcmp(command
, "enable"))
65 op
= IPP_RESUME_PRINTER
;
68 _cupsLangPrintf(stderr
, _("%s: Don't know what to do\n"),
76 * Process command-line arguments...
79 for (i
= 1; i
< argc
; i
++)
80 if (argv
[i
][0] == '-')
84 case 'E' : /* Encrypt */
86 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
88 _cupsLangPrintf(stderr
,
89 _("%s: Sorry, no encryption support compiled in\n"),
94 case 'U' : /* Username */
95 if (argv
[i
][2] != '\0')
96 cupsSetUser(argv
[i
] + 2);
102 _cupsLangPrintf(stderr
,
103 _("%s: Error - expected username after "
109 cupsSetUser(argv
[i
]);
113 case 'c' : /* Cancel jobs */
117 case 'h' : /* Connect to host */
118 if (argv
[i
][2] != '\0')
119 cupsSetServer(argv
[i
] + 2);
125 _cupsLangPrintf(stderr
,
126 _("%s: Error - expected hostname after "
132 cupsSetServer(argv
[i
]);
136 case 'r' : /* Reason for cancellation */
137 if (argv
[i
][2] != '\0')
138 reason
= argv
[i
] + 2;
144 _cupsLangPrintf(stderr
,
145 _("%s: Error - expected reason text after "
156 if (!strcmp(argv
[i
], "--hold"))
157 op
= IPP_HOLD_NEW_JOBS
;
158 else if (!strcmp(argv
[i
], "--release"))
159 op
= IPP_RELEASE_HELD_NEW_JOBS
;
162 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \'%s\'\n"),
169 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \'%c\'\n"),
170 command
, argv
[i
][1]);
177 * Accept/disable/enable/reject a destination...
180 request
= ippNewRequest(op
);
182 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
183 "localhost", 0, "/printers/%s", argv
[i
]);
184 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
185 "printer-uri", NULL
, uri
);
187 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
188 "requesting-user-name", NULL
, cupsUser());
191 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
192 "printer-state-message", NULL
, reason
);
195 * Do the request and get back a response...
198 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
200 if (cupsLastError() > IPP_OK_CONFLICT
)
202 _cupsLangPrintf(stderr
,
203 _("%s: Operation failed: %s\n"),
204 command
, ippErrorString(cupsLastError()));
209 * Cancel all jobs if requested...
215 * Build an IPP_PURGE_JOBS request, which requires the following
219 * attributes-natural-language
223 request
= ippNewRequest(IPP_PURGE_JOBS
);
225 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
226 "printer-uri", NULL
, uri
);
228 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
230 if (cupsLastError() > IPP_OK_CONFLICT
)
232 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());