| Title: | Public Suffix List Engine |
|---|---|
| Description: | A focused implementation of the Public Suffix List (PSL). Bundles a reproducible, pinned PSL snapshot and implements the official prevailing-rule algorithm to answer public-suffix (eTLD) and registrable-domain (eTLD+1) queries. Distinguishes ICANN and PRIVATE rule sections, accepts Unicode and ASCII hostnames via 'punycoder' canonicalization, and supports an explicit, validated offline refresh path. The matcher is compiled with 'cpp11' and requires no external system library. Used as the PSL engine by the 'rurl' package. |
| Authors: | Bart Turczynski [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-8788-7980>) |
| Maintainer: | Bart Turczynski <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.2.2.9000 |
| Built: | 2026-11-18 15:55:26 UTC |
| Source: | https://gitlab.com/bart-turczynski/pslr |
TRUE exactly when the valid canonical host equals its own public suffix
under the selected policy. Returns NA whenever public_suffix() would
return NA (missing or invalid input, or an unresolved host under
unknown = "na"). Under the default unknown = "default", an unlisted
single label such as "madeuptld" is TRUE via the implicit * rule; ask
unknown = "na" to test explicit membership instead.
is_public_suffix( domain, section = "all", unknown = "default", invalid = "na", engine = psl_default_engine() )is_public_suffix( domain, section = "all", unknown = "default", invalid = "na", engine = psl_default_engine() )
domain |
Character vector of DNS hostnames (not URLs). Each element may be a mixed-case ASCII, Unicode, or A-label hostname, a single label, or a hostname with exactly one terminal root dot. See Input contract. |
section |
Which rule sections are eligible: |
unknown |
|
invalid |
|
engine |
The |
A logical vector with length(domain), preserving the names of
domain.
NA is treated as missing (returns NA), not invalid. Invalid elements
include empty or whitespace-only strings, leading or consecutive dots, URL
syntax, IPv6 addresses, canonical dotted-decimal IPv4 literals, and labels
that fail hostname/IDNA validation. Wrong argument types and non-scalar or
unknown option values always abort regardless of invalid.
is_public_suffix("com") is_public_suffix("example.com") is_public_suffix("madeuptld") is_public_suffix("madeuptld", unknown = "na")is_public_suffix("com") is_public_suffix("example.com") is_public_suffix("madeuptld") is_public_suffix("madeuptld", unknown = "na")
Reclaims cached snapshots that nothing points at any more. The call is explicit, strictly offline, and destructive by design: it deletes snapshot files. It never changes which list is active, and every reference that could still be followed survives it.
psl_cache_prune(keep = 1L)psl_cache_prune(keep = 1L)
keep |
Number of unreferenced snapshots to retain in addition to
every referenced one, as a single non-negative whole number. The default
|
A snapshot is protected, and therefore never removed, when it is any of:
the selected cache snapshot, the one psl_use() resolves with
source = "cache";
named by any source's stored state, across every source this cache knows, not only the official endpoint;
active in the calling R session; or
among the keep most recently first-retrieved snapshots that none of the
above already protects.
Retention is ordered by when a snapshot's bytes were first retrieved, as recorded in its descriptor when it was published, rather than by file modification time. A copy, a restore from backup, or any tool that rewrites timestamps changes mtime but not the fact of when the bytes were received, so first retrieval is the only stable order for history.
Pruning runs under the cache's publication lock and removes only complete
.dat/.rds snapshot pairs, so it can never leave a reference pointing at
bytes that are gone. Snapshot state pslr cannot fully read is treated as a
reference it cannot see: if any source or selection stream is damaged,
nothing is collected at all, and the damage is left visible rather than
quietly erased. psl_cache_prune() is an explicit mutator, so it also
performs the one-time migration of a pre-v2 cache before pruning; it never
deletes legacy files, and it never reads or writes the reminder preference,
which is configuration and lives outside the cache.
One honest limitation: pruning cannot discover engines held by other R processes, which already hold their parsed rules in memory. It therefore guarantees persistent referential integrity – no stored reference is ever left dangling – and not continued on-disk availability for another process's detached engine descriptor.
This is distinct from psl_cache_clear(), which only flushes this session's
in-memory match-result cache and deletes nothing from disk.
Invisibly, a data.frame with one row per removed snapshot and the
columns checksum (character, the "sha256:<hex>" identity),
bytes_path and descriptor_path (character paths removed, NA when
that half was already absent), and bytes_reclaimed (numeric). The frame
has zero rows when nothing was pruned, including when there is no cache at
all. A prune that removes only part of what it selected signals an error
of class pslr_prune_partial_error whose result field is this same
frame, describing what was removed before the failure.
psl_snapshots(), which lists what a prune would consider;
psl_refresh(), which publishes the snapshots this reclaims; psl_use().
# Deleting cached snapshots is never a side effect of running an example: if (interactive()) { psl_cache_prune() # keep referenced snapshots plus one more psl_cache_prune(keep = 0) # keep only referenced snapshots }# Deleting cached snapshots is never a side effect of running an example: if (interactive()) { psl_cache_prune() # keep referenced snapshots plus one more psl_cache_prune(keep = 0) # keep only referenced snapshots }
Reports which rules were added, removed, or changed between two Public Suffix List snapshots that are already available locally. The comparison is canonical rather than textual: both sides are parsed and canonicalized first, so comments, blank lines, whitespace, letter case, source ordering, and raw Unicode spelling are never reported as changes.
psl_diff(old, new, ...)psl_diff(old, new, ...)
old, new
|
The two snapshots to compare. Each accepts, independently, one
of: |
... |
These dots are for future extension and must be empty. |
The call is strictly offline. No input form triggers a request, and neither
side changes the session-global list that psl_use() controls, so diffing
the cache leaves the next query answering from exactly the list it did
before.
A base data.frame with one row per changed logical identity,
ordered by that identity, and columns, in order: change ("added",
"removed", or "changed"), rule (the logical identity), old_rule and
new_rule (canonical rule text including any *. or ! marker),
old_kind and new_kind ("normal", "wildcard", or "exception"), and
old_section and new_section ("icann" or "private"). Every field
belonging to a side the identity is absent from is NA. Two snapshots that
agree return the same columns and types with zero rows.
Provenance is attached as the attributes old_version and new_version,
each a one-row psl_version() frame describing that side's snapshot, or
NULL when the input was a rule table and therefore carries no provenance.
The upstream endpoint publishes only the current list, and the list itself
asks callers not to depend on version-control URLs, so psl_diff() resolves
no dates and downloads no history. Installing the package performs no
request and provides only the bundled snapshot; local collection begins at
the first explicit psl_refresh(), after which each distinct validated
download is retained as an immutable file until psl_cache_prune() collects
it. psl_snapshots() lists what is resolvable, with a path for each set of
stored bytes; any of those paths, or any historical revision the caller
materializes as a file by other means, can be passed here directly.
A rule's logical identity is its canonical labels with the leading *. or
! marker removed, so *.example.com and example.com are the same
identity in two different states. change is:
addedThe identity exists only in new.
removedThe identity exists only in old.
changedThe identity exists in both, but its canonical rule kind or its ICANN/PRIVATE section differs.
Identities that exist in both snapshots in the same state are not reported.
Section membership is a compared attribute rather than part of the identity,
so a rule moving between the ICANN and PRIVATE sections is one changed row
rather than an unrelated removed/added pair. A list may legally carry the
same labels once in each section; such rules collapse into the single row for
their identity, with the values of that side joined in ICANN-then-PRIVATE
order.
psl_snapshots(), psl_refresh(), psl_rules(), psl_version()
# Two small lists on disk, written offline. write_list <- function(private) { path <- tempfile(fileext = ".dat") writeLines( c( "// ===BEGIN ICANN DOMAINS===", "com", "// ===END ICANN DOMAINS===", "// ===BEGIN PRIVATE DOMAINS===", private, "// ===END PRIVATE DOMAINS===" ), path ) path } old <- write_list(c("a.example.com", "*.b.example.com")) new <- write_list(c("b.example.com", "c.example.com")) # One row each: a.example.com removed, b.example.com changed kind, # c.example.com added. psl_diff(old, new) # Agreeing snapshots return the same columns with zero rows. psl_diff("bundled", "bundled") # Provenance travels with the result when the input form carries it. attr(psl_diff("bundled", old), "old_version")$checksum# Two small lists on disk, written offline. write_list <- function(private) { path <- tempfile(fileext = ".dat") writeLines( c( "// ===BEGIN ICANN DOMAINS===", "com", "// ===END ICANN DOMAINS===", "// ===BEGIN PRIVATE DOMAINS===", private, "// ===END PRIVATE DOMAINS===" ), path ) path } old <- write_list(c("a.example.com", "*.b.example.com")) new <- write_list(c("b.example.com", "c.example.com")) # One row each: a.example.com removed, b.example.com changed kind, # c.example.com added. psl_diff(old, new) # Agreeing snapshots return the same columns with zero rows. psl_diff("bundled", "bundled") # Provenance travels with the result when the input form carries it. attr(psl_diff("bundled", old), "old_version")$checksum
Revalidates the Public Suffix List against its source and publishes any changed bytes into the user cache. This is the only function in the package that accesses the network, and only when you call it explicitly.
psl_refresh( url = "https://publicsuffix.org/list/public_suffix_list.dat", ..., activate = FALSE, force = FALSE )psl_refresh( url = "https://publicsuffix.org/list/public_suffix_list.dat", ..., activate = FALSE, force = FALSE )
url |
Absolute |
... |
These dots are for future extensions and must be empty. They also
make |
activate |
When |
force |
When |
A refresh has exactly four successful outcomes:
skipped_recentlyNo request: the last successful check is still inside its courtesy window (at least 24 hours).
not_modifiedOne conditional request answered 304; the local
bytes were verified and remain current.
downloaded_unchangedOne 200 whose validated bytes hash to the
snapshot already held, so no new snapshot is created.
updatedOne 200 whose validated bytes are a new snapshot.
Downloaded bytes are fully validated – size ceiling, UTF-8, official section markers, rule grammar, and canonicalization of every rule – before anything references them, and exact same-section duplicates warn once and are deduplicated. Publication is append-only: snapshot bytes and their descriptor are written before any reference to them, so an interrupted refresh never exposes a dangling reference. Refreshes of one source are serialized across processes; a second concurrent refresh of the same source makes no request and signals a busy error. A failed refresh records only a coarse attempt and leaves the cache, the selected snapshot, and the active matcher untouched.
Invisibly, a psl_refresh_result with stable fields outcome,
request_url, effective_url, http_status, checked_at,
previous_checksum, checksum, activated, validator,
bytes_downloaded, and snapshot. Operational failures signal a classed
error rooted at pslr_refresh_error instead.
if (interactive()) { psl_refresh() psl_refresh(force = TRUE, activate = TRUE) }if (interactive()) { psl_refresh() psl_refresh(force = TRUE, activate = TRUE) }
Returns the explicit rules of the active list as a base data.frame, one row
per rule. The implicit default * rule is not included.
psl_rules(section = "all")psl_rules(section = "all")
section |
Which rule sections to return: |
A base data.frame with columns, in order: rule (original source
rule text), canonical_rule (the canonicalized rule, including the *. or
! marker), kind ("normal", "wildcard", or "exception"), section
("icann" or "private"), and labels (integer rule depth, counting a
wildcard label). Rows are ordered first by section (ICANN before PRIVATE)
and then by source-file order.
psl_version(), public_suffix_rule(), psl_diff()
head(psl_rules("icann")) nrow(psl_rules("private"))head(psl_rules("icann")) nrow(psl_rules("private"))
Switches the list backing every query in the current R session. The change is session-only and is validated before any session state changes; a failure leaves the previously active list usable. A successful switch invalidates the match-result cache.
psl_use(source = "bundled", path = NULL)psl_use(source = "bundled", path = NULL)
source |
Where to load the list from: |
path |
For |
A custom path is held to the same runtime duplicate policy as
psl_refresh(): exact same-section duplicates warn once and are
deduplicated, while conflicting rule kinds for the same labels are fatal.
Cache and custom-path sources are read in source form and indexed under the
runtime normalizer; they never reuse the bundled generated index.
Invisibly, the psl_version() row for the newly active list.
psl_refresh(), psl_version(), psl_rules()
psl_use("bundled") if (interactive()) { psl_use("cache") psl_use("path", path = "my_list.dat") }psl_use("bundled") if (interactive()) { psl_use("cache") psl_use("path", path = "my_list.dat") }
Returns a one-row data.frame describing the list currently active in this R session: its source-snapshot provenance and the normalization identifiers actually used to index the active matcher. Reproducing a query result requires both the active-list identity and these normalization identifiers (PRD s10), so a reproducibility-sensitive workflow should record this row.
psl_version()psl_version()
The columns, in order, are:
source"bundled", "cache", or "path".
urlSource URL of the active snapshot: the upstream download URL
for the bundled list; NA for a "cache" or "path" source.
pathFile path of a "cache" or "path" source; NA otherwise.
retrieved_atNetwork retrieval timestamp, or NA.
list_dateUpstream list date, or NA when unknown.
commitUpstream commit SHA, or NA when unknown.
sizeSource byte size (integer).
checksumSource checksum, including its algorithm prefix
(e.g. "sha256:...").
normalizerThe dependency providing canonicalization,
currently "punycoder".
normalizer_versionIts installed package version.
normalization_profileIts stable case-mapping / IDNA / validation profile identifier.
unicode_versionThe Unicode data version used by that profile.
Unavailable metadata is a typed NA, never omitted. The normalization
identifiers describe the implementation used by the current session, whether
the active list came from the bundled snapshot, the user cache, or a custom
path; an in-memory compatibility rebuild (PRD s8.3) updates them without
altering the shipped source identity or checksum.
A one-row base data.frame with the columns described in Details.
psl_use(), psl_refresh(), psl_rules()
psl_version()psl_version()
Returns the public suffix (effective top-level domain, eTLD) of each host under the selected Public Suffix List policy, following the official prevailing-rule algorithm.
public_suffix( domain, section = "all", output = "ascii", unknown = "default", invalid = "na", engine = psl_default_engine() )public_suffix( domain, section = "all", output = "ascii", unknown = "default", invalid = "na", engine = psl_default_engine() )
domain |
Character vector of DNS hostnames (not URLs). Each element may be a mixed-case ASCII, Unicode, or A-label hostname, a single label, or a hostname with exactly one terminal root dot. See Input contract. |
section |
Which rule sections are eligible: |
output |
|
unknown |
|
invalid |
|
engine |
The |
A character vector with length(domain), preserving the names of
domain. Other attributes are dropped.
NA is treated as missing (returns NA), not invalid. Invalid elements
include empty or whitespace-only strings, leading or consecutive dots, URL
syntax, IPv6 addresses, canonical dotted-decimal IPv4 literals, and labels
that fail hostname/IDNA validation. Wrong argument types and non-scalar or
unknown option values always abort regardless of invalid.
registrable_domain(), is_public_suffix(), suffix_extract(),
public_suffix_rule()
public_suffix("www.example.com") public_suffix("example.co.uk") public_suffix("example.com.") public_suffix("madeuptld", unknown = "na")public_suffix("www.example.com") public_suffix("example.co.uk") public_suffix("example.com.") public_suffix("madeuptld", unknown = "na")
Inspect the prevailing PSL rule for each host
public_suffix_rule( domain, section = "all", unknown = "default", invalid = "na", engine = psl_default_engine() )public_suffix_rule( domain, section = "all", unknown = "default", invalid = "na", engine = psl_default_engine() )
domain |
Character vector of DNS hostnames (not URLs). Each element may be a mixed-case ASCII, Unicode, or A-label hostname, a single label, or a hostname with exactly one terminal root dot. See Input contract. |
section |
Which rule sections are eligible: |
unknown |
|
invalid |
|
engine |
The |
A base data.frame with one row per input and columns, in order:
input (original), host_ascii (canonical A-label host), rule (the
canonical rule including *. or !, "*" for the implicit default),
kind ("normal", "wildcard", "exception", or "default"),
rule_section ("icann", "private", or NA for the default/no result),
and public_suffix_ascii (the derived A-label public suffix). Invalid rows
are NA in every derived column. A valid host left unresolved by
unknown = "na" keeps host_ascii while the rule and suffix columns are
NA. An exception rule retains its ! for auditability. Zero-length
input returns a zero-row frame; all-invalid input keeps one row per input.
NA is treated as missing (returns NA), not invalid. Invalid elements
include empty or whitespace-only strings, leading or consecutive dots, URL
syntax, IPv6 addresses, canonical dotted-decimal IPv4 literals, and labels
that fail hostname/IDNA validation. Wrong argument types and non-scalar or
unknown option values always abort regardless of invalid.
public_suffix(), suffix_extract()
public_suffix_rule("www.example.co.uk") public_suffix_rule("madeuptld")public_suffix_rule("www.example.co.uk") public_suffix_rule("madeuptld")
Returns the registrable domain (eTLD+1) of each host: its public suffix plus
one host label to the left. It is NA when no such label exists (the host is
itself a public suffix) or when the public suffix is NA.
registrable_domain( domain, section = "all", output = "ascii", unknown = "default", invalid = "na", engine = psl_default_engine() )registrable_domain( domain, section = "all", output = "ascii", unknown = "default", invalid = "na", engine = psl_default_engine() )
domain |
Character vector of DNS hostnames (not URLs). Each element may be a mixed-case ASCII, Unicode, or A-label hostname, a single label, or a hostname with exactly one terminal root dot. See Input contract. |
section |
Which rule sections are eligible: |
output |
|
unknown |
|
invalid |
|
engine |
The |
A character vector with length(domain), preserving the names of
domain. Other attributes are dropped.
NA is treated as missing (returns NA), not invalid. Invalid elements
include empty or whitespace-only strings, leading or consecutive dots, URL
syntax, IPv6 addresses, canonical dotted-decimal IPv4 literals, and labels
that fail hostname/IDNA validation. Wrong argument types and non-scalar or
unknown option values always abort regardless of invalid.
public_suffix(), is_public_suffix(), suffix_extract()
registrable_domain("www.example.co.uk") registrable_domain("com") registrable_domain("foo.madeuptld", unknown = "na")registrable_domain("www.example.co.uk") registrable_domain("com") registrable_domain("foo.madeuptld", unknown = "na")
Split hosts into subdomain, registrant label, and public suffix
suffix_extract( domain, section = "all", output = "ascii", unknown = "default", invalid = "na", engine = psl_default_engine() )suffix_extract( domain, section = "all", output = "ascii", unknown = "default", invalid = "na", engine = psl_default_engine() )
domain |
Character vector of DNS hostnames (not URLs). Each element may be a mixed-case ASCII, Unicode, or A-label hostname, a single label, or a hostname with exactly one terminal root dot. See Input contract. |
section |
Which rule sections are eligible: |
output |
|
unknown |
|
invalid |
|
engine |
The |
A base data.frame with one row per input and columns, in order:
input (original, unchanged), host (canonical host in output form),
subdomain (labels left of the registrable domain; "" when none),
domain (the single registrant label left of the suffix), suffix (the
public suffix), and registrable_domain (eTLD+1). domain, subdomain,
and registrable_domain are NA when the host is itself a public suffix.
If public-suffix resolution is NA, every derived column except input
and a successfully normalized host is NA. Zero-length input returns a
zero-row frame; all-invalid input keeps one row per input. Root dots are
preserved on host, suffix, and registrable_domain only.
NA is treated as missing (returns NA), not invalid. Invalid elements
include empty or whitespace-only strings, leading or consecutive dots, URL
syntax, IPv6 addresses, canonical dotted-decimal IPv4 literals, and labels
that fail hostname/IDNA validation. Wrong argument types and non-scalar or
unknown option values always abort regardless of invalid.
public_suffix(), public_suffix_rule()
suffix_extract("www.example.co.uk") suffix_extract(c("example.com", "com", NA))suffix_extract("www.example.co.uk") suffix_extract(c("example.com", "com", NA))