An Open Source CMS System in C++
The libtld is a library used to extract the TLD from a URI. This allows you to extract the exact domain name, sub-domains, and all the TLD (top level, second level, third level, etc.)
The problem with TLDs is that you cannot know where the domain starts. Some domains can use one top-level domain, others use two, etc. However, it may be useful to know where the domain is to have the exact list of sub-domains. For example, if you want to force www. at the start of the domain name if no other sub-domains are specified, then you need to know exactly how many TLD are defined in a URI.
The libtld offers one main function: tld(), which gives you a way to extract the TLD from any URI. The result is the offset where the TLD starts. This gives you enough information to extract everything else you need.
You can download the TLD Library from SourceForge.net.
The library offers:
The development environment required CMake to generate the Makefiles.
The XML parser makes use of C++ and Qt4.
The library itself does not have any requirements (other than a C or C++ compiler, obviously.) It comes with one header (tld.h).
The libtld has a small documentation since it includes only a very few functions. The documentation is available in the References section of this website.
The Mozilla Foundation keeps a list of top-level domain names as a text file including comments. The project is called Public Suffix List.
I'm thinking to add a test that uses that link to check the libtld against URLs generated using this list. That way we can easily find discrepancies. From a quick look, it seems more complete, but at the same time, it looks like it may include valid URLs.
The list is very specifically used to handle cookies and prevent users from assigning a cookie at the wrong level (i.e. you may assign snapwebsites.org as the domain of a cookie, but not just .org; see Supercookie in wikipedia.)
The idn library includes support for checking TLDs in a string. Their interface is 100% in C and it includes the possibility to have additional definitions (overrides) of the TLD data.
On an Ubuntu system you can install the development library with:
apt-get install libidn11-dev
At this time I did not test that library, however, I changed the name of the libtld library header from just tld.h to libtld/tld.h to avoid the header conflict (because libidn also called their TLD header tld.h).
You can find manual pages by looking up the existing functions in the /usr/include/tld.h from the libidn11-dev package and use man to find the corresponding pages. For example:
It feels like they offer a check of the characters of a domain as per each TLD defined rules.