]>
git.ipfire.org Git - thirdparty/cups.git/blob - berkeley/lprm.c
2 * "lprm" command for CUPS.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include <cups/cups-private.h>
18 * 'main()' - Parse options and cancel jobs.
21 int /* O - Exit status */
22 main(int argc
, /* I - Number of command-line arguments */
23 char *argv
[]) /* I - Command-line arguments */
25 int i
; /* Looping var */
26 int job_id
; /* Job ID */
27 const char *name
; /* Destination printer */
28 char *instance
, /* Pointer to instance name */
29 *opt
; /* Option pointer */
30 cups_dest_t
*dest
, /* Destination */
31 *defdest
; /* Default destination */
32 int did_cancel
; /* Did we cancel something? */
38 * Setup to cancel individual print jobs...
42 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
43 name
= defdest
? defdest
->name
: NULL
;
46 * Process command-line arguments...
49 for (i
= 1; i
< argc
; i
++)
51 if (argv
[i
][0] == '-' && argv
[i
][1] != '\0')
53 for (opt
= argv
[i
] + 1; *opt
; opt
++)
57 case 'E' : /* Encrypt */
59 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
61 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."), argv
[0]);
65 case 'P' : /* Cancel jobs on a printer */
69 opt
+= strlen(opt
) - 1;
77 if ((instance
= strchr(name
, '/')) != NULL
)
80 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, name
, NULL
)) == NULL
)
82 _cupsLangPrintf(stderr
, _("%s: Error - unknown destination \"%s\"."), argv
[0], name
);
86 cupsFreeDests(1, dest
);
89 case 'U' : /* Username */
93 opt
+= strlen(opt
) - 1;
100 _cupsLangPrintf(stderr
, _("%s: Error - expected username after \"-U\" option."), argv
[0]);
104 cupsSetUser(argv
[i
]);
108 case 'h' : /* Connect to host */
111 cupsSetServer(opt
+ 1);
112 opt
+= strlen(opt
) - 1;
120 _cupsLangPrintf(stderr
, _("%s: Error - expected hostname after \"-h\" option."), argv
[0]);
124 cupsSetServer(argv
[i
]);
128 cupsFreeDests(1, defdest
);
130 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
131 name
= defdest
? defdest
->name
: NULL
;
135 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."), argv
[0], *opt
);
143 * Cancel a job or printer...
146 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, argv
[i
], NULL
)) != NULL
)
147 cupsFreeDests(1, dest
);
154 else if (isdigit(argv
[i
][0] & 255))
157 job_id
= atoi(argv
[i
]);
159 else if (!strcmp(argv
[i
], "-"))
169 _cupsLangPrintf(stderr
, _("%s: Error - unknown destination \"%s\"."),
174 if (cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, job_id
, 0) != IPP_OK
)
176 _cupsLangPrintf(stderr
, "%s: %s", argv
[0], cupsLastErrorString());
185 * If nothing has been canceled yet, cancel the current job on the specified
186 * (or default) printer...
189 if (!did_cancel
&& cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, 0, 0) != IPP_OK
)
191 _cupsLangPrintf(stderr
, "%s: %s", argv
[0], cupsLastErrorString());
196 cupsFreeDests(1, defdest
);
201 * If we get here there was an error, so clean up...
207 cupsFreeDests(1, defdest
);