28 MSG(
"Cookies: absolutely disabled at compilation time.\n");
47#include "../dpip/dpip.h"
51#define LINE_MAXLEN 4096
86 if ((F_in = fopen(filename,
"r")) == NULL) {
88 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
91 rc = write(fd, init_str, strlen(init_str));
93 MSG(
"Cookies: Could not write initial string to file %s: %s\n",
99 MSG(
"Cookies: Created file: %s\n", filename);
100 F_in = fopen(filename,
"r");
102 MSG(
"Cookies: Could not create file: %s!\n", filename);
108 fcntl(fileno(F_in), F_SETFD, FD_CLOEXEC | fcntl(fileno(F_in), F_GETFD));
125 MSG(
"Disabling cookies.\n");
129 MSG(
"Enabling cookies as from cookiesrc...\n");
147 char *cmd, *cookie_string, *dpip_tag;
160 for (i = 0; (cookie_string =
dList_nth_data(cookie_strings, i)); ++i) {
164 "set_cookie", cookie_string,
168 "set_cookie", cookie_string,
171 _MSG(
"Cookies.c: a_Cookies_set \n\t \"%s\" \n",cmd );
177 _MSG(
"a_Cookies_set: dpip_tag = {%s}\n", dpip_tag);
189 char *cmd, *dpip_tag, *query;
202 if (requester == NULL) {
205 MSG(
"Cookies: not sent for non-root request by '%s' for '%s'\n",
217 _MSG(
"cookies.c: a_Dpi_send_blocking_cmd cmd = {%s}\n", cmd);
219 _MSG(
"cookies.c: after a_Dpi_send_blocking_cmd resp={%s}\n", dpip_tag);
222 if (dpip_tag != NULL) {
262 while (!feof(stream)) {
265 if (!rc && ferror(stream)) {
266 MSG(
"Cookies1: Error while reading rule from cookiesrc: %s\n",
275 if (line[0] !=
'\0' && line[0] !=
'#') {
279 while (line[i] !=
'\0' && !
dIsspace(line[i]))
280 domain[j++] = line[i++];
289 while (line[i] !=
'\0' && !
dIsspace(line[i]))
290 rule[j++] = line[i++];
300 MSG(
"Cookies: rule '%s' for domain '%s' is not recognised.\n",
312 uint_t len = strlen(cc.domain);
317 i > 0 && (len > strlen(
ccontrol[i-1].domain));
331 return (enabled ? 0 : 1);
345 diff = strlen(domain) - strlen(
ccontrol[i].domain);
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
int dStrAsciiCasecmp(const char *s1, const char *s2)
char * dStrstrip(char *s)
Remove leading and trailing whitespace.
char * dStrdup(const char *s)
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
int dClose(int fd)
Close a FD handling EINTR.
char * dGethomedir(void)
Return the home directory in a static string (don't free)
static int num_ccontrol_max
static CookieControl * ccontrol
static int Cookie_control_init(void)
#define a_List_add(list, num_items, alloc_step)
static CookieControlAction default_action
static CookieControlAction Cookies_control_check_domain(const char *domain)
static FILE * Cookies_fopen(const char *filename, const char *mode, const char *init_str)
char * a_Dpip_build_cmd(const char *format,...)
Printf like function for building dpip commands.
char * a_Dpip_get_attr(const char *tag, const char *attrname)
Task: given a tag and an attribute name, return its value.
char * a_Dpi_send_blocking_cmd(const char *server_name, const char *cmd)
Send a command to a dpi server, and block until the answer is got.
void a_Cookies_init(void)
Initialize the cookies module (The 'disabled' variable is writable only within a_Cookies_init)
static CookieControlAction Cookies_control_check(const DilloUrl *url)
Same as Cookies_control_check_domain except it takes an URL.
void a_Cookies_freeall(void)
Flush cookies to disk and free all the memory allocated.
void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url, const char *date)
Set the value corresponding to the cookie string.
char * a_Cookies_get_query(const DilloUrl *query_url, const DilloUrl *requester, int is_root_url)
Return a string containing cookie data for an HTTP query.
bool_t a_Url_same_organization(const DilloUrl *u1, const DilloUrl *u2)