]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpmove.c
2 * "lpmove" command for CUPS.
4 * Copyright 2007-2010 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
18 #include <cups/cups-private.h>
25 static int move_job(http_t
*http
, const char *src
, int jobid
,
30 * 'main()' - Parse options and show status information.
34 main(int argc
, /* I - Number of command-line arguments */
35 char *argv
[]) /* I - Command-line arguments */
37 int i
; /* Looping var */
38 http_t
*http
; /* Connection to server */
39 const char *job
; /* Job name */
40 int jobid
; /* Job ID */
41 int num_dests
; /* Number of destinations */
42 cups_dest_t
*dests
; /* Destinations */
43 const char *src
, /* Original queue */
44 *dest
; /* New destination */
56 for (i
= 1; i
< argc
; i
++)
57 if (argv
[i
][0] == '-')
60 case 'E' : /* Encrypt */
62 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
65 _cupsLangPrintf(stderr
,
66 _("%s: Sorry, no encryption support."),
71 case 'h' : /* Connect to host */
72 if (argv
[i
][2] != '\0')
73 cupsSetServer(argv
[i
] + 2);
81 _("Error: need hostname after \"-h\" option."));
85 cupsSetServer(argv
[i
]);
90 _cupsLangPrintf(stderr
, _("lpmove: Unknown option \"%c\"."),
94 else if (!jobid
&& !src
)
97 num_dests
= cupsGetDests(&dests
);
99 if ((job
= strrchr(argv
[i
], '-')) != NULL
&&
100 cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) == NULL
)
101 jobid
= atoi(job
+ 1);
102 else if (isdigit(argv
[i
][0] & 255) &&
103 !cupsGetDest(argv
[i
], NULL
, num_dests
, dests
))
104 jobid
= atoi(argv
[i
]);
108 else if (dest
== NULL
)
112 _cupsLangPrintf(stderr
, _("lpmove: Unknown argument \"%s\"."), argv
[i
]);
116 if ((!jobid
&& !src
) || !dest
)
118 _cupsLangPuts(stdout
, _("Usage: lpmove job/src dest"));
122 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
126 _cupsLangPrintf(stderr
, _("lpmove: Unable to connect to server: %s"),
131 return (move_job(http
, src
, jobid
, dest
));
136 * 'move_job()' - Move a job.
139 static int /* O - 0 on success, 1 on error */
140 move_job(http_t
*http
, /* I - HTTP connection to server */
141 const char *src
, /* I - Source queue */
142 int jobid
, /* I - Job ID */
143 const char *dest
) /* I - Destination queue */
145 ipp_t
*request
; /* IPP Request */
146 char job_uri
[HTTP_MAX_URI
], /* job-uri */
147 printer_uri
[HTTP_MAX_URI
]; /* job-printer-uri */
154 * Build a CUPS_MOVE_JOB request, which requires the following
158 * attributes-natural-language
159 * job-uri/printer-uri
161 * requesting-user-name
164 request
= ippNewRequest(CUPS_MOVE_JOB
);
168 snprintf(job_uri
, sizeof(job_uri
), "ipp://localhost/jobs/%d", jobid
);
169 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
174 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
175 "localhost", 0, "/printers/%s", src
);
176 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
180 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
183 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
184 "ipp", NULL
, "localhost", 0, "/printers/%s", dest
);
185 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri",
189 * Do the request and get back a response...
192 ippDelete(cupsDoRequest(http
, request
, "/jobs"));
194 if (cupsLastError() > IPP_OK_CONFLICT
)
196 _cupsLangPrintf(stderr
, "lpmove: %s", cupsLastErrorString());