NetSurf
|
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"
Go to the source code of this file.
Macros | |
#define | FQDN_MAX 256 |
#define | NO_ACTION (void)0 |
#define | FQDN_APPEND(s, len, action) |
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... | |
NetSurf international domain name handling implementation.
Definition in file idna.c.
#define FQDN_APPEND | ( | s, | |
len, | |||
action | |||
) |
|
static |
Convert a host label in ACE format to UCS-4.
ace_label | ASCII string containing host label |
ace_len | Length of host label |
ucs4_label | Pointer to hold UCS4 decoded version |
ucs4_len | Pointer to hold length of ucs4_label |
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().
|
static |
Find the length of a host label.
host | String containing a host or FQDN |
max_length | Length of host string to search (in bytes) |
Definition at line 620 of file idna.c.
Referenced by idna_decode(), and idna_encode().
|
static |
Check if a host label appears to be ACE.
label | Host label to check |
len | Length of host label |
Definition at line 675 of file idna.c.
References idna__is_ldh().
Referenced by idna_decode(), and idna_encode().
|
static |
Check if a host label is LDH.
label | Host label to check |
len | Length of host label |
Definition at line 644 of file idna.c.
Referenced by idna__is_ace(), and idna_encode().
|
static |
Check if a host label is valid for IDNA2008.
label | Host label to check (UCS-4) |
len | Length of host label (in characters/codepoints) |
Definition at line 591 of file idna.c.
Referenced by idna_encode().
|
static |
Convert a host label in UCS-4 to an ACE version.
ucs4_label | UCS-4 NFC string containing host label |
len | Length of host label (in characters/codepoints) |
ace_label | ASCII-compatible encoded version |
out_len | Length of ace_label |
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().
|
static |
Convert a UCS-4 string to UTF-8.
ucs4_label | UCS-4 string containing host label |
ucs4_len | Length of host label (in bytes) |
utf8_label | Pointer to update with the output |
utf8_len | Pointer to update with the length |
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().
|
static |
Convert a UTF-8 string to UCS-4.
utf8_label | UTF-8 string containing host label |
len | Length of host label (in bytes) |
ucs4_label | Pointer to update with the output |
ucs4_len | Pointer to update with the length |
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().
|
static |
Verify an ACE label is valid.
label | Host label to check |
len | Length of label |
Definition at line 604 of file idna.c.
Referenced by idna_encode().
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.
ace_host | String containing host |
ace_len | Length of host string |
host | Pointer to update with the output |
host_len | Pointer to update with length of host |
If return value != NSERROR_OK, output will be left untouched.
Definition at line 785 of file idna.c.
References FQDN_APPEND, FQDN_MAX, idna__ace_to_ucs4(), idna__host_label_length(), idna__is_ace(), idna__ucs4_to_utf8(), NO_ACTION, NSERROR_BAD_URL, and NSERROR_OK.
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.
host | String containing host |
len | Length of host string |
ace_host | Pointer to update with the output |
ace_len | Pointer to update with length of ace_host |
If return value != NSERROR_OK, output will be left untouched.
Definition at line 713 of file idna.c.
References FQDN_APPEND, FQDN_MAX, idna__host_label_length(), idna__is_ace(), idna__is_ldh(), idna__is_valid(), idna__ucs4_to_ace(), idna__utf8_to_ucs4(), idna__verify(), NO_ACTION, NSERROR_BAD_URL, NSERROR_OK, and NSLOG.
|
static |
Convert punycode status into nserror.
status | The punycode status to convert. |
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().