Use standard bool types.
I'm using `stdbool.h` for the few remaining C files. That will have to change, soon.
This commit is contained in:
132
dpi/cookies.cc
132
dpi/cookies.cc
@ -103,9 +103,9 @@ typedef struct {
|
||||
char *domain;
|
||||
char *path;
|
||||
time_t expires_at;
|
||||
bool_t host_only;
|
||||
bool_t secure;
|
||||
bool_t session_only;
|
||||
bool host_only;
|
||||
bool secure;
|
||||
bool session_only;
|
||||
long last_used;
|
||||
} CookieData_t;
|
||||
|
||||
@ -130,7 +130,7 @@ static int num_ccontrol_max = 1;
|
||||
static CookieControlAction default_action = COOKIE_DENY;
|
||||
|
||||
static long cookies_use_counter = 0;
|
||||
static bool_t disabled;
|
||||
static bool disabled;
|
||||
static FILE *file_stream;
|
||||
static const char *const cookies_txt_header_str =
|
||||
"# HTTP Cookie File\n"
|
||||
@ -279,15 +279,15 @@ static void Cookies_load_cookies(FILE *stream)
|
||||
char *line_marker = line;
|
||||
CookieData_t *cookie = dNew0(CookieData_t, 1);
|
||||
|
||||
cookie->session_only = FALSE;
|
||||
cookie->session_only = false;
|
||||
cookie->domain = dStrdup(dStrsep(&line_marker, "\t"));
|
||||
piece = dStrsep(&line_marker, "\t");
|
||||
if (piece != NULL && piece[0] == 'F')
|
||||
cookie->host_only = TRUE;
|
||||
cookie->host_only = true;
|
||||
cookie->path = dStrdup(dStrsep(&line_marker, "\t"));
|
||||
piece = dStrsep(&line_marker, "\t");
|
||||
if (piece != NULL && piece[0] == 'T')
|
||||
cookie->secure = TRUE;
|
||||
cookie->secure = true;
|
||||
piece = dStrsep(&line_marker, "\t");
|
||||
if (piece != NULL) {
|
||||
/* There is some problem with simply putting the maximum value
|
||||
@ -318,7 +318,7 @@ static void Cookies_load_cookies(FILE *stream)
|
||||
Cookies_free_cookie(cookie);
|
||||
continue;
|
||||
} else if (action == COOKIE_ACCEPT_SESSION) {
|
||||
cookie->session_only = TRUE;
|
||||
cookie->session_only = true;
|
||||
}
|
||||
|
||||
/* Save cookie in memory */
|
||||
@ -341,7 +341,7 @@ static void Cookies_init(void)
|
||||
struct tm future_tm = {7, 14, 3, 19, 0, 138, 0, 0, 0, 0, 0};
|
||||
|
||||
/* Default setting */
|
||||
disabled = TRUE;
|
||||
disabled = true;
|
||||
|
||||
cookies_epoch_time = mktime(&cookies_epoch_tm);
|
||||
cookies_future_time = mktime(&future_tm);
|
||||
@ -457,7 +457,7 @@ static void Cookies_save_and_free(void)
|
||||
/*
|
||||
* Month parsing
|
||||
*/
|
||||
static bool_t Cookies_get_month(struct tm *tm, const char **str)
|
||||
static bool Cookies_get_month(struct tm *tm, const char **str)
|
||||
{
|
||||
static const char *const months[] =
|
||||
{ "Jan", "Feb", "Mar",
|
||||
@ -472,10 +472,10 @@ static bool_t Cookies_get_month(struct tm *tm, const char **str)
|
||||
_MSG("Found month: %s\n", months[i]);
|
||||
tm->tm_mon = i;
|
||||
*str += 3;
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -505,47 +505,47 @@ static int Cookies_get_timefield(const char **str)
|
||||
* Time parsing: 'time-field ":" time-field ":" time-field'
|
||||
* 'time-field = 1*2DIGIT'
|
||||
*/
|
||||
static bool_t Cookies_get_time(struct tm *tm, const char **str)
|
||||
static bool Cookies_get_time(struct tm *tm, const char **str)
|
||||
{
|
||||
const char *s = *str;
|
||||
|
||||
if ((tm->tm_hour = Cookies_get_timefield(&s)) == -1)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
if (*(s++) != ':')
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
if ((tm->tm_min = Cookies_get_timefield(&s)) == -1)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
if (*(s++) != ':')
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
if ((tm->tm_sec = Cookies_get_timefield(&s)) == -1)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
*str = s;
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Day parsing: "day-of-month = 1*2DIGIT"
|
||||
*/
|
||||
static bool_t Cookies_get_day(struct tm *tm, const char **str)
|
||||
static bool Cookies_get_day(struct tm *tm, const char **str)
|
||||
{
|
||||
const char *s = *str;
|
||||
|
||||
if ((tm->tm_mday = Cookies_get_timefield(&s)) == -1)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
*str = s;
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Date parsing: "year = 2*4DIGIT"
|
||||
*/
|
||||
static bool_t Cookies_get_year(struct tm *tm, const char **str)
|
||||
static bool Cookies_get_year(struct tm *tm, const char **str)
|
||||
{
|
||||
int n;
|
||||
const char *s = *str;
|
||||
@ -553,12 +553,12 @@ static bool_t Cookies_get_year(struct tm *tm, const char **str)
|
||||
if (isdigit(*s))
|
||||
n = *(s++) - '0';
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
if (isdigit(*s)) {
|
||||
n *= 10;
|
||||
n += *(s++) - '0';
|
||||
} else
|
||||
return FALSE;
|
||||
return false;
|
||||
if (isdigit(*s)) {
|
||||
n *= 10;
|
||||
n += *(s++) - '0';
|
||||
@ -569,7 +569,7 @@ static bool_t Cookies_get_year(struct tm *tm, const char **str)
|
||||
}
|
||||
if (isdigit(*s)) {
|
||||
/* Sorry, users of prehistoric software in the year 10000! */
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
if (n >= 70 && n <= 99)
|
||||
n += 1900;
|
||||
@ -579,13 +579,13 @@ static bool_t Cookies_get_year(struct tm *tm, const char **str)
|
||||
tm->tm_year = n - 1900;
|
||||
|
||||
*str = s;
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* As given in RFC 6265.
|
||||
*/
|
||||
static bool_t Cookies_date_delim(char c)
|
||||
static bool Cookies_date_delim(char c)
|
||||
{
|
||||
return (c == '\x09' ||
|
||||
(c >= '\x20' && c <= '\x2F') ||
|
||||
@ -605,13 +605,13 @@ static bool_t Cookies_date_delim(char c)
|
||||
*/
|
||||
static struct tm *Cookies_parse_date(const char *date)
|
||||
{
|
||||
bool_t found_time = FALSE, found_day = FALSE, found_month = FALSE,
|
||||
found_year = FALSE, matched;
|
||||
bool found_time = false, found_day = false, found_month = false,
|
||||
found_year = false, matched;
|
||||
struct tm *tm = dNew0(struct tm, 1);
|
||||
const char *s = date;
|
||||
|
||||
while (*s) {
|
||||
matched = FALSE;
|
||||
matched = false;
|
||||
|
||||
if (!found_time)
|
||||
matched = found_time = Cookies_get_time(tm, &s);
|
||||
@ -893,9 +893,9 @@ static CookieData_t *Cookies_parse(char *cookie_str, const char *server_date)
|
||||
{
|
||||
CookieData_t *cookie = NULL;
|
||||
char *str = cookie_str;
|
||||
bool_t first_attr = TRUE;
|
||||
bool_t max_age = FALSE;
|
||||
bool_t expires = FALSE;
|
||||
bool first_attr = true;
|
||||
bool max_age = false;
|
||||
bool expires = false;
|
||||
|
||||
/* Iterate until there is nothing left of the string */
|
||||
while (*str) {
|
||||
@ -1023,26 +1023,26 @@ static int Cookies_cmp(const void *a, const void *b)
|
||||
/*
|
||||
* Is the domain an IP address?
|
||||
*/
|
||||
static bool_t Cookies_domain_is_ip(const char *domain)
|
||||
static bool Cookies_domain_is_ip(const char *domain)
|
||||
{
|
||||
uint_t len;
|
||||
|
||||
if (!domain)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
len = strlen(domain);
|
||||
|
||||
if (len == strspn(domain, "0123456789.")) {
|
||||
_MSG("an IPv4 address\n");
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
if (strchr(domain, ':') &&
|
||||
(len == strspn(domain, "0123456789abcdefABCDEF:."))) {
|
||||
/* The precise format is shown in section 3.2.2 of rfc 3986 */
|
||||
MSG("an IPv6 address\n");
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1051,13 +1051,13 @@ static bool_t Cookies_domain_is_ip(const char *domain)
|
||||
* Note different user agents apparently vary in path-matching behaviour,
|
||||
* but this is the recommended method at the moment.
|
||||
*/
|
||||
static bool_t Cookies_path_matches(const char *url_path,
|
||||
static bool Cookies_path_matches(const char *url_path,
|
||||
const char *cookie_path)
|
||||
{
|
||||
bool_t ret = TRUE;
|
||||
bool ret = true;
|
||||
|
||||
if (!url_path || !cookie_path) {
|
||||
ret = FALSE;
|
||||
ret = false;
|
||||
} else {
|
||||
uint_t c_len = strlen(cookie_path);
|
||||
uint_t u_len = strlen(url_path);
|
||||
@ -1093,12 +1093,12 @@ static void Cookies_validate_path(CookieData_t *cookie, const char *url_path)
|
||||
/*
|
||||
* Check whether host name A domain-matches host name B.
|
||||
*/
|
||||
static bool_t Cookies_domain_matches(char *A, char *B)
|
||||
static bool Cookies_domain_matches(char *A, char *B)
|
||||
{
|
||||
int diff;
|
||||
|
||||
if (!A || !*A || !B || !*B)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
if (*B == '.')
|
||||
B++;
|
||||
@ -1109,10 +1109,10 @@ static bool_t Cookies_domain_matches(char *A, char *B)
|
||||
*/
|
||||
|
||||
if (!dStrAsciiCasecmp(A, B))
|
||||
return TRUE;
|
||||
return true;
|
||||
|
||||
if (Cookies_domain_is_ip(B))
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
diff = strlen(A) - strlen(B);
|
||||
|
||||
@ -1120,7 +1120,7 @@ static bool_t Cookies_domain_matches(char *A, char *B)
|
||||
/* B is the tail of A, and the match is preceded by a '.' */
|
||||
return (dStrAsciiCasecmp(A + diff, B) == 0 && A[diff - 1] == '.');
|
||||
} else {
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1178,18 +1178,18 @@ static uint_t Cookies_internal_dots_required(const char *host)
|
||||
/*
|
||||
* Validate cookies domain against some security checks.
|
||||
*/
|
||||
static bool_t Cookies_validate_domain(CookieData_t *cookie, char *host)
|
||||
static bool Cookies_validate_domain(CookieData_t *cookie, char *host)
|
||||
{
|
||||
uint_t i, internal_dots;
|
||||
|
||||
if (!cookie->domain) {
|
||||
cookie->domain = dStrdup(host);
|
||||
cookie->host_only = TRUE;
|
||||
return TRUE;
|
||||
cookie->host_only = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Cookies_domain_matches(host, cookie->domain))
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
internal_dots = 0;
|
||||
for (i = 1; i < strlen(cookie->domain) - 1; i++) {
|
||||
@ -1202,11 +1202,11 @@ static bool_t Cookies_validate_domain(CookieData_t *cookie, char *host)
|
||||
*/
|
||||
if (internal_dots < Cookies_internal_dots_required(host)) {
|
||||
MSG("not enough dots in %s\n", cookie->domain);
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
_MSG("host %s and domain %s is all right\n", host, cookie->domain);
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1252,29 +1252,29 @@ static int Cookies_set(char *cookie_string, char *url_host,
|
||||
/*
|
||||
* Compare the cookie with the supplied data to see whether it matches
|
||||
*/
|
||||
static bool_t Cookies_match(CookieData_t *cookie, const char *url_path,
|
||||
bool_t host_only_val, bool_t is_tls)
|
||||
static bool Cookies_match(CookieData_t *cookie, const char *url_path,
|
||||
bool host_only_val, bool is_tls)
|
||||
{
|
||||
if (cookie->host_only != host_only_val)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
/* Insecure cookies match both secure and insecure urls, secure
|
||||
cookies match only secure urls */
|
||||
if (cookie->secure && !is_tls)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
if (!Cookies_path_matches(url_path, cookie->path))
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
/* It's a match */
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void Cookies_add_matching_cookies(const char *domain,
|
||||
const char *url_path,
|
||||
bool_t host_only_val,
|
||||
bool host_only_val,
|
||||
Dlist *matching_cookies,
|
||||
bool_t is_tls)
|
||||
bool is_tls)
|
||||
{
|
||||
DomainNode *node = reinterpret_cast< DomainNode * >( dList_find_sorted(domains, domain,
|
||||
Domain_node_by_domain_cmp) );
|
||||
@ -1324,7 +1324,7 @@ static std::string Cookies_get(char *url_host, char *url_path,
|
||||
char *domain_str;
|
||||
CookieData_t *cookie;
|
||||
Dlist *matching_cookies;
|
||||
bool_t is_tls, is_ip_addr, host_only_val;
|
||||
bool is_tls, is_ip_addr, host_only_val;
|
||||
|
||||
int i;
|
||||
|
||||
@ -1345,7 +1345,7 @@ static std::string Cookies_get(char *url_host, char *url_path,
|
||||
* attrs can have leading dots, which should be ignored for matching
|
||||
* purposes.
|
||||
*/
|
||||
host_only_val = FALSE;
|
||||
host_only_val = false;
|
||||
if (!is_ip_addr) {
|
||||
/* e.g., sub.example.com set a cookie with domain ".sub.example.com". */
|
||||
domain_str = dStrconcat(".", url_host, NULL);
|
||||
@ -1353,11 +1353,11 @@ static std::string Cookies_get(char *url_host, char *url_path,
|
||||
matching_cookies, is_tls);
|
||||
dFree(domain_str);
|
||||
}
|
||||
host_only_val = TRUE;
|
||||
host_only_val = true;
|
||||
/* e.g., sub.example.com set a cookie with no domain attribute. */
|
||||
Cookies_add_matching_cookies(url_host, url_path, host_only_val,
|
||||
matching_cookies, is_tls);
|
||||
host_only_val = FALSE;
|
||||
host_only_val = false;
|
||||
/* e.g., sub.example.com set a cookie with domain "sub.example.com". */
|
||||
Cookies_add_matching_cookies(url_host, url_path, host_only_val,
|
||||
matching_cookies, is_tls);
|
||||
@ -1422,7 +1422,7 @@ static int Cookie_control_init(void)
|
||||
char line[LINE_MAXLEN];
|
||||
char domain[LINE_MAXLEN];
|
||||
char rule[LINE_MAXLEN];
|
||||
bool_t enabled = FALSE;
|
||||
bool enabled = false;
|
||||
|
||||
/* Get a file pointer */
|
||||
filename = dStrconcat(dGethomedir(), "/.flenser/cookiesrc", NULL);
|
||||
|
@ -702,7 +702,7 @@ static int File_send_file(ClientInfo *client)
|
||||
const char *unknown_type = "application/octet-stream";
|
||||
char buf[LBUF], *d_cmd, *name;
|
||||
int st, st2, namelen;
|
||||
bool_t gzipped = FALSE;
|
||||
bool gzipped = false;
|
||||
|
||||
if (client->state == st_start) {
|
||||
/* Send DPI command */
|
||||
@ -719,7 +719,7 @@ static int File_send_file(ClientInfo *client)
|
||||
namelen = strlen(client->filename);
|
||||
if (namelen > 3 &&
|
||||
!dStrAsciiCasecmp(client->filename + namelen - 3, ".gz")) {
|
||||
gzipped = TRUE;
|
||||
gzipped = true;
|
||||
namelen -= 3;
|
||||
}
|
||||
/* Content-Type info is based on filename extension (with ".gz" removed).
|
||||
|
Reference in New Issue
Block a user