ext_time_quota_acl.cc File Reference
#include "squid.h"
#include "debug/Stream.h"
#include "helper/protocol_defines.h"
#include "sbuf/Stream.h"
#include <ctime>
Include dependency graph for ext_time_quota_acl.cc:

Go to the source code of this file.

Functions

static void init_db (void)
 
static void shutdown_db (void)
 
static SBuf KeyString (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

static const auto MY_DEBUG_SECTION = 82
 
const char * db_path = DEFAULT_QUOTA_DB
 
const char * program_name
 
TDB_CONTEXT * db = nullptr
 
static const auto KeyLastActivity = "last-activity"
 
static const auto KeyPeriodStart = "period-start"
 
static const auto KeyPeriodLengthConfigured = "period-length-configured"
 
static const auto KeyTimeBudgetLeft = "time-budget-left"
 
static const auto KeyTimeBudgetConfigured = "time-budget-configured"
 
static const size_t TQ_BUFFERSIZE = 1024
 
static int pauseLength = 300
 

Function Documentation

◆ init_db()

static void init_db ( void  )
static

Definition at line 73 of file ext_time_quota_acl.cc.

References db, db_path, DBG_CRITICAL, debugs, and MY_DEBUG_SECTION.

Referenced by main().

◆ KeyString()

static SBuf KeyString ( const char *  user_key,
const char *  sub_key 
)
static

Definition at line 91 of file ext_time_quota_acl.cc.

References ToSBuf().

Referenced by readTime(), and writeTime().

◆ main()

◆ parseTime()

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

Definition at line 140 of file ext_time_quota_acl.cc.

References DBG_IMPORTANT, debugs, MY_DEBUG_SECTION, 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 185 of file ext_time_quota_acl.cc.

References DBG_IMPORTANT, debugs, KeyPeriodLengthConfigured, KeyPeriodStart, KeyTimeBudgetConfigured, KeyTimeBudgetLeft, MY_DEBUG_SECTION, 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 112 of file ext_time_quota_acl.cc.

References db, DBG_IMPORTANT, debugs, KeyString(), and MY_DEBUG_SECTION.

Referenced by processActivity(), and readConfig().

◆ shutdown_db()

static void shutdown_db ( void  )
static

Definition at line 86 of file ext_time_quota_acl.cc.

References db.

Referenced by main().

◆ usage()

static void usage ( void  )
static

Definition at line 326 of file ext_time_quota_acl.cc.

References DBG_CRITICAL, debugs, MY_DEBUG_SECTION, and program_name.

Referenced by main().

◆ writeTime()

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

Definition at line 96 of file ext_time_quota_acl.cc.

References db, debugs, KeyString(), and MY_DEBUG_SECTION.

Referenced by processActivity(), and readConfig().

Variable Documentation

◆ db

◆ db_path

const char* db_path = DEFAULT_QUOTA_DB

Definition at line 49 of file ext_time_quota_acl.cc.

Referenced by init_db(), and main().

◆ KeyLastActivity

const auto KeyLastActivity = "last-activity"
static

Definition at line 54 of file ext_time_quota_acl.cc.

Referenced by processActivity().

◆ KeyPeriodLengthConfigured

const auto KeyPeriodLengthConfigured = "period-length-configured"
static

Definition at line 56 of file ext_time_quota_acl.cc.

Referenced by processActivity(), and readConfig().

◆ KeyPeriodStart

const auto KeyPeriodStart = "period-start"
static

Definition at line 55 of file ext_time_quota_acl.cc.

Referenced by processActivity(), and readConfig().

◆ KeyTimeBudgetConfigured

const auto KeyTimeBudgetConfigured = "time-budget-configured"
static

Definition at line 58 of file ext_time_quota_acl.cc.

Referenced by processActivity(), and readConfig().

◆ KeyTimeBudgetLeft

const auto KeyTimeBudgetLeft = "time-budget-left"
static

Definition at line 57 of file ext_time_quota_acl.cc.

Referenced by processActivity(), and readConfig().

◆ MY_DEBUG_SECTION

const auto MY_DEBUG_SECTION = 82
static

◆ 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 71 of file ext_time_quota_acl.cc.

Referenced by main(), and processActivity().

◆ program_name

const char* program_name

Definition at line 50 of file ext_time_quota_acl.cc.

Referenced by main(), and usage().

◆ TQ_BUFFERSIZE

const size_t TQ_BUFFERSIZE = 1024
static

Maximum size of buffers used to read or display lines.

Definition at line 61 of file ext_time_quota_acl.cc.

Referenced by readConfig().

 

Introduction

Documentation

Support

Miscellaneous