2 * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
5 * Copyright 2007-2017 by Apple Inc.
6 * Copyright 1997-2006 by Easy Software Products.
8 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
12 * Include necessary headers...
15 #include <cups/cups-private.h>
19 * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
22 int /* O - Exit status */
23 main(int argc
, /* I - Number of command-line arguments */
24 char *argv
[]) /* I - Command-line arguments */
26 int i
; /* Looping var */
27 char *command
, /* Command to do */
28 *opt
, /* Option pointer */
29 uri
[1024], /* Printer URI */
30 *reason
; /* Reason for reject/disable */
31 ipp_t
*request
; /* IPP request */
32 ipp_op_t op
; /* Operation */
33 int cancel
; /* Cancel jobs? */
39 * See what operation we're supposed to do...
42 if ((command
= strrchr(argv
[0], '/')) != NULL
)
49 if (!strcmp(command
, "cupsaccept") || !strcmp(command
, "accept"))
50 op
= CUPS_ACCEPT_JOBS
;
51 else if (!strcmp(command
, "cupsreject") || !strcmp(command
, "reject"))
52 op
= CUPS_REJECT_JOBS
;
53 else if (!strcmp(command
, "cupsdisable") || !strcmp(command
, "disable"))
54 op
= IPP_PAUSE_PRINTER
;
55 else if (!strcmp(command
, "cupsenable") || !strcmp(command
, "enable"))
56 op
= IPP_RESUME_PRINTER
;
59 _cupsLangPrintf(stderr
, _("%s: Don't know what to do."), command
);
66 * Process command-line arguments...
69 for (i
= 1; i
< argc
; i
++)
71 if (!strcmp(argv
[i
], "--hold"))
72 op
= IPP_HOLD_NEW_JOBS
;
73 else if (!strcmp(argv
[i
], "--release"))
74 op
= IPP_RELEASE_HELD_NEW_JOBS
;
75 else if (argv
[i
][0] == '-')
77 for (opt
= argv
[i
] + 1; *opt
; opt
++)
81 case 'E' : /* Encrypt */
83 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
85 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."), command
);
89 case 'U' : /* Username */
93 opt
+= strlen(opt
) - 1;
100 _cupsLangPrintf(stderr
, _("%s: Error - expected username after \"-U\" option."), command
);
104 cupsSetUser(argv
[i
]);
108 case 'c' : /* Cancel jobs */
112 case 'h' : /* Connect to host */
115 cupsSetServer(opt
+ 1);
116 opt
+= strlen(opt
) - 1;
123 _cupsLangPrintf(stderr
, _("%s: Error - expected hostname after \"-h\" option."), command
);
127 cupsSetServer(argv
[i
]);
131 case 'r' : /* Reason for cancellation */
135 opt
+= strlen(opt
) - 1;
142 _cupsLangPrintf(stderr
, _("%s: Error - expected reason text after \"-r\" option."), command
);
151 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."), command
, *opt
);
159 * Accept/disable/enable/reject a destination...
162 request
= ippNewRequest(op
);
164 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
165 "localhost", 0, "/printers/%s", argv
[i
]);
166 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
167 "printer-uri", NULL
, uri
);
169 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
170 "requesting-user-name", NULL
, cupsUser());
173 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
174 "printer-state-message", NULL
, reason
);
177 * Do the request and get back a response...
180 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
182 if (cupsLastError() > IPP_OK_CONFLICT
)
184 _cupsLangPrintf(stderr
,
185 _("%s: Operation failed: %s"),
186 command
, ippErrorString(cupsLastError()));
191 * Cancel all jobs if requested...
197 * Build an IPP_PURGE_JOBS request, which requires the following
201 * attributes-natural-language
205 request
= ippNewRequest(IPP_PURGE_JOBS
);
207 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
208 "printer-uri", NULL
, uri
);
210 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/admin/"));
212 if (cupsLastError() > IPP_OK_CONFLICT
)
214 _cupsLangPrintf(stderr
, "%s: %s", command
, cupsLastErrorString());