mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 12:28:19 -04:00
have evhttp_set_cb return an int; -1 on failure, 0 on success; this is better than returning a pointer
svn:r1179
This commit is contained in:
parent
edfc28caef
commit
30648529e8
9
http.c
9
http.c
@ -2557,12 +2557,17 @@ evhttp_set_timeout(struct evhttp* http, int timeout_in_secs)
|
||||
http->timeout = timeout_in_secs;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
evhttp_set_cb(struct evhttp *http, const char *uri,
|
||||
void (*cb)(struct evhttp_request *, void *), void *cbarg)
|
||||
{
|
||||
struct evhttp_cb *http_cb;
|
||||
|
||||
TAILQ_FOREACH(http_cb, &http->callbacks, next) {
|
||||
if (strcmp(http_cb->what, uri) == 0)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((http_cb = mm_calloc(1, sizeof(struct evhttp_cb))) == NULL)
|
||||
event_err(1, "%s: calloc", __func__);
|
||||
|
||||
@ -2571,6 +2576,8 @@ evhttp_set_cb(struct evhttp *http, const char *uri,
|
||||
http_cb->cbarg = cbarg;
|
||||
|
||||
TAILQ_INSERT_TAIL(&http->callbacks, http_cb, next);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -119,9 +119,17 @@ int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd);
|
||||
*/
|
||||
void evhttp_free(struct evhttp* http);
|
||||
|
||||
/** Set a callback for a specified URI */
|
||||
void evhttp_set_cb(struct evhttp *, const char *,
|
||||
void (*)(struct evhttp_request *, void *), void *);
|
||||
/**
|
||||
Set a callback for a specified URI
|
||||
|
||||
@param http the http sever on which to set the callback
|
||||
@param path the path for which to invoke the callback
|
||||
@param cb the callback function that gets invoked on requesting path
|
||||
@param cb_arg an additional context argument for the callback
|
||||
@return 0 on success, -1 if the callback existed already
|
||||
*/
|
||||
int evhttp_set_cb(struct evhttp *http, const char *path,
|
||||
void (*cb)(struct evhttp_request *, void *), void *cb_arg);
|
||||
|
||||
/** Removes the callback for a specified URI */
|
||||
int evhttp_del_cb(struct evhttp *, const char *);
|
||||
|
@ -2076,6 +2076,7 @@ static void
|
||||
http_primitives(void *ptr)
|
||||
{
|
||||
char *escaped = NULL;
|
||||
struct evhttp *http;
|
||||
|
||||
escaped = evhttp_htmlescape("<script>");
|
||||
tt_str_op(escaped, ==, "<script>");
|
||||
@ -2084,6 +2085,14 @@ http_primitives(void *ptr)
|
||||
escaped = evhttp_htmlescape("\"\'&");
|
||||
tt_str_op(escaped, ==, ""'&");
|
||||
|
||||
http = evhttp_new(NULL);
|
||||
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, 0);
|
||||
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, -1);
|
||||
tt_int_op(evhttp_del_cb(http, "/test"), ==, 0);
|
||||
tt_int_op(evhttp_del_cb(http, "/test"), ==, -1);
|
||||
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, 0);
|
||||
evhttp_free(http);
|
||||
|
||||
end:
|
||||
if (escaped)
|
||||
free(escaped);
|
||||
|
Loading…
x
Reference in New Issue
Block a user