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
@@ -11,23 +11,18 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdbool.h>
+#include "tbf.h"
#include <syslog.h>
#include <inttypes.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <db.h>
-#include "vrt.h"
-#include "vcc_if.h"
-#include "bin/varnishd/cache.h"
static int debug_level;
static void
debugprt(const char *fmt, ...)
{
@@ -348,24 +343,24 @@ tbf_init(struct vmod_priv *priv, const struct VCL_conf *vclconf)
{
VTAILQ_INIT(&keylock_head);
VTAILQ_INIT(&keylock_avail);
}
void
-vmod_open(struct sess *sp, const char *dir, const char *params)
+vmod_open(MOD_CTX ctx, const char *dir, const char *params)
{
if (db) {
syslog(LOG_DAEMON|LOG_ERR, "tbf.open called twice");
return;
}
tbf_set_db_dir(dir);
tbf_open_safe(params);
}
void
-vmod_close(struct sess *sp)
+vmod_close(MOD_CTX ctx)
{
pthread_mutex_lock(&mutex);
if (db) {
debug(1, ("closing database %s", dbname));
db->close(db, 0);
db = NULL;
@@ -374,13 +369,13 @@ vmod_close(struct sess *sp)
tbf_disabled = 0;
}
pthread_mutex_unlock(&mutex);
}
void
-vmod_sync(struct sess *sp)
+vmod_sync(MOD_CTX ctx)
{
if (db) {
debug(1, ("synchronizing database"));
db->sync(db, 0);
}
}
@@ -407,13 +402,13 @@ vmod_sync(struct sess *sp)
struct tbf_bucket {
uint64_t timestamp; /* microseconds since epoch */
size_t tokens; /* tokens available */
};
int
-tbf_proc(struct sess *sp, DB *db, const char *key, int cost,
+tbf_proc(MOD_CTX ctx, DB *db, const char *key, int cost,
unsigned long interval, int burst_size)
{
DBT keydat, content;
struct timeval tv;
uint64_t now;
uint64_t elapsed;
@@ -496,14 +491,15 @@ tbf_proc(struct sess *sp, DB *db, const char *key, int cost,
autosync_count = 0;
}
return res;
}
-unsigned
-vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size)
+VCL_BOOL
+vmod_rate(MOD_CTX ctx, VCL_STRING key, VCL_INT cost, VCL_REAL t,
+ VCL_INT burst_size)
{
unsigned long interval = t * USEC_PER_SEC;
int rc;
debug(2, ("entering rate(%s,%d,%g,%d)", key, cost, t, burst_size));
@@ -524,26 +520,26 @@ vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size)
if (db) {
struct keylock *kp;
kp = keylock_find_safe(key);
debug(2, ("found key %s, ref %u", key, kp->refcnt));
AZ(pthread_mutex_lock(&kp->mutex));
- rc = tbf_proc(sp, db, key, cost, interval, burst_size);
+ rc = tbf_proc(ctx, db, key, cost, interval, burst_size);
if (--kp->refcnt == 0)
keylock_remove_safe(kp);
AZ(pthread_mutex_unlock(&kp->mutex));
} else
rc = false;
return rc;
}
#define ISWS(c) ((c)==' '||(c)=='\t')
-unsigned
-vmod_check(struct sess *sp, const char *key, const char *spec)
+VCL_BOOL
+vmod_check(MOD_CTX ctx, VCL_STRING key, VCL_STRING spec)
{
double t, v, n;
char *p;
#define SKIPWS(init) for (init; *spec && ISWS(*spec); spec++)
int burst;
@@ -598,8 +594,8 @@ vmod_check(struct sess *sp, const char *key, const char *spec)
SKIPWS(++spec);
if (*spec)
syslog(LOG_DAEMON|LOG_WARNING, "garbage after rate spec: %s",
spec);
- return vmod_rate(sp, key, 1, n/v, v/n+1);
+ return vmod_rate(ctx, key, 1, n/v, v/n+1);
}

Return to:

Send suggestions and report system problems to the System administrator.