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."), command
);
75 * Process command-line arguments...
78 for (i
= 1; i
< argc
; i
++)
79 if (argv
[i
][0] == '-')
83 case 'E' : /* Encrypt */
85 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
87 _cupsLangPrintf(stderr
,
88 _("%s: Sorry, no encryption support."), command
);
92 case 'U' : /* Username */
93 if (argv
[i
][2] != '\0')
94 cupsSetUser(argv
[i
] + 2);
100 _cupsLangPrintf(stderr
,
101 _("%s: Error - expected username after "
102 "\"-U\" option."), command
);
106 cupsSetUser(argv
[i
]);
110 case 'c' : /* Cancel jobs */
114 case 'h' : /* Connect to host */
115 if (argv
[i
][2] != '\0')
116 cupsSetServer(argv
[i
] + 2);
122 _cupsLangPrintf(stderr
,
123 _("%s: Error - expected hostname after "
124 "\"-h\" option."), command
);
128 cupsSetServer(argv
[i
]);
132 case 'r' : /* Reason for cancellation */
133 if (argv
[i
][2] != '\0')
134 reason
= argv
[i
] + 2;
140 _cupsLangPrintf(stderr
,
141 _("%s: Error - expected reason text after "
142 "\"-r\" option."), command
);
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
;
157 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%s\"."),
164 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."),
165 command
, argv
[i
][1]);
172 * Accept/disable/enable/reject a destination...
175 request
= ippNewRequest(op
);
177 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
178 "localhost", 0, "/printers/%s", argv
[i
]);
179 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
180 "printer-uri", NULL
, uri
);
182 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
183 "requesting-user-name", NULL
, cupsUser());
186 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
187 "printer-state-message", NULL
, reason
);
190 * Do the request and get back a response...
193 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
195 if (cupsLastError() > IPP_OK_CONFLICT
)
197 _cupsLangPrintf(stderr
,
198 _("%s: Operation failed: %s"),
199 command
, ippErrorString(cupsLastError()));
204 * Cancel all jobs if requested...
210 * Build an IPP_PURGE_JOBS request, which requires the following
214 * attributes-natural-language
218 request
= ippNewRequest(IPP_PURGE_JOBS
);
220 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
221 "printer-uri", NULL
, uri
);
223 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
225 if (cupsLastError() > IPP_OK_CONFLICT
)
227 _cupsLangPrintf(stderr
, "%s: %s", command
, cupsLastErrorString());