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