platform/dns.c: Add platform DNS hook

This commit is contained in:
Tau 2019-09-04 13:43:15 -04:00
parent 8ecbb860d8
commit 1affb5c169
5 changed files with 122 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);

View File

@ -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);

57
platform/dns.c Normal file
View File

@ -0,0 +1,57 @@
#include <windows.h>
#include <assert.h>
#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;
}

8
platform/dns.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <windows.h>
#include "platform/config.h"
HRESULT dns_platform_hook_init(const struct dns_config *cfg);

View File

@ -11,6 +11,8 @@ platform_lib = static_library(
'amvideo.h',
'config.c',
'config.h',
'dns.c',
'dns.h',
'hwmon.c',
'hwmon.h',
'misc.c',