]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/printers.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / printers.c
index 1beabcf1fda2385e040784f48417184ad7a2307f..c987f1605f908433b71bda780311415ec91e1c67 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: printers.c 5533 2006-05-16 19:45:14Z mike $"
+ * "$Id: printers.c 5686 2006-06-21 21:02:56Z mike $"
  *
  *   Printer routines for the Common UNIX Printing System (CUPS).
  *
@@ -62,6 +62,7 @@
  */
 
 #include "cupsd.h"
+#include <cups/dir.h>
 
 
 /*
@@ -257,6 +258,11 @@ cupsdCreateCommonData(void)
 {
   int                  i;              /* Looping var */
   ipp_attribute_t      *attr;          /* Attribute data */
+  cups_dir_t           *dir;           /* Notifier directory */
+  cups_dentry_t                *dent;          /* Notifier directory entry */
+  cups_array_t         *notifiers;     /* Notifier array */
+  char                 filename[1024], /* Filename */
+                       *notifier;      /* Current notifier */
   static const int nups[] =            /* number-up-supported values */
                { 1, 2, 4, 6, 9, 16 };
   static const ipp_orient_t orients[4] =/* orientation-requested-supported values */
@@ -406,6 +412,10 @@ cupsdCreateCommonData(void)
   /* copies-supported */
   ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies);
 
+  /* document-format-default */
+  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
+               "document-format-default", NULL, "application/octet-stream");
+
   /* generated-natural-language-supported */
   ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
                "generated-natural-language-supported", NULL, DefaultLanguage);
@@ -498,11 +508,11 @@ cupsdCreateCommonData(void)
   ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
                "notify-max-events-supported", MaxEvents);
 
-  /* notify-notify-events-default */
+  /* notify-events-default */
   ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                "notify-events-default", NULL, "job-completed");
 
-  /* notify-notify-events-supported */
+  /* notify-events-supported */
   ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                 "notify-events-supported",
                (int)(sizeof(notify_events) / sizeof(notify_events[0])),
@@ -512,10 +522,31 @@ cupsdCreateCommonData(void)
   ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                "notify-pull-method-supported", NULL, "ippget");
 
-  /* TODO: scan notifier directory */
   /* notify-schemes-supported */
-  ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-               "notify-schemes-supported", NULL, "mailto");
+  snprintf(filename, sizeof(filename), "%s/notifier", ServerBin);
+  if ((dir = cupsDirOpen(filename)) != NULL)
+  {
+    notifiers = cupsArrayNew((cups_array_func_t)strcmp, NULL);
+
+    while ((dent = cupsDirRead(dir)) != NULL)
+      if (S_ISREG(dent->fileinfo.st_mode) &&
+          (dent->fileinfo.st_mode & S_IXOTH) != 0)
+        cupsArrayAdd(notifiers, _cupsStrAlloc(dent->filename));
+
+    if (cupsArrayCount(notifiers) > 0)
+    {
+      attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+                          "notify-schemes-supported",
+                          cupsArrayCount(notifiers), NULL, NULL);
+
+      for (i = 0, notifier = (char *)cupsArrayFirst(notifiers);
+           notifier;
+          i ++, notifier = (char *)cupsArrayNext(notifiers))
+       attr->values[i].string.text = notifier;
+    }
+
+    cupsArrayDelete(notifiers);
+  }
 
   /* number-up-supported */
   ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
@@ -661,7 +692,7 @@ cupsdDeletePrinter(
           dp = (cupsd_printer_t *)cupsArrayNext(Printers))
        if (dp != p && (dp->type & CUPS_PRINTER_DEFAULT))
        {
-         DefaultPrinter = p;
+         DefaultPrinter = dp;
          break;
        }
     }
@@ -2400,25 +2431,18 @@ cupsdUpdatePrinters(void)
 
 const char *                           /* O - Printer or class name */
 cupsdValidateDest(
-    const char      *uri,              /* I - Printer URI */
+    const char      *hostname,         /* I - Host name */
+    const char      *resource,         /* I - Resource name */
     cups_ptype_t    *dtype,            /* O - Type (printer or class) */
     cupsd_printer_t **printer)         /* O - Printer pointer */
 {
   cupsd_printer_t      *p;             /* Current printer */
   char                 localname[1024],/* Localized hostname */
                        *lptr,          /* Pointer into localized hostname */
-                       *sptr,          /* Pointer into server name */
-                       *rptr,          /* Pointer into resource */
-                       scheme[32],     /* Scheme portion of URI */
-                       username[64],   /* Username portion of URI */
-                       hostname[HTTP_MAX_HOST],
-                                       /* Host portion of URI */
-                       resource[HTTP_MAX_URI];
-                                       /* Resource portion of URI */
-  int                  port;           /* Port portion of URI */
-
-
-  DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri,
+                       *sptr;          /* Pointer into server name */
+
+
+  DEBUG_printf(("cupsdValidateDest(\"%s\", \"%s\", %p, %p)\n", hostname, resource,
                 dtype, printer));
 
  /*
@@ -2428,16 +2452,7 @@ cupsdValidateDest(
   if (printer)
     *printer = NULL;
 
-  if (dtype)
-    *dtype = (cups_ptype_t)0;
-
- /*
-  * Pull the hostname and resource from the URI...
-  */
-
-  httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
-                  username, sizeof(username), hostname, sizeof(hostname),
-                 &port, resource, sizeof(resource));
+  *dtype = (cups_ptype_t)0;
 
  /*
   * See if the resource is a class or printer...
@@ -2449,7 +2464,7 @@ cupsdValidateDest(
     * Class...
     */
 
-    rptr = resource + 9;
+    resource += 9;
   }
   else if (!strncmp(resource, "/printers/", 10))
   {
@@ -2457,7 +2472,7 @@ cupsdValidateDest(
     * Printer...
     */
 
-    rptr = resource + 10;
+    resource += 10;
   }
   else
   {
@@ -2472,19 +2487,17 @@ cupsdValidateDest(
   * See if the printer or class name exists...
   */
 
-  p = cupsdFindDest(rptr);
+  p = cupsdFindDest(resource);
 
-  if (p == NULL && strchr(rptr, '@') == NULL)
+  if (p == NULL && strchr(resource, '@') == NULL)
     return (NULL);
   else if (p != NULL)
   {
     if (printer)
       *printer = p;
 
-    if (dtype)
-      *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
-                          CUPS_PRINTER_REMOTE);
-
+    *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
+                        CUPS_PRINTER_REMOTE);
     return (p->name);
   }
 
@@ -2493,7 +2506,7 @@ cupsdValidateDest(
   */
 
   if (!strcasecmp(hostname, "localhost"))
-    strlcpy(hostname, ServerName, sizeof(hostname));
+    hostname = ServerName;
 
   strlcpy(localname, hostname, sizeof(localname));
 
@@ -2535,15 +2548,13 @@ cupsdValidateDest(
        p;
        p = (cupsd_printer_t *)cupsArrayNext(Printers))
     if (!strcasecmp(p->hostname, localname) &&
-        !strcasecmp(p->name, rptr))
+        !strcasecmp(p->name, resource))
     {
       if (printer)
         *printer = p;
 
-      if (dtype)
-       *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
-                            CUPS_PRINTER_REMOTE);
-
+      *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
+                          CUPS_PRINTER_REMOTE);
       return (p->name);
     }
 
@@ -2792,10 +2803,6 @@ add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
     ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default",
                   1);
 
-  if (!cupsGetOption("document-format", p->num_options, p->options))
-    ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
-                "document-format-default", NULL, "application/octet-stream");
-
   if (!cupsGetOption("job-hold-until", p->num_options, p->options))
     ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
                  "job-hold-until-default", NULL, "no-hold");
@@ -3300,5 +3307,5 @@ write_irix_state(cupsd_printer_t *p)      /* I - Printer to update */
 
 
 /*
- * End of "$Id: printers.c 5533 2006-05-16 19:45:14Z mike $".
+ * End of "$Id: printers.c 5686 2006-06-21 21:02:56Z mike $".
  */