]> git.ipfire.org Git - thirdparty/cups.git/blame - berkeley/lprm.c
Merge changes from CUPS 1.4svn-r7874.
[thirdparty/cups.git] / berkeley / lprm.c
CommitLineData
ef416fc2 1/*
75bd9771 2 * "$Id: lprm.c 7261 2008-01-28 23:09:31Z mike $"
ef416fc2 3 *
4 * "lprm" command for the Common UNIX Printing System (CUPS).
5 *
bc44d920 6 * Copyright 2007 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
24#include <stdio.h>
25#include <stdlib.h>
26
27#include <cups/cups.h>
28#include <cups/i18n.h>
29#include <cups/string.h>
30
31
32/*
33 * 'main()' - Parse options and cancel jobs.
34 */
35
36int /* O - Exit status */
37main(int argc, /* I - Number of command-line arguments */
38 char *argv[]) /* I - Command-line arguments */
39{
ef416fc2 40 int i; /* Looping var */
41 int job_id; /* Job ID */
5a738aea 42 const char *name; /* Destination printer */
ef416fc2 43 char *instance; /* Pointer to instance name */
5a738aea 44 cups_dest_t *dest, /* Destination */
8ca02f3c 45 *defdest; /* Default destination */
5a738aea 46 int did_cancel; /* Did we cancel something? */
ef416fc2 47
48
07725fee 49 _cupsSetLocale(argv);
d09495fa 50
ef416fc2 51 /*
52 * Setup to cancel individual print jobs...
53 */
54
5a738aea
MS
55 did_cancel = 0;
56 defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
57 name = defdest ? defdest->name : NULL;
8ca02f3c 58
ef416fc2 59 /*
60 * Process command-line arguments...
61 */
62
63 for (i = 1; i < argc; i ++)
64 if (argv[i][0] == '-' && argv[i][1] != '\0')
65 switch (argv[i][1])
66 {
67 case 'E' : /* Encrypt */
68#ifdef HAVE_SSL
5a738aea 69 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
ef416fc2 70#else
fa73b229 71 _cupsLangPrintf(stderr,
ef416fc2 72 _("%s: Sorry, no encryption support compiled in!\n"),
73 argv[0]);
74#endif /* HAVE_SSL */
75 break;
76
77 case 'P' : /* Cancel jobs on a printer */
78 if (argv[i][2])
5a738aea 79 name = argv[i] + 2;
ef416fc2 80 else
81 {
82 i ++;
5a738aea 83 name = argv[i];
ef416fc2 84 }
85
5a738aea 86 if ((instance = strchr(name, '/')) != NULL)
ef416fc2 87 *instance = '\0';
88
5a738aea
MS
89 if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name,
90 NULL)) == NULL)
ef416fc2 91 {
fa73b229 92 _cupsLangPrintf(stderr,
93 _("%s: Error - unknown destination \"%s\"!\n"),
5a738aea
MS
94 argv[0], name);
95 goto error;
ef416fc2 96 }
5a738aea
MS
97
98 cupsFreeDests(1, dest);
ef416fc2 99 break;
100
fa73b229 101 case 'U' : /* Username */
102 if (argv[i][2] != '\0')
103 cupsSetUser(argv[i] + 2);
104 else
105 {
106 i ++;
107 if (i >= argc)
108 {
109 _cupsLangPrintf(stderr,
110 _("%s: Error - expected username after "
111 "\'-U\' option!\n"),
112 argv[0]);
5a738aea 113 goto error;
fa73b229 114 }
115
116 cupsSetUser(argv[i]);
117 }
118 break;
119
120 case 'h' : /* Connect to host */
fa73b229 121 if (argv[i][2] != '\0')
122 cupsSetServer(argv[i] + 2);
123 else
124 {
125 i ++;
126
127 if (i >= argc)
128 {
129 _cupsLangPrintf(stderr,
130 _("%s: Error - expected hostname after "
131 "\'-h\' option!\n"),
132 argv[0]);
5a738aea 133 goto error;
fa73b229 134 }
135 else
136 cupsSetServer(argv[i]);
137 }
8ca02f3c 138
5a738aea
MS
139 if (defdest)
140 cupsFreeDests(1, defdest);
8ca02f3c 141
5a738aea
MS
142 defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
143 name = defdest ? defdest->name : NULL;
fa73b229 144 break;
145
ef416fc2 146 default :
fa73b229 147 _cupsLangPrintf(stderr,
148 _("%s: Error - unknown option \'%c\'!\n"),
149 argv[0], argv[i][1]);
5a738aea 150 goto error;
ef416fc2 151 }
152 else
153 {
154 /*
155 * Cancel a job or printer...
156 */
157
5a738aea
MS
158 if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[i], NULL)) != NULL)
159 cupsFreeDests(1, dest);
160
161 if (dest)
ef416fc2 162 {
5a738aea
MS
163 name = argv[i];
164 job_id = 0;
165 }
166 else if (isdigit(argv[i][0] & 255))
167 {
168 name = NULL;
ef416fc2 169 job_id = atoi(argv[i]);
170 }
fa73b229 171 else if (!strcmp(argv[i], "-"))
ef416fc2 172 {
173 /*
174 * Cancel all jobs
175 */
176
5a738aea 177 job_id = -1;
ef416fc2 178 }
179 else
180 {
5a738aea
MS
181 _cupsLangPrintf(stderr,
182 _("%s: Error - unknown destination \"%s\"!\n"),
183 argv[0], argv[i]);
184 goto error;
ef416fc2 185 }
186
5a738aea 187 if (cupsCancelJob2(CUPS_HTTP_DEFAULT, name, job_id, 0) != IPP_OK)
ef416fc2 188 {
fa73b229 189 _cupsLangPrintf(stderr, "%s: %s\n", argv[0], cupsLastErrorString());
5a738aea 190 goto error;
ef416fc2 191 }
5a738aea
MS
192
193 did_cancel = 1;
ef416fc2 194 }
195
196 /*
d09495fa 197 * If nothing has been canceled yet, cancel the current job on the specified
ef416fc2 198 * (or default) printer...
199 */
200
5a738aea 201 if (!did_cancel && cupsCancelJob2(CUPS_HTTP_DEFAULT, name, 0, 0) != IPP_OK)
ef416fc2 202 {
fa73b229 203 _cupsLangPrintf(stderr, "%s: %s\n", argv[0], cupsLastErrorString());
5a738aea 204 goto error;
ef416fc2 205 }
206
5a738aea
MS
207 if (defdest)
208 cupsFreeDests(1, defdest);
ef416fc2 209
210 return (0);
5a738aea
MS
211
212 /*
213 * If we get here there was an error, so clean up...
214 */
215
216 error:
217
218 if (defdest)
219 cupsFreeDests(1, defdest);
220
221 return (1);
ef416fc2 222}
223
224
225/*
75bd9771 226 * End of "$Id: lprm.c 7261 2008-01-28 23:09:31Z mike $".
ef416fc2 227 */