]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/network.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / backend / network.c
index 4560fb03375509f48750e2ef148206c8035d7690..4414ce5e63ff5b5871d8f34bb4d0d4e224cea7d9 100644 (file)
@@ -1,9 +1,7 @@
 /*
- * "$Id$"
- *
  * Common backend network APIs for CUPS.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 2006-2007 by Easy Software Products, all rights reserved.
  *
  * These coded instructions, statements, and computer programs are the
@@ -11,8 +9,6 @@
  * 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/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
@@ -28,7 +24,6 @@
  * 'backendCheckSideChannel()' - Check the side-channel for pending requests.
  */
 
-
 void
 backendCheckSideChannel(
     int         snmp_fd,               /* I - SNMP socket */
@@ -48,6 +43,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.
  */
@@ -301,8 +355,3 @@ backendNetworkSideCB(
 
   return (cupsSideChannelWrite(command, status, data, datalen, 1.0));
 }
-
-
-/*
- * End of "$Id$".
- */