4 * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
5 * the Common UNIX Printing System (CUPS).
7 * Copyright 2007-2008 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...
28 #include <cups/string.h>
29 #include <cups/cups.h>
30 #include <cups/i18n.h>
34 * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
37 int /* O - Exit status */
38 main(int argc
, /* I - Number of command-line arguments */
39 char *argv
[]) /* I - Command-line arguments */
41 int i
; /* Looping var */
42 char *command
, /* Command to do */
43 uri
[1024], /* Printer URI */
44 *reason
; /* Reason for reject/disable */
45 ipp_t
*request
; /* IPP request */
46 ipp_op_t op
; /* Operation */
47 int cancel
; /* Cancel jobs? */
53 * See what operation we're supposed to do...
56 if ((command
= strrchr(argv
[0], '/')) != NULL
)
63 if (!strcmp(command
, "cupsaccept") || !strcmp(command
, "accept"))
64 op
= CUPS_ACCEPT_JOBS
;
65 else if (!strcmp(command
, "cupsreject") || !strcmp(command
, "reject"))
66 op
= CUPS_REJECT_JOBS
;
67 else if (!strcmp(command
, "cupsdisable") || !strcmp(command
, "disable"))
68 op
= IPP_PAUSE_PRINTER
;
69 else if (!strcmp(command
, "cupsenable") || !strcmp(command
, "enable"))
70 op
= IPP_RESUME_PRINTER
;
73 _cupsLangPrintf(stderr
, _("%s: Don't know what to do!\n"),
81 * Process command-line arguments...
84 for (i
= 1; i
< argc
; i
++)
85 if (argv
[i
][0] == '-')
89 case 'E' : /* Encrypt */
91 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
93 _cupsLangPrintf(stderr
,
94 _("%s: Sorry, no encryption support compiled in!\n"),
99 case 'U' : /* Username */
100 if (argv
[i
][2] != '\0')
101 cupsSetUser(argv
[i
] + 2);
107 _cupsLangPrintf(stderr
,
108 _("%s: Error - expected username after "
114 cupsSetUser(argv
[i
]);
118 case 'c' : /* Cancel jobs */
122 case 'h' : /* Connect to host */
123 if (argv
[i
][2] != '\0')
124 cupsSetServer(argv
[i
] + 2);
130 _cupsLangPrintf(stderr
,
131 _("%s: Error - expected hostname after "
137 cupsSetServer(argv
[i
]);
141 case 'r' : /* Reason for cancellation */
142 if (argv
[i
][2] != '\0')
143 reason
= argv
[i
] + 2;
149 _cupsLangPrintf(stderr
,
150 _("%s: Error - expected reason text after "
161 if (!strcmp(argv
[i
], "--hold"))
162 op
= IPP_HOLD_NEW_JOBS
;
163 else if (!strcmp(argv
[i
], "--release"))
164 op
= IPP_RELEASE_HELD_NEW_JOBS
;
167 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \'%s\'!\n"),
174 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \'%c\'!\n"),
175 command
, argv
[i
][1]);
182 * Accept/disable/enable/reject a destination...
185 request
= ippNewRequest(op
);
187 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
188 "localhost", 0, "/printers/%s", argv
[i
]);
189 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
190 "printer-uri", NULL
, uri
);
192 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
193 "requesting-user-name", NULL
, cupsUser());
196 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
197 "printer-state-message", NULL
, reason
);
200 * Do the request and get back a response...
203 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
205 if (cupsLastError() > IPP_OK_CONFLICT
)
207 _cupsLangPrintf(stderr
,
208 _("%s: Operation failed: %s\n"),
209 command
, ippErrorString(cupsLastError()));
214 * Cancel all jobs if requested...
220 * Build an IPP_PURGE_JOBS request, which requires the following
224 * attributes-natural-language
228 request
= ippNewRequest(IPP_PURGE_JOBS
);
230 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
231 "printer-uri", NULL
, uri
);
233 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
235 if (cupsLastError() > IPP_OK_CONFLICT
)
237 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());