27 MSG(
"Cookies: absolutely disabled at compilation time.\n");
46#include "../dpip/dpip.h"
50#define LINE_MAXLEN 4096
85 if ((F_in = fopen(filename,
"r")) == NULL) {
87 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
90 rc = write(fd, init_str, strlen(init_str));
92 MSG(
"Cookies: Could not write initial string to file %s: %s\n",
98 MSG(
"Cookies: Created file: %s\n", filename);
99 F_in = fopen(filename,
"r");
101 MSG(
"Cookies: Could not create file: %s!\n", filename);
107 fcntl(fileno(F_in), F_SETFD, FD_CLOEXEC | fcntl(fileno(F_in), F_GETFD));
124 MSG(
"Disabling cookies.\n");
128 MSG(
"Enabling cookies as from cookiesrc...\n");
146 char *cmd, *cookie_string, *dpip_tag;
159 for (i = 0; (cookie_string =
dList_nth_data(cookie_strings, i)); ++i) {
163 "set_cookie", cookie_string,
167 "set_cookie", cookie_string,
170 _MSG(
"Cookies.c: a_Cookies_set \n\t \"%s\" \n",cmd );
176 _MSG(
"a_Cookies_set: dpip_tag = {%s}\n", dpip_tag);
187 char *cmd, *dpip_tag, *query;
200 if (requester == NULL) {
203 MSG(
"Cookies: not sent for request by '%s' for '%s'\n",
215 _MSG(
"cookies.c: a_Dpi_send_blocking_cmd cmd = {%s}\n", cmd);
217 _MSG(
"cookies.c: after a_Dpi_send_blocking_cmd resp={%s}\n", dpip_tag);
220 if (dpip_tag != NULL) {
260 while (!feof(stream)) {
263 if (!rc && ferror(stream)) {
264 MSG(
"Cookies1: Error while reading rule from cookiesrc: %s\n",
273 if (line[0] !=
'\0' && line[0] !=
'#') {
277 while (line[i] !=
'\0' && !
dIsspace(line[i]))
278 domain[j++] = line[i++];
287 while (line[i] !=
'\0' && !
dIsspace(line[i]))
288 rule[j++] = line[i++];
298 MSG(
"Cookies: rule '%s' for domain '%s' is not recognised.\n",
310 uint_t len = strlen(cc.domain);
315 i > 0 && (len > strlen(
ccontrol[i-1].domain));
329 return (enabled ? 0 : 1);
343 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.
char * a_Cookies_get_query(const DilloUrl *query_url, const DilloUrl *requester)
Return a string containing cookie data for an HTTP query.
void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url, const char *date)
Set the value corresponding to the cookie string.
bool_t a_Url_same_organization(const DilloUrl *u1, const DilloUrl *u2)