Tor
0.4.7.0-alpha-dev
|
Common code to parse and validate various type of descriptors. More...
#include "feature/dirparse/parsecommon.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/encoding/binascii.h"
#include "lib/container/smartlist.h"
#include "lib/string/util_string.h"
#include "lib/string/printf.h"
#include "lib/memarea/memarea.h"
#include "lib/crypt_ops/crypto_rsa.h"
#include "lib/ctime/di_ops.h"
#include <string.h>
Go to the source code of this file.
Macros | |
#define | MIN_ANNOTATION A_PURPOSE |
#define | MAX_ANNOTATION A_UNKNOWN_ |
#define | ALLOC_ZERO(sz) memarea_alloc_zero(area,sz) |
#define | ALLOC(sz) memarea_alloc(area,sz) |
#define | STRDUP(str) memarea_strdup(area,str) |
#define | STRNDUP(str, n) memarea_strndup(area,(str),(n)) |
#define | RET_ERR(msg) |
#define | MAX_ARGS 512 |
#define | MAX_UNPARSED_OBJECT_SIZE (128*1024) |
#define | MAX_LINE_LENGTH (128*1024) |
Functions | |
void | token_clear (directory_token_t *tok) |
int | tokenize_string (memarea_t *area, const char *start, const char *end, smartlist_t *out, const token_rule_t *table, int flags) |
static int | get_token_arguments (memarea_t *area, directory_token_t *tok, const char *s, const char *eol) |
static directory_token_t * | token_check_object (memarea_t *area, const char *kwd, directory_token_t *tok, obj_syntax o_syn) |
static bool | mem_eq_token (const void *mem, size_t memlen, const char *token) |
directory_token_t * | get_next_token (memarea_t *area, const char **s, const char *eos, const token_rule_t *table) |
directory_token_t * | find_by_keyword_ (smartlist_t *s, directory_keyword keyword, const char *keyword_as_string) |
directory_token_t * | find_opt_by_keyword (const smartlist_t *s, directory_keyword keyword) |
smartlist_t * | find_all_by_keyword (const smartlist_t *s, directory_keyword k) |
Common code to parse and validate various type of descriptors.
Definition in file parsecommon.c.
#define RET_ERR | ( | msg | ) |
Definition at line 30 of file parsecommon.c.
smartlist_t* find_all_by_keyword | ( | const smartlist_t * | s, |
directory_keyword | k | ||
) |
If there are any directory_token_t entries in s whose keyword is k, return a newly allocated smartlist_t containing all such entries, in the same order in which they occur in s. Otherwise return NULL.
Definition at line 451 of file parsecommon.c.
Referenced by set_intro_point_onion_key().
directory_token_t* find_by_keyword_ | ( | smartlist_t * | s, |
directory_keyword | keyword, | ||
const char * | keyword_as_string | ||
) |
Find the first token in s whose keyword is keyword; fail with an assert if no such keyword is found.
Definition at line 424 of file parsecommon.c.
directory_token_t* find_opt_by_keyword | ( | const smartlist_t * | s, |
directory_keyword | keyword | ||
) |
Find the first token in s whose keyword is keyword; return NULL if no such keyword is found.
Definition at line 440 of file parsecommon.c.
Referenced by find_by_keyword_().
directory_token_t* get_next_token | ( | memarea_t * | area, |
const char ** | s, | ||
const char * | eos, | ||
const token_rule_t * | table | ||
) |
Helper function: read the next token from *s, advance *s to the end of the token, and return the parsed token. Parse *s according to the list of tokens in table.
Reject any object at least this big; it is probably an overflow, an attack, a bug, or some other nonsense.
Reject any line at least this big; it is probably an overflow, an attack, a bug, or some other nonsense.
Definition at line 261 of file parsecommon.c.
|
inlinestatic |
Helper: parse space-separated arguments from the string s ending at eol, and store them in the args field of tok. Store the number of parsed elements into the n_args field of tok. Allocate all storage in area. Return the number of arguments parsed, or return -1 if there was an insanely high number of arguments.
Largest number of arguments we'll accept to any token, ever.
Definition at line 164 of file parsecommon.c.
|
static |
Return true iff the memlen-byte chunk of memory at memlen is the same length as token, and their contents are equal.
Definition at line 250 of file parsecommon.c.
|
inlinestatic |
Helper: make sure that the token tok with keyword kwd obeys the object syntax of o_syn. Allocate all storage in area. Return tok on success, or a new ERR_ token if the token didn't conform to the syntax we wanted.
Definition at line 195 of file parsecommon.c.
void token_clear | ( | directory_token_t * | tok | ) |
Free all resources allocated for tok
Definition at line 41 of file parsecommon.c.
int tokenize_string | ( | memarea_t * | area, |
const char * | start, | ||
const char * | end, | ||
smartlist_t * | out, | ||
const token_rule_t * | table, | ||
int | flags | ||
) |
Read all tokens from a string between start and end, and add them to out. Parse according to the token rules in table. Caller must free tokens in out. If end is NULL, use the entire string.
Definition at line 53 of file parsecommon.c.
Referenced by decode_introduction_point(), and router_parse_entry_from_string().