]>
git.ipfire.org Git - thirdparty/cups.git/blob - berkeley/lprm.c
2 * "lprm" command for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
15 #include <cups/cups-private.h>
22 static void usage(void) _CUPS_NORETURN
;
26 * 'main()' - Parse options and cancel jobs.
29 int /* O - Exit status */
30 main(int argc
, /* I - Number of command-line arguments */
31 char *argv
[]) /* I - Command-line arguments */
33 int i
; /* Looping var */
34 int job_id
; /* Job ID */
35 const char *name
; /* Destination printer */
36 char *instance
, /* Pointer to instance name */
37 *opt
; /* Option pointer */
38 cups_dest_t
*dest
, /* Destination */
39 *defdest
; /* Default destination */
40 int did_cancel
; /* Did we cancel something? */
46 * Setup to cancel individual print jobs...
50 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
51 name
= defdest
? defdest
->name
: NULL
;
54 * Process command-line arguments...
57 for (i
= 1; i
< argc
; i
++)
59 if (!strcmp(argv
[i
], "--help"))
61 else if (argv
[i
][0] == '-' && argv
[i
][1] != '\0')
63 for (opt
= argv
[i
] + 1; *opt
; opt
++)
67 case 'E' : /* Encrypt */
69 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
71 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."), argv
[0]);
75 case 'P' : /* Cancel jobs on a printer */
79 opt
+= strlen(opt
) - 1;
87 if ((instance
= strchr(name
, '/')) != NULL
)
90 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, name
, NULL
)) == NULL
)
92 _cupsLangPrintf(stderr
, _("%s: Error - unknown destination \"%s\"."), argv
[0], name
);
96 cupsFreeDests(1, dest
);
99 case 'U' : /* Username */
102 cupsSetUser(opt
+ 1);
103 opt
+= strlen(opt
) - 1;
110 _cupsLangPrintf(stderr
, _("%s: Error - expected username after \"-U\" option."), argv
[0]);
114 cupsSetUser(argv
[i
]);
118 case 'h' : /* Connect to host */
121 cupsSetServer(opt
+ 1);
122 opt
+= strlen(opt
) - 1;
130 _cupsLangPrintf(stderr
, _("%s: Error - expected hostname after \"-h\" option."), argv
[0]);
134 cupsSetServer(argv
[i
]);
138 cupsFreeDests(1, defdest
);
140 defdest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
141 name
= defdest
? defdest
->name
: NULL
;
145 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."), argv
[0], *opt
);
153 * Cancel a job or printer...
156 if ((dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, argv
[i
], NULL
)) != NULL
)
157 cupsFreeDests(1, dest
);
164 else if (isdigit(argv
[i
][0] & 255))
167 job_id
= atoi(argv
[i
]);
169 else if (!strcmp(argv
[i
], "-"))
179 _cupsLangPrintf(stderr
, _("%s: Error - unknown destination \"%s\"."),
184 if (cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, job_id
, 0) != IPP_OK
)
186 _cupsLangPrintf(stderr
, "%s: %s", argv
[0], cupsLastErrorString());
195 * If nothing has been canceled yet, cancel the current job on the specified
196 * (or default) printer...
199 if (!did_cancel
&& cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, 0, 0) != IPP_OK
)
201 _cupsLangPrintf(stderr
, "%s: %s", argv
[0], cupsLastErrorString());
206 cupsFreeDests(1, defdest
);
211 * If we get here there was an error, so clean up...
217 cupsFreeDests(1, defdest
);
224 * 'usage()' - Show program usage and exit.
230 _cupsLangPuts(stdout
, _("Usage: lprm [options] [id]\n"
231 " lprm [options] -"));
232 _cupsLangPuts(stdout
, _("Options:"));
233 _cupsLangPuts(stdout
, _("- Cancel all jobs"));
234 _cupsLangPuts(stdout
, _("-E Encrypt the connection to the server"));
235 _cupsLangPuts(stdout
, _("-h server[:port] Connect to the named server and port"));
236 _cupsLangPuts(stdout
, _("-P destination Specify the destination"));
237 _cupsLangPuts(stdout
, _("-U username Specify the username to use for authentication"));