355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER START
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * The contents of this file are subject to the terms of the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Common Development and Distribution License (the "License").
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * You may not use this file except in compliance with the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * or http://www.opensolaris.org/os/licensing.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * See the License for the specific language governing permissions
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * and limitations under the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * When distributing Covered Code, include this CDDL HEADER in each
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * If applicable, add the following below this CDDL HEADER, with the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * fields enclosed by brackets "[]" replaced with your own identifying
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * information: Portions Copyright [yyyy] [name of copyright owner]
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER END
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Use is subject to license terms.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* $Id: cups-get-default.c 146 2006-03-24 00:26:54Z njacobs $ */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#pragma ident "%Z%%M% %I% %E% SMI"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdio.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <papi.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <ipp.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <ipp-listener.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <config-site.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobspapi_status_t
355b4669e025ff377602b6fc7caaf30dbc218371jacobscups_get_default(papi_service_t svc, papi_attribute_t **request,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_attribute_t ***response)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_status_t status;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_printer_t p = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_attribute_t **operational = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_attribute_t **printer_attributes = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char **req_attrs = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int limit = 0;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Get operational attributes from the request */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListGetCollection(request, NULL,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "operational-attributes-group", &operational);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * The operational-attributes-group may contain:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * requested-attributes
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs get_string_list(operational, "requested-attributes", &req_attrs);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiPrinterQuery(svc, DEFAULT_DEST, req_attrs, NULL, &p);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (status != PAPI_OK) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_set_status(response, status, "query default: %s",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_svc_status_mesg(svc, status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiPrinterFree(p); /* we shouldn't have a printer */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (status);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * add the printer attributes to the response in a
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * printer-attributes-group
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs printer_attributes = papiPrinterGetAttributeList(p);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs add_default_attributes(&printer_attributes);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddCollection(response, PAPI_ATTR_REPLACE,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "printer-attributes-group", printer_attributes);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiPrinterFree(p);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (status);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}