ext_time_quota_acl.cc File Reference
#include "squid.h"
#include "helper/protocol_defines.h"
#include <cstdarg>
#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 __BIT_TYPES_DEFINED__
 
#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 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
 
DB * db = NULL
 
static int pauseLength = 300
 
static FILE * logfile = stderr
 
static int tq_debug_enabled = false
 

Macro Definition Documentation

#define __BIT_TYPES_DEFINED__

Definition at line 51 of file ext_time_quota_acl.cc.

#define KEY_LAST_ACTIVITY   "last-activity"

Definition at line 69 of file ext_time_quota_acl.cc.

Referenced by processActivity().

#define KEY_PERIOD_LENGTH_CONFIGURED   "period-length-configured"

Definition at line 71 of file ext_time_quota_acl.cc.

Referenced by processActivity(), and readConfig().

#define KEY_PERIOD_START   "period-start"

Definition at line 70 of file ext_time_quota_acl.cc.

Referenced by processActivity(), and readConfig().

#define KEY_TIME_BUDGET_CONFIGURED   "time-budget-configured"

Definition at line 73 of file ext_time_quota_acl.cc.

Referenced by processActivity(), and readConfig().

#define KEY_TIME_BUDGET_LEFT   "time-budget-left"

Definition at line 72 of file ext_time_quota_acl.cc.

Referenced by processActivity(), and readConfig().

#define TQ_BUFFERSIZE   1024

Maximum size of buffers used to read or display lines.

Definition at line 76 of file ext_time_quota_acl.cc.

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

Function Documentation

static void init_db ( void  )
static

Definition at line 148 of file ext_time_quota_acl.cc.

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

Referenced by main().

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

Definition at line 110 of file ext_time_quota_acl.cc.

References tq_debug_enabled, and vlog().

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

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

Definition at line 130 of file ext_time_quota_acl.cc.

References vlog().

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

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

Definition at line 139 of file ext_time_quota_acl.cc.

References vlog().

Referenced by init_db().

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

Definition at line 121 of file ext_time_quota_acl.cc.

References vlog().

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

static void open_log ( const char *  logfilename)
static

Definition at line 91 of file ext_time_quota_acl.cc.

References logfile, and NULL.

Referenced by main().

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

Definition at line 208 of file ext_time_quota_acl.cc.

References log_error(), and NULL.

Referenced by readConfig().

static void processActivity ( const char *  user_key)
static
static void readConfig ( const char *  filename)
static

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

Definition at line 253 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().

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

Definition at line 182 of file ext_time_quota_acl.cc.

References data, db, key, log_debug(), log_error(), and TQ_BUFFERSIZE.

Referenced by processActivity(), and readConfig().

static void shutdown_db ( void  )
static

Definition at line 158 of file ext_time_quota_acl.cc.

References db.

Referenced by main().

static void usage ( void  )
static

Definition at line 396 of file ext_time_quota_acl.cc.

References log_error(), and program_name.

Referenced by main().

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

Definition at line 100 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().

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

Definition at line 163 of file ext_time_quota_acl.cc.

References data, db, key, log_debug(), log_error(), and TQ_BUFFERSIZE.

Referenced by processActivity(), and readConfig().

Variable Documentation

DB* db = NULL

Definition at line 67 of file ext_time_quota_acl.cc.

Referenced by init_db(), processActivity(), readTime(), shutdown_db(), and writeTime().

const char* db_path = DEFAULT_QUOTA_DB

Definition at line 64 of file ext_time_quota_acl.cc.

Referenced by init_db(), and main().

FILE* logfile = stderr
static

Definition at line 88 of file ext_time_quota_acl.cc.

Referenced by debugOpenLog(), main(), open_log(), and vlog().

int pauseLength = 300
static

If there is more than this given number of seconds between two sucessive 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 86 of file ext_time_quota_acl.cc.

Referenced by main(), and processActivity().

const char* program_name

Definition at line 65 of file ext_time_quota_acl.cc.

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

int tq_debug_enabled = false
static

Definition at line 89 of file ext_time_quota_acl.cc.

Referenced by log_debug(), and main().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors