]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/cups-lpd.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / cups-lpd.c
index 60b68090fc708815f8385a88f64a2ec6d35e3e47..55febeb3e250e8da70470a8cbe82d4161de5a387 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: cups-lpd.c 5455 2006-04-24 13:49:59Z mike $"
+ * "$Id: cups-lpd.c 6670 2007-07-13 23:15:02Z mike $"
  *
  *   Line Printer Daemon interface for the Common UNIX Printing System (CUPS).
  *
+ *   Copyright 2007 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  * Contents:
  *
@@ -96,7 +87,8 @@ static int    get_printer(http_t *http, const char *name, char *dest,
                            int destsize, cups_option_t **options,
                            int *accepting, int *shared, ipp_pstate_t *state);
 static int     print_file(http_t *http, int id, const char *filename,
-                          const char *docname, const char *user, int last);
+                          const char *docname, const char *user,
+                          const char *format, int last);
 static int     recv_print_job(const char *name, int num_defaults,
                               cups_option_t *defaults);
 static int     remove_jobs(const char *name, const char *agent,
@@ -150,8 +142,6 @@ main(int  argc,                             /* I - Number of command-line arguments */
   num_defaults = 0;
   defaults     = NULL;
   hostlookups  = 1;
-  num_defaults = cupsAddOption("job-originating-host-name", hostname,
-                               num_defaults, &defaults);
 
   for (i = 1; i < argc; i ++)
     if (argv[i][0] == '-')
@@ -217,6 +207,9 @@ main(int  argc,                             /* I - Number of command-line arguments */
            hostip);
   }
 
+  num_defaults = cupsAddOption("job-originating-host-name", hostname,
+                               num_defaults, &defaults);
+
  /*
   * RFC1179 specifies that only 1 daemon command can be received for
   * every connection.
@@ -448,14 +441,41 @@ get_printer(http_t        *http,  /* I - HTTP connection */
     *options = NULL;
 
  /*
-  * If the queue name contains a space, lookup the printer-name using
-  * the printer-info value...
+  * See if the name is a queue name optionally with an instance name.
+  */
+
+  strlcpy(dest, name, destsize);
+  if ((value = strchr(dest, '/')) != NULL)
+    *value = '\0';
+
+ /*
+  * Setup the Get-Printer-Attributes request...
+  */
+
+  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+
+  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+                  "localhost", 0, "/printers/%s", dest);
+
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+              NULL, uri);
+
+  ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+               "requested-attributes",
+               (int)(sizeof(requested) / sizeof(requested[0])),
+               NULL, requested);
+
+ /*
+  * Do the request...
   */
 
-  if (strchr(name, ' '))
+  response = cupsDoRequest(http, request, "/");
+
+  if (!response || cupsLastError() > IPP_OK_CONFLICT)
   {
    /*
-    * Lookup the printer-info...
+    * If we can't find the printer by name, look up the printer-name
+    * using the printer-info values...
     */
 
     ipp_attribute_t    *accepting_attr,/* printer-is-accepting-jobs */
@@ -465,13 +485,15 @@ get_printer(http_t        *http,  /* I - HTTP connection */
                        *state_attr;    /* printer-state */
 
 
+    ippDelete(response);
+
    /*
     * Setup the CUPS-Get-Printers request...
     */
 
     request = ippNewRequest(CUPS_GET_PRINTERS);
 
-    ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+    ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
                   "requested-attributes",
                  (int)(sizeof(requested) / sizeof(requested[0])),
                   NULL, requested);
@@ -575,89 +597,46 @@ get_printer(http_t        *http,  /* I - HTTP connection */
 
     name = dest;
   }
-  else
-  {
-   /*
-    * Otherwise treat it as a queue name optionally with an instance name.
-    */
-
-    strlcpy(dest, name, destsize);
-    if ((value = strchr(dest, '/')) != NULL)
-      *value = '\0';
 
-   /*
-    * Setup the Get-Printer-Attributes request...
-    */
-
-    request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
-
-    httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                     "localhost", 0, "/printers/%s", dest);
-
-    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
-                NULL, uri);
-
-    ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
-                  "requested-attributes",
-                 (int)(sizeof(requested) / sizeof(requested[0])),
-                  NULL, requested);
-
-   /*
-    * Do the request...
-    */
-
-    response = cupsDoRequest(http, request, "/");
-
-    if (!response || cupsLastError() > IPP_OK_CONFLICT)
-    {
-      syslog(LOG_ERR, "Unable to check printer status - %s",
-             cupsLastErrorString());
-
-      ippDelete(response);
-
-      return (-1);
-    }
-
-   /*
-    * Get values from the response...
-    */
-
-    if (accepting)
-    {
-      if ((attr = ippFindAttribute(response, "printer-is-accepting-jobs",
-                                  IPP_TAG_BOOLEAN)) == NULL)
-       syslog(LOG_ERR, "No printer-is-accepting-jobs attribute found in "
-                       "response from server!");
-      else
-       *accepting = attr->values[0].boolean;
-    }
+ /*
+  * Get values from the response...
+  */
 
-    if (shared)
-    {
-      if ((attr = ippFindAttribute(response, "printer-is-shared",
-                                  IPP_TAG_BOOLEAN)) == NULL)
-      {
-       syslog(LOG_ERR, "No printer-is-shared attribute found in "
-                       "response from server!");
-       *shared = 1;
-      }
-      else
-       *shared = attr->values[0].boolean;
-    }
+  if (accepting)
+  {
+    if ((attr = ippFindAttribute(response, "printer-is-accepting-jobs",
+                                IPP_TAG_BOOLEAN)) == NULL)
+      syslog(LOG_ERR, "No printer-is-accepting-jobs attribute found in "
+                     "response from server!");
+    else
+      *accepting = attr->values[0].boolean;
+  }
 
-    if (state)
+  if (shared)
+  {
+    if ((attr = ippFindAttribute(response, "printer-is-shared",
+                                IPP_TAG_BOOLEAN)) == NULL)
     {
-      if ((attr = ippFindAttribute(response, "printer-state",
-                                  IPP_TAG_INTEGER)) == NULL)
-       syslog(LOG_ERR, "No printer-state attribute found in "
-                       "response from server!");
-      else
-       *state = (ipp_pstate_t)attr->values[0].integer;
+      syslog(LOG_ERR, "No printer-is-shared attribute found in "
+                     "response from server!");
+      *shared = 1;
     }
+    else
+      *shared = attr->values[0].boolean;
+  }
 
-    ippDelete(response);
+  if (state)
+  {
+    if ((attr = ippFindAttribute(response, "printer-state",
+                                IPP_TAG_ENUM)) == NULL)
+      syslog(LOG_ERR, "No printer-state attribute found in "
+                     "response from server!");
+    else
+      *state = (ipp_pstate_t)attr->values[0].integer;
   }
 
+  ippDelete(response);
+
  /*
   * Override shared value for LPD using system-specific APIs...
   */
@@ -823,6 +802,7 @@ print_file(http_t     *http,                /* I - HTTP connection */
           const char *filename,        /* I - File to print */
            const char *docname,                /* I - document-name */
           const char *user,            /* I - requesting-user-name */
+          const char *format,          /* I - document-format */
           int        last)             /* I - 1 = last file in job */
 {
   ipp_t                *request;               /* IPP request */
@@ -845,6 +825,10 @@ print_file(http_t     *http,               /* I - HTTP connection */
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
                 "document-name", NULL, docname);
 
+  if (format)
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
+                 "document-format", NULL, format);
+
   if (last)
     ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1);
 
@@ -1277,6 +1261,8 @@ recv_print_job(
                docnumber ++;
 
                if (print_file(http, id, temp[i], docname, user,
+                              cupsGetOption("document-format", num_options,
+                                            options),
                               docnumber == doccount))
                   status = 1;
                else
@@ -1387,7 +1373,7 @@ remove_jobs(const char *dest,             /* I - Destination */
       return (1);
     }
     else
-      syslog(LOG_INFO, "Job ID %d cancelled", id);
+      syslog(LOG_INFO, "Job ID %d canceled", id);
   }
 
   httpClose(http);
@@ -1716,5 +1702,5 @@ smart_gets(char *s,                       /* I - Pointer to line buffer */
 
 
 /*
- * End of "$Id: cups-lpd.c 5455 2006-04-24 13:49:59Z mike $".
+ * End of "$Id: cups-lpd.c 6670 2007-07-13 23:15:02Z mike $".
  */