mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
3f8c7cd035
Previously we used include-guards with names like _EVENT2_EVENT_H_. But C reserves macros beginning with an underscore for use by the system. This patch converts all include guards for files like include/event2/<fname.h> to be of form EVENT2_<FNAME_H>_INCLUDED_, and all Libevent 1.x headers in include/<fname.h> to be of the form EVENT1_<FNAME_H>_INCLUDED_, and all internal libevent headers with names like <fname.h> to the form <FNAME_H>_INCLUDED_. FNAME_H is here derived from fname.h by replacing every non-macro-usable character in fname.h with an underscore, and putting every remaining character in uppercase. This is an automatic conversion. The script that produced was made by running the following script over all header files: ===== #!/usr/bin/perl -w # Run this on every .h file except config.h, sys/queue.h, WIN32/event2/event-config.h use strict; my %macros = (); my %skipped = (); FILE: for my $fn (@ARGV) { my $f = $fn; if ($fn !~ /^\.\//) { $f = "./$fn"; } if ($f eq './config.h' or $f =~ m#/tree.h$# or $f =~ m#/queue.h# or $f =~ m#/event-config.h# or $f =~ m#/evconfig-private.h#) { $skipped{$fn} = 1; next FILE; } $skipped{$fn} = 0; open(F, $fn); while (<F>) { if (/^#ifndef ([A-Za-z0-9_]+)/) { $macros{$fn} = $1; next FILE; } } } print "#!/usr/bin/perl -w -i -p\n\n"; for my $fn (@ARGV) { if (! exists $macros{$fn}) { print "# No macro known for $fn!\n" if (!$skipped{$fn}); } else { if ($macros{$fn} !~ /_H_?$/) { print "# Weird macro for $fn...\n"; } my $goodmacro = uc $fn; $goodmacro =~ s#^\./##; $goodmacro =~ s#INCLUDE/EVENT2#EVENT2#; $goodmacro =~ s#INCLUDE/#EVENT1_#; $goodmacro =~ s#TEST/##; $goodmacro =~ s#[\/\-\.]#_#g; print "s/(?<![A-Za-z0-9_])$macros{$fn}(?![A-Za-z0-9_])/${goodmacro}_INCLUDED_/g;\n" } } === And then running the script below that it generated over all === the .h files again #!/usr/bin/perl -w -i -p s/(?<![A-Za-z0-9_])_BUFFEREVENT_INTERNAL_H_(?![A-Za-z0-9_])/BUFFEREVENT_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_CHANGELIST_H_(?![A-Za-z0-9_])/CHANGELIST_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_DEFER_INTERNAL_H_(?![A-Za-z0-9_])/DEFER_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVBUFFER_INTERNAL_H_(?![A-Za-z0-9_])/EVBUFFER_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT_INTERNAL_H_(?![A-Za-z0-9_])/EVENT_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVMAP_H_(?![A-Za-z0-9_])/EVMAP_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVRPC_INTERNAL_H_(?![A-Za-z0-9_])/EVRPC_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVSIGNAL_H_(?![A-Za-z0-9_])/EVSIGNAL_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVTHREAD_INTERNAL_H_(?![A-Za-z0-9_])/EVTHREAD_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT_HT_H(?![A-Za-z0-9_])/HT_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_HTTP_INTERNAL_H_(?![A-Za-z0-9_])/HTTP_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVDNS_H_(?![A-Za-z0-9_])/EVENT1_EVDNS_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT_H_(?![A-Za-z0-9_])/EVENT1_EVENT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_BUFFER_H_(?![A-Za-z0-9_])/EVENT2_BUFFER_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_BUFFER_COMPAT_H_(?![A-Za-z0-9_])/EVENT2_BUFFER_COMPAT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_BUFFEREVENT_H_(?![A-Za-z0-9_])/EVENT2_BUFFEREVENT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_BUFFEREVENT_COMPAT_H_(?![A-Za-z0-9_])/EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_BUFFEREVENT_SSL_H_(?![A-Za-z0-9_])/EVENT2_BUFFEREVENT_SSL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_BUFFEREVENT_STRUCT_H_(?![A-Za-z0-9_])/EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_DNS_H_(?![A-Za-z0-9_])/EVENT2_DNS_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_DNS_COMPAT_H_(?![A-Za-z0-9_])/EVENT2_DNS_COMPAT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_DNS_STRUCT_H_(?![A-Za-z0-9_])/EVENT2_DNS_STRUCT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_EVENT_H_(?![A-Za-z0-9_])/EVENT2_EVENT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_EVENT_COMPAT_H_(?![A-Za-z0-9_])/EVENT2_EVENT_COMPAT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_EVENT_STRUCT_H_(?![A-Za-z0-9_])/EVENT2_EVENT_STRUCT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_HTTP_H_(?![A-Za-z0-9_])/EVENT2_HTTP_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_HTTP_COMPAT_H_(?![A-Za-z0-9_])/EVENT2_HTTP_COMPAT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_HTTP_STRUCT_H_(?![A-Za-z0-9_])/EVENT2_HTTP_STRUCT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_EVENT_KEYVALQ_STRUCT_H_(?![A-Za-z0-9_])/EVENT2_KEYVALQ_STRUCT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_LISTENER_H_(?![A-Za-z0-9_])/EVENT2_LISTENER_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_RPC_H_(?![A-Za-z0-9_])/EVENT2_RPC_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_RPC_COMPAT_H_(?![A-Za-z0-9_])/EVENT2_RPC_COMPAT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_RPC_STRUCT_H_(?![A-Za-z0-9_])/EVENT2_RPC_STRUCT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_TAG_H_(?![A-Za-z0-9_])/EVENT2_TAG_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_TAG_COMPAT_H_(?![A-Za-z0-9_])/EVENT2_TAG_COMPAT_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_THREAD_H_(?![A-Za-z0-9_])/EVENT2_THREAD_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT2_UTIL_H_(?![A-Za-z0-9_])/EVENT2_UTIL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVHTTP_H_(?![A-Za-z0-9_])/EVENT1_EVHTTP_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVRPC_H_(?![A-Za-z0-9_])/EVENT1_EVRPC_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVUTIL_H_(?![A-Za-z0-9_])/EVENT1_EVUTIL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT_IOCP_INTERNAL_H(?![A-Za-z0-9_])/IOCP_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT_IPV6_INTERNAL_H(?![A-Za-z0-9_])/IPV6_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_LOG_H_(?![A-Za-z0-9_])/LOG_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_MIN_HEAP_H_(?![A-Za-z0-9_])/MINHEAP_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT_MM_INTERNAL_H(?![A-Za-z0-9_])/MM_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_RATELIM_INTERNAL_H_(?![A-Za-z0-9_])/RATELIM_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_STRLCPY_INTERNAL_H_(?![A-Za-z0-9_])/STRLCPY_INTERNAL_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_REGRESS_H_(?![A-Za-z0-9_])/REGRESS_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_TESTUTILS_H(?![A-Za-z0-9_])/REGRESS_TESTUTILS_H_INCLUDED_/g; # Weird macro for test/tinytest.h... s/(?<![A-Za-z0-9_])TINYTEST_H_INCLUDED_(?![A-Za-z0-9_])/TINYTEST_H_INCLUDED_/g; # No macro known for test/tinytest_local.h! # Weird macro for test/tinytest_macros.h... s/(?<![A-Za-z0-9_])TINYTEST_MACROS_H_INCLUDED_(?![A-Za-z0-9_])/TINYTEST_MACROS_H_INCLUDED_/g; s/(?<![A-Za-z0-9_])_EVENT_UTIL_INTERNAL_H(?![A-Za-z0-9_])/UTIL_INTERNAL_H_INCLUDED_/g;
201 lines
5.4 KiB
C
201 lines
5.4 KiB
C
/*
|
|
* Copyright 2001-2007 Niels Provos <provos@citi.umich.edu>
|
|
* Copyright 2007-2012 Niels Provos and Nick Mathewson
|
|
*
|
|
* This header file contains definitions for dealing with HTTP requests
|
|
* that are internal to libevent. As user of the library, you should not
|
|
* need to know about these.
|
|
*/
|
|
|
|
#ifndef HTTP_INTERNAL_H_INCLUDED_
|
|
#define HTTP_INTERNAL_H_INCLUDED_
|
|
|
|
#include "event2/event_struct.h"
|
|
#include "util-internal.h"
|
|
#include "defer-internal.h"
|
|
|
|
#define HTTP_CONNECT_TIMEOUT 45
|
|
#define HTTP_WRITE_TIMEOUT 50
|
|
#define HTTP_READ_TIMEOUT 50
|
|
|
|
#define HTTP_PREFIX "http://"
|
|
#define HTTP_DEFAULTPORT 80
|
|
|
|
enum message_read_status {
|
|
ALL_DATA_READ = 1,
|
|
MORE_DATA_EXPECTED = 0,
|
|
DATA_CORRUPTED = -1,
|
|
REQUEST_CANCELED = -2,
|
|
DATA_TOO_LONG = -3
|
|
};
|
|
|
|
enum evhttp_connection_error {
|
|
EVCON_HTTP_TIMEOUT,
|
|
EVCON_HTTP_EOF,
|
|
EVCON_HTTP_INVALID_HEADER,
|
|
EVCON_HTTP_BUFFER_ERROR,
|
|
EVCON_HTTP_REQUEST_CANCEL
|
|
};
|
|
|
|
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 */
|
|
EVCON_IDLE, /**< connection is established */
|
|
EVCON_READING_FIRSTLINE,/**< reading Request-Line (incoming conn) or
|
|
**< Status-Line (outgoing conn) */
|
|
EVCON_READING_HEADERS, /**< reading request/response headers */
|
|
EVCON_READING_BODY, /**< reading request/response body */
|
|
EVCON_READING_TRAILER, /**< reading request/response chunked trailer */
|
|
EVCON_WRITING /**< writing request/response headers/body */
|
|
};
|
|
|
|
struct event_base;
|
|
|
|
/* A client or server connection. */
|
|
struct evhttp_connection {
|
|
/* we use this tailq only if this connection was created for an http
|
|
* server */
|
|
TAILQ_ENTRY(evhttp_connection) next;
|
|
|
|
evutil_socket_t fd;
|
|
struct bufferevent *bufev;
|
|
|
|
struct event retry_ev; /* for retrying connects */
|
|
|
|
char *bind_address; /* address to use for binding the src */
|
|
u_short bind_port; /* local port for binding the src */
|
|
|
|
char *address; /* address to connect to */
|
|
u_short port;
|
|
|
|
size_t max_headers_size;
|
|
ev_uint64_t max_body_size;
|
|
|
|
int flags;
|
|
#define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */
|
|
#define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */
|
|
#define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */
|
|
|
|
struct timeval timeout; /* timeout for events */
|
|
int retry_cnt; /* retry count */
|
|
int retry_max; /* maximum number of retries */
|
|
struct timeval initial_retry_timeout; /* Timeout for low long to wait
|
|
* after first failing attempt
|
|
* before retry */
|
|
|
|
enum evhttp_connection_state state;
|
|
|
|
/* for server connections, the http server they are connected with */
|
|
struct evhttp *http_server;
|
|
|
|
TAILQ_HEAD(evcon_requestq, evhttp_request) requests;
|
|
|
|
void (*cb)(struct evhttp_connection *, void *);
|
|
void *cb_arg;
|
|
|
|
void (*closecb)(struct evhttp_connection *, void *);
|
|
void *closecb_arg;
|
|
|
|
struct deferred_cb read_more_deferred_cb;
|
|
|
|
struct event_base *base;
|
|
struct evdns_base *dns_base;
|
|
};
|
|
|
|
/* A callback for an http server */
|
|
struct evhttp_cb {
|
|
TAILQ_ENTRY(evhttp_cb) next;
|
|
|
|
char *what;
|
|
|
|
void (*cb)(struct evhttp_request *req, void *);
|
|
void *cbarg;
|
|
};
|
|
|
|
/* both the http server as well as the rpc system need to queue connections */
|
|
TAILQ_HEAD(evconq, evhttp_connection);
|
|
|
|
/* each bound socket is stored in one of these */
|
|
struct evhttp_bound_socket {
|
|
TAILQ_ENTRY(evhttp_bound_socket) next;
|
|
|
|
struct evconnlistener *listener;
|
|
};
|
|
|
|
/* server alias list item. */
|
|
struct evhttp_server_alias {
|
|
TAILQ_ENTRY(evhttp_server_alias) next;
|
|
|
|
char *alias; /* the server alias. */
|
|
};
|
|
|
|
struct evhttp {
|
|
/* Next vhost, if this is a vhost. */
|
|
TAILQ_ENTRY(evhttp) next_vhost;
|
|
|
|
/* All listeners for this host */
|
|
TAILQ_HEAD(boundq, evhttp_bound_socket) sockets;
|
|
|
|
TAILQ_HEAD(httpcbq, evhttp_cb) callbacks;
|
|
|
|
/* All live connections on this host. */
|
|
struct evconq connections;
|
|
|
|
TAILQ_HEAD(vhostsq, evhttp) virtualhosts;
|
|
|
|
TAILQ_HEAD(aliasq, evhttp_server_alias) aliases;
|
|
|
|
/* NULL if this server is not a vhost */
|
|
char *vhost_pattern;
|
|
|
|
struct timeval timeout;
|
|
|
|
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 *);
|
|
void *gencbarg;
|
|
struct bufferevent* (*bevcb)(struct event_base *, void *);
|
|
void *bevcbarg;
|
|
|
|
struct event_base *base;
|
|
};
|
|
|
|
/* XXX most of these functions could be static. */
|
|
|
|
/* resets the connection; can be reused for more requests */
|
|
void evhttp_connection_reset(struct evhttp_connection *);
|
|
|
|
/* connects if necessary */
|
|
int evhttp_connection_connect(struct evhttp_connection *);
|
|
|
|
/* notifies the current request that it failed; resets connection */
|
|
void evhttp_connection_fail(struct evhttp_connection *,
|
|
enum evhttp_connection_error error);
|
|
|
|
enum message_read_status;
|
|
|
|
enum message_read_status evhttp_parse_firstline(struct evhttp_request *, struct evbuffer*);
|
|
enum message_read_status evhttp_parse_headers(struct evhttp_request *, struct evbuffer*);
|
|
|
|
void evhttp_start_read(struct evhttp_connection *);
|
|
|
|
/* response sending HTML the data in the buffer */
|
|
void evhttp_response_code(struct evhttp_request *, int, const char *);
|
|
void evhttp_send_page(struct evhttp_request *, struct evbuffer *);
|
|
|
|
#endif /* _HTTP_H */
|