]>
git.ipfire.org Git - thirdparty/cups.git/blob - berkeley/lprm.c
2271d48720ec584f453db3554cba09b173d37915
2 * "lprm" command for CUPS.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
18 #include <cups/cups-private.h>
22 * 'main()' - Parse options and cancel jobs.
25 int /* O - Exit status */
26 main(int argc
, /* I - Number of command-line arguments */
27 char *argv
[]) /* I - Command-line arguments */
29 int i
; /* Looping var */
30 int job_id
; /* Job ID */
31 const char *name
; /* Destination printer */
32 char *instance
, /* Pointer to instance name */
33 *opt
; /* Option pointer */
34 cups_dest_t
*dest
, /* Destination */
35 *defdest
; /* Default destination */
36 int did_cancel
; /* Did we cancel something? */
42 * Setup to cancel individual print jobs...
46 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
47 name
= defdest
? defdest
->name
: NULL
;
50 * Process command-line arguments...
53 for (i
= 1; i
< argc
; i
++)
55 if (argv
[i
][0] == '-' && argv
[i
][1] != '\0')
57 for (opt
= argv
[i
] + 1; *opt
; opt
++)
61 case 'E' : /* Encrypt */
63 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
65 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."), argv
[0]);
69 case 'P' : /* Cancel jobs on a printer */
73 opt
+= strlen(opt
) - 1;
81 if ((instance
= strchr(name
, '/')) != NULL
)
84 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, name
, NULL
)) == NULL
)
86 _cupsLangPrintf(stderr
, _("%s: Error - unknown destination \"%s\"."), argv
[0], name
);
90 cupsFreeDests(1, dest
);
93 case 'U' : /* Username */
97 opt
+= strlen(opt
) - 1;
104 _cupsLangPrintf(stderr
, _("%s: Error - expected username after \"-U\" option."), argv
[0]);
108 cupsSetUser(argv
[i
]);
112 case 'h' : /* Connect to host */
115 cupsSetServer(opt
+ 1);
116 opt
+= strlen(opt
) - 1;
124 _cupsLangPrintf(stderr
, _("%s: Error - expected hostname after \"-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\"."), argv
[0], *opt
);
147 * Cancel a job or printer...
150 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, argv
[i
], NULL
)) != NULL
)
151 cupsFreeDests(1, dest
);
158 else if (isdigit(argv
[i
][0] & 255))
161 job_id
= atoi(argv
[i
]);
163 else if (!strcmp(argv
[i
], "-"))
173 _cupsLangPrintf(stderr
, _("%s: Error - unknown destination \"%s\"."),
178 if (cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, job_id
, 0) != IPP_OK
)
180 _cupsLangPrintf(stderr
, "%s: %s", argv
[0], cupsLastErrorString());
189 * If nothing has been canceled yet, cancel the current job on the specified
190 * (or default) printer...
193 if (!did_cancel
&& cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, 0, 0) != IPP_OK
)
195 _cupsLangPrintf(stderr
, "%s: %s", argv
[0], cupsLastErrorString());
200 cupsFreeDests(1, defdest
);
205 * If we get here there was an error, so clean up...
211 cupsFreeDests(1, defdest
);