]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/cups-lpd.c
Import CUPS v2.0.3
[thirdparty/cups.git] / scheduler / cups-lpd.c
index 15b855072369d632c7d4f381513f3b3063b400c8..7ce14ef62839589cd5ab9ba752c9e82c1c0ff4dd 100644 (file)
@@ -1,27 +1,16 @@
 /*
- * "$Id: cups-lpd.c 7899 2008-09-03 12:57:17Z mike $"
+ * "$Id: cups-lpd.c 12612 2015-05-06 15:30:50Z msweet $"
  *
- *   Line Printer Daemon interface for CUPS.
+ * Line Printer Daemon interface for CUPS.
  *
- *   Copyright 2007-2012 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
- *   These coded instructions, statements, and computer programs are the
- *   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:
- *
- *   main()           - Process an incoming LPD request...
- *   create_job()     - Create a new print job.
- *   get_printer()    - Get the named printer and its options.
- *   print_file()     - Add a file to the current job.
- *   recv_print_job() - Receive a print job from the client.
- *   remove_jobs()    - Cancel one or more jobs.
- *   send_state()     - Send the queue state.
- *   smart_gets()     - Get a line of text, removing the trailing CR and/or LF.
+ * These coded instructions, statements, and computer programs are the
+ * 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/".
  */
 
 /*
@@ -70,7 +59,7 @@ static int    create_job(http_t *http, const char *dest, const char *title,
                            const char *docname, const char *user,
                           int num_options, cups_option_t *options);
 static int     get_printer(http_t *http, const char *name, char *dest,
-                           int destsize, cups_option_t **options,
+                           size_t 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,
@@ -230,8 +219,10 @@ main(int  argc,                            /* I - Number of command-line arguments */
   * resource list, and/or user name.
   */
 
-  command = line[0];
-  dest    = line + 1;
+  if ((command = line[0]) == '\0')
+    dest = line;
+  else
+    dest = line + 1;
 
   if (command == 0x02)
     list = NULL;
@@ -268,21 +259,21 @@ main(int  argc,                           /* I - Number of command-line arguments */
         syslog(LOG_INFO, "Receive print job for %s", dest);
         /* recv_print_job() sends initial status byte */
 
-        status = recv_print_job(dest, num_defaults, defaults);
+        status = (char)recv_print_job(dest, num_defaults, defaults);
        break;
 
     case 0x03 : /* Send queue state (short) */
         syslog(LOG_INFO, "Send queue state (short) for %s %s", dest, list);
        /* no status byte for this command */
 
-        status = send_state(dest, list, 0);
+        status = (char)send_state(dest, list, 0);
        break;
 
     case 0x04 : /* Send queue state (long) */
         syslog(LOG_INFO, "Send queue state (long) for %s %s", dest, list);
        /* no status byte for this command */
 
-        status = send_state(dest, list, 1);
+        status = (char)send_state(dest, list, 1);
        break;
 
     case 0x05 : /* Remove jobs */
@@ -300,7 +291,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
          syslog(LOG_INFO, "Remove jobs %s on %s by %s", list, dest, agent);
 
-         status = remove_jobs(dest, agent, list);
+         status = (char)remove_jobs(dest, agent, list);
         }
        else
          status = 1;
@@ -409,7 +400,7 @@ static int                          /* O - Number of options or -1 on error */
 get_printer(http_t        *http,       /* I - HTTP connection */
             const char    *name,       /* I - Printer name from request */
            char          *dest,        /* I - Destination buffer */
-            int           destsize,    /* I - Size of destination buffer */
+            size_t        destsize,    /* I - Size of destination buffer */
            cups_option_t **options,    /* O - Printer options */
            int           *accepting,   /* O - printer-is-accepting-jobs value */
            int           *shared,      /* O - printer-is-shared value */
@@ -744,7 +735,7 @@ print_file(http_t     *http,                /* I - HTTP connection */
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
                  "document-format", NULL, format);
 
-  ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", last);
+  ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", (char)last);
 
  /*
   * Do the request...
@@ -781,7 +772,8 @@ recv_print_job(
   int          fd;                     /* Temporary file */
   FILE         *fp;                    /* File pointer */
   char         filename[1024];         /* Temporary filename */
-  int          bytes;                  /* Bytes received */
+  ssize_t      bytes;                  /* Bytes received */
+  size_t       total;                  /* Total bytes */
   char         line[256],              /* Line from file/stdin */
                command,                /* Command from line */
                *count,                 /* Number of bytes */
@@ -965,15 +957,15 @@ recv_print_job(
     * Copy the data or control file from the client...
     */
 
-    for (i = atoi(count); i > 0; i -= bytes)
+    for (total = (size_t)strtoll(count, NULL, 10); total > 0; total -= (size_t)bytes)
     {
-      if (i > sizeof(line))
-        bytes = sizeof(line);
+      if (total > sizeof(line))
+        bytes = (ssize_t)sizeof(line);
       else
-        bytes = i;
+        bytes = (ssize_t)total;
 
-      if ((bytes = fread(line, 1, bytes, stdin)) > 0)
-        bytes = write(fd, line, bytes);
+      if ((bytes = (ssize_t)fread(line, 1, (size_t)bytes, stdin)) > 0)
+        bytes = write(fd, line, (size_t)bytes);
 
       if (bytes < 1)
       {
@@ -1609,7 +1601,7 @@ smart_gets(char *s,                       /* I - Pointer to line buffer */
       break;
     }
     else if (ptr < end)
-      *ptr++ = ch;
+      *ptr++ = (char)ch;
   }
 
   *ptr = '\0';
@@ -1622,5 +1614,5 @@ smart_gets(char *s,                       /* I - Pointer to line buffer */
 
 
 /*
- * End of "$Id: cups-lpd.c 7899 2008-09-03 12:57:17Z mike $".
+ * End of "$Id: cups-lpd.c 12612 2015-05-06 15:30:50Z msweet $".
  */