tor  0.4.2.0-alpha-dev
Data Fields
var_type_fns_t Struct Reference

#include <var_type_def_st.h>

Data Fields

int(* parse )(void *target, const char *value, char **errmsg, const void *params)
 
int(* kv_parse )(void *target, const struct config_line_t *line, char **errmsg, const void *params)
 
char *(* encode )(const void *value, const void *params)
 
struct config_line_t *(* kv_encode )(const char *key, const void *value, const void *params)
 
void(* clear )(void *arg, const void *params)
 
bool(* eq )(const void *a, const void *b, const void *params)
 
int(* copy )(void *target, const void *value, const void *params)
 
bool(* ok )(const void *value, const void *params)
 
void(* mark_fragile )(void *value, const void *params)
 

Detailed Description

A structure full of functions pointers to implement a variable type.

Every type MUST implement parse or kv_parse and encode or kv_encode; the other functions pointers MAY be NULL.

All functions here take a params argument, whose value is determined by the type definition. Two types may have the same functions, but differ only in parameters.

Definition at line 43 of file var_type_def_st.h.

Field Documentation

◆ clear

void(* var_type_fns_t::clear) (void *arg, const void *params)

Free all storage held in arg, and set arg to a default value – usually zero or NULL.

If this function is absent, the default implementation does nothing.

Definition at line 100 of file var_type_def_st.h.

◆ copy

int(* var_type_fns_t::copy) (void *target, const void *value, const void *params)

Try to copy the value from value into target. On success return 0; on failure return -1.

If this function is absent, it is implemented by encoding the value into a string, and then parsing it into the target.

Definition at line 116 of file var_type_def_st.h.

◆ encode

char*(* var_type_fns_t::encode) (const void *value, const void *params)

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

If this function is absent, it is implemented in terms of kv_encode().

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

Requirement: all strings generated by encode() should produce a semantically equivalent value when given to parse().

Definition at line 79 of file var_type_def_st.h.

◆ eq

bool(* var_type_fns_t::eq) (const void *a, const void *b, const void *params)

Return true if a and b hold the same value, and false otherwise.

If this function is absent, it is implemented by encoding both a and b and comparing their encoded strings for equality.

Definition at line 108 of file var_type_def_st.h.

◆ kv_encode

struct config_line_t*(* var_type_fns_t::kv_encode) (const char *key, const void *value, const void *params)

As 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 that encodes its own keys.

Unlike kv_parse(), this function will return a list of multiple lines, if value is such that it must be encoded by multiple lines.

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

If this function is absent, it is implemented in terms of encode().

Definition at line 92 of file var_type_def_st.h.

◆ kv_parse

int(* var_type_fns_t::kv_parse) (void *target, const struct config_line_t *line, char **errmsg, const void *params)

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

If this function is absent, it is implemented in terms of parse().

All types for which keys are significant should use this method. For example, a "linelist" type records the actual keys that are given for each line, and so should use this method.

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

Definition at line 66 of file var_type_def_st.h.

◆ mark_fragile

void(* var_type_fns_t::mark_fragile) (void *value, const void *params)

Mark a value of this variable as "fragile", so that future attempts to assign to this variable will replace rather than extending it.

The default implementation for this function does nothing.

Only meaningful for types with is_cumulative set.

Definition at line 133 of file var_type_def_st.h.

◆ ok

bool(* var_type_fns_t::ok) (const void *value, const void *params)

Check whether value holds a valid value according to the rules of this type; return true if it does and false if it doesn't.

The default implementation for this function assumes that all values are valid.

Definition at line 124 of file var_type_def_st.h.

Referenced by tor_version_parse().

◆ parse

int(* var_type_fns_t::parse) (void *target, const char *value, char **errmsg, const void *params)

Try to parse a string in value that encodes an object of this type. 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 50 of file var_type_def_st.h.


The documentation for this struct was generated from the following file: