From 1affb5c169632b67e25e68017236d423d56d2c41 Mon Sep 17 00:00:00 2001 From: Tau Date: Wed, 4 Sep 2019 13:43:15 -0400 Subject: [PATCH] platform/dns.c: Add platform DNS hook --- platform/config.c | 45 ++++++++++++++++++++++++++++++++++ platform/config.h | 10 ++++++++ platform/dns.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ platform/dns.h | 8 +++++++ platform/meson.build | 2 ++ 5 files changed, 122 insertions(+) create mode 100644 platform/dns.c create mode 100644 platform/dns.h diff --git a/platform/config.c b/platform/config.c index 754e14e6..e722824d 100644 --- a/platform/config.c +++ b/platform/config.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "platform/config.h" @@ -16,6 +17,7 @@ void alls_config_load(struct alls_config *cfg, const wchar_t *filename) assert(filename != NULL); amvideo_config_load(&cfg->amvideo, filename); + dns_config_load(&cfg->dns, filename); hwmon_config_load(&cfg->hwmon, filename); misc_config_load(&cfg->misc, filename); pcbid_config_load(&cfg->pcbid, filename); @@ -29,6 +31,7 @@ void nu_config_load(struct nu_config *cfg, const wchar_t *filename) assert(filename != NULL); amvideo_config_load(&cfg->amvideo, filename); + dns_config_load(&cfg->dns, filename); hwmon_config_load(&cfg->hwmon, filename); misc_config_load(&cfg->misc, filename); nusec_config_load(&cfg->nusec, filename); @@ -43,6 +46,48 @@ void amvideo_config_load(struct amvideo_config *cfg, const wchar_t *filename) cfg->enable = GetPrivateProfileIntW(L"amvideo", L"enable", 1, filename); } +void dns_config_load(struct dns_config *cfg, const wchar_t *filename) +{ + wchar_t default_[128]; + + assert(cfg != NULL); + assert(filename != NULL); + + cfg->enable = GetPrivateProfileIntW(L"dns", L"enable", 1, filename); + + GetPrivateProfileStringW( + L"dns", + L"default", + L"localhost", + default_, + _countof(default_), + filename); + + GetPrivateProfileStringW( + L"dns", + L"startup", + default_, + cfg->startup, + _countof(cfg->startup), + filename); + + GetPrivateProfileStringW( + L"dns", + L"billing", + default_, + cfg->billing, + _countof(cfg->billing), + filename); + + GetPrivateProfileStringW( + L"dns", + L"aimedb", + default_, + cfg->aimedb, + _countof(cfg->aimedb), + filename); +} + void hwmon_config_load(struct hwmon_config *cfg, const wchar_t *filename) { assert(cfg != NULL); diff --git a/platform/config.h b/platform/config.h index fccc661e..37ae5558 100644 --- a/platform/config.h +++ b/platform/config.h @@ -10,6 +10,13 @@ struct amvideo_config { bool enable; }; +struct dns_config { + bool enable; + wchar_t startup[128]; + wchar_t billing[128]; + wchar_t aimedb[128]; +}; + struct hwmon_config { bool enable; }; @@ -43,6 +50,7 @@ struct vfs_config { struct nu_config { struct amvideo_config amvideo; + struct dns_config dns; struct hwmon_config hwmon; struct misc_config misc; struct nusec_config nusec; @@ -51,6 +59,7 @@ struct nu_config { struct alls_config { struct amvideo_config amvideo; + struct dns_config dns; struct hwmon_config hwmon; struct misc_config misc; struct pcbid_config pcbid; @@ -62,6 +71,7 @@ void alls_config_load(struct alls_config *cfg, const wchar_t *filename); void nu_config_load(struct nu_config *cfg, const wchar_t *filename); void amvideo_config_load(struct amvideo_config *cfg, const wchar_t *filename); +void dns_config_load(struct dns_config *cfg, const wchar_t *filename); void hwmon_config_load(struct hwmon_config *cfg, const wchar_t *filename); void misc_config_load(struct misc_config *cfg, const wchar_t *filename); void nusec_config_load(struct nusec_config *cfg, const wchar_t *filename); diff --git a/platform/dns.c b/platform/dns.c new file mode 100644 index 00000000..8a8ea46b --- /dev/null +++ b/platform/dns.c @@ -0,0 +1,57 @@ +#include + +#include + +#include "hooklib/dns.h" + +#include "platform/config.h" +#include "platform/dns.h" + +HRESULT dns_platform_hook_init(const struct dns_config *cfg) +{ + HRESULT hr; + + assert(cfg != NULL); + + if (!cfg->enable) { + return S_FALSE; + } + + hr = dns_hook_push(L"naominet.jp", cfg->startup); + + if (FAILED(hr)) { + return hr; + } + + hr = dns_hook_push(L"anbzvarg.wc", cfg->startup); + + if (FAILED(hr)) { + return hr; + } + + hr = dns_hook_push(L"ib.naominet.jp", cfg->billing); + + if (FAILED(hr)) { + return hr; + } + + hr = dns_hook_push(L"vo.anbzvarg.wc", cfg->billing); + + if (FAILED(hr)) { + return hr; + } + + hr = dns_hook_push(L"aime.naominet.jp", cfg->aimedb); + + if (FAILED(hr)) { + return hr; + } + + hr = dns_hook_push(L"nvzr.anbzvarg.wc", cfg->aimedb); + + if (FAILED(hr)) { + return hr; + } + + return S_OK; +} diff --git a/platform/dns.h b/platform/dns.h new file mode 100644 index 00000000..ab12edb5 --- /dev/null +++ b/platform/dns.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +#include "platform/config.h" + +HRESULT dns_platform_hook_init(const struct dns_config *cfg); + diff --git a/platform/meson.build b/platform/meson.build index dffa0120..67d0a6eb 100644 --- a/platform/meson.build +++ b/platform/meson.build @@ -11,6 +11,8 @@ platform_lib = static_library( 'amvideo.h', 'config.c', 'config.h', + 'dns.c', + 'dns.h', 'hwmon.c', 'hwmon.h', 'misc.c',