]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/cups-deviced.c
Update svn:keyword properties.
[thirdparty/cups.git] / scheduler / cups-deviced.c
index d35940c0786c7745ebf0400760a53228fefca63b..0cd5b8ea8c4042065ae87a2c5c315a40cffb6871 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: cups-deviced.c 7816 2008-07-30 20:53:31Z mike $"
+ * "$Id$"
  *
- *   Device scanning mini-daemon for the Common UNIX Printing System (CUPS).
+ *   Device scanning mini-daemon for CUPS.
  *
- *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -17,7 +17,6 @@
  *   main()                 - Scan for devices and return an IPP response.
  *   add_device()           - Add a new device to the list.
  *   compare_devices()      - Compare device names to eliminate duplicates.
- *   create_strings_array() - Create a CUPS array of strings.
  *   get_current_time()     - Get the current time as a double value in seconds.
  *   get_device()           - Get a device from a backend.
  *   process_children()     - Process all dead children...
@@ -108,7 +107,6 @@ static int          add_device(const char *device_class,
                                   const char *device_location);
 static int             compare_devices(cupsd_device_t *p0,
                                        cupsd_device_t *p1);
-static cups_array_t    *create_strings_array(const char *s);
 static double          get_current_time(void);
 static int             get_device(cupsd_backend_t *backend);
 static void            process_children(void);
@@ -140,7 +138,8 @@ main(int  argc,                             /* I - Number of command-line args */
   int          num_options;            /* Number of options */
   cups_option_t        *options;               /* Options */
   cups_array_t *requested,             /* requested-attributes values */
-               *exclude;               /* exclude-schemes values */
+               *exclude,               /* exclude-schemes values */
+               *include;               /* include-schemes values */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;             /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
@@ -192,10 +191,12 @@ main(int  argc,                           /* I - Number of command-line args */
   }
 
   num_options = cupsParseOptions(argv[5], 0, &options);
-  requested   = create_strings_array(cupsGetOption("requested-attributes",
-                                                   num_options, options));
-  exclude     = create_strings_array(cupsGetOption("exclude-schemes",
-                                                   num_options, options));
+  requested   = cupsdCreateStringsArray(cupsGetOption("requested-attributes",
+                                                      num_options, options));
+  exclude     = cupsdCreateStringsArray(cupsGetOption("exclude-schemes",
+                                                      num_options, options));
+  include     = cupsdCreateStringsArray(cupsGetOption("include-schemes",
+                                                      num_options, options));
 
   if (!requested || cupsArrayFind(requested, "all") != NULL)
   {
@@ -267,7 +268,12 @@ main(int  argc,                            /* I - Number of command-line args */
         (dent->fileinfo.st_mode & (S_IRUSR | S_IXUSR)) != (S_IRUSR | S_IXUSR))
       continue;
 
-    if (cupsArrayFind(exclude, dent->filename))
+   /*
+    * Skip excluded or not included backends...
+    */
+
+    if (cupsArrayFind(exclude, dent->filename) ||
+        (include && !cupsArrayFind(include, dent->filename)))
       continue;
 
    /*
@@ -307,11 +313,22 @@ main(int  argc,                           /* I - Number of command-line args */
     {
       for (i = 0; i < num_backends; i ++)
         if (backend_fds[i].revents && backends[i].pipe)
-         if (get_device(backends + i))
+       {
+         cups_file_t *bpipe = backends[i].pipe;
+                                       /* Copy of pipe for backend... */
+
+         do
          {
-           backend_fds[i].fd     = 0;
-           backend_fds[i].events = 0;
+           if (get_device(backends + i))
+           {
+             backend_fds[i].fd     = 0;
+             backend_fds[i].events = 0;
+             break;
+           }
          }
+         while (bpipe->ptr &&
+                memchr(bpipe->ptr, '\n', bpipe->end - bpipe->ptr));
+        }
     }
 
    /*
@@ -440,53 +457,10 @@ compare_devices(cupsd_device_t *d0,       /* I - First device */
 
   if ((diff = cupsdCompareNames(d0->device_info, d1->device_info)) != 0)
     return (diff);
-  else if ((diff = strcasecmp(d0->device_class, d1->device_class)) != 0)
+  else if ((diff = _cups_strcasecmp(d0->device_class, d1->device_class)) != 0)
     return (diff);
   else
-    return (strcasecmp(d0->device_uri, d1->device_uri));
-}
-
-
-/*
- * 'create_strings_array()' - Create a CUPS array of strings.
- */
-
-static cups_array_t *                  /* O - CUPS array */
-create_strings_array(const char *s)    /* I - Comma-delimited strings */
-{
-  cups_array_t *a;                     /* CUPS array */
-  const char   *start,                 /* Start of string */
-               *end;                   /* End of string */
-  char         *ptr;                   /* New string */
-
-
-  if (!s)
-    return (NULL);
-
-  if ((a = cupsArrayNew((cups_array_func_t)strcmp, NULL)) != NULL)
-  {
-    for (start = end = s; *end; start = end + 1)
-    {
-     /*
-      * Find the end of the current delimited string...
-      */
-
-      if ((end = strchr(start, ',')) == NULL)
-        end = start + strlen(start);
-
-     /*
-      * Duplicate the string and add it to the array...
-      */
-
-      if ((ptr = calloc(1, end - start + 1)) == NULL)
-        break;
-
-      memcpy(ptr, start, end - start);
-      cupsArrayAdd(a, ptr);
-    }
-  }
-
-  return (a);
+    return (_cups_strcasecmp(d0->device_uri, d1->device_uri));
 }
 
 
@@ -793,6 +767,10 @@ start_backend(const char *name,            /* I - Backend to run */
 
   snprintf(program, sizeof(program), "%s/backend/%s", server_bin, name);
 
+  if (_cupsFileCheck(program, _CUPS_FILE_CHECK_PROGRAM, !geteuid(),
+                     _cupsFileCheckFilter, NULL))
+    return (-1);
+
   backend = backends + num_backends;
 
   argv[0] = (char *)name;
@@ -828,5 +806,5 @@ start_backend(const char *name,             /* I - Backend to run */
 
 
 /*
- * End of "$Id: cups-deviced.c 7816 2008-07-30 20:53:31Z mike $".
+ * End of "$Id$".
  */