]> git.ipfire.org Git - thirdparty/cups.git/blame - berkeley/lprm.c
More localization work.
[thirdparty/cups.git] / berkeley / lprm.c
CommitLineData
bd0b97ff 1/*
c9d3f842 2 * "$Id$"
bd0b97ff 3 *
3d94661a 4 * "lprm" command for CUPS.
bd0b97ff 5 *
3d94661a 6 * Copyright 2007-2010 by Apple Inc.
0e66904d 7 * Copyright 1997-2006 by Easy Software Products.
bd0b97ff 8 *
9 * These coded instructions, statements, and computer programs are the
4e8d321f 10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
bd0b97ff 14 *
15 * Contents:
16 *
17 * main() - Parse options and cancel jobs.
18 */
19
20/*
21 * Include necessary headers...
22 */
23
3d94661a 24#include <cups/cups-private.h>
bd0b97ff 25
26
27/*
28 * 'main()' - Parse options and cancel jobs.
29 */
30
31int /* O - Exit status */
32main(int argc, /* I - Number of command-line arguments */
33 char *argv[]) /* I - Command-line arguments */
34{
bd0b97ff 35 int i; /* Looping var */
36 int job_id; /* Job ID */
7f826886 37 const char *name; /* Destination printer */
79e9fc64 38 char *instance; /* Pointer to instance name */
7f826886 39 cups_dest_t *dest, /* Destination */
c6f746f7 40 *defdest; /* Default destination */
7f826886 41 int did_cancel; /* Did we cancel something? */
bd0b97ff 42
43
156dd8aa 44 _cupsSetLocale(argv);
ebad28ad 45
bd0b97ff 46 /*
47 * Setup to cancel individual print jobs...
48 */
49
7f826886 50 did_cancel = 0;
51 defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
52 name = defdest ? defdest->name : NULL;
c6f746f7 53
bd0b97ff 54 /*
55 * Process command-line arguments...
56 */
57
58 for (i = 1; i < argc; i ++)
59 if (argv[i][0] == '-' && argv[i][1] != '\0')
60 switch (argv[i][1])
61 {
1c9e0181 62 case 'E' : /* Encrypt */
bcf61448 63#ifdef HAVE_SSL
7f826886 64 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
1c9e0181 65#else
89fd567e 66 _cupsLangPrintf(stderr,
4c4eea89 67 _("%s: Sorry, no encryption support."), argv[0]);
bcf61448 68#endif /* HAVE_SSL */
1c9e0181 69 break;
70
bd0b97ff 71 case 'P' : /* Cancel jobs on a printer */
72 if (argv[i][2])
7f826886 73 name = argv[i] + 2;
bd0b97ff 74 else
75 {
76 i ++;
7f826886 77 name = argv[i];
bd0b97ff 78 }
79e9fc64 79
7f826886 80 if ((instance = strchr(name, '/')) != NULL)
79e9fc64 81 *instance = '\0';
727e6d14 82
7f826886 83 if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name,
84 NULL)) == NULL)
727e6d14 85 {
89fd567e 86 _cupsLangPrintf(stderr,
4c4eea89 87 _("%s: Error - unknown destination \"%s\"."),
7f826886 88 argv[0], name);
89 goto error;
727e6d14 90 }
7f826886 91
92 cupsFreeDests(1, dest);
bd0b97ff 93 break;
94
cfea7a92 95 case 'U' : /* Username */
96 if (argv[i][2] != '\0')
97 cupsSetUser(argv[i] + 2);
98 else
99 {
100 i ++;
101 if (i >= argc)
102 {
103 _cupsLangPrintf(stderr,
104 _("%s: Error - expected username after "
4c4eea89 105 "\"-U\" option."), argv[0]);
7f826886 106 goto error;
cfea7a92 107 }
108
109 cupsSetUser(argv[i]);
110 }
111 break;
112
113 case 'h' : /* Connect to host */
cfea7a92 114 if (argv[i][2] != '\0')
115 cupsSetServer(argv[i] + 2);
116 else
117 {
118 i ++;
119
120 if (i >= argc)
121 {
122 _cupsLangPrintf(stderr,
123 _("%s: Error - expected hostname after "
4c4eea89 124 "\"-h\" option."), argv[0]);
7f826886 125 goto error;
cfea7a92 126 }
127 else
128 cupsSetServer(argv[i]);
129 }
c6f746f7 130
7f826886 131 if (defdest)
132 cupsFreeDests(1, defdest);
c6f746f7 133
7f826886 134 defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
135 name = defdest ? defdest->name : NULL;
cfea7a92 136 break;
137
bd0b97ff 138 default :
4c4eea89 139 _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."),
cfea7a92 140 argv[0], argv[i][1]);
7f826886 141 goto error;
bd0b97ff 142 }
143 else
144 {
145 /*
146 * Cancel a job or printer...
147 */
148
7f826886 149 if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[i], NULL)) != NULL)
150 cupsFreeDests(1, dest);
151
152 if (dest)
bd0b97ff 153 {
7f826886 154 name = argv[i];
155 job_id = 0;
156 }
157 else if (isdigit(argv[i][0] & 255))
158 {
159 name = NULL;
bd0b97ff 160 job_id = atoi(argv[i]);
161 }
cfea7a92 162 else if (!strcmp(argv[i], "-"))
bd0b97ff 163 {
164 /*
165 * Cancel all jobs
166 */
167
7f826886 168 job_id = -1;
bd0b97ff 169 }
170 else
171 {
4c4eea89 172 _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s\"."),
7f826886 173 argv[0], argv[i]);
174 goto error;
bd0b97ff 175 }
176
7f826886 177 if (cupsCancelJob2(CUPS_HTTP_DEFAULT, name, job_id, 0) != IPP_OK)
67e0502b 178 {
4c4eea89 179 _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString());
7f826886 180 goto error;
bd0b97ff 181 }
7f826886 182
183 did_cancel = 1;
bd0b97ff 184 }
185
186 /*
eaa628bf 187 * If nothing has been canceled yet, cancel the current job on the specified
bd0b97ff 188 * (or default) printer...
189 */
190
7f826886 191 if (!did_cancel && cupsCancelJob2(CUPS_HTTP_DEFAULT, name, 0, 0) != IPP_OK)
bd0b97ff 192 {
4c4eea89 193 _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString());
7f826886 194 goto error;
bd0b97ff 195 }
196
7f826886 197 if (defdest)
198 cupsFreeDests(1, defdest);
99cc28d6 199
bd0b97ff 200 return (0);
7f826886 201
202 /*
203 * If we get here there was an error, so clean up...
204 */
205
206 error:
207
208 if (defdest)
209 cupsFreeDests(1, defdest);
210
211 return (1);
bd0b97ff 212}
213
214
215/*
c9d3f842 216 * End of "$Id$".
bd0b97ff 217 */