mirror of
https://github.com/rfc1036/whois.git
synced 2026-05-03 06:51:09 +00:00
Implement support for libidn2
Contributed by Tim Rühsen. Closes #49 from Github.
This commit is contained in:
parent
cf61394ded
commit
8ed6d73095
5
Makefile
5
Makefile
@ -32,10 +32,15 @@ ifdef LOCALEDIR
|
|||||||
DEFS += -DLOCALEDIR=\"$(BASEDIR)$(prefix)/share/locale\"
|
DEFS += -DLOCALEDIR=\"$(BASEDIR)$(prefix)/share/locale\"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifdef HAVE_LIBIDN2
|
||||||
|
whois_LDADD += -lidn2
|
||||||
|
DEFS += -DHAVE_LIBIDN2
|
||||||
|
else
|
||||||
ifdef HAVE_LIBIDN
|
ifdef HAVE_LIBIDN
|
||||||
whois_LDADD += -lidn
|
whois_LDADD += -lidn
|
||||||
DEFS += -DHAVE_LIBIDN
|
DEFS += -DHAVE_LIBIDN
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ifdef HAVE_ICONV
|
ifdef HAVE_ICONV
|
||||||
whois_OBJECTS += simple_recode.o
|
whois_OBJECTS += simple_recode.o
|
||||||
|
|||||||
3
utils.h
3
utils.h
@ -49,6 +49,9 @@
|
|||||||
# define ngettext(a, b, c) ((c==1) ? (a) : (b))
|
# define ngettext(a, b, c) ((c==1) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined IDN2_VERSION_NUMBER && IDN2_VERSION_NUMBER < 0x00140000
|
||||||
|
# define IDN2_NONTRANSITIONAL IDN2_NFC_INPUT
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
void *do_nofail(void *ptr, const char *file, const int line);
|
void *do_nofail(void *ptr, const char *file, const int line);
|
||||||
|
|||||||
20
whois.c
20
whois.c
@ -31,7 +31,9 @@
|
|||||||
#ifdef HAVE_REGEXEC
|
#ifdef HAVE_REGEXEC
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBIDN
|
#ifdef HAVE_LIBIDN2
|
||||||
|
#include <idn2.h>
|
||||||
|
#elif defined HAVE_LIBIDN
|
||||||
#include <idna.h>
|
#include <idna.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_INET_PTON
|
#ifdef HAVE_INET_PTON
|
||||||
@ -654,7 +656,7 @@ char *queryformat(const char *server, const char *flags, const char *query)
|
|||||||
simple_recode_input_charset = "utf-8"; /* then try UTF-8 */
|
simple_recode_input_charset = "utf-8"; /* then try UTF-8 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBIDN
|
#if defined HAVE_LIBIDN || defined HAVE_LIBIDN2
|
||||||
# define DENIC_PARAM_ACE ",ace"
|
# define DENIC_PARAM_ACE ",ace"
|
||||||
#else
|
#else
|
||||||
# define DENIC_PARAM_ACE ""
|
# define DENIC_PARAM_ACE ""
|
||||||
@ -1144,7 +1146,7 @@ const char *is_new_gtld(const char *s)
|
|||||||
char *normalize_domain(const char *dom)
|
char *normalize_domain(const char *dom)
|
||||||
{
|
{
|
||||||
char *p, *ret;
|
char *p, *ret;
|
||||||
#ifdef HAVE_LIBIDN
|
#if defined HAVE_LIBIDN || defined HAVE_LIBIDN2
|
||||||
char *domain_start = NULL;
|
char *domain_start = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1159,7 +1161,7 @@ char *normalize_domain(const char *dom)
|
|||||||
p--;
|
p--;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBIDN
|
#if defined HAVE_LIBIDN || defined HAVE_LIBIDN2
|
||||||
/* find the start of the last word if there are spaces in the query */
|
/* find the start of the last word if there are spaces in the query */
|
||||||
for (p = ret; *p; p++)
|
for (p = ret; *p; p++)
|
||||||
if (*p == ' ')
|
if (*p == ' ')
|
||||||
@ -1169,8 +1171,13 @@ char *normalize_domain(const char *dom)
|
|||||||
char *q, *r;
|
char *q, *r;
|
||||||
int prefix_len;
|
int prefix_len;
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBIDN2
|
||||||
|
if (idn2_lookup_ul(domain_start, &q, IDN2_NONTRANSITIONAL) != IDN2_OK)
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
if (idna_to_ascii_lz(domain_start, &q, 0) != IDNA_SUCCESS)
|
if (idna_to_ascii_lz(domain_start, &q, 0) != IDNA_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* reassemble the original query in a new buffer */
|
/* reassemble the original query in a new buffer */
|
||||||
prefix_len = domain_start - ret;
|
prefix_len = domain_start - ret;
|
||||||
@ -1185,8 +1192,13 @@ char *normalize_domain(const char *dom)
|
|||||||
} else {
|
} else {
|
||||||
char *q;
|
char *q;
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBIDN2
|
||||||
|
if (idn2_lookup_ul(ret, &q, IDN2_NONTRANSITIONAL) != IDN2_OK)
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
if (idna_to_ascii_lz(ret, &q, 0) != IDNA_SUCCESS)
|
if (idna_to_ascii_lz(ret, &q, 0) != IDNA_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
|
#endif
|
||||||
|
|
||||||
free(ret);
|
free(ret);
|
||||||
return q;
|
return q;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user