OpenVPN
Data Structures | Macros | Functions
test_options_parse.c File Reference
#include "syshead.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <setjmp.h>
#include <cmocka.h>
#include "options.h"
#include "test_common.h"
#include "mock_msg.h"
Include dependency graph for test_options_parse.c:

Go to the source code of this file.

Data Structures

union  tokens_parameter
 

Macros

#define A_TIMES_256   "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO"
 
#define PARSE_LINE_TST(string)
 
#define LargestIntegralType   uintmax_t
 

Functions

void add_option (struct options *options, char *p[], bool is_inline, const char *file, int line, const int level, const msglvl_t msglevel, const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
 
void remove_option (struct context *c, struct options *options, char *p[], bool is_inline, const char *file, int line, const msglvl_t msglevel, const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
 Resets options found in the PUSH_UPDATE message that are preceded by the - flag.
 
void update_option (struct context *c, struct options *options, char *p[], bool is_inline, const char *file, int line, const int level, const msglvl_t msglevel, const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es, unsigned int *update_options_found)
 Processes an option to update.
 
void usage (void)
 
static void test_parse_line (void **state)
 
static void read_single_config (struct options *options, const char *config)
 
static int check_tokens (const LargestIntegralType value, const LargestIntegralType expected)
 
static void test_read_config (void **state)
 
int main (void)
 

Macro Definition Documentation

◆ A_TIMES_256

#define A_TIMES_256   "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO"

Definition at line 73 of file test_options_parse.c.

◆ LargestIntegralType

#define LargestIntegralType   uintmax_t

Definition at line 209 of file test_options_parse.c.

◆ PARSE_LINE_TST

#define PARSE_LINE_TST (   string)
Value:
do \
{ \
CLEAR(p); \
res = parse_line(string, p, SIZE(p) - 1, "test_options_parse", 1, M_INFO, &gc); \
} while (0);
#define M_INFO
Definition errlevel.h:54
#define SIZE(x)
Definition basic.h:29
int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num, msglvl_t msglevel, struct gc_arena *gc)
char ** res
struct gc_arena gc
Definition test_ssl.c:131

Function Documentation

◆ add_option()

void add_option ( struct options options,
char *  p[],
bool  is_inline,
const char *  file,
int  line,
const int  level,
const msglvl_t  msglevel,
const unsigned int  permission_mask,
unsigned int *  option_types_found,
struct env_set es 
)

Definition at line 41 of file test_options_parse.c.

Referenced by test_read_config().

◆ check_tokens()

static int check_tokens ( const LargestIntegralType  value,
const LargestIntegralType  expected 
)
static

Definition at line 219 of file test_options_parse.c.

References tokens_parameter::as_int, tokens_parameter::as_pointer, i, and MAX_PARMS.

Referenced by test_read_config().

◆ main()

int main ( void  )

Definition at line 308 of file test_options_parse.c.

References test_parse_line(), and test_read_config().

◆ read_single_config()

static void read_single_config ( struct options options,
const char *  config 
)
static

Definition at line 192 of file test_options_parse.c.

References CLEAR, es, M_INFO, OPT_P_DEFAULT, and read_config_string().

Referenced by test_read_config().

◆ remove_option()

void remove_option ( struct context c,
struct options options,
char *  p[],
bool  is_inline,
const char *  file,
int  line,
const msglvl_t  msglevel,
const unsigned int  permission_mask,
unsigned int *  option_types_found,
struct env_set es 
)

Resets options found in the PUSH_UPDATE message that are preceded by the - flag.

This function is used in push-updates to reset specified options. The number of parameters p must always be 1. If the permission is verified, all related options are erased or reset to their default values. Upon successful permission verification (by VERIFY_PERMISSION()), option_types_found is filled with the flag corresponding to the option.

Parameters
cThe context structure.
optionsA pointer to the options structure.
pAn array of strings containing the options and their parameters.
is_inlineA boolean indicating if the option is inline.
fileThe file where the function is called.
lineThe line number where the function is called.
msglevelThe message level.
permission_maskThe permission mask used by VERIFY_PERMISSION().
option_types_foundA pointer to the variable where the flags corresponding to the options found are stored.
esThe environment set structure.

Definition at line 52 of file test_options_parse.c.

◆ test_parse_line()

static void test_parse_line ( void **  state)
static

Definition at line 76 of file test_options_parse.c.

References A_TIMES_256, gc, gc_free(), gc_new(), i, MAX_PARMS, PARSE_LINE_TST, and res.

Referenced by main().

◆ test_read_config()

static void test_read_config ( void **  state)
static

◆ update_option()

void update_option ( struct context c,
struct options options,
char *  p[],
bool  is_inline,
const char *  file,
int  line,
const int  level,
const msglvl_t  msglevel,
const unsigned int  permission_mask,
unsigned int *  option_types_found,
struct env_set es,
unsigned int *  update_options_found 
)

Processes an option to update.

It first checks whether it has already received an option of the same type within the same update message. If the option has already been received, it calls add_option(). Otherwise, it deletes all existing values related to that option before calling add_option().

Parameters
cThe context structure.
optionsA pointer to the options structure.
pAn array of strings containing the options and their parameters.
is_inlineA boolean indicating if the option is inline.
fileThe file where the function is called.
lineThe line number where the function is called.
levelThe level of the option.
msglevelThe message level for logging.
permission_maskThe permission mask used by VERIFY_PERMISSION().
option_types_foundA pointer to the variable where the flags corresponding to the options found are stored.
esThe environment set structure.
update_options_foundA pointer to the variable where the flags corresponding to the update options found are stored, used to check if an option of the same type has already been processed by update_option() within the same push-update message.

Definition at line 60 of file test_options_parse.c.

◆ usage()

void usage ( void  )

Definition at line 68 of file test_options_parse.c.