source/extensions/dynamic_modules/STYLE.md
This document defines the naming conventions and style guidelines for the Dynamic Modules ABI header (abi.h). All ABI definitions must follow these conventions to maintain consistency and clarity across the codebase.
Dynamic module mainly has two types of functions: event hooks and callbacks. The event hooks are implemented by the dynamic module and called by Envoy, while the callbacks are implemented by Envoy and called by the dynamic module.
For all event hooks, the return type could be any reasonable type that fits the purpose of the event hook.
For callbacks, the return type should be one of the following:
number, bool, enum, pointer), and function calling never fails or zero has no difference as calling failure, return the simple type directly (e.g., size_t, bool, enum type, pointer type).bool or enum as the return type to indicate success or failure.And for both event hooks and callbacks, follow these guidelines:
Example:
/**
* @return envoy_dynamic_module_type_http_filter_module_ptr is the pointer to the in-module HTTP
* filter. Returning nullptr indicates a failure to initialize the module.
*/
Example:
/**
* @param filter_config_ptr is the pointer to the in-module HTTP filter configuration.
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object.
* @param end_of_stream is true if this is the final data frame.
*/
All ABI types are prefixed with envoy_dynamic_module_type_ to avoid naming conflicts.
Format:
envoy_dynamic_module_type_<name>
Examples:
envoy_dynamic_module_type_http_filter_module_ptrenvoy_dynamic_module_type_envoy_bufferenvoy_dynamic_module_type_http_header_typeTypes use suffixes to indicate memory ownership:
_module_ptr: Memory allocated and owned by the dynamic module_envoy_ptr: Memory allocated and owned by Envoy_envoy_buffer: Buffer owned by Envoy_module_buffer: Buffer owned by the dynamic module_envoy_http_header: HTTP header owned by Envoy_module_http_header: HTTP header owned by the dynamic moduleAll event hooks are prefixed with envoy_dynamic_module_on_ and use snake_case for the remainder.
Format:
envoy_dynamic_module_on_<component>_<event>
Examples:
envoy_dynamic_module_on_program_initenvoy_dynamic_module_on_http_filter_request_headersenvoy_dynamic_module_on_http_filter_config_destroyAll callbacks are prefixed with envoy_dynamic_module_callback_ and use snake_case.
Format:
envoy_dynamic_module_callback_<component>_<action>
Examples:
envoy_dynamic_module_callback_logenvoy_dynamic_module_callback_http_get_metadata_valueAll functions must have a documentation block with:
@param@returnTemplate:
/**
* envoy_dynamic_module_on_<name> <brief description>.
*
* <Detailed explanation of when/why this is called.>
*
* @param <name> <description>.
* @return <type> <description of return values and their meanings>.
*/
Struct and enum documentation must include:
Template:
/**
* envoy_dynamic_module_type_<name> <brief description>.
*
* <Detailed explanation of the type's purpose and usage.>
*
* OWNERSHIP: <Module/Envoy> owns the pointer.
*/
Example:
typedef enum envoy_dynamic_module_type_http_header_type {
envoy_dynamic_module_type_http_header_type_RequestHeader,
envoy_dynamic_module_type_http_header_type_RequestTrailer,
envoy_dynamic_module_type_http_header_type_ResponseHeader,
envoy_dynamic_module_type_http_header_type_ResponseTrailer,
} envoy_dynamic_module_type_http_header_type;
Example:
typedef struct envoy_dynamic_module_type_module_buffer {
envoy_dynamic_module_type_buffer_module_ptr ptr;
size_t length;
} envoy_dynamic_module_type_module_buffer;