]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f7faf1f5 | 2 | * "$Id: lpmove.c 5023 2006-01-29 14:39:44Z mike $" |
ef416fc2 | 3 | * |
4 | * "lpmove" command for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 1997-2006 by Easy Software Products. | |
7 | * | |
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 | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636 USA | |
19 | * | |
20 | * Voice: (301) 373-9600 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * Contents: | |
25 | * | |
26 | * main() - Parse options and move jobs. | |
27 | * move_job() - Move a job. | |
28 | */ | |
29 | ||
30 | /* | |
31 | * Include necessary headers... | |
32 | */ | |
33 | ||
34 | #include <stdio.h> | |
35 | #include <stdlib.h> | |
36 | #include <errno.h> | |
37 | #include <cups/string.h> | |
38 | #include <cups/cups.h> | |
39 | #include <cups/i18n.h> | |
40 | #include <cups/debug.h> | |
41 | ||
42 | ||
43 | /* | |
44 | * Local functions... | |
45 | */ | |
46 | ||
fa73b229 | 47 | static int move_job(http_t *http, const char *src, int jobid, |
48 | const char *dest); | |
ef416fc2 | 49 | |
50 | ||
51 | /* | |
52 | * 'main()' - Parse options and show status information. | |
53 | */ | |
54 | ||
55 | int | |
56 | main(int argc, /* I - Number of command-line arguments */ | |
57 | char *argv[]) /* I - Command-line arguments */ | |
58 | { | |
59 | int i; /* Looping var */ | |
60 | http_t *http; /* Connection to server */ | |
61 | const char *job; /* Job name */ | |
fa73b229 | 62 | int jobid; /* Job ID */ |
ef416fc2 | 63 | int num_dests; /* Number of destinations */ |
64 | cups_dest_t *dests; /* Destinations */ | |
fa73b229 | 65 | const char *src, /* Original queue */ |
66 | *dest; /* New destination */ | |
ef416fc2 | 67 | |
68 | ||
fa73b229 | 69 | dest = NULL; |
70 | dests = NULL; | |
ef416fc2 | 71 | http = NULL; |
72 | job = NULL; | |
fa73b229 | 73 | jobid = 0; |
ef416fc2 | 74 | num_dests = 0; |
fa73b229 | 75 | src = NULL; |
ef416fc2 | 76 | |
77 | for (i = 1; i < argc; i ++) | |
78 | if (argv[i][0] == '-') | |
79 | switch (argv[i][1]) | |
80 | { | |
81 | case 'E' : /* Encrypt */ | |
82 | #ifdef HAVE_SSL | |
83 | cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); | |
84 | ||
85 | if (http) | |
86 | httpEncryption(http, HTTP_ENCRYPT_REQUIRED); | |
87 | #else | |
fa73b229 | 88 | _cupsLangPrintf(stderr, |
ef416fc2 | 89 | _("%s: Sorry, no encryption support compiled in!\n"), |
90 | argv[0]); | |
91 | #endif /* HAVE_SSL */ | |
92 | break; | |
93 | ||
94 | case 'h' : /* Connect to host */ | |
95 | if (http) | |
96 | { | |
97 | httpClose(http); | |
98 | http = NULL; | |
99 | } | |
100 | ||
101 | if (argv[i][2] != '\0') | |
102 | cupsSetServer(argv[i] + 2); | |
103 | else | |
104 | { | |
105 | i ++; | |
106 | ||
107 | if (i >= argc) | |
108 | { | |
fa73b229 | 109 | _cupsLangPuts(stderr, |
ef416fc2 | 110 | _("Error: need hostname after \'-h\' option!\n")); |
111 | return (1); | |
112 | } | |
113 | ||
114 | cupsSetServer(argv[i]); | |
115 | } | |
116 | break; | |
117 | ||
118 | default : | |
fa73b229 | 119 | _cupsLangPrintf(stderr, _("lpmove: Unknown option \'%c\'!\n"), |
ef416fc2 | 120 | argv[i][1]); |
121 | return (1); | |
122 | } | |
fa73b229 | 123 | else if (!jobid && !src) |
ef416fc2 | 124 | { |
125 | if (num_dests == 0) | |
126 | num_dests = cupsGetDests(&dests); | |
127 | ||
128 | if ((job = strrchr(argv[i], '-')) != NULL && | |
129 | cupsGetDest(argv[i], NULL, num_dests, dests) == NULL) | |
fa73b229 | 130 | jobid = atoi(job + 1); |
ef416fc2 | 131 | else |
fa73b229 | 132 | src = argv[i]; |
ef416fc2 | 133 | } |
134 | else if (dest == NULL) | |
135 | dest = argv[i]; | |
136 | else | |
137 | { | |
fa73b229 | 138 | _cupsLangPrintf(stderr, _("lpmove: Unknown argument \'%s\'!\n"), |
ef416fc2 | 139 | argv[i]); |
140 | return (1); | |
141 | } | |
142 | ||
fa73b229 | 143 | if ((!jobid && !src) || !dest) |
ef416fc2 | 144 | { |
fa73b229 | 145 | _cupsLangPuts(stdout, _("Usage: lpmove job/src dest\n")); |
ef416fc2 | 146 | return (1); |
147 | } | |
148 | ||
149 | if (!http) | |
150 | { | |
151 | http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); | |
152 | ||
153 | if (http == NULL) | |
154 | { | |
fa73b229 | 155 | _cupsLangPrintf(stderr, |
ef416fc2 | 156 | _("lpmove: Unable to connect to server: %s\n"), |
157 | strerror(errno)); | |
158 | return (1); | |
159 | } | |
160 | } | |
161 | ||
fa73b229 | 162 | return (move_job(http, src, jobid, dest)); |
ef416fc2 | 163 | } |
164 | ||
165 | ||
166 | /* | |
167 | * 'move_job()' - Move a job. | |
168 | */ | |
169 | ||
fa73b229 | 170 | static int /* O - 0 on success, 1 on error */ |
ef416fc2 | 171 | move_job(http_t *http, /* I - HTTP connection to server */ |
fa73b229 | 172 | const char *src, /* I - Source queue */ |
ef416fc2 | 173 | int jobid, /* I - Job ID */ |
fa73b229 | 174 | const char *dest) /* I - Destination queue */ |
ef416fc2 | 175 | { |
fa73b229 | 176 | ipp_t *request; /* IPP Request */ |
177 | char job_uri[HTTP_MAX_URI], /* job-uri */ | |
178 | printer_uri[HTTP_MAX_URI]; /* job-printer-uri */ | |
ef416fc2 | 179 | |
180 | ||
fa73b229 | 181 | if (!http) |
182 | return (1); | |
ef416fc2 | 183 | |
184 | /* | |
185 | * Build a CUPS_MOVE_JOB request, which requires the following | |
186 | * attributes: | |
187 | * | |
188 | * attributes-charset | |
189 | * attributes-natural-language | |
fa73b229 | 190 | * job-uri/printer-uri |
ef416fc2 | 191 | * job-printer-uri |
fa73b229 | 192 | * requesting-user-name |
ef416fc2 | 193 | */ |
194 | ||
fa73b229 | 195 | request = ippNewRequest(CUPS_MOVE_JOB); |
ef416fc2 | 196 | |
fa73b229 | 197 | if (jobid) |
198 | { | |
199 | snprintf(job_uri, sizeof(job_uri), "ipp://localhost/jobs/%d", jobid); | |
200 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, | |
201 | job_uri); | |
202 | } | |
203 | else | |
204 | { | |
a4d04587 | 205 | httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL, |
206 | "localhost", 0, "/printers/%s", src); | |
fa73b229 | 207 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, |
208 | job_uri); | |
209 | } | |
ef416fc2 | 210 | |
211 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", | |
212 | NULL, cupsUser()); | |
213 | ||
a4d04587 | 214 | httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri), |
215 | "ipp", NULL, "localhost", 0, "/printers/%s", dest); | |
ef416fc2 | 216 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", |
217 | NULL, printer_uri); | |
218 | ||
219 | /* | |
220 | * Do the request and get back a response... | |
221 | */ | |
222 | ||
fa73b229 | 223 | ippDelete(cupsDoRequest(http, request, "/jobs")); |
ef416fc2 | 224 | |
fa73b229 | 225 | if (cupsLastError() > IPP_OK_CONFLICT) |
226 | { | |
227 | _cupsLangPrintf(stderr, "lpmove: %s\n", cupsLastErrorString()); | |
228 | return (1); | |
ef416fc2 | 229 | } |
230 | else | |
fa73b229 | 231 | return (0); |
ef416fc2 | 232 | } |
233 | ||
234 | ||
235 | /* | |
f7faf1f5 | 236 | * End of "$Id: lpmove.c 5023 2006-01-29 14:39:44Z mike $". |
ef416fc2 | 237 | */ |