diff options
author | Roger Dingledine <arma@torproject.org> | 2003-12-17 21:14:13 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-12-17 21:14:13 +0000 |
commit | eb730c41c8a799bc61dfd7d106443fe467921caa (patch) | |
tree | 20154333f62aadb2d851d42baae6dc30a57067bf | |
parent | 6a19e64066fc0fb362db9b16e386008807d0984c (diff) | |
download | tor-eb730c41c8a799bc61dfd7d106443fe467921caa.tar.gz tor-eb730c41c8a799bc61dfd7d106443fe467921caa.zip |
clean tabs, trailing whitespace
svn:r952
-rw-r--r-- | src/common/aes.c | 2 | ||||
-rw-r--r-- | src/common/fakepoll.c | 68 | ||||
-rw-r--r-- | src/common/log.c | 10 | ||||
-rw-r--r-- | src/common/log.h | 6 | ||||
-rw-r--r-- | src/common/torint.h | 4 | ||||
-rw-r--r-- | src/common/tortls.c | 84 | ||||
-rw-r--r-- | src/common/util.c | 32 | ||||
-rw-r--r-- | src/common/util.h | 2 |
8 files changed, 104 insertions, 104 deletions
diff --git a/src/common/aes.c b/src/common/aes.c index ed3397ec40..1d9f916165 100644 --- a/src/common/aes.c +++ b/src/common/aes.c @@ -44,7 +44,7 @@ struct aes_cnt_cipher { u8 pos; }; -static void +static void _aes_fill_buf(aes_cnt_cipher_t *cipher) { u32 counter0 = cipher->counter0; diff --git a/src/common/fakepoll.c b/src/common/fakepoll.c index dda1228741..f9e044eaf1 100644 --- a/src/common/fakepoll.c +++ b/src/common/fakepoll.c @@ -33,61 +33,61 @@ int poll(struct pollfd *ufds, unsigned int nfds, int timeout) { int idx, maxfd, fd; - int r; + int r; #ifdef MS_WINDOWS int any_fds_set = 0; #endif - fd_set readfds, writefds, exceptfds; + fd_set readfds, writefds, exceptfds; #ifdef USING_FAKE_TIMEVAL #undef timeval #undef tv_sec #undef tv_usec #endif - struct timeval _timeout; - _timeout.tv_sec = timeout/1000; - _timeout.tv_usec = (timeout%1000)*1000; - FD_ZERO(&readfds); - FD_ZERO(&writefds); - FD_ZERO(&exceptfds); + struct timeval _timeout; + _timeout.tv_sec = timeout/1000; + _timeout.tv_usec = (timeout%1000)*1000; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); - maxfd = -1; - for (idx = 0; idx < nfds; ++idx) { + maxfd = -1; + for (idx = 0; idx < nfds; ++idx) { ufds[idx].revents = 0; - fd = ufds[idx].fd; + fd = ufds[idx].fd; if (fd > maxfd) { maxfd = fd; #ifdef MS_WINDOWS any_fds_set = 1; #endif } - if (ufds[idx].events & POLLIN) - FD_SET(fd, &readfds); - if (ufds[idx].events & POLLOUT) - FD_SET(fd, &writefds); - FD_SET(fd, &exceptfds); - } + if (ufds[idx].events & POLLIN) + FD_SET(fd, &readfds); + if (ufds[idx].events & POLLOUT) + FD_SET(fd, &writefds); + FD_SET(fd, &exceptfds); + } #ifdef MS_WINDOWS if (!any_fds_set) { Sleep(timeout); return 0; } #endif - r = select(maxfd+1, &readfds, &writefds, &exceptfds, - timeout == -1 ? NULL : &_timeout); - if (r <= 0) - return r; - r = 0; - for (idx = 0; idx < nfds; ++idx) { - fd = ufds[idx].fd; - if (FD_ISSET(fd, &readfds)) - ufds[idx].revents |= POLLIN; - if (FD_ISSET(fd, &writefds)) - ufds[idx].revents |= POLLOUT; - if (FD_ISSET(fd, &exceptfds)) - ufds[idx].revents |= POLLERR; - if (ufds[idx].revents) - ++r; - } - return r; + r = select(maxfd+1, &readfds, &writefds, &exceptfds, + timeout == -1 ? NULL : &_timeout); + if (r <= 0) + return r; + r = 0; + for (idx = 0; idx < nfds; ++idx) { + fd = ufds[idx].fd; + if (FD_ISSET(fd, &readfds)) + ufds[idx].revents |= POLLIN; + if (FD_ISSET(fd, &writefds)) + ufds[idx].revents |= POLLOUT; + if (FD_ISSET(fd, &exceptfds)) + ufds[idx].revents |= POLLERR; + if (ufds[idx].revents) + ++r; + } + return r; } #endif diff --git a/src/common/log.c b/src/common/log.c index 791883c165..947029079a 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -30,8 +30,8 @@ static logfile_t *logfiles = NULL; * of 'logv' so that we never format a message more than once. */ static INLINE void format_msg(char *buf, size_t buf_len, - int severity, const char *funcname, - const char *format, va_list ap) + int severity, const char *funcname, + const char *format, va_list ap) { time_t t; struct timeval now; @@ -44,7 +44,7 @@ static INLINE void format_msg(char *buf, size_t buf_len, n = strftime(buf, buf_len, "%b %d %H:%M:%S", localtime(&t)); n += snprintf(buf+n, buf_len-n, - ".%.3ld [%s] ", + ".%.3ld [%s] ", (long)now.tv_usec / 1000, sev_to_string(severity)); if(n > buf_len) n = buf_len-1; /* the *nprintf funcs return how many bytes they @@ -64,7 +64,7 @@ static INLINE void format_msg(char *buf, size_t buf_len, buf[n+1]='\0'; } -static void +static void logv(int severity, const char *funcname, const char *format, va_list ap) { char buf[10024]; @@ -145,7 +145,7 @@ void add_stream_log(int loglevel, const char *name, FILE *stream) * If opening the logfile fails, -1 is returned and * errno is set appropriately (by fopen) */ -int add_file_log(int loglevel, const char *filename) +int add_file_log(int loglevel, const char *filename) { FILE *f; f = fopen(filename, "a"); diff --git a/src/common/log.h b/src/common/log.h index dace715d43..87a74bafe3 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -14,13 +14,13 @@ #define LOG_ERR 4 #endif -/* magic to make GCC check for proper format strings. */ +/* magic to make GCC check for proper format strings. */ #ifdef __GNUC__ #define CHECK_PRINTF(formatIdx, firstArg) \ __attribute__ ((format (printf, formatIdx, firstArg))) #else -#define CHECK_PRINTF(formatIdx, firstArg) -#endif +#define CHECK_PRINTF(formatIdx, firstArg) +#endif void add_stream_log(int loglevel, const char *name, FILE *stream); int add_file_log(int severity, const char *filename); diff --git a/src/common/torint.h b/src/common/torint.h index 96b1e83335..d3efe62122 100644 --- a/src/common/torint.h +++ b/src/common/torint.h @@ -51,7 +51,7 @@ typedef unsigned char uint8_t; #endif #endif -#if (SIZEOF_SHORT == 2) +#if (SIZEOF_SHORT == 2) #ifndef HAVE_INT16_T typedef signed short int16_t; #define HAVE_INT16_T @@ -63,7 +63,7 @@ typedef unsigned short uint16_t; #endif -#if (SIZEOF_INT == 2) +#if (SIZEOF_INT == 2) #ifndef HAVE_INT16_T typedef signed int int16_t; #define HAVE_INT16_T diff --git a/src/common/tortls.c b/src/common/tortls.c index aab22b88ec..89009ea13e 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -34,16 +34,16 @@ struct tor_tls_context_st { struct tor_tls_st { SSL *ssl; int socket; - enum { - TOR_TLS_ST_HANDSHAKE, TOR_TLS_ST_OPEN, TOR_TLS_ST_GOTCLOSE, + enum { + TOR_TLS_ST_HANDSHAKE, TOR_TLS_ST_OPEN, TOR_TLS_ST_GOTCLOSE, TOR_TLS_ST_SENTCLOSE, TOR_TLS_ST_CLOSED } state; int isServer; int wantwrite_n; /* 0 normally, >0 if we returned wantwrite last time */ }; -static X509* tor_tls_create_certificate(crypto_pk_env_t *rsa, - const char *nickname); +static X509* tor_tls_create_certificate(crypto_pk_env_t *rsa, + const char *nickname); /* global tls context, keep it here because nobody else needs to touch it */ static tor_tls_context *global_tls_context = NULL; @@ -80,7 +80,7 @@ tls_log_errors(int severity, const char *doing) static int tor_tls_get_error(tor_tls *tls, int r, int extra, - const char *doing, int severity) + const char *doing, int severity) { int err = SSL_get_error(tls->ssl, r); switch (err) { @@ -92,13 +92,13 @@ tor_tls_get_error(tor_tls *tls, int r, int extra, return TOR_TLS_WANTWRITE; case SSL_ERROR_SYSCALL: if (extra&CATCH_SYSCALL) - return _TOR_TLS_SYSCALL; + return _TOR_TLS_SYSCALL; log(severity, "TLS error: <syscall error> (errno=%d)",errno); tls_log_errors(severity, doing); return TOR_TLS_ERROR; case SSL_ERROR_ZERO_RETURN: if (extra&CATCH_ZERO) - return _TOR_TLS_ZERORETURN; + return _TOR_TLS_ZERORETURN; log(severity, "TLS error: Zero return"); tls_log_errors(severity, doing); return TOR_TLS_ERROR; @@ -119,7 +119,7 @@ tor_tls_init() { } } -static int always_accept_verify_cb(int preverify_ok, +static int always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) { /* We always accept peer certs and complete the handshake. We don't validate @@ -132,7 +132,7 @@ static int always_accept_verify_cb(int preverify_ok, * by 'certfile'. Return 0 on success, -1 for failure. */ X509 * -tor_tls_create_certificate(crypto_pk_env_t *rsa, +tor_tls_create_certificate(crypto_pk_env_t *rsa, const char *nickname) { time_t start_time, end_time; @@ -140,7 +140,7 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa, X509 *x509 = NULL; X509_NAME *name = NULL; int nid; - + tor_tls_init(); start_time = time(NULL); @@ -154,7 +154,7 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa, goto error; if (!(ASN1_INTEGER_set(X509_get_serialNumber(x509), (long)start_time))) goto error; - + if (!(name = X509_NAME_new())) goto error; if ((nid = OBJ_txt2nid("organizationName")) == NID_undef) goto error; @@ -163,7 +163,7 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa, if ((nid = OBJ_txt2nid("commonName")) == NID_undef) goto error; if (!(X509_NAME_add_entry_by_NID(name, nid, MBSTRING_ASC, (char*)nickname, -1, -1, 0))) goto error; - + if (!(X509_set_issuer_name(x509, name))) goto error; if (!(X509_set_subject_name(x509, name))) @@ -181,7 +181,7 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa, goto done; error: if (x509) { - X509_free(x509); + X509_free(x509); x509 = NULL; } done: @@ -198,11 +198,11 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa, * is needed. */ #define CIPHER_LIST TLS1_TXT_DHE_RSA_WITH_AES_128_SHA #elif defined(TLS1_TXT_DHE_RSA_WITH_AES_128_SHA) -/* Some people are running OpenSSL before 0.9.7, but we aren't. +/* Some people are running OpenSSL before 0.9.7, but we aren't. * We can support AES and 3DES. */ #define CIPHER_LIST (TLS1_TXT_DHE_RSA_WITH_AES_128_SHA ":" \ - SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA) + SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA) #else /* We're running OpenSSL before 0.9.7. We only support 3DES. */ #define CIPHER_LIST SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA @@ -221,7 +221,7 @@ tor_tls_context_new(crypto_pk_env_t *rsa, EVP_PKEY *pkey = NULL; tor_tls_context *result; X509 *cert = NULL; - + tor_tls_init(); if (rsa) { @@ -264,10 +264,10 @@ tor_tls_context_new(crypto_pk_env_t *rsa, dh = crypto_dh_new(); SSL_CTX_set_tmp_dh(result->ctx, dh->dh); crypto_dh_free(dh); - SSL_CTX_set_verify(result->ctx, SSL_VERIFY_PEER, + SSL_CTX_set_verify(result->ctx, SSL_VERIFY_PEER, always_accept_verify_cb); /* let us realloc bufs that we're writing from */ - SSL_CTX_set_mode(result->ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); + SSL_CTX_set_mode(result->ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); /* Free the old context if one exists. */ if (global_tls_context) { @@ -292,7 +292,7 @@ tor_tls_context_new(crypto_pk_env_t *rsa, return -1; } -/* Create a new TLS object from a TLS context, a filedescriptor, and +/* Create a new TLS object from a TLS context, a filedescriptor, and * a flag to determine whether it is functioning as a server. */ tor_tls * @@ -346,7 +346,7 @@ tor_tls_read(tor_tls *tls, char *cp, int len) /* Underlying function for TLS writing. Write up to 'n' characters * from 'cp' onto 'tls'. On success, returns the number of characters - * written. On failure, returns TOR_TLS_ERROR, TOR_TLS_WANTREAD, + * written. On failure, returns TOR_TLS_ERROR, TOR_TLS_WANTREAD, * or TOR_TLS_WANTWRITE. */ int @@ -394,11 +394,11 @@ tor_tls_handshake(tor_tls *tls) } r = tor_tls_get_error(tls,r,0, "handshaking", LOG_INFO); if (r == TOR_TLS_DONE) { - tls->state = TOR_TLS_ST_OPEN; + tls->state = TOR_TLS_ST_OPEN; } return r; } - + /* Shut down an open tls connection 'tls'. When finished, returns * TOR_TLS_DONE. On failure, returns TOR_TLS_ERROR, TOR_TLS_WANTREAD, * or TOR_TLS_WANTWRITE. @@ -416,15 +416,15 @@ tor_tls_shutdown(tor_tls *tls) * we read until the other side has closed too. */ do { - r = SSL_read(tls->ssl, buf, 128); + r = SSL_read(tls->ssl, buf, 128); } while (r>0); - err = tor_tls_get_error(tls, r, CATCH_ZERO, "reading to shut down", - LOG_INFO); + err = tor_tls_get_error(tls, r, CATCH_ZERO, "reading to shut down", + LOG_INFO); if (err == _TOR_TLS_ZERORETURN) { - tls->state = TOR_TLS_ST_GOTCLOSE; - /* fall through... */ + tls->state = TOR_TLS_ST_GOTCLOSE; + /* fall through... */ } else { - return err; + return err; } } @@ -434,11 +434,11 @@ tor_tls_shutdown(tor_tls *tls) tls->state = TOR_TLS_ST_CLOSED; return TOR_TLS_DONE; } - err = tor_tls_get_error(tls, r, CATCH_SYSCALL|CATCH_ZERO, "shutting down", - LOG_INFO); + err = tor_tls_get_error(tls, r, CATCH_SYSCALL|CATCH_ZERO, "shutting down", + LOG_INFO); if (err == _TOR_TLS_SYSCALL) { /* The underlying TCP connection closed while we were shutting down. */ - tls->state = TOR_TLS_ST_CLOSED; + tls->state = TOR_TLS_ST_CLOSED; return TOR_TLS_DONE; } else if (err == _TOR_TLS_ZERORETURN) { /* The TLS connection says that it sent a shutdown record, but @@ -446,11 +446,11 @@ tor_tls_shutdown(tor_tls *tls) * happened before, then go back to the start of the function * and try to read. */ - if (tls->state == TOR_TLS_ST_GOTCLOSE || - tls->state == TOR_TLS_ST_SENTCLOSE) { - log(LOG_WARN, - "TLS returned \"half-closed\" value while already half-closed"); - return TOR_TLS_ERROR; + if (tls->state == TOR_TLS_ST_GOTCLOSE || + tls->state == TOR_TLS_ST_SENTCLOSE) { + log(LOG_WARN, + "TLS returned \"half-closed\" value while already half-closed"); + return TOR_TLS_ERROR; } tls->state = TOR_TLS_ST_SENTCLOSE; /* fall through ... */ @@ -479,7 +479,7 @@ tor_tls_get_peer_cert_nickname(tor_tls *tls, char *buf, int buflen) X509_NAME *name = NULL; int nid; int lenout; - + if (!(cert = SSL_get_peer_certificate(tls->ssl))) { log_fn(LOG_WARN, "Peer has no certificate"); goto error; @@ -490,7 +490,7 @@ tor_tls_get_peer_cert_nickname(tor_tls *tls, char *buf, int buflen) } if ((nid = OBJ_txt2nid("commonName")) == NID_undef) goto error; - + lenout = X509_NAME_get_text_by_NID(name, nid, buf, buflen); if (lenout == -1) goto error; @@ -521,7 +521,7 @@ tor_tls_verify(tor_tls *tls) crypto_pk_env_t *r = NULL; if (!(cert = SSL_get_peer_certificate(tls->ssl))) return NULL; - + now = time(NULL); t = now + CERT_ALLOW_SKEW; if (X509_cmp_time(X509_get_notBefore(cert), &t) > 0) { @@ -533,7 +533,7 @@ tor_tls_verify(tor_tls *tls) log_fn(LOG_WARN,"Certificate already expired; possible clock skew."); goto done; } - + /* Get the public key. */ if (!(pkey = X509_get_pubkey(cert))) { log_fn(LOG_WARN,"X509_get_pubkey returned null"); @@ -554,7 +554,7 @@ tor_tls_verify(tor_tls *tls) r = _crypto_new_pk_env_rsa(rsa); rsa = NULL; - + done: if (cert) X509_free(cert); @@ -565,7 +565,7 @@ tor_tls_verify(tor_tls *tls) return r; } -int +int tor_tls_get_pending_bytes(tor_tls *tls) { assert(tls); diff --git a/src/common/util.c b/src/common/util.c index 1de6b99d6c..4d9a44953a 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -164,7 +164,7 @@ const char *eat_whitespace(const char *s) { } const char *eat_whitespace_no_nl(const char *s) { - while(*s == ' ' || *s == '\t') + while(*s == ' ' || *s == '\t') ++s; return s; } @@ -250,11 +250,11 @@ static int n_leapdays(int y1, int y2) { --y2; return (y2/4 - y1/4) - (y2/100 - y1/100) + (y2/400 - y1/400); } -static const int days_per_month[] = +static const int days_per_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; time_t tor_timegm (struct tm *tm) { - /* This is a pretty ironclad timegm implementation, snarfed from Python2.2. + /* This is a pretty ironclad timegm implementation, snarfed from Python2.2. * It's way more brute-force than fiddling with tzset(). */ time_t ret; @@ -270,7 +270,7 @@ time_t tor_timegm (struct tm *tm) { ++days; days += tm->tm_mday - 1; hours = days*24 + tm->tm_hour; - + minutes = hours*60 + tm->tm_min; ret = minutes*60 + tm->tm_sec; return ret; @@ -380,7 +380,7 @@ tor_socketpair(int family, int type, int protocol, int fd[2]) struct sockaddr_in listen_addr; struct sockaddr_in connect_addr; int size; - + if (protocol #ifdef AF_UNIX || family != AF_UNIX @@ -495,7 +495,7 @@ file_status_t file_status(const char *fname) } return FN_ERROR; } - if (st.st_mode & S_IFDIR) + if (st.st_mode & S_IFDIR) return FN_DIR; else if (st.st_mode & S_IFREG) return FN_FILE; @@ -510,17 +510,17 @@ int check_private_dir(const char *dirname, int create) struct stat st; if (stat(dirname, &st)) { if (errno != ENOENT) { - log(LOG_WARN, "Directory %s cannot be read: %s", dirname, + log(LOG_WARN, "Directory %s cannot be read: %s", dirname, strerror(errno)); return -1; - } + } if (!create) { log(LOG_WARN, "Directory %s does not exist.", dirname); return -1; } - log(LOG_INFO, "Creating directory %s", dirname); + log(LOG_INFO, "Creating directory %s", dirname); if (mkdir(dirname, 0700)) { - log(LOG_WARN, "Error creating directory %s: %s", dirname, + log(LOG_WARN, "Error creating directory %s: %s", dirname, strerror(errno)); return -1; } else { @@ -538,7 +538,7 @@ int check_private_dir(const char *dirname, int create) if (st.st_mode & 0077) { log(LOG_WARN, "Fixing permissions on directory %s", dirname); if (chmod(dirname, 0700)) { - log(LOG_WARN, "Could not chmod directory %s: %s", dirname, + log(LOG_WARN, "Could not chmod directory %s: %s", dirname, strerror(errno)); return -1; } else { @@ -561,12 +561,12 @@ write_str_to_file(const char *fname, const char *str) strcpy(tempname,fname); strcat(tempname,".tmp"); if ((fd = open(tempname, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) { - log(LOG_WARN, "Couldn't open %s for writing: %s", tempname, + log(LOG_WARN, "Couldn't open %s for writing: %s", tempname, strerror(errno)); return -1; } if (!(file = fdopen(fd, "w"))) { - log(LOG_WARN, "Couldn't fdopen %s for writing: %s", tempname, + log(LOG_WARN, "Couldn't fdopen %s for writing: %s", tempname, strerror(errno)); close(fd); return -1; } @@ -615,7 +615,7 @@ char *read_file_to_str(const char *filename) { return NULL; } close(fd); - + string[statbuf.st_size] = 0; /* null terminate it */ return string; } @@ -686,7 +686,7 @@ get_uname(void) snprintf(uname_result, 255, "%s %s %s %s %s", u.sysname, u.nodename, u.release, u.version, u.machine); uname_result[255] = '\0'; - } else + } else #endif { strcpy(uname_result, "Unknown platform"); @@ -780,7 +780,7 @@ int switch_id(char *user, char *group) { return 0; #endif - log_fn(LOG_ERR, + log_fn(LOG_ERR, "User or group specified, but switching users is not supported."); return -1; diff --git a/src/common/util.h b/src/common/util.h index 955e3c7e34..acb8ab82a4 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -90,7 +90,7 @@ void daemonize(void); void write_pidfile(char *filename); int switch_id(char *user, char *group); -/* For stupid historical reasons, windows sockets have an independent set of +/* For stupid historical reasons, windows sockets have an independent set of * errnos which they use as the fancy strikes them. */ #ifdef MS_WINDOWS |