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 *
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* $Id: mod_ipp.c 149 2006-04-25 16:55:01Z njacobs $ */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Internet Printing Protocol (IPP) module for Apache.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "ap_config.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdio.h>
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross#include <unistd.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <time.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <sys/time.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <values.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <libintl.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <alloca.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "httpd.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "http_config.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "http_core.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "http_protocol.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "http_log.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "http_main.h"
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross#ifndef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "apr_compat.h"
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross#define apr_table_get ap_table_get
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross#endif /* APACHE2 */
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross#include "papi.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <papi.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <ipp-listener.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobsmodule MODULE_VAR_EXPORT ipp_module;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#else
355b4669e025ff377602b6fc7caaf30dbc218371jacobsmodule AP_MODULE_DECLARE_DATA ipp_module;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef AP_INIT_TAKE1 /* Apache 2.X has this, but 1.3.X does not */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#define AP_INIT_NO_ARGS(directive, action, arg, where, mesg) \
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { directive, action, arg, where, NO_ARGS, mesg }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#define AP_INIT_TAKE1(directive, action, arg, where, mesg) \
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { directive, action, arg, where, TAKE1, mesg }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#define AP_INIT_TAKE2(directive, action, arg, where, mesg) \
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { directive, action, arg, where, TAKE2, mesg }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobstypedef struct {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int conformance;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char *default_user;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char *default_svc;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_attribute_t **operations;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs} IPPListenerConfig;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobsvoid
355b4669e025ff377602b6fc7caaf30dbc218371jacobsdump_buffer(FILE *fp, char *tag, char *buffer, int bytes)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int i, j, ch;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(fp, "%s %d(0x%x) bytes\n", (tag ? tag : ""), bytes, bytes);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (i = 0; i < bytes; i += 16) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(fp, "%s ", (tag ? tag : ""));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (j = 0; j < 16 && (i + j) < bytes; j ++)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(fp, " %02X", buffer[i + j] & 255);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs while (j < 16) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(fp, " ");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs j++;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(fp, " ");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (j = 0; j < 16 && (i + j) < bytes; j ++) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ch = buffer[i + j] & 255;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (ch < ' ' || ch == 127)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ch = '.';
355b4669e025ff377602b6fc7caaf30dbc218371jacobs putc(ch, fp);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs putc('\n', fp);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fflush(fp);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic ssize_t
355b4669e025ff377602b6fc7caaf30dbc218371jacobsread_data(void *fd, void *buf, size_t siz)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ssize_t len_read;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs request_rec *ap_r = (request_rec *)fd;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs len_read = ap_get_client_block(ap_r, buf, siz);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ap_reset_timeout(ap_r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(stderr, "read_data(0x%8.8x, 0x%8.8x, %d): %d",
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross fd, buf, siz, len_read);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (len_read < 0)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(stderr, ": %s", strerror(errno));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs putc('\n', stderr);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs dump_buffer(stderr, "read_data:", buf, len_read);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (len_read);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic ssize_t
355b4669e025ff377602b6fc7caaf30dbc218371jacobswrite_data(void *fd, void *buf, size_t siz)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ssize_t len_written;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs request_rec *ap_r = (request_rec *)fd;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ap_reset_timeout(ap_r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobs dump_buffer(stderr, "write_data:", buf, siz);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs len_written = ap_rwrite(buf, siz, ap_r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (len_written);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void
355b4669e025ff377602b6fc7caaf30dbc218371jacobsdiscard_data(request_rec *r)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) ap_discard_request_body(r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#else
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * This is taken from ap_discard_request_body(). The reason we can't
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * just use it in Apache 1.3 is that it does various timeout things we
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * don't want it to do. Apache 2.0 doesn't do that, so we can safely
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * use the normal function.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (r->read_chunked || r->remaining > 0) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char dumpbuf[HUGE_STRING_LEN];
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int i;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs do {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs i = ap_get_client_block(r, dumpbuf, HUGE_STRING_LEN);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobs dump_buffer(stderr, "discarded", dumpbuf, i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs } while (i > 0);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsvoid _log_rerror(const char *file, int line, int level, request_rec *r,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs const char *fmt, ...)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs va_list args;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs size_t size;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char *message = alloca(BUFSIZ);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs va_start(args, fmt);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * fill in the message. If the buffer is too small, allocate
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * one that is large enough and fill it in.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((size = vsnprintf(message, BUFSIZ, fmt, args)) >= BUFSIZ)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((message = alloca(size)) != NULL)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs vsnprintf(message, size, fmt, args);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs va_end(args);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef APACHE2
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross ap_log_rerror(file, line, level, APR_SUCCESS, r, message);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#else
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ap_log_rerror(file, line, level, r, message);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic int
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_handler(request_rec *r)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_attribute_t **request = NULL, **response = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs IPPListenerConfig *config;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_status_t status;
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross const char *s;
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross int sockfd = -1;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs int ret;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Really, IPP is all POST requests */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (r->method_number != M_POST)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (DECLINED);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * An IPP request must have a MIME type of "application/ipp"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * (RFC-2910, Section 4, page 19). If it doesn't match this
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * MIME type, we should decline the request and let someone else
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * try and handle it.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross if (r->headers_in == NULL)
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross return (DECLINED);
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross s = apr_table_get(r->headers_in, "Content-Type");
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross if ((s == NULL) || (strcasecmp(s, "application/ipp") != 0))
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross return (DECLINED);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* CHUNKED_DECHUNK might not work right for IPP? */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((ret = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK)) != OK)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (ret);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (!ap_should_client_block(r))
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (HTTP_INTERNAL_SERVER_ERROR);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ap_soft_timeout("ipp_module: read/reply request ", r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* read the IPP request off the network */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = ipp_read_message(read_data, r, &request, IPP_TYPE_REQUEST);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (status != PAPI_OK)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs _log_rerror(APLOG_MARK, APLOG_ERR, r,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "read failed: %s\n", papiStatusString(status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiAttributeListPrint(stderr, request, "request (%d) ", getpid());
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef APACHE2
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross s = ap_get_remote_host(r->connection, r->per_dir_config,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross REMOTE_NAME, NULL);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#else
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross s = ap_get_remote_host(r->connection, r->per_dir_config,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross REMOTE_NAME);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross (void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "originating-host", (char *)s);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "uri-port", ap_get_server_port(r));
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (r->headers_in != NULL) {
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross char *host = (char *)apr_table_get(r->headers_in, "Host");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((host == NULL) || (host[0] == '\0'))
355b4669e025ff377602b6fc7caaf30dbc218371jacobs host = (char *)ap_get_server_name(r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "uri-host", host);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "uri-path", r->uri);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config = ap_get_module_config(r->per_dir_config, &ipp_module);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (config != NULL) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "conformance", config->conformance);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddCollection(&request, PAPI_ATTR_EXCL,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "operations", config->operations);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (config->default_user != NULL)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddString(&request,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross PAPI_ATTR_EXCL, "default-user",
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross config->default_user);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (config->default_svc != NULL)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) papiAttributeListAddString(&request,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross PAPI_ATTR_EXCL, "default-service",
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross config->default_svc);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * For Trusted Solaris, pass the fd number of the socket connection
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * to the backend so the it can be forwarded to the backend print
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * service to retrieve the sensativity label off of a multi-level
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * port.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross#ifdef APACHE2
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross /*
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross * In Apache 2.4 and later, could use: ap_get_conn_socket()
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross * Apache 2.2 uses ap_get_module_config() but that needs
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross * &core_module, for .module_index (which is just zero).
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross * Could either inline that with index zero, or declare
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross * core_module here. Latter seems less evil.
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross */
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross {
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross extern module core_module;
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross apr_socket_t *csd = ap_get_module_config(
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross r->connection->conn_config, &core_module);
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross if (csd != NULL)
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross (void) apr_os_sock_get(&sockfd, csd);
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross }
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross#else
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross sockfd = ap_bfileno(r->connection->client, B_RD);
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross#endif
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross if (sockfd != -1) {
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross (void) papiAttributeListAddInteger(&request,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross PAPI_ATTR_EXCL, "peer-socket", sockfd);
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* process the request */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = ipp_process_request(request, &response, read_data, r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (status != PAPI_OK) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs errno = 0;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs _log_rerror(APLOG_MARK, APLOG_ERR, r,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "request failed: %s\n", papiStatusString(status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs discard_data(r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(stderr, "processing result: %s\n", papiStatusString(status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiAttributeListPrint(stderr, response, "response (%d) ", getpid());
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * If the client is using chunking and we have not yet received the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * final "0" sized chunk, we need to discard any data that may
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * remain in the post request.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if ((r->read_chunked != 0) &&
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross (apr_table_get(r->headers_in, "Content-Length") == NULL))
355b4669e025ff377602b6fc7caaf30dbc218371jacobs discard_data(r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* write an IPP response back to the network */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs r->content_type = "application/ipp";
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ap_send_http_header(r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs status = ipp_write_message(write_data, r, response);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (status != PAPI_OK)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs _log_rerror(APLOG_MARK, APLOG_ERR, r,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "write failed: %s\n", papiStatusString(status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fprintf(stderr, "write result: %s\n", papiStatusString(status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs fflush(stderr);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiAttributeListFree(request);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papiAttributeListFree(response);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ap_kill_timeout(r);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (ap_rflush(r) < 0)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs _log_rerror(APLOG_MARK, APLOG_ERR, r,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "flush failed, response may not have been sent");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (OK);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*ARGSUSED1*/
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void *
355b4669e025ff377602b6fc7caaf30dbc218371jacobscreate_ipp_dir_config(
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs pool *p,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#else
355b4669e025ff377602b6fc7caaf30dbc218371jacobs apr_pool_t *p,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs char *dirspec)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross IPPListenerConfig *config;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifndef APACHE2
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross config = ap_pcalloc(p, sizeof (*config));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#else
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross config = apr_pcalloc(p, sizeof (*config));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (config != NULL) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs (void) memset(config, 0, sizeof (*config));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config->conformance = IPP_PARSE_CONFORMANCE_RASH;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config->default_user = NULL;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config->default_svc = NULL;
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross (void) ipp_configure_operation(&config->operations,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross "required", "enable");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (config);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*ARGSUSED0*/
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic const char *
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_conformance(cmd_parms *cmd, void *cfg, const char *arg)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs IPPListenerConfig *config = (IPPListenerConfig *)cfg;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (strncasecmp(arg, "automatic", 4) == 0) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config->conformance = IPP_PARSE_CONFORMANCE_RASH;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs } else if (strcasecmp(arg, "1.0") == 0) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config->conformance = IPP_PARSE_CONFORMANCE_LOOSE;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs } else if (strcasecmp(arg, "1.1") == 0) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config->conformance = IPP_PARSE_CONFORMANCE_STRICT;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs } else {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return ("unknown conformance, try (automatic/1.0/1.1)");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (NULL);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*ARGSUSED0*/
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic const char *
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Rossipp_operation(cmd_parms *cmd, void *cfg, const char *op, const char *toggle)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs IPPListenerConfig *config = (IPPListenerConfig *)cfg;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs papi_status_t status;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross status = ipp_configure_operation(&config->operations,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross (char *)op, (char *)toggle);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs switch (status) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case PAPI_OK:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (NULL);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case PAPI_BAD_ARGUMENT:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (gettext("internal error (invalid argument)"));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs default:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (papiStatusString(status));
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* NOTREACHED */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* return (gettext("contact your software vendor")); */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic const char *
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_default_user(cmd_parms *cmd, void *cfg, const char *arg)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs IPPListenerConfig *config = (IPPListenerConfig *)cfg;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config->default_user = (char *)arg;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (NULL);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic const char *
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_default_svc(cmd_parms *cmd, void *cfg, const char *arg)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs IPPListenerConfig *config = (IPPListenerConfig *)cfg;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs config->default_svc = (char *)arg;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (NULL);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*ARGSUSED0*/
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Rossvolatile int ipp_module_hang_sleeping = 1;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic const char *
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_module_hang(cmd_parms *cmd, void *cfg)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross /*
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross * Wait so we can attach with a debugger. Once attached,
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross * assign ipp_module_hang_sleeping = 0 and step through.
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross */
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross while (ipp_module_hang_sleeping)
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross sleep(1);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (NULL);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif /* DEBUG */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic const command_rec ipp_cmds[] =
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs AP_INIT_TAKE1("ipp-conformance", ipp_conformance, NULL, ACCESS_CONF,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "IPP protocol conformance (loose/strict)"),
355b4669e025ff377602b6fc7caaf30dbc218371jacobs AP_INIT_TAKE2("ipp-operation", ipp_operation, NULL, ACCESS_CONF,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "IPP protocol operations to enable/disable)"),
355b4669e025ff377602b6fc7caaf30dbc218371jacobs AP_INIT_TAKE1("ipp-default-user", ipp_default_user, NULL, ACCESS_CONF,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "default user for various operations"),
355b4669e025ff377602b6fc7caaf30dbc218371jacobs AP_INIT_TAKE1("ipp-default-service", ipp_default_svc, NULL, ACCESS_CONF,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "default service for various operations"),
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef DEBUG
355b4669e025ff377602b6fc7caaf30dbc218371jacobs AP_INIT_NO_ARGS("ipp-module-hang", ipp_module_hang, NULL, ACCESS_CONF,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs "hang the module until we can attach a debugger (no args)"),
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { NULL }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs};
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#ifdef APACHE2
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*ARGSUSED0*/
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic const char *
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Rossipp_scheme(const request_rec *r)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return ("ipp");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*ARGSUSED0*/
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic unsigned short
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_port(const request_rec *r)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs return (631);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* Dispatch list for API hooks */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*ARGSUSED0*/
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void
355b4669e025ff377602b6fc7caaf30dbc218371jacobsipp_register_hooks(apr_pool_t *p)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs static const char * const modules[] = { "mod_dir.c", NULL };
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /* Need to make sure we don't get directory listings by accident */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ap_hook_handler(ipp_handler, NULL, modules, APR_HOOK_MIDDLE);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ap_hook_default_port(ipp_port, NULL, NULL, APR_HOOK_MIDDLE);
b0e753dd6a955fb2f10a0ce17d32bd33172e0400Gordon Ross ap_hook_http_scheme(ipp_scheme, NULL, NULL, APR_HOOK_MIDDLE);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsmodule AP_MODULE_DECLARE_DATA ipp_module = {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs STANDARD20_MODULE_STUFF,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs create_ipp_dir_config, /* create per-dir config */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* merge per-dir config */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* create per-server config */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* merge per-server config */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_cmds, /* table of config commands */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_register_hooks /* register hooks */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs};
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#else /* Apache 1.X */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* Dispatch list of content handlers */
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic const handler_rec ipp_handlers[] = {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * This handler association causes all IPP request with the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * correct MIME type to call the protocol handler.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { "application/ipp", ipp_handler },
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * This hander association is causes everything to go through the IPP
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * protocol request handler. This is necessary because client POST
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * request may be for something outside of the normal printer-uri
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * space.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { "*/*", ipp_handler },
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs { NULL, NULL }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs};
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsmodule MODULE_VAR_EXPORT ipp_module = {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs STANDARD_MODULE_STUFF,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* module initializer */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs create_ipp_dir_config, /* create per-dir config structures */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* merge per-dir config structures */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* create per-server config structures */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* merge per-server config structures */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_cmds, /* table of config file commands */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ipp_handlers, /* [#8] MIME-typed-dispatched handlers */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* [#1] URI to filename translation */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* [#4] validate user id from request */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* [#5] check if the user is ok _here_ */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* [#3] check access by host address */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* [#6] determine MIME type */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* [#7] pre-run fixups */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* [#9] log a transaction */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* [#2] header parser */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* child_init */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* child_exit */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL /* [#0] post read-request */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs};
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#endif