* docs: fully-expandable generated sidebar, replacing index.md link pages
Rework docs navigation so the sidebar expands to every page of every
reference tree, instead of terminating at generated index.md link lists:
- New docs/gen_sidebar.py (replaces gen_index.py + update_index.sh):
walks efun/, apply/, stdlib/, concepts/, driver/, cli/ and zh-CN/ and
emits sidebars.generated.json — a full Docusaurus category tree per
directory. Category landing pages are now `generated-index` card pages
(title/description/slug), so all generated index.md files are deleted.
--check mode verifies freshness; new .github/workflows/docs-sidebar.yml
runs it in CI.
- New docs/sidebar_meta.json holds curated presentation: category labels,
one-line descriptions (shown on the landing cards), explicit ordering
(driver/cli/concepts read top-down from user-facing to internals) and
per-page label overrides.
- sidebars.ts becomes a hand-authored skeleton (Getting Started, lpc/,
Historical) that splices in the generated trees.
Content reorganization (from a docs-wide review):
- Move misplaced efun pages out of efun/general: terminal/protocol efuns
(act_mxp, send_zmp, request_term_*) to interactive/, debugging efuns
(check_memory, dump_*, clear_debug_level, destructed_objects) to
internals/, shallow_inherit_list to system/.
- Delete stub duplicates superseded by complete pages elsewhere:
general/parse_{add_synonym,dump,my_rules,remove}, contrib/{shuffle,
element_of}.
Modernize key pages with MDX:
- index.mdx: landing page with a card grid linking each doc section.
- build.mdx: per-platform <Tabs> (Ubuntu/macOS/Windows/Alpine+Docker),
admonitions, VitePress [[toc]] leftover removed, stale per-platform CI
workflow links updated to the unified ci.yml.
- ffi-plan.md: GitHub-style [!CAUTION] alert converted to an admonition.
`npm run build` passes clean (onBrokenLinks: throw, no warnings).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0174GM2azvAHBmvyESwxm5om
* docs: serve the Chinese corpus through Docusaurus i18n
Move the zh-CN/ directory out of the default docs tree and into a proper
Docusaurus locale (i18n/zh-CN/docusaurus-plugin-content-docs/current/):
- The flat zh-CN/efun/ directory (333 pages) is re-homed to mirror the
categorized English layout (name-matched 1:1; `hash` maps to strings/
per its own frontmatter). apply/ pages map 1:1; the stray English-text
zh-CN/apply/master/view_errors.md documents a MudOS-era apply that no
longer exists in the driver and is dropped; stdlib/db/database_zh.md
becomes the i18n translation of stdlib/db/database.md; the Chinese
build guide becomes the translation of build.mdx.
- Untranslated pages automatically fall back to English content under
/zh-CN/, so the whole site is navigable in either locale from the new
navbar locale dropdown.
- Both locales share one sidebar. Generated sidebar items now carry
stable `key` fields (the directory/doc path) so translation keys are
unique (both efun/ and stdlib/ have an "Arrays" category, crypto and
strings both document `hash`). Category labels, generated-index
titles/descriptions, navbar and footer are translated in
i18n/zh-CN/...; theme UI strings come from Docusaurus' bundled
zh-Hans translations. Translated landing page at /zh-CN/.
- The "中文文档" sidebar section, the zh-CN tree in gen_sidebar.py /
sidebar_meta.json, and its slice of sidebars.generated.json are gone.
- Relative .md-file links on pages that render in both locales break
the localized build (the file->permalink map points at the localized
copy), so concepts/, the two socket_*_option pages and the config.md
generator now emit extension-less route links instead.
- zh interactive.md/objects.md get explicit slugs like their English
counterparts (a doc named after its parent directory is otherwise a
Docusaurus category-index doc, colliding with the generated-index
route).
`npm run build` builds both locales clean (onBrokenLinks: throw).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0174GM2azvAHBmvyESwxm5om
---------
Co-authored-by: Claude <noreply@anthropic.com>
6.3 KiB
| title |
|---|
| sockets / socket_set_option |
socket_set_option
NAME
socket_set_option - set options on a socket
SYNOPSIS
void socket_set_option(int socket, int option, mixed value);
DESCRIPTION
Sets socket-specific options that control socket behavior, particularly
for TLS/SSL connections. This efun allows fine-grained control over
socket security and connection parameters.
This function must be called before establishing the connection (i.e.,
before socket_connect() for client sockets or socket_accept() for
server sockets).
ARGUMENTS
socket- The socket descriptor returned by socket_create()option- The option constant to set (see Options below)value- The value for the option (type depends on option)
OPTIONS
SO_TLS_VERIFY_PEER (1)
Controls whether the TLS/SSL peer certificate should be verified.
- Type: integer
- Values:
0- Do not verify peer certificate (insecure, for testing only)1- Verify peer certificate (default, recommended)
- Use Case: Client connections to TLS servers
When enabled, the driver will verify that the server's certificate:
- Is signed by a trusted Certificate Authority
- Is not expired
- Matches the hostname being connected to
Security Note: Disabling verification (value 0) makes the connection vulnerable to man-in-the-middle attacks and should only be used for testing.
SO_TLS_SNI_HOSTNAME (2)
Sets the Server Name Indication (SNI) hostname for TLS connections.
- Type: string
- Value: The hostname to send in the SNI extension
- Use Case: Client connections when the server hosts multiple TLS sites
SNI allows the server to present the correct SSL certificate when multiple domains are hosted on the same IP address. This is essential for modern HTTPS and TLS connections.
SO_TLS_CERT (3)
Sets the path to the TLS certificate file for server-side TLS sockets.
- Type: string
- Value: Path to a PEM-formatted certificate file
- Use Case: Server sockets that accept TLS connections
This option is required for TLS server sockets before calling socket_listen(). The certificate file must be in PEM format and readable by the driver.
SO_TLS_KEY (4)
Sets the path to the TLS private key file for server-side TLS sockets.
- Type: string
- Value: Path to a PEM-formatted private key file
- Use Case: Server sockets that accept TLS connections
This option is required for TLS server sockets before calling socket_listen(). The private key file must be in PEM format, match the certificate, and be readable by the driver.
ERRORS
- Generates an error if the socket descriptor is invalid
- Generates an error if the option is unknown
- Generates an error if the value type doesn't match the option requirements
EXAMPLES
Basic TLS client connection with verification:
void connect_to_server() {
int sock;
// Create a TLS client socket
sock = socket_create(STREAM_TLS, "read_callback", "close_callback");
// Enable peer verification (default, but shown explicitly)
socket_set_option(sock, SO_TLS_VERIFY_PEER, 1);
// Set SNI hostname
socket_set_option(sock, SO_TLS_SNI_HOSTNAME, "api.example.com");
// Now connect
socket_connect(sock, "api.example.com:443", "read_callback", "write_callback");
}
Testing/development with self-signed certificates:
void connect_to_dev_server() {
int sock;
sock = socket_create(STREAM_TLS, "read_callback", "close_callback");
// ONLY for testing with self-signed certificates!
// DO NOT USE IN PRODUCTION
socket_set_option(sock, SO_TLS_VERIFY_PEER, 0);
socket_set_option(sock, SO_TLS_SNI_HOSTNAME, "dev.example.com");
socket_connect(sock, "dev.example.com:8443", "read_callback", "write_callback");
}
HTTPS API client:
void fetch_api_data() {
int sock;
sock = socket_create(STREAM_TLS, "api_read", "api_close");
// Verify the API server's certificate
socket_set_option(sock, SO_TLS_VERIFY_PEER, 1);
// Set SNI for the API endpoint
socket_set_option(sock, SO_TLS_SNI_HOSTNAME, "api.mudserver.com");
socket_connect(sock, "api.mudserver.com:443", "api_connected");
}
void api_connected(int sock) {
socket_write(sock, "GET /data HTTP/1.1\r\n"
"Host: api.mudserver.com\r\n"
"Connection: close\r\n\r\n");
}
TLS server accepting HTTPS connections:
void create_https_server() {
int sock;
// Create a TLS server socket
sock = socket_create(STREAM_TLS, "read_callback", "close_callback");
// Set certificate and key for server-side TLS
socket_set_option(sock, SO_TLS_CERT, "/secure/certs/server.crt");
socket_set_option(sock, SO_TLS_KEY, "/secure/certs/server.key");
// Bind to port
socket_bind(sock, 8443);
// Start listening for TLS connections
socket_listen(sock, "listen_callback");
}
void listen_callback(int listen_sock) {
// Accept the TLS connection (SSL handshake happens automatically)
int client_sock = socket_accept(listen_sock, "client_read", "client_write");
}
void client_read(int sock, string data) {
// Data is automatically decrypted
write("Received encrypted data: " + data);
}
SEE ALSO
- socket_get_option - Get socket options
- socket_create - Create a socket
- socket_connect - Connect a socket
- socket_accept - Accept connections
NOTES
Option Constants: The option constants should be defined in your mudlib include files:
#define SO_TLS_VERIFY_PEER 1
#define SO_TLS_SNI_HOSTNAME 2
#define SO_TLS_CERT 3
#define SO_TLS_KEY 4
TLS Socket Modes: These options only apply to sockets created with TLS modes:
STREAM_TLS- TLS socket modeSTREAM_TLS_BINARY- TLS binary mode
Timing: Options must be set before the socket is connected. Setting options after connection establishment may have no effect or cause errors.
Certificate Verification: When SO_TLS_VERIFY_PEER is enabled, the driver uses the system's trusted Certificate Authority store to verify certificates. Ensure your system's CA certificates are up to date.
AVAILABILITY
Added in commit 1fd7f61 (2023). Requires the sockets package to be enabled.