Lines Matching +full:address +full:- +full:model
4 * Copyright © 2007-2014 by Apple Inc.
5 * Copyright © 2006-2007 by Easy Software Products, all rights reserved.
15 #include "backend-private.h"
18 #include <cups/http-private.h>
23 * This backend implements SNMP printer discovery. It uses a broadcast-
36 * Address ip-address
37 * Address @LOCAL
38 * Address @IF(name)
48 * Address @LOCAL
99 http_addr_t address; /* Address of device */ member
101 *uri, /* device-uri */
102 *id, /* device-id */
103 *info, /* device-info */
104 *location, /* device-location */
105 *make_and_model; /* device-make-and-model */
131 static void read_snmp_conf(const char *address);
149 static const int DescriptionOID[] = { CUPS_OID_hrDeviceDescr, 1, -1 };
150 static const int LocationOID[] = { CUPS_OID_sysLocation, 0, -1 };
151 static const int DeviceTypeOID[] = { CUPS_OID_hrDeviceType, 1, -1 };
152 static const int DeviceIdOID[] = { CUPS_OID_ppmPrinterIEEE1284DeviceId, 1, -1 };
153 static const int UriOID[] = { CUPS_OID_ppmPortServiceNameOrURI, 1, 1, -1 };
154 static const int LexmarkProductOID[] = { 1,3,6,1,4,1,641,2,1,2,1,2,1,-1 };
155 static const int LexmarkProductOID2[] = { 1,3,6,1,4,1,674,10898,100,2,1,2,1,2,1,-1 };
156 static const int LexmarkDeviceIdOID[] = { 1,3,6,1,4,1,641,2,1,2,1,3,1,-1 };
157 static const int HPDeviceIdOID[] = { 1,3,6,1,4,1,11,2,3,9,1,1,7,0,-1 };
158 static const int RicohDeviceIdOID[] = { 1,3,6,1,4,1,367,3,2,1,1,1,11,0,-1 };
159 static const int XeroxProductOID[] = { 1,3,6,1,4,1,128,2,1,3,1,2,0,-1 };
167 * 'main()' - Discover printers via SNMP.
170 int /* O - Exit status */
171 main(int argc, /* I - Number of command-line arguments (6 or 7) */ in main()
172 char *argv[]) /* I - Command-line arguments */ in main()
182 * Check command-line options... in main()
187 _cupsLangPuts(stderr, _("Usage: snmp [host-or-ip-address]")); in main()
225 ipv6 = -1; in main()
261 * 'add_array()' - Add a string to an array.
264 static char * /* O - New string */
265 add_array(cups_array_t *a, /* I - Array */ in add_array()
266 const char *s) /* I - String to add */ in add_array()
280 * 'add_cache()' - Add a cached device...
284 add_cache(http_addr_t *addr, /* I - Device IP address */ in add_cache()
285 const char *addrname, /* I - IP address or name string */ in add_cache()
286 const char *uri, /* I - Device URI */ in add_cache()
287 const char *id, /* I - 1284 device ID */ in add_cache()
288 const char *make_and_model) /* I - Make and model */ in add_cache()
299 memcpy(&(temp->address), addr, sizeof(temp->address)); in add_cache()
301 temp->addrname = strdup(addrname); in add_cache()
304 temp->uri = strdup(uri); in add_cache()
307 temp->id = strdup(id); in add_cache()
310 temp->make_and_model = strdup(make_and_model); in add_cache()
320 * 'add_device_uri()' - Add a device URI to the cache.
325 static device_uri_t * /* O - Device URI */
326 add_device_uri(char *value) /* I - Value from snmp.conf */ in add_device_uri()
345 if ((device_uri->uris = cupsArrayNew(NULL, NULL)) == NULL) in add_device_uri()
365 cupsArrayDelete(device_uri->uris); in add_device_uri()
373 if (regcomp(&(device_uri->re), start, REG_EXTENDED | REG_ICASE)) in add_device_uri()
377 cupsArrayDelete(device_uri->uris); in add_device_uri()
396 cupsArrayAdd(device_uri->uris, strdup(start)); in add_device_uri()
410 * 'alarm_handler()' - Handle alarm signals...
414 alarm_handler(int sig) /* I - Signal number */ in alarm_handler()
432 * 'compare_cache()' - Compare two cache entries.
435 static int /* O - Result of comparison */
436 compare_cache(snmp_cache_t *a, /* I - First cache entry */ in compare_cache()
437 snmp_cache_t *b) /* I - Second cache entry */ in compare_cache()
439 return (_cups_strcasecmp(a->addrname, b->addrname)); in compare_cache()
444 * 'debug_printf()' - Display some debugging information.
448 debug_printf(const char *format, /* I - Printf-style format string */ in debug_printf()
449 ...) /* I - Additional arguments as needed */ in debug_printf()
464 * 'fix_make_model()' - Fix common problems in the make-and-model string.
469 char *make_model, /* I - New make-and-model string */ in fix_make_model()
470 const char *old_make_model, /* I - Old make-and-model string */ in fix_make_model()
471 int make_model_size) /* I - Size of new string buffer */ in fix_make_model()
473 char *mmptr; /* Pointer into make-and-model string */ in fix_make_model()
477 * Fix some common problems with the make-and-model string so in fix_make_model()
481 if (!_cups_strncasecmp(old_make_model, "Hewlett-Packard", 15)) in fix_make_model()
484 * Strip leading Hewlett-Packard and hp prefixes and replace in fix_make_model()
504 strlcpy(make_model + 3, mmptr, (size_t)make_model_size - 3); in fix_make_model()
529 * Network LaserJet - 2.12" becomes "Xerox DocuPrint N2025"... in fix_make_model()
547 * 'free_array()' - Free an array of strings.
551 free_array(cups_array_t *a) /* I - Array */ in free_array()
564 * 'free_cache()' - Free the array of cached devices.
577 free(cache->addrname); in free_cache()
579 if (cache->uri) in free_cache()
580 free(cache->uri); in free_cache()
582 if (cache->id) in free_cache()
583 free(cache->id); in free_cache()
585 if (cache->make_and_model) in free_cache()
586 free(cache->make_and_model); in free_cache()
597 * 'get_interface_addresses()' - Get the broadcast address(es) associated
601 static http_addrlist_t * /* O - List of addresses */
603 const char *ifname) /* I - Interface name */ in get_interface_addresses()
605 struct ifaddrs *addrs, /* Interface address list */ in get_interface_addresses()
606 *addr; /* Current interface address */ in get_interface_addresses()
607 http_addrlist_t *first, /* First address in list */ in get_interface_addresses()
608 *last, /* Last address in list */ in get_interface_addresses()
609 *current; /* Current address */ in get_interface_addresses()
615 for (addr = addrs, first = NULL, last = NULL; addr; addr = addr->ifa_next) in get_interface_addresses()
616 if ((addr->ifa_flags & IFF_BROADCAST) && addr->ifa_broadaddr && in get_interface_addresses()
617 addr->ifa_broadaddr->sa_family == AF_INET && in get_interface_addresses()
618 (!ifname || !strcmp(ifname, addr->ifa_name))) in get_interface_addresses()
622 memcpy(&(current->addr), addr->ifa_broadaddr, in get_interface_addresses()
628 last->next = current; in get_interface_addresses()
640 * 'list_device()' - List a device we found...
644 list_device(snmp_cache_t *cache) /* I - Cached device */ in list_device()
646 if (cache->uri) in list_device()
647 cupsBackendReport("network", cache->uri, cache->make_and_model, in list_device()
648 cache->info, cache->id, cache->location); in list_device()
653 * 'password_cb()' - Handle authentication requests.
659 static const char * /* O - Password (NULL) */
660 password_cb(const char *prompt) /* I - Prompt message */ in password_cb()
662 (void)prompt; /* Anti-compiler-warning-code */ in password_cb()
669 * 'probe_device()' - Probe a device to discover whether it is a printer.
672 * to use - first need a commercially-available printer that supports
677 probe_device(snmp_cache_t *device) /* I - Device */ in probe_device()
685 debug_printf("DEBUG: %.3f Probing %s...\n", run_time(), device->addrname); in probe_device()
692 if (!try_connect(&(device->address), device->addrname, 5353)) in probe_device()
694 debug_printf("DEBUG: %s supports mDNS, not reporting!\n", device->addrname); in probe_device()
706 if (device->make_and_model && in probe_device()
707 !regexec(&(device_uri->re), device->make_and_model, 0, NULL, 0)) in probe_device()
713 for (format = (char *)cupsArrayFirst(device_uri->uris); in probe_device()
715 format = (char *)cupsArrayNext(device_uri->uris)) in probe_device()
717 for (uriptr = uri; *format && uriptr < (uri + sizeof(uri) - 1);) in probe_device()
721 * Insert hostname/address... in probe_device()
724 strlcpy(uriptr, device->addrname, sizeof(uri) - (size_t)(uriptr - uri)); in probe_device()
743 if (!try_connect(&(device->address), device->addrname, 9100)) in probe_device()
745 debug_printf("DEBUG: %s supports AppSocket!\n", device->addrname); in probe_device()
747 snprintf(uri, sizeof(uri), "socket://%s", device->addrname); in probe_device()
750 else if (!try_connect(&(device->address), device->addrname, 515)) in probe_device()
752 debug_printf("DEBUG: %s supports LPD!\n", device->addrname); in probe_device()
754 snprintf(uri, sizeof(uri), "lpd://%s/", device->addrname); in probe_device()
761 * 'read_snmp_conf()' - Read the snmp.conf file.
765 read_snmp_conf(const char *address) /* I - Single address to probe */ in read_snmp_conf() argument
778 * Initialize the global address and community lists... in read_snmp_conf()
784 if (address) in read_snmp_conf()
785 add_array(Addresses, address); in read_snmp_conf()
815 else if (!_cups_strcasecmp(line, "Address")) in read_snmp_conf()
817 if (!address) in read_snmp_conf()
859 "DEBUG: No address specified and no Address line in %s...\n", in read_snmp_conf()
873 * 'read_snmp_response()' - Read and parse a SNMP response...
877 read_snmp_response(int fd) /* I - SNMP socket file descriptor */ in read_snmp_response()
879 char addrname[256]; /* Source address name */ in read_snmp_response()
889 if (!_cupsSNMPRead(fd, &packet, -1.0)) in read_snmp_response()
897 httpAddrLookup(&(packet.address), addrname, sizeof(addrname)); in read_snmp_response()
899 httpAddrString(&(packet.address), addrname, sizeof(addrname)); in read_snmp_response()
916 debug_printf("DEBUG: request-id=%d\n", packet.request_id); in read_snmp_response()
917 debug_printf("DEBUG: error-status=%d\n", packet.error_status); in read_snmp_response()
951 add_cache(&(packet.address), addrname, NULL, NULL, NULL); in read_snmp_response()
953 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
956 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
959 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
962 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
965 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
968 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
971 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
974 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
977 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
980 _cupsSNMPWrite(fd, &(packet.address), CUPS_SNMP_VERSION_1, in read_snmp_response()
992 char make_model[256]; /* Make and model */ in read_snmp_response()
999 * Description is the IEEE-1284 device ID... in read_snmp_response()
1007 if (!device->id) in read_snmp_response()
1008 device->id = strdup((char *)packet.object_value.string.bytes); in read_snmp_response()
1013 if (device->info) in read_snmp_response()
1014 free(device->info); in read_snmp_response()
1016 device->info = strdup(make_model); in read_snmp_response()
1027 if (device->info) in read_snmp_response()
1028 free(device->info); in read_snmp_response()
1030 device->info = strdup((char *)packet.object_value.string.bytes); in read_snmp_response()
1033 if (!device->make_and_model) in read_snmp_response()
1034 device->make_and_model = strdup(make_model); in read_snmp_response()
1040 (!device->id || in read_snmp_response()
1041 strlen(device->id) < packet.object_value.string.num_bytes)) in read_snmp_response()
1047 char make_model[256]; /* Make and model */ in read_snmp_response()
1053 if (device->id) in read_snmp_response()
1054 free(device->id); in read_snmp_response()
1056 device->id = strdup((char *)packet.object_value.string.bytes); in read_snmp_response()
1059 * Convert the ID to a make and model string... in read_snmp_response()
1064 if (device->make_and_model) in read_snmp_response()
1065 free(device->make_and_model); in read_snmp_response()
1067 device->make_and_model = strdup(make_model); in read_snmp_response()
1073 !device->location) in read_snmp_response()
1074 device->location = strdup((char *)packet.object_value.string.bytes); in read_snmp_response()
1079 !device->id) in read_snmp_response()
1085 if (!device->info) in read_snmp_response()
1086 device->info = strdup((char *)packet.object_value.string.bytes); in read_snmp_response()
1088 if (device->make_and_model) in read_snmp_response()
1089 free(device->make_and_model); in read_snmp_response()
1091 device->make_and_model = strdup((char *)packet.object_value.string.bytes); in read_snmp_response()
1097 !device->uri && packet.object_value.string.num_bytes > 3) in read_snmp_response()
1124 device->uri = strdup((char *)packet.object_value.string.bytes); in read_snmp_response()
1132 * 'run_time()' - Return the total running time...
1135 static double /* O - Number of seconds */
1143 return (curtime.tv_sec - StartTime.tv_sec + in run_time()
1144 0.000001 * (curtime.tv_usec - StartTime.tv_usec)); in run_time()
1149 * 'scan_devices()' - Scan for devices using SNMP.
1153 scan_devices(int ipv4, /* I - SNMP IPv4 socket */ in scan_devices()
1154 int ipv6) /* I - SNMP IPv6 socket */ in scan_devices()
1156 int fd, /* File descriptor for this address */ in scan_devices()
1158 char *address, /* Current address */ in scan_devices() local
1164 *addr; /* Current address */ in scan_devices()
1166 char temp[1024]; /* Temporary address string */ in scan_devices()
1175 for (address = (char *)cupsArrayFirst(Addresses); in scan_devices()
1176 address; in scan_devices()
1177 address = (char *)cupsArrayNext(Addresses)) in scan_devices()
1179 if (!strcmp(address, "@LOCAL")) in scan_devices()
1181 else if (!strncmp(address, "@IF(", 4)) in scan_devices()
1185 strlcpy(ifname, address + 4, sizeof(ifname)); in scan_devices()
1187 ifname[strlen(ifname) - 1] = '\0'; in scan_devices()
1192 addrs = httpAddrGetList(address, AF_UNSPEC, NULL); in scan_devices()
1196 fprintf(stderr, "ERROR: Unable to scan \"%s\"!\n", address); in scan_devices()
1205 community, address); in scan_devices()
1207 for (addr = addrs; addr; addr = addr->next) in scan_devices()
1210 if (httpAddrFamily(&(addr->addr)) == AF_INET6) in scan_devices()
1217 httpAddrString(&(addr->addr), temp, sizeof(temp))); in scan_devices()
1219 _cupsSNMPWrite(fd, &(addr->addr), CUPS_SNMP_VERSION_1, community, in scan_devices()
1277 if (!device->sent && device->info && device->make_and_model) in scan_devices()
1279 if (device->uri) in scan_devices()
1284 device->sent = sent_something = 1; in scan_devices()
1297 * 'try_connect()' - Try connecting on a port...
1300 static int /* O - 0 on success or -1 on error */
1301 try_connect(http_addr_t *addr, /* I - Socket address */ in try_connect()
1302 const char *addrname, /* I - Hostname or IP address */ in try_connect()
1303 int port) /* I - Port number */ in try_connect()
1316 return (-1); in try_connect()
1333 * 'update_cache()' - Update a cached device...
1337 update_cache(snmp_cache_t *device, /* I - Device */ in update_cache()
1338 const char *uri, /* I - Device URI */ in update_cache()
1339 const char *id, /* I - Device ID */ in update_cache()
1340 const char *make_model) /* I - Device make and model */ in update_cache()
1342 if (device->uri) in update_cache()
1343 free(device->uri); in update_cache()
1345 device->uri = strdup(uri); in update_cache()
1349 if (device->id) in update_cache()
1350 free(device->id); in update_cache()
1352 device->id = strdup(id); in update_cache()
1357 if (device->make_and_model) in update_cache()
1358 free(device->make_and_model); in update_cache()
1360 device->make_and_model = strdup(make_model); in update_cache()