]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/network.c
Update copyrights and license text on files that were missed.
[thirdparty/cups.git] / backend / network.c
index 62be7f399e6c82930cc1f1ad2908c84553f3759d..5af0a8eeadd07145f6c5b6eab74ee1d68ad2d890 100644 (file)
@@ -1,18 +1,11 @@
 /*
- * "$Id$"
- *
  * Common backend network APIs for CUPS.
  *
- * Copyright 2007-2014 by Apple Inc.
- * Copyright 2006-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"
- * "LICENSE" which should have been included with this file.  If this
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Copyright © 2007-2016 by Apple Inc.
+ * Copyright © 2006-2007 by Easy Software Products, all rights reserved.
  *
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
@@ -28,7 +21,6 @@
  * 'backendCheckSideChannel()' - Check the side-channel for pending requests.
  */
 
-
 void
 backendCheckSideChannel(
     int         snmp_fd,               /* I - SNMP socket */
@@ -48,6 +40,65 @@ backendCheckSideChannel(
 }
 
 
+/*
+ * 'backendLookup()' - Lookup the given host and log addresses.
+ */
+
+http_addrlist_t        *                       /* O - List of addresses or NULL */
+backendLookup(const char *hostname,    /* I - Hostname */
+              int        port,         /* I - Port number */
+             int        *cancel)       /* I - Variable to watch for job cancel */
+{
+  char                 portname[32],   /* Port number as string */
+                       addrname[256];  /* Address as string */
+  http_addrlist_t      *addrlist,      /* List of addresses */
+                       *current;       /* Current address */
+
+
+ /*
+  * Lookup the address for the named host...
+  */
+
+  snprintf(portname, sizeof(portname), "%d", port);
+
+  fputs("STATE: +connecting-to-device\n", stderr);
+  fprintf(stderr, "DEBUG: Looking up \"%s\"...\n", hostname);
+
+  while ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL)
+  {
+    _cupsLangPrintFilter(stderr, "INFO", _("Unable to locate printer \"%s\"."), hostname);
+    sleep(10);
+
+    if (getenv("CLASS") != NULL)
+    {
+      fputs("STATE: -connecting-to-device\n", stderr);
+      exit(CUPS_BACKEND_STOP);
+    }
+
+    if (cancel && *cancel)
+    {
+      fputs("STATE: -connecting-to-device\n", stderr);
+      exit(CUPS_BACKEND_OK);
+    }
+  }
+
+  fputs("STATE: -connecting-to-device\n", stderr);
+
+ /*
+  * Log the addresses we got...
+  */
+
+  for (current = addrlist; current; current = current->next)
+    fprintf(stderr, "DEBUG: %s=%s\n", hostname, httpAddrString(&current->addr, addrname, sizeof(addrname)));
+
+ /*
+  * Return...
+  */
+
+  return (addrlist);
+}
+
+
 /*
  * 'backendNetworkSideCB()' - Handle common network side-channel commands.
  */
@@ -175,13 +226,13 @@ backendNetworkSideCB(
              {
                case CUPS_ASN1_BOOLEAN :
                    snprintf(dataptr, sizeof(data) - (size_t)(dataptr - data), "%d", packet.object_value.boolean);
-                   datalen += strlen(dataptr);
+                   datalen += (int)strlen(dataptr);
                    break;
 
                case CUPS_ASN1_INTEGER :
                    snprintf(dataptr, sizeof(data) - (size_t)(dataptr - data), "%d",
                             packet.object_value.integer);
-                   datalen += strlen(dataptr);
+                   datalen += (int)strlen(dataptr);
                    break;
 
                case CUPS_ASN1_BIT_STRING :
@@ -193,13 +244,13 @@ backendNetworkSideCB(
 
                    memcpy(dataptr, packet.object_value.string.bytes, i);
 
-                    datalen += i;
+                    datalen += (int)i;
                    break;
 
                case CUPS_ASN1_OID :
                    _cupsSNMPOIDToString(packet.object_value.oid, dataptr,
                                         sizeof(data) - (size_t)(dataptr - data));
-                   datalen += strlen(dataptr);
+                   datalen += (int)strlen(dataptr);
                    break;
 
                 case CUPS_ASN1_HEX_STRING :
@@ -208,22 +259,22 @@ backendNetworkSideCB(
                             dataptr < (data + sizeof(data) - 3);
                         i ++, dataptr += 2)
                      sprintf(dataptr, "%02X", packet.object_value.string.bytes[i]);
-                   datalen += strlen(dataptr);
+                   datalen += (int)strlen(dataptr);
                    break;
 
                 case CUPS_ASN1_COUNTER :
                    snprintf(dataptr, sizeof(data) - (size_t)(dataptr - data), "%u", packet.object_value.counter);
-                   datalen += strlen(dataptr);
+                   datalen += (int)strlen(dataptr);
                    break;
 
                 case CUPS_ASN1_GAUGE :
                    snprintf(dataptr, sizeof(data) - (size_t)(dataptr - data), "%u", packet.object_value.gauge);
-                   datalen += strlen(dataptr);
+                   datalen += (int)strlen(dataptr);
                    break;
 
                 case CUPS_ASN1_TIMETICKS :
                    snprintf(dataptr, sizeof(data) - (size_t)(dataptr - data), "%u", packet.object_value.timeticks);
-                   datalen += strlen(dataptr);
+                   datalen += (int)strlen(dataptr);
                    break;
 
                 default :
@@ -301,8 +352,3 @@ backendNetworkSideCB(
 
   return (cupsSideChannelWrite(command, status, data, datalen, 1.0));
 }
-
-
-/*
- * End of "$Id$".
- */