Skip to content

Commit

Permalink
domain-set: support punycode.
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Dec 6, 2023
1 parent 11d92a6 commit 9554b3d
Show file tree
Hide file tree
Showing 7 changed files with 461 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

BIN=smartdns
OBJS_LIB=lib/rbtree.o lib/art.o lib/bitops.o lib/radix.o lib/timer_wheel.o
OBJS_MAIN=smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_conf.o dns_cache.o http_parse.o proxy.o timer.o lib/conf.o lib/nftset.o
OBJS_LIB=lib/rbtree.o lib/art.o lib/bitops.o lib/radix.o lib/timer_wheel.o lib/idna.o lib/conf.o lib/nftset.o
OBJS_MAIN=smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_conf.o dns_cache.o http_parse.o proxy.o timer.o
OBJS=$(OBJS_MAIN) $(OBJS_LIB)

# cflags
Expand Down
11 changes: 9 additions & 2 deletions src/dns_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "dns_conf.h"
#include "idna.h"
#include "list.h"
#include "rbtree.h"
#include "tlog.h"
Expand Down Expand Up @@ -308,8 +309,14 @@ static int _get_domain(char *value, char *domain, int max_domain_size, char **pt
goto errout;
}

memcpy(domain, begin, len);
domain[len] = '\0';
size_t domain_len = max_domain_size;
domain_len = utf8_to_punycode(begin, len, domain, domain_len);
if (domain_len <= 0) {
tlog(TLOG_ERROR, "domain name %s invalid", value);
goto errout;
}

domain[domain_len] = '\0';

if (ptr_after_domain) {
*ptr_after_domain = end + 1;
Expand Down
32 changes: 32 additions & 0 deletions src/include/idna.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*************************************************************************
*
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* smartdns is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _SMARTDNS_IDNA_H
#define _SMARTDNS_IDNA_H

#ifdef __cplusplus
extern "C" {
#endif

int utf8_to_punycode(const char *src, int src_len, char *dst, int dst_len);

#ifdef __cplusplus
}
#endif

#endif // !_SMARTDNS_IDNA_H
Loading

0 comments on commit 9554b3d

Please sign in to comment.