[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r9090: Merge whitespace and other changes from libevent (in tor/trunk: . src/or)
Author: nickm
Date: 2006-12-12 00:45:19 -0500 (Tue, 12 Dec 2006)
New Revision: 9090
Modified:
tor/trunk/
tor/trunk/src/or/eventdns.c
tor/trunk/src/or/eventdns.h
Log:
r11548@Kushana: nickm | 2006-12-12 00:44:51 -0500
Merge whitespace and other changes from libevent
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r11548] on c95137ef-5f19-0410-b913-86e773d04f59
Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c 2006-12-12 03:48:46 UTC (rev 9089)
+++ tor/trunk/src/or/eventdns.c 2006-12-12 05:45:19 UTC (rev 9090)
@@ -502,7 +502,7 @@
static void server_port_free(struct evdns_server_port *port);
static void server_port_ready_callback(int fd, short events, void *arg);
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) || defined(WIN32)
static int
last_error(int sock)
{
@@ -578,13 +578,14 @@
static void _evdns_log(int warn, const char *fmt, ...) EVDNS_LOG_CHECK;
static void
-_evdns_log(int warn, const char *fmt, ...) {
+_evdns_log(int warn, const char *fmt, ...)
+{
va_list args;
static char buf[512];
if (!evdns_log_fn)
return;
va_start(args,fmt);
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) || defined(WIN32)
_vsnprintf(buf, sizeof(buf), fmt, args);
#else
vsnprintf(buf, sizeof(buf), fmt, args);
@@ -838,7 +839,7 @@
return;
case TYPE_AAAA:
if (reply)
- req->user_callback(DNS_ERR_NONE, DNS_IPv4_AAAA,
+ req->user_callback(DNS_ERR_NONE, DNS_IPv6_AAAA,
reply->data.aaaa.addrcount, ttl,
reply->data.aaaa.addresses,
req->user_pointer);
@@ -850,8 +851,7 @@
// this processes a parsed reply packet
static void
-reply_handle(struct request *const req,
- u16 flags, u32 ttl, struct reply *reply) {
+reply_handle(struct request *const req, u16 flags, u32 ttl, struct reply *reply) {
int error;
static const int error_codes[] = {DNS_ERR_FORMAT, DNS_ERR_SERVERFAILED, DNS_ERR_NOTEXIST, DNS_ERR_NOTIMPL, DNS_ERR_REFUSED};
@@ -959,8 +959,7 @@
// parses a raw request from a nameserver.
static int
-reply_parse(u8 *packet, int length)
-{
+reply_parse(u8 *packet, int length) {
int j = 0; // index into packet
u16 _t; // used by the macros
u32 _t32; // used by the macros
@@ -990,9 +989,7 @@
req = request_find_from_trans_id(trans_id);
if (!req) return -1;
-
// XXXX should the other return points also call reply_handle? -NM
- // log("reqparse: trans was %d\n", (int)trans_id);
memset(&reply, 0, sizeof(reply));
@@ -1029,24 +1026,22 @@
GET32(ttl);
GET16(datalength);
- // log("@%d, Name %s, type %d, class %d, j=%d", pre, tmp_name, (int)type, (int)class, j);
-
if (type == TYPE_A && class == CLASS_INET) {
int addrcount, addrtocopy;
- if (req->request_type != type) {
+ if (req->request_type != TYPE_A) {
j += datalength; continue;
}
- // XXXX do something sane with malformed answers.
- addrcount = datalength >> 2; // each address is 4 bytes long
+ // XXXX do something sane with malformed A answers.
+ addrcount = datalength >> 2;
addrtocopy = MIN(MAX_ADDRS - reply.data.a.addrcount, (unsigned)addrcount);
+
ttl_r = MIN(ttl_r, ttl);
-
// we only bother with the first four addresses.
if (j + 4*addrtocopy > length) return -1;
memcpy(&reply.data.a.addresses[reply.data.a.addrcount],
packet + j, 4*addrtocopy);
+ j += 4*addrtocopy;
reply.data.a.addrcount += addrtocopy;
- j += 4*addrtocopy;
reply.have_answer = 1;
if (reply.data.a.addrcount == MAX_ADDRS) break;
} else if (type == TYPE_PTR && class == CLASS_INET) {
@@ -1060,10 +1055,10 @@
break;
} else if (type == TYPE_AAAA && class == CLASS_INET) {
int addrcount, addrtocopy;
- if (req->request_type != type) {
+ if (req->request_type != TYPE_AAAA) {
j += datalength; continue;
}
- // XXXX do something sane with malformed answers.
+ // XXXX do something sane with malformed AAAA answers.
addrcount = datalength >> 4; // each address is 16 bytes long
addrtocopy = MIN(MAX_ADDRS - reply.data.aaaa.addrcount, (unsigned)addrcount);
ttl_r = MIN(ttl_r, ttl);
@@ -1179,15 +1174,21 @@
const struct request *req = req_head, *started_at;
#ifdef DNS_USE_CPU_CLOCK_FOR_ID
struct timespec ts;
- const u16 trans_id = ts.tv_nsec & 0xffff;
- if (clock_gettime(CLOCK_MONOTONIC, &ts))
- abort();
+ u16 trans_id;
+#ifdef CLOCK_MONOTONIC
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
+#else
+ if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
#endif
+ event_err(1, "clock_gettime");
+ trans_id = ts.tv_nsec & 0xffff;
+#endif
#ifdef DNS_USE_GETTIMEOFDAY_FOR_ID
struct timeval tv;
- const u16 trans_id = tv.tv_usec & 0xffff;
+ u16 trans_id;
gettimeofday(&tv, NULL);
+ trans_id = tv.tv_usec & 0xffff;
#endif
#ifdef DNS_USE_OPENSSL_FOR_ID
@@ -2095,7 +2096,8 @@
// exported function
int
-evdns_count_nameservers(void) {
+evdns_count_nameservers(void)
+{
const struct nameserver *server = server_head;
int n = 0;
if (!server)
@@ -2109,7 +2111,8 @@
// exported function
int
-evdns_clear_nameservers_and_suspend(void) {
+evdns_clear_nameservers_and_suspend(void)
+{
struct nameserver *server = server_head, *started_at = server_head;
struct request *req = req_head, *req_started_at = req_head;
@@ -2158,7 +2161,8 @@
// exported function
int
-evdns_resume(void) {
+evdns_resume(void)
+{
evdns_requests_pump_waiting_queue();
return 0;
}
@@ -2186,7 +2190,7 @@
ns->socket = socket(PF_INET, SOCK_DGRAM, 0);
if (ns->socket < 0) { err = 1; goto out1; }
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) || defined(WIN32)
{
u_long nonblocking = 1;
ioctlsocket(ns->socket, FIONBIO, &nonblocking);
@@ -2229,12 +2233,11 @@
return 0;
- out2:
+out2:
CLOSE_SOCKET(ns->socket);
- out1:
+out1:
free(ns);
- log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d",
- debug_ntoa(address), err);
+ log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d", debug_ntoa(address), err);
return err;
}
@@ -2242,7 +2245,8 @@
int
evdns_nameserver_ip_add(const char *ip_as_string) {
struct in_addr ina;
- if (!inet_aton(ip_as_string, &ina)) return 4;
+ if (!inet_aton(ip_as_string, &ina))
+ return 4;
return evdns_nameserver_add(ina.s_addr);
}
@@ -2272,14 +2276,17 @@
}
static struct request *
-request_new(int type, const char *name, int flags, evdns_callback_type callback, void *user_ptr) {
- const char issuing_now = (global_requests_inflight < global_max_requests_inflight) ? 1 : 0;
+request_new(int type, const char *name, int flags,
+ evdns_callback_type callback, void *user_ptr) {
+ const char issuing_now =
+ (global_requests_inflight < global_max_requests_inflight) ? 1 : 0;
const int name_len = strlen(name);
const int request_max_len = evdns_request_len(name_len);
const u16 trans_id = issuing_now ? transaction_id_pick() : 0xffff;
// the request data is alloced in a single block with the header
- struct request *const req = (struct request *) malloc(sizeof(struct request) + request_max_len);
+ struct request *const req =
+ (struct request *) malloc(sizeof(struct request) + request_max_len);
int rlen;
(void) flags;
@@ -2304,7 +2311,7 @@
req->next = req->prev = NULL;
return req;
- err1:
+err1:
free(req);
return NULL;
}
@@ -2331,9 +2338,9 @@
struct request *const req =
request_new(TYPE_A, name, flags, callback, ptr);
if (req == NULL)
- return 1;
+ return (1);
request_submit(req);
- return 0;
+ return (0);
} else {
return search_request_new(TYPE_A, name, flags, callback, ptr);
}
@@ -2347,9 +2354,9 @@
struct request *const req =
request_new(TYPE_AAAA, name, flags, callback, ptr);
if (req == NULL)
- return 1;
+ return (1);
request_submit(req);
- return 0;
+ return (0);
} else {
return search_request_new(TYPE_AAAA, name, flags, callback, ptr);
}
@@ -2752,7 +2759,7 @@
fd = open(filename, O_RDONLY);
if (fd < 0) {
evdns_resolv_set_defaults(flags);
- return 0;
+ return 1;
}
if (fstat(fd, &st)) { err = 2; goto out1; }
@@ -2799,7 +2806,7 @@
return err;
}
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) || defined(WIN32)
// Add multiple nameservers from a space-or-comma-separated list.
static int
evdns_nameserver_ip_add_line(const char *ips) {
@@ -2828,7 +2835,8 @@
// Use the windows GetNetworkParams interface in iphlpapi.dll to
// figure out what our nameservers are.
static int
-load_nameservers_with_getnetworkparams(void) {
+load_nameservers_with_getnetworkparams(void)
+{
// Based on MSDN examples and inspection of c-ares code.
FIXED_INFO *fixed;
HMODULE handle = 0;
@@ -2844,7 +2852,6 @@
status = -1;
goto done;
}
-
if (!(fn = (GetNetworkParams_fn_t) GetProcAddress(handle, "GetNetworkParams"))) {
log(EVDNS_LOG_WARN, "Could not get address of function.");
//same as above
@@ -2853,9 +2860,7 @@
}
buf = malloc(size);
- if (!buf) {
- status = 4;
- goto done;
+ if (!buf) { status = 4; goto done; }
}
fixed = buf;
r = fn(fixed, &size);
@@ -2909,7 +2914,8 @@
}
static int
-config_nameserver_from_reg_key(HKEY key, const char *subkey) {
+config_nameserver_from_reg_key(HKEY key, const char *subkey)
+{
char *buf;
DWORD bufsz = 0, type = 0;
int status = 0;
@@ -2934,7 +2940,8 @@
#define WIN_NS_NT_KEY SERVICES_KEY "Tcpip\\Parameters"
static int
-load_nameservers_from_registry(void) {
+load_nameservers_from_registry(void)
+{
int found = 0;
int r;
#define TRY(k, name) \
@@ -2987,10 +2994,10 @@
}
int
-evdns_config_windows_nameservers(void) {
+evdns_config_windows_nameservers(void)
+{
if (load_nameservers_with_getnetworkparams() == 0)
return 0;
-
return load_nameservers_from_registry();
}
#endif
@@ -2999,7 +3006,7 @@
evdns_init(void)
{
int res = 0;
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) || defined(WIN32)
evdns_config_windows_nameservers();
#else
res = evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf");
Modified: tor/trunk/src/or/eventdns.h
===================================================================
--- tor/trunk/src/or/eventdns.h 2006-12-12 03:48:46 UTC (rev 9089)
+++ tor/trunk/src/or/eventdns.h 2006-12-12 05:45:19 UTC (rev 9090)
@@ -41,7 +41,7 @@
#define DNS_IPv4_A 1
#define DNS_PTR 2
-#define DNS_IPv4_AAAA 3
+#define DNS_IPv6_AAAA 3
#define DNS_QUERY_NO_SEARCH 1
@@ -50,11 +50,18 @@
#define DNS_OPTION_MISC 4
#define DNS_OPTIONS_ALL 7
+/*
+ * The callback that contains the results from a lookup.
+ * - type is either DNS_IPv4_A or DNS_IPv6_AAAA or DNS_PTR
+ * - count contains the number of addresses of form type
+ * - ttl is the number of seconds the resolution may be cached for.
+ * - addresses needs to be cast according to type
+ */
typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
int evdns_init(void);
void evdns_shutdown(int fail_requests);
-const char * evdns_err_to_string(int err);
+const char *evdns_err_to_string(int err);
int evdns_nameserver_add(unsigned long int address);
int evdns_count_nameservers(void);
int evdns_clear_nameservers_and_suspend(void);
@@ -64,8 +71,8 @@
int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr);
struct in_addr;
struct in6_addr;
-int evdns_resolve_reverse(struct in_addr *addr, int flags, evdns_callback_type callback, void *ptr);
-int evdns_resolve_reverse_ipv6(struct in6_addr *addr, int flags, evdns_callback_type callback, void *ptr);
+int evdns_resolve_reverse(struct in_addr *in, int flags, evdns_callback_type callback, void *ptr);
+int evdns_resolve_reverse_ipv6(struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr);
int evdns_resolv_conf_parse(int flags, const char *);
#ifdef MS_WINDOWS
int evdns_config_windows_nameservers(void);
@@ -74,7 +81,7 @@
void evdns_search_add(const char *domain);
void evdns_search_ndots_set(const int ndots);
-typedef void (*evdns_debug_log_fn_type)(int warn, const char *msg);
+typedef void (*evdns_debug_log_fn_type)(int is_warning, const char *msg);
void evdns_set_log_fn(evdns_debug_log_fn_type fn);
#define DNS_NO_SEARCH 1