r7009@Kushana: nickm | 2006-08-03 10:44:58 -0700

Add functions to eventdns to allow detecting whether we have any nameservers configured, and to change the list of nameservers after initial configuration.


svn:r6976
This commit is contained in:
Nick Mathewson 2006-08-04 18:26:13 +00:00
parent 87939813c3
commit 3fa1cdafce
3 changed files with 76 additions and 5 deletions

View File

@ -563,7 +563,7 @@ connection_dns_remove(edge_connection_t *conn)
* <b>address</b> from the cache. * <b>address</b> from the cache.
*/ */
void void
dns_cancel_pending_resolve(char *address) //XXXX NM CHECKME. dns_cancel_pending_resolve(char *address)
{ {
pending_connection_t *pend; pending_connection_t *pend;
cached_resolve_t search; cached_resolve_t search;

View File

@ -393,9 +393,11 @@ error_is_eagain(int err)
{ {
return err == EAGAIN || err == WSAEWOULDBLOCK; return err == EAGAIN || err == WSAEWOULDBLOCK;
} }
#define CLOSE_SOCKET(x) closesocket(x)
#else #else
#define last_error(sock) (errno) #define last_error(sock) (errno)
#define error_is_eagain(err) ((err) == EAGAIN) #define error_is_eagain(err) ((err) == EAGAIN)
#define CLOSE_SOCKET(x) close(x)
#endif #endif
#define ISSPACE(c) isspace((int)(unsigned char)(c)) #define ISSPACE(c) isspace((int)(unsigned char)(c))
@ -1165,6 +1167,72 @@ eventdns_transmit(void) {
return did_try_to_transmit; return did_try_to_transmit;
} }
// exported function
int
eventdns_count_nameservers(void)
{
const struct nameserver *server = server_head;
int n = 0;
if (!server)
return 0;
do {
++n;
server = server->next;
} while (server != server_head);
return n;
}
// exported function
int
eventdns_clear_nameservers_and_suspend(void)
{
struct nameserver *server = server_head, *started_at = server_head;
struct request *req = req_head, *req_started_at = req_head;
if (!server)
return 0;
while (1) {
struct nameserver *next = server->next;
event_del(&server->event);
evtimer_del(&server->timeout_event);
if (server->socket >= 0)
CLOSE_SOCKET(server->socket);
free(server);
if (next == started_at)
break;
server = next;
}
server_head = NULL;
while (req) {
struct request *next = req->next;
req->next = req->prev = NULL;
req->tx_count = req->reissue_count = 0;
req->ns = NULL;
// ???? What to do about searches?
evtimer_del(&req->timeout_event);
req->trans_id = 0;
req->transmit_me = 0;
eventdns_request_insert(req, &req_waiting_head);
if (next == req_started_at)
break;
req = next;
}
req_head = NULL;
return 0;
}
// exported function
int
eventdns_resume(void)
{
eventdns_requests_pump_waiting_queue();
return 0;
}
// exported function // exported function
int int
eventdns_nameserver_add(unsigned long int address) { eventdns_nameserver_add(unsigned long int address) {
@ -1209,6 +1277,8 @@ eventdns_nameserver_add(unsigned long int address) {
event_set(&ns->event, ns->socket, EV_READ | EV_PERSIST, nameserver_ready_callback, ns); event_set(&ns->event, ns->socket, EV_READ | EV_PERSIST, nameserver_ready_callback, ns);
event_add(&ns->event, NULL); event_add(&ns->event, NULL);
log("Added nameserver %s", debug_ntoa(address));
// insert this nameserver into the list of them // insert this nameserver into the list of them
if (!server_head) { if (!server_head) {
ns->next = ns->prev = ns; ns->next = ns->prev = ns;
@ -1227,13 +1297,11 @@ eventdns_nameserver_add(unsigned long int address) {
return 0; return 0;
out2: out2:
#ifdef MS_WINDOWS CLOSE_SOCKET(ns->socket);
closesocket(ns->socket);
#else
close(ns->socket);
#endif #endif
out1: out1:
free(ns); free(ns);
log("Unable to add nameserver %s: error %d", debug_ntoa(address), err);
return err; return err;
} }

View File

@ -49,6 +49,9 @@
typedef void (*eventdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg); typedef void (*eventdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
int eventdns_nameserver_add(unsigned long int address); int eventdns_nameserver_add(unsigned long int address);
int eventdns_count_nameservers(void);
int eventdns_clear_nameservers_and_suspend(void);
int eventdns_resume(void);
int eventdns_nameserver_ip_add(const char *ip_as_string); int eventdns_nameserver_ip_add(const char *ip_as_string);
int eventdns_resolve(const char *name, int flags, eventdns_callback_type callback, void *ptr); int eventdns_resolve(const char *name, int flags, eventdns_callback_type callback, void *ptr);
int eventdns_resolv_conf_parse(int flags, const char *); int eventdns_resolv_conf_parse(int flags, const char *);