]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/printers.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / printers.c
index 556bf0297f592ae286a263da394c5cab084af851..96ccbcaa858727bb6dde4718a2ac129954c17e36 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: printers.c 4903 2006-01-10 20:02:46Z mike $"
+ * "$Id: printers.c 5178 2006-02-26 00:24:23Z mike $"
  *
  *   Printer routines for the Common UNIX Printing System (CUPS).
  *
@@ -24,7 +24,6 @@
  * Contents:
  *
  *   cupsdAddPrinter()           - Add a printer to the system.
- *   cupsdAddPrinterFilter()     - Add a MIME filter for a printer.
  *   cupsdAddPrinterHistory()    - Add the current printer state to the history.
  *   cupsdAddPrinterUser()       - Add a user to the ACL.
  *   cupsdDeleteAllPrinters()    - Delete all printers from the system.
  *   cupsdFindPrinter()          - Find a printer in the list.
  *   cupsdFreePrinterUsers()     - Free allow/deny users.
  *   cupsdLoadAllPrinters()      - Load printers from the printers.conf file.
- *   cupsdSaveAllPrinters()      - Save all printer definitions to the printers.conf
- *   cupsdSetPrinterAttrs()      - Set printer attributes based upon the PPD file.
+ *   cupsdRenamePrinter()        - Rename a printer.
+ *   cupsdSaveAllPrinters()      - Save all printer definitions to the
+ *                                 printers.conf file.
+ *   cupsdSetPrinterAttrs()      - Set printer attributes based upon the PPD
+ *                                 file.
  *   cupsdSetPrinterReasons()    - Set/update the reasons strings.
  *   cupsdSetPrinterState()      - Update the current state of a printer.
  *   cupsdStopPrinter()          - Stop a printer from printing any jobs...
  *   cupsdWritePrintcap()        - Write a pseudo-printcap file for older
  *                                 applications that need it...
  *   cupsdSanitizeURI()          - Sanitize a device URI...
+ *   add_printer_defaults()      - Add name-default attributes to the printer
+ *                                 attributes.
+ *   add_printer_filter()        - Add a MIME filter for a printer.
+ *   add_printer_formats()       - Add document-format-supported values for
+ *                                 a printer.
  *   compare_printers()          - Compare two printers.
+ *   transcode_nickname()        - Convert the PPD NickName to UTF-8...
  *   write_irix_config()         - Update the config files used by the IRIX
  *                                 desktop tools.
- *   write_irix_state()          - Update the status files used by IRIX printing
- *                                 desktop tools.
+ *   write_irix_state()          - Update the status files used by IRIX
+ *                                 printing desktop tools.
  */
 
 /*
  */
 
 #include "cupsd.h"
+#include <cups/transcode.h>
 
 
 /*
  * Local functions...
  */
 
+static void    add_printer_defaults(cupsd_printer_t *p);
+static void    add_printer_filter(cupsd_printer_t *p, const char *filter);
+static void    add_printer_formats(cupsd_printer_t *p);
 static int     compare_printers(void *first, void *second, void *data);
+static void    transcode_nickname(cupsd_printer_t *p, ppd_file_t *ppd);
 #ifdef __sgi
 static void    write_irix_config(cupsd_printer_t *p);
 static void    write_irix_state(cupsd_printer_t *p);
@@ -105,7 +118,7 @@ cupsdAddPrinter(const char *name)   /* I - Name of printer */
   p->state      = IPP_PRINTER_STOPPED;
   p->state_time = time(NULL);
   p->accepting  = 0;
-  p->shared     = 1;
+  p->shared     = DefaultShared;
   p->filetype   = mimeAddType(MimeDatabase, "printer", name);
 
   cupsdSetString(&p->job_sheets[0], "none");
@@ -139,64 +152,6 @@ cupsdAddPrinter(const char *name)  /* I - Name of printer */
 }
 
 
-/*
- * 'cupsdAddPrinterFilter()' - Add a MIME filter for a printer.
- */
-
-void
-cupsdAddPrinterFilter(
-    cupsd_printer_t  *p,               /* I - Printer to add to */
-    const char       *filter)          /* I - Filter to add */
-{
-  int          i;                      /* Looping var */
-  char         super[MIME_MAX_SUPER],  /* Super-type for filter */
-               type[MIME_MAX_TYPE],    /* Type for filter */
-               program[1024];          /* Program/filter name */
-  int          cost;                   /* Cost of filter */
-  mime_type_t  **temptype;             /* MIME type looping var */
-
-
- /*
-  * Range check input...
-  */
-
-  if (p == NULL || p->filetype == NULL || filter == NULL)
-    return;
-
- /*
-  * Parse the filter string; it should be in the following format:
-  *
-  *     super/type cost program
-  */
-
-  if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "cupsdAddPrinterFilter: Invalid filter string \"%s\"!",
-                    filter);
-    return;
-  }
-
- /*
-  * Add the filter to the MIME database, supporting wildcards as needed...
-  */
-
-  for (temptype = MimeDatabase->types, i = MimeDatabase->num_types;
-       i > 0;
-       i --, temptype ++)
-    if (((super[0] == '*' && strcasecmp((*temptype)->super, "printer") != 0) ||
-         !strcasecmp((*temptype)->super, super)) &&
-        (type[0] == '*' || !strcasecmp((*temptype)->type, type)))
-    {
-      cupsdLogMessage(CUPSD_LOG_DEBUG2, "Adding filter %s/%s %s/%s %d %s",
-                      (*temptype)->super, (*temptype)->type,
-                     p->filetype->super, p->filetype->type,
-                      cost, program);
-      mimeAddFilter(MimeDatabase, *temptype, p->filetype, cost, program);
-    }
-}
-
-
 /*
  * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
  */
@@ -238,8 +193,14 @@ cupsdAddPrinterHistory(
                 p->state);
   ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
                 p->accepting);
+  ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-shared", p->shared);
   ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-state-message",
                NULL, p->state_message);
+#ifdef __APPLE__
+  if (p->recoverable)
+    ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+                 "com.apple.print.recoverable-message", NULL, p->recoverable);
+#endif /* __APPLE__ */
   if (p->num_reasons == 0)
     ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                  "printer-state-reasons", NULL,
@@ -444,24 +405,13 @@ cupsdCreateCommonData(void)
                sizeof(compressions) / sizeof(compressions[0]),
                NULL, compressions);
 
-  /* TODO: move to printer-specific section! */
-  /* copies-default */
-  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                "copies-default", 1);
-
   /* copies-supported */
   ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies);
 
-  /* TODO: move to printer-specific section! */
   /* document-format-default */
   ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
                "document-format-default", NULL, "application/octet-stream");
 
-  /* document-format-supported */
-  ippAddStrings(CommonData, IPP_TAG_PRINTER,
-                (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),
-                "document-format-supported", NumMimeTypes, NULL, MimeTypes);
-
   /* generated-natural-language-supported */
   ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
                "generated-natural-language-supported", NULL, DefaultLanguage);
@@ -471,27 +421,17 @@ cupsdCreateCommonData(void)
                 "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]),
                NULL, versions);
 
-  /* TODO: move to printer-specific section! */
-  /* job-hold-until-default */
-  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-               "job-hold-until-default", NULL, "no-hold");
-
   /* job-hold-until-supported */
   ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                 "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]),
                NULL, holds);
 
-  /* TODO: move to printer-specific section! */
-  /* job-priority-default */
-  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                "job-priority-default", 50);
-
   /* job-priority-supported */
   ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
                 "job-priority-supported", 100);
 
   /* job-sheets-supported */
-  if (NumBanners > 0)
+  if (cupsArrayCount(Banners) > 0)
   {
    /*
     * Setup the job-sheets-supported attribute...
@@ -502,18 +442,24 @@ cupsdCreateCommonData(void)
                          "job-sheets-supported", NULL, Classification);
     else
       attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
-                          "job-sheets-supported", NumBanners + 1, NULL, NULL);
+                          "job-sheets-supported", cupsArrayCount(Banners) + 1,
+                          NULL, NULL);
 
     if (attr == NULL)
       cupsdLogMessage(CUPSD_LOG_EMERG,
-                      "cupsdSetPrinterAttrs: Unable to allocate memory for "
+                      "Unable to allocate memory for "
                       "job-sheets-supported attribute: %s!", strerror(errno));
     else if (!Classification || ClassifyOverride)
     {
-      attr->values[0].string.text = strdup("none");
+      cupsd_banner_t   *banner;        /* Current banner */
 
-      for (i = 0; i < NumBanners; i ++)
-       attr->values[i + 1].string.text = strdup(Banners[i].name);
+
+      attr->values[0].string.text = _cups_sp_alloc("none");
+
+      for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners);
+          banner;
+          i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners))
+       attr->values[i].string.text = _cups_sp_alloc(banner->name);
     }
   }
   else
@@ -545,7 +491,6 @@ cupsdCreateCommonData(void)
                (int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])),
                NULL, notify_attrs);
 
-  /* TODO: move to printer-specific section! */
   /* notify-lease-duration-default */
   ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
                "notify-lease-duration-default", DefaultLeaseDuration);
@@ -578,11 +523,6 @@ cupsdCreateCommonData(void)
   ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                "notify-schemes-supported", NULL, "mailto");
 
-  /* TODO: move to printer-specific section! */
-  /* number-up-default */
-  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                "number-up-default", 1);
-
   /* number-up-supported */
   ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
                  "number-up-supported", sizeof(nups) / sizeof(nups[0]), nups);
@@ -592,11 +532,6 @@ cupsdCreateCommonData(void)
                  "operations-supported",
                  sizeof(ops) / sizeof(ops[0]) + JobFiles - 1, (int *)ops);
 
-  /* TODO: move to printer-specific section! */
-  /* orientation-requested-default */
-  ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
-                "orientation-requested-default", IPP_PORTRAIT);
-
   /* orientation-requested-supported */
   ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
                  "orientation-requested-supported", 4, (int *)orients);
@@ -617,7 +552,7 @@ cupsdCreateCommonData(void)
   attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
                        "printer-op-policy-supported", NumPolicies, NULL, NULL);
   for (i = 0; i < NumPolicies; i ++)
-    attr->values[i].string.text = strdup(Policies[i]->name);
+    attr->values[i].string.text = _cups_sp_alloc(Policies[i]->name);
 }
 
 
@@ -711,11 +646,32 @@ cupsdDeletePrinter(
 #endif /* __sgi */
 
  /*
-  * If p is the default printer, assign the next one...
+  * If p is the default printer, assign a different one...
   */
 
   if (p == DefaultPrinter)
-    DefaultPrinter = (cupsd_printer_t *)cupsArrayFirst(Printers);
+  {
+    DefaultPrinter = NULL;
+
+    if (UseNetworkDefault)
+    {
+     /*
+      * Find the first network default printer and use it...
+      */
+
+      cupsd_printer_t  *dp;            /* New default printer */
+
+
+      for (dp = (cupsd_printer_t *)cupsArrayFirst(Printers);
+          dp;
+          dp = (cupsd_printer_t *)cupsArrayNext(Printers))
+       if (dp != p && (dp->type & CUPS_PRINTER_DEFAULT))
+       {
+         DefaultPrinter = p;
+         break;
+       }
+    }
+  }
 
  /*
   * Remove this printer from any classes and send a browse delete message...
@@ -749,6 +705,8 @@ cupsdDeletePrinter(
 
   cupsdDeletePrinterFilters(p);
 
+  mimeDeleteType(MimeDatabase, p->filetype);
+
   cupsdFreePrinterUsers(p);
   cupsdFreeQuotas(p);
 
@@ -765,6 +723,15 @@ cupsdDeletePrinter(
   cupsdClearString(&p->op_policy);
   cupsdClearString(&p->error_policy);
 
+  if (p->browse_attrs)
+    free(p->browse_attrs);
+
+#ifdef __APPLE__
+  cupsdClearString(&p->recoverable);
+#endif /* __APPLE__ */
+
+  cupsFreeOptions(p->num_options, p->options);
+
   free(p);
 
  /*
@@ -783,7 +750,6 @@ void
 cupsdDeletePrinterFilters(
     cupsd_printer_t *p)                        /* I - Printer to remove from */
 {
-  int          i;                      /* Looping var */
   mime_filter_t        *filter;                /* MIME filter looping var */
 
 
@@ -799,21 +765,16 @@ cupsdDeletePrinterFilters(
   * type == printer...
   */
 
-  for (filter = MimeDatabase->filters, i = MimeDatabase->num_filters;
-       i > 0;
-       i --, filter ++)
+  for (filter = mimeFirstFilter(MimeDatabase);
+       filter;
+       filter = mimeNextFilter(MimeDatabase))
     if (filter->dst == p->filetype)
     {
      /*
       * Delete the current filter...
       */
 
-      MimeDatabase->num_filters --;
-
-      if (i > 1)
-        memmove(filter, filter + 1, sizeof(mime_filter_t) * (i - 1));
-
-      filter --;
+      mimeDeleteFilter(MimeDatabase, filter);
     }
 }
 
@@ -896,9 +857,9 @@ cupsdLoadAllPrinters(void)
   snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
   if ((fp = cupsFileOpen(line, "r")) == NULL)
   {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "cupsdLoadAllPrinters: Unable to open %s - %s", line,
-                    strerror(errno));
+    if (errno != ENOENT)
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line,
+                     strerror(errno));
     return;
   }
 
@@ -928,8 +889,7 @@ cupsdLoadAllPrinters(void)
         * Add the printer and a base file type...
        */
 
-        cupsdLogMessage(CUPSD_LOG_DEBUG,
-                       "cupsdLoadAllPrinters: Loading printer %s...", value);
+        cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading printer %s...", value);
 
         p = cupsdAddPrinter(value);
        p->accepting = 1;
@@ -1021,6 +981,25 @@ cupsdLoadAllPrinters(void)
        return;
       }
     }
+    else if (!strcasecmp(line, "Option") && value)
+    {
+     /*
+      * Option name value
+      */
+
+      for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
+
+      if (!*valueptr)
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Syntax error on line %d of printers.conf.", linenum);
+      else
+      {
+        for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
+
+        p->num_options = cupsAddOption(value, valueptr, p->num_options,
+                                      &(p->options));
+      }
+    }
     else if (!strcasecmp(line, "PortMonitor"))
     {
       if (value && strcmp(value, "none"))
@@ -1249,6 +1228,53 @@ cupsdLoadAllPrinters(void)
 }
 
 
+/*
+ * 'cupsdRenamePrinter()' - Rename a printer.
+ */
+
+void
+cupsdRenamePrinter(
+    cupsd_printer_t *p,                        /* I - Printer */
+    const char      *name)             /* I - New name */
+{
+ /*
+  * Remove the printer from the array(s) first...
+  */
+
+  cupsArrayRemove(Printers, p);
+
+  if (p->type & CUPS_PRINTER_IMPLICIT)
+    cupsArrayRemove(ImplicitPrinters, p);
+
+ /*
+  * Rename the printer type...
+  */
+
+  mimeDeleteType(MimeDatabase, p->filetype);
+  p->filetype = mimeAddType(MimeDatabase, "printer", name);
+
+ /*
+  * Rename the printer...
+  */
+
+  cupsdSetStringf(&p->name, name);
+
+ /*
+  * Reset printer attributes...
+  */
+
+  cupsdSetPrinterAttrs(p);
+
+ /*
+  * Add the printer back to the printer array(s)...
+  */
+
+  cupsArrayAdd(Printers, p);
+  if (p->type & CUPS_PRINTER_IMPLICIT)
+    cupsArrayAdd(ImplicitPrinters, p);
+}
+
+
 /*
  * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
  *                            file.
@@ -1264,6 +1290,7 @@ cupsdSaveAllPrinters(void)
   cupsd_printer_t      *printer;       /* Current printer class */
   time_t               curtime;        /* Current time */
   struct tm            *curdate;       /* Current date */
+  cups_option_t                *option;        /* Current option */
 
 
  /*
@@ -1298,7 +1325,7 @@ cupsdSaveAllPrinters(void)
   */
 
   fchown(cupsFileNumber(fp), getuid(), Group);
-  fchmod(cupsFileNumber(fp), ConfigFilePerm);
+  fchmod(cupsFileNumber(fp), 0600);
 
  /*
   * Write a small header to the file...
@@ -1385,6 +1412,11 @@ cupsdSaveAllPrinters(void)
     if (printer->error_policy)
       cupsFilePrintf(fp, "ErrorPolicy %s\n", printer->error_policy);
 
+    for (i = printer->num_options, option = printer->options;
+         i > 0;
+        i --, option ++)
+      cupsFilePrintf(fp, "Option %s %s\n", option->name, option->value);
+
     cupsFilePuts(fp, "</Printer>\n");
 
 #ifdef __sgi
@@ -1407,33 +1439,33 @@ cupsdSaveAllPrinters(void)
 void
 cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
 {
-  char                 uri[HTTP_MAX_URI];
-                                       /* URI for printer */
-  char                 resource[HTTP_MAX_URI];
-                                       /* Resource portion of URI */
-  int                  i;              /* Looping var */
-  char                 filename[1024]; /* Name of PPD file */
-  int                  num_media;      /* Number of media options */
-  cupsd_location_t     *auth;          /* Pointer to authentication element */
-  const char           *auth_supported;/* Authentication supported */
-  cups_ptype_t         cupsd_printer_type;
-                                       /* Printer type data */
-  ppd_file_t           *ppd;           /* PPD file data */
-  ppd_option_t         *input_slot,    /* InputSlot options */
-                       *media_type,    /* MediaType options */
-                       *page_size,     /* PageSize options */
-                       *output_bin,    /* OutputBin options */
-                       *media_quality; /* EFMediaQualityMode options */
-  ppd_attr_t           *ppdattr;       /* PPD attribute */
-  ipp_attribute_t      *attr;          /* Attribute data */
-  ipp_value_t          *val;           /* Attribute value */
-  int                  num_finishings; /* Number of finishings */
-  ipp_finish_t         finishings[5];  /* finishings-supported values */
+  int          i,                      /* Looping var */
+               length;                 /* Length of browse attributes */
+  char         uri[HTTP_MAX_URI];      /* URI for printer */
+  char         resource[HTTP_MAX_URI]; /* Resource portion of URI */
+  char         filename[1024];         /* Name of PPD file */
+  int          num_media;              /* Number of media options */
+  cupsd_location_t *auth;              /* Pointer to authentication element */
+  const char   *auth_supported;        /* Authentication supported */
+  cups_ptype_t printer_type;           /* Printer type data */
+  ppd_file_t   *ppd;                   /* PPD file data */
+  ppd_option_t *input_slot,            /* InputSlot options */
+               *media_type,            /* MediaType options */
+               *page_size,             /* PageSize options */
+               *output_bin,            /* OutputBin options */
+               *media_quality,         /* EFMediaQualityMode options */
+               *duplex;                /* Duplex options */
+  ppd_attr_t   *ppdattr;               /* PPD attribute */
+  ipp_attribute_t *attr;               /* Attribute data */
+  ipp_value_t  *val;                   /* Attribute value */
+  int          num_finishings;         /* Number of finishings */
+  ipp_finish_t finishings[5];          /* finishings-supported values */
+  cups_option_t        *option;                /* Current printer option */
   static const char * const sides[3] = /* sides-supported values */
                {
-                 "one",
-                 "two-long-edge",
-                 "two-short-edge"
+                 "one-sided",
+                 "two-sided-long-edge",
+                 "two-sided-short-edge"
                };
 
 
@@ -1525,7 +1557,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
   ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
                 "job-page-limit", p->page_limit);
 
-  if (NumBanners > 0 && !(p->type & CUPS_PRINTER_REMOTE))
+  if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_REMOTE))
   {
    /*
     * Setup the job-sheets-default attribute...
@@ -1536,14 +1568,14 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
 
     if (attr != NULL)
     {
-      attr->values[0].string.text = strdup(Classification ?
+      attr->values[0].string.text = _cups_sp_alloc(Classification ?
                                           Classification : p->job_sheets[0]);
-      attr->values[1].string.text = strdup(Classification ?
+      attr->values[1].string.text = _cups_sp_alloc(Classification ?
                                           Classification : p->job_sheets[1]);
     }
   }
 
-  cupsd_printer_type = p->type;
+  printer_type = p->type;
 
   p->raw = 0;
 
@@ -1560,6 +1592,9 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
       ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
                    "printer-make-and-model", NULL, p->make_model);
 
+    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
+                p->uri);
+
     p->raw = 1;
   }
   else
@@ -1587,6 +1622,9 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
        ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
                      "printer-make-and-model", NULL, "Local Printer Class");
 
+      ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
+                  "file:///dev/null");
+
       if (p->num_printers > 0)
       {
        /*
@@ -1600,7 +1638,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
        for (i = 0; i < p->num_printers; i ++)
        {
           if (attr != NULL)
-            attr->values[i].string.text = strdup(p->printers[i]->uri);
+            attr->values[i].string.text = _cups_sp_alloc(p->printers[i]->uri);
 
          p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;
         }
@@ -1611,7 +1649,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
        if (attr != NULL)
        {
          for (i = 0; i < p->num_printers; i ++)
-            attr->values[i].string.text = strdup(p->printers[i]->name);
+            attr->values[i].string.text = _cups_sp_alloc(p->printers[i]->name);
         }
       }
     }
@@ -1678,15 +1716,22 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
                        "pages-per-minute", ppd->throughput);
 
         if (ppd->nickname)
-          cupsdSetString(&p->make_model, ppd->nickname);
+       {
+        /*
+         * The NickName can be localized in the character set specified
+         * by the LanugageEncoding attribute.  Convert as needed to
+         * UTF-8...
+         */
+
+          transcode_nickname(p, ppd);
+       }
        else if (ppd->modelname)
           cupsdSetString(&p->make_model, ppd->modelname);
        else
          cupsdSetString(&p->make_model, "Bad PPD File");
 
-        if (p->make_model)
-         ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
-                       "printer-make-and-model", NULL, p->make_model);
+       ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+                     "printer-make-and-model", NULL, p->make_model);
 
        /*
        * Add media options from the PPD file...
@@ -1708,9 +1753,9 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
 
         if (num_media == 0)
        {
-         cupsdLogMessage(CUPSD_LOG_CRIT, "cupsdSetPrinterAttrs: The PPD file for printer %s "
-                            "contains no media options and is therefore "
-                            "invalid!", p->name);
+         cupsdLogMessage(CUPSD_LOG_CRIT,
+                         "The PPD file for printer %s contains no media "
+                         "options and is therefore invalid!", p->name);
        }
        else
        {
@@ -1722,36 +1767,36 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
 
            if (input_slot != NULL)
              for (i = 0; i < input_slot->num_choices; i ++, val ++)
-               val->string.text = strdup(input_slot->choices[i].choice);
+               val->string.text = _cups_sp_alloc(input_slot->choices[i].choice);
 
            if (media_type != NULL)
              for (i = 0; i < media_type->num_choices; i ++, val ++)
-               val->string.text = strdup(media_type->choices[i].choice);
+               val->string.text = _cups_sp_alloc(media_type->choices[i].choice);
 
            if (media_quality != NULL)
              for (i = 0; i < media_quality->num_choices; i ++, val ++)
-               val->string.text = strdup(media_quality->choices[i].choice);
+               val->string.text = _cups_sp_alloc(media_quality->choices[i].choice);
 
            if (page_size != NULL)
            {
              for (i = 0; i < page_size->num_choices; i ++, val ++)
-               val->string.text = strdup(page_size->choices[i].choice);
+               val->string.text = _cups_sp_alloc(page_size->choices[i].choice);
 
-             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
-                          NULL, page_size->defchoice);
+             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                          "media-default", NULL, page_size->defchoice);
             }
            else if (input_slot != NULL)
-             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
-                          NULL, input_slot->defchoice);
+             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                          "media-default", NULL, input_slot->defchoice);
            else if (media_type != NULL)
-             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
-                          NULL, media_type->defchoice);
+             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                          "media-default", NULL, media_type->defchoice);
            else if (media_quality != NULL)
-             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
-                          NULL, media_quality->defchoice);
+             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                          "media-default", NULL, media_quality->defchoice);
            else
-             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
-                          NULL, "none");
+             ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                          "media-default", NULL, "none");
           }
         }
 
@@ -1770,7 +1815,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
            for (i = 0, val = attr->values;
                 i < output_bin->num_choices;
                 i ++, val ++)
-             val->string.text = strdup(output_bin->choices[i].choice);
+             val->string.text = _cups_sp_alloc(output_bin->choices[i].choice);
           }
        }
 
@@ -1778,14 +1823,28 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
         * Duplexing, etc...
        */
 
-       if (ppdFindOption(ppd, "Duplex") != NULL)
+       if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL)
+         if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL)
+           if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL)
+             if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL)
+               duplex = ppdFindOption(ppd, "JCLDuplex");
+
+       if (duplex && duplex->num_choices > 1)
        {
          p->type |= CUPS_PRINTER_DUPLEX;
 
-         ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-supported",
-                       3, NULL, sides);
-         ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-default",
-                       NULL, "one");
+         ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                       "sides-supported", 3, NULL, sides);
+
+          if (!strcasecmp(duplex->defchoice, "DuplexTumble"))
+           ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                        "sides-default", NULL, "two-sided-short-edge");
+          else if (!strcasecmp(duplex->defchoice, "DuplexNoTumble"))
+           ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                        "sides-default", NULL, "two-sided-long-edge");
+         else
+           ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                        "sides-default", NULL, "one-sided");
        }
 
        if (ppdFindOption(ppd, "Collate") != NULL)
@@ -1816,7 +1875,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
        * handle "raw" printing by users.
        */
 
-        cupsdAddPrinterFilter(p, "application/vnd.cups-raw 0 -");
+        add_printer_filter(p, "application/vnd.cups-raw 0 -");
 
        /*
        * Add any filters in the PPD file...
@@ -1826,7 +1885,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
        for (i = 0; i < ppd->num_filters; i ++)
        {
           DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i]));
-          cupsdAddPrinterFilter(p, ppd->filters[i]);
+          add_printer_filter(p, ppd->filters[i]);
        }
 
        if (ppd->num_filters == 0)
@@ -1835,7 +1894,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
          * If there are no filters, add a PostScript printing filter.
          */
 
-          cupsdAddPrinterFilter(p, "application/vnd.cups-postscript 0 -");
+          add_printer_filter(p, "application/vnd.cups-postscript 0 -");
         }
 
        /*
@@ -1861,19 +1920,19 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
         attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                             "port-monitor-supported", i, NULL, NULL);
 
-        attr->values[0].string.text = strdup("none");
+        attr->values[0].string.text = _cups_sp_alloc("none");
 
         for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
             ppdattr;
             i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL))
-         attr->values[i].string.text = strdup(ppdattr->value);
+         attr->values[i].string.text = _cups_sp_alloc(ppdattr->value);
 
         if (ppd->protocols)
        {
          if (strstr(ppd->protocols, "TBCP"))
-           attr->values[i].string.text = strdup("tbcp");
+           attr->values[i].string.text = _cups_sp_alloc("tbcp");
          else if (strstr(ppd->protocols, "BCP"))
-           attr->values[i].string.text = strdup("bcp");
+           attr->values[i].string.text = _cups_sp_alloc("bcp");
        }
 
        /*
@@ -1882,7 +1941,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
 
        ppdClose(ppd);
 
-        cupsd_printer_type = p->type;
+        printer_type = p->type;
       }
       else if (!access(filename, 0))
       {
@@ -1892,29 +1951,31 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
 
         pstatus = ppdLastError(&pline);
 
-       cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!", p->name);
+       cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!",
+                       p->name);
 
        if (pstatus <= PPD_ALLOC_ERROR)
          cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno));
         else
-         cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.", ppdErrorString(pstatus),
-                    pline);
+         cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.",
+                         ppdErrorString(pstatus), pline);
 
-        cupsdLogMessage(CUPSD_LOG_INFO, "Hint: Run \"cupstestppd %s\" and fix any errors.",
-                  filename);
+        cupsdLogMessage(CUPSD_LOG_INFO,
+                       "Hint: Run \"cupstestppd %s\" and fix any errors.",
+                       filename);
 
        /*
        * Add a filter from application/vnd.cups-raw to printer/name to
        * handle "raw" printing by users.
        */
 
-        cupsdAddPrinterFilter(p, "application/vnd.cups-raw 0 -");
+        add_printer_filter(p, "application/vnd.cups-raw 0 -");
 
        /*
         * Add a PostScript filter, since this is still possibly PS printer.
        */
 
-       cupsdAddPrinterFilter(p, "application/vnd.cups-postscript 0 -");
+       add_printer_filter(p, "application/vnd.cups-postscript 0 -");
       }
       else
       {
@@ -1924,7 +1985,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
 
        snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
                 p->name);
-       if (access(filename, X_OK) == 0)
+       if (!access(filename, X_OK))
        {
         /*
          * Yes, we have a System V style interface script; use it!
@@ -1935,7 +1996,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
 
          snprintf(filename, sizeof(filename), "*/* 0 %s/interfaces/%s",
                   ServerRoot, p->name);
-         cupsdAddPrinterFilter(p, filename);
+         add_printer_filter(p, filename);
        }
        else if (p->device_uri &&
                 !strncmp(p->device_uri, "ipp://", 6) &&
@@ -1946,7 +2007,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
          * Tell the client this is really a hard-wired remote printer.
          */
 
-          cupsd_printer_type |= CUPS_PRINTER_REMOTE;
+          printer_type |= CUPS_PRINTER_REMOTE;
 
          /*
          * Point the printer-uri-supported attribute to the
@@ -1991,20 +2052,113 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
   }
 
  /*
-  * Add the CUPS-specific printer-type attribute...
+  * Copy the printer options into a browse attributes string we can re-use.
   */
 
-  if (!p->shared)
-    p->type |= CUPS_PRINTER_NOT_SHARED;
-  else
-    p->type &= ~CUPS_PRINTER_NOT_SHARED;
+  if (!(p->type & CUPS_PRINTER_REMOTE))
+  {
+    const char *valptr;                /* Pointer into value */
+    char       *attrptr;               /* Pointer into attribute string */
+
+
+   /*
+    * Free the old browse attributes as needed...
+    */
+
+    if (p->browse_attrs)
+      free(p->browse_attrs);
+
+   /*
+    * Compute the length of all attributes + job-sheets, lease-duration,
+    * and BrowseLocalOptions.
+    */
+
+    for (length = 1, i = p->num_options, option = p->options;
+         i > 0;
+        i --, option ++)
+    {
+      length += strlen(option->name) + 2;
+
+      if (option->value)
+      {
+        for (valptr = option->value; *valptr; valptr ++)
+         if (strchr(" \"\'\\", *valptr))
+           length += 2;
+         else
+           length ++;
+      }
+    }
+
+    length += 13 + strlen(p->job_sheets[0]) + strlen(p->job_sheets[1]);
+    length += 32;
+    if (BrowseLocalOptions)
+      length += 12 + strlen(BrowseLocalOptions); 
+
+   /*
+    * Allocate the new string...
+    */
+    if ((p->browse_attrs = calloc(1, length)) == NULL)
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to allocate %d bytes for browse data!",
+                     length);
+    else
+    {
+     /*
+      * Got the allocated string, now copy the options and attributes over...
+      */
+
+      sprintf(p->browse_attrs, "job-sheets=%s,%s lease-duration=%d",
+              p->job_sheets[0], p->job_sheets[1], BrowseTimeout);
+      attrptr = p->browse_attrs + strlen(p->browse_attrs);
+
+      if (BrowseLocalOptions)
+      {
+        sprintf(attrptr, " ipp-options=%s", BrowseLocalOptions);
+        attrptr += strlen(attrptr);
+      }
+
+      for (i = p->num_options, option = p->options;
+           i > 0;
+          i --, option ++)
+      {
+        *attrptr++ = ' ';
+       strcpy(attrptr, option->name);
+       attrptr += strlen(attrptr);
+
+       if (option->value)
+       {
+         *attrptr++ = '=';
+
+          for (valptr = option->value; *valptr; valptr ++)
+         {
+           if (strchr(" \"\'\\", *valptr))
+             *attrptr++ = '\\';
+
+           *attrptr++ = *valptr;
+         }
+       }
+      }
+
+      *attrptr = '\0';
+    }
+  }
+
+ /*
+  * Populate the document-format-supported attribute...
+  */
 
-  ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type",
-                cupsd_printer_type);
+  add_printer_formats(p);
 
   DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name,
                 p->type));
 
+ /*
+  * Add name-default attributes...
+  */
+
+  add_printer_defaults(p);
+
 #ifdef __sgi
  /*
   * Write the IRIX printer config and status files...
@@ -2218,6 +2372,7 @@ cupsdStopPrinter(cupsd_printer_t *p,      /* I - Printer to stop */
     */
 
     job->state->values[0].integer = IPP_JOB_PENDING;
+    job->state_value              = IPP_JOB_PENDING;
 
     cupsdSaveJob(job);
   }
@@ -2600,6 +2755,250 @@ cupsdSanitizeURI(const char *uri,       /* I - Original device URI */
 }
 
 
+/*
+ * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
+ */
+
+static void
+add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
+{
+  int          i;                      /* Looping var */
+  int          num_options;            /* Number of default options */
+  cups_option_t        *options,               /* Default options */
+               *option;                /* Current option */
+  char         name[256];              /* name-default */
+
+
+ /*
+  * Add all of the default options from the .conf files...
+  */
+
+  for (num_options = 0, i = p->num_options, option = p->options;
+       i > 0;
+       i --, option ++)
+  {
+    if (strcmp(option->name, "ipp-options") &&
+       strcmp(option->name, "job-sheets") &&
+        strcmp(option->name, "lease-duration"))
+    {
+      snprintf(name, sizeof(name), "%s-default", option->name);
+      num_options = cupsAddOption(name, option->value, num_options, &options);
+    }
+  }
+
+ /*
+  * Convert options to IPP attributes...
+  */
+
+  cupsEncodeOptions2(p->attrs, num_options, options, IPP_TAG_PRINTER);
+  cupsFreeOptions(num_options, options);
+
+ /*
+  * Add standard -default attributes as needed...
+  */
+
+  if (!cupsGetOption("copies", p->num_options, p->options))
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default",
+                  1);
+
+  if (!cupsGetOption("job-hold-until", p->num_options, p->options))
+    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                 "job-hold-until-default", NULL, "no-hold");
+
+  if (!cupsGetOption("job-priority", p->num_options, p->options))
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+                  "job-priority-default", 50);
+
+  if (!cupsGetOption("number-up", p->num_options, p->options))
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+                  "number-up-default", 1);
+
+  if (!cupsGetOption("orientation-requested", p->num_options, p->options))
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
+                  "orientation-requested-default", IPP_PORTRAIT);
+}
+
+
+/*
+ * 'add_printer_filter()' - Add a MIME filter for a printer.
+ */
+
+static void
+add_printer_filter(
+    cupsd_printer_t  *p,               /* I - Printer to add to */
+    const char       *filter)          /* I - Filter to add */
+{
+  char         super[MIME_MAX_SUPER],  /* Super-type for filter */
+               type[MIME_MAX_TYPE],    /* Type for filter */
+               program[1024];          /* Program/filter name */
+  int          cost;                   /* Cost of filter */
+  mime_type_t  *temptype;              /* MIME type looping var */
+  char         filename[1024];         /* Full filter filename */
+
+
+ /*
+  * Parse the filter string; it should be in the following format:
+  *
+  *     super/type cost program
+  */
+
+  if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!",
+                    p->name, filter);
+    return;
+  }
+
+ /*
+  * See if the filter program exists; if not, stop the printer and flag
+  * the error!
+  */
+
+  if (strcmp(program, "-"))
+  {
+    if (program[0] == '/')
+      strlcpy(filename, program, sizeof(filename));
+    else
+      snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program);
+
+    if (access(filename, X_OK))
+    {
+      snprintf(p->state_message, sizeof(p->state_message),
+               "Filter \"%s\" for printer \"%s\" not available: %s",
+              program, p->name, strerror(errno));
+      cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 0);
+      cupsdSetPrinterReasons(p, "+cups-missing-filter-error");
+      cupsdAddPrinterHistory(p);
+
+      cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message);
+    }
+  }
+
+ /*
+  * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
+  * application/vnd.cups-command...
+  */
+
+  if (!strcasecmp(super, "application") &&
+      !strcasecmp(type, "vnd.cups-command"))
+    p->type |= CUPS_PRINTER_COMMANDS;
+
+ /*
+  * Add the filter to the MIME database, supporting wildcards as needed...
+  */
+
+  for (temptype = mimeFirstType(MimeDatabase);
+       temptype;
+       temptype = mimeNextType(MimeDatabase))
+    if (((super[0] == '*' && strcasecmp(temptype->super, "printer")) ||
+         !strcasecmp(temptype->super, super)) &&
+        (type[0] == '*' || !strcasecmp(temptype->type, type)))
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
+                      p->name, temptype->super, temptype->type,
+                     p->filetype->super, p->filetype->type,
+                      cost, program);
+      mimeAddFilter(MimeDatabase, temptype, p->filetype, cost, program);
+    }
+}
+
+
+/*
+ * 'add_printer_formats()' - Add document-format-supported values for a printer.
+ */
+
+static void
+add_printer_formats(cupsd_printer_t *p)        /* I - Printer */
+{
+  int          i;                      /* Looping var */
+  mime_type_t  *type;                  /* Current MIME type */
+  cups_array_t *filters;               /* Filters */
+  int          num_types;              /* Number of supported types */
+  const char   **types;                /* Array of supported type names */
+  char         mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
+                                       /* MIME type name */
+
+
+ /*
+  * Raw (and remote) queues advertise all of the supported MIME
+  * types...
+  */
+
+  if (p->raw)
+  {
+    ippAddStrings(p->attrs, IPP_TAG_PRINTER,
+                  (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),
+                  "document-format-supported", NumMimeTypes, NULL, MimeTypes);
+    return;
+  }
+
+ /*
+  * Otherwise, loop through the supported MIME types and see if there
+  * are filters for them...
+  */
+
+  if ((types = calloc(NumMimeTypes, sizeof(char *))) == NULL)
+  {
+    cupsdLogMessage(CUPSD_LOG_EMERG,
+                    "Unable to allocate memory for \"%s\" MIME type list!",
+                   p->name);
+    return;
+  }
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters",
+                  mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
+
+  types[0] = _cups_sp_alloc("application/octet-stream");
+
+  for (num_types = 1, type = mimeFirstType(MimeDatabase);
+       type;
+       type = mimeNextType(MimeDatabase))
+  {
+    if (!strcasecmp(type->super, "application") &&
+       !strcasecmp(type->type, "octet-stream"))
+      continue;
+
+    snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
+
+    if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "add_printer_formats: %s: %s needs %d filters",
+                      p->name, mimetype, cupsArrayCount(filters));
+
+      cupsArrayDelete(filters);
+      types[num_types] = _cups_sp_alloc(mimetype);
+      num_types ++;
+    }
+    else
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                      "add_printer_formats: %s: %s not supported",
+                      p->name, mimetype);
+  }
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "add_printer_formats: %s: %d supported types",
+                 p->name, num_types);
+
+ /*
+  * Add the file formats that can be filtered...
+  */
+
+  ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
+                "document-format-supported", num_types, NULL, types);
+
+ /*
+  * Free the temporary data...
+  */
+
+  for (i = 0; i < num_types; i ++)
+    _cups_sp_free(types[i]);
+
+  free(types);
+}
+
+
 /*
  * 'compare_printers()' - Compare two printers.
  */
@@ -2614,6 +3013,88 @@ compare_printers(void *first,            /* I - First printer */
 }
 
 
+/*
+ * 'transcode_nickname()' - Convert the PPD NickName to UTF-8...
+ */
+
+static void
+transcode_nickname(cupsd_printer_t *p, /* I - Printer */
+                   ppd_file_t      *ppd)/* I - PPD file */
+{
+  cups_utf8_t          utf8[256];      /* UTF-8 version of nickname */
+  cups_encoding_t      encoding;       /* Encoding of PPD file */
+  const char           *nickptr;       /* Pointer into nickname */
+
+
+ /*
+  * See if we need to convert to UTF-8...
+  */
+
+  if (!ppd->lang_encoding || !strcasecmp(ppd->lang_encoding, "UTF-8"))
+  {
+   /*
+    * No language encoding, or encoding uses the non-standard UTF-8
+    * value, so no transcoding is required...
+    */
+
+    goto no_transcode;
+  }
+
+  for (nickptr = ppd->nickname; *nickptr; nickptr ++)
+    if (*nickptr & 0x80)
+      break;
+
+  if (!*nickptr)
+  {
+   /*
+    * No non-ASCII characters, so no transcoding is required...
+    */
+
+    goto no_transcode;
+  }
+
+ /*
+  * OK, we need to transcode...
+  */
+
+  if (!strcasecmp(ppd->lang_encoding, "ISOLatin1"))
+    encoding = CUPS_ISO8859_1;
+  else if (!strcasecmp(ppd->lang_encoding, "ISOLatin2"))
+    encoding = CUPS_ISO8859_2;
+  else if (!strcasecmp(ppd->lang_encoding, "ISOLatin5"))
+    encoding = CUPS_ISO8859_5;
+  else if (!strcasecmp(ppd->lang_encoding, "JIS83-RKSJ"))
+    encoding = CUPS_WINDOWS_932;
+  else if (!strcasecmp(ppd->lang_encoding, "MacStandard"))
+    encoding = CUPS_MAC_ROMAN;
+  else if (!strcasecmp(ppd->lang_encoding, "WindowsANSI"))
+    encoding = CUPS_WINDOWS_1252;
+  else
+  {
+   /*
+    * Unknown encoding, treat as UTF-8...
+    */
+
+    goto no_transcode;
+  }
+
+  cupsCharsetToUTF8(utf8, ppd->nickname, sizeof(utf8), encoding);
+
+  cupsdSetString(&p->make_model, (char *)utf8);
+
+  return;
+
+ /*
+  * Yeah, yeah, gotos are evil, but code bloat is more evil...
+  */
+
+  no_transcode:
+
+  cupsdSetString(&p->make_model, ppd->nickname);
+  return;
+}
+
+
 #ifdef __sgi
 /*
  * 'write_irix_config()' - Update the config files used by the IRIX
@@ -2870,5 +3351,5 @@ write_irix_state(cupsd_printer_t *p)      /* I - Printer to update */
 
 
 /*
- * End of "$Id: printers.c 4903 2006-01-10 20:02:46Z mike $".
+ * End of "$Id: printers.c 5178 2006-02-26 00:24:23Z mike $".
  */