Added getdns_convert_ulabel_to_alabel and getdns_convert_alabel_to_ulabel; introduced dependency on libidn11

This commit is contained in:
Melinda Shore 2013-11-25 17:40:38 -08:00
parent 3e0411f8f8
commit 4065396935
3 changed files with 50 additions and 5 deletions

View File

@ -29,6 +29,8 @@ found_all_libs=1
AC_MSG_NOTICE([Checking for dependencies libevent, ldns])
AC_CHECK_LIB([event_core], [event_base_new], [], [found_all_libs=0])
AC_CHECK_LIB([ldns], [ldns_dname_new_frm_str], [], [found_all_libs=0])
AC_CHECK_LIB([idn], [idna_to_ascii_8z], [], [found_all_libs=0])
if test $found_all_libs == 0
then
AC_MSG_ERROR([One more dependencies is missing])

View File

@ -16,7 +16,7 @@ VPATH = @srcdir@
CC=gcc
CFLAGS=@CFLAGS@ -Wall -g -fPIC -I$(srcdir)/ -I/usr/local/include -std=c99
LDFLAGS=@LDFLAGS@ -levent_core -lldns -lunbound
LDFLAGS=@LDFLAGS@ -levent_core -lldns -lunbound -lidn
# PROGRAMS=example-simple-answers example-tree example-all-functions example-synchronous
.SUFFIXES: .c .o .a .lo .h

View File

@ -33,6 +33,9 @@
#include <stdio.h>
#include <arpa/inet.h>
#include <util-internal.h>
#include <locale.h>
#include <stringprep.h>
#include <idna.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
@ -51,20 +54,60 @@ getdns_convert_fqdn_to_dns_name(char *fqdn_as_string)
return NULL;
}
/*---------------------------------------- getdns_convert_alabel_to_ulabel */
/**
* Convert UTF-8 string into an ACE-encoded domain
* It is the application programmer's responsibility to free()
* the returned buffer after use
*
* @param ulabel the UTF-8-encoded domain name to convert
* @return pointer to ACE-encoded string
* @return NULL if conversion fails
*/
char *
getdns_convert_ulabel_to_alabel(char *ulabel)
{
UNUSED_PARAM(ulabel);
return NULL;
int ret;
char *buf;
char *prepped;
setlocale(LC_ALL, "");
if ((prepped = stringprep_locale_to_utf8(ulabel)) == 0)
return 0;
if ((ret = stringprep(prepped, BUFSIZ, 0, stringprep_nameprep)) != STRINGPREP_OK)
return 0;
if ((ret = idna_to_ascii_8z(prepped, &buf, 0)) != IDNA_SUCCESS) {
return 0;
}
return buf;
}
/*---------------------------------------- getdns_convert_alabel_to_ulabel */
/**
* Convert ACE-encoded domain name into a UTF-8 string.
* It is the application programmer's responsibility to free()
* the returned buffer after use
*
* @param alabel the ACE-encoded domain name to convert
* @return pointer to UTF-8 string
* @return NULL if conversion fails
*/
char *
getdns_convert_alabel_to_ulabel(char *alabel)
{
UNUSED_PARAM(alabel);
return NULL;
int ret; /* just in case we might want to use it someday */
char *buf;
if ((ret = idna_to_unicode_8z8z(alabel, &buf, 0)) != IDNA_SUCCESS) {
return NULL;
}
return buf;
}
char *
getdns_display_ip_address(struct getdns_bindata
*bindata_of_ipv4_or_ipv6_address)