Reformat inconsistent function declarations.

svn:r5160
This commit is contained in:
Nick Mathewson 2005-09-30 01:09:52 +00:00
parent 6ce1add8da
commit 92451f74a8
20 changed files with 368 additions and 168 deletions

View File

@ -608,7 +608,9 @@ static const u32 rcon[] = {
* *
* @return the number of rounds for the given cipher key size. * @return the number of rounds for the given cipher key size.
*/ */
int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits) { int
rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits)
{
int i = 0; int i = 0;
u32 temp; u32 temp;
@ -689,7 +691,9 @@ int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBit
return 0; return 0;
} }
void rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]) { void
rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16])
{
u32 s0, s1, s2, s3, t0, t1, t2, t3; u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL #ifndef FULL_UNROLL
int r; int r;

View File

@ -440,7 +440,8 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
* have a low soft limit.) Make sure we set it to at least * have a low soft limit.) Make sure we set it to at least
* <b>limit</b>. Return a new limit if we can, or -1 if we fail. */ * <b>limit</b>. Return a new limit if we can, or -1 if we fail. */
int int
set_max_file_descriptors(unsigned long limit, unsigned long cap) { set_max_file_descriptors(unsigned long limit, unsigned long cap)
{
#ifndef HAVE_GETRLIMIT #ifndef HAVE_GETRLIMIT
log_fn(LOG_INFO,"This platform is missing getrlimit(). Proceeding."); log_fn(LOG_INFO,"This platform is missing getrlimit(). Proceeding.");
if (limit > cap) { if (limit > cap) {
@ -488,7 +489,8 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap) {
* success. On failure, log and return -1. * success. On failure, log and return -1.
*/ */
int int
switch_id(char *user, char *group) { switch_id(char *user, char *group)
{
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
struct passwd *pw = NULL; struct passwd *pw = NULL;
struct group *gr = NULL; struct group *gr = NULL;
@ -1041,7 +1043,8 @@ struct tor_mutex_t {
* socket to get the error. * socket to get the error.
*/ */
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
int tor_socket_errno(int sock) int
tor_socket_errno(int sock)
{ {
int optval, optvallen=sizeof(optval); int optval, optvallen=sizeof(optval);
int err = WSAGetLastError(); int err = WSAGetLastError();

View File

@ -43,7 +43,8 @@ struct smartlist_t {
/** Allocate and return an empty smartlist. /** Allocate and return an empty smartlist.
*/ */
smartlist_t * smartlist_t *
smartlist_create(void) { smartlist_create(void)
{
smartlist_t *sl = tor_malloc(sizeof(smartlist_t)); smartlist_t *sl = tor_malloc(sizeof(smartlist_t));
sl->num_used = 0; sl->num_used = 0;
sl->capacity = SMARTLIST_DEFAULT_CAPACITY; sl->capacity = SMARTLIST_DEFAULT_CAPACITY;
@ -55,7 +56,8 @@ smartlist_create(void) {
* list's elements. * list's elements.
*/ */
void void
smartlist_free(smartlist_t *sl) { smartlist_free(smartlist_t *sl)
{
free(sl->list); free(sl->list);
free(sl); free(sl);
} }
@ -66,7 +68,9 @@ smartlist_free(smartlist_t *sl) {
* currently in the list, reduce the list's capacity as much as * currently in the list, reduce the list's capacity as much as
* possible without losing elements. * possible without losing elements.
*/ */
void smartlist_set_capacity(smartlist_t *sl, int n) { void
smartlist_set_capacity(smartlist_t *sl, int n)
{
if (n < sl->num_used) if (n < sl->num_used)
n = sl->num_used; n = sl->num_used;
if (sl->capacity != n) { if (sl->capacity != n) {
@ -78,7 +82,8 @@ void smartlist_set_capacity(smartlist_t *sl, int n) {
/** Remove all elements from the list. /** Remove all elements from the list.
*/ */
void void
smartlist_clear(smartlist_t *sl) { smartlist_clear(smartlist_t *sl)
{
sl->num_used = 0; sl->num_used = 0;
} }
@ -95,7 +100,8 @@ smartlist_truncate(smartlist_t *sl, int len)
/** Append element to the end of the list. */ /** Append element to the end of the list. */
void void
smartlist_add(smartlist_t *sl, void *element) { smartlist_add(smartlist_t *sl, void *element)
{
if (sl->num_used >= sl->capacity) { if (sl->num_used >= sl->capacity) {
int higher = sl->capacity * 2; int higher = sl->capacity * 2;
tor_assert(higher > sl->capacity); /* detect overflow */ tor_assert(higher > sl->capacity); /* detect overflow */

View File

@ -119,7 +119,8 @@ static int tor_check_dh_key(BIGNUM *bn);
/** Return the number of bytes added by padding method <b>padding</b>. /** Return the number of bytes added by padding method <b>padding</b>.
*/ */
static INLINE int static INLINE int
crypto_get_rsa_padding_overhead(int padding) { crypto_get_rsa_padding_overhead(int padding)
{
switch (padding) switch (padding)
{ {
case RSA_NO_PADDING: return 0; case RSA_NO_PADDING: return 0;
@ -132,7 +133,8 @@ crypto_get_rsa_padding_overhead(int padding) {
/** Given a padding method <b>padding</b>, return the correct OpenSSL constant. /** Given a padding method <b>padding</b>, return the correct OpenSSL constant.
*/ */
static INLINE int static INLINE int
crypto_get_rsa_padding(int padding) { crypto_get_rsa_padding(int padding)
{
switch (padding) switch (padding)
{ {
case PK_NO_PADDING: return RSA_NO_PADDING; case PK_NO_PADDING: return RSA_NO_PADDING;
@ -216,7 +218,8 @@ crypto_global_init(int useAccel)
/** Uninitialize the crypto library. Return 0 on success, -1 on failure. /** Uninitialize the crypto library. Return 0 on success, -1 on failure.
*/ */
int crypto_global_cleanup(void) int
crypto_global_cleanup(void)
{ {
ERR_free_strings(); ERR_free_strings();
#ifndef NO_ENGINES #ifndef NO_ENGINES
@ -304,7 +307,8 @@ crypto_pk_env_t *crypto_new_pk_env(void)
/** Release a reference to an asymmetric key; when all the references /** Release a reference to an asymmetric key; when all the references
* are released, free the key. * are released, free the key.
*/ */
void crypto_free_pk_env(crypto_pk_env_t *env) void
crypto_free_pk_env(crypto_pk_env_t *env)
{ {
tor_assert(env); tor_assert(env);
@ -365,7 +369,8 @@ crypto_cipher_env_t *crypto_new_cipher_env(void)
/** Free a symmetric cipher. /** Free a symmetric cipher.
*/ */
void crypto_free_cipher_env(crypto_cipher_env_t *env) void
crypto_free_cipher_env(crypto_cipher_env_t *env)
{ {
tor_assert(env); tor_assert(env);
@ -379,7 +384,8 @@ void crypto_free_cipher_env(crypto_cipher_env_t *env)
/** Generate a new public/private keypair in <b>env</b>. Return 0 on /** Generate a new public/private keypair in <b>env</b>. Return 0 on
* success, -1 on failure. * success, -1 on failure.
*/ */
int crypto_pk_generate_key(crypto_pk_env_t *env) int
crypto_pk_generate_key(crypto_pk_env_t *env)
{ {
tor_assert(env); tor_assert(env);
@ -397,7 +403,8 @@ int crypto_pk_generate_key(crypto_pk_env_t *env)
/** Read a PEM-encoded private key from the string <b>s</b> into <b>env</b>. /** Read a PEM-encoded private key from the string <b>s</b> into <b>env</b>.
* Return 0 on success, -1 on failure. * Return 0 on success, -1 on failure.
*/ */
static int crypto_pk_read_private_key_from_string(crypto_pk_env_t *env, static int
crypto_pk_read_private_key_from_string(crypto_pk_env_t *env,
const char *s) const char *s)
{ {
BIO *b; BIO *b;
@ -425,7 +432,8 @@ static int crypto_pk_read_private_key_from_string(crypto_pk_env_t *env,
/** Read a PEM-encoded private key from the file named by /** Read a PEM-encoded private key from the file named by
* <b>keyfile</b> into <b>env</b>. Return 0 on success, -1 on failure. * <b>keyfile</b> into <b>env</b>. Return 0 on success, -1 on failure.
*/ */
int crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, const char *keyfile) int
crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, const char *keyfile)
{ {
char *contents; char *contents;
int r; int r;
@ -455,7 +463,9 @@ int crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, const char *k
* string, *<b>len</b> to the string's length, and return 0. On * string, *<b>len</b> to the string's length, and return 0. On
* failure, return -1. * failure, return -1.
*/ */
int crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size_t *len) { int
crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size_t *len)
{
BUF_MEM *buf; BUF_MEM *buf;
BIO *b; BIO *b;
@ -491,7 +501,9 @@ int crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size
* <b>src</b>, and store the result in <b>env</b>. Return 0 on success, -1 on * <b>src</b>, and store the result in <b>env</b>. Return 0 on success, -1 on
* failure. * failure.
*/ */
int crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, const char *src, size_t len) { int
crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, const char *src, size_t len)
{
BIO *b; BIO *b;
tor_assert(env); tor_assert(env);
@ -556,7 +568,8 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
* directories containing "opt keyword\n-----BEGIN OBJECT----" entries * directories containing "opt keyword\n-----BEGIN OBJECT----" entries
* in versions of Tor up to 0.0.9pre2.</i> * in versions of Tor up to 0.0.9pre2.</i>
*/ */
int crypto_pk_DER64_encode_public_key(crypto_pk_env_t *env, char **out) int
crypto_pk_DER64_encode_public_key(crypto_pk_env_t *env, char **out)
{ {
int len; int len;
char buf[PK_BYTES*2]; /* Too long, but hey, stacks are big. */ char buf[PK_BYTES*2]; /* Too long, but hey, stacks are big. */
@ -585,7 +598,8 @@ int crypto_pk_DER64_encode_public_key(crypto_pk_env_t *env, char **out)
* directories containing "opt keyword\n-----BEGIN OBJECT----" entries * directories containing "opt keyword\n-----BEGIN OBJECT----" entries
* in versions of Tor up to 0.0.9pre2.</i> * in versions of Tor up to 0.0.9pre2.</i>
*/ */
crypto_pk_env_t *crypto_pk_DER64_decode_public_key(const char *in) crypto_pk_env_t *
crypto_pk_DER64_decode_public_key(const char *in)
{ {
char partitioned[PK_BYTES*2 + 16]; char partitioned[PK_BYTES*2 + 16];
char buf[PK_BYTES*2]; char buf[PK_BYTES*2];
@ -611,7 +625,8 @@ crypto_pk_env_t *crypto_pk_DER64_decode_public_key(const char *in)
/** Return true iff <b>env</b> has a valid key. /** Return true iff <b>env</b> has a valid key.
*/ */
int crypto_pk_check_key(crypto_pk_env_t *env) int
crypto_pk_check_key(crypto_pk_env_t *env)
{ {
int r; int r;
tor_assert(env); tor_assert(env);
@ -625,7 +640,9 @@ int crypto_pk_check_key(crypto_pk_env_t *env)
/** Compare the public-key components of a and b. Return -1 if a\<b, 0 /** Compare the public-key components of a and b. Return -1 if a\<b, 0
* if a==b, and 1 if a\>b. * if a==b, and 1 if a\>b.
*/ */
int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b) { int
crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b)
{
int result; int result;
if (!a || !b) if (!a || !b)
@ -643,7 +660,8 @@ int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b) {
} }
/** Return the size of the public key modulus in <b>env</b>, in bytes. */ /** Return the size of the public key modulus in <b>env</b>, in bytes. */
size_t crypto_pk_keysize(crypto_pk_env_t *env) size_t
crypto_pk_keysize(crypto_pk_env_t *env)
{ {
tor_assert(env); tor_assert(env);
tor_assert(env->key); tor_assert(env->key);
@ -653,7 +671,9 @@ size_t crypto_pk_keysize(crypto_pk_env_t *env)
/** Increase the reference count of <b>env</b>, and return it. /** Increase the reference count of <b>env</b>, and return it.
*/ */
crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *env) { crypto_pk_env_t *
crypto_pk_dup_key(crypto_pk_env_t *env)
{
tor_assert(env); tor_assert(env);
tor_assert(env->key); tor_assert(env->key);
@ -827,7 +847,8 @@ crypto_pk_private_sign_digest(crypto_pk_env_t *env, char *to,
* padded and encrypted with the public key; followed by the rest of * padded and encrypted with the public key; followed by the rest of
* the source data encrypted in AES-CTR mode with the symmetric key. * the source data encrypted in AES-CTR mode with the symmetric key.
*/ */
int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env, int
crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env,
char *to, char *to,
const char *from, const char *from,
size_t fromlen, size_t fromlen,
@ -890,7 +911,8 @@ int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env,
} }
/** Invert crypto_pk_public_hybrid_encrypt. */ /** Invert crypto_pk_public_hybrid_encrypt. */
int crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env, int
crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
char *to, char *to,
const char *from, const char *from,
size_t fromlen, size_t fromlen,
@ -937,7 +959,8 @@ int crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
/** ASN.1-encode the public portion of <b>pk</b> into <b>dest</b>. /** ASN.1-encode the public portion of <b>pk</b> into <b>dest</b>.
* Return -1 on error, or the number of characters used on success. * Return -1 on error, or the number of characters used on success.
*/ */
int crypto_pk_asn1_encode(crypto_pk_env_t *pk, char *dest, int dest_len) int
crypto_pk_asn1_encode(crypto_pk_env_t *pk, char *dest, int dest_len)
{ {
int len; int len;
unsigned char *buf, *cp; unsigned char *buf, *cp;
@ -962,7 +985,8 @@ int crypto_pk_asn1_encode(crypto_pk_env_t *pk, char *dest, int dest_len)
/** Decode an ASN.1-encoded public key from <b>str</b>; return the result on /** Decode an ASN.1-encoded public key from <b>str</b>; return the result on
* success and NULL on failure. * success and NULL on failure.
*/ */
crypto_pk_env_t *crypto_pk_asn1_decode(const char *str, size_t len) crypto_pk_env_t *
crypto_pk_asn1_decode(const char *str, size_t len)
{ {
RSA *rsa; RSA *rsa;
unsigned char *buf; unsigned char *buf;
@ -989,7 +1013,8 @@ crypto_pk_env_t *crypto_pk_asn1_decode(const char *str, size_t len)
* public key into <b>digest_out</b> (must have DIGEST_LEN bytes of space). * public key into <b>digest_out</b> (must have DIGEST_LEN bytes of space).
* Return 0 on success, -1 on failure. * Return 0 on success, -1 on failure.
*/ */
int crypto_pk_get_digest(crypto_pk_env_t *pk, char *digest_out) int
crypto_pk_get_digest(crypto_pk_env_t *pk, char *digest_out)
{ {
unsigned char *buf, *bufp; unsigned char *buf, *bufp;
int len; int len;
@ -1063,7 +1088,8 @@ crypto_pk_check_fingerprint_syntax(const char *s)
/** Generate a new random key for the symmetric cipher in <b>env</b>. /** Generate a new random key for the symmetric cipher in <b>env</b>.
* Return 0 on success, -1 on failure. Does not initialize the cipher. * Return 0 on success, -1 on failure. Does not initialize the cipher.
*/ */
int crypto_cipher_generate_key(crypto_cipher_env_t *env) int
crypto_cipher_generate_key(crypto_cipher_env_t *env)
{ {
tor_assert(env); tor_assert(env);
@ -1074,7 +1100,8 @@ int crypto_cipher_generate_key(crypto_cipher_env_t *env)
* CIPHER_KEY_LEN bytes of <b>key</b>. Does not initialize the cipher. * CIPHER_KEY_LEN bytes of <b>key</b>. Does not initialize the cipher.
* Return 0 on success, -1 on failure. * Return 0 on success, -1 on failure.
*/ */
int crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key) int
crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key)
{ {
tor_assert(env); tor_assert(env);
tor_assert(key); tor_assert(key);
@ -1089,7 +1116,8 @@ int crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key)
/** Return a pointer to the key set for the cipher in <b>env</b>. /** Return a pointer to the key set for the cipher in <b>env</b>.
*/ */
const char *crypto_cipher_get_key(crypto_cipher_env_t *env) const char *
crypto_cipher_get_key(crypto_cipher_env_t *env)
{ {
return env->key; return env->key;
} }
@ -1097,7 +1125,8 @@ const char *crypto_cipher_get_key(crypto_cipher_env_t *env)
/** Initialize the cipher in <b>env</b> for encryption. Return 0 on /** Initialize the cipher in <b>env</b> for encryption. Return 0 on
* success, -1 on failure. * success, -1 on failure.
*/ */
int crypto_cipher_encrypt_init_cipher(crypto_cipher_env_t *env) int
crypto_cipher_encrypt_init_cipher(crypto_cipher_env_t *env)
{ {
tor_assert(env); tor_assert(env);
@ -1108,7 +1137,8 @@ int crypto_cipher_encrypt_init_cipher(crypto_cipher_env_t *env)
/** Initialize the cipher in <b>env</b> for decryption. Return 0 on /** Initialize the cipher in <b>env</b> for decryption. Return 0 on
* success, -1 on failure. * success, -1 on failure.
*/ */
int crypto_cipher_decrypt_init_cipher(crypto_cipher_env_t *env) int
crypto_cipher_decrypt_init_cipher(crypto_cipher_env_t *env)
{ {
tor_assert(env); tor_assert(env);
@ -1175,7 +1205,8 @@ crypto_cipher_advance(crypto_cipher_env_t *env, long delta)
* <b>m</b>. Write the DIGEST_LEN byte result into <b>digest</b>. * <b>m</b>. Write the DIGEST_LEN byte result into <b>digest</b>.
* Return 0 on success, -1 on failure. * Return 0 on success, -1 on failure.
*/ */
int crypto_digest(char *digest, const char *m, size_t len) int
crypto_digest(char *digest, const char *m, size_t len)
{ {
tor_assert(m); tor_assert(m);
tor_assert(digest); tor_assert(digest);
@ -1200,7 +1231,8 @@ crypto_new_digest_env(void)
/** Deallocate a digest object. /** Deallocate a digest object.
*/ */
void void
crypto_free_digest_env(crypto_digest_env_t *digest) { crypto_free_digest_env(crypto_digest_env_t *digest)
{
tor_free(digest); tor_free(digest);
} }
@ -1224,7 +1256,8 @@ crypto_digest_add_bytes(crypto_digest_env_t *digest, const char *data,
* object; write the first out_len bytes of the result to <b>out</b>. * object; write the first out_len bytes of the result to <b>out</b>.
* <b>out_len</b> must be \<= DIGEST_LEN. * <b>out_len</b> must be \<= DIGEST_LEN.
*/ */
void crypto_digest_get_digest(crypto_digest_env_t *digest, void
crypto_digest_get_digest(crypto_digest_env_t *digest,
char *out, size_t out_len) char *out, size_t out_len)
{ {
static unsigned char r[DIGEST_LEN]; static unsigned char r[DIGEST_LEN];
@ -1272,7 +1305,9 @@ static BIGNUM *dh_param_g = NULL;
/** Initialize dh_param_p and dh_param_g if they are not already /** Initialize dh_param_p and dh_param_g if they are not already
* set. */ * set. */
static void init_dh_param(void) { static void
init_dh_param(void)
{
BIGNUM *p, *g; BIGNUM *p, *g;
int r; int r;
if (dh_param_p && dh_param_g) if (dh_param_p && dh_param_g)
@ -1303,7 +1338,8 @@ static void init_dh_param(void) {
/** Allocate and return a new DH object for a key exchange. /** Allocate and return a new DH object for a key exchange.
*/ */
crypto_dh_env_t *crypto_dh_new(void) crypto_dh_env_t *
crypto_dh_new(void)
{ {
crypto_dh_env_t *res = NULL; crypto_dh_env_t *res = NULL;
@ -1331,7 +1367,8 @@ crypto_dh_env_t *crypto_dh_new(void)
/** Return the length of the DH key in <b>dh</b>, in bytes. /** Return the length of the DH key in <b>dh</b>, in bytes.
*/ */
int crypto_dh_get_bytes(crypto_dh_env_t *dh) int
crypto_dh_get_bytes(crypto_dh_env_t *dh)
{ {
tor_assert(dh); tor_assert(dh);
return DH_size(dh->dh); return DH_size(dh->dh);
@ -1340,7 +1377,8 @@ int crypto_dh_get_bytes(crypto_dh_env_t *dh)
/** Generate \<x,g^x\> for our part of the key exchange. Return 0 on /** Generate \<x,g^x\> for our part of the key exchange. Return 0 on
* success, -1 on failure. * success, -1 on failure.
*/ */
int crypto_dh_generate_public(crypto_dh_env_t *dh) int
crypto_dh_generate_public(crypto_dh_env_t *dh)
{ {
again: again:
if (!DH_generate_key(dh->dh)) { if (!DH_generate_key(dh->dh)) {
@ -1362,7 +1400,8 @@ int crypto_dh_generate_public(crypto_dh_env_t *dh)
* as a <b>pubkey_len</b>-byte value into <b>pubkey</b>. Return 0 on * as a <b>pubkey_len</b>-byte value into <b>pubkey</b>. Return 0 on
* success, -1 on failure. <b>pubkey_len</b> must be \>= DH_BYTES. * success, -1 on failure. <b>pubkey_len</b> must be \>= DH_BYTES.
*/ */
int crypto_dh_get_public(crypto_dh_env_t *dh, char *pubkey, size_t pubkey_len) int
crypto_dh_get_public(crypto_dh_env_t *dh, char *pubkey, size_t pubkey_len)
{ {
int bytes; int bytes;
tor_assert(dh); tor_assert(dh);
@ -1454,7 +1493,8 @@ tor_check_dh_key(BIGNUM *bn)
* SHA1( g^xy || "\x00" ) || SHA1( g^xy || "\x01" ) || ... * SHA1( g^xy || "\x00" ) || SHA1( g^xy || "\x01" ) || ...
* where || is concatenation.) * where || is concatenation.)
*/ */
int crypto_dh_compute_secret(crypto_dh_env_t *dh, int
crypto_dh_compute_secret(crypto_dh_env_t *dh,
const char *pubkey, size_t pubkey_len, const char *pubkey, size_t pubkey_len,
char *secret_out, size_t secret_bytes_out) char *secret_out, size_t secret_bytes_out)
{ {
@ -1512,7 +1552,8 @@ int crypto_dh_compute_secret(crypto_dh_env_t *dh,
/** Free a DH key exchange object. /** Free a DH key exchange object.
*/ */
void crypto_dh_free(crypto_dh_env_t *dh) void
crypto_dh_free(crypto_dh_env_t *dh)
{ {
tor_assert(dh); tor_assert(dh);
tor_assert(dh->dh); tor_assert(dh->dh);
@ -1525,7 +1566,8 @@ void crypto_dh_free(crypto_dh_env_t *dh)
/** Seed OpenSSL's random number generator with DIGEST_LEN bytes from the /** Seed OpenSSL's random number generator with DIGEST_LEN bytes from the
* operating system. Return 0 on success, -1 on failure. * operating system. Return 0 on success, -1 on failure.
*/ */
int crypto_seed_rng(void) int
crypto_seed_rng(void)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
static int provider_set = 0; static int provider_set = 0;
@ -1580,7 +1622,8 @@ int crypto_seed_rng(void)
/** Write n bytes of strong random data to <b>to</b>. Return 0 on /** Write n bytes of strong random data to <b>to</b>. Return 0 on
* success, -1 on failure. * success, -1 on failure.
*/ */
int crypto_rand(char *to, size_t n) int
crypto_rand(char *to, size_t n)
{ {
int r; int r;
tor_assert(to); tor_assert(to);
@ -1593,7 +1636,8 @@ int crypto_rand(char *to, size_t n)
/** Write n bytes of pseudorandom data to <b>to</b>. Return 0 on /** Write n bytes of pseudorandom data to <b>to</b>. Return 0 on
* success, -1 on failure. * success, -1 on failure.
*/ */
void crypto_pseudo_rand(char *to, size_t n) void
crypto_pseudo_rand(char *to, size_t n)
{ {
tor_assert(to); tor_assert(to);
if (RAND_pseudo_bytes((unsigned char*)to, n) == -1) { if (RAND_pseudo_bytes((unsigned char*)to, n) == -1) {
@ -1605,7 +1649,9 @@ void crypto_pseudo_rand(char *to, size_t n)
/** Return a pseudorandom integer, chosen uniformly from the values /** Return a pseudorandom integer, chosen uniformly from the values
* between 0 and max-1. */ * between 0 and max-1. */
int crypto_pseudo_rand_int(unsigned int max) { int
crypto_pseudo_rand_int(unsigned int max)
{
unsigned int val; unsigned int val;
unsigned int cutoff; unsigned int cutoff;
tor_assert(max < UINT_MAX); tor_assert(max < UINT_MAX);
@ -1625,7 +1671,9 @@ int crypto_pseudo_rand_int(unsigned int max) {
/** Return a randomly chosen element of sl; or NULL if sl is empty. /** Return a randomly chosen element of sl; or NULL if sl is empty.
*/ */
void *smartlist_choose(const smartlist_t *sl) { void *
smartlist_choose(const smartlist_t *sl)
{
size_t len; size_t len;
len = smartlist_len(sl); len = smartlist_len(sl);
if (len) if (len)
@ -1793,8 +1841,10 @@ _openssl_locking_cb(int mode, int n, const char *file, int line)
else else
tor_mutex_release(_openssl_mutexes[n]); tor_mutex_release(_openssl_mutexes[n]);
} }
static int static int
setup_openssl_threading(void) { setup_openssl_threading(void)
{
int i; int i;
int n = CRYPTO_num_locks(); int n = CRYPTO_num_locks();
_n_openssl_mutexes = n; _n_openssl_mutexes = n;
@ -1806,6 +1856,10 @@ setup_openssl_threading(void) {
return 0; return 0;
} }
#else #else
static int setup_openssl_threading(void) { return 0; } static int
setup_openssl_threading(void)
{
return 0;
}
#endif #endif

View File

@ -46,7 +46,9 @@ typedef struct logfile_t {
} logfile_t; } logfile_t;
/** Helper: map a log severity to descriptive string. */ /** Helper: map a log severity to descriptive string. */
static INLINE const char *sev_to_string(int severity) { static INLINE const char *
sev_to_string(int severity)
{
switch (severity) { switch (severity) {
case LOG_DEBUG: return "debug"; case LOG_DEBUG: return "debug";
case LOG_INFO: return "info"; case LOG_INFO: return "info";
@ -97,7 +99,8 @@ _log_prefix(char *buf, size_t buf_len, int severity)
* *
* Return -1 if the log is broken and needs to be deleted, else return 0. * Return -1 if the log is broken and needs to be deleted, else return 0.
*/ */
static int log_tor_version(logfile_t *lf, int reset) static int
log_tor_version(logfile_t *lf, int reset)
{ {
char buf[256]; char buf[256];
size_t n; size_t n;
@ -132,7 +135,8 @@ static int log_tor_version(logfile_t *lf, int reset)
* than once.) Return a pointer to the first character of the message * than once.) Return a pointer to the first character of the message
* portion of the formatted string. * portion of the formatted string.
*/ */
static INLINE char *format_msg(char *buf, size_t buf_len, static INLINE char *
format_msg(char *buf, size_t buf_len,
int severity, const char *funcname, int severity, const char *funcname,
const char *format, va_list ap) const char *format, va_list ap)
{ {
@ -228,7 +232,8 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
} }
/** Output a message to the log. */ /** Output a message to the log. */
void _log(int severity, const char *format, ...) void
_log(int severity, const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap,format); va_start(ap,format);
@ -238,7 +243,8 @@ void _log(int severity, const char *format, ...)
/** Output a message to the log, prefixed with a function name <b>fn</b>. */ /** Output a message to the log, prefixed with a function name <b>fn</b>. */
#ifdef __GNUC__ #ifdef __GNUC__
void _log_fn(int severity, const char *fn, const char *format, ...) void
_log_fn(int severity, const char *fn, const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap,format); va_start(ap,format);
@ -247,7 +253,8 @@ void _log_fn(int severity, const char *fn, const char *format, ...)
} }
#else #else
const char *_log_fn_function_name=NULL; const char *_log_fn_function_name=NULL;
void _log_fn(int severity, const char *format, ...) void
_log_fn(int severity, const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap,format); va_start(ap,format);
@ -258,7 +265,8 @@ void _log_fn(int severity, const char *format, ...)
#endif #endif
/** Close all open log files. */ /** Close all open log files. */
void close_logs(void) void
close_logs(void)
{ {
logfile_t *victim; logfile_t *victim;
while (logfiles) { while (logfiles) {
@ -271,7 +279,8 @@ void close_logs(void)
} }
/** Close and re-open all log files; used to rotate logs on SIGHUP. */ /** Close and re-open all log files; used to rotate logs on SIGHUP. */
void reset_logs(void) void
reset_logs(void)
{ {
logfile_t *lf = logfiles; logfile_t *lf = logfiles;
while (lf) { while (lf) {
@ -291,7 +300,9 @@ void reset_logs(void)
* called). After this function is called, the caller shouldn't refer * called). After this function is called, the caller shouldn't refer
* to <b>victim</b> anymore. * to <b>victim</b> anymore.
*/ */
static void delete_log(logfile_t *victim) { static void
delete_log(logfile_t *victim)
{
logfile_t *tmpl; logfile_t *tmpl;
if (victim == logfiles) if (victim == logfiles)
logfiles = victim->next; logfiles = victim->next;
@ -307,7 +318,8 @@ static void delete_log(logfile_t *victim) {
/** Helper: release system resources (but not memory) held by a single /** Helper: release system resources (but not memory) held by a single
* logfile_t. */ * logfile_t. */
static void close_log(logfile_t *victim) static void
close_log(logfile_t *victim)
{ {
if (victim->needs_close && victim->file) { if (victim->needs_close && victim->file) {
fclose(victim->file); fclose(victim->file);
@ -324,7 +336,8 @@ static void close_log(logfile_t *victim)
/** Helper: reset a single logfile_t. For a file log, this involves /** Helper: reset a single logfile_t. For a file log, this involves
* closing and reopening the log, and maybe writing the version. For * closing and reopening the log, and maybe writing the version. For
* other log types, do nothing. */ * other log types, do nothing. */
static int reset_log(logfile_t *lf) static int
reset_log(logfile_t *lf)
{ {
if (lf->needs_close) { if (lf->needs_close) {
if (fclose(lf->file)==EOF || if (fclose(lf->file)==EOF ||
@ -340,7 +353,8 @@ static int reset_log(logfile_t *lf)
/** Add a log handler to send all messages of severity <b>loglevel</b> /** Add a log handler to send all messages of severity <b>loglevel</b>
* or higher to <b>stream</b>. */ * or higher to <b>stream</b>. */
void add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *stream) void
add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *stream)
{ {
logfile_t *lf; logfile_t *lf;
lf = tor_malloc_zero(sizeof(logfile_t)); lf = tor_malloc_zero(sizeof(logfile_t));
@ -355,7 +369,8 @@ void add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *st
/** Add a log handler to receive messages during startup (before the real /** Add a log handler to receive messages during startup (before the real
* logs are initialized). * logs are initialized).
*/ */
void add_temp_log(void) void
add_temp_log(void)
{ {
add_stream_log(LOG_NOTICE, LOG_ERR, "<temp>", stdout); add_stream_log(LOG_NOTICE, LOG_ERR, "<temp>", stdout);
logfiles->is_temporary = 1; logfiles->is_temporary = 1;
@ -366,7 +381,8 @@ void add_temp_log(void)
* <b>logLevelmin</b> and <b>logLevelMax</b> to the function * <b>logLevelmin</b> and <b>logLevelMax</b> to the function
* <b>cb</b>. * <b>cb</b>.
*/ */
int add_callback_log(int loglevelMin, int loglevelMax, log_callback cb) int
add_callback_log(int loglevelMin, int loglevelMax, log_callback cb)
{ {
logfile_t *lf; logfile_t *lf;
lf = tor_malloc_zero(sizeof(logfile_t)); lf = tor_malloc_zero(sizeof(logfile_t));
@ -379,7 +395,8 @@ int add_callback_log(int loglevelMin, int loglevelMax, log_callback cb)
return 0; return 0;
} }
void change_callback_log_severity(int loglevelMin, int loglevelMax, void
change_callback_log_severity(int loglevelMin, int loglevelMax,
log_callback cb) log_callback cb)
{ {
logfile_t *lf; logfile_t *lf;
@ -392,7 +409,8 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax,
} }
/** Close any log handlers added by add_temp_log or marked by mark_logs_temp */ /** Close any log handlers added by add_temp_log or marked by mark_logs_temp */
void close_temp_logs(void) void
close_temp_logs(void)
{ {
logfile_t *lf, **p; logfile_t *lf, **p;
for (p = &logfiles; *p; ) { for (p = &logfiles; *p; ) {
@ -410,7 +428,8 @@ void close_temp_logs(void)
} }
/** Configure all log handles to be closed by close_temp_logs */ /** Configure all log handles to be closed by close_temp_logs */
void mark_logs_temp(void) void
mark_logs_temp(void)
{ {
logfile_t *lf; logfile_t *lf;
for (lf = logfiles; lf; lf = lf->next) for (lf = logfiles; lf; lf = lf->next)
@ -422,7 +441,8 @@ void mark_logs_temp(void)
* the logfile fails, -1 is returned and errno is set appropriately * the logfile fails, -1 is returned and errno is set appropriately
* (by fopen). * (by fopen).
*/ */
int add_file_log(int loglevelMin, int loglevelMax, const char *filename) int
add_file_log(int loglevelMin, int loglevelMax, const char *filename)
{ {
FILE *f; FILE *f;
f = fopen(filename, "a"); f = fopen(filename, "a");
@ -439,7 +459,8 @@ int add_file_log(int loglevelMin, int loglevelMax, const char *filename)
/** /**
* Add a log handler to send messages to they system log facility. * Add a log handler to send messages to they system log facility.
*/ */
int add_syslog_log(int loglevelMin, int loglevelMax) int
add_syslog_log(int loglevelMin, int loglevelMax)
{ {
logfile_t *lf; logfile_t *lf;
if (syslog_count++ == 0) if (syslog_count++ == 0)
@ -459,7 +480,9 @@ int add_syslog_log(int loglevelMin, int loglevelMax)
/** If <b>level</b> is a valid log severity, return the corresponding /** If <b>level</b> is a valid log severity, return the corresponding
* numeric value. Otherwise, return -1. */ * numeric value. Otherwise, return -1. */
int parse_log_level(const char *level) { int
parse_log_level(const char *level)
{
if (!strcasecmp(level, "err")) if (!strcasecmp(level, "err"))
return LOG_ERR; return LOG_ERR;
if (!strcasecmp(level, "warn")) if (!strcasecmp(level, "warn"))
@ -474,13 +497,15 @@ int parse_log_level(const char *level) {
} }
/** Return the string equivalent of a given log level. */ /** Return the string equivalent of a given log level. */
const char *log_level_to_string(int level) const char *
log_level_to_string(int level)
{ {
return sev_to_string(level); return sev_to_string(level);
} }
/** Return the least severe log level that any current log is interested in. */ /** Return the least severe log level that any current log is interested in. */
int get_min_log_level(void) int
get_min_log_level(void)
{ {
logfile_t *lf; logfile_t *lf;
int min = LOG_ERR; int min = LOG_ERR;
@ -492,7 +517,8 @@ int get_min_log_level(void)
} }
/** Switch all logs to output at most verbose level. */ /** Switch all logs to output at most verbose level. */
void switch_logs_debug(void) void
switch_logs_debug(void)
{ {
logfile_t *lf; logfile_t *lf;
for (lf = logfiles; lf; lf=lf->next) { for (lf = logfiles; lf; lf=lf->next) {
@ -531,16 +557,24 @@ libevent_logging_callback(int severity, const char *msg)
break; break;
} }
} }
void configure_libevent_logging(void) void
configure_libevent_logging(void)
{ {
event_set_log_callback(libevent_logging_callback); event_set_log_callback(libevent_logging_callback);
} }
void suppress_libevent_log_msg(const char *msg) void
suppress_libevent_log_msg(const char *msg)
{ {
suppress_msg = msg; suppress_msg = msg;
} }
#else #else
void configure_libevent_logging(void) {} void
void suppress_libevent_log_msg(const char *msg) {} configure_libevent_logging(void)
{
}
void
suppress_libevent_log_msg(const char *msg)
{
}
#endif #endif

View File

@ -253,7 +253,8 @@ tor_gzip_uncompress(char **out, size_t *out_len,
* to be compressed or not. If it is, return the likeliest compression method. * to be compressed or not. If it is, return the likeliest compression method.
* Otherwise, return 0. * Otherwise, return 0.
*/ */
int detect_compression_method(const char *in, size_t in_len) int
detect_compression_method(const char *in, size_t in_len)
{ {
if (in_len > 2 && !memcmp(in, "\x1f\x8b", 2)) { if (in_len > 2 && !memcmp(in, "\x1f\x8b", 2)) {
return GZIP_METHOD; return GZIP_METHOD;

View File

@ -174,7 +174,8 @@ tor_tls_free_all(void)
* it: We always accept peer certs and complete the handshake. We * it: We always accept peer certs and complete the handshake. We
* don't validate them until later. * don't validate them until later.
*/ */
static int always_accept_verify_cb(int preverify_ok, static int
always_accept_verify_cb(int preverify_ok,
X509_STORE_CTX *x509_ctx) X509_STORE_CTX *x509_ctx)
{ {
/* avoid "unused parameter" warning. */ /* avoid "unused parameter" warning. */
@ -672,7 +673,8 @@ tor_tls_get_peer_cert_nickname(tor_tls *tls, char *buf, size_t buflen)
return r; return r;
} }
static void log_cert_lifetime(X509 *cert, const char *problem) static void
log_cert_lifetime(X509 *cert, const char *problem)
{ {
BIO *bio = NULL; BIO *bio = NULL;
BUF_MEM *buf; BUF_MEM *buf;
@ -842,13 +844,15 @@ tor_tls_get_pending_bytes(tor_tls *tls)
} }
/** Return the number of bytes read across the underlying socket. */ /** Return the number of bytes read across the underlying socket. */
unsigned long tor_tls_get_n_bytes_read(tor_tls *tls) unsigned long
tor_tls_get_n_bytes_read(tor_tls *tls)
{ {
tor_assert(tls); tor_assert(tls);
return BIO_number_read(SSL_get_rbio(tls->ssl)); return BIO_number_read(SSL_get_rbio(tls->ssl));
} }
/** Return the number of bytes written across the underlying socket. */ /** Return the number of bytes written across the underlying socket. */
unsigned long tor_tls_get_n_bytes_written(tor_tls *tls) unsigned long
tor_tls_get_n_bytes_written(tor_tls *tls)
{ {
tor_assert(tls); tor_assert(tls);
return BIO_number_written(SSL_get_wbio(tls->ssl)); return BIO_number_written(SSL_get_wbio(tls->ssl));
@ -856,7 +860,8 @@ unsigned long tor_tls_get_n_bytes_written(tor_tls *tls)
/** Implement check_no_tls_errors: If there are any pending OpenSSL /** Implement check_no_tls_errors: If there are any pending OpenSSL
* errors, log an error message and assert(0). */ * errors, log an error message and assert(0). */
void _check_no_tls_errors(const char *fname, int line) void
_check_no_tls_errors(const char *fname, int line)
{ {
if (ERR_peek_error() == 0) if (ERR_peek_error() == 0)
return; return;

View File

@ -139,7 +139,9 @@ void *_tor_malloc(DMALLOC_PARAMS size_t size)
* zero bytes, and return a pointer to the result. Log and terminate * zero bytes, and return a pointer to the result. Log and terminate
* the process on error. (Same as calloc(size,1), but never returns NULL.) * the process on error. (Same as calloc(size,1), but never returns NULL.)
*/ */
void *_tor_malloc_zero(DMALLOC_PARAMS size_t size) { void *
_tor_malloc_zero(DMALLOC_PARAMS size_t size)
{
void *result = _tor_malloc(DMALLOC_FN_ARGS size); void *result = _tor_malloc(DMALLOC_FN_ARGS size);
memset(result, 0, size); memset(result, 0, size);
return result; return result;
@ -149,7 +151,9 @@ void *_tor_malloc_zero(DMALLOC_PARAMS size_t size) {
* bytes long; return the new memory block. On error, log and * bytes long; return the new memory block. On error, log and
* terminate. (Like realloc(ptr,size), but never returns NULL.) * terminate. (Like realloc(ptr,size), but never returns NULL.)
*/ */
void *_tor_realloc(DMALLOC_PARAMS void *ptr, size_t size) { void *
_tor_realloc(DMALLOC_PARAMS void *ptr, size_t size)
{
void *result; void *result;
result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0); result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
@ -164,7 +168,9 @@ void *_tor_realloc(DMALLOC_PARAMS void *ptr, size_t size) {
* error, log and terminate. (Like strdup(s), but never returns * error, log and terminate. (Like strdup(s), but never returns
* NULL.) * NULL.)
*/ */
char *_tor_strdup(DMALLOC_PARAMS const char *s) { char *
_tor_strdup(DMALLOC_PARAMS const char *s)
{
char *dup; char *dup;
tor_assert(s); tor_assert(s);
@ -182,7 +188,9 @@ char *_tor_strdup(DMALLOC_PARAMS const char *s) {
* always NUL-terminated. (Like strndup(s,n), but never returns * always NUL-terminated. (Like strndup(s,n), but never returns
* NULL.) * NULL.)
*/ */
char *_tor_strndup(DMALLOC_PARAMS const char *s, size_t n) { char *
_tor_strndup(DMALLOC_PARAMS const char *s, size_t n)
{
char *dup; char *dup;
tor_assert(s); tor_assert(s);
dup = _tor_malloc(DMALLOC_FN_ARGS n+1); dup = _tor_malloc(DMALLOC_FN_ARGS n+1);
@ -201,7 +209,8 @@ char *_tor_strndup(DMALLOC_PARAMS const char *s, size_t n) {
/** Remove from the string <b>s</b> every character which appears in /** Remove from the string <b>s</b> every character which appears in
* <b>strip</b>. Return the number of characters removed. */ * <b>strip</b>. Return the number of characters removed. */
int tor_strstrip(char *s, const char *strip) int
tor_strstrip(char *s, const char *strip)
{ {
char *read = s; char *read = s;
while (*read) { while (*read) {
@ -226,7 +235,8 @@ int tor_strstrip(char *s, const char *strip)
* If <b>rule</b> is TERMINATE_IF_EVEN, then end the string with <b>insert</b> * If <b>rule</b> is TERMINATE_IF_EVEN, then end the string with <b>insert</b>
* exactly when its length <i>is</i> a multiple of <b>n</b>. * exactly when its length <i>is</i> a multiple of <b>n</b>.
*/ */
int tor_strpartition(char *dest, size_t dest_len, int
tor_strpartition(char *dest, size_t dest_len,
const char *s, const char *insert, size_t n, const char *s, const char *insert, size_t n,
part_finish_rule_t rule) part_finish_rule_t rule)
{ {
@ -283,7 +293,8 @@ int tor_strpartition(char *dest, size_t dest_len,
* result does not need to be deallocated, but repeated calls to * result does not need to be deallocated, but repeated calls to
* hex_str will trash old results. * hex_str will trash old results.
*/ */
const char *hex_str(const char *from, size_t fromlen) const char *
hex_str(const char *from, size_t fromlen)
{ {
static char buf[65]; static char buf[65];
if (fromlen>(sizeof(buf)-1)/2) if (fromlen>(sizeof(buf)-1)/2)
@ -294,7 +305,8 @@ const char *hex_str(const char *from, size_t fromlen)
/** Convert all alphabetic characters in the nul-terminated string <b>s</b> to /** Convert all alphabetic characters in the nul-terminated string <b>s</b> to
* lowercase. */ * lowercase. */
void tor_strlower(char *s) void
tor_strlower(char *s)
{ {
while (*s) { while (*s) {
*s = tolower(*s); *s = tolower(*s);
@ -304,7 +316,8 @@ void tor_strlower(char *s)
/** Convert all alphabetic characters in the nul-terminated string <b>s</b> to /** Convert all alphabetic characters in the nul-terminated string <b>s</b> to
* lowercase. */ * lowercase. */
void tor_strupper(char *s) void
tor_strupper(char *s)
{ {
while (*s) { while (*s) {
*s = toupper(*s); *s = toupper(*s);
@ -315,7 +328,8 @@ void tor_strupper(char *s)
/* Compares the first strlen(s2) characters of s1 with s2. Returns as for /* Compares the first strlen(s2) characters of s1 with s2. Returns as for
* strcmp. * strcmp.
*/ */
int strcmpstart(const char *s1, const char *s2) int
strcmpstart(const char *s1, const char *s2)
{ {
size_t n = strlen(s2); size_t n = strlen(s2);
return strncmp(s1, s2, n); return strncmp(s1, s2, n);
@ -324,7 +338,8 @@ int strcmpstart(const char *s1, const char *s2)
/* Compares the first strlen(s2) characters of s1 with s2. Returns as for /* Compares the first strlen(s2) characters of s1 with s2. Returns as for
* strcasecmp. * strcasecmp.
*/ */
int strcasecmpstart(const char *s1, const char *s2) int
strcasecmpstart(const char *s1, const char *s2)
{ {
size_t n = strlen(s2); size_t n = strlen(s2);
return strncasecmp(s1, s2, n); return strncasecmp(s1, s2, n);
@ -333,7 +348,8 @@ int strcasecmpstart(const char *s1, const char *s2)
/* Compares the last strlen(s2) characters of s1 with s2. Returns as for /* Compares the last strlen(s2) characters of s1 with s2. Returns as for
* strcmp. * strcmp.
*/ */
int strcmpend(const char *s1, const char *s2) int
strcmpend(const char *s1, const char *s2)
{ {
size_t n1 = strlen(s1), n2 = strlen(s2); size_t n1 = strlen(s1), n2 = strlen(s2);
if (n2>n1) if (n2>n1)
@ -345,7 +361,8 @@ int strcmpend(const char *s1, const char *s2)
/* Compares the last strlen(s2) characters of s1 with s2. Returns as for /* Compares the last strlen(s2) characters of s1 with s2. Returns as for
* strcasecmp. * strcasecmp.
*/ */
int strcasecmpend(const char *s1, const char *s2) int
strcasecmpend(const char *s1, const char *s2)
{ {
size_t n1 = strlen(s1), n2 = strlen(s2); size_t n1 = strlen(s1), n2 = strlen(s2);
if (n2>n1) /* then they can't be the same; figure out which is bigger */ if (n2>n1) /* then they can't be the same; figure out which is bigger */
@ -357,7 +374,9 @@ int strcasecmpend(const char *s1, const char *s2)
/** Return a pointer to the first char of s that is not whitespace and /** Return a pointer to the first char of s that is not whitespace and
* not a comment, or to the terminating NUL if no such character exists. * not a comment, or to the terminating NUL if no such character exists.
*/ */
const char *eat_whitespace(const char *s) { const char *
eat_whitespace(const char *s)
{
tor_assert(s); tor_assert(s);
while (TOR_ISSPACE(*s) || *s == '#') { while (TOR_ISSPACE(*s) || *s == '#') {
@ -375,7 +394,9 @@ const char *eat_whitespace(const char *s) {
/** Return a pointer to the first char of s that is not a space or a tab, /** Return a pointer to the first char of s that is not a space or a tab,
* or to the terminating NUL if no such character exists. */ * or to the terminating NUL if no such character exists. */
const char *eat_whitespace_no_nl(const char *s) { const char *
eat_whitespace_no_nl(const char *s)
{
while (*s == ' ' || *s == '\t') while (*s == ' ' || *s == '\t')
++s; ++s;
return s; return s;
@ -384,7 +405,9 @@ const char *eat_whitespace_no_nl(const char *s) {
/** Return a pointer to the first char of s that is whitespace or <b>#</b>, /** Return a pointer to the first char of s that is whitespace or <b>#</b>,
* or to the terminating NUL if no such character exists. * or to the terminating NUL if no such character exists.
*/ */
const char *find_whitespace(const char *s) { const char *
find_whitespace(const char *s)
{
tor_assert(s); tor_assert(s);
while (*s && !TOR_ISSPACE(*s) && *s != '#') while (*s && !TOR_ISSPACE(*s) && *s != '#')
@ -470,7 +493,8 @@ tor_parse_uint64(const char *s, int base, uint64_t min,
CHECK_STRTOX_RESULT(); CHECK_STRTOX_RESULT();
} }
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen) void
base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
{ {
const char *end; const char *end;
char *cp; char *cp;
@ -490,7 +514,8 @@ void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
static const char HEX_DIGITS[] = "0123456789ABCDEFabcdef"; static const char HEX_DIGITS[] = "0123456789ABCDEFabcdef";
static INLINE int hex_decode_digit(char c) static INLINE int
hex_decode_digit(char c)
{ {
const char *cp; const char *cp;
int n; int n;
@ -504,7 +529,8 @@ static INLINE int hex_decode_digit(char c)
return n-6; /* lowercase */ return n-6; /* lowercase */
} }
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen) int
base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
{ {
const char *end; const char *end;
int v1,v2; int v1,v2;
@ -548,7 +574,9 @@ tv_udiff(struct timeval *start, struct timeval *end)
/** Return -1 if *a \< *b, 0 if *a==*b, and 1 if *a \> *b. /** Return -1 if *a \< *b, 0 if *a==*b, and 1 if *a \> *b.
*/ */
int tv_cmp(struct timeval *a, struct timeval *b) { int
tv_cmp(struct timeval *a, struct timeval *b)
{
if (a->tv_sec > b->tv_sec) if (a->tv_sec > b->tv_sec)
return 1; return 1;
if (a->tv_sec < b->tv_sec) if (a->tv_sec < b->tv_sec)
@ -562,7 +590,9 @@ int tv_cmp(struct timeval *a, struct timeval *b) {
/** Increment *a by the number of seconds and microseconds in *b. /** Increment *a by the number of seconds and microseconds in *b.
*/ */
void tv_add(struct timeval *a, struct timeval *b) { void
tv_add(struct timeval *a, struct timeval *b)
{
a->tv_usec += b->tv_usec; a->tv_usec += b->tv_usec;
a->tv_sec += b->tv_sec + (a->tv_usec / 1000000); a->tv_sec += b->tv_sec + (a->tv_usec / 1000000);
a->tv_usec %= 1000000; a->tv_usec %= 1000000;
@ -570,14 +600,18 @@ void tv_add(struct timeval *a, struct timeval *b) {
/** Increment *a by <b>ms</b> milliseconds. /** Increment *a by <b>ms</b> milliseconds.
*/ */
void tv_addms(struct timeval *a, long ms) { void
tv_addms(struct timeval *a, long ms)
{
a->tv_usec += (ms * 1000) % 1000000; a->tv_usec += (ms * 1000) % 1000000;
a->tv_sec += ((ms * 1000) / 1000000) + (a->tv_usec / 1000000); a->tv_sec += ((ms * 1000) / 1000000) + (a->tv_usec / 1000000);
a->tv_usec %= 1000000; a->tv_usec %= 1000000;
} }
#define IS_LEAPYEAR(y) (!(y % 4) && ((y % 100) || !(y % 400))) #define IS_LEAPYEAR(y) (!(y % 4) && ((y % 100) || !(y % 400)))
static int n_leapdays(int y1, int y2) { static int
n_leapdays(int y1, int y2)
{
--y1; --y1;
--y2; --y2;
return (y2/4 - y1/4) - (y2/100 - y1/100) + (y2/400 - y1/400); return (y2/4 - y1/4) - (y2/100 - y1/100) + (y2/400 - y1/400);
@ -590,7 +624,8 @@ static const int days_per_month[] =
* does not account for leap seconds. * does not account for leap seconds.
*/ */
time_t time_t
tor_timegm(struct tm *tm) { 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(). * It's way more brute-force than fiddling with tzset().
*/ */
@ -621,7 +656,9 @@ static const char *MONTH_NAMES[] =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
void format_rfc1123_time(char *buf, time_t t) { void
format_rfc1123_time(char *buf, time_t t)
{
struct tm tm; struct tm tm;
tor_gmtime_r(&t, &tm); tor_gmtime_r(&t, &tm);
@ -635,7 +672,9 @@ void format_rfc1123_time(char *buf, time_t t) {
memcpy(buf+8, MONTH_NAMES[tm.tm_mon], 3); memcpy(buf+8, MONTH_NAMES[tm.tm_mon], 3);
} }
int parse_rfc1123_time(const char *buf, time_t *t) { int
parse_rfc1123_time(const char *buf, time_t *t)
{
struct tm tm; struct tm tm;
char month[4]; char month[4];
char weekday[4]; char weekday[4];
@ -669,17 +708,23 @@ int parse_rfc1123_time(const char *buf, time_t *t) {
return 0; return 0;
} }
void format_local_iso_time(char *buf, time_t t) { void
format_local_iso_time(char *buf, time_t t)
{
struct tm tm; struct tm tm;
strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_localtime_r(&t, &tm)); strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_localtime_r(&t, &tm));
} }
void format_iso_time(char *buf, time_t t) { void
format_iso_time(char *buf, time_t t)
{
struct tm tm; struct tm tm;
strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_gmtime_r(&t, &tm)); strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_gmtime_r(&t, &tm));
} }
int parse_iso_time(const char *cp, time_t *t) { int
parse_iso_time(const char *cp, time_t *t)
{
struct tm st_tm; struct tm st_tm;
#ifdef HAVE_STRPTIME #ifdef HAVE_STRPTIME
if (!strptime(cp, "%Y-%m-%d %H:%M:%S", &st_tm)) { if (!strptime(cp, "%Y-%m-%d %H:%M:%S", &st_tm)) {
@ -715,7 +760,8 @@ int parse_iso_time(const char *cp, time_t *t) {
* was returned by open(). Return the number of bytes written, or -1 * was returned by open(). Return the number of bytes written, or -1
* on error. Only use if fd is a blocking fd. */ * on error. Only use if fd is a blocking fd. */
int int
write_all(int fd, const char *buf, size_t count, int isSocket) { write_all(int fd, const char *buf, size_t count, int isSocket)
{
size_t written = 0; size_t written = 0;
int result; int result;
@ -737,7 +783,8 @@ write_all(int fd, const char *buf, size_t count, int isSocket) {
* open(). Return the number of bytes read, or -1 on error. Only use * open(). Return the number of bytes read, or -1 on error. Only use
* if fd is a blocking fd. */ * if fd is a blocking fd. */
int int
read_all(int fd, char *buf, size_t count, int isSocket) { read_all(int fd, char *buf, size_t count, int isSocket)
{
size_t numread = 0; size_t numread = 0;
int result; int result;
@ -783,7 +830,8 @@ clean_name_for_stat(char *name)
/** Return FN_ERROR if filename can't be read, FN_NOENT if it doesn't /** Return FN_ERROR if filename can't be read, FN_NOENT if it doesn't
* exist, FN_FILE if it is a regular file, or FN_DIR if it's a * exist, FN_FILE if it is a regular file, or FN_DIR if it's a
* directory. */ * directory. */
file_status_t file_status(const char *fname) file_status_t
file_status(const char *fname)
{ {
struct stat st; struct stat st;
char *f; char *f;
@ -811,7 +859,8 @@ file_status_t file_status(const char *fname)
* and return 0 on success. If it does not exist, and * and return 0 on success. If it does not exist, and
* check==CPD_CHECK, and we think we can create it, return 0. Else * check==CPD_CHECK, and we think we can create it, return 0. Else
* return -1. */ * return -1. */
int check_private_dir(const char *dirname, cpd_check_t check) int
check_private_dir(const char *dirname, cpd_check_t check)
{ {
int r; int r;
struct stat st; struct stat st;
@ -988,7 +1037,9 @@ append_bytes_to_file(const char *fname, const char *str, size_t len,
* the call to stat and the call to read_all: the resulting string will * the call to stat and the call to read_all: the resulting string will
* be truncated. * be truncated.
*/ */
char *read_file_to_str(const char *filename, int bin) { char *
read_file_to_str(const char *filename, int bin)
{
int fd; /* router file */ int fd; /* router file */
struct stat statbuf; struct stat statbuf;
char *string, *f; char *string, *f;
@ -1117,7 +1168,8 @@ parse_line_from_str(char *line, char **key_out, char **value_out)
/** Expand any homedir prefix on 'filename'; return a newly allocated /** Expand any homedir prefix on 'filename'; return a newly allocated
* string. */ * string. */
char *expand_filename(const char *filename) char *
expand_filename(const char *filename)
{ {
tor_assert(filename); tor_assert(filename);
if (*filename == '~') { if (*filename == '~') {
@ -1225,8 +1277,9 @@ tor_listdir(const char *dirname)
/** Return true iff <b>ip</b> (in host order) is an IP reserved to localhost, /** Return true iff <b>ip</b> (in host order) is an IP reserved to localhost,
* or reserved for local networks by RFC 1918. * or reserved for local networks by RFC 1918.
*/ */
int is_internal_IP(uint32_t ip) { int
is_internal_IP(uint32_t ip)
{
if (((ip & 0xff000000) == 0x0a000000) || /* 10/8 */ if (((ip & 0xff000000) == 0x0a000000) || /* 10/8 */
((ip & 0xff000000) == 0x00000000) || /* 0/8 */ ((ip & 0xff000000) == 0x00000000) || /* 0/8 */
((ip & 0xff000000) == 0x7f000000) || /* 127/8 */ ((ip & 0xff000000) == 0x7f000000) || /* 127/8 */
@ -1242,7 +1295,9 @@ int is_internal_IP(uint32_t ip) {
* *
* XXX Also check if it's on the same class C network as our public IP. * XXX Also check if it's on the same class C network as our public IP.
*/ */
int is_local_IP(uint32_t ip) { int
is_local_IP(uint32_t ip)
{
return is_internal_IP(ip); return is_internal_IP(ip);
} }
@ -1523,7 +1578,8 @@ static int daemon_filedes[2];
* until finish_daemon is called. (Note: it's safe to call this more * until finish_daemon is called. (Note: it's safe to call this more
* than once: calls after the first are ignored.) * than once: calls after the first are ignored.)
*/ */
void start_daemon(void) void
start_daemon(void)
{ {
pid_t pid; pid_t pid;
@ -1574,7 +1630,8 @@ void start_daemon(void)
* calls after the first are ignored. Calls start_daemon first if it hasn't * calls after the first are ignored. Calls start_daemon first if it hasn't
* been called already.) * been called already.)
*/ */
void finish_daemon(const char *desired_cwd) void
finish_daemon(const char *desired_cwd)
{ {
int nullfd; int nullfd;
char c = '.'; char c = '.';
@ -1615,13 +1672,21 @@ void finish_daemon(const char *desired_cwd)
} }
#else #else
/* defined(MS_WINDOWS) */ /* defined(MS_WINDOWS) */
void start_daemon(void) {} void
void finish_daemon(const char *cp) {} start_daemon(void)
{
}
void
finish_daemon(const char *cp)
{
}
#endif #endif
/** Write the current process ID, followed by NL, into <b>filename</b>. /** Write the current process ID, followed by NL, into <b>filename</b>.
*/ */
void write_pidfile(char *filename) { void
write_pidfile(char *filename)
{
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
FILE *pidfile; FILE *pidfile;

View File

@ -289,7 +289,8 @@ buf_shrink(buf_t *buf)
/** Remove the first <b>n</b> bytes from buf. */ /** Remove the first <b>n</b> bytes from buf. */
static INLINE void static INLINE void
buf_remove_from_front(buf_t *buf, size_t n) { buf_remove_from_front(buf_t *buf, size_t n)
{
tor_assert(buf->datalen >= n); tor_assert(buf->datalen >= n);
buf->datalen -= n; buf->datalen -= n;
buf_total_used -= n; buf_total_used -= n;
@ -313,7 +314,8 @@ buf_nul_terminate(buf_t *buf)
/** Create and return a new buf with capacity <b>size</b>. */ /** Create and return a new buf with capacity <b>size</b>. */
buf_t * buf_t *
buf_new_with_capacity(size_t size) { buf_new_with_capacity(size_t size)
{
buf_t *buf; buf_t *buf;
buf = tor_malloc_zero(sizeof(buf_t)); buf = tor_malloc_zero(sizeof(buf_t));
buf->magic = BUFFER_MAGIC; buf->magic = BUFFER_MAGIC;
@ -646,7 +648,8 @@ flush_buf_tls_impl(tor_tls *tls, buf_t *buf, size_t sz, size_t *buf_flushlen)
/** As flush_buf(), but writes data to a TLS connection. /** As flush_buf(), but writes data to a TLS connection.
*/ */
int flush_buf_tls(tor_tls *tls, buf_t *buf, size_t *buf_flushlen) int
flush_buf_tls(tor_tls *tls, buf_t *buf, size_t *buf_flushlen)
{ {
int r; int r;
size_t flushed=0; size_t flushed=0;
@ -1198,7 +1201,8 @@ fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len)
/** Log an error and exit if <b>buf</b> is corrupted. /** Log an error and exit if <b>buf</b> is corrupted.
*/ */
void assert_buf_ok(buf_t *buf) void
assert_buf_ok(buf_t *buf)
{ {
tor_assert(buf); tor_assert(buf);
tor_assert(buf->magic == BUFFER_MAGIC); tor_assert(buf->magic == BUFFER_MAGIC);

View File

@ -178,7 +178,8 @@ _circuit_get_global_list(void)
/** Function to make circ-\>state human-readable */ /** Function to make circ-\>state human-readable */
const char * const char *
circuit_state_to_string(int state) { circuit_state_to_string(int state)
{
static char buf[64]; static char buf[64];
switch (state) { switch (state) {
case CIRCUIT_STATE_BUILDING: return "doing handshakes"; case CIRCUIT_STATE_BUILDING: return "doing handshakes";

View File

@ -585,7 +585,8 @@ circuit_testing_opened(circuit_t *circ)
/** A testing circuit has failed to build. Take whatever stats we want. */ /** A testing circuit has failed to build. Take whatever stats we want. */
static void static void
circuit_testing_failed(circuit_t *circ, int at_last_hop) { circuit_testing_failed(circuit_t *circ, int at_last_hop)
{
#if 0 #if 0
routerinfo_t *me = router_get_my_routerinfo(); routerinfo_t *me = router_get_my_routerinfo();

View File

@ -3154,7 +3154,8 @@ config_parse_units(const char *val, struct unit_table_t *u, int *ok)
* and return the number of bytes specified. Otherwise, set * and return the number of bytes specified. Otherwise, set
* *<b>ok</b> to false and return 0. */ * *<b>ok</b> to false and return 0. */
static uint64_t static uint64_t
config_parse_memunit(const char *s, int *ok) { config_parse_memunit(const char *s, int *ok)
{
return config_parse_units(s, memory_units, ok); return config_parse_units(s, memory_units, ok);
} }
@ -3163,7 +3164,8 @@ config_parse_memunit(const char *s, int *ok) {
* the provided interval. Otherwise, set *<b>ok</b> to 0 and return -1. * the provided interval. Otherwise, set *<b>ok</b> to 0 and return -1.
*/ */
static int static int
config_parse_interval(const char *s, int *ok) { config_parse_interval(const char *s, int *ok)
{
uint64_t r; uint64_t r;
r = config_parse_units(s, time_units, ok); r = config_parse_units(s, time_units, ok);
if (!ok) if (!ok)

View File

@ -1637,7 +1637,8 @@ connection_get_by_type_state_lastwritten(int type, int state)
* is non-zero, conn must be of that state too. * is non-zero, conn must be of that state too.
*/ */
connection_t * connection_t *
connection_get_by_type_state_rendquery(int type, int state, const char *rendquery) { connection_get_by_type_state_rendquery(int type, int state, const char *rendquery)
{
int i, n; int i, n;
connection_t *conn; connection_t *conn;
connection_t **carray; connection_t **carray;

View File

@ -1122,7 +1122,8 @@ connection_dir_reached_eof(connection_t *conn)
/** Read handler for directory connections. (That's connections <em>to</em> /** Read handler for directory connections. (That's connections <em>to</em>
* directory servers and connections <em>at</em> directory servers.) * directory servers and connections <em>at</em> directory servers.)
*/ */
int connection_dir_process_inbuf(connection_t *conn) int
connection_dir_process_inbuf(connection_t *conn)
{ {
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_DIR); tor_assert(conn->type == CONN_TYPE_DIR);

View File

@ -50,7 +50,8 @@ static addr_policy_t *authdir_invalid_policy = NULL;
/** Parse authdir policy strings from the configuration. /** Parse authdir policy strings from the configuration.
*/ */
void void
parse_authdir_policy(void) { parse_authdir_policy(void)
{
addr_policy_t *n; addr_policy_t *n;
if (authdir_reject_policy) { if (authdir_reject_policy) {
addr_policy_free(authdir_reject_policy); addr_policy_free(authdir_reject_policy);

View File

@ -81,8 +81,10 @@ static SPLAY_HEAD(cache_tree, cached_resolve_t) cache_root;
/** Function to compare hashed resolves on their addresses; used to /** Function to compare hashed resolves on their addresses; used to
* implement splay trees. */ * implement splay trees. */
static int compare_cached_resolves(cached_resolve_t *a, static int
cached_resolve_t *b) { compare_cached_resolves(cached_resolve_t *a,
cached_resolve_t *b)
{
/* make this smarter one day? */ /* make this smarter one day? */
return strncmp(a->address, b->address, MAX_ADDRESSLEN); return strncmp(a->address, b->address, MAX_ADDRESSLEN);
} }

View File

@ -1377,7 +1377,8 @@ tor_free_all(int postfork)
/** Do whatever cleanup is necessary before shutting Tor down. */ /** Do whatever cleanup is necessary before shutting Tor down. */
void void
tor_cleanup(void) { tor_cleanup(void)
{
or_options_t *options = get_options(); or_options_t *options = get_options();
/* Remove our pid file. We don't care if there was an error when we /* Remove our pid file. We don't care if there was an error when we
* unlink, nothing we could do about it anyways. */ * unlink, nothing we could do about it anyways. */
@ -1442,7 +1443,8 @@ do_hash_password(void)
/** Checks if torrc is present in the same directory /** Checks if torrc is present in the same directory
* as the service executable. * as the service executable.
* Return 1 if it is, 0 if it is not present. */ * Return 1 if it is, 0 if it is not present. */
static int nt_torrc_is_present() static int
nt_torrc_is_present()
{ {
HANDLE hFile; HANDLE hFile;
TCHAR szPath[_MAX_PATH]; TCHAR szPath[_MAX_PATH];

View File

@ -12,13 +12,16 @@ const char rendcommon_c_id[] = "$Id$";
#include "or.h" #include "or.h"
/** Return 0 if one and two are the same service ids, else -1 or 1 */ /** Return 0 if one and two are the same service ids, else -1 or 1 */
int rend_cmp_service_ids(const char *one, const char *two) { int
rend_cmp_service_ids(const char *one, const char *two)
{
return strcasecmp(one,two); return strcasecmp(one,two);
} }
/** Free the storage held by the service descriptor <b>desc</b>. /** Free the storage held by the service descriptor <b>desc</b>.
*/ */
void rend_service_descriptor_free(rend_service_descriptor_t *desc) void
rend_service_descriptor_free(rend_service_descriptor_t *desc)
{ {
int i; int i;
if (desc->pk) if (desc->pk)

View File

@ -62,7 +62,9 @@ typedef struct rend_service_t {
static smartlist_t *rend_service_list = NULL; static smartlist_t *rend_service_list = NULL;
/** Return the number of rendezvous services we have configured. */ /** Return the number of rendezvous services we have configured. */
int num_rend_services(void) { int
num_rend_services(void)
{
if (!rend_service_list) if (!rend_service_list)
return 0; return 0;
return smartlist_len(rend_service_list); return smartlist_len(rend_service_list);
@ -374,7 +376,8 @@ rend_service_get_by_pk_digest(const char* digest)
* to have good uptime. Else return 0. * to have good uptime. Else return 0.
*/ */
static int static int
rend_service_requires_uptime(rend_service_t *service) { rend_service_requires_uptime(rend_service_t *service)
{
int i; int i;
rend_service_port_config_t *p; rend_service_port_config_t *p;

View File

@ -766,8 +766,15 @@ rep_hist_get_predicted_hidserv(time_t now, int *need_uptime, int *need_capacity)
} }
/* not used yet */ /* not used yet */
void rep_hist_note_used_resolve(time_t now) { } void
int rep_hist_get_predicted_resolve(time_t now) { return 0; } rep_hist_note_used_resolve(time_t now)
{
}
int
rep_hist_get_predicted_resolve(time_t now)
{
return 0;
}
/** Free all storage held by the OR/link history caches, by the /** Free all storage held by the OR/link history caches, by the
* bandwidth history arrays, or by the port history. */ * bandwidth history arrays, or by the port history. */