]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/accept.c
2 * "$Id: accept.c 7221 2008-01-16 22:20:08Z mike $"
4 * "accept", "disable", "enable", and "reject" commands for the Common
5 * UNIX Printing System (CUPS).
7 * Copyright 2007-2008 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 */
134 if (argv
[i
][2] != '\0')
135 cupsSetServer(argv
[i
] + 2);
141 _cupsLangPrintf(stderr
,
142 _("%s: Error - expected hostname after "
148 cupsSetServer(argv
[i
]);
152 case 'r' : /* Reason for cancellation */
153 if (argv
[i
][2] != '\0')
154 reason
= argv
[i
] + 2;
160 _cupsLangPrintf(stderr
,
161 _("%s: Error - expected reason text after "
172 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \'%c\'!\n"),
173 command
, argv
[i
][1]);
179 * Accept/disable/enable/reject a destination...
183 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
187 _cupsLangPrintf(stderr
,
188 _("%s: Unable to connect to server: %s\n"),
189 command
, strerror(errno
));
194 * Build an IPP request, which requires the following
198 * attributes-natural-language
200 * printer-state-message [optional]
203 request
= ippNewRequest(op
);
205 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
206 "localhost", 0, "/printers/%s", argv
[i
]);
207 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
208 "printer-uri", NULL
, uri
);
210 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
211 "requesting-user-name", NULL
, cupsUser());
214 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
215 "printer-state-message", NULL
, reason
);
218 * Do the request and get back a response...
221 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
223 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
225 _cupsLangPrintf(stderr
,
226 _("%s: Operation failed: %s\n"),
227 command
, ippErrorString(cupsLastError()));
235 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
240 * Cancel all jobs if requested...
246 * Build an IPP_PURGE_JOBS request, which requires the following
250 * attributes-natural-language
254 request
= ippNewRequest(IPP_PURGE_JOBS
);
256 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
257 "printer-uri", NULL
, uri
);
259 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
261 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
263 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
271 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
285 * End of "$Id: accept.c 7221 2008-01-16 22:20:08Z mike $".