Quantum Secure Tunneling Protocol 1.0.0.0a (A1)
A three-party quantum secure encrypted tunneling protocol
logger.h File Reference

QSTP logging functions. More...

#include "common.h"

Go to the source code of this file.

Macros

#define QSTP_LOGGING_MESSAGE_MAX   256
 Maximum length of a log message.
 

Functions

bool qstp_logger_exists (void)
 Test if the log file exists.
 
void qstp_logger_initialize (const char *path)
 Initialize the logger.
 
void qstp_logger_print (void)
 Print the log file.
 
void qstp_logger_read (char *output, size_t otplen)
 Read the log file into a buffer.
 
void qstp_logger_reset (void)
 Reset the logger.
 
size_t qstp_logger_size (void)
 Get the size of the log file.
 
bool qstp_logger_write (const char *message)
 Write a message to the log file.
 
bool qstp_logger_test (void)
 Run a manual test of the logger functions.
 

Detailed Description

QSTP logging functions.

This header defines the internal logging functions for the Quantum Secure Tunneling Protocol (QSTP). These functions provide a basic logging subsystem to record operational events, errors, and diagnostic messages during QSTP execution. The logging system is designed for debugging and monitoring purposes and includes functionality to initialize the log, write messages, read and print the log, reset (clear) the log, and retrieve the current log file size.

The logging subsystem uses several defined constants:

  • QSTP_LOGGING_MESSAGE_MAX: Defines the maximum allowed length (in characters) for a single log message.
  • QSTP_LOGGER_PATH: The default directory path where the QSTP log file is stored.
  • QSTP_LOGGER_FILE: The default log filename.
  • QSTP_LOGGER_HEAD: The header string written to the log file at initialization, which typically includes version information.

The logger also includes a built-in manual test (qstp_logger_test()) that exercises all of the logging functions to ensure proper operation.

Note
These functions and constants are internal and non-exportable.

Macro Definition Documentation

◆ QSTP_LOGGING_MESSAGE_MAX

#define QSTP_LOGGING_MESSAGE_MAX   256

Maximum length of a log message.

This macro defines the maximum number of characters allowed for a single log message.

Function Documentation

◆ qstp_logger_exists()

bool qstp_logger_exists ( void )

Test if the log file exists.

This function checks whether the QSTP log file exists in the configured logging directory.

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

◆ qstp_logger_initialize()

void qstp_logger_initialize ( const char * path)

Initialize the logger.

This function initializes the QSTP logging subsystem. It sets the log file path to the provided value and creates the log file if it does not already exist, writing the default header (QSTP_LOGGER_HEAD) to the file.

Parameters
pathA pointer to a null-terminated string specifying the log file path.

◆ qstp_logger_print()

void qstp_logger_print ( void )

Print the log file.

This function outputs the contents of the QSTP log file to the standard output or a designated debug console. It is useful for real-time debugging and monitoring of log messages.

◆ qstp_logger_read()

void qstp_logger_read ( char * output,
size_t otplen )

Read the log file into a buffer.

This function reads the contents of the QSTP log file into the provided output array. The caller must ensure that the output buffer is large enough to hold the log contents.

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

◆ qstp_logger_reset()

void qstp_logger_reset ( void )

Reset the logger.

This function erases all contents of the QSTP log file, effectively resetting the log. This is useful for clearing old log data before starting a new session or for troubleshooting.

◆ qstp_logger_size()

size_t qstp_logger_size ( void )

Get the size of the log file.

This function returns the current size (in bytes) of the QSTP log file.

Returns
Returns the size of the log file in bytes.

◆ qstp_logger_test()

bool qstp_logger_test ( void )

Run a manual test of the logger functions.

This function performs a manual test of the QSTP logging subsystem. The test includes:

  • Checking if the log file exists.
  • Initializing the logger with a test path.
  • Writing test messages to the log.
  • Reading and printing the log contents.
  • Resetting the log and verifying that the log is cleared.

This test ensures that all logging operations (initialization, writing, reading, resetting, and size retrieval) function as expected.

Returns
Returns true if all logger tests pass successfully.

◆ qstp_logger_write()

bool qstp_logger_write ( const char * message)

Write a message to the log file.

This function appends the provided log message to the QSTP log file. The message should be a null-terminated string and must not exceed QSTP_LOGGING_MESSAGE_MAX characters.

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