1355b466jacobs/*
2355b466jacobs * CDDL HEADER START
3355b466jacobs *
4355b466jacobs * The contents of this file are subject to the terms of the
5355b466jacobs * Common Development and Distribution License (the "License").
6355b466jacobs * You may not use this file except in compliance with the License.
7355b466jacobs *
8355b466jacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9355b466jacobs * or http://www.opensolaris.org/os/licensing.
10355b466jacobs * See the License for the specific language governing permissions
11355b466jacobs * and limitations under the License.
12355b466jacobs *
13355b466jacobs * When distributing Covered Code, include this CDDL HEADER in each
14355b466jacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15355b466jacobs * If applicable, add the following below this CDDL HEADER, with the
16355b466jacobs * fields enclosed by brackets "[]" replaced with your own identifying
17355b466jacobs * information: Portions Copyright [yyyy] [name of copyright owner]
18355b466jacobs *
19355b466jacobs * CDDL HEADER END
20355b466jacobs */
21355b466jacobs
22355b466jacobs/*
23355b466jacobs * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24355b466jacobs * Use is subject to license terms.
25355b466jacobs *
26355b466jacobs */
27355b466jacobs
28355b466jacobs/* $Id: cancel-job.c 146 2006-03-24 00:26:54Z njacobs $ */
29355b466jacobs
30355b466jacobs#pragma ident	"%Z%%M%	%I%	%E% SMI"
31355b466jacobs
32355b466jacobs#include <stdio.h>
33355b466jacobs#include <papi.h>
34355b466jacobs#include <ipp.h>
35355b466jacobs#include <ipp-listener.h>
36355b466jacobs
37355b466jacobspapi_status_t
38355b466jacobsipp_cancel_job(papi_service_t svc, papi_attribute_t **request,
39355b466jacobs		papi_attribute_t ***response)
40355b466jacobs{
41355b466jacobs	papi_status_t status;
42355b466jacobs	papi_attribute_t **operational = NULL;
43355b466jacobs
44355b466jacobs	char *message = NULL;
45355b466jacobs	char *queue = NULL;
46355b466jacobs	int id = -1;
47355b466jacobs
48355b466jacobs	/* Get operational attributes from the request */
49355b466jacobs	(void) papiAttributeListGetCollection(request, NULL,
50355b466jacobs				"operational-attributes-group", &operational);
51355b466jacobs
52355b466jacobs	/*
53355b466jacobs	 * the operational-attributes-group must contain:
54355b466jacobs	 *	job-uri (or printer-uri/job-id)
55355b466jacobs	 */
56355b466jacobs	get_printer_id(operational, &queue, &id);
57355b466jacobs	if (id < 0) {
58355b466jacobs		ipp_set_status(response, PAPI_BAD_REQUEST,
59355b466jacobs				"missing job-uri or job-id");
60355b466jacobs		return (PAPI_BAD_REQUEST);
61355b466jacobs	} else if (queue == NULL) {
62355b466jacobs		ipp_set_status(response, PAPI_BAD_REQUEST,
63355b466jacobs				"missing printer-uri or job-uri");
64355b466jacobs		return (PAPI_BAD_REQUEST);
65355b466jacobs	}
66355b466jacobs
67355b466jacobs	/*
68355b466jacobs	 * the operational-attributes-group may contain:
69355b466jacobs	 *	message
70355b466jacobs	 */
71355b466jacobs	(void) papiAttributeListGetString(operational, NULL,
72355b466jacobs				"message", &message);
73355b466jacobs
74355b466jacobs	status = papiJobCancel(svc, queue, id);
75355b466jacobs	if (status != PAPI_OK) {
76355b466jacobs		ipp_set_status(response, status,
77