]> granicus.if.org Git - libevent/commitdiff
split finding of callbacks out of code
authorNiels Provos <provos@gmail.com>
Tue, 6 Mar 2007 06:26:10 +0000 (06:26 +0000)
committerNiels Provos <provos@gmail.com>
Tue, 6 Mar 2007 06:26:10 +0000 (06:26 +0000)
svn:r350

evhttp.h
http.c

index 162a796ab5fe8ad0457e0a0076566c730c83fe1c..3477b763945d40773e16e296720259647a100f1d 100644 (file)
--- a/evhttp.h
+++ b/evhttp.h
@@ -155,6 +155,8 @@ struct evhttp_request {
  */
 struct evhttp_request *evhttp_request_new(
        void (*cb)(struct evhttp_request *, void *), void *arg);
+
+/* enable delivery of chunks to requestor */
 void evhttp_request_set_chunked_cb(struct evhttp_request *,
     void (*cb)(struct evhttp_request *, void *));
 
diff --git a/http.c b/http.c
index 6ff181de2a85bc0caded3ed8432382fcb371bbc4..11b6abcd4cf330d8f0abd937a12cfa2d08a7e226 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1795,30 +1795,41 @@ evhttp_parse_query(const char *uri, struct evkeyvalq *headers)
        free(line);
 }
 
-void
-evhttp_handle_request(struct evhttp_request *req, void *arg)
+static struct evhttp_cb *
+evhttp_dispatch_callback(struct httpcbq *callbacks, struct evhttp_request *req)
 {
-       struct evhttp *http = arg;
        struct evhttp_cb *cb;
 
-       if (req->uri == NULL) {
-               evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
-               return;
-       }
-
        /* Test for different URLs */
-       TAILQ_FOREACH(cb, &http->callbacks, next) {
+       char *p = strchr(req->uri, '?');
+       TAILQ_FOREACH(cb, callbacks, next) {
                int res;
-               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;
-               }
+               if (res)
+                       return (cb);
+       }
+
+       return (NULL);
+}
+
+void
+evhttp_handle_request(struct evhttp_request *req, void *arg)
+{
+       struct evhttp *http = arg;
+       struct evhttp_cb *cb = NULL;
+
+       if (req->uri == NULL) {
+               evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
+               return;
+       }
+
+       if ((cb = evhttp_dispatch_callback(&http->callbacks, req)) != NULL) {
+               (*cb->cb)(req, cb->cbarg);
+               return;
        }
 
        /* Generic call back */