--- a/web_main.c Sun Jun 01 01:48:09 2008 +0300
+++ b/web_main.c Sun Jun 01 05:03:53 2008 +0300
@@ -8,8 +8,10 @@
#include <arpa/inet.h>
#include <signal.h>
-#include <event.h>
-#include <evhttp.h>
+#include <event2/event.h>
+#include <event2/event_compat.h>
+#include <event2/http.h>
+#include <event2/event_struct.h>
#include "render.h"
#include "render_remote.h"
@@ -18,6 +20,10 @@
#define CHUNK_SIZE 4096
#define OVERFLOW_BUFFER 4096
+
+// what event_base we're using
+static struct event_base *ev_base;
+
// what render node to use
static struct sockaddr_storage render_node;
@@ -33,9 +39,6 @@
};
void _render_cleanup (struct render_request *ctx) {
- // not interested anymore
- evhttp_connection_set_closecb(ctx->http_request->evcon, NULL, NULL);
-
// clean up
free(ctx);
}
@@ -47,7 +50,7 @@
render_remote_set_chunk_size(ctx->remote_ctx, CHUNK_SIZE, OVERFLOW_BUFFER);
// send headers
- evhttp_add_header(ctx->http_request->output_headers, "Content-Type", "image/png");
+ evhttp_add_header(evhttp_request_get_output_headers(ctx->http_request), "Content-Type", "image/png");
evhttp_send_reply_start(ctx->http_request, HTTP_OK, "OK");
ctx->headers_sent = 1;
@@ -94,7 +97,7 @@
_render_cleanup(ctx);
}
-void _render_http_lost (struct evhttp_connection *connection, void *arg) {
+void _render_http_lost (struct evhttp_request *req, void *arg) {
struct render_request *ctx = arg;
printf("render [%p]: lost http connection\n", ctx);
@@ -133,7 +136,7 @@
}
// set close cb
- evhttp_connection_set_closecb(request->evcon, &_render_http_lost, req_ctx);
+ evhttp_set_reply_abortcb(request, &_render_http_lost, req_ctx);
printf("render [%p]: started\n", req_ctx);
}
@@ -143,17 +146,34 @@
*/
void http_render (struct evhttp_request *request, void *arg) {
// gather some info about the request
- const char *uri = evhttp_request_uri(request);
+ const char *uri = evhttp_request_get_uri(request);
char *peer_address;
u_short peer_port;
- evhttp_connection_get_peer(request->evcon, &peer_address, &peer_port);
+ evhttp_request_get_peer(request, &peer_address, &peer_port);
// request arguments
u_int32_t img_w = 256, img_h = 256;
struct evkeyval *qarg;
struct evkeyvalq qargs;
+/*
+ enum query_arg_type {
+ QARG_END,
+ QARG_INT,
+ };
+
+ struct query_arg {
+ const char *qa_key;
+ enum query_arg_type qa_type;
+ void *qa_addr;
+ } arg_def[] = {
+ { "w", QARG_INT, &img_w },
+ { "h", QARG_INT, &img_h },
+ { NULL, QARG_END, NULL }
+ };
+*/
+
evhttp_parse_query(uri, &qargs);
TAILQ_FOREACH(qarg, &qargs, next) {
@@ -167,7 +187,7 @@
evhttp_clear_headers(&qargs);
// request log
- printf("REQ: [%s:%d] method=%d, uri=%s, img_w=%d, img_h=%d\n", peer_address, peer_port, request->type, uri, img_w, img_h);
+ printf("REQ: [%s:%d] method=%d, uri=%s, img_w=%d, img_h=%d\n", peer_address, peer_port, evhttp_request_get_type(request), uri, img_w, img_h);
// do it
_http_render_execute(request, img_w, img_h);
@@ -178,7 +198,7 @@
void sigint_handler (int signal, short event, void *arg) {
printf("SIGINT: shutting down\n");
- if (event_loopexit(NULL))
+ if (event_base_loopexit(ev_base, NULL))
err_exit("event_loopexit");
}
@@ -193,7 +213,7 @@
int main (void) {
// libevent init
- struct event_base *ev_base = event_init();
+ ev_base = event_init();
if (!ev_base)
die("event_init");
@@ -225,7 +245,7 @@
printf("RUN 0.0.0.0:8117\n");
// run the libevent mainloop
- if (event_dispatch())
+ if (event_base_dispatch(ev_base))
die("event_dispatch");
printf("SHUTDOWN\n");