tor  0.4.2.1-alpha-dev
Functions
kvline.c File Reference
#include "orconfig.h"
#include "lib/container/smartlist.h"
#include "lib/encoding/confline.h"
#include "lib/encoding/cstring.h"
#include "lib/encoding/kvline.h"
#include "lib/encoding/qstring.h"
#include "lib/malloc/malloc.h"
#include "lib/string/compat_ctype.h"
#include "lib/string/printf.h"
#include "lib/string/util_string.h"
#include "lib/log/escape.h"
#include "lib/log/util_bug.h"
#include <stdbool.h>
#include <stddef.h>
#include <string.h>

Go to the source code of this file.

Functions

static bool needs_escape (const char *s, bool as_keyless_val)
 
static bool line_has_no_key (const config_line_t *line)
 
static bool line_has_no_val (const config_line_t *line)
 
static bool kvline_can_encode_lines (const config_line_t *line, unsigned flags)
 
char * kvline_encode (const config_line_t *line, unsigned flags)
 
config_line_tkvline_parse (const char *line, unsigned flags)
 

Detailed Description

Manipulating lines of key-value pairs.

Definition in file kvline.c.

Function Documentation

◆ kvline_can_encode_lines()

static bool kvline_can_encode_lines ( const config_line_t line,
unsigned  flags 
)
static

Return true iff the all the lines in line can be encoded using flags.

Definition at line 71 of file kvline.c.

References line_has_no_key().

◆ kvline_encode()

char* kvline_encode ( const config_line_t line,
unsigned  flags 
)

Encode a linked list of lines in line as a series of 'Key=Value' pairs, using the provided flags to encode it. Return a newly allocated string on success, or NULL on failure.

If KV_QUOTED is set in flags, then all values that contain spaces or unusual characters are escaped and quoted. Otherwise, such values are not allowed.

If KV_OMIT_KEYS is set in flags, then pairs with empty keys are allowed, and are encoded as 'Value'. Otherwise, such pairs are not allowed.

If KV_OMIT_VALS is set in flags, then an empty value is encoded as 'Key', not as 'Key=' or 'Key=""'. Mutually exclusive with KV_OMIT_KEYS.

KV_QUOTED_QSTRING is not supported.

Definition at line 119 of file kvline.c.

References tor_assert().

◆ kvline_parse()

config_line_t* kvline_parse ( const char *  line,
unsigned  flags 
)

Decode a line containing a series of space-separated 'Key=Value' pairs, using the provided flags to decode it. Return a newly allocated list of pairs on success, or NULL on failure.

If KV_QUOTED is set in flags, then (double-)quoted values are allowed and handled as C strings. Otherwise, such values are not allowed.

If KV_OMIT_KEYS is set in flags, then values without keys are allowed. Otherwise, such values are not allowed.

If KV_OMIT_VALS is set in flags, then keys without values are allowed. Otherwise, such keys are not allowed. Mutually exclusive with KV_OMIT_KEYS.

If KV_QUOTED_QSTRING is set in flags, then double-quoted values are allowed and handled as QuotedStrings per qstring.c. Do not add new users of this flag.

Definition at line 192 of file kvline.c.

References tor_assert().

◆ line_has_no_key()

static bool line_has_no_key ( const config_line_t line)
static

Return true iff the key in line is not set.

Definition at line 52 of file kvline.c.

Referenced by kvline_can_encode_lines().

◆ line_has_no_val()

static bool line_has_no_val ( const config_line_t line)
static

Return true iff the value in line is not set.

Definition at line 61 of file kvline.c.

◆ needs_escape()

static bool needs_escape ( const char *  s,
bool  as_keyless_val 
)
static

Return true iff we need to quote and escape the string s to encode it.

Definition at line 34 of file kvline.c.