NetSurf
Functions
idna.c File Reference

NetSurf international domain name handling implementation. More...

#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "netsurf/inttypes.h"
#include "utils/errors.h"
#include "utils/idna.h"
#include "utils/idna_props.h"
#include "utils/log.h"
#include "utils/punycode.h"
#include "utils/utf8.h"
#include "utils/utils.h"
Include dependency graph for idna.c:

Go to the source code of this file.

Functions

static nserror punycode_status_to_nserror (enum punycode_status status)
 Convert punycode status into nserror. More...
 
static nserror idna__ucs4_to_ace (int32_t *ucs4_label, size_t len, char **ace_label, size_t *out_len)
 Convert a host label in UCS-4 to an ACE version. More...
 
static nserror idna__ace_to_ucs4 (const char *ace_label, size_t ace_len, int32_t **ucs4_label, size_t *ucs4_len)
 Convert a host label in ACE format to UCS-4. More...
 
static nserror idna__utf8_to_ucs4 (const char *utf8_label, size_t len, int32_t **ucs4_label, size_t *ucs4_len)
 Convert a UTF-8 string to UCS-4. More...
 
static nserror idna__ucs4_to_utf8 (const int32_t *ucs4_label, size_t ucs4_len, char **utf8_label, size_t *utf8_len)
 Convert a UCS-4 string to UTF-8. More...
 
static bool idna__is_valid (int32_t *label, size_t len)
 Check if a host label is valid for IDNA2008. More...
 
static bool idna__verify (const char *label, size_t len)
 Verify an ACE label is valid. More...
 
static size_t idna__host_label_length (const char *host, size_t max_length)
 Find the length of a host label. More...
 
static bool idna__is_ldh (const char *label, size_t len)
 Check if a host label is LDH. More...
 
static bool idna__is_ace (const char *label, size_t len)
 Check if a host label appears to be ACE. More...
 
nserror idna_encode (const char *host, size_t len, char **ace_host, size_t *ace_len)
 Convert a hostname to an ACE version suitable for DNS lookup. More...
 
nserror idna_decode (const char *ace_host, size_t ace_len, char **host, size_t *host_len)
 Convert a hostname from ACE to UTF-8 suitable for display. More...
 

Detailed Description

NetSurf international domain name handling implementation.

Definition in file idna.c.

Function Documentation

◆ idna__ace_to_ucs4()

static nserror idna__ace_to_ucs4 ( const char *  ace_label,
size_t  ace_len,
int32_t **  ucs4_label,
size_t *  ucs4_len 
)
static

Convert a host label in ACE format to UCS-4.

Parameters
ace_labelASCII string containing host label
ace_lenLength of host label
ucs4_labelPointer to hold UCS4 decoded version
ucs4_lenPointer to hold length of ucs4_label
Returns
NSERROR_OK on success, appropriate error otherwise

If return value != NSERROR_OK, output will be left untouched.

Definition at line 134 of file idna.c.

References NSERROR_NOMEM, NSERROR_OK, punycode_decode(), and punycode_status_to_nserror().

Referenced by idna_decode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idna__host_label_length()

static size_t idna__host_label_length ( const char *  host,
size_t  max_length 
)
static

Find the length of a host label.

Parameters
hostString containing a host or FQDN
max_lengthLength of host string to search (in bytes)
Returns
Distance to next separator character or end of string

Definition at line 620 of file idna.c.

Referenced by idna_decode(), and idna_encode().

Here is the caller graph for this function:

◆ idna__is_ace()

static bool idna__is_ace ( const char *  label,
size_t  len 
)
static

Check if a host label appears to be ACE.

Parameters
labelHost label to check
lenLength of host label
Returns
true if ACE compliant, false otherwise

Definition at line 675 of file idna.c.

References idna__is_ldh().

Referenced by idna_decode(), and idna_encode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idna__is_ldh()

static bool idna__is_ldh ( const char *  label,
size_t  len 
)
static

Check if a host label is LDH.

Parameters
labelHost label to check
lenLength of host label
Returns
true if LDH compliant, false otherwise

Definition at line 644 of file idna.c.

Referenced by idna__is_ace(), and idna_encode().

Here is the caller graph for this function:

◆ idna__is_valid()

static bool idna__is_valid ( int32_t *  label,
size_t  len 
)
static

Check if a host label is valid for IDNA2008.

Parameters
labelHost label to check (UCS-4)
lenLength of host label (in characters/codepoints)
Returns
true if compliant, false otherwise

Definition at line 591 of file idna.c.

Referenced by idna_encode().

Here is the caller graph for this function:

◆ idna__ucs4_to_ace()

static nserror idna__ucs4_to_ace ( int32_t *  ucs4_label,
size_t  len,
char **  ace_label,
size_t *  out_len 
)
static

Convert a host label in UCS-4 to an ACE version.

Parameters
ucs4_labelUCS-4 NFC string containing host label
lenLength of host label (in characters/codepoints)
ace_labelASCII-compatible encoded version
out_lenLength of ace_label
Returns
NSERROR_OK on success, appropriate error otherwise

If return value != NSERROR_OK, output will be left untouched.

Definition at line 91 of file idna.c.

References NSERROR_OK, punycode_encode(), punycode_status_to_nserror(), and SLEN.

Referenced by idna_encode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ idna__ucs4_to_utf8()

static nserror idna__ucs4_to_utf8 ( const int32_t *  ucs4_label,
size_t  ucs4_len,
char **  utf8_label,
size_t *  utf8_len 
)
static

Convert a UCS-4 string to UTF-8.

Parameters
ucs4_labelUCS-4 string containing host label
ucs4_lenLength of host label (in bytes)
utf8_labelPointer to update with the output
utf8_lenPointer to update with the length
Returns
NSERROR_OK on success, appropriate error otherwise

If return value != NSERROR_OK, output will be left untouched.

Definition at line 575 of file idna.c.

References NSERROR_NOT_IMPLEMENTED.

Referenced by idna_decode().

Here is the caller graph for this function:

◆ idna__utf8_to_ucs4()

static nserror idna__utf8_to_ucs4 ( const char *  utf8_label,
size_t  len,
int32_t **  ucs4_label,
size_t *  ucs4_len 
)
static

Convert a UTF-8 string to UCS-4.

Parameters
utf8_labelUTF-8 string containing host label
lenLength of host label (in bytes)
ucs4_labelPointer to update with the output
ucs4_lenPointer to update with the length
Returns
NSERROR_OK on success, appropriate error otherwise

If return value != NSERROR_OK, output will be left untouched.

Definition at line 554 of file idna.c.

References NSERROR_NOT_IMPLEMENTED.

Referenced by idna_encode().

Here is the caller graph for this function:

◆ idna__verify()

static bool idna__verify ( const char *  label,
size_t  len 
)
static

Verify an ACE label is valid.

Parameters
labelHost label to check
lenLength of label
Returns
true if valid, false otherwise

Definition at line 604 of file idna.c.

Referenced by idna_encode().

Here is the caller graph for this function:

◆ idna_decode()

nserror idna_decode ( const char *  ace_host,
size_t  ace_len,
char **  host,
size_t *  host_len 
)

Convert a hostname from ACE to UTF-8 suitable for display.

Parameters
ace_hostString containing host
ace_lenLength of host string
hostPointer to update with the output
host_lenPointer to update with length of host
Returns
NSERROR_OK on success, appropriate error otherwise

If return value != NSERROR_OK, output will be left untouched.

Definition at line 773 of file idna.c.

References idna__ace_to_ucs4(), idna__host_label_length(), idna__is_ace(), idna__ucs4_to_utf8(), NSERROR_BAD_URL, and NSERROR_OK.

Here is the call graph for this function:

◆ idna_encode()

nserror idna_encode ( const char *  host,
size_t  len,
char **  ace_host,
size_t *  ace_len 
)

Convert a hostname to an ACE version suitable for DNS lookup.

Parameters
hostString containing host
lenLength of host string
ace_hostPointer to update with the output
ace_lenPointer to update with length of ace_host
Returns
NSERROR_OK on success, appropriate error otherwise

If return value != NSERROR_OK, output will be left untouched.

Definition at line 694 of file idna.c.

References idna__host_label_length(), idna__is_ace(), idna__is_ldh(), idna__is_valid(), idna__ucs4_to_ace(), idna__utf8_to_ucs4(), idna__verify(), NSERROR_BAD_URL, NSERROR_OK, and NSLOG.

Here is the call graph for this function:

◆ punycode_status_to_nserror()

static nserror punycode_status_to_nserror ( enum punycode_status  status)
static

Convert punycode status into nserror.

Parameters
statusThe punycode status to convert.
Returns
The corresponding nserror code for the status.

Definition at line 48 of file idna.c.

References NSERROR_BAD_ENCODING, NSERROR_BAD_SIZE, NSERROR_NOMEM, NSERROR_NOSPACE, NSERROR_OK, NSLOG, punycode_bad_input, punycode_big_output, punycode_overflow, and punycode_success.

Referenced by idna__ace_to_ucs4(), and idna__ucs4_to_ace().

Here is the caller graph for this function: