Niels Provos wrote:
It would be the easiest if you were to give some example code. There
are two callbacks that libevent supports. One gives you all data at
the end of the request and the other one gives you updates as chunks
arrive.
Of course code examples would help. Excuse me. I've attached a
trimmed-down portion of code.
I would be more interested in the "updates as chunks" as there is the
possibility that the POSTed data would be very large. I was
hoping/thinking that there was a callback that would be triggered on
socket activity.
If you could point me to what the two callbacks are, I would appreciate
it as well as any other advice you might have on seeing my very (very)
simple code that is early early on.
On 3/5/07, Elliot F <[EMAIL PROTECTED]> wrote:
Hello all,
I'm writing a small web server using libevent's http layer, and would
like some pointers on how to continue reading the input buffer. The end
goal is a stream parser for a multipart/form-data. If one already
exists, please let me know.
When using 'EVBUFFER_DATA(evhttp_request->input_buffer)', I only get a
portion of the upload. I'm assuming/hoping there is some way of
associating a callback with that connection (or vice versa) to continue
reading any data related to that request. Could someone point me in the
right direction? Any tips and/or advice are welcome, including pointers
to example code.
Thank you in advance,
Elliot F
_______________________________________________
Libevent-users mailing list
[email protected]
http://monkey.org/mailman/listinfo/libevent-users
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <stdlib.h>
#include <event.h>
#include <evhttp.h>
void callback_http_default(struct evhttp_request *, void *);
void callback_http_index(struct evhttp_request *, void *);
int main(int argc, char **argv)
{
struct evhttp *httpd;
event_init();
/* bind to port 8081, server not yet started... */
httpd = evhttp_start("0.0.0.0", 8081);
/* assign callbacks */
evhttp_set_cb(httpd, "/", callback_http_index, NULL);
evhttp_set_gencb(httpd, callback_http_default, NULL);
/* start the server */
event_dispatch();
evhttp_free(httpd);
return 0;
}
void callback_http_default(struct evhttp_request *req, void *arg)
{
struct evbuffer *buf = evbuffer_new();
char *escaped = evhttp_htmlescape(evhttp_request_uri(req));
evbuffer_add_printf(buf,
"<html><head><title>Not Found</title></head>"
"<body>Location %s not found</body></html>",
escaped);
evhttp_send_reply(req, HTTP_NOTFOUND, "Location not found", buf);
}
void callback_http_index(struct evhttp_request *req, void *arg)
{
struct evbuffer *buf = evbuffer_new();
/* TODO: function to parse cgi params and populate cgi object */
evbuffer_add_printf(buf,
"<html><head><title>Testing</title></head>\n"
"<body>Testing</body></html>\n");
evhttp_send_reply(req, HTTP_OK, "OK", buf);
}
_______________________________________________
Libevent-users mailing list
[email protected]
http://monkey.org/mailman/listinfo/libevent-users