]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/dirsvc.c
Merge changes from CUPS 1.5svn-r9641
[thirdparty/cups.git] / scheduler / dirsvc.c
index 300fa6976e83091cff175c2967301d41d6e0f449..ad05fe4c3818266b42af443623e9c3afd9daf6d7 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Directory services routines for the CUPS scheduler.
  *
- *   Copyright 2007-2010 by Apple Inc.
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -461,6 +461,14 @@ cupsdLoadRemoteCache(void)
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Syntax error on line %d of remote.cache.", linenum);
     }
+    else if (!strcasecmp(line, "UUID"))
+    {
+      if (value && !strncmp(value, "urn:uuid:", 9))
+        cupsdSetString(&(p->uuid), value);
+      else
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Bad UUID on line %d of remote.cache.", linenum);
+    }
     else if (!strcasecmp(line, "Info"))
     {
       if (value)
@@ -800,6 +808,8 @@ cupsdSaveRemoteCache(void)
 
     cupsFilePrintf(fp, "BrowseTime %d\n", (int)printer->browse_expire);
 
+    cupsFilePrintf(fp, "UUID %s\n", printer->uuid);
+
     if (printer->info)
       cupsFilePutConf(fp, "Info", printer->info);
 
@@ -2349,8 +2359,9 @@ dnssdBuildTxtRecord(
     int             for_lpd)           /* I - 1 = LPD, 0 = IPP */
 {
   int          i;                      /* Looping var */
-  char         adminurl_str[256],      /* URL for the admin page */
-               type_str[32],           /* Type to string buffer */
+  char         admin_hostname[256],    /* .local hostname for admin page */
+               adminurl_str[256],      /* URL for the admin page */
+               type_str[32],           /* Type to string buffer */
                state_str[32],          /* State to string buffer */
                rp_str[1024],           /* Queue name string buffer */
                air_str[1024],          /* auth-info-required string buffer */
@@ -2380,8 +2391,9 @@ dnssdBuildTxtRecord(
   keyvalue[i  ][0] = "ty";
   keyvalue[i++][1] = p->make_model ? p->make_model : "Unknown";
 
+  snprintf(admin_hostname, sizeof(admin_hostname), "%s.local.", DNSSDHostName);
   httpAssembleURIf(HTTP_URI_CODING_ALL, adminurl_str, sizeof(adminurl_str),
-                   "http", NULL, DNSSDHostName, DNSSDPort, "/%s/%s",
+                   "http", NULL, admin_hostname, DNSSDPort, "/%s/%s",
                   (p->type & CUPS_PRINTER_CLASS) ? "classes" : "printers",
                   p->name);
   keyvalue[i  ][0] = "adminurl";
@@ -2394,22 +2406,30 @@ dnssdBuildTxtRecord(
   keyvalue[i++][1] = for_lpd ? "100" : "0";
 
   keyvalue[i  ][0] = "product";
-  keyvalue[i++][1] = p->product ? p->product : "Unknown";
+  keyvalue[i++][1] = p->pc && p->pc->product ? p->pc->product : "Unknown";
 
-  snprintf(type_str, sizeof(type_str), "0x%X", p->type | CUPS_PRINTER_REMOTE);
-  snprintf(state_str, sizeof(state_str), "%d", p->state);
+  keyvalue[i  ][0] = "pdl";
+  keyvalue[i++][1] = p->pdl ? p->pdl : "application/postscript";
 
-  keyvalue[i  ][0] = "printer-state";
-  keyvalue[i++][1] = state_str;
+  if (get_auth_info_required(p, air_str, sizeof(air_str)))
+  {
+    keyvalue[i  ][0] = "air";
+    keyvalue[i++][1] = air_str;
+  }
 
-  keyvalue[i  ][0] = "printer-type";
-  keyvalue[i++][1] = type_str;
+  keyvalue[i  ][0] = "UUID";
+  keyvalue[i++][1] = p->uuid + 9;
+
+#ifdef HAVE_SSL
+  keyvalue[i  ][0] = "TLS";
+  keyvalue[i++][1] = "1.2";
+#endif /* HAVE_SSL */
 
   keyvalue[i  ][0] = "Transparent";
-  keyvalue[i++][1] = "T";
+  keyvalue[i++][1] = "F";
 
   keyvalue[i  ][0] = "Binary";
-  keyvalue[i++][1] = "T";
+  keyvalue[i++][1] = "F";
 
   keyvalue[i  ][0] = "Fax";
   keyvalue[i++][1] = (p->type & CUPS_PRINTER_FAX) ? "T" : "F";
@@ -2441,14 +2461,14 @@ dnssdBuildTxtRecord(
   keyvalue[i  ][0] = "Scan";
   keyvalue[i++][1] = (p->type & CUPS_PRINTER_MFP) ? "T" : "F";
 
-  keyvalue[i  ][0] = "pdl";
-  keyvalue[i++][1] = p->pdl ? p->pdl : "application/postscript";
+  snprintf(type_str, sizeof(type_str), "0x%X", p->type | CUPS_PRINTER_REMOTE);
+  snprintf(state_str, sizeof(state_str), "%d", p->state);
 
-  if (get_auth_info_required(p, air_str, sizeof(air_str)))
-  {
-    keyvalue[i  ][0] = "air";
-    keyvalue[i++][1] = air_str;
-  }
+  keyvalue[i  ][0] = "printer-state";
+  keyvalue[i++][1] = state_str;
+
+  keyvalue[i  ][0] = "printer-type";
+  keyvalue[i++][1] = type_str;
 
  /*
   * Then pack them into a proper txt record...
@@ -2548,6 +2568,9 @@ dnssdPackTxtRecord(int  *txt_len, /* O - TXT record length */
   * Calculate the buffer size
   */
 
+  if (count <= 0)
+    return (NULL);
+
   for (length = i = 0; i < count; i++)
     length += 1 + strlen(keyvalue[i][0]) + 
              (keyvalue[i][1] ? 1 + strlen(keyvalue[i][1]) : 0);
@@ -2645,7 +2668,8 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
                        name[1024],     /* Service name */
                        *nameptr;       /* Pointer into name */
   int                  ipp_len,        /* IPP TXT record length */
-                       printer_len;    /* LPD TXT record length */
+                       printer_len,    /* LPD TXT record length */
+                       printer_port;   /* LPD port number */
   const char           *regtype;       /* Registration type */
 
 
@@ -2735,11 +2759,10 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
   if (!p->ipp_ref)
   {
    /*
-    * Initial registration.  Use the _fax subtype for fax queues...
+    * Initial registration.  Use the _fax-ipp regtype for fax queues...
     */
 
-    regtype = (p->type & CUPS_PRINTER_FAX) ? "_fax-ipp._tcp" :
-                                             "_ipp._tcp,_cups";
+    regtype = (p->type & CUPS_PRINTER_FAX) ? "_fax-ipp._tcp" : DNSSDRegType;
 
     cupsdLogMessage(CUPSD_LOG_DEBUG, 
                    "Registering DNS-SD printer %s with name \"%s\" and "
@@ -2793,75 +2816,82 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
 
   if (BrowseLocalProtocols & BROWSE_LPD)
   {
-    printer_len = 0;                   /* anti-compiler-warning-code */
-    printer_txt = dnssdBuildTxtRecord(&printer_len, p, 1);
-
-    if (p->printer_ref &&
-       (printer_len != p->printer_len ||
-        memcmp(printer_txt, p->printer_txt, printer_len)))
-    {
-     /*
-      * Update the existing registration...
-      */
-
-      /* A TTL of 0 means use record's original value (Radar 3176248) */
-      if ((se = DNSServiceUpdateRecord(p->printer_ref, NULL, 0, printer_len,
-                                      printer_txt,
-                                      0)) == kDNSServiceErr_NoError)
-      {
-       if (p->printer_txt)
-         free(p->printer_txt);
+    printer_len  = 0;                  /* anti-compiler-warning-code */
+    printer_port = 515;
+    printer_txt  = dnssdBuildTxtRecord(&printer_len, p, 1);
+  }
+  else
+  {
+    printer_len  = 0;
+    printer_port = 0;
+    printer_txt  = NULL;
+  }
 
-       p->printer_txt = printer_txt;
-       p->printer_len = printer_len;
-       printer_txt    = NULL;
-      }
-      else
-      {
-       /*
-       * Failed to update record, lets close this reference and move on...
-       */
+  if (p->printer_ref &&
+      (printer_len != p->printer_len ||
+       memcmp(printer_txt, p->printer_txt, printer_len)))
+  {
+   /*
+    * Update the existing registration...
+    */
 
-       cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Unable to update LPD DNS-SD record for %s - %d",
-                       p->name, se);
+    /* A TTL of 0 means use record's original value (Radar 3176248) */
+    if ((se = DNSServiceUpdateRecord(p->printer_ref, NULL, 0, printer_len,
+                                    printer_txt,
+                                    0)) == kDNSServiceErr_NoError)
+    {
+      if (p->printer_txt)
+       free(p->printer_txt);
 
-       DNSServiceRefDeallocate(p->printer_ref);
-       p->printer_ref = NULL;
-      }
+      p->printer_txt = printer_txt;
+      p->printer_len = printer_len;
+      printer_txt    = NULL;
     }
-    
-    if (!p->printer_ref)
+    else
     {
      /*
-      * Initial registration...
+      * Failed to update record, lets close this reference and move on...
       */
 
-      cupsdLogMessage(CUPSD_LOG_DEBUG, 
-                     "Registering DNS-SD printer %s with name \"%s\" and "
-                     "type \"_printer._tcp\"", p->name, name);
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                     "Unable to update LPD DNS-SD record for %s - %d",
+                     p->name, se);
 
-      p->printer_ref = DNSSDRef;
-      if ((se = DNSServiceRegister(&p->printer_ref,
-                                   kDNSServiceFlagsShareConnection,
-                                  0, name, "_printer._tcp", NULL, NULL,
-                                  htons(515), printer_len, printer_txt,
-                                  dnssdRegisterCallback,
-                                  p)) == kDNSServiceErr_NoError)
-      {
-       p->printer_txt = printer_txt;
-       p->printer_len = printer_len;
-       printer_txt    = NULL;
-      }
-      else
-       cupsdLogMessage(CUPSD_LOG_WARN,
-                       "DNS-SD LPD registration of \"%s\" failed: %d",
-                       p->name, se);
+      DNSServiceRefDeallocate(p->printer_ref);
+      p->printer_ref = NULL;
     }
+  }
+  
+  if (!p->printer_ref)
+  {
+   /*
+    * Initial registration...
+    */
 
-    if (printer_txt)
-      free(printer_txt);
+    cupsdLogMessage(CUPSD_LOG_DEBUG, 
+                   "Registering DNS-SD printer %s with name \"%s\" and "
+                   "type \"_printer._tcp\"", p->name, name);
+
+    p->printer_ref = DNSSDRef;
+    if ((se = DNSServiceRegister(&p->printer_ref,
+                                kDNSServiceFlagsShareConnection,
+                                0, name, "_printer._tcp", NULL, NULL,
+                                htons(printer_port), printer_len, printer_txt,
+                                dnssdRegisterCallback,
+                                p)) == kDNSServiceErr_NoError)
+    {
+      p->printer_txt = printer_txt;
+      p->printer_len = printer_len;
+      printer_txt    = NULL;
+    }
+    else
+      cupsdLogMessage(CUPSD_LOG_WARN,
+                     "DNS-SD LPD registration of \"%s\" failed: %d",
+                     p->name, se);
   }
+
+  if (printer_txt)
+    free(printer_txt);
 }
 
 
@@ -3008,7 +3038,7 @@ get_auth_info_required(
     return (buffer);
   }
 
-  return (NULL);
+  return ("none");
 }
 
 
@@ -3144,7 +3174,8 @@ process_browse_data(
                                        /* Local make and model */
   cupsd_printer_t *p;                  /* Printer information */
   const char   *ipp_options,           /* ipp-options value */
-               *lease_duration;        /* lease-duration value */
+               *lease_duration,        /* lease-duration value */
+               *uuid;                  /* uuid value */
   int          is_class;               /* Is this queue a class? */
 
 
@@ -3233,6 +3264,7 @@ process_browse_data(
   hptr     = strchr(host, '.');
   sptr     = strchr(ServerName, '.');
   is_class = type & CUPS_PRINTER_CLASS;
+  uuid     = cupsGetOption("uuid", num_attrs, attrs);
 
   if (!ServerNameIsIP && sptr != NULL && hptr != NULL)
   {
@@ -3445,6 +3477,12 @@ process_browse_data(
     update  = 1;
   }
 
+  if (uuid && strcmp(p->uuid, uuid))
+  {
+    cupsdSetString(&p->uuid, uuid);
+    update = 1;
+  }
+
   if (location && (!p->location || strcmp(p->location, location)))
   {
     cupsdSetString(&p->location, location);
@@ -3853,9 +3891,10 @@ send_cups_browse(cupsd_printer_t *p)     /* I - Printer to send */
                           (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s" :
                                                            "/printers/%s",
                           p->name);
-         snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\" %s%s\n",
+         snprintf(packet, sizeof(packet),
+                  "%x %x %s \"%s\" \"%s\" \"%s\" %s%s uuid=%s\n",
                   type, p->state, uri, location, info, make_model,
-                  p->browse_attrs ? p->browse_attrs : "", air);
+                  p->browse_attrs ? p->browse_attrs : "", air, p->uuid);
 
          bytes = strlen(packet);
 
@@ -3895,9 +3934,9 @@ send_cups_browse(cupsd_printer_t *p)      /* I - Printer to send */
                                                            "/printers/%s",
                           p->name);
          snprintf(packet, sizeof(packet),
-                  "%x %x %s \"%s\" \"%s\" \"%s\" %s%s\n",
+                  "%x %x %s \"%s\" \"%s\" \"%s\" %s%s uuid=%s\n",
                   type, p->state, uri, location, info, make_model,
-                  p->browse_attrs ? p->browse_attrs : "", air);
+                  p->browse_attrs ? p->browse_attrs : "", air, p->uuid);
 
          bytes = strlen(packet);
 
@@ -3920,9 +3959,10 @@ send_cups_browse(cupsd_printer_t *p)     /* I - Printer to send */
       * the default server name...
       */
 
-      snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\" %s%s\n",
+      snprintf(packet, sizeof(packet),
+               "%x %x %s \"%s\" \"%s\" \"%s\" %s%s uuid=%s\n",
                       type, p->state, p->uri, location, info, make_model,
-              p->browse_attrs ? p->browse_attrs : "", air);
+              p->browse_attrs ? p->browse_attrs : "", air, p->uuid);
 
       bytes = strlen(packet);
       cupsdLogMessage(CUPSD_LOG_DEBUG2,