]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/accept.c
2 * "$Id: accept.c 6649 2007-07-11 21:46:42Z mike $"
4 * "accept", "disable", "enable", and "reject" commands for the Common
5 * UNIX Printing System (CUPS).
7 * Copyright 2007 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...
28 #include <cups/string.h>
29 #include <cups/cups.h>
30 #include <cups/i18n.h>
34 * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
37 int /* O - Exit status */
38 main(int argc
, /* I - Number of command-line arguments */
39 char *argv
[]) /* I - Command-line arguments */
41 http_t
*http
; /* HTTP connection to server */
42 int i
; /* Looping var */
43 char *command
, /* Command to do */
44 uri
[1024], /* Printer URI */
45 *reason
; /* Reason for reject/disable */
46 ipp_t
*request
; /* IPP request */
47 ipp_t
*response
; /* IPP response */
48 ipp_op_t op
; /* Operation */
49 int cancel
; /* Cancel jobs? */
55 * See what operation we're supposed to do...
58 if ((command
= strrchr(argv
[0], '/')) != NULL
)
65 if (!strcmp(command
, "accept"))
66 op
= CUPS_ACCEPT_JOBS
;
67 else if (!strcmp(command
, "reject"))
68 op
= CUPS_REJECT_JOBS
;
69 else if (!strcmp(command
, "cupsdisable") || !strcmp(command
, "disable"))
70 op
= IPP_PAUSE_PRINTER
;
71 else if (!strcmp(command
, "cupsenable") || !strcmp(command
, "enable"))
72 op
= IPP_RESUME_PRINTER
;
75 _cupsLangPrintf(stderr
, _("%s: Don't know what to do!\n"),
84 * Process command-line arguments...
87 for (i
= 1; i
< argc
; i
++)
88 if (argv
[i
][0] == '-')
91 case 'E' : /* Encrypt */
93 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
96 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
98 _cupsLangPrintf(stderr
,
99 _("%s: Sorry, no encryption support compiled in!\n"),
101 #endif /* HAVE_SSL */
104 case 'U' : /* Username */
105 if (argv
[i
][2] != '\0')
106 cupsSetUser(argv
[i
] + 2);
112 _cupsLangPrintf(stderr
,
113 _("%s: Error - expected username after "
119 cupsSetUser(argv
[i
]);
123 case 'c' : /* Cancel jobs */
127 case 'h' : /* Connect to host */
131 if (argv
[i
][2] != '\0')
132 cupsSetServer(argv
[i
] + 2);
138 _cupsLangPrintf(stderr
,
139 _("%s: Error - expected hostname after "
145 cupsSetServer(argv
[i
]);
149 case 'r' : /* Reason for cancellation */
150 if (argv
[i
][2] != '\0')
151 reason
= argv
[i
] + 2;
157 _cupsLangPrintf(stderr
,
158 _("%s: Error - expected reason text after "
169 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \'%c\'!\n"),
170 command
, argv
[i
][1]);
176 * Accept/disable/enable/reject a destination...
180 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
184 _cupsLangPrintf(stderr
,
185 _("%s: Unable to connect to server: %s\n"),
186 command
, strerror(errno
));
191 * Build an IPP request, which requires the following
195 * attributes-natural-language
197 * printer-state-message [optional]
200 request
= ippNewRequest(op
);
202 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
203 "localhost", 0, "/printers/%s", argv
[i
]);
204 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
205 "printer-uri", NULL
, uri
);
207 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
208 "requesting-user-name", NULL
, cupsUser());
211 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
212 "printer-state-message", NULL
, reason
);
215 * Do the request and get back a response...
218 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
220 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
222 _cupsLangPrintf(stderr
,
223 _("%s: Operation failed: %s\n"),
224 command
, ippErrorString(cupsLastError()));
232 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
237 * Cancel all jobs if requested...
243 * Build an IPP_PURGE_JOBS request, which requires the following
247 * attributes-natural-language
251 request
= ippNewRequest(IPP_PURGE_JOBS
);
253 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
254 "printer-uri", NULL
, uri
);
256 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
258 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
260 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
268 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
282 * End of "$Id: accept.c 6649 2007-07-11 21:46:42Z mike $".