Index: scheduler/dirsvc.c =================================================================== --- scheduler/dirsvc.c (revision 7722) +++ scheduler/dirsvc.c (working copy) @@ -802,7 +802,7 @@ to; /* Timeout time */ - if (!Browsing || !BrowseLocalProtocols || !Printers) + if (!Browsing || !Printers) return; /* @@ -816,7 +816,7 @@ * Figure out how many printers need an update... */ - if (BrowseInterval > 0) + if (BrowseInterval > 0 && BrowseLocalProtocols) { int max_count; /* Maximum number to update */ @@ -894,7 +894,7 @@ } /* - * Loop through all of the printers and send local updates as needed... + * Loop through all of the printers and timeout old printers as needed... */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); @@ -905,25 +905,24 @@ * If this is a remote queue, see if it needs to be timed out... */ - if (p->type & CUPS_PRINTER_DISCOVERED) + if ((p->type & CUPS_PRINTER_DISCOVERED) && + !(p->type & CUPS_PRINTER_IMPLICIT) && + p->browse_expire < to) { - if (p->browse_expire < to) - { - cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL, - "%s \'%s\' deleted by directory services (timeout).", - (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", + cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL, + "%s \'%s\' deleted by directory services (timeout).", + (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", + p->name); + + cupsdLogMessage(CUPSD_LOG_DEBUG, + "Remote destination \"%s\" has timed out; " + "deleting it...", p->name); - cupsdLogMessage(CUPSD_LOG_DEBUG, - "Remote destination \"%s\" has timed out; " - "deleting it...", - p->name); - - cupsArraySave(Printers); - cupsdDeletePrinter(p, 1); - cupsArrayRestore(Printers); - cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE); - } + cupsArraySave(Printers); + cupsdDeletePrinter(p, 1); + cupsArrayRestore(Printers); + cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE); } } } @@ -2439,13 +2438,23 @@ newname[IPP_MAX_NAME], /* New name of printer */ *hptr, /* Pointer into hostname */ *sptr; /* Pointer into ServerName */ + const char *shortname; /* Short queue name (queue) */ char local_make_model[IPP_MAX_NAME]; /* Local make and model */ cupsd_printer_t *p; /* Printer information */ const char *ipp_options, /* ipp-options value */ *lease_duration; /* lease-duration value */ + int is_class; /* Is this queue a class? */ + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "process_browse_data(uri=\"%s\", host=\"%s\", " + "resource=\"%s\", type=%x, state=%d, location=\"%s\", " + "info=\"%s\", make_model=\"%s\", num_attrs=%d, attrs=%p)", + uri, host, resource, type, state, + location ? location : "(nil)", info ? info : "(nil)", + make_model ? make_model : "(nil)", num_attrs, attrs); + /* * Determine if the URI contains any illegal characters in it... */ @@ -2454,9 +2463,7 @@ (strncmp(resource, "/printers/", 10) && strncmp(resource, "/classes/", 9))) { - cupsdLogMessage(CUPSD_LOG_ERROR, - "process_browse_data: Bad printer URI in browse data: %s", - uri); + cupsdLogMessage(CUPSD_LOG_ERROR, "Bad printer URI in browse data: %s", uri); return; } @@ -2464,8 +2471,7 @@ (!strncmp(resource, "/printers/", 10) && strchr(resource + 10, '/')) || (!strncmp(resource, "/classes/", 9) && strchr(resource + 9, '/'))) { - cupsdLogMessage(CUPSD_LOG_ERROR, - "process_browse_data: Bad resource in browse data: %s", + cupsdLogMessage(CUPSD_LOG_ERROR, "Bad resource in browse data: %s", resource); return; } @@ -2520,11 +2526,12 @@ * See if we already have it listed in the Printers list, and add it if not... */ - type |= CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED; - type &= ~CUPS_PRINTER_IMPLICIT; - update = 0; - hptr = strchr(host, '.'); - sptr = strchr(ServerName, '.'); + type |= CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED; + type &= ~CUPS_PRINTER_IMPLICIT; + update = 0; + hptr = strchr(host, '.'); + sptr = strchr(ServerName, '.'); + is_class = type & CUPS_PRINTER_CLASS; if (!ServerNameIsIP && sptr != NULL && hptr != NULL) { @@ -2544,7 +2551,7 @@ } } - if (type & CUPS_PRINTER_CLASS) + if (is_class) { /* * Remote destination is a class... @@ -2555,210 +2562,140 @@ else return; - if (hptr && !*hptr) - *hptr = '.'; /* Resource FQDN */ + shortname = resource + 9; + } + else + { + /* + * Remote destination is a printer... + */ - if ((p = cupsdFindDest(name)) == NULL && BrowseShortNames) - { - if ((p = cupsdFindDest(resource + 9)) != NULL) - { - if (p->hostname && strcasecmp(p->hostname, host)) - { - /* - * Nope, this isn't the same host; if the hostname isn't the local host, - * add it to the other class and then find a class using the full host - * name... - */ + if (!strncmp(resource, "/printers/", 10)) + snprintf(name, sizeof(name), "%s@%s", resource + 10, host); + else + return; - if (p->type & CUPS_PRINTER_REMOTE) - { - cupsdLogMessage(CUPSD_LOG_DEBUG, - "Renamed remote class \"%s\" to \"%s@%s\"...", - p->name, p->name, p->hostname); - cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL, - "Class \'%s\' deleted by directory services.", - p->name); + shortname = resource + 10; + } - snprintf(newname, sizeof(newname), "%s@%s", p->name, p->hostname); - cupsdRenamePrinter(p, newname); + if (hptr && !*hptr) + *hptr = '.'; /* Resource FQDN */ - cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL, - "Class \'%s\' added by directory services.", - p->name); - } + if ((p = cupsdFindDest(name)) == NULL && BrowseShortNames) + { + /* + * Long name doesn't exist, try short name... + */ - p = NULL; - } - else if (!p->hostname) - { - /* - * Hostname not set, so this must be a cached remote printer - * that was created for a pending print job... - */ + cupsdLogMessage(CUPSD_LOG_DEBUG, "process_browse_data: %s not found...", + name); - cupsdSetString(&p->hostname, host); - cupsdSetString(&p->uri, uri); - cupsdSetString(&p->device_uri, uri); - update = 1; - } - } - else - { - /* - * Use the short name for this shared class. - */ - - strlcpy(name, resource + 9, sizeof(name)); - } - } - else if (p && !p->hostname) + if ((p = cupsdFindDest(shortname)) == NULL) { /* - * Hostname not set, so this must be a cached remote printer - * that was created for a pending print job... + * Short name doesn't exist, use it for this shared queue. */ - cupsdSetString(&p->hostname, host); - cupsdSetString(&p->uri, uri); - cupsdSetString(&p->device_uri, uri); - update = 1; + cupsdLogMessage(CUPSD_LOG_DEBUG2, "process_browse_data: %s not found...", + shortname); + strlcpy(name, shortname, sizeof(name)); } - - if (!p) + else { /* - * Class doesn't exist; add it... + * Short name exists... */ - p = cupsdAddClass(name); + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "process_browse_data: %s found, type=%x, hostname=%s...", + shortname, p->type, p->hostname ? p->hostname : "(nil)"); - cupsdLogMessage(CUPSD_LOG_DEBUG, "Added remote class \"%s\"...", name); + if (p->type & CUPS_PRINTER_IMPLICIT) + p = NULL; /* Don't replace implicit classes */ + else if (p->hostname && strcasecmp(p->hostname, host)) + { + /* + * Short name exists but is for a different host. If this is a remote + * queue, rename it and use the long name... + */ - cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL, - "Class \'%s\' added by directory services.", name); + if (p->type & CUPS_PRINTER_REMOTE) + { + cupsdLogMessage(CUPSD_LOG_DEBUG, + "Renamed remote %s \"%s\" to \"%s@%s\"...", + is_class ? "class" : "printer", p->name, p->name, + p->hostname); + cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL, + "%s \'%s\' deleted by directory services.", + is_class ? "Class" : "Printer", p->name); - /* - * Force the URI to point to the real server... - */ + snprintf(newname, sizeof(newname), "%s@%s", p->name, p->hostname); + cupsdRenamePrinter(p, newname); - p->type = type & ~CUPS_PRINTER_REJECTING; - p->accepting = 1; - cupsdSetString(&p->uri, uri); - cupsdSetString(&p->device_uri, uri); - cupsdSetString(&p->hostname, host); + cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL, + "%s \'%s\' added by directory services.", + is_class ? "Class" : "Printer", p->name); + } - update = 1; + /* + * Force creation with long name... + */ - cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE); + p = NULL; + } } } else + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "process_browse_data: %s found, type=%x, hostname=%s...", + name, p->type, p->hostname ? p->hostname : "(nil)"); + + if (!p) { /* - * Remote destination is a printer... + * Queue doesn't exist; add it... */ - if (!strncmp(resource, "/printers/", 10)) - snprintf(name, sizeof(name), "%s@%s", resource + 10, host); + if (is_class) + p = cupsdAddClass(name); else - return; + p = cupsdAddPrinter(name); - if (hptr && !*hptr) - *hptr = '.'; /* Resource FQDN */ + cupsdClearString(&(p->hostname)); - if ((p = cupsdFindDest(name)) == NULL && BrowseShortNames) - { - if ((p = cupsdFindDest(resource + 10)) != NULL) - { - if (p->hostname && strcasecmp(p->hostname, host)) - { - /* - * Nope, this isn't the same host; if the hostname isn't the local host, - * add it to the other printer and then find a printer using the full host - * name... - */ + cupsdLogMessage(CUPSD_LOG_DEBUG, "Added remote %s \"%s\"...", + is_class ? "class" : "printer", name); - if (p->type & CUPS_PRINTER_REMOTE) - { - cupsdLogMessage(CUPSD_LOG_DEBUG, - "Renamed remote printer \"%s\" to \"%s@%s\"...", - p->name, p->name, p->hostname); - cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL, - "Printer \'%s\' deleted by directory services.", - p->name); + cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL, + "%s \'%s\' added by directory services.", + is_class ? "Class" : "Printer", name); - snprintf(newname, sizeof(newname), "%s@%s", p->name, p->hostname); - cupsdRenamePrinter(p, newname); + /* + * Force the URI to point to the real server... + */ - cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL, - "Printer \'%s\' added by directory services.", - p->name); - } + p->type = type & ~CUPS_PRINTER_REJECTING; + p->accepting = 1; - p = NULL; - } - else if (!p->hostname) - { - /* - * Hostname not set, so this must be a cached remote printer - * that was created for a pending print job... - */ + cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); + } - cupsdSetString(&p->hostname, host); - cupsdSetString(&p->uri, uri); - cupsdSetString(&p->device_uri, uri); - update = 1; - } - } - else - { - /* - * Use the short name for this shared printer. - */ + if (!p) + return; - strlcpy(name, resource + 10, sizeof(name)); - } - } - else if (p && !p->hostname) - { - /* - * Hostname not set, so this must be a cached remote printer - * that was created for a pending print job... - */ + if (!p->hostname) + { + /* + * Hostname not set, so this must be a cached remote printer + * that was created for a pending print job... + */ - cupsdSetString(&p->hostname, host); - cupsdSetString(&p->uri, uri); - cupsdSetString(&p->device_uri, uri); - update = 1; - } + cupsdSetString(&p->hostname, host); + cupsdSetString(&p->uri, uri); + cupsdSetString(&p->device_uri, uri); + update = 1; - if (!p) - { - /* - * Printer doesn't exist; add it... - */ - - p = cupsdAddPrinter(name); - - cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL, - "Printer \'%s\' added by directory services.", name); - - cupsdLogMessage(CUPSD_LOG_DEBUG, "Added remote printer \"%s\"...", name); - - /* - * Force the URI to point to the real server... - */ - - p->type = type & ~CUPS_PRINTER_REJECTING; - p->accepting = 1; - cupsdSetString(&p->hostname, host); - cupsdSetString(&p->uri, uri); - cupsdSetString(&p->device_uri, uri); - - update = 1; - - cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP | CUPSD_DIRTY_REMOTE); - } + cupsdMarkDirty(CUPSD_DIRTY_REMOTE); } /* @@ -2823,7 +2760,7 @@ if (!make_model || !make_model[0]) { - if (type & CUPS_PRINTER_CLASS) + if (is_class) snprintf(local_make_model, sizeof(local_make_model), "Remote Class on %s", host); else @@ -2877,7 +2814,7 @@ { cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL, "%s \'%s\' deleted by directory services.", - (type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", p->name); + is_class ? "Class" : "Printer", p->name); cupsdExpireSubscriptions(p, NULL); Index: scheduler/printers.c =================================================================== --- scheduler/printers.c (revision 7723) +++ scheduler/printers.c (working copy) @@ -133,6 +133,8 @@ if (!Printers) Printers = cupsArrayNew(compare_printers, NULL); + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "cupsdAddPrinter: Adding %s to Printers", p->name); cupsArrayAdd(Printers, p); if (!ImplicitPrinters) @@ -640,10 +642,17 @@ * Remove the printer from the list... */ + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "cupsdDeletePrinter: Removing %s from Printers", p->name); cupsArrayRemove(Printers, p); if (p->type & CUPS_PRINTER_IMPLICIT) + { + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "cupsdDeletePrinter: Removing %s from ImplicitPrinters", + p->name); cupsArrayRemove(ImplicitPrinters, p); + } /* * Remove the dummy interface/icon/option files under IRIX... @@ -1285,10 +1294,17 @@ * Remove the printer from the array(s) first... */ + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "cupsdRenamePrinter: Removing %s from Printers", p->name); cupsArrayRemove(Printers, p); if (p->type & CUPS_PRINTER_IMPLICIT) + { + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "cupsdRenamePrinter: Removing %s from ImplicitPrinters", + p->name); cupsArrayRemove(ImplicitPrinters, p); + } /* * Rename the printer type... @@ -1316,10 +1332,17 @@ * Add the printer back to the printer array(s)... */ + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "cupsdRenamePrinter: Adding %s to Printers", p->name); cupsArrayAdd(Printers, p); if (p->type & CUPS_PRINTER_IMPLICIT) + { + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "cupsdRenamePrinter: Adding %s to ImplicitPrinters", + p->name); cupsArrayAdd(ImplicitPrinters, p); + } } Index: scheduler/main.c =================================================================== --- scheduler/main.c (revision 7722) +++ scheduler/main.c (working copy) @@ -941,7 +941,7 @@ #endif /* HAVE_LDAP */ } - if (Browsing && BrowseLocalProtocols && current_time > browse_time) + if (Browsing && current_time > browse_time) { cupsdSendBrowseList(); browse_time = current_time; Index: scheduler/classes.c =================================================================== --- scheduler/classes.c (revision 7722) +++ scheduler/classes.c (working copy) @@ -210,7 +210,8 @@ c = (cupsd_printer_t *)cupsArrayNext(ImplicitPrinters)) if (c->num_printers == 0) { - cupsArrayRemove(ImplicitPrinters, c); + cupsdLogMessage(CUPSD_LOG_DEBUG, "Deleting implicit class \"%s\"...", + c->name); cupsdDeletePrinter(c, 0); } }