@@ -1,5 +1,5 @@
/* tr46map.c - header file for IDNA2008 TR46
Copyright (C) 2016-2017 Tim Rühsen
Copyright (C) 2016-2017 Tim Ruehsen
Libidn2 is free software: you can redistribute it and/or modify it
under the terms of either:
@@ -26,7 +26,11 @@
not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIBIDN2_TR46MAP_H
#define LIBIDN2_TR46MAP_H

#include <stdint.h>
#include "idn2.h"

#define TR46_FLG_VALID 1
#define TR46_FLG_MAPPED 2
@@ -51,8 +55,14 @@ typedef struct
char check; /* 0=NO 2=MAYBE (YES if codepoint has no table entry) */
} NFCQCMap;

int get_idna_map (uint32_t c, IDNAMap * map);
int get_map_data (uint32_t * dst, const IDNAMap * map);
int map_is (const IDNAMap * map, unsigned flags);
int
get_idna_map (uint32_t c, IDNAMap * map);
int
get_map_data (uint32_t * dst, const IDNAMap * map);
int G_GNUC_IDN2_ATTRIBUTE_PURE
map_is (const IDNAMap * map, unsigned flags);

G_GNUC_IDN2_ATTRIBUTE_PURE NFCQCMap
*get_nfcqc_map (uint32_t c);

NFCQCMap *get_nfcqc_map (uint32_t c);
#endif /* LIBIDN2_TR46MAP_H */
@@ -822,7 +822,7 @@ static const struct idna idna[] = {
{"_443._tcp.example.com", "443.tcp.example.com", IDN2_OK, IDN2_USE_STD3_ASCII_RULES|IDN2_NONTRANSITIONAL},
{"_443._tcp.example.com", "443.tcp.example.com", IDN2_OK, IDN2_USE_STD3_ASCII_RULES|IDN2_TRANSITIONAL},
{"_443._tcp.example.com", "_443._tcp.example.com", IDN2_OK, IDN2_USE_STD3_ASCII_RULES|IDN2_NO_TR46}, /* flag is ignored when not using TR46 */
/* _��� */
/* _??? */
{"_\xc3\xbc", "xn--_-eha", IDN2_DISALLOWED, IDN2_NO_TR46},
{"_\xc3\xbc", "xn--_-eha", IDN2_OK, IDN2_TRANSITIONAL},
{"_\xc3\xbc", "xn--_-eha", IDN2_OK, IDN2_NONTRANSITIONAL},
@@ -839,12 +839,12 @@ static const struct idna idna[] = {
static int ok = 0, failed = 0;
static int break_on_error = 0;

static char *_nextField(char **line)
static const char *_nextField(char **line)
{
char *s = *line, *e;

if (!*s)
return NULL;
return "";

if (!(e = strpbrk(s, ";#"))) {
e = *line += strlen(s);
@@ -899,7 +899,6 @@ test_homebrewed(void)
{
uint32_t dummy_u32[4] = { 'a', 'b', 'c', 0 };
uint8_t *out;
char outbuf[4];
size_t i;
int rc;

@@ -1033,17 +1032,18 @@ test_homebrewed(void)
ok++;
}

if ((rc = idna_to_ascii_4i (dummy_u32, 4, outbuf, 0)) != IDN2_OK) {
if ((rc = idn2_to_ascii_4i2 (dummy_u32, 4, (char **) &out, 0)) != IDN2_OK) {
failed++;
printf("special #9 failed with %d\n", rc);
} else {
idn2_free (out);
ok++;
}
}

// decode embedded UTF-16/32 sequences
static char *
_decodeIdnaTest(uint8_t *src_u8)
static uint8_t *
_decodeIdnaTest(const uint8_t *src_u8)
{
size_t it2 = 0, len;
uint32_t *src;
@@ -1088,19 +1088,16 @@ _decodeIdnaTest(uint8_t *src_u8)
}

// convert UTF-32 to UTF-8
uint8_t *tmp=src_u8;
src_u8 = u32_to_u8(src, it2, NULL, &len);
free(src);
if (!src_u8) {
printf("u32_to_u8(%s) failed (%d)\n", tmp, errno);
return NULL;
}
uint8_t *dst_u8 = u32_to_u8(src, it2, NULL, &len);
if (!dst_u8)
printf("u32_to_u8(%s) failed (%d)\n", src_u8, errno);

return (char *) src_u8;
free(src);
return dst_u8;
}

static void
_check_toASCII(char *source, char *expected, int transitional, int expected_toASCII_failure)
_check_toASCII(const char *source, const char *expected, int transitional, int expected_toASCII_failure)
{
int rc;
char *ace = NULL;
@@ -1133,18 +1130,19 @@ _check_toASCII(char *source, char *expected, int transitional, int expected_toAS
static int
test_IdnaTest(char *linep)
{
char *type, *source, *toUnicode, *toASCII, *NV8, *org_source;
char *source;
const char *type, *toUnicode, *toASCII, *NV8, *org_source;
int expected_toASCII_failure;

type = _nextField(&linep);
org_source = source = _nextField(&linep);
org_source = _nextField(&linep);
toUnicode = _nextField(&linep);
toASCII = _nextField(&linep);
NV8 = _nextField(&linep); // if set, the input should be disallowed for IDNA2008

// sigh, these Unicode people really mix UTF-8 and UCS-2/4
// quick and dirty translation of '\uXXXX' found in IdnaTest.txt including surrogate handling
source = _decodeIdnaTest((uint8_t *) source);
source = (char *) _decodeIdnaTest((uint8_t *) org_source);
if (!source)
return 0; // some Unicode sequences can't be encoded into UTF-8, skip them

@@ -19,7 +19,7 @@

#include <idn2.h>

int
int G_GNUC_IDN2_ATTRIBUTE_CONST
main (void)
{
int i, failed = 0;
@@ -383,7 +383,7 @@ ucs4print (const uint32_t * str, size_t len)
printf ("\n");
}

static size_t
static size_t G_GNUC_IDN2_ATTRIBUTE_PURE
_u32_strlen(const uint32_t *s)
{
const uint32_t *e;
@@ -394,7 +394,7 @@ _u32_strlen(const uint32_t *s)
return e - s;
}

static size_t
static size_t G_GNUC_IDN2_ATTRIBUTE_PURE
_u32_strcmp(const uint32_t *s1, const uint32_t *s2)
{
while (*s1 && *s2 && *s1 == *s2)