mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-14 06:49:35 -04:00
split finding of callbacks out of code
svn:r350
This commit is contained in:
parent
50edb19f17
commit
a968da7425
2
evhttp.h
2
evhttp.h
@ -155,6 +155,8 @@ struct evhttp_request {
|
|||||||
*/
|
*/
|
||||||
struct evhttp_request *evhttp_request_new(
|
struct evhttp_request *evhttp_request_new(
|
||||||
void (*cb)(struct evhttp_request *, void *), void *arg);
|
void (*cb)(struct evhttp_request *, void *), void *arg);
|
||||||
|
|
||||||
|
/* enable delivery of chunks to requestor */
|
||||||
void evhttp_request_set_chunked_cb(struct evhttp_request *,
|
void evhttp_request_set_chunked_cb(struct evhttp_request *,
|
||||||
void (*cb)(struct evhttp_request *, void *));
|
void (*cb)(struct evhttp_request *, void *));
|
||||||
|
|
||||||
|
39
http.c
39
http.c
@ -1795,30 +1795,41 @@ evhttp_parse_query(const char *uri, struct evkeyvalq *headers)
|
|||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct evhttp_cb *
|
||||||
|
evhttp_dispatch_callback(struct httpcbq *callbacks, struct evhttp_request *req)
|
||||||
|
{
|
||||||
|
struct evhttp_cb *cb;
|
||||||
|
|
||||||
|
/* Test for different URLs */
|
||||||
|
char *p = strchr(req->uri, '?');
|
||||||
|
TAILQ_FOREACH(cb, callbacks, next) {
|
||||||
|
int res;
|
||||||
|
if (p == NULL)
|
||||||
|
res = strcmp(cb->what, req->uri) == 0;
|
||||||
|
else
|
||||||
|
res = strncmp(cb->what, req->uri,
|
||||||
|
(size_t)(p - req->uri)) == 0;
|
||||||
|
if (res)
|
||||||
|
return (cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
evhttp_handle_request(struct evhttp_request *req, void *arg)
|
evhttp_handle_request(struct evhttp_request *req, void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp *http = arg;
|
struct evhttp *http = arg;
|
||||||
struct evhttp_cb *cb;
|
struct evhttp_cb *cb = NULL;
|
||||||
|
|
||||||
if (req->uri == NULL) {
|
if (req->uri == NULL) {
|
||||||
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
|
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test for different URLs */
|
if ((cb = evhttp_dispatch_callback(&http->callbacks, req)) != NULL) {
|
||||||
TAILQ_FOREACH(cb, &http->callbacks, next) {
|
(*cb->cb)(req, cb->cbarg);
|
||||||
int res;
|
return;
|
||||||
char *p = strchr(req->uri, '?');
|
|
||||||
if (p == NULL)
|
|
||||||
res = strcmp(cb->what, req->uri) == 0;
|
|
||||||
else
|
|
||||||
res = strncmp(cb->what, req->uri,
|
|
||||||
(size_t)(p - req->uri)) == 0;
|
|
||||||
if (res) {
|
|
||||||
(*cb->cb)(req, cb->cbarg);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generic call back */
|
/* Generic call back */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user