2 * "$Id: lpmove.c,v 1.5.2.1 2001/05/13 18:38:41 mike Exp $"
4 * "lpmove" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2001 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Parse options and move jobs.
27 * move_job() - Move a job.
31 * Include necessary headers...
37 #include <cups/cups.h>
38 #include <cups/language.h>
39 #include <cups/debug.h>
40 #include <cups/string.h>
47 static void move_job(http_t
*, int, const char *);
51 * 'main()' - Parse options and show status information.
55 main(int argc
, /* I - Number of command-line arguments */
56 char *argv
[]) /* I - Command-line arguments */
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? */
68 encryption
= cupsEncryption();
70 for (i
= 1; i
< argc
; i
++)
71 if (argv
[i
][0] == '-')
74 case 'E' : /* Encrypt */
76 encryption
= HTTP_ENCRYPT_REQUIRED
;
79 httpEncryption(http
, encryption
);
81 fprintf(stderr
, "%s: Sorry, no encryption support compiled in!\n",
83 #endif /* HAVE_LIBSSL */
86 case 'h' : /* Connect to host */
90 if (argv
[i
][2] != '\0')
91 http
= httpConnectEncrypt(argv
[i
] + 2, ippPort(), encryption
);
98 fputs("Error: need hostname after \'-h\' option!\n", stderr
);
102 http
= httpConnectEncrypt(argv
[i
], ippPort(), encryption
);
107 perror("lpmove: Unable to connect to server");
113 fprintf(stderr
, "lpmove: Unknown option \'%c\'!\n", argv
[i
][1]);
116 else if (job
== NULL
)
118 if ((job
= strrchr(argv
[i
], '-')) != NULL
)
123 else if (dest
== NULL
)
127 fprintf(stderr
, "lpmove: Unknown argument \'%s\'!\n", argv
[i
]);
131 if (job
== NULL
|| dest
== NULL
)
133 puts("Usage: lpmove job dest");
139 http
= httpConnectEncrypt(cupsServer(), ippPort(), encryption
);
143 perror("lpmove: Unable to connect to server");
148 move_job(http
, atoi(job
), dest
);
155 * 'move_job()' - Move a job.
159 move_job(http_t
*http
, /* I - HTTP connection to server */
160 int jobid
, /* I - Job ID */
161 const char *dest
) /* I - Destination */
163 ipp_t
*request
, /* IPP Request */
164 *response
; /* IPP Response */
165 cups_lang_t
*language
; /* Default language */
166 char job_uri
[HTTP_MAX_URI
],
168 printer_uri
[HTTP_MAX_URI
];
169 /* job-printer-uri */
176 * Build a CUPS_MOVE_JOB request, which requires the following
180 * attributes-natural-language
187 request
->request
.op
.operation_id
= CUPS_MOVE_JOB
;
188 request
->request
.op
.request_id
= 1;
190 language
= cupsLangDefault();
192 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
193 "attributes-charset", NULL
, cupsLangEncoding(language
));
195 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
196 "attributes-natural-language", NULL
, language
->language
);
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
);
201 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
204 snprintf(printer_uri
, sizeof(printer_uri
), "ipp://localhost/printers/%s", dest
);
205 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri",
209 * Do the request and get back a response...
212 if ((response
= cupsDoRequest(http
, request
, "/jobs")) != NULL
)
214 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
216 fprintf(stderr
, "lpmove: move-job failed: %s\n",
217 ippErrorString(response
->request
.status
.status_code
));
225 fprintf(stderr
, "lpmove: move-job failed: %s\n",
226 ippErrorString(cupsLastError()));
231 * End of "$Id: lpmove.c,v 1.5.2.1 2001/05/13 18:38:41 mike Exp $".