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