Attached is a two-part patch. First, it makes evhttp.h portable on
mingw and other systems w/o TAILQ_ENTRY by defining the macro itself
if a system header hasn't already defined it. This is the same as
what event.h already does.
The second part is a repeat of the patch I submitted a couple of days
ago that lets libevent's http parser more gracefully handle servers
that don't use the proper \r\n linebreak. Some tracker servers only
return \n, which breaks the current libevent's parsing.
Those servers are causing me quite a headache, but there was no
response to my initial patch. Is this something that's likely to
be considered for use in libevent?
Charles
Index: http.c
===================================================================
--- http.c (revision 400)
+++ http.c (working copy)
@@ -1175,58 +1175,55 @@
int
evhttp_parse_lines(struct evhttp_request *req, struct evbuffer* buffer)
{
- u_char *endp;
+ char *line;
int done = 0;
struct evkeyvalq* headers = req->input_headers;
- while ((endp = evbuffer_find(buffer, (u_char *)"\r\n", 2)) != NULL) {
+ while ((line = evbuffer_readline(buffer)) != NULL) {
char *skey, *svalue;
- if (strncmp((char *)EVBUFFER_DATA(buffer), "\r\n", 2) == 0) {
- evbuffer_drain(buffer, 2);
- /* Last header - Done */
+ if (*line == '\0') { /* Last header - Done */
done = 1;
+ free (line);
break;
}
- *endp = '\0';
- endp += 2;
-
/* Processing of header lines */
if (req->got_firstline == 0) {
switch (req->kind) {
case EVHTTP_REQUEST:
- if (evhttp_parse_request_line(req,
- (char *)EVBUFFER_DATA(buffer)) == -1)
- return (-1);
+ if (evhttp_parse_request_line(req, line) == -1)
+ goto error;
break;
case EVHTTP_RESPONSE:
- if (evhttp_parse_response_line(req,
- (char *)EVBUFFER_DATA(buffer)) == -1)
- return (-1);
+ if (evhttp_parse_response_line(req, line) == -1)
+ goto error;
break;
default:
- return (-1);
+ goto error;
}
req->got_firstline = 1;
} else {
/* Regular header */
- svalue = (char *)EVBUFFER_DATA(buffer);
+ svalue = line;
skey = strsep(&svalue, ":");
if (svalue == NULL)
- return (-1);
+ goto error;
svalue += strspn(svalue, " ");
if (evhttp_add_header(headers, skey, svalue) == -1)
- return (-1);
+ goto error;
}
- /* Move the uncompleted headers forward */
- evbuffer_drain(buffer, endp - EVBUFFER_DATA(buffer));
+ free (line);
}
return (done);
+
+ error:
+ free (line);
+ return (-1);
}
static int
Index: evhttp.h
===================================================================
--- evhttp.h (revision 400)
+++ evhttp.h (working copy)
@@ -38,6 +38,27 @@
#undef WIN32_LEAN_AND_MEAN
#endif
+/* Fix so that ppl dont have to run with <sys/queue.h> */
+#ifndef TAILQ_ENTRY
+#define _EVENT_DEFINED_TQENTRY
+#define TAILQ_ENTRY(type) \
+struct { \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
+}
+#endif /* !TAILQ_ENTRY */
+#ifndef RB_ENTRY
+#define _EVENT_DEFINED_RBENTRY
+#define RB_ENTRY(type) \
+struct { \
+ struct type *rbe_left; /* left element */ \
+ struct type *rbe_right; /* right element */ \
+ struct type *rbe_parent; /* parent element */ \
+ int rbe_color; /* node color */ \
+}
+#endif /* !RB_ENTRY */
+
+
/*
* Basic support for HTTP serving.
*
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users