]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpmove.c
2 * "lpmove" command for CUPS.
4 * Copyright 2007-2016 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 * 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 *opt
, /* Option pointer */
41 int jobid
; /* Job ID */
42 int num_dests
; /* Number of destinations */
43 cups_dest_t
*dests
; /* Destinations */
44 const char *src
, /* Original queue */
45 *dest
; /* New destination */
57 for (i
= 1; i
< argc
; i
++)
59 if (argv
[i
][0] == '-')
61 for (opt
= argv
[i
] + 1; *opt
; opt
++)
65 case 'E' : /* Encrypt */
67 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
70 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."), argv
[0]);
74 case 'h' : /* Connect to host */
77 cupsSetServer(opt
+ 1);
78 opt
+= strlen(opt
) - 1;
86 _cupsLangPuts(stderr
, _("Error: need hostname after \"-h\" option."));
90 cupsSetServer(argv
[i
]);
95 _cupsLangPrintf(stderr
, _("%s: Unknown option \"%c\"."), argv
[0], *opt
);
100 else if (!jobid
&& !src
)
103 num_dests
= cupsGetDests(&dests
);
105 if ((job
= strrchr(argv
[i
], '-')) != NULL
&&
106 cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) == NULL
)
107 jobid
= atoi(job
+ 1);
108 else if (isdigit(argv
[i
][0] & 255) &&
109 !cupsGetDest(argv
[i
], NULL
, num_dests
, dests
))
110 jobid
= atoi(argv
[i
]);
114 else if (dest
== NULL
)
118 _cupsLangPrintf(stderr
, _("lpmove: Unknown argument \"%s\"."), argv
[i
]);
123 if ((!jobid
&& !src
) || !dest
)
125 _cupsLangPuts(stdout
, _("Usage: lpmove job/src dest"));
129 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
133 _cupsLangPrintf(stderr
, _("lpmove: Unable to connect to server: %s"),
138 return (move_job(http
, src
, jobid
, dest
));
143 * 'move_job()' - Move a job.
146 static int /* O - 0 on success, 1 on error */
147 move_job(http_t
*http
, /* I - HTTP connection to server */
148 const char *src
, /* I - Source queue */
149 int jobid
, /* I - Job ID */
150 const char *dest
) /* I - Destination queue */
152 ipp_t
*request
; /* IPP Request */
153 char job_uri
[HTTP_MAX_URI
], /* job-uri */
154 printer_uri
[HTTP_MAX_URI
]; /* job-printer-uri */
161 * Build a CUPS_MOVE_JOB request, which requires the following
165 * attributes-natural-language
166 * job-uri/printer-uri
168 * requesting-user-name
171 request
= ippNewRequest(CUPS_MOVE_JOB
);
175 snprintf(job_uri
, sizeof(job_uri
), "ipp://localhost/jobs/%d", jobid
);
176 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
181 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
182 "localhost", 0, "/printers/%s", src
);
183 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
187 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
190 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
191 "ipp", NULL
, "localhost", 0, "/printers/%s", dest
);
192 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri",
196 * Do the request and get back a response...
199 ippDelete(cupsDoRequest(http
, request
, "/jobs"));
201 if (cupsLastError() > IPP_OK_CONFLICT
)
203 _cupsLangPrintf(stderr
, "lpmove: %s", cupsLastErrorString());