2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
22 jlimit
jlimit_new(int maxt
, int maxp
)
28 r
= pmalloc(p
,sizeof(_jlimit
));
30 r
->start
= r
->points
= 0;
38 void jlimit_free(jlimit r
)
42 if(r
->key
!= NULL
) free(r
->key
);
47 int jlimit_check(jlimit r
, char *key
, int points
)
51 if(r
== NULL
) return 0;
53 /* make sure we didn't go over the time frame or get a null/new key */
54 if((now
- r
->start
) > r
->maxt
|| key
== NULL
|| j_strcmp(key
,r
->key
) != 0)
55 { /* start a new key */
58 /* We use strdup instead of pstrdup since r->key needs to be free'd before
59 and more often than the rest of the rlimit structure */
69 /* if we're within the time frame and over the point limit */
70 if(r
->points
> r
->maxp
&& (now
- r
->start
) < r
->maxt
)
72 return 1; /* we don't reset the rate here, so that it remains rated until the time runs out */