]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/quotas.c
Changing the printer-is-shared value for a remote queue did not produce an
[thirdparty/cups.git] / scheduler / quotas.c
index 7d3e4e3eb5138111685ca7adc1a1fb234c2b354a..9f0b6c0a335582f30cae6e110e872975dd8519e5 100644 (file)
@@ -1,33 +1,24 @@
 /*
- * "$Id: quotas.c 5970 2006-09-19 20:11:08Z mike $"
+ * "$Id$"
  *
- *   Quota routines for the Common UNIX Printing System (CUPS).
+ *   Quota routines for the CUPS scheduler.
  *
- *   Copyright 1997-2006 by Easy Software Products.
+ *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 1997-2007 by Easy Software Products.
  *
  *   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:
  *
+ *   cupsdFindQuota()   - Find a quota record.
  *   cupsdFreeQuotas()  - Free quotas for a printer.
  *   cupsdUpdateQuota() - Update quota data for the specified printer and user.
  *   add_quota()        - Add a quota record for this printer and user.
  *   compare_quotas()   - Compare two quota records...
- *   find_quota()       - Find a quota record.
  */
 
 /*
 static cupsd_quota_t   *add_quota(cupsd_printer_t *p, const char *username);
 static int             compare_quotas(const cupsd_quota_t *q1,
                                       const cupsd_quota_t *q2);
-static cupsd_quota_t   *find_quota(cupsd_printer_t *p, const char *username);
+
+
+/*
+ * 'cupsdFindQuota()' - Find a quota record.
+ */
+
+cupsd_quota_t *                                /* O - Quota data */
+cupsdFindQuota(
+    cupsd_printer_t *p,                        /* I - Printer */
+    const char      *username)         /* I - User */
+{
+  cupsd_quota_t        *q,                     /* Quota data pointer */
+               match;                  /* Search data */
+  char         *ptr;                   /* Pointer into username */
+
+
+  if (!p || !username)
+    return (NULL);
+
+  strlcpy(match.username, username, sizeof(match.username));
+  if ((ptr = strchr(match.username, '@')) != NULL)
+    *ptr = '\0';                       /* Strip @domain/@KDC */
+
+  if ((q = (cupsd_quota_t *)cupsArrayFind(p->quotas, &match)) != NULL)
+    return (q);
+  else
+    return (add_quota(p, username));
+}
 
 
 /*
@@ -94,7 +112,7 @@ cupsdUpdateQuota(
   if (!p->k_limit && !p->page_limit)
     return (NULL);
 
-  if ((q = find_quota(p, username)) == NULL)
+  if ((q = cupsdFindQuota(p, username)) == NULL)
     return (NULL);
 
   cupsdLogMessage(CUPSD_LOG_DEBUG,
@@ -124,8 +142,20 @@ cupsdUpdateQuota(
        job;
        job = (cupsd_job_t *)cupsArrayNext(Jobs))
   {
-    if (strcasecmp(job->dest, p->name) != 0 ||
-        strcasecmp(job->username, q->username) != 0)
+   /*
+    * We only care about the current printer/class and user...
+    */
+
+    if (_cups_strcasecmp(job->dest, p->name) != 0 ||
+        _cups_strcasecmp(job->username, q->username) != 0)
+      continue;
+
+   /*
+    * Make sure attributes are loaded; we always call cupsdLoadJob() to ensure
+    * the access_time member is updated so the job isn't unloaded right away...
+    */
+
+    if (!cupsdLoadJob(job))
       continue;
 
     if ((attr = ippFindAttribute(job->attrs, "time-at-completion",
@@ -135,13 +165,14 @@ cupsdUpdateQuota(
         attr = ippFindAttribute(job->attrs, "time-at-creation",
                                 IPP_TAG_INTEGER);
 
-    if (attr == NULL)
-      break;
-
     if (attr->values[0].integer < curtime)
     {
-      if (JobAutoPurge)
-        cupsdCancelJob(job, 1, IPP_JOB_CANCELED);
+     /*
+      * This job is too old to count towards the quota, ignore it...
+      */
+
+      if (JobAutoPurge && !job->printer && job->state_value > IPP_JOB_STOPPED)
+        cupsdDeleteJob(job, CUPSD_JOB_PURGE);
 
       continue;
     }
@@ -171,6 +202,7 @@ add_quota(cupsd_printer_t *p,               /* I - Printer */
           const char      *username)   /* I - User */
 {
   cupsd_quota_t        *q;                     /* New quota data */
+  char         *ptr;                   /* Pointer into username */
 
 
   if (!p || !username)
@@ -186,6 +218,8 @@ add_quota(cupsd_printer_t *p,               /* I - Printer */
     return (NULL);
 
   strlcpy(q->username, username, sizeof(q->username));
+  if ((ptr = strchr(q->username, '@')) != NULL)
+    *ptr = '\0';                       /* Strip @domain/@KDC */
 
   cupsArrayAdd(p->quotas, q);
 
@@ -201,34 +235,10 @@ static int                                /* O - Result of comparison */
 compare_quotas(const cupsd_quota_t *q1,        /* I - First quota record */
                const cupsd_quota_t *q2)        /* I - Second quota record */
 {
-  return (strcasecmp(q1->username, q2->username));
-}
-
-
-/*
- * 'find_quota()' - Find a quota record.
- */
-
-static cupsd_quota_t *                 /* O - Quota data */
-find_quota(cupsd_printer_t *p,         /* I - Printer */
-           const char      *username)  /* I - User */
-{
-  cupsd_quota_t        *q,                     /* Quota data pointer */
-               match;                  /* Search data */
-
-
-  if (!p || !username)
-    return (NULL);
-
-  strlcpy(match.username, username, sizeof(match.username));
-
-  if ((q = (cupsd_quota_t *)cupsArrayFind(p->quotas, &match)) != NULL)
-    return (q);
-  else
-    return (add_quota(p, username));
+  return (_cups_strcasecmp(q1->username, q2->username));
 }
 
 
 /*
- * End of "$Id: quotas.c 5970 2006-09-19 20:11:08Z mike $".
+ * End of "$Id$".
  */