]> git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpmove.c
"-E" option for all commands (use encryption.)
[thirdparty/cups.git] / systemv / lpmove.c
1 /*
2 * "$Id: lpmove.c,v 1.5 2001/01/23 17:36:24 mike Exp $"
3 *
4 * "lpmove" command for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2001 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-3111 USA
19 *
20 * Voice: (301) 373-9603
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 <ctype.h>
37 #include <cups/cups.h>
38 #include <cups/language.h>
39 #include <cups/debug.h>
40 #include <cups/string.h>
41
42
43 /*
44 * Local functions...
45 */
46
47 static void move_job(http_t *, int, const char *);
48
49
50 /*
51 * 'main()' - Parse options and show status information.
52 */
53
54 int
55 main(int argc, /* I - Number of command-line arguments */
56 char *argv[]) /* I - Command-line arguments */
57 {
58 int i; /* Looping var */
59 http_t *http; /* Connection to server */
60 const char *job; /* Job name */
61 const char *dest; /* New destination */
62 http_encryption_t encryption; /* Encryption? */
63
64
65 http = NULL;
66 job = NULL;
67 dest = NULL;
68 encryption = cupsEncryption();
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_LIBSSL
76 encryption = HTTP_ENCRYPT_REQUIRED;
77
78 if (http)
79 httpEncryption(http, encryption);
80 #else
81 fprintf(stderr, "%s: Sorry, no encryption support compiled in!\n",
82 argv[0]);
83 #endif /* HAVE_LIBSSL */
84 break;
85
86 case 'h' : /* Connect to host */
87 if (http)
88 httpClose(http);
89
90 if (argv[i][2] != '\0')
91 http = httpConnect(argv[i] + 2, ippPort());
92 else
93 {
94 i ++;
95
96 if (i >= argc)
97 {
98 fputs("Error: need hostname after \'-h\' option!\n", stderr);
99 return (1);
100 }
101
102 http = httpConnect(argv[i], ippPort());
103 }
104
105 if (http == NULL)
106 {
107 perror("lpmove: Unable to connect to server");
108 return (1);
109 }
110
111 httpEncryption(http, encryption);
112 break;
113
114 default :
115 fprintf(stderr, "lpmove: Unknown option \'%c\'!\n", argv[i][1]);
116 return (1);
117 }
118 else if (job == NULL)
119 {
120 if ((job = strrchr(argv[i], '-')) != NULL)
121 job ++;
122 else
123 job = argv[i];
124 }
125 else if (dest == NULL)
126 dest = argv[i];
127 else
128 {
129 fprintf(stderr, "lpmove: Unknown argument \'%s\'!\n", argv[i]);
130 return (1);
131 }
132
133 if (job == NULL || dest == NULL)
134 {
135 puts("Usage: lpmove job dest");
136 return (1);
137 }
138
139 if (!http)
140 {
141 http = httpConnect(cupsServer(), ippPort());
142
143 if (http == NULL)
144 {
145 perror("lpmove: Unable to connect to server");
146 return (1);
147 }
148
149 httpEncryption(http, encryption);
150 }
151
152 move_job(http, atoi(job), dest);
153
154 return (0);
155 }
156
157
158 /*
159 * 'move_job()' - Move a job.
160 */
161
162 static void
163 move_job(http_t *http, /* I - HTTP connection to server */
164 int jobid, /* I - Job ID */
165 const char *dest) /* I - Destination */
166 {
167 ipp_t *request, /* IPP Request */
168 *response; /* IPP Response */
169 cups_lang_t *language; /* Default language */
170 char job_uri[HTTP_MAX_URI],
171 /* job-uri */
172 printer_uri[HTTP_MAX_URI];
173 /* job-printer-uri */
174
175
176 if (http == NULL)
177 return;
178
179 /*
180 * Build a CUPS_MOVE_JOB request, which requires the following
181 * attributes:
182 *
183 * attributes-charset
184 * attributes-natural-language
185 * job-uri
186 * job-printer-uri
187 */
188
189 request = ippNew();
190
191 request->request.op.operation_id = CUPS_MOVE_JOB;
192 request->request.op.request_id = 1;
193
194 language = cupsLangDefault();
195
196 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
197 "attributes-charset", NULL, cupsLangEncoding(language));
198
199 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
200 "attributes-natural-language", NULL, language->language);
201
202 snprintf(job_uri, sizeof(job_uri), "ipp://localhost/jobs/%d", jobid);
203 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, job_uri);
204
205 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
206 NULL, cupsUser());
207
208 snprintf(printer_uri, sizeof(printer_uri), "ipp://localhost/printers/%s", dest);
209 ippAddString(request, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri",
210 NULL, printer_uri);
211
212 /*
213 * Do the request and get back a response...
214 */
215
216 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
217 {
218 if (response->request.status.status_code > IPP_OK_CONFLICT)
219 {
220 fprintf(stderr, "lpmove: move-job failed: %s\n",
221 ippErrorString(response->request.status.status_code));
222 ippDelete(response);
223 return;
224 }
225
226 ippDelete(response);
227 }
228 else
229 fprintf(stderr, "lpmove: move-job failed: %s\n",
230 ippErrorString(cupsLastError()));
231 }
232
233
234 /*
235 * End of "$Id: lpmove.c,v 1.5 2001/01/23 17:36:24 mike Exp $".
236 */