From de508c5f50af855742b59579afd6c9c328eb7cd6 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 21 Jun 2018 17:00:48 -0400 Subject: [PATCH] Extract smartlist.h from container.h --- src/common/address.c | 2 +- src/common/address.h | 23 ++++++++++++----------- src/common/compat.c | 3 +-- src/common/confline.c | 3 +-- src/common/confline.h | 5 ++--- src/common/log.c | 2 +- src/common/storagedir.c | 3 +-- src/common/util.c | 2 +- src/common/util_bug.c | 4 +++- src/lib/container/container.h | 2 -- src/lib/crypt_ops/crypto_digest.c | 2 +- src/lib/crypt_ops/crypto_digest.h | 3 ++- src/lib/crypt_ops/crypto_format.c | 3 +-- src/lib/crypt_ops/crypto_rand.c | 3 +-- src/lib/tls/tortls.c | 2 +- src/or/parsecommon.c | 2 +- src/or/parsecommon.h | 13 +++++++------ src/or/protover.h | 11 +++++------ 18 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/common/address.c b/src/common/address.c index f9e5cc5c74..f2cddd394a 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -40,7 +40,7 @@ #include "common/util_format.h" #include "common/address.h" #include "common/torlog.h" -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include "common/sandbox.h" #include "siphash.h" diff --git a/src/common/address.h b/src/common/address.h index b8fccd81ec..87f29fc281 100644 --- a/src/common/address.h +++ b/src/common/address.h @@ -207,10 +207,11 @@ const char * fmt_addr32(uint32_t addr); MOCK_DECL(int,get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr)); -void interface_address6_list_free_(smartlist_t * addrs);// XXXX +struct smartlist_t; +void interface_address6_list_free_(struct smartlist_t * addrs);// XXXX #define interface_address6_list_free(addrs) \ - FREE_AND_NULL(smartlist_t, interface_address6_list_free_, (addrs)) -MOCK_DECL(smartlist_t *,get_interface_address6_list,(int severity, + FREE_AND_NULL(struct smartlist_t, interface_address6_list_free_, (addrs)) +MOCK_DECL(struct smartlist_t *,get_interface_address6_list,(int severity, sa_family_t family, int include_internal)); @@ -336,7 +337,7 @@ MOCK_DECL(int,get_interface_address,(int severity, uint32_t *addr)); * Returns NULL on failure. * Use free_interface_address_list to free the returned list. */ -static inline smartlist_t * +static inline struct smartlist_t * get_interface_address_list(int severity, int include_internal) { return get_interface_address6_list(severity, AF_INET, include_internal); @@ -347,30 +348,30 @@ int tor_addr_port_eq(const tor_addr_port_t *a, const tor_addr_port_t *b); #ifdef ADDRESS_PRIVATE -MOCK_DECL(smartlist_t *,get_interface_addresses_raw,(int severity, +MOCK_DECL(struct smartlist_t *,get_interface_addresses_raw,(int severity, sa_family_t family)); MOCK_DECL(int,get_interface_address6_via_udp_socket_hack,(int severity, sa_family_t family, tor_addr_t *addr)); #ifdef HAVE_IFADDRS_TO_SMARTLIST -STATIC smartlist_t *ifaddrs_to_smartlist(const struct ifaddrs *ifa, +STATIC struct smartlist_t *ifaddrs_to_smartlist(const struct ifaddrs *ifa, sa_family_t family); -STATIC smartlist_t *get_interface_addresses_ifaddrs(int severity, +STATIC struct smartlist_t *get_interface_addresses_ifaddrs(int severity, sa_family_t family); #endif /* defined(HAVE_IFADDRS_TO_SMARTLIST) */ #ifdef HAVE_IP_ADAPTER_TO_SMARTLIST -STATIC smartlist_t *ip_adapter_addresses_to_smartlist( +STATIC struct smartlist_t *ip_adapter_addresses_to_smartlist( const IP_ADAPTER_ADDRESSES *addresses); -STATIC smartlist_t *get_interface_addresses_win32(int severity, +STATIC struct smartlist_t *get_interface_addresses_win32(int severity, sa_family_t family); #endif /* defined(HAVE_IP_ADAPTER_TO_SMARTLIST) */ #ifdef HAVE_IFCONF_TO_SMARTLIST -STATIC smartlist_t *ifreq_to_smartlist(char *ifr, +STATIC struct smartlist_t *ifreq_to_smartlist(char *ifr, size_t buflen); -STATIC smartlist_t *get_interface_addresses_ioctl(int severity, +STATIC struct smartlist_t *get_interface_addresses_ioctl(int severity, sa_family_t family); #endif /* defined(HAVE_IFCONF_TO_SMARTLIST) */ diff --git a/src/common/compat.c b/src/common/compat.c index 577ebe7574..9462195ba2 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -126,7 +126,7 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt) #include "common/torlog.h" #include "common/util.h" -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include "common/address.h" #include "common/sandbox.h" @@ -3527,4 +3527,3 @@ tor_get_avail_disk_space(const char *path) return -1; #endif /* defined(HAVE_STATVFS) || ... */ } - diff --git a/src/common/confline.c b/src/common/confline.c index 7343c5f528..76f5ac04e5 100644 --- a/src/common/confline.c +++ b/src/common/confline.c @@ -8,7 +8,7 @@ #include "common/confline.h" #include "common/torlog.h" #include "common/util.h" -#include "lib/container/container.h" +#include "lib/container/smartlist.h" static int config_get_lines_aux(const char *string, config_line_t **result, int extended, int allow_include, @@ -535,4 +535,3 @@ parse_config_line_from_str_verbose(const char *line, char **key_out, return line; } - diff --git a/src/common/confline.h b/src/common/confline.h index 10af34a0a6..d1f6fdb7e5 100644 --- a/src/common/confline.h +++ b/src/common/confline.h @@ -7,7 +7,7 @@ #ifndef TOR_CONFLINE_H #define TOR_CONFLINE_H -#include "lib/container/container.h" +struct smartlist_t; /** Ordinary configuration line. */ #define CONFIG_LINE_NORMAL 0 @@ -47,7 +47,7 @@ int config_count_key(const config_line_t *a, const char *key); int config_get_lines(const char *string, config_line_t **result, int extended); int config_get_lines_include(const char *string, config_line_t **result, int extended, int *has_include, - smartlist_t *opened_lst); + struct smartlist_t *opened_lst); void config_free_lines_(config_line_t *front); #define config_free_lines(front) \ do { \ @@ -58,4 +58,3 @@ const char *parse_config_line_from_str_verbose(const char *line, char **key_out, char **value_out, const char **err_out); #endif /* !defined(TOR_CONFLINE_H) */ - diff --git a/src/common/log.c b/src/common/log.c index 8ea686a12e..5224a21970 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -33,7 +33,7 @@ #include "common/util.h" #define LOG_PRIVATE #include "common/torlog.h" -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include "lib/err/torerr.h" #ifdef HAVE_ANDROID_LOG_H diff --git a/src/common/storagedir.c b/src/common/storagedir.c index f3270ce7b8..82a5e1b21d 100644 --- a/src/common/storagedir.c +++ b/src/common/storagedir.c @@ -1,7 +1,7 @@ /* Copyright (c) 2017-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include "common/compat.h" #include "common/confline.h" #include "common/memarea.h" @@ -583,4 +583,3 @@ storage_dir_get_max_files(storage_dir_t *d) { return d->max_files; } - diff --git a/src/common/util.c b/src/common/util.c index cd8ff93a3d..877368af59 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -18,7 +18,7 @@ #include "common/torlog.h" #include "lib/crypt_ops/crypto_digest.h" #include "lib/cc/torint.h" -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include "common/address.h" #include "common/sandbox.h" #include "lib/err/backtrace.h" diff --git a/src/common/util_bug.c b/src/common/util_bug.c index 3d86131e7c..7d6dc0750f 100644 --- a/src/common/util_bug.c +++ b/src/common/util_bug.c @@ -11,7 +11,9 @@ #include "common/util_bug.h" #include "common/torlog.h" #include "lib/err/backtrace.h" -#include "lib/container/container.h" +#ifdef TOR_UNIT_TESTS +#include "lib/container/smartlist.h" +#endif #include "lib/malloc/util_malloc.h" #ifdef __COVERITY__ diff --git a/src/lib/container/container.h b/src/lib/container/container.h index 6912ae31ea..3dc70e6353 100644 --- a/src/lib/container/container.h +++ b/src/lib/container/container.h @@ -6,6 +6,4 @@ #ifndef TOR_CONTAINER_H #define TOR_CONTAINER_H -#include "lib/container/smartlist.h" - #endif /* !defined(TOR_CONTAINER_H) */ diff --git a/src/lib/crypt_ops/crypto_digest.c b/src/lib/crypt_ops/crypto_digest.c index b6ec2b2841..b1aede3a83 100644 --- a/src/lib/crypt_ops/crypto_digest.c +++ b/src/lib/crypt_ops/crypto_digest.c @@ -10,7 +10,7 @@ * operations. **/ -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include "lib/crypt_ops/crypto_digest.h" #include "lib/crypt_ops/crypto_openssl_mgt.h" #include "lib/crypt_ops/crypto_util.h" diff --git a/src/lib/crypt_ops/crypto_digest.h b/src/lib/crypt_ops/crypto_digest.h index 628224a03f..15bc5ad5b9 100644 --- a/src/lib/crypt_ops/crypto_digest.h +++ b/src/lib/crypt_ops/crypto_digest.h @@ -13,7 +13,6 @@ #ifndef TOR_CRYPTO_DIGEST_H #define TOR_CRYPTO_DIGEST_H -#include "lib/container/container.h" #include "lib/cc/torint.h" #include "lib/defs/digest_sizes.h" #include "lib/malloc/util_malloc.h" @@ -70,6 +69,8 @@ typedef struct { typedef struct crypto_digest_t crypto_digest_t; typedef struct crypto_xof_t crypto_xof_t; +struct smartlist_t; + /* SHA-1 and other digests */ int crypto_digest(char *digest, const char *m, size_t len); int crypto_digest256(char *digest, const char *m, size_t len, diff --git a/src/lib/crypt_ops/crypto_format.c b/src/lib/crypt_ops/crypto_format.c index 246f28716a..2d28090aaa 100644 --- a/src/lib/crypt_ops/crypto_format.c +++ b/src/lib/crypt_ops/crypto_format.c @@ -14,7 +14,7 @@ #ifdef HAVE_SYS_STAT_H #include #endif -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include "lib/crypt_ops/crypto_curve25519.h" #include "lib/crypt_ops/crypto_digest.h" #include "lib/crypt_ops/crypto_ed25519.h" @@ -296,4 +296,3 @@ digest256_from_base64(char *digest, const char *d64) else return -1; } - diff --git a/src/lib/crypt_ops/crypto_rand.c b/src/lib/crypt_ops/crypto_rand.c index af258abea4..0d41a207e8 100644 --- a/src/lib/crypt_ops/crypto_rand.c +++ b/src/lib/crypt_ops/crypto_rand.c @@ -21,7 +21,7 @@ #include #endif /* defined(_WIN32) */ -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include "common/compat.h" #include "lib/crypt_ops/compat_openssl.h" #include "lib/crypt_ops/crypto_util.h" @@ -612,4 +612,3 @@ crypto_force_rand_ssleay(void) } #endif /* !defined(CRYPTO_RAND_PRIVATE) */ - diff --git a/src/lib/tls/tortls.c b/src/lib/tls/tortls.c index ea3a420541..eb8a91b420 100644 --- a/src/lib/tls/tortls.c +++ b/src/lib/tls/tortls.c @@ -55,7 +55,7 @@ ENABLE_GCC_WARNING(redundant-decls) #include "lib/tls/tortls.h" #include "common/util.h" #include "common/torlog.h" -#include "lib/container/container.h" +#include "lib/container/smartlist.h" #include #ifdef OPENSSL_1_1_API diff --git a/src/or/parsecommon.c b/src/or/parsecommon.c index 09c7d665fe..298d3658ba 100644 --- a/src/or/parsecommon.c +++ b/src/or/parsecommon.c @@ -9,6 +9,7 @@ #include "or/parsecommon.h" #include "common/torlog.h" #include "common/util_format.h" +#include "lib/container/smartlist.h" #define MIN_ANNOTATION A_PURPOSE #define MAX_ANNOTATION A_UNKNOWN_ @@ -448,4 +449,3 @@ find_all_by_keyword(const smartlist_t *s, directory_keyword k) }); return out; } - diff --git a/src/or/parsecommon.h b/src/or/parsecommon.h index c786bcc548..fc61c514a1 100644 --- a/src/or/parsecommon.h +++ b/src/or/parsecommon.h @@ -9,10 +9,11 @@ #ifndef TOR_PARSECOMMON_H #define TOR_PARSECOMMON_H -#include "lib/container/container.h" #include "lib/crypt_ops/crypto.h" #include "common/memarea.h" +struct smartlist_t; + /** Enumeration of possible token types. The ones starting with K_ correspond * to directory 'keywords'. A_ is for an annotation, R or C is related to * hidden services, ERR_ is an error in the tokenizing process, EOF_ is an @@ -299,7 +300,7 @@ void token_clear(directory_token_t *tok); int tokenize_string(memarea_t *area, const char *start, const char *end, - smartlist_t *out, + struct smartlist_t *out, token_rule_t *table, int flags); directory_token_t *get_next_token(memarea_t *area, @@ -307,16 +308,16 @@ directory_token_t *get_next_token(memarea_t *area, const char *eos, token_rule_t *table); -directory_token_t *find_by_keyword_(smartlist_t *s, +directory_token_t *find_by_keyword_(struct smartlist_t *s, directory_keyword keyword, const char *keyword_str); #define find_by_keyword(s, keyword) \ find_by_keyword_((s), (keyword), #keyword) -directory_token_t *find_opt_by_keyword(const smartlist_t *s, +directory_token_t *find_opt_by_keyword(const struct smartlist_t *s, directory_keyword keyword); -smartlist_t * find_all_by_keyword(const smartlist_t *s, directory_keyword k); +struct smartlist_t * find_all_by_keyword(const struct smartlist_t *s, + directory_keyword k); #endif /* !defined(TOR_PARSECOMMON_H) */ - diff --git a/src/or/protover.h b/src/or/protover.h index 99502645ca..aab311e96f 100644 --- a/src/or/protover.h +++ b/src/or/protover.h @@ -9,7 +9,7 @@ #ifndef TOR_PROTOVER_H #define TOR_PROTOVER_H -#include "lib/container/container.h" +struct smartlist_t; /** The first version of Tor that included "proto" entries in its * descriptors. Authorities should use this to decide whether to @@ -47,7 +47,7 @@ int protover_all_supported(const char *s, char **missing); int protover_is_supported_here(protocol_type_t pr, uint32_t ver); const char *protover_get_supported_protocols(void); -char *protover_compute_vote(const smartlist_t *list_of_proto_strings, +char *protover_compute_vote(const struct smartlist_t *list_of_proto_strings, int threshold); const char *protover_compute_for_old_tor(const char *version); int protocol_list_supports_protocol(const char *list, protocol_type_t tp, @@ -75,12 +75,12 @@ typedef struct proto_entry_t { */ char *name; /** Smartlist of proto_range_t */ - smartlist_t *ranges; + struct smartlist_t *ranges; } proto_entry_t; #if !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS) -STATIC smartlist_t *parse_protocol_list(const char *s); -STATIC char *encode_protocol_list(const smartlist_t *sl); +STATIC struct smartlist_t *parse_protocol_list(const char *s); +STATIC char *encode_protocol_list(const struct smartlist_t *sl); STATIC const char *protocol_type_to_str(protocol_type_t pr); STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out); STATIC void proto_entry_free_(proto_entry_t *entry); @@ -92,4 +92,3 @@ STATIC void proto_entry_free_(proto_entry_t *entry); #endif /* defined(PROTOVER_PRIVATE) */ #endif /* !defined(TOR_PROTOVER_H) */ -