QSMP: Quantum Secure Messaging Protocol 1.3.0.0a (A3)
A quantum secure encrypted tunneling protocol
logger.h File Reference

QSMP logging functions. More...

#include "common.h"

Go to the source code of this file.

Macros

#define QSMP_LOGGING_MESSAGE_MAX   256
 Maximum length of a log message.
 

Functions

bool qsmp_logger_exists (void)
 Check if the QSMP log file exists.
 
void qsmp_logger_initialize (const char *path)
 Initialize the QSMP logger.
 
void qsmp_logger_print (void)
 Print the contents of the QSMP log file.
 
void qsmp_logger_read (char *output, size_t otplen)
 Read the QSMP log file into a provided buffer.
 
void qsmp_logger_reset (void)
 Reset the QSMP log.
 
size_t qsmp_logger_size (void)
 Get the current size of the QSMP log file.
 
bool qsmp_logger_write (const char *message)
 Write a message to the QSMP log file.
 
bool qsmp_logger_test (void)
 Run a manual test of the QSMP logger functions.
 

Detailed Description

QSMP logging functions.

This header file defines the internal logging functions for the Quantum Secure Messaging Protocol (QSMP). The logging subsystem provides basic functionality to create, manage, and inspect log files. These functions allow the QSMP system to record operational events, errors, and other informational messages which can be used for debugging and monitoring purposes.

The following constants are defined:

  • QSMP_LOGGING_MESSAGE_MAX: Maximum length allowed for a single log message.
  • QSMP_LOGGER_PATH: The default directory path for QSMP log files.
  • QSMP_LOGGER_FILE: The default filename for the QSMP log.
  • QSMP_LOGGER_HEAD: The header string for the log file, which typically includes version information.
Note
These functions and constants are internal and non-exportable.

Macro Definition Documentation

◆ QSMP_LOGGING_MESSAGE_MAX

#define QSMP_LOGGING_MESSAGE_MAX   256

Maximum length of a log message.

This macro defines the maximum number of characters that a single log message may contain.

Function Documentation

◆ qsmp_logger_exists()

bool qsmp_logger_exists ( void )

Check if the QSMP log file exists.

This function checks for the existence of the QSMP log file in the configured logging directory.

Returns
Returns true if the log file exists; otherwise, false.

◆ qsmp_logger_initialize()

void qsmp_logger_initialize ( const char * path)

Initialize the QSMP logger.

This function initializes the logging subsystem by setting the log file path and creating the log file if it does not already exist. The default header (QSMP_LOGGER_HEAD) is written to the log file upon initialization.

Parameters
pathThe file path or directory where the log file should be created.

◆ qsmp_logger_print()

void qsmp_logger_print ( void )

Print the contents of the QSMP log file.

This function outputs the entire contents of the QSMP log file to the standard output or designated debug stream. It is useful for real-time monitoring and debugging purposes.

◆ qsmp_logger_read()

void qsmp_logger_read ( char * output,
size_t otplen )

Read the QSMP log file into a provided buffer.

This function reads the content of the QSMP log file and copies it into the specified output buffer. The caller must ensure that the output buffer is large enough to hold the log data, up to otplen bytes.

Parameters
outputA pointer to the buffer where the log content will be stored.
otplenThe size, in bytes, of the output buffer.

◆ qsmp_logger_reset()

void qsmp_logger_reset ( void )

Reset the QSMP log.

This function erases all the contents of the QSMP log file, effectively resetting it to an empty state. This operation is useful for clearing old log data before starting a new session.

◆ qsmp_logger_size()

size_t qsmp_logger_size ( void )

Get the current size of the QSMP log file.

This function returns the size of the log file in bytes. It can be used to monitor log growth and manage log rotation.

Returns
The size of the log file in bytes.

◆ qsmp_logger_test()

bool qsmp_logger_test ( void )

Run a manual test of the QSMP logger functions.

This function performs a series of tests on the QSMP logging subsystem. The test routine includes:

  • Initializing the logger with a test path.
  • Writing one or more test messages to the log.
  • Reading and printing the log content.
  • Resetting the log and verifying that it has been cleared.
  • Checking the reported log file size.

The function returns true if all logger operations work as expected.

Returns
Returns true if all logger tests succeed; otherwise, false.

◆ qsmp_logger_write()

bool qsmp_logger_write ( const char * message)

Write a message to the QSMP log file.

This function writes the specified log message to the QSMP log file. The message should be a null-terminated string, and its length should not exceed QSMP_LOGGING_MESSAGE_MAX characters.

Parameters
message[const] The log message to be written.
Returns
Returns true if the message was successfully written to the log file; otherwise, false.