1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[lookup] idna

This commit is contained in:
Witold Filipczyk 2021-04-28 16:10:59 +02:00
parent c45c98438f
commit 38d8d634f7

View File

@ -5,6 +5,7 @@
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
@ -15,6 +16,10 @@
#include <netdb.h>
#endif
#ifdef HAVE_IDNA_H
#include <idna.h>
#endif
/* We need to have it here. Stupid BSD. */
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
@ -153,17 +158,37 @@ lookup_cmd(struct option *o, char ***argv, int *argc)
{
struct sockaddr_storage *addrs = NULL;
int addrno, i;
char *idname, *idname2;
int allocated = 0;
if (!*argc) return gettext("Parameter expected");
if (*argc > 1) return gettext("Too many parameters");
(*argv)++; (*argc)--;
if (do_real_lookup(*(*argv - 1), &addrs, &addrno, 0) == DNS_ERROR) {
idname = *(*argv - 1);
#ifdef CONFIG_IDN
if (idname) {
int code = idna_to_ascii_lz(idname, &idname2, 0);
/* FIXME: Return NULL if it coughed? --jonas */
if (code == IDNA_SUCCESS) {
idname = idname2;
allocated = 1;
}
}
#endif
if (do_real_lookup(idname, &addrs, &addrno, 0) == DNS_ERROR) {
#ifdef HAVE_HERROR
herror(gettext("error"));
#else
usrerror(gettext("Host not found"));
#endif
if (allocated) {
free(idname2);
}
return "";
}
@ -192,6 +217,10 @@ lookup_cmd(struct option *o, char ***argv, int *argc)
fflush(stdout);
if (allocated) {
free(idname2);
}
return "";
}