added qse_httpd_dns_server_t and qse_httpd_urs_server_t.

deleted qse_httpd_natr_t.
deleted QSE_HTTPD_DNSNOA and QSE_HTTPD_DNSNOAAAA
added QSE_HTTPD_DNS_SERVER_A and QSE_HTTPD_DNS_SERVER_AAAA
This commit is contained in:
hyung-hwan 2014-09-11 09:02:07 +00:00
parent 3fd82c7943
commit 97c528ca1f
7 changed files with 88 additions and 45 deletions

View File

@ -195,7 +195,7 @@ struct loccfg_t
qse_nwad_t urs_nwad; /* TODO: multiple urs */ qse_nwad_t urs_nwad; /* TODO: multiple urs */
int dns_timeout; int dns_timeout;
int dns_retries; int dns_retries;
int dns_query_type; int dns_queries;
int urs_timeout; int urs_timeout;
int urs_retries; int urs_retries;
qse_httpd_mod_t* urs_prerewrite_mod; qse_httpd_mod_t* urs_prerewrite_mod;
@ -565,6 +565,7 @@ proxy_ok:
root->u.proxy.dns_server.nwad = loccfg->proxy.dns_nwad; root->u.proxy.dns_server.nwad = loccfg->proxy.dns_nwad;
root->u.proxy.dns_server.tmout.sec = loccfg->proxy.dns_timeout; root->u.proxy.dns_server.tmout.sec = loccfg->proxy.dns_timeout;
root->u.proxy.dns_server.retries = loccfg->proxy.dns_retries; root->u.proxy.dns_server.retries = loccfg->proxy.dns_retries;
root->u.proxy.dns_server.flags = loccfg->proxy.dns_queries;
} }
if (loccfg->proxy.urs_enabled) if (loccfg->proxy.urs_enabled)
@ -1001,6 +1002,27 @@ static int get_integer (const qse_xli_str_t* v)
return qse_strxtoi (v->ptr, v->len, 10); return qse_strxtoi (v->ptr, v->len, 10);
} }
static int parse_dns_query_types (qse_httpd_t* httpd, const qse_xli_str_t* str)
{
int flags = 0;
while (str)
{
if (qse_strxcasecmp (str->ptr, str->len, QSE_T("a")) == 0) flags |= QSE_HTTPD_DNS_SERVER_A;
else if (qse_strxcasecmp (str->ptr, str->len, QSE_T("aaaa")) == 0) flags |= QSE_HTTPD_DNS_SERVER_AAAA;
else
{
qse_printf (QSE_T("ERROR: invalid dns query type for proxy dns - %s\n"), str->ptr);
return -1;
}
str = str->next;
}
return flags;
}
static int load_loccfg_basic (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_t* list, loccfg_t* cfg) static int load_loccfg_basic (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_t* list, loccfg_t* cfg)
{ {
static struct static struct
@ -1356,6 +1378,7 @@ static int load_loccfg_access (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_
return 0; return 0;
} }
static int load_loccfg_proxy (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_t* list, loccfg_t* cfg) static int load_loccfg_proxy (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_t* list, loccfg_t* cfg)
{ {
qse_xli_pair_t* pair; qse_xli_pair_t* pair;
@ -1435,13 +1458,15 @@ static int load_loccfg_proxy (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_t
if (pair) cfg->proxy.dns_retries = get_integer ((qse_xli_str_t*)pair->val); if (pair) cfg->proxy.dns_retries = get_integer ((qse_xli_str_t*)pair->val);
else cfg->proxy.dns_retries = -1; else cfg->proxy.dns_retries = -1;
#if 0
pair = QSE_NULL; pair = QSE_NULL;
if (proxy) pair = qse_xli_findpair (xli, proxy, QSE_T("dns-query-type")); if (proxy) pair = qse_xli_findpair (xli, proxy, QSE_T("dns-queries"));
if (!pair && default_proxy) pair = qse_xli_findpair (xli, default_proxy, QSE_T("dns-query-type")); if (!pair && default_proxy) pair = qse_xli_findpair (xli, default_proxy, QSE_T("dns-queries"));
if (pair) cfg->proxy.dns_retries = parse_dns_query_type ((qse_xli_str_t*)pair->val); if (pair)
else cfg->proxy.dns_flag {
#endif cfg->proxy.dns_queries = parse_dns_query_types (httpd, (qse_xli_str_t*)pair->val);
if (cfg->proxy.dns_queries <= -1) return -1;
}
else cfg->proxy.dns_queries = QSE_HTTPD_DNS_SERVER_A | QSE_HTTPD_DNS_SERVER_AAAA;
pair = QSE_NULL; pair = QSE_NULL;
if (proxy) pair = qse_xli_findpair (xli, proxy, QSE_T("urs-enabled")); if (proxy) pair = qse_xli_findpair (xli, proxy, QSE_T("urs-enabled"));
@ -1855,6 +1880,7 @@ static int open_config_file (qse_httpd_t* httpd)
{ QSE_T("server-default.proxy.dns-server"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.proxy.dns-server"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server-default.proxy.dns-timeout"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.proxy.dns-timeout"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server-default.proxy.dns-retries"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.proxy.dns-retries"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server-default.proxy.dns-queries"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 0, 0xFFFF } },
{ QSE_T("server-default.proxy.urs-enabled"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.proxy.urs-enabled"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server-default.proxy.urs-server"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.proxy.urs-server"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server-default.proxy.urs-timeout"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.proxy.urs-timeout"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
@ -1908,6 +1934,7 @@ static int open_config_file (qse_httpd_t* httpd)
{ QSE_T("server.host.location.proxy.dns-server"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.proxy.dns-server"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.proxy.dns-timeout"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.proxy.dns-timeout"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.proxy.dns-retries"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.proxy.dns-retries"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.proxy.dns-queries"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 0, 0xFFFF } },
{ QSE_T("server.host.location.proxy.urs-enabled"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.proxy.urs-enabled"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.proxy.urs-server"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.proxy.urs-server"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.proxy.urs-timeout"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.proxy.urs-timeout"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
@ -2383,7 +2410,7 @@ static int httpd_main (int argc, qse_char_t* argv[])
setup_signal_handlers (); setup_signal_handlers ();
qse_httpd_getopt (httpd, QSE_HTTPD_TRAIT, &trait); qse_httpd_getopt (httpd, QSE_HTTPD_TRAIT, &trait);
trait |= QSE_HTTPD_CGIERRTONUL | QSE_HTTPD_LOGACT | QSE_HTTPD_DNSNOAAAA; /* TODO: make NOAAAA configurable */ trait |= QSE_HTTPD_CGIERRTONUL | QSE_HTTPD_LOGACT;
qse_httpd_setopt (httpd, QSE_HTTPD_TRAIT, &trait); qse_httpd_setopt (httpd, QSE_HTTPD_TRAIT, &trait);
tmout.sec = 10; tmout.sec = 10;

View File

@ -143,7 +143,7 @@ server-default {
#dns-server = "[::1]:53"; #dns-server = "[::1]:53";
#dns-timeout = 3 #dns-timeout = 3
#dns-retries = 2 #dns-retries = 2
dns-query-type = a, aaaa; dns-queries = a, aaaa;
#urs-enabled = yes; # no, yes, #urs-enabled = yes; # no, yes,
#urs-server = "127.0.0.1:97"; #urs-server = "127.0.0.1:97";

View File

@ -83,9 +83,7 @@ enum qse_httpd_trait_t
QSE_HTTPD_CGINOCLOEXEC = (1 << 2), QSE_HTTPD_CGINOCLOEXEC = (1 << 2),
QSE_HTTPD_CGINOCHUNKED = (1 << 3), QSE_HTTPD_CGINOCHUNKED = (1 << 3),
QSE_HTTPD_PROXYNOVIA = (1 << 4), QSE_HTTPD_PROXYNOVIA = (1 << 4),
QSE_HTTPD_LOGACT = (1 << 5), QSE_HTTPD_LOGACT = (1 << 5)
QSE_HTTPD_DNSNOA = (1 << 6),
QSE_HTTPD_DNSNOAAAA = (1 << 7)
}; };
typedef enum qse_httpd_trait_t qse_httpd_trait_t; typedef enum qse_httpd_trait_t qse_httpd_trait_t;
@ -168,15 +166,36 @@ struct qse_httpd_dirent_t
qse_httpd_stat_t stat; qse_httpd_stat_t stat;
}; };
typedef struct qse_httpd_natr_t qse_httpd_natr_t;
struct qse_httpd_natr_t /* -------------------------------------------------------------------------- */
enum qse_httpd_dns_server_flag_t
{
QSE_HTTPD_DNS_SERVER_A = (1 << 0), /* send A query */
QSE_HTTPD_DNS_SERVER_AAAA = (1 << 1) /* send AAAA query */
};
typedef enum qse_httpd_dns_server_flag_t qse_httpd_dns_server_flag_t;
typedef struct qse_httpd_dns_server_t qse_httpd_dns_server_t;
struct qse_httpd_dns_server_t
{
qse_nwad_t nwad;
qse_ntime_t tmout;
int retries;
int flags; /* bitwise-ORed of qse_httpd_dns_server_flag_t enumerators */
};
typedef struct qse_httpd_urs_server_t qse_httpd_urs_server_t;
struct qse_httpd_urs_server_t
{ {
qse_nwad_t nwad; qse_nwad_t nwad;
qse_ntime_t tmout; qse_ntime_t tmout;
int retries; int retries;
}; };
/* -------------------------------------------------------------------------- */
typedef void (*qse_httpd_resol_t) ( typedef void (*qse_httpd_resol_t) (
qse_httpd_t* httpd, qse_httpd_t* httpd,
const qse_mchar_t* name, const qse_mchar_t* name,
@ -213,12 +232,12 @@ typedef int (*qse_httpd_urs_recv_t) (
); );
typedef int (*qse_httpd_urs_send_t) ( typedef int (*qse_httpd_urs_send_t) (
qse_httpd_t* httpd, qse_httpd_t* httpd,
qse_httpd_urs_t* urs, qse_httpd_urs_t* urs,
const qse_mchar_t* url, const qse_mchar_t* url,
qse_httpd_rewrite_t rewrite, qse_httpd_rewrite_t rewrite,
const qse_httpd_natr_t* urs_server, const qse_httpd_urs_server_t* urs_server,
void* ctx void* ctx
); );
/* Success is indicated by a positive return value including 0. /* Success is indicated by a positive return value including 0.
@ -371,7 +390,7 @@ struct qse_httpd_scb_t
int (*recv) (qse_httpd_t* httpd, qse_httpd_dns_t* dns, qse_ubi_t handle); int (*recv) (qse_httpd_t* httpd, qse_httpd_dns_t* dns, qse_ubi_t handle);
int (*send) (qse_httpd_t* httpd, qse_httpd_dns_t* dns, int (*send) (qse_httpd_t* httpd, qse_httpd_dns_t* dns,
const qse_mchar_t* name, qse_httpd_resol_t resol, const qse_mchar_t* name, qse_httpd_resol_t resol,
const qse_httpd_natr_t* dns_server, void* ctx); const qse_httpd_dns_server_t* dns_server, void* ctx);
} dns; } dns;
struct struct
@ -716,8 +735,8 @@ struct qse_httpd_rsrc_proxy_t
const qse_mchar_t* str; const qse_mchar_t* str;
} dst; /* remote destination address to connect to */ } dst; /* remote destination address to connect to */
qse_httpd_natr_t dns_server; qse_httpd_dns_server_t dns_server;
qse_httpd_natr_t urs_server; qse_httpd_urs_server_t urs_server;
qse_httpd_mod_t* urs_prerewrite_mod; qse_httpd_mod_t* urs_prerewrite_mod;
/* optional pseudonym to use for Via: */ /* optional pseudonym to use for Via: */
@ -1147,22 +1166,21 @@ QSE_EXPORT qse_mchar_t* qse_httpd_escapehtml (
); );
QSE_EXPORT int qse_httpd_resolname ( QSE_EXPORT int qse_httpd_resolname (
qse_httpd_t* httpd, qse_httpd_t* httpd,
const qse_mchar_t* name, const qse_mchar_t* name,
qse_httpd_resol_t resol, qse_httpd_resol_t resol,
const qse_httpd_natr_t* dns_server, const qse_httpd_dns_server_t* dns_server,
void* ctx void* ctx
); );
QSE_EXPORT int qse_httpd_rewriteurl ( QSE_EXPORT int qse_httpd_rewriteurl (
qse_httpd_t* httpd, qse_httpd_t* httpd,
const qse_mchar_t* url, const qse_mchar_t* url,
qse_httpd_rewrite_t rewrite, qse_httpd_rewrite_t rewrite,
const qse_httpd_natr_t* urs_server, const qse_httpd_urs_server_t* urs_server,
void* ctx void* ctx
); );
QSE_EXPORT int qse_httpd_loadmod ( QSE_EXPORT int qse_httpd_loadmod (
qse_httpd_t* httpd, qse_httpd_t* httpd,
const qse_char_t* name const qse_char_t* name

View File

@ -67,8 +67,8 @@ struct task_proxy_t
qse_size_t qpath_pos_in_reqfwdbuf; /* position where qpath begins */ qse_size_t qpath_pos_in_reqfwdbuf; /* position where qpath begins */
qse_size_t qpath_len_in_reqfwdbuf; /* length of qpath + qparams */ qse_size_t qpath_len_in_reqfwdbuf; /* length of qpath + qparams */
qse_httpd_natr_t dns_server; qse_httpd_dns_server_t dns_server;
qse_httpd_natr_t urs_server; qse_httpd_urs_server_t urs_server;
qse_mchar_t* pseudonym; qse_mchar_t* pseudonym;
qse_htrd_t* peer_htrd; qse_htrd_t* peer_htrd;

View File

@ -795,7 +795,7 @@ printf (">>tmr_dns_tmout_handle req->>%p\n", req);
dc->req_count--; dc->req_count--;
} }
static int dns_send (qse_httpd_t* httpd, qse_httpd_dns_t* dns, const qse_mchar_t* name, qse_httpd_resol_t resol, const qse_httpd_natr_t* dns_server, void* ctx) static int dns_send (qse_httpd_t* httpd, qse_httpd_dns_t* dns, const qse_mchar_t* name, qse_httpd_resol_t resol, const qse_httpd_dns_server_t* dns_server, void* ctx)
{ {
dns_ctx_t* dc = (dns_ctx_t*)dns->ctx; dns_ctx_t* dc = (dns_ctx_t*)dns->ctx;
httpd_xtn_t* httpd_xtn; httpd_xtn_t* httpd_xtn;
@ -857,12 +857,13 @@ printf ("DNS REALLY SENING>>>>>>>>>>>>>>>>>>>>>>>\n");
req->resol = resol; req->resol = resol;
req->ctx = ctx; req->ctx = ctx;
if (!(httpd->opt.trait & QSE_HTTPD_DNSNOA))
if (dns_server->flags & QSE_HTTPD_DNS_SERVER_A)
req->qalen = init_dns_query (req->qa, QSE_SIZEOF(req->qa), name, DNS_QTYPE_A, req->seqa); req->qalen = init_dns_query (req->qa, QSE_SIZEOF(req->qa), name, DNS_QTYPE_A, req->seqa);
else else
req->flags |= DNS_REQ_A_NX; req->flags |= DNS_REQ_A_NX;
if (!(httpd->opt.trait & QSE_HTTPD_DNSNOAAAA)) if (dns_server->flags & QSE_HTTPD_DNS_SERVER_AAAA)
req->qaaaalen = init_dns_query (req->qaaaa, QSE_SIZEOF(req->qaaaa), name, DNS_QTYPE_AAAA, req->seqaaaa); req->qaaaalen = init_dns_query (req->qaaaa, QSE_SIZEOF(req->qaaaa), name, DNS_QTYPE_AAAA, req->seqaaaa);
else else
req->flags |= DNS_REQ_AAAA_NX; req->flags |= DNS_REQ_AAAA_NX;

View File

@ -348,7 +348,7 @@ printf ("urs timed out....\n");
dc->req_count--; dc->req_count--;
} }
static int urs_send (qse_httpd_t* httpd, qse_httpd_urs_t* urs, const qse_mchar_t* url, qse_httpd_rewrite_t rewrite, const qse_httpd_natr_t* urs_server, void* ctx) static int urs_send (qse_httpd_t* httpd, qse_httpd_urs_t* urs, const qse_mchar_t* url, qse_httpd_rewrite_t rewrite, const qse_httpd_urs_server_t* urs_server, void* ctx)
{ {
urs_ctx_t* dc = (urs_ctx_t*)urs->ctx; urs_ctx_t* dc = (urs_ctx_t*)urs->ctx;
httpd_xtn_t* httpd_xtn; httpd_xtn_t* httpd_xtn;

View File

@ -1831,11 +1831,8 @@ qse_mchar_t* qse_httpd_escapehtml (qse_httpd_t* httpd, const qse_mchar_t* str)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int qse_httpd_resolname (qse_httpd_t* httpd, const qse_mchar_t* name, qse_httpd_resol_t resol, const qse_httpd_natr_t* dns_server, void* ctx) int qse_httpd_resolname (qse_httpd_t* httpd, const qse_mchar_t* name, qse_httpd_resol_t resol, const qse_httpd_dns_server_t* dns_server, void* ctx)
{ {
/* TODO: find the name in cache */
/* not found in the cache */
printf ("DNS_SEND.........................\n"); printf ("DNS_SEND.........................\n");
if (!httpd->dnsactive) if (!httpd->dnsactive)
{ {
@ -1847,7 +1844,7 @@ printf ("DNS_SEND.........................\n");
return httpd->opt.scb.dns.send (httpd, &httpd->dns, name, resol, dns_server, ctx); return httpd->opt.scb.dns.send (httpd, &httpd->dns, name, resol, dns_server, ctx);
} }
int qse_httpd_rewriteurl (qse_httpd_t* httpd, const qse_mchar_t* url, qse_httpd_rewrite_t rewrite, const qse_httpd_natr_t* urs_server, void* ctx) int qse_httpd_rewriteurl (qse_httpd_t* httpd, const qse_mchar_t* url, qse_httpd_rewrite_t rewrite, const qse_httpd_urs_server_t* urs_server, void* ctx)
{ {
if (!httpd->ursactive) if (!httpd->ursactive)
{ {