]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/quotas.c
2 * "$Id: quotas.c 6365 2007-03-19 20:56:57Z mike $"
4 * Quota routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 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 #if defined(__APPLE__) && defined(HAVE_DLFCN_H)
106 * Use Apple PrintService quota enforcement if installed (X Server only)
109 if (AppleQuotas
&& PSQUpdateQuotaProc
)
111 q
->page_count
= (*PSQUpdateQuotaProc
)(p
->name
, p
->info
, username
, pages
, 0);
115 #endif /* __APPLE__ && HAVE_DLFCN_H */
117 curtime
= time(NULL
);
119 if (curtime
< q
->next_update
)
121 q
->page_count
+= pages
;
128 curtime
-= p
->quota_period
;
136 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
138 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
140 if (strcasecmp(job
->dest
, p
->name
) != 0 ||
141 strcasecmp(job
->username
, q
->username
) != 0)
144 if ((attr
= ippFindAttribute(job
->attrs
, "time-at-completion",
145 IPP_TAG_INTEGER
)) == NULL
)
146 if ((attr
= ippFindAttribute(job
->attrs
, "time-at-processing",
147 IPP_TAG_INTEGER
)) == NULL
)
148 attr
= ippFindAttribute(job
->attrs
, "time-at-creation",
154 if (attr
->values
[0].integer
< curtime
)
157 cupsdCancelJob(job
, 1, IPP_JOB_CANCELED
);
162 if (q
->next_update
== 0)
163 q
->next_update
= attr
->values
[0].integer
+ p
->quota_period
;
165 if ((attr
= ippFindAttribute(job
->attrs
, "job-media-sheets-completed",
166 IPP_TAG_INTEGER
)) != NULL
)
167 q
->page_count
+= attr
->values
[0].integer
;
169 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
170 IPP_TAG_INTEGER
)) != NULL
)
171 q
->k_count
+= attr
->values
[0].integer
;
179 * 'add_quota()' - Add a quota record for this printer and user.
182 static cupsd_quota_t
* /* O - Quota data */
183 add_quota(cupsd_printer_t
*p
, /* I - Printer */
184 const char *username
) /* I - User */
186 cupsd_quota_t
*q
; /* New quota data */
193 p
->quotas
= cupsArrayNew((cups_array_func_t
)compare_quotas
, NULL
);
198 if ((q
= calloc(1, sizeof(cupsd_quota_t
))) == NULL
)
201 strlcpy(q
->username
, username
, sizeof(q
->username
));
203 cupsArrayAdd(p
->quotas
, q
);
210 * 'compare_quotas()' - Compare two quota records...
213 static int /* O - Result of comparison */
214 compare_quotas(const cupsd_quota_t
*q1
, /* I - First quota record */
215 const cupsd_quota_t
*q2
) /* I - Second quota record */
217 return (strcasecmp(q1
->username
, q2
->username
));
222 * 'find_quota()' - Find a quota record.
225 static cupsd_quota_t
* /* O - Quota data */
226 find_quota(cupsd_printer_t
*p
, /* I - Printer */
227 const char *username
) /* I - User */
229 cupsd_quota_t
*q
, /* Quota data pointer */
230 match
; /* Search data */
236 strlcpy(match
.username
, username
, sizeof(match
.username
));
238 if ((q
= (cupsd_quota_t
*)cupsArrayFind(p
->quotas
, &match
)) != NULL
)
241 return (add_quota(p
, username
));
246 * End of "$Id: quotas.c 6365 2007-03-19 20:56:57Z mike $".