Ver código fonte

Completed function and structure documentation

lammertb 8 anos atrás
pai
commit
dcd7a0b67d

+ 2 - 2
docs/api/mg_get_cookie.md

@@ -19,9 +19,9 @@
 
 ### Description
 
-The function `mg_get_cookie() tries to fetch the value of a certain cookie variable. The contents will either be stored in an application provided buffer, or an error code will be returned. The destination buffer is guaranteed to be NUL terminated if the pointer of the buffer is not a NULL pointer and the size of the buffer is at least one byte.
+The function `mg_get_cookie()` tries to fetch the value of a certain cookie variable. The contents will either be stored in an application provided buffer, or an error code will be returned. The destination buffer is guaranteed to be NUL terminated if the pointer of the buffer is not a NULL pointer and the size of the buffer is at least one byte.
 
-If the function succeeds, the return value of the function is the length in bytes of the cookie. The value **`-1`** is returned if the requested cookie could not be found and -2 if the destination buffer is represented by a NULL pointer, is zero length or too short to store the whole cookie.
+If the function succeeds, the return value of the function is the length in bytes of the cookie. The value **`-1`** is returned if the requested cookie could not be found and **`-2`** if the destination buffer is represented by a NULL pointer, is zero length or too short to store the whole cookie.
 
 ### See Also
 

+ 1 - 6
docs/api/mg_get_header.md

@@ -17,11 +17,6 @@
 
 ### Description
 
-HTTP and HTTPS clients can send request headers to the server to provide details about
-the communication. These request headers can for example specify the preferred language
-in which the server should respond and the supported compression algorithms. The
-function `mg_get_header()` can be called to return the contents of a specific request
-header. The function will return a pointer to the value text of the header when succesful,
-and NULL of no matching request header from the client could be found.
+HTTP and HTTPS clients can send request headers to the server to provide details about the communication. These request headers can for example specify the preferred language in which the server should respond and the supported compression algorithms. The function `mg_get_header()` can be called to return the contents of a specific request header. The function will return a pointer to the value text of the header when succesful, and NULL of no matching request header from the client could be found.
 
 ### See Also

+ 1 - 9
docs/api/mg_get_option.md

@@ -17,15 +17,7 @@
 
 ### Description
 
-When starting the CivetWeb webserver, options are provided to set the wanted
-behaviour of the server. The options which were used during startup can be
-queried through the `mg_get_option()` function. Options are read-only and
-cannot be changed while the webserver is running. The function returns a
-pointer to a text string containing the value of the queried option, or NULL
-if an error occured. It is guaranteed however that if a valid option name is
-provided as a parameter to this function, that a pointer to a string is returned
-and not NULL. In case an option was empty or NULL during initialisation,
-`mg_get_option()` will return a pointer to an empty string.
+When starting the CivetWeb webserver, options are provided to set the wanted behaviour of the server. The options which were used during startup can be queried through the `mg_get_option()` function. Options are read-only and cannot be changed while the webserver is running. The function returns a pointer to a text string containing the value of the queried option, or NULL if an error occured. It is guaranteed however that if a valid option name is provided as a parameter to this function, that a pointer to a string is returned and not NULL. In case an option was empty or NULL during initialisation, `mg_get_option()` will return a pointer to an empty string.
 
 ### See Also
 

+ 11 - 5
docs/api/mg_modify_passwords_file.md

@@ -6,17 +6,23 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`passwords_file_name`**|`const char *`||
-|**`domain`**|`const char *`||
-|**`user`**|`const char *`||
-|**`password`**|`const char *`||
+|**`passwords_file_name`**|`const char *`|The path to the passwords file|
+|**`domain`**|`const char *`|The domain of the user record|
+|**`user`**|`const char *`|Username of the record to be added, changed or deleted|
+|**`password`**|`const char *`|Password associated with the user or NULL if the record must be deleted|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|Success or error code|
 
 ### Description
 
+The function `mg_modify_passwords_file()` allows an application to manipulate .htpasswd files on the fly by adding, deleting and changing user records. This is one of the several ways to implement authentication on the server side.
+
+If the password parameter is not `NULL` an entry is added to the password file. An existing records is modified in that case. If `NULL` is used as the password the enrty is removed from the file.
+
+The function returns 1 when successful and 0 if an error occurs.
+
 ### See Also

+ 15 - 11
docs/api/mg_option.md

@@ -6,21 +6,25 @@
 
 | Field | Type | Description |
 | :--- | :--- | :--- |
-|**`name`**|`const char *`||
-|**`type`**|`int`||
-|**`default_value`**|`const char *`||
+|**`name`**|`const char *`|Name of the option|
+|**`type`**|`int`|Type of the option|
+|**`default_value`**|`const char *`|Value of the option|
 
 ### Description
 
-Type can be one of the following values:
+A list of valid configuration options of the Civetweb instance can be retrieved with a call to [`mg_get_valid_options()`](mg_get_valid_options.md). This function fills a list of `struct mg_option` structures where the content of each structure represents a configuration option. Each structure contains three fields. One field contains the name of the option, the second contains the value of the option and the third is an identifier used to define the type of the option and how the value contents should be interpreted.
 
-`CONFIG_TYPE_UNKNOWN`
-`CONFIG_TYPE_NUMBER`
-`CONFIG_TYPE_STRING`
-`CONFIG_TYPE_FILE`
-`CONFIG_TYPE_DIRECTORY`
-`CONFIG_TYPE_BOOLEAN`
-`CONFIG_TYPE_EXT_PATTERN`
+The field `type` can be one of the following values:
+
+|Value|Description|
+| :--- | :--- |
+|**`CONFIG_TYPE_UNKNOWN`**|The type of the option value is unknown|
+|**`CONFIG_TYPE_NUMBER`**|The option value is an integer|
+|**`CONFIG_TYPE_STRING`**|The option value is a number|
+|**`CONFIG_TYPE_FILE`**|The option value is a file name|
+|**`CONFIG_TYPE_DIRECTORY`**|The option value is a directory name|
+|**`CONFIG_TYPE_BOOLEAN`**|The option value is a boolean|
+|**`CONFIG_TYPE_EXT_PATTERN`**|The option value is a list of regular expression patterns|
 
 ### See Also
 

+ 6 - 4
docs/api/mg_printf.md

@@ -6,18 +6,20 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`fmt`**|`const char *`||
-|**`...`**|*various*||
+|**`conn`**|`struct mg_connection *`|The connection over which the data must be sent|
+|**`fmt`**|`const char *`|Format string|
+|**`...`**|*various*|Parameters as specified in the format string|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|Number of bytes written or an error code|
 
 ### Description
 
+The function `mg_printf()` can be used to send formatted strings over a connection. The functionality is comparable to the `printf()` family of functions in the standard C library. The function returns **0** when the connection has been closed, **-1** if an error occurred and otherwise the number of bytes written over the connection. Except for the formatting part, the `mg_printf()` function is identical to the function [`mg_write()`](mg_write.md).
+
 ### See Also
 
 * [`mg_websocket_client_write();`](mg_websocket_client_write.md)

+ 4 - 4
docs/api/mg_read.md

@@ -18,9 +18,9 @@
 
 ### Description
 
-The function `mg_read()` receives data over an existing connection. The data is handled as
-binary and is stored in a buffer whose address has been provided as a parameter. The function
-returns the number of read bytes when successful, the value 0 when the connection has been
-closed by peer and a negative value when no more data could be read from the connection.
+The function `mg_read()` receives data over an existing connection. The data is handled as binary and is stored in a buffer whose address has been provided as a parameter. The function returns the number of read bytes when successful, the value **0** when the connection has been closed by peer and a negative value when no more data could be read from the connection.
 
 ### See Also
+
+* [`mg_printf();`](mg_printf.md)
+* [`mg_write();`](mg_write.md)

+ 4 - 2
docs/api/mg_send_file.md

@@ -6,8 +6,8 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`path`**|`const char *`||
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
 
 ### Return Value
 
@@ -15,6 +15,8 @@
 
 ### Description
 
+The function `mg_send_file()` sends the contents of a file over a connection to the remote peer. The function also adds the necessary HTTP headers.
+
 ### See Also
 
 * [`mg_printf();`](mg_printf.md)

+ 5 - 3
docs/api/mg_send_mime_file.md

@@ -6,9 +6,9 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`path`**|`const char *`||
-|**`mime_type`**|`const char *`||
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
+|**`mime_type`**|`const char *`|The mime type of the file, or NULL for automatic detection|
 
 ### Return Value
 
@@ -16,6 +16,8 @@
 
 ### Description
 
+The function `mg_send_mime_file()` sends a file over a connection including the HTTP headers. The function is similar to the [`mg_send_file()`](mg_send_file.md) with the additional functionality that the MIME type of the file can be specified. If the `mime_type` parameter is NULL, the routine will try to determine the MIME type based on the extension of the filename.
+
 ### See Also
 
 * [`mg_get_builtin_mime_type();`](mg_get_builtin_mime_type.md)

+ 8 - 4
docs/api/mg_send_mime_file2.md

@@ -6,10 +6,10 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`path`**|`const char *`||
-|**`mime_type`**|`const char *`||
-|**`additional_headers`**|`const char *`||
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
+|**`mime_type`**|`const char *`|The mime type or NULL for automatic detection|
+|**`additional_headers`**|`const char *`|Additional headers to be sent|
 
 ### Return Value
 
@@ -17,6 +17,10 @@
 
 ### Description
 
+The function `mg_send_mime_file2()` can be used to send a file over a connection. The function is similar to [`mg_send_mime_file()`](mg_send_mime_file.md) with the additional functionality that user specified headers can be sent. The MIME type of the file can be specified in the function call, or will be automatically determined based on the extension of the filename if the `mime_type` parameter has the value NULL.
+
+Additional custom header fields can be added as a parameter. Please make sure that these header names begin with `X-` to prevent name clashes with other headers. If the `additional_headers` parameter is NULL, no custom headers will be added.
+
 ### See Also
 
 * [`mg_get_builtin_mime_type();`](mg_get_builtin_mime_type.md)

+ 10 - 8
docs/api/mg_server_ports.md

@@ -6,17 +6,19 @@
 
 | Field | Type | Description |
 | :--- | :--- | :--- |
-|**`protocol`**|`int`||
-|**`port`**|`int`||
-|**`is_ssl`**|`int`||
-|**`is_redirect`**|`int`||
-|**`_reserved1`**|`int`||
-|**`_reserved2`**|`int`||
-|**`_reserved3`**|`int`||
-|**`_reserved4`**|`int`||
+|**`protocol`**|`int`|The protocol mask where `IPv4` is **1**, `IPv6` is **2** and both `IPv4` and `IPv6` is **3**|
+|**`port`**|`int`|The port number on which the service listens|
+|**`is_ssl`**|`int`|**0** for `HTTP` communication, **1** for `HTTPS`|
+|**`is_redirect`**|`int`|**1** if all requests are redirected, otherwise **0**|
+|**`_reserved1`**|`int`|Reserved for internal use|
+|**`_reserved2`**|`int`|Reserved for internal use|
+|**`_reserved3`**|`int`|Reserved for internal use|
+|**`_reserved4`**|`int`|Reserved for internal use|
 
 ### Description
 
+A call to the function [`mg_get_server_ports()`](mg_get_server_ports.md) returns a list of structures with information about each running Civetweb service. These structures are of type `struct mg_server_ports` and contain the base information of each service.
+
 ### See Also
 
 * [`mg_get_server_ports();`](mg_get_server_ports.md)

+ 14 - 4
docs/api/mg_set_auth_handler.md

@@ -6,10 +6,12 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`ctx`**|`struct mg_context *`||
-|**`uri`**|`const char *`||
-|**`handler`**|`mg_authorization_handler`||
-|**`cbdata`**|`void *`||
+|**`ctx`**|`struct mg_context *`|The context on which the handler must be set|
+|**`uri`**|`const char *`|The URI for the authorization handler|
+|**`handler`**|`mg_authorization_handler`|Callback function doing the actual authorization|
+|**`cbdata`**|`void *`|Optional user data|
+
+`int mg_authorization_handler( struct mg_connection *conn, void *cbdata );`
 
 ### Return Value
 
@@ -17,4 +19,12 @@
 
 ### Description
 
+The function `mg_set_auth_handler()` hooks an authorization function to an URI to check if a user is authorized to visit that URI. The check is performed by a callback function of type `mg_authorization_handler`. The callback function is passed two parameters: the current connection and a pointer to optional user defined data which was passed to `mg_set_auth_handler()` when the callback was hooked to the URI.
+
+The callback function can return **0** to deny access, and **1** to allow access.
+
+The `mg_set_auth_handler()` function is very similar in use to [`mg_set_request_handler()`](mg_set_request_handler.md).
+
 ### See Also
+
+* [`mg_set_request_handler();`](mg_set_request_handler.md)

+ 10 - 4
docs/api/mg_set_request_handler.md

@@ -6,10 +6,12 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`ctx`**|`struct mg_context *`||
-|**`uri`**|`const char *`||
-|**`handler`**|`mg_request_handler`||
-|**`cbdata`**|`void *`||
+|**`ctx`**|`struct mg_context *`|The context where the handler must be active|
+|**`uri`**|`const char *`|The URI to hook the handler on|
+|**`handler`**|`mg_request_handler`|Callback function doing the heavy lifting|
+|**`cbdata`**|`void *`|Optional user supplied data|
+
+`int mg_request_handler( struct mg_connection *conn, void *cbdata );`
 
 ### Return Value
 
@@ -17,4 +19,8 @@
 
 ### Description
 
+The function `mg_set_request_handler()` hooks a callback function on a URI. That callback function is called whenever a client requests the specific URI. The callback function receives the connection information and optional user supplied data as parameters and can serve information back to the client. When the callback function does not send any information back to the client, it should return **0** to signal Civetweb that the Civetweb core should handle the request. A return value between 1 and 999 is used to tell Civetweb that the request has been handled and no further processing is necessary. The returned code is stored as the status code in the access log, it is therefore recommended, although not mandatory to return a status code which matches the state of the request.
+
 ### See Also
+
+* [`mg_set_auth_handler();`](mg_set_auth_handler.md)

+ 4 - 2
docs/api/mg_set_user_connection_data.md

@@ -6,8 +6,8 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`data`**|`void *`||
+|**`conn`**|`struct mg_connection *`|connection to add the user data|
+|**`data`**|`void *`|Pointer to the user data|
 
 ### Return Value
 
@@ -15,6 +15,8 @@
 
 ### Description
 
+The function `mg_set_user_connection_data()` can be used to add or change the user data pointer attached to a connection. Using the value NULL in the call will remove a previously assigned user data pointer.
+
 ### See Also
 
 * [`mg_get_user_connection_data();`](mg_user_connection_data.md)

+ 14 - 7
docs/api/mg_set_websocket_handler.md

@@ -6,13 +6,18 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`ctx`**|`mg_context *`||
-|**`uri`**|`const char *`||
-|**`connect_handler`**|`mg_websocket_connect_handler`||
-|**`ready_handler`**|`mg_websocket_ready_handler`||
-|**`data_handler`**|`mg_websocket_data_handler`||
-|**`close_handler`**|`mg_websocket_close_handler`||
-|**`cbdata`**|`void *`||
+|**`ctx`**|`mg_context *`|The context in which to add the handlers|
+|**`uri`**|`const char *`|The URI for which the handlers should be activated|
+|**`connect_handler`**|`mg_websocket_connect_handler`|Handler called when a connect is signalled|
+|**`ready_handler`**|`mg_websocket_ready_handler`|Handler called when the connection is ready|
+|**`data_handler`**|`mg_websocket_data_handler`|Handler called when data is received|
+|**`close_handler`**|`mg_websocket_close_handler`|Handler called when the connection closes|
+|**`cbdata`**|`void *`|User defined data|
+
+`int mg_websocket_connect_handler( const struct mg_connection *conn, void *cbdata );`
+`int mg_websocket_ready_handler( struct mg_connection *conn, void *cbdata );`
+`int mg_websocket_data_handler( struct mg_connection *conn, int opcode, char * buf, size_t buf_len, void *cbdata );`
+`int mg_websocket_close_handler( const struct mg_connection *conn,  void *cbdata );`
 
 ### Return Value
 
@@ -20,4 +25,6 @@
 
 ### Description
 
+The function `mg_set_websocket_handler()` connects callback functions to a websocket URI. The callback functions are called when a state change is detected on the URI like an incomming connection or data received from a remote peer.
+
 ### See Also

+ 3 - 12
docs/api/mg_start.md

@@ -29,18 +29,9 @@ The option list can be used to set the following options:
 
 ### Description
 
-The function `mg_start()` is the only function needed to call to initialize the webserver. After the
-function returns and a pointer to a context structure is provided, it is guaranteed that the server
-has started and is listening on the designated ports. In case of failure a NULL pointer is returned.
-The behaviour of the web server is controlled by a list of callback functions and a list of options.
-The callback functions can do application specific processing of events which are encountered by the
-webserver. If a specific callback function is set to NULL, the webserver uses their default callback
-routine. The options list controls how the webserver should be started and contains settings for for
-example the ports to listen on, the maximum number of threads created to handle requests in parallel
-and if settings for SSL encryption.
-
-As a side effect on Unix systems, SIGCHLD and SIGPIPE signals will be ignored. If custom processing
-is needed for these signals, signal handlers must be setup after the call to `mg_start()` has completed.
+The function `mg_start()` is the only function needed to call to initialize the webserver. After the function returns and a pointer to a context structure is provided, it is guaranteed that the server has started and is listening on the designated ports. In case of failure a NULL pointer is returned.  The behaviour of the web server is controlled by a list of callback functions and a list of options.  The callback functions can do application specific processing of events which are encountered by the webserver. If a specific callback function is set to NULL, the webserver uses their default callback routine. The options list controls how the webserver should be started and contains settings for for example the ports to listen on, the maximum number of threads created to handle requests in parallel and if settings for SSL encryption.
+
+As a side effect on Unix systems, SIGCHLD and SIGPIPE signals will be ignored. If custom processing is needed for these signals, signal handlers must be setup after the call to `mg_start()` has completed.
 
 ### See Also
 

+ 10 - 4
docs/api/mg_start_thread.md

@@ -1,20 +1,26 @@
 # Civetweb API Reference
 
-### `mg_start_thread( f, p );`
+### `mg_start_thread( func, cbdata );`
 
 ### Parameters
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`f`**|`mg_thread_func`||
-|**`p`**|`void *`||
+|**`func`**|`mg_thread_func_t`|Function to start as a separate thread|
+|**`cbdata`**|`void *`|User defined data to be passed to the thread as parameter|
+
+`void mg_thread_func_t( void *cbdata );`
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|Success or error code|
 
 ### Description
 
+The function `mg_start_thread()` is a convenience function to create a detached thread. The function returns **0** when successful and another value if an error occured. A pointer to user supplied data can be passed which is then passed further on to the thread function as parameter.
+
 ### See Also
+
+* [`mg_start();`](mg_start.md)

+ 2 - 5
docs/api/mg_stop.md

@@ -14,12 +14,9 @@
 
 ### Description
 
-The function `mg_stop()` is used to stop and cleanup a running webserver. A pointer to the context of
-the running webserver is provided as a parameter. The execution of this function may take some time
-because it waits until all threads have stopped and returns all memory to the heap. After the
-function returns, the location the context pointer points to is invalid. The function does not
-return a return value and it is therefore not possible to know if stopping the webserver succeeded or not.
+The function `mg_stop()` is used to stop and cleanup a running webserver. A pointer to the context of the running webserver is provided as a parameter. The execution of this function may take some time because it waits until all threads have stopped and returns all memory to the heap. After the function returns, the location the context pointer points to is invalid. The function does not return a return value and it is therefore not possible to know if stopping the webserver succeeded or not.
 
 ### See Also
 
 * [`mg_start();`](mg_start.md)
+* [`mg_start_thread();`](mg_start_thread.md)

+ 7 - 3
docs/api/mg_store_body.md

@@ -6,15 +6,19 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`path`**|`const char *`||
+|**`conn`**|`struct mg_connection *`|connection on which to read the data|
+|**`path`**|`const char *`|file to store the request body|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`long long`||
+|`long long`|Number of bytes written to the file, or an error code|
 
 ### Description
 
+The function `mg_store_body()` stores the body of an incoming request to a data file. The function returns the number of bytes stored in the file, or a negative value to indicate an error.
+
 ### See Also
+
+* [`mg_read();`](mg_read.md)

+ 5 - 3
docs/api/mg_strcasecmp.md

@@ -6,17 +6,19 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`s1`**|`const char *`||
-|**`s2`**|`const char *`||
+|**`s1`**|`const char *`|First string to compare|
+|**`s2`**|`const char *`|Second string to compare|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|Integer value with the result of the comparison|
 
 ### Description
 
+The function `mg_strcasecmp()` is a helper function to compare two strings. The comparison is case insensitive. The return value is **0** if both strings are equal, less then zero if the first string is less than the second in a lexical comparison, and greater than zero if the first string is greater than the second.
+
 ### See Also
 
 * [`mg_strncasecmp();`](mg_strncasecmp.md)

+ 6 - 4
docs/api/mg_strncasecmp.md

@@ -6,18 +6,20 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`s1`**|`const char *`||
-|**`s2`**|`const char *`||
-|**`len`**|`size_t`||
+|**`s1`**|`const char *`|First string in the comparison|
+|**`s2`**|`const char *`|Second string in the comparison|
+|**`len`**|`size_t`|The maximum number of characters to compare|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|The result of the comparison|
 
 ### Description
 
+The function `mg_strncasecmp()` is a helper function to compare two strings. The comparison is case insensitive and only a limited number of characters are compared. This limit is provided as third parameter in the function call. The return value is **0** if both strings are equal, less then zero if the first string is less than the second in a lexical comparison, and greater than zero if the first string is greater than the second.
+
 ### See Also
 
 * [`mg_strcasecmp();`](mg_strcasecmp.md)

+ 3 - 1
docs/api/mg_unlock_connection.md

@@ -6,7 +6,7 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
+|**`conn`**|`struct mg_connection *`|Connection to remove the lock from|
 
 ### Return Value
 
@@ -14,6 +14,8 @@
 
 ### Description
 
+The function `mg_unlock_connection()` removes the lock on a connection which was previously set with a call to [`mg_lock_connection()`](mg_lock_connection.md). Locking may be necessary when using [`mg_write()`](mg_write.md) or [`mg_printf()`](mg_printf.md) on websocket connections to prevent data corruption.
+
 ### See Also
 
 * [`mg_lock_connection();`](mg_lock_connection.md)

+ 3 - 1
docs/api/mg_unlock_context.md

@@ -6,7 +6,7 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`ctx`**|`struct mg_context *`||
+|**`ctx`**|`struct mg_context *`|The context to remove the lock from|
 
 ### Return Value
 
@@ -14,6 +14,8 @@
 
 ### Description
 
+The function `mg_unlock_contect()` removes a lock put previously on a context with a call to [`mg_lock_context()`](mg_lock_context.md). Locking a context may be necessary when accessing shared resources.
+
 ### See Also
 
 * [`mg_lock_connection();`](mg_lock_connection.md)

+ 4 - 5
docs/api/mg_upload.md

@@ -6,18 +6,17 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`destination_dir`**|`const char *`||
+|**`conn`**|`struct mg_connection *`|Connection on which files to upload|
+|**`destination_dir`**|`const char *`|The destination directory to upload to|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|Success or error code|
 
 ### Description
 
-The function `mg_upload()` is deprecated and may be removed from future releases. Use of this function
-is therefore highly discouraged.
+The function `mg_upload()` is deprecated and may be removed from future releases. Use of this function is therefore highly discouraged.
 
 ### See Also

+ 8 - 6
docs/api/mg_url_decode.md

@@ -6,20 +6,22 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`src`**|`const char *`||
-|**`src_len`**|`int`||
-|**`dst`**|`char *`||
-|**`dst_len`**|`int`||
-|**`is_form_url_encoded`**|`int`||
+|**`src`**|`const char *`|Source data to convert|
+|**`src_len`**|`int`|Length of the source buffer|
+|**`dst`**|`char *`|Destination buffer to store the result|
+|**`dst_len`**|`int`|Length of the destination buffer|
+|**`is_form_url_encoded`**|`int`|Not equal zero when form decoding must be used|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-int
+|`int`|The number of bytes stored in the destination buffer, or **-1** if the buffer doesn't exist or is too small|
 
 ### Description
 
+The function `mg_url_decode()` Decodes a in input buffer. Both normal URIs and form URIs can be decoded. In the latter case the space character is converted to a `+` as defined in [RFC 1866](http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt) in section 8.2.1.
+
 ### See Also
 
 * [`mg_url_encode();`](mg_url_encode.md)

+ 6 - 4
docs/api/mg_url_encode.md

@@ -6,18 +6,20 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`src`**|`const char *`||
-|**`dst`**|`char *`||
-|**`dst_len`**|`size_t`||
+|**`src`**|`const char *`|Input string to encode|
+|**`dst`**|`char *`|Destination buffer to store the encoded result|
+|**`dst_len`**|`size_t`|Length of the destination buffer including the terminating NUL|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|The number of characters written in the destination buffer|
 
 ### Description
 
+The function `mg_url_encode()` encodes a in input buffer. Both normal URIs and form URIs can be encoded. In the latter case the space character is converted to a `+` as defined in [RFC 1866](http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt) in section 8.2.1.
+
 ### See Also
 
 * [`mg_url_decode();`](mg_url_decode.md)

+ 1 - 3
docs/api/mg_version.md

@@ -14,8 +14,6 @@
 
 ### Description
 
-The function `mg_version()` can be used to return the current CivetWeb version.
-The function returns a pointer to a string with the current major and minor version number
-separated with a dot, for example "1.9".
+The function `mg_version()` can be used to return the current CivetWeb version.  The function returns a pointer to a string with the current major and minor version number separated with a dot, for example "1.9".
 
 ### See Also

+ 9 - 5
docs/api/mg_websocket_client_write.md

@@ -6,19 +6,23 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`opcode`**|`int`||
-|**`data const`**|`char *`||
-|**`data_len`**|`size_t`||
+|**`conn`**|`struct mg_connection *`|Connection on which to send data|
+|**`opcode`**|`int`|Opcode|
+|**`data const`**|`char *`|The data to be written|
+|**`data_len`**|`size_t`|Length of the data buffer|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|Number of bytes written or an error code|
 
 ### Description
 
+The function `mg_websocket_client_write()` sends data to a websocket server wrapped in a masked websocket frame. The function issues calls to [`mg_lock_connection()`](mg_lock_connection.md) and [`mg_unlock_connection()`](mg_unlock_connection.md) to ensure that the transmission is not interrupted. Interruption can happen the the application is proactively communicating and responding to a request simultaneously. This function is available only, if Civetweb is compiled with the option `-DUSE_WEBSOCKET`.
+
+The return value is the number of bytes written on success, **0** when the connection has been closed and **-1** if an error occured.
+
 ### See Also
 
 * [`mg_lock_connection();`](mg_lock_connection.md)

+ 11 - 5
docs/api/mg_websocket_write.md

@@ -6,19 +6,25 @@
 
 | Parameter | Type | Description |
 | :--- | :--- | :--- |
-|**`conn`**|`struct mg_connection *`||
-|**`opcode`**|`int`||
-|**`data`**|`const char *`||
-|**`data_len`**|`size_t`||
+|**`conn`**|`struct mg_connection *`|Connection on which the data must be written|
+|**`opcode`**|`int`|Opcode|
+|**`data`**|`const char *`|Data to be written to the client|
+|**`data_len`**|`size_t`|Length of the data|
 
 ### Return Value
 
 | Type | Description |
 | :--- | :--- |
-|`int`||
+|`int`|Number of bytes written or an error code|
 
 ### Description
 
+The function `mg_websocket_write()` sends data to a websocket client wrapped in a websocket frame. The function issues calls to [`mg_lock_connection()`](mg_lock_connection.md) and [`mg_unlock_connaction()`](mg_unlock_connection.md) to ensure that the transmission is not interrupted. Data corruption can otherwise happn if the application is proactively communicating and responding to a request simultaneously.
+
+The function is available only when Civetweb is compilet with the `-DUSE_WEBSOCKET` option.
+
+The function returns the number of bytes written, **0** when the connection has been closed and **-1** if an error occured.
+
 ### See Also
 
 * [`mg_lock_connection();`](mg_lock_connection.md)

+ 1 - 7
docs/api/mg_write.md

@@ -18,13 +18,7 @@
 
 ### Description
 
-The function `mg_write()` can be used to send a blob of arbitrary data over a
-connection. The size of the data is provided as a parameter. The only length
-limitation on this function is `MAX_INT`, because the return value of this
-function will turn negative with larger blocks of data, although they may
-have been sent correctly. The function returns the amount of bytes sent in
-case of success, the value **0** when the connection has been closed, and **-1** in
-case of an error.
+The function `mg_write()` can be used to send a blob of arbitrary data over a connection. The size of the data is provided as a parameter. The only length limitation on this function is `MAX_INT`, because the return value of this function will turn negative with larger blocks of data, although they may have been sent correctly. The function returns the amount of bytes sent in case of success, the value **0** when the connection has been closed, and **-1** in case of an error.
 
 ### See Also