Commit b597da34 authored by Sergey Lyubka's avatar Sergey Lyubka

Pass user_data to the callback

parent bf387f95
...@@ -518,6 +518,9 @@ const char **mg_get_valid_option_names(void) { ...@@ -518,6 +518,9 @@ const char **mg_get_valid_option_names(void) {
} }
static void *call_user(struct mg_connection *conn, enum mg_event event) { static void *call_user(struct mg_connection *conn, enum mg_event event) {
if (conn != NULL && conn->ctx != NULL) {
conn->request_info.user_data = conn->ctx->user_data;
}
return conn == NULL || conn->ctx == NULL || conn->ctx->user_callback == NULL ? return conn == NULL || conn->ctx == NULL || conn->ctx->user_callback == NULL ?
NULL : conn->ctx->user_callback(event, conn); NULL : conn->ctx->user_callback(event, conn);
} }
......
...@@ -333,6 +333,22 @@ static void test_lua(void) { ...@@ -333,6 +333,22 @@ static void test_lua(void) {
} }
#endif #endif
static void *user_data_tester(enum mg_event event, struct mg_connection *conn) {
struct mg_request_info *ri = mg_get_request_info(conn);
ASSERT(ri->user_data == (void *) 123);
ASSERT(event == MG_NEW_REQUEST);
return NULL;
}
static void test_user_data(void) {
static const char *options[] = {"listening_ports", UNUSED_PORT, NULL};
struct mg_context *ctx;
ASSERT((ctx = mg_start(user_data_tester, (void *) 123, options)) != NULL);
ASSERT(ctx->user_data == (void *) 123);
call_user(fc(ctx), MG_NEW_REQUEST);
}
int main(void) { int main(void) {
test_base64_encode(); test_base64_encode();
test_match_prefix(); test_match_prefix();
...@@ -343,6 +359,7 @@ int main(void) { ...@@ -343,6 +359,7 @@ int main(void) {
test_mg_get_var(); test_mg_get_var();
test_set_throttle(); test_set_throttle();
test_next_option(); test_next_option();
test_user_data();
#ifdef USE_LUA #ifdef USE_LUA
test_lua(); test_lua();
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment