Commit 4d428cd2 authored by Rich Salz's avatar Rich Salz
Browse files

Dead code removal: #if 0 bio, comp, rand



The start of removing dead code.
A remaining #if 0 in bss_conn.c needs more thought.

Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
parent 33fc38ff
Loading
Loading
Loading
Loading
+2 −218
Original line number Diff line number Diff line
@@ -94,23 +94,7 @@ static int wsa_init_done = 0;
#  define WSAAPI
# endif

# if 0
static unsigned long BIO_ghbn_hits = 0L;
static unsigned long BIO_ghbn_miss = 0L;

#  define GHBN_NUM        4
static struct ghbn_cache_st {
    char name[129];
    struct hostent *ent;
    unsigned long order;
} ghbn_cache[GHBN_NUM];
# endif

static int get_ip(const char *str, unsigned char *ip);
# if 0
static void ghbn_free(struct hostent *a);
static struct hostent *ghbn_dup(struct hostent *a);
# endif
int BIO_get_host_ip(const char *str, unsigned char *ip)
{
    int i;
@@ -207,10 +191,6 @@ int BIO_get_port(const char *str, unsigned short *port_ptr)
                *port_ptr = 21;
            else if (strcmp(str, "gopher") == 0)
                *port_ptr = 70;
# if 0
            else if (strcmp(str, "wais") == 0)
                *port_ptr = 21;
# endif
            else {
                SYSerr(SYS_F_GETSERVBYNAME, get_last_socket_error());
                ERR_add_error_data(3, "service='", str, "'");
@@ -244,124 +224,8 @@ int BIO_sock_error(int sock)
        return (j);
}

# if 0
long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
{
    int i;
    char **p;

    switch (cmd) {
    case BIO_GHBN_CTRL_HITS:
        return (BIO_ghbn_hits);
        /* break; */
    case BIO_GHBN_CTRL_MISSES:
        return (BIO_ghbn_miss);
        /* break; */
    case BIO_GHBN_CTRL_CACHE_SIZE:
        return (GHBN_NUM);
        /* break; */
    case BIO_GHBN_CTRL_GET_ENTRY:
        if ((iarg >= 0) && (iarg < GHBN_NUM) && (ghbn_cache[iarg].order > 0)) {
            p = (char **)parg;
            if (p == NULL)
                return (0);
            *p = ghbn_cache[iarg].name;
            ghbn_cache[iarg].name[128] = '\0';
            return (1);
        }
        return (0);
        /* break; */
    case BIO_GHBN_CTRL_FLUSH:
        for (i = 0; i < GHBN_NUM; i++)
            ghbn_cache[i].order = 0;
        break;
    default:
        return (0);
    }
    return (1);
}
# endif

# if 0
static struct hostent *ghbn_dup(struct hostent *a)
{
    struct hostent *ret;
    int i, j;

    MemCheck_off();
    ret = (struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
    if (ret == NULL)
        return (NULL);
    memset(ret, 0, sizeof(struct hostent));

    for (i = 0; a->h_aliases[i] != NULL; i++) ;
    i++;
    ret->h_aliases = (char **)OPENSSL_malloc(i * sizeof(char *));
    if (ret->h_aliases == NULL)
        goto err;
    memset(ret->h_aliases, 0, i * sizeof(char *));

    for (i = 0; a->h_addr_list[i] != NULL; i++) ;
    i++;
    ret->h_addr_list = (char **)OPENSSL_malloc(i * sizeof(char *));
    if (ret->h_addr_list == NULL)
        goto err;
    memset(ret->h_addr_list, 0, i * sizeof(char *));

    j = strlen(a->h_name) + 1;
    if ((ret->h_name = OPENSSL_malloc(j)) == NULL)
        goto err;
    memcpy((char *)ret->h_name, a->h_name, j);
    for (i = 0; a->h_aliases[i] != NULL; i++) {
        j = strlen(a->h_aliases[i]) + 1;
        if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL)
            goto err;
        memcpy(ret->h_aliases[i], a->h_aliases[i], j);
    }
    ret->h_length = a->h_length;
    ret->h_addrtype = a->h_addrtype;
    for (i = 0; a->h_addr_list[i] != NULL; i++) {
        if ((ret->h_addr_list[i] = OPENSSL_malloc(a->h_length)) == NULL)
            goto err;
        memcpy(ret->h_addr_list[i], a->h_addr_list[i], a->h_length);
    }
    if (0) {
 err:
        if (ret != NULL)
            ghbn_free(ret);
        ret = NULL;
    }
    MemCheck_on();
    return (ret);
}

static void ghbn_free(struct hostent *a)
{
    int i;

    if (a == NULL)
        return;

    if (a->h_aliases != NULL) {
        for (i = 0; a->h_aliases[i] != NULL; i++)
            OPENSSL_free(a->h_aliases[i]);
        OPENSSL_free(a->h_aliases);
    }
    if (a->h_addr_list != NULL) {
        for (i = 0; a->h_addr_list[i] != NULL; i++)
            OPENSSL_free(a->h_addr_list[i]);
        OPENSSL_free(a->h_addr_list);
    }
    if (a->h_name != NULL)
        OPENSSL_free(a->h_name);
    OPENSSL_free(a);
}

# endif

struct hostent *BIO_gethostbyname(const char *name)
{
# if 1
    /*
     * Caching gethostbyname() results forever is wrong, so we have to let
     * the true gethostbyname() worry about this
@@ -371,82 +235,6 @@ struct hostent *BIO_gethostbyname(const char *name)
# else
    return gethostbyname(name);
# endif
# else
    struct hostent *ret;
    int i, lowi = 0, j;
    unsigned long low = (unsigned long)-1;

#  if 0
    /*
     * It doesn't make sense to use locking here: The function interface is
     * not thread-safe, because threads can never be sure when some other
     * thread destroys the data they were given a pointer to.
     */
    CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
#  endif
    j = strlen(name);
    if (j < 128) {
        for (i = 0; i < GHBN_NUM; i++) {
            if (low > ghbn_cache[i].order) {
                low = ghbn_cache[i].order;
                lowi = i;
            }
            if (ghbn_cache[i].order > 0) {
                if (strncmp(name, ghbn_cache[i].name, 128) == 0)
                    break;
            }
        }
    } else
        i = GHBN_NUM;

    if (i == GHBN_NUM) {        /* no hit */
        BIO_ghbn_miss++;
        /*
         * Note: under VMS with SOCKETSHR, it seems like the first parameter
         * is 'char *', instead of 'const char *'
         */
#  ifndef CONST_STRICT
        ret = gethostbyname((char *)name);
#  else
        ret = gethostbyname(name);
#  endif

        if (ret == NULL)
            goto end;
        if (j > 128) {          /* too big to cache */
#  if 0
            /*
             * If we were trying to make this function thread-safe (which is
             * bound to fail), we'd have to give up in this case (or allocate
             * more memory).
             */
            ret = NULL;
#  endif
            goto end;
        }

        /* else add to cache */
        if (ghbn_cache[lowi].ent != NULL)
            ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
        ghbn_cache[lowi].name[0] = '\0';

        if ((ret = ghbn_cache[lowi].ent = ghbn_dup(ret)) == NULL) {
            BIOerr(BIO_F_BIO_GETHOSTBYNAME, ERR_R_MALLOC_FAILURE);
            goto end;
        }
        strncpy(ghbn_cache[lowi].name, name, 128);
        ghbn_cache[lowi].order = BIO_ghbn_miss + BIO_ghbn_hits;
    } else {
        BIO_ghbn_hits++;
        ret = ghbn_cache[i].ent;
        ghbn_cache[i].order = BIO_ghbn_miss + BIO_ghbn_hits;
    }
 end:
#  if 0
    CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
#  endif
    return (ret);
# endif
}

int BIO_sock_init(void)
@@ -505,10 +293,6 @@ void BIO_sock_cleanup(void)
# ifdef OPENSSL_SYS_WINDOWS
    if (wsa_init_done) {
        wsa_init_done = 0;
#  if 0                         /* this call is claimed to be non-present in
                                 * Winsock2 */
        WSACancelBlockingCall();
#  endif
        WSACleanup();
    }
# elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
+0 −4
Original line number Diff line number Diff line
@@ -414,10 +414,6 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
            if (ctx->obuf_len > 0) {
                r = BIO_write(b->next_bio,
                              &(ctx->obuf[ctx->obuf_off]), ctx->obuf_len);
#if 0
                fprintf(stderr, "FLUSH [%3d] %3d -> %3d\n", ctx->obuf_off,
                        ctx->obuf_len, r);
#endif
                BIO_copy_next_retry(b);
                if (r <= 0)
                    return ((long)r);
+0 −21
Original line number Diff line number Diff line
@@ -198,25 +198,16 @@ static int linebuffer_write(BIO *b, const char *in, int inl)
                    num += i;
                }
            }
#if 0
            BIO_write(b->next_bio, "<*<", 3);
#endif
            i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len);
            if (i <= 0) {
                ctx->obuf_len = orig_olen;
                BIO_copy_next_retry(b);

#if 0
                BIO_write(b->next_bio, ">*>", 3);
#endif
                if (i < 0)
                    return ((num > 0) ? num : i);
                if (i == 0)
                    return (num);
            }
#if 0
            BIO_write(b->next_bio, ">*>", 3);
#endif
            if (i < ctx->obuf_len)
                memmove(ctx->obuf, ctx->obuf + i, ctx->obuf_len - i);
            ctx->obuf_len -= i;
@@ -227,23 +218,14 @@ static int linebuffer_write(BIO *b, const char *in, int inl)
         * if a NL was found and there is anything to write.
         */
        if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) {
#if 0
            BIO_write(b->next_bio, "<*<", 3);
#endif
            i = BIO_write(b->next_bio, in, p - in);
            if (i <= 0) {
                BIO_copy_next_retry(b);
#if 0
                BIO_write(b->next_bio, ">*>", 3);
#endif
                if (i < 0)
                    return ((num > 0) ? num : i);
                if (i == 0)
                    return (num);
            }
#if 0
            BIO_write(b->next_bio, ">*>", 3);
#endif
            num += i;
            in += i;
            inl -= i;
@@ -330,9 +312,6 @@ static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
            BIO_clear_retry_flags(b);
            if (ctx->obuf_len > 0) {
                r = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len);
#if 0
                fprintf(stderr, "FLUSH %3d -> %3d\n", ctx->obuf_len, r);
#endif
                BIO_copy_next_retry(b);
                if (r <= 0)
                    return ((long)r);
+10 −32
Original line number Diff line number Diff line
@@ -449,13 +449,6 @@ static int dgram_write(BIO *b, const char *in, int inl)
        if (BIO_dgram_should_retry(ret)) {
            BIO_set_retry_write(b);
            data->_errno = get_last_socket_error();

# if 0                          /* higher layers are responsible for querying
                                 * MTU, if necessary */
            if (data->_errno == EMSGSIZE)
                /* retrieve the new MTU */
                BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
# endif
        }
    }
    return (ret);
@@ -559,12 +552,6 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
        break;
    case BIO_CTRL_DGRAM_CONNECT:
        to = (struct sockaddr *)ptr;
# if 0
        if (connect(b->num, to, sizeof(struct sockaddr)) < 0) {
            perror("connect");
            ret = 0;
        } else {
# endif
        switch (to->sa_family) {
        case AF_INET:
            memcpy(&data->peer, to, sizeof(data->peer.sa_in));
@@ -578,9 +565,6 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
            memcpy(&data->peer, to, sizeof(data->peer.sa));
            break;
        }
# if 0
        }
# endif
        break;
        /* (Linux)kernel sets DF bit on outgoing IP packets */
    case BIO_CTRL_DGRAM_MTU_DISCOVER:
@@ -1992,12 +1976,6 @@ int BIO_dgram_non_fatal_error(int err)
#  if defined(WSAEWOULDBLOCK)
    case WSAEWOULDBLOCK:
#  endif

#  if 0                         /* This appears to always be an error */
#   if defined(WSAENOTCONN)
    case WSAENOTCONN:
#   endif
#  endif
# endif

# ifdef EWOULDBLOCK
+0 −6
Original line number Diff line number Diff line
@@ -233,12 +233,6 @@ int BIO_sock_non_fatal_error(int err)
#  if defined(WSAEWOULDBLOCK)
    case WSAEWOULDBLOCK:
#  endif

#  if 0                         /* This appears to always be an error */
#   if defined(WSAENOTCONN)
    case WSAENOTCONN:
#   endif
#  endif
# endif

# ifdef EWOULDBLOCK
Loading