mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
r19061@catbus: nickm | 2008-03-26 12:53:18 -0400
Now that every thing in routerparse.c is switched over to use memareas, there is no need to keep the heap-allocated token code. svn:r14196
This commit is contained in:
parent
6edab8569a
commit
3af9e099f7
@ -113,16 +113,21 @@ typedef enum {
|
|||||||
* of a keyword, a line full of arguments, and a binary object. The
|
* of a keyword, a line full of arguments, and a binary object. The
|
||||||
* arguments and object are both optional, depending on the keyword
|
* arguments and object are both optional, depending on the keyword
|
||||||
* type.
|
* type.
|
||||||
|
*
|
||||||
|
* This structure is only allocated in memareas; do not allocate it on
|
||||||
|
* the heap, or token_free() won't work.
|
||||||
*/
|
*/
|
||||||
typedef struct directory_token_t {
|
typedef struct directory_token_t {
|
||||||
directory_keyword tp; /**< Type of the token. */
|
directory_keyword tp; /**< Type of the token. */
|
||||||
unsigned int in_area:1;/**<XXXX021 remove need for this. */
|
int n_args:30; /**< Number of elements in args */
|
||||||
int n_args : 31; /**< Number of elements in args */
|
|
||||||
char **args; /**< Array of arguments from keyword line. */
|
char **args; /**< Array of arguments from keyword line. */
|
||||||
|
|
||||||
char *object_type; /**< -----BEGIN [object_type]-----*/
|
char *object_type; /**< -----BEGIN [object_type]-----*/
|
||||||
size_t object_size; /**< Bytes in object_body */
|
size_t object_size; /**< Bytes in object_body */
|
||||||
char *object_body; /**< Contents of object, base64-decoded. */
|
char *object_body; /**< Contents of object, base64-decoded. */
|
||||||
crypto_pk_env_t *key; /**< For public keys only. */
|
|
||||||
|
crypto_pk_env_t *key; /**< For public keys only. Heap-allocated. */
|
||||||
|
|
||||||
char *error; /**< For _ERR tokens only. */
|
char *error; /**< For _ERR tokens only. */
|
||||||
} directory_token_t;
|
} directory_token_t;
|
||||||
|
|
||||||
@ -1974,7 +1979,7 @@ networkstatus_v2_parse_from_string(const char *s)
|
|||||||
memarea_clear(area);
|
memarea_clear(area);
|
||||||
while (!strcmpstart(s, "r ")) {
|
while (!strcmpstart(s, "r ")) {
|
||||||
routerstatus_t *rs;
|
routerstatus_t *rs;
|
||||||
if ((rs = routerstatus_parse_entry_from_string(NULL, &s, tokens, NULL, NULL, 0)))
|
if ((rs = routerstatus_parse_entry_from_string(area, &s, tokens, NULL, NULL, 0)))
|
||||||
smartlist_add(ns->entries, rs);
|
smartlist_add(ns->entries, rs);
|
||||||
}
|
}
|
||||||
smartlist_sort(ns->entries, _compare_routerstatus_entries);
|
smartlist_sort(ns->entries, _compare_routerstatus_entries);
|
||||||
@ -2661,35 +2666,20 @@ assert_addr_policy_ok(smartlist_t *lst)
|
|||||||
static void
|
static void
|
||||||
token_free(directory_token_t *tok)
|
token_free(directory_token_t *tok)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
tor_assert(tok);
|
tor_assert(tok);
|
||||||
if (tok->key)
|
if (tok->key)
|
||||||
crypto_free_pk_env(tok->key);
|
crypto_free_pk_env(tok->key);
|
||||||
|
|
||||||
if (! tok->in_area) {
|
|
||||||
if (tok->args) {
|
|
||||||
for (i = 0; i < tok->n_args; ++i) {
|
|
||||||
tor_free(tok->args[i]);
|
|
||||||
}
|
|
||||||
tor_free(tok->args);
|
|
||||||
}
|
|
||||||
tor_free(tok->object_type);
|
|
||||||
tor_free(tok->object_body);
|
|
||||||
tor_free(tok->error);
|
|
||||||
tor_free(tok);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ALLOC_ZERO(sz) (area?memarea_alloc_zero(area,sz):tor_malloc_zero(sz))
|
#define ALLOC_ZERO(sz) memarea_alloc_zero(area,sz)
|
||||||
#define ALLOC(sz) (area?memarea_alloc(area,sz):tor_malloc(sz))
|
#define ALLOC(sz) memarea_alloc(area,sz)
|
||||||
#define STRDUP(str) (area?memarea_strdup(area,str):tor_strdup(str))
|
#define STRDUP(str) memarea_strdup(area,str)
|
||||||
#define STRNDUP(str,n) (area?memarea_strndup(area,(str),(n)):tor_strndup((str),(n)))
|
#define STRNDUP(str,n) memarea_strndup(area,(str),(n))
|
||||||
|
|
||||||
#define RET_ERR(msg) \
|
#define RET_ERR(msg) \
|
||||||
STMT_BEGIN \
|
STMT_BEGIN \
|
||||||
if (tok) token_free(tok); \
|
if (tok) token_free(tok); \
|
||||||
tok = ALLOC_ZERO(sizeof(directory_token_t)); \
|
tok = ALLOC_ZERO(sizeof(directory_token_t)); \
|
||||||
tok->in_area = area?1:0; \
|
|
||||||
tok->tp = _ERR; \
|
tok->tp = _ERR; \
|
||||||
tok->error = STRDUP(msg); \
|
tok->error = STRDUP(msg); \
|
||||||
goto done_tokenizing; \
|
goto done_tokenizing; \
|
||||||
@ -2746,15 +2736,15 @@ get_next_token(memarea_t *area,
|
|||||||
const char **s, const char *eos, token_rule_t *table)
|
const char **s, const char *eos, token_rule_t *table)
|
||||||
{
|
{
|
||||||
const char *next, *eol, *obstart;
|
const char *next, *eol, *obstart;
|
||||||
int i, j, allocated;
|
|
||||||
size_t obname_len;
|
size_t obname_len;
|
||||||
|
int i;
|
||||||
directory_token_t *tok;
|
directory_token_t *tok;
|
||||||
obj_syntax o_syn = NO_OBJ;
|
obj_syntax o_syn = NO_OBJ;
|
||||||
char ebuf[128];
|
char ebuf[128];
|
||||||
const char *kwd = "";
|
const char *kwd = "";
|
||||||
|
|
||||||
|
tor_assert(area);
|
||||||
tok = ALLOC_ZERO(sizeof(directory_token_t));
|
tok = ALLOC_ZERO(sizeof(directory_token_t));
|
||||||
tok->in_area = area?1:0;
|
|
||||||
tok->tp = _ERR;
|
tok->tp = _ERR;
|
||||||
|
|
||||||
/* Set *s to first token, eol to end-of-line, next to after first token */
|
/* Set *s to first token, eol to end-of-line, next to after first token */
|
||||||
@ -2792,10 +2782,10 @@ get_next_token(memarea_t *area,
|
|||||||
tok->n_args = 1;
|
tok->n_args = 1;
|
||||||
} else {
|
} else {
|
||||||
/* This keyword takes multiple arguments. */
|
/* This keyword takes multiple arguments. */
|
||||||
if (area) {
|
/* XXXX021 this code is still too complicated. */
|
||||||
char *mem = memarea_strndup(area, *s, eol-*s);
|
char *mem = memarea_strndup(area, *s, eol-*s);
|
||||||
char *cp = mem;
|
char *cp = mem;
|
||||||
j = 0;
|
int j = 0;
|
||||||
while (*cp) {
|
while (*cp) {
|
||||||
j++;
|
j++;
|
||||||
cp = (char*)find_whitespace(cp);
|
cp = (char*)find_whitespace(cp);
|
||||||
@ -2818,22 +2808,6 @@ get_next_token(memarea_t *area,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*s = eol;
|
*s = eol;
|
||||||
} else {
|
|
||||||
/*XXXX021 make this needless. */
|
|
||||||
j = 0;
|
|
||||||
allocated = 16;
|
|
||||||
tok->args = tor_malloc(sizeof(char*)*allocated);
|
|
||||||
while (*s < eol) { /* While not at eol, store the next token */
|
|
||||||
if (j == allocated) {
|
|
||||||
allocated *= 2;
|
|
||||||
tok->args = tor_realloc(tok->args,sizeof(char*)*allocated);
|
|
||||||
}
|
|
||||||
tok->args[j++] = tor_strndup(*s, next-*s);
|
|
||||||
*s = eat_whitespace_eos_no_nl(next, eol); /* eat intra-line ws */
|
|
||||||
next = find_whitespace_eos(*s, eol); /* find end of token at *s */
|
|
||||||
}
|
|
||||||
tok->n_args = j;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (tok->n_args < table[i].min_args) {
|
if (tok->n_args < table[i].min_args) {
|
||||||
tor_snprintf(ebuf, sizeof(ebuf), "Too few arguments to %s", kwd);
|
tor_snprintf(ebuf, sizeof(ebuf), "Too few arguments to %s", kwd);
|
||||||
@ -2936,6 +2910,7 @@ tokenize_string(memarea_t *area,
|
|||||||
int i;
|
int i;
|
||||||
int first_nonannotation;
|
int first_nonannotation;
|
||||||
int prev_len = smartlist_len(out);
|
int prev_len = smartlist_len(out);
|
||||||
|
tor_assert(area);
|
||||||
|
|
||||||
s = &start;
|
s = &start;
|
||||||
if (!end)
|
if (!end)
|
||||||
|
Loading…
Reference in New Issue
Block a user