Browse Source

Add a function "mg_get_user_context_data" + documentation

There seems to be some confusion between the `void * user_data` assigned to the
CivetWeb server context (set as parameter in the mg_start call), and the
`void * user_data` assigned to the current connection.
Add a (convenience) function to get the user data directly from the connection
object, and improve API documentation.
bel2125 5 years ago
parent
commit
937907dc66
2 changed files with 11 additions and 0 deletions
  1. 4 0
      include/civetweb.h
  2. 7 0
      src/civetweb.c

+ 4 - 0
include/civetweb.h

@@ -618,6 +618,10 @@ mg_get_context(const struct mg_connection *conn);
 CIVETWEB_API void *mg_get_user_data(const struct mg_context *ctx);
 
 
+/* Get user data passed to mg_start from connection. */
+CIVETWEB_API void *mg_get_user_context_data(const struct mg_connection *conn);
+
+
 /* Get user defined thread pointer for server threads (see init_thread). */
 CIVETWEB_API void *mg_get_thread_pointer(const struct mg_connection *conn);
 

+ 7 - 0
src/civetweb.c

@@ -3518,6 +3518,13 @@ mg_get_user_data(const struct mg_context *ctx)
 
 
 void *
+mg_get_user_context_data(const struct mg_connection *conn)
+{
+	return mg_get_user_data(mg_get_context(conn));
+}
+
+
+void *
 mg_get_thread_pointer(const struct mg_connection *conn)
 {
 	/* both methods should return the same pointer */