]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/quotas.c
2 * "$Id: quotas.c 4970 2006-01-24 14:05:45Z 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 * cupsdAddQuota() - Add a quota record for this printer and user.
27 * cupsdFindQuota() - Find a quota record.
28 * cupsdFreeQuotas() - Free quotas for a printer.
29 * cupsdUpdateQuota() - Update quota data for the specified printer and user.
30 * compare_quotas() - Compare two quota records...
34 * Include necessary headers...
44 static int compare_quotas(const cupsd_quota_t
*q1
,
45 const cupsd_quota_t
*q2
);
49 * 'cupsdAddQuota()' - Add a quota record for this printer and user.
52 cupsd_quota_t
* /* O - Quota data */
53 cupsdAddQuota(cupsd_printer_t
*p
, /* I - Printer */
54 const char *username
)/* I - User */
56 cupsd_quota_t
*q
; /* New quota data */
63 p
->quotas
= cupsArrayNew((cups_array_func_t
)compare_quotas
, NULL
);
68 if ((q
= calloc(1, sizeof(cupsd_quota_t
))) == NULL
)
71 strlcpy(q
->username
, username
, sizeof(q
->username
));
73 cupsArrayAdd(p
->quotas
, q
);
80 * 'cupsdFindQuota()' - Find a quota record.
83 cupsd_quota_t
* /* O - Quota data */
85 cupsd_printer_t
*p
, /* I - Printer */
86 const char *username
) /* I - User */
88 cupsd_quota_t
*q
, /* Quota data pointer */
89 match
; /* Search data */
95 strlcpy(match
.username
, username
, sizeof(match
.username
));
97 if ((q
= (cupsd_quota_t
*)cupsArrayFind(p
->quotas
, &match
)) != NULL
)
100 return (cupsdAddQuota(p
, username
));
105 * 'cupsdFreeQuotas()' - Free quotas for a printer.
109 cupsdFreeQuotas(cupsd_printer_t
*p
) /* I - Printer */
111 cupsd_quota_t
*q
; /* Current quota record */
117 for (q
= (cupsd_quota_t
*)cupsArrayFirst(p
->quotas
);
119 q
= (cupsd_quota_t
*)cupsArrayNext(p
->quotas
))
122 cupsArrayDelete(p
->quotas
);
129 * 'cupsdUpdateQuota()' - Update quota data for the specified printer and user.
132 cupsd_quota_t
* /* O - Quota data */
134 cupsd_printer_t
*p
, /* I - Printer */
135 const char *username
, /* I - User */
136 int pages
, /* I - Number of pages */
137 int k
) /* I - Number of kilobytes */
139 cupsd_quota_t
*q
; /* Quota data */
140 cupsd_job_t
*job
; /* Current job */
141 time_t curtime
; /* Current time */
142 ipp_attribute_t
*attr
; /* Job attribute */
148 if (!p
->k_limit
&& !p
->page_limit
)
151 if ((q
= cupsdFindQuota(p
, username
)) == NULL
)
154 cupsdLogMessage(CUPSD_LOG_DEBUG
,
155 "cupsdUpdateQuota: p=%s username=%s pages=%d k=%d",
156 p
->name
, username
, pages
, k
);
158 curtime
= time(NULL
);
160 if (curtime
< q
->next_update
)
162 q
->page_count
+= pages
;
169 curtime
-= p
->quota_period
;
177 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
179 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
181 if (strcasecmp(job
->dest
, p
->name
) != 0 ||
182 strcasecmp(job
->username
, q
->username
) != 0)
185 if ((attr
= ippFindAttribute(job
->attrs
, "time-at-completion",
186 IPP_TAG_INTEGER
)) == NULL
)
187 if ((attr
= ippFindAttribute(job
->attrs
, "time-at-processing",
188 IPP_TAG_INTEGER
)) == NULL
)
189 attr
= ippFindAttribute(job
->attrs
, "time-at-creation",
195 if (attr
->values
[0].integer
< curtime
)
198 cupsdCancelJob(job
, 1);
203 if (q
->next_update
== 0)
204 q
->next_update
= attr
->values
[0].integer
+ p
->quota_period
;
206 if ((attr
= ippFindAttribute(job
->attrs
, "job-media-sheets-completed",
207 IPP_TAG_INTEGER
)) != NULL
)
208 q
->page_count
+= attr
->values
[0].integer
;
210 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
211 IPP_TAG_INTEGER
)) != NULL
)
212 q
->k_count
+= attr
->values
[0].integer
;
220 * 'compare_quotas()' - Compare two quota records...
223 static int /* O - Result of comparison */
224 compare_quotas(const cupsd_quota_t
*q1
, /* I - First quota record */
225 const cupsd_quota_t
*q2
) /* I - Second quota record */
227 return (strcasecmp(q1
->username
, q2
->username
));
232 * End of "$Id: quotas.c 4970 2006-01-24 14:05:45Z mike $".