]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpmove.c
2 * "$Id: lpmove.c 5926 2006-09-05 20:45:47Z mike $"
4 * "lpmove" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Parse options and move jobs.
27 * move_job() - Move a job.
31 * Include necessary headers...
37 #include <cups/string.h>
38 #include <cups/cups.h>
39 #include <cups/i18n.h>
40 #include <cups/debug.h>
47 static int move_job(http_t
*http
, const char *src
, int jobid
,
52 * 'main()' - Parse options and show status information.
56 main(int argc
, /* I - Number of command-line arguments */
57 char *argv
[]) /* I - Command-line arguments */
59 int i
; /* Looping var */
60 http_t
*http
; /* Connection to server */
61 const char *job
; /* Job name */
62 int jobid
; /* Job ID */
63 int num_dests
; /* Number of destinations */
64 cups_dest_t
*dests
; /* Destinations */
65 const char *src
, /* Original queue */
66 *dest
; /* New destination */
79 for (i
= 1; i
< argc
; i
++)
80 if (argv
[i
][0] == '-')
83 case 'E' : /* Encrypt */
85 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
88 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
90 _cupsLangPrintf(stderr
,
91 _("%s: Sorry, no encryption support compiled in!\n"),
96 case 'h' : /* Connect to host */
103 if (argv
[i
][2] != '\0')
104 cupsSetServer(argv
[i
] + 2);
111 _cupsLangPuts(stderr
,
112 _("Error: need hostname after \'-h\' option!\n"));
116 cupsSetServer(argv
[i
]);
121 _cupsLangPrintf(stderr
, _("lpmove: Unknown option \'%c\'!\n"),
125 else if (!jobid
&& !src
)
128 num_dests
= cupsGetDests(&dests
);
130 if ((job
= strrchr(argv
[i
], '-')) != NULL
&&
131 cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) == NULL
)
132 jobid
= atoi(job
+ 1);
136 else if (dest
== NULL
)
140 _cupsLangPrintf(stderr
, _("lpmove: Unknown argument \'%s\'!\n"),
145 if ((!jobid
&& !src
) || !dest
)
147 _cupsLangPuts(stdout
, _("Usage: lpmove job/src dest\n"));
153 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
157 _cupsLangPrintf(stderr
,
158 _("lpmove: Unable to connect to server: %s\n"),
164 return (move_job(http
, src
, jobid
, dest
));
169 * 'move_job()' - Move a job.
172 static int /* O - 0 on success, 1 on error */
173 move_job(http_t
*http
, /* I - HTTP connection to server */
174 const char *src
, /* I - Source queue */
175 int jobid
, /* I - Job ID */
176 const char *dest
) /* I - Destination queue */
178 ipp_t
*request
; /* IPP Request */
179 char job_uri
[HTTP_MAX_URI
], /* job-uri */
180 printer_uri
[HTTP_MAX_URI
]; /* job-printer-uri */
187 * Build a CUPS_MOVE_JOB request, which requires the following
191 * attributes-natural-language
192 * job-uri/printer-uri
194 * requesting-user-name
197 request
= ippNewRequest(CUPS_MOVE_JOB
);
201 snprintf(job_uri
, sizeof(job_uri
), "ipp://localhost/jobs/%d", jobid
);
202 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
207 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
208 "localhost", 0, "/printers/%s", src
);
209 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
213 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
216 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
217 "ipp", NULL
, "localhost", 0, "/printers/%s", dest
);
218 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri",
222 * Do the request and get back a response...
225 ippDelete(cupsDoRequest(http
, request
, "/jobs"));
227 if (cupsLastError() > IPP_OK_CONFLICT
)
229 _cupsLangPrintf(stderr
, "lpmove: %s\n", cupsLastErrorString());
238 * End of "$Id: lpmove.c 5926 2006-09-05 20:45:47Z mike $".