]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpmove.c
2 * "$Id: lpmove.c 7219 2008-01-14 22:00:02Z mike $"
4 * "lpmove" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
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/".
17 * main() - Parse options and move jobs.
18 * move_job() - Move a job.
22 * Include necessary headers...
28 #include <cups/string.h>
29 #include <cups/cups.h>
30 #include <cups/i18n.h>
31 #include <cups/debug.h>
38 static int move_job(http_t
*http
, const char *src
, int jobid
,
43 * 'main()' - Parse options and show status information.
47 main(int argc
, /* I - Number of command-line arguments */
48 char *argv
[]) /* I - Command-line arguments */
50 int i
; /* Looping var */
51 http_t
*http
; /* Connection to server */
52 const char *job
; /* Job name */
53 int jobid
; /* Job ID */
54 int num_dests
; /* Number of destinations */
55 cups_dest_t
*dests
; /* Destinations */
56 const char *src
, /* Original queue */
57 *dest
; /* New destination */
69 for (i
= 1; i
< argc
; i
++)
70 if (argv
[i
][0] == '-')
73 case 'E' : /* Encrypt */
75 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
78 _cupsLangPrintf(stderr
,
79 _("%s: Sorry, no encryption support compiled in!\n"),
84 case 'h' : /* Connect to host */
85 if (argv
[i
][2] != '\0')
86 cupsSetServer(argv
[i
] + 2);
94 _("Error: need hostname after \'-h\' option!\n"));
98 cupsSetServer(argv
[i
]);
103 _cupsLangPrintf(stderr
, _("lpmove: Unknown option \'%c\'!\n"),
107 else if (!jobid
&& !src
)
110 num_dests
= cupsGetDests(&dests
);
112 if ((job
= strrchr(argv
[i
], '-')) != NULL
&&
113 cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) == NULL
)
114 jobid
= atoi(job
+ 1);
115 else if (isdigit(argv
[i
][0] & 255) &&
116 !cupsGetDest(argv
[i
], NULL
, num_dests
, dests
))
117 jobid
= atoi(argv
[i
]);
121 else if (dest
== NULL
)
125 _cupsLangPrintf(stderr
, _("lpmove: Unknown argument \'%s\'!\n"),
130 if ((!jobid
&& !src
) || !dest
)
132 _cupsLangPuts(stdout
, _("Usage: lpmove job/src dest\n"));
136 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
140 _cupsLangPrintf(stderr
,
141 _("lpmove: Unable to connect to server: %s\n"),
146 return (move_job(http
, src
, jobid
, dest
));
151 * 'move_job()' - Move a job.
154 static int /* O - 0 on success, 1 on error */
155 move_job(http_t
*http
, /* I - HTTP connection to server */
156 const char *src
, /* I - Source queue */
157 int jobid
, /* I - Job ID */
158 const char *dest
) /* I - Destination queue */
160 ipp_t
*request
; /* IPP Request */
161 char job_uri
[HTTP_MAX_URI
], /* job-uri */
162 printer_uri
[HTTP_MAX_URI
]; /* job-printer-uri */
169 * Build a CUPS_MOVE_JOB request, which requires the following
173 * attributes-natural-language
174 * job-uri/printer-uri
176 * requesting-user-name
179 request
= ippNewRequest(CUPS_MOVE_JOB
);
183 snprintf(job_uri
, sizeof(job_uri
), "ipp://localhost/jobs/%d", jobid
);
184 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
189 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
190 "localhost", 0, "/printers/%s", src
);
191 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
195 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
198 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
199 "ipp", NULL
, "localhost", 0, "/printers/%s", dest
);
200 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri",
204 * Do the request and get back a response...
207 ippDelete(cupsDoRequest(http
, request
, "/jobs"));
209 if (cupsLastError() > IPP_OK_CONFLICT
)
211 _cupsLangPrintf(stderr
, "lpmove: %s\n", cupsLastErrorString());
220 * End of "$Id: lpmove.c 7219 2008-01-14 22:00:02Z mike $".