summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-12-24 12:27:24 -0500
committerNick Mathewson <nickm@torproject.org>2013-12-24 12:27:24 -0500
commit471fbe3bafdbfe85e470700679f5efc3a032e015 (patch)
tree2e8d2fa4ca3fe59ee36e80f035fedefcaa2789f3
parenta3172a415b709d1df76b27ee86c738e4d8b6f87b (diff)
parentb0bd7fe1db93a1adde29587e12ed78726f962012 (diff)
downloadlibevent-471fbe3bafdbfe85e470700679f5efc3a032e015.tar.gz
Merge remote-tracking branch 'rbalint/from-forked-daapd'
-rw-r--r--http.c25
-rw-r--r--include/event2/http.h27
-rw-r--r--include/event2/http_struct.h8
3 files changed, 58 insertions, 2 deletions
diff --git a/http.c b/http.c
index e8672b77..826deffe 100644
--- a/http.c
+++ b/http.c
@@ -2150,6 +2150,14 @@ evhttp_read_header(struct evhttp_connection *evcon,
/* Disable reading for now */
bufferevent_disable(evcon->bufev, EV_READ);
+ /* Callback can shut down connection with negative return value */
+ if (req->header_cb != NULL) {
+ if ((*req->header_cb)(req, req->cb_arg) < 0) {
+ evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF);
+ return;
+ }
+ }
+
/* Done reading headers, do the real work */
switch (req->kind) {
case EVHTTP_REQUEST:
@@ -2658,7 +2666,8 @@ evhttp_send_reply_start(struct evhttp_request *req, int code,
}
void
-evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
+evhttp_send_reply_chunk_with_cb(struct evhttp_request *req, struct evbuffer *databuf,
+ void (*cb)(struct evhttp_connection *, void *), void *arg)
{
struct evhttp_connection *evcon = req->evcon;
struct evbuffer *output;
@@ -2680,10 +2689,15 @@ evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
if (req->chunked) {
evbuffer_add(output, "\r\n", 2);
}
- evhttp_write_buffer(evcon, NULL, NULL);
+ evhttp_write_buffer(evcon, cb, arg);
}
void
+evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
+{
+ evhttp_send_reply_chunk_with_cb(req, databuf, NULL, NULL);
+}
+void
evhttp_send_reply_end(struct evhttp_request *req)
{
struct evhttp_connection *evcon = req->evcon;
@@ -3813,6 +3827,13 @@ evhttp_request_set_chunked_cb(struct evhttp_request *req,
}
void
+evhttp_request_set_header_cb(struct evhttp_request *req,
+ int (*cb)(struct evhttp_request *, void *))
+{
+ req->header_cb = cb;
+}
+
+void
evhttp_request_set_error_cb(struct evhttp_request *req,
void (*cb)(enum evhttp_request_error, void *))
{
diff --git a/include/event2/http.h b/include/event2/http.h
index 956d9d6c..068120c7 100644
--- a/include/event2/http.h
+++ b/include/event2/http.h
@@ -38,6 +38,7 @@ extern "C" {
struct evbuffer;
struct event_base;
struct bufferevent;
+struct evhttp_connection;
/** @file event2/http.h
*
@@ -407,6 +408,23 @@ void evhttp_send_reply_start(struct evhttp_request *req, int code,
*/
void evhttp_send_reply_chunk(struct evhttp_request *req,
struct evbuffer *databuf);
+
+/**
+ Send another data chunk as part of an ongoing chunked reply.
+
+ The reply chunk consists of the data in databuf. After calling
+ evhttp_send_reply_chunk() databuf will be empty, but the buffer is
+ still owned by the caller and needs to be deallocated by the caller
+ if necessary.
+
+ @param req a request object
+ @param databuf the data chunk to send as part of the reply.
+ @param cb callback funcion
+ @param call back's argument.
+*/
+void evhttp_send_reply_chunk_with_cb(struct evhttp_request *, struct evbuffer *,
+ void (*cb)(struct evhttp_connection *, void *), void *arg);
+
/**
Complete a chunked reply, freeing the request as appropriate.
@@ -487,6 +505,15 @@ void evhttp_request_set_chunked_cb(struct evhttp_request *,
void (*cb)(struct evhttp_request *, void *));
/**
+ * Register callback for additional parsing of request headers.
+ * @param cb will be called after receiving and parsing the full header.
+ * It allows analyzing the header and possibly closing the connection
+ * by returning a value < 0.
+ */
+void evhttp_request_set_header_cb(struct evhttp_request *,
+ int (*cb)(struct evhttp_request *, void *));
+
+/**
* The different error types supported by evhttp
*
* @see evhttp_request_set_error_cb()
diff --git a/include/event2/http_struct.h b/include/event2/http_struct.h
index 25e19bd9..4ca196ee 100644
--- a/include/event2/http_struct.h
+++ b/include/event2/http_struct.h
@@ -120,6 +120,14 @@ struct {
* the regular callback.
*/
void (*chunk_cb)(struct evhttp_request *, void *);
+
+ /*
+ * Callback added for forked-daapd so they can collect ICY
+ * (shoutcast) metadata from the http header. If return
+ * int is negative the connection will be closed.
+ */
+ int (*header_cb)(struct evhttp_request *, void *);
+
/*
* Error callback - called when error is occured.
* @see evhttp_request_error for error types.