]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | # CivetWeb API Reference |
2 | ||
3 | CivetWeb is often used as HTTP and HTTPS library inside a larger application. | |
4 | A C API is available to integrate the CivetWeb functionality in a larger | |
5 | codebase. A C++ wrapper is also available, although it is not guaranteed | |
6 | that all functionality available through the C API can also be accessed | |
7 | from C++. This document describes the public C API. Basic usage examples of | |
8 | the API can be found in [Embedding.md](Embedding.md), as well as in the | |
9 | examples directory. | |
10 | ||
11 | ## Macros | |
12 | ||
13 | | Macro | Description | | |
14 | | :--- | :--- | | |
15 | | **`CIVETWEB_VERSION`** | The current version of the software as a string with the major and minor version number seperated with a dot. For version 1.9, this string will have the value "1.9", for thw first patch of this version "1.9.1". | | |
16 | | **`CIVETWEB_VERSION_MAJOR`** | The current major version as number, e.g., (1) for version 1.9. | | |
17 | | **`CIVETWEB_VERSION_MINOR`** | The current minor version as number, e.g., (9) for version 1.9. | | |
18 | | **`CIVETWEB_VERSION_PATCH`** | The current patch version as number, e.g., (0) for version 1.9 or (1) for version 1.9.1. | | |
19 | ||
20 | ## Handles | |
21 | ||
22 | * `struct mg_context *` | |
23 | Handle for one instance of the HTTP(S) server. | |
24 | All functions using `const struct mg_context *` as an argument do not modify a running server instance, but just query information. Functions using a non-const `struct mg_context *` as an argument may modify a server instance (e.g., register a new URI, stop the server, ...). | |
25 | ||
26 | * `struct mg_connection *` | |
27 | Handle for one individual client-server connection. | |
28 | Functions working with `const struct mg_connection *` operate on data already known to the server without reading data from or sending data to the client. Callbacks using a `const struct mg_connection *` argument are supposed to not call functions from the `mg_read()` and `mg_write()` family. To support a correct application, reading and writing functions require a non-const `struct mg_connection *` connection handle. | |
29 | ||
30 | The content of both structures is not defined in the interface - they are only used as opaque pointers (handles). | |
31 | ||
32 | ## Structures | |
33 | ||
34 | * [`struct mg_client_cert;`](api/mg_client_cert.md) | |
35 | * [`struct mg_client_options;`](api/mg_client_options.md) | |
36 | * [`struct mg_callbacks;`](api/mg_callbacks.md) | |
37 | * [`struct mg_form_data_handler;`](api/mg_form_data_handler.md) | |
38 | * [`struct mg_header;`](api/mg_header.md) | |
39 | * [`struct mg_option;`](api/mg_option.md) | |
40 | * [`struct mg_request_info;`](api/mg_request_info.md) | |
41 | * [`struct mg_server_ports;`](api/mg_server_ports.md) | |
42 | ||
43 | ||
44 | ## Library API Functions | |
45 | ||
46 | * [`mg_init_library( feature );`](api/mg_init_library.md) | |
47 | * [`mg_exit_library( feature );`](api/mg_exit_library.md) | |
48 | ||
49 | * [`mg_check_feature( feature );`](api/mg_check_feature.md) | |
50 | * [`mg_version();`](api/mg_version.md) | |
51 | ||
52 | ||
53 | ## Server API Functions | |
54 | ||
55 | * [`mg_start( callbacks, user_data, options );`](api/mg_start.md) | |
56 | * [`mg_stop( ctx );`](api/mg_stop.md) | |
57 | ||
58 | * [`mg_get_builtin_mime_type( file_name );`](api/mg_get_builtin_mime_type.md) | |
59 | * [`mg_get_option( ctx, name );`](api/mg_get_option.md) | |
60 | * [`mg_get_server_ports( ctx, size, ports );`](api/mg_get_server_ports.md) | |
61 | * [`mg_get_user_data( ctx );`](api/mg_get_user_data.md) | |
62 | * [`mg_set_auth_handler( ctx, uri, handler, cbdata );`](api/mg_set_auth_handler.md) | |
63 | * [`mg_set_request_handler( ctx, uri, handler, cbdata );`](api/mg_set_request_handler.md) | |
64 | * [`mg_set_websocket_handler( ctx, uri, connect_handler, ready_handler, data_handler, close_handler, cbdata );`](api/mg_set_websocket_handler.md) | |
65 | ||
66 | * [`mg_lock_context( ctx );`](api/mg_lock_context.md) | |
67 | * [`mg_unlock_context( ctx );`](api/mg_unlock_context.md) | |
68 | ||
69 | * [`mg_get_context( conn );`](api/mg_get_context.md) | |
70 | ||
71 | * [`mg_send_http_error( conn, status_code, fmt, ... );`](api/mg_send_http_error.md) | |
72 | ||
73 | * [`mg_send_digest_access_authentication_request( conn, realm );`](api/mg_send_digest_access_authentication_request.md) | |
74 | * [`mg_check_digest_access_authentication( conn, realm, filename );`](api/mg_check_digest_access_authentication.md) | |
75 | * [`mg_modify_passwords_file( passwords_file_name, realm, user, password );`](api/mg_modify_passwords_file.md) | |
76 | ||
77 | ||
78 | ## Client API Functions | |
79 | ||
80 | * [`mg_connect_client( host, port, use_ssl, error_buffer, error_buffer_size );`](api/mg_connect_client.md) | |
81 | * [`mg_connect_websocket_client( host, port, use_ssl, error_buffer, error_buffer_size, path, origin, data_func, close_func, user_data);`](api/mg_connect_websocket_client.md) | |
82 | * [`mg_websocket_client_write( conn, opcode, data, data_len );`](api/mg_websocket_client_write.md) | |
83 | ||
84 | * [`mg_download( host, port, use_ssl, error_buffer, error_buffer_size, fmt, ... );`](api/mg_download.md) | |
85 | ||
86 | ||
87 | ## Common API Functions | |
88 | ||
89 | * [`mg_close_connection( conn );`](api/mg_close_connection.md) | |
90 | * [`mg_cry( conn, fmt, ... );`](api/mg_cry.md) | |
91 | ||
92 | * [`mg_get_cookie( cookie, var_name, buf, buf_len );`](api/mg_get_cookie.md) | |
93 | * [`mg_get_header( conn, name );`](api/mg_get_header.md) | |
94 | * [`mg_get_request_info( conn );`](api/mg_get_request_info.md) | |
95 | * [`mg_get_response( conn, ebuf, ebuf_len, timeout );`](api/mg_get_response.md) | |
96 | * [`mg_get_response_code_text( conn, response_code );`](api/mg_get_response_code_text.md) | |
97 | * [`mg_get_user_connection_data( conn );`](api/mg_get_user_connection_data.md) | |
98 | * [`mg_get_valid_options();`](api/mg_get_valid_options.md) | |
99 | * [`mg_get_var( data, data_len, var_name, dst, dst_len );`](api/mg_get_var.md) | |
100 | * [`mg_get_var2( data, data_len, var_name, dst, dst_len, occurrence );`](api/mg_get_var2.md) | |
101 | * [`mg_handle_form_request( conn, fdh );`](api/mg_handle_form_request.md) | |
102 | * [`mg_lock_connection( conn );`](api/mg_lock_connection.md) | |
103 | * [`mg_md5( buf, ... );`](api/mg_md5.md) | |
104 | * [`mg_printf( conn, fmt, ... );`](api/mg_printf.md) | |
105 | * [`mg_read( conn, buf, len );`](api/mg_read.md) | |
106 | * [`mg_send_chunk( conn, buf, len );`](api/mg_send_chunk.md) | |
107 | * [`mg_send_file( conn, path );`](api/mg_send_file.md) | |
108 | * [`mg_send_mime_file( conn, path, mime_type );`](api/mg_send_mime_file.md) | |
109 | * [`mg_send_mime_file2( conn, path, mime_type, additional_headers );`](api/mg_send_mime_file2.md) | |
110 | * [`mg_set_user_connection_data( conn, data );`](api/mg_set_user_connection_data.md) | |
111 | * [`mg_start_thread( f, p );`](api/mg_start_thread.md) | |
112 | * [`mg_store_body( conn, path );`](api/mg_store_body.md) | |
113 | * [`mg_strcasecmp( s1, s2 );`](api/mg_strcasecmp.md) | |
114 | * [`mg_strncasecmp( s1, s2, len );`](api/mg_strncasecmp.md) | |
115 | * [`mg_unlock_connection( conn );`](api/mg_unlock_connection.md) | |
116 | * [`mg_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );`](api/mg_url_decode.md) | |
117 | * [`mg_url_encode( src, dst, dst_len );`](api/mg_url_encode.md) | |
118 | * [`mg_websocket_write( conn, opcode, data, data_len );`](api/mg_websocket_write.md) | |
119 | * [`mg_write( conn, buf, len );`](api/mg_write.md) | |
120 | ||
121 | ||
122 | ## Diagnosis Functions | |
123 | ||
124 | * [`mg_get_system_info( buffer, buf_len );`](api/mg_get_system_info.md) | |
125 | * [`mg_get_context_info( ctx, buffer, buf_len );`](api/mg_get_context_info.md) | |
126 | * [`mg_get_connection_info( ctx, idx, buffer, buf_len );`](api/mg_get_context_info.md) | |
127 | ||
128 | ||
129 | ## Deprecated: | |
130 | ||
131 | * [~~`mg_get_valid_option_names();`~~](api/mg_get_valid_option_names.md) | |
132 | * [~~`mg_upload( conn, destination_dir );`~~](api/mg_upload.md) | |
133 | ||
134 |