]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Added implicit/auto class code.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 9 Jun 1999 20:07:04 +0000 (20:07 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 9 Jun 1999 20:07:04 +0000 (20:07 +0000)
Implemented MaxRequestSize.

Fixed bug in StartJob() if the filter function failed.

Added code to disable core dumps and set the number of available
file descriptors to the max allowed.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@376 7a7537e8-13f0-0310-91df-b6672ffda945

scheduler/client.c
scheduler/dirsvc.c
scheduler/job.c
scheduler/main.c

index e280242ca07dbab5557637002e65bde8c7278ce5..edd9b57d7fb4b3496f19db39a4abedeeb420bae4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: client.c,v 1.19 1999/05/10 21:35:40 mike Exp $"
+ * "$Id: client.c,v 1.20 1999/06/09 20:07:02 mike Exp $"
  *
  *   Client routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -543,6 +543,28 @@ ReadClient(client_t *con)  /* I - Client to read from */
           break;
 
       case HTTP_POST_RECV :
+         /*
+         * See if the POST request includes a Content-Length field, and if
+         * so check the length against any limits that are set...
+         */
+
+          if (con->http.fields[HTTP_FIELD_CONTENT_LENGTH][0] &&
+             atoi(con->http.fields[HTTP_FIELD_CONTENT_LENGTH]) > MaxRequestSize &&
+             MaxRequestSize > 0)
+         {
+          /*
+           * Request too large...
+           */
+
+            if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
+           {
+             CloseClient(con);
+             return (0);
+           }
+
+           break;
+          }
+
          /*
          * See what kind of POST request this is; for IPP requests the
          * content-type field will be "application/ipp"...
@@ -804,8 +826,35 @@ ReadClient(client_t *con)  /* I - Client to read from */
        {
          if (con->file)
          {
+           fstat(con->file, &filestats);
            close(con->file);
            con->file = 0;
+
+            if (filestats.st_size > MaxRequestSize &&
+               MaxRequestSize > 0)
+           {
+            /*
+             * Request is too big; remove it and send an error...
+             */
+
+             unlink(con->filename);
+
+             if (con->request)
+             {
+              /*
+               * Delete any IPP request data...
+               */
+
+               ippDelete(con->request);
+               con->request = NULL;
+              }
+
+              if (!SendError(con, HTTP_REQUEST_TOO_LARGE))
+             {
+               CloseClient(con);
+               return (0);
+             }
+           }
          }
 
           if (con->request)
@@ -1565,5 +1614,5 @@ pipe_command(client_t *con,       /* I - Client connection */
 
 
 /*
- * End of "$Id: client.c,v 1.19 1999/05/10 21:35:40 mike Exp $".
+ * End of "$Id: client.c,v 1.20 1999/06/09 20:07:02 mike Exp $".
  */
index 62302247001555bf6e320628e441f6cfbb1d70db..f2eb65f644b8c8caa5adad6e1f988f6e3c9a0f0f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: dirsvc.c,v 1.18 1999/05/20 18:43:05 mike Exp $"
+ * "$Id: dirsvc.c,v 1.19 1999/06/09 20:07:03 mike Exp $"
  *
  *   Directory services routines for the Common UNIX Printing System (CUPS).
  *
@@ -147,6 +147,8 @@ StopBrowsing(void)
 void
 UpdateBrowseList(void)
 {
+  int          i;                      /* Looping var */
+  int          len;                    /* Length of name string */
   int          bytes;                  /* Number of bytes left */
   char         packet[1540];           /* Broadcast packet */
   cups_ptype_t type;                   /* Printer type */
@@ -158,8 +160,11 @@ UpdateBrowseList(void)
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
   int          port;                   /* Port portion of URI */
   char         name[IPP_MAX_NAME],     /* Name of printer */
-               *ptr;                   /* Pointer into hostname */
-  printer_t    *p;                     /* Printer information */
+               *hptr,                  /* Pointer into hostname */
+               *sptr;                  /* Pointer into ServerName */
+  printer_t    *p,                     /* Printer information */
+               *pclass,                /* Printer class */
+               *first;                 /* First printer in class */
 
 
  /*
@@ -199,8 +204,12 @@ UpdateBrowseList(void)
 
   type |= CUPS_PRINTER_REMOTE;
 
-  if ((ptr = strchr(host, '.')) != NULL)
-    *ptr = '\0';
+  hptr = strchr(host, '.');
+  sptr = strchr(ServerName, '.');
+
+  if (hptr != NULL && sptr != NULL &&
+      strcasecmp(hptr, sptr) == 0)
+    *hptr = '\0';
 
   if (type & CUPS_PRINTER_CLASS)
   {
@@ -269,6 +278,84 @@ UpdateBrowseList(void)
   p->state       = state;
   p->accepting   = state != IPP_PRINTER_STOPPED;
   p->browse_time = time(NULL);
+
+ /*
+  * Do auto-classing if needed...
+  */
+
+  if (ImplicitClasses)
+  {
+   /*
+    * Loop through all available printers and create classes as needed...
+    */
+
+    for (p = Printers, len = 0; p != NULL; p = p->next)
+    {
+     /*
+      * Skip classes...
+      */
+
+      if (p->type & CUPS_PRINTER_CLASS)
+      {
+        len = 0;
+        continue;
+      }
+
+     /*
+      * If len == 0, get the length of this printer name up to the "@"
+      * sign (if any).
+      */
+
+      if (len > 0 &&
+         strncasecmp(p->name, name + 3, len) == 0 &&
+         (p->name[len] == '\0' || p->name[len] == '@'))
+      {
+       /*
+       * We have more than one printer with the same name; see if
+       * we have a class, and if this printer is a member...
+       */
+
+        if ((pclass = FindClass(name)) == NULL)
+         pclass = AddClass(name);
+
+        if (first != NULL)
+       {
+          for (i = 0; i < pclass->num_printers; i ++)
+           if (pclass->printers[i] == first)
+             break;
+
+          if (i >= pclass->num_printers)
+           AddPrinterToClass(pclass, first);
+
+         first = NULL;
+       }
+
+        for (i = 0; i < pclass->num_printers; i ++)
+         if (pclass->printers[i] == p)
+           break;
+
+        if (i >= pclass->num_printers)
+         AddPrinterToClass(pclass, p);
+      }
+      else
+      {
+       /*
+        * First time around; just get name length and mark it as first
+       * in the list...
+       */
+
+       if ((hptr = strchr(p->name, '@')) != NULL)
+         len = hptr - p->name;
+       else
+         len = strlen(p->name);
+
+        strcpy(name, "Any");
+        strncpy(name + 3, p->name, len);
+       name[len + 3] = '\0';
+       first = p;
+      }
+    }
+  }
 }
 
 
@@ -340,5 +427,5 @@ SendBrowseList(void)
 
 
 /*
- * End of "$Id: dirsvc.c,v 1.18 1999/05/20 18:43:05 mike Exp $".
+ * End of "$Id: dirsvc.c,v 1.19 1999/06/09 20:07:03 mike Exp $".
  */
index 0abab06ab18cc3556e29a69b753e4869ae0dcdd7..ce5e4bce1e10acf8e6ad670bc3d03a7cc2215ab4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: job.c,v 1.24 1999/06/04 21:07:23 mike Exp $"
+ * "$Id: job.c,v 1.25 1999/06/09 20:07:04 mike Exp $"
  *
  *   Job management routines for the Common UNIX Printing System (CUPS).
  *
@@ -194,8 +194,10 @@ CheckJobs(void)
     {
       DEBUG_printf(("CheckJobs: current->dest = \'%s\'\n", current->dest));
 
-      if ((printer = FindPrinter(current->dest)) == NULL)
+      if (FindClass(current->dest) != NULL)
         printer = FindAvailablePrinter(current->dest);
+      else
+        printer = FindPrinter(current->dest);
 
       if (printer == NULL && FindClass(current->dest) == NULL)
       {
@@ -338,6 +340,7 @@ StartJob(int       id,              /* I - Job ID */
         LogMessage(LOG_ERROR, "Unable to convert file to printable format for job %s-%d!",
                   printer->name, current->id);
         CancelJob(current->id);
+       return;
       }
 
      /*
@@ -904,5 +907,5 @@ start_process(char *command,        /* I - Full path to command */
 
 
 /*
- * End of "$Id: job.c,v 1.24 1999/06/04 21:07:23 mike Exp $".
+ * End of "$Id: job.c,v 1.25 1999/06/09 20:07:04 mike Exp $".
  */
index 37bad6b8418d90b77c7c50bd22e47d6fdb34a281..a582ad6353261d47c074932bfa417741aec720a6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: main.c,v 1.18 1999/05/26 20:05:05 mike Exp $"
+ * "$Id: main.c,v 1.19 1999/06/09 20:07:04 mike Exp $"
  *
  *   Scheduler main loop for the Common UNIX Printing System (CUPS).
  *
@@ -35,6 +35,7 @@
 
 #define _MAIN_C_
 #include "cupsd.h"
+#include <sys/resource.h>
 
 
 /*
@@ -64,6 +65,7 @@ main(int  argc,                       /* I - Number of command-line arguments */
   listener_t           *lis;           /* Current listener */
   time_t               activity;       /* Activity timer */
   struct timeval       timeout;        /* select() timeout */
+  struct rlimit                limit;          /* Runtime limit */
 #ifdef HAVE_SIGACTION
   struct sigaction     action;         /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION */
@@ -105,6 +107,24 @@ main(int  argc,                    /* I - Number of command-line arguments */
   putenv("TZ=GMT");
   tzset();
 
+#ifndef DEBUG
+ /*
+  * Disable core dumps...
+  */
+
+  getrlimit(RLIMIT_CORE, &limit);
+  limit.rlim_cur = 0;
+  setrlimit(RLIMIT_CORE, &limit);
+#endif /* DEBUG */
+
+ /*
+  * Set the maximum number of files...
+  */
+
+  getrlimit(RLIMIT_NOFILE, &limit);
+  limit.rlim_cur = limit.rlim_max;
+  setrlimit(RLIMIT_NOFILE, &limit);
+
  /*
   * Catch hangup and child signals and ignore broken pipes...
   */
@@ -381,5 +401,5 @@ usage(void)
 
 
 /*
- * End of "$Id: main.c,v 1.18 1999/05/26 20:05:05 mike Exp $".
+ * End of "$Id: main.c,v 1.19 1999/06/09 20:07:04 mike Exp $".
  */