]> git.ipfire.org Git - thirdparty/cups.git/blame - systemv/cupsaccept.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / systemv / cupsaccept.c
CommitLineData
ef416fc2 1/*
503b54c9
MS
2 * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
3 * CUPS.
ef416fc2 4 *
bdbfacc7 5 * Copyright 2007-2016 by Apple Inc.
503b54c9 6 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 7 *
503b54c9
MS
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
57b7b66b 12 * missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 13 */
14
15/*
16 * Include necessary headers...
17 */
18
71e16022 19#include <cups/cups-private.h>
ef416fc2 20
21
22/*
23 * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
24 */
25
26int /* O - Exit status */
27main(int argc, /* I - Number of command-line arguments */
28 char *argv[]) /* I - Command-line arguments */
29{
ef416fc2 30 int i; /* Looping var */
31 char *command, /* Command to do */
bdbfacc7 32 *opt, /* Option pointer */
ef416fc2 33 uri[1024], /* Printer URI */
34 *reason; /* Reason for reject/disable */
35 ipp_t *request; /* IPP request */
ef416fc2 36 ipp_op_t op; /* Operation */
ef416fc2 37 int cancel; /* Cancel jobs? */
38
39
07725fee 40 _cupsSetLocale(argv);
d09495fa 41
ef416fc2 42 /*
43 * See what operation we're supposed to do...
44 */
45
46 if ((command = strrchr(argv[0], '/')) != NULL)
47 command ++;
48 else
49 command = argv[0];
50
fa73b229 51 cancel = 0;
ef416fc2 52
49d87452 53 if (!strcmp(command, "cupsaccept") || !strcmp(command, "accept"))
ef416fc2 54 op = CUPS_ACCEPT_JOBS;
49d87452 55 else if (!strcmp(command, "cupsreject") || !strcmp(command, "reject"))
ef416fc2 56 op = CUPS_REJECT_JOBS;
bd7854cb 57 else if (!strcmp(command, "cupsdisable") || !strcmp(command, "disable"))
ef416fc2 58 op = IPP_PAUSE_PRINTER;
bd7854cb 59 else if (!strcmp(command, "cupsenable") || !strcmp(command, "enable"))
ef416fc2 60 op = IPP_RESUME_PRINTER;
61 else
62 {
0837b7e8 63 _cupsLangPrintf(stderr, _("%s: Don't know what to do."), command);
ef416fc2 64 return (1);
65 }
66
ef416fc2 67 reason = NULL;
68
69 /*
70 * Process command-line arguments...
71 */
72
73 for (i = 1; i < argc; i ++)
bdbfacc7
MS
74 {
75 if (!strcmp(argv[i], "--hold"))
76 op = IPP_HOLD_NEW_JOBS;
77 else if (!strcmp(argv[i], "--release"))
78 op = IPP_RELEASE_HELD_NEW_JOBS;
79 else if (argv[i][0] == '-')
61cf44e2 80 {
bdbfacc7 81 for (opt = argv[i] + 1; *opt; opt ++)
ef416fc2 82 {
bdbfacc7
MS
83 switch (*opt)
84 {
85 case 'E' : /* Encrypt */
86 #ifdef HAVE_SSL
87 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
88 #else
89 _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), command);
90 #endif /* HAVE_SSL */
91 break;
92
93 case 'U' : /* Username */
94 if (opt[1] != '\0')
fa73b229 95 {
bdbfacc7
MS
96 cupsSetUser(opt + 1);
97 opt += strlen(opt) - 1;
fa73b229 98 }
bdbfacc7
MS
99 else
100 {
101 i ++;
102 if (i >= argc)
103 {
104 _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), command);
105 return (1);
106 }
107
108 cupsSetUser(argv[i]);
109 }
110 break;
57b7b66b 111
bdbfacc7
MS
112 case 'c' : /* Cancel jobs */
113 cancel = 1;
114 break;
115
116 case 'h' : /* Connect to host */
117 if (opt[1] != '\0')
118 {
119 cupsSetServer(opt + 1);
120 opt += strlen(opt) - 1;
121 }
122 else
ef416fc2 123 {
bdbfacc7
MS
124 i ++;
125 if (i >= argc)
126 {
127 _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), command);
128 return (1);
129 }
130
131 cupsSetServer(argv[i]);
ef416fc2 132 }
bdbfacc7 133 break;
ef416fc2 134
bdbfacc7
MS
135 case 'r' : /* Reason for cancellation */
136 if (opt[1] != '\0')
137 {
138 reason = opt + 1;
139 opt += strlen(opt) - 1;
140 }
141 else
ef416fc2 142 {
bdbfacc7
MS
143 i ++;
144 if (i >= argc)
145 {
146 _cupsLangPrintf(stderr, _("%s: Error - expected reason text after \"-r\" option."), command);
147 return (1);
148 }
149
150 reason = argv[i];
ef416fc2 151 }
bdbfacc7 152 break;
ef416fc2 153
bdbfacc7
MS
154 default :
155 _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), command, *opt);
61cf44e2 156 return (1);
bdbfacc7 157 }
ef416fc2 158 }
61cf44e2 159 }
ef416fc2 160 else
161 {
162 /*
163 * Accept/disable/enable/reject a destination...
164 */
165
fa73b229 166 request = ippNewRequest(op);
ef416fc2 167
a4d04587 168 httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
169 "localhost", 0, "/printers/%s", argv[i]);
ef416fc2 170 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
171 "printer-uri", NULL, uri);
172
fa73b229 173 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
174 "requesting-user-name", NULL, cupsUser());
175
ef416fc2 176 if (reason != NULL)
177 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT,
178 "printer-state-message", NULL, reason);
179
180 /*
181 * Do the request and get back a response...
182 */
183
61cf44e2
MS
184 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/admin/"));
185
186 if (cupsLastError() > IPP_OK_CONFLICT)
ef416fc2 187 {
61cf44e2 188 _cupsLangPrintf(stderr,
0837b7e8 189 _("%s: Operation failed: %s"),
61cf44e2 190 command, ippErrorString(cupsLastError()));
ef416fc2 191 return (1);
192 }
193
194 /*
195 * Cancel all jobs if requested...
196 */
197
198 if (cancel)
199 {
200 /*
201 * Build an IPP_PURGE_JOBS request, which requires the following
202 * attributes:
203 *
204 * attributes-charset
205 * attributes-natural-language
206 * printer-uri
207 */
208
fa73b229 209 request = ippNewRequest(IPP_PURGE_JOBS);
ef416fc2 210
211 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
212 "printer-uri", NULL, uri);
213
61cf44e2 214 ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/admin/"));
ef416fc2 215
61cf44e2 216 if (cupsLastError() > IPP_OK_CONFLICT)
ef416fc2 217 {
0837b7e8 218 _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
ef416fc2 219 return (1);
220 }
221 }
222 }
bdbfacc7 223 }
ef416fc2 224
ef416fc2 225 return (0);
226}