2 * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
5 * Copyright 2007-2016 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 * 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 *opt
, /* Option pointer */
33 uri
[1024], /* Printer URI */
34 *reason
; /* Reason for reject/disable */
35 ipp_t
*request
; /* IPP request */
36 ipp_op_t op
; /* Operation */
37 int cancel
; /* Cancel jobs? */
43 * See what operation we're supposed to do...
46 if ((command
= strrchr(argv
[0], '/')) != NULL
)
53 if (!strcmp(command
, "cupsaccept") || !strcmp(command
, "accept"))
54 op
= CUPS_ACCEPT_JOBS
;
55 else if (!strcmp(command
, "cupsreject") || !strcmp(command
, "reject"))
56 op
= CUPS_REJECT_JOBS
;
57 else if (!strcmp(command
, "cupsdisable") || !strcmp(command
, "disable"))
58 op
= IPP_PAUSE_PRINTER
;
59 else if (!strcmp(command
, "cupsenable") || !strcmp(command
, "enable"))
60 op
= IPP_RESUME_PRINTER
;
63 _cupsLangPrintf(stderr
, _("%s: Don't know what to do."), command
);
70 * Process command-line arguments...
73 for (i
= 1; i
< argc
; i
++)
75 if (!strcmp(argv
[i
], "--hold"))
76 op
= IPP_HOLD_NEW_JOBS
;
77 else if (!strcmp(argv
[i
], "--release"))
78 op
= IPP_RELEASE_HELD_NEW_JOBS
;
79 else if (argv
[i
][0] == '-')
81 for (opt
= argv
[i
] + 1; *opt
; opt
++)
85 case 'E' : /* Encrypt */
87 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
89 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."), command
);
93 case 'U' : /* Username */
97 opt
+= strlen(opt
) - 1;
104 _cupsLangPrintf(stderr
, _("%s: Error - expected username after \"-U\" option."), command
);
108 cupsSetUser(argv
[i
]);
112 case 'c' : /* Cancel jobs */
116 case 'h' : /* Connect to host */
119 cupsSetServer(opt
+ 1);
120 opt
+= strlen(opt
) - 1;
127 _cupsLangPrintf(stderr
, _("%s: Error - expected hostname after \"-h\" option."), command
);
131 cupsSetServer(argv
[i
]);
135 case 'r' : /* Reason for cancellation */
139 opt
+= strlen(opt
) - 1;
146 _cupsLangPrintf(stderr
, _("%s: Error - expected reason text after \"-r\" option."), command
);
155 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."), command
, *opt
);
163 * Accept/disable/enable/reject a destination...
166 request
= ippNewRequest(op
);
168 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
169 "localhost", 0, "/printers/%s", argv
[i
]);
170 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
171 "printer-uri", NULL
, uri
);
173 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
174 "requesting-user-name", NULL
, cupsUser());
177 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
178 "printer-state-message", NULL
, reason
);
181 * Do the request and get back a response...
184 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
186 if (cupsLastError() > IPP_OK_CONFLICT
)
188 _cupsLangPrintf(stderr
,
189 _("%s: Operation failed: %s"),
190 command
, ippErrorString(cupsLastError()));
195 * Cancel all jobs if requested...
201 * Build an IPP_PURGE_JOBS request, which requires the following
205 * attributes-natural-language
209 request
= ippNewRequest(IPP_PURGE_JOBS
);
211 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
212 "printer-uri", NULL
, uri
);
214 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
216 if (cupsLastError() > IPP_OK_CONFLICT
)
218 _cupsLangPrintf(stderr
, "%s: %s", command
, cupsLastErrorString());