2013-07-25 19:07:46 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Michael Drake <tlsa@netsurf-browser.org>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-09-09 12:56:11 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Implementation of Cookie Management
|
|
|
|
*
|
|
|
|
* This allows users to view and remove their web cookies.
|
|
|
|
*
|
|
|
|
* \todo the viewing of cookies is pretty basic and it would be good
|
|
|
|
* to apply more processing of the values and perhaps top level domain
|
|
|
|
* suffix highlighting to give a better user information as to how the
|
|
|
|
* cookies interact with the users sessions.
|
|
|
|
*
|
|
|
|
* \todo In addition to removing cookies it might be useful to allow
|
|
|
|
* users to edit them, especially to alter expiry times.
|
2013-07-25 19:07:46 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2014-07-17 03:18:44 +04:00
|
|
|
#include <string.h>
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/log.h"
|
2014-07-17 03:18:44 +04:00
|
|
|
#include "content/urldb.h"
|
|
|
|
|
|
|
|
#include "desktop/cookie_manager.h"
|
|
|
|
#include "desktop/treeview.h"
|
2013-07-25 19:07:46 +04:00
|
|
|
|
2013-07-26 01:22:36 +04:00
|
|
|
enum cookie_manager_field {
|
2013-07-26 18:20:19 +04:00
|
|
|
COOKIE_M_NAME,
|
|
|
|
COOKIE_M_CONTENT,
|
|
|
|
COOKIE_M_DOMAIN,
|
|
|
|
COOKIE_M_PATH,
|
|
|
|
COOKIE_M_EXPIRES,
|
|
|
|
COOKIE_M_LAST_USED,
|
|
|
|
COOKIE_M_RESTRICTIONS,
|
|
|
|
COOKIE_M_VERSION,
|
|
|
|
COOKIE_M_DOMAIN_FOLDER,
|
|
|
|
COOKIE_M_N_FIELDS
|
2013-07-25 19:07:46 +04:00
|
|
|
};
|
|
|
|
|
2013-07-26 15:11:14 +04:00
|
|
|
enum cookie_manager_value {
|
2013-07-26 18:20:19 +04:00
|
|
|
COOKIE_M_HTTPS,
|
|
|
|
COOKIE_M_SECURE,
|
|
|
|
COOKIE_M_HTTP,
|
|
|
|
COOKIE_M_NONE,
|
|
|
|
COOKIE_M_NETSCAPE,
|
|
|
|
COOKIE_M_RFC2109,
|
|
|
|
COOKIE_M_RFC2965,
|
|
|
|
COOKIE_M_YES,
|
|
|
|
COOKIE_M_NO,
|
|
|
|
COOKIE_M_N_VALUES
|
2013-07-26 15:11:14 +04:00
|
|
|
};
|
|
|
|
|
2013-07-25 19:07:46 +04:00
|
|
|
struct cookie_manager_folder {
|
|
|
|
treeview_node *folder;
|
|
|
|
struct treeview_field_data data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cookie_manager_ctx {
|
|
|
|
treeview *tree;
|
2013-07-26 18:20:19 +04:00
|
|
|
struct treeview_field_desc fields[COOKIE_M_N_FIELDS];
|
|
|
|
struct treeview_field_data values[COOKIE_M_N_VALUES];
|
2013-07-25 19:07:46 +04:00
|
|
|
bool built;
|
|
|
|
};
|
|
|
|
struct cookie_manager_ctx cm_ctx;
|
|
|
|
|
|
|
|
struct cookie_manager_entry {
|
|
|
|
bool user_delete;
|
|
|
|
|
|
|
|
treeview_node *entry;
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
struct treeview_field_data data[COOKIE_M_N_FIELDS - 1];
|
2013-07-25 19:07:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct treeview_walk_ctx {
|
|
|
|
const char *title;
|
2013-07-26 01:31:27 +04:00
|
|
|
size_t title_len;
|
2013-07-25 19:07:46 +04:00
|
|
|
struct cookie_manager_folder *folder;
|
|
|
|
struct cookie_manager_entry *entry;
|
|
|
|
};
|
|
|
|
/** Callback for treeview_walk */
|
|
|
|
static nserror cookie_manager_walk_cb(void *ctx, void *node_data,
|
|
|
|
enum treeview_node_type type, bool *abort)
|
|
|
|
{
|
|
|
|
struct treeview_walk_ctx *tw = ctx;
|
|
|
|
|
|
|
|
if (type == TREE_NODE_ENTRY) {
|
|
|
|
struct cookie_manager_entry *entry = node_data;
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
if (entry->data[COOKIE_M_NAME].value_len == tw->title_len &&
|
2013-07-26 01:31:27 +04:00
|
|
|
strcmp(tw->title,
|
2013-07-26 18:20:19 +04:00
|
|
|
entry->data[COOKIE_M_NAME].value) == 0) {
|
2013-07-25 19:07:46 +04:00
|
|
|
/* Found what we're looking for */
|
|
|
|
tw->entry = entry;
|
|
|
|
*abort = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (type == TREE_NODE_FOLDER) {
|
|
|
|
struct cookie_manager_folder *folder = node_data;
|
|
|
|
|
2013-07-26 01:31:27 +04:00
|
|
|
if (folder->data.value_len == tw->title_len &&
|
|
|
|
strcmp(tw->title, folder->data.value) == 0) {
|
2013-07-25 19:07:46 +04:00
|
|
|
/* Found what we're looking for */
|
|
|
|
tw->folder = folder;
|
|
|
|
*abort = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Find a cookie entry in the cookie manager's treeview
|
|
|
|
*
|
|
|
|
* \param root Search root node, or NULL to search from tree's root
|
|
|
|
* \param title ID of the node to look for
|
2013-07-26 01:31:27 +04:00
|
|
|
* \param title_len Byte length of title string
|
2013-07-25 19:07:46 +04:00
|
|
|
* \param found Updated to the matching node's cookie maanger entry
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
|
|
|
static nserror cookie_manager_find_entry(treeview_node *root,
|
2013-07-26 01:31:27 +04:00
|
|
|
const char *title, size_t title_len,
|
|
|
|
struct cookie_manager_entry **found)
|
2013-07-25 19:07:46 +04:00
|
|
|
{
|
|
|
|
nserror err;
|
|
|
|
struct treeview_walk_ctx tw = {
|
|
|
|
.title = title,
|
2013-07-26 01:31:27 +04:00
|
|
|
.title_len = title_len,
|
2013-07-25 19:07:46 +04:00
|
|
|
.folder = NULL,
|
|
|
|
.entry = NULL
|
|
|
|
};
|
|
|
|
|
2013-08-22 19:05:03 +04:00
|
|
|
err = treeview_walk(cm_ctx.tree, root, cookie_manager_walk_cb, NULL,
|
|
|
|
&tw, TREE_NODE_ENTRY);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*found = tw.entry;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Find a cookie domain folder in the cookie manager's treeview
|
|
|
|
*
|
|
|
|
* \param root Search root node, or NULL to search from tree's root
|
|
|
|
* \param title ID of the node to look for
|
2013-07-26 01:31:27 +04:00
|
|
|
* \param title_len Byte length of title string
|
2013-07-25 19:07:46 +04:00
|
|
|
* \param found Updated to the matching node's cookie maanger folder
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
|
|
|
static nserror cookie_manager_find_folder(treeview_node *root,
|
2013-07-26 01:31:27 +04:00
|
|
|
const char *title, size_t title_len,
|
|
|
|
struct cookie_manager_folder **found)
|
2013-07-25 19:07:46 +04:00
|
|
|
{
|
|
|
|
nserror err;
|
|
|
|
struct treeview_walk_ctx tw = {
|
|
|
|
.title = title,
|
2013-07-26 01:31:27 +04:00
|
|
|
.title_len = title_len,
|
2013-07-25 19:07:46 +04:00
|
|
|
.folder = NULL,
|
|
|
|
.entry = NULL
|
|
|
|
};
|
|
|
|
|
2013-08-22 19:05:03 +04:00
|
|
|
err = treeview_walk(cm_ctx.tree, root, cookie_manager_walk_cb, NULL,
|
|
|
|
&tw, TREE_NODE_FOLDER);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*found = tw.folder;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a cookie manager entry's treeview field data.
|
|
|
|
*
|
|
|
|
* \param e Cookie manager entry to free data from
|
|
|
|
*/
|
|
|
|
static void cookie_manager_free_treeview_field_data(
|
|
|
|
struct cookie_manager_entry *e)
|
|
|
|
{
|
|
|
|
/* Eww */
|
2013-07-26 18:20:19 +04:00
|
|
|
free((void *)e->data[COOKIE_M_NAME].value);
|
|
|
|
free((void *)e->data[COOKIE_M_CONTENT].value);
|
|
|
|
free((void *)e->data[COOKIE_M_DOMAIN].value);
|
|
|
|
free((void *)e->data[COOKIE_M_PATH].value);
|
|
|
|
free((void *)e->data[COOKIE_M_EXPIRES].value);
|
|
|
|
free((void *)e->data[COOKIE_M_LAST_USED].value);
|
2013-07-25 19:07:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-26 01:22:36 +04:00
|
|
|
/**
|
|
|
|
* Build a cookie manager treeview field from given text
|
|
|
|
*
|
|
|
|
* \param field Cookie manager treeview field to build
|
2013-07-26 15:11:14 +04:00
|
|
|
* \param data Cookie manager entry field data to set
|
2013-07-26 15:23:00 +04:00
|
|
|
* \param value Text to set in field, ownership yielded
|
2013-07-26 01:22:36 +04:00
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
2016-09-09 12:56:11 +03:00
|
|
|
static inline nserror
|
|
|
|
cookie_manager_field_builder(enum cookie_manager_field field,
|
|
|
|
struct treeview_field_data *data,
|
|
|
|
const char *value)
|
2013-07-26 01:22:36 +04:00
|
|
|
{
|
|
|
|
data->field = cm_ctx.fields[field].field;
|
2013-07-26 15:23:00 +04:00
|
|
|
data->value = value;
|
2013-07-26 01:22:36 +04:00
|
|
|
data->value_len = (value != NULL) ? strlen(value) : 0;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-09 12:56:11 +03:00
|
|
|
/**
|
|
|
|
* Build a cookie manager treeview field from given time
|
|
|
|
*
|
|
|
|
* The time should be converted to text in the users locacle
|
|
|
|
*
|
|
|
|
* \todo This should probably generate the user text using localtime
|
|
|
|
* and strftime with the c format specifier. Currently ctime will
|
|
|
|
* always generate output in the C locale.
|
|
|
|
*
|
|
|
|
* \param field Cookie manager treeview field to build
|
|
|
|
* \param fdata Cookie manager entry field data to set
|
|
|
|
* \param value Time to show in field
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
|
|
|
static inline nserror
|
|
|
|
cookie_manager_field_builder_time(enum cookie_manager_field field,
|
|
|
|
struct treeview_field_data *fdata,
|
|
|
|
const time_t *value)
|
|
|
|
{
|
|
|
|
const char *date;
|
|
|
|
char *date2;
|
|
|
|
|
|
|
|
fdata->field = cm_ctx.fields[field].field;
|
|
|
|
|
|
|
|
date = ctime(value);
|
|
|
|
date2 = strdup(date);
|
|
|
|
if (date2 == NULL) {
|
|
|
|
fdata->value = NULL;
|
|
|
|
fdata->value_len = 0;
|
|
|
|
} else {
|
|
|
|
assert(date2[24] == '\n');
|
|
|
|
date2[24] = '\0';
|
|
|
|
|
|
|
|
fdata->value = date2;
|
|
|
|
fdata->value_len = strlen(date2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-26 01:22:36 +04:00
|
|
|
|
2013-07-25 19:07:46 +04:00
|
|
|
/**
|
|
|
|
* Set a cookie manager entry's data from the cookie_data.
|
|
|
|
*
|
|
|
|
* \param e Cookie manager entry to set up
|
|
|
|
* \param data Data associated with entry's cookie
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
2016-09-09 12:56:11 +03:00
|
|
|
static nserror
|
|
|
|
cookie_manager_set_treeview_field_data(struct cookie_manager_entry *e,
|
|
|
|
const struct cookie_data *data)
|
2013-07-25 19:07:46 +04:00
|
|
|
{
|
|
|
|
assert(e != NULL);
|
|
|
|
assert(data != NULL);
|
|
|
|
|
2013-07-26 01:22:36 +04:00
|
|
|
/* Set the fields up */
|
2013-07-26 18:20:19 +04:00
|
|
|
cookie_manager_field_builder(COOKIE_M_NAME,
|
|
|
|
&e->data[COOKIE_M_NAME], strdup(data->name));
|
|
|
|
cookie_manager_field_builder(COOKIE_M_CONTENT,
|
|
|
|
&e->data[COOKIE_M_CONTENT], strdup(data->value));
|
|
|
|
cookie_manager_field_builder(COOKIE_M_DOMAIN,
|
|
|
|
&e->data[COOKIE_M_DOMAIN], strdup(data->domain));
|
|
|
|
cookie_manager_field_builder(COOKIE_M_PATH,
|
|
|
|
&e->data[COOKIE_M_PATH], strdup(data->path));
|
2013-07-26 01:22:36 +04:00
|
|
|
|
|
|
|
/* Set the Expires date field */
|
2016-09-14 01:17:28 +03:00
|
|
|
if (data->expires == -1) {
|
|
|
|
cookie_manager_field_builder(COOKIE_M_EXPIRES,
|
|
|
|
&e->data[COOKIE_M_EXPIRES],
|
|
|
|
strdup(messages_get("CookieManagerSession")));
|
|
|
|
} else {
|
|
|
|
cookie_manager_field_builder_time(COOKIE_M_EXPIRES,
|
2016-09-09 12:56:11 +03:00
|
|
|
&e->data[COOKIE_M_EXPIRES], &data->expires);
|
2016-09-14 01:17:28 +03:00
|
|
|
}
|
2013-07-25 19:07:46 +04:00
|
|
|
|
2013-07-26 01:22:36 +04:00
|
|
|
/* Set the Last used date field */
|
2016-09-09 12:56:11 +03:00
|
|
|
cookie_manager_field_builder_time(COOKIE_M_LAST_USED,
|
|
|
|
&e->data[COOKIE_M_LAST_USED], &data->last_used);
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
/* Set the Restrictions text */
|
2016-09-09 12:56:11 +03:00
|
|
|
if (data->secure && data->http_only) {
|
2013-07-26 18:20:19 +04:00
|
|
|
e->data[COOKIE_M_RESTRICTIONS] = cm_ctx.values[COOKIE_M_HTTPS];
|
2016-09-09 12:56:11 +03:00
|
|
|
} else if (data->secure) {
|
2013-07-26 18:20:19 +04:00
|
|
|
e->data[COOKIE_M_RESTRICTIONS] = cm_ctx.values[COOKIE_M_SECURE];
|
2016-09-09 12:56:11 +03:00
|
|
|
} else if (data->http_only) {
|
2013-07-26 18:20:19 +04:00
|
|
|
e->data[COOKIE_M_RESTRICTIONS] = cm_ctx.values[COOKIE_M_HTTP];
|
2016-09-09 12:56:11 +03:00
|
|
|
} else {
|
2013-07-26 18:20:19 +04:00
|
|
|
e->data[COOKIE_M_RESTRICTIONS] = cm_ctx.values[COOKIE_M_NONE];
|
2016-09-09 12:56:11 +03:00
|
|
|
}
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
/* Set the Version text */
|
2013-07-26 15:11:14 +04:00
|
|
|
switch (data->version) {
|
|
|
|
case COOKIE_NETSCAPE:
|
2013-07-26 18:20:19 +04:00
|
|
|
e->data[COOKIE_M_VERSION] = cm_ctx.values[COOKIE_M_NETSCAPE];
|
2013-07-26 15:11:14 +04:00
|
|
|
break;
|
2016-09-09 12:56:11 +03:00
|
|
|
|
2013-07-26 15:11:14 +04:00
|
|
|
case COOKIE_RFC2109:
|
2013-07-26 18:20:19 +04:00
|
|
|
e->data[COOKIE_M_VERSION] = cm_ctx.values[COOKIE_M_RFC2109];
|
2013-07-26 15:11:14 +04:00
|
|
|
break;
|
2016-09-09 12:56:11 +03:00
|
|
|
|
2013-07-26 15:11:14 +04:00
|
|
|
case COOKIE_RFC2965:
|
2013-07-26 18:20:19 +04:00
|
|
|
e->data[COOKIE_M_VERSION] = cm_ctx.values[COOKIE_M_RFC2965];
|
2013-07-26 15:11:14 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an empty tree entry for a cookie, and links it into the tree.
|
|
|
|
*
|
|
|
|
* All information is copied from the cookie_data, and as such can
|
|
|
|
* be edited and should be freed.
|
|
|
|
*
|
|
|
|
* \param parent the node to link to
|
|
|
|
* \param data the cookie data to use
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
|
|
|
static nserror cookie_manager_create_cookie_node(
|
|
|
|
struct cookie_manager_folder *parent,
|
|
|
|
const struct cookie_data *data)
|
|
|
|
{
|
|
|
|
nserror err;
|
|
|
|
struct cookie_manager_entry *cookie;
|
|
|
|
|
|
|
|
/* Create new cookie manager entry */
|
|
|
|
cookie = malloc(sizeof(struct cookie_manager_entry));
|
|
|
|
if (cookie == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
cookie->user_delete = false;
|
|
|
|
|
|
|
|
err = cookie_manager_set_treeview_field_data(cookie, data);
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
free(cookie);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-09-09 12:56:11 +03:00
|
|
|
err = treeview_create_node_entry(cm_ctx.tree,
|
|
|
|
&(cookie->entry),
|
|
|
|
parent->folder,
|
|
|
|
TREE_REL_FIRST_CHILD,
|
|
|
|
cookie->data,
|
|
|
|
cookie,
|
|
|
|
cm_ctx.built ? TREE_OPTION_NONE :
|
2013-08-30 15:51:40 +04:00
|
|
|
TREE_OPTION_SUPPRESS_RESIZE |
|
|
|
|
TREE_OPTION_SUPPRESS_REDRAW);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
cookie_manager_free_treeview_field_data(cookie);
|
|
|
|
free(cookie);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates a cookie manager entry for updated cookie_data.
|
|
|
|
*
|
|
|
|
* All information is copied from the cookie_data, and as such can
|
|
|
|
* be edited and should be freed.
|
|
|
|
*
|
|
|
|
* \param e the entry to update
|
|
|
|
* \param data the cookie data to use
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
|
|
|
static nserror cookie_manager_update_cookie_node(
|
|
|
|
struct cookie_manager_entry *e,
|
|
|
|
const struct cookie_data *data)
|
|
|
|
{
|
|
|
|
nserror err;
|
|
|
|
|
|
|
|
assert(e != NULL);
|
|
|
|
|
|
|
|
/* Reset to defaults */
|
|
|
|
e->user_delete = false;
|
|
|
|
cookie_manager_free_treeview_field_data(e);
|
|
|
|
|
|
|
|
/* Set new field values from the cookie_data */
|
|
|
|
err = cookie_manager_set_treeview_field_data(e, data);
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the treeview */
|
|
|
|
err = treeview_update_node_entry(cm_ctx.tree, e->entry, e->data, e);
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an empty tree folder for a cookie domain, and links it into the tree.
|
|
|
|
*
|
|
|
|
* All information is copied from the cookie_data, and as such can
|
|
|
|
* be edited and should be freed.
|
|
|
|
*
|
|
|
|
* \param folder updated to the new folder
|
|
|
|
* \param data the cookie data to use
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
|
|
|
static nserror cookie_manager_create_domain_folder(
|
|
|
|
struct cookie_manager_folder **folder,
|
|
|
|
const struct cookie_data *data)
|
|
|
|
{
|
|
|
|
nserror err;
|
|
|
|
struct cookie_manager_folder *f;
|
|
|
|
|
|
|
|
/* Create new cookie manager entry */
|
|
|
|
f = malloc(sizeof(struct cookie_manager_folder));
|
|
|
|
if (f == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
f->data.field = cm_ctx.fields[COOKIE_M_N_FIELDS - 1].field;
|
2013-07-25 19:07:46 +04:00
|
|
|
f->data.value = strdup(data->domain);
|
|
|
|
f->data.value_len = (f->data.value != NULL) ?
|
|
|
|
strlen(data->domain) : 0;
|
|
|
|
|
|
|
|
err = treeview_create_node_folder(cm_ctx.tree, &(f->folder),
|
|
|
|
NULL, TREE_REL_FIRST_CHILD, &f->data, f,
|
2013-08-30 15:51:40 +04:00
|
|
|
cm_ctx.built ? TREE_OPTION_NONE :
|
|
|
|
TREE_OPTION_SUPPRESS_RESIZE |
|
|
|
|
TREE_OPTION_SUPPRESS_REDRAW);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
free((void *)f->data.value);
|
|
|
|
free(f);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
*folder = f;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* exported interface documented in cookie_manager.h */
|
|
|
|
bool cookie_manager_add(const struct cookie_data *data)
|
|
|
|
{
|
|
|
|
struct cookie_manager_folder *parent = NULL;
|
|
|
|
struct cookie_manager_entry *cookie = NULL;
|
|
|
|
nserror err;
|
|
|
|
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
/* If we don't have a cookie manager at the moment, just return true */
|
|
|
|
if (cm_ctx.tree == NULL)
|
|
|
|
return true;
|
|
|
|
|
2013-07-26 01:31:27 +04:00
|
|
|
err = cookie_manager_find_folder(NULL, data->domain,
|
|
|
|
strlen(data->domain), &parent);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent == NULL) {
|
|
|
|
/* Need to create domain directory */
|
|
|
|
err = cookie_manager_create_domain_folder(&parent, data);
|
|
|
|
if (err != NSERROR_OK || parent == NULL)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create cookie node */
|
2013-07-26 01:31:27 +04:00
|
|
|
err = cookie_manager_find_entry(parent->folder, data->name,
|
|
|
|
strlen(data->name), &cookie);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (cookie == NULL) {
|
|
|
|
err = cookie_manager_create_cookie_node(parent, data);
|
|
|
|
} else {
|
|
|
|
err = cookie_manager_update_cookie_node(cookie, data);
|
|
|
|
}
|
|
|
|
if (err != NSERROR_OK)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* exported interface documented in cookie_manager.h */
|
|
|
|
void cookie_manager_remove(const struct cookie_data *data)
|
|
|
|
{
|
|
|
|
struct cookie_manager_folder *parent = NULL;
|
|
|
|
struct cookie_manager_entry *cookie = NULL;
|
|
|
|
nserror err;
|
|
|
|
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
/* If we don't have a cookie manager at the moment, just return */
|
|
|
|
if (cm_ctx.tree == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-07-26 01:31:27 +04:00
|
|
|
err = cookie_manager_find_folder(NULL, data->domain,
|
|
|
|
strlen(data->domain), &parent);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK || parent == NULL) {
|
|
|
|
/* Nothing to delete */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-26 01:31:27 +04:00
|
|
|
err = cookie_manager_find_entry(parent->folder, data->name,
|
|
|
|
strlen(data->name), &cookie);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK || cookie == NULL) {
|
|
|
|
/* Nothing to delete */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete the node */
|
2013-08-30 15:51:40 +04:00
|
|
|
treeview_delete_node(cm_ctx.tree, cookie->entry, TREE_OPTION_NONE);
|
2013-07-25 19:07:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the treeview entry feilds
|
|
|
|
*
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
static nserror cookie_manager_init_entry_fields(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char *label;
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
for (i = 0; i < COOKIE_M_N_FIELDS; i++)
|
2013-07-25 19:07:46 +04:00
|
|
|
cm_ctx.fields[i].field = NULL;
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
cm_ctx.fields[COOKIE_M_NAME].flags = TREE_FLAG_DEFAULT;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelName";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_NAME].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
cm_ctx.fields[COOKIE_M_CONTENT].flags = TREE_FLAG_SHOW_NAME;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelContent";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_CONTENT].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2017-09-19 01:13:39 +03:00
|
|
|
cm_ctx.fields[COOKIE_M_DOMAIN].flags =
|
|
|
|
TREE_FLAG_SHOW_NAME |
|
|
|
|
TREE_FLAG_SEARCHABLE;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelDomain";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_DOMAIN].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
cm_ctx.fields[COOKIE_M_PATH].flags = TREE_FLAG_SHOW_NAME;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelPath";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_PATH].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
cm_ctx.fields[COOKIE_M_EXPIRES].flags = TREE_FLAG_SHOW_NAME;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelExpires";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_EXPIRES].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
cm_ctx.fields[COOKIE_M_LAST_USED].flags = TREE_FLAG_SHOW_NAME;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelLastUsed";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_LAST_USED].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
cm_ctx.fields[COOKIE_M_RESTRICTIONS].flags = TREE_FLAG_SHOW_NAME;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelRestrictions";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_RESTRICTIONS].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
cm_ctx.fields[COOKIE_M_VERSION].flags = TREE_FLAG_SHOW_NAME;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelVersion";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_VERSION].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:20:19 +04:00
|
|
|
cm_ctx.fields[COOKIE_M_DOMAIN_FOLDER].flags = TREE_FLAG_DEFAULT;
|
2013-07-25 19:07:46 +04:00
|
|
|
label = "TreeviewLabelDomainFolder";
|
|
|
|
label = messages_get(label);
|
|
|
|
if (lwc_intern_string(label, strlen(label),
|
2013-07-26 18:20:19 +04:00
|
|
|
&cm_ctx.fields[COOKIE_M_DOMAIN_FOLDER].field) !=
|
2013-07-25 19:07:46 +04:00
|
|
|
lwc_error_ok) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
|
|
|
|
error:
|
2013-07-26 18:20:19 +04:00
|
|
|
for (i = 0; i < COOKIE_M_N_FIELDS; i++)
|
2013-07-25 19:07:46 +04:00
|
|
|
if (cm_ctx.fields[i].field != NULL)
|
|
|
|
lwc_string_unref(cm_ctx.fields[i].field);
|
|
|
|
|
|
|
|
return NSERROR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:11:14 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the common entry values
|
|
|
|
*
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
static nserror cookie_manager_init_common_values(void)
|
|
|
|
{
|
|
|
|
const char *temp;
|
|
|
|
|
|
|
|
/* Set the Restrictions text */
|
2013-07-26 15:49:41 +04:00
|
|
|
temp = messages_get("CookieManagerHTTPS");
|
2013-07-26 18:20:19 +04:00
|
|
|
cookie_manager_field_builder(COOKIE_M_RESTRICTIONS,
|
|
|
|
&cm_ctx.values[COOKIE_M_HTTPS], strdup(temp));
|
2013-07-26 15:11:14 +04:00
|
|
|
|
2013-07-26 15:49:41 +04:00
|
|
|
temp = messages_get("CookieManagerSecure");
|
2013-07-26 18:20:19 +04:00
|
|
|
cookie_manager_field_builder(COOKIE_M_RESTRICTIONS,
|
|
|
|
&cm_ctx.values[COOKIE_M_SECURE], strdup(temp));
|
2013-07-26 15:11:14 +04:00
|
|
|
|
2013-07-26 15:49:41 +04:00
|
|
|
temp = messages_get("CookieManagerHTTP");
|
2013-07-26 18:20:19 +04:00
|
|
|
cookie_manager_field_builder(COOKIE_M_RESTRICTIONS,
|
|
|
|
&cm_ctx.values[COOKIE_M_HTTP], strdup(temp));
|
2013-07-26 15:11:14 +04:00
|
|
|
|
2013-07-26 15:49:41 +04:00
|
|
|
temp = messages_get("None");
|
2013-07-26 18:20:19 +04:00
|
|
|
cookie_manager_field_builder(COOKIE_M_RESTRICTIONS,
|
|
|
|
&cm_ctx.values[COOKIE_M_NONE], strdup(temp));
|
2013-07-26 15:11:14 +04:00
|
|
|
|
|
|
|
/* Set the Cookie version text */
|
2013-07-26 15:16:53 +04:00
|
|
|
assert(COOKIE_NETSCAPE == 0);
|
|
|
|
temp = messages_get("TreeVersion0");
|
2013-07-26 18:20:19 +04:00
|
|
|
cookie_manager_field_builder(COOKIE_M_VERSION,
|
|
|
|
&cm_ctx.values[COOKIE_M_NETSCAPE], strdup(temp));
|
2013-07-26 15:11:14 +04:00
|
|
|
|
2013-07-26 15:16:53 +04:00
|
|
|
assert(COOKIE_RFC2109 == 1);
|
|
|
|
temp = messages_get("TreeVersion1");
|
2013-07-26 18:20:19 +04:00
|
|
|
cookie_manager_field_builder(COOKIE_M_VERSION,
|
|
|
|
&cm_ctx.values[COOKIE_M_RFC2109], strdup(temp));
|
2013-07-26 15:11:14 +04:00
|
|
|
|
2013-07-26 15:16:53 +04:00
|
|
|
assert(COOKIE_RFC2965 == 2);
|
|
|
|
temp = messages_get("TreeVersion2");
|
2013-07-26 18:20:19 +04:00
|
|
|
cookie_manager_field_builder(COOKIE_M_VERSION,
|
|
|
|
&cm_ctx.values[COOKIE_M_RFC2965], strdup(temp));
|
2013-07-26 15:11:14 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-25 19:07:46 +04:00
|
|
|
/**
|
|
|
|
* Delete cookie manager entries (and optionally delete from urldb)
|
|
|
|
*
|
2016-09-09 12:56:11 +03:00
|
|
|
* \param e Cookie manager entry to delete.
|
2013-07-25 19:07:46 +04:00
|
|
|
*/
|
|
|
|
static void cookie_manager_delete_entry(struct cookie_manager_entry *e)
|
|
|
|
{
|
|
|
|
const char *domain;
|
|
|
|
const char *path;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (e->user_delete) {
|
|
|
|
/* Delete the cookie from URLdb */
|
2013-07-26 18:20:19 +04:00
|
|
|
domain = e->data[COOKIE_M_DOMAIN].value;
|
|
|
|
path = e->data[COOKIE_M_PATH].value;
|
|
|
|
name = e->data[COOKIE_M_NAME].value;
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
if ((domain != NULL) && (path != NULL) && (name != NULL)) {
|
|
|
|
|
|
|
|
urldb_delete_cookie(domain, path, name);
|
|
|
|
} else {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"Delete cookie fail: ""need domain, path, and name.");
|
2013-07-25 19:07:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete the cookie manager entry */
|
|
|
|
cookie_manager_free_treeview_field_data(e);
|
|
|
|
free(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static nserror cookie_manager_tree_node_folder_cb(
|
|
|
|
struct treeview_node_msg msg, void *data)
|
|
|
|
{
|
|
|
|
struct cookie_manager_folder *f = data;
|
|
|
|
|
|
|
|
switch (msg.msg) {
|
|
|
|
case TREE_MSG_NODE_DELETE:
|
|
|
|
free(f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_MSG_NODE_EDIT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_MSG_NODE_LAUNCH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2016-09-09 12:56:11 +03:00
|
|
|
|
|
|
|
|
2013-07-25 19:07:46 +04:00
|
|
|
static nserror cookie_manager_tree_node_entry_cb(
|
|
|
|
struct treeview_node_msg msg, void *data)
|
|
|
|
{
|
|
|
|
struct cookie_manager_entry *e = data;
|
|
|
|
|
|
|
|
switch (msg.msg) {
|
|
|
|
case TREE_MSG_NODE_DELETE:
|
|
|
|
e->entry = NULL;
|
|
|
|
e->user_delete = msg.data.delete.user;
|
|
|
|
cookie_manager_delete_entry(e);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_MSG_NODE_EDIT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_MSG_NODE_LAUNCH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2016-09-09 12:56:11 +03:00
|
|
|
|
|
|
|
|
2013-07-25 19:07:46 +04:00
|
|
|
struct treeview_callback_table cm_tree_cb_t = {
|
|
|
|
.folder = cookie_manager_tree_node_folder_cb,
|
|
|
|
.entry = cookie_manager_tree_node_entry_cb
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Exported interface, documented in cookie_manager.h */
|
|
|
|
nserror cookie_manager_init(struct core_window_callback_table *cw_t,
|
|
|
|
void *core_window_handle)
|
|
|
|
{
|
|
|
|
nserror err;
|
|
|
|
|
Treeview: Rationalise initialisation and finalisation.
Previously the expected behaviour for front ends using the correct
API for hotlist, global history, cookie manager, and ssl cert
viewer was that the front end would initialise the treeview module
on startup and finalise it on application exit.
However, this meant that the front ends had to include the core
treeview header, which they didn't otherwise need.
Since the tree module provided access to the new treeview utilities
through the old tree API, and was used by front ends with no changes
for the new treeview API, the tree layer refcounted initialisations
of treeview-based widgets, and only called the underlying treeview
init/fini functions when needed.
This change moves that refcounting into the treeview module. Now
the hotlist, global history, cookie manager, and ssl cert viewer
widgets call call treeview init/fini as part of their own
initialisation and finalisation. This means that front ends
using the correct APIs for treeview-based widgets don't need to
know anything about the underlying treeview, and the tree module
compatibility layer has had its treeview refcounting removed.
Finally, the treeview_init function took a font size parameter.
Now it does not and lit gets font size from config. We probably
want to add a new `treeview_font_size` option to nsoptions, and
have differnent defaults on different platforms. 12pt on RISC OS,
and 11pt elsewhere, most likely.
2016-08-10 20:36:41 +03:00
|
|
|
err = treeview_init();
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Generating cookie manager data");
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
/* Init. cookie manager treeview entry fields */
|
|
|
|
err = cookie_manager_init_entry_fields();
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
cm_ctx.tree = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:11:14 +04:00
|
|
|
/* Init. common treeview field values */
|
|
|
|
err = cookie_manager_init_common_values();
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
cm_ctx.tree = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-07-25 19:07:46 +04:00
|
|
|
/* Create the cookie manager treeview */
|
|
|
|
err = treeview_create(&cm_ctx.tree, &cm_tree_cb_t,
|
2013-07-26 18:20:19 +04:00
|
|
|
COOKIE_M_N_FIELDS, cm_ctx.fields,
|
2013-07-25 19:07:46 +04:00
|
|
|
cw_t, core_window_handle,
|
2017-09-19 01:03:40 +03:00
|
|
|
TREEVIEW_NO_MOVES |
|
|
|
|
TREEVIEW_DEL_EMPTY_DIRS |
|
|
|
|
TREEVIEW_SEARCHABLE);
|
2013-07-25 19:07:46 +04:00
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
cm_ctx.tree = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the cookies */
|
|
|
|
urldb_iterate_cookies(cookie_manager_add);
|
|
|
|
|
|
|
|
/* Cookie manager is built
|
|
|
|
* We suppress the treeview height callback on entry insertion before
|
|
|
|
* the treeview is built. */
|
|
|
|
cm_ctx.built = true;
|
|
|
|
|
2013-09-03 17:38:01 +04:00
|
|
|
/* Inform client of window height */
|
|
|
|
treeview_get_height(cm_ctx.tree);
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Generated cookie manager data");
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Exported interface, documented in cookie_manager.h */
|
|
|
|
nserror cookie_manager_fini(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
nserror err;
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Finalising cookie manager");
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
cm_ctx.built = false;
|
|
|
|
|
|
|
|
/* Destroy the cookie manager treeview */
|
|
|
|
err = treeview_destroy(cm_ctx.tree);
|
2017-01-05 21:53:33 +03:00
|
|
|
cm_ctx.tree = NULL;
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
/* Free cookie manager treeview entry fields */
|
2013-07-26 18:20:19 +04:00
|
|
|
for (i = 0; i < COOKIE_M_N_FIELDS; i++)
|
2013-07-25 19:07:46 +04:00
|
|
|
if (cm_ctx.fields[i].field != NULL)
|
|
|
|
lwc_string_unref(cm_ctx.fields[i].field);
|
|
|
|
|
2013-07-26 15:11:14 +04:00
|
|
|
/* Free cookie manager treeview common entry values */
|
2013-07-26 18:20:19 +04:00
|
|
|
for (i = 0; i < COOKIE_M_N_VALUES; i++)
|
2013-07-26 15:11:14 +04:00
|
|
|
if (cm_ctx.values[i].value != NULL)
|
|
|
|
free((void *) cm_ctx.values[i].value);
|
|
|
|
|
Treeview: Rationalise initialisation and finalisation.
Previously the expected behaviour for front ends using the correct
API for hotlist, global history, cookie manager, and ssl cert
viewer was that the front end would initialise the treeview module
on startup and finalise it on application exit.
However, this meant that the front ends had to include the core
treeview header, which they didn't otherwise need.
Since the tree module provided access to the new treeview utilities
through the old tree API, and was used by front ends with no changes
for the new treeview API, the tree layer refcounted initialisations
of treeview-based widgets, and only called the underlying treeview
init/fini functions when needed.
This change moves that refcounting into the treeview module. Now
the hotlist, global history, cookie manager, and ssl cert viewer
widgets call call treeview init/fini as part of their own
initialisation and finalisation. This means that front ends
using the correct APIs for treeview-based widgets don't need to
know anything about the underlying treeview, and the tree module
compatibility layer has had its treeview refcounting removed.
Finally, the treeview_init function took a font size parameter.
Now it does not and lit gets font size from config. We probably
want to add a new `treeview_font_size` option to nsoptions, and
have differnent defaults on different platforms. 12pt on RISC OS,
and 11pt elsewhere, most likely.
2016-08-10 20:36:41 +03:00
|
|
|
err = treeview_fini();
|
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Finalised cookie manager");
|
2013-07-25 19:07:46 +04:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Exported interface, documented in cookie_manager.h */
|
|
|
|
void cookie_manager_redraw(int x, int y, struct rect *clip,
|
|
|
|
const struct redraw_context *ctx)
|
|
|
|
{
|
|
|
|
treeview_redraw(cm_ctx.tree, x, y, clip, ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Exported interface, documented in cookie_manager.h */
|
2014-05-18 20:30:53 +04:00
|
|
|
void cookie_manager_mouse_action(enum browser_mouse_state mouse, int x, int y)
|
2013-07-25 19:07:46 +04:00
|
|
|
{
|
|
|
|
treeview_mouse_action(cm_ctx.tree, mouse, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Exported interface, documented in cookie_manager.h */
|
2016-07-31 02:07:07 +03:00
|
|
|
bool cookie_manager_keypress(uint32_t key)
|
2013-07-25 19:07:46 +04:00
|
|
|
{
|
2016-07-31 02:07:07 +03:00
|
|
|
return treeview_keypress(cm_ctx.tree, key);
|
2013-07-25 19:07:46 +04:00
|
|
|
}
|
|
|
|
|
2013-08-28 17:23:22 +04:00
|
|
|
|
|
|
|
/* Exported interface, documented in cookie_manager.h */
|
|
|
|
bool cookie_manager_has_selection(void)
|
|
|
|
{
|
|
|
|
return treeview_has_selection(cm_ctx.tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 14:28:02 +04:00
|
|
|
/* Exported interface, documented in cookie_manager.h */
|
|
|
|
nserror cookie_manager_expand(bool only_folders)
|
|
|
|
{
|
|
|
|
return treeview_expand(cm_ctx.tree, only_folders);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Exported interface, documented in cookie_manager.h */
|
|
|
|
nserror cookie_manager_contract(bool all)
|
|
|
|
{
|
|
|
|
return treeview_contract(cm_ctx.tree, all);
|
|
|
|
}
|
|
|
|
|