355b4669e025ff377602b6fc7caaf30dbc218371jacobs * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * See the License for the specific language governing permissions
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * and limitations under the License.
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 * CDDL HEADER END
a18dc42fc967d11feba9b8be61c6727dc6c56b48ps * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Use is subject to license terms.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* $Id: ipp-listener.c 146 2006-03-24 00:26:54Z njacobs $ */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#pragma ident "%Z%%M% %I% %E% SMI"
355b4669e025ff377602b6fc7caaf30dbc218371jacobstypedef papi_status_t (ipp_handler_t)(papi_service_t svc,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * protocol request handlers are inserted below. The handler must be
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * declared extern immediately below this comment and then an entry
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * must be inserted in the "handlers" table a little further down.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* ARGSUSED0 */
355b4669e025ff377602b6fc7caaf30dbc218371jacobsdefault_handler(papi_service_t svc, papi_attribute_t **request,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_attribute_t ***response, ipp_reader_t iread, void *fd)
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic struct {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Printer Operations */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { 0x0005, "create-job", ipp_create_job, OP_OPTIONAL },
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { 0x000b, "get-printer-attributes", ipp_get_printer_attributes,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { 0x0012, "purge-jobs", ipp_purge_jobs, OP_OPTIONAL },
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { 0x0013, "set-printer-attributes", ipp_set_printer_attributes,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { 0x0014, "set-job-attributes", ipp_set_job_attributes,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Job Operations */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { 0x0008, "cancel-job", ipp_cancel_job, OP_REQUIRED },
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { 0x0009, "get-job-attributes", ipp_get_job_attributes,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Other Operations */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { 0x400D, "cups-move-job", cups_move_job, OP_VENDOR },
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (-1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (-1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_operation_handler(papi_attribute_t **request, papi_attribute_t ***response)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* get the operation from the request */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "no operation specified in request");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* find the operation in the handler table */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((index == -1) || (handlers[index].function == NULL)) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "operation (0x%4.4x) not implemented by server",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* find the configured operations */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiAttributeListGetCollection(request, NULL,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (status != PAPI_OK) { /* this should not be possible */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "sofware error, no operations configured");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* check if the requested operation is configured */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((status != PAPI_OK) || (configured != PAPI_TRUE)) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "operation (%s 0x%4.4x) not enabled on server",
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_configure_required_operations(papi_attribute_t ***list, char boolean)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (i = 0; ((result == PAPI_OK) && (handlers[i].name != NULL)); i++)
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_configure_all_operations(papi_attribute_t ***list, char boolean)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (i = 0; ((result == PAPI_OK) && (handlers[i].name != NULL)); i++)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs result = papiAttributeListAddBoolean(list, PAPI_ATTR_REPLACE,
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_configure_operation(papi_attribute_t ***list, char *operation, char *type)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((list == NULL) || (operation == NULL) || (type == NULL))
355b4669e025ff377602b6fc7caaf30dbc218371jacobs result = ipp_configure_all_operations(list, boolean);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs result = ipp_configure_required_operations(list, boolean);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs } else if (ipp_operation_name_to_index(operation) != -1) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs result = papiAttributeListAddBoolean(list, PAPI_ATTR_REPLACE,
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_operations_supported(papi_attribute_t ***list, papi_attribute_t **request)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "operations-supported",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* If the response was initialized, start over */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Add the basic ipp header information to the response */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListGetInteger(request, NULL, "version-major", &i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "version-major", i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListGetInteger(request, NULL, "version-minor", &i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "version-minor", i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListGetInteger(request, NULL, "request-id", &i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "request-id", i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Add a default operational attributes group to the response */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddString(&operational, PAPI_ATTR_EXCL,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddString(&operational, PAPI_ATTR_EXCL,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddCollection(response, PAPI_ATTR_REPLACE,
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs/* simplistic check for cyclical service references */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* was there a service_uri? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((list = getprinterbyname(svc_name, NULL)) == NULL)
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0); /* if it doesnt' resolve, we will fail later */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs papiAttributeListGetString(list, NULL, "printer-uri-supported", &s);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0); /* they don't match */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it in uri form? */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs if ((uri == NULL) || (uri->scheme == NULL) || (uri->host == NULL)) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* is it ipp form */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* does the host match up */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* does the port match our own */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ((uri->port != NULL) && (atoi(uri->port) != port))) {
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (0);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs return (1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsprint_service_connect(papi_service_t *svc, papi_attribute_t **request,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Get the operational attributes group from the request */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* get the user name */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListGetString(request, NULL, "default-user", &user);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* get the printer or service name */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs /* get the port that we are listening on */
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs (void) papiAttributeListGetInteger(request, NULL, "uri-port", &port);
0a44ef6d9afbfe052a7e975f55ea0d2954b62a82jacobs ipp_set_status(response, status, "printer-uri is cyclical");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = papiServiceCreate(svc, svc_name, user, NULL, NULL,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_set_status(response, status, "print service: %s",
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Trusted Solaris can't be trusting of intermediaries. Pass
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * the socket connection to the print service to retrieve the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * sensativity label off of a multi-level port.
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_process_request(papi_attribute_t **request, papi_attribute_t ***response,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiAttributeListPrint(stderr, request, " %d ", getpid());
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* verify that the request is "well-formed" */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((result = ipp_validate_request(request, response)) == PAPI_OK) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs result = print_service_connect(&svc, request, response);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* process the request */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs result = (handler)(svc, request, response, iread, fd);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(stderr, "RESULT: %s\n", papiStatusString(result));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddInteger(response, PAPI_ATTR_EXCL,