]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpmove.c
2 * "$Id: lpmove.c 4906 2006-01-10 20:53:28Z mike $"
4 * "lpmove" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 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 USA
20 * Voice: (301) 373-9600
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/string.h>
38 #include <cups/cups.h>
39 #include <cups/i18n.h>
40 #include <cups/debug.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 int num_dests
; /* Number of destinations */
62 cups_dest_t
*dests
; /* Destinations */
63 const char *dest
; /* New destination */
72 for (i
= 1; i
< argc
; i
++)
73 if (argv
[i
][0] == '-')
76 case 'E' : /* Encrypt */
78 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
81 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
83 _cupsLangPrintf(stderr
, NULL
,
84 _("%s: Sorry, no encryption support compiled in!\n"),
89 case 'h' : /* Connect to host */
96 if (argv
[i
][2] != '\0')
97 cupsSetServer(argv
[i
] + 2);
104 _cupsLangPuts(stderr
, NULL
,
105 _("Error: need hostname after \'-h\' option!\n"));
109 cupsSetServer(argv
[i
]);
114 _cupsLangPrintf(stderr
, NULL
, _("lpmove: Unknown option \'%c\'!\n"),
118 else if (job
== NULL
)
121 num_dests
= cupsGetDests(&dests
);
123 if ((job
= strrchr(argv
[i
], '-')) != NULL
&&
124 cupsGetDest(argv
[i
], NULL
, num_dests
, dests
) == NULL
)
129 else if (dest
== NULL
)
133 _cupsLangPrintf(stderr
, NULL
, _("lpmove: Unknown argument \'%s\'!\n"),
138 if (job
== NULL
|| dest
== NULL
)
140 _cupsLangPuts(stdout
, NULL
, _("Usage: lpmove job dest\n"));
146 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
150 _cupsLangPrintf(stderr
, NULL
,
151 _("lpmove: Unable to connect to server: %s\n"),
157 move_job(http
, atoi(job
), dest
);
164 * 'move_job()' - Move a job.
168 move_job(http_t
*http
, /* I - HTTP connection to server */
169 int jobid
, /* I - Job ID */
170 const char *dest
) /* I - Destination */
172 ipp_t
*request
, /* IPP Request */
173 *response
; /* IPP Response */
174 cups_lang_t
*language
; /* Default language */
175 char job_uri
[HTTP_MAX_URI
], /* job-uri */
176 printer_uri
[HTTP_MAX_URI
];
177 /* job-printer-uri */
184 * Build a CUPS_MOVE_JOB request, which requires the following
188 * attributes-natural-language
195 request
->request
.op
.operation_id
= CUPS_MOVE_JOB
;
196 request
->request
.op
.request_id
= 1;
198 language
= cupsLangDefault();
200 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
201 "attributes-charset", NULL
, cupsLangEncoding(language
));
203 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
204 "attributes-natural-language", NULL
, language
->language
);
206 snprintf(job_uri
, sizeof(job_uri
), "ipp://localhost/jobs/%d", jobid
);
207 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
, job_uri
);
209 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
212 httpAssembleURIf(printer_uri
, sizeof(printer_uri
), "ipp", NULL
, "localhost", 0,
213 "/printers/%s", dest
);
214 ippAddString(request
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri",
218 * Do the request and get back a response...
221 if ((response
= cupsDoRequest(http
, request
, "/jobs")) != NULL
)
223 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
225 _cupsLangPrintf(stderr
, NULL
, _("lpmove: move-job failed: %s\n"),
226 ippErrorString(response
->request
.status
.status_code
));
234 _cupsLangPrintf(stderr
, NULL
, _("lpmove: move-job failed: %s\n"),
235 ippErrorString(cupsLastError()));
240 * End of "$Id: lpmove.c 4906 2006-01-10 20:53:28Z mike $".