]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/http-support.c
Update CREDITS.txt
[thirdparty/cups.git] / cups / http-support.c
index aae75e12d761ab44cb11c4ab88fd0c70b8f9c325..21776d70e18f4d0304ae57cf69e307de3a88f8cd 100644 (file)
@@ -1,9 +1,7 @@
 /*
- * "$Id$"
- *
  * HTTP support routines for CUPS.
  *
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  * These coded instructions, statements, and computer programs are the
@@ -152,7 +150,7 @@ static void http_resolve_cb(AvahiServiceResolver *resolver,
  * place of traditional string functions whenever you need to create a
  * URI string.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 http_uri_status_t                      /* O - URI status */
@@ -432,7 +430,7 @@ httpAssembleURI(
  * this function in place of traditional string functions whenever
  * you need to create a URI string.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 http_uri_status_t                      /* O - URI status */
@@ -492,7 +490,7 @@ httpAssembleURIf(
  *
  * The buffer needs to be at least 46 bytes in size.
  *
- * @since CUPS 1.7/OS X 10.9@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 char *                                 /* I - UUID string */
@@ -568,7 +566,7 @@ httpDecode64(char       *out,               /* I - String to write to */
 /*
  * 'httpDecode64_2()' - Base64-decode a string.
  *
- * @since CUPS 1.1.21/OS X 10.4@
+ * @since CUPS 1.1.21/macOS 10.4@
  */
 
 char *                                 /* O  - Decoded string */
@@ -687,7 +685,7 @@ httpEncode64(char       *out,               /* I - String to write to */
 /*
  * 'httpEncode64_2()' - Base64-encode a string.
  *
- * @since CUPS 1.1.21/OS X 10.4@
+ * @since CUPS 1.1.21/macOS 10.4@
  */
 
 char *                                 /* O - Encoded string */
@@ -796,7 +794,7 @@ httpGetDateString(time_t t)         /* I - UNIX time */
 /*
  * 'httpGetDateString2()' - Get a formatted date/time string from a time value.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 const char *                           /* O - Date/time string */
@@ -913,7 +911,7 @@ httpSeparate(const char *uri,               /* I - Universal Resource Identifier */
  *
  * This function is deprecated; use the httpSeparateURI() function instead.
  *
- * @since CUPS 1.1.21/OS X 10.4@
+ * @since CUPS 1.1.21/macOS 10.4@
  * @deprecated@
  */
 
@@ -938,7 +936,7 @@ httpSeparate2(const char *uri,              /* I - Universal Resource Identifier */
  * 'httpSeparateURI()' - Separate a Universal Resource Identifier into its
  *                       components.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 http_uri_status_t                      /* O - Result of separation */
@@ -1233,6 +1231,12 @@ httpSeparateURI(
 
       *port = (int)strtol(uri + 1, (char **)&uri, 10);
 
+      if (*port <= 0 || *port > 65535)
+      {
+        *port = 0;
+        return (HTTP_URI_STATUS_BAD_PORT);
+      }
+
       if (*uri != '/' && *uri)
       {
         *port = 0;
@@ -1574,9 +1578,7 @@ _httpResolveURI(
 #endif /* DEBUG */
 
 
-  DEBUG_printf(("4_httpResolveURI(uri=\"%s\", resolved_uri=%p, "
-                "resolved_size=" CUPS_LLFMT ")", uri, resolved_uri,
-               CUPS_LLCAST resolved_size));
+  DEBUG_printf(("_httpResolveURI(uri=\"%s\", resolved_uri=%p, resolved_size=" CUPS_LLFMT ", options=0x%x, cb=%p, context=%p)", uri, (void *)resolved_uri, CUPS_LLCAST resolved_size, options, (void *)cb, context));
 
  /*
   * Get the device URI...
@@ -1597,8 +1599,8 @@ _httpResolveURI(
     if (options & _HTTP_RESOLVE_STDERR)
       _cupsLangPrintFilter(stderr, "ERROR", _("Bad device-uri \"%s\"."), uri);
 
-    DEBUG_printf(("6_httpResolveURI: httpSeparateURI returned %d!", status));
-    DEBUG_puts("5_httpResolveURI: Returning NULL");
+    DEBUG_printf(("2_httpResolveURI: httpSeparateURI returned %d!", status));
+    DEBUG_puts("2_httpResolveURI: Returning NULL");
     return (NULL);
   }
 
@@ -1658,7 +1660,7 @@ _httpResolveURI(
 
     if (regtype <= hostname)
     {
-      DEBUG_puts("5_httpResolveURI: Bad hostname, returning NULL");
+      DEBUG_puts("2_httpResolveURI: Bad hostname, returning NULL");
       return (NULL);
     }
 
@@ -1687,7 +1689,7 @@ _httpResolveURI(
     uribuf.resource = resource;
     uribuf.uuid     = uuid;
 
-    DEBUG_printf(("6_httpResolveURI: Resolving hostname=\"%s\", regtype=\"%s\", "
+    DEBUG_printf(("2_httpResolveURI: Resolving hostname=\"%s\", regtype=\"%s\", "
                   "domain=\"%s\"\n", hostname, regtype, domain));
     if (options & _HTTP_RESOLVE_STDERR)
     {
@@ -1722,11 +1724,11 @@ _httpResolveURI(
        while (time(NULL) < end_time)
        {
          if (options & _HTTP_RESOLVE_STDERR)
-           _cupsLangPrintFilter(stderr, "INFO", _("Looking for printer..."));
+           _cupsLangPrintFilter(stderr, "INFO", _("Looking for printer."));
 
          if (cb && !(*cb)(context))
          {
-           DEBUG_puts("5_httpResolveURI: callback returned 0 (stop)");
+           DEBUG_puts("2_httpResolveURI: callback returned 0 (stop)");
            break;
          }
 
@@ -1762,7 +1764,7 @@ _httpResolveURI(
          {
            if (errno != EINTR && errno != EAGAIN)
            {
-             DEBUG_printf(("5_httpResolveURI: poll error: %s", strerror(errno)));
+             DEBUG_printf(("2_httpResolveURI: poll error: %s", strerror(errno)));
              break;
            }
          }
@@ -1958,7 +1960,7 @@ _httpResolveURI(
     uri = resolved_uri;
   }
 
-  DEBUG_printf(("5_httpResolveURI: Returning \"%s\"", uri));
+  DEBUG_printf(("2_httpResolveURI: Returning \"%s\"", uri));
 
   return (uri);
 }
@@ -2145,11 +2147,7 @@ http_resolve_cb(
   uint8_t              valueLen;       /* Length of value */
 
 
-  DEBUG_printf(("7http_resolve_cb(sdRef=%p, flags=%x, interfaceIndex=%u, "
-               "errorCode=%d, fullName=\"%s\", hostTarget=\"%s\", port=%u, "
-               "txtLen=%u, txtRecord=%p, context=%p)", sdRef, flags,
-               interfaceIndex, errorCode, fullName, hostTarget, port, txtLen,
-               txtRecord, context));
+  DEBUG_printf(("4http_resolve_cb(sdRef=%p, flags=%x, interfaceIndex=%u, errorCode=%d, fullName=\"%s\", hostTarget=\"%s\", port=%u, txtLen=%u, txtRecord=%p, context=%p)", (void *)sdRef, flags, interfaceIndex, errorCode, fullName, hostTarget, port, txtLen, (void *)txtRecord, context));
 
  /*
   * If we have a UUID, compare it...
@@ -2170,7 +2168,7 @@ http_resolve_cb(
        fprintf(stderr, "DEBUG: Found UUID %s, looking for %s.", uuid,
                uribuf->uuid);
 
-      DEBUG_printf(("7http_resolve_cb: Found UUID %s, looking for %s.", uuid,
+      DEBUG_printf(("5http_resolve_cb: Found UUID %s, looking for %s.", uuid,
                     uribuf->uuid));
       return;
     }
@@ -2260,7 +2258,7 @@ http_resolve_cb(
     http_addrlist_t    *addrlist,      /* List of addresses */
                        *addr;          /* Current address */
 
-    DEBUG_printf(("8http_resolve_cb: Looking up \"%s\".", hostTarget));
+    DEBUG_printf(("5http_resolve_cb: Looking up \"%s\".", hostTarget));
 
     snprintf(fqdn, sizeof(fqdn), "%d", ntohs(port));
     if ((addrlist = httpAddrGetList(hostTarget, AF_UNSPEC, fqdn)) != NULL)
@@ -2271,7 +2269,7 @@ http_resolve_cb(
 
         if (!error)
        {
-         DEBUG_printf(("8http_resolve_cb: Found \"%s\".", fqdn));
+         DEBUG_printf(("5http_resolve_cb: Found \"%s\".", fqdn));
 
          if ((hostptr = fqdn + strlen(fqdn) - 6) <= fqdn ||
              _cups_strcasecmp(hostptr, ".local"))
@@ -2282,7 +2280,7 @@ http_resolve_cb(
        }
 #ifdef DEBUG
        else
-         DEBUG_printf(("8http_resolve_cb: \"%s\" did not resolve: %d",
+         DEBUG_printf(("5http_resolve_cb: \"%s\" did not resolve: %d",
                        httpAddrString(&(addr->addr), fqdn, sizeof(fqdn)),
                        error));
 #endif /* DEBUG */
@@ -2302,7 +2300,7 @@ http_resolve_cb(
   else
     httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme, NULL, hostTarget, ntohs(port), resource);
 
-  DEBUG_printf(("8http_resolve_cb: Resolved URI is \"%s\"...", uribuf->buffer));
+  DEBUG_printf(("5http_resolve_cb: Resolved URI is \"%s\"...", uribuf->buffer));
 }
 
 #elif defined(HAVE_AVAHI)
@@ -2361,7 +2359,7 @@ http_resolve_cb(
   size_t               valueLen = 0;   /* Length of "rp" key */
 
 
-  DEBUG_printf(("7http_resolve_cb(resolver=%p, "
+  DEBUG_printf(("4http_resolve_cb(resolver=%p, "
                "interface=%d, protocol=%d, event=%d, name=\"%s\", "
                "type=\"%s\", domain=\"%s\", hostTarget=\"%s\", address=%p, "
                "port=%d, txt=%p, flags=%d, context=%p)",
@@ -2394,7 +2392,7 @@ http_resolve_cb(
        fprintf(stderr, "DEBUG: Found UUID %s, looking for %s.", uuid,
                uribuf->uuid);
 
-      DEBUG_printf(("7http_resolve_cb: Found UUID %s, looking for %s.", uuid,
+      DEBUG_printf(("5http_resolve_cb: Found UUID %s, looking for %s.", uuid,
                     uribuf->uuid));
       return;
     }
@@ -2498,7 +2496,7 @@ http_resolve_cb(
     http_addrlist_t    *addrlist,      /* List of addresses */
                        *addr;          /* Current address */
 
-    DEBUG_printf(("8http_resolve_cb: Looking up \"%s\".", hostTarget));
+    DEBUG_printf(("5http_resolve_cb: Looking up \"%s\".", hostTarget));
 
     snprintf(fqdn, sizeof(fqdn), "%d", ntohs(port));
     if ((addrlist = httpAddrGetList(hostTarget, AF_UNSPEC, fqdn)) != NULL)
@@ -2509,7 +2507,7 @@ http_resolve_cb(
 
         if (!error)
        {
-         DEBUG_printf(("8http_resolve_cb: Found \"%s\".", fqdn));
+         DEBUG_printf(("5http_resolve_cb: Found \"%s\".", fqdn));
 
          if ((hostptr = fqdn + strlen(fqdn) - 6) <= fqdn ||
              _cups_strcasecmp(hostptr, ".local"))
@@ -2520,7 +2518,7 @@ http_resolve_cb(
        }
 #ifdef DEBUG
        else
-         DEBUG_printf(("8http_resolve_cb: \"%s\" did not resolve: %d",
+         DEBUG_printf(("5http_resolve_cb: \"%s\" did not resolve: %d",
                        httpAddrString(&(addr->addr), fqdn, sizeof(fqdn)),
                        error));
 #endif /* DEBUG */
@@ -2534,15 +2532,10 @@ http_resolve_cb(
   * Assemble the final device URI using the resolved hostname...
   */
 
-  httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, uribuf->bufsize, scheme,
+  httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme,
                   NULL, hostTarget, port, resource);
-  DEBUG_printf(("8http_resolve_cb: Resolved URI is \"%s\".", uribuf->buffer));
+  DEBUG_printf(("5http_resolve_cb: Resolved URI is \"%s\".", uribuf->buffer));
 
   avahi_simple_poll_quit(uribuf->poll);
 }
 #endif /* HAVE_DNSSD */
-
-
-/*
- * End of "$Id$".
- */