]> git.ipfire.org Git - thirdparty/cups.git/blame - systemv/lpmove.c
More localization work.
[thirdparty/cups.git] / systemv / lpmove.c
CommitLineData
38138d28 1/*
c9d3f842 2 * "$Id$"
38138d28 3 *
3d94661a 4 * "lpmove" command for CUPS.
38138d28 5 *
3d94661a 6 * Copyright 2007-2010 by Apple Inc.
0e66904d 7 * Copyright 1997-2006 by Easy Software Products.
38138d28 8 *
9 * These coded instructions, statements, and computer programs are the
4e8d321f 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/".
38138d28 14 *
15 * Contents:
16 *
5a4cc9a6 17 * main() - Parse options and move jobs.
18 * move_job() - Move a job.
38138d28 19 */
20
21/*
22 * Include necessary headers...
23 */
24
3d94661a 25#include <cups/cups-private.h>
38138d28 26
27
28/*
29 * Local functions...
30 */
31
b7c5e827 32static int move_job(http_t *http, const char *src, int jobid,
33 const char *dest);
38138d28 34
35
36/*
37 * 'main()' - Parse options and show status information.
38 */
39
40int
b7382443 41main(int argc, /* I - Number of command-line arguments */
42 char *argv[]) /* I - Command-line arguments */
38138d28 43{
b7382443 44 int i; /* Looping var */
45 http_t *http; /* Connection to server */
46 const char *job; /* Job name */
b7c5e827 47 int jobid; /* Job ID */
b7382443 48 int num_dests; /* Number of destinations */
49 cups_dest_t *dests; /* Destinations */
b7c5e827 50 const char *src, /* Original queue */
51 *dest; /* New destination */
38138d28 52
53
156dd8aa 54 _cupsSetLocale(argv);
ebad28ad 55
b7c5e827 56 dest = NULL;
57 dests = NULL;
192a8a08 58 job = NULL;
b7c5e827 59 jobid = 0;
192a8a08 60 num_dests = 0;
b7c5e827 61 src = NULL;
38138d28 62
63 for (i = 1; i < argc; i ++)
64 if (argv[i][0] == '-')
65 switch (argv[i][1])
66 {
1c9e0181 67 case 'E' : /* Encrypt */
bcf61448 68#ifdef HAVE_SSL
192a8a08 69 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
1c9e0181 70
1c9e0181 71#else
89fd567e 72 _cupsLangPrintf(stderr,
4c4eea89 73 _("%s: Sorry, no encryption support."),
b7382443 74 argv[0]);
bcf61448 75#endif /* HAVE_SSL */
1c9e0181 76 break;
77
38138d28 78 case 'h' : /* Connect to host */
38138d28 79 if (argv[i][2] != '\0')
192a8a08 80 cupsSetServer(argv[i] + 2);
38138d28 81 else
82 {
83 i ++;
84
85 if (i >= argc)
86 {
89fd567e 87 _cupsLangPuts(stderr,
4c4eea89 88 _("Error: need hostname after \"-h\" option."));
38138d28 89 return (1);
90 }
91
192a8a08 92 cupsSetServer(argv[i]);
38138d28 93 }
94 break;
95
38138d28 96 default :
4c4eea89 97 _cupsLangPrintf(stderr, _("lpmove: Unknown option \"%c\"."),
b7382443 98 argv[i][1]);
38138d28 99 return (1);
100 }
b7c5e827 101 else if (!jobid && !src)
5a4cc9a6 102 {
bfbad344 103 if (num_dests == 0)
104 num_dests = cupsGetDests(&dests);
105
106 if ((job = strrchr(argv[i], '-')) != NULL &&
107 cupsGetDest(argv[i], NULL, num_dests, dests) == NULL)
b7c5e827 108 jobid = atoi(job + 1);
e53ccdf9 109 else if (isdigit(argv[i][0] & 255) &&
110 !cupsGetDest(argv[i], NULL, num_dests, dests))
111 jobid = atoi(argv[i]);
5a4cc9a6 112 else
b7c5e827 113 src = argv[i];
5a4cc9a6 114 }
115 else if (dest == NULL)
116 dest = argv[i];
38138d28 117 else
118 {
4c4eea89 119 _cupsLangPrintf(stderr, _("lpmove: Unknown argument \"%s\"."), argv[i]);
38138d28 120 return (1);
121 }
122
b7c5e827 123 if ((!jobid && !src) || !dest)
38138d28 124 {
4c4eea89 125 _cupsLangPuts(stdout, _("Usage: lpmove job/src dest"));
5a4cc9a6 126 return (1);
127 }
38138d28 128
18e6d242 129 http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
38138d28 130
18e6d242 131 if (http == NULL)
132 {
4c4eea89 133 _cupsLangPrintf(stderr, _("lpmove: Unable to connect to server: %s"),
18e6d242 134 strerror(errno));
135 return (1);
38138d28 136 }
137
b7c5e827 138 return (move_job(http, src, jobid, dest));
38138d28 139}
140
141
142/*
5a4cc9a6 143 * 'move_job()' - Move a job.
38138d28 144 */
145
b7c5e827 146static int /* O - 0 on success, 1 on error */
b7382443 147move_job(http_t *http, /* I - HTTP connection to server */
b7c5e827 148 const char *src, /* I - Source queue */
b7382443 149 int jobid, /* I - Job ID */
b7c5e827 150 const char *dest) /* I - Destination queue */
38138d28 151{
b7c5e827 152 ipp_t *request; /* IPP Request */
00f3aaf5 153 char job_uri[HTTP_MAX_URI], /* job-uri */
154 printer_uri[HTTP_MAX_URI]; /* job-printer-uri */
38138d28 155
38138d28 156
b7c5e827 157 if (!http)
158 return (1);
38138d28 159
160 /*
5a4cc9a6 161 * Build a CUPS_MOVE_JOB request, which requires the following
38138d28 162 * attributes:
163 *
164 * attributes-charset
165 * attributes-natural-language
b7c5e827 166 * job-uri/printer-uri
5a4cc9a6 167 * job-printer-uri
00f3aaf5 168 * requesting-user-name
38138d28 169 */
170
00f3aaf5 171 request = ippNewRequest(CUPS_MOVE_JOB);
38138d28 172
b7c5e827 173 if (jobid)
174 {
175 snprintf(job_uri, sizeof(job_uri), "ipp://localhost/jobs/%d", jobid);
176 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL,
177 job_uri);
178 }
179 else
180 {
00a1fad8 181 httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
182 "localhost", 0, "/printers/%s", src);
b7c5e827 183 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
184 job_uri);
185 }
5a4cc9a6 186
e43e883e 187 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
188 NULL, cupsUser());
189
00a1fad8 190 httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
191 "ipp", NULL, "localhost", 0, "/printers/%s", dest);
5a4cc9a6 192 ippAddString(request, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri",
193 NULL, printer_uri);
194
38138d28 195 /*
196 * Do the request and get back a response...
197 */
198
b7c5e827 199 ippDelete(cupsDoRequest(http, request, "/jobs"));
38138d28 200
b7c5e827 201 if (cupsLastError() > IPP_OK_CONFLICT)
202 {
4c4eea89 203 _cupsLangPrintf(stderr, "lpmove: %s", cupsLastErrorString());
b7c5e827 204 return (1);
38138d28 205 }
206 else
b7c5e827 207 return (0);
38138d28 208}
209
210
211/*
c9d3f842 212 * End of "$Id$".
38138d28 213 */