From: msweet Date: Fri, 4 Oct 2013 03:11:42 +0000 (+0000) Subject: Save work; public accessors for more stuff, continue transition away from private X-Git-Tag: v2.2b1~846 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fcups.git;a=commitdiff_plain;h=5ec1fd3d9e344d8a81466346d0a259fa6c1f0c36 Save work; public accessors for more stuff, continue transition away from private APIs. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11324 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/backend/snmp.c b/backend/snmp.c index fc40800c6..62fc54327 100644 --- a/backend/snmp.c +++ b/backend/snmp.c @@ -1233,7 +1233,7 @@ scan_devices(int ipv4, /* I - SNMP IPv4 socket */ for (addr = addrs; addr; addr = addr->next) { #ifdef AF_INET6 - if (_httpAddrFamily(&(addr->addr)) == AF_INET6) + if (httpAddrFamily(&(addr->addr)) == AF_INET6) fd = ipv6; else #endif /* AF_INET6 */ @@ -1335,7 +1335,7 @@ try_connect(http_addr_t *addr, /* I - Socket address */ debug_printf("DEBUG: %.3f Trying %s://%s:%d...\n", run_time(), port == 515 ? "lpd" : "socket", addrname, port); - if ((fd = socket(_httpAddrFamily(addr), SOCK_STREAM, 0)) < 0) + if ((fd = socket(httpAddrFamily(addr), SOCK_STREAM, 0)) < 0) { fprintf(stderr, "ERROR: Unable to create socket: %s\n", strerror(errno)); diff --git a/config-scripts/cups-common.m4 b/config-scripts/cups-common.m4 index 27be08f0d..a67f5aba4 100644 --- a/config-scripts/cups-common.m4 +++ b/config-scripts/cups-common.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-common.m4 8781 2009-08-28 17:34:54Z mike $" +dnl "$Id$" dnl dnl Common configuration stuff for CUPS. dnl @@ -462,5 +462,5 @@ esac AC_SUBST(BUILDDIRS) dnl -dnl End of "$Id: cups-common.m4 8781 2009-08-28 17:34:54Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-compiler.m4 b/config-scripts/cups-compiler.m4 index 252f2aa25..3c85abc14 100644 --- a/config-scripts/cups-compiler.m4 +++ b/config-scripts/cups-compiler.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $" +dnl "$Id$" dnl dnl Compiler stuff for CUPS. dnl @@ -296,5 +296,5 @@ case $uname in esac dnl -dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-defaults.m4 b/config-scripts/cups-defaults.m4 index 173cfeac8..02f9870a0 100644 --- a/config-scripts/cups-defaults.m4 +++ b/config-scripts/cups-defaults.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-defaults.m4 7959 2008-09-17 19:30:58Z mike $" +dnl "$Id$" dnl dnl Default cupsd configuration settings for CUPS. dnl @@ -400,5 +400,5 @@ AC_SUBST(CUPS_WEBIF) AC_DEFINE_UNQUOTED(CUPS_DEFAULT_WEBIF, $CUPS_DEFAULT_WEBIF) dnl -dnl End of "$Id: cups-defaults.m4 7959 2008-09-17 19:30:58Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-directories.m4 b/config-scripts/cups-directories.m4 index eec3dec02..45665a13f 100644 --- a/config-scripts/cups-directories.m4 +++ b/config-scripts/cups-directories.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-directories.m4 7799 2008-07-25 20:06:08Z mike $" +dnl "$Id$" dnl dnl Directory stuff for CUPS. dnl @@ -427,5 +427,5 @@ AC_DEFINE_UNQUOTED(CUPS_STATEDIR, "$CUPS_STATEDIR") AC_SUBST(CUPS_STATEDIR) dnl -dnl End of "$Id: cups-directories.m4 7799 2008-07-25 20:06:08Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-dnssd.m4 b/config-scripts/cups-dnssd.m4 index 02974ef8a..9207d616f 100644 --- a/config-scripts/cups-dnssd.m4 +++ b/config-scripts/cups-dnssd.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-dnssd.m4 7890 2008-08-29 22:19:39Z mike $" +dnl "$Id$" dnl dnl DNS Service Discovery (aka Bonjour) stuff for CUPS. dnl @@ -82,5 +82,5 @@ AC_SUBST(IPPFIND_BIN) AC_SUBST(IPPFIND_MAN) dnl -dnl End of "$Id: cups-dnssd.m4 7890 2008-08-29 22:19:39Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-gssapi.m4 b/config-scripts/cups-gssapi.m4 index d378bbfab..690d36c7c 100644 --- a/config-scripts/cups-gssapi.m4 +++ b/config-scripts/cups-gssapi.m4 @@ -3,7 +3,7 @@ dnl "$Id$" dnl dnl GSSAPI/Kerberos library detection for CUPS. dnl -dnl Copyright 2007-2012 by Apple Inc. +dnl Copyright 2007-2013 by Apple Inc. dnl Copyright 2006-2007 by Easy Software Products. dnl dnl This file contains Kerberos support code, copyright 2006 by @@ -71,38 +71,9 @@ if test x$enable_gssapi != xno; then if test "x$LIBGSSAPI" != x; then AC_CHECK_HEADER(krb5.h, AC_DEFINE(HAVE_KRB5_H)) if test -d /System/Library/Frameworks/GSS.framework; then - gssdir="/System/Library/Frameworks/GSS.framework" - AC_MSG_CHECKING(for GSS/gssapi.h presence) - if test -f $gssdir/Headers/gssapi.h; then - AC_DEFINE(HAVE_GSS_GSSAPI_H) - AC_MSG_RESULT(yes) - else - AC_MSG_RESULT(no) - fi - AC_MSG_CHECKING(for GSS/gssapi_generic.h presence) - if test -f $gssdir/Headers/gssapi_generic.h; then - AC_DEFINE(HAVE_GSSAPI_GENERIC_H) - AC_MSG_RESULT(yes) - else - AC_MSG_RESULT(no) - fi - AC_MSG_CHECKING(for GSS/gssapi_spi.h presence) - if test -f $gssdir/PrivateHeaders/gssapi_spi.h; then - AC_MSG_RESULT(yes) - AC_MSG_CHECKING(for GSS/gssapi_spi.h usability) - if test -s $gssdir/PrivateHeaders/gssapi_spi.h; then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_GSS_GSSAPI_SPI_H) - else - AC_MSG_RESULT(no) - fi - else - AC_MSG_RESULT(no) - if test $uversion -ge 110 -a $uversion -lt 120; then - # Broken public headers in 10.7.x... - AC_MSG_ERROR(Run 'sudo mkdir -p $gssdir/PrivateHeaders' and 'sudo touch $gssdir/PrivateHeaders/gssapi_spi.h' to build CUPS.) - fi - fi + AC_CHECK_HEADER(GSS/gssapi.h, AC_DEFINE(HAVE_GSS_GSSAPI_H)) + AC_CHECK_HEADER(GSS/gssapi_generic.h, AC_DEFINE(HAVE_GSS_GSSAPI_GENERIC_H)) + AC_CHECK_HEADER(GSS/gssapi_spi.h, AC_DEFINE(HAVE_GSS_GSSAPI_SPI_H)) else AC_CHECK_HEADER(gssapi.h, AC_DEFINE(HAVE_GSSAPI_H)) AC_CHECK_HEADER(gssapi/gssapi.h, AC_DEFINE(HAVE_GSSAPI_GSSAPI_H)) diff --git a/config-scripts/cups-largefile.m4 b/config-scripts/cups-largefile.m4 index 8243de787..6ef4b81e1 100644 --- a/config-scripts/cups-largefile.m4 +++ b/config-scripts/cups-largefile.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-largefile.m4 6649 2007-07-11 21:46:42Z mike $" +dnl "$Id$" dnl dnl Large file support stuff for CUPS. dnl @@ -48,5 +48,5 @@ fi AC_CHECK_FUNC(strtoll, AC_DEFINE(HAVE_STRTOLL)) dnl -dnl End of "$Id: cups-largefile.m4 6649 2007-07-11 21:46:42Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-launchd.m4 b/config-scripts/cups-launchd.m4 index 23a229516..8db35d43d 100644 --- a/config-scripts/cups-launchd.m4 +++ b/config-scripts/cups-launchd.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-launchd.m4 6649 2007-07-11 21:46:42Z mike $" +dnl "$Id$" dnl dnl launchd stuff for CUPS. dnl @@ -39,5 +39,5 @@ AC_SUBST(DEFAULT_LAUNCHD_CONF) AC_SUBST(LAUNCHDLIBS) dnl -dnl End of "$Id: cups-launchd.m4 6649 2007-07-11 21:46:42Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-libtool.m4 b/config-scripts/cups-libtool.m4 index d6026b24b..5fc0d6e3c 100644 --- a/config-scripts/cups-libtool.m4 +++ b/config-scripts/cups-libtool.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-libtool.m4 6649 2007-07-11 21:46:42Z mike $" +dnl "$Id$" dnl dnl Libtool stuff for CUPS. dnl @@ -35,5 +35,5 @@ if test x$LIBTOOL != x; then fi dnl -dnl End of "$Id: cups-libtool.m4 6649 2007-07-11 21:46:42Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-manpages.m4 b/config-scripts/cups-manpages.m4 index 16246838c..fd1d8c791 100644 --- a/config-scripts/cups-manpages.m4 +++ b/config-scripts/cups-manpages.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-manpages.m4 6649 2007-07-11 21:46:42Z mike $" +dnl "$Id$" dnl dnl Manpage stuff for CUPS. dnl @@ -78,5 +78,5 @@ AC_SUBST(MAN8EXT) AC_SUBST(MAN8DIR) dnl -dnl End of "$Id: cups-manpages.m4 6649 2007-07-11 21:46:42Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-network.m4 b/config-scripts/cups-network.m4 index b97fb4a49..697cfb5b3 100644 --- a/config-scripts/cups-network.m4 +++ b/config-scripts/cups-network.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-network.m4 7918 2008-09-08 22:03:01Z mike $" +dnl "$Id$" dnl dnl Networking stuff for CUPS. dnl @@ -70,5 +70,5 @@ AC_CHECK_HEADERS(AppleTalk/at_proto.h,AC_DEFINE(HAVE_APPLETALK_AT_PROTO_H),, [#include ]) dnl -dnl End of "$Id: cups-network.m4 7918 2008-09-08 22:03:01Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-opsys.m4 b/config-scripts/cups-opsys.m4 index acf5b51a3..700a284d0 100644 --- a/config-scripts/cups-opsys.m4 +++ b/config-scripts/cups-opsys.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-opsys.m4 6649 2007-07-11 21:46:42Z mike $" +dnl "$Id$" dnl dnl Operating system stuff for CUPS. dnl @@ -35,5 +35,5 @@ case "$uname" in esac dnl -dnl "$Id: cups-opsys.m4 6649 2007-07-11 21:46:42Z mike $" +dnl "$Id$" dnl diff --git a/config-scripts/cups-pam.m4 b/config-scripts/cups-pam.m4 index 72bf32fc3..aa554d1b7 100644 --- a/config-scripts/cups-pam.m4 +++ b/config-scripts/cups-pam.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-pam.m4 7960 2008-09-17 19:42:02Z mike $" +dnl "$Id$" dnl dnl PAM stuff for CUPS. dnl @@ -98,5 +98,5 @@ AC_SUBST(PAMMOD) AC_SUBST(PAMMODAUTH) dnl -dnl End of "$Id: cups-pam.m4 7960 2008-09-17 19:42:02Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-scripting.m4 b/config-scripts/cups-scripting.m4 index d4ed98850..af97a94dc 100644 --- a/config-scripts/cups-scripting.m4 +++ b/config-scripts/cups-scripting.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-scripting.m4 7915 2008-09-07 22:18:29Z mike $" +dnl "$Id$" dnl dnl Scripting configuration stuff for CUPS. dnl @@ -85,5 +85,5 @@ if test "x$CUPS_PYTHON" != x; then fi dnl -dnl End of "$Id: cups-scripting.m4 7915 2008-09-07 22:18:29Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-sharedlibs.m4 b/config-scripts/cups-sharedlibs.m4 index ef2c71424..2313a2ae4 100644 --- a/config-scripts/cups-sharedlibs.m4 +++ b/config-scripts/cups-sharedlibs.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-sharedlibs.m4 7630 2008-06-09 22:31:44Z mike $" +dnl "$Id$" dnl dnl Shared library support for CUPS. dnl @@ -234,5 +234,5 @@ AC_SUBST(IMGLIBS) AC_SUBST(EXPORT_LDFLAGS) dnl -dnl End of "$Id: cups-sharedlibs.m4 7630 2008-06-09 22:31:44Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-ssl.m4 b/config-scripts/cups-ssl.m4 index f3dc0595f..faa9cc68e 100644 --- a/config-scripts/cups-ssl.m4 +++ b/config-scripts/cups-ssl.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-ssl.m4 7241 2008-01-22 22:34:52Z mike $" +dnl "$Id$" dnl dnl OpenSSL/GNUTLS stuff for CUPS. dnl @@ -157,5 +157,5 @@ EXPORT_SSLLIBS="$SSLLIBS" AC_SUBST(EXPORT_SSLLIBS) dnl -dnl End of "$Id: cups-ssl.m4 7241 2008-01-22 22:34:52Z mike $". +dnl End of "$Id$". dnl diff --git a/config-scripts/cups-threads.m4 b/config-scripts/cups-threads.m4 index b95c79fa4..bd5c69867 100644 --- a/config-scripts/cups-threads.m4 +++ b/config-scripts/cups-threads.m4 @@ -1,5 +1,5 @@ dnl -dnl "$Id: cups-threads.m4 6649 2007-07-11 21:46:42Z mike $" +dnl "$Id$" dnl dnl Threading stuff for CUPS. dnl @@ -50,5 +50,5 @@ fi AC_SUBST(PTHREAD_FLAGS) dnl -dnl End of "$Id: cups-threads.m4 6649 2007-07-11 21:46:42Z mike $". +dnl End of "$Id$". dnl diff --git a/cups/http-addr.c b/cups/http-addr.c index 4955ba4d7..d9ab97099 100644 --- a/cups/http-addr.c +++ b/cups/http-addr.c @@ -345,6 +345,20 @@ httpAddrLookup( } +/* + * 'httpAddrFamily()' - Get the address family of an address. + */ + +int /* O - Address family */ +httpAddrFamily(http_addr_t *addr) /* I - Address */ +{ + if (addr) + return (addr->addr.sa_family); + else + return (0); +} + + /* * 'httpAddrPort()' - Get the port number associated with an address. * @@ -355,7 +369,7 @@ int /* O - Port number */ httpAddrPort(http_addr_t *addr) /* I - Address */ { if (!addr) - return (ippPort()); + return (-1); #ifdef AF_INET6 else if (addr->addr.sa_family == AF_INET6) return (ntohs(addr->ipv6.sin6_port)); @@ -363,7 +377,7 @@ httpAddrPort(http_addr_t *addr) /* I - Address */ else if (addr->addr.sa_family == AF_INET) return (ntohs(addr->ipv4.sin_port)); else - return (ippPort()); + return (0); } /* For OS X 10.8 and earlier */ @@ -694,12 +708,16 @@ httpGetHostname(http_t *http, /* I - HTTP connection or NULL */ char *s, /* I - String buffer for name */ int slen) /* I - Size of buffer */ { - if (!s || slen <= 1) - return (NULL); - if (http) { - if (http->hostname[0] == '/') + if (!s || slen <= 1) + { + if (http->hostname[0] == '/') + return ("localhost"); + else + return (http->hostname); + } + else if (http->hostname[0] == '/') strlcpy(s, "localhost", slen); else strlcpy(s, http->hostname, slen); @@ -710,6 +728,9 @@ httpGetHostname(http_t *http, /* I - HTTP connection or NULL */ * Get the hostname... */ + if (!s || slen <= 1) + return (NULL); + if (gethostname(s, slen) < 0) strlcpy(s, "localhost", slen); diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index a718ba347..0b7e24359 100644 --- a/cups/http-addrlist.c +++ b/cups/http-addrlist.c @@ -122,7 +122,7 @@ httpAddrConnect2( httpAddrString(&(addrlist->addr), temp, sizeof(temp)), httpAddrPort(&(addrlist->addr)))); - if ((*sock = (int)socket(_httpAddrFamily(&(addrlist->addr)), SOCK_STREAM, + if ((*sock = (int)socket(httpAddrFamily(&(addrlist->addr)), SOCK_STREAM, 0)) < 0) { /* diff --git a/cups/http-private.h b/cups/http-private.h index 016dfe2ba..43285b3c5 100644 --- a/cups/http-private.h +++ b/cups/http-private.h @@ -243,6 +243,7 @@ typedef enum _http_mode_e /**** HTTP mode enumeration ****/ _HTTP_MODE_SERVER /* Server connected (accepted) from client */ } _http_mode_t; +# ifndef _HTTP_NO_PRIVATE struct _http_s /**** HTTP connection structure ****/ { int fd; /* File descriptor for this socket */ @@ -264,7 +265,7 @@ struct _http_s /**** HTTP connection structure ****/ int used; /* Number of bytes used in buffer */ char buffer[HTTP_MAX_BUFFER]; /* Buffer for incoming data */ - int auth_type; /* Authentication in use */ + int _auth_type; /* Authentication in use (deprecated) */ _cups_md5_state_t md5_state; /* MD5 state */ char nonce[HTTP_MAX_VALUE]; /* Nonce value */ @@ -333,6 +334,7 @@ struct _http_s /**** HTTP connection structure ****/ Bytef *dbuffer; /* Decompression buffer */ # endif /* HAVE_LIBZ */ }; +# endif /* !_HTTP_NO_PRIVATE */ /* @@ -396,7 +398,6 @@ extern void _cups_freeifaddrs(struct ifaddrs *addrs); * Prototypes... */ -#define _httpAddrFamily(addrp) (addrp)->addr.sa_family extern int _httpAddrPort(http_addr_t *addr) _CUPS_INTERNAL_MSG("Use httpAddrPort instead."); extern void _httpAddrSetPort(http_addr_t *addr, int port); diff --git a/cups/http-support.c b/cups/http-support.c index 8f5c67d80..70838feff 100644 --- a/cups/http-support.c +++ b/cups/http-support.c @@ -1,55 +1,18 @@ /* * "$Id$" * - * HTTP support routines for CUPS. + * HTTP support routines for CUPS. * - * Copyright 2007-2013 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". * - * This file is subject to the Apple OS-Developed Software exception. - * - * Contents: - * - * httpAssembleURI() - Assemble a uniform resource identifier from its - * components. - * httpAssembleURIf() - Assemble a uniform resource identifier from its - * components with a formatted resource. - * httpAssembleUUID() - Assemble a name-based UUID URN conforming to RFC - * 4122. - * httpDecode64() - Base64-decode a string. - * httpDecode64_2() - Base64-decode a string. - * httpEncode64() - Base64-encode a string. - * httpEncode64_2() - Base64-encode a string. - * httpGetDateString() - Get a formatted date/time string from a time value. - * httpGetDateString2() - Get a formatted date/time string from a time value. - * httpGetDateTime() - Get a time value from a formatted date/time string. - * httpSeparate() - Separate a Universal Resource Identifier into its - * components. - * httpSeparate2() - Separate a Universal Resource Identifier into its - * components. - * httpSeparateURI() - Separate a Universal Resource Identifier into its - * components. - * _httpStatus() - Return the localized string describing a HTTP - * status code. - * httpStatus() - Return a short string describing a HTTP status - * code. - * _cups_hstrerror() - hstrerror() emulation function for Solaris and - * others. - * _httpDecodeURI() - Percent-decode a HTTP request URI. - * _httpEncodeURI() - Percent-encode a HTTP request URI. - * _httpResolveURI() - Resolve a DNS-SD URI. - * http_client_cb() - Client callback for resolving URI. - * http_copy_decode() - Copy and decode a URI. - * http_copy_encode() - Copy and encode a URI. - * http_poll_cb() - Wait for input on the specified file descriptors. - * http_resolve_cb() - Build a device URI for the given service name. - * http_resolve_cb() - Build a device URI for the given service name. + * This file is subject to the Apple OS-Developed Software exception. */ /* @@ -94,7 +57,7 @@ typedef struct _http_uribuf_s /* URI buffer */ * Local globals... */ -static const char * const http_days[7] = +static const char * const http_days[7] =/* Days of the week */ { "Sun", "Mon", @@ -105,7 +68,7 @@ static const char * const http_days[7] = "Sat" }; static const char * const http_months[12] = - { + { /* Months of the year */ "Jan", "Feb", "Mar", @@ -119,6 +82,26 @@ static const char * const http_months[12] = "Nov", "Dec" }; +static const char * const http_states[] = + { /* HTTP state strings */ + "HTTP_STATE_ERROR", + "HTTP_STATE_WAITING", + "HTTP_STATE_OPTIONS", + "HTTP_STATE_GET", + "HTTP_STATE_GET_SEND", + "HTTP_STATE_HEAD", + "HTTP_STATE_POST", + "HTTP_STATE_POST_RECV", + "HTTP_STATE_POST_SEND", + "HTTP_STATE_PUT", + "HTTP_STATE_PUT_RECV", + "HTTP_STATE_DELETE", + "HTTP_STATE_TRACE", + "HTTP_STATE_CONNECT", + "HTTP_STATE_STATUS", + "HTTP_STATE_UNKNOWN_METHOD", + "HTTP_STATE_UNKNOWN_VERSION" + }; /* @@ -1324,6 +1307,22 @@ httpSeparateURI( } +/* + * 'httpStateString()' - Return the string describing a HTTP state value. + * + * @since CUPS 2.0@ + */ + +const char * /* O - State string */ +httpStateString(http_state_t state) /* I - HTTP state value */ +{ + if (state < HTTP_STATE_ERROR || state > HTTP_STATE_UNKNOWN_VERSION) + return ("HTTP_STATE_???"); + else + return (http_states[state - HTTP_STATE_ERROR]); +} + + /* * '_httpStatus()' - Return the localized string describing a HTTP status code. * diff --git a/cups/http.c b/cups/http.c index 8315cd227..fc67ba890 100644 --- a/cups/http.c +++ b/cups/http.c @@ -202,8 +202,12 @@ httpAcceptConnection(int fd, /* I - Listen socket file descriptor */ return (NULL); } - httpAddrString(&(http->addrlist->addr), http->hostname, - sizeof(http->hostname)); + http->hostaddr = &(http->addrlist->addr); + + if (httpAddrLocalhost(http->hostaddr)) + strlcpy(http->hostname, "localhost", sizeof(http->hostname)); + else + httpAddrString(http->hostaddr, http->hostname, sizeof(http->hostname)); #ifdef SO_NOSIGPIPE /* @@ -1059,6 +1063,23 @@ httpGetCookie(http_t *http) /* I - HTTP connecion */ } +/* + * 'httpGetEncryption()' - Get the current encryption mode of a connection. + * + * This function returns the encryption mode for the connection. Use the + * @link httpIsEncrypted@ function to determine whether a TLS session has + * been established. + * + * @since CUPS 2.0@ + */ + +http_encryption_t /* O - Current encryption mode */ +httpGetEncryption(http_t *http) /* I - HTTP connection */ +{ + return (http ? http->encryption : HTTP_ENCRYPTION_IF_REQUESTED); +} + + /* * 'httpGetExpect()' - Get the value of the Expect header, if any. * @@ -1274,6 +1295,23 @@ httpGetReady(http_t *http) /* I - HTTP connection */ } +/* + * 'httpGetRemaining()' - Get the number of remaining bytes in the message + * body or current chunk. + * + * The @link httpIsChunked@ function can be used to determine whether the + * message body is chunked or fixed-length. + * + * @since CUPS 2.0@ + */ + +size_t /* O - Remaining bytes */ +httpGetRemaining(http_t *http) /* I - HTTP connection */ +{ + return (http ? http->data_remaining : 0); +} + + /* * 'httpGets()' - Get a line of text from a HTTP connection. */ @@ -1726,6 +1764,37 @@ httpInitialize(void) } +/* + * 'httpIsChunked()' - Report whether a message body is chunked. + * + * This function returns non-zero if the message body is composed of + * variable-length chunks. + * + * @since CUPS 2.0@ + */ + +int /* O - 1 if chunked, 0 if not */ +httpIsChunked(http_t *http) /* I - HTTP connection */ +{ + return (http ? http->data_encoding == HTTP_ENCODING_CHUNKED : 0); +} + + +/* + * 'httpIsEncrypted()' - Report whether a connection is encrypted. + * + * This function returns non-zero if the connection is currently encrypted. + * + * @since CUPS 2.0@ + */ + +int /* O - 1 if encrypted, 0 if not */ +httpIsEncrypted(http_t *http) /* I - HTTP connection */ +{ + return (http ? http->tls != NULL : 0); +} + + /* * 'httpOptions()' - Send an OPTIONS request to the server. */ @@ -3083,6 +3152,25 @@ httpSetTimeout( } +/* + * 'httpShutdown()' - Shutdown one side of an HTTP connection. + * + * @since CUPS 2.0@ + */ + +void +httpShutdown(http_t *http) /* I - HTTP connection */ +{ + if (!http || http->fd < 0) + return; + + if (http->tls) + http_shutdown_ssl(http); + + shutdown(http->fd, SHUT_RD); +} + + /* * 'httpTrace()' - Send an TRACE request to the server. */ @@ -3812,7 +3900,7 @@ httpWriteResponse(http_t *http, /* I - HTTP connection */ if (status >= HTTP_STATUS_BAD_REQUEST && http->keep_alive) { - http->keep_alive = 0; + http->keep_alive = HTTP_KEEPALIVE_OFF; httpSetField(http, HTTP_FIELD_KEEP_ALIVE, ""); } diff --git a/cups/http.h b/cups/http.h index 11f5b4af5..ce2c25152 100644 --- a/cups/http.h +++ b/cups/http.h @@ -614,11 +614,19 @@ extern http_state_t httpWriteResponse(http_t *http, /**** New in CUPS 2.0 ****/ +extern int httpAddrFamily(http_addr_t *addr) _CUPS_API_2_0; extern time_t httpGetActivity(http_t *http) _CUPS_API_2_0; extern http_addr_t *httpGetAddress(http_t *http) _CUPS_API_2_0; +extern http_encryption_t httpGetEncryption(http_t *http) _CUPS_API_2_0; extern http_keepalive_t httpGetKeepAlive(http_t *http) _CUPS_API_2_0; extern size_t httpGetReady(http_t *http) _CUPS_API_2_0; +extern size_t httpGetRemaining(http_t *http) _CUPS_API_2_0; +extern int httpIsChunked(http_t *http) _CUPS_API_2_0; +extern int httpIsEncrypted(http_t *http) _CUPS_API_2_0; extern void httpSetKeepAlive(http_t *http, http_keepalive_t keep_alive) _CUPS_API_2_0; +extern void httpShutdown(http_t *http) _CUPS_API_2_0; +extern const char *httpStateString(http_state_t state); + /* * C++ magic... diff --git a/doc/help/man-cups-files.conf.html b/doc/help/man-cups-files.conf.html index 8c3a610fd..3e30a9d98 100644 --- a/doc/help/man-cups-files.conf.html +++ b/doc/help/man-cups-files.conf.html @@ -140,6 +140,14 @@ be found.
Specifies the directory where the server configuration files can be found.
+
SyncOnClose Yes +
+
+
SyncOnClose No +
+
Specifies whether the scheduler calls fsync(2) after writing configuration +or state files. The default is No. +
SystemGroup group-name [group-name ...]
diff --git a/doc/help/man-cupsaddsmb.html b/doc/help/man-cupsaddsmb.html index 0bb0ddcd9..cc4e46e6c 100644 --- a/doc/help/man-cupsaddsmb.html +++ b/doc/help/man-cupsaddsmb.html @@ -162,8 +162,6 @@ Getting the full set of Windows driver files should be easier.

See Also

smbd(8), smb.conf(5), http://localhost:631/help -
-http://www.cups.org/windows/

Copyright

Copyright 2007-2013 by Apple Inc. diff --git a/scheduler/auth.c b/scheduler/auth.c index 635d2c648..514f683bc 100644 --- a/scheduler/auth.c +++ b/scheduler/auth.c @@ -1,51 +1,19 @@ /* * "$Id$" * - * Authorization routines for the CUPS scheduler. + * Authorization routines for the CUPS scheduler. * - * Copyright 2007-2012 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * This file contains Kerberos support code, copyright 2006 by - * Jelmer Vernooij. + * This file contains Kerberos support code, copyright 2006 by + * Jelmer Vernooij. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". - * - * Contents: - * - * cupsdAddIPMask() - Add an IP address authorization mask. - * cupsdAddLocation() - Add a location for authorization. - * cupsdAddName() - Add a name to a location... - * cupsdAddNameMask() - Add a host or interface name authorization - * mask. - * cupsdAuthorize() - Validate any authorization credentials. - * cupsdCheckAccess() - Check whether the given address is allowed to - * access a location. - * cupsdCheckAuth() - Check authorization masks. - * cupsdCheckGroup() - Check for a user's group membership. - * cupsdCopyLocation() - Make a copy of a location... - * cupsdDeleteAllLocations() - Free all memory used for location - * authorization. - * cupsdFindBest() - Find the location entry that best matches the - * resource. - * cupsdFindLocation() - Find the named location. - * cupsdFreeLocation() - Free all memory used by a location. - * cupsdIsAuthorized() - Check to see if the user is authorized... - * cupsdNewLocation() - Create a new location for authorization. - * check_authref() - Check if an authorization services reference - * has the supplied right. - * compare_locations() - Compare two locations. - * copy_authmask() - Copy function for auth masks. - * cups_crypt() - Encrypt the password using the DES or MD5 - * algorithms, as needed. - * free_authmask() - Free function for auth masks. - * get_md5_password() - Get an MD5 password. - * pam_func() - PAM conversation function. - * to64() - Base64-encode an integer value... + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ /* @@ -408,7 +376,7 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */ } #ifdef HAVE_AUTHORIZATION_H else if (!strncmp(authorization, "AuthRef ", 8) && - !_cups_strcasecmp(con->http->hostname, "localhost")) + httpAddrLocalhost(httpGetAddress(con->http))) { OSStatus status; /* Status */ int authlen; /* Auth string length */ @@ -601,7 +569,7 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */ } #endif /* SO_PEERCRED && AF_LOCAL */ else if (!strncmp(authorization, "Local", 5) && - !_cups_strcasecmp(con->http->hostname, "localhost")) + httpAddrLocalhost(httpGetAddress(con->http))) { /* * Get Local certificate authentication data... @@ -1148,7 +1116,7 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */ * to run as the correct user to get Kerberos credentials of its own. */ - if (_httpAddrFamily(con->http->hostaddr) == AF_LOCAL) + if (httpAddrFamily(con->http->hostaddr) == AF_LOCAL) { cupsd_ucred_t peercred; /* Peer credentials */ socklen_t peersize; /* Size of peer credentials */ @@ -1210,7 +1178,7 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */ int /* O - 1 if allowed, 0 otherwise */ cupsdCheckAccess( unsigned ip[4], /* I - Client address */ - char *name, /* I - Client hostname */ + const char *name, /* I - Client hostname */ int namelen, /* I - Length of hostname */ cupsd_location_t *loc) /* I - Location to check */ { @@ -1269,7 +1237,7 @@ cupsdCheckAccess( int /* O - 1 if mask matches, 0 otherwise */ cupsdCheckAuth(unsigned ip[4], /* I - Client address */ - char *name, /* I - Client hostname */ + const char *name, /* I - Client hostname */ int name_len, /* I - Length of hostname */ cups_array_t *masks) /* I - Masks */ { @@ -1817,6 +1785,10 @@ cupsdIsAuthorized(cupsd_client_t *con, /* I - Connection */ int i, /* Looping vars */ auth, /* Authorization status */ type; /* Type of authentication */ + http_addr_t *hostaddr = httpGetAddress(con->http); + /* Client address */ + const char *hostname = httpGetHostname(con->http, NULL, 0); + /* Client hostname */ unsigned address[4]; /* Authorization address */ cupsd_location_t *best; /* Best match for location so far */ int hostlen; /* Length of hostname */ @@ -1857,8 +1829,9 @@ cupsdIsAuthorized(cupsd_client_t *con, /* I - Connection */ if (!con->best) { - if (!strcmp(con->http->hostname, "localhost") || - !strcmp(con->http->hostname, ServerName)) + if (httpAddrLocalhost(httpGetAddress(con->http)) || + !strcmp(hostname, ServerName) || + cupsArrayFind(ServerAlias, (void *)hostname)) return (HTTP_OK); else return (HTTP_FORBIDDEN); @@ -1884,16 +1857,16 @@ cupsdIsAuthorized(cupsd_client_t *con, /* I - Connection */ */ #ifdef AF_INET6 - if (con->http->hostaddr->addr.sa_family == AF_INET6) + if (httpAddrFamily(hostaddr) == AF_INET6) { /* * Copy IPv6 address... */ - address[0] = ntohl(con->http->hostaddr->ipv6.sin6_addr.s6_addr32[0]); - address[1] = ntohl(con->http->hostaddr->ipv6.sin6_addr.s6_addr32[1]); - address[2] = ntohl(con->http->hostaddr->ipv6.sin6_addr.s6_addr32[2]); - address[3] = ntohl(con->http->hostaddr->ipv6.sin6_addr.s6_addr32[3]); + address[0] = ntohl(hostaddr->ipv6.sin6_addr.s6_addr32[0]); + address[1] = ntohl(hostaddr->ipv6.sin6_addr.s6_addr32[1]); + address[2] = ntohl(hostaddr->ipv6.sin6_addr.s6_addr32[2]); + address[3] = ntohl(hostaddr->ipv6.sin6_addr.s6_addr32[3]); } else #endif /* AF_INET6 */ @@ -1906,14 +1879,14 @@ cupsdIsAuthorized(cupsd_client_t *con, /* I - Connection */ address[0] = 0; address[1] = 0; address[2] = 0; - address[3] = ntohl(con->http->hostaddr->ipv4.sin_addr.s_addr); + address[3] = ntohl(hostaddr->ipv4.sin_addr.s_addr); } else memset(address, 0, sizeof(address)); - hostlen = strlen(con->http->hostname); + hostlen = strlen(hostname); - auth = cupsdCheckAccess(address, con->http->hostname, hostlen, best) + auth = cupsdCheckAccess(address, hostname, hostlen, best) ? CUPSD_AUTH_ALLOW : CUPSD_AUTH_DENY; cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdIsAuthorized: auth=CUPSD_AUTH_%s...", @@ -1928,7 +1901,8 @@ cupsdIsAuthorized(cupsd_client_t *con, /* I - Connection */ */ if ((best->encryption >= HTTP_ENCRYPT_REQUIRED && !con->http->tls && - _cups_strcasecmp(con->http->hostname, "localhost") && + _cups_strcasecmp(hostname, "localhost") && + !httpAddrLocalhost(hostaddr) && best->satisfy == CUPSD_AUTH_SATISFY_ALL) && !(type == CUPSD_AUTH_NEGOTIATE || (type == CUPSD_AUTH_NONE && diff --git a/scheduler/auth.h b/scheduler/auth.h index feb2fcd52..ef5bd401e 100644 --- a/scheduler/auth.h +++ b/scheduler/auth.h @@ -1,16 +1,16 @@ /* * "$Id$" * - * Authorization definitions for the CUPS scheduler. + * Authorization definitions for the CUPS scheduler. * - * Copyright 2007-2011 by Apple Inc. - * Copyright 1997-2006 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2006 by Easy Software Products, all rights reserved. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ /* @@ -130,9 +130,9 @@ extern void cupsdAddLocation(cupsd_location_t *loc); extern void cupsdAddName(cupsd_location_t *loc, char *name); extern int cupsdAddNameMask(cups_array_t **masks, char *name); extern void cupsdAuthorize(cupsd_client_t *con); -extern int cupsdCheckAccess(unsigned ip[4], char *name, +extern int cupsdCheckAccess(unsigned ip[4], const char *name, int namelen, cupsd_location_t *loc); -extern int cupsdCheckAuth(unsigned ip[4], char *name, int namelen, +extern int cupsdCheckAuth(unsigned ip[4], const char *name, int namelen, cups_array_t *masks); extern int cupsdCheckGroup(const char *username, struct passwd *user, diff --git a/scheduler/client.c b/scheduler/client.c index 676826413..0fda74791 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -1,52 +1,27 @@ /* * "$Id$" * - * Client routines for the CUPS scheduler. + * Client routines for the CUPS scheduler. * - * Copyright 2007-2013 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * This file contains Kerberos support code, copyright 2006 by - * Jelmer Vernooij. + * This file contains Kerberos support code, copyright 2006 by + * Jelmer Vernooij. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". - * - * Contents: - * - * cupsdAcceptClient() - Accept a new client. - * cupsdCloseAllClients() - Close all remote clients immediately. - * cupsdCloseClient() - Close a remote client. - * cupsdFlushHeader() - Flush the header fields to the client. - * cupsdReadClient() - Read data from a client. - * cupsdSendCommand() - Send output from a command via HTTP. - * cupsdSendError() - Send an error message via HTTP. - * cupsdSendHeader() - Send an HTTP request. - * cupsdUpdateCGI() - Read status messages from CGI scripts and - * programs. - * cupsdWriteClient() - Write data to a client as needed. - * check_if_modified() - Decode an "If-Modified-Since" line. - * compare_clients() - Compare two client connections. - * data_ready() - Check whether data is available from a client. - * get_file() - Get a filename and state info. - * install_cupsd_conf() - Install a configuration file. - * is_cgi() - Is the resource a CGI script/program? - * is_path_absolute() - Is a path absolute and free of relative elements - * (i.e. ".."). - * pipe_command() - Pipe the output of a command to the remote - * client. - * valid_host() - Is the Host: field valid? - * write_file() - Send a file via HTTP. - * write_pipe() - Flag that data is available on the CGI pipe. + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ /* * Include necessary headers... */ +#define _CUPS_NO_DEPRECATED +//#define _HTTP_NO_PRIVATE #include "cupsd.h" #ifdef __APPLE__ @@ -61,32 +36,12 @@ * Local globals... */ -static const char * const http_states[] = - { /* HTTP state strings */ - "HTTP_STATE_ERROR", - "HTTP_STATE_WAITING", - "HTTP_STATE_OPTIONS", - "HTTP_STATE_GET", - "HTTP_STATE_GET_SEND", - "HTTP_STATE_HEAD", - "HTTP_STATE_POST", - "HTTP_STATE_POST_RECV", - "HTTP_STATE_POST_SEND", - "HTTP_STATE_PUT", - "HTTP_STATE_PUT_RECV", - "HTTP_STATE_DELETE", - "HTTP_STATE_TRACE", - "HTTP_STATE_CONNECT", - "HTTP_STATE_STATUS", - "HTTP_STATE_UNKNOWN_METHOD", - "HTTP_STATE_UNKNOWN_VERSION" - }; static const char * const ipp_states[] = { /* IPP state strings */ "IPP_IDLE", "IPP_HEADER", "IPP_ATTRIBUTE", - "IPP_DATA" + "IPP_STATE_DATA" }; @@ -98,7 +53,6 @@ static int check_if_modified(cupsd_client_t *con, struct stat *filestats); static int compare_clients(cupsd_client_t *a, cupsd_client_t *b, void *data); -static int data_ready(cupsd_client_t *con); static char *get_file(cupsd_client_t *con, struct stat *filestats, char *filename, int len); static http_status_t install_cupsd_conf(cupsd_client_t *con); @@ -188,7 +142,7 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ con->number = ++ LastClientNumber; con->file = -1; // con->http->activity = time(NULL); -// con->http->hostaddr = &(con->clientaddr); +// httpGetAddress(con->http) = &(con->clientaddr); // con->http->wait_value = 10000; // con->http->mode = _HTTP_MODE_SERVER; @@ -220,10 +174,10 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ */ if (lis->address.addr.sa_family == AF_INET6 && - con->http->hostaddr->ipv6.sin6_addr.s6_addr32[0] == 0 && - con->http->hostaddr->ipv6.sin6_addr.s6_addr32[1] == 0 && - ntohl(con->http->hostaddr->ipv6.sin6_addr.s6_addr32[2]) == 0xffff) - con->http->hostaddr->ipv6.sin6_addr.s6_addr32[2] = 0; + httpGetAddress(con->http)->ipv6.sin6_addr.s6_addr32[0] == 0 && + httpGetAddress(con->http)->ipv6.sin6_addr.s6_addr32[1] == 0 && + ntohl(httpGetAddress(con->http)->ipv6.sin6_addr.s6_addr32[2]) == 0xffff) + httpGetAddress(con->http)->ipv6.sin6_addr.s6_addr32[2] = 0; #endif /* AF_INET6 */ /* @@ -262,14 +216,14 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ * Get the hostname or format the IP address as needed... */ - if (httpAddrLocalhost(con->http->hostaddr)) + if (httpAddrLocalhost(httpGetAddress(con->http))) { /* * Map accesses from the loopback interface to "localhost"... */ - strlcpy(con->http->hostname, "localhost", sizeof(con->http->hostname)); - hostname = con->http->hostname; + strlcpy(httpGetHostname(con->http, NULL, 0), "localhost", sizeof(httpGetHostname(con->http, NULL, 0))); + hostname = httpGetHostname(con->http, NULL, 0); } else { @@ -278,13 +232,13 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ */ if (HostNameLookups) - hostname = httpAddrLookup(con->http->hostaddr, con->http->hostname, - sizeof(con->http->hostname)); + hostname = httpAddrLookup(httpGetAddress(con->http), httpGetHostname(con->http, NULL, 0), + sizeof(httpGetHostname(con->http, NULL, 0))); else { hostname = NULL; - httpAddrString(con->http->hostaddr, con->http->hostname, - sizeof(con->http->hostname)); + httpAddrString(httpGetAddress(con->http), httpGetHostname(con->http, NULL, 0), + sizeof(httpGetHostname(con->http, NULL, 0))); } } @@ -298,7 +252,7 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ cupsdLogClient(con, CUPSD_LOG_WARN, "Name lookup failed - connection from %s closed!", - con->http->hostname); + httpGetHostname(con->http, NULL, 0)); free(con); return; @@ -310,7 +264,7 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ * Do double lookups as needed... */ - if ((addrlist = httpAddrGetList(con->http->hostname, AF_UNSPEC, NULL)) + if ((addrlist = httpAddrGetList(httpGetHostname(con->http, NULL, 0), AF_UNSPEC, NULL)) != NULL) { /* @@ -318,7 +272,7 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ */ for (addr = addrlist; addr; addr = addr->next) - if (httpAddrEqual(con->http->hostaddr, &(addr->addr))) + if (httpAddrEqual(httpGetAddress(con->http), &(addr->addr))) break; } else @@ -337,7 +291,7 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ cupsdLogClient(con, CUPSD_LOG_WARN, "IP lookup failed - connection from %s closed!", - con->http->hostname); + httpGetHostname(con->http, NULL, 0)); free(con); return; } @@ -359,14 +313,14 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ cupsdLogClient(con, CUPSD_LOG_WARN, "Connection from %s refused by /etc/hosts.allow and " - "/etc/hosts.deny rules.", con->http->hostname); + "/etc/hosts.deny rules.", httpGetHostname(con->http, NULL, 0)); free(con); return; } #endif /* HAVE_TCPD_H */ #ifdef AF_LOCAL - if (httpGetAddress(con->http)->addr.sa_family == AF_LOCAL) + if (httpAddrFamily(httpGetAddress(con->http)) == AF_LOCAL) { # ifdef __APPLE__ socklen_t peersize; /* Size of peer credentials */ @@ -380,23 +334,24 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ if (!proc_name(peerpid, peername, sizeof(peername))) cupsdLogClient(con, CUPSD_LOG_DEBUG, "Accepted from %s (Domain ???[%d])", - con->http->hostname, (int)peerpid); + httpGetHostname(con->http, NULL, 0), (int)peerpid); else cupsdLogClient(con, CUPSD_LOG_DEBUG, "Accepted from %s (Domain %s[%d])", - con->http->hostname, name, (int)peerpid); + httpGetHostname(con->http, NULL, 0), name, (int)peerpid); } else # endif /* __APPLE__ */ cupsdLogClient(con, CUPSD_LOG_DEBUG, "Accepted from %s (Domain)", - con->http->hostname); + httpGetHostname(con->http, NULL, 0)); } else #endif /* AF_LOCAL */ cupsdLogClient(con, CUPSD_LOG_DEBUG, "Accepted from %s:%d (IPv%d)", - con->http->hostname, httpAddrPort(con->http->hostaddr), - _httpAddrFamily(con->http->hostaddr) == AF_INET ? 4 : 6); + httpGetHostname(con->http, NULL, 0), + httpAddrPort(httpGetAddress(con->http)), + httpAddrFamily(httpGetAddress(con->http)) == AF_INET ? 4 : 6); /* * Get the local address the client connected to... @@ -412,7 +367,7 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ con->serverport = LocalPort; } #ifdef AF_LOCAL - else if (_httpAddrFamily(&temp) == AF_LOCAL) + else if (httpAddrFamily(&temp) == AF_LOCAL) { strlcpy(con->servername, "localhost", sizeof(con->servername)); con->serverport = LocalPort; @@ -457,14 +412,12 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ * See if we are connecting on a secure port... */ - if (lis->encryption == HTTP_ENCRYPT_ALWAYS) + if (lis->encryption == HTTP_ENCRYPTION_ALWAYS) { /* * https connection; go secure... */ - con->http->encryption = HTTP_ENCRYPT_ALWAYS; - if (!cupsdStartTLS(con)) cupsdCloseClient(con); } @@ -519,19 +472,6 @@ cupsdCloseClient(cupsd_client_t *con) /* I - Client to close */ partial = 0; -#ifdef HAVE_SSL - /* - * Shutdown encryption as needed... - */ - - if (con->http->tls) - { - partial = 1; - - cupsdEndTLS(con); - } -#endif /* HAVE_SSL */ - if (con->pipe_pid != 0) { /* @@ -559,13 +499,22 @@ cupsdCloseClient(cupsd_client_t *con) /* I - Client to close */ cupsArrayRemove(ActiveClients, con); cupsdSetBusyState(); +#ifdef HAVE_SSL + /* + * Shutdown encryption as needed... + */ + + if (httpIsEncrypted(con->http)) + partial = 1; +#endif /* HAVE_SSL */ + if (partial) { /* * Only do a partial close so that the encrypted client gets everything. */ - shutdown(httpGetFd(con->http), 0); + httpShutdown(con->http); cupsdAddSelect(httpGetFd(con->http), (cupsd_selfunc_t)cupsdReadClient, NULL, con); @@ -589,6 +538,8 @@ cupsdCloseClient(cupsd_client_t *con) /* I - Client to close */ * Free memory... */ + cupsdRemoveSelect(httpGetFd(con->http)); + httpClose(con->http); cupsdClearString(&con->filename); @@ -683,7 +634,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ static unsigned request_id = 0; /* Request ID for temp files */ - status = HTTP_CONTINUE; + status = HTTP_STATUS_CONTINUE; cupsdLogClient(con, CUPSD_LOG_DEBUG2, "cupsdReadClient " @@ -694,11 +645,10 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ "data_remaining=" CUPS_LLFMT ", " "request=%p(%s), " "file=%d", - con->http->error, con->http->used, - http_states[con->http->state + 1], - con->http->data_encoding == HTTP_ENCODING_CHUNKED ? - "CHUNKED" : "LENGTH", - CUPS_LLCAST con->http->data_remaining, + httpError(con->http), (int)httpGetReady(con->http), + httpStateString(httpGetState(con->http)), + httpIsChunked(con->http) ? "CHUNKED" : "LENGTH", + CUPS_LLCAST httpGetRemaining(con->http), con->request, con->request ? ipp_states[con->request->state] : "", con->file); @@ -731,7 +681,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } #endif /* HAVE_SSL */ - switch (con->http->state) + switch (httpGetState(con->http)) { case HTTP_STATE_WAITING : /* @@ -740,10 +690,10 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (httpGets(line, sizeof(line) - 1, con->http) == NULL) { - if (con->http->error && con->http->error != EPIPE) + if (httpError(con->http) && httpError(con->http) != EPIPE) cupsdLogClient(con, CUPSD_LOG_DEBUG, "HTTP_STATE_WAITING Closing for error %d (%s)", - con->http->error, strerror(con->http->error)); + httpError(con->http), strerror(httpError(con->http))); else cupsdLogClient(con, CUPSD_LOG_DEBUG, "HTTP_STATE_WAITING Closing on EOF."); @@ -766,8 +716,8 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ httpClearFields(con->http); con->http->activity = time(NULL); - con->http->version = HTTP_1_0; - con->http->keep_alive = HTTP_KEEPALIVE_OFF; + con->http->version = HTTP_VERSION_1_0; + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); con->http->data_encoding = HTTP_ENCODING_LENGTH; con->http->data_remaining = 0; con->http->_data_remaining = 0; @@ -819,13 +769,13 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogClient(con, CUPSD_LOG_ERROR, "Bad request line \"%s\" from %s.", _httpEncodeURI(buf, line, sizeof(buf)), - con->http->hostname); - cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE); + httpGetHostname(con->http, NULL, 0)); + cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE); cupsdCloseClient(con); } return; case 2 : - con->http->version = HTTP_0_9; + con->http->version = HTTP_VERSION_0_9; break; case 3 : if (sscanf(version, "HTTP/%d.%d", &major, &minor) != 2) @@ -833,8 +783,8 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogClient(con, CUPSD_LOG_ERROR, "Bad request line \"%s\" from %s.", _httpEncodeURI(buf, line, sizeof(buf)), - con->http->hostname); - cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE); + httpGetHostname(con->http, NULL, 0)); + cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE); cupsdCloseClient(con); return; } @@ -842,18 +792,18 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (major < 2) { con->http->version = (http_version_t)(major * 100 + minor); - if (con->http->version == HTTP_1_1 && KeepAlive) - con->http->keep_alive = HTTP_KEEPALIVE_ON; + if (con->http->version == HTTP_VERSION_1_1 && KeepAlive) + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_ON); else - con->http->keep_alive = HTTP_KEEPALIVE_OFF; + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); } else { cupsdLogClient(con, CUPSD_LOG_ERROR, "Unsupported request line \"%s\" from %s.", _httpEncodeURI(buf, line, sizeof(buf)), - con->http->hostname); - cupsdSendError(con, HTTP_NOT_SUPPORTED, CUPSD_AUTH_NONE); + httpGetHostname(con->http, NULL, 0)); + cupsdSendError(con, HTTP_STATUS_NOT_SUPPORTED, CUPSD_AUTH_NONE); cupsdCloseClient(con); return; } @@ -899,7 +849,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogClient(con, CUPSD_LOG_ERROR, "Bad URI \"%s\" in request.", con->uri); - cupsdSendError(con, HTTP_METHOD_NOT_ALLOWED, CUPSD_AUTH_NONE); + cupsdSendError(con, HTTP_STATUS_METHOD_NOT_ALLOWED, CUPSD_AUTH_NONE); cupsdCloseClient(con); return; } @@ -934,19 +884,19 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ { cupsdLogClient(con, CUPSD_LOG_ERROR, "Bad operation \"%s\".", operation); - cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE); + cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE); cupsdCloseClient(con); return; } gettimeofday(&(con->start), NULL); - con->operation = con->http->state; + con->operation = httpGetState(con->http); cupsdLogClient(con, CUPSD_LOG_DEBUG, "%s %s HTTP/%d.%d", operation, con->uri, con->http->version / 100, con->http->version % 100); - con->http->status = HTTP_OK; + con->http->status = HTTP_STATUS_OK; if (!cupsArrayFind(ActiveClients, con)) { @@ -965,28 +915,28 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Parse incoming parameters until the status changes... */ - while ((status = httpUpdate(con->http)) == HTTP_CONTINUE) - if (!data_ready(con)) + while ((status = httpUpdate(con->http)) == HTTP_STATUS_CONTINUE) + if (!httpGetReady(con->http)) break; - if (status != HTTP_OK && status != HTTP_CONTINUE) + if (status != HTTP_STATUS_OK && status != HTTP_STATUS_CONTINUE) { - if (con->http->error && con->http->error != EPIPE) + if (httpError(con->http) && httpError(con->http) != EPIPE) cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing for error %d (%s) while reading headers.", - con->http->error, strerror(con->http->error)); + httpError(con->http), strerror(httpError(con->http))); else cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing on EOF while reading headers."); - cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE); + cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE); cupsdCloseClient(con); return; } break; default : - if (!data_ready(con) && recv(httpGetFd(con->http), buf, 1, MSG_PEEK) < 1) + if (!httpGetReady(con->http) && recv(httpGetFd(con->http), buf, 1, MSG_PEEK) < 1) { /* * Connection closed... @@ -1003,24 +953,24 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Handle new transfers... */ - if (status == HTTP_OK) + if (status == HTTP_STATUS_OK) { - if (con->http->fields[HTTP_FIELD_ACCEPT_LANGUAGE][0]) + if (httpGetField(con->http, HTTP_FIELD_ACCEPT_LANGUAGE)[0]) { /* * Figure out the locale from the Accept-Language and Content-Type * fields... */ - if ((ptr = strchr(con->http->fields[HTTP_FIELD_ACCEPT_LANGUAGE], + if ((ptr = strchr(httpGetField(con->http, HTTP_FIELD_ACCEPT_LANGUAGE), ',')) != NULL) *ptr = '\0'; - if ((ptr = strchr(con->http->fields[HTTP_FIELD_ACCEPT_LANGUAGE], + if ((ptr = strchr(httpGetField(con->http, HTTP_FIELD_ACCEPT_LANGUAGE), ';')) != NULL) *ptr = '\0'; - if ((ptr = strstr(con->http->fields[HTTP_FIELD_CONTENT_TYPE], + if ((ptr = strstr(httpGetField(con->http, HTTP_FIELD_CONTENT_TYPE), "charset=")) != NULL) { /* @@ -1029,14 +979,14 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ */ snprintf(locale, sizeof(locale), "%s.%s", - con->http->fields[HTTP_FIELD_ACCEPT_LANGUAGE], ptr + 8); + httpGetField(con->http, HTTP_FIELD_ACCEPT_LANGUAGE), ptr + 8); if ((ptr = strchr(locale, ',')) != NULL) *ptr = '\0'; } else snprintf(locale, sizeof(locale), "%s.UTF-8", - con->http->fields[HTTP_FIELD_ACCEPT_LANGUAGE]); + httpGetField(con->http, HTTP_FIELD_ACCEPT_LANGUAGE)); con->language = cupsLangGet(locale); } @@ -1045,21 +995,21 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdAuthorize(con); - if (!_cups_strncasecmp(con->http->fields[HTTP_FIELD_CONNECTION], + if (!_cups_strncasecmp(httpGetField(con->http, HTTP_FIELD_CONNECTION), "Keep-Alive", 10) && KeepAlive) - con->http->keep_alive = HTTP_KEEPALIVE_ON; - else if (!_cups_strncasecmp(con->http->fields[HTTP_FIELD_CONNECTION], + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_ON); + else if (!_cups_strncasecmp(httpGetField(con->http, HTTP_FIELD_CONNECTION), "close", 5)) - con->http->keep_alive = HTTP_KEEPALIVE_OFF; + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); - if (!con->http->fields[HTTP_FIELD_HOST][0] && - con->http->version >= HTTP_1_1) + if (!httpGetField(con->http, HTTP_FIELD_HOST)[0] && + httpGetVersion(con->http) >= HTTP_VERSION_1_1) { /* * HTTP/1.1 and higher require the "Host:" field... */ - if (!cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE)) { cupsdLogClient(con, CUPSD_LOG_ERROR, "Missing Host: field in request."); cupsdCloseClient(con); @@ -1075,9 +1025,9 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogClient(con, CUPSD_LOG_ERROR, "Request from \"%s\" using invalid Host: field \"%s\".", - con->http->hostname, con->http->fields[HTTP_FIELD_HOST]); + httpGetHostname(con->http, NULL, 0), httpGetField(con->http, HTTP_FIELD_HOST)); - if (!cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1091,22 +1041,22 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (con->best && con->best->type != CUPSD_AUTH_NONE) { - if (!cupsdSendHeader(con, HTTP_UNAUTHORIZED, NULL, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_UNAUTHORIZED, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } } - if (!_cups_strcasecmp(con->http->fields[HTTP_FIELD_CONNECTION], "Upgrade") && - con->http->tls == NULL) + if (!_cups_strcasecmp(httpGetField(con->http, HTTP_FIELD_CONNECTION), "Upgrade") && + !httpIsEncrypted(con->http)) { #ifdef HAVE_SSL /* * Do encryption stuff... */ - if (!cupsdSendHeader(con, HTTP_SWITCHING_PROTOCOLS, NULL, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_SWITCHING_PROTOCOLS, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1137,7 +1087,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ #endif /* HAVE_SSL */ } - if (!cupsdSendHeader(con, HTTP_OK, NULL, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_OK, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1162,7 +1112,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogClient(con, CUPSD_LOG_ERROR, "Request for non-absolute resource \"%s\".", con->uri); - if (!cupsdSendError(con, HTTP_FORBIDDEN, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1170,7 +1120,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else { - if (!_cups_strcasecmp(con->http->fields[HTTP_FIELD_CONNECTION], + if (!_cups_strcasecmp(httpGetField(con->http, HTTP_FIELD_CONNECTION), "Upgrade") && con->http->tls == NULL) { #ifdef HAVE_SSL @@ -1178,7 +1128,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Do encryption stuff... */ - if (!cupsdSendHeader(con, HTTP_SWITCHING_PROTOCOLS, NULL, + if (!cupsdSendHeader(con, HTTP_STATUS_SWITCHING_PROTOCOLS, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); @@ -1210,7 +1160,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ #endif /* HAVE_SSL */ } - if ((status = cupsdIsAuthorized(con, NULL)) != HTTP_OK) + if ((status = cupsdIsAuthorized(con, NULL)) != HTTP_STATUS_OK) { cupsdSendError(con, status, CUPSD_AUTH_NONE); cupsdCloseClient(con); @@ -1220,13 +1170,13 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (con->http->expect && (con->operation == HTTP_STATE_POST || con->operation == HTTP_STATE_PUT)) { - if (con->http->expect == HTTP_CONTINUE) + if (con->http->expect == HTTP_STATUS_CONTINUE) { /* * Send 100-continue header... */ - if (!cupsdSendHeader(con, HTTP_CONTINUE, NULL, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_CONTINUE, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1238,7 +1188,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Send 417-expectation-failed header... */ - if (!cupsdSendHeader(con, HTTP_EXPECTATION_FAILED, NULL, + if (!cupsdSendHeader(con, HTTP_STATUS_EXPECTATION_FAILED, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); @@ -1256,7 +1206,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } } - switch (con->http->state) + switch (httpGetState(con->http)) { case HTTP_STATE_GET_SEND : if ((!strncmp(con->uri, "/ppd/", 5) || @@ -1310,7 +1260,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1368,7 +1318,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ snprintf(con->uri, sizeof(con->uri), "/icons/%s.png", p->name); else { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1383,7 +1333,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Web interface is disabled. Show an appropriate message... */ - if (!cupsdSendError(con, HTTP_WEBIF_DISABLED, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_CUPS_WEBIF_DISABLED, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1454,17 +1404,17 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (!cupsdSendCommand(con, con->command, con->options, 0)) { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } } else - cupsdLogRequest(con, HTTP_OK); + cupsdLogRequest(con, HTTP_STATUS_OK); - if (con->http->version <= HTTP_1_0) - con->http->keep_alive = HTTP_KEEPALIVE_OFF; + if (con->http->version <= HTTP_VERSION_1_0) + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); } else if ((!strncmp(con->uri, "/admin/conf/", 12) && (strchr(con->uri + 12, '/') || @@ -1481,7 +1431,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogClient(con, CUPSD_LOG_ERROR, "Request for subdirectory \"%s\"!", con->uri); - if (!cupsdSendError(con, HTTP_FORBIDDEN, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1498,7 +1448,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if ((filename = get_file(con, &filestats, buf, sizeof(buf))) == NULL) { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1518,23 +1468,23 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (!cupsdSendCommand(con, con->command, con->options, 0)) { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } } else - cupsdLogRequest(con, HTTP_OK); + cupsdLogRequest(con, HTTP_STATUS_OK); - if (con->http->version <= HTTP_1_0) - con->http->keep_alive = HTTP_KEEPALIVE_OFF; + if (con->http->version <= HTTP_VERSION_1_0) + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); break; } if (!check_if_modified(con, &filestats)) { - if (!cupsdSendError(con, HTTP_NOT_MODIFIED, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1547,7 +1497,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ else snprintf(line, sizeof(line), "%s/%s", type->super, type->type); - if (!write_file(con, HTTP_OK, filename, line, &filestats)) + if (!write_file(con, HTTP_STATUS_OK, filename, line, &filestats)) { cupsdCloseClient(con); return; @@ -1562,7 +1512,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * so check the length against any limits that are set... */ - if (con->http->fields[HTTP_FIELD_CONTENT_LENGTH][0] && + if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && MaxRequestSize > 0 && con->http->data_remaining > MaxRequestSize) { @@ -1570,7 +1520,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Request too large... */ - if (!cupsdSendError(con, HTTP_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1579,14 +1529,14 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ break; } else if (con->http->data_remaining < 0 || - (!con->http->fields[HTTP_FIELD_CONTENT_LENGTH][0] && + (!httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && con->http->data_encoding == HTTP_ENCODING_LENGTH)) { /* * Negative content lengths are invalid! */ - if (!cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1600,7 +1550,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * content-type field will be "application/ipp"... */ - if (!strcmp(con->http->fields[HTTP_FIELD_CONTENT_TYPE], + if (!strcmp(httpGetField(con->http, HTTP_FIELD_CONTENT_TYPE), "application/ipp")) con->request = ippNew(); else if (!WebInterface) @@ -1609,7 +1559,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Web interface is disabled. Show an appropriate message... */ - if (!cupsdSendError(con, HTTP_WEBIF_DISABLED, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_CUPS_WEBIF_DISABLED, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1677,8 +1627,8 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdSetString(&con->options, NULL); } - if (con->http->version <= HTTP_1_0) - con->http->keep_alive = HTTP_KEEPALIVE_OFF; + if (con->http->version <= HTTP_VERSION_1_0) + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); } else { @@ -1689,7 +1639,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if ((filename = get_file(con, &filestats, buf, sizeof(buf))) == NULL) { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1706,7 +1656,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Only POST to CGI's... */ - if (!cupsdSendError(con, HTTP_UNAUTHORIZED, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_UNAUTHORIZED, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1729,7 +1679,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogClient(con, CUPSD_LOG_ERROR, "Disallowed PUT request for \"%s\".", con->uri); - if (!cupsdSendError(con, HTTP_FORBIDDEN, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1743,7 +1693,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * so check the length against any limits that are set... */ - if (con->http->fields[HTTP_FIELD_CONTENT_LENGTH][0] && + if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && MaxRequestSize > 0 && con->http->data_remaining > MaxRequestSize) { @@ -1751,7 +1701,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Request too large... */ - if (!cupsdSendError(con, HTTP_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1765,7 +1715,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Negative content lengths are invalid! */ - if (!cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1788,7 +1738,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ "Unable to create request file \"%s\": %s", con->filename, strerror(errno)); - if (!cupsdSendError(con, HTTP_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1802,7 +1752,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ case HTTP_STATE_DELETE : case HTTP_STATE_TRACE : - cupsdSendError(con, HTTP_NOT_IMPLEMENTED, CUPSD_AUTH_NONE); + cupsdSendError(con, HTTP_STATUS_NOT_IMPLEMENTED, CUPSD_AUTH_NONE); cupsdCloseClient(con); return; @@ -1821,7 +1771,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ snprintf(con->uri, sizeof(con->uri), "/ppd/%s.ppd", p->name); else { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1844,7 +1794,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ snprintf(con->uri, sizeof(con->uri), "/icons/%s.png", p->name); else { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1855,7 +1805,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else if (!WebInterface) { - if (!cupsdSendHeader(con, HTTP_OK, NULL, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_OK, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1891,7 +1841,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * CGI output... */ - if (!cupsdSendHeader(con, HTTP_OK, "text/html", CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_OK, "text/html", CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1909,7 +1859,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ return; } - cupsdLogRequest(con, HTTP_OK); + cupsdLogRequest(con, HTTP_STATUS_OK); } else if ((!strncmp(con->uri, "/admin/conf/", 12) && (strchr(con->uri + 12, '/') || @@ -1926,7 +1876,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogClient(con, CUPSD_LOG_ERROR, "Request for subdirectory \"%s\".", con->uri); - if (!cupsdSendError(con, HTTP_FORBIDDEN, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1937,24 +1887,24 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ else if ((filename = get_file(con, &filestats, buf, sizeof(buf))) == NULL) { - if (!cupsdSendHeader(con, HTTP_NOT_FOUND, "text/html", + if (!cupsdSendHeader(con, HTTP_STATUS_NOT_FOUND, "text/html", CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } - cupsdLogRequest(con, HTTP_NOT_FOUND); + cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND); } else if (!check_if_modified(con, &filestats)) { - if (!cupsdSendError(con, HTTP_NOT_MODIFIED, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } - cupsdLogRequest(con, HTTP_NOT_MODIFIED); + cupsdLogRequest(con, HTTP_STATUS_NOT_MODIFIED); } else { @@ -1968,7 +1918,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ else snprintf(line, sizeof(line), "%s/%s", type->super, type->type); - if (!cupsdSendHeader(con, HTTP_OK, line, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_OK, line, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -1988,7 +1938,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ return; } - cupsdLogRequest(con, HTTP_OK); + cupsdLogRequest(con, HTTP_STATUS_OK); } if (httpPrintf(con->http, "\r\n") < 0) @@ -2018,17 +1968,17 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Handle any incoming data... */ - switch (con->http->state) + switch (httpGetState(con->http)) { case HTTP_STATE_PUT_RECV : do { if ((bytes = httpRead2(con->http, line, sizeof(line))) < 0) { - if (con->http->error && con->http->error != EPIPE) + if (httpError(con->http) && httpError(con->http) != EPIPE) cupsdLogClient(con, CUPSD_LOG_DEBUG, "HTTP_STATE_PUT_RECV Closing for error %d (%s)", - con->http->error, strerror(con->http->error)); + httpError(con->http), strerror(httpError(con->http))); else cupsdLogClient(con, CUPSD_LOG_DEBUG, "HTTP_STATE_PUT_RECV Closing on EOF."); @@ -2051,7 +2001,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ unlink(con->filename); cupsdClearString(&con->filename); - if (!cupsdSendError(con, HTTP_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -2059,9 +2009,9 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } } } - while (con->http->state == HTTP_STATE_PUT_RECV && data_ready(con)); + while (httpGetState(con->http) == HTTP_STATE_PUT_RECV && httpGetReady(con->http)); - if (con->http->state == HTTP_STATE_STATUS) + if (httpGetState(con->http) == HTTP_STATE_STATUS) { /* * End of file, see how big it is... @@ -2082,7 +2032,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ unlink(con->filename); cupsdClearString(&con->filename); - if (!cupsdSendError(con, HTTP_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -2116,25 +2066,25 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Grab any request data from the connection... */ - if ((ipp_state = ippRead(con->http, con->request)) == IPP_ERROR) + if ((ipp_state = ippRead(con->http, con->request)) == IPP_STATE_ERROR) { cupsdLogClient(con, CUPSD_LOG_ERROR, "IPP read error: %s", cupsLastErrorString()); - cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE); + cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE); cupsdCloseClient(con); return; } - else if (ipp_state != IPP_DATA) + else if (ipp_state != IPP_STATE_DATA) { - if (con->http->state == HTTP_STATE_POST_SEND) + if (httpGetState(con->http) == HTTP_STATE_POST_SEND) { - cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE); + cupsdSendError(con, HTTP_STATUS_BAD_REQUEST, CUPSD_AUTH_NONE); cupsdCloseClient(con); return; } - if (data_ready(con)) + if (httpGetReady(con->http)) continue; break; } @@ -2149,7 +2099,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } } - if (con->file < 0 && con->http->state != HTTP_STATE_POST_SEND) + if (con->file < 0 && httpGetState(con->http) != HTTP_STATE_POST_SEND) { /* * Create a file as needed for the request data... @@ -2165,7 +2115,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ "Unable to create request file \"%s\": %s", con->filename, strerror(errno)); - if (!cupsdSendError(con, HTTP_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -2177,16 +2127,16 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC); } - if (con->http->state != HTTP_STATE_POST_SEND) + if (httpGetState(con->http) != HTTP_STATE_POST_SEND) { if (!httpWait(con->http, 0)) return; else if ((bytes = httpRead2(con->http, line, sizeof(line))) < 0) { - if (con->http->error && con->http->error != EPIPE) + if (httpError(con->http) && httpError(con->http) != EPIPE) cupsdLogClient(con, CUPSD_LOG_DEBUG, "HTTP_STATE_POST_SEND Closing for error %d (%s)", - con->http->error, strerror(con->http->error)); + httpError(con->http), strerror(httpError(con->http))); else cupsdLogClient(con, CUPSD_LOG_DEBUG, "HTTP_STATE_POST_SEND Closing on EOF."); @@ -2209,7 +2159,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ unlink(con->filename); cupsdClearString(&con->filename); - if (!cupsdSendError(con, HTTP_REQUEST_TOO_LARGE, + if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); @@ -2217,21 +2167,21 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } } } - else if (con->http->state == HTTP_STATE_POST_RECV) + else if (httpGetState(con->http) == HTTP_STATE_POST_RECV) return; - else if (con->http->state != HTTP_STATE_POST_SEND) + else if (httpGetState(con->http) != HTTP_STATE_POST_SEND) { cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing on unexpected state %s.", - http_states[con->http->state + 1]); + httpStateString(httpGetState(con->http))); cupsdCloseClient(con); return; } } } - while (con->http->state == HTTP_STATE_POST_RECV && data_ready(con)); + while (httpGetState(con->http) == HTTP_STATE_POST_RECV && httpGetReady(con->http)); - if (con->http->state == HTTP_STATE_POST_SEND) + if (httpGetState(con->http) == HTTP_STATE_POST_SEND) { if (con->file >= 0) { @@ -2260,7 +2210,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ con->request = NULL; } - if (!cupsdSendError(con, HTTP_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -2280,14 +2230,14 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ { if (!cupsdSendCommand(con, con->command, con->options, 0)) { - if (!cupsdSendError(con, HTTP_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } } else - cupsdLogRequest(con, HTTP_OK); + cupsdLogRequest(con, HTTP_STATUS_OK); } } @@ -2310,9 +2260,9 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ break; /* Anti-compiler-warning-code */ } - if (con->http->state == HTTP_STATE_WAITING) + if (httpGetState(con->http) == HTTP_STATE_WAITING) { - if (!con->http->keep_alive) + if (!httpGetKeepAlive(con->http)) { cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing because Keep-Alive is disabled."); @@ -2403,12 +2353,12 @@ cupsdSendError(cupsd_client_t *con, /* I - Connection */ * server is configured... */ - if (code == HTTP_UNAUTHORIZED && - DefaultEncryption == HTTP_ENCRYPT_REQUIRED && - _cups_strcasecmp(con->http->hostname, "localhost") && - !con->http->tls) + if (code == HTTP_STATUS_UNAUTHORIZED && + DefaultEncryption == HTTP_ENCRYPTION_REQUIRED && + _cups_strcasecmp(httpGetHostname(con->http, NULL, 0), "localhost") && + !httpIsEncrypted(con->http)) { - code = HTTP_UPGRADE_REQUIRED; + code = HTTP_STATUS_UPGRADE_REQUIRED; } #endif /* HAVE_SSL */ @@ -2426,8 +2376,8 @@ cupsdSendError(cupsd_client_t *con, /* I - Connection */ * never disable it in that case. */ - if (code >= HTTP_BAD_REQUEST && con->http->auth_type != CUPSD_AUTH_NEGOTIATE) - con->http->keep_alive = HTTP_KEEPALIVE_OFF; + if (code >= HTTP_STATUS_BAD_REQUEST && con->type != CUPSD_AUTH_NEGOTIATE) + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); /* * Send an error message back to the client. If the error code is a @@ -2438,7 +2388,7 @@ cupsdSendError(cupsd_client_t *con, /* I - Connection */ return (0); #ifdef HAVE_SSL - if (code == HTTP_UPGRADE_REQUIRED) + if (code == HTTP_STATUS_UPGRADE_REQUIRED) if (httpPrintf(con->http, "Connection: Upgrade\r\n") < 0) return (0); @@ -2446,14 +2396,14 @@ cupsdSendError(cupsd_client_t *con, /* I - Connection */ return (0); #endif /* HAVE_SSL */ - if (con->http->version >= HTTP_1_1 && - con->http->keep_alive == HTTP_KEEPALIVE_OFF) + if (con->http->version >= HTTP_VERSION_1_1 && + httpGetKeepAlive(con->http) == HTTP_KEEPALIVE_OFF) { if (httpPrintf(con->http, "Connection: close\r\n") < 0) return (0); } - if (code >= HTTP_BAD_REQUEST) + if (code >= HTTP_STATUS_BAD_REQUEST) { /* * Send a human-readable error message. @@ -2467,13 +2417,13 @@ cupsdSendError(cupsd_client_t *con, /* I - Connection */ redirect[0] = '\0'; - if (code == HTTP_UNAUTHORIZED) + if (code == HTTP_STATUS_UNAUTHORIZED) text = _cupsLangString(con->language, _("Enter your username and password or the " "root username and password to access this " "page. If you are using Kerberos authentication, " "make sure you have a valid Kerberos ticket.")); - else if (code == HTTP_UPGRADE_REQUIRED) + else if (code == HTTP_STATUS_UPGRADE_REQUIRED) { text = urltext; @@ -2490,7 +2440,7 @@ cupsdSendError(cupsd_client_t *con, /* I - Connection */ "CONTENT=\"3;URL=https://%s:%d%s\">\n", con->servername, con->serverport, con->uri); } - else if (code == HTTP_WEBIF_DISABLED) + else if (code == HTTP_STATUS_CUPS_WEBIF_DISABLED) text = _cupsLangString(con->language, _("The web interface is currently disabled. Run " "\"cupsctl WebInterface=yes\" to enable it.")); @@ -2559,7 +2509,7 @@ cupsdSendHeader( * Send the HTTP status header... */ - if (code == HTTP_CONTINUE) + if (code == HTTP_STATUS_CONTINUE) { /* * 100-continue doesn't send any headers... @@ -2568,14 +2518,14 @@ cupsdSendHeader( return (httpPrintf(con->http, "HTTP/%d.%d 100 Continue\r\n\r\n", con->http->version / 100, con->http->version % 100) > 0); } - else if (code == HTTP_WEBIF_DISABLED) + else if (code == HTTP_STATUS_CUPS_WEBIF_DISABLED) { /* * Treat our special "web interface is disabled" status as "200 OK" for web * browsers. */ - code = HTTP_OK; + code = HTTP_STATUS_OK; } httpFlushWrite(con->http); @@ -2590,7 +2540,7 @@ cupsdSendHeader( if (ServerHeader) if (httpPrintf(con->http, "Server: %s\r\n", ServerHeader) < 0) return (0); - if (con->http->keep_alive && con->http->version >= HTTP_1_0) + if (httpGetKeepAlive(con->http) && con->http->version >= HTTP_VERSION_1_0) { if (httpPrintf(con->http, "Connection: Keep-Alive\r\n") < 0) return (0); @@ -2598,11 +2548,14 @@ cupsdSendHeader( KeepAliveTimeout) < 0) return (0); } - if (code == HTTP_METHOD_NOT_ALLOWED) + else if (httpPrintf(con->http, "Connection: close\r\n") < 0) + return (0); + + if (code == HTTP_STATUS_METHOD_NOT_ALLOWED) if (httpPrintf(con->http, "Allow: GET, HEAD, OPTIONS, POST, PUT\r\n") < 0) return (0); - if (code == HTTP_UNAUTHORIZED) + if (code == HTTP_STATUS_UNAUTHORIZED) { if (auth_type == CUPSD_AUTH_NONE) { @@ -2618,12 +2571,12 @@ cupsdSendHeader( strlcpy(auth_str, "Basic realm=\"CUPS\"", sizeof(auth_str)); else if (auth_type == CUPSD_AUTH_DIGEST) snprintf(auth_str, sizeof(auth_str), "Digest realm=\"CUPS\", nonce=\"%s\"", - con->http->hostname); + httpGetHostname(con->http, NULL, 0)); #ifdef HAVE_GSSAPI else if (auth_type == CUPSD_AUTH_NEGOTIATE) { # ifdef AF_LOCAL - if (_httpAddrFamily(con->http->hostaddr) == AF_LOCAL) + if (httpAddrFamily(httpGetAddress(con->http)) == AF_LOCAL) strlcpy(auth_str, "Basic realm=\"CUPS\"", sizeof(auth_str)); else # endif /* AF_LOCAL */ @@ -2632,7 +2585,7 @@ cupsdSendHeader( #endif /* HAVE_GSSAPI */ if (con->best && auth_type != CUPSD_AUTH_NEGOTIATE && - !_cups_strcasecmp(con->http->hostname, "localhost")) + !_cups_strcasecmp(httpGetHostname(con->http, NULL, 0), "localhost")) { /* * Add a "trc" (try root certification) parameter for local non-Kerberos @@ -2760,6 +2713,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ ipp_state_t ipp_state; /* IPP state value */ + cupsdLogClient(con, CUPSD_LOG_DEBUG, "con->http=%p", con->http); cupsdLogClient(con, CUPSD_LOG_DEBUG, "cupsdWriteClient " "error=%d, " @@ -2770,8 +2724,8 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ "response=%p(%s), " "pipe_pid=%d, " "file=%d", - con->http->error, con->http->used, - http_states[con->http->state + 1], + httpError(con->http), (int)httpGetReady(con->http), + httpStateString(httpGetState(con->http)), con->http->data_encoding == HTTP_ENCODING_CHUNKED ? "CHUNKED" : "LENGTH", CUPS_LLCAST con->http->data_remaining, @@ -2779,8 +2733,8 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ con->response ? ipp_states[con->response->state] : "", con->pipe_pid, con->file); - if (con->http->state != HTTP_STATE_GET_SEND && - con->http->state != HTTP_STATE_POST_SEND) + if (httpGetState(con->http) != HTTP_STATE_GET_SEND && + httpGetState(con->http) != HTTP_STATE_POST_SEND) { /* * If we get called in the wrong state, then something went wrong with the @@ -2788,7 +2742,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ */ cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing on unexpected HTTP state %s.", - http_states[con->http->state + 1]); + httpStateString(httpGetState(con->http))); cupsdCloseClient(con); return; } @@ -2816,7 +2770,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ con->file_ready = 0; } - if (con->response && con->response->state != IPP_DATA) + if (con->response && con->response->state != IPP_STATE_DATA) { int wused = con->http->wused; /* Previous write buffer use */ @@ -2854,7 +2808,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ cupsdLogClient(con, CUPSD_LOG_DEBUG, "bytes=%d, http_state=%d, data_remaining=" CUPS_LLFMT, - (int)bytes, con->http->state, + (int)bytes, httpGetState(con->http), CUPS_LLCAST con->http->data_remaining); } else if ((bytes = read(con->file, con->header + con->header_used, @@ -2893,7 +2847,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ if (!_cups_strncasecmp(con->header, "Location:", 9)) { - if (!cupsdSendHeader(con, HTTP_SEE_OTHER, NULL, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_SEE_OTHER, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -2912,7 +2866,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ } else { - if (!cupsdSendHeader(con, HTTP_OK, NULL, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_OK, NULL, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; @@ -2920,7 +2874,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ con->sent_header = 1; - if (con->http->version == HTTP_1_1) + if (con->http->version == HTTP_VERSION_1_1) { if (httpPrintf(con->http, "Transfer-Encoding: chunked\r\n") < 0) return; @@ -2956,7 +2910,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ return; } - if (con->http->version == HTTP_1_1) + if (con->http->version == HTTP_VERSION_1_1) con->http->data_encoding = HTTP_ENCODING_CHUNKED; } else @@ -2978,7 +2932,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ if (httpWrite2(con->http, con->header, con->header_used) < 0) { cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing for error %d (%s)", - con->http->error, strerror(con->http->error)); + httpError(con->http), strerror(httpError(con->http))); cupsdCloseClient(con); return; } @@ -2988,7 +2942,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ con->bytes += con->header_used; - if (con->http->state == HTTP_STATE_WAITING) + if (httpGetState(con->http) == HTTP_STATE_WAITING) bytes = 0; else bytes = con->header_used; @@ -2998,14 +2952,14 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ } if (bytes <= 0 || - (con->http->state != HTTP_STATE_GET_SEND && - con->http->state != HTTP_STATE_POST_SEND)) + (httpGetState(con->http) != HTTP_STATE_GET_SEND && + httpGetState(con->http) != HTTP_STATE_POST_SEND)) { if (!con->sent_header && con->pipe_pid) - cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE); + cupsdSendError(con, HTTP_STATUS_SERVER_ERROR, CUPSD_AUTH_NONE); else { - cupsdLogRequest(con, HTTP_OK); + cupsdLogRequest(con, HTTP_STATUS_OK); httpFlushWrite(con->http); @@ -3015,7 +2969,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ if (httpWrite2(con->http, "", 0) < 0) { cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing for error %d (%s)", - con->http->error, strerror(con->http->error)); + httpError(con->http), strerror(httpError(con->http))); cupsdCloseClient(con); return; } @@ -3062,7 +3016,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ cupsdClearString(&con->options); cupsdClearString(&con->query_string); - if (!con->http->keep_alive) + if (!httpGetKeepAlive(con->http)) { cupsdLogClient(con, CUPSD_LOG_DEBUG, "Closing because Keep-Alive is disabled."); @@ -3089,14 +3043,14 @@ check_if_modified( cupsd_client_t *con, /* I - Client connection */ struct stat *filestats) /* I - File information */ { - char *ptr; /* Pointer into field */ + const char *ptr; /* Pointer into field */ time_t date; /* Time/date value */ off_t size; /* Size/length value */ size = 0; date = 0; - ptr = con->http->fields[HTTP_FIELD_IF_MODIFIED_SINCE]; + ptr = httpGetField(con->http, HTTP_FIELD_IF_MODIFIED_SINCE); if (*ptr == '\0') return (1); @@ -3156,37 +3110,6 @@ compare_clients(cupsd_client_t *a, /* I - First client */ } -/* - * 'data_ready()' - Check whether data is available from a client. - */ - -static int /* O - 1 if data is ready, 0 otherwise */ -data_ready(cupsd_client_t *con) /* I - Client */ -{ - if (con->http->used > 0) - return (1); -#ifdef HAVE_SSL - else if (con->http->tls) - { -# ifdef HAVE_LIBSSL - if (SSL_pending((SSL *)(con->http->tls))) - return (1); -# elif defined(HAVE_GNUTLS) - if (gnutls_record_check_pending(con->http->tls)) - return (1); -# elif defined(HAVE_CDSASSL) - size_t bytes; /* Bytes that are available */ - - if (!SSLGetBufferedReadSize(con->http->tls, &bytes) && bytes > 0) - return (1); -# endif /* HAVE_LIBSSL */ - } -#endif /* HAVE_SSL */ - - return (0); -} - - /* * 'get_file()' - Get a filename and state info. */ @@ -3403,7 +3326,7 @@ install_cupsd_conf(cupsd_client_t *con) /* I - Connection */ { cupsdLogClient(con, CUPSD_LOG_ERROR, "Unable to open request file \"%s\": %s", con->filename, strerror(errno)); - return (HTTP_SERVER_ERROR); + return (HTTP_STATUS_SERVER_ERROR); } /* @@ -3413,7 +3336,7 @@ install_cupsd_conf(cupsd_client_t *con) /* I - Connection */ if ((out = cupsdCreateConfFile(ConfigurationFile, ConfigFilePerm)) == NULL) { cupsFileClose(in); - return (HTTP_SERVER_ERROR); + return (HTTP_STATUS_SERVER_ERROR); } cupsdLogClient(con, CUPSD_LOG_INFO, "Installing config file \"%s\"...", @@ -3436,7 +3359,7 @@ install_cupsd_conf(cupsd_client_t *con) /* I - Connection */ snprintf(filename, sizeof(filename), "%s.N", ConfigurationFile); cupsdUnlinkOrRemoveFile(filename); - return (HTTP_SERVER_ERROR); + return (HTTP_STATUS_SERVER_ERROR); } /* @@ -3446,7 +3369,7 @@ install_cupsd_conf(cupsd_client_t *con) /* I - Connection */ cupsFileClose(in); if (cupsdCloseCreatedConfFile(out, ConfigurationFile)) - return (HTTP_SERVER_ERROR); + return (HTTP_STATUS_SERVER_ERROR); /* * Remove the request file... @@ -3466,7 +3389,7 @@ install_cupsd_conf(cupsd_client_t *con) /* I - Connection */ * Return that the file was created successfully... */ - return (HTTP_CREATED); + return (HTTP_STATUS_CREATED); } @@ -3877,11 +3800,11 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */ strlcpy(lang, "LANG=C", sizeof(lang)); strlcpy(remote_addr, "REMOTE_ADDR=", sizeof(remote_addr)); - httpAddrString(con->http->hostaddr, remote_addr + 12, + httpAddrString(httpGetAddress(con->http), remote_addr + 12, sizeof(remote_addr) - 12); snprintf(remote_host, sizeof(remote_host), "REMOTE_HOST=%s", - con->http->hostname); + httpGetHostname(con->http, NULL, 0)); snprintf(script_name, sizeof(script_name), "SCRIPT_NAME=%s", con->uri); if ((uriptr = strchr(script_name, '?')) != NULL) @@ -3892,12 +3815,12 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */ sprintf(server_port, "SERVER_PORT=%d", con->serverport); - if (con->http->fields[HTTP_FIELD_HOST][0]) + if (httpGetField(con->http, HTTP_FIELD_HOST)[0]) { char *nameptr; /* Pointer to ":port" */ snprintf(server_name, sizeof(server_name), "SERVER_NAME=%s", - con->http->fields[HTTP_FIELD_HOST]); + httpGetField(con->http, HTTP_FIELD_HOST)); if ((nameptr = strrchr(server_name, ':')) != NULL && !strchr(nameptr, ']')) *nameptr = '\0'; /* Strip trailing ":port" */ } @@ -3930,9 +3853,9 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */ envp[envc ++] = remote_user; } - if (con->http->version == HTTP_1_1) + if (con->http->version == HTTP_VERSION_1_1) envp[envc ++] = "SERVER_PROTOCOL=HTTP/1.1"; - else if (con->http->version == HTTP_1_0) + else if (con->http->version == HTTP_VERSION_1_0) envp[envc ++] = "SERVER_PROTOCOL=HTTP/1.0"; else envp[envc ++] = "SERVER_PROTOCOL=HTTP/0.9"; @@ -3944,17 +3867,17 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */ envp[envc ++] = http_cookie; } - if (con->http->fields[HTTP_FIELD_USER_AGENT][0]) + if (httpGetField(con->http, HTTP_FIELD_USER_AGENT)[0]) { snprintf(http_user_agent, sizeof(http_user_agent), "HTTP_USER_AGENT=%s", - con->http->fields[HTTP_FIELD_USER_AGENT]); + httpGetField(con->http, HTTP_FIELD_USER_AGENT)); envp[envc ++] = http_user_agent; } - if (con->http->fields[HTTP_FIELD_REFERER][0]) + if (httpGetField(con->http, HTTP_FIELD_REFERER)[0]) { snprintf(http_referer, sizeof(http_referer), "HTTP_REFERER=%s", - con->http->fields[HTTP_FIELD_REFERER]); + httpGetField(con->http, HTTP_FIELD_REFERER)); envp[envc ++] = http_referer; } @@ -3978,7 +3901,7 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */ sprintf(content_length, "CONTENT_LENGTH=" CUPS_LLFMT, CUPS_LLCAST con->bytes); snprintf(content_type, sizeof(content_type), "CONTENT_TYPE=%s", - con->http->fields[HTTP_FIELD_CONTENT_TYPE]); + httpGetField(con->http, HTTP_FIELD_CONTENT_TYPE)); envp[envc ++] = "REQUEST_METHOD=POST"; envp[envc ++] = content_length; @@ -4072,7 +3995,7 @@ valid_host(cupsd_client_t *con) /* I - Client connection */ * Copy the Host: header for later use... */ - strlcpy(con->clientname, con->http->fields[HTTP_FIELD_HOST], + strlcpy(con->clientname, httpGetField(con->http, HTTP_FIELD_HOST), sizeof(con->clientname)); if ((ptr = strrchr(con->clientname, ':')) != NULL && !strchr(ptr, ']')) { @@ -4086,7 +4009,7 @@ valid_host(cupsd_client_t *con) /* I - Client connection */ * Then validate... */ - if (httpAddrLocalhost(con->http->hostaddr)) + if (httpAddrLocalhost(httpGetAddress(con->http))) { /* * Only allow "localhost" or the equivalent IPv4 or IPv6 numerical diff --git a/scheduler/client.h b/scheduler/client.h index b604d47a1..ade341b92 100644 --- a/scheduler/client.h +++ b/scheduler/client.h @@ -1,16 +1,16 @@ /* * "$Id$" * - * Client definitions for the CUPS scheduler. + * Client definitions for the CUPS scheduler. * - * Copyright 2007-2011 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ #ifdef HAVE_AUTHORIZATION_H diff --git a/scheduler/conf.c b/scheduler/conf.c index fd1c0c027..a12793f7d 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -3035,7 +3035,7 @@ read_cupsd_conf(cups_file_t *fp) /* I - File to read from */ #endif /* AF_LOCAL */ cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv%d)", temp, httpAddrPort(&(lis->address)), - _httpAddrFamily(&(lis->address)) == AF_INET ? 4 : 6); + httpAddrFamily(&(lis->address)) == AF_INET ? 4 : 6); if (!httpAddrLocalhost(&(lis->address))) RemotePort = httpAddrPort(&(lis->address)); diff --git a/scheduler/ipp.c b/scheduler/ipp.c index e0340ebe1..635ebb268 100644 --- a/scheduler/ipp.c +++ b/scheduler/ipp.c @@ -1,102 +1,19 @@ /* * "$Id$" * - * IPP routines for the CUPS scheduler. + * IPP routines for the CUPS scheduler. * - * Copyright 2007-2013 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * This file contains Kerberos support code, copyright 2006 by - * Jelmer Vernooij. + * This file contains Kerberos support code, copyright 2006 by + * Jelmer Vernooij. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". - * - * Contents: - * - * cupsdProcessIPPRequest() - Process an incoming IPP request. - * cupsdTimeoutJob() - Timeout a job waiting on job files. - * accept_jobs() - Accept print jobs to a printer. - * add_class() - Add a class to the system. - * add_file() - Add a file to a job. - * add_job() - Add a job to a print queue. - * add_job_subscriptions() - Add any subscriptions for a job. - * add_job_uuid() - Add job-uuid attribute to a job. - * add_printer() - Add a printer to the system. - * add_printer_state_reasons() - Add the "printer-state-reasons" attribute - * based upon the printer state... - * add_queued_job_count() - Add the "queued-job-count" attribute for the - * specified printer or class. - * apply_printer_defaults() - Apply printer default options to a job. - * authenticate_job() - Set job authentication info. - * cancel_all_jobs() - Cancel all or selected print jobs. - * cancel_job() - Cancel a print job. - * cancel_subscription() - Cancel a subscription. - * check_rss_recipient() - Check that we do not have a duplicate RSS - * feed URI. - * check_quotas() - Check quotas for a printer and user. - * close_job() - Close a multi-file job. - * copy_attrs() - Copy attributes from one request to another. - * copy_banner() - Copy a banner file to the requests directory - * for the specified job. - * copy_file() - Copy a PPD file or interface script... - * copy_model() - Copy a PPD model file, substituting default - * values as needed... - * copy_job_attrs() - Copy job attributes. - * copy_printer_attrs() - Copy printer attributes. - * copy_subscription_attrs() - Copy subscription attributes. - * create_job() - Print a file to a printer or class. - * create_requested_array() - Create an array for the requested-attributes. - * create_subscription() - Create a notification subscription. - * delete_printer() - Remove a printer or class from the system. - * get_default() - Get the default destination. - * get_devices() - Get the list of available devices on the - * local system. - * get_document() - Get a copy of a job file. - * get_job_attrs() - Get job attributes. - * get_jobs() - Get a list of jobs for the specified printer. - * get_notifications() - Get events for a subscription. - * get_ppd() - Get a named PPD from the local system. - * get_ppds() - Get the list of PPD files on the local - * system. - * get_printer_attrs() - Get printer attributes. - * get_printer_supported() - Get printer supported values. - * get_printers() - Get a list of printers or classes. - * get_subscription_attrs() - Get subscription attributes. - * get_subscriptions() - Get subscriptions. - * get_username() - Get the username associated with a request. - * hold_job() - Hold a print job. - * hold_new_jobs() - Hold pending/new jobs on a printer or class. - * move_job() - Move a job to a new destination. - * ppd_parse_line() - Parse a PPD default line. - * print_job() - Print a file to a printer or class. - * read_job_ticket() - Read a job ticket embedded in a print file. - * reject_jobs() - Reject print jobs to a printer. - * release_held_new_jobs() - Release pending/new jobs on a printer or - * class. - * release_job() - Release a held print job. - * renew_subscription() - Renew an existing subscription... - * restart_job() - Restart an old print job. - * save_auth_info() - Save authentication information for a job. - * send_document() - Send a file to a printer or class. - * send_http_error() - Send a HTTP error back to the IPP client. - * send_ipp_status() - Send a status back to the IPP client. - * set_default() - Set the default destination... - * set_job_attrs() - Set job attributes. - * set_printer_attrs() - Set printer attributes. - * set_printer_defaults() - Set printer default options from a request. - * start_printer() - Start a printer. - * stop_printer() - Stop a printer. - * url_encode_attr() - URL-encode a string attribute. - * url_encode_string() - URL-encode a string. - * user_allowed() - See if a user is allowed to print to a queue. - * validate_job() - Validate printer options and destination. - * validate_name() - Make sure the printer name only contains - * valid chars. - * validate_user() - Validate the user for the request. + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ /* @@ -787,7 +704,7 @@ cupsdProcessIPPRequest( con->http->_data_remaining = INT_MAX; } - cupsdAddSelect(con->number, (cupsd_selfunc_t)cupsdReadClient, + cupsdAddSelect(httpGetFd(con->http), (cupsd_selfunc_t)cupsdReadClient, (cupsd_selfunc_t)cupsdWriteClient, con); /* diff --git a/scheduler/tls-darwin.c b/scheduler/tls-darwin.c index c78dc30a0..9d62498f5 100644 --- a/scheduler/tls-darwin.c +++ b/scheduler/tls-darwin.c @@ -64,6 +64,8 @@ cupsdStartTLS(cupsd_client_t *con) /* I - Client connection */ cupsdLogMessage(CUPSD_LOG_DEBUG, "[Client %d] Encrypting connection.", con->number); + con->http->encryption = HTTP_ENCRYPTION_ALWAYS; + con->http->tls_credentials = copy_cdsa_certificate(con); if (!con->http->tls_credentials)