From 7055f837abeca974d3b73ed26b6d26898daa9e89 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 28 Apr 2004 20:13:21 +0000 Subject: [PATCH] Make Tor build on win32 with VC6 without warnings. svn:r1739 --- Win32Build/or/or.dsp | 20 ++++++++++++++++++++ src/common/crypto.c | 15 ++++++++------- src/common/log.c | 1 + src/common/util.c | 37 ++++++++++++++++++++++++------------- src/common/util.h | 10 ++++++++-- src/or/buffers.c | 16 ++++++++-------- src/or/circuit.c | 2 +- src/or/dirserv.c | 2 +- src/or/or.h | 8 ++++---- src/or/rendservice.c | 4 ++-- src/win32/orconfig.h | 2 ++ 11 files changed, 79 insertions(+), 38 deletions(-) diff --git a/Win32Build/or/or.dsp b/Win32Build/or/or.dsp index 7378ac7d8a..b88f88fa5d 100644 --- a/Win32Build/or/or.dsp +++ b/Win32Build/or/or.dsp @@ -155,6 +155,26 @@ SOURCE=..\..\src\or\onion.c # End Source File # Begin Source File +SOURCE=..\..\src\or\rendclient.c +# End Source File +# Begin Source File + +SOURCE=..\..\src\or\rendcommon.c +# End Source File +# Begin Source File + +SOURCE=..\..\src\or\rendmid.c +# End Source File +# Begin Source File + +SOURCE=..\..\src\or\rendservice.c +# End Source File +# Begin Source File + +SOURCE=..\..\src\or\rephist.c +# End Source File +# Begin Source File + SOURCE=..\..\src\or\router.c # End Source File # Begin Source File diff --git a/src/common/crypto.c b/src/common/crypto.c index 8d8c78a1e3..4599e0cbb6 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -4,6 +4,14 @@ #include "orconfig.h" +#ifdef MS_WINDOWS +#define WIN32_WINNT 0x400 +#define _WIN32_WINNT 0x400 +#define WIN32_LEAN_AND_MEAN +#include +#include +#endif + #include #include @@ -40,13 +48,6 @@ #include "aes.h" #include "util.h" -#ifdef MS_WINDOWS -#define WIN32_WINNT 0x400 -#define _WIN32_WINNT 0x400 -#define WIN32_LEAN_AND_MEAN -#include -#endif - #if OPENSSL_VERSION_NUMBER < 0x00905000l #error "We require openssl >= 0.9.5" #elif OPENSSL_VERSION_NUMBER < 0x00906000l diff --git a/src/common/log.c b/src/common/log.c index 73733dccf0..9014c9394b 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -12,6 +12,7 @@ #ifdef MS_WINDOWS #define vsnprintf _vsnprintf +#define snprintf _snprintf #endif struct logfile_t; diff --git a/src/common/util.c b/src/common/util.c index 64e3a9b5a4..9c834db589 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -3,6 +3,23 @@ /* $Id$ */ #include "orconfig.h" + +#ifdef MS_WINDOWS +#define WIN32_WINNT 0x400 +#define _WIN32_WINNT 0x400 +#define WIN32_LEAN_AND_MEAN +#if _MSC_VER > 1300 +#include +#include +#elif defined(_MSC_VER) +#include +#endif +#include +#include +#include +#include +#endif + #include #include #include @@ -27,6 +44,9 @@ #ifdef HAVE_ERRNO_H #include #endif +#ifdef HAVE_LIMITS_H +#include +#endif #ifdef HAVE_SYS_LIMITS_H #include #endif @@ -57,17 +77,8 @@ #ifdef HAVE_GRP_H #include #endif - -#ifdef HAVE_WINSOCK_H -#define WIN32_WINNT 0x400 -#define _WIN32_WINNT 0x400 -#define WIN32_LEAN_AND_MEAN -#endif -#if _MSC_VER > 1300 -#include -#include -#elif defined(_MSC_VER) -#include +#ifdef HAVE_FCNTL_H +#include #endif /* used by inet_addr, not defined on solaris anywhere!? */ @@ -152,13 +163,13 @@ void tor_strlower(char *s) } #ifndef UNALIGNED_INT_ACCESS_OK -uint16_t get_uint16(char *cp) +uint16_t get_uint16(const char *cp) { uint16_t v; memcpy(&v,cp,2); return v; } -uint32_t get_uint32(char *cp) +uint32_t get_uint32(const char *cp) { uint32_t v; memcpy(&v,cp,4); diff --git a/src/common/util.h b/src/common/util.h index bd65a0153b..dcfe7a94dc 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -36,8 +36,14 @@ #define strncasecmp strnicmp #define strcasecmp stricmp #define INLINE __inline +#define _ARRAYSIZE(x) (((x)==0)?1:0) +/* Windows compilers before VC7 don't have __FUNCTION__. */ +#if _MSC_VER < 1300 +#define __FUNCTION__ "???" +#endif #else #define INLINE inline +#define _ARRAYSIZE(x) (x) #endif #ifdef NDEBUG @@ -76,8 +82,8 @@ void tor_strlower(char *s); #define set_uint32(cp,v) do { *(uint32_t*)(cp) = (v); } while (0) #else #if 1 -uint16_t get_uint16(char *cp); -uint32_t get_uint32(char *cp); +uint16_t get_uint16(const char *cp); +uint32_t get_uint32(const char *cp); void set_uint16(char *cp, uint16_t v); void set_uint32(char *cp, uint32_t v); #else diff --git a/src/or/buffers.c b/src/or/buffers.c index 47b5b4e6ac..6598c2654c 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -168,7 +168,7 @@ void buf_free(buf_t *buf) { * to tear down the connection return -1, else return the number of * bytes read. */ -int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) { +int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof) { int read_result; #ifdef MS_WINDOWS @@ -181,7 +181,7 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) { if (buf_ensure_capacity(buf,buf->datalen+at_most)) return -1; - if(at_most > buf->len - buf->datalen) + if(at_most + buf->datalen > buf->len) at_most = buf->len - buf->datalen; /* take the min of the two */ if(at_most == 0) @@ -212,7 +212,7 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) { } } -int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) { +int read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf) { int r; tor_assert(tls); assert_buf_ok(buf); @@ -223,7 +223,7 @@ int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) { if (buf_ensure_capacity(buf, at_most+buf->datalen)) return TOR_TLS_ERROR; - if (at_most > buf->len - buf->datalen) + if (at_most + buf->datalen > buf->len) at_most = buf->len - buf->datalen; if (at_most == 0) @@ -255,7 +255,7 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen) #endif assert_buf_ok(buf); - tor_assert(buf_flushlen && (s>=0) && (*buf_flushlen <= buf->datalen)); + tor_assert(buf_flushlen && (s>=0) && ((unsigned)*buf_flushlen <= buf->datalen)); if(*buf_flushlen == 0) /* nothing to flush */ return 0; @@ -323,7 +323,7 @@ int write_to_buf(const char *string, int string_len, buf_t *buf) { return buf->datalen; } -int fetch_from_buf(char *string, int string_len, buf_t *buf) { +int fetch_from_buf(char *string, size_t string_len, buf_t *buf) { /* There must be string_len bytes in buf; write them onto string, * then memmove buf back (that is, remove them from buf). @@ -447,7 +447,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { if(req->socks_version != 5) { /* we need to negotiate a method */ unsigned char nummethods = (unsigned char)*(buf->mem+1); tor_assert(!req->socks_version); - if(buf->datalen < 2+nummethods) + if(buf->datalen < 2u+nummethods) return 0; if(!nummethods || !memchr(buf->mem+2, 0, nummethods)) { log_fn(LOG_WARN,"socks5: offered methods don't include 'no auth'. Rejecting."); @@ -493,7 +493,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { case 3: /* fqdn */ log_fn(LOG_DEBUG,"socks5: fqdn address type"); len = (unsigned char)*(buf->mem+4); - if(buf->datalen < 7+len) /* addr/port there? */ + if(buf->datalen < 7u+len) /* addr/port there? */ return 0; /* not yet */ if(len+1 > MAX_SOCKS_ADDR_LEN) { log_fn(LOG_WARN,"socks5 hostname is %d bytes, which doesn't fit in %d. Rejecting.", diff --git a/src/or/circuit.c b/src/or/circuit.c index 24ab5c59fb..4298922f01 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -1627,7 +1627,7 @@ int circuit_extend(cell_t *cell, circuit_t *circ) { */ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse) { - unsigned char iv[CIPHER_IV_LEN]; + unsigned char iv[_ARRAYSIZE(CIPHER_IV_LEN)]; crypto_digest_env_t *tmp_digest; crypto_cipher_env_t *tmp_crypto; diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 0888039d62..631f3d244b 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -407,7 +407,7 @@ dirserv_remove_old_servers(void) * Return 0 on success, -1 on failure. */ int -dirserv_dump_directory_to_string(char *s, int maxlen, +dirserv_dump_directory_to_string(char *s, unsigned int maxlen, crypto_pk_env_t *private_key) { char *cp, *eos; diff --git a/src/or/or.h b/src/or/or.h index 10b8b63437..83d1bb7267 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -657,14 +657,14 @@ size_t buf_datalen(const buf_t *buf); size_t buf_capacity(const buf_t *buf); const char *_buf_peek_raw_buffer(const buf_t *buf); -int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof); -int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf); +int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof); +int read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf); int flush_buf(int s, buf_t *buf, int *buf_flushlen); int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen); int write_to_buf(const char *string, int string_len, buf_t *buf); -int fetch_from_buf(char *string, int string_len, buf_t *buf); +int fetch_from_buf(char *string, size_t string_len, buf_t *buf); int fetch_from_buf_http(buf_t *buf, char **headers_out, int max_headerlen, char **body_out, int *body_used, int max_bodylen); @@ -1026,7 +1026,7 @@ void dirserv_free_fingerprint_list(); int dirserv_add_descriptor(const char **desc); int dirserv_init_from_directory_string(const char *dir); void dirserv_free_descriptors(); -int dirserv_dump_directory_to_string(char *s, int maxlen, +int dirserv_dump_directory_to_string(char *s, unsigned int maxlen, crypto_pk_env_t *private_key); void directory_set_dirty(void); size_t dirserv_get_directory(const char **cp); diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 8b354b658e..503cd0593a 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -396,7 +396,7 @@ rend_service_introduce(circuit_t *circuit, const char *request, int request_len) log_fn(LOG_WARN, "Couldn't find a null-padded nickname in INTRODUCE2 cell"); return -1; } - if (strspn(buf,LEGAL_NICKNAME_CHARACTERS) != ptr-buf) { + if ((int)strspn(buf,LEGAL_NICKNAME_CHARACTERS) != ptr-buf) { log_fn(LOG_WARN, "Nickname in INTRODUCE2 cell contains illegal character."); return -1; } @@ -551,7 +551,7 @@ rend_service_intro_is_ready(circuit_t *circuit) /* Build the payload for a RELAY_ESTABLISH_INTRO cell. */ len = crypto_pk_asn1_encode(service->private_key, buf+2, RELAY_PAYLOAD_SIZE-2); - set_uint16(buf, htons(len)); + set_uint16(buf, htons((uint16_t)len)); len += 2; memcpy(auth, circuit->cpath->prev->handshake_digest, DIGEST_LEN); memcpy(auth+DIGEST_LEN, "INTRODUCE", 9); diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h index 3d3d2cf877..c51f427b4d 100644 --- a/src/win32/orconfig.h +++ b/src/win32/orconfig.h @@ -141,6 +141,8 @@ /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS +#define HAVE_LIMITS_H + /* Version number of package */ #define VERSION "0.0.2pre26" -- 2.11.4.GIT