@@ -88,4 +88,4 @@ socketpair(int d, int type, int protocol, int *sv) | |||||
sv[1] = (int)fd; | sv[1] = (int)fd; | ||||
return (0); | return (0); | ||||
} | } |
@@ -25,11 +25,15 @@ | |||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
*/ | */ | ||||
#ifdef _MSC_VER | |||||
#include "config.h" | #include "config.h" | ||||
#else | |||||
#include <winsock2.h> | /* Avoid the windows/msvc thing. */ | ||||
#include "../config.h" | |||||
#endif | |||||
#include <windows.h> | #include <windows.h> | ||||
#include <winsock2.h> | |||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/tree.h> | #include <sys/tree.h> | ||||
@@ -135,17 +135,23 @@ evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap) | |||||
va_list aq; | va_list aq; | ||||
for (;;) { | for (;;) { | ||||
buffer = buf->buffer + buf->off; | buffer = (char *)buf->buffer + buf->off; | ||||
space = buf->totallen - buf->misalign - buf->off; | space = buf->totallen - buf->misalign - buf->off; | ||||
#ifndef va_copy | |||||
#define va_copy(dst, src) memcpy(&(dst), &(src), sizeof(va_list)) | |||||
#endif | |||||
va_copy(aq, ap); | va_copy(aq, ap); | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
sz = vsnprintf(buffer, space - 1, fmt, aq); | sz = vsnprintf(buffer, space - 1, fmt, aq); | ||||
buffer[space - 1] = '\0'; | buffer[space - 1] = '\0'; | ||||
#else | #else | ||||
sz = vsnprintf(buffer, space, fmt, aq); | sz = vsnprintf(buffer, space, fmt, aq); | ||||
#endif | #endif | ||||
va_end(aq); | va_end(aq); | ||||
if (sz == -1) | if (sz == -1) | ||||
return (-1); | return (-1); | ||||
if (sz < space) { | if (sz < space) { | ||||
@@ -285,7 +291,7 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen) | |||||
} | } | ||||
int | int | ||||
evbuffer_add(struct evbuffer *buf, void *data, size_t datlen) | evbuffer_add(struct evbuffer *buf, const void *data, size_t datlen) | ||||
{ | { | ||||
size_t need = buf->misalign + buf->off + datlen; | size_t need = buf->misalign + buf->off + datlen; | ||||
size_t oldoff = buf->off; | size_t oldoff = buf->off; | ||||
@@ -429,12 +435,13 @@ evbuffer_find(struct evbuffer *buffer, const u_char *what, size_t len) | |||||
u_char *search = buffer->buffer; | u_char *search = buffer->buffer; | ||||
u_char *p; | u_char *p; | ||||
while ((p = memchr(search, *what, remain)) != NULL && remain >= len) { | while ((p = memchr(search, *what, remain)) != NULL) { | ||||
remain = buffer->off - (size_t)(search - buffer->buffer); | |||||
if (remain < len) | |||||
break; | |||||
if (memcmp(p, what, len) == 0) | if (memcmp(p, what, len) == 0) | ||||
return (p); | return (p); | ||||
search = p + 1; | search = p + 1; | ||||
remain = buffer->off - (size_t)(search - buffer->buffer); | |||||
} | } | ||||
return (NULL); | return (NULL); | ||||
@@ -1,8 +1,7 @@ | |||||
dnl configure.in for libevent | dnl configure.in for libevent | ||||
dnl Dug Song <dugsong@monkey.org> | |||||
AC_INIT(event.c) | AC_INIT(event.c) | ||||
AM_INIT_AUTOMAKE(libevent,1.2) | AM_INIT_AUTOMAKE(libevent,1.3a) | ||||
AM_CONFIG_HEADER(config.h) | AM_CONFIG_HEADER(config.h) | ||||
AM_MAINTAINER_MODE | AM_MAINTAINER_MODE | ||||
@@ -39,7 +38,7 @@ AC_CHECK_LIB(socket, socket) | |||||
dnl Checks for header files. | dnl Checks for header files. | ||||
AC_HEADER_STDC | AC_HEADER_STDC | ||||
AC_CHECK_HEADERS(fcntl.h stdarg.h inttypes.h stdint.h poll.h signal.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h sys/ioctl.h sys/devpoll.h port.h) | AC_CHECK_HEADERS(fcntl.h stdarg.h inttypes.h stdint.h poll.h signal.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h sys/ioctl.h sys/devpoll.h port.h netinet/in6.h) | ||||
if test "x$ac_cv_header_sys_queue_h" = "xyes"; then | if test "x$ac_cv_header_sys_queue_h" = "xyes"; then | ||||
AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h) | AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h) | ||||
AC_EGREP_CPP(yes, | AC_EGREP_CPP(yes, | ||||
@@ -132,8 +131,7 @@ AC_C_INLINE | |||||
AC_HEADER_TIME | AC_HEADER_TIME | ||||
dnl Checks for library functions. | dnl Checks for library functions. | ||||
AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r) | AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop) | ||||
dnl AC_REPLACE_FUNCS(strlcpy) | |||||
if test "x$ac_cv_func_clock_gettime" = "xyes"; then | if test "x$ac_cv_func_clock_gettime" = "xyes"; then | ||||
AC_DEFINE(DNS_USE_CPU_CLOCK_FOR_ID, 1, [Define if clock_gettime is available in libc]) | AC_DEFINE(DNS_USE_CPU_CLOCK_FOR_ID, 1, [Define if clock_gettime is available in libc]) | ||||
@@ -341,6 +339,17 @@ AC_CHECK_TYPE(u_int64_t, unsigned long long) | |||||
AC_CHECK_TYPE(u_int32_t, unsigned int) | AC_CHECK_TYPE(u_int32_t, unsigned int) | ||||
AC_CHECK_TYPE(u_int16_t, unsigned short) | AC_CHECK_TYPE(u_int16_t, unsigned short) | ||||
AC_CHECK_TYPE(u_int8_t, unsigned char) | AC_CHECK_TYPE(u_int8_t, unsigned char) | ||||
AC_CHECK_TYPES([struct in6_addr], , , | |||||
[#ifdef WIN32 | |||||
#include <winsock2.h> | |||||
#else | |||||
#include <sys/types.h> | |||||
#include <netinet/in.h> | |||||
#include <sys/socket.h> | |||||
#endif | |||||
#ifdef HAVE_NETINET_IN6_H | |||||
#include <netinet/in6.h> | |||||
#endif]) | |||||
AC_MSG_CHECKING([for socklen_t]) | AC_MSG_CHECKING([for socklen_t]) | ||||
AC_TRY_COMPILE([ | AC_TRY_COMPILE([ | ||||
@@ -213,6 +213,7 @@ | |||||
* 3 file too large | * 3 file too large | ||||
* 4 out of memory | * 4 out of memory | ||||
* 5 short read from file | * 5 short read from file | ||||
* 6 no nameservers in file | |||||
* | * | ||||
* Internals: | * Internals: | ||||
* | * | ||||
@@ -237,6 +238,10 @@ | |||||
#ifndef EVENTDNS_H | #ifndef EVENTDNS_H | ||||
#define EVENTDNS_H | #define EVENTDNS_H | ||||
#ifdef __cplusplus | |||||
extern "C" { | |||||
#endif | |||||
/* Error codes 0-5 are as described in RFC 1035. */ | /* Error codes 0-5 are as described in RFC 1035. */ | ||||
#define DNS_ERR_NONE 0 | #define DNS_ERR_NONE 0 | ||||
/* The name server was unable to interpret the query */ | /* The name server was unable to interpret the query */ | ||||
@@ -262,6 +267,7 @@ | |||||
#define DNS_IPv4_A 1 | #define DNS_IPv4_A 1 | ||||
#define DNS_PTR 2 | #define DNS_PTR 2 | ||||
#define DNS_IPv6_AAAA 3 | |||||
#define DNS_QUERY_NO_SEARCH 1 | #define DNS_QUERY_NO_SEARCH 1 | ||||
@@ -272,7 +278,7 @@ | |||||
/* | /* | ||||
* The callback that contains the results from a lookup. | * The callback that contains the results from a lookup. | ||||
* - type is either DNS_IPv4_A or DNS_PTR | * - type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA | ||||
* - count contains the number of addresses of form type | * - count contains the number of addresses of form type | ||||
* - ttl is the number of seconds the resolution may be cached for. | * - ttl is the number of seconds the resolution may be cached for. | ||||
* - addresses needs to be cast according to type | * - addresses needs to be cast according to type | ||||
@@ -288,8 +294,12 @@ int evdns_clear_nameservers_and_suspend(void); | |||||
int evdns_resume(void); | int evdns_resume(void); | ||||
int evdns_nameserver_ip_add(const char *ip_as_string); | int evdns_nameserver_ip_add(const char *ip_as_string); | ||||
int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr); | int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr); | ||||
int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr); | |||||
struct in_addr; | struct in_addr; | ||||
struct in6_addr; | |||||
int evdns_resolve_reverse(struct in_addr *in, 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_set_option(const char *option, const char *val, int flags); | |||||
int evdns_resolv_conf_parse(int flags, const char *); | int evdns_resolv_conf_parse(int flags, const char *); | ||||
#ifdef MS_WINDOWS | #ifdef MS_WINDOWS | ||||
int evdns_config_windows_nameservers(void); | int evdns_config_windows_nameservers(void); | ||||
@@ -303,4 +313,53 @@ void evdns_set_log_fn(evdns_debug_log_fn_type fn); | |||||
#define DNS_NO_SEARCH 1 | #define DNS_NO_SEARCH 1 | ||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
/* | |||||
* Structures and functions used to implement a DNS server. | |||||
*/ | |||||
struct evdns_server_request { | |||||
int flags; | |||||
int nquestions; | |||||
struct evdns_server_question **questions; | |||||
}; | |||||
struct evdns_server_question { | |||||
int type; | |||||
int class; | |||||
char name[1]; | |||||
}; | |||||
typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, void *); | |||||
#define EVDNS_ANSWER_SECTION 0 | |||||
#define EVDNS_AUTHORITY_SECTION 1 | |||||
#define EVDNS_ADDITIONAL_SECTION 2 | |||||
#define EVDNS_TYPE_A 1 | |||||
#define EVDNS_TYPE_NS 2 | |||||
#define EVDNS_TYPE_CNAME 5 | |||||
#define EVDNS_TYPE_SOA 6 | |||||
#define EVDNS_TYPE_PTR 12 | |||||
#define EVDNS_TYPE_MX 15 | |||||
#define EVDNS_TYPE_TXT 16 | |||||
#define EVDNS_TYPE_AAAA 28 | |||||
#define EVDNS_QTYPE_AXFR 252 | |||||
#define EVDNS_QTYPE_ALL 255 | |||||
#define EVDNS_CLASS_INET 1 | |||||
struct evdns_server_port *evdns_add_server_port(int socket, int is_tcp, evdns_request_callback_fn_type callback, void *user_data); | |||||
void evdns_close_server_port(struct evdns_server_port *port); | |||||
int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data); | |||||
int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl); | |||||
int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl); | |||||
int evdns_server_request_add_ptr_reply(struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl); | |||||
int evdns_server_request_add_cname_reply(struct evdns_server_request *req, const char *name, const char *cname, int ttl); | |||||
int evdns_server_request_respond(struct evdns_server_request *req, int err); | |||||
int evdns_server_request_drop(struct evdns_server_request *req); | |||||
#endif // !EVENTDNS_H | #endif // !EVENTDNS_H |
@@ -149,8 +149,12 @@ gettime(struct timeval *tp) | |||||
{ | { | ||||
#ifdef HAVE_CLOCK_GETTIME | #ifdef HAVE_CLOCK_GETTIME | ||||
struct timespec ts; | struct timespec ts; | ||||
#ifdef HAVE_CLOCK_MONOTONIC | |||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) | if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) | ||||
#else | |||||
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) | |||||
#endif | |||||
return (-1); | return (-1); | ||||
tp->tv_sec = ts.tv_sec; | tp->tv_sec = ts.tv_sec; | ||||
tp->tv_usec = ts.tv_nsec / 1000; | tp->tv_usec = ts.tv_nsec / 1000; | ||||
@@ -297,6 +301,8 @@ event_process_active(struct event_base *base) | |||||
} | } | ||||
} | } | ||||
assert(activeq != NULL); | |||||
for (ev = TAILQ_FIRST(activeq); ev; ev = TAILQ_FIRST(activeq)) { | for (ev = TAILQ_FIRST(activeq); ev; ev = TAILQ_FIRST(activeq)) { | ||||
event_queue_remove(base, ev, EVLIST_ACTIVE); | event_queue_remove(base, ev, EVLIST_ACTIVE); | ||||
@@ -307,6 +313,8 @@ event_process_active(struct event_base *base) | |||||
ncalls--; | ncalls--; | ||||
ev->ev_ncalls = ncalls; | ev->ev_ncalls = ncalls; | ||||
(*ev->ev_callback)((int)ev->ev_fd, ev->ev_res, ev->ev_arg); | (*ev->ev_callback)((int)ev->ev_fd, ev->ev_res, ev->ev_arg); | ||||
if (event_gotsig) | |||||
return; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -38,6 +38,7 @@ extern "C" { | |||||
#include <windows.h> | #include <windows.h> | ||||
#undef WIN32_LEAN_AND_MEAN | #undef WIN32_LEAN_AND_MEAN | ||||
typedef unsigned char u_char; | typedef unsigned char u_char; | ||||
typedef unsigned short u_short; | |||||
#endif | #endif | ||||
#define EVLIST_TIMEOUT 0x01 | #define EVLIST_TIMEOUT 0x01 | ||||
@@ -191,7 +192,7 @@ void event_active(struct event *, int, short); | |||||
int event_pending(struct event *, short, struct timeval *); | int event_pending(struct event *, short, struct timeval *); | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
#define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT && (ev)->ev_fd != INVALID_HANDLE_VALUE) | #define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT && (ev)->ev_fd != (int)INVALID_HANDLE_VALUE) | ||||
#else | #else | ||||
#define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) | #define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) | ||||
#endif | #endif | ||||
@@ -259,6 +260,7 @@ struct bufferevent { | |||||
struct bufferevent *bufferevent_new(int fd, | struct bufferevent *bufferevent_new(int fd, | ||||
evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg); | evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg); | ||||
int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev); | |||||
int bufferevent_priority_set(struct bufferevent *bufev, int pri); | int bufferevent_priority_set(struct bufferevent *bufev, int pri); | ||||
void bufferevent_free(struct bufferevent *bufev); | void bufferevent_free(struct bufferevent *bufev); | ||||
int bufferevent_write(struct bufferevent *bufev, void *data, size_t size); | int bufferevent_write(struct bufferevent *bufev, void *data, size_t size); | ||||
@@ -277,7 +279,7 @@ void bufferevent_settimeout(struct bufferevent *bufev, | |||||
struct evbuffer *evbuffer_new(void); | struct evbuffer *evbuffer_new(void); | ||||
void evbuffer_free(struct evbuffer *); | void evbuffer_free(struct evbuffer *); | ||||
int evbuffer_expand(struct evbuffer *, size_t); | int evbuffer_expand(struct evbuffer *, size_t); | ||||
int evbuffer_add(struct evbuffer *, void *, size_t); | int evbuffer_add(struct evbuffer *, const void *, size_t); | ||||
int evbuffer_remove(struct evbuffer *, void *, size_t); | int evbuffer_remove(struct evbuffer *, void *, size_t); | ||||
char *evbuffer_readline(struct evbuffer *); | char *evbuffer_readline(struct evbuffer *); | ||||
int evbuffer_add_buffer(struct evbuffer *, struct evbuffer *); | int evbuffer_add_buffer(struct evbuffer *, struct evbuffer *); | ||||