]>
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 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include <cups/cups-private.h>
21 static int move_job(http_t
*http
, const char *src
, int jobid
,
26 * 'main()' - Parse options and show status information.
30 main(int argc
, /* I - Number of command-line arguments */
31 char *argv
[]) /* I - Command-line arguments */
33 int i
; /* Looping var */
34 http_t
*http
; /* Connection to server */
35 const char *opt
, /* Option pointer */
37 int jobid
; /* Job ID */
38 int num_dests
; /* Number of destinations */
39 cups_dest_t
*dests
; /* Destinations */
40 const char *src
, /* Original queue */
41 *dest
; /* New destination */
53 for (i
= 1; i
< argc
; i
++)
55 if (argv
[i
][0] == '-')
57 for (opt
= argv
[i
] + 1; *opt
; opt
++)
61 case 'E' : /* Encrypt */
63 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
66 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."), argv
[0]);
70 case 'h' : /* Connect to host */
73 cupsSetServer(opt
+ 1);
74 opt
+= strlen(opt
) - 1;
82 _cupsLangPuts(stderr
, _("Error: need hostname after \"-h\" option."));
86 cupsSetServer(argv
[i
]);
91 _cupsLangPrintf(stderr
, _("%s: Unknown option \"%c\"."), argv
[0], *opt
);
96 else if (!jobid
&& !src
)
99 num_dests
= cupsGetDests(&dests
);
101 if ((job
= strrchr(argv
[i
], '-')) != NULL
&&
102 cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) == NULL
)
103 jobid
= atoi(job
+ 1);
104 else if (isdigit(argv
[i
][0] & 255) &&
105 !cupsGetDest(argv
[i
], NULL
, num_dests
, dests
))
106 jobid
= atoi(argv
[i
]);
110 else if (dest
== NULL
)
114 _cupsLangPrintf(stderr
, _("lpmove: Unknown argument \"%s\"."), argv
[i
]);
119 if ((!jobid
&& !src
) || !dest
)
121 _cupsLangPuts(stdout
, _("Usage: lpmove job/src dest"));
125 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
129 _cupsLangPrintf(stderr
, _("lpmove: Unable to connect to server: %s"),
134 return (move_job(http
, src
, jobid
, dest
));
139 * 'move_job()' - Move a job.
142 static int /* O - 0 on success, 1 on error */
143 move_job(http_t
*http
, /* I - HTTP connection to server */
144 const char *src
, /* I - Source queue */
145 int jobid
, /* I - Job ID */
146 const char *dest
) /* I - Destination queue */
148 ipp_t
*request
; /* IPP Request */
149 char job_uri
[HTTP_MAX_URI
], /* job-uri */
150 printer_uri
[HTTP_MAX_URI
]; /* job-printer-uri */
157 * Build a CUPS_MOVE_JOB request, which requires the following
161 * attributes-natural-language
162 * job-uri/printer-uri
164 * requesting-user-name
167 request
= ippNewRequest(CUPS_MOVE_JOB
);
171 snprintf(job_uri
, sizeof(job_uri
), "ipp://localhost/jobs/%d", jobid
);
172 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
,
177 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
178 "localhost", 0, "/printers/%s", src
);
179 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
183 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
186 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
187 "ipp", NULL
, "localhost", 0, "/printers/%s", dest
);
188 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri",
192 * Do the request and get back a response...
195 ippDelete(cupsDoRequest(http
, request
, "/jobs"));
197 if (cupsLastError() > IPP_OK_CONFLICT
)
199 _cupsLangPrintf(stderr
, "lpmove: %s", cupsLastErrorString());