1
0
Fork 0
mirror of https://github.com/rockdaboot/libpsl.git synced 2025-12-05 22:37:13 +00:00
C library for the Public Suffix List
Find a file
2025-11-21 09:40:30 +01:00
.github Fix CI for meson on MacOS (#255) 2025-11-10 20:14:39 +01:00
contrib Add build/test script for static MinGW library 2024-03-23 19:28:24 +01:00
docs/libpsl meson: build and install the libpsl.3 manpage 2023-12-24 20:48:59 -05:00
fuzz Update copyright 2024-01-13 19:15:51 +01:00
include Update copyright 2024-01-13 19:15:51 +01:00
list@64ba165cf3 Update PSL list 2025-11-15 18:29:57 +01:00
m4 Add configure flag --with-libunistring-prefix 2024-03-25 18:26:48 +01:00
msvc fix syntax error of config-msvc.mak.in 2024-04-28 17:17:11 +02:00
po autoconf first version 2014-03-20 22:43:04 +01:00
src Allow building from tarball without Python (#257) 2025-11-21 09:40:30 +01:00
tests Allow building from tarball without Python (#257) 2025-11-21 09:40:30 +01:00
tools Get rid of Windows WSA startup code 2024-03-23 19:28:24 +01:00
.dir-locals.el document indentation conventions for emacs users 2014-03-21 14:39:17 -04:00
.gitignore Rename suffixes_dafsa.c to suffixes_dafsa.h 2018-12-06 09:11:02 -05:00
.gitmodules Add https://github.com/publicsuffix as git submodule 2015-07-14 13:25:42 +02:00
.lgtm.yml Add .lgtm.yml 2018-10-15 17:29:23 +02:00
AUTHORS Release V0.21.0 2019-04-16 15:10:17 +02:00
autogen.sh Let autogen.sh work on Solaris and without gtkdocize 2016-01-02 13:01:19 +01:00
configure.ac Allow building from tarball without Python (#257) 2025-11-21 09:40:30 +01:00
COPYING Update copyright 2024-01-13 19:15:51 +01:00
libpsl.pc.in Add Libs.private to autoconf libpsl.pc 2024-05-09 18:50:15 +02:00
libtool_version_info.txt Release v0.21.3 2024-01-13 19:15:51 +01:00
LICENSE Update copyright 2024-01-13 19:15:51 +01:00
Makefile.am Include meson build files into tarball 2019-04-17 12:05:00 +02:00
meson.build Unconditionally use psl_strdup instead of strdup 2024-03-23 19:28:24 +01:00
meson_options.txt add 'tests' option to disable tests and fuzzers 2023-01-22 22:41:42 -05:00
NEWS Release v0.21.5 2024-01-13 22:44:01 +01:00
README inital commit 2014-03-20 17:17:24 +01:00
README.md Drop OpenCSW badges (#258) 2025-11-21 09:36:45 +01:00
README.MSVC.md NMake builds: Include Visual Studio version in output dir 2019-10-30 18:07:19 +08:00
version.txt Release v0.21.5 2024-01-13 22:44:01 +01:00

Coverity Scan Coverage Status CodeQL

libpsl - C library to handle the Public Suffix List

A Public Suffix List is a collection of Top Level Domains (TLDs) suffixes. TLDs include Global Top Level Domains (gTLDs) like .com and .net; Country Top Level Domains (ccTLDs) like .de and .cn; and Brand Top Level Domains like .apple and .google. Brand TLDs allows users to register their own top level domain that exist at the same level as ICANN's gTLDs. Brand TLDs are sometimes referred to as Vanity Domains.

Browsers, web clients and other user agents can use a public suffix list to:

  • avoid privacy-leaking "supercookies"
  • avoid privacy-leaking "super domain" certificates (see post from Jeffry Walton)
  • domain highlighting parts of the domain in a user interface
  • sorting domain lists by site

Libpsl...

  • has built-in PSL data for fast access (DAWG/DAFSA reduces size from ~300kB to ~50kB)
  • allows to load PSL data from files
  • checks if a given domain is a "public suffix"
  • provides immediate cookie domain verification
  • finds the longest public part of a given domain
  • finds the shortest private part of a given domain
  • works with international domains (UTF-8 and IDNA2008 Punycode)
  • is thread-safe
  • handles IDNA2008 UTS#46 (if either libidn2 or libicu is available)

Find more information about the Public Suffix List here.

Download the Public Suffix List here.

The original DAFSA code is from the Chromium Project.

API Documentation

You find the current API documentation here.

Quick API example

#include <stdio.h>
#include <libpsl.h>

int main(int argc, char **argv)
{
	const char *domain = "www.example.com";
	const char *cookie_domain = ".com";
	const psl_ctx_t *psl = psl_builtin();
	int is_public, is_acceptable;

	is_public = psl_is_public_suffix(psl, domain);
	printf("%s %s a public suffix.\n", domain, is_public ? "is" : "is not");

	is_acceptable = psl_is_cookie_domain_acceptable(psl, domain, cookie_domain);
	printf("cookie domain '%s' %s acceptable for domain '%s'.\n",
		cookie_domain, is_acceptable ? "is" : "is not", domain);

	return 0;
}

Command Line Tool

Libpsl comes with a tool 'psl' that gives you access to most of the library API via command line.

$ psl --help

prints the usage.

Convert PSL into DAFSA

The DAFSA format is a compressed representation of strings. Here we use it to reduce the whole PSL to about 32k in size.

Generate psl.dafsa from list/public_suffix_list.dat

$ src/psl-make-dafsa --output-format=binary list/public_suffix_list.dat psl.dafsa

Test the result (example)

$ tools/psl --load-psl-file psl.dafsa aeroclub.aero

License

Libpsl is made available under the terms of the MIT license.
See the LICENSE file that accompanies this distribution for the full text of the license.

src/psl-make-dafsa and src/lookup_string_in_fixed_set.c are licensed under the term written in src/LICENSE.chromium.

Building from tarball

Choose a release from https://github.com/rockdaboot/libpsl/tags an download the tarball named libpsl-{version}.tar.*. Unpack with tar xf <filename>, cd into the libsl* directory.

Build with

./configure
make
make check

Install with

sudo make install

Building from git

Download project with

	git clone --recursive https://github.com/rockdaboot/libpsl
	cd libpsl

Building with GNU autotools

Prerequisites:

  • python2.7+ (for converting the PSL list)

  • basic C development tools (compiler, linker, make)

  • autoconf, autoconf-archive, autopoint, automake, autotools

  • libtool, gettext, pkg-config

  • development files for either libidn2, libicu or libidn (the latter only offers IDNA2003)

  • for building docs: gtk-doc-tools (gtkdocize)

    ./autogen.sh
    ./configure
    make
    make check
    

Building with meson

	meson builddir
	ninja -C builddir
	ninja -C builddir test

There is also an unofficial MSVC nmake build configuration in msvc/. Please see README.MSVC.md on building libpsl with Visual Studio via NMake or Meson.

Mailing List

Mailing List Archive

Mailing List

To join the mailing list send an email to

libpsl-bugs+subscribe@googlegroups.com

and follow the instructions provided by the answer mail.

Or click join.