]> git.ipfire.org Git - thirdparty/cups.git/blame - systemv/lpmove.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / systemv / lpmove.c
CommitLineData
ef416fc2 1/*
503b54c9 2 * "lpmove" command for CUPS.
ef416fc2 3 *
503b54c9
MS
4 * Copyright 2007-2010 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 6 *
503b54c9
MS
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 12 */
13
14/*
15 * Include necessary headers...
16 */
17
71e16022 18#include <cups/cups-private.h>
ef416fc2 19
20
21/*
22 * Local functions...
23 */
24
fa73b229 25static int move_job(http_t *http, const char *src, int jobid,
26 const char *dest);
ef416fc2 27
28
29/*
30 * 'main()' - Parse options and show status information.
31 */
32
33int
34main(int argc, /* I - Number of command-line arguments */
35 char *argv[]) /* I - Command-line arguments */
36{
37 int i; /* Looping var */
38 http_t *http; /* Connection to server */
39 const char *job; /* Job name */
fa73b229 40 int jobid; /* Job ID */
ef416fc2 41 int num_dests; /* Number of destinations */
42 cups_dest_t *dests; /* Destinations */
fa73b229 43 const char *src, /* Original queue */
44 *dest; /* New destination */
ef416fc2 45
46
07725fee 47 _cupsSetLocale(argv);
d09495fa 48
fa73b229 49 dest = NULL;
50 dests = NULL;
ef416fc2 51 job = NULL;
fa73b229 52 jobid = 0;
ef416fc2 53 num_dests = 0;
fa73b229 54 src = NULL;
ef416fc2 55
56 for (i = 1; i < argc; i ++)
57 if (argv[i][0] == '-')
58 switch (argv[i][1])
59 {
60 case 'E' : /* Encrypt */
61#ifdef HAVE_SSL
62 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
63
ef416fc2 64#else
fa73b229 65 _cupsLangPrintf(stderr,
0837b7e8 66 _("%s: Sorry, no encryption support."),
ef416fc2 67 argv[0]);
68#endif /* HAVE_SSL */
69 break;
70
71 case 'h' : /* Connect to host */
ef416fc2 72 if (argv[i][2] != '\0')
73 cupsSetServer(argv[i] + 2);
74 else
75 {
76 i ++;
77
78 if (i >= argc)
79 {
fa73b229 80 _cupsLangPuts(stderr,
0837b7e8 81 _("Error: need hostname after \"-h\" option."));
ef416fc2 82 return (1);
83 }
84
85 cupsSetServer(argv[i]);
86 }
87 break;
88
89 default :
0837b7e8 90 _cupsLangPrintf(stderr, _("lpmove: Unknown option \"%c\"."),
ef416fc2 91 argv[i][1]);
92 return (1);
93 }
fa73b229 94 else if (!jobid && !src)
ef416fc2 95 {
96 if (num_dests == 0)
97 num_dests = cupsGetDests(&dests);
98
99 if ((job = strrchr(argv[i], '-')) != NULL &&
100 cupsGetDest(argv[i], NULL, num_dests, dests) == NULL)
fa73b229 101 jobid = atoi(job + 1);
0a682745
MS
102 else if (isdigit(argv[i][0] & 255) &&
103 !cupsGetDest(argv[i], NULL, num_dests, dests))
104 jobid = atoi(argv[i]);
ef416fc2 105 else
fa73b229 106 src = argv[i];
ef416fc2 107 }
108 else if (dest == NULL)
109 dest = argv[i];
110 else
111 {
0837b7e8 112 _cupsLangPrintf(stderr, _("lpmove: Unknown argument \"%s\"."), argv[i]);
ef416fc2 113 return (1);
114 }
115
fa73b229 116 if ((!jobid && !src) || !dest)
ef416fc2 117 {
0837b7e8 118 _cupsLangPuts(stdout, _("Usage: lpmove job/src dest"));
ef416fc2 119 return (1);
120 }
121
91c84a35 122 http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
ef416fc2 123
91c84a35
MS
124 if (http == NULL)
125 {
0837b7e8 126 _cupsLangPrintf(stderr, _("lpmove: Unable to connect to server: %s"),
91c84a35
MS
127 strerror(errno));
128 return (1);
ef416fc2 129 }
130
fa73b229 131 return (move_job(http, src, jobid, dest));
ef416fc2 132}
133
134
135/*
136 * 'move_job()' - Move a job.
137 */
138
fa73b229 139static int /* O - 0 on success, 1 on error */
ef416fc2 140move_job(http_t *http, /* I - HTTP connection to server */
fa73b229 141 const char *src, /* I - Source queue */
ef416fc2 142 int jobid, /* I - Job ID */
fa73b229 143 const char *dest) /* I - Destination queue */
ef416fc2 144{
fa73b229 145 ipp_t *request; /* IPP Request */
146 char job_uri[HTTP_MAX_URI], /* job-uri */
147 printer_uri[HTTP_MAX_URI]; /* job-printer-uri */
ef416fc2 148
149
fa73b229 150 if (!http)
151 return (1);
ef416fc2 152
153 /*
154 * Build a CUPS_MOVE_JOB request, which requires the following
155 * attributes:
156 *
157 * attributes-charset
158 * attributes-natural-language
fa73b229 159 * job-uri/printer-uri
ef416fc2 160 * job-printer-uri
fa73b229 161 * requesting-user-name
ef416fc2 162 */
163
fa73b229 164 request = ippNewRequest(CUPS_MOVE_JOB);
ef416fc2 165
fa73b229 166 if (jobid)
167 {
168 snprintf(job_uri, sizeof(job_uri), "ipp://localhost/jobs/%d", jobid);
169 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL,
170 job_uri);
171 }
172 else
173 {
a4d04587 174 httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
175 "localhost", 0, "/printers/%s", src);
fa73b229 176 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
177 job_uri);
178 }
ef416fc2 179
180 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
181 NULL, cupsUser());
182
a4d04587 183 httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
184 "ipp", NULL, "localhost", 0, "/printers/%s", dest);
ef416fc2 185 ippAddString(request, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri",
186 NULL, printer_uri);
187
188 /*
189 * Do the request and get back a response...
190 */
191
fa73b229 192 ippDelete(cupsDoRequest(http, request, "/jobs"));
ef416fc2 193
fa73b229 194 if (cupsLastError() > IPP_OK_CONFLICT)
195 {
0837b7e8 196 _cupsLangPrintf(stderr, "lpmove: %s", cupsLastErrorString());
fa73b229 197 return (1);
ef416fc2 198 }
199 else
fa73b229 200 return (0);
ef416fc2 201}