acl/app/jaws/global/dns.h

76 lines
2.1 KiB
C
Raw Normal View History

#ifndef __DNS_SERVER_INCLUDE_H__
#define __DNS_SERVER_INCLUDE_H__
#include "lib_acl.h"
#ifdef __cplusplus
extern "C" {
#endif
#define USE_THREAD_POOL /* <20><><EFBFBD>Ҳ<EFBFBD>ѯDNSģ<53><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳߳ط<CCB3>ʽ */
/* <20><>ѯDNS<4E><53><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> */
#define DNS_MSG_LOOKUP ACL_MSGIO_USER + 100
#define DNS_MSG_LOOKUP_RESULT ACL_MSGIO_USER + 101
#define DNS_IP_MAX 5
typedef struct DNS_CTX DNS_CTX;
typedef struct DNS_SERVER DNS_SERVER;
typedef struct DNS_CACHE DNS_CACHE;
typedef void (*DNS_CALLBACK)(const DNS_CTX *);
struct DNS_CTX {
/* public */
char domain_key[256]; /* <20><><EFBFBD><EFBFBD>(Сд) */
char ip[DNS_IP_MAX][64]; /* IP<49><50>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD> */
int port[DNS_IP_MAX]; /* port <20><><EFBFBD><EFBFBD> */
int ip_cnt; /* IP<49><50>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>ЧIP<49><50>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD> */
time_t begin; /* <20><>ʼ<EFBFBD><CABC>ѯʱ<D1AF><CAB1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> */
/* public */
DNS_CALLBACK callback; /* <20><>ѯ<EFBFBD><D1AF><EFBFBD>ص<EFBFBD><D8B5>õ<EFBFBD><C3B5>û<EFBFBD><C3BB>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
void *context; /* <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ݵIJ<DDB5><C4B2><EFBFBD> */
/* private */
DNS_SERVER *dns; /* DNS<4E><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD> */
ACL_MSGIO *mio; /* IO<49><4F>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD> */
ACL_DNS_DB *dns_db; /* <20><>ʱ<EFBFBD><CAB1><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>DNS<4E><53>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD> */
};
struct DNS_SERVER {
ACL_AIO *aio; /* <20>첽ͨ<ECB2BD>ſ<EFBFBD><C5BF><EFBFBD> */
acl_pthread_pool_t *wq; /* <20>̳߳ؾ<CCB3><D8BE><EFBFBD> */
ACL_MSGIO *listener; /* <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>߾<EFBFBD><DFBE><EFBFBD> */
ACL_MSGIO *mio; /* <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD> */
char addr[256];
DNS_CACHE *dns_cache; /* DNS<4E><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
acl_pthread_mutex_t lock; /* <20>߳<EFBFBD><DFB3><EFBFBD> */
};
/* in dns_server.c */
DNS_SERVER *dns_server_create(ACL_AIO *aio, int timeout);
void dns_server_close(DNS_SERVER *dns);
void dns_server_static_add(DNS_SERVER *dns, const char *map, const char *delim, int def_port);
int dns_server_lookup(DNS_SERVER *dns, const DNS_CTX *ctx);
/* in dns_cache.c */
void dns_cache_push_one(DNS_CACHE *dns_cache, const ACL_DNS_DB *dns_db, int timeout);
void dns_cache_push(DNS_CACHE *dns_cache, const ACL_DNS_DB *dns_db);
void dns_cache_push2(DNS_CACHE *dns_cache, const DNS_CTX *dns_ctx);
ACL_DNS_DB *dns_cache_lookup(DNS_CACHE *dns_cache, const char *name);
void dns_cache_del_host(DNS_CACHE *dns_cache, const char *name);
DNS_CACHE *dns_cache_create(int timeout, int thread_safe);
/* in dns_hosts.c */
void dns_hosts_load(ACL_DNS *dns_handle, const char *filename);
#ifdef __cplusplus
}
#endif
#endif