]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
d09495fa | 2 | * "$Id: lpmove.c 5833 2006-08-16 20:05:58Z 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 | ||
d09495fa | 69 | _cupsSetLocale(); |
70 | ||
fa73b229 | 71 | dest = NULL; |
72 | dests = NULL; | |
ef416fc2 | 73 | http = NULL; |
74 | job = NULL; | |
fa73b229 | 75 | jobid = 0; |
ef416fc2 | 76 | num_dests = 0; |
fa73b229 | 77 | src = NULL; |
ef416fc2 | 78 | |
79 | for (i = 1; i < argc; i ++) | |
80 | if (argv[i][0] == '-') | |
81 | switch (argv[i][1]) | |
82 | { | |
83 | case 'E' : /* Encrypt */ | |
84 | #ifdef HAVE_SSL | |
85 | cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); | |
86 | ||
87 | if (http) | |
88 | httpEncryption(http, HTTP_ENCRYPT_REQUIRED); | |
89 | #else | |
fa73b229 | 90 | _cupsLangPrintf(stderr, |
ef416fc2 | 91 | _("%s: Sorry, no encryption support compiled in!\n"), |
92 | argv[0]); | |
93 | #endif /* HAVE_SSL */ | |
94 | break; | |
95 | ||
96 | case 'h' : /* Connect to host */ | |
97 | if (http) | |
98 | { | |
99 | httpClose(http); | |
100 | http = NULL; | |
101 | } | |
102 | ||
103 | if (argv[i][2] != '\0') | |
104 | cupsSetServer(argv[i] + 2); | |
105 | else | |
106 | { | |
107 | i ++; | |
108 | ||
109 | if (i >= argc) | |
110 | { | |
fa73b229 | 111 | _cupsLangPuts(stderr, |
ef416fc2 | 112 | _("Error: need hostname after \'-h\' option!\n")); |
113 | return (1); | |
114 | } | |
115 | ||
116 | cupsSetServer(argv[i]); | |
117 | } | |
118 | break; | |
119 | ||
120 | default : | |
fa73b229 | 121 | _cupsLangPrintf(stderr, _("lpmove: Unknown option \'%c\'!\n"), |
ef416fc2 | 122 | argv[i][1]); |
123 | return (1); | |
124 | } | |
fa73b229 | 125 | else if (!jobid && !src) |
ef416fc2 | 126 | { |
127 | if (num_dests == 0) | |
128 | num_dests = cupsGetDests(&dests); | |
129 | ||
130 | if ((job = strrchr(argv[i], '-')) != NULL && | |
131 | cupsGetDest(argv[i], NULL, num_dests, dests) == NULL) | |
fa73b229 | 132 | jobid = atoi(job + 1); |
ef416fc2 | 133 | else |
fa73b229 | 134 | src = argv[i]; |
ef416fc2 | 135 | } |
136 | else if (dest == NULL) | |
137 | dest = argv[i]; | |
138 | else | |
139 | { | |
fa73b229 | 140 | _cupsLangPrintf(stderr, _("lpmove: Unknown argument \'%s\'!\n"), |
ef416fc2 | 141 | argv[i]); |
142 | return (1); | |
143 | } | |
144 | ||
fa73b229 | 145 | if ((!jobid && !src) || !dest) |
ef416fc2 | 146 | { |
fa73b229 | 147 | _cupsLangPuts(stdout, _("Usage: lpmove job/src dest\n")); |
ef416fc2 | 148 | return (1); |
149 | } | |
150 | ||
151 | if (!http) | |
152 | { | |
153 | http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); | |
154 | ||
155 | if (http == NULL) | |
156 | { | |
fa73b229 | 157 | _cupsLangPrintf(stderr, |
ef416fc2 | 158 | _("lpmove: Unable to connect to server: %s\n"), |
159 | strerror(errno)); | |
160 | return (1); | |
161 | } | |
162 | } | |
163 | ||
fa73b229 | 164 | return (move_job(http, src, jobid, dest)); |
ef416fc2 | 165 | } |
166 | ||
167 | ||
168 | /* | |
169 | * 'move_job()' - Move a job. | |
170 | */ | |
171 | ||
fa73b229 | 172 | static int /* O - 0 on success, 1 on error */ |
ef416fc2 | 173 | move_job(http_t *http, /* I - HTTP connection to server */ |
fa73b229 | 174 | const char *src, /* I - Source queue */ |
ef416fc2 | 175 | int jobid, /* I - Job ID */ |
fa73b229 | 176 | const char *dest) /* I - Destination queue */ |
ef416fc2 | 177 | { |
fa73b229 | 178 | ipp_t *request; /* IPP Request */ |
179 | char job_uri[HTTP_MAX_URI], /* job-uri */ | |
180 | printer_uri[HTTP_MAX_URI]; /* job-printer-uri */ | |
ef416fc2 | 181 | |
182 | ||
fa73b229 | 183 | if (!http) |
184 | return (1); | |
ef416fc2 | 185 | |
186 | /* | |
187 | * Build a CUPS_MOVE_JOB request, which requires the following | |
188 | * attributes: | |
189 | * | |
190 | * attributes-charset | |
191 | * attributes-natural-language | |
fa73b229 | 192 | * job-uri/printer-uri |
ef416fc2 | 193 | * job-printer-uri |
fa73b229 | 194 | * requesting-user-name |
ef416fc2 | 195 | */ |
196 | ||
fa73b229 | 197 | request = ippNewRequest(CUPS_MOVE_JOB); |
ef416fc2 | 198 | |
fa73b229 | 199 | if (jobid) |
200 | { | |
201 | snprintf(job_uri, sizeof(job_uri), "ipp://localhost/jobs/%d", jobid); | |
202 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, | |
203 | job_uri); | |
204 | } | |
205 | else | |
206 | { | |
a4d04587 | 207 | httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL, |
208 | "localhost", 0, "/printers/%s", src); | |
fa73b229 | 209 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, |
210 | job_uri); | |
211 | } | |
ef416fc2 | 212 | |
213 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", | |
214 | NULL, cupsUser()); | |
215 | ||
a4d04587 | 216 | httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri), |
217 | "ipp", NULL, "localhost", 0, "/printers/%s", dest); | |
ef416fc2 | 218 | ippAddString(request, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", |
219 | NULL, printer_uri); | |
220 | ||
221 | /* | |
222 | * Do the request and get back a response... | |
223 | */ | |
224 | ||
fa73b229 | 225 | ippDelete(cupsDoRequest(http, request, "/jobs")); |
ef416fc2 | 226 | |
fa73b229 | 227 | if (cupsLastError() > IPP_OK_CONFLICT) |
228 | { | |
229 | _cupsLangPrintf(stderr, "lpmove: %s\n", cupsLastErrorString()); | |
230 | return (1); | |
ef416fc2 | 231 | } |
232 | else | |
fa73b229 | 233 | return (0); |
ef416fc2 | 234 | } |
235 | ||
236 | ||
237 | /* | |
d09495fa | 238 | * End of "$Id: lpmove.c 5833 2006-08-16 20:05:58Z mike $". |
ef416fc2 | 239 | */ |