Commit 3fa1cdaf authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

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
parent 87939813
......@@ -563,7 +563,7 @@ connection_dns_remove(edge_connection_t *conn)
* <b>address</b> from the cache.
*/
void
dns_cancel_pending_resolve(char *address) //XXXX NM CHECKME.
dns_cancel_pending_resolve(char *address)
{
pending_connection_t *pend;
cached_resolve_t search;
......
......@@ -393,9 +393,11 @@ error_is_eagain(int err)
{
return err == EAGAIN || err == WSAEWOULDBLOCK;
}
#define CLOSE_SOCKET(x) closesocket(x)
#else
#define last_error(sock) (errno)
#define error_is_eagain(err) ((err) == EAGAIN)
#define CLOSE_SOCKET(x) close(x)
#endif
#define ISSPACE(c) isspace((int)(unsigned char)(c))
......@@ -1165,6 +1167,72 @@ eventdns_transmit(void) {
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
int
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_add(&ns->event, NULL);
log("Added nameserver %s", debug_ntoa(address));
// insert this nameserver into the list of them
if (!server_head) {
ns->next = ns->prev = ns;
......@@ -1227,13 +1297,11 @@ eventdns_nameserver_add(unsigned long int address) {
return 0;
out2:
#ifdef MS_WINDOWS
closesocket(ns->socket);
#else
close(ns->socket);
CLOSE_SOCKET(ns->socket);
#endif
out1:
free(ns);
log("Unable to add nameserver %s: error %d", debug_ntoa(address), err);
return err;
}
......
......@@ -49,6 +49,9 @@
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_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_resolve(const char *name, int flags, eventdns_callback_type callback, void *ptr);
int eventdns_resolv_conf_parse(int flags, const char *);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment