]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Merge changes from CUPS 1.5svn-r9400
[thirdparty/cups.git] / scheduler / ipp.c
index f711b8bd0ad27e1679b33f8f641f1770df637e7a..1122665bc3e09b2d91d719e8963ae75b38503891 100644 (file)
 
 #ifdef __APPLE__
 #  include <ApplicationServices/ApplicationServices.h>
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 #  include <CoreFoundation/CoreFoundation.h>
 #  ifdef HAVE_MEMBERSHIP_H
 #    include <membership.h>
@@ -149,9 +152,13 @@ static void        add_printer_state_reasons(cupsd_client_t *con,
 static void    add_queued_job_count(cupsd_client_t *con, cupsd_printer_t *p);
 #ifdef __APPLE__
 static void    apple_init_profile(ppd_file_t *ppd, cups_array_t *languages,
-                                  CMDeviceProfileInfo *profile, unsigned id,
-                                  const char *name, const char *text,
-                                  const char *iccfile);
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+                                   CFMutableDictionaryRef profile,
+#  else
+                                  CMDeviceProfileInfo *profile,
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
+                                  unsigned id, const char *name,
+                                  const char *text, const char *iccfile);
 static void    apple_register_profiles(cupsd_printer_t *p);
 static void    apple_unregister_profiles(cupsd_printer_t *p);
 #endif /* __APPLE__ */
@@ -167,7 +174,8 @@ static ipp_attribute_t      *copy_attribute(ipp_t *to, ipp_attribute_t *attr,
                                        int quickcopy);
 static void    close_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    copy_attrs(ipp_t *to, ipp_t *from, cups_array_t *ra,
-                          ipp_tag_t group, int quickcopy);
+                          ipp_tag_t group, int quickcopy,
+                          cups_array_t *exclude);
 static int     copy_banner(cupsd_client_t *con, cupsd_job_t *job,
                            const char *name);
 static int     copy_file(const char *from, const char *to);
@@ -175,13 +183,14 @@ static int        copy_model(cupsd_client_t *con, const char *from,
                           const char *to);
 static void    copy_job_attrs(cupsd_client_t *con,
                               cupsd_job_t *job,
-                              cups_array_t *ra);
+                              cups_array_t *ra, cups_array_t *exclude);
 static void    copy_printer_attrs(cupsd_client_t *con,
                                   cupsd_printer_t *printer,
                                   cups_array_t *ra);
 static void    copy_subscription_attrs(cupsd_client_t *con,
                                        cupsd_subscription_t *sub,
-                                       cups_array_t *ra);
+                                       cups_array_t *ra,
+                                       cups_array_t *exclude);
 static void    create_job(cupsd_client_t *con, ipp_attribute_t *uri);
 static cups_array_t *create_requested_array(ipp_t *request);
 static void    create_subscription(cupsd_client_t *con, ipp_attribute_t *uri);
@@ -3106,15 +3115,21 @@ add_queued_job_count(
 
 static void
 apple_init_profile(
-    ppd_file_t          *ppd,          /* I - PPD file */
-    cups_array_t       *languages,     /* I - Languages in the PPD file */
-    CMDeviceProfileInfo *profile,      /* I - Profile record */
-    unsigned            id,            /* I - Profile ID */
-    const char          *name,         /* I - Profile name */
-    const char          *text,         /* I - Profile UI text */
-    const char          *iccfile)      /* I - ICC filename */
+    ppd_file_t             *ppd,       /* I - PPD file */
+    cups_array_t          *languages,  /* I - Languages in the PPD file */
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+    CFMutableDictionaryRef profile,    /* I - Profile dictionary */
+#  else
+    CMDeviceProfileInfo    *profile,   /* I - Profile record */
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
+    unsigned               id,         /* I - Profile ID */
+    const char             *name,      /* I - Profile name */
+    const char             *text,      /* I - Profile UI text */
+    const char             *iccfile)   /* I - ICC filename */
 {
-  char                 url[1024];      /* URL for profile filename */
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+  CFURLRef             url;            /* URL for profile filename */
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
   CFMutableDictionaryRef dict;         /* Dictionary for name */
   char                 *language;      /* Current language */
   ppd_attr_t           *attr;          /* Profile attribute */
@@ -3135,7 +3150,7 @@ apple_init_profile(
 
   if (cftext)
   {
-    CFDictionarySetValue(dict, CFSTR("en"), cftext);
+    CFDictionarySetValue(dict, CFSTR("en_US"), cftext);
     CFRelease(cftext);
   }
 
@@ -3185,10 +3200,24 @@ apple_init_profile(
   * Fill in the profile data...
   */
 
-  if (iccfile)
-    httpAssembleURI(HTTP_URI_CODING_ALL, url, sizeof(url), "file", NULL, "", 0,
-                   iccfile);
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+ if (iccfile)
+ {
+    url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, 
+                                                 (const UInt8 *)iccfile,
+                                                  strlen(iccfile), false);
+
+    if (url)
+    {
+      CFDictionarySetValue(profile, kColorSyncDeviceProfileURL, url);
+      CFRelease(url);
+    }
+  }
+
+  CFDictionarySetValue(profile, kColorSyncDeviceModeDescriptions, dict);
+  CFRelease(dict);
 
+#  else
   profile->dataVersion        = cmDeviceProfileInfoVersion1;
   profile->profileID          = id;
   profile->profileLoc.locType = iccfile ? cmPathBasedProfile : cmNoProfileBase;
@@ -3197,6 +3226,7 @@ apple_init_profile(
   if (iccfile)
     strlcpy(profile->profileLoc.u.pathLoc.path, iccfile,
            sizeof(profile->profileLoc.u.pathLoc.path));
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 }
 
 
@@ -3228,13 +3258,19 @@ apple_register_profiles(
   ppd_option_t         *cm_option;     /* Color model option */
   ppd_choice_t         *cm_choice;     /* Color model choice */
   int                  num_profiles;   /* Number of profiles */
-  CMError              error;          /* Last error */
+  CMError              error = 0;      /* Last error */
   unsigned             device_id,      /* Printer device ID */
                        profile_id,     /* Profile ID */
                        default_profile_id = 0;
                                        /* Default profile ID */
   CFMutableDictionaryRef device_name;  /* Printer device name dictionary */
   CFStringRef          printer_name;   /* Printer name string */
+  cups_array_t         *languages;     /* Languages array */
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+  CFMutableDictionaryRef profiles,     /* Dictionary of profiles */
+                       profile;        /* Current profile info dictionary */
+  CFStringRef          dict_key;       /* Key in factory profile dictionary */
+#  else
   CMDeviceScope                scope =         /* Scope of the registration */
                        {
                          kCFPreferencesAnyUser,
@@ -3242,15 +3278,21 @@ apple_register_profiles(
                        };
   CMDeviceProfileArrayPtr profiles;    /* Profiles */
   CMDeviceProfileInfo  *profile;       /* Current profile */
-  cups_array_t         *languages;     /* Languages array */
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 
 
  /*
   * Make sure ColorSync is available...
   */
 
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+  if (ColorSyncRegisterDevice == NULL)
+    return;
+
+#  else
   if (CMRegisterColorDevice == NULL)
     return;
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 
  /*
   * Try opening the PPD file for this printer...
@@ -3287,6 +3329,22 @@ apple_register_profiles(
       num_profiles ++;
     }
 
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+ /*
+  * Create a dictionary for the factory profiles...
+  */
+
+  profiles = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+                                      &kCFTypeDictionaryKeyCallBacks,
+                                      &kCFTypeDictionaryValueCallBacks);
+  if (!profiles)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                   "Unable to allocate memory for factory profiles.");
+    ppdClose(ppd);
+    return;
+  }
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 
  /*
   * If we have profiles, add them...
@@ -3356,6 +3414,7 @@ apple_register_profiles(
        q3_choice = NULL;
     }
 
+#  ifndef HAVE_COLORSYNCREGISTERDEVICE
    /*
     * Build the array of profiles...
     *
@@ -3365,17 +3424,22 @@ apple_register_profiles(
     if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for %d profiles",
-                     num_profiles);
+                      "Unable to allocate memory for factory profiles.");
       ppdClose(ppd);
       return;
     }
 
     profiles->profileCount = num_profiles;
-    languages              = _ppdGetLanguages(ppd);
+    profile = profiles->profiles;
+#  endif /* !HAVE_COLORSYNCREGISTERDEVICE */
+
+   /*
+    * Loop through the profiles listed in the PPD...
+    */
+
+    languages = _ppdGetLanguages(ppd);
 
-    for (profile = profiles->profiles,
-             attr = ppdFindAttr(ppd, profile_key, NULL);
+    for (attr = ppdFindAttr(ppd, profile_key, NULL);
         attr;
         attr = ppdFindNextAttr(ppd, profile_key, NULL))
       if (attr->spec[0] && attr->value && attr->value[0])
@@ -3409,10 +3473,38 @@ apple_register_profiles(
        else
          profile_id = atoi(attr->spec);
 
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+       profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+                                           &kCFTypeDictionaryKeyCallBacks,
+                                           &kCFTypeDictionaryValueCallBacks);
+       if (!profile)
+       {
+         cupsdLogMessage(CUPSD_LOG_ERROR,
+                         "Unable to allocate memory for color profile.");
+         CFRelease(profiles);
+         ppdClose(ppd);
+         return;
+       }
+
+       apple_init_profile(ppd, languages, profile, profile_id, attr->spec,
+                          attr->text[0] ? attr->text : attr->spec, iccfile);
+
+       dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
+                                           CFSTR("%u"), profile_id);
+       if (dict_key)
+       {
+         CFDictionarySetValue(profiles, dict_key, profile);
+         CFRelease(dict_key);
+       }
+
+       CFRelease(profile);
+
+#  else
         apple_init_profile(ppd, languages, profile, profile_id, attr->spec,
                           attr->text[0] ? attr->text : attr->spec, iccfile);
 
        profile ++;
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 
        /*
         * See if this is the default profile...
@@ -3469,21 +3561,26 @@ apple_register_profiles(
 
     num_profiles = cm_option->num_choices;
 
+#  ifndef HAVE_COLORSYNCREGISTERDEVICE
+   /*
+    * Create an array for the factory profiles...
+    */
+
     if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for %d profiles",
-                     num_profiles);
+                      "Unable to allocate memory for factory profiles.");
       ppdClose(ppd);
       return;
     }
 
     profiles->profileCount = num_profiles;
+    profile = profiles->profiles;
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 
-    for (profile = profiles->profiles, i = cm_option->num_choices,
-             cm_choice = cm_option->choices;
+    for (i = cm_option->num_choices, cm_choice = cm_option->choices;
          i > 0;
-        i --, cm_choice ++, profile ++)
+        i --, cm_choice ++)
     {
       if (!strcmp(cm_choice->choice, "Gray") ||
           !strcmp(cm_choice->choice, "Black"))
@@ -3500,8 +3597,37 @@ apple_register_profiles(
       snprintf(selector, sizeof(selector), "%s..", profile_name);
       profile_id = _ppdHashName(selector);
 
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+      profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+                                         &kCFTypeDictionaryKeyCallBacks,
+                                         &kCFTypeDictionaryValueCallBacks);
+      if (!profile)
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unable to allocate memory for color profile.");
+       CFRelease(profiles);
+       ppdClose(ppd);
+       return;
+      }
+
+      apple_init_profile(ppd, NULL, profile, profile_id, cm_choice->choice,
+                         cm_choice->text, NULL);
+
+      dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
+                                          CFSTR("%u"), profile_id);
+      if (dict_key)
+      {
+       CFDictionarySetValue(profiles, dict_key, profile);
+       CFRelease(dict_key);
+      }
+
+      CFRelease(profile);
+
+#  else
       apple_init_profile(ppd, NULL, profile, profile_id, cm_choice->choice,
                          cm_choice->text, NULL);
+      profile ++;
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 
       if (cm_choice->marked)
         default_profile_id = profile_id;
@@ -3517,31 +3643,133 @@ apple_register_profiles(
 
     num_profiles = (attr && ppd->colorspace == PPD_CS_GRAY) ? 1 : 2;
 
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+   /*
+    * Add the grayscale profile first.  We always have a grayscale profile.
+    */
+
+    profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+                                       &kCFTypeDictionaryKeyCallBacks,
+                                       &kCFTypeDictionaryValueCallBacks);
+
+    if (!profile)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to allocate memory for color profile.");
+      CFRelease(profiles);
+      ppdClose(ppd);
+      return;
+    }
+
+    profile_id = _ppdHashName("Gray..");
+    apple_init_profile(ppd, NULL, profile, profile_id, "Gray", "Gray", NULL);
+
+    dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"),
+                                        profile_id);
+    if (dict_key)
+    {
+      CFDictionarySetValue(profiles, dict_key, profile);
+      CFRelease(dict_key);
+    }
+
+    CFRelease(profile);
+
+   /*
+    * Then add the RGB/CMYK/DeviceN color profile...
+    */
+
+    profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+                                       &kCFTypeDictionaryKeyCallBacks,
+                                       &kCFTypeDictionaryValueCallBacks);
+
+    if (!profile)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to allocate memory for color profile.");
+      CFRelease(profiles);
+      ppdClose(ppd);
+      return;
+    }
+
+    switch (ppd->colorspace)
+    {
+      case PPD_CS_RGB :
+      case PPD_CS_CMY :
+          profile_id = _ppdHashName("RGB..");
+          apple_init_profile(ppd, NULL, profile, profile_id, "RGB", "RGB",
+                            NULL);
+          break;
+      case PPD_CS_RGBK :
+      case PPD_CS_CMYK :
+          profile_id = _ppdHashName("CMYK..");
+          apple_init_profile(ppd, NULL, profile, profile_id, "CMYK", "CMYK",
+                            NULL);
+          break;
+
+      case PPD_CS_GRAY :
+          if (attr)
+            break;
+
+      case PPD_CS_N :
+          profile_id = _ppdHashName("DeviceN..");
+          apple_init_profile(ppd, NULL, profile, profile_id, "DeviceN",
+                            "DeviceN", NULL);
+          break;
+    }
+
+    if (CFDictionaryGetCount(profile) > 0)
+    {
+      dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
+                                          CFSTR("%u"), profile_id);
+      if (dict_key)
+      {
+        CFDictionarySetValue(profiles, dict_key, profile);
+        CFRelease(dict_key);
+      }
+    }
+
+    CFRelease(profile);
+
+#  else
+   /*
+    * Create an array for the factory profiles...
+    */
+
     if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to allocate memory for %d profiles",
-                     num_profiles);
+                      "Unable to allocate memory for factory profiles.");
       ppdClose(ppd);
       return;
     }
 
     profiles->profileCount = num_profiles;
 
-    apple_init_profile(ppd, NULL, profiles->profiles, _ppdHashName("Gray.."),
-                       "Gray", "Gray", NULL);
+   /*
+    * Add the grayscale profile first.  We always have a grayscale profile.
+    */
+
+    profile_id = _ppdHashName("Gray..");
+    apple_init_profile(ppd, NULL, profiles->profiles, profile_id, "Gray",
+                       "Gray", NULL);
+
+   /*
+    * Then add the RGB/CMYK/DeviceN color profile...
+    */
 
     switch (ppd->colorspace)
     {
       case PPD_CS_RGB :
       case PPD_CS_CMY :
-          apple_init_profile(ppd, NULL, profiles->profiles + 1,
-                            _ppdHashName("RGB.."), "RGB", "RGB", NULL);
+          profile_id = _ppdHashName("RGB..");
+          apple_init_profile(ppd, NULL, profiles->profiles + 1, profile_id,
+                            "RGB", "RGB", NULL);
           break;
       case PPD_CS_RGBK :
       case PPD_CS_CMYK :
-          apple_init_profile(ppd, NULL, profiles->profiles + 1,
-                            _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL);
+          profile_id = _ppdHashName("CMYK..");
+          apple_init_profile(ppd, NULL, profiles->profiles + 1, profile_id,
+                            "CMYK", "CMYK", NULL);
           break;
 
       case PPD_CS_GRAY :
@@ -3549,11 +3777,12 @@ apple_register_profiles(
            break;
 
       case PPD_CS_N :
-          apple_init_profile(ppd, NULL, profiles->profiles + 1,
-                            _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
-                            NULL);
+          profile_id = _ppdHashName("DeviceN..");
+          apple_init_profile(ppd, NULL, profiles->profiles + 1, profile_id,
+                            "DeviceN", "DeviceN", NULL);
           break;
     }
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
   }
 
   if (num_profiles > 0)
@@ -3563,7 +3792,18 @@ apple_register_profiles(
     */
 
     if (!default_profile_id)
-      default_profile_id = profiles->profiles[num_profiles - 1].profileID;
+      default_profile_id = profile_id; /* Last profile */
+
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+    dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"),
+                                        default_profile_id);
+    if (dict_key)
+    {
+      CFDictionarySetValue(profiles, kColorSyncDeviceDefaultProfileID,
+                           dict_key);
+      CFRelease(dict_key);
+    }
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 
    /*
     * Get the device ID hash and pathelogical name dictionary.
@@ -3581,12 +3821,50 @@ apple_register_profiles(
 
     if (device_name && printer_name)
     {
-      CFDictionarySetValue(device_name, CFSTR("en"), printer_name);
+      CFDictionarySetValue(device_name, CFSTR("en_US"), printer_name);
 
      /*
       * Register the device with ColorSync...
       */
 
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+      CFTypeRef                deviceDictKeys[] =
+      {                                        /* Device keys */
+        kColorSyncDeviceDescriptions,
+       kColorSyncFactoryProfiles,
+       kColorSyncDeviceUserScope,
+       kColorSyncDeviceHostScope
+      };
+      CFTypeRef        deviceDictVals[] =
+      {                                        /* Device values */
+        device_name,
+       profiles,
+       kCFPreferencesAnyUser,
+       kCFPreferencesCurrentHost
+      };
+      CFDictionaryRef  deviceDict;     /* Device dictionary */
+      CFUUIDRef                deviceUUID;     /* Device UUID (TODO: use printer-uuid value) */
+
+      deviceDict = CFDictionaryCreate(kCFAllocatorDefault,
+                                     (const void **)deviceDictKeys,
+                                     (const void **)deviceDictVals,
+                                     sizeof(deviceDictKeys) /
+                                         sizeof(deviceDictVals),
+                                     &kCFTypeDictionaryKeyCallBacks,
+                                     &kCFTypeDictionaryValueCallBacks);
+      deviceUUID = ColorSyncCreateUUIDFromUInt32(device_id);
+      if (deviceDict && deviceUUID &&
+          !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass, deviceUUID,
+                                  deviceDict))
+       error = 1001;
+
+      if (deviceUUID)
+        CFRelease(deviceUUID);
+
+      if (deviceDict)
+        CFRelease(deviceDict);
+
+#  else
       error = CMRegisterColorDevice(cmPrinterDeviceClass, device_id,
                                     device_name, &scope);
 
@@ -3597,6 +3875,7 @@ apple_register_profiles(
       if (error == noErr)
        error = CMSetDeviceFactoryProfiles(cmPrinterDeviceClass, device_id,
                                           default_profile_id, profiles);
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
     }
     else
       error = 1000;
@@ -3607,22 +3886,34 @@ apple_register_profiles(
 
     if (error != noErr)
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                     "Unable to register ICC color profiles for \"%s\" - %d",
+                     "Unable to register ICC color profiles for \"%s\": %d",
                      p->name, (int)error);
 
+    if (printer_name)
+      CFRelease(printer_name);
+
+    if (device_name)
+      CFRelease(device_name);
+  }
+
+ /*
+  * Free any memory we used...
+  */
+
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+  CFRelease(profiles);
+
+#  else
+  if (num_profiles > 0)
+  {
     for (profile = profiles->profiles;
         num_profiles > 0;
         profile ++, num_profiles --)
       CFRelease(profile->profileName);
 
     free(profiles);
-
-    if (printer_name)
-      CFRelease(printer_name);
-
-    if (device_name)
-      CFRelease(device_name);
   }
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 
   ppdClose(ppd);
 }
@@ -3641,8 +3932,25 @@ apple_unregister_profiles(
   * Make sure ColorSync is available...
   */
 
+#  ifdef HAVE_COLORSYNCREGISTERDEVICE
+  if (ColorSyncUnregisterDevice != NULL)
+  {
+    CFUUIDRef deviceUUID;              /* Printer UUID */
+
+    deviceUUID = ColorSyncCreateUUIDFromUInt32(_ppdHashName(p->name));
+                                       /* TODO: Use printer-uuid value */
+
+    if (deviceUUID)
+    {
+      ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass, deviceUUID);
+      CFRelease(deviceUUID);
+    }
+  }
+
+#  else
   if (CMUnregisterColorDevice != NULL)
     CMUnregisterColorDevice(cmPrinterDeviceClass, _ppdHashName(p->name));
+#  endif /* HAVE_COLORSYNCREGISTERDEVICE */
 }
 #endif /* __APPLE__ */
 
@@ -4391,12 +4699,13 @@ check_rss_recipient(
  * 'check_quotas()' - Check quotas for a printer and user.
  */
 
-static int                             /* O - 1 if OK, 0 if not */
+static int                             /* O - 1 if OK, 0 if forbidden,
+                                              -1 if limit reached */
 check_quotas(cupsd_client_t  *con,     /* I - Client connection */
              cupsd_printer_t *p)       /* I - Printer or class */
 {
-  int          i;                      /* Looping var */
-  char         username[33];           /* Username */
+  char         username[33],           /* Username */
+               *name;                  /* Current user name */
   cupsd_quota_t        *q;                     /* Quota data */
 #ifdef HAVE_MBR_UID_TO_UUID
  /*
@@ -4441,7 +4750,7 @@ check_quotas(cupsd_client_t  *con,        /* I - Client connection */
     {
       cupsdLogMessage(CUPSD_LOG_INFO, "Too many jobs for printer \"%s\"...",
                       p->name);
-      return (0);
+      return (-1);
     }
   }
 
@@ -4455,7 +4764,7 @@ check_quotas(cupsd_client_t  *con,        /* I - Client connection */
     {
       cupsdLogMessage(CUPSD_LOG_INFO, "Too many jobs for user \"%s\"...",
                       username);
-      return (0);
+      return (-1);
     }
   }
 
@@ -4463,10 +4772,10 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
   * Check against users...
   */
 
-  if (p->num_users == 0 && p->k_limit == 0 && p->page_limit == 0)
+  if (cupsArrayCount(p->users) == 0 && p->k_limit == 0 && p->page_limit == 0)
     return (1);
 
-  if (p->num_users)
+  if (cupsArrayCount(p->users))
   {
 #ifdef HAVE_MBR_UID_TO_UUID
    /*
@@ -4497,21 +4806,22 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
     endpwent();
 #endif /* HAVE_MBR_UID_TO_UUID */
 
-    for (i = 0; i < p->num_users; i ++)
-      if (p->users[i][0] == '@')
+    for (name = (char *)cupsArrayFirst(p->users);
+         name;
+        name = (char *)cupsArrayNext(p->users))
+      if (name[0] == '@')
       {
        /*
         * Check group membership...
        */
 
 #ifdef HAVE_MBR_UID_TO_UUID
-        if (p->users[i][1] == '#')
+        if (name[1] == '#')
        {
-         if (uuid_parse((char *)p->users[i] + 2, grp_uuid))
+         if (uuid_parse(name + 2, grp_uuid))
            uuid_clear(grp_uuid);
        }
-       else if ((mbr_err = mbr_group_name_to_uuid((char *)p->users[i] + 1,
-                                                  grp_uuid)) != 0)
+       else if ((mbr_err = mbr_group_name_to_uuid(name + 1, grp_uuid)) != 0)
        {
         /*
          * Invalid ACL entries are ignored for matching; just record a
@@ -4520,10 +4830,10 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
 
          cupsdLogMessage(CUPSD_LOG_DEBUG,
                          "check_quotas: UUID lookup failed for ACL entry "
-                         "\"%s\" (err=%d)", p->users[i], mbr_err);
+                         "\"%s\" (err=%d)", name, mbr_err);
          cupsdLogMessage(CUPSD_LOG_WARN,
                          "Access control entry \"%s\" not a valid group name; "
-                         "entry ignored", p->users[i]);
+                         "entry ignored", name);
        }
 
        if ((mbr_err = mbr_check_membership(usr_uuid, grp_uuid,
@@ -4535,7 +4845,7 @@ check_quotas(cupsd_client_t  *con,        /* I - Client connection */
 
          cupsdLogMessage(CUPSD_LOG_DEBUG,
                          "check_quotas: group \"%s\" membership check "
-                         "failed (err=%d)", p->users[i] + 1, mbr_err);
+                         "failed (err=%d)", name + 1, mbr_err);
          is_member = 0;
        }
 
@@ -4547,20 +4857,19 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
          break;
 
 #else
-        if (cupsdCheckGroup(username, pw, p->users[i] + 1))
+        if (cupsdCheckGroup(username, pw, name + 1))
          break;
 #endif /* HAVE_MBR_UID_TO_UUID */
       }
 #ifdef HAVE_MBR_UID_TO_UUID
       else
       {
-        if (p->users[i][0] == '#')
+        if (name[0] == '#')
        {
-         if (uuid_parse((char *)p->users[i] + 1, usr2_uuid))
+         if (uuid_parse(name + 1, usr2_uuid))
            uuid_clear(usr2_uuid);
         }
-        else if ((mbr_err = mbr_user_name_to_uuid((char *)p->users[i],
-                                                 usr2_uuid)) != 0)
+        else if ((mbr_err = mbr_user_name_to_uuid(name, usr2_uuid)) != 0)
        {
         /*
          * Invalid ACL entries are ignored for matching; just record a
@@ -4569,21 +4878,21 @@ check_quotas(cupsd_client_t  *con,      /* I - Client connection */
 
           cupsdLogMessage(CUPSD_LOG_DEBUG,
                          "check_quotas: UUID lookup failed for ACL entry "
-                         "\"%s\" (err=%d)", p->users[i], mbr_err);
+                         "\"%s\" (err=%d)", name, mbr_err);
           cupsdLogMessage(CUPSD_LOG_WARN,
                          "Access control entry \"%s\" not a valid user name; "
-                         "entry ignored", p->users[i]);
+                         "entry ignored", name);
        }
 
        if (!uuid_compare(usr_uuid, usr2_uuid))
          break;
       }
 #else
-      else if (!strcasecmp(username, p->users[i]))
+      else if (!strcasecmp(username, name))
        break;
 #endif /* HAVE_MBR_UID_TO_UUID */
 
-    if ((i < p->num_users) == p->deny_users)
+    if ((name != NULL) == p->deny_users)
     {
       cupsdLogMessage(CUPSD_LOG_INFO,
                       "Denying user \"%s\" access to printer \"%s\"...",
@@ -4939,7 +5248,8 @@ copy_attrs(ipp_t        *to,              /* I - Destination request */
            ipp_t        *from,         /* I - Source request */
            cups_array_t *ra,           /* I - Requested attributes */
           ipp_tag_t    group,          /* I - Group to copy */
-          int          quickcopy)      /* I - Do a quick copy? */
+          int          quickcopy,      /* I - Do a quick copy? */
+          cups_array_t *exclude)       /* I - Attributes to exclude? */
 {
   ipp_attribute_t      *fromattr;      /* Source attribute */
 
@@ -4961,6 +5271,23 @@ copy_attrs(ipp_t        *to,             /* I - Destination request */
          fromattr->group_tag != IPP_TAG_ZERO) || !fromattr->name)
       continue;
 
+    if (exclude && 
+        (cupsArrayFind(exclude, fromattr->name) ||
+        cupsArrayFind(exclude, "all")))
+    {
+     /*
+      * We need to exclude this attribute for security reasons; we require the
+      * job-id and job-printer-uri attributes regardless of the security
+      * settings for IPP conformance.
+      *
+      * Subscription attribute security is handled by copy_subscription_attrs().
+      */
+
+      if (strcmp(fromattr->name, "job-id") &&
+         strcmp(fromattr->name, "job-printer-uri"))
+        continue;
+    }
+
     if (!ra || cupsArrayFind(ra, fromattr->name))
     {
      /*
@@ -5607,7 +5934,8 @@ copy_model(cupsd_client_t *con,           /* I - Client connection */
 static void
 copy_job_attrs(cupsd_client_t *con,    /* I - Client connection */
               cupsd_job_t    *job,     /* I - Job */
-              cups_array_t   *ra)      /* I - Requested attributes array */
+              cups_array_t   *ra,      /* I - Requested attributes array */
+              cups_array_t   *exclude) /* I - Private attributes array */
 {
   char job_uri[HTTP_MAX_URI];          /* Job URI */
 
@@ -5620,26 +5948,34 @@ copy_job_attrs(cupsd_client_t *con,     /* I - Client connection */
                    con->servername, con->serverport, "/jobs/%d",
                   job->id);
 
-  if (!ra || cupsArrayFind(ra, "document-count"))
-    ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                 "document-count", job->num_files);
+  if (!cupsArrayFind(exclude, "all"))
+  {
+    if ((!exclude || !cupsArrayFind(exclude, "document-count")) &&
+        (!ra || cupsArrayFind(ra, "document-count")))
+      ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                   "document-count", job->num_files);
 
-  if (!ra || cupsArrayFind(ra, "job-media-progress"))
-    ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                 "job-media-progress", job->progress);
+    if ((!exclude || !cupsArrayFind(exclude, "job-media-progress")) &&
+        (!ra || cupsArrayFind(ra, "job-media-progress")))
+      ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                   "job-media-progress", job->progress);
 
-  if (!ra || cupsArrayFind(ra, "job-more-info"))
-    ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
-                "job-more-info", NULL, job_uri);
+    if ((!exclude || !cupsArrayFind(exclude, "job-more-info")) &&
+        (!ra || cupsArrayFind(ra, "job-more-info")))
+      ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
+                  "job-more-info", NULL, job_uri);
 
-  if (job->state_value > IPP_JOB_PROCESSING &&
-      (!ra || cupsArrayFind(ra, "job-preserved")))
-    ippAddBoolean(con->response, IPP_TAG_JOB, "job-preserved",
-                  job->num_files > 0);
+    if (job->state_value > IPP_JOB_PROCESSING &&
+       (!exclude || !cupsArrayFind(exclude, "job-preserved")) &&
+        (!ra || cupsArrayFind(ra, "job-preserved")))
+      ippAddBoolean(con->response, IPP_TAG_JOB, "job-preserved",
+                   job->num_files > 0);
 
-  if (!ra || cupsArrayFind(ra, "job-printer-up-time"))
-    ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
-                  "job-printer-up-time", time(NULL));
+    if ((!exclude || !cupsArrayFind(exclude, "job-printer-up-time")) &&
+        (!ra || cupsArrayFind(ra, "job-printer-up-time")))
+      ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
+                   "job-printer-up-time", time(NULL));
+  }
 
   if (!ra || cupsArrayFind(ra, "job-state-reasons"))
     add_job_state_reasons(con, job);
@@ -5648,7 +5984,7 @@ copy_job_attrs(cupsd_client_t *con,       /* I - Client connection */
     ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
                 "job-uri", NULL, job_uri);
 
-  copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0);
+  copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0, exclude);
 }
 
 
@@ -5820,7 +6156,7 @@ copy_printer_attrs(
 
     for (i = 0; i < printer->num_history; i ++)
       copy_attrs(history->values[i].collection = ippNew(), printer->history[i],
-                 NULL, IPP_TAG_ZERO, 0);
+                 NULL, IPP_TAG_ZERO, 0, NULL);
   }
 
   if (!ra || cupsArrayFind(ra, "printer-state-message"))
@@ -5874,10 +6210,10 @@ copy_printer_attrs(
   if (!ra || cupsArrayFind(ra, "queued-job-count"))
     add_queued_job_count(con, printer);
 
-  copy_attrs(con->response, printer->attrs, ra, IPP_TAG_ZERO, 0);
+  copy_attrs(con->response, printer->attrs, ra, IPP_TAG_ZERO, 0, NULL);
   if (printer->ppd_attrs)
-    copy_attrs(con->response, printer->ppd_attrs, ra, IPP_TAG_ZERO, 0);
-  copy_attrs(con->response, CommonData, ra, IPP_TAG_ZERO, IPP_TAG_COPY);
+    copy_attrs(con->response, printer->ppd_attrs, ra, IPP_TAG_ZERO, 0, NULL);
+  copy_attrs(con->response, CommonData, ra, IPP_TAG_ZERO, IPP_TAG_COPY, NULL);
 }
 
 
@@ -5889,7 +6225,8 @@ static void
 copy_subscription_attrs(
     cupsd_client_t       *con,         /* I - Client connection */
     cupsd_subscription_t *sub,         /* I - Subscription */
-    cups_array_t         *ra)          /* I - Requested attributes array */
+    cups_array_t         *ra,          /* I - Requested attributes array */
+    cups_array_t         *exclude)     /* I - Private attributes array */
 {
   ipp_attribute_t      *attr;          /* Current attribute */
   char                 printer_uri[HTTP_MAX_URI];
@@ -5899,56 +6236,92 @@ copy_subscription_attrs(
   const char           *name;          /* Current event name */
 
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
+                 con, sub, ra, exclude);
+
  /*
   * Copy the subscription attributes to the response using the
   * requested-attributes attribute that may be provided by the client.
   */
 
-  if (!ra || cupsArrayFind(ra, "notify-events"))
+  if (!exclude || !cupsArrayFind(exclude, "all"))
   {
-    if ((name = cupsdEventName((cupsd_eventmask_t)sub->mask)) != NULL)
+    if ((!exclude || !cupsArrayFind(exclude, "notify-events")) &&
+        (!ra || cupsArrayFind(ra, "notify-events")))
     {
-     /*
-      * Simple event list...
-      */
+      cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_subscription_attrs: notify-events");
 
-      ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
-                   (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
-                   "notify-events", NULL, name);
-    }
-    else
-    {
-     /*
-      * Complex event list...
-      */
+      if ((name = cupsdEventName((cupsd_eventmask_t)sub->mask)) != NULL)
+      {
+       /*
+       * Simple event list...
+       */
 
-      for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
-       if (sub->mask & mask)
-          count ++;
+       ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
+                    (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
+                    "notify-events", NULL, name);
+      }
+      else
+      {
+       /*
+       * Complex event list...
+       */
 
-      attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
-                           (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
-                           "notify-events", count, NULL, NULL);
+       for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
+         if (sub->mask & mask)
+           count ++;
 
-      for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
-       if (sub->mask & mask)
-       {
-          attr->values[count].string.text =
-             (char *)cupsdEventName((cupsd_eventmask_t)mask);
+       attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
+                            (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
+                            "notify-events", count, NULL, NULL);
 
-          count ++;
-       }
+       for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
+         if (sub->mask & mask)
+         {
+           attr->values[count].string.text =
+               (char *)cupsdEventName((cupsd_eventmask_t)mask);
+
+           count ++;
+         }
+      }
     }
+
+    if ((!exclude || !cupsArrayFind(exclude, "notify-lease-duration")) &&
+        (!sub->job && (!ra || cupsArrayFind(ra, "notify-lease-duration"))))
+      ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+                   "notify-lease-duration", sub->lease);
+
+    if ((!exclude || !cupsArrayFind(exclude, "notify-recipient-uri")) &&
+        (sub->recipient && (!ra || cupsArrayFind(ra, "notify-recipient-uri"))))
+      ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
+                  "notify-recipient-uri", NULL, sub->recipient);
+    else if ((!exclude || !cupsArrayFind(exclude, "notify-pull-method")) &&
+             (!ra || cupsArrayFind(ra, "notify-pull-method")))
+      ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
+                  "notify-pull-method", NULL, "ippget");
+
+    if ((!exclude || !cupsArrayFind(exclude, "notify-subscriber-user-name")) &&
+        (!ra || cupsArrayFind(ra, "notify-subscriber-user-name")))
+      ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_NAME,
+                  "notify-subscriber-user-name", NULL, sub->owner);
+
+    if ((!exclude || !cupsArrayFind(exclude, "notify-time-interval")) &&
+        (!ra || cupsArrayFind(ra, "notify-time-interval")))
+      ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+                   "notify-time-interval", sub->interval);
+
+    if (sub->user_data_len > 0 &&
+       (!exclude || !cupsArrayFind(exclude, "notify-user-data")) &&
+        (!ra || cupsArrayFind(ra, "notify-user-data")))
+      ippAddOctetString(con->response, IPP_TAG_SUBSCRIPTION, "notify-user-data",
+                       sub->user_data, sub->user_data_len);
   }
 
   if (sub->job && (!ra || cupsArrayFind(ra, "notify-job-id")))
     ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
                   "notify-job-id", sub->job->id);
 
-  if (!sub->job && (!ra || cupsArrayFind(ra, "notify-lease-duration")))
-    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
-                  "notify-lease-duration", sub->lease);
-
   if (sub->dest && (!ra || cupsArrayFind(ra, "notify-printer-uri")))
   {
     httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
@@ -5958,28 +6331,9 @@ copy_subscription_attrs(
                 "notify-printer-uri", NULL, printer_uri);
   }
 
-  if (sub->recipient && (!ra || cupsArrayFind(ra, "notify-recipient-uri")))
-    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
-                "notify-recipient-uri", NULL, sub->recipient);
-  else if (!ra || cupsArrayFind(ra, "notify-pull-method"))
-    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
-                 "notify-pull-method", NULL, "ippget");
-
-  if (!ra || cupsArrayFind(ra, "notify-subscriber-user-name"))
-    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_NAME,
-                "notify-subscriber-user-name", NULL, sub->owner);
-
   if (!ra || cupsArrayFind(ra, "notify-subscription-id"))
     ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
                   "notify-subscription-id", sub->id);
-
-  if (!ra || cupsArrayFind(ra, "notify-time-interval"))
-    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
-                  "notify-time-interval", sub->interval);
-
-  if (sub->user_data_len > 0 && (!ra || cupsArrayFind(ra, "notify-user-data")))
-    ippAddOctetString(con->response, IPP_TAG_SUBSCRIPTION, "notify-user-data",
-                      sub->user_data, sub->user_data_len);
 }
 
 
@@ -7003,12 +7357,14 @@ get_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
   int          jobid;                  /* Job ID */
   cupsd_job_t  *job;                   /* Current job */
   cupsd_printer_t *printer;            /* Current printer */
-  char         scheme[HTTP_MAX_URI],   /* Method portion of URI */
+  cupsd_policy_t *policy;              /* Current security policy */
+  char         scheme[HTTP_MAX_URI],   /* Scheme portion of URI */
                username[HTTP_MAX_URI], /* Username portion of URI */
                host[HTTP_MAX_URI],     /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
   int          port;                   /* Port portion of URI */
-  cups_array_t *ra;                    /* Requested attributes array */
+  cups_array_t *ra,                    /* Requested attributes array */
+               *exclude;               /* Private attributes array */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_job_attrs(%p[%d], %s)", con,
@@ -7081,20 +7437,18 @@ get_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
     printer = cupsdFindDest(job->dest);
 
   if (printer)
-  {
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
-                                   NULL)) != HTTP_OK)
-    {
-      send_http_error(con, status, printer);
-      return;
-    }
-  }
-  else if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    policy = printer->op_policy_ptr;
+  else
+    policy = DefaultPolicyPtr;
+
+  if ((status = cupsdCheckPolicy(policy, con, job->username)) != HTTP_OK)
   {
     send_http_error(con, status, NULL);
     return;
   }
 
+  exclude = cupsdGetPrivateAttrs(policy, con, printer, job->username);
+
  /*
   * Copy attributes...
   */
@@ -7102,7 +7456,7 @@ get_job_attrs(cupsd_client_t  *con,       /* I - Client connection */
   cupsdLoadJob(job);
 
   ra = create_requested_array(con->request);
-  copy_job_attrs(con, job, ra);
+  copy_job_attrs(con, job, ra, exclude);
   cupsArrayDelete(ra);
 
   con->response->request.status.status_code = IPP_OK;
@@ -7136,7 +7490,9 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
   cupsd_job_t  *job;                   /* Current job pointer */
   cupsd_printer_t *printer;            /* Printer */
   cups_array_t *list;                  /* Which job list... */
-  cups_array_t *ra;                    /* Requested attributes array */
+  cups_array_t *ra,                    /* Requested attributes array */
+               *exclude;               /* Private attributes array */
+  cupsd_policy_t *policy;              /* Current policy */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs(%p[%d], %s)", con, con->http.fd,
@@ -7199,15 +7555,11 @@ get_jobs(cupsd_client_t  *con,          /* I - Client connection */
   */
 
   if (printer)
-  {
-    if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
-                                   NULL)) != HTTP_OK)
-    {
-      send_http_error(con, status, printer);
-      return;
-    }
-  }
-  else if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+    policy = printer->op_policy_ptr;
+  else
+    policy = DefaultPolicyPtr;
+
+  if ((status = cupsdCheckPolicy(policy, con, NULL)) != HTTP_OK)
   {
     send_http_error(con, status, NULL);
     return;
@@ -7394,7 +7746,12 @@ get_jobs(cupsd_client_t  *con,           /* I - Client connection */
       if (i > 0)
        ippAddSeparator(con->response);
 
-      copy_job_attrs(con, job, ra);
+      exclude = cupsdGetPrivateAttrs(job->printer ?
+                                         job->printer->op_policy_ptr :
+                                        policy, con, job->printer,
+                                        job->username);
+
+      copy_job_attrs(con, job, ra, exclude);
     }
   }
   else
@@ -7450,7 +7807,12 @@ get_jobs(cupsd_client_t  *con,           /* I - Client connection */
 
       count ++;
 
-      copy_job_attrs(con, job, ra);
+      exclude = cupsdGetPrivateAttrs(job->printer ?
+                                         job->printer->op_policy_ptr :
+                                        policy, con, job->printer,
+                                        job->username);
+
+      copy_job_attrs(con, job, ra, exclude);
     }
 
     cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: count=%d", count);
@@ -7576,7 +7938,7 @@ get_notifications(cupsd_client_t *con)    /* I - Client connection */
     * If we don't have any new events, nothing to do here...
     */
 
-    if (min_seq > (sub->first_event_id + sub->num_events))
+    if (min_seq > (sub->first_event_id + cupsArrayCount(sub->events)))
       continue;
 
    /*
@@ -7588,12 +7950,13 @@ get_notifications(cupsd_client_t *con)  /* I - Client connection */
     else
       j = min_seq - sub->first_event_id;
 
-    for (; j < sub->num_events; j ++)
+    for (; j < cupsArrayCount(sub->events); j ++)
     {
       ippAddSeparator(con->response);
 
-      copy_attrs(con->response, sub->events[j]->attrs, NULL,
-                IPP_TAG_EVENT_NOTIFICATION, 0);
+      copy_attrs(con->response,
+                 ((cupsd_event_t *)cupsArrayIndex(sub->events, j))->attrs, NULL,
+                IPP_TAG_EVENT_NOTIFICATION, 0, NULL);
     }
   }
 }
@@ -8161,7 +8524,8 @@ get_printers(cupsd_client_t *con, /* I - Client connection */
       * access...
       */
 
-      if (printer->num_users && username && !user_allowed(printer, username))
+      if (cupsArrayCount(printer->users) && username &&
+         !user_allowed(printer, username))
         continue;
 
      /*
@@ -8198,7 +8562,9 @@ get_subscription_attrs(
 {
   http_status_t                status;         /* Policy status */
   cupsd_subscription_t *sub;           /* Subscription */
-  cups_array_t         *ra;            /* Requested attributes array */
+  cupsd_policy_t       *policy;        /* Current security policy */
+  cups_array_t         *ra,            /* Requested attributes array */
+                       *exclude;       /* Private attributes array */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
@@ -8224,14 +8590,19 @@ get_subscription_attrs(
   * Check policy...
   */
 
-  if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr :
-                                             DefaultPolicyPtr,
-                                 con, sub->owner)) != HTTP_OK)
+  if (sub->dest)
+    policy = sub->dest->op_policy_ptr;
+  else
+    policy = DefaultPolicyPtr;
+
+  if ((status = cupsdCheckPolicy(policy, con, sub->owner)) != HTTP_OK)
   {
     send_http_error(con, status, sub->dest);
     return;
   }
 
+  exclude = cupsdGetPrivateAttrs(policy, con, sub->dest, sub->owner);
+
  /*
   * Copy the subscription attributes to the response using the
   * requested-attributes attribute that may be provided by the client.
@@ -8239,7 +8610,7 @@ get_subscription_attrs(
 
   ra = create_requested_array(con->request);
 
-  copy_subscription_attrs(con, sub, ra);
+  copy_subscription_attrs(con, sub, ra, exclude);
 
   cupsArrayDelete(ra);
 
@@ -8273,6 +8644,8 @@ get_subscriptions(cupsd_client_t  *con,   /* I - Client connection */
   int                  port;           /* Port portion of URI */
   cupsd_job_t          *job;           /* Job pointer */
   cupsd_printer_t      *printer;       /* Printer */
+  cupsd_policy_t       *policy;        /* Policy */
+  cups_array_t         *exclude;       /* Private attributes array */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
@@ -8336,9 +8709,12 @@ get_subscriptions(cupsd_client_t  *con,  /* I - Client connection */
   * Check policy...
   */
 
-  if ((status = cupsdCheckPolicy(printer ? printer->op_policy_ptr :
-                                           DefaultPolicyPtr,
-                                 con, NULL)) != HTTP_OK)
+  if (printer)
+    policy = printer->op_policy_ptr;
+  else
+    policy = DefaultPolicyPtr;
+
+  if ((status = cupsdCheckPolicy(policy, con, NULL)) != HTTP_OK)
   {
     send_http_error(con, status, printer);
     return;
@@ -8375,7 +8751,12 @@ get_subscriptions(cupsd_client_t  *con,  /* I - Client connection */
         (!username[0] || !strcasecmp(username, sub->owner)))
     {
       ippAddSeparator(con->response);
-      copy_subscription_attrs(con, sub, ra);
+
+      exclude = cupsdGetPrivateAttrs(sub->dest ? sub->dest->op_policy_ptr :
+                                                policy, con, sub->dest,
+                                                sub->owner);
+
+      copy_subscription_attrs(con, sub, ra, exclude);
 
       count ++;
       if (limit && count >= limit)
@@ -11197,7 +11578,7 @@ set_printer_defaults(
     }
     else if (!strcmp(attr->name, "requesting-user-name-allowed"))
     {
-      cupsdFreePrinterUsers(printer);
+      cupsdFreeStrings(&(printer->users));
 
       printer->deny_users = 0;
 
@@ -11206,12 +11587,12 @@ set_printer_defaults(
           strcmp(attr->values[0].string.text, "all")))
       {
        for (i = 0; i < attr->num_values; i ++)
-         cupsdAddPrinterUser(printer, attr->values[i].string.text);
+         cupsdAddString(&(printer->users), attr->values[i].string.text);
       }
     }
     else if (!strcmp(attr->name, "requesting-user-name-denied"))
     {
-      cupsdFreePrinterUsers(printer);
+      cupsdFreeStrings(&(printer->users));
 
       printer->deny_users = 1;
 
@@ -11220,7 +11601,7 @@ set_printer_defaults(
           strcmp(attr->values[0].string.text, "none")))
       {
        for (i = 0; i < attr->num_values; i ++)
-         cupsdAddPrinterUser(printer, attr->values[i].string.text);
+         cupsdAddString(&(printer->users), attr->values[i].string.text);
       }
     }
     else if (!strcmp(attr->name, "job-quota-period"))
@@ -11400,6 +11781,7 @@ static void
 start_printer(cupsd_client_t  *con,    /* I - Client connection */
               ipp_attribute_t *uri)    /* I - Printer URI */
 {
+  int                  i;              /* Temporary variable */
   http_status_t                status;         /* Policy status */
   cups_ptype_t         dtype;          /* Destination type (printer/class) */
   cupsd_printer_t      *printer;       /* Printer data */
@@ -11450,6 +11832,21 @@ start_printer(cupsd_client_t  *con,    /* I - Client connection */
 
   cupsdCheckJobs();
 
+ /*
+  * Check quotas...
+  */
+
+  if ((i = check_quotas(con, printer)) < 0)
+  {
+    send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached."));
+    return;
+  }
+  else if (i == 0)
+  {
+    send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Not allowed to print."));
+    return;
+  }
+
  /*
   * Everything was ok, so return OK status...
   */
@@ -11633,13 +12030,13 @@ static int                            /* O - 0 if not allowed, 1 if allowed */
 user_allowed(cupsd_printer_t *p,       /* I - Printer or class */
              const char      *username)        /* I - Username */
 {
-  int          i;                      /* Looping var */
   struct passwd        *pw;                    /* User password data */
   char         baseuser[256],          /* Base username */
-               *baseptr;               /* Pointer to "@" in base username */
+               *baseptr,               /* Pointer to "@" in base username */
+               *name;                  /* Current user name */
 
 
-  if (p->num_users == 0)
+  if (cupsArrayCount(p->users) == 0)
     return (1);
 
   if (!strcmp(username, "root"))
@@ -11662,31 +12059,33 @@ user_allowed(cupsd_printer_t *p,      /* I - Printer or class */
   pw = getpwnam(username);
   endpwent();
 
-  for (i = 0; i < p->num_users; i ++)
+  for (name = (char *)cupsArrayFirst(p->users);
+       name;
+       name = (char *)cupsArrayNext(p->users))
   {
-    if (p->users[i][0] == '@')
+    if (name[0] == '@')
     {
      /*
       * Check group membership...
       */
 
-      if (cupsdCheckGroup(username, pw, p->users[i] + 1))
+      if (cupsdCheckGroup(username, pw, name + 1))
         break;
     }
-    else if (p->users[i][0] == '#')
+    else if (name[0] == '#')
     {
      /*
       * Check UUID...
       */
 
-      if (cupsdCheckGroup(username, pw, p->users[i]))
+      if (cupsdCheckGroup(username, pw, name))
         break;
     }
-    else if (!strcasecmp(username, p->users[i]))
+    else if (!strcasecmp(username, name))
       break;
   }
 
-  return ((i < p->num_users) != p->deny_users);
+  return ((name != NULL) != p->deny_users);
 }