Print this page
2837 - remove print/lp* from gate and use CUPS from userland
@@ -22,15 +22,16 @@
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
+/*
+ * Copyright (c) 2013 Andrew Stormont. All rights reserved.
+ */
/* $Id: mod_ipp.c 149 2006-04-25 16:55:01Z njacobs $ */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* Internet Printing Protocol (IPP) module for Apache.
*/
#include "ap_config.h"
@@ -47,19 +48,27 @@
#include "http_core.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "papi.h"
-#ifndef APACHE_RELEASE /* appears to only exist in Apache 1.X */
-#define APACHE2
-#include "apr_compat.h"
+/* Try and guess the version of apache */
+#ifdef APACHE_RELEASE
+# define AP_SERVER_MAJORVERSION_NUMBER 1
+# define AP_SERVER_MINORVERSION_NUMBER 0
+#else
+# ifndef AP_SERVER_MAJORVERSION_NUMBER
+# define AP_SERVER_MAJORVERSION_NUMBER 2
+# endif
+# ifndef AP_SERVER_MINORVERSION_NUMBER
+# define AP_SERVER_MINORVERSION_NUMBER 0
+# endif
#endif
#include <papi.h>
#include <ipp-listener.h>
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
module MODULE_VAR_EXPORT ipp_module;
#else
module AP_MODULE_DECLARE_DATA ipp_module;
#endif
@@ -115,11 +124,11 @@
{
ssize_t len_read;
request_rec *ap_r = (request_rec *)fd;
len_read = ap_get_client_block(ap_r, buf, siz);
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
ap_reset_timeout(ap_r);
#endif
#ifdef DEBUG
fprintf(stderr, "read_data(0x%8.8x, 0x%8.8x, %d): %d",
@@ -137,11 +146,11 @@
write_data(void *fd, void *buf, size_t siz)
{
ssize_t len_written;
request_rec *ap_r = (request_rec *)fd;
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
ap_reset_timeout(ap_r);
#endif
#ifdef DEBUG
dump_buffer(stderr, "write_data:", buf, siz);
#endif
@@ -151,11 +160,11 @@
}
static void
discard_data(request_rec *r)
{
-#ifdef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
(void) ap_discard_request_body(r);
#else
/*
* This is taken from ap_discard_request_body(). The reason we can't
* just use it in Apache 1.3 is that it does various timeout things we
@@ -174,12 +183,17 @@
} while (i > 0);
}
#endif
}
+#if AP_SERVER_MAJORVERSION_NUMBER > 2 || AP_SERVER_MINORVERSION_NUMBER > 3
+void _log_rerror(const char *file, int line, int module_index,
+ int level, request_rec *r, const char *fmt, ...)
+#else
void _log_rerror(const char *file, int line, int level, request_rec *r,
const char *fmt, ...)
+#endif
{
va_list args;
size_t size;
char *message = alloca(BUFSIZ);
@@ -191,11 +205,13 @@
if ((size = vsnprintf(message, BUFSIZ, fmt, args)) >= BUFSIZ)
if ((message = alloca(size)) != NULL)
vsnprintf(message, size, fmt, args);
va_end(args);
-#ifdef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER > 2 || AP_SERVER_MINORVERSION_NUMBER > 3
+ ap_log_rerror(file, line, module_index, level, APR_SUCCESS, r, message);
+#elif AP_SERVER_MAJORVERSION_NUMBER > 1
ap_log_rerror(file, line, level, NULL, r, message);
#else
ap_log_rerror(file, line, level, r, message);
#endif
}
@@ -205,16 +221,20 @@
{
papi_attribute_t **request = NULL, **response = NULL;
IPPListenerConfig *config;
papi_status_t status;
int ret;
+#if AP_SERVER_MAJORVERSION_NUMBER > 1
+ apr_os_sock_t *os_sock = NULL;
+ apr_status_t st;
+#endif
/* Really, IPP is all POST requests */
if (r->method_number != M_POST)
return (DECLINED);
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
/*
* An IPP request must have a MIME type of "application/ipp"
* (RFC-2910, Section 4, page 19). If it doesn't match this
* MIME type, we should decline the request and let someone else
* try and handle it.
@@ -233,11 +253,11 @@
return (ret);
if (!ap_should_client_block(r))
return (HTTP_INTERNAL_SERVER_ERROR);
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
ap_soft_timeout("ipp_module: read/reply request ", r);
#endif
/* read the IPP request off the network */
status = ipp_read_message(read_data, r, &request, IPP_TYPE_REQUEST);
@@ -248,22 +268,26 @@
papiAttributeListPrint(stderr, request, "request (%d) ", getpid());
#endif
(void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL,
"originating-host", (char *)
-#ifdef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER >= 2
ap_get_remote_host
(r->connection, r->per_dir_config, REMOTE_NAME, NULL));
#else
ap_get_remote_host
(r->connection, r->per_dir_config, REMOTE_NAME));
#endif
(void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL,
"uri-port", ap_get_server_port(r));
if (r->headers_in != NULL) {
+#if AP_SERVER_MAJORVERSION_NUMBER >= 2 || AP_SERVER_MINORVERSION_NUMBER > 2
+ char *host = (char *)apr_table_get(r->headers_in, "Host");
+#else
char *host = (char *)ap_table_get(r->headers_in, "Host");
+#endif
if ((host == NULL) || (host[0] == '\0'))
host = (char *)ap_get_server_name(r);
(void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL,
@@ -289,15 +313,23 @@
}
/*
* For Trusted Solaris, pass the fd number of the socket connection
* to the backend so the it can be forwarded to the backend print
- * service to retrieve the sensativity label off of a multi-level
+ * service to retrieve the sensitivity label off of a multi-level
* port.
*/
+#if AP_SERVER_MAJORVERSION_NUMBER > 1
+ st = apr_os_sock_get(os_sock, r->connection->cs->pfd.desc.s);
+ if (st == APR_SUCCESS) {
+ (void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL,
+ "peer-socket", (int)os_sock);
+ }
+#else
(void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL,
"peer-socket", ap_bfileno(r->connection->client, B_RD));
+#endif
/* process the request */
status = ipp_process_request(request, &response, read_data, r);
if (status != PAPI_OK) {
errno = 0;
@@ -314,17 +346,21 @@
* If the client is using chunking and we have not yet received the
* final "0" sized chunk, we need to discard any data that may
* remain in the post request.
*/
if ((r->read_chunked != 0) &&
+#if AP_SERVER_MAJORVERSION_NUMBER >= 2 || AP_SERVER_MINORVERSION_NUMBER > 2
+ (apr_table_get(r->headers_in, "Content-Length") == NULL))
+#else
(ap_table_get(r->headers_in, "Content-Length") == NULL))
+#endif
discard_data(r);
/* write an IPP response back to the network */
r->content_type = "application/ipp";
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
ap_send_http_header(r);
#endif
status = ipp_write_message(write_data, r, response);
if (status != PAPI_OK)
@@ -336,11 +372,11 @@
#endif
papiAttributeListFree(request);
papiAttributeListFree(response);
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
ap_kill_timeout(r);
if (ap_rflush(r) < 0)
_log_rerror(APLOG_MARK, APLOG_ERR, r,
"flush failed, response may not have been sent");
#endif
@@ -350,19 +386,19 @@
/*ARGSUSED1*/
static void *
create_ipp_dir_config(
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
pool *p,
#else
apr_pool_t *p,
#endif
char *dirspec)
{
IPPListenerConfig *config =
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
ap_pcalloc(p, sizeof (*config));
#else
apr_pcalloc(p, sizeof (*config));
#endif
@@ -397,11 +433,11 @@
return (NULL);
}
/*ARGSUSED0*/
static const char *
-ipp_operation(cmd_parms *cmd, void *cfg, char *op, char *toggle)
+ipp_operation(cmd_parms *cmd, void *cfg, const char *op, const char *toggle)
{
IPPListenerConfig *config = (IPPListenerConfig *)cfg;
papi_status_t status;
status = ipp_configure_operation(&config->operations, op, toggle);
@@ -467,11 +503,11 @@
"hang the module until we can attach a debugger (no args)"),
#endif
{ NULL }
};
-#ifdef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER >= 2
/*ARGSUSED0*/
static const char *
ipp_method(const request_rec *r)
{
return ("ipp");
@@ -492,11 +528,15 @@
static const char * const modules[] = { "mod_dir.c", NULL };
/* Need to make sure we don't get directory listings by accident */
ap_hook_handler(ipp_handler, NULL, modules, APR_HOOK_MIDDLE);
ap_hook_default_port(ipp_port, NULL, NULL, APR_HOOK_MIDDLE);
+#if AP_SERVER_MAJORVERSION_NUMBER >= 2
+ ap_hook_http_scheme(ipp_method, NULL, NULL, APR_HOOK_MIDDLE);
+#else
ap_hook_http_method(ipp_method, NULL, NULL, APR_HOOK_MIDDLE);
+#endif
}
module AP_MODULE_DECLARE_DATA ipp_module = {
STANDARD20_MODULE_STUFF,
create_ipp_dir_config, /* create per-dir config */