]>
git.ipfire.org Git - thirdparty/cups.git/blob - berkeley/lprm.c
4 * "lprm" command for CUPS.
6 * Copyright 2007-2010 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...
24 #include <cups/cups-private.h>
28 * 'main()' - Parse options and cancel jobs.
31 int /* O - Exit status */
32 main(int argc
, /* I - Number of command-line arguments */
33 char *argv
[]) /* I - Command-line arguments */
35 int i
; /* Looping var */
36 int job_id
; /* Job ID */
37 const char *name
; /* Destination printer */
38 char *instance
; /* Pointer to instance name */
39 cups_dest_t
*dest
, /* Destination */
40 *defdest
; /* Default destination */
41 int did_cancel
; /* Did we cancel something? */
47 * Setup to cancel individual print jobs...
51 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
52 name
= defdest
? defdest
->name
: NULL
;
55 * Process command-line arguments...
58 for (i
= 1; i
< argc
; i
++)
59 if (argv
[i
][0] == '-' && argv
[i
][1] != '\0')
62 case 'E' : /* Encrypt */
64 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
66 _cupsLangPrintf(stderr
,
67 _("%s: Sorry, no encryption support."), argv
[0]);
71 case 'P' : /* Cancel jobs on a printer */
80 if ((instance
= strchr(name
, '/')) != NULL
)
83 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, name
,
86 _cupsLangPrintf(stderr
,
87 _("%s: Error - unknown destination \"%s\"."),
92 cupsFreeDests(1, dest
);
95 case 'U' : /* Username */
96 if (argv
[i
][2] != '\0')
97 cupsSetUser(argv
[i
] + 2);
103 _cupsLangPrintf(stderr
,
104 _("%s: Error - expected username after "
105 "\"-U\" option."), argv
[0]);
109 cupsSetUser(argv
[i
]);
113 case 'h' : /* Connect to host */
114 if (argv
[i
][2] != '\0')
115 cupsSetServer(argv
[i
] + 2);
122 _cupsLangPrintf(stderr
,
123 _("%s: Error - expected hostname after "
124 "\"-h\" option."), argv
[0]);
128 cupsSetServer(argv
[i
]);
132 cupsFreeDests(1, defdest
);
134 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
135 name
= defdest
? defdest
->name
: NULL
;
139 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."),
140 argv
[0], argv
[i
][1]);
146 * Cancel a job or printer...
149 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, argv
[i
], NULL
)) != NULL
)
150 cupsFreeDests(1, dest
);
157 else if (isdigit(argv
[i
][0] & 255))
160 job_id
= atoi(argv
[i
]);
162 else if (!strcmp(argv
[i
], "-"))
172 _cupsLangPrintf(stderr
, _("%s: Error - unknown destination \"%s\"."),
177 if (cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, job_id
, 0) != IPP_OK
)
179 _cupsLangPrintf(stderr
, "%s: %s", argv
[0], cupsLastErrorString());
187 * If nothing has been canceled yet, cancel the current job on the specified
188 * (or default) printer...
191 if (!did_cancel
&& cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, 0, 0) != IPP_OK
)
193 _cupsLangPrintf(stderr
, "%s: %s", argv
[0], cupsLastErrorString());
198 cupsFreeDests(1, defdest
);
203 * If we get here there was an error, so clean up...
209 cupsFreeDests(1, defdest
);