Tor  0.4.7.0-alpha-dev
Functions
confline.c File Reference

Functions to manipulate a linked list of key-value pairs, of the type used in Tor's configuration files. More...

#include "lib/encoding/confline.h"
#include "lib/encoding/cstring.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/malloc/malloc.h"
#include "lib/string/compat_ctype.h"
#include "lib/string/compat_string.h"
#include "lib/string/util_string.h"
#include <string.h>

Go to the source code of this file.

Functions

void config_line_append (config_line_t **lst, const char *key, const char *val)
 
void config_line_prepend (config_line_t **lst, const char *key, const char *val)
 
const config_line_tconfig_line_find (const config_line_t *lines, const char *key)
 
const config_line_tconfig_line_find_case (const config_line_t *lines, const char *key)
 
int config_get_lines_aux (const char *string, config_line_t **result, int extended, int allow_include, int *has_include, struct smartlist_t *opened_lst, int recursion_level, config_line_t **last, include_handler_fn handle_include)
 
int config_get_lines (const char *string, config_line_t **result, int extended)
 
void config_free_lines_ (config_line_t *front)
 
config_line_tconfig_lines_dup (const config_line_t *inp)
 
config_line_tconfig_lines_dup_and_filter (const config_line_t *inp, const char *key)
 
config_line_tconfig_lines_partition (config_line_t *inp, const char *header)
 
int config_lines_eq (const config_line_t *a, const config_line_t *b)
 
int config_count_key (const config_line_t *a, const char *key)
 
const char * parse_config_line_from_str_verbose (const char *line, char **key_out, char **value_out, const char **err_out)
 

Detailed Description

Functions to manipulate a linked list of key-value pairs, of the type used in Tor's configuration files.

Tor uses the config_line_t type and its associated serialized format for human-readable key-value pairs in many places, including its configuration, its state files, its consensus cache, and so on.

Definition in file confline.c.

Function Documentation

◆ config_count_key()

int config_count_key ( const config_line_t a,
const char *  key 
)

Return the number of lines in a whose key is key.

Definition at line 302 of file confline.c.

◆ config_free_lines_()

void config_free_lines_ ( config_line_t front)

Free all the configuration lines on the linked list front.

Definition at line 210 of file confline.c.

◆ config_get_lines()

int config_get_lines ( const char *  string,
config_line_t **  result,
int  extended 
)

Same as config_get_lines_include but does not allow include

Definition at line 200 of file confline.c.

Referenced by storage_dir_map_labeled().

◆ config_get_lines_aux()

int config_get_lines_aux ( const char *  string,
config_line_t **  result,
int  extended,
int  allow_include,
int *  has_include,
struct smartlist_t opened_lst,
int  recursion_level,
config_line_t **  last,
include_handler_fn  handle_include 
)

Auxiliary function that does all the work of config_get_lines. recursion_level is the count of how many nested includes we have. opened_lst will have a list of opened files if provided. Returns the a pointer to the last element of the result in last.

Definition at line 104 of file confline.c.

Referenced by config_get_lines(), and config_get_lines_include().

◆ config_line_append()

void config_line_append ( config_line_t **  lst,
const char *  key,
const char *  val 
)

Helper: allocate a new configuration option mapping 'key' to 'val', append it to *lst.

Definition at line 32 of file confline.c.

Referenced by get_options_defaults().

◆ config_line_find()

const config_line_t* config_line_find ( const config_line_t lines,
const char *  key 
)

Return the first line in lines whose key is exactly key, or NULL if no such key exists.

(In options parsing, this is for handling commandline-only options only; other options should be looked up in the appropriate data structure.)

Definition at line 74 of file confline.c.

Referenced by consensus_cache_entry_get_value(), and options_init_from_torrc().

◆ config_line_find_case()

const config_line_t* config_line_find_case ( const config_line_t lines,
const char *  key 
)

As config_line_find(), but perform a case-insensitive comparison.

Definition at line 87 of file confline.c.

Referenced by config_lines_contain_flag(), and handle_control_postdescriptor().

◆ config_line_prepend()

void config_line_prepend ( config_line_t **  lst,
const char *  key,
const char *  val 
)

Helper: allocate a new configuration option mapping 'key' to 'val', and prepend it to *lst

Definition at line 53 of file confline.c.

Referenced by directory_request_add_header().

◆ config_lines_dup()

config_line_t* config_lines_dup ( const config_line_t inp)

Return a newly allocated deep copy of the lines in inp.

Definition at line 226 of file confline.c.

Referenced by consensus_compress_worker_threadfn(), control_setconf_helper(), and dirauth_options_pre_normalize().

◆ config_lines_dup_and_filter()

config_line_t* config_lines_dup_and_filter ( const config_line_t inp,
const char *  key 
)

Return a newly allocated deep copy of the lines in inp, but only the ones whose keys begin with key (case-insensitive). If key is NULL, do not filter.

Definition at line 235 of file confline.c.

Referenced by config_lines_dup().

◆ config_lines_eq()

int config_lines_eq ( const config_line_t a,
const config_line_t b 
)

Return true iff a and b contain identical keys and values in identical order.

Definition at line 287 of file confline.c.

Referenced by options_act_bridge_stats().

◆ config_lines_partition()

config_line_t* config_lines_partition ( config_line_t inp,
const char *  header 
)

Given a linelist inp beginning with the key header, find the next line with that key, and remove that instance and all following lines from the list. Return the lines that were removed. Operate case-insensitively.

For example, if the header is "H", and inp contains "H, A, B, H, C, H, D", this function will alter inp to contain only "H, A, B", and return the elements "H, C, H, D" as a separate list.

Definition at line 266 of file confline.c.

◆ parse_config_line_from_str_verbose()

const char* parse_config_line_from_str_verbose ( const char *  line,
char **  key_out,
char **  value_out,
const char **  err_out 
)

Given a string containing part of a configuration file or similar format, advance past comments and whitespace and try to parse a single line. If we parse a line successfully, set *key_out to a new string holding the key portion and *value_out to a new string holding the value portion of the line, and return a pointer to the start of the next line. If we run out of data, return a pointer to the end of the string. If we encounter an error, return NULL and set *err_out (if provided) to an error message.

Definition at line 324 of file confline.c.