mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-08 20:07:56 -04:00
Merge remote branches 'github/20_evdns_cancel_segfault_v2', 'github/20_http_close_detect', 'github/20_http_versions', 'github/20_more_http_methods', 'github/20_shutdown_iocp_listener' and 'github/20_win64_fixes'
This commit is contained in:
commit
5c8a59e886
@ -317,6 +317,13 @@
|
||||
#define _EVENT_SIZEOF_SIZE_T 4
|
||||
#endif
|
||||
|
||||
/* The size of `void *', as computed by sizeof. */
|
||||
#ifdef _WIN64
|
||||
#define _EVENT_SIZEOF_VOID_P 8
|
||||
#else
|
||||
#define _EVENT_SIZEOF_VOID_P 4
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define _EVENT_STDC_HEADERS 1
|
||||
|
||||
|
67
buffer.c
67
buffer.c
@ -146,7 +146,7 @@ static struct evbuffer_chain *evbuffer_expand_singlechain(struct evbuffer *buf,
|
||||
|
||||
#ifdef WIN32
|
||||
static int evbuffer_readfile(struct evbuffer *buf, evutil_socket_t fd,
|
||||
int howmuch);
|
||||
ev_ssize_t howmuch);
|
||||
#else
|
||||
#define evbuffer_readfile evbuffer_read
|
||||
#endif
|
||||
@ -572,7 +572,7 @@ evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size,
|
||||
goto done;
|
||||
|
||||
vec[0].iov_base = CHAIN_SPACE_PTR(chain);
|
||||
vec[0].iov_len = CHAIN_SPACE_LEN(chain);
|
||||
vec[0].iov_len = (size_t) CHAIN_SPACE_LEN(chain);
|
||||
EVUTIL_ASSERT(size<0 || (size_t)vec[0].iov_len >= (size_t)size);
|
||||
n = 1;
|
||||
} else {
|
||||
@ -1025,6 +1025,7 @@ done:
|
||||
|
||||
/* reads data from the src buffer to the dst buffer, avoids memcpy as
|
||||
* possible. */
|
||||
/* XXXX should return ev_ssize_t */
|
||||
int
|
||||
evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
|
||||
size_t datlen)
|
||||
@ -1054,7 +1055,7 @@ evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
|
||||
if (datlen >= src->total_len) {
|
||||
datlen = src->total_len;
|
||||
evbuffer_add_buffer(dst, src);
|
||||
result = datlen;
|
||||
result = (int)datlen; /*XXXX should return ev_ssize_t*/
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -1102,7 +1103,7 @@ evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
|
||||
evbuffer_invoke_callbacks(dst);
|
||||
evbuffer_invoke_callbacks(src);
|
||||
}
|
||||
result = nread;
|
||||
result = (int)nread;/*XXXX should change return type */
|
||||
|
||||
done:
|
||||
EVBUFFER_UNLOCK2(src, dst);
|
||||
@ -1231,11 +1232,11 @@ evbuffer_readline(struct evbuffer *buffer)
|
||||
return evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY);
|
||||
}
|
||||
|
||||
static inline int
|
||||
static inline ev_ssize_t
|
||||
evbuffer_strchr(struct evbuffer_ptr *it, const char chr)
|
||||
{
|
||||
struct evbuffer_chain *chain = it->_internal.chain;
|
||||
unsigned i = it->_internal.pos_in_chain;
|
||||
size_t i = it->_internal.pos_in_chain;
|
||||
while (chain != NULL) {
|
||||
char *buffer = (char *)chain->buffer + chain->misalign;
|
||||
char *cp = memchr(buffer+i, chr, chain->off-i);
|
||||
@ -1280,11 +1281,11 @@ find_eol_char(char *s, size_t len)
|
||||
#undef CHUNK_SZ
|
||||
}
|
||||
|
||||
static int
|
||||
static ev_ssize_t
|
||||
evbuffer_find_eol_char(struct evbuffer_ptr *it)
|
||||
{
|
||||
struct evbuffer_chain *chain = it->_internal.chain;
|
||||
unsigned i = it->_internal.pos_in_chain;
|
||||
size_t i = it->_internal.pos_in_chain;
|
||||
while (chain != NULL) {
|
||||
char *buffer = (char *)chain->buffer + chain->misalign;
|
||||
char *cp = find_eol_char(buffer+i, chain->off-i);
|
||||
@ -1308,7 +1309,7 @@ evbuffer_strspn(
|
||||
{
|
||||
int count = 0;
|
||||
struct evbuffer_chain *chain = ptr->_internal.chain;
|
||||
unsigned i = ptr->_internal.pos_in_chain;
|
||||
size_t i = ptr->_internal.pos_in_chain;
|
||||
|
||||
if (!chain)
|
||||
return -1;
|
||||
@ -1346,7 +1347,7 @@ static inline char
|
||||
evbuffer_getchr(struct evbuffer_ptr *it)
|
||||
{
|
||||
struct evbuffer_chain *chain = it->_internal.chain;
|
||||
int off = it->_internal.pos_in_chain;
|
||||
size_t off = it->_internal.pos_in_chain;
|
||||
|
||||
return chain->buffer[chain->misalign + off];
|
||||
}
|
||||
@ -1495,7 +1496,7 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
|
||||
}
|
||||
|
||||
if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) {
|
||||
remain = chain->buffer_len - chain->misalign - chain->off;
|
||||
remain = (size_t)(chain->buffer_len - chain->misalign - chain->off);
|
||||
if (remain >= datlen) {
|
||||
/* there's enough space to hold all the data in the
|
||||
* current last chain */
|
||||
@ -1595,11 +1596,11 @@ evbuffer_prepend(struct evbuffer *buf, const void *data, size_t datlen)
|
||||
/* we can only fit some of the data. */
|
||||
memcpy(chain->buffer,
|
||||
(char*)data + datlen - chain->misalign,
|
||||
chain->misalign);
|
||||
chain->off += chain->misalign;
|
||||
buf->total_len += chain->misalign;
|
||||
buf->n_add_for_cb += chain->misalign;
|
||||
datlen -= chain->misalign;
|
||||
(size_t)chain->misalign);
|
||||
chain->off += (size_t)chain->misalign;
|
||||
buf->total_len += (size_t)chain->misalign;
|
||||
buf->n_add_for_cb += (size_t)chain->misalign;
|
||||
datlen -= (size_t)chain->misalign;
|
||||
chain->misalign = 0;
|
||||
}
|
||||
}
|
||||
@ -1618,7 +1619,7 @@ evbuffer_prepend(struct evbuffer *buf, const void *data, size_t datlen)
|
||||
|
||||
memcpy(tmp->buffer + tmp->misalign, data, datlen);
|
||||
buf->total_len += datlen;
|
||||
buf->n_add_for_cb += chain->misalign;
|
||||
buf->n_add_for_cb += (size_t)chain->misalign;
|
||||
|
||||
out:
|
||||
evbuffer_invoke_callbacks(buf);
|
||||
@ -1793,7 +1794,7 @@ _evbuffer_expand_fast(struct evbuffer *buf, size_t datlen, int n)
|
||||
* space we have in the first n. */
|
||||
for (chain = *buf->last_with_datap; chain; chain = chain->next) {
|
||||
if (chain->off) {
|
||||
size_t space = CHAIN_SPACE_LEN(chain);
|
||||
size_t space = (size_t) CHAIN_SPACE_LEN(chain);
|
||||
EVUTIL_ASSERT(chain == *buf->last_with_datap);
|
||||
if (space) {
|
||||
avail += space;
|
||||
@ -1840,7 +1841,7 @@ _evbuffer_expand_fast(struct evbuffer *buf, size_t datlen, int n)
|
||||
rmv_all = 1;
|
||||
avail = 0;
|
||||
} else {
|
||||
avail = CHAIN_SPACE_LEN(chain);
|
||||
avail = (size_t) CHAIN_SPACE_LEN(chain);
|
||||
chain = chain->next;
|
||||
}
|
||||
|
||||
@ -1910,11 +1911,13 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen)
|
||||
#define IOV_TYPE struct iovec
|
||||
#define IOV_PTR_FIELD iov_base
|
||||
#define IOV_LEN_FIELD iov_len
|
||||
#define IOV_LEN_TYPE size_t
|
||||
#else
|
||||
#define NUM_WRITE_IOVEC 16
|
||||
#define IOV_TYPE WSABUF
|
||||
#define IOV_PTR_FIELD buf
|
||||
#define IOV_LEN_FIELD len
|
||||
#define IOV_LEN_TYPE unsigned long
|
||||
#endif
|
||||
#endif
|
||||
#define NUM_READ_IOVEC 4
|
||||
@ -1957,7 +1960,7 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ev_ssize_t howmuch,
|
||||
|
||||
chain = *firstchainp;
|
||||
for (i = 0; i < n_vecs_avail && so_far < (size_t)howmuch; ++i) {
|
||||
size_t avail = CHAIN_SPACE_LEN(chain);
|
||||
size_t avail = (size_t) CHAIN_SPACE_LEN(chain);
|
||||
if (avail > (howmuch - so_far) && exact)
|
||||
avail = howmuch - so_far;
|
||||
vecs[i].iov_base = CHAIN_SPACE_PTR(chain);
|
||||
@ -2090,10 +2093,10 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
|
||||
#ifdef USE_IOVEC_IMPL
|
||||
remaining = n;
|
||||
for (i=0; i < nvecs; ++i) {
|
||||
ev_ssize_t space = CHAIN_SPACE_LEN(*chainp);
|
||||
ev_ssize_t space = (ev_ssize_t) CHAIN_SPACE_LEN(*chainp);
|
||||
if (space < remaining) {
|
||||
(*chainp)->off += space;
|
||||
remaining -= space;
|
||||
remaining -= (int)space;
|
||||
} else {
|
||||
(*chainp)->off += remaining;
|
||||
buf->last_with_datap = chainp;
|
||||
@ -2118,7 +2121,7 @@ done:
|
||||
|
||||
#ifdef WIN32
|
||||
static int
|
||||
evbuffer_readfile(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
|
||||
evbuffer_readfile(struct evbuffer *buf, evutil_socket_t fd, ev_ssize_t howmuch)
|
||||
{
|
||||
int result;
|
||||
int nchains, n;
|
||||
@ -2142,16 +2145,16 @@ evbuffer_readfile(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
|
||||
result = -1;
|
||||
goto done;
|
||||
}
|
||||
n = read(fd, v[0].iov_base, v[0].iov_len);
|
||||
n = read((int)fd, v[0].iov_base, (unsigned int)v[0].iov_len);
|
||||
if (n <= 0) {
|
||||
result = n;
|
||||
goto done;
|
||||
}
|
||||
v[0].iov_len = n;
|
||||
v[0].iov_len = (IOV_LEN_TYPE) n; /* XXXX another problem with big n.*/
|
||||
if (nchains > 1) {
|
||||
n = read(fd, v[1].iov_base, v[1].iov_len);
|
||||
n = read((int)fd, v[1].iov_base, (unsigned int)v[1].iov_len);
|
||||
if (n <= 0) {
|
||||
result = v[0].iov_len;
|
||||
result = (unsigned long) v[0].iov_len;
|
||||
evbuffer_commit_space(buf, v, 1);
|
||||
goto done;
|
||||
}
|
||||
@ -2190,10 +2193,12 @@ evbuffer_write_iovec(struct evbuffer *buffer, evutil_socket_t fd,
|
||||
#endif
|
||||
iov[i].IOV_PTR_FIELD = (void *) (chain->buffer + chain->misalign);
|
||||
if ((size_t)howmuch >= chain->off) {
|
||||
iov[i++].IOV_LEN_FIELD = chain->off;
|
||||
/* XXXcould be problematic when windows supports mmap*/
|
||||
iov[i++].IOV_LEN_FIELD = (IOV_LEN_TYPE)chain->off;
|
||||
howmuch -= chain->off;
|
||||
} else {
|
||||
iov[i++].IOV_LEN_FIELD = howmuch;
|
||||
/* XXXcould be problematic when windows supports mmap*/
|
||||
iov[i++].IOV_LEN_FIELD = (IOV_LEN_TYPE)howmuch;
|
||||
break;
|
||||
}
|
||||
chain = chain->next;
|
||||
@ -2558,7 +2563,7 @@ evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap)
|
||||
space = chain->buffer_len - used;
|
||||
#endif
|
||||
buffer = (char*) CHAIN_SPACE_PTR(chain);
|
||||
space = CHAIN_SPACE_LEN(chain);
|
||||
space = (size_t) CHAIN_SPACE_LEN(chain);
|
||||
|
||||
#ifndef va_copy
|
||||
#define va_copy(dst, src) memcpy(&(dst), &(src), sizeof(va_list))
|
||||
@ -2760,7 +2765,7 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
|
||||
* can abort without side effects if the read fails.
|
||||
*/
|
||||
while (length) {
|
||||
read = evbuffer_readfile(tmp, fd, length);
|
||||
read = evbuffer_readfile(tmp, fd, (ev_ssize_t)length);
|
||||
if (read == -1) {
|
||||
evbuffer_free(tmp);
|
||||
return (-1);
|
||||
|
@ -201,10 +201,14 @@ evbuffer_launch_write(struct evbuffer *buf, ev_ssize_t at_most,
|
||||
_evbuffer_chain_pin(chain, EVBUFFER_MEM_PINNED_W);
|
||||
|
||||
if ((size_t)at_most > chain->off) {
|
||||
b->len = chain->off;
|
||||
/* XXXX Cast is safe for now, since win32 has no
|
||||
mmaped chains. But later, we need to have this
|
||||
add more WSAbufs if chain->off is greater than
|
||||
ULONG_MAX */
|
||||
b->len = (unsigned long)chain->off;
|
||||
at_most -= chain->off;
|
||||
} else {
|
||||
b->len = at_most;
|
||||
b->len = (unsigned long)at_most;
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
|
@ -378,11 +378,11 @@ int _bufferevent_generic_adj_timeouts(struct bufferevent *bev);
|
||||
/* ==== For rate-limiting. */
|
||||
|
||||
int _bufferevent_decrement_write_buckets(struct bufferevent_private *bev,
|
||||
int bytes);
|
||||
ev_ssize_t bytes);
|
||||
int _bufferevent_decrement_read_buckets(struct bufferevent_private *bev,
|
||||
int bytes);
|
||||
int _bufferevent_get_read_max(struct bufferevent_private *bev);
|
||||
int _bufferevent_get_write_max(struct bufferevent_private *bev);
|
||||
ev_ssize_t bytes);
|
||||
ev_ssize_t _bufferevent_get_read_max(struct bufferevent_private *bev);
|
||||
ev_ssize_t _bufferevent_get_write_max(struct bufferevent_private *bev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -194,7 +194,9 @@ bev_async_consider_writing(struct bufferevent_async *beva)
|
||||
at_most = evbuffer_get_length(bev->output);
|
||||
|
||||
/* XXXX This over-commits. */
|
||||
limit = _bufferevent_get_write_max(&beva->bev);
|
||||
/* This is safe so long as bufferevent_get_write_max never returns
|
||||
* more than INT_MAX. That's true for now. XXXX */
|
||||
limit = (int)_bufferevent_get_write_max(&beva->bev);
|
||||
if (at_most >= (size_t)limit && limit >= 0)
|
||||
at_most = limit;
|
||||
|
||||
@ -248,7 +250,8 @@ bev_async_consider_reading(struct bufferevent_async *beva)
|
||||
}
|
||||
|
||||
/* XXXX This over-commits. */
|
||||
limit = _bufferevent_get_read_max(&beva->bev);
|
||||
/* XXXX see also not above on cast on _bufferevent_get_write_max() */
|
||||
limit = (int)_bufferevent_get_read_max(&beva->bev);
|
||||
if (at_most >= (size_t)limit && limit >= 0)
|
||||
at_most = limit;
|
||||
|
||||
|
@ -192,11 +192,11 @@ static int _bev_group_suspend_writing(struct bufferevent_rate_limit_group *g);
|
||||
the maximum amount we should read if is_read. Return that maximum, or
|
||||
0 if our bucket is wholly exhausted.
|
||||
*/
|
||||
static inline int
|
||||
static inline ev_ssize_t
|
||||
_bufferevent_get_rlim_max(struct bufferevent_private *bev, int is_write)
|
||||
{
|
||||
/* needs lock on bev. */
|
||||
int max_so_far = is_write?MAX_TO_WRITE_EVER:MAX_TO_READ_EVER;
|
||||
ev_ssize_t max_so_far = is_write?MAX_TO_WRITE_EVER:MAX_TO_READ_EVER;
|
||||
|
||||
#define LIM(x) \
|
||||
(is_write ? (x).write_limit : (x).read_limit)
|
||||
@ -255,20 +255,20 @@ _bufferevent_get_rlim_max(struct bufferevent_private *bev, int is_write)
|
||||
return max_so_far;
|
||||
}
|
||||
|
||||
int
|
||||
ev_ssize_t
|
||||
_bufferevent_get_read_max(struct bufferevent_private *bev)
|
||||
{
|
||||
return _bufferevent_get_rlim_max(bev, 0);
|
||||
}
|
||||
|
||||
int
|
||||
ev_ssize_t
|
||||
_bufferevent_get_write_max(struct bufferevent_private *bev)
|
||||
{
|
||||
return _bufferevent_get_rlim_max(bev, 1);
|
||||
}
|
||||
|
||||
int
|
||||
_bufferevent_decrement_read_buckets(struct bufferevent_private *bev, int bytes)
|
||||
_bufferevent_decrement_read_buckets(struct bufferevent_private *bev, ev_ssize_t bytes)
|
||||
{
|
||||
/* XXXXX Make sure all users of this function check its return value */
|
||||
int r = 0;
|
||||
@ -300,7 +300,7 @@ _bufferevent_decrement_read_buckets(struct bufferevent_private *bev, int bytes)
|
||||
}
|
||||
|
||||
int
|
||||
_bufferevent_decrement_write_buckets(struct bufferevent_private *bev, int bytes)
|
||||
_bufferevent_decrement_write_buckets(struct bufferevent_private *bev, ev_ssize_t bytes)
|
||||
{
|
||||
/* XXXXX Make sure all users of this function check its return value */
|
||||
int r = 0;
|
||||
|
@ -127,7 +127,7 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
|
||||
struct evbuffer *input;
|
||||
int res = 0;
|
||||
short what = BEV_EVENT_READING;
|
||||
int howmuch = -1, readmax=-1;
|
||||
ev_ssize_t howmuch = -1, readmax=-1;
|
||||
|
||||
_bufferevent_incref_and_lock(bufev);
|
||||
|
||||
@ -152,13 +152,13 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
|
||||
}
|
||||
readmax = _bufferevent_get_read_max(bufev_p);
|
||||
if (howmuch < 0 || howmuch > readmax) /* The use of -1 for "unlimited"
|
||||
* uglifies this code. */
|
||||
* uglifies this code. XXXX */
|
||||
howmuch = readmax;
|
||||
if (bufev_p->read_suspended)
|
||||
goto done;
|
||||
|
||||
evbuffer_unfreeze(input, 0);
|
||||
res = evbuffer_read(input, fd, howmuch);
|
||||
res = evbuffer_read(input, fd, (int)howmuch); /* XXXX evbuffer_read would do better to take and return ev_ssize_t */
|
||||
evbuffer_freeze(input, 0);
|
||||
|
||||
if (res == -1) {
|
||||
@ -203,7 +203,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
|
||||
int res = 0;
|
||||
short what = BEV_EVENT_WRITING;
|
||||
int connected = 0;
|
||||
int atmost = -1;
|
||||
ev_ssize_t atmost = -1;
|
||||
|
||||
_bufferevent_incref_and_lock(bufev);
|
||||
|
||||
@ -449,7 +449,7 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai,
|
||||
}
|
||||
|
||||
/* XXX use the other addrinfos? */
|
||||
r = bufferevent_socket_connect(bev, ai->ai_addr, ai->ai_addrlen);
|
||||
r = bufferevent_socket_connect(bev, ai->ai_addr, (int)ai->ai_addrlen);
|
||||
_bufferevent_decref_and_unlock(bev);
|
||||
evutil_freeaddrinfo(ai);
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ struct evbuffer_chain {
|
||||
|
||||
/** unused space at the beginning of buffer or an offset into a
|
||||
* file for sendfile buffers. */
|
||||
off_t misalign;
|
||||
ev_off_t misalign;
|
||||
|
||||
/** Offset into buffer + misalign at which to start writing.
|
||||
* In other words, the total number of bytes actually stored
|
||||
@ -262,8 +262,10 @@ int _evbuffer_read_setup_vecs(struct evbuffer *buf, ev_ssize_t howmuch,
|
||||
/* Helper macro: copies an evbuffer_iovec in ei to a win32 WSABUF in i. */
|
||||
#define WSABUF_FROM_EVBUFFER_IOV(i,ei) do { \
|
||||
(i)->buf = (ei)->iov_base; \
|
||||
(i)->len = (ei)->iov_len; \
|
||||
(i)->len = (unsigned long)(ei)->iov_len; \
|
||||
} while (0)
|
||||
/* XXXX the cast above is safe for now, but not if we allow mmaps on win64.
|
||||
* See note in buffer_iocp's launch_write function */
|
||||
|
||||
/** Set the parent bufferevent object for buf to bev */
|
||||
void evbuffer_set_parent(struct evbuffer *buf, struct bufferevent *bev);
|
||||
|
38
evdns.c
38
evdns.c
@ -1171,7 +1171,7 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc
|
||||
goto err;
|
||||
GET16(type);
|
||||
GET16(class);
|
||||
namelen = strlen(tmp_name);
|
||||
namelen = (int)strlen(tmp_name);
|
||||
q = mm_malloc(sizeof(struct evdns_server_question) + namelen);
|
||||
if (!q)
|
||||
goto err;
|
||||
@ -1346,8 +1346,8 @@ server_port_flush(struct evdns_server_port *port)
|
||||
struct server_request *req = port->pending_replies;
|
||||
ASSERT_LOCKED(port);
|
||||
while (req) {
|
||||
int r = sendto(port->socket, req->response, req->response_len, 0,
|
||||
(struct sockaddr*) &req->addr, req->addrlen);
|
||||
int r = sendto(port->socket, req->response, (int)req->response_len, 0,
|
||||
(struct sockaddr*) &req->addr, (ev_socklen_t)req->addrlen);
|
||||
if (r < 0) {
|
||||
int err = evutil_socket_geterror(port->socket);
|
||||
if (EVUTIL_ERR_RW_RETRIABLE(err))
|
||||
@ -1508,7 +1508,7 @@ dnslabel_table_add(struct dnslabel_table *table, const char *label, off_t pos)
|
||||
/* */
|
||||
static off_t
|
||||
dnsname_to_labels(u8 *const buf, size_t buf_len, off_t j,
|
||||
const char *name, const int name_len,
|
||||
const char *name, const size_t name_len,
|
||||
struct dnslabel_table *table) {
|
||||
const char *end = name + name_len;
|
||||
int ref = 0;
|
||||
@ -1539,25 +1539,25 @@ dnsname_to_labels(u8 *const buf, size_t buf_len, off_t j,
|
||||
}
|
||||
name = strchr(name, '.');
|
||||
if (!name) {
|
||||
const unsigned int label_len = end - start;
|
||||
const size_t label_len = end - start;
|
||||
if (label_len > 63) return -1;
|
||||
if ((size_t)(j+label_len+1) > buf_len) return -2;
|
||||
if (table) dnslabel_table_add(table, start, j);
|
||||
buf[j++] = label_len;
|
||||
buf[j++] = (ev_uint8_t)label_len;
|
||||
|
||||
memcpy(buf + j, start, end - start);
|
||||
j += end - start;
|
||||
memcpy(buf + j, start, label_len);
|
||||
j += (int) label_len;
|
||||
break;
|
||||
} else {
|
||||
/* append length of the label. */
|
||||
const unsigned int label_len = name - start;
|
||||
const size_t label_len = name - start;
|
||||
if (label_len > 63) return -1;
|
||||
if ((size_t)(j+label_len+1) > buf_len) return -2;
|
||||
if (table) dnslabel_table_add(table, start, j);
|
||||
buf[j++] = label_len;
|
||||
buf[j++] = (ev_uint8_t)label_len;
|
||||
|
||||
memcpy(buf + j, start, name - start);
|
||||
j += name - start;
|
||||
memcpy(buf + j, start, label_len);
|
||||
j += (int) label_len;
|
||||
/* hop over the '.' */
|
||||
name++;
|
||||
}
|
||||
@ -1587,7 +1587,7 @@ evdns_request_len(const size_t name_len) {
|
||||
/* */
|
||||
/* Returns the amount of space used. Negative on error. */
|
||||
static int
|
||||
evdns_request_data_build(const char *const name, const int name_len,
|
||||
evdns_request_data_build(const char *const name, const size_t name_len,
|
||||
const u16 trans_id, const u16 type, const u16 class,
|
||||
u8 *const buf, size_t buf_len) {
|
||||
off_t j = 0; /* current offset into buf */
|
||||
@ -1908,8 +1908,8 @@ evdns_server_request_respond(struct evdns_server_request *_req, int err)
|
||||
goto done;
|
||||
}
|
||||
|
||||
r = sendto(port->socket, req->response, req->response_len, 0,
|
||||
(struct sockaddr*) &req->addr, req->addrlen);
|
||||
r = sendto(port->socket, req->response, (int)req->response_len, 0,
|
||||
(struct sockaddr*) &req->addr, (ev_socklen_t)req->addrlen);
|
||||
if (r<0) {
|
||||
int sock_err = evutil_socket_geterror(port->socket);
|
||||
if (EVUTIL_ERR_RW_RETRIABLE(sock_err))
|
||||
@ -2942,7 +2942,7 @@ evdns_search_clear(void) {
|
||||
|
||||
static void
|
||||
search_postfix_add(struct evdns_base *base, const char *domain) {
|
||||
int domain_len;
|
||||
size_t domain_len;
|
||||
struct search_domain *sdomain;
|
||||
while (domain[0] == '.') domain++;
|
||||
domain_len = strlen(domain);
|
||||
@ -2956,7 +2956,7 @@ search_postfix_add(struct evdns_base *base, const char *domain) {
|
||||
if (!sdomain) return;
|
||||
memcpy( ((u8 *) sdomain) + sizeof(struct search_domain), domain, domain_len);
|
||||
sdomain->next = base->global_search_state->head;
|
||||
sdomain->len = domain_len;
|
||||
sdomain->len = (int) domain_len;
|
||||
|
||||
base->global_search_state->head = sdomain;
|
||||
}
|
||||
@ -3019,7 +3019,7 @@ search_set_from_hostname(struct evdns_base *base) {
|
||||
/* warning: returns malloced string */
|
||||
static char *
|
||||
search_make_new(const struct search_state *const state, int n, const char *const base_name) {
|
||||
const int base_len = strlen(base_name);
|
||||
const size_t base_len = strlen(base_name);
|
||||
const char need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1;
|
||||
struct search_domain *dom;
|
||||
|
||||
@ -3429,7 +3429,7 @@ evdns_get_default_hosts_filename(void)
|
||||
char path[MAX_PATH+1];
|
||||
static const char hostfile[] = "\\drivers\\etc\\hosts";
|
||||
char *path_out;
|
||||
int len_out;
|
||||
size_t len_out;
|
||||
|
||||
if (! SHGetSpecialFolderPathA(NULL, path, CSIDL_SYSTEM, 0))
|
||||
return NULL;
|
||||
|
@ -267,7 +267,7 @@ struct event_base {
|
||||
int is_notify_pending;
|
||||
/** A socketpair used by some th_notify functions to wake up the main
|
||||
* thread. */
|
||||
int th_notify_fd[2];
|
||||
evutil_socket_t th_notify_fd[2];
|
||||
/** An event used by some th_notify functions to wake up the main
|
||||
* thread. */
|
||||
struct event th_notify;
|
||||
|
6
event.c
6
event.c
@ -824,7 +824,7 @@ event_reinit(struct event_base *base)
|
||||
if (evmap_io_add(base, ev->ev_fd, ev) == -1)
|
||||
res = -1;
|
||||
} else if (ev->ev_events & EV_SIGNAL) {
|
||||
if (evmap_signal_add(base, ev->ev_fd, ev) == -1)
|
||||
if (evmap_signal_add(base, (int)ev->ev_fd, ev) == -1)
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
@ -1995,7 +1995,7 @@ event_add_internal(struct event *ev, const struct timeval *tv,
|
||||
if (ev->ev_events & (EV_READ|EV_WRITE))
|
||||
res = evmap_io_add(base, ev->ev_fd, ev);
|
||||
else if (ev->ev_events & EV_SIGNAL)
|
||||
res = evmap_signal_add(base, ev->ev_fd, ev);
|
||||
res = evmap_signal_add(base, (int)ev->ev_fd, ev);
|
||||
if (res != -1)
|
||||
event_queue_insert(base, ev, EVLIST_INSERTED);
|
||||
if (res == 1) {
|
||||
@ -2173,7 +2173,7 @@ event_del_internal(struct event *ev)
|
||||
if (ev->ev_events & (EV_READ|EV_WRITE))
|
||||
res = evmap_io_del(base, ev->ev_fd, ev);
|
||||
else
|
||||
res = evmap_signal_del(base, ev->ev_fd, ev);
|
||||
res = evmap_signal_del(base, (int)ev->ev_fd, ev);
|
||||
if (res == 1) {
|
||||
/* evmap says we need to notify the main thread. */
|
||||
notify = 1;
|
||||
|
@ -256,7 +256,8 @@ evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag,
|
||||
struct evbuffer *data)
|
||||
{
|
||||
evtag_encode_tag(evbuf, tag);
|
||||
evtag_encode_int(evbuf, evbuffer_get_length(data));
|
||||
/* XXX support more than UINT32_MAX data */
|
||||
evtag_encode_int(evbuf, (ev_uint32_t)evbuffer_get_length(data));
|
||||
evbuffer_add_buffer(evbuf, data);
|
||||
}
|
||||
|
||||
@ -287,7 +288,8 @@ evtag_marshal_int64(struct evbuffer *evbuf, ev_uint32_t tag,
|
||||
void
|
||||
evtag_marshal_string(struct evbuffer *buf, ev_uint32_t tag, const char *string)
|
||||
{
|
||||
evtag_marshal(buf, tag, string, strlen(string));
|
||||
/* TODO support strings longer than UINT32_MAX ? */
|
||||
evtag_marshal(buf, tag, string, (ev_uint32_t)strlen(string));
|
||||
}
|
||||
|
||||
void
|
||||
@ -302,7 +304,7 @@ evtag_marshal_timeval(struct evbuffer *evbuf, ev_uint32_t tag, struct timeval *t
|
||||
#define DECODE_INT_INTERNAL(number, maxnibbles, pnumber, evbuf, offset) \
|
||||
do { \
|
||||
ev_uint8_t *data; \
|
||||
int len = evbuffer_get_length(evbuf) - offset; \
|
||||
ev_ssize_t len = evbuffer_get_length(evbuf) - offset; \
|
||||
int nibbles = 0; \
|
||||
\
|
||||
if (len <= 0) \
|
||||
@ -329,7 +331,7 @@ do { \
|
||||
\
|
||||
*pnumber = number; \
|
||||
\
|
||||
return (len); \
|
||||
return (int)(len); \
|
||||
} while (0)
|
||||
|
||||
/* Internal: decode an integer from an evbuffer, without draining it.
|
||||
|
2
evrpc.c
2
evrpc.c
@ -210,7 +210,7 @@ static char *
|
||||
evrpc_construct_uri(const char *uri)
|
||||
{
|
||||
char *constructed_uri;
|
||||
int constructed_uri_len;
|
||||
size_t constructed_uri_len;
|
||||
|
||||
constructed_uri_len = strlen(EVRPC_URI_PREFIX) + strlen(uri) + 1;
|
||||
if ((constructed_uri = mm_malloc(constructed_uri_len)) == NULL)
|
||||
|
15
evutil.c
15
evutil.c
@ -83,8 +83,8 @@
|
||||
#define open _open
|
||||
#define read _read
|
||||
#define close _close
|
||||
#define fstat _fstat
|
||||
#define stat _stat
|
||||
#define fstat _fstati64
|
||||
#define stat _stati64
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -125,13 +125,18 @@ evutil_read_file(const char *filename, char **content_out, size_t *len_out,
|
||||
close(fd);
|
||||
return -2;
|
||||
}
|
||||
mem = mm_malloc(st.st_size + 1);
|
||||
mem = mm_malloc((size_t)st.st_size + 1);
|
||||
if (!mem) {
|
||||
close(fd);
|
||||
return -2;
|
||||
}
|
||||
read_so_far = 0;
|
||||
while ((r = read(fd, mem+read_so_far, st.st_size - read_so_far)) > 0) {
|
||||
#ifdef WIN32
|
||||
#define N_TO_READ(x) ((x) > INT_MAX) ? INT_MAX : ((int)(x))
|
||||
#else
|
||||
#define N_TO_READ(x) (x)
|
||||
#endif
|
||||
while ((r = read(fd, mem+read_so_far, N_TO_READ(st.st_size - read_so_far))) > 0) {
|
||||
read_so_far += r;
|
||||
if (read_so_far >= (size_t)st.st_size)
|
||||
break;
|
||||
@ -1717,7 +1722,7 @@ evutil_parse_sockaddr_port(const char *ip_as_string, struct sockaddr *out, int *
|
||||
if (!(cp = strchr(ip_as_string, ']'))) {
|
||||
return -1;
|
||||
}
|
||||
len = cp-(ip_as_string + 1);
|
||||
len = (int) ( cp-(ip_as_string + 1) );
|
||||
if (len > (int)sizeof(buf)-1) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
|
||||
#include "event2/event-config.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "util-internal.h"
|
||||
#include "evthread-internal.h"
|
||||
|
||||
@ -118,6 +120,7 @@ evutil_secure_rng_get_bytes(void *buf, size_t n)
|
||||
void
|
||||
evutil_secure_rng_add_bytes(const char *buf, size_t n)
|
||||
{
|
||||
arc4random_addrandom((unsigned char*)buf, n);
|
||||
arc4random_addrandom((unsigned char*)buf,
|
||||
n>(size_t)INT_MAX ? INT_MAX : (int)n);
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,9 @@ struct evbuffer;
|
||||
struct addrinfo;
|
||||
struct evhttp_request;
|
||||
|
||||
/* Indicates an unknown request method. */
|
||||
#define _EVHTTP_REQ_UNKNOWN (1<<15)
|
||||
|
||||
enum evhttp_connection_state {
|
||||
EVCON_DISCONNECTED, /**< not currently connected not trying either*/
|
||||
EVCON_CONNECTING, /**< tries to currently connect */
|
||||
@ -145,6 +148,10 @@ struct evhttp {
|
||||
size_t default_max_headers_size;
|
||||
ev_uint64_t default_max_body_size;
|
||||
|
||||
/* Bitmask of all HTTP methods that we accept and pass to user
|
||||
* callbacks. */
|
||||
ev_uint16_t allowed_methods;
|
||||
|
||||
/* Fallback callback if all the other callbacks for this connection
|
||||
don't match. */
|
||||
void (*gencb)(struct evhttp_request *req, void *);
|
||||
|
133
http.c
133
http.c
@ -149,6 +149,14 @@ fake_getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
||||
|
||||
#endif
|
||||
|
||||
#define REQ_VERSION_BEFORE(req, major_v, minor_v) \
|
||||
((req)->major < (major_v) || \
|
||||
((req)->major == (major_v) && (req)->minor < (minor_v)))
|
||||
|
||||
#define REQ_VERSION_ATLEAST(req, major_v, minor_v) \
|
||||
((req)->major > (major_v) || \
|
||||
((req)->major == (major_v) && (req)->minor >= (minor_v)))
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#endif
|
||||
@ -240,7 +248,8 @@ html_replace(char ch, char *buf)
|
||||
char *
|
||||
evhttp_htmlescape(const char *html)
|
||||
{
|
||||
int i, new_size = 0, old_size = strlen(html);
|
||||
size_t i;
|
||||
size_t new_size = 0, old_size = strlen(html);
|
||||
char *escaped_html, *p;
|
||||
char scratch_space[2];
|
||||
|
||||
@ -249,7 +258,7 @@ evhttp_htmlescape(const char *html)
|
||||
|
||||
p = escaped_html = mm_malloc(new_size + 1);
|
||||
if (escaped_html == NULL) {
|
||||
event_warn("%s: malloc(%d)", __func__, new_size + 1);
|
||||
event_warn("%s: malloc(%ld)", __func__, (long)(new_size + 1));
|
||||
return (NULL);
|
||||
}
|
||||
for (i = 0; i < old_size; ++i) {
|
||||
@ -288,6 +297,18 @@ evhttp_method(enum evhttp_cmd_type type)
|
||||
case EVHTTP_REQ_DELETE:
|
||||
method = "DELETE";
|
||||
break;
|
||||
case EVHTTP_REQ_OPTIONS:
|
||||
method = "OPTIONS";
|
||||
break;
|
||||
case EVHTTP_REQ_TRACE:
|
||||
method = "TRACE";
|
||||
break;
|
||||
case EVHTTP_REQ_CONNECT:
|
||||
method = "CONNECT";
|
||||
break;
|
||||
case EVHTTP_REQ_PATCH:
|
||||
method = "PATCH";
|
||||
break;
|
||||
default:
|
||||
method = NULL;
|
||||
break;
|
||||
@ -342,8 +363,16 @@ evhttp_write_buffer(struct evhttp_connection *evcon,
|
||||
evcon->cb = cb;
|
||||
evcon->cb_arg = arg;
|
||||
|
||||
bufferevent_disable(evcon->bufev, EV_READ);
|
||||
bufferevent_enable(evcon->bufev, EV_WRITE);
|
||||
|
||||
/* Disable the read callback: we don't actually care about data;
|
||||
* we only care about close detection. (We don't disable reading,
|
||||
* since we *do* want to learn about any close events.) */
|
||||
bufferevent_setcb(evcon->bufev,
|
||||
NULL, /*read*/
|
||||
evhttp_write_cb,
|
||||
evhttp_error_cb,
|
||||
evcon);
|
||||
}
|
||||
|
||||
/** Helper: returns true iff evconn is in any connected state. */
|
||||
@ -470,9 +499,8 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
|
||||
req->major, req->minor, req->response_code,
|
||||
req->response_code_line);
|
||||
|
||||
/* XXX shouldn't these check for >= rather than == ? - NM */
|
||||
if (req->major == 1) {
|
||||
if (req->minor == 1)
|
||||
if (req->minor >= 1)
|
||||
evhttp_maybe_add_date_header(req->output_headers);
|
||||
|
||||
/*
|
||||
@ -483,7 +511,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
|
||||
evhttp_add_header(req->output_headers,
|
||||
"Connection", "keep-alive");
|
||||
|
||||
if ((req->minor == 1 || is_keepalive) &&
|
||||
if ((req->minor >= 1 || is_keepalive) &&
|
||||
evhttp_response_needs_body(req)) {
|
||||
/*
|
||||
* we need to add the content length if the
|
||||
@ -762,7 +790,7 @@ evhttp_connection_done(struct evhttp_connection *evcon)
|
||||
static enum message_read_status
|
||||
evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf)
|
||||
{
|
||||
int len;
|
||||
ev_ssize_t len;
|
||||
|
||||
while ((len = evbuffer_get_length(buf)) > 0) {
|
||||
if (req->ntoread < 0) {
|
||||
@ -1305,6 +1333,22 @@ evhttp_valid_response_code(int code)
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
evhttp_parse_http_version(const char *version, struct evhttp_request *req)
|
||||
{
|
||||
int major, minor;
|
||||
char ch;
|
||||
int n = sscanf(version, "HTTP/%d.%d%c", &major, &minor, &ch);
|
||||
if (n > 2 || major > 1) {
|
||||
event_debug(("%s: bad version %s on message %p from %s",
|
||||
__func__, version, req, req->remote_host));
|
||||
return (-1);
|
||||
}
|
||||
req->major = major;
|
||||
req->minor = minor;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Parses the status line of a web server */
|
||||
|
||||
static int
|
||||
@ -1321,17 +1365,8 @@ evhttp_parse_response_line(struct evhttp_request *req, char *line)
|
||||
if (line != NULL)
|
||||
readable = line;
|
||||
|
||||
if (strcmp(protocol, "HTTP/1.0") == 0) {
|
||||
req->major = 1;
|
||||
req->minor = 0;
|
||||
} else if (strcmp(protocol, "HTTP/1.1") == 0) {
|
||||
req->major = 1;
|
||||
req->minor = 1;
|
||||
} else {
|
||||
event_debug(("%s: bad protocol \"%s\"",
|
||||
__func__, protocol));
|
||||
if (evhttp_parse_http_version(protocol, req) < 0)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
req->response_code = atoi(number);
|
||||
if (!evhttp_valid_response_code(req->response_code)) {
|
||||
@ -1379,24 +1414,22 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
|
||||
req->type = EVHTTP_REQ_PUT;
|
||||
} else if (strcmp(method, "DELETE") == 0) {
|
||||
req->type = EVHTTP_REQ_DELETE;
|
||||
} else if (strcmp(method, "OPTIONS") == 0) {
|
||||
req->type = EVHTTP_REQ_OPTIONS;
|
||||
} else if (strcmp(method, "TRACE") == 0) {
|
||||
req->type = EVHTTP_REQ_TRACE;
|
||||
} else if (strcmp(method, "PATCH") == 0) {
|
||||
req->type = EVHTTP_REQ_PATCH;
|
||||
} else {
|
||||
req->type = _EVHTTP_REQ_UNKNOWN;
|
||||
event_debug(("%s: bad method %s on request %p from %s",
|
||||
__func__, method, req, req->remote_host));
|
||||
return (-1);
|
||||
/* No error yet; we'll give a better error later when
|
||||
* we see that req->type is unsupported. */
|
||||
}
|
||||
|
||||
if (strcmp(version, "HTTP/1.0") == 0) {
|
||||
req->major = 1;
|
||||
req->minor = 0;
|
||||
} else if (strcmp(version, "HTTP/1.1") == 0) {
|
||||
req->major = 1;
|
||||
req->minor = 1;
|
||||
} else {
|
||||
/* XXX So, http/1.2 kills us? Is that right? -NM */
|
||||
event_debug(("%s: bad version %s on request %p from %s",
|
||||
__func__, version, req, req->remote_host));
|
||||
if (evhttp_parse_http_version(version, req) < 0)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((req->uri = mm_strdup(uri)) == NULL) {
|
||||
event_debug(("%s: mm_strdup", __func__));
|
||||
@ -2057,6 +2090,12 @@ evhttp_start_read(struct evhttp_connection *evcon)
|
||||
bufferevent_disable(evcon->bufev, EV_WRITE);
|
||||
bufferevent_enable(evcon->bufev, EV_READ);
|
||||
evcon->state = EVCON_READING_FIRSTLINE;
|
||||
/* Reset the bufferevent callbacks */
|
||||
bufferevent_setcb(evcon->bufev,
|
||||
evhttp_read_cb,
|
||||
evhttp_write_cb,
|
||||
evhttp_error_cb,
|
||||
evcon);
|
||||
|
||||
/* If there's still data pending, process it next time through the
|
||||
* loop. Don't do it now; that could get recusive. */
|
||||
@ -2074,7 +2113,7 @@ evhttp_send_done(struct evhttp_connection *evcon, void *arg)
|
||||
TAILQ_REMOVE(&evcon->requests, req, next);
|
||||
|
||||
need_close =
|
||||
(req->minor == 0 &&
|
||||
(REQ_VERSION_BEFORE(req, 1, 1) &&
|
||||
!evhttp_is_connection_keepalive(req->input_headers))||
|
||||
evhttp_is_connection_close(req->flags, req->input_headers) ||
|
||||
evhttp_is_connection_close(req->flags, req->output_headers);
|
||||
@ -2169,7 +2208,7 @@ evhttp_send_reply_start(struct evhttp_request *req, int code,
|
||||
{
|
||||
evhttp_response_code(req, code, reason);
|
||||
if (evhttp_find_header(req->output_headers, "Content-Length") == NULL &&
|
||||
req->major == 1 && req->minor == 1 &&
|
||||
REQ_VERSION_ATLEAST(req, 1, 1) &&
|
||||
evhttp_response_needs_body(req)) {
|
||||
/*
|
||||
* prefer HTTP/1.1 chunked encoding to closing the connection;
|
||||
@ -2179,6 +2218,8 @@ evhttp_send_reply_start(struct evhttp_request *req, int code,
|
||||
evhttp_add_header(req->output_headers, "Transfer-Encoding",
|
||||
"chunked");
|
||||
req->chunked = 1;
|
||||
} else {
|
||||
req->chunked = 0;
|
||||
}
|
||||
evhttp_make_header(req->evcon, req);
|
||||
evhttp_write_buffer(req->evcon, NULL, NULL);
|
||||
@ -2666,11 +2707,18 @@ evhttp_handle_request(struct evhttp_request *req, void *arg)
|
||||
/* we have a new request on which the user needs to take action */
|
||||
req->userdone = 0;
|
||||
|
||||
if (req->uri == NULL) {
|
||||
if (req->type == 0 || req->uri == NULL) {
|
||||
evhttp_send_error(req, HTTP_BADREQUEST, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((http->allowed_methods & req->type) == 0) {
|
||||
event_debug(("Rejecting disallowed method %x (allowed: %x)\n",
|
||||
(unsigned)req->type, (unsigned)http->allowed_methods));
|
||||
evhttp_send_error(req, HTTP_NOTIMPLEMENTED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* handle potential virtual hosts */
|
||||
hostname = evhttp_find_header(req->input_headers, "Host");
|
||||
if (hostname != NULL) {
|
||||
@ -2856,6 +2904,11 @@ evhttp_new_object(void)
|
||||
http->timeout = -1;
|
||||
evhttp_set_max_headers_size(http, EV_SIZE_MAX);
|
||||
evhttp_set_max_body_size(http, EV_SIZE_MAX);
|
||||
evhttp_set_allowed_methods(http, EVHTTP_REQ_GET |
|
||||
EVHTTP_REQ_POST |
|
||||
EVHTTP_REQ_HEAD |
|
||||
EVHTTP_REQ_PUT |
|
||||
EVHTTP_REQ_DELETE);
|
||||
|
||||
TAILQ_INIT(&http->sockets);
|
||||
TAILQ_INIT(&http->callbacks);
|
||||
@ -2988,6 +3041,12 @@ evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size)
|
||||
http->default_max_body_size = max_body_size;
|
||||
}
|
||||
|
||||
void
|
||||
evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods)
|
||||
{
|
||||
http->allowed_methods = methods;
|
||||
}
|
||||
|
||||
int
|
||||
evhttp_set_cb(struct evhttp *http, const char *uri,
|
||||
void (*cb)(struct evhttp_request *, void *), void *cbarg)
|
||||
@ -3171,6 +3230,12 @@ evhttp_request_get_command(const struct evhttp_request *req) {
|
||||
return (req->type);
|
||||
}
|
||||
|
||||
int
|
||||
evhttp_request_get_response_code(const struct evhttp_request *req)
|
||||
{
|
||||
return req->response_code;
|
||||
}
|
||||
|
||||
/** Returns the input headers */
|
||||
struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req)
|
||||
{
|
||||
@ -3371,7 +3436,7 @@ bind_socket_ai(struct evutil_addrinfo *ai, int reuse)
|
||||
evutil_make_listen_socket_reuseable(fd);
|
||||
|
||||
if (ai != NULL) {
|
||||
r = bind(fd, ai->ai_addr, ai->ai_addrlen);
|
||||
r = bind(fd, ai->ai_addr, (ev_socklen_t)ai->ai_addrlen);
|
||||
if (r == -1)
|
||||
goto out;
|
||||
}
|
||||
@ -3563,7 +3628,7 @@ bracket_addr_ok(const char *s, const char *eos)
|
||||
} else {
|
||||
/* IPv6, or junk */
|
||||
char buf[64];
|
||||
int n_chars = eos-s-2;
|
||||
ev_ssize_t n_chars = eos-s-2;
|
||||
struct in6_addr in6;
|
||||
if (n_chars >= 64) /* way too long */
|
||||
return 0;
|
||||
|
@ -57,6 +57,9 @@ struct event_base;
|
||||
#define HTTP_NOTMODIFIED 304 /**< page was not modified from last */
|
||||
#define HTTP_BADREQUEST 400 /**< invalid http request was made */
|
||||
#define HTTP_NOTFOUND 404 /**< could not find content for uri */
|
||||
#define HTTP_BADMETHOD 405 /**< method not allowed for this uri */
|
||||
#define HTTP_INTERNAL 500 /**< internal error */
|
||||
#define HTTP_NOTIMPLEMENTED 501 /**< not implemented */
|
||||
#define HTTP_SERVUNAVAIL 503 /**< the server is not available */
|
||||
|
||||
struct evhttp;
|
||||
@ -183,6 +186,19 @@ void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_siz
|
||||
/** XXX Document. */
|
||||
void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size);
|
||||
|
||||
/**
|
||||
Sets the what HTTP methods are supported in requests accepted by this
|
||||
server, and passed to user callbacks.
|
||||
|
||||
If not supported they will generate a "405 Method not allowed" response.
|
||||
|
||||
By default this includes the following methods: GET, POST, HEAD, PUT, DELETE
|
||||
|
||||
@param http the http server on which to set the methods
|
||||
@param methods bit mask constructed from evhttp_cmd_type values
|
||||
*/
|
||||
void evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods);
|
||||
|
||||
/**
|
||||
Set a callback for a specified URI
|
||||
|
||||
@ -327,13 +343,23 @@ void evhttp_send_reply_end(struct evhttp_request *req);
|
||||
* Interfaces for making requests
|
||||
*/
|
||||
|
||||
/** the different request types supported by evhttp */
|
||||
/** The different request types supported by evhttp. These are as specified
|
||||
* in RFC2616, except for PATCH which is specified by RFC5789.
|
||||
*
|
||||
* By default, only some of these methods are accepted and passed to user
|
||||
* callbacks; use evhttp_set_allowed_methods() to change which methods
|
||||
* are allowed.
|
||||
*/
|
||||
enum evhttp_cmd_type {
|
||||
EVHTTP_REQ_GET,
|
||||
EVHTTP_REQ_POST,
|
||||
EVHTTP_REQ_HEAD,
|
||||
EVHTTP_REQ_PUT,
|
||||
EVHTTP_REQ_DELETE
|
||||
EVHTTP_REQ_GET = 1 << 0,
|
||||
EVHTTP_REQ_POST = 1 << 1,
|
||||
EVHTTP_REQ_HEAD = 1 << 2,
|
||||
EVHTTP_REQ_PUT = 1 << 3,
|
||||
EVHTTP_REQ_DELETE = 1 << 4,
|
||||
EVHTTP_REQ_OPTIONS = 1 << 5,
|
||||
EVHTTP_REQ_TRACE = 1 << 6,
|
||||
EVHTTP_REQ_CONNECT = 1 << 7,
|
||||
EVHTTP_REQ_PATCH = 1 << 8
|
||||
};
|
||||
|
||||
/** a request object can represent either a request or a reply */
|
||||
@ -391,7 +417,7 @@ int evhttp_request_is_owned(struct evhttp_request *req);
|
||||
/**
|
||||
* Returns the connection object associated with the request or NULL
|
||||
*
|
||||
* The server needs to either free the request explicitly or call
|
||||
* The user needs to either free the request explicitly or call
|
||||
* evhttp_send_reply_end().
|
||||
*/
|
||||
struct evhttp_connection *evhttp_request_get_connection(struct evhttp_request *req);
|
||||
@ -466,11 +492,13 @@ int evhttp_make_request(struct evhttp_connection *evcon,
|
||||
*/
|
||||
void evhttp_cancel_request(struct evhttp_request *req);
|
||||
|
||||
|
||||
/** Returns the request URI */
|
||||
const char *evhttp_request_get_uri(const struct evhttp_request *req);
|
||||
/** Returns the request command */
|
||||
enum evhttp_cmd_type evhttp_request_get_command(const struct evhttp_request *req);
|
||||
|
||||
int evhttp_request_get_response_code(const struct evhttp_request *req);
|
||||
|
||||
/** Returns the input headers */
|
||||
struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req);
|
||||
/** Returns the output headers */
|
||||
|
@ -526,6 +526,8 @@ start_accepting(struct accepting_socket *as)
|
||||
goto report_err;
|
||||
}
|
||||
|
||||
/* XXXX It turns out we need to do this again later. Does this call
|
||||
* have any effect? */
|
||||
setsockopt(s, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
|
||||
(char *)&as->lev->fd, sizeof(&as->lev->fd));
|
||||
|
||||
@ -609,6 +611,12 @@ accepted_socket_invoke_user_cb(struct deferred_cb *dcb, void *arg)
|
||||
sock = as->s;
|
||||
cb = lev->cb;
|
||||
as->s = INVALID_SOCKET;
|
||||
|
||||
/* We need to call this so getsockname, getpeername, and
|
||||
* shutdown work correctly on the accepted socket. */
|
||||
/* XXXX handle error? */
|
||||
setsockopt(as->s, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
|
||||
(char *)&as->lev->fd, sizeof(&as->lev->fd));
|
||||
}
|
||||
data = lev->user_data;
|
||||
|
||||
|
14
signal.c
14
signal.c
@ -87,8 +87,8 @@
|
||||
#define __cdecl
|
||||
#endif
|
||||
|
||||
static int evsig_add(struct event_base *, int, short, short, void *);
|
||||
static int evsig_del(struct event_base *, int, short, short, void *);
|
||||
static int evsig_add(struct event_base *, evutil_socket_t, short, short, void *);
|
||||
static int evsig_del(struct event_base *, evutil_socket_t, short, short, void *);
|
||||
|
||||
static const struct eventop evsigops = {
|
||||
"signal",
|
||||
@ -278,7 +278,7 @@ _evsig_set_handler(struct event_base *base,
|
||||
}
|
||||
|
||||
static int
|
||||
evsig_add(struct event_base *base, int evsignal, short old, short events, void *p)
|
||||
evsig_add(struct event_base *base, evutil_socket_t evsignal, short old, short events, void *p)
|
||||
{
|
||||
struct evsig_info *sig = &base->sig;
|
||||
(void)p;
|
||||
@ -301,8 +301,8 @@ evsig_add(struct event_base *base, int evsignal, short old, short events, void *
|
||||
evsig_base_fd = base->sig.ev_signal_pair[0];
|
||||
EVSIGBASE_UNLOCK();
|
||||
|
||||
event_debug(("%s: %d: changing signal handler", __func__, evsignal));
|
||||
if (_evsig_set_handler(base, evsignal, evsig_handler) == -1) {
|
||||
event_debug(("%s: %d: changing signal handler", __func__, (int)evsignal));
|
||||
if (_evsig_set_handler(base, (int)evsignal, evsig_handler) == -1) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -355,7 +355,7 @@ _evsig_restore_handler(struct event_base *base, int evsignal)
|
||||
}
|
||||
|
||||
static int
|
||||
evsig_del(struct event_base *base, int evsignal, short old, short events, void *p)
|
||||
evsig_del(struct event_base *base, evutil_socket_t evsignal, short old, short events, void *p)
|
||||
{
|
||||
EVUTIL_ASSERT(evsignal >= 0 && evsignal < NSIG);
|
||||
|
||||
@ -366,7 +366,7 @@ evsig_del(struct event_base *base, int evsignal, short old, short events, void *
|
||||
--base->sig.ev_n_signals_added;
|
||||
EVSIGBASE_UNLOCK();
|
||||
|
||||
return (_evsig_restore_handler(base, evsignal));
|
||||
return (_evsig_restore_handler(base, (int)evsignal));
|
||||
}
|
||||
|
||||
static void __cdecl
|
||||
|
@ -94,8 +94,8 @@ static struct timeval tcalled;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define write(fd,buf,len) send((fd),(buf),(len),0)
|
||||
#define read(fd,buf,len) recv((fd),(buf),(len),0)
|
||||
#define write(fd,buf,len) send((fd),(buf),(int)(len),0)
|
||||
#define read(fd,buf,len) recv((fd),(buf),(int)(len),0)
|
||||
#endif
|
||||
|
||||
struct basic_cb_args
|
||||
@ -1272,7 +1272,7 @@ test_event_base_new(void *ptr)
|
||||
struct event ev1;
|
||||
struct basic_cb_args args;
|
||||
|
||||
int towrite = strlen(TEST1)+1;
|
||||
int towrite = (int)strlen(TEST1)+1;
|
||||
int len = write(data->pair[0], TEST1, towrite);
|
||||
|
||||
if (len < 0)
|
||||
@ -1646,9 +1646,9 @@ evtag_int_test(void *ptr)
|
||||
|
||||
for (i = 0; i < TEST_MAX_INT; i++) {
|
||||
int oldlen, newlen;
|
||||
oldlen = EVBUFFER_LENGTH(tmp);
|
||||
oldlen = (int)EVBUFFER_LENGTH(tmp);
|
||||
evtag_encode_int(tmp, integers[i]);
|
||||
newlen = EVBUFFER_LENGTH(tmp);
|
||||
newlen = (int)EVBUFFER_LENGTH(tmp);
|
||||
TT_BLATHER(("encoded 0x%08x with %d bytes",
|
||||
(unsigned)integers[i], newlen - oldlen));
|
||||
big_int = integers[i];
|
||||
@ -1723,9 +1723,9 @@ evtag_tag_encoding(void *ptr)
|
||||
|
||||
for (i = 0; i < TEST_MAX_INT; i++) {
|
||||
int oldlen, newlen;
|
||||
oldlen = EVBUFFER_LENGTH(tmp);
|
||||
oldlen = (int)EVBUFFER_LENGTH(tmp);
|
||||
evtag_encode_tag(tmp, integers[i]);
|
||||
newlen = EVBUFFER_LENGTH(tmp);
|
||||
newlen = (int)EVBUFFER_LENGTH(tmp);
|
||||
TT_BLATHER(("encoded 0x%08x with %d bytes",
|
||||
(unsigned)integers[i], newlen - oldlen));
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ extern int called;
|
||||
extern struct event_base *global_base;
|
||||
extern int in_legacy_test_wrapper;
|
||||
|
||||
evutil_socket_t regress_make_tmpfile(const void *data, size_t datalen);
|
||||
int regress_make_tmpfile(const void *data, size_t datalen);
|
||||
|
||||
struct basic_test_data {
|
||||
struct event_base *base;
|
||||
|
@ -139,17 +139,17 @@ evbuffer_get_waste(struct evbuffer *buf, size_t *allocatedp, size_t *wastedp, si
|
||||
a += chain->buffer_len;
|
||||
u += chain->off;
|
||||
if (chain->next && chain->next->off)
|
||||
w += chain->buffer_len - (chain->misalign + chain->off);
|
||||
w += (size_t)(chain->buffer_len - (chain->misalign + chain->off));
|
||||
chain = chain->next;
|
||||
}
|
||||
/* subsequent nonempty chains */
|
||||
while (chain && chain->off) {
|
||||
++n;
|
||||
a += chain->buffer_len;
|
||||
w += chain->misalign;
|
||||
w += (size_t)chain->misalign;
|
||||
u += chain->off;
|
||||
if (chain->next && chain->next->off)
|
||||
w += chain->buffer_len - (chain->misalign + chain->off);
|
||||
w += (size_t) (chain->buffer_len - (chain->misalign + chain->off));
|
||||
chain = chain->next;
|
||||
}
|
||||
/* subsequent empty chains */
|
||||
@ -491,7 +491,7 @@ test_evbuffer_expand(void *ptr)
|
||||
buf = evbuffer_new();
|
||||
evbuffer_add(buf, data, 400);
|
||||
{
|
||||
int n = buf->first->buffer_len - buf->first->off - 1;
|
||||
int n = (int)(buf->first->buffer_len - buf->first->off - 1);
|
||||
tt_assert(n < (int)sizeof(data));
|
||||
evbuffer_add(buf, data, n);
|
||||
}
|
||||
@ -595,7 +595,8 @@ test_evbuffer_add_file(void *ptr)
|
||||
const char *data = "this is what we add as file system data.";
|
||||
size_t datalen;
|
||||
const char *compare;
|
||||
evutil_socket_t fd = -1, pair[2] = {-1, -1};
|
||||
int fd = -1;
|
||||
evutil_socket_t pair[2] = {-1, -1};
|
||||
int r=0, n_written=0;
|
||||
|
||||
/* Add a test for a big file. XXXX */
|
||||
@ -645,7 +646,7 @@ test_evbuffer_add_file(void *ptr)
|
||||
tt_int_op(n_written, ==, datalen);
|
||||
|
||||
evbuffer_validate(src);
|
||||
tt_int_op(evbuffer_read(src, pair[1], strlen(data)), ==, datalen);
|
||||
tt_int_op(evbuffer_read(src, pair[1], (int)strlen(data)), ==, datalen);
|
||||
evbuffer_validate(src);
|
||||
compare = (char *)evbuffer_pullup(src, datalen);
|
||||
tt_assert(compare != NULL);
|
||||
|
@ -189,7 +189,7 @@ static void
|
||||
wm_readcb(struct bufferevent *bev, void *arg)
|
||||
{
|
||||
struct evbuffer *evbuf = evbuffer_new();
|
||||
int len = evbuffer_get_length(bev->input);
|
||||
int len = (int)evbuffer_get_length(bev->input);
|
||||
static int nread;
|
||||
|
||||
assert(len >= 10 && len <= 20);
|
||||
|
@ -97,7 +97,7 @@ test_edgetriggered(void *et)
|
||||
|
||||
called = was_et = 0;
|
||||
|
||||
send(pair[0], test, strlen(test)+1, 0);
|
||||
send(pair[0], test, (int)strlen(test)+1, 0);
|
||||
shutdown(pair[0], SHUT_WR);
|
||||
|
||||
/* Initalize the event library */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -107,7 +107,7 @@ static void dnslogcb(int w, const char *m)
|
||||
}
|
||||
|
||||
/* creates a temporary file with the data in it */
|
||||
evutil_socket_t
|
||||
int
|
||||
regress_make_tmpfile(const void *data, size_t datalen)
|
||||
{
|
||||
#ifndef WIN32
|
||||
@ -147,7 +147,7 @@ regress_make_tmpfile(const void *data, size_t datalen)
|
||||
if (tries == 0)
|
||||
return (-1);
|
||||
written = 0;
|
||||
WriteFile(h, data, datalen, &written, NULL);
|
||||
WriteFile(h, data, (DWORD)datalen, &written, NULL);
|
||||
/* Closing the fd returned by this function will indeed close h. */
|
||||
return _open_osfhandle((intptr_t)h,_O_RDONLY);
|
||||
#endif
|
||||
|
@ -602,7 +602,7 @@ end:
|
||||
}
|
||||
|
||||
struct example_struct {
|
||||
long a;
|
||||
const char *a;
|
||||
const char *b;
|
||||
long c;
|
||||
};
|
||||
@ -612,11 +612,11 @@ test_evutil_upcast(void *arg)
|
||||
{
|
||||
struct example_struct es1;
|
||||
const char **cp;
|
||||
es1.a = 5;
|
||||
es1.a = "World";
|
||||
es1.b = "Hello";
|
||||
es1.c = -99;
|
||||
|
||||
tt_int_op(evutil_offsetof(struct example_struct, b), ==, sizeof(long));
|
||||
tt_int_op(evutil_offsetof(struct example_struct, b), ==, sizeof(char*));
|
||||
|
||||
cp = &es1.b;
|
||||
tt_ptr_op(EVUTIL_UPCAST(cp, struct example_struct, b), ==, &es1);
|
||||
|
@ -143,7 +143,7 @@ main(int argc, char **argv)
|
||||
struct event* timeout;
|
||||
struct event_base* base;
|
||||
|
||||
int pair[2];
|
||||
evutil_socket_t pair[2];
|
||||
int res;
|
||||
struct timeval tv;
|
||||
struct cpu_usage_timer timer;
|
||||
|
@ -62,7 +62,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
struct event ev;
|
||||
const char *test = "test string";
|
||||
int pair[2];
|
||||
evutil_socket_t pair[2];
|
||||
|
||||
#ifdef WIN32
|
||||
WORD wVersionRequested;
|
||||
@ -78,7 +78,7 @@ main(int argc, char **argv)
|
||||
return (1);
|
||||
|
||||
|
||||
send(pair[0], test, strlen(test)+1, 0);
|
||||
send(pair[0], test, (int)strlen(test)+1, 0);
|
||||
shutdown(pair[0], SHUT_WR);
|
||||
|
||||
/* Initalize the event library */
|
||||
|
@ -33,7 +33,7 @@
|
||||
#define __func__ _EVENT___func__
|
||||
#endif
|
||||
|
||||
int pair[2];
|
||||
evutil_socket_t pair[2];
|
||||
int test_okay = 1;
|
||||
int called = 0;
|
||||
|
||||
@ -43,7 +43,7 @@ write_cb(evutil_socket_t fd, short event, void *arg)
|
||||
const char *test = "test string";
|
||||
int len;
|
||||
|
||||
len = send(fd, test, strlen(test) + 1, 0);
|
||||
len = send(fd, test, (int)strlen(test) + 1, 0);
|
||||
|
||||
printf("%s: write %d%s\n", __func__,
|
||||
len, len ? "" : " - means EOF");
|
||||
|
@ -66,7 +66,7 @@ struct idx_info {
|
||||
};
|
||||
|
||||
struct win32op {
|
||||
int fd_setsz;
|
||||
unsigned num_fds_in_fd_sets;
|
||||
int resize_out_sets;
|
||||
struct win_fd_set *readset_in;
|
||||
struct win_fd_set *writeset_in;
|
||||
@ -97,21 +97,21 @@ struct eventop win32ops = {
|
||||
#define FD_SET_ALLOC_SIZE(n) ((sizeof(struct win_fd_set) + ((n)-1)*sizeof(SOCKET)))
|
||||
|
||||
static int
|
||||
realloc_fd_sets(struct win32op *op, size_t new_size)
|
||||
grow_fd_sets(struct win32op *op, unsigned new_num_fds)
|
||||
{
|
||||
size_t size;
|
||||
|
||||
EVUTIL_ASSERT(new_size >= op->readset_in->fd_count &&
|
||||
new_size >= op->writeset_in->fd_count);
|
||||
EVUTIL_ASSERT(new_size >= 1);
|
||||
EVUTIL_ASSERT(new_num_fds >= op->readset_in->fd_count &&
|
||||
new_num_fds >= op->writeset_in->fd_count);
|
||||
EVUTIL_ASSERT(new_num_fds >= 1);
|
||||
|
||||
size = FD_SET_ALLOC_SIZE(new_size);
|
||||
size = FD_SET_ALLOC_SIZE(new_num_fds);
|
||||
if (!(op->readset_in = mm_realloc(op->readset_in, size)))
|
||||
return (-1);
|
||||
if (!(op->writeset_in = mm_realloc(op->writeset_in, size)))
|
||||
return (-1);
|
||||
op->resize_out_sets = 1;
|
||||
op->fd_setsz = new_size;
|
||||
op->num_fds_in_fd_sets = new_num_fds;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -126,8 +126,8 @@ do_fd_set(struct win32op *op, struct idx_info *ent, evutil_socket_t s, int read)
|
||||
if (ent->write_pos_plus1 > 0)
|
||||
return (0);
|
||||
}
|
||||
if ((int)set->fd_count == op->fd_setsz) {
|
||||
if (realloc_fd_sets(op, op->fd_setsz*2))
|
||||
if (set->fd_count == op->num_fds_in_fd_sets) {
|
||||
if (grow_fd_sets(op, op->num_fds_in_fd_sets*2))
|
||||
return (-1);
|
||||
/* set pointer will have changed and needs reiniting! */
|
||||
set = read ? op->readset_in : op->writeset_in;
|
||||
@ -180,7 +180,7 @@ win32_init(struct event_base *_base)
|
||||
size_t size;
|
||||
if (!(winop = mm_calloc(1, sizeof(struct win32op))))
|
||||
return NULL;
|
||||
winop->fd_setsz = NEVENT;
|
||||
winop->num_fds_in_fd_sets = NEVENT;
|
||||
size = FD_SET_ALLOC_SIZE(NEVENT);
|
||||
if (!(winop->readset_in = mm_malloc(size)))
|
||||
goto err;
|
||||
@ -279,7 +279,7 @@ win32_dispatch(struct event_base *base, struct timeval *tv)
|
||||
SOCKET s;
|
||||
|
||||
if (win32op->resize_out_sets) {
|
||||
size_t size = FD_SET_ALLOC_SIZE(win32op->fd_setsz);
|
||||
size_t size = FD_SET_ALLOC_SIZE(win32op->num_fds_in_fd_sets);
|
||||
if (!(win32op->readset_out = mm_realloc(win32op->readset_out, size)))
|
||||
return (-1);
|
||||
if (!(win32op->exset_out = mm_realloc(win32op->exset_out, size)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user