]> git.ipfire.org Git - thirdparty/cups.git/blame - systemv/lpmove.c
Copyright update...
[thirdparty/cups.git] / systemv / lpmove.c
CommitLineData
38138d28 1/*
efb2f309 2 * "$Id: lpmove.c,v 1.7 2002/01/02 17:59:19 mike Exp $"
38138d28 3 *
5a4cc9a6 4 * "lpmove" command for the Common UNIX Printing System (CUPS).
38138d28 5 *
efb2f309 6 * Copyright 1997-2002 by Easy Software Products.
38138d28 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 *
5a4cc9a6 26 * main() - Parse options and move jobs.
27 * move_job() - Move a job.
38138d28 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
5a4cc9a6 47static void move_job(http_t *, int, const char *);
38138d28 48
49
50/*
51 * 'main()' - Parse options and show status information.
52 */
53
54int
55main(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 */
5a4cc9a6 60 const char *job; /* Job name */
61 const char *dest; /* New destination */
1c9e0181 62 http_encryption_t encryption; /* Encryption? */
38138d28 63
64
1c9e0181 65 http = NULL;
66 job = NULL;
67 dest = NULL;
68 encryption = cupsEncryption();
38138d28 69
70 for (i = 1; i < argc; i ++)
71 if (argv[i][0] == '-')
72 switch (argv[i][1])
73 {
1c9e0181 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
38138d28 86 case 'h' : /* Connect to host */
87 if (http)
88 httpClose(http);
89
90 if (argv[i][2] != '\0')
a1793153 91 http = httpConnectEncrypt(argv[i] + 2, ippPort(), encryption);
38138d28 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
a1793153 102 http = httpConnectEncrypt(argv[i], ippPort(), encryption);
38138d28 103 }
104
38138d28 105 if (http == NULL)
106 {
5a4cc9a6 107 perror("lpmove: Unable to connect to server");
38138d28 108 return (1);
109 }
110 break;
111
38138d28 112 default :
5a4cc9a6 113 fprintf(stderr, "lpmove: Unknown option \'%c\'!\n", argv[i][1]);
38138d28 114 return (1);
115 }
5a4cc9a6 116 else if (job == NULL)
117 {
118 if ((job = strrchr(argv[i], '-')) != NULL)
119 job ++;
120 else
121 job = argv[i];
122 }
123 else if (dest == NULL)
124 dest = argv[i];
38138d28 125 else
126 {
5a4cc9a6 127 fprintf(stderr, "lpmove: Unknown argument \'%s\'!\n", argv[i]);
38138d28 128 return (1);
129 }
130
5a4cc9a6 131 if (job == NULL || dest == NULL)
38138d28 132 {
5a4cc9a6 133 puts("Usage: lpmove job dest");
134 return (1);
135 }
38138d28 136
5a4cc9a6 137 if (!http)
138 {
a1793153 139 http = httpConnectEncrypt(cupsServer(), ippPort(), encryption);
38138d28 140
5a4cc9a6 141 if (http == NULL)
142 {
143 perror("lpmove: Unable to connect to server");
144 return (1);
145 }
38138d28 146 }
147
5a4cc9a6 148 move_job(http, atoi(job), dest);
149
38138d28 150 return (0);
151}
152
153
154/*
5a4cc9a6 155 * 'move_job()' - Move a job.
38138d28 156 */
157
158static void
5a4cc9a6 159move_job(http_t *http, /* I - HTTP connection to server */
160 int jobid, /* I - Job ID */
161 const char *dest) /* I - Destination */
38138d28 162{
38138d28 163 ipp_t *request, /* IPP Request */
164 *response; /* IPP Response */
38138d28 165 cups_lang_t *language; /* Default language */
5a4cc9a6 166 char job_uri[HTTP_MAX_URI],
167 /* job-uri */
168 printer_uri[HTTP_MAX_URI];
169 /* job-printer-uri */
38138d28 170
38138d28 171
172 if (http == NULL)
173 return;
174
175 /*
5a4cc9a6 176 * Build a CUPS_MOVE_JOB request, which requires the following
38138d28 177 * attributes:
178 *
179 * attributes-charset
180 * attributes-natural-language
5a4cc9a6 181 * job-uri
182 * job-printer-uri
38138d28 183 */
184
185 request = ippNew();
186
5a4cc9a6 187 request->request.op.operation_id = CUPS_MOVE_JOB;
38138d28 188 request->request.op.request_id = 1;
189
190 language = cupsLangDefault();
191
192 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
193 "attributes-charset", NULL, cupsLangEncoding(language));
194
195 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
196 "attributes-natural-language", NULL, language->language);
197
5a4cc9a6 198 snprintf(job_uri, sizeof(job_uri), "ipp://localhost/jobs/%d", jobid);
199 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, job_uri);
200
e43e883e 201 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
202 NULL, cupsUser());
203
5a4cc9a6 204 snprintf(printer_uri, sizeof(printer_uri), "ipp://localhost/printers/%s", dest);
205 ippAddString(request, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri",
206 NULL, printer_uri);
207
38138d28 208 /*
209 * Do the request and get back a response...
210 */
211
5a4cc9a6 212 if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
38138d28 213 {
38138d28 214 if (response->request.status.status_code > IPP_OK_CONFLICT)
215 {
5a4cc9a6 216 fprintf(stderr, "lpmove: move-job failed: %s\n",
38138d28 217 ippErrorString(response->request.status.status_code));
218 ippDelete(response);
219 return;
220 }
221
38138d28 222 ippDelete(response);
223 }
224 else
5a4cc9a6 225 fprintf(stderr, "lpmove: move-job failed: %s\n",
38138d28 226 ippErrorString(cupsLastError()));
227}
228
229
230/*
efb2f309 231 * End of "$Id: lpmove.c,v 1.7 2002/01/02 17:59:19 mike Exp $".
38138d28 232 */