## SoupTLD

SoupTLD — Top-Level Domain Utilities

## Functions

const char * | soup_tld_get_base_domain ()
gboolean | soup_tld_domain_is_public_suffix ()

## Types and Values

#define | SOUP_TLD_ERROR
enum | SoupTLDError

## Includes

    #include <libsoup/soup.h>

## Description

These functions can be used to parse hostnames to attempt to determine what part of the name belongs to the domain owner, and what part is simply a "public suffix" such as ".com".

## Functions

### soup_tld_get_base_domain ()

    const char *
    soup_tld_get_base_domain (const char *hostname,
                              GError **error);

Finds the base domain for a given `hostname` . The base domain is composed by the top level domain (such as .org, .com, .co.uk, etc) plus the second level domain, for example for myhost.mydomain.com it will return mydomain.com.

Note that `NULL` will be returned for private URLs (those not ending with any well known TLD) because choosing a base domain for them would be totally arbitrary.

Prior to libsoup 2.46, this function required that `hostname` be in UTF-8 if it was an IDN. From 2.46 on, the name can be in either UTF-8 or ASCII format (and the return value will be in the same format).

#### Parameters

hostname | a hostname |
error | return location for a GError, or `NULL` to ignore errors. See SoupTLDError for the available error codes |

#### Returns

a pointer to the start of the base domain in `hostname` . If an error occurs, `NULL` will be returned and `error` set.

### soup_tld_domain_is_public_suffix ()

    gboolean
    soup_tld_domain_is_public_suffix (const char *domain);

Looks whether the `domain` passed as argument is a public domain suffix (.org, .com, .co.uk, etc) or not.

Prior to libsoup 2.46, this function required that `domain` be in UTF-8 if it was an IDN. From 2.46 on, the name can be in either UTF-8 or ASCII format.

#### Parameters

domain | a domain name |

#### Returns

`TRUE` if it is a public domain, `FALSE` otherwise.

## Types and Values

### SOUP_TLD_ERROR

    #define SOUP_TLD_ERROR soup_tld_error_quark()

The GError domain for soup-tld-related errors.

### enum SoupTLDError

Error codes for `SOUP_TLD_ERROR`.

#### Members

SOUP_TLD_ERROR_INVALID_HOSTNAME | A hostname was syntactically invalid. |
SOUP_TLD_ERROR_IS_IP_ADDRESS | The passed-in "hostname" was actually an IP address (and thus has no base domain or public suffix). |
SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS | The passed-in hostname did not have enough components. Eg, calling `soup_tld_get_base_domain()` on `"co.uk"`. |
SOUP_TLD_ERROR_NO_BASE_DOMAIN | The passed-in hostname has no recognized public suffix. |
SOUP_TLD_ERROR_NO_PSL_DATA | The Public Suffix List was not available. |