xref: /illumos-gate/usr/src/lib/print/libipp-listener/common/cups-move-job.c (revision d17be682a2c70b4505d43c830bbd2603da11918d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  */
27 
28 /* $Id: cups-move-job.c 146 2006-03-24 00:26:54Z njacobs $ */
29 
30 #include <stdio.h>
31 #include <papi.h>
32 #include <ipp.h>
33 #include <ipp-listener.h>
34 
35 papi_status_t
36 cups_move_job(papi_service_t svc, papi_attribute_t **request,
37 		papi_attribute_t ***response)
38 {
39 	papi_status_t status;
40 	papi_attribute_t **operational = NULL, **job = NULL;
41 
42 	char *message = NULL;
43 	char *job_printer_uri = NULL;
44 	char *queue = NULL;
45 	char *dest = NULL;
46 	int id = -1;
47 
48 	/* Get operational attributes from the request */
49 	(void) papiAttributeListGetCollection(request, NULL,
50 				"operational-attributes-group", &operational);
51 
52 	/*
53 	 * Get job attributes from the request
54 	 */
55 	status = papiAttributeListGetCollection(request, NULL,
56 				"job-attributes-group", &job);
57 	if (status != PAPI_OK) {
58 		ipp_set_status(response, status,
59 				"job-attributes-group: %s",
60 				papiStatusString(status));
61 		return (status);
62 	}
63 
64 	/*
65 	 * the operational-attributes-group must contain:
66 	 *	job-uri (or printer-uri/job-id)
67 	 */
68 	get_printer_id(operational, &queue, &id);
69 	if (id < 0) {
70 		ipp_set_status(response, PAPI_BAD_REQUEST,
71 				"missing job-uri or job-id");
72 		return (PAPI_BAD_REQUEST);
73 	} else if (queue == NULL) {
74 		ipp_set_status(response, PAPI_BAD_REQUEST,
75 				"missing printer-uri or job-uri");
76 		return (PAPI_BAD_REQUEST);
77 	}
78 
79 	/*
80 	 * the job-attributes-group must contain:
81 	 *	job-printer-uri
82 	 */
83 	job_printer_uri = NULL;
84 	(void) papiAttributeListGetString(job, NULL,
85 				"job-printer-uri", &job_printer_uri);
86 	if (job_printer_uri == NULL) {
87 		ipp_set_status(response, PAPI_BAD_REQUEST,
88 				"missing job-printer-uri");
89 		return (PAPI_BAD_REQUEST);
90 	} else
91 		dest = destination_from_printer_uri(job_printer_uri);
92 
93 	if ((status = papiJobMove(svc, queue, id, dest)) != PAPI_OK)
94 		ipp_set_status(response, status,
95 				"move failed: %s-%d to %s: %s",
96 				(queue ? queue : "(null)"), id,
97 				(dest ? dest : "(null)"),
98 				ipp_svc_status_mesg(svc, status));
99 
100 	return (status);
101 }
102