2 * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
5 * Copyright 2007-2010 by Apple Inc.
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
16 * Include necessary headers...
19 #include <cups/cups-private.h>
23 * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
26 int /* O - Exit status */
27 main(int argc
, /* I - Number of command-line arguments */
28 char *argv
[]) /* I - Command-line arguments */
30 int i
; /* Looping var */
31 char *command
, /* Command to do */
32 uri
[1024], /* Printer URI */
33 *reason
; /* Reason for reject/disable */
34 ipp_t
*request
; /* IPP request */
35 ipp_op_t op
; /* Operation */
36 int cancel
; /* Cancel jobs? */
42 * See what operation we're supposed to do...
45 if ((command
= strrchr(argv
[0], '/')) != NULL
)
52 if (!strcmp(command
, "cupsaccept") || !strcmp(command
, "accept"))
53 op
= CUPS_ACCEPT_JOBS
;
54 else if (!strcmp(command
, "cupsreject") || !strcmp(command
, "reject"))
55 op
= CUPS_REJECT_JOBS
;
56 else if (!strcmp(command
, "cupsdisable") || !strcmp(command
, "disable"))
57 op
= IPP_PAUSE_PRINTER
;
58 else if (!strcmp(command
, "cupsenable") || !strcmp(command
, "enable"))
59 op
= IPP_RESUME_PRINTER
;
62 _cupsLangPrintf(stderr
, _("%s: Don't know what to do."), command
);
69 * Process command-line arguments...
72 for (i
= 1; i
< argc
; i
++)
73 if (argv
[i
][0] == '-')
77 case 'E' : /* Encrypt */
79 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
81 _cupsLangPrintf(stderr
,
82 _("%s: Sorry, no encryption support."), command
);
86 case 'U' : /* Username */
87 if (argv
[i
][2] != '\0')
88 cupsSetUser(argv
[i
] + 2);
94 _cupsLangPrintf(stderr
,
95 _("%s: Error - expected username after "
96 "\"-U\" option."), command
);
100 cupsSetUser(argv
[i
]);
104 case 'c' : /* Cancel jobs */
108 case 'h' : /* Connect to host */
109 if (argv
[i
][2] != '\0')
110 cupsSetServer(argv
[i
] + 2);
116 _cupsLangPrintf(stderr
,
117 _("%s: Error - expected hostname after "
118 "\"-h\" option."), command
);
122 cupsSetServer(argv
[i
]);
126 case 'r' : /* Reason for cancellation */
127 if (argv
[i
][2] != '\0')
128 reason
= argv
[i
] + 2;
134 _cupsLangPrintf(stderr
,
135 _("%s: Error - expected reason text after "
136 "\"-r\" option."), command
);
145 if (!strcmp(argv
[i
], "--hold"))
146 op
= IPP_HOLD_NEW_JOBS
;
147 else if (!strcmp(argv
[i
], "--release"))
148 op
= IPP_RELEASE_HELD_NEW_JOBS
;
151 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%s\"."),
158 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."),
159 command
, argv
[i
][1]);
166 * Accept/disable/enable/reject a destination...
169 request
= ippNewRequest(op
);
171 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
172 "localhost", 0, "/printers/%s", argv
[i
]);
173 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
174 "printer-uri", NULL
, uri
);
176 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
177 "requesting-user-name", NULL
, cupsUser());
180 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
181 "printer-state-message", NULL
, reason
);
184 * Do the request and get back a response...
187 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
189 if (cupsLastError() > IPP_OK_CONFLICT
)
191 _cupsLangPrintf(stderr
,
192 _("%s: Operation failed: %s"),
193 command
, ippErrorString(cupsLastError()));
198 * Cancel all jobs if requested...
204 * Build an IPP_PURGE_JOBS request, which requires the following
208 * attributes-natural-language
212 request
= ippNewRequest(IPP_PURGE_JOBS
);
214 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
215 "printer-uri", NULL
, uri
);
217 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
219 if (cupsLastError() > IPP_OK_CONFLICT
)
221 _cupsLangPrintf(stderr
, "%s: %s", command
, cupsLastErrorString());