]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Merge changes from CUPS 1.4svn-r7366.
[thirdparty/cups.git] / scheduler / ipp.c
index 183b839ccdd549379b6b1638717b254f9a30f2dd..2c1ae3050ddc3a5ebdef2b137998ab599b302f56 100644 (file)
  *
  * Contents:
  *
+ *   cupsdProcessIPPRequest()    - Process an incoming IPP request.
+ *   cupsdTimeoutJob()           - Timeout a job waiting on job files.
+ *   accept_jobs()               - Accept print jobs to a printer.
+ *   add_class()                 - Add a class to the system.
+ *   add_file()                  - Add a file to a job.
+ *   add_job()                   - Add a job to a print queue.
+ *   add_job_state_reasons()     - Add the "job-state-reasons" attribute based
+ *                                 upon the job and printer state...
+ *   add_job_subscriptions()     - Add any subcriptions for a job.
+ *   add_job_uuid()              - Add job-uuid attribute to a job.
+ *   add_printer()               - Add a printer to the system.
+ *   add_printer_state_reasons() - Add the "printer-state-reasons" attribute
+ *                                 based upon the printer state...
+ *   add_queued_job_count()      - Add the "queued-job-count" attribute for the
+ *                                 specified printer or class.
+ *   apple_init_profile()        - Initialize a color profile.
+ *   apple_register_profiles()   - Register color profiles for a printer.
+ *   apple_unregister_profiles() - Remove color profiles for the specified
+ *                                 printer.
+ *   apply_printer_defaults()    - Apply printer default options to a job.
+ *   authenticate_job()          - Set job authentication info.
+ *   cancel_all_jobs()           - Cancel all print jobs.
+ *   cancel_job()                - Cancel a print job.
+ *   cancel_subscription()       - Cancel a subscription.
+ *   check_quotas()              - Check quotas for a printer and user.
+ *   copy_attribute()            - Copy a single attribute.
+ *   copy_attrs()                - Copy attributes from one request to another.
+ *   copy_banner()               - Copy a banner file to the requests directory
+ *                                 for the specified job.
+ *   copy_file()                 - Copy a PPD file or interface script...
+ *   copy_model()                - Copy a PPD model file, substituting default
+ *                                 values as needed...
+ *   copy_job_attrs()            - Copy job attributes.
+ *   copy_printer_attrs()        - Copy printer attributes.
+ *   copy_subscription_attrs()   - Copy subscription attributes.
+ *   create_job()                - Print a file to a printer or class.
+ *   create_requested_array()    - Create an array for the requested-attributes.
+ *   create_subscription()       - Create a notification subscription.
+ *   delete_printer()            - Remove a printer or class from the system.
+ *   get_default()               - Get the default destination.
+ *   get_devices()               - Get the list of available devices on the
+ *                                 local system.
+ *   get_document()              - Get a copy of a job file.
+ *   get_job_attrs()             - Get job attributes.
+ *   get_jobs()                  - Get a list of jobs for the specified printer.
+ *   get_notifications()         - Get events for a subscription.
+ *   get_ppd()                   - Get a named PPD from the local system.
+ *   get_ppds()                  - Get the list of PPD files on the local
+ *                                 system.
+ *   get_printer_attrs()         - Get printer attributes.
+ *   get_printers()              - Get a list of printers or classes.
+ *   get_subscription_attrs()    - Get subscription attributes.
+ *   get_subscriptions()         - Get subscriptions.
+ *   get_username()              - Get the username associated with a request.
+ *   hold_job()                  - Hold a print job.
+ *   move_job()                  - Move a job to a new destination.
+ *   ppd_parse_line()            - Parse a PPD default line.
+ *   print_job()                 - Print a file to a printer or class.
+ *   read_ps_job_ticket()        - Reads a job ticket embedded in a PS file.
+ *   reject_jobs()               - Reject print jobs to a printer.
+ *   release_job()               - Release a held print job.
+ *   renew_subscription()        - Renew an existing subscription...
+ *   restart_job()               - Restart an old print job.
+ *   save_auth_info()            - Save authentication information for a job.
+ *   save_krb5_creds()           - Save Kerberos credentials for the job.
+ *   send_document()             - Send a file to a printer or class.
+ *   send_http_error()           - Send a HTTP error back to the IPP client.
+ *   send_ipp_status()           - Send a status back to the IPP client.
+ *   set_default()               - Set the default destination...
+ *   set_job_attrs()             - Set job attributes.
+ *   set_printer_defaults()      - Set printer default options from a request.
+ *   start_printer()             - Start a printer.
+ *   stop_printer()              - Stop a printer.
+ *   url_encode_attr()           - URL-encode a string attribute.
+ *   url_encode_string()         - URL-encode a string.
+ *   user_allowed()              - See if a user is allowed to print to a queue.
+ *   validate_job()              - Validate printer options and destination.
+ *   validate_name()             - Make sure the printer name only contains
+ *                                 valid chars.
+ *   validate_user()             - Validate the user for the request.
  */
 
 /*
  */
 
 #include "cupsd.h"
+#include <cups/ppd-private.h>
 
 #ifdef HAVE_LIBPAPER
 #  include <paper.h>
@@ -63,9 +144,10 @@ static void add_printer_state_reasons(cupsd_client_t *con,
                                          cupsd_printer_t *p);
 static void    add_queued_job_count(cupsd_client_t *con, cupsd_printer_t *p);
 #ifdef __APPLE__
-static unsigned        apple_hash_name(const char *name);
-static void    apple_init_profile(CMDeviceProfileInfo *profile, unsigned id,
-                                  const char *name, const char *iccfile);
+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);
 static void    apple_register_profiles(cupsd_printer_t *p);
 static void    apple_unregister_profiles(cupsd_printer_t *p);
 #endif /* __APPLE__ */
@@ -2735,47 +2817,72 @@ add_queued_job_count(
 
 
 #ifdef __APPLE__
-/*
- * 'apple_hash_name()' - Calculate a 32-bit hash of a printer/profile name.
- */
-
-static unsigned                                /* O - Hash value */
-apple_hash_name(const char *name)      /* I - Printer/profile name */
-{
-  int          mult;                   /* Multiplier */
-  unsigned     hash = 0;               /* Hash value */
-
-
-  for (mult = 1; *name && mult <= 128; mult ++, name ++)
-    hash += (*name & 255) & mult;
-
-  return (hash);
-}
-
-
 /*
  * 'apple_init_profile()' - Initialize a color profile.
  */
 
 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 */
 {
   char                 url[1024];      /* URL for profile filename */
   CFMutableDictionaryRef dict;         /* Dictionary for name */
+  char                 *language;      /* Current language */
+  ppd_attr_t           *attr;          /* Profile attribute */
 
 
-  if (iccfile)
-    httpAssembleURI(HTTP_URI_CODING_ALL, url, sizeof(url), "file", NULL, "", 0,
-                   iccfile);
+ /*
+  * Build the profile name dictionary...
+  */
 
   dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
                                   &kCFTypeDictionaryKeyCallBacks,
                                   &kCFTypeDictionaryValueCallBacks);
 
+  CFDictionarySetValue(dict, CFSTR("en"),
+                      CFStringCreateWithCString(kCFAllocatorDefault,
+                                                text, kCFStringEncodingUTF8));
+
+  if (iccfile && languages)
+  {
+   /*
+    * Find localized names for the color profiles...
+    */
+
+    cupsArraySave(ppd->sorted_attrs);
+
+    for (language = (char *)cupsArrayFirst(languages);
+        language;
+        language = (char *)cupsArrayNext(languages))
+    {
+      if ((attr = _ppdLocalizedAttr(ppd, "cupsICCProfile", name,
+                                   language)) != NULL && attr->text[0])
+       CFDictionarySetValue(dict,
+                            CFStringCreateWithCString(kCFAllocatorDefault,
+                                                      language,
+                                                      kCFStringEncodingUTF8),
+                            CFStringCreateWithCString(kCFAllocatorDefault,
+                                                      attr->text,
+                                                      kCFStringEncodingUTF8));
+    }
+
+    cupsArrayRestore(ppd->sorted_attrs);
+  }
+
+ /*
+  * Fill in the profile data...
+  */
+
+  if (iccfile)
+    httpAssembleURI(HTTP_URI_CODING_ALL, url, sizeof(url), "file", NULL, "", 0,
+                   iccfile);
+
   profile->dataVersion        = cmDeviceProfileInfoVersion1;
   profile->profileID          = id;
   profile->profileLoc.locType = iccfile ? cmPathBasedProfile : cmNoProfileBase;
@@ -2784,20 +2891,6 @@ apple_init_profile(
   if (iccfile)
     strlcpy(profile->profileLoc.u.pathLoc.path, iccfile,
            sizeof(profile->profileLoc.u.pathLoc.path));
-
-  CFDictionarySetValue(dict, CFSTR("PMColorDeviceProfileID"),
-                      CFNumberCreate(kCFAllocatorDefault,
-                                     kCFNumberSInt32Type,
-                                     &profile->profileID));
-  CFDictionarySetValue(dict, CFSTR("PMColorDeviceProfileName"),
-                      CFStringCreateWithCString(kCFAllocatorDefault,
-                                                name,
-                                                kCFStringEncodingUTF8));
-  if (iccfile)
-    CFDictionarySetValue(dict, CFSTR("PMColorDeviceProfileURL"),
-                        CFStringCreateWithCString(kCFAllocatorDefault,
-                                                  url,
-                                                  kCFStringEncodingUTF8));
 }
 
 
@@ -2827,6 +2920,7 @@ apple_register_profiles(
                        };
   CMDeviceProfileArrayPtr profiles;    /* Profiles */
   CMDeviceProfileInfo  *profile;       /* Current profile */
+  cups_array_t         *languages;     /* Languages array */
 
 
  /*
@@ -2880,6 +2974,7 @@ apple_register_profiles(
     }
 
     profiles->profileCount = num_profiles;
+    languages              = _ppdGetLanguages(ppd);
 
     for (profile = profiles->profiles,
              attr = ppdFindAttr(ppd, "cupsICCProfile", NULL);
@@ -2900,11 +2995,14 @@ apple_register_profiles(
         if (access(iccfile, 0))
          continue;
 
-        apple_init_profile(profile, apple_hash_name(attr->spec), attr->spec,
+        apple_init_profile(ppd, languages, profile, _ppdHashName(attr->spec),
+                          attr->spec, attr->text[0] ? attr->text : attr->spec,
                           iccfile);
 
        profile ++;
       }
+
+    _ppdFreeLanguages(languages);
   }
   else if ((cm_option = ppdFindOption(ppd, "ColorModel")) != NULL)
   {
@@ -2944,17 +3042,20 @@ apple_register_profiles(
         i --, cm_choice ++)
       if (!strcmp(cm_choice->choice, "Gray"))
       {
-        apple_init_profile(profile, apple_hash_name("Gray.."), "Gray", NULL);
+        apple_init_profile(ppd, NULL, profile, _ppdHashName("Gray.."),
+                          "Gray", "Gray", NULL);
        profile ++;
       }
       else if (!strcmp(cm_choice->choice, "RGB"))
       {
-        apple_init_profile(profile, apple_hash_name("RGB.."), "RGB", NULL);
+        apple_init_profile(ppd, NULL, profile, _ppdHashName("RGB.."),
+                          "RGB", "RGB", NULL);
        profile ++;
       }
       else if (!strcmp(cm_choice->choice, "CMYK"))
       {
-        apple_init_profile(profile, apple_hash_name("CMYK.."), "CMYK", NULL);
+        apple_init_profile(ppd, NULL, profile, _ppdHashName("CMYK.."),
+                          "CMYK", "CMYK", NULL);
        profile ++;
       }
   }
@@ -2980,16 +3081,16 @@ apple_register_profiles(
     switch (ppd->colorspace)
     {
       case PPD_CS_GRAY :
-          apple_init_profile(profiles->profiles, apple_hash_name("Gray.."),
-                            "Gray", NULL);
+          apple_init_profile(ppd, NULL, profiles->profiles,
+                            _ppdHashName("Gray.."), "Gray", "Gray", NULL);
           break;
       case PPD_CS_RGB :
-          apple_init_profile(profiles->profiles, apple_hash_name("RGB.."),
-                            "RGB", NULL);
+          apple_init_profile(ppd, NULL, profiles->profiles,
+                            _ppdHashName("RGB.."), "RGB", "RGB", NULL);
           break;
       case PPD_CS_CMYK :
-          apple_init_profile(profiles->profiles, apple_hash_name("CMYK.."),
-                            "CMYK", NULL);
+          apple_init_profile(ppd, NULL, profiles->profiles,
+                            _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL);
           break;
 
       default :
@@ -3008,7 +3109,7 @@ apple_register_profiles(
     cupsdLogMessage(CUPSD_LOG_INFO, "Registering ICC color profiles for \"%s\"",
                    p->name);
 
-    id   = apple_hash_name(p->name);
+    id   = _ppdHashName(p->name);
     name = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
                                     &kCFTypeDictionaryKeyCallBacks,
                                     &kCFTypeDictionaryValueCallBacks);
@@ -3063,7 +3164,7 @@ static void
 apple_unregister_profiles(
     cupsd_printer_t *p)                        /* I - Printer */
 {
-  CMUnregisterColorDevice(cmPrinterDeviceClass, apple_hash_name(p->name));
+  CMUnregisterColorDevice(cmPrinterDeviceClass, _ppdHashName(p->name));
 }
 #endif /* __APPLE__ */