r14507@tombo: nickm | 2008-02-26 15:23:44 -0500

Patch from Tani Hosokawa: make some functions in http.c threadsafe.  Also, note some functions in http.c that still are not threadsafe.


svn:r671
This commit is contained in:
Nick Mathewson 2008-02-26 20:24:29 +00:00
parent bd31d00fc1
commit e7ad549390
2 changed files with 12 additions and 11 deletions

View File

@ -51,7 +51,7 @@ Changes in current version:
o introduce evhttp_accept_socket() to accept from an already created socket
o include Content-Length in reply for HTTP/1.0 requests with keep-alive
o increase listen queue for http sockets to 128; if that is not enough the evhttp_accpet_socket() api can be used with a prepared socket.
o Patch from Tani Hosokawa: make some functions in http.c threadsafe.
Changes in 1.4.0:
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.

19
http.c
View File

@ -188,10 +188,8 @@ strsep(char **s, const char *del)
#endif
static const char *
html_replace(char ch)
html_replace(char ch, char *buf)
{
static char buf[2];
switch (ch) {
case '<':
return "&lt;";
@ -226,15 +224,16 @@ evhttp_htmlescape(const char *html)
{
int i, new_size = 0, old_size = strlen(html);
char *escaped_html, *p;
char scratch_space[2];
for (i = 0; i < old_size; ++i)
new_size += strlen(html_replace(html[i]));
new_size += strlen(html_replace(html[i], scratch_space));
p = escaped_html = event_malloc(new_size + 1);
if (escaped_html == NULL)
event_err(1, "%s: malloc(%d)", __func__, new_size + 1);
for (i = 0; i < old_size; ++i) {
const char *replaced = html_replace(html[i]);
const char *replaced = html_replace(html[i], scratch_space);
/* this is length checked */
strcpy(p, replaced);
p += strlen(replaced);
@ -314,7 +313,7 @@ static void
evhttp_make_header_request(struct evhttp_connection *evcon,
struct evhttp_request *req)
{
static char line[1024];
char line[1024];
const char *method;
evhttp_remove_header(req->output_headers, "Accept-Encoding");
@ -386,7 +385,7 @@ evhttp_maybe_add_content_length_header(struct evkeyvalq *headers,
{
if (evhttp_find_header(headers, "Transfer-Encoding") == NULL &&
evhttp_find_header(headers, "Content-Length") == NULL) {
static char len[12]; /* XXX: not thread-safe */
char len[12];
snprintf(len, sizeof(len), "%ld", content_length);
evhttp_add_header(headers, "Content-Length", len);
}
@ -400,7 +399,7 @@ static void
evhttp_make_header_response(struct evhttp_connection *evcon,
struct evhttp_request *req)
{
static char line[1024];
char line[1024];
snprintf(line, sizeof(line), "HTTP/%d.%d %d %s\r\n",
req->major, req->minor, req->response_code,
req->response_code_line);
@ -442,7 +441,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
void
evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
{
static char line[1024];
char line[1024];
struct evkeyval *header;
/*
@ -476,6 +475,7 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
int
evhttp_hostportfile(char *url, char **phost, u_short *pport, char **pfile)
{
/* XXX not threadsafe. */
static char host[1024];
static char file[1024];
char *p;
@ -2387,6 +2387,7 @@ name_from_addr(struct sockaddr *sa, socklen_t salen,
char **phost, char **pport)
{
#ifdef HAVE_GETNAMEINFO
/* XXXX not threadsafe. */
static char ntop[NI_MAXHOST];
static char strport[NI_MAXSERV];
int ni_result;