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