Print this page
2837 - remove print/lp* from gate and use CUPS from userland
*** 22,36 ****
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
/* $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"
--- 22,37 ----
/*
* 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 $ */
/*
* Internet Printing Protocol (IPP) module for Apache.
*/
#include "ap_config.h"
*** 47,65 ****
#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"
#endif
#include <papi.h>
#include <ipp-listener.h>
! #ifndef APACHE2
module MODULE_VAR_EXPORT ipp_module;
#else
module AP_MODULE_DECLARE_DATA ipp_module;
#endif
--- 48,74 ----
#include "http_core.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "papi.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>
! #if AP_SERVER_MAJORVERSION_NUMBER < 2
module MODULE_VAR_EXPORT ipp_module;
#else
module AP_MODULE_DECLARE_DATA ipp_module;
#endif
*** 115,125 ****
{
ssize_t len_read;
request_rec *ap_r = (request_rec *)fd;
len_read = ap_get_client_block(ap_r, buf, siz);
! #ifndef APACHE2
ap_reset_timeout(ap_r);
#endif
#ifdef DEBUG
fprintf(stderr, "read_data(0x%8.8x, 0x%8.8x, %d): %d",
--- 124,134 ----
{
ssize_t len_read;
request_rec *ap_r = (request_rec *)fd;
len_read = ap_get_client_block(ap_r, buf, siz);
! #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,147 ****
write_data(void *fd, void *buf, size_t siz)
{
ssize_t len_written;
request_rec *ap_r = (request_rec *)fd;
! #ifndef APACHE2
ap_reset_timeout(ap_r);
#endif
#ifdef DEBUG
dump_buffer(stderr, "write_data:", buf, siz);
#endif
--- 146,156 ----
write_data(void *fd, void *buf, size_t siz)
{
ssize_t len_written;
request_rec *ap_r = (request_rec *)fd;
! #if AP_SERVER_MAJORVERSION_NUMBER < 2
ap_reset_timeout(ap_r);
#endif
#ifdef DEBUG
dump_buffer(stderr, "write_data:", buf, siz);
#endif
*** 151,161 ****
}
static void
discard_data(request_rec *r)
{
! #ifdef APACHE2
(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
--- 160,170 ----
}
static void
discard_data(request_rec *r)
{
! #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,185 ****
--- 183,199 ----
} 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,201 ****
if ((size = vsnprintf(message, BUFSIZ, fmt, args)) >= BUFSIZ)
if ((message = alloca(size)) != NULL)
vsnprintf(message, size, fmt, args);
va_end(args);
! #ifdef APACHE2
ap_log_rerror(file, line, level, NULL, r, message);
#else
ap_log_rerror(file, line, level, r, message);
#endif
}
--- 205,217 ----
if ((size = vsnprintf(message, BUFSIZ, fmt, args)) >= BUFSIZ)
if ((message = alloca(size)) != NULL)
vsnprintf(message, size, fmt, args);
va_end(args);
! #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,220 ****
{
papi_attribute_t **request = NULL, **response = NULL;
IPPListenerConfig *config;
papi_status_t status;
int ret;
/* Really, IPP is all POST requests */
if (r->method_number != M_POST)
return (DECLINED);
! #ifndef APACHE2
/*
* 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.
--- 221,240 ----
{
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);
! #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,243 ****
return (ret);
if (!ap_should_client_block(r))
return (HTTP_INTERNAL_SERVER_ERROR);
! #ifndef APACHE2
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);
--- 253,263 ----
return (ret);
if (!ap_should_client_block(r))
return (HTTP_INTERNAL_SERVER_ERROR);
! #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,269 ****
papiAttributeListPrint(stderr, request, "request (%d) ", getpid());
#endif
(void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL,
"originating-host", (char *)
! #ifdef APACHE2
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) {
char *host = (char *)ap_table_get(r->headers_in, "Host");
if ((host == NULL) || (host[0] == '\0'))
host = (char *)ap_get_server_name(r);
(void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL,
--- 268,293 ----
papiAttributeListPrint(stderr, request, "request (%d) ", getpid());
#endif
(void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL,
"originating-host", (char *)
! #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,303 ****
}
/*
* 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
* port.
*/
(void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL,
"peer-socket", ap_bfileno(r->connection->client, B_RD));
/* process the request */
status = ipp_process_request(request, &response, read_data, r);
if (status != PAPI_OK) {
errno = 0;
--- 313,335 ----
}
/*
* 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 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,330 ****
* 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) &&
(ap_table_get(r->headers_in, "Content-Length") == NULL))
discard_data(r);
/* write an IPP response back to the network */
r->content_type = "application/ipp";
! #ifndef APACHE2
ap_send_http_header(r);
#endif
status = ipp_write_message(write_data, r, response);
if (status != PAPI_OK)
--- 346,366 ----
* 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";
! #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,346 ****
#endif
papiAttributeListFree(request);
papiAttributeListFree(response);
! #ifndef APACHE2
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
--- 372,382 ----
#endif
papiAttributeListFree(request);
papiAttributeListFree(response);
! #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,368 ****
/*ARGSUSED1*/
static void *
create_ipp_dir_config(
! #ifndef APACHE2
pool *p,
#else
apr_pool_t *p,
#endif
char *dirspec)
{
IPPListenerConfig *config =
! #ifndef APACHE2
ap_pcalloc(p, sizeof (*config));
#else
apr_pcalloc(p, sizeof (*config));
#endif
--- 386,404 ----
/*ARGSUSED1*/
static void *
create_ipp_dir_config(
! #if AP_SERVER_MAJORVERSION_NUMBER < 2
pool *p,
#else
apr_pool_t *p,
#endif
char *dirspec)
{
IPPListenerConfig *config =
! #if AP_SERVER_MAJORVERSION_NUMBER < 2
ap_pcalloc(p, sizeof (*config));
#else
apr_pcalloc(p, sizeof (*config));
#endif
*** 397,407 ****
return (NULL);
}
/*ARGSUSED0*/
static const char *
! ipp_operation(cmd_parms *cmd, void *cfg, char *op, char *toggle)
{
IPPListenerConfig *config = (IPPListenerConfig *)cfg;
papi_status_t status;
status = ipp_configure_operation(&config->operations, op, toggle);
--- 433,443 ----
return (NULL);
}
/*ARGSUSED0*/
static const char *
! 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,477 ****
"hang the module until we can attach a debugger (no args)"),
#endif
{ NULL }
};
! #ifdef APACHE2
/*ARGSUSED0*/
static const char *
ipp_method(const request_rec *r)
{
return ("ipp");
--- 503,513 ----
"hang the module until we can attach a debugger (no args)"),
#endif
{ NULL }
};
! #if AP_SERVER_MAJORVERSION_NUMBER >= 2
/*ARGSUSED0*/
static const char *
ipp_method(const request_rec *r)
{
return ("ipp");
*** 492,502 ****
--- 528,542 ----
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 */