]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/accept.c
2 * "$Id: accept.c 5925 2006-09-05 19:43:11Z 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? */
64 * See what operation we're supposed to do...
67 if ((command
= strrchr(argv
[0], '/')) != NULL
)
74 if (!strcmp(command
, "accept"))
75 op
= CUPS_ACCEPT_JOBS
;
76 else if (!strcmp(command
, "reject"))
77 op
= CUPS_REJECT_JOBS
;
78 else if (!strcmp(command
, "cupsdisable") || !strcmp(command
, "disable"))
79 op
= IPP_PAUSE_PRINTER
;
80 else if (!strcmp(command
, "cupsenable") || !strcmp(command
, "enable"))
81 op
= IPP_RESUME_PRINTER
;
84 _cupsLangPrintf(stderr
, _("%s: Don't know what to do!\n"),
93 * Process command-line arguments...
96 for (i
= 1; i
< argc
; i
++)
97 if (argv
[i
][0] == '-')
100 case 'E' : /* Encrypt */
102 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
105 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
107 _cupsLangPrintf(stderr
,
108 _("%s: Sorry, no encryption support compiled in!\n"),
110 #endif /* HAVE_SSL */
113 case 'U' : /* Username */
114 if (argv
[i
][2] != '\0')
115 cupsSetUser(argv
[i
] + 2);
121 _cupsLangPrintf(stderr
,
122 _("%s: Error - expected username after "
128 cupsSetUser(argv
[i
]);
132 case 'c' : /* Cancel jobs */
136 case 'h' : /* Connect to host */
140 if (argv
[i
][2] != '\0')
141 cupsSetServer(argv
[i
] + 2);
147 _cupsLangPrintf(stderr
,
148 _("%s: Error - expected hostname after "
154 cupsSetServer(argv
[i
]);
158 case 'r' : /* Reason for cancellation */
159 if (argv
[i
][2] != '\0')
160 reason
= argv
[i
] + 2;
166 _cupsLangPrintf(stderr
,
167 _("%s: Error - expected reason text after "
178 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \'%c\'!\n"),
179 command
, argv
[i
][1]);
185 * Accept/disable/enable/reject a destination...
189 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
193 _cupsLangPrintf(stderr
,
194 _("%s: Unable to connect to server: %s\n"),
195 command
, strerror(errno
));
200 * Build an IPP request, which requires the following
204 * attributes-natural-language
206 * printer-state-message [optional]
209 request
= ippNewRequest(op
);
211 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
212 "localhost", 0, "/printers/%s", argv
[i
]);
213 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
214 "printer-uri", NULL
, uri
);
216 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
217 "requesting-user-name", NULL
, cupsUser());
220 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
221 "printer-state-message", NULL
, reason
);
224 * Do the request and get back a response...
227 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
229 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
231 _cupsLangPrintf(stderr
,
232 _("%s: Operation failed: %s\n"),
233 command
, ippErrorString(cupsLastError()));
241 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
246 * Cancel all jobs if requested...
252 * Build an IPP_PURGE_JOBS request, which requires the following
256 * attributes-natural-language
260 request
= ippNewRequest(IPP_PURGE_JOBS
);
262 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
263 "printer-uri", NULL
, uri
);
265 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
267 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
269 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
277 _cupsLangPrintf(stderr
, "%s: %s\n", command
, cupsLastErrorString());
291 * End of "$Id: accept.c 5925 2006-09-05 19:43:11Z mike $".