--- old/usr/src/lib/print/mod_ipp/mod_ipp.c	2014-05-07 18:40:52.333673291 +0400
+++ new/usr/src/lib/print/mod_ipp/mod_ipp.c	2014-05-07 18:40:52.354393086 +0400
@@ -24,11 +24,12 @@
  * 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.
  */
@@ -49,15 +50,23 @@
 #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;
@@ -117,7 +126,7 @@
 	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
 
@@ -139,7 +148,7 @@
 	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
@@ -153,7 +162,7 @@
 static void
 discard_data(request_rec *r)
 {
-#ifdef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
 	(void) ap_discard_request_body(r);
 #else
 	/*
@@ -176,8 +185,13 @@
 #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;
@@ -193,7 +207,9 @@
 			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);
@@ -207,12 +223,16 @@
 	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
@@ -235,7 +255,7 @@
 	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 */
@@ -250,7 +270,7 @@
 
 	(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
@@ -261,7 +281,11 @@
 	(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);
@@ -291,11 +315,19 @@
 	/*
 	 * 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));
+		"peer-socket", ap_bfileno(r->connection->client, B_RD));
+#endif
 
 	/* process the request */
 	status = ipp_process_request(request, &response, read_data, r);
@@ -316,13 +348,17 @@
 	 * 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
 
@@ -338,7 +374,7 @@
 	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,
@@ -352,7 +388,7 @@
 /*ARGSUSED1*/
 static void *
 create_ipp_dir_config(
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
 	pool *p,
 #else
 	apr_pool_t *p,
@@ -360,7 +396,7 @@
 	char *dirspec)
 {
 	IPPListenerConfig *config =
-#ifndef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER < 2
 		ap_pcalloc(p, sizeof (*config));
 #else
 		apr_pcalloc(p, sizeof (*config));
@@ -399,7 +435,7 @@
 
 /*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;
@@ -469,7 +505,7 @@
 	{ NULL }
 };
 
-#ifdef APACHE2
+#if AP_SERVER_MAJORVERSION_NUMBER >= 2
 /*ARGSUSED0*/
 static const char *
 ipp_method(const request_rec *r)
@@ -494,7 +530,11 @@
 	/* 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 = {
