/*
- * "$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.
*/
/*
* 'backendCheckSideChannel()' - Check the side-channel for pending requests.
*/
-
void
backendCheckSideChannel(
int snmp_fd, /* I - SNMP socket */
}
+/*
+ * '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(¤t->addr, addrname, sizeof(addrname)));
+
+ /*
+ * Return...
+ */
+
+ return (addrlist);
+}
+
+
/*
* 'backendNetworkSideCB()' - Handle common network side-channel commands.
*/
{
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 :
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 :
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 :
return (cupsSideChannelWrite(command, status, data, datalen, 1.0));
}
-
-
-/*
- * End of "$Id$".
- */