aboutsummaryrefslogtreecommitdiff
path: root/src/tbf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tbf.c')
-rw-r--r--src/tbf.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/tbf.c b/src/tbf.c
index 7050fc7..56a4ad1 100644
--- a/src/tbf.c
+++ b/src/tbf.c
@@ -14,17 +14,12 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>. 15 along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <config.h> 17#include "tbf.h"
18#include <stdlib.h>
19#include <stdio.h>
20#include <stdbool.h>
21#include <syslog.h> 18#include <syslog.h>
22#include <inttypes.h> 19#include <inttypes.h>
23#include <sys/stat.h> 20#include <sys/stat.h>
21#include <sys/time.h>
24#include <db.h> 22#include <db.h>
25#include "vrt.h"
26#include "vcc_if.h"
27#include "bin/varnishd/cache.h"
28 23
29static int debug_level; 24static int debug_level;
30 25
@@ -351,7 +346,7 @@ tbf_init(struct vmod_priv *priv, const struct VCL_conf *vclconf)
351} 346}
352 347
353void 348void
354vmod_open(struct sess *sp, const char *dir, const char *params) 349vmod_open(MOD_CTX ctx, const char *dir, const char *params)
355{ 350{
356 if (db) { 351 if (db) {
357 syslog(LOG_DAEMON|LOG_ERR, "tbf.open called twice"); 352 syslog(LOG_DAEMON|LOG_ERR, "tbf.open called twice");
@@ -362,7 +357,7 @@ vmod_open(struct sess *sp, const char *dir, const char *params)
362} 357}
363 358
364void 359void
365vmod_close(struct sess *sp) 360vmod_close(MOD_CTX ctx)
366{ 361{
367 pthread_mutex_lock(&mutex); 362 pthread_mutex_lock(&mutex);
368 if (db) { 363 if (db) {
@@ -377,7 +372,7 @@ vmod_close(struct sess *sp)
377} 372}
378 373
379void 374void
380vmod_sync(struct sess *sp) 375vmod_sync(MOD_CTX ctx)
381{ 376{
382 if (db) { 377 if (db) {
383 debug(1, ("synchronizing database")); 378 debug(1, ("synchronizing database"));
@@ -410,7 +405,7 @@ struct tbf_bucket {
410}; 405};
411 406
412int 407int
413tbf_proc(struct sess *sp, DB *db, const char *key, int cost, 408tbf_proc(MOD_CTX ctx, DB *db, const char *key, int cost,
414 unsigned long interval, int burst_size) 409 unsigned long interval, int burst_size)
415{ 410{
416 DBT keydat, content; 411 DBT keydat, content;
@@ -499,8 +494,9 @@ tbf_proc(struct sess *sp, DB *db, const char *key, int cost,
499 return res; 494 return res;
500} 495}
501 496
502unsigned 497VCL_BOOL
503vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size) 498vmod_rate(MOD_CTX ctx, VCL_STRING key, VCL_INT cost, VCL_REAL t,
499 VCL_INT burst_size)
504{ 500{
505 unsigned long interval = t * USEC_PER_SEC; 501 unsigned long interval = t * USEC_PER_SEC;
506 int rc; 502 int rc;
@@ -527,7 +523,7 @@ vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size)
527 kp = keylock_find_safe(key); 523 kp = keylock_find_safe(key);
528 debug(2, ("found key %s, ref %u", key, kp->refcnt)); 524 debug(2, ("found key %s, ref %u", key, kp->refcnt));
529 AZ(pthread_mutex_lock(&kp->mutex)); 525 AZ(pthread_mutex_lock(&kp->mutex));
530 rc = tbf_proc(sp, db, key, cost, interval, burst_size); 526 rc = tbf_proc(ctx, db, key, cost, interval, burst_size);
531 if (--kp->refcnt == 0) 527 if (--kp->refcnt == 0)
532 keylock_remove_safe(kp); 528 keylock_remove_safe(kp);
533 AZ(pthread_mutex_unlock(&kp->mutex)); 529 AZ(pthread_mutex_unlock(&kp->mutex));
@@ -539,8 +535,8 @@ vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size)
539 535
540#define ISWS(c) ((c)==' '||(c)=='\t') 536#define ISWS(c) ((c)==' '||(c)=='\t')
541 537
542unsigned 538VCL_BOOL
543vmod_check(struct sess *sp, const char *key, const char *spec) 539vmod_check(MOD_CTX ctx, VCL_STRING key, VCL_STRING spec)
544{ 540{
545 double t, v, n; 541 double t, v, n;
546 char *p; 542 char *p;
@@ -601,5 +597,5 @@ vmod_check(struct sess *sp, const char *key, const char *spec)
601 syslog(LOG_DAEMON|LOG_WARNING, "garbage after rate spec: %s", 597 syslog(LOG_DAEMON|LOG_WARNING, "garbage after rate spec: %s",
602 spec); 598 spec);
603 599
604 return vmod_rate(sp, key, 1, n/v, v/n+1); 600 return vmod_rate(ctx, key, 1, n/v, v/n+1);
605} 601}

Return to:

Send suggestions and report system problems to the System administrator.