]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/quotas.c
2 * "$Id: quotas.c 5969 2006-09-19 20:09:24Z mike $"
4 * Quota routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdFreeQuotas() - Free quotas for a printer.
27 * cupsdUpdateQuota() - Update quota data for the specified printer and user.
28 * add_quota() - Add a quota record for this printer and user.
29 * compare_quotas() - Compare two quota records...
30 * find_quota() - Find a quota record.
34 * Include necessary headers...
44 static cupsd_quota_t
*add_quota(cupsd_printer_t
*p
, const char *username
);
45 static int compare_quotas(const cupsd_quota_t
*q1
,
46 const cupsd_quota_t
*q2
);
47 static cupsd_quota_t
*find_quota(cupsd_printer_t
*p
, const char *username
);
51 * 'cupsdFreeQuotas()' - Free quotas for a printer.
55 cupsdFreeQuotas(cupsd_printer_t
*p
) /* I - Printer */
57 cupsd_quota_t
*q
; /* Current quota record */
63 for (q
= (cupsd_quota_t
*)cupsArrayFirst(p
->quotas
);
65 q
= (cupsd_quota_t
*)cupsArrayNext(p
->quotas
))
68 cupsArrayDelete(p
->quotas
);
75 * 'cupsdUpdateQuota()' - Update quota data for the specified printer and user.
78 cupsd_quota_t
* /* O - Quota data */
80 cupsd_printer_t
*p
, /* I - Printer */
81 const char *username
, /* I - User */
82 int pages
, /* I - Number of pages */
83 int k
) /* I - Number of kilobytes */
85 cupsd_quota_t
*q
; /* Quota data */
86 cupsd_job_t
*job
; /* Current job */
87 time_t curtime
; /* Current time */
88 ipp_attribute_t
*attr
; /* Job attribute */
94 if (!p
->k_limit
&& !p
->page_limit
)
97 if ((q
= find_quota(p
, username
)) == NULL
)
100 cupsdLogMessage(CUPSD_LOG_DEBUG
,
101 "cupsdUpdateQuota: p=%s username=%s pages=%d k=%d",
102 p
->name
, username
, pages
, k
);
104 curtime
= time(NULL
);
106 if (curtime
< q
->next_update
)
108 q
->page_count
+= pages
;
115 curtime
-= p
->quota_period
;
123 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
125 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
127 if (strcasecmp(job
->dest
, p
->name
) != 0 ||
128 strcasecmp(job
->username
, q
->username
) != 0)
131 if ((attr
= ippFindAttribute(job
->attrs
, "time-at-completion",
132 IPP_TAG_INTEGER
)) == NULL
)
133 if ((attr
= ippFindAttribute(job
->attrs
, "time-at-processing",
134 IPP_TAG_INTEGER
)) == NULL
)
135 attr
= ippFindAttribute(job
->attrs
, "time-at-creation",
141 if (attr
->values
[0].integer
< curtime
)
144 cupsdCancelJob(job
, 1, IPP_JOB_CANCELED
);
149 if (q
->next_update
== 0)
150 q
->next_update
= attr
->values
[0].integer
+ p
->quota_period
;
152 if ((attr
= ippFindAttribute(job
->attrs
, "job-media-sheets-completed",
153 IPP_TAG_INTEGER
)) != NULL
)
154 q
->page_count
+= attr
->values
[0].integer
;
156 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
157 IPP_TAG_INTEGER
)) != NULL
)
158 q
->k_count
+= attr
->values
[0].integer
;
166 * 'add_quota()' - Add a quota record for this printer and user.
169 static cupsd_quota_t
* /* O - Quota data */
170 add_quota(cupsd_printer_t
*p
, /* I - Printer */
171 const char *username
) /* I - User */
173 cupsd_quota_t
*q
; /* New quota data */
180 p
->quotas
= cupsArrayNew((cups_array_func_t
)compare_quotas
, NULL
);
185 if ((q
= calloc(1, sizeof(cupsd_quota_t
))) == NULL
)
188 strlcpy(q
->username
, username
, sizeof(q
->username
));
190 cupsArrayAdd(p
->quotas
, q
);
197 * 'compare_quotas()' - Compare two quota records...
200 static int /* O - Result of comparison */
201 compare_quotas(const cupsd_quota_t
*q1
, /* I - First quota record */
202 const cupsd_quota_t
*q2
) /* I - Second quota record */
204 return (strcasecmp(q1
->username
, q2
->username
));
209 * 'find_quota()' - Find a quota record.
212 static cupsd_quota_t
* /* O - Quota data */
213 find_quota(cupsd_printer_t
*p
, /* I - Printer */
214 const char *username
) /* I - User */
216 cupsd_quota_t
*q
, /* Quota data pointer */
217 match
; /* Search data */
223 strlcpy(match
.username
, username
, sizeof(match
.username
));
225 if ((q
= (cupsd_quota_t
*)cupsArrayFind(p
->quotas
, &match
)) != NULL
)
228 return (add_quota(p
, username
));
233 * End of "$Id: quotas.c 5969 2006-09-19 20:09:24Z mike $".