]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/quotas.c
f569bbd5572b3c84a491c51b3bef483b31fc287b
2 * "$Id: quotas.c,v 1.4 2001/01/22 15:04:01 mike Exp $"
4 * Quota routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2001 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-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * AddQuota() - Add a quota record for this printer and user.
27 * FindQuota() - Find a quota record.
28 * FreeQuotas() - Free quotas for a printer.
29 * UpdateQuota() - Update quota data for the specified printer and user.
30 * compare() - Compare two quota records...
34 * Include necessary headers...
44 static int compare(const quota_t
*q1
, const quota_t
*q2
);
48 * 'AddQuota()' - Add a quota record for this printer and user.
51 quota_t
* /* O - Quota data */
52 AddQuota(printer_t
*p
, /* I - Printer */
53 const char *username
) /* I - User */
55 quota_t
*q
; /* New quota data */
61 if (p
->num_quotas
== 0)
62 q
= malloc(sizeof(quota_t
));
64 q
= realloc(p
->quotas
, sizeof(quota_t
) * (p
->num_quotas
+ 1));
73 memset(q
, 0, sizeof(quota_t
));
74 strncpy(q
->username
, username
, sizeof(q
->username
) - 1);
76 if (p
->num_quotas
> 1)
77 qsort(p
->quotas
, p
->num_quotas
, sizeof(quota_t
),
78 (int (*)(const void *, const void *))compare
);
80 return (FindQuota(p
, username
));
85 * 'FindQuota()' - Find a quota record.
88 quota_t
* /* O - Quota data */
89 FindQuota(printer_t
*p
, /* I - Printer */
90 const char *username
) /* I - User */
92 quota_t
*q
, /* Quota data pointer */
93 match
; /* Search data */
99 if (p
->num_quotas
== 0)
103 strncpy(match
.username
, username
, sizeof(match
.username
) - 1);
104 match
.username
[sizeof(match
.username
) - 1] = '\0';
106 q
= bsearch(&match
, p
->quotas
, p
->num_quotas
, sizeof(quota_t
),
107 (int(*)(const void *, const void *))compare
);
113 return (AddQuota(p
, username
));
118 * 'FreeQuotas()' - Free quotas for a printer.
122 FreeQuotas(printer_t
*p
) /* I - Printer */
136 * 'UpdateQuota()' - Update quota data for the specified printer and user.
139 quota_t
* /* O - Quota data */
140 UpdateQuota(printer_t
*p
, /* I - Printer */
141 const char *username
, /* I - User */
142 int pages
, /* I - Number of pages */
143 int k
) /* I - Number of kilobytes */
145 quota_t
*q
; /* Quota data */
146 job_t
*job
, /* Current job */
147 *next
; /* Next job */
148 time_t curtime
; /* Current time */
149 ipp_attribute_t
*attr
; /* Job attribute */
155 if (!p
->k_limit
&& !p
->page_limit
)
158 if ((q
= FindQuota(p
, username
)) == NULL
)
161 curtime
= time(NULL
);
163 if (curtime
< q
->next_update
)
165 q
->page_count
+= pages
;
172 curtime
-= p
->quota_period
;
180 for (job
= Jobs
; job
; job
= next
)
184 if (strcasecmp(job
->dest
, p
->name
) != 0 ||
185 strcmp(job
->username
, q
->username
) != 0)
188 if ((attr
= ippFindAttribute(job
->attrs
, "time-at-completion",
189 IPP_TAG_INTEGER
)) == NULL
)
190 if ((attr
= ippFindAttribute(job
->attrs
, "time-at-processing",
191 IPP_TAG_INTEGER
)) == NULL
)
192 attr
= ippFindAttribute(job
->attrs
, "time-at-creation",
198 if (attr
->values
[0].integer
< curtime
)
201 CancelJob(job
->id
, 1);
206 if (q
->next_update
== 0)
207 q
->next_update
= attr
->values
[0].integer
+ p
->quota_period
;
209 if ((attr
= ippFindAttribute(job
->attrs
, "job-media-sheets-completed",
210 IPP_TAG_INTEGER
)) != NULL
)
211 q
->page_count
+= attr
->values
[0].integer
;
213 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
214 IPP_TAG_INTEGER
)) != NULL
)
215 q
->k_count
+= attr
->values
[0].integer
;
223 * 'compare()' - Compare two quota records...
226 static int /* O - Result of comparison */
227 compare(const quota_t
*q1
, /* I - First quota record */
228 const quota_t
*q2
) /* I - Second quota record */
230 return (strcmp(q1
->username
, q2
->username
));
235 * End of "$Id: quotas.c,v 1.4 2001/01/22 15:04:01 mike Exp $".