[or-cvs] Split directory/router parsing functionality into separate ...
Nick Mathewson
nickm at seul.org
Mon May 10 17:30:53 UTC 2004
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv9310/src/or
Modified Files:
Makefile.am dirserv.c or.h router.c routerlist.c test.c
Added Files:
routerparse.c
Log Message:
Split directory/router parsing functionality into separate file from routerlist.c
--- NEW FILE: routerparse.c ---
/* Copyright 2001-2003 Roger Dingledine, Matej Pfajfar. */
/* See LICENSE for licensing information */
/* $Id: routerparse.c,v 1.1 2004/05/10 17:30:51 nickm Exp $ */
/**
* \file routerparse.c
*
* \brief Code to parse and validate router descriptors and directories.
**/
#define _GNU_SOURCE
/* XXX this is required on rh7 to make strptime not complain. how bad
* is this for portability?
*/
#include "or.h"
/****************************************************************************/
[...1013 lines suppressed...]
log_fn(LOG_WARN,"couldn't find EOL");
return -1;
}
++end;
if (crypto_digest(start, end-start, digest)) {
log_fn(LOG_WARN,"couldn't compute digest");
return -1;
}
return 0;
}
/*
Local Variables:
mode:c
indent-tabs-mode:nil
c-basic-offset:2
End:
*/
Index: Makefile.am
===================================================================
RCS file: /home/or/cvsroot/src/or/Makefile.am,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- Makefile.am 2 Apr 2004 22:23:15 -0000 1.31
+++ Makefile.am 10 May 2004 17:30:51 -0000 1.32
@@ -8,7 +8,7 @@
connection.c connection_edge.c connection_or.c \
cpuworker.c directory.c dirserv.c dns.c main.c \
onion.c rendcommon.c rendclient.c rendmid.c \
- rendservice.c rephist.c router.c routerlist.c \
+ rendservice.c rephist.c router.c routerlist.c routerparse.c \
tor_main.c
tor_LDADD = ../common/libor.a
@@ -17,7 +17,7 @@
connection.c connection_edge.c connection_or.c \
cpuworker.c directory.c dirserv.c dns.c main.c \
onion.c rendcommon.c rendclient.c rendmid.c \
- rendservice.c rephist.c router.c routerlist.c \
+ rendservice.c rephist.c router.c routerlist.c routerparse.c \
test.c
test_LDADD = ../common/libor.a
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- dirserv.c 10 May 2004 04:34:48 -0000 1.45
+++ dirserv.c 10 May 2004 17:30:51 -0000 1.46
@@ -268,7 +268,7 @@
cp = desc_tmp = tor_strndup(start, desc_len);
/* Check: is the descriptor syntactically valid? */
- ri = router_get_entry_from_string(cp, NULL);
+ ri = router_parse_entry_from_string(cp, NULL);
tor_free(desc_tmp);
if (!ri) {
log(LOG_WARN, "Couldn't parse descriptor");
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.339
retrieving revision 1.340
diff -u -d -r1.339 -r1.340
--- or.h 10 May 2004 10:31:48 -0000 1.339
+++ or.h 10 May 2004 17:30:51 -0000 1.340
@@ -1185,16 +1185,13 @@
routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
routerinfo_t *router_get_by_nickname(char *nickname);
void router_get_routerlist(routerlist_t **prouterlist);
+void routerlist_free(routerlist_t *routerlist);
void routerinfo_free(routerinfo_t *router);
routerinfo_t *routerinfo_copy(const routerinfo_t *router);
void router_mark_as_down(char *nickname);
int router_set_routerlist_from_file(char *routerfile);
int router_set_routerlist_from_string(const char *s);
-int router_get_dir_hash(const char *s, char *digest);
-int router_get_router_hash(const char *s, char *digest);
int router_set_routerlist_from_directory(const char *s, crypto_pk_env_t *pkey);
-routerinfo_t *router_get_entry_from_string(const char *s, const char *end);
-int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port,
struct exit_policy_t *policy);
#define ADDR_POLICY_ACCEPTED 0
@@ -1203,6 +1200,20 @@
int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port);
int router_exit_policy_rejects_all(routerinfo_t *router);
+/********************************* routerparse.c ************************/
+
+int router_get_router_hash(const char *s, char *digest);
+int router_get_dir_hash(const char *s, char *digest);
+int router_parse_list_from_string(const char **s,
+ routerlist_t **dest,
+ int n_good_nicknames,
+ const char **good_nickname_lst);
+int router_parse_routerlist_from_directory(const char *s,
+ routerlist_t **dest,
+ crypto_pk_env_t *pkey);
+routerinfo_t *router_parse_entry_from_string(const char *s, const char *end);
+int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
+
/********************************* dirserv.c ***************************/
int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk);
int dirserv_parse_fingerprint_file(const char *fname);
Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- router.c 10 May 2004 10:27:54 -0000 1.41
+++ router.c 10 May 2004 17:30:51 -0000 1.42
@@ -652,7 +652,7 @@
#ifdef DEBUG_ROUTER_DUMP_ROUTER_TO_STRING
cp = s_tmp = s_dup = tor_strdup(s);
- ri_tmp = router_get_entry_from_string(cp, NULL);
+ ri_tmp = router_parse_entry_from_string(cp, NULL);
if (!ri_tmp) {
log_fn(LOG_ERR, "We just generated a router descriptor we can't parse: <<%s>>",
s);
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- routerlist.c 10 May 2004 04:34:48 -0000 1.73
+++ routerlist.c 10 May 2004 17:30:51 -0000 1.74
@@ -2,17 +2,12 @@
/* See LICENSE for licensing information */
/* $Id$ */
-#define _GNU_SOURCE
-/* XXX this is required on rh7 to make strptime not complain. how bad
- * is this for portability?
- */
-
#include "or.h"
/**
[...1091 lines suppressed...]
- return -1;
- }
- end = strchr(end, '\n');
- if (!end) {
- log_fn(LOG_WARN,"couldn't find EOL");
- return -1;
- }
- ++end;
-
- if (crypto_digest(start, end-start, digest)) {
- log_fn(LOG_WARN,"couldn't compute digest");
- return -1;
- }
-
- return 0;
-}
-
/*
Local Variables:
mode:c
Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- test.c 5 May 2004 20:27:20 -0000 1.90
+++ test.c 10 May 2004 17:30:51 -0000 1.91
@@ -20,8 +20,6 @@
int have_failed = 0;
/* These functions are file-local, but are exposed so we can test. */
-int router_get_routerlist_from_directory_impl(
- const char *s, routerlist_t **dest, crypto_pk_env_t *pkey);
void add_fingerprint_to_dir(const char *nickname, const char *fp);
void get_platform_str(char *platform, int len);
@@ -727,7 +725,7 @@
test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0);
cp = buf;
- rp1 = router_get_entry_from_string((const char*)cp,NULL);
+ rp1 = router_parse_entry_from_string((const char*)cp,NULL);
test_assert(rp1);
test_streq(rp1->address, r1.address);
test_eq(rp1->or_port, r1.or_port);
@@ -750,7 +748,7 @@
test_streq(buf, buf2);
cp = buf;
- rp2 = router_get_entry_from_string(&cp);
+ rp2 = router_parse_entry_from_string(&cp);
test_assert(rp2);
test_streq(rp2->address, r2.address);
test_eq(rp2->or_port, r2.or_port);
@@ -787,7 +785,7 @@
options.Nickname = "DirServer";
test_assert(!dirserv_dump_directory_to_string(buf,8192,pk3));
cp = buf;
- test_assert(!router_get_routerlist_from_directory_impl(buf, &dir1, pk3));
+ test_assert(!router_parse_routerlist_from_directory(buf, &dir1, pk3));
test_eq(2, smartlist_len(dir1->routers));
dirserv_free_fingerprint_list();
More information about the tor-commits
mailing list