aboutsummaryrefslogtreecommitdiff
path: root/config-daemon.ac
blob: 86306effe1f8444ea7669a0249ae826fe7dd9bcf (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
dnl -*- Autoconf -*- fragment for the C++ daemon.

AC_MSG_CHECKING([whether to build daemon])
AC_MSG_RESULT([$guix_build_daemon])

dnl C++ environment.  This macro must be used unconditionnaly.
AC_PROG_CXX
AM_PROG_AR
AC_LANG([C++])

if test "x$guix_build_daemon" = "xyes"; then

  GUIX_ASSERT_CXX11

  AC_PROG_RANLIB
  AC_CONFIG_HEADERS([nix/config.h])

  dnl Use 64-bit file system calls so that we can support files > 2 GiB.
  AC_SYS_LARGEFILE

  dnl Look for zlib, a required dependency.
  AC_CHECK_LIB([z], [gzdopen], [true],
    [AC_MSG_ERROR([Guix requires zlib.  See http://www.zlib.net/.])])
  AC_CHECK_HEADERS([zlib.h], [true],
    [AC_MSG_ERROR([Guix requires zlib.  See http://www.zlib.net/.])])

  dnl Look for libbz2, an optional dependency.
  AC_CHECK_LIB([bz2], [BZ2_bzWriteOpen], [HAVE_LIBBZ2=yes], [HAVE_LIBBZ2=no])
  if test "x$HAVE_LIBBZ2" = xyes; then
    AC_CHECK_HEADERS([bzlib.h])
    HAVE_LIBBZ2="$ac_cv_header_bzlib_h"
  fi

  dnl Look for SQLite, a required dependency.
  PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19])

  AC_DEFINE_UNQUOTED([SYSTEM], ["$guix_system"],
    [Guix host system type--i.e., platform and OS kernel tuple.])

  case "$LIBGCRYPT_PREFIX" in
    no)
      LIBGCRYPT_CFLAGS=""
      ;;
    *)
      LIBGCRYPT_CFLAGS="-I$LIBGCRYPT_PREFIX/include"
      ;;
  esac

  case "$LIBGCRYPT_LIBDIR" in
    no | "")
      LIBGCRYPT_LIBS="-lgcrypt"
      ;;
    *)
      LIBGCRYPT_LIBS="-L$LIBGCRYPT_LIBDIR -lgcrypt"
      ;;
  esac

  AC_SUBST([LIBGCRYPT_CFLAGS])
  AC_SUBST([LIBGCRYPT_LIBS])

  save_CFLAGS="$CFLAGS"
  save_LDFLAGS="$LDFLAGS"
  CFLAGS="$CFLAGS $LIBGCRYPT_CFLAGS"
  LDFLAGS="$LDFLAGS $LIBGCRYPT_LDFLAGS"

  have_gcrypt=yes
  AC_CHECK_LIB([gcrypt], [gcry_md_open], [:], [have_gcrypt=no])
  AC_CHECK_HEADER([gcrypt.h], [:], [have_gcrypt=no])
  if test "x$have_gcrypt" != "xyes"; then
    AC_MSG_ERROR([GNU libgcrypt not found; please install it.])
  fi

  CFLAGS="$save_CFLAGS"
  LDFLAGS="$save_LDFLAGS"

  dnl Chroot support.
  AC_CHECK_FUNCS([chroot unshare])
  AC_CHECK_HEADERS([sched.h sys/param.h sys/mount.h sys/syscall.h])

  if test "x$ac_cv_func_chroot" != "xyes"; then
    AC_MSG_ERROR(['chroot' function missing, bailing out])
  fi

  dnl lutimes and lchown: used when canonicalizing store items.
  dnl posix_fallocate: used when extracting archives.
  dnl vfork: to speed up spawning of helper programs.
  dnl   `--> now disabled because of unpredictable behavior:
  dnl        see <http://lists.gnu.org/archive/html/guix-devel/2014-05/msg00036.html>
  dnl        and Nix commit f794465c (Nov. 2012).
  dnl sched_setaffinity: to improve RPC locality.
  dnl statvfs: to detect disk-full conditions.
  dnl strsignal: for error reporting.
  dnl statx: fine-grain 'stat' call, new in glibc 2.28.
  AC_CHECK_FUNCS([lutimes lchown posix_fallocate sched_setaffinity \
     statvfs nanosleep strsignal statx])

  dnl Check for <locale>.
  AC_LANG_PUSH(C++)
  AC_CHECK_HEADERS([locale])
  AC_LANG_POP(C++)


  dnl Check whether we have the `personality' syscall, which allows us
  dnl to do i686-linux builds on x86_64-linux machines.
  AC_CHECK_HEADERS([sys/personality.h])

  dnl Determine the appropriate default list of substitute URLs (GnuTLS
  dnl is required so we can default to 'https'.)
  guix_substitute_urls="https://ci.guix.gnu.org https://bordeaux.guix.gnu.org"

  AC_MSG_CHECKING([for default substitute URLs])
  AC_MSG_RESULT([$guix_substitute_urls])

  AC_DEFINE_UNQUOTED([GUIX_SUBSTITUTE_URLS], ["$guix_substitute_urls"],
    [Default list of substitute URLs used by 'guix-daemon'.])

  dnl Check for Guile-SSH, which is required by 'guix offload'.
  GUIX_CHECK_GUILE_SSH

  case "x$guix_cv_have_recent_guile_ssh" in
    xyes)
      guix_build_daemon_offload="yes"
      AC_DEFINE([HAVE_DAEMON_OFFLOAD_HOOK], [1],
	[Define if the daemon's 'offload' build hook is being built (requires Guile-SSH).])
      ;;
    *)
      guix_build_daemon_offload="no"
      ;;
  esac

  dnl Temporary directory used to store the daemon's data.
  GUIX_TEST_ROOT_DIRECTORY
  GUIX_TEST_ROOT="$ac_cv_guix_test_root"
  AC_SUBST([GUIX_TEST_ROOT])

  GUIX_CHECK_LOCALSTATEDIR
fi

AM_CONDITIONAL([HAVE_LIBBZ2], [test "x$HAVE_LIBBZ2" = "xyes"])
AM_CONDITIONAL([BUILD_DAEMON], [test "x$guix_build_daemon" = "xyes"])
AM_CONDITIONAL([BUILD_DAEMON_OFFLOAD],			\
  [test "x$guix_build_daemon" = "xyes"			\
   && test "x$guix_build_daemon_offload" = "xyes"])
> -rw-r--r--common/entities.js15
-rw-r--r--common/indexeddb.js63
-rw-r--r--common/lock.js17
-rw-r--r--common/message_server.js12
-rw-r--r--common/misc.js43
-rw-r--r--common/observables.js (renamed from common/observable.js)18
-rw-r--r--common/once.js6
-rw-r--r--common/patterns.js13
-rw-r--r--common/patterns_query_tree.js27
-rw-r--r--common/sanitize_JSON.js6
-rw-r--r--common/settings_query.js27
-rw-r--r--common/sha256.js8
-rw-r--r--common/storage_client.js21
-rw-r--r--common/storage_light.js39
-rw-r--r--common/storage_raw.js33
-rw-r--r--common/stored_types.js12
-rwxr-xr-x[-rw-r--r--]compute_scripts.awk748
-rw-r--r--content/activity_info_server.js34
-rw-r--r--content/main.js29
-rw-r--r--content/page_actions.js19
-rw-r--r--content/repo_query.js30
-rw-r--r--copyright17
-rw-r--r--html/DOM_helpers.js15
-rw-r--r--html/MOZILLA_scrollbar_fix.css48
-rw-r--r--html/back_button.css28
-rw-r--r--html/base.css29
-rw-r--r--html/default_blocking_policy.html32
-rw-r--r--html/default_blocking_policy.js17
-rw-r--r--html/display_panel.html (renamed from html/display-panel.html)42
-rw-r--r--html/display_panel.js (renamed from html/display-panel.js)68
-rw-r--r--html/import_frame.html31
-rw-r--r--html/import_frame.js21
-rw-r--r--html/mozilla_scrollbar_fix.css67
-rw-r--r--html/options.html38
-rw-r--r--html/options_main.js24
-rw-r--r--html/reset.css3
-rw-r--r--html/table.css29
-rw-r--r--manifest.json53
-rwxr-xr-xprocess_html_file.sh43
-rw-r--r--test/script_loader.py55
-rw-r--r--test/unit/conftest.py8
-rw-r--r--test/unit/test_basic.py6
-rw-r--r--test/unit/test_broadcast.py54
-rw-r--r--test/unit/test_indexeddb.py32
-rw-r--r--test/unit/test_patterns.py12
-rw-r--r--test/unit/test_patterns_query_tree.py52
62 files changed, 1412 insertions, 1188 deletions
diff --git a/CHROMIUM_exports_init.js b/CHROMIUM_exports_init.js
deleted file mode 100644
index 0e61d40..0000000
--- a/CHROMIUM_exports_init.js
+++ /dev/null
@@ -1,3 +0,0 @@
-// SPDX-License-Identifier: CC0-1.0
-
-window.haketilo_exports = {is_chrome: true, browser: window.chrome};
diff --git a/MOZILLA_exports_init.js b/MOZILLA_exports_init.js
deleted file mode 100644
index a1135e8..0000000
--- a/MOZILLA_exports_init.js
+++ /dev/null
@@ -1,57 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-/**
- * This file is part of Haketilo.
- *
- * Function: Data structure to query items by URL patterns.
- *
- * Copyright (C) 2021 Wojtek Kosior
- *
- * This program 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, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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.
- *
- * As additional permission under GNU GPL version 3 section 7, you
- * may distribute forms of that code without the copy of the GNU
- * GPL normally required by section 4, provided you include this
- * license notice and, in case of non-source distribution, a URL
- * through which recipients can access the Corresponding Source.
- * If you modify file(s) with this exception, you may extend this
- * exception to your version of the file(s), but you are not
- * obligated to do so. If you do not wish to do so, delete this
- * exception statement from your version.
- *
- * As a special exception to the GPL, any HTML file which merely
- * makes function calls to this code, and for that purpose
- * includes it by reference shall be deemed a separate work for
- * copyright law purposes. If you modify this code, you may extend
- * this exception to your version of the code, but you are not
- * obligated to do so. If you do not wish to do so, delete this
- * exception statement from your version.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * I, Wojtek Kosior, thereby promise not to sue for violation of this file's
- * license. Although I request that you do not make use this code in a
- * proprietary program, I am not going to enforce this in court.
- */
-
-/* Polyfill for IceCat 60. */
-String.prototype.matchAll = String.prototype.matchAll || function(regex) {
- if (regex.flags.search("g") === -1)
- throw new TypeError("String.prototype.matchAll called with a non-global RegExp argument");
-
- for (const matches = [];;) {
- if (matches[matches.push(regex.exec(this)) - 1] === null)
- return matches.splice(0, matches.length - 1);
- }
-}
-
-window.haketilo_exports = {is_mozilla: true, browser: this.browser};
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9eed5d5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,44 @@
+[//]: # ( SPDX-License-Identifier: CC0-1.0 )
+
+[//]: # ( Haketilo's README file )
+
+[//]: # ( Copyright (C) 2021 Wojtek Kosior )
+
+[//]: # ( Available under the terms of Creative Commons Zero v1.0 Universal. )
+
+# Haketilo - Make The Web Great Again!
+
+This extension's goal is to allow replacing javascript served by websites
+with scripts specified by user. Something like NoScript and Greasemonkey
+together. Such facility is necessary to enable browsing World Wide Web
+without executing nonfree software.
+
+Currently, the target browsers for this extension are Ungoogled Chromium
+and various forks of Firefox (version 60+).
+
+This extension is still in an early stage. Also see
+[our wiki](https://hydrillabugs.koszko.org/projects/haketilo/wiki/)
+for documentation in development.
+
+## Installation
+The extension can be "built" with `./build.sh mozilla` or `./build.sh chromium`.
+This creates directories build_mozilla/ and build_chromium/, respectively.
+Such directory can be loaded into Ungoogled Chromium or a modern Gecko-based
+browser as unpacked extension.
+
+## Copyright
+All copyright information is gathered in the `copyright` file which follows
+(loosely) the [format of debian/copyright file](https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/). License notices are also present in all text files of the extension.
+
+In general, this entire extension is available under the terms of GPLv3+ with
+various additional licenses and permissions for particular files.
+
+I, Wojtek Kosior, thereby promise not to sue for violation of this program's
+licenses. Although I request that you do not make use this code in a proprietary
+program, I am not going to enforce this in court.
+
+## Contributing
+Get the code from: https://git.koszko.org/browser-extension/
+Come to: https://hydrillabugs.koszko.org/projects/haketilo
+
+Optionally, write to `$(echo a29zemtvQGtvc3prby5vcmcK | base64 -d)`
diff --git a/README.txt b/README.txt
deleted file mode 100644
index 1aec0ba..0000000
--- a/README.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-# Haketilo - Make The Web Great Again! #
-
-This extension's goal is to allow replacing javascript served by websites
-with scripts specified by user. Something like NoScript and Greasemonkey
-together. Such facility is necessary to enable browsing World Wide Web
-without executing nonfree software.
-
-Currently, the target browsers for this extension are Ungoogled Chromium
-and various forks of Firefox (version 60+).
-
-This extension is still in an early stage. Also see
-`https://hydrillabugs.koszko.org/projects/haketilo/wiki/' for documentation in
-development.
-
-## Installation ##
-The extension can be "built" with `./build.sh mozilla' or `./build.sh chromium'.
-This creates directories build_mozilla/ and build_chromium/, respectively.
-Such directory can be loaded into Ungoogled Chromium or a modern Gecko-based
-browser as unpacked extension.
-
-## Copyright ##
-All copyright information is gathered in the `copyright' file which follows
-(loosely) the format of debian/copyright file described at
-`https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/'
-
-In general, this entire extension is available under the terms of GPLv3+ with
-various additional licenses and permissions for particular files.
-
-## Contributing ##
-Get the code from: https://git.koszko.org/browser-extension/
-Come to: https://hydrillabugs.koszko.org/projects/haketilo
-
-Optionally, write to $(echo a29zemtvQGtvc3prby5vcmcK | base64 -d)
diff --git a/background/broadcast_broker.js b/background/broadcast_broker.js
index 7af8769..9847d7e 100644
--- a/background/broadcast_broker.js
+++ b/background/broadcast_broker.js
@@ -42,12 +42,9 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT listen_for_connection
- * IMPORT CONNECTION_TYPE
- * IMPORTS_END
- */
+#IMPORT common/connection_types.js AS CONNECTION_TYPE
+
+#FROM common/message_server.js IMPORT listen_for_connection
let next_id = 1;
@@ -55,7 +52,7 @@ const listeners_by_channel = new Map();
function new_broadcast_listener(port)
{
- listener_ctx = {port, id: ++next_id, channels: new Set()};
+ const listener_ctx = {port, id: ++next_id, channels: new Set()};
port.onMessage.addListener(msg => listener_command(msg, listener_ctx));
port.onDisconnect.addListener(msg => listener_remove(msg, listener_ctx));
}
@@ -102,7 +99,7 @@ function remove_broadcast_listener(listener_ctx)
function new_broadcast_sender(port)
{
- sender_ctx = {prepared_broadcasts: new Set()};
+ const sender_ctx = {prepared_broadcasts: new Set()};
port.onMessage.addListener(msg => sender_command(msg, sender_ctx));
port.onDisconnect.addListener(msg => flush(sender_ctx));
}
@@ -125,7 +122,7 @@ function sender_command(msg, sender_ctx)
function prepare(sender_ctx, channel_name, value, timeout)
{
- broadcast_data = [channel_name, value];
+ const broadcast_data = [channel_name, value];
sender_ctx.prepared_broadcasts.add(broadcast_data);
if (timeout === 0)
@@ -170,15 +167,10 @@ function remove_broadcast_sender(sender_ctx)
sender_ctx.prepared_broadcasts.forEach(nv => broadcast(...nv));
}
-function start_broadcast_broker()
+function start()
{
listen_for_connection(CONNECTION_TYPE.BROADCAST_SEND, new_broadcast_sender);
listen_for_connection(CONNECTION_TYPE.BROADCAST_LISTEN,
new_broadcast_listener);
}
-
-/*
- * EXPORTS_START
- * EXPORT start_broadcast_broker
- * EXPORTS_END
- */
+#EXPORT start
diff --git a/background/main.js b/background/main.js
index 2809334..cff0786 100644
--- a/background/main.js
+++ b/background/main.js
@@ -42,26 +42,25 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT initial_data
- * IMPORT TYPE_PREFIX
- * IMPORT get_storage
- * IMPORT light_storage
- * IMPORT start_storage_server
- * IMPORT start_page_actions_server
- * IMPORT browser
- * IMPORT is_privileged_url
- * IMPORT query_best
- * IMPORT inject_csp_headers
- * IMPORT apply_stream_filter
- * IMPORT is_chrome
- * IMPORT is_mozilla
- * IMPORTS_END
- */
+#IMPORT common/storage_light.js AS light_storage
+
+#IMPORT background/storage_server.js
+#IMPORT background/page_actions_server.js
+#IMPORT background/stream_filter.js
+
+#FROM common/browser.js IMPORT browser
+#FROM common/stored_types.js IMPORT TYPE_PREFIX
+#FROM background/storage.js IMPORT get_storage
+#FROM common/misc.js IMPORT is_privileged_url
+#FROM common/settings_query.js IMPORT query_best
+#FROM background/policy_injector.js IMPORT inject_csp_headers
+
+const initial_data = (
+#INCLUDE_VERBATIM default_settings.json
+);
-start_storage_server();
-start_page_actions_server();
+storage_server.start();
+page_actions_server.start();
async function init_ext(install_details)
{
@@ -131,7 +130,7 @@ function sanitize_web_page(details)
if (!skip) {
/* Check for API availability. */
if (browser.webRequest.filterResponseData)
- headers = apply_stream_filter(details, headers, policy);
+ headers = stream_filter.apply(details, headers, policy);
}
return {responseHeaders: headers};
@@ -192,9 +191,11 @@ async function start_webRequest_operations()
{
storage = await get_storage();
+#IF CHROMIUM
+ const extra_opts = ["blocking", "extraHeaders"];
+#ELSE
const extra_opts = ["blocking"];
- if (is_chrome)
- extra_opts.push("extraHeaders");
+#ENDIF
browser.webRequest.onHeadersReceived.addListener(
sanitize_web_page,
@@ -214,6 +215,7 @@ async function start_webRequest_operations()
start_webRequest_operations();
+#IF MOZILLA
const code = `\
console.warn("Hi, I'm Mr Dynamic!");
@@ -232,5 +234,5 @@ async function test_dynamic_content_scripts()
});
}
-if (is_mozilla)
- test_dynamic_content_scripts();
+test_dynamic_content_scripts();
+#ENDIF
diff --git a/background/page_actions_server.js b/background/page_actions_server.js
index bb4c34f..578d1b1 100644
--- a/background/page_actions_server.js
+++ b/background/page_actions_server.js
@@ -41,18 +41,15 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT get_storage
- * IMPORT light_storage
- * IMPORT TYPE_PREFIX
- * IMPORT CONNECTION_TYPE
- * IMPORT browser
- * IMPORT listen_for_connection
- * IMPORT sha256
- * IMPORT make_ajax_request
- * IMPORTS_END
- */
+#IMPORT common/storage_light.js AS light_storage
+#IMPORT common/connection_types.js AS CONNECTION_TYPE
+
+#FROM common/browser.js IMPORT browser
+#FROM common/message_server.js IMPORT listen_for_connection
+#FROM background/storage.js IMPORT get_storage
+#FROM common/stored_types.js IMPORT TYPE_PREFIX
+#FROM common/sha256.js IMPORT sha256
+#FROM common/ajax.js IMPORT make_ajax_request
var storage;
var handler;
@@ -143,15 +140,10 @@ function new_connection(port)
port.onMessage.addListener(handler[0]);
}
-async function start_page_actions_server()
+async function start()
{
storage = await get_storage();
listen_for_connection(CONNECTION_TYPE.PAGE_ACTIONS, new_connection);
}
-
-/*
- * EXPORTS_START
- * EXPORT start_page_actions_server
- * EXPORTS_END
- */
+#EXPORT start
diff --git a/background/policy_injector.js b/background/policy_injector.js
index 787f1f0..2544e8e 100644
--- a/background/policy_injector.js
+++ b/background/policy_injector.js
@@ -43,14 +43,12 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT make_csp_rule
- * IMPORT csp_header_regex
- * Re-enable the import below once nonce stuff here is ready
- * !mport gen_nonce
- * IMPORTS_END
- */
+#FROM common/misc.js IMPORT make_csp_rule, csp_header_regex
+
+/* Re-enable the import below once nonce stuff here is ready */
+#IF NEVER
+#FROM common/misc.js IMPORT gen_nonce
+#ENDIF
function inject_csp_headers(headers, policy)
{
@@ -76,8 +74,4 @@ function inject_csp_headers(headers, policy)
return headers;
}
-/*
- * EXPORTS_START
- * EXPORT inject_csp_headers
- * EXPORTS_END
- */
+#EXPORT inject_csp_headers
diff --git a/background/storage.js b/background/storage.js
index d57c701..2a93b87 100644
--- a/background/storage.js
+++ b/background/storage.js
@@ -41,19 +41,13 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT raw_storage
- * IMPORT TYPE_NAME
- * IMPORT list_prefixes
- * IMPORT make_lock
- * IMPORT lock
- * IMPORT unlock
- * IMPORT make_once
- * IMPORT browser
- * IMPORT observables
- * IMPORTS_END
- */
+#IMPORT common/storage_raw.js AS raw_storage
+#IMPORT common/observables.js
+
+#FROM common/stored_types.js IMPORT list_prefixes, TYPE_NAME
+#FROM common/lock.js IMPORT lock, unlock, make_lock
+#FROM common/once.js IMPORT make_once
+#FROM common/browser.js IMPORT browser
var exports = {};
@@ -362,10 +356,4 @@ exports.clear = async function ()
unlock(list.lock);
}
-const get_storage = make_once(init);
-
-/*
- * EXPORTS_START
- * EXPORT get_storage
- * EXPORTS_END
- */
+#EXPORT make_once(init) AS get_storage
diff --git a/background/storage_server.js b/background/storage_server.js
index 9355f86..2d13690 100644
--- a/background/storage_server.js
+++ b/background/storage_server.js
@@ -41,14 +41,11 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT listen_for_connection
- * IMPORT get_storage
- * IMPORT list_prefixes
- * IMPORT CONNECTION_TYPE
- * IMPORTS_END
- */
+#IMPORT common/connection_types.js AS CONNECTION_TYPE
+
+#FROM common/message_server.js IMPORT listen_for_connection
+#FROM background/storage.js IMPORT get_storage
+#FROM common/stored_types.js IMPORT list_prefixes
var storage;
@@ -89,15 +86,10 @@ function new_connection(port)
remove_storage_listener(handle_change));
}
-async function start_storage_server()
+async function start()
{
storage = await get_storage();
listen_for_connection(CONNECTION_TYPE.REMOTE_STORAGE, new_connection);
}
-
-/*
- * EXPORTS_START
- * EXPORT start_storage_server
- * EXPORTS_END
- */
+#EXPORT start
diff --git a/background/stream_filter.js b/background/stream_filter.js
index 9d8e1e5..925a39d 100644
--- a/background/stream_filter.js
+++ b/background/stream_filter.js
@@ -29,12 +29,8 @@
* in LibreJS.
*/
-/*
- * IMPORTS_START
- * IMPORT browser
- * IMPORT csp_header_regex
- * IMPORTS_END
- */
+#FROM common/browser.js IMPORT browser
+#FROM common/misc.js IMPORT csp_header_regex
function validate_encoding(charset)
{
@@ -204,7 +200,7 @@ function filter_data(properties, event)
properties.filter.disconnect();
}
-function apply_stream_filter(details, headers, policy)
+function apply(details, headers, policy)
{
if (!policy.payload)
return headers;
@@ -224,9 +220,4 @@ function apply_stream_filter(details, headers, policy)
*/
return headers;
}
-
-/*
- * EXPORTS_START
- * EXPORT apply_stream_filter
- * EXPORTS_END
- */
+#EXPORT apply
diff --git a/build.sh b/build.sh
index d0958a1..8d5b97e 100755
--- a/build.sh
+++ b/build.sh
@@ -17,137 +17,18 @@ set -e
. ./shell_utils.sh
-as_json_list() {
- while true; do
- if [ "x" = "x$2" ]; then
- printf '\\n\t\t"%s"\\n\t' "$1"
- return
- fi
- printf '\\n\t\t"%s",' "$1"
- shift
- done
-}
-
-as_html_list() {
- while [ "x" != "x$1" ]; do
- printf '\\n <script src="/%s"></script>' "$1"
- shift
- done
-}
-
-compute_scripts() {
- local DIRS="$1"
- local ROOT_SCRIPT="$2"
-
- local AVAILABLE="$(find $DIRS -name '[^.#]*.js')"
-
- awk -f compute_scripts.awk script_dependencies "$ROOT_SCRIPT" $AVAILABLE
-}
-
-build_main() {
- local ALL_SCRIPTDIRS='background html common content'
-
- local ALL_SCRIPTS_AVAILABLE="$(find $ALL_SCRIPTDIRS -name '[^.#]*.js')"
-
- local SCRIPT
- for SCRIPT in $ALL_SCRIPTS_AVAILABLE; do
- map_set SCRIPTS_UNUSED $(sanitize $SCRIPT) yes
- done
-
- local ROOT=background/main.js
- local SCRIPTS_BG="$( compute_scripts 'common/ background/' $ROOT)"
-
- local ROOT=content/main.js
- local SCRIPTS_CONTENT="$( compute_scripts 'common/ content/' $ROOT)"
-
- local ROOT=html/display-panel.js
- local SCRIPTS_POPUP="$( compute_scripts 'common/ html/' $ROOT)"
-
- local ROOT=html/options_main.js
- local SCRIPTS_OPTIONS="$( compute_scripts 'common/ html/' $ROOT)"
-
- local BGSCRIPTS="$( as_json_list $SCRIPTS_BG )"
- local CONTENTSCRIPTS="$( as_json_list $SCRIPTS_CONTENT )"
- local POPUPSCRIPTS="$( as_html_list $SCRIPTS_POPUP )"
- local OPTIONSSCRIPTS="$( as_html_list $SCRIPTS_OPTIONS )"
-
- for SCRIPT in $SCRIPTS_BG $SCRIPTS_CONTENT $SCRIPTS_POPUP $SCRIPTS_OPTIONS
- do
- map_del SCRIPTS_UNUSED $(sanitize $SCRIPT)
- done
-
- for DIR in $(find $ALL_SCRIPTDIRS -type d); do
- mkdir -p "$BUILDDIR"/$DIR
- done
-
- CHROMIUM_UPDATE_URL=''
- GECKO_APPLICATIONS=''
-
- if [ "x$UPDATE_URL" != x ]; then
- UPDATE_URL=",\n \"update_url\": \"$UPDATE_URL\""
- fi
-
- if [ "$BROWSER" = "chromium" ]; then
- CHROMIUM_UPDATE_URL="$UPDATE_URL"
- else
- GECKO_APPLICATIONS="\n\
- \"applications\": {\n\
- \"gecko\": {\n\
- \"id\": \"{6fe13369-88e9-440f-b837-5012fb3bedec}\",\n\
- \"strict_min_version\": \"60.0\"$UPDATE_URL\n\
- }\n\
- },"
- fi
-
- sed "\
-s^_GECKO_APPLICATIONS_^$GECKO_APPLICATIONS^
-s^_CHROMIUM_UPDATE_URL_^$CHROMIUM_UPDATE_URL^
-s^_BGSCRIPTS_^$BGSCRIPTS^
-s^_CONTENTSCRIPTS_^$CONTENTSCRIPTS^" \
- < manifest.json > "$BUILDDIR"/manifest.json
-
- ./process_html_file.sh html/display-panel.html |
- sed "s^_POPUPSCRIPTS_^$POPUPSCRIPTS^" \
- > "$BUILDDIR"/html/display-panel.html
-
- ./process_html_file.sh html/options.html |
- sed "s^_OPTIONSSCRIPTS_^$OPTIONSSCRIPTS^" \
- > "$BUILDDIR"/html/options.html
-
- for FILE in $ALL_SCRIPTS_AVAILABLE; do
- FILEKEY=$(sanitize "$FILE")
- if [ "x$(map_get SCRIPTS_UNUSED $FILEKEY)" = "xyes" ]; then
- printf 'WARNING! %s not used\n' "$FILE" >&2
- else
- awk -f compute_scripts.awk wrapped_code "$FILE" > "$BUILDDIR"/$FILE
- fi
- done
-
- ./write_exports_init.sh "$BROWSER" "$BUILDDIR" default_settings.json
-
- cp -r copyright licenses/ "$BUILDDIR"
- cp dummy "$BUILDDIR"
- cp html/*.css "$BUILDDIR"/html
- mkdir "$BUILDDIR"/icons
- cp icons/*.png "$BUILDDIR"/icons
-
- if [ "$BROWSER" = "chromium" ]; then
- for MOZILLA_FILE in $(find "$BUILDDIR" -name "MOZILLA_*"); do
- printf '\n' > "$MOZILLA_FILE"
- done
- fi
- if [ "$BROWSER" = "mozilla" ]; then
- for CHROMIUM_FILE in $(find "$BUILDDIR" -name "CHROMIUM_*"); do
- printf '\n' > "$CHROMIUM_FILE"
- done
- fi
-}
-
print_usage() {
printf 'usage: %s mozilla|chromium [source directory] [update url]\n' \
"$0" >&2
}
+call_awk() {
+ local BROWSER_UPCASE="$(printf %s "$BROWSER" | tr '[:lower:]' '[:upper:]')"
+ nawk -f compute_scripts.awk -- -M manifest.json -D "$BROWSER_UPCASE" \
+ -D MV2 --output=files-to-copy --write-js-deps --write-html-deps \
+ --output-dir="$BUILDDIR"
+}
+
main() {
if [ "x$1" = "xmozilla" -o "x$1" = "xchromium" ]; then
BROWSER=$1
@@ -168,8 +49,22 @@ main() {
fi
UPDATE_URL="$3"
+ if [ -n "$3" ]; then
+ printf 'possibility of using an update url is currently unimplemented' \
+ >&2
+ exit 1
+ fi
+
+ FILES_TO_COPY="$(call_awk)"
+ for FILE in $FILES_TO_COPY; do
+ FILEDIR="$(printf %s "$FILE" | sed 's_[^/]*$_/_')"
+ if [ -n "$FILEDIR" -a ! -d "$BUILDDIR/$FILEDIR" ]; then
+ mkdir -p "$BUILDDIR/$FILEDIR"
+ fi
+ cp "$FILE" "$BUILDDIR/$FILE"
+ done
- build_main
+ cp -r README.md copyright licenses/ "$BUILDDIR"
}
main "$@"
diff --git a/common/ajax.js b/common/ajax.js
index d61faa6..4d0e630 100644
--- a/common/ajax.js
+++ b/common/ajax.js
@@ -67,8 +67,4 @@ function make_ajax_request(method, url)
initiate_ajax_request(resolve, reject, method, url));
}
-/*
- * EXPORTS_START
- * EXPORT make_ajax_request
- * EXPORTS_END
- */
+#EXPORT make_ajax_request
diff --git a/common/broadcast.js b/common/broadcast.js
index cc11a20..b69f352 100644
--- a/common/broadcast.js
+++ b/common/broadcast.js
@@ -41,11 +41,9 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT CONNECTION_TYPE
- * IMPORTS_END
- */
+#IMPORT common/connection_types.js AS CONNECTION_TYPE
+
+#FROM common/browser.js IMPORT browser
function sender_connection()
{
@@ -53,11 +51,13 @@ function sender_connection()
port: browser.runtime.connect({name: CONNECTION_TYPE.BROADCAST_SEND})
};
}
+#EXPORT sender_connection
function out(sender_conn, channel_name, value)
{
sender_conn.port.postMessage(["broadcast", channel_name, value]);
}
+#EXPORT out
/*
* prepare()'d message will be broadcasted if the connection is closed or when
@@ -77,16 +77,19 @@ function prepare(sender_conn, channel_name, value, timeout=5000)
{
sender_conn.port.postMessage(["prepare", channel_name, value, timeout]);
}
+#EXPORT prepare
function discard(sender_conn)
{
sender_conn.port.postMessage(["discard"]);
}
+#EXPORT discard
function flush(sender_conn)
{
sender_conn.port.postMessage(["flush"]);
}
+#EXPORT flush
function listener_connection(cb)
{
@@ -98,30 +101,22 @@ function listener_connection(cb)
return conn;
}
+#EXPORT listener_connection
function subscribe(listener_conn, channel_name)
{
listener_conn.port.postMessage(["subscribe", channel_name]);
}
+#EXPORT subscribe
function unsubscribe(listener_conn, channel_name)
{
listener_conn.port.postMessage(["unsubscribe", channel_name]);
}
+#EXPORT unsubscribe
function close(conn)
{
conn.port.disconnect();
}
-
-const broadcast = {
- sender_connection, out, prepare, discard, flush,
- listener_connection, subscribe, unsubscribe,
- close
-};
-
-/*
- * EXPORTS_START
- * EXPORT broadcast
- * EXPORTS_END
- */
+#EXPORT close
diff --git a/common/browser.js b/common/browser.js
new file mode 100644
index 0000000..4830774
--- /dev/null
+++ b/common/browser.js
@@ -0,0 +1,26 @@
+/**
+ * This file is part of Haketilo.
+ *
+ * Function: Export the browser API object.
+ *
+ * Copyright (C) 2021 Wojtek Kosior
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the CC0 1.0 Universal License as published by
+ * the Creative Commons Corporation.
+ *
+ * This program 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
+ * CC0 1.0 Universal License for more details.
+ */
+
+#IF MOZILLA
+
+#EXPORT globalThis.browser AS browser
+
+#ELIF CHROMIUM
+
+#EXPORT chrome AS browser
+
+#ENDIF
diff --git a/common/connection_types.js b/common/connection_types.js
index 9747e5c..0b83c2b 100644
--- a/common/connection_types.js
+++ b/common/connection_types.js
@@ -46,16 +46,8 @@
* to browser.runtime.connect()
*/
-const CONNECTION_TYPE = {
- REMOTE_STORAGE : "0",
- PAGE_ACTIONS : "1",
- ACTIVITY_INFO : "2",
- BROADCAST_SEND: "3",
- BROADCAST_LISTEN: "4"
-};
-
-/*
- * EXPORTS_START
- * EXPORT CONNECTION_TYPE
- * EXPORTS_END
- */
+#EXPORT "0" AS REMOTE_STORAGE
+#EXPORT "1" AS PAGE_ACTIONS
+#EXPORT "2" AS ACTIVITY_INFO
+#EXPORT "3" AS BROADCAST_SEND
+#EXPORT "4" AS BROADCAST_LISTEN
diff --git a/common/entities.js b/common/entities.js
index 3a1346a..29e130c 100644
--- a/common/entities.js
+++ b/common/entities.js
@@ -80,6 +80,7 @@ function get_newest_version(versioned_item)
const best_ver = max(Object.keys(versioned_item).map(parse_version));
return versioned_item[version_string(best_ver)];
}
+#EXPORT get_newest_version AS get_newest
/*
* item is a definition of a resource or mapping. Yield all file references
@@ -95,17 +96,9 @@ function* get_used_files(item)
yield file;
}
}
+#EXPORT get_used_files AS get_files
-const entities = {
- get_newest: get_newest_version,
- get_files: get_used_files
-};
-
-/*
- * EXPORTS_START
- * EXPORT entities
- * EXPORTS_END
- */
+#IF NEVER
/*
* Note: the functions below were overeagerly written and are not used now but
@@ -146,3 +139,5 @@ const version_reductor = (acc, n) => [...(n || acc.length ? [n] : []), ...acc];
* Returns a *new* array. Doesn't modify its argument.
*/
const normalize_version = ver => Array.reduceRight(ver, version_reductor, []);
+
+#ENDIF
diff --git a/common/indexeddb.js b/common/indexeddb.js
index 1741c91..c97c115 100644
--- a/common/indexeddb.js
+++ b/common/indexeddb.js
@@ -41,13 +41,12 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT initial_data
- * IMPORT entities
- * IMPORT broadcast
- * IMPORTS_END
- */
+#IMPORT common/entities.js
+#IMPORT common/broadcast.js
+
+let initial_data = (
+#INCLUDE_VERBATIM default_settings.json
+);
/* Update when changes are made to database schema. Must have 3 elements */
const db_version = [1, 0, 0];
@@ -79,6 +78,7 @@ async function idb_get(transaction, store_name, key)
const req = transaction.objectStore(store_name).get(key);
return (await wait_request(req)).target.result;
}
+#EXPORT idb_get
/* asynchronous wrapper for IDBObjectStore's put() method. */
async function idb_put(transaction, store_name, object)
@@ -132,6 +132,7 @@ async function get_db()
return db;
}
+#EXPORT get_db AS get
/* Helper function used by make_context(). */
function reject_discard(context)
@@ -177,10 +178,11 @@ function make_context(transaction, files)
*/
async function start_items_transaction(item_store_names, files)
{
- const db = await haketilodb.get();
+ const db = await get_db();
const scope = [...item_store_names, "files", "file_uses"];
return make_context(db.transaction(scope, "readwrite"), files);
}
+#EXPORT start_items_transaction
async function incr_file_uses(context, file_ref, by=1)
{
@@ -242,6 +244,7 @@ async function finalize_items_transaction(context)
return context.result;
}
+#EXPORT finalize_items_transaction
/*
* How a sample data argument to the function below might look like:
@@ -287,6 +290,7 @@ async function save_items(data)
return _save_items(data.resources, data.mappings, context);
}
+#EXPORT save_items
async function _save_items(resources, mappings, context)
{
@@ -322,6 +326,7 @@ async function save_item(item, context)
await _remove_item(store_name, item.identifier, context, false);
await idb_put(context.transaction, store_name, item);
}
+#EXPORT save_item
/* Helper function used by remove_item() and save_item(). */
async function _remove_item(store_name, identifier, context)
@@ -348,11 +353,16 @@ async function remove_item(store_name, identifier, context)
await idb_del(context.transaction, store_name, identifier);
}
+const remove_resource = (id, ctx) => remove_item("resources", id, ctx);
+#EXPORT remove_resource
+
+const remove_mapping = (id, ctx) => remove_item("mappings", id, ctx);
+#EXPORT remove_mapping
+
/* Callback used when listening to broadcasts while tracking db changes. */
async function track_change(tracking, identifier)
{
- const transaction =
- (await haketilodb.get()).transaction([tracking.store_name]);
+ const transaction = (await get_db()).transaction([tracking.store_name]);
const new_val = await idb_get(transaction, tracking.store_name, identifier);
tracking.onchange({identifier, new_val});
@@ -373,7 +383,7 @@ async function track_change(tracking, identifier)
* }
*
* Returns a [tracking, all_current_items] array where `tracking` is an object
- * that can be later passed to haketilodb.untrack() to stop tracking changes and
+ * that can be later passed to untrack() to stop tracking changes and
* `all_current_items` is an array of items currently present in the object
* store.
*
@@ -388,33 +398,18 @@ async function track(store_name, onchange)
broadcast.listener_connection(msg => track_change(tracking, msg[1]));
broadcast.subscribe(tracking.listener, `idb_changes_${store_name}`);
- const transaction = (await haketilodb.get()).transaction([store_name]);
+ const transaction = (await get_db()).transaction([store_name]);
const all_req = transaction.objectStore(store_name).getAll();
return [tracking, (await wait_request(all_req)).target.result];
}
-function untrack(tracking)
-{
- broadcast.close(tracking.listener);
-}
+const track_resources = onchange => track("resources", onchange);
+#EXPORT track_resources
-const haketilodb = {
- get: get_db,
- save_items,
- save_item,
- remove_resource: (id, ctx) => remove_item("resources", id, ctx),
- remove_mapping: (id, ctx) => remove_item("mappings", id, ctx),
- start_items_transaction,
- finalize_items_transaction,
- track_resources: onchange => track("resources", onchange),
- track_mappings: onchange => track("mappings", onchange),
- untrack
-};
+const track_mappings = onchange => track("mappings", onchange);
+#EXPORT track_mappings
+
+const untrack = tracking => broadcast.close(tracking.listener);
+#EXPORT untrack
-/*
- * EXPORTS_START
- * EXPORT haketilodb
- * EXPORT idb_get
- * EXPORTS_END
- */
diff --git a/common/lock.js b/common/lock.js
index d136469..56dad4f 100644
--- a/common/lock.js
+++ b/common/lock.js
@@ -55,9 +55,7 @@
* in a promise.
*/
-function make_lock() {
- return {free: true, queue: []};
-}
+#EXPORT () => ({free: true, queue: []}) AS make_lock
function _lock(lock, cb) {
if (lock.free) {
@@ -68,9 +66,7 @@ function _lock(lock, cb) {
}
}
-function lock(lock) {
- return new Promise((resolve, reject) => _lock(lock, resolve));
-}
+#EXPORT lock => new Promise(resolve => _lock(lock, resolve)) AS lock
function unlock(lock) {
if (lock.free)
@@ -84,11 +80,4 @@ function unlock(lock) {
setTimeout(cb);
}
}
-
-/*
- * EXPORTS_START
- * EXPORT make_lock
- * EXPORT lock
- * EXPORT unlock
- * EXPORTS_END
- */
+#EXPORT unlock
diff --git a/common/message_server.js b/common/message_server.js
index cd9a4d8..fd609c7 100644
--- a/common/message_server.js
+++ b/common/message_server.js
@@ -41,11 +41,7 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT browser
- * IMPORTS_END
- */
+#FROM common/browser.js IMPORT browser
var listeners = {};
@@ -66,8 +62,4 @@ function raw_listen(port)
browser.runtime.onConnect.addListener(raw_listen);
-/*
- * EXPORTS_START
- * EXPORT listen_for_connection
- * EXPORTS_END
- */
+#EXPORT listen_for_connection
diff --git a/common/misc.js b/common/misc.js
index 4d4b346..dc4a598 100644
--- a/common/misc.js
+++ b/common/misc.js
@@ -42,21 +42,8 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT browser
- * IMPORT TYPE_NAME
- * IMPORT TYPE_PREFIX
- * IMPORTS_END
- */
-
-/* Generate a random base64-encoded 128-bit sequence */
-function gen_nonce()
-{
- let randomData = new Uint8Array(16);
- crypto.getRandomValues(randomData);
- return btoa(String.fromCharCode.apply(null, randomData));
-}
+#FROM common/browser.js IMPORT browser
+#FROM common/stored_types.js IMPORT TYPE_NAME, TYPE_PREFIX
/*
* generating unique, per-site value that can be computed synchronously
@@ -78,6 +65,7 @@ function gen_nonce(length=16)
crypto.getRandomValues(randomData);
return Uint8toHex(randomData);
}
+#EXPORT gen_nonce
/* CSP rule that blocks scripts according to policy's needs. */
function make_csp_rule(policy)
@@ -88,19 +76,18 @@ function make_csp_rule(policy)
rule += ` script-src ${script_src}; script-src-elem ${script_src};`;
return rule;
}
+#EXPORT make_csp_rule
/* Check if some HTTP header might define CSP rules. */
const csp_header_regex =
/^\s*(content-security-policy|x-webkit-csp|x-content-security-policy)/i;
+#EXPORT csp_header_regex
/*
* Print item together with type, e.g.
* nice_name("s", "hello") → "hello (script)"
*/
-function nice_name(prefix, name)
-{
- return `${name} (${TYPE_NAME[prefix]})`;
-}
+#EXPORT (prefix, name) => `${name} (${TYPE_NAME[prefix]})` AS nice_name
/* Open settings tab with given item's editing already on. */
function open_in_settings(prefix, name)
@@ -109,6 +96,7 @@ function open_in_settings(prefix, name)
const url = browser.runtime.getURL("html/options.html#" + prefix + name);
window.open(url, "_blank");
}
+#EXPORT open_in_settings
/*
* Check if url corresponds to a browser's special page (or a directory index in
@@ -116,7 +104,7 @@ function open_in_settings(prefix, name)
*/
const privileged_reg =
/^(chrome(-extension)?|moz-extension):\/\/|^about:|^file:\/\/.*\/$/;
-const is_privileged_url = url => privileged_reg.test(url);
+#EXPORT url => privileged_reg.test(url) AS is_privileged_url
/* Parse a CSP header */
function parse_csp(csp) {
@@ -148,6 +136,7 @@ const matchers = {
nonempty_string_matcher
]
};
+#EXPORT matchers
/*
* Facilitates checking if there aren't any keys in object. This does *NOT*
@@ -159,16 +148,4 @@ function is_object_empty(object)
return false;
return true;
}
-
-/*
- * EXPORTS_START
- * EXPORT gen_nonce
- * EXPORT make_csp_rule
- * EXPORT csp_header_regex
- * EXPORT nice_name
- * EXPORT open_in_settings
- * EXPORT is_privileged_url
- * EXPORT matchers
- * EXPORT is_object_empty
- * EXPORTS_END
- */
+#EXPORT is_object_empty
diff --git a/common/observable.js b/common/observables.js
index 56d0ed6..f1db88c 100644
--- a/common/observable.js
+++ b/common/observables.js
@@ -41,13 +41,16 @@
* proprietary program, I am not going to enforce this in court.
*/
-const make = (value=undefined) => ({value, listeners: new Set()});
-const subscribe = (observable, cb) => observable.listeners.add(cb);
-const unsubscribe = (observable, cb) => observable.listeners.delete(cb);
+#EXPORT (value=undefined) => ({value, listeners: new Set()}) AS make
+#EXPORT (observable, cb) => observable.listeners.add(cb) AS subscribe
+#EXPORT (observable, cb) => observable.listeners.delete(cb) AS unsubscribe
const silent_set = (observable, value) => observable.value = value;
+#EXPORT silent_set
+
const broadcast = (observable, ...values) =>
observable.listeners.forEach(cb => cb(...values));
+#EXPORT broadcast
function set(observable, value)
{
@@ -55,11 +58,4 @@ function set(observable, value)
silent_set(observable, value);
broadcast(observable, value, old_value);
}
-
-const observables = {make, subscribe, unsubscribe, broadcast, silent_set, set};
-
-/*
- * EXPORTS_START
- * EXPORT observables
- * EXPORTS_END
- */
+#EXPORT set
diff --git a/common/once.js b/common/once.js
index 5a62b09..6e82528 100644
--- a/common/once.js
+++ b/common/once.js
@@ -71,8 +71,4 @@ function make_once(result_producer)
return () => get_result(state);
}
-/*
- * EXPORTS_START
- * EXPORT make_once
- * EXPORTS_END
- */
+#EXPORT make_once
diff --git a/common/patterns.js b/common/patterns.js
index 7d28dfe..0b1c3ad 100644
--- a/common/patterns.js
+++ b/common/patterns.js
@@ -72,9 +72,9 @@ function match_or_throw(regex, string, error_msg)
function deconstruct_url(url, use_limits=true)
{
- const max = MAX;
+ const max = Object.assign({}, MAX);
if (!use_limits) {
- for (key in MAX)
+ for (const key in MAX)
max[key] = Infinity;
}
@@ -129,6 +129,7 @@ function deconstruct_url(url, use_limits=true)
return deco;
}
+#EXPORT deconstruct_url
function* each_domain_pattern(deco)
{
@@ -183,10 +184,4 @@ function* each_url_pattern(url)
yield `${deco.proto}://${domain}${path}`;
}
}
-
-/*
- * EXPORTS_START
- * EXPORT each_url_pattern
- * EXPORT deconstruct_url
- * EXPORTS_END
- */
+#EXPORT each_url_pattern
diff --git a/common/patterns_query_tree.js b/common/patterns_query_tree.js
index 49205c5..1bbdb39 100644
--- a/common/patterns_query_tree.js
+++ b/common/patterns_query_tree.js
@@ -41,17 +41,16 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT deconstruct_url
- * IMPORTS_END
- */
+#FROM common/patterns.js IMPORT deconstruct_url
/* "Pattern Tree" is how we refer to the data structure used for querying
* Haketilo patterns. Those look like 'https://*.example.com/ab/***'. The goal
* is to make it possible for given URL to quickly retrieve all known patterns
* that match it.
*/
+const pattern_tree_make = () => ({})
+#EXPORT pattern_tree_make AS make
+
function empty_node() {
return {
wildcard_matches: [null, null, null],
@@ -134,8 +133,6 @@ function modify_sequence(tree_node, segments, item_modifier)
let removed = true;
for (var current_segment of segments) {
- wildcards = tree_node.wildcard_matches;
-
const child = tree_node.children[current_segment] || empty_node();
tree_node.children[current_segment] = child;
tree_node = child;
@@ -216,6 +213,7 @@ function pattern_tree_register(patterns_by_proto, pattern, item_name, item)
const add_item = obj => Object.assign(obj || {}, {[item_name]: item});
modify_tree(patterns_by_proto, pattern, add_item);
}
+#EXPORT pattern_tree_register AS register
/* Helper function for pattern_tree_deregister(). */
function _remove_item(obj, item_name)
@@ -240,6 +238,7 @@ function pattern_tree_deregister(patterns_by_proto, pattern, item_name)
const remove_item = obj => _remove_item(obj, item_name);
modify_tree(patterns_by_proto, pattern, remove_item);
}
+#EXPORT pattern_tree_deregister AS deregister
/*
* Yield registered items that match url. Each yielded value is an object with
@@ -281,16 +280,4 @@ function* pattern_tree_search(patterns_by_proto, url)
}
}
}
-
-const pattern_tree = {
- make: () => ({}),
- register: pattern_tree_register,
- deregister: pattern_tree_deregister,
- search: pattern_tree_search
-}
-
-/*
- * EXPORTS_START
- * EXPORT pattern_tree
- * EXPORTS_END
- */
+#EXPORT pattern_tree_search AS search
diff --git a/common/sanitize_JSON.js b/common/sanitize_JSON.js
index c775acb..58519b2 100644
--- a/common/sanitize_JSON.js
+++ b/common/sanitize_JSON.js