Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / boringssl / src / ssl / d1_lib.c
index 454236f..96ce496 100644 (file)
@@ -62,6 +62,7 @@
 #include <sys/timeb.h>
 #else
 #include <sys/socket.h>
+#include <sys/time.h>
 #endif
 
 #include <openssl/err.h>
@@ -70,7 +71,8 @@
 
 #include "ssl_locl.h"
 
-static void get_current_time(struct timeval *t);
+static void get_current_time(OPENSSL_timeval *t);
+static OPENSSL_timeval* dtls1_get_timeout(SSL *s, OPENSSL_timeval* timeleft);
 static void dtls1_set_handshake_header(SSL *s, int type, unsigned long len);
 static int dtls1_handshake_write(SSL *s);
 int dtls1_listen(SSL *s, struct sockaddr *client);
@@ -114,13 +116,6 @@ SSL3_ENC_METHOD DTLSv1_2_enc_data={
        dtls1_handshake_write   
        };
 
-long dtls1_default_timeout(void)
-       {
-       /* 2 hours, the 24 hours mentioned in the DTLSv1 spec
-        * is way too long for http, the cache would over fill */
-       return(60*60*2);
-       }
-
 int dtls1_new(SSL *s)
        {
        DTLS1_STATE *d1;
@@ -276,9 +271,7 @@ void dtls1_clear(SSL *s)
                }
 
        ssl3_clear(s);
-       if (s->options & SSL_OP_CISCO_ANYCONNECT)
-               s->version=DTLS1_BAD_VER;
-       else if (s->method->version == DTLS_ANY_VERSION)
+       if (s->method->version == DTLS_ANY_VERSION)
                s->version=DTLS1_2_VERSION;
        else
                s->version=s->method->version;
@@ -291,7 +284,7 @@ long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg)
        switch (cmd)
                {
        case DTLS_CTRL_GET_TIMEOUT:
-               if (dtls1_get_timeout(s, (struct timeval*) parg) != NULL)
+               if (dtls1_get_timeout(s, (OPENSSL_timeval*) parg) != NULL)
                        {
                        ret = 1;
                        }
@@ -339,16 +332,16 @@ void dtls1_start_timer(SSL *s)
                }
        
        /* Set timeout to current time */
-       get_current_time(&(s->d1->next_timeout));
+       get_current_time(&s->d1->next_timeout);
 
        /* Add duration to current time */
        s->d1->next_timeout.tv_sec += s->d1->timeout_duration;
-       BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &(s->d1->next_timeout));
+       BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &s->d1->next_timeout);
        }
 
-struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft)
+static OPENSSL_timeval* dtls1_get_timeout(SSL *s, OPENSSL_timeval* timeleft)
        {
-       struct timeval timenow;
+       OPENSSL_timeval timenow;
 
        /* If no timeout is set, just return NULL */
        if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0)
@@ -364,12 +357,12 @@ struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft)
                (s->d1->next_timeout.tv_sec == timenow.tv_sec &&
                 s->d1->next_timeout.tv_usec <= timenow.tv_usec))
                {
-               memset(timeleft, 0, sizeof(struct timeval));
+               memset(timeleft, 0, sizeof(OPENSSL_timeval));
                return timeleft;
                }
 
        /* Calculate time left until timer expires */
-       memcpy(timeleft, &(s->d1->next_timeout), sizeof(struct timeval));
+       memcpy(timeleft, &s->d1->next_timeout, sizeof(OPENSSL_timeval));
        timeleft->tv_sec -= timenow.tv_sec;
        timeleft->tv_usec -= timenow.tv_usec;
        if (timeleft->tv_usec < 0)
@@ -384,7 +377,7 @@ struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft)
         */
        if (timeleft->tv_sec == 0 && timeleft->tv_usec < 15000)
                {
-               memset(timeleft, 0, sizeof(struct timeval));
+               memset(timeleft, 0, sizeof(OPENSSL_timeval));
                }
        
 
@@ -393,7 +386,7 @@ struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft)
 
 int dtls1_is_timer_expired(SSL *s)
        {
-       struct timeval timeleft;
+       OPENSSL_timeval timeleft;
 
        /* Get time left until timeout, return false if no timer running */
        if (dtls1_get_timeout(s, &timeleft) == NULL)
@@ -423,9 +416,9 @@ void dtls1_stop_timer(SSL *s)
        {
        /* Reset everything */
        memset(&(s->d1->timeout), 0, sizeof(struct dtls1_timeout_st));
-       memset(&(s->d1->next_timeout), 0, sizeof(struct timeval));
+       memset(&s->d1->next_timeout, 0, sizeof(OPENSSL_timeval));
        s->d1->timeout_duration = 1;
-       BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &(s->d1->next_timeout));
+       BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &s->d1->next_timeout);
        /* Clear retransmission buffer */
        dtls1_clear_record_buffer(s);
        }
@@ -473,13 +466,13 @@ int dtls1_handle_timeout(SSL *s)
        return dtls1_retransmit_buffered_messages(s);
        }
 
-static void get_current_time(struct timeval *t)
+static void get_current_time(OPENSSL_timeval *t)
 {
-#ifdef OPENSSL_SYS_WIN32
-       struct _timeb tb;
-       _ftime(&tb);
-       t->tv_sec = (long)tb.time;
-       t->tv_usec = (long)tb.millitm * 1000;
+#if defined(OPENSSL_WINDOWS)
+       struct _timeb time;
+       _ftime(&time);
+       t->tv_sec = time.time;
+       t->tv_usec = time.millitm * 1000;
 #else
        gettimeofday(t, NULL);
 #endif