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