Dillo v3.1.1-91-g6d5b3ee3
Loading...
Searching...
No Matches
cookies.c File Reference
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <limits.h>
#include <netdb.h>
#include <signal.h>
#include "dpiutil.h"
#include "../dpip/dpip.h"
Include dependency graph for cookies.c:

Go to the source code of this file.

Macros

#define _MSG(...)
 
#define MSG(...)   printf("[cookies dpi]: " __VA_ARGS__)
 
#define a_List_add(list, num_items, alloc_step)
 
#define LINE_MAXLEN   4096
 
#define MAX_DOMAIN_COOKIES   20
 
#define MAX_TOTAL_COOKIES   1200
 

Enumerations

enum  CookieControlAction { COOKIE_ACCEPT , COOKIE_ACCEPT_SESSION , COOKIE_DENY }
 

Functions

static CookieControlAction Cookies_control_check_domain (const char *domain)
 
static int Cookie_control_init (void)
 
static void Cookies_add_cookie (CookieData_t *cookie)
 
static int Cookies_cmp (const void *a, const void *b)
 
static int Domain_node_cmp (const void *v1, const void *v2)
 
static int Domain_node_by_domain_cmp (const void *v1, const void *v2)
 
static void Cookies_delete_node (DomainNode *node)
 
static FILE * Cookies_fopen (const char *filename, const char *mode, const char *init_str)
 
static void Cookies_free_cookie (CookieData_t *cookie)
 
static void Cookies_tm_init (struct tm *tm)
 
static void Cookies_load_cookies (FILE *stream)
 
static void Cookies_init (void)
 
static void Cookies_save_and_free (void)
 
static bool_t Cookies_get_month (struct tm *tm, const char **str)
 
static int Cookies_get_timefield (const char **str)
 
static bool_t Cookies_get_time (struct tm *tm, const char **str)
 
static bool_t Cookies_get_day (struct tm *tm, const char **str)
 
static bool_t Cookies_get_year (struct tm *tm, const char **str)
 
static bool_t Cookies_date_delim (char c)
 
static struct tm * Cookies_parse_date (const char *date)
 
static CookieData_t * Cookies_get_LRU (Dlist *cookies)
 
static int Cookies_rm_expired_cookies (DomainNode *node)
 
static void Cookies_too_many (DomainNode *node)
 
static char * Cookies_parse_attr (char **cookie_str)
 
static char * Cookies_parse_value (char **cookie_str)
 
static void Cookies_eat_value (char **cookie_str)
 
static double Cookies_server_timediff (const char *server_date)
 
static void Cookies_unquote_string (char *str)
 
static CookieData_t * Cookies_parse (char *cookie_str, const char *server_date)
 
static bool_t Cookies_domain_is_ip (const char *domain)
 
static bool_t Cookies_path_matches (const char *url_path, const char *cookie_path)
 
static void Cookies_validate_path (CookieData_t *cookie, const char *url_path)
 
static bool_t Cookies_domain_matches (char *A, char *B)
 
static uint_t Cookies_internal_dots_required (const char *host)
 
static bool_t Cookies_validate_domain (CookieData_t *cookie, char *host)
 
static int Cookies_set (char *cookie_string, char *url_host, char *url_path, char *server_date)
 
static bool_t Cookies_match (CookieData_t *cookie, const char *url_path, bool_t host_only_val, bool_t is_tls)
 
static void Cookies_add_matching_cookies (const char *domain, const char *url_path, bool_t host_only_val, Dlist *matching_cookies, bool_t is_tls)
 
static char * Cookies_get (char *url_host, char *url_path, char *url_scheme)
 
static int srv_parse_tok (Dsh *sh, ClientInfo *client, char *Buf)
 
static void cleanup (void)
 
static void termination_handler (int signum)
 
int main (void)
 

Variables

static Dlistall_cookies
 
static Dlistdomains
 
static CookieControl * ccontrol = NULL
 
static int num_ccontrol = 0
 
static int num_ccontrol_max = 1
 
static CookieControlAction default_action = COOKIE_DENY
 
static long cookies_use_counter = 0
 
static bool_t disabled
 
static FILE * file_stream
 
static const char *const cookies_txt_header_str
 
static struct tm cookies_epoch_tm = {0, 0, 0, 1, 0, 70, 0, 0, 0, 0, 0}
 
static time_t cookies_epoch_time
 
static time_t cookies_future_time
 

Macro Definition Documentation

◆ _MSG

#define _MSG (   ...)

Definition at line 58 of file cookies.c.

◆ a_List_add

#define a_List_add (   list,
  num_items,
  alloc_step 
)
Value:
if (!list) { \
list = dMalloc(alloc_step * sizeof((*list))); \
} \
if (num_items >= alloc_step){ \
while ( num_items >= alloc_step ) \
alloc_step <<= 1; \
list = dRealloc(list, alloc_step * sizeof((*list))); \
}
void * dMalloc(size_t size)
Definition dlib.c:45
void * dRealloc(void *mem, size_t size)
Definition dlib.c:53

Definition at line 68 of file cookies.c.

◆ LINE_MAXLEN

#define LINE_MAXLEN   4096

Definition at line 79 of file cookies.c.

◆ MAX_DOMAIN_COOKIES

#define MAX_DOMAIN_COOKIES   20

Definition at line 81 of file cookies.c.

◆ MAX_TOTAL_COOKIES

#define MAX_TOTAL_COOKIES   1200

Definition at line 82 of file cookies.c.

◆ MSG

#define MSG (   ...)    printf("[cookies dpi]: " __VA_ARGS__)

Definition at line 59 of file cookies.c.

Enumeration Type Documentation

◆ CookieControlAction

Enumerator
COOKIE_ACCEPT 
COOKIE_ACCEPT_SESSION 
COOKIE_DENY 

Definition at line 84 of file cookies.c.

Function Documentation

◆ cleanup()

static void cleanup ( void  )
static

Definition at line 1620 of file cookies.c.

References Cookies_save_and_free(), and MSG.

Referenced by main().

◆ Cookie_control_init()

◆ Cookies_add_cookie()

◆ Cookies_add_matching_cookies()

static void Cookies_add_matching_cookies ( const char *  domain,
const char *  url_path,
bool_t  host_only_val,
Dlist matching_cookies,
bool_t  is_tls 
)
static

◆ Cookies_cmp()

static int Cookies_cmp ( const void *  a,
const void *  b 
)
static

Definition at line 1014 of file cookies.c.

Referenced by Cookies_add_cookie().

◆ Cookies_control_check_domain()

static CookieControlAction Cookies_control_check_domain ( const char *  domain)
static

◆ Cookies_date_delim()

static bool_t Cookies_date_delim ( char  c)
static

Definition at line 588 of file cookies.c.

Referenced by Cookies_parse_date().

◆ Cookies_delete_node()

static void Cookies_delete_node ( DomainNode *  node)
static

◆ Cookies_domain_is_ip()

static bool_t Cookies_domain_is_ip ( const char *  domain)
static

Definition at line 1026 of file cookies.c.

References _MSG, FALSE, MSG, and TRUE.

Referenced by Cookies_domain_matches(), and Cookies_get().

◆ Cookies_domain_matches()

static bool_t Cookies_domain_matches ( char *  A,
char *  B 
)
static

Definition at line 1096 of file cookies.c.

References Cookies_domain_is_ip(), dStrAsciiCasecmp(), FALSE, and TRUE.

Referenced by Cookies_validate_domain().

◆ Cookies_eat_value()

static void Cookies_eat_value ( char **  cookie_str)
static

Definition at line 847 of file cookies.c.

Referenced by Cookies_parse().

◆ Cookies_fopen()

static FILE * Cookies_fopen ( const char *  filename,
const char *  mode,
const char *  init_str 
)
static

Definition at line 191 of file cookies.c.

References dStrerror, and MSG.

Referenced by Cookie_control_init(), and Cookies_init().

◆ Cookies_free_cookie()

static void Cookies_free_cookie ( CookieData_t *  cookie)
static

◆ Cookies_get()

static char * Cookies_get ( char *  url_host,
char *  url_path,
char *  url_scheme 
)
static

◆ Cookies_get_day()

static bool_t Cookies_get_day ( struct tm *  tm,
const char **  str 
)
static

Definition at line 534 of file cookies.c.

References Cookies_get_timefield(), FALSE, and TRUE.

Referenced by Cookies_parse_date().

◆ Cookies_get_LRU()

static CookieData_t * Cookies_get_LRU ( Dlist cookies)
static

Definition at line 656 of file cookies.c.

References dList_length(), and dList_nth_data().

Referenced by Cookies_too_many().

◆ Cookies_get_month()

static bool_t Cookies_get_month ( struct tm *  tm,
const char **  str 
)
static

Definition at line 460 of file cookies.c.

References _MSG, dStrnAsciiCasecmp(), FALSE, and TRUE.

Referenced by Cookies_parse_date().

◆ Cookies_get_time()

static bool_t Cookies_get_time ( struct tm *  tm,
const char **  str 
)
static

Definition at line 508 of file cookies.c.

References Cookies_get_timefield(), FALSE, and TRUE.

Referenced by Cookies_parse_date().

◆ Cookies_get_timefield()

static int Cookies_get_timefield ( const char **  str)
static

Definition at line 485 of file cookies.c.

Referenced by Cookies_get_day(), and Cookies_get_time().

◆ Cookies_get_year()

static bool_t Cookies_get_year ( struct tm *  tm,
const char **  str 
)
static

Definition at line 548 of file cookies.c.

References FALSE, and TRUE.

Referenced by Cookies_parse_date().

◆ Cookies_init()

◆ Cookies_internal_dots_required()

static uint_t Cookies_internal_dots_required ( const char *  host)
static

Definition at line 1136 of file cookies.c.

References _MSG, and dStrnAsciiCasecmp().

Referenced by Cookies_validate_domain().

◆ Cookies_load_cookies()

◆ Cookies_match()

static bool_t Cookies_match ( CookieData_t *  cookie,
const char *  url_path,
bool_t  host_only_val,
bool_t  is_tls 
)
static

Definition at line 1255 of file cookies.c.

References Cookies_path_matches(), FALSE, and TRUE.

Referenced by Cookies_add_matching_cookies().

◆ Cookies_parse()

static CookieData_t * Cookies_parse ( char *  cookie_str,
const char *  server_date 
)
static

◆ Cookies_parse_attr()

static char * Cookies_parse_attr ( char **  cookie_str)
static

Definition at line 799 of file cookies.c.

References dIsspace, and dStrndup().

Referenced by Cookies_parse().

◆ Cookies_parse_date()

static struct tm * Cookies_parse_date ( const char *  date)
static

◆ Cookies_parse_value()

static char * Cookies_parse_value ( char **  cookie_str)
static

Definition at line 820 of file cookies.c.

References dIsspace, and dStrndup().

Referenced by Cookies_parse().

◆ Cookies_path_matches()

static bool_t Cookies_path_matches ( const char *  url_path,
const char *  cookie_path 
)
static

Definition at line 1054 of file cookies.c.

References FALSE, and TRUE.

Referenced by Cookies_match().

◆ Cookies_rm_expired_cookies()

static int Cookies_rm_expired_cookies ( DomainNode *  node)
static

◆ Cookies_save_and_free()

static void Cookies_save_and_free ( void  )
static

◆ Cookies_server_timediff()

static double Cookies_server_timediff ( const char *  server_date)
static

Definition at line 857 of file cookies.c.

References Cookies_parse_date(), and dFree().

Referenced by Cookies_parse().

◆ Cookies_set()

static int Cookies_set ( char *  cookie_string,
char *  url_host,
char *  url_path,
char *  server_date 
)
static

◆ Cookies_tm_init()

static void Cookies_tm_init ( struct tm *  tm)
static

Definition at line 234 of file cookies.c.

References cookies_epoch_tm.

Referenced by Cookies_load_cookies().

◆ Cookies_too_many()

static void Cookies_too_many ( DomainNode *  node)
static

◆ Cookies_unquote_string()

static void Cookies_unquote_string ( char *  str)
static

Definition at line 875 of file cookies.c.

Referenced by Cookies_parse().

◆ Cookies_validate_domain()

static bool_t Cookies_validate_domain ( CookieData_t *  cookie,
char *  host 
)
static

Definition at line 1181 of file cookies.c.

References _MSG, Cookies_domain_matches(), Cookies_internal_dots_required(), dStrdup(), FALSE, MSG, and TRUE.

Referenced by Cookies_set().

◆ Cookies_validate_path()

static void Cookies_validate_path ( CookieData_t *  cookie,
const char *  url_path 
)
static

Definition at line 1076 of file cookies.c.

References dFree(), dStrdup(), and dStrndup().

Referenced by Cookies_set().

◆ Domain_node_by_domain_cmp()

static int Domain_node_by_domain_cmp ( const void *  v1,
const void *  v2 
)
static

◆ Domain_node_cmp()

static int Domain_node_cmp ( const void *  v1,
const void *  v2 
)
static

Definition at line 158 of file cookies.c.

References dStrAsciiCasecmp().

Referenced by Cookies_add_cookie().

◆ main()

◆ srv_parse_tok()

static int srv_parse_tok ( Dsh sh,
ClientInfo *  client,
char *  Buf 
)
static

◆ termination_handler()

static void termination_handler ( int  signum)
static

Definition at line 1630 of file cookies.c.

Referenced by main().

Variable Documentation

◆ all_cookies

◆ ccontrol

CookieControl* ccontrol = NULL
static

Definition at line 127 of file cookies.c.

Referenced by Cookie_control_init(), and Cookies_control_check_domain().

◆ cookies_epoch_time

time_t cookies_epoch_time
static

Definition at line 144 of file cookies.c.

Referenced by Cookies_init(), and Cookies_save_and_free().

◆ cookies_epoch_tm

struct tm cookies_epoch_tm = {0, 0, 0, 1, 0, 70, 0, 0, 0, 0, 0}
static

Definition at line 143 of file cookies.c.

Referenced by Cookies_init(), and Cookies_tm_init().

◆ cookies_future_time

time_t cookies_future_time
static

Definition at line 144 of file cookies.c.

Referenced by Cookies_init(), and Cookies_parse().

◆ cookies_txt_header_str

const char* const cookies_txt_header_str
static
Initial value:
=
"# HTTP Cookie File\n"
"# This is a generated file! Do not edit.\n"
"# [domain subdomains path secure expiry_time name value]\n\n"

Definition at line 135 of file cookies.c.

Referenced by Cookies_init(), and Cookies_save_and_free().

◆ cookies_use_counter

long cookies_use_counter = 0
static

Definition at line 132 of file cookies.c.

Referenced by Cookies_add_cookie(), Cookies_add_matching_cookies(), and Cookies_get().

◆ default_action

CookieControlAction default_action = COOKIE_DENY
static

Definition at line 130 of file cookies.c.

Referenced by Cookie_control_init(), and Cookies_control_check_domain().

◆ disabled

◆ domains

◆ file_stream

FILE* file_stream
static

Definition at line 134 of file cookies.c.

Referenced by Cookies_init(), and Cookies_save_and_free().

◆ num_ccontrol

int num_ccontrol = 0
static

Definition at line 128 of file cookies.c.

Referenced by Cookie_control_init(), and Cookies_control_check_domain().

◆ num_ccontrol_max

int num_ccontrol_max = 1
static

Definition at line 129 of file cookies.c.

Referenced by Cookie_control_init().