Index: scheduler/dirsvc.c =================================================================== --- scheduler/dirsvc.c (revision 7724) +++ scheduler/dirsvc.c (revision 7725) @@ -793,7 +793,7 @@ int write_printcap; /* Write the printcap file? */ - if (!Browsing || !BrowseLocalProtocols || !Printers) + if (!Browsing || !Printers) return; /* @@ -807,7 +807,7 @@ * Figure out how many printers need an update... */ - if (BrowseInterval > 0) + if (BrowseInterval > 0 && BrowseLocalProtocols) { int max_count; /* Maximum number to update */ @@ -885,7 +885,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), write_printcap = 0; @@ -896,25 +896,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); - write_printcap = 1; - } + cupsArraySave(Printers); + cupsdDeletePrinter(p, 1); + cupsArrayRestore(Printers); + write_printcap = 1; } } @@ -1673,13 +1672,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... */ @@ -1688,9 +1697,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; } @@ -1698,8 +1705,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; } @@ -1760,6 +1766,7 @@ write_printcap = 0; hptr = strchr(host, '.'); sptr = strchr(ServerName, '.'); + is_class = type & CUPS_PRINTER_CLASS; if (!ServerNameIsIP && sptr != NULL && hptr != NULL) { @@ -1779,7 +1786,7 @@ } } - if (type & CUPS_PRINTER_CLASS) + if (is_class) { /* * Remote destination is a class... @@ -1790,208 +1797,137 @@ 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; - write_printcap = 1; + /* + * Force creation with long name... + */ + + 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; + write_printcap = 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... - */ + if (!p) + return; - 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->hostname) + { + /* + * Hostname not set, so this must be a cached remote printer + * that was created for a pending print job... + */ - 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... - */ - - 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); - - write_printcap = 1; - update = 1; - } + cupsdSetString(&p->hostname, host); + cupsdSetString(&p->uri, uri); + cupsdSetString(&p->device_uri, uri); + update = 1; } /* @@ -2055,7 +1991,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 @@ -2109,7 +2045,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 7724) +++ scheduler/printers.c (revision 7725) @@ -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) @@ -631,10 +633,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... @@ -1256,10 +1265,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... @@ -1287,10 +1303,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); + } } @@ -3372,7 +3395,8 @@ * super/type cost program */ - if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4) + if (sscanf(filter, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super, type, &cost, + program) != 4) { cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!", p->name, filter); Index: scheduler/main.c =================================================================== --- scheduler/main.c (revision 7724) +++ scheduler/main.c (revision 7725) @@ -910,7 +910,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 7724) +++ scheduler/classes.c (revision 7725) @@ -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); } }