]>
git.ipfire.org Git - thirdparty/cups.git/blob - berkeley/lprm.c
2 * "$Id: lprm.c 6649 2007-07-11 21:46:42Z mike $"
4 * "lprm" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
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/".
17 * main() - Parse options and cancel jobs.
21 * Include necessary headers...
27 #include <cups/cups.h>
28 #include <cups/i18n.h>
29 #include <cups/string.h>
33 * 'main()' - Parse options and cancel jobs.
36 int /* O - Exit status */
37 main(int argc
, /* I - Number of command-line arguments */
38 char *argv
[]) /* I - Command-line arguments */
40 int i
; /* Looping var */
41 int job_id
; /* Job ID */
42 const char *name
; /* Destination printer */
43 char *instance
; /* Pointer to instance name */
44 cups_dest_t
*dest
, /* Destination */
45 *defdest
; /* Default destination */
46 int did_cancel
; /* Did we cancel something? */
52 * Setup to cancel individual print jobs...
56 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
57 name
= defdest
? defdest
->name
: NULL
;
60 * Process command-line arguments...
63 for (i
= 1; i
< argc
; i
++)
64 if (argv
[i
][0] == '-' && argv
[i
][1] != '\0')
67 case 'E' : /* Encrypt */
69 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
71 _cupsLangPrintf(stderr
,
72 _("%s: Sorry, no encryption support compiled in!\n"),
77 case 'P' : /* Cancel jobs on a printer */
86 if ((instance
= strchr(name
, '/')) != NULL
)
89 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, name
,
92 _cupsLangPrintf(stderr
,
93 _("%s: Error - unknown destination \"%s\"!\n"),
98 cupsFreeDests(1, dest
);
101 case 'U' : /* Username */
102 if (argv
[i
][2] != '\0')
103 cupsSetUser(argv
[i
] + 2);
109 _cupsLangPrintf(stderr
,
110 _("%s: Error - expected username after "
116 cupsSetUser(argv
[i
]);
120 case 'h' : /* Connect to host */
121 if (argv
[i
][2] != '\0')
122 cupsSetServer(argv
[i
] + 2);
129 _cupsLangPrintf(stderr
,
130 _("%s: Error - expected hostname after "
136 cupsSetServer(argv
[i
]);
140 cupsFreeDests(1, defdest
);
142 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
143 name
= defdest
? defdest
->name
: NULL
;
147 _cupsLangPrintf(stderr
,
148 _("%s: Error - unknown option \'%c\'!\n"),
149 argv
[0], argv
[i
][1]);
155 * Cancel a job or printer...
158 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, argv
[i
], NULL
)) != NULL
)
159 cupsFreeDests(1, dest
);
166 else if (isdigit(argv
[i
][0] & 255))
169 job_id
= atoi(argv
[i
]);
171 else if (!strcmp(argv
[i
], "-"))
181 _cupsLangPrintf(stderr
,
182 _("%s: Error - unknown destination \"%s\"!\n"),
187 if (cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, job_id
, 0) != IPP_OK
)
189 _cupsLangPrintf(stderr
, "%s: %s\n", argv
[0], cupsLastErrorString());
197 * If nothing has been canceled yet, cancel the current job on the specified
198 * (or default) printer...
201 if (!did_cancel
&& cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, 0, 0) != IPP_OK
)
203 _cupsLangPrintf(stderr
, "%s: %s\n", argv
[0], cupsLastErrorString());
208 cupsFreeDests(1, defdest
);
213 * If we get here there was an error, so clean up...
219 cupsFreeDests(1, defdest
);
226 * End of "$Id: lprm.c 6649 2007-07-11 21:46:42Z mike $".