MySQL  8.0.20
Source Code Documentation
audit_api_message_emit.cc File Reference
#include <ctype.h>
#include <my_dbug.h>
#include <mysql/components/component_implementation.h>
#include <mysql/components/my_service.h>
#include <mysql/components/service_implementation.h>
#include <mysql/components/services/audit_api_message_service.h>
#include <mysql/components/services/udf_metadata.h>
#include <mysql/components/services/udf_registration.h>
#include <mysql/service_plugin_registry.h>
#include <mysql_com.h>
#include "template_utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <cstdarg>
#include <map>
#include <memory>
#include <string>

Classes

class  IError_handler
 Error handling interface. More...
 
struct  Arg_type
 Structure used for argument type validation. More...
 
struct  Arg_def
 Argument definition structure. More...
 
class  String_error_handler
 Error handler that copies error message into specified buffer. More...
 

Typedefs

typedef bool(* validate_function) (IError_handler &handler, const char *arg, unsigned long length, size_t arg_pos)
 Argument validation function prototype. More...
 

Functions

 REQUIRES_SERVICE_PLACEHOLDER (mysql_udf_metadata)
 audit_api_message_emit component exposes audit_log_message UDF that generates MYSQL_AUDIT_MESSAGE_USER event of the MYSQL_AUDIT_MESSAGE_CLASS class. More...
 
 REQUIRES_SERVICE_PLACEHOLDER (mysql_audit_api_message)
 
 REQUIRES_SERVICE_PLACEHOLDER (udf_registration)
 
static bool not_null (IError_handler &handler, const char *arg, unsigned long length, size_t arg_pos)
 Check, whether the argument is not null pointer. More...
 
size_t max_arg_count (Arg_def *arg_def, size_t arg_def_size)
 Max argument count of all definitions. More...
 
static bool set_args_charset_info (UDF_ARGS *args, IError_handler &handler)
 Set the character set and collation of each argument. More...
 
bool set_return_value_charset_info (UDF_INIT *initid, IError_handler &handler)
 Sets the charset info of the return value to utf8. More...
 
static int arg_check (IError_handler &handler, unsigned int arg_count, Item_result *arg_type, Arg_def *arg_def, size_t arg_def_size, char **args, unsigned long *arg_lengths, bool strict_arg_count=true)
 Check, whether specified arguments match the definitions. More...
 
static bool arg_check (IError_handler &handler, UDF_ARGS *args)
 Argument check for UDF provided arguments. More...
 
static char * emit (UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, unsigned char *null_value, unsigned char *error)
 UDF function itself. More...
 
static bool emit_init (UDF_INIT *initd, UDF_ARGS *args, char *message)
 UDF initialization. More...
 
static mysql_service_status_t init ()
 Component initialization. More...
 
static mysql_service_status_t deinit ()
 Component deinitialization. More...
 
 END_COMPONENT_PROVIDES ()
 
 REQUIRES_SERVICE (mysql_audit_api_message)
 
 REQUIRES_SERVICE (udf_registration)
 
 REQUIRES_SERVICE (mysql_udf_metadata)
 
 END_COMPONENT_REQUIRES ()
 
 METADATA ("mysql.author", "Oracle Corporation")
 
 METADATA ("mysql.license", "GPL")
 
 END_COMPONENT_METADATA ()
 

Variables

Arg_type audit_log_primary_args []
 Obligatory UDF parameters. More...
 
Arg_type audit_log_key_value_string_args []
 Key value string parameters. More...
 
Arg_type audit_log_key_value_int_args []
 Key value numeric parameters. More...
 
Arg_def audit_log_primary_args_def []
 Obligatory arguments definition (component, producer, message). More...
 
Arg_def audit_log_extra_args_def []
 Optional arguments defition (key, value). More...
 
mysql_component_t mysql_component_audit_api_message_emit
 

Typedef Documentation

◆ validate_function

typedef bool(* validate_function) (IError_handler &handler, const char *arg, unsigned long length, size_t arg_pos)

Argument validation function prototype.

Parameters
handlerError reporting handler.
argArgument value pointer.
lengthArgument value length.
arg_posArgument pos.

Function Documentation

◆ arg_check() [1/2]

static int arg_check ( IError_handler handler,
unsigned int  arg_count,
Item_result arg_type,
Arg_def arg_def,
size_t  arg_def_size,
char **  args,
unsigned long *  arg_lengths,
bool  strict_arg_count = true 
)
static

Check, whether specified arguments match the definitions.

Parameters
handlerError reporting handler.
arg_countNumber of arguments.
arg_typeArgument type array.
arg_defArgument definitions.
arg_def_sizeArgument definitions size.
argsUDF arguments.
arg_lengthsUDF argument lengths.
strict_arg_countStrictly check provided argument count. If this is set to false, if the provided argument count is greater, this does not return error.
Return values
-1None of the argument definition was matched.
>=0n-th argument definition was matched.

◆ arg_check() [2/2]

static bool arg_check ( IError_handler handler,
UDF_ARGS args 
)
static

Argument check for UDF provided arguments.

This checks both, obligatory and optional arguments.

Parameters
handlerError handler used for error handling.
argsUDF_ARGS structure.
Return values
falseSucceeded. Arguments are ok.
trueFailed. Error is reported via specified handler.

◆ deinit()

static mysql_service_status_t deinit ( )
static

Component deinitialization.

◆ emit()

static char* emit ( UDF_INIT initid,
UDF_ARGS args,
char *  result,
unsigned long *  length,
unsigned char *  null_value,
unsigned char *  error 
)
static

UDF function itself.

Allocate array that is used by the audit api service.

◆ emit_init()

static bool emit_init ( UDF_INIT initd,
UDF_ARGS args,
char *  message 
)
static

UDF initialization.

Check argument correctness.

Parameters
initdUDF initializer structure
argsUDF arguments.
messageBuffer, where the error is to be written.

◆ END_COMPONENT_METADATA()

END_COMPONENT_METADATA ( )

◆ END_COMPONENT_PROVIDES()

END_COMPONENT_PROVIDES ( )

◆ END_COMPONENT_REQUIRES()

END_COMPONENT_REQUIRES ( )

◆ init()

static mysql_service_status_t init ( )
static

Component initialization.

◆ max_arg_count()

size_t max_arg_count ( Arg_def arg_def,
size_t  arg_def_size 
)

Max argument count of all definitions.

Parameters
arg_defArgument definitions.
arg_def_sizeArgument definitions size.
Returns
Max argument count.

◆ METADATA() [1/2]

METADATA ( "mysql.author"  ,
"Oracle Corporation"   
)

◆ METADATA() [2/2]

METADATA ( "mysql.license"  ,
"GPL"   
)

◆ not_null()

static bool not_null ( IError_handler handler,
const char *  arg,
unsigned long  length,
size_t  arg_pos 
)
static

Check, whether the argument is not null pointer.

◆ REQUIRES_SERVICE() [1/3]

REQUIRES_SERVICE ( udf_registration  )

◆ REQUIRES_SERVICE() [2/3]

REQUIRES_SERVICE ( mysql_audit_api_message  )

◆ REQUIRES_SERVICE() [3/3]

REQUIRES_SERVICE ( mysql_udf_metadata  )

◆ REQUIRES_SERVICE_PLACEHOLDER() [1/3]

REQUIRES_SERVICE_PLACEHOLDER ( mysql_udf_metadata  )

audit_api_message_emit component exposes audit_log_message UDF that generates MYSQL_AUDIT_MESSAGE_USER event of the MYSQL_AUDIT_MESSAGE_CLASS class.

All installed audit plugins that subscribe MYSQL_AUDIT_MESSAGE_USER event will receive this event.

◆ REQUIRES_SERVICE_PLACEHOLDER() [2/3]

REQUIRES_SERVICE_PLACEHOLDER ( mysql_audit_api_message  )

◆ REQUIRES_SERVICE_PLACEHOLDER() [3/3]

REQUIRES_SERVICE_PLACEHOLDER ( udf_registration  )

◆ set_args_charset_info()

static bool set_args_charset_info ( UDF_ARGS args,
IError_handler handler 
)
static

Set the character set and collation of each argument.

Parameters
[in,out]argsUDF arguments structure
[out]handlerError handler
Return values
falseSet the charset of all arguments successully
trueOtherwise

◆ set_return_value_charset_info()

bool set_return_value_charset_info ( UDF_INIT initid,
IError_handler handler 
)

Sets the charset info of the return value to utf8.

Parameters
[in,out]initidA pointer to the UDF_INIT structure
[out]handlerError handler that keeps the error message
Return values
falseCharset info of return value set successfully.
trueOtherwise

Variable Documentation

◆ audit_log_extra_args_def

Arg_def audit_log_extra_args_def[]
Initial value:
= {
Arg_type audit_log_key_value_string_args[]
Key value string parameters.
Definition: audit_api_message_emit.cc:128
#define array_elements(A)
Definition: validate_password_imp.cc:45
Arg_type audit_log_key_value_int_args[]
Key value numeric parameters.
Definition: audit_api_message_emit.cc:133

Optional arguments defition (key, value).

◆ audit_log_key_value_int_args

Arg_type audit_log_key_value_int_args[]
Initial value:
{INT_RESULT, nullptr}}
not valid for UDFs
Definition: udf_registration_types.h:40
static bool not_null(IError_handler &handler, const char *arg, unsigned long length, size_t arg_pos)
Check, whether the argument is not null pointer.
Definition: audit_api_message_emit.cc:94
double
Definition: udf_registration_types.h:42

Key value numeric parameters.

◆ audit_log_key_value_string_args

Arg_type audit_log_key_value_string_args[]
Initial value:
{STRING_RESULT, nullptr}}
not valid for UDFs
Definition: udf_registration_types.h:40
static bool not_null(IError_handler &handler, const char *arg, unsigned long length, size_t arg_pos)
Check, whether the argument is not null pointer.
Definition: audit_api_message_emit.cc:94

Key value string parameters.

◆ audit_log_primary_args

Arg_type audit_log_primary_args[]
Initial value:
{STRING_RESULT, not_null},
{STRING_RESULT, not_null}}
not valid for UDFs
Definition: udf_registration_types.h:40
static bool not_null(IError_handler &handler, const char *arg, unsigned long length, size_t arg_pos)
Check, whether the argument is not null pointer.
Definition: audit_api_message_emit.cc:94

Obligatory UDF parameters.

◆ audit_log_primary_args_def

Arg_def audit_log_primary_args_def[]
Initial value:
= {
Arg_type audit_log_primary_args[]
Obligatory UDF parameters.
Definition: audit_api_message_emit.cc:122
#define array_elements(A)
Definition: validate_password_imp.cc:45

Obligatory arguments definition (component, producer, message).

◆ mysql_component_audit_api_message_emit

mysql_component_t mysql_component_audit_api_message_emit
Initial value:
= { "audit_api_message_emit" , __audit_api_message_emit_provides, __audit_api_message_emit_requires, __audit_api_message_emit_metadata,
static mysql_service_status_t deinit()
Component deinitialization.
Definition: audit_api_message_emit.cc:579
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:570