2 * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
5 * Copyright © 2007-2018 by Apple Inc.
6 * Copyright © 1997-2006 by Easy Software Products.
8 * Licensed under Apache License v2.0. See the file "LICENSE" for more
13 * Include necessary headers...
16 #include <cups/cups-private.h>
23 static void usage(const char *command
) _CUPS_NORETURN
;
27 * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
30 int /* O - Exit status */
31 main(int argc
, /* I - Number of command-line arguments */
32 char *argv
[]) /* I - Command-line arguments */
34 int i
; /* Looping var */
35 char *command
, /* Command to do */
36 *opt
, /* Option pointer */
37 uri
[1024], /* Printer URI */
38 *reason
; /* Reason for reject/disable */
39 ipp_t
*request
; /* IPP request */
40 ipp_op_t op
; /* Operation */
41 int cancel
; /* Cancel jobs? */
47 * See what operation we're supposed to do...
50 if ((command
= strrchr(argv
[0], '/')) != NULL
)
57 if (!strcmp(command
, "cupsaccept"))
58 op
= CUPS_ACCEPT_JOBS
;
59 else if (!strcmp(command
, "cupsreject"))
60 op
= CUPS_REJECT_JOBS
;
61 else if (!strcmp(command
, "cupsdisable"))
62 op
= IPP_PAUSE_PRINTER
;
63 else if (!strcmp(command
, "cupsenable"))
64 op
= IPP_RESUME_PRINTER
;
67 _cupsLangPrintf(stderr
, _("%s: Don't know what to do."), command
);
74 * Process command-line arguments...
77 for (i
= 1; i
< argc
; i
++)
79 if (!strcmp(argv
[i
], "--help"))
81 else if (!strcmp(argv
[i
], "--hold"))
82 op
= IPP_HOLD_NEW_JOBS
;
83 else if (!strcmp(argv
[i
], "--release"))
84 op
= IPP_RELEASE_HELD_NEW_JOBS
;
85 else if (argv
[i
][0] == '-')
87 for (opt
= argv
[i
] + 1; *opt
; opt
++)
91 case 'E' : /* Encrypt */
93 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
95 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."), command
);
99 case 'U' : /* Username */
102 cupsSetUser(opt
+ 1);
103 opt
+= strlen(opt
) - 1;
110 _cupsLangPrintf(stderr
, _("%s: Error - expected username after \"-U\" option."), command
);
114 cupsSetUser(argv
[i
]);
118 case 'c' : /* Cancel jobs */
122 case 'h' : /* Connect to host */
125 cupsSetServer(opt
+ 1);
126 opt
+= strlen(opt
) - 1;
133 _cupsLangPrintf(stderr
, _("%s: Error - expected hostname after \"-h\" option."), command
);
137 cupsSetServer(argv
[i
]);
141 case 'r' : /* Reason for cancellation */
145 opt
+= strlen(opt
) - 1;
152 _cupsLangPrintf(stderr
, _("%s: Error - expected reason text after \"-r\" option."), command
);
161 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."), command
, *opt
);
169 * Accept/disable/enable/reject a destination...
172 request
= ippNewRequest(op
);
174 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
175 "localhost", 0, "/printers/%s", argv
[i
]);
176 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
177 "printer-uri", NULL
, uri
);
179 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
180 "requesting-user-name", NULL
, cupsUser());
183 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
184 "printer-state-message", NULL
, reason
);
187 * Do the request and get back a response...
190 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
192 if (cupsLastError() > IPP_OK_CONFLICT
)
194 _cupsLangPrintf(stderr
,
195 _("%s: Operation failed: %s"),
196 command
, ippErrorString(cupsLastError()));
201 * Cancel all jobs if requested...
207 * Build an IPP_PURGE_JOBS request, which requires the following
211 * attributes-natural-language
215 request
= ippNewRequest(IPP_PURGE_JOBS
);
217 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
218 "printer-uri", NULL
, uri
);
220 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
222 if (cupsLastError() > IPP_OK_CONFLICT
)
224 _cupsLangPrintf(stderr
, "%s: %s", command
, cupsLastErrorString());
236 * 'usage()' - Show program usage and exit.
240 usage(const char *command
) /* I - Command name */
242 _cupsLangPrintf(stdout
, _("Usage: %s [options] destination(s)"), command
);
243 _cupsLangPuts(stdout
, _("Options:"));
244 _cupsLangPuts(stdout
, _("-E Encrypt the connection to the server"));
245 _cupsLangPuts(stdout
, _("-h server[:port] Connect to the named server and port"));
246 _cupsLangPuts(stdout
, _("-r reason Specify a reason message that others can see"));
247 _cupsLangPuts(stdout
, _("-U username Specify the username to use for authentication"));
248 if (!strcmp(command
, "cupsdisable"))
249 _cupsLangPuts(stdout
, _("--hold Hold new jobs"));
250 if (!strcmp(command
, "cupsenable"))
251 _cupsLangPuts(stdout
, _("--release Release previously held jobs"));