]> git.ipfire.org Git - thirdparty/cups.git/blame - berkeley/lprm.c
Import CUPS v1.7.1
[thirdparty/cups.git] / berkeley / lprm.c
CommitLineData
ef416fc2 1/*
61515785 2 * "$Id: lprm.c 10996 2013-05-29 11:51:34Z msweet $"
ef416fc2 3 *
71e16022 4 * "lprm" command for CUPS.
ef416fc2 5 *
71e16022 6 * Copyright 2007-2010 by Apple Inc.
ef416fc2 7 * Copyright 1997-2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
ef416fc2 14 *
15 * Contents:
16 *
17 * main() - Parse options and cancel jobs.
18 */
19
20/*
21 * Include necessary headers...
22 */
23
71e16022 24#include <cups/cups-private.h>
ef416fc2 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{
ef416fc2 35 int i; /* Looping var */
36 int job_id; /* Job ID */
5a738aea 37 const char *name; /* Destination printer */
ef416fc2 38 char *instance; /* Pointer to instance name */
5a738aea 39 cups_dest_t *dest, /* Destination */
8ca02f3c 40 *defdest; /* Default destination */
5a738aea 41 int did_cancel; /* Did we cancel something? */
ef416fc2 42
43
07725fee 44 _cupsSetLocale(argv);
d09495fa 45
ef416fc2 46 /*
47 * Setup to cancel individual print jobs...
48 */
49
5a738aea
MS
50 did_cancel = 0;
51 defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
52 name = defdest ? defdest->name : NULL;
8ca02f3c 53
ef416fc2 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 {
62 case 'E' : /* Encrypt */
63#ifdef HAVE_SSL
5a738aea 64 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
ef416fc2 65#else
fa73b229 66 _cupsLangPrintf(stderr,
0837b7e8 67 _("%s: Sorry, no encryption support."), argv[0]);
ef416fc2 68#endif /* HAVE_SSL */
69 break;
70
71 case 'P' : /* Cancel jobs on a printer */
72 if (argv[i][2])
5a738aea 73 name = argv[i] + 2;
ef416fc2 74 else
75 {
76 i ++;
5a738aea 77 name = argv[i];
ef416fc2 78 }
79
5a738aea 80 if ((instance = strchr(name, '/')) != NULL)
ef416fc2 81 *instance = '\0';
82
5a738aea
MS
83 if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name,
84 NULL)) == NULL)
ef416fc2 85 {
fa73b229 86 _cupsLangPrintf(stderr,
0837b7e8 87 _("%s: Error - unknown destination \"%s\"."),
5a738aea
MS
88 argv[0], name);
89 goto error;
ef416fc2 90 }
5a738aea
MS
91
92 cupsFreeDests(1, dest);
ef416fc2 93 break;
94
fa73b229 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 "
0837b7e8 105 "\"-U\" option."), argv[0]);
5a738aea 106 goto error;
fa73b229 107 }
108
109 cupsSetUser(argv[i]);
110 }
111 break;
112
113 case 'h' : /* Connect to host */
fa73b229 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 "
0837b7e8 124 "\"-h\" option."), argv[0]);
5a738aea 125 goto error;
fa73b229 126 }
127 else
128 cupsSetServer(argv[i]);
129 }
8ca02f3c 130
5a738aea
MS
131 if (defdest)
132 cupsFreeDests(1, defdest);
8ca02f3c 133
5a738aea
MS
134 defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
135 name = defdest ? defdest->name : NULL;
fa73b229 136 break;
137
ef416fc2 138 default :
0837b7e8 139 _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."),
fa73b229 140 argv[0], argv[i][1]);
5a738aea 141 goto error;
ef416fc2 142 }
143 else
144 {
145 /*
146 * Cancel a job or printer...
147 */
148
5a738aea
MS
149 if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[i], NULL)) != NULL)
150 cupsFreeDests(1, dest);
151
152 if (dest)
ef416fc2 153 {
5a738aea
MS
154 name = argv[i];
155 job_id = 0;
156 }
157 else if (isdigit(argv[i][0] & 255))
158 {
159 name = NULL;
ef416fc2 160 job_id = atoi(argv[i]);
161 }
fa73b229 162 else if (!strcmp(argv[i], "-"))
ef416fc2 163 {
164 /*
165 * Cancel all jobs
166 */
167
5a738aea 168 job_id = -1;
ef416fc2 169 }
170 else
171 {
0837b7e8 172 _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s\"."),
5a738aea
MS
173 argv[0], argv[i]);
174 goto error;
ef416fc2 175 }
176
5a738aea 177 if (cupsCancelJob2(CUPS_HTTP_DEFAULT, name, job_id, 0) != IPP_OK)
ef416fc2 178 {
0837b7e8 179 _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString());
5a738aea 180 goto error;
ef416fc2 181 }
5a738aea
MS
182
183 did_cancel = 1;
ef416fc2 184 }
185
186 /*
d09495fa 187 * If nothing has been canceled yet, cancel the current job on the specified
ef416fc2 188 * (or default) printer...
189 */
190
5a738aea 191 if (!did_cancel && cupsCancelJob2(CUPS_HTTP_DEFAULT, name, 0, 0) != IPP_OK)
ef416fc2 192 {
0837b7e8 193 _cupsLangPrintf(stderr, "%s: %s", argv[0], cupsLastErrorString());
5a738aea 194 goto error;
ef416fc2 195 }
196
5a738aea
MS
197 if (defdest)
198 cupsFreeDests(1, defdest);
ef416fc2 199
200 return (0);
5a738aea
MS
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);
ef416fc2 212}
213
214
215/*
61515785 216 * End of "$Id: lprm.c 10996 2013-05-29 11:51:34Z msweet $".
ef416fc2 217 */