]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/accept.c
2 * "$Id: accept.c 5104 2006-02-15 03:21:04Z mike $"
4 * "accept", "disable", "enable", and "reject" commands for the Common
5 * UNIX Printing System (CUPS).
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Easy Software Products and are protected by Federal
11 * copyright law. Distribution and use rights are outlined in the file
12 * "LICENSE.txt" which should have been included with this file. If this
13 * file is missing or damaged please contact Easy Software Products
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636 USA
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
27 * main() - Parse options and accept/reject jobs or disable/enable printers.
31 * Include necessary headers...
37 #include <cups/string.h>
38 #include <cups/cups.h>
39 #include <cups/i18n.h>
43 * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
46 int /* O - Exit status */
47 main(int argc
, /* I - Number of command-line arguments */
48 char *argv
[]) /* I - Command-line arguments */
50 http_t
*http
; /* HTTP connection to server */
51 int i
; /* Looping var */
52 char *command
, /* Command to do */
53 uri
[1024], /* Printer URI */
54 *reason
; /* Reason for reject/disable */
55 ipp_t
*request
; /* IPP request */
56 ipp_t
*response
; /* IPP response */
57 ipp_op_t op
; /* Operation */
58 int cancel
; /* Cancel jobs? */
62 * See what operation we're supposed to do...
65 if ((command
= strrchr(argv
[0], '/')) != NULL
)
72 if (!strcmp(command
, "accept"))
73 op
= CUPS_ACCEPT_JOBS
;
74 else if (!strcmp(command
, "reject"))
75 op
= CUPS_REJECT_JOBS
;
76 else if (!strcmp(command
, "cupsdisable") || !strcmp(command
, "disable"))
77 op
= IPP_PAUSE_PRINTER
;
78 else if (!strcmp(command
, "cupsenable") || !strcmp(command
, "enable"))
79 op
= IPP_RESUME_PRINTER
;
82 _cupsLangPrintf(stderr
, _("%s: Don't know what to do!\n"),
91 * Process command-line arguments...
94 for (i
= 1; i
< argc
; i
++)
95 if (argv
[i
][0] == '-')
98 case 'E' : /* Encrypt */
100 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
103 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
105 _cupsLangPrintf(stderr
,
106 _("%s: Sorry, no encryption support compiled in!\n"),
108 #endif /* HAVE_SSL */
111 case 'U' : /* Username */
112 if (argv
[i
][2] != '\0')
113 cupsSetUser(argv
[i
] + 2);
119 _cupsLangPrintf(stderr
,
120 _("%s: Error - expected username after "
126 cupsSetUser(argv
[i
]);
130 case 'c' : /* Cancel jobs */
134 case 'h' : /* Connect to host */
138 if (argv
[i
][2] != '\0')
139 cupsSetServer(argv
[i
] + 2);
145 _cupsLangPrintf(stderr
,
146 _("%s: Error - expected hostname after "
152 cupsSetServer(argv
[i
]);
156 case 'r' : /* Reason for cancellation */
157 if (argv
[i
][2] != '\0')
158 reason
= argv
[i
] + 2;
164 _cupsLangPrintf(stderr
,
165 _("%s: Error - expected reason text after "
176 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \'%c\'!\n"),
177 command
, argv
[i
][1]);
183 * Accept/disable/enable/reject a destination...
187 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
191 _cupsLangPrintf(stderr
,
192 _("%s: Unable to connect to server: %s\n"),
193 command
, strerror(errno
));
198 * Build an IPP request, which requires the following
202 * attributes-natural-language
204 * printer-state-message [optional]
207 request
= ippNewRequest(op
);
209 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
210 "localhost", 0, "/printers/%s", argv
[i
]);
211 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
212 "printer-uri", NULL
, uri
);
214 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
215 "requesting-user-name", NULL
, cupsUser());
218 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
219 "printer-state-message", NULL
, reason
);
222 * Do the request and get back a response...
225 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
227 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
229 _cupsLangPrintf(stderr
,
230 _("%s: Operation failed: %s\n"),
231 command
, ippErrorString(cupsLastError()));
239 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
244 * Cancel all jobs if requested...
250 * Build an IPP_PURGE_JOBS request, which requires the following
254 * attributes-natural-language
258 request
= ippNewRequest(IPP_PURGE_JOBS
);
260 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
261 "printer-uri", NULL
, uri
);
263 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
265 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
267 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
275 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
289 * End of "$Id: accept.c 5104 2006-02-15 03:21:04Z mike $".