mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
clean up some file-scope-global directory variables
svn:r925
This commit is contained in:
parent
1096eae543
commit
50e17d633b
@ -13,10 +13,6 @@ extern or_options_t options; /* command-line and config-file options */
|
||||
|
||||
static char fetchstring[] = "GET / HTTP/1.0\r\n\r\n";
|
||||
static char answerstring[] = "HTTP/1.0 200 OK\r\n\r\n";
|
||||
/* XXX the_directory is the same name as a different variable in·
|
||||
* dirserv.c, are you crazy?? */
|
||||
static char the_directory[MAX_DIR_SIZE+1];
|
||||
static int directorylen=0;
|
||||
|
||||
/********* END VARIABLES ************/
|
||||
|
||||
@ -98,15 +94,17 @@ static int directory_send_command(connection_t *conn, int command) {
|
||||
}
|
||||
|
||||
int connection_dir_process_inbuf(connection_t *conn) {
|
||||
char directory[MAX_DIR_SIZE+1];
|
||||
int directorylen=0;
|
||||
|
||||
assert(conn && conn->type == CONN_TYPE_DIR);
|
||||
|
||||
if(conn->inbuf_reached_eof) {
|
||||
switch(conn->state) {
|
||||
case DIR_CONN_STATE_CLIENT_READING_FETCH:
|
||||
/* kill it, but first process the_directory and learn about new routers. */
|
||||
/* kill it, but first fetch/process the directory to learn about new routers. */
|
||||
switch(fetch_from_buf_http(conn->inbuf,
|
||||
NULL, 0, the_directory, MAX_DIR_SIZE)) {
|
||||
NULL, 0, directory, MAX_DIR_SIZE)) {
|
||||
case -1: /* overflow */
|
||||
log_fn(LOG_WARN,"'fetch' response too large. Failing.");
|
||||
return -1;
|
||||
@ -116,13 +114,13 @@ int connection_dir_process_inbuf(connection_t *conn) {
|
||||
/* case 1, fall through */
|
||||
}
|
||||
/* XXX check headers, at least make sure returned 2xx */
|
||||
directorylen = strlen(the_directory);
|
||||
log_fn(LOG_INFO,"Received directory (size %d):\n%s", directorylen, the_directory);
|
||||
directorylen = strlen(directory);
|
||||
log_fn(LOG_INFO,"Received directory (size %d):\n%s", directorylen, directory);
|
||||
if(directorylen == 0) {
|
||||
log_fn(LOG_INFO,"Empty directory. Ignoring.");
|
||||
return -1;
|
||||
}
|
||||
if(router_set_routerlist_from_directory(the_directory, conn->identity_pkey) < 0){
|
||||
if(router_set_routerlist_from_directory(directory, conn->identity_pkey) < 0){
|
||||
log_fn(LOG_INFO,"...but parsing failed. Ignoring.");
|
||||
} else {
|
||||
log_fn(LOG_INFO,"updated routers.");
|
||||
|
@ -10,10 +10,6 @@
|
||||
extern or_options_t options; /* command-line and config-file options */
|
||||
|
||||
static int the_directory_is_dirty = 1;
|
||||
/* XXX the_directory is the same name as a different variable in
|
||||
* directory.c, are you crazy?? */
|
||||
static char *the_directory = NULL;
|
||||
static int the_directory_len = -1;
|
||||
|
||||
static int list_running_servers(char **nicknames_out);
|
||||
|
||||
@ -108,7 +104,7 @@ dirserv_parse_fingerprint_file(const char *fname)
|
||||
free(fingerprint_list_tmp[i].fingerprint);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* return 1 if router's identity and nickname match,
|
||||
* -1 if they don't match, 0 if the nickname is not known. */
|
||||
@ -272,7 +268,7 @@ dirserv_add_descriptor(const char **desc)
|
||||
desc_ent_ptr = &descriptor_list[n_descriptors++];
|
||||
/* XXX check if n_descriptors is too big */
|
||||
}
|
||||
|
||||
|
||||
(*desc_ent_ptr) = tor_malloc(sizeof(descriptor_entry_t));
|
||||
(*desc_ent_ptr)->nickname = tor_strdup(ri->nickname);
|
||||
(*desc_ent_ptr)->published = ri->published_on;
|
||||
@ -281,8 +277,8 @@ dirserv_add_descriptor(const char **desc)
|
||||
strncpy((*desc_ent_ptr)->descriptor, start, desc_len);
|
||||
(*desc_ent_ptr)->descriptor[desc_len] = '\0';
|
||||
*desc = end;
|
||||
the_directory_is_dirty = 1;
|
||||
|
||||
directory_set_dirty();
|
||||
|
||||
routerinfo_free(ri);
|
||||
return 0;
|
||||
err:
|
||||
@ -378,7 +374,7 @@ dirserv_dump_directory_to_string(char *s, int maxlen,
|
||||
free(cp);
|
||||
i = strlen(s);
|
||||
cp = s+i;
|
||||
|
||||
|
||||
for (i = 0; i < n_descriptors; ++i) {
|
||||
strncat(cp, descriptor_list[i]->descriptor, descriptor_list[i]->desc_len);
|
||||
cp += descriptor_list[i]->desc_len;
|
||||
@ -391,7 +387,7 @@ dirserv_dump_directory_to_string(char *s, int maxlen,
|
||||
strncat(s, "directory-signature\n", maxlen-i);
|
||||
i = strlen(s);
|
||||
cp = s + i;
|
||||
|
||||
|
||||
if (router_get_dir_hash(s,digest)) {
|
||||
log_fn(LOG_WARN,"couldn't compute digest");
|
||||
return -1;
|
||||
@ -403,10 +399,10 @@ dirserv_dump_directory_to_string(char *s, int maxlen,
|
||||
log(LOG_DEBUG,"generated directory digest begins with %02x:%02x:%02x:%02x",
|
||||
((int)digest[0])&0xff,((int)digest[1])&0xff,
|
||||
((int)digest[2])&0xff,((int)digest[3])&0xff);
|
||||
|
||||
|
||||
strncpy(cp,
|
||||
"-----BEGIN SIGNATURE-----\n", maxlen-i);
|
||||
|
||||
|
||||
i = strlen(s);
|
||||
cp = s+i;
|
||||
if (base64_encode(cp, maxlen-i, signature, 128) < 0) {
|
||||
@ -426,6 +422,9 @@ dirserv_dump_directory_to_string(char *s, int maxlen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *the_directory = NULL;
|
||||
static int the_directory_len = -1;
|
||||
|
||||
size_t dirserv_get_directory(const char **directory)
|
||||
{
|
||||
char *new_directory;
|
||||
|
Loading…
Reference in New Issue
Block a user