The libtld project is a dearly optimized C and C++ library used to verify a TLD (i.e. it can directly be used in your C or C++ projects). This is important if you want to verify an SSL certificate because invalid TLDs should always be ignored. If you are using PHP, there is an extension offered to run in PHP.
The library also supports verifying email addresses, which is notoriously difficult if you want to properly support all possible valid email addresses.
The newer version also includes a TLD compiler which lets you edit the list of TLDs and recompile them in a .tld file which the library can use on the fly (i.e. that means you can update the list of TLD without having to recompile the whole library to take the update in account).
The project can be found online at this URI:
https://snapwebsites.org/project/libtld
That page has some basic documentation and latest information about the library.
Packages are available on launchpad in the snapcpp PPA. You may want to consider using the packages directly instead of attempting to compile libtld yourself. It should save you a lot of time.
If the packages are not available for your version, check out the github source instead.
The library requirements are:
- cmake -- the tool to generate the Makefile (no auto-tool or configure!)
- doxygen -- currently required with the new cmake scheme
- dot (optional) -- recommanded if you want more complete documentations
- gcc & g++ -- to compile everything
- gcov & lcov -- to run coverage tests and generate HTML as output
- make -- to run the Makefile
- php5-dev -- if you want to create the PHP extension
The following are the basic steps once all the necessary requirements were installed on your system:
tar xf snapcmakemodules_x.y.z.tar.gz
tar xf libtld-x.y.z.tar.gz
mkdir BUILD
cd BUILD
cmake -DCMAKE_MODULE_PATH=../snapCMakeModules/Modules ../libtld
make
sudo make install
To install the package exactly where you would like it to be, you will want to make sure that the cmake tool is called with the correct installation prefix.
You may test a URI from the command line, once you installed everything
(or from your BUILD directory) using the validate_tld tool as in:
# Valid test:
validate_tld https://snapwebsites.org/project/libtld
# Invalid test:
validate_tld https://snapwebsites.organization/project/libtld
The library let you compile TLD .ini files in a .tld file. By default,
the library does so at compile time and installs a .tld file in
/usr/share/libtld/tlds.tld. However, the list of TLDs changes often
now that it is possible to add your own top level domain names such as
your brand (.google), a place (.berlin) or a generic name (.gay).
The default files are placed under /usr/share/libtld/tlds. You can add
your own .ini files under /var/lib/libtld/tlds where it will
automatically be picked up. Then the compiler command line is:
tldc --source /usr/share/libtld/tlds /var/lib/libtld/tlds.tld
You may have to (are likely to need to) use sudo as the tlds.tld
will likely be root by default. The ownership can always be changed.
Make sure to keep the file readable by all the users that may run a
tool using the libtld.
Fallback: The library still generates a tld_data.c file which
includes the tables from when the library was compiled. This is used
if the external tlds.tld file cannot be read.
Submit bug reports and patches on github.
This file is part of the snapcpp project.
vim: tw=4 sw=4 et syntax=markdown