Tor  0.4.7.0-alpha-dev
Macros | Functions | Variables
microdesc_parse.c File Reference

Code to parse and validate microdescriptors. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/or/policies.h"
#include "feature/dirparse/microdesc_parse.h"
#include "feature/dirparse/parsecommon.h"
#include "feature/dirparse/routerparse.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/nickname.h"
#include "feature/nodelist/nodefamily.h"
#include "feature/relay/router.h"
#include "lib/crypt_ops/crypto_curve25519.h"
#include "lib/crypt_ops/crypto_ed25519.h"
#include "lib/crypt_ops/crypto_format.h"
#include "lib/memarea/memarea.h"
#include "feature/nodelist/microdesc_st.h"

Go to the source code of this file.

Macros

#define CHECK_LENGTH()
 
#define NEXT_LINE()
 

Functions

static const char * find_start_of_next_microdesc (const char *s, const char *eos)
 
static int policy_is_reject_star_or_null (struct short_policy_t *policy)
 
static const char * saved_location_to_string (saved_location_t where)
 
static int microdesc_extract_body (microdesc_t *md, const char *start, const char *s, const char *start_of_next_microdesc, saved_location_t where)
 
static int microdesc_parse_fields (microdesc_t *md, memarea_t *area, const char *s, const char *start_of_next_microdesc, int allow_annotations, saved_location_t where)
 
smartlist_tmicrodescs_parse_from_string (const char *s, const char *eos, int allow_annotations, saved_location_t where, smartlist_t *invalid_digests_out)
 

Variables

static token_rule_t microdesc_token_table []
 

Detailed Description

Code to parse and validate microdescriptors.

Definition in file microdesc_parse.c.

Macro Definition Documentation

◆ CHECK_LENGTH

#define CHECK_LENGTH ( )
Value:
STMT_BEGIN \
if (eos - s < 32) \
return NULL; \
STMT_END

◆ NEXT_LINE

#define NEXT_LINE ( )
Value:
STMT_BEGIN \
s = memchr(s, '\n', eos-s); \
if (!s || eos - s <= 1) \
return NULL; \
s++; \
STMT_END

Function Documentation

◆ find_start_of_next_microdesc()

static const char* find_start_of_next_microdesc ( const char *  s,
const char *  eos 
)
static

Assuming that s starts with a microdesc, return the start of the NEXT one. Return NULL on "not found."

Definition at line 48 of file microdesc_parse.c.

Referenced by microdescs_parse_from_string().

◆ microdesc_extract_body()

static int microdesc_extract_body ( microdesc_t md,
const char *  start,
const char *  s,
const char *  start_of_next_microdesc,
saved_location_t  where 
)
static

Given a microdescriptor stored in where which starts at s, which ends at start_of_next_microdescriptor, and which is located within a larger document beginning at start: Fill in the body, bodylen, bodylen, saved_location, off, and digest fields of md as appropriate.

The body field will be an alias within s if saved_location is SAVED_IN_CACHE, and will be copied into body and nul-terminated otherwise.

Definition at line 140 of file microdesc_parse.c.

◆ microdesc_parse_fields()

static int microdesc_parse_fields ( microdesc_t md,
memarea_t area,
const char *  s,
const char *  start_of_next_microdesc,
int  allow_annotations,
saved_location_t  where 
)
static

Parse a microdescriptor which begins at s and ends at start_of_next_microdesc. Store its fields into md. Use where for generating log information. If allow_annotations is true, then one or more annotations may precede the microdescriptor body proper. Use area for memory management, clearing it when done.

On success, return 0; otherwise return -1.

Definition at line 177 of file microdesc_parse.c.

◆ microdescs_parse_from_string()

smartlist_t* microdescs_parse_from_string ( const char *  s,
const char *  eos,
int  allow_annotations,
saved_location_t  where,
smartlist_t invalid_digests_out 
)

Parse as many microdescriptors as are found from the string starting at s and ending at eos. If allow_annotations is set, read any annotations we recognize and ignore ones we don't.

If saved_location isn't SAVED_IN_CACHE, make a local copy of each descriptor in the body field of each microdesc_t.

Return all newly parsed microdescriptors in a newly allocated smartlist_t. If invalid_disgests_out is provided, add a SHA256 microdesc digest to it for every microdesc that we found to be badly formed. (This may cause duplicates)

Definition at line 293 of file microdesc_parse.c.

Referenced by microdescs_add_to_cache().

◆ saved_location_to_string()

static const char* saved_location_to_string ( saved_location_t  where)
static

Return a human-readable description of a given saved_location_t. Never returns NULL.

Definition at line 108 of file microdesc_parse.c.

Variable Documentation

◆ microdesc_token_table

token_rule_t microdesc_token_table[]
static
Initial value:
= {
T1_START("onion-key", K_ONION_KEY, NO_ARGS, NEED_KEY_1024),
T1("ntor-onion-key", K_ONION_KEY_NTOR, GE(1), NO_OBJ ),
T0N("id", K_ID, GE(2), NO_OBJ ),
T0N("a", K_A, GE(1), NO_OBJ ),
T01("family", K_FAMILY, CONCAT_ARGS, NO_OBJ ),
T01("p", K_P, CONCAT_ARGS, NO_OBJ ),
T01("p6", K_P6, CONCAT_ARGS, NO_OBJ ),
A01("@last-listed", A_LAST_LISTED, CONCAT_ARGS, NO_OBJ ),
}
#define T0N(s, t, a, o)
Definition: parsecommon.h:247
#define T01(s, t, a, o)
Definition: parsecommon.h:257
#define NO_ARGS
Definition: parsecommon.h:264
#define A01(s, t, a, o)
Definition: parsecommon.h:259
@ NO_OBJ
Definition: parsecommon.h:219
@ NEED_KEY_1024
Definition: parsecommon.h:221
#define T1_START(s, t, a, o)
Definition: parsecommon.h:251
#define GE(n)
Definition: parsecommon.h:268
#define CONCAT_ARGS
Definition: parsecommon.h:266
#define T1(s, t, a, o)
Definition: parsecommon.h:249
#define END_OF_TABLE
Definition: parsecommon.h:243

List of tokens recognized in microdescriptors

Definition at line 32 of file microdesc_parse.c.