Dillo v3.1.1-98-g318d1f14
|
#include <assert.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "msg.h"
#include "dns.h"
#include "list.h"
#include "IO/iowatch.hh"
Go to the source code of this file.
Macros | |
#define | D_DNS_MAX_SERVERS 1 |
Enumerations | |
enum | DnsServerState_t { DNS_SERVER_IDLE , DNS_SERVER_PROCESSING , DNS_SERVER_RESOLVED } |
Functions | |
static void | Dns_timeout_client (int fd, void *data) |
This function is called on the main thread and reads the DNS results. | |
static void | Dns_queue_add (int channel, const char *hostname, DnsCallback_t cb_func, void *cb_data) |
static int | Dns_queue_find (const char *hostname) |
Find hostname index in dns_queue (if found, returns queue index; -1 if not) | |
static void | Dns_queue_remove (int index) |
Given an index, remove an entry from the dns_queue. | |
static void | Dns_cache_add (char *hostname, Dlist *addr_list) |
Add an IP/hostname pair to Dns-cache. | |
void | a_Dns_init (void) |
Initializer function. | |
static void | Dns_note_hosts (Dlist *list, struct addrinfo *res0) |
Allocate a host structure and add it to the list. | |
static void * | Dns_server (void *data) |
Server function (runs on its own thread) | |
static void | Dns_server_req (int channel, const char *hostname) |
Request function (spawn a server and let it handle the request) | |
void | a_Dns_resolve (const char *hostname, DnsCallback_t cb_func, void *cb_data) |
Return the IP for the given hostname using a callback. | |
static void | Dns_serve_channel (int channel) |
Give answer to all queued callbacks on this channel. | |
static void | Dns_assign_channels (void) |
Assign free channels to waiting clients (-2) | |
void | a_Dns_freeall (void) |
Dns memory-deallocation. | |
void | a_Dns_dillohost_to_string (DilloHost *host, char *dst, size_t size) |
Writes a string representation of the given DilloHost into dst. | |
Variables | |
static DnsServer | dns_server [D_DNS_MAX_SERVERS] |
static int | num_servers |
static GDnsCache * | dns_cache |
static int | dns_cache_size |
static int | dns_cache_size_max |
static GDnsQueue * | dns_queue |
static int | dns_queue_size |
static int | dns_queue_size_max |
static int | dns_notify_pipe [2] |
enum DnsServerState_t |
void a_Dns_dillohost_to_string | ( | DilloHost * | host, |
char * | dst, | ||
size_t | size | ||
) |
Writes a string representation of the given DilloHost into dst.
dst will be \0 terminated. Please note that dst must be at least 40 bytes long for IPv6 addresses.
Definition at line 502 of file dns.c.
References DilloHost::af, and DilloHost::data.
Referenced by Dns_server().
void a_Dns_freeall | ( | void | ) |
Dns memory-deallocation.
(Call this one at exit time) The Dns_queue is deallocated at execution time (no need to do that here) 'dns_cache' is the only one that grows dynamically
Definition at line 480 of file dns.c.
References a_IOwatch_remove_fd(), dClose(), dFree(), DIO_READ, dList_free(), dList_length(), dList_nth_data(), dns_cache, dns_cache_size, and dns_notify_pipe.
Referenced by main().
void a_Dns_init | ( | void | ) |
Initializer function.
Definition at line 177 of file dns.c.
References a_IOwatch_add_fd(), D_DNS_MAX_SERVERS, DIO_READ, dNew, dns_cache, dns_cache_size, dns_cache_size_max, dns_notify_pipe, dns_queue, dns_queue_size, dns_queue_size_max, dns_server, DNS_SERVER_IDLE, Dns_timeout_client(), MSG, and num_servers.
Referenced by main().
void a_Dns_resolve | ( | const char * | hostname, |
DnsCallback_t | cb_func, | ||
void * | cb_data | ||
) |
Return the IP for the given hostname using a callback.
Side effect: a thread is spawned when hostname is not cached.
Definition at line 361 of file dns.c.
References dns_cache, dns_cache_size, dns_queue, Dns_queue_add(), Dns_queue_find(), dns_server, DNS_SERVER_IDLE, Dns_server_req(), dStrAsciiCasecmp(), and num_servers.
Referenced by Http_get().
|
static |
Assign free channels to waiting clients (-2)
Definition at line 420 of file dns.c.
References dns_queue, dns_queue_size, dns_server, DNS_SERVER_IDLE, Dns_server_req(), dStrAsciiCasecmp(), and num_servers.
Referenced by Dns_timeout_client().
|
static |
Add an IP/hostname pair to Dns-cache.
Definition at line 164 of file dns.c.
References _MSG, a_List_add, dns_cache, dns_cache_size, dns_cache_size_max, and dStrdup().
Referenced by Dns_timeout_client().
|
static |
Allocate a host structure and add it to the list.
Definition at line 219 of file dns.c.
References DilloHost::af, DilloHost::alen, DilloHost::data, dList_append(), and dNew0.
Referenced by Dns_server().
|
static |
Definition at line 103 of file dns.c.
References a_List_add, dns_queue, dns_queue_size, dns_queue_size_max, and dStrdup().
Referenced by a_Dns_resolve().
|
static |
Find hostname index in dns_queue (if found, returns queue index; -1 if not)
Definition at line 118 of file dns.c.
References dns_queue, dns_queue_size, and dStrAsciiCasecmp().
Referenced by a_Dns_resolve().
|
static |
Given an index, remove an entry from the dns_queue.
Definition at line 132 of file dns.c.
References _MSG, dFree(), dns_queue, and dns_queue_size.
Referenced by Dns_serve_channel().
|
static |
Give answer to all queued callbacks on this channel.
Definition at line 402 of file dns.c.
References dns_queue, Dns_queue_remove(), dns_queue_size, and dns_server.
Referenced by Dns_timeout_client().
|
static |
Server function (runs on its own thread)
Definition at line 265 of file dns.c.
References _MSG, a_Dns_dillohost_to_string(), dList_free(), dList_length(), dList_new(), dList_nth_data(), Dns_note_hosts(), dns_notify_pipe, dns_server, DNS_SERVER_RESOLVED, error(), MSG, and VOIDP2INT.
Referenced by Dns_server_req().
|
static |
Request function (spawn a server and let it handle the request)
Definition at line 330 of file dns.c.
References dFree(), Dns_server(), dns_server, DNS_SERVER_PROCESSING, dStrdup(), and INT2VOIDP.
Referenced by a_Dns_resolve(), and Dns_assign_channels().
|
static |
This function is called on the main thread and reads the DNS results.
Definition at line 451 of file dns.c.
References Dns_assign_channels(), Dns_cache_add(), dns_notify_pipe, Dns_serve_channel(), dns_server, DNS_SERVER_IDLE, DNS_SERVER_RESOLVED, and num_servers.
Referenced by a_Dns_init().
|
static |
Definition at line 93 of file dns.c.
Referenced by a_Dns_freeall(), a_Dns_init(), a_Dns_resolve(), and Dns_cache_add().
|
static |
Definition at line 94 of file dns.c.
Referenced by a_Dns_freeall(), a_Dns_init(), a_Dns_resolve(), and Dns_cache_add().
|
static |
Definition at line 94 of file dns.c.
Referenced by a_Dns_init(), and Dns_cache_add().
|
static |
Definition at line 97 of file dns.c.
Referenced by a_Dns_freeall(), a_Dns_init(), Dns_server(), and Dns_timeout_client().
|
static |
Definition at line 95 of file dns.c.
Referenced by a_Dns_init(), a_Dns_resolve(), Dns_assign_channels(), Dns_queue_add(), Dns_queue_find(), Dns_queue_remove(), and Dns_serve_channel().
|
static |
Definition at line 96 of file dns.c.
Referenced by a_Dns_init(), Dns_assign_channels(), Dns_queue_add(), Dns_queue_find(), Dns_queue_remove(), and Dns_serve_channel().
|
static |
Definition at line 96 of file dns.c.
Referenced by a_Dns_init(), and Dns_queue_add().
|
static |
Definition at line 91 of file dns.c.
Referenced by a_Dns_init(), a_Dns_resolve(), Dns_assign_channels(), Dns_serve_channel(), Dns_server(), Dns_server_req(), and Dns_timeout_client().
|
static |
Definition at line 92 of file dns.c.
Referenced by a_Dns_init(), a_Dns_resolve(), Dns_assign_channels(), and Dns_timeout_client().