Skip to content

Commit 5d18b70

Browse files
committed
whois
1 parent a14e5f2 commit 5d18b70

15 files changed

Lines changed: 1272 additions & 278 deletions

File tree

CMakeLists-implied-options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ if (LWS_WITH_SELFDNS)
130130
set(LWS_WITH_SYS_ASYNC_DNS 1)
131131
set(LWS_WITH_SYS_ASYNC_DNS_DNSSEC 1)
132132
set(LWS_WITH_AUTH_SERVER 1)
133+
set(LWS_WITH_SYS_WHOIS 1)
133134
endif()
134135

135136
if (LWS_WITH_AUTH_SERVER)

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ option(LWS_WITH_SYS_ASYNC_DNS "Nonblocking internal IPv4 + IPv6 DNS resolver" OF
179179
option(LWS_WITH_SYS_ASYNC_DNS_DNSSEC "Include DNSSEC parsing/validation in async-dns (requires crypto)" OFF)
180180
option(LWS_WITH_AUTHORITATIVE_DNS "Authoritative DNS zone signer / server" OFF)
181181
option(LWS_WITH_SYS_NTPCLIENT "Build in tiny ntpclient good for tls date validation and run via lws_system" OFF)
182+
option(LWS_WITH_SYS_WHOIS "Build in tiny recursive whois client run via lws_system" OFF)
182183
option(LWS_WITH_SYS_DHCP_CLIENT "Build in tiny DHCP client" OFF)
183184
option(LWS_WITH_HTTP_BASIC_AUTH "Support Basic Auth" ON)
184185
option(LWS_WITH_HTTP_DIGEST_AUTH "Support Digest Auth (caution deprecated crypto)" ON)

cmake/lws_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
#cmakedefine LWS_WITH_SYS_FAULT_INJECTION
258258
#cmakedefine LWS_WITH_SYS_METRICS
259259
#cmakedefine LWS_WITH_SYS_NTPCLIENT
260+
#cmakedefine LWS_WITH_SYS_WHOIS
260261
#cmakedefine LWS_WITH_LATENCY
261262
#cmakedefine LWS_WITH_UPNG
262263
#cmakedefine LWS_WITH_SYS_STATE

include/libwebsockets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ lws_fx_string(const lws_fx_t *a, char *buf, size_t size);
823823

824824
#include <libwebsockets/lws-ota.h>
825825
#include <libwebsockets/lws-system.h>
826+
#include <libwebsockets/lws-whois.h>
826827
#include <libwebsockets/lws-callbacks.h>
827828

828829
#if defined(LWS_WITH_NETWORK)

include/libwebsockets/lws-misc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,17 @@ LWS_VISIBLE LWS_EXTERN void
798798
lws_cmdline_option_handle_builtin(int argc, const char **argv,
799799
struct lws_context_creation_info *info);
800800

801+
/**
802+
* lws_parse_iso8601() - parse ISO8601 date string into unixtime
803+
*
804+
* \param ads: the date string to parse
805+
*
806+
* Returns the unixtime represented by the string, or 0 if parsing failed.
807+
* Supports YYYY-MM-DDTHH:MM:SSZ and some common simple variations.
808+
*/
809+
LWS_VISIBLE LWS_EXTERN lws_usec_t
810+
lws_parse_iso8601(const char *ads);
811+
801812
/**
802813
* lws_now_secs(): return seconds since 1970-1-1
803814
*/

include/libwebsockets/lws-whois.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* libwebsockets - small server side websockets and web server implementation
3+
*
4+
* Copyright (C) 2010 - 2026 Andy Green <andy@warmcat.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to
8+
* deal in the Software without restriction, including without limitation the
9+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
* sell copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22+
* IN THE SOFTWARE.
23+
*/
24+
25+
/** \defgroup whois WHOIS Client
26+
* ##WHOIS Client APIs
27+
*/
28+
///@{
29+
30+
struct lws_whois_results {
31+
lws_usec_t creation_date;
32+
lws_usec_t expiry_date;
33+
lws_usec_t updated_date;
34+
char nameservers[256];
35+
char dnssec[64];
36+
char ds_data[512];
37+
};
38+
39+
typedef void (*lws_whois_cb_t)(void *opaque, const struct lws_whois_results *res);
40+
41+
struct lws_whois_args {
42+
struct lws_context *context;
43+
/**< The lws context to run the query in */
44+
const char *domain;
45+
/**< The domain name to query */
46+
const char *server;
47+
/**< Optional: The WHOIS server to query directly. If NULL, recursive
48+
* lookup starting from whois.iana.org is performed. */
49+
lws_whois_cb_t cb;
50+
/**< Callback to receive results. Called once when query completes or fails. */
51+
void *opaque;
52+
/**< User-supplied pointer passed to the callback */
53+
};
54+
55+
/**
56+
* lws_whois_query() - Trigger a WHOIS query for a domain
57+
*
58+
* \param args: struct containing query parameters
59+
*
60+
* Returns 0 if the query was successfully initiated, or nonzero if failed.
61+
* The results are delivered asynchronously via the callback in args.
62+
*/
63+
#if defined(LWS_WITH_SYS_WHOIS)
64+
LWS_VISIBLE LWS_EXTERN int
65+
lws_whois_query(const struct lws_whois_args *args);
66+
#else
67+
#define lws_whois_query(_a) (1)
68+
#endif
69+
70+
///@}

lib/core/context.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,9 @@ lws_create_context(const struct lws_context_creation_info *info)
14331433
#if defined(LWS_WITH_SYS_DHCP_CLIENT)
14341434
extern const struct lws_protocols lws_system_protocol_dhcpc4;
14351435
#endif
1436+
#if defined(LWS_WITH_SYS_WHOIS)
1437+
extern const struct lws_protocols lws_system_protocol_whois;
1438+
#endif
14361439
#if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL) && !defined(LWS_PLAT_ANDROID) && defined(LWS_WITH_NETWORK)
14371440
extern const struct lws_protocols lws_system_protocol_stdin;
14381441
#endif
@@ -1453,6 +1456,9 @@ lws_create_context(const struct lws_context_creation_info *info)
14531456
#if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL) && !defined(LWS_PLAT_ANDROID) && defined(LWS_WITH_NETWORK)
14541457
pp[n++] = &lws_system_protocol_stdin;
14551458
#endif
1459+
#if defined(LWS_WITH_SYS_WHOIS)
1460+
pp[n++] = &lws_system_protocol_whois;
1461+
#endif
14561462
#if defined(LWS_WITH_DIR)
14571463
pp[n++] = &protocol_lws_dir_notify;
14581464
#endif

lib/core/libwebsockets.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,3 +2277,33 @@ lws_fx_string(const lws_fx_t *a, char *buf, size_t size)
22772277

22782278
return buf;
22792279
}
2280+
2281+
lws_usec_t
2282+
lws_parse_iso8601(const char *ads)
2283+
{
2284+
struct tm tm;
2285+
const char *p = ads;
2286+
2287+
if (!ads)
2288+
return 0;
2289+
2290+
memset(&tm, 0, sizeof(tm));
2291+
2292+
/* ISO8601 / WHOIS dates: YYYY-MM-DDTHH:MM:SSZ and variants */
2293+
if (sscanf(p, "%d-%d-%dT%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
2294+
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 3) {
2295+
/* Try with space instead of T */
2296+
if (sscanf(p, "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
2297+
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 3)
2298+
return 0;
2299+
}
2300+
2301+
tm.tm_year -= 1900;
2302+
tm.tm_mon -= 1;
2303+
2304+
#if defined(LWS_HAVE_TIMEGM)
2305+
return (lws_usec_t)timegm(&tm);
2306+
#else
2307+
return (lws_usec_t)mktime(&tm); /* flawed but better than nothing */
2308+
#endif
2309+
}

lib/system/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ if (LWS_WITH_NETWORK)
6464
list(APPEND SOURCES
6565
system/ntpclient/ntpclient.c)
6666
endif()
67+
68+
if (LWS_WITH_SYS_WHOIS)
69+
list(APPEND SOURCES
70+
system/whois/whois.c)
71+
endif()
6772

6873
if (LWS_WITH_SYS_DHCP_CLIENT)
6974
list(APPEND SOURCES

lib/system/policy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ policy_cb(struct lejp_ctx *ctx, char reason)
7272

7373
static const char *default_policy =
7474
"{\n"
75-
" \"dns_base_dir\": \"/etc/dnssec\",\n"
75+
" \"dns_base_dir\": \"/var/dnssec\",\n"
7676
" \"seeds\": [ \"selfdns.org\", \"uk1.selfdns.org\", \"asia1.selfdns.org\" ]\n"
7777
"}\n";
7878

0 commit comments

Comments
 (0)