Tor 0.4.9.0-alpha-dev
Functions
typedvar.c File Reference

Functions for accessing a pointer as an object of a given type. More...

#include "orconfig.h"
#include "lib/conf/conftypes.h"
#include "lib/confmgt/type_defs.h"
#include "lib/confmgt/typedvar.h"
#include "lib/encoding/confline.h"
#include "lib/log/escape.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/malloc/malloc.h"
#include "lib/string/printf.h"
#include "lib/string/util_string.h"
#include "lib/confmgt/var_type_def_st.h"
#include <stddef.h>
#include <string.h>

Go to the source code of this file.

Functions

int typed_var_assign (void *target, const char *value, char **errmsg, const var_type_def_t *def)
 
int typed_var_kvassign (void *target, const config_line_t *line, char **errmsg, const var_type_def_t *def)
 
void typed_var_free (void *target, const var_type_def_t *def)
 
char * typed_var_encode (const void *value, const var_type_def_t *def)
 
config_line_ttyped_var_kvencode (const char *key, const void *value, const var_type_def_t *def)
 
int typed_var_copy (void *dest, const void *src, const var_type_def_t *def)
 
bool typed_var_eq (const void *a, const void *b, const var_type_def_t *def)
 
bool typed_var_ok (const void *value, const var_type_def_t *def)
 
void typed_var_mark_fragile (void *value, const var_type_def_t *def)
 

Detailed Description

Functions for accessing a pointer as an object of a given type.

These functions represent a low-level API for accessing a typed variable. They are used in the configuration system to examine and set fields in configuration objects used by individual modules.

Almost no code should call these directly.

Definition in file typedvar.c.

Function Documentation

◆ typed_var_assign()

int typed_var_assign ( void *  target,
const char *  value,
char **  errmsg,
const var_type_def_t def 
)

Try to parse a string in value that encodes an object of the type defined by def.

On success, adjust the lvalue pointed to by target to hold that value, and return 0. On failure, set *errmsg to a newly allocated string holding an error message, and return -1.

Definition at line 44 of file typedvar.c.

◆ typed_var_copy()

int typed_var_copy ( void *  dest,
const void *  src,
const var_type_def_t def 
)

Set dest to contain the same value as src. Both types must be as defined by def.

Return 0 on success, and -1 on failure.

Definition at line 154 of file typedvar.c.

Referenced by struct_var_copy().

◆ typed_var_encode()

char * typed_var_encode ( const void *  value,
const var_type_def_t def 
)

Encode a value of type def pointed to by value, and return its result in a newly allocated string. The string may need to be escaped.

Returns NULL if this option has a NULL value, or on internal error.

Definition at line 111 of file typedvar.c.

◆ typed_var_eq()

bool typed_var_eq ( const void *  a,
const void *  b,
const var_type_def_t def 
)

Return true if a and b are semantically equivalent. Both types must be as defined by def.

Definition at line 187 of file typedvar.c.

Referenced by struct_var_eq().

◆ typed_var_free()

void typed_var_free ( void *  target,
const var_type_def_t def 
)

Release storage held by a variable in target of type defined by def, and set target to a reasonable default.

Definition at line 95 of file typedvar.c.

Referenced by struct_var_free().

◆ typed_var_kvassign()

int typed_var_kvassign ( void *  target,
const config_line_t line,
char **  errmsg,
const var_type_def_t def 
)

Try to parse a single line from the head ofline that encodes an object of the type defined in def. On success and failure, behave as typed_var_assign().

All types for which keys are significant should use this function.

Note that although multiple lines may be provided in line, only the first one is handled by this function.

Definition at line 67 of file typedvar.c.

Referenced by struct_var_kvassign().

◆ typed_var_kvencode()

config_line_t * typed_var_kvencode ( const char *  key,
const void *  value,
const var_type_def_t def 
)

As typed_var_encode(), but returns a newly allocated config_line_t object. The provided key is used as the key of the lines, unless the type is one (line a linelist) that encodes its own keys.

This function may return a list of multiple lines.

Returns NULL if there are no lines to encode, or on internal error.

Definition at line 129 of file typedvar.c.

Referenced by struct_var_kvencode().

◆ typed_var_mark_fragile()

void typed_var_mark_fragile ( void *  value,
const var_type_def_t def 
)

Mark value – a variable that ordinarily would be extended by assignment – as "fragile", so that it will get replaced by the next assignment instead.

Definition at line 228 of file typedvar.c.

Referenced by struct_var_mark_fragile().

◆ typed_var_ok()

bool typed_var_ok ( const void *  value,
const var_type_def_t def 
)

Check whether value encodes a valid value according to the type definition in def.

Definition at line 211 of file typedvar.c.

Referenced by struct_var_ok().