2005-09-15 09:58:31 -04:00
|
|
|
/* Cookie-related dialogs */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-08-25 16:44:11 -04:00
|
|
|
#if defined(HAVE_STRFTIME) || defined(HAVE_STRPTIME)
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "bfu/dialog.h"
|
|
|
|
#include "cookies/cookies.h"
|
|
|
|
#include "cookies/dialogs.h"
|
|
|
|
#include "dialogs/edit.h"
|
|
|
|
#include "intl/gettext/libintl.h"
|
|
|
|
#include "main/object.h"
|
|
|
|
#include "session/session.h"
|
|
|
|
#include "terminal/draw.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/conv.h"
|
|
|
|
#include "util/lists.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
|
|
|
|
|
2007-07-26 15:39:08 -04:00
|
|
|
INIT_LIST_OF(struct cookie, cookie_queries);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
static void
|
2019-04-21 06:27:40 -04:00
|
|
|
add_cookie_info_to_string(struct string *string, struct cookie *cookie,
|
2005-09-15 09:58:31 -04:00
|
|
|
struct terminal *term)
|
|
|
|
{
|
|
|
|
add_format_to_string(string, "\n%s: %s", _("Name", term), cookie->name);
|
|
|
|
add_format_to_string(string, "\n%s: %s", _("Value", term), cookie->value);
|
|
|
|
add_format_to_string(string, "\n%s: %s", _("Domain", term), cookie->domain);
|
|
|
|
add_format_to_string(string, "\n%s: %s", _("Path", term), cookie->path);
|
|
|
|
|
|
|
|
if (!cookie->expires) {
|
|
|
|
add_format_to_string(string, "\n%s: ", _("Expires", term));
|
|
|
|
add_to_string(string, _("at quit time", term));
|
|
|
|
#ifdef HAVE_STRFTIME
|
|
|
|
} else {
|
|
|
|
add_format_to_string(string, "\n%s: ", _("Expires", term));
|
2007-08-28 12:41:18 -04:00
|
|
|
add_date_to_string(string, get_opt_str("ui.date_format", NULL), &cookie->expires);
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
add_format_to_string(string, "\n%s: %s", _("Secure", term),
|
|
|
|
_(cookie->secure ? N_("yes") : N_("no"), term));
|
2018-08-25 09:28:29 -04:00
|
|
|
add_format_to_string(string, "\n%s: %s", _("HttpOnly", term),
|
|
|
|
_(cookie->httponly ? N_("yes") : N_("no"), term));
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
2007-03-10 16:50:56 -05:00
|
|
|
static void
|
|
|
|
accept_cookie_in_msg_box(void *cookie_)
|
|
|
|
{
|
|
|
|
accept_cookie((struct cookie *) cookie_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reject_cookie_in_msg_box(void *cookie_)
|
|
|
|
{
|
|
|
|
done_cookie((struct cookie *) cookie_);
|
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
/* TODO: Store cookie in data arg. --jonas*/
|
|
|
|
void
|
|
|
|
accept_cookie_dialog(struct session *ses, void *data)
|
|
|
|
{
|
Here is a framework that detects cases where a PO file assigns
the same accelerator key to multiple buttons in a dialog box or
to multiple items in a menu. ELinks already has some support for
this but it requires the translator to run ELinks and manually
scan through all menus and dialogs. The attached changes make it
possible to quickly detect and list any conflicts, including ones
that can only occur on operating systems or configurations that
the translator is not currently using.
The changes have no immediate effect on the elinks executable or
the MO files. PO files become larger, however.
The scheme works like this:
- Like before, accelerator keys in translatable strings are
tagged with the tilde (~) character.
- Whenever a C source file defines an accelerator key, it must
assign one or more named "contexts" to it. The translations in
the PO files inherit these contexts. If multiple strings use
the same accelerator (case insensitive) in the same context,
that's a conflict and can be detected automatically.
- The contexts are defined with "gettext_accelerator_context"
comments in source files. These comments delimit regions where
all translatable strings containing tildes are given the same
contexts. There must be one special comment at the top of the
region; it lists the contexts assigned to that region. The
region automatically ends at the end of the function (found
with regexp /^\}/), but it can also be closed explicitly with
another special comment. The comments are formatted like this:
/* [gettext_accelerator_context(foo, bar, baz)]
begins a region that uses the contexts "foo", "bar", and "baz".
The comma is the delimiter; whitespace is optional.
[gettext_accelerator_context()]
ends the region. */
The scripts don't currently check whether this syntax occurs
inside or outside comments.
- The names of contexts consist of C identifiers delimited with
periods. I typically used the name of a function that sets
up a dialog, or the name of an array where the items of a
menu are listed. There is a special feature for static
functions: if the name begins with a period, then the period
will be replaced with the name of the source file and a colon.
- If a menu is programmatically generated from multiple parts,
of which some are never used together, so that it is safe to
use the same accelerators in them, then it is necessary to
define multiple contexts for the same menu. link_menu() in
src/viewer/text/link.c is the most complex example of this.
- During make update-po:
- A Perl script (po/gather-accelerator-contexts.pl) reads
po/elinks.pot, scans the source files listed in it for
"gettext_accelerator_context" comments, and rewrites
po/elinks.pot with "accelerator_context" comments that
indicate the contexts of each msgid: the union of all
contexts of all of its uses in the source files. It also
removes any "gettext_accelerator_context" comments that
xgettext --add-comments has copied to elinks.pot.
- If po/gather-accelerator-contexts.pl does not find any
contexts for some use of an msgid that seems to contain an
accelerator (because it contains a tilde), it warns. If the
tilde refers to e.g. "~/.elinks" and does not actually mark
an accelerator, the warning can be silenced by specifying the
special context "IGNORE", which the script otherwise ignores.
- msgmerge copies the "accelerator_context" comments from
po/elinks.pot to po/*.po. Translators do not edit those
comments.
- During make check-po:
- Another Perl script (po/check-accelerator-contexts.pl) reads
po/*.po and keeps track of which accelerators have been bound
in each context. It warns about any conflicts it finds.
This script does not access the C source files; thus it does
not matter if the line numbers in "#:" lines are out of date.
This implementation is not perfect and I am not proposing to
add it to the main source tree at this time. Specifically:
- It introduces compile-time dependencies on Perl and Locale::PO.
There should be a configure-time or compile-time check so that
the new features are skipped if the prerequisites are missing.
- When the scripts include msgstr strings in warnings, they
should transcode them from the charset of the PO file to the
one specified by the user's locale.
- It is not adequately documented (well, except perhaps here).
- po/check-accelerator-contexts.pl reports the same conflict
multiple times if it occurs in multiple contexts.
- The warning messages should include line numbers, so that users
of Emacs could conveniently edit the conflicting part of the PO
file. This is not feasible with the current version of
Locale::PO.
- Locale::PO does not understand #~ lines and spews warnings
about them. There is an ugly hack to hide these warnings.
- Jonas Fonseca suggested the script could propose accelerators
that are still available. This has not been implemented.
There are three files attached:
- po/gather-accelerator-contexts.pl: Augments elinks.pot with
context information.
- po/check-accelerator-contexts.pl: Checks conflicts.
- accelerator-contexts.diff: Makes po/Makefile run the scripts,
and adds special comments to source files.
2005-12-04 18:38:29 -05:00
|
|
|
/* [gettext_accelerator_context(accept_cookie_dialog)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct cookie *cookie = cookie_queries.next;
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string string;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
assert(ses);
|
|
|
|
|
|
|
|
if (list_empty(cookie_queries)
|
|
|
|
|| !init_string(&string))
|
|
|
|
return;
|
|
|
|
|
|
|
|
del_from_list(cookie);
|
|
|
|
|
|
|
|
add_format_to_string(&string,
|
|
|
|
_("Do you want to accept a cookie from %s?", ses->tab->term),
|
|
|
|
cookie->server->host);
|
|
|
|
|
|
|
|
add_to_string(&string, "\n\n");
|
|
|
|
|
|
|
|
add_cookie_info_to_string(&string, cookie, ses->tab->term);
|
|
|
|
|
|
|
|
msg_box(ses->tab->term, NULL, MSGBOX_FREE_TEXT,
|
|
|
|
N_("Accept cookie?"), ALIGN_LEFT,
|
|
|
|
string.source,
|
|
|
|
cookie, 2,
|
2007-03-10 16:50:56 -05:00
|
|
|
MSG_BOX_BUTTON(N_("~Accept"), accept_cookie_in_msg_box, B_ENTER),
|
|
|
|
MSG_BOX_BUTTON(N_("~Reject"), reject_cookie_in_msg_box, B_ESC));
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
lock_cookie(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
if (item->type == BI_LEAF)
|
|
|
|
object_lock((struct cookie *) item->udata);
|
|
|
|
else
|
|
|
|
object_lock((struct cookie_server *) item->udata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unlock_cookie(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
if (item->type == BI_LEAF)
|
|
|
|
object_unlock((struct cookie *) item->udata);
|
|
|
|
else
|
|
|
|
object_unlock((struct cookie_server *) item->udata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_cookie_used(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
if (item->type == BI_FOLDER) {
|
|
|
|
struct listbox_item *root = item;
|
|
|
|
|
|
|
|
foreach (item, root->child)
|
|
|
|
if (is_object_used((struct cookie *) item->udata))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_object_used((struct cookie *) item->udata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char *
|
|
|
|
get_cookie_text(struct listbox_item *item, struct terminal *term)
|
|
|
|
{
|
|
|
|
/* Are we dealing with a folder? */
|
|
|
|
if (item->type == BI_FOLDER) {
|
|
|
|
struct cookie_server *server = item->udata;
|
|
|
|
|
|
|
|
return stracpy(server->host);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
struct cookie *cookie = item->udata;
|
|
|
|
|
|
|
|
return stracpy(cookie->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char *
|
|
|
|
get_cookie_info(struct listbox_item *item, struct terminal *term)
|
|
|
|
{
|
|
|
|
struct cookie *cookie = item->udata;
|
|
|
|
struct cookie_server *server;
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string string;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (item->type == BI_FOLDER) return NULL;
|
|
|
|
|
|
|
|
if (!init_string(&string)) return NULL;
|
|
|
|
|
|
|
|
server = cookie->server;
|
|
|
|
|
|
|
|
add_format_to_string(&string, "%s: %s", _("Server", term), server->host);
|
|
|
|
|
|
|
|
add_cookie_info_to_string(&string, cookie, term);
|
|
|
|
|
|
|
|
return string.source;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct listbox_item *
|
|
|
|
get_cookie_root(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
/* Are we dealing with a folder? */
|
|
|
|
if (item->type == BI_FOLDER) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
struct cookie *cookie = item->udata;
|
|
|
|
|
|
|
|
return cookie->server->box_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
can_delete_cookie(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_cookie_item(struct listbox_item *item, int last)
|
|
|
|
{
|
|
|
|
struct cookie *cookie = item->udata;
|
|
|
|
|
|
|
|
if (item->type == BI_FOLDER) {
|
|
|
|
struct listbox_item *next, *root = item;
|
|
|
|
|
|
|
|
/* Releasing refcounts on the cookie_server will automagically
|
|
|
|
* delete it. */
|
|
|
|
foreachsafe (item, next, root->child)
|
|
|
|
delete_cookie_item(item, 0);
|
|
|
|
} else {
|
|
|
|
assert(!is_object_used(cookie));
|
|
|
|
|
|
|
|
delete_cookie(cookie);
|
2006-12-09 09:24:24 -05:00
|
|
|
set_cookies_dirty();
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct listbox_ops_messages cookies_messages = {
|
|
|
|
/* cant_delete_item */
|
|
|
|
N_("Sorry, but cookie \"%s\" cannot be deleted."),
|
|
|
|
/* cant_delete_used_item */
|
|
|
|
N_("Sorry, but cookie \"%s\" is being used by something else."),
|
|
|
|
/* cant_delete_folder */
|
|
|
|
N_("Sorry, but cookie domain \"%s\" cannot be deleted."),
|
|
|
|
/* cant_delete_used_folder */
|
|
|
|
N_("Sorry, but cookie domain \"%s\" is being used by something else."),
|
|
|
|
/* delete_marked_items_title */
|
|
|
|
N_("Delete marked cookies"),
|
|
|
|
/* delete_marked_items */
|
|
|
|
N_("Delete marked cookies?"),
|
|
|
|
/* delete_folder_title */
|
|
|
|
N_("Delete domain's cookies"),
|
|
|
|
/* delete_folder */
|
|
|
|
N_("Delete all cookies from domain \"%s\"?"),
|
|
|
|
/* delete_item_title */
|
|
|
|
N_("Delete cookie"),
|
2006-05-27 01:51:24 -04:00
|
|
|
/* delete_item; xgettext:c-format */
|
2005-09-15 09:58:31 -04:00
|
|
|
N_("Delete this cookie?"),
|
|
|
|
/* clear_all_items_title */
|
|
|
|
N_("Clear all cookies"),
|
|
|
|
/* clear_all_items_title */
|
|
|
|
N_("Do you really want to remove all cookies?"),
|
|
|
|
};
|
|
|
|
|
2007-02-04 08:17:49 -05:00
|
|
|
static const struct listbox_ops cookies_listbox_ops = {
|
2005-09-15 09:58:31 -04:00
|
|
|
lock_cookie,
|
|
|
|
unlock_cookie,
|
|
|
|
is_cookie_used,
|
|
|
|
get_cookie_text,
|
|
|
|
get_cookie_info,
|
|
|
|
NULL,
|
|
|
|
get_cookie_root,
|
|
|
|
NULL,
|
|
|
|
can_delete_cookie,
|
|
|
|
delete_cookie_item,
|
|
|
|
NULL,
|
|
|
|
&cookies_messages,
|
|
|
|
};
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
set_cookie_name(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
|
|
|
struct cookie *cookie = dlg_data->dlg->udata;
|
|
|
|
unsigned char *value = widget_data->cdata;
|
|
|
|
|
|
|
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
|
|
|
mem_free_set(&cookie->name, stracpy(value));
|
2006-12-09 07:01:39 -05:00
|
|
|
set_cookies_dirty();
|
2005-09-15 09:58:31 -04:00
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
set_cookie_value(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
|
|
|
struct cookie *cookie = dlg_data->dlg->udata;
|
|
|
|
unsigned char *value = widget_data->cdata;
|
|
|
|
|
|
|
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
|
|
|
mem_free_set(&cookie->value, stracpy(value));
|
2006-12-09 07:01:39 -05:00
|
|
|
set_cookies_dirty();
|
2005-09-15 09:58:31 -04:00
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
set_cookie_domain(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
|
|
|
struct cookie *cookie = dlg_data->dlg->udata;
|
|
|
|
unsigned char *value = widget_data->cdata;
|
|
|
|
|
|
|
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
|
|
|
mem_free_set(&cookie->domain, stracpy(value));
|
2006-12-09 07:01:39 -05:00
|
|
|
set_cookies_dirty();
|
2005-09-15 09:58:31 -04:00
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
set_cookie_expires(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
|
|
|
struct cookie *cookie = dlg_data->dlg->udata;
|
|
|
|
unsigned char *value = widget_data->cdata;
|
|
|
|
unsigned char *end;
|
|
|
|
|
|
|
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
2018-08-25 16:44:11 -04:00
|
|
|
#ifdef HAVE_STRPTIME
|
|
|
|
{
|
|
|
|
struct tm tm = {0};
|
|
|
|
end = strptime(value, get_opt_str("ui.date_format", NULL), &tm);
|
|
|
|
if (!end) return EVENT_NOT_PROCESSED;
|
|
|
|
tm.tm_isdst = -1;
|
|
|
|
cookie->expires = mktime(&tm);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
long number;
|
|
|
|
errno = 0;
|
|
|
|
number = strtol(value, (char **) &end, 10);
|
|
|
|
if (errno || *end || number < 0) return EVENT_NOT_PROCESSED;
|
|
|
|
cookie->expires = (time_t) number;
|
|
|
|
}
|
|
|
|
#endif
|
2006-12-09 07:01:39 -05:00
|
|
|
set_cookies_dirty();
|
2005-09-15 09:58:31 -04:00
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
set_cookie_secure(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
|
|
|
struct cookie *cookie = dlg_data->dlg->udata;
|
|
|
|
unsigned char *value = widget_data->cdata;
|
|
|
|
unsigned char *end;
|
|
|
|
long number;
|
|
|
|
|
|
|
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
number = strtol(value, (char **) &end, 10);
|
|
|
|
if (errno || *end) return EVENT_NOT_PROCESSED;
|
|
|
|
|
|
|
|
cookie->secure = (number != 0);
|
2006-12-09 07:01:39 -05:00
|
|
|
set_cookies_dirty();
|
2005-09-15 09:58:31 -04:00
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
2018-08-25 09:28:29 -04:00
|
|
|
static widget_handler_status_T
|
|
|
|
set_cookie_httponly(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
|
|
|
struct cookie *cookie = dlg_data->dlg->udata;
|
|
|
|
unsigned char *value = widget_data->cdata;
|
|
|
|
unsigned char *end;
|
|
|
|
long number;
|
|
|
|
|
|
|
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
number = strtol(value, (char **) &end, 10);
|
|
|
|
if (errno || *end) return EVENT_NOT_PROCESSED;
|
|
|
|
|
|
|
|
cookie->httponly = (number != 0);
|
|
|
|
set_cookies_dirty();
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
static void
|
|
|
|
build_edit_dialog(struct terminal *term, struct cookie *cookie)
|
|
|
|
{
|
2018-08-25 09:28:29 -04:00
|
|
|
#define EDIT_WIDGETS_COUNT 9
|
Here is a framework that detects cases where a PO file assigns
the same accelerator key to multiple buttons in a dialog box or
to multiple items in a menu. ELinks already has some support for
this but it requires the translator to run ELinks and manually
scan through all menus and dialogs. The attached changes make it
possible to quickly detect and list any conflicts, including ones
that can only occur on operating systems or configurations that
the translator is not currently using.
The changes have no immediate effect on the elinks executable or
the MO files. PO files become larger, however.
The scheme works like this:
- Like before, accelerator keys in translatable strings are
tagged with the tilde (~) character.
- Whenever a C source file defines an accelerator key, it must
assign one or more named "contexts" to it. The translations in
the PO files inherit these contexts. If multiple strings use
the same accelerator (case insensitive) in the same context,
that's a conflict and can be detected automatically.
- The contexts are defined with "gettext_accelerator_context"
comments in source files. These comments delimit regions where
all translatable strings containing tildes are given the same
contexts. There must be one special comment at the top of the
region; it lists the contexts assigned to that region. The
region automatically ends at the end of the function (found
with regexp /^\}/), but it can also be closed explicitly with
another special comment. The comments are formatted like this:
/* [gettext_accelerator_context(foo, bar, baz)]
begins a region that uses the contexts "foo", "bar", and "baz".
The comma is the delimiter; whitespace is optional.
[gettext_accelerator_context()]
ends the region. */
The scripts don't currently check whether this syntax occurs
inside or outside comments.
- The names of contexts consist of C identifiers delimited with
periods. I typically used the name of a function that sets
up a dialog, or the name of an array where the items of a
menu are listed. There is a special feature for static
functions: if the name begins with a period, then the period
will be replaced with the name of the source file and a colon.
- If a menu is programmatically generated from multiple parts,
of which some are never used together, so that it is safe to
use the same accelerators in them, then it is necessary to
define multiple contexts for the same menu. link_menu() in
src/viewer/text/link.c is the most complex example of this.
- During make update-po:
- A Perl script (po/gather-accelerator-contexts.pl) reads
po/elinks.pot, scans the source files listed in it for
"gettext_accelerator_context" comments, and rewrites
po/elinks.pot with "accelerator_context" comments that
indicate the contexts of each msgid: the union of all
contexts of all of its uses in the source files. It also
removes any "gettext_accelerator_context" comments that
xgettext --add-comments has copied to elinks.pot.
- If po/gather-accelerator-contexts.pl does not find any
contexts for some use of an msgid that seems to contain an
accelerator (because it contains a tilde), it warns. If the
tilde refers to e.g. "~/.elinks" and does not actually mark
an accelerator, the warning can be silenced by specifying the
special context "IGNORE", which the script otherwise ignores.
- msgmerge copies the "accelerator_context" comments from
po/elinks.pot to po/*.po. Translators do not edit those
comments.
- During make check-po:
- Another Perl script (po/check-accelerator-contexts.pl) reads
po/*.po and keeps track of which accelerators have been bound
in each context. It warns about any conflicts it finds.
This script does not access the C source files; thus it does
not matter if the line numbers in "#:" lines are out of date.
This implementation is not perfect and I am not proposing to
add it to the main source tree at this time. Specifically:
- It introduces compile-time dependencies on Perl and Locale::PO.
There should be a configure-time or compile-time check so that
the new features are skipped if the prerequisites are missing.
- When the scripts include msgstr strings in warnings, they
should transcode them from the charset of the PO file to the
one specified by the user's locale.
- It is not adequately documented (well, except perhaps here).
- po/check-accelerator-contexts.pl reports the same conflict
multiple times if it occurs in multiple contexts.
- The warning messages should include line numbers, so that users
of Emacs could conveniently edit the conflicting part of the PO
file. This is not feasible with the current version of
Locale::PO.
- Locale::PO does not understand #~ lines and spews warnings
about them. There is an ugly hack to hide these warnings.
- Jonas Fonseca suggested the script could propose accelerators
that are still available. This has not been implemented.
There are three files attached:
- po/gather-accelerator-contexts.pl: Augments elinks.pot with
context information.
- po/check-accelerator-contexts.pl: Checks conflicts.
- accelerator-contexts.diff: Makes po/Makefile run the scripts,
and adds special comments to source files.
2005-12-04 18:38:29 -05:00
|
|
|
/* [gettext_accelerator_context(.build_edit_dialog)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct dialog *dlg;
|
2018-08-25 09:28:29 -04:00
|
|
|
unsigned char *name, *value, *domain, *expires, *secure, *httponly;
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *dlg_server;
|
|
|
|
int length = 0;
|
|
|
|
|
2018-08-25 16:44:11 -04:00
|
|
|
dlg = calloc_dialog(EDIT_WIDGETS_COUNT, MAX_STR_LEN * 6);
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!dlg) return;
|
|
|
|
|
|
|
|
dlg->title = _("Edit", term);
|
|
|
|
dlg->layouter = generic_dialog_layouter;
|
|
|
|
dlg->udata = cookie;
|
|
|
|
dlg->udata2 = NULL;
|
|
|
|
|
|
|
|
name = get_dialog_offset(dlg, EDIT_WIDGETS_COUNT);
|
|
|
|
value = name + MAX_STR_LEN;
|
|
|
|
domain = value + MAX_STR_LEN;
|
|
|
|
expires = domain + MAX_STR_LEN;
|
|
|
|
secure = expires + MAX_STR_LEN;
|
2018-08-25 09:28:29 -04:00
|
|
|
httponly = secure + MAX_STR_LEN;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
safe_strncpy(name, cookie->name, MAX_STR_LEN);
|
|
|
|
safe_strncpy(value, cookie->value, MAX_STR_LEN);
|
|
|
|
safe_strncpy(domain, cookie->domain, MAX_STR_LEN);
|
2018-08-25 16:44:11 -04:00
|
|
|
#ifdef HAVE_STRFTIME
|
|
|
|
if (cookie->expires) {
|
|
|
|
struct tm *tm = localtime(&cookie->expires);
|
|
|
|
|
|
|
|
if (tm) {
|
|
|
|
strftime(expires, MAX_STR_LEN, get_opt_str("ui.date_format", NULL), tm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2005-09-15 09:58:31 -04:00
|
|
|
ulongcat(expires, &length, cookie->expires, MAX_STR_LEN, 0);
|
2018-08-25 16:44:11 -04:00
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
length = 0;
|
|
|
|
ulongcat(secure, &length, cookie->secure, MAX_STR_LEN, 0);
|
2018-08-25 09:28:29 -04:00
|
|
|
length = 0;
|
|
|
|
ulongcat(httponly, &length, cookie->httponly, MAX_STR_LEN, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
dlg_server = cookie->server->host;
|
2007-03-11 06:59:11 -04:00
|
|
|
dlg_server = straconcat(_("Server", term), ": ", dlg_server, "\n",
|
|
|
|
(unsigned char *) NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (!dlg_server) {
|
|
|
|
mem_free(dlg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_dlg_text(dlg, dlg_server, ALIGN_LEFT, 0);
|
|
|
|
add_dlg_field_float(dlg, _("Name", term), 0, 0, set_cookie_name, MAX_STR_LEN, name, NULL);
|
|
|
|
add_dlg_field_float(dlg, _("Value", term), 0, 0, set_cookie_value, MAX_STR_LEN, value, NULL);
|
|
|
|
add_dlg_field_float(dlg, _("Domain", term), 0, 0, set_cookie_domain, MAX_STR_LEN, domain, NULL);
|
|
|
|
add_dlg_field_float(dlg, _("Expires", term), 0, 0, set_cookie_expires, MAX_STR_LEN, expires, NULL);
|
|
|
|
add_dlg_field_float(dlg, _("Secure", term), 0, 0, set_cookie_secure, MAX_STR_LEN, secure, NULL);
|
2018-08-25 09:28:29 -04:00
|
|
|
add_dlg_field_float(dlg, _("HttpOnly", term), 0, 0, set_cookie_httponly, MAX_STR_LEN, httponly, NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
add_dlg_button(dlg, _("~OK", term), B_ENTER, ok_dialog, NULL);
|
|
|
|
add_dlg_button(dlg, _("~Cancel", term), B_ESC, cancel_dialog, NULL);
|
|
|
|
|
|
|
|
add_dlg_end(dlg, EDIT_WIDGETS_COUNT);
|
|
|
|
|
2007-03-11 06:41:17 -04:00
|
|
|
do_dialog(term, dlg, getml(dlg, (void *) dlg_server, (void *) NULL));
|
2005-09-15 09:58:31 -04:00
|
|
|
#undef EDIT_WIDGETS_COUNT
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
push_edit_button(struct dialog_data *dlg_data, struct widget_data *button)
|
|
|
|
{
|
|
|
|
struct listbox_data *box = get_dlg_listbox_data(dlg_data);
|
|
|
|
struct terminal *term = dlg_data->win->term;
|
|
|
|
struct cookie *cookie;
|
|
|
|
|
|
|
|
if (!box->sel) return EVENT_PROCESSED;
|
|
|
|
if (box->sel->type == BI_FOLDER) return EVENT_PROCESSED;
|
|
|
|
cookie = box->sel->udata;
|
|
|
|
if (!cookie) return EVENT_PROCESSED;
|
|
|
|
build_edit_dialog(term, cookie);
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
push_add_button(struct dialog_data *dlg_data, struct widget_data *button)
|
|
|
|
{
|
|
|
|
struct listbox_data *box = get_dlg_listbox_data(dlg_data);
|
|
|
|
struct terminal *term = dlg_data->win->term;
|
|
|
|
struct cookie *new_cookie;
|
|
|
|
struct cookie_server *server;
|
|
|
|
|
|
|
|
if (!box->sel || !box->sel->udata) return EVENT_PROCESSED;
|
|
|
|
|
|
|
|
if (box->sel->type == BI_FOLDER) {
|
|
|
|
assert(box->sel->depth == 0);
|
|
|
|
server = box->sel->udata;
|
|
|
|
} else {
|
|
|
|
struct cookie *cookie = box->sel->udata;
|
|
|
|
|
|
|
|
server = cookie->server;
|
|
|
|
}
|
|
|
|
|
2006-05-31 17:36:11 -04:00
|
|
|
object_lock(server); /* ref consumed by init_cookie */
|
|
|
|
|
|
|
|
new_cookie = init_cookie(stracpy("") /* name */,
|
|
|
|
stracpy("") /* value */,
|
|
|
|
stracpy("/") /* path */,
|
|
|
|
stracpy(server->host) /* domain */,
|
|
|
|
server);
|
|
|
|
if (!new_cookie) return EVENT_PROCESSED;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
accept_cookie(new_cookie);
|
|
|
|
build_edit_dialog(term, new_cookie);
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
2006-05-28 05:43:29 -04:00
|
|
|
/* Called by ok_dialog for the "OK" button in the "Add Server" dialog.
|
|
|
|
* The data parameter points to the buffer used by the server name
|
|
|
|
* widget. */
|
|
|
|
static void
|
|
|
|
add_server_do(void *data)
|
2006-04-01 13:22:18 -05:00
|
|
|
{
|
2006-05-28 05:43:29 -04:00
|
|
|
unsigned char *value = data;
|
2006-05-31 17:36:11 -04:00
|
|
|
struct cookie *dummy_cookie;
|
2006-04-01 13:22:18 -05:00
|
|
|
|
2006-05-28 05:43:29 -04:00
|
|
|
if (!value) return;
|
2006-05-27 17:56:42 -04:00
|
|
|
|
2006-05-31 17:36:11 -04:00
|
|
|
dummy_cookie = init_cookie(stracpy("empty") /* name */,
|
|
|
|
stracpy("1") /* value */,
|
|
|
|
stracpy("/") /* path */,
|
|
|
|
stracpy(value) /* domain */,
|
|
|
|
get_cookie_server(value, strlen(value)));
|
|
|
|
if (!dummy_cookie) return;
|
2006-05-27 17:56:42 -04:00
|
|
|
|
|
|
|
accept_cookie(dummy_cookie);
|
2006-04-01 13:22:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
push_add_server_button(struct dialog_data *dlg_data, struct widget_data *button)
|
|
|
|
{
|
2006-05-21 09:51:07 -04:00
|
|
|
/* [gettext_accelerator_context(.push_add_server_button)] */
|
2006-04-01 13:22:18 -05:00
|
|
|
#define SERVER_WIDGETS_COUNT 3
|
|
|
|
struct terminal *term = dlg_data->win->term;
|
|
|
|
struct dialog *dlg;
|
|
|
|
unsigned char *name;
|
|
|
|
unsigned char *text;
|
|
|
|
|
|
|
|
dlg = calloc_dialog(SERVER_WIDGETS_COUNT, MAX_STR_LEN);
|
|
|
|
if (!dlg) return EVENT_NOT_PROCESSED;
|
|
|
|
|
|
|
|
name = get_dialog_offset(dlg, SERVER_WIDGETS_COUNT);
|
|
|
|
dlg->title = _("Add server", term);
|
|
|
|
dlg->layouter = generic_dialog_layouter;
|
|
|
|
dlg->udata = NULL;
|
|
|
|
dlg->udata2 = NULL;
|
|
|
|
text = _("Server name", term);
|
2006-05-28 05:43:29 -04:00
|
|
|
add_dlg_field_float(dlg, text, 0, 0, check_nonempty, MAX_STR_LEN, name, NULL);
|
|
|
|
add_dlg_ok_button(dlg, _("~OK", term), B_ENTER, add_server_do, name);
|
2006-04-01 13:22:18 -05:00
|
|
|
add_dlg_button(dlg, _("~Cancel", term), B_ESC, cancel_dialog, NULL);
|
|
|
|
add_dlg_end(dlg, SERVER_WIDGETS_COUNT);
|
2007-03-11 06:41:17 -04:00
|
|
|
do_dialog(term, dlg, getml(dlg, (void *) NULL));
|
2006-04-01 13:22:18 -05:00
|
|
|
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
#undef SERVER_WIDGETS_COUNT
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
static widget_handler_status_T
|
|
|
|
push_save_button(struct dialog_data *dlg_data, struct widget_data *button)
|
|
|
|
{
|
2006-12-09 11:27:40 -05:00
|
|
|
save_cookies(dlg_data->win->term);
|
2005-09-15 09:58:31 -04:00
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
2007-02-04 06:54:07 -05:00
|
|
|
static const struct hierbox_browser_button cookie_buttons[] = {
|
Here is a framework that detects cases where a PO file assigns
the same accelerator key to multiple buttons in a dialog box or
to multiple items in a menu. ELinks already has some support for
this but it requires the translator to run ELinks and manually
scan through all menus and dialogs. The attached changes make it
possible to quickly detect and list any conflicts, including ones
that can only occur on operating systems or configurations that
the translator is not currently using.
The changes have no immediate effect on the elinks executable or
the MO files. PO files become larger, however.
The scheme works like this:
- Like before, accelerator keys in translatable strings are
tagged with the tilde (~) character.
- Whenever a C source file defines an accelerator key, it must
assign one or more named "contexts" to it. The translations in
the PO files inherit these contexts. If multiple strings use
the same accelerator (case insensitive) in the same context,
that's a conflict and can be detected automatically.
- The contexts are defined with "gettext_accelerator_context"
comments in source files. These comments delimit regions where
all translatable strings containing tildes are given the same
contexts. There must be one special comment at the top of the
region; it lists the contexts assigned to that region. The
region automatically ends at the end of the function (found
with regexp /^\}/), but it can also be closed explicitly with
another special comment. The comments are formatted like this:
/* [gettext_accelerator_context(foo, bar, baz)]
begins a region that uses the contexts "foo", "bar", and "baz".
The comma is the delimiter; whitespace is optional.
[gettext_accelerator_context()]
ends the region. */
The scripts don't currently check whether this syntax occurs
inside or outside comments.
- The names of contexts consist of C identifiers delimited with
periods. I typically used the name of a function that sets
up a dialog, or the name of an array where the items of a
menu are listed. There is a special feature for static
functions: if the name begins with a period, then the period
will be replaced with the name of the source file and a colon.
- If a menu is programmatically generated from multiple parts,
of which some are never used together, so that it is safe to
use the same accelerators in them, then it is necessary to
define multiple contexts for the same menu. link_menu() in
src/viewer/text/link.c is the most complex example of this.
- During make update-po:
- A Perl script (po/gather-accelerator-contexts.pl) reads
po/elinks.pot, scans the source files listed in it for
"gettext_accelerator_context" comments, and rewrites
po/elinks.pot with "accelerator_context" comments that
indicate the contexts of each msgid: the union of all
contexts of all of its uses in the source files. It also
removes any "gettext_accelerator_context" comments that
xgettext --add-comments has copied to elinks.pot.
- If po/gather-accelerator-contexts.pl does not find any
contexts for some use of an msgid that seems to contain an
accelerator (because it contains a tilde), it warns. If the
tilde refers to e.g. "~/.elinks" and does not actually mark
an accelerator, the warning can be silenced by specifying the
special context "IGNORE", which the script otherwise ignores.
- msgmerge copies the "accelerator_context" comments from
po/elinks.pot to po/*.po. Translators do not edit those
comments.
- During make check-po:
- Another Perl script (po/check-accelerator-contexts.pl) reads
po/*.po and keeps track of which accelerators have been bound
in each context. It warns about any conflicts it finds.
This script does not access the C source files; thus it does
not matter if the line numbers in "#:" lines are out of date.
This implementation is not perfect and I am not proposing to
add it to the main source tree at this time. Specifically:
- It introduces compile-time dependencies on Perl and Locale::PO.
There should be a configure-time or compile-time check so that
the new features are skipped if the prerequisites are missing.
- When the scripts include msgstr strings in warnings, they
should transcode them from the charset of the PO file to the
one specified by the user's locale.
- It is not adequately documented (well, except perhaps here).
- po/check-accelerator-contexts.pl reports the same conflict
multiple times if it occurs in multiple contexts.
- The warning messages should include line numbers, so that users
of Emacs could conveniently edit the conflicting part of the PO
file. This is not feasible with the current version of
Locale::PO.
- Locale::PO does not understand #~ lines and spews warnings
about them. There is an ugly hack to hide these warnings.
- Jonas Fonseca suggested the script could propose accelerators
that are still available. This has not been implemented.
There are three files attached:
- po/gather-accelerator-contexts.pl: Augments elinks.pot with
context information.
- po/check-accelerator-contexts.pl: Checks conflicts.
- accelerator-contexts.diff: Makes po/Makefile run the scripts,
and adds special comments to source files.
2005-12-04 18:38:29 -05:00
|
|
|
/* [gettext_accelerator_context(.cookie_buttons)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
{ N_("~Info"), push_hierbox_info_button, 1 },
|
|
|
|
{ N_("~Add"), push_add_button, 1 },
|
2006-04-01 13:22:18 -05:00
|
|
|
{ N_("Add ~server"), push_add_server_button, 1 },
|
2005-09-15 09:58:31 -04:00
|
|
|
{ N_("~Edit"), push_edit_button, 1 },
|
|
|
|
{ N_("~Delete"), push_hierbox_delete_button, 1 },
|
2006-01-01 04:16:42 -05:00
|
|
|
{ N_("C~lear"), push_hierbox_clear_button, 1 },
|
2005-09-15 09:58:31 -04:00
|
|
|
{ N_("Sa~ve"), push_save_button, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
struct_hierbox_browser(
|
|
|
|
cookie_browser,
|
|
|
|
N_("Cookie manager"),
|
|
|
|
cookie_buttons,
|
|
|
|
&cookies_listbox_ops
|
|
|
|
);
|
|
|
|
|
|
|
|
void
|
|
|
|
cookie_manager(struct session *ses)
|
|
|
|
{
|
|
|
|
hierbox_browser(&cookie_browser, ses);
|
|
|
|
}
|