ext_time_quota_acl.cc File Reference
#include "squid.h"
#include "helper/protocol_defines.h"
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
Include dependency graph for ext_time_quota_acl.cc:

Go to the source code of this file.

Macros

#define KEY_LAST_ACTIVITY   "last-activity"
 
#define KEY_PERIOD_START   "period-start"
 
#define KEY_PERIOD_LENGTH_CONFIGURED   "period-length-configured"
 
#define KEY_TIME_BUDGET_LEFT   "time-budget-left"
 
#define KEY_TIME_BUDGET_CONFIGURED   "time-budget-configured"
 
#define TQ_BUFFERSIZE   1024
 

Functions

static void open_log (const char *logfilename)
 
static void vlog (const char *level, const char *format, va_list args)
 
static void log_debug (const char *format,...)
 
static void log_info (const char *format,...)
 
static void log_error (const char *format,...)
 
static void log_fatal (const char *format,...)
 
static void init_db (void)
 
static void shutdown_db (void)
 
static char * KeyString (int &len, const char *user_key, const char *sub_key)
 
static void writeTime (const char *user_key, const char *sub_key, time_t t)
 
static time_t readTime (const char *user_key, const char *sub_key)
 
static void parseTime (const char *s, time_t *secs, time_t *start)
 
static void readConfig (const char *filename)
 
static void processActivity (const char *user_key)
 
static void usage (void)
 
int main (int argc, char **argv)
 

Variables

const char * db_path = DEFAULT_QUOTA_DB
 
const char * program_name
 
TDB_CONTEXT * db = nullptr
 
static int pauseLength = 300
 
static FILE * logfile = stderr
 
static int tq_debug_enabled = false
 

Macro Definition Documentation

◆ KEY_LAST_ACTIVITY

#define KEY_LAST_ACTIVITY   "last-activity"

Definition at line 57 of file ext_time_quota_acl.cc.

◆ KEY_PERIOD_LENGTH_CONFIGURED

#define KEY_PERIOD_LENGTH_CONFIGURED   "period-length-configured"

Definition at line 59 of file ext_time_quota_acl.cc.

◆ KEY_PERIOD_START

#define KEY_PERIOD_START   "period-start"

Definition at line 58 of file ext_time_quota_acl.cc.

◆ KEY_TIME_BUDGET_CONFIGURED

#define KEY_TIME_BUDGET_CONFIGURED   "time-budget-configured"

Definition at line 61 of file ext_time_quota_acl.cc.

◆ KEY_TIME_BUDGET_LEFT

#define KEY_TIME_BUDGET_LEFT   "time-budget-left"

Definition at line 60 of file ext_time_quota_acl.cc.

◆ TQ_BUFFERSIZE

#define TQ_BUFFERSIZE   1024

Maximum size of buffers used to read or display lines.

Definition at line 64 of file ext_time_quota_acl.cc.

Function Documentation

◆ init_db()

static void init_db ( void  )
static

Definition at line 136 of file ext_time_quota_acl.cc.

References db, db_path, log_fatal(), and log_info().

Referenced by main().

◆ KeyString()

static char * KeyString ( int len,
const char *  user_key,
const char *  sub_key 
)
static

Definition at line 151 of file ext_time_quota_acl.cc.

References log_error(), and TQ_BUFFERSIZE.

Referenced by readTime(), and writeTime().

◆ log_debug()

static void log_debug ( const char *  format,
  ... 
)
static

Definition at line 98 of file ext_time_quota_acl.cc.

References tq_debug_enabled, and vlog().

Referenced by processActivity(), readConfig(), readTime(), and writeTime().

◆ log_error()

static void log_error ( const char *  format,
  ... 
)
static

Definition at line 118 of file ext_time_quota_acl.cc.

References vlog().

Referenced by KeyString(), parseTime(), readTime(), and usage().

◆ log_fatal()

static void log_fatal ( const char *  format,
  ... 
)
static

Definition at line 127 of file ext_time_quota_acl.cc.

References vlog().

Referenced by init_db().

◆ log_info()

static void log_info ( const char *  format,
  ... 
)
static

Definition at line 109 of file ext_time_quota_acl.cc.

References vlog().

Referenced by init_db(), main(), and readConfig().

◆ main()

◆ open_log()

static void open_log ( const char *  logfilename)
static

Definition at line 79 of file ext_time_quota_acl.cc.

References logfile, and NULL.

Referenced by main().

◆ parseTime()

static void parseTime ( const char *  s,
time_t *  secs,
time_t *  start 
)
static

Definition at line 212 of file ext_time_quota_acl.cc.

References log_error(), and NULL.

Referenced by readConfig().

◆ processActivity()

static void processActivity ( const char *  user_key)
static

◆ readConfig()

static void readConfig ( const char *  filename)
static

This function parses the time quota file and stores it in memory.

Definition at line 257 of file ext_time_quota_acl.cc.

References KEY_PERIOD_LENGTH_CONFIGURED, KEY_PERIOD_START, KEY_TIME_BUDGET_CONFIGURED, KEY_TIME_BUDGET_LEFT, log_debug(), log_info(), NULL, parseTime(), readTime(), TQ_BUFFERSIZE, and writeTime().

Referenced by main().

◆ readTime()

static time_t readTime ( const char *  user_key,
const char *  sub_key 
)
static

Definition at line 187 of file ext_time_quota_acl.cc.

References db, KeyString(), log_debug(), and log_error().

Referenced by processActivity(), and readConfig().

◆ shutdown_db()

static void shutdown_db ( void  )
static

Definition at line 146 of file ext_time_quota_acl.cc.

References db.

Referenced by main().

◆ usage()

static void usage ( void  )
static

Definition at line 398 of file ext_time_quota_acl.cc.

References log_error(), and program_name.

Referenced by main().

◆ vlog()

static void vlog ( const char *  level,
const char *  format,
va_list  args 
)
static

Definition at line 88 of file ext_time_quota_acl.cc.

References logfile, now, NULL, and program_name.

Referenced by log_debug(), log_error(), log_fatal(), and log_info().

◆ writeTime()

static void writeTime ( const char *  user_key,
const char *  sub_key,
time_t  t 
)
static

Definition at line 169 of file ext_time_quota_acl.cc.

References db, KeyString(), and log_debug().

Referenced by processActivity(), and readConfig().

Variable Documentation

◆ db

◆ db_path

const char* db_path = DEFAULT_QUOTA_DB

Definition at line 52 of file ext_time_quota_acl.cc.

Referenced by init_db(), and main().

◆ logfile

◆ pauseLength

int pauseLength = 300
static

If there is more than this given number of seconds between two successive requests, than the second request will be treated as a new request and the time between first and seconds request will be treated as a activity pause.

Otherwise the following request will be treated as belonging to the same activity and the quota will be reduced.

Definition at line 74 of file ext_time_quota_acl.cc.

Referenced by main(), and processActivity().

◆ program_name

const char* program_name

Definition at line 53 of file ext_time_quota_acl.cc.

Referenced by main(), usage(), and vlog().

◆ tq_debug_enabled

int tq_debug_enabled = false
static

Definition at line 77 of file ext_time_quota_acl.cc.

Referenced by log_debug(), and main().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors