]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/http-addr.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cups / http-addr.c
index 0a49ee3e807a42f5c0e00358f0ae17a07636d46b..fc945989598760d20b38add8da6c16b2f73d67b8 100644 (file)
@@ -1,16 +1,10 @@
 /*
- * "$Id$"
- *
  * HTTP address routines for CUPS.
  *
  * Copyright 2007-2014 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/".
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -31,7 +25,7 @@
 /*
  * 'httpAddrAny()' - Check for the "any" address.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 int                                    /* O - 1 if "any", 0 otherwise */
@@ -58,11 +52,11 @@ httpAddrAny(const http_addr_t *addr)        /* I - Address to check */
  * 'httpAddrClose()' - Close a socket created by @link httpAddrConnect@ or
  *                     @link httpAddrListen@.
  *
- * Pass @code NULL@ for sockets created with @link httpAddrConnect@ and the
- * listen address for sockets created with @link httpAddrListen@. This will
- * ensure that domain sockets are removed when closed.
+ * Pass @code NULL@ for sockets created with @link httpAddrConnect2@ and the
+ * listen address for sockets created with @link httpAddrListen@.  This function
+ * ensures that domain sockets are removed when closed.
  *
- * @since CUPS 2.0@
+ * @since CUPS 2.0/OS 10.10@
  */
 
 int                                            /* O - 0 on success, -1 on failure */
@@ -88,7 +82,7 @@ httpAddrClose(http_addr_t *addr,              /* I - Listen address or @code NULL@ */
 /*
  * 'httpAddrEqual()' - Compare two addresses.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 int                                            /* O - 1 if equal, 0 if not */
@@ -121,7 +115,7 @@ httpAddrEqual(const http_addr_t *addr1,             /* I - First address */
 /*
  * 'httpAddrLength()' - Return the length of the address in bytes.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 int                                    /* O - Length in bytes */
@@ -152,7 +146,7 @@ httpAddrLength(const http_addr_t *addr)     /* I - Address */
  * 'httpAddrListen()' - Create a listening socket bound to the specified
  *                      address and port.
  *
- * @since CUPS 1.7/OS X 10.9@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 int                                    /* O - Socket or -1 on error */
@@ -278,7 +272,7 @@ httpAddrListen(http_addr_t *addr,   /* I - Address to bind to */
 /*
  * 'httpAddrLocalhost()' - Check for the local loopback address.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 int                                    /* O - 1 if local host, 0 otherwise */
@@ -310,7 +304,7 @@ httpAddrLocalhost(
 /*
  * 'httpAddrLookup()' - Lookup the hostname associated with the address.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 char *                                 /* O - Host name */
@@ -323,8 +317,7 @@ httpAddrLookup(
                                        /* Global data */
 
 
-  DEBUG_printf(("httpAddrLookup(addr=%p, name=%p, namelen=%d)", addr, name,
-               namelen));
+  DEBUG_printf(("httpAddrLookup(addr=%p, name=%p, namelen=%d)", (void *)addr, (void *)name, namelen));
 
  /*
   * Range check input...
@@ -450,7 +443,7 @@ httpAddrFamily(http_addr_t *addr)   /* I - Address */
 /*
  * 'httpAddrPort()' - Get the port number associated with an address.
  *
- * @since CUPS 1.7/OS X 10.9@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 int                                    /* O - Port number */
@@ -493,7 +486,7 @@ _httpAddrSetPort(http_addr_t *addr, /* I - Address */
 /*
  * 'httpAddrString()' - Convert an address to a numeric string.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 char *                                 /* O - Numeric address string */
@@ -501,7 +494,7 @@ httpAddrString(const http_addr_t *addr,     /* I - Address to convert */
                char              *s,   /* I - String buffer */
               int               slen)  /* I - Length of string */
 {
-  DEBUG_printf(("httpAddrString(addr=%p, s=%p, slen=%d)", addr, s, slen));
+  DEBUG_printf(("httpAddrString(addr=%p, s=%p, slen=%d)", (void *)addr, (void *)s, slen));
 
  /*
   * Range check input...
@@ -649,9 +642,13 @@ httpAddrString(const http_addr_t *addr,    /* I - Address to convert */
 /*
  * 'httpGetAddress()' - Get the address of the connected peer of a connection.
  *
+ * For connections created with @link httpConnect2@, the address is for the
+ * server.  For connections created with @link httpAccept@, the address is for
+ * the client.
+ *
  * Returns @code NULL@ if the socket is currently unconnected.
  *
- * @since CUPS 2.0@
+ * @since CUPS 2.0/OS 10.10@
  */
 
 http_addr_t *                          /* O - Connected address or @code NULL@ */
@@ -668,7 +665,7 @@ httpGetAddress(http_t *http)                /* I - HTTP connection */
  * 'httpGetHostByName()' - Lookup a hostname or IPv4 address, and return
  *                         address records for the specified name.
  *
- * @deprecated@
+ * @deprecated@ @exclude all@
  */
 
 struct hostent *                       /* O - Host entry */
@@ -782,7 +779,7 @@ httpGetHostByName(const char *name) /* I - Hostname or IP address */
  * Otherwise, return the FQDN for the local system using both gethostname()
  * and gethostbyname() to get the local hostname with domain.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 const char *                           /* O - FQDN for connection or system */
@@ -863,6 +860,25 @@ httpGetHostname(http_t *http,              /* I - HTTP connection or NULL */
       }
 #endif /* HAVE_SCDYNAMICSTORECOPYCOMPUTERNAME */
     }
+
+   /*
+    * Make sure .local hostnames end with a period...
+    */
+
+    if (strlen(s) > 6 && !strcmp(s + strlen(s) - 6, ".local"))
+      strlcat(s, ".", (size_t)slen);
+  }
+
+ /*
+  * Convert the hostname to lowercase as needed...
+  */
+
+  if (s[0] != '/')
+  {
+    char       *ptr;                   /* Pointer into string */
+
+    for (ptr = s; *ptr; ptr ++)
+      *ptr = (char)_cups_tolower((int)*ptr);
   }
 
  /*
@@ -877,7 +893,7 @@ httpGetHostname(http_t *http,               /* I - HTTP connection or NULL */
  * 'httpResolveHostname()' - Resolve the hostname of the HTTP connection
  *                           address.
  *
- * @since CUPS 2.0@
+ * @since CUPS 2.0/OS 10.10@
  */
 
 const char *                           /* O - Resolved hostname or @code NULL@ */
@@ -912,8 +928,3 @@ httpResolveHostname(http_t *http,   /* I - HTTP connection */
   else
     return (http->hostname);
 }
-
-
-/*
- * End of "$Id$".
- */