]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/dirsvc.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / dirsvc.c
index 1c0be6a3b13ce5f1d85263a8120728cc2bf945e7..e26d20db7c11f420598eded0627209b64faaed15 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$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).
  *
@@ -36,6 +36,7 @@
  *   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.
@@ -77,8 +78,9 @@ static void   send_cups_browse(cupsd_printer_t *p);
 #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 */
@@ -664,10 +666,10 @@ cupsdSendBrowseDelete(
   * 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 */
 }
@@ -798,7 +800,7 @@ cupsdSendBrowseList(void)
                      (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);
@@ -933,6 +935,8 @@ cupsdStartBrowsing(void)
 
     BrowseSLPRefresh = 0;
   }
+  else
+    BrowseSLPHandle = NULL;
 #endif /* HAVE_LIBSLP */
 
 #ifdef HAVE_OPENLDAP
@@ -1160,7 +1164,7 @@ cupsdStopBrowsing(void)
   }
 #endif /* HAVE_LIBSLP */
 
-#ifdef HAVE_OPENDAP
+#ifdef HAVE_OPENLDAP
   if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_LDAP) &&
       BrowseLDAPHandle)
   {
@@ -1523,39 +1527,57 @@ cupsdUpdateLDAPBrowse(void)
   * 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 */
@@ -1906,7 +1928,7 @@ process_browse_data(
 
          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,
@@ -1966,7 +1988,7 @@ process_browse_data(
 
       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);
@@ -2009,7 +2031,7 @@ process_browse_data(
 
          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,
@@ -2072,7 +2094,7 @@ process_browse_data(
       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...
@@ -2333,7 +2355,7 @@ process_implicit_classes(void)
 
         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.",
@@ -2470,8 +2492,20 @@ send_cups_browse(cupsd_printer_t *p)     /* I - Printer to send */
 
   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...
@@ -2506,7 +2540,7 @@ send_cups_browse(cupsd_printer_t *p)      /* I - Printer to send */
 
          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",
@@ -2645,13 +2679,13 @@ send_ldap_browse(cupsd_printer_t *p)    /* I - Printer to register */
 
   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;
@@ -2659,7 +2693,7 @@ send_ldap_browse(cupsd_printer_t *p)      /* I - Printer to register */
   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);
@@ -2681,7 +2715,7 @@ send_ldap_browse(cupsd_printer_t *p)      /* I - Printer to register */
   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)
@@ -2709,7 +2743,7 @@ send_ldap_browse(cupsd_printer_t *p)      /* I - Printer to register */
   else 
   {
    /*
-    * Printer has already been registered, modify the current
+    * Printer has never been registered, add the current
     * registration...
     */
 
@@ -2719,11 +2753,11 @@ send_ldap_browse(cupsd_printer_t *p)    /* I - Printer to register */
     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));
@@ -3115,5 +3149,5 @@ slp_url_callback(
 
 
 /*
- * 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 $".
  */