/*
- * "$Id: dirsvc.c 5305 2006-03-18 03:05:12Z mike $"
+ * "$Id: dirsvc.c 5663 2006-06-15 20:36:42Z mike $"
*
* Directory services routines for the Common UNIX Printing System (CUPS).
*
* cupsdStopPolling() - Stop polling servers as needed.
* cupsdUpdateCUPSBrowse() - Update the browse lists using the CUPS
* protocol.
+ * cupsdUpdateLDAPBrowse() - Scan for new printers via LDAP...
* cupsdUpdatePolling() - Read status messages from the poll daemons.
* cupsdUpdateSLPBrowse() - Get browsing information via SLP.
* dequote() - Remote quotes from a string.
#ifdef HAVE_LDAP
static void send_ldap_browse(cupsd_printer_t *p);
#endif /* HAVE_LDAP */
+#ifdef HAVE_LIBSLP
static void send_slp_browse(cupsd_printer_t *p);
-
+#endif /* HAVE_LIBSLP */
#ifdef HAVE_OPENLDAP
static const char * const ldap_attrs[] =/* CUPS LDAP attributes */
* Announce the deletion...
*/
- if (BrowseLocalProtocols & BROWSE_CUPS)
+ if ((BrowseLocalProtocols & BROWSE_CUPS) && BrowseSocket >= 0)
send_cups_browse(p);
#ifdef HAVE_LIBSLP
- if (BrowseLocalProtocols & BROWSE_SLP)
+ if ((BrowseLocalProtocols & BROWSE_SLP) && BrowseSLPHandle)
slp_dereg_printer(p);
#endif /* HAVE_LIBSLP */
}
(p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
p->name);
- cupsdLogMessage(CUPSD_LOG_INFO,
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
"Remote destination \"%s\" has timed out; "
"deleting it...",
p->name);
BrowseSLPRefresh = 0;
}
+ else
+ BrowseSLPHandle = NULL;
#endif /* HAVE_LIBSLP */
#ifdef HAVE_OPENLDAP
}
#endif /* HAVE_LIBSLP */
-#ifdef HAVE_OPENDAP
+#ifdef HAVE_OPENLDAP
if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_LDAP) &&
BrowseLDAPHandle)
{
* Loop through the available printers...
*/
- if ((e = ldap_first_entry(BrowseLDAPHandle, res)) == NULL)
+ for (e = ldap_first_entry(BrowseLDAPHandle, res);
+ e;
+ e = ldap_next_entry(BrowseLDAPHandle, e))
{
- cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get LDAP printer entry!");
- return;
- }
+ /*
+ * Get the required values from this entry...
+ */
+
+ if ((value = ldap_get_values(BrowseLDAPHandle, e,
+ "printerDescription")) == NULL)
+ continue;
- while (e)
- {
- value = ldap_get_values(BrowseLDAPHandle, e, "printerDescription");
strlcpy(info, *value, sizeof(info));
ldap_value_free(value);
- value = ldap_get_values(BrowseLDAPHandle, e, "printerLocation");
+ if ((value = ldap_get_values(BrowseLDAPHandle, e,
+ "printerLocation")) == NULL)
+ continue;
+
strlcpy(location, *value, sizeof(location));
ldap_value_free(value);
- value = ldap_get_values(BrowseLDAPHandle, e, "printerMakeAndModel");
+ if ((value = ldap_get_values(BrowseLDAPHandle, e,
+ "printerMakeAndModel")) == NULL)
+ continue;
+
strlcpy(make_model, *value, sizeof(make_model));
ldap_value_free(value);
- value = ldap_get_values(BrowseLDAPHandle, e, "printerType");
+ if ((value = ldap_get_values(BrowseLDAPHandle, e,
+ "printerType")) == NULL)
+ continue;
+
type = atoi(*value);
ldap_value_free(value);
- value = ldap_get_values(BrowseLDAPHandle, e, "printerURI");
+ if ((value = ldap_get_values(BrowseLDAPHandle, e,
+ "printerURI")) == NULL)
+ continue;
+
strlcpy(uri, *value, sizeof(uri));
ldap_value_free(value);
+ /*
+ * Process the entry as browse data...
+ */
+
if (!is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
process_browse_data(uri, host, resource, type, IPP_PRINTER_IDLE,
location, info, make_model, 0, NULL);
- e = ldap_next_entry(BrowseLDAPHandle, e);
}
}
#endif /* HAVE_OPENLDAP */
if (p->type & CUPS_PRINTER_REMOTE)
{
- cupsdLogMessage(CUPSD_LOG_INFO,
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
"Renamed remote class \"%s\" to \"%s@%s\"...",
p->name, p->name, p->hostname);
cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
p = cupsdAddClass(name);
- cupsdLogMessage(CUPSD_LOG_INFO, "Added remote class \"%s\"...", name);
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Added remote class \"%s\"...", name);
cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
"Class \'%s\' added by directory services.", name);
if (p->type & CUPS_PRINTER_REMOTE)
{
- cupsdLogMessage(CUPSD_LOG_INFO,
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
"Renamed remote printer \"%s\" to \"%s@%s\"...",
p->name, p->name, p->hostname);
cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
"Printer \'%s\' added by directory services.", name);
- cupsdLogMessage(CUPSD_LOG_INFO, "Added remote printer \"%s\"...", name);
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Added remote printer \"%s\"...", name);
/*
* Force the URI to point to the real server...
update = 1;
- cupsdLogMessage(CUPSD_LOG_INFO, "Added implicit class \"%s\"...",
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Added implicit class \"%s\"...",
name);
cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
"Implicit class \'%s\' added by directory services.",
dequote(location, p->location, sizeof(location));
dequote(info, p->info, sizeof(info));
- dequote(make_model, p->make_model ? p->make_model : "Unknown",
- sizeof(make_model));
+
+ if (p->make_model)
+ dequote(make_model, p->make_model, sizeof(make_model));
+ else if (p->type & CUPS_PRINTER_CLASS)
+ {
+ if (p->num_printers > 0 && p->printers[0]->make_model)
+ strlcpy(make_model, p->printers[0]->make_model, sizeof(make_model));
+ else
+ strlcpy(make_model, "Local Printer Class", sizeof(make_model));
+ }
+ else if (p->raw)
+ strlcpy(make_model, "Local Raw Printer", sizeof(make_model));
+ else
+ strlcpy(make_model, "Local System V Printer", sizeof(make_model));
/*
* Send a packet to each browse address...
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
iface->hostname, iface->port,
- (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s%s" :
+ (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s" :
"/printers/%s",
p->name);
snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\" %s\n",
sprintf(typestring, "%u", p->type);
- cn_value[0] = p->info;
+ cn_value[0] = p->name;
cn_value[1] = NULL;
- info[0] = p->info;
+ info[0] = p->info ? p->info : "Unknown";
info[1] = NULL;
- location[0] = p->location;
+ location[0] = p->location ? p->location : "Unknown";
location[1] = NULL;
- make_model[0] = p->make_model;
+ make_model[0] = p->make_model ? p->make_model : "Unknown";
make_model[1] = NULL;
type[0] = typestring;
type[1] = NULL;
uri[1] = NULL;
snprintf(filter, sizeof(filter),
- "(&(objectclass=cupsPrinter)(printerDescription~=%s))", p->info);
+ "(&(objectclass=cupsPrinter)(printerURI=%s))", p->uri);
ldap_search_s(BrowseLDAPHandle, BrowseLDAPDN, LDAP_SCOPE_SUBTREE,
filter, (char **)ldap_attrs, 0, &res);
mods[6].mod_type = "objectClass";
mods[6].mod_values = (char **)objectClass_values;
- snprintf(dn, sizeof(dn), "cn=%s,ou=printers,%s", p->info, BrowseLDAPDN);
+ snprintf(dn, sizeof(dn), "cn=%s,ou=printers,%s", p->name, BrowseLDAPDN);
cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: dn=\"%s\"", dn);
if (ldap_count_entries(BrowseLDAPHandle, res) > 0)
else
{
/*
- * Printer has already been registered, modify the current
+ * Printer has never been registered, add the current
* registration...
*/
for (i = 0; i < 7; i ++)
{
pmods[i] = mods + i;
- pmods[i]->mod_op = LDAP_MOD_REPLACE;
+ pmods[i]->mod_op = LDAP_MOD_ADD;
}
pmods[i] = NULL;
- if ((rc = ldap_modify_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
+ if ((rc = ldap_add_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
cupsdLogMessage(CUPSD_LOG_ERROR,
"LDAP add for %s failed with status %d: %s",
p->name, rc, ldap_err2string(rc));
/*
- * End of "$Id: dirsvc.c 5305 2006-03-18 03:05:12Z mike $".
+ * End of "$Id: dirsvc.c 5663 2006-06-15 20:36:42Z mike $".
*/