]> git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpmove.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / systemv / lpmove.c
1 /*
2 * "lpmove" command for CUPS.
3 *
4 * Copyright 2007-2010 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
6 *
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/".
12 */
13
14 /*
15 * Include necessary headers...
16 */
17
18 #include <cups/cups-private.h>
19
20
21 /*
22 * Local functions...
23 */
24
25 static int move_job(http_t *http, const char *src, int jobid,
26 const char *dest);
27
28
29 /*
30 * 'main()' - Parse options and show status information.
31 */
32
33 int
34 main(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 */
40 int jobid; /* Job ID */
41 int num_dests; /* Number of destinations */
42 cups_dest_t *dests; /* Destinations */
43 const char *src, /* Original queue */
44 *dest; /* New destination */
45
46
47 _cupsSetLocale(argv);
48
49 dest = NULL;
50 dests = NULL;
51 job = NULL;
52 jobid = 0;
53 num_dests = 0;
54 src = NULL;
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
64 #else
65 _cupsLangPrintf(stderr,
66 _("%s: Sorry, no encryption support."),
67 argv[0]);
68 #endif /* HAVE_SSL */
69 break;
70
71 case 'h' : /* Connect to host */
72 if (argv[i][2] != '\0')
73 cupsSetServer(argv[i] + 2);
74 else
75 {
76 i ++;
77
78 if (i >= argc)
79 {
80 _cupsLangPuts(stderr,
81 _("Error: need hostname after \"-h\" option."));
82 return (1);
83 }
84
85 cupsSetServer(argv[i]);
86 }
87 break;
88
89 default :
90 _cupsLangPrintf(stderr, _("lpmove: Unknown option \"%c\"."),
91 argv[i][1]);
92 return (1);
93 }
94 else if (!jobid && !src)
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)
101 jobid = atoi(job + 1);
102 else if (isdigit(argv[i][0] & 255) &&
103 !cupsGetDest(argv[i], NULL, num_dests, dests))
104 jobid = atoi(argv[i]);
105 else
106 src = argv[i];
107 }
108 else if (dest == NULL)
109 dest = argv[i];
110 else
111 {
112 _cupsLangPrintf(stderr, _("lpmove: Unknown argument \"%s\"."), argv[i]);
113 return (1);
114 }
115
116 if ((!jobid && !src) || !dest)
117 {
118 _cupsLangPuts(stdout, _("Usage: lpmove job/src dest"));
119 return (1);
120 }
121
122 http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
123
124 if (http == NULL)
125 {
126 _cupsLangPrintf(stderr, _("lpmove: Unable to connect to server: %s"),
127 strerror(errno));
128 return (1);
129 }
130
131 return (move_job(http, src, jobid, dest));
132 }
133
134
135 /*
136 * 'move_job()' - Move a job.
137 */
138
139 static int /* O - 0 on success, 1 on error */
140 move_job(http_t *http, /* I - HTTP connection to server */
141 const char *src, /* I - Source queue */
142 int jobid, /* I - Job ID */
143 const char *dest) /* I - Destination queue */
144 {
145 ipp_t *request; /* IPP Request */
146 char job_uri[HTTP_MAX_URI], /* job-uri */
147 printer_uri[HTTP_MAX_URI]; /* job-printer-uri */
148
149
150 if (!http)
151 return (1);
152
153 /*
154 * Build a CUPS_MOVE_JOB request, which requires the following
155 * attributes:
156 *
157 * attributes-charset
158 * attributes-natural-language
159 * job-uri/printer-uri
160 * job-printer-uri
161 * requesting-user-name
162 */
163
164 request = ippNewRequest(CUPS_MOVE_JOB);
165
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 {
174 httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
175 "localhost", 0, "/printers/%s", src);
176 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
177 job_uri);
178 }
179
180 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
181 NULL, cupsUser());
182
183 httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
184 "ipp", NULL, "localhost", 0, "/printers/%s", dest);
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
192 ippDelete(cupsDoRequest(http, request, "/jobs"));
193
194 if (cupsLastError() > IPP_OK_CONFLICT)
195 {
196 _cupsLangPrintf(stderr, "lpmove: %s", cupsLastErrorString());
197 return (1);
198 }
199 else
200 return (0);
201 }