Security framework.
[openssl.git] / apps / s_time.c
index 2fb853d0719efb5c69f984a42e53fb6ecc872554..b823c33c58a02656c3f33c5e1654f990b97b1efb 100644 (file)
 #include OPENSSL_UNISTD
 #endif
 
 #include OPENSSL_UNISTD
 #endif
 
-#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
-#define TIMES
-#endif
-
-#ifndef _IRIX
-#include <time.h>
-#endif
-#ifdef TIMES
-#include <sys/types.h>
-#include <sys/times.h>
-#endif
-
-/* Depending on the VMS version, the tms structure is perhaps defined.
-   The __TMS macro will show if it was.  If it wasn't defined, we should
-   undefine TIMES, since that tells the rest of the program how things
-   should be handled.                          -- Richard Levitte */
-#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
-#undef TIMES
-#endif
-
-#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS)
-#include <sys/timeb.h>
-#endif
-
-#ifdef _AIX
-#include <sys/select.h>
-#endif
-
-#if defined(sun) || defined(__ultrix)
-#define _POSIX_SOURCE
-#include <limits.h>
-#include <sys/param.h>
-#endif
-
-/* The following if from times(3) man page.  It may need to be changed
-*/
-#ifndef HZ
-# ifdef _SC_CLK_TCK
-#  define HZ ((double)sysconf(_SC_CLK_TCK))
-# else
-#  ifndef CLK_TCK
-#   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
-#    define HZ 100.0
-#   else /* _BSD_CLK_TCK_ */
-#    define HZ ((double)_BSD_CLK_TCK_)
-#   endif
-#  else /* CLK_TCK */
-#   define HZ ((double)CLK_TCK)
-#  endif
-# endif
-#endif
-
 #undef PROG
 #define PROG s_time_main
 
 #undef PROG
 #define PROG s_time_main
 
 #undef BUFSIZZ
 #define BUFSIZZ 1024*10
 
 #undef BUFSIZZ
 #define BUFSIZZ 1024*10
 
+#define MYBUFSIZ 1024*8
+
 #undef min
 #undef max
 #define min(a,b) (((a) < (b)) ? (a) : (b))
 #undef min
 #undef max
 #define min(a,b) (((a) < (b)) ? (a) : (b))
@@ -179,7 +129,7 @@ static char *tm_cipher=NULL;
 static int tm_verify = SSL_VERIFY_NONE;
 static int maxTime = SECONDS;
 static SSL_CTX *tm_ctx=NULL;
 static int tm_verify = SSL_VERIFY_NONE;
 static int maxTime = SECONDS;
 static SSL_CTX *tm_ctx=NULL;
-static SSL_METHOD *s_time_meth=NULL;
+static const SSL_METHOD *s_time_meth=NULL;
 static char *s_www_path=NULL;
 static long bytes_read=0; 
 static int st_bugs=0;
 static char *s_www_path=NULL;
 static long bytes_read=0; 
 static int st_bugs=0;
@@ -324,6 +274,11 @@ static int parseArgs(int argc, char **argv)
                {
                if (--argc < 1) goto bad;
                s_www_path= *(++argv);
                {
                if (--argc < 1) goto bad;
                s_www_path= *(++argv);
+               if(strlen(s_www_path) > MYBUFSIZ-100)
+                       {
+                       BIO_printf(bio_err,"-www option too long\n");
+                       badop=1;
+                       }
                }
        else if(strcmp(*argv,"-bugs") == 0)
            st_bugs=1;
                }
        else if(strcmp(*argv,"-bugs") == 0)
            st_bugs=1;
@@ -369,49 +324,8 @@ bad:
 
 static double tm_Time_F(int s)
        {
 
 static double tm_Time_F(int s)
        {
-       static double ret;
-#ifdef TIMES
-       static struct tms tstart,tend;
-
-       if(s == START) {
-               times(&tstart);
-               return(0);
-       } else {
-               times(&tend);
-               ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
-               return((ret == 0.0)?1e-6:ret);
-       }
-#elif defined(OPENSSL_SYS_VXWORKS)
-        {
-       static unsigned long tick_start, tick_end;
-
-       if( s == START )
-               {
-               tick_start = tickGet();
-               return 0;
-               }
-       else
-               {
-               tick_end = tickGet();
-               ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
-               return((ret == 0.0)?1e-6:ret);
-               }
-        }
-#else /* !times() */
-       static struct timeb tstart,tend;
-       long i;
-
-       if(s == START) {
-               ftime(&tstart);
-               return(0);
-       } else {
-               ftime(&tend);
-               i=(long)tend.millitm-(long)tstart.millitm;
-               ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
-               return((ret == 0.0)?1e-6:ret);
+       return app_tminterval(s,1);
        }
        }
-#endif
-}
 
 /***********************************************************************
  * MAIN - main processing area for client
 
 /***********************************************************************
  * MAIN - main processing area for client
@@ -484,7 +398,7 @@ int MAIN(int argc, char **argv)
        tm_Time_F(START);
        for (;;)
                {
        tm_Time_F(START);
        for (;;)
                {
-               if (finishtime < time(NULL)) break;
+               if (finishtime < (long)time(NULL)) break;
 #ifdef WIN32_STUFF
 
                if( flushWinMsgs(0) == -1 )
 #ifdef WIN32_STUFF
 
                if( flushWinMsgs(0) == -1 )
@@ -499,7 +413,7 @@ int MAIN(int argc, char **argv)
 
                if (s_www_path != NULL)
                        {
 
                if (s_www_path != NULL)
                        {
-                       sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
+                       BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
                        SSL_write(scon,buf,strlen(buf));
                        while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
                                bytes_read+=i;
                        SSL_write(scon,buf,strlen(buf));
                        while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
                                bytes_read+=i;
@@ -535,9 +449,9 @@ int MAIN(int argc, char **argv)
                }
        totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
 
                }
        totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
 
-       i=(int)(time(NULL)-finishtime+maxTime);
+       i=(int)((long)time(NULL)-finishtime+maxTime);
        printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
        printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
-       printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);
+       printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
 
        /* Now loop and time connections using the same session id over and over */
 
 
        /* Now loop and time connections using the same session id over and over */
 
@@ -554,7 +468,7 @@ next:
 
        if (s_www_path != NULL)
                {
 
        if (s_www_path != NULL)
                {
-               sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
+               BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
                SSL_write(scon,buf,strlen(buf));
                while (SSL_read(scon,buf,sizeof(buf)) > 0)
                        ;
                SSL_write(scon,buf,strlen(buf));
                while (SSL_read(scon,buf,sizeof(buf)) > 0)
                        ;
@@ -569,7 +483,7 @@ next:
        nConn = 0;
        totalTime = 0.0;
 
        nConn = 0;
        totalTime = 0.0;
 
-       finishtime=time(NULL)+maxTime;
+       finishtime=(long)time(NULL)+maxTime;
 
        printf( "starting\n" );
        bytes_read=0;
 
        printf( "starting\n" );
        bytes_read=0;
@@ -577,7 +491,7 @@ next:
                
        for (;;)
                {
                
        for (;;)
                {
-               if (finishtime < time(NULL)) break;
+               if (finishtime < (long)time(NULL)) break;
 
 #ifdef WIN32_STUFF
                if( flushWinMsgs(0) == -1 )
 
 #ifdef WIN32_STUFF
                if( flushWinMsgs(0) == -1 )
@@ -592,7 +506,7 @@ next:
 
                if (s_www_path)
                        {
 
                if (s_www_path)
                        {
-                       sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
+                       BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
                        SSL_write(scon,buf,strlen(buf));
                        while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
                                bytes_read+=i;
                        SSL_write(scon,buf,strlen(buf));
                        while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
                                bytes_read+=i;
@@ -627,7 +541,7 @@ next:
 
 
        printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
 
 
        printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
-       printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);
+       printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
 
        ret=0;
 end:
 
        ret=0;
 end:
@@ -639,7 +553,7 @@ end:
                tm_ctx=NULL;
                }
        apps_shutdown();
                tm_ctx=NULL;
                }
        apps_shutdown();
-       EXIT(ret);
+       OPENSSL_EXIT(ret);
        }
 
 /***********************************************************************
        }
 
 /***********************************************************************
@@ -687,7 +601,7 @@ static SSL *doConnection(SSL *scon)
                        i=SSL_get_fd(serverCon);
                        width=i+1;
                        FD_ZERO(&readfds);
                        i=SSL_get_fd(serverCon);
                        width=i+1;
                        FD_ZERO(&readfds);
-                       FD_SET(i,&readfds);
+                       openssl_fdset(i,&readfds);
                        /* Note: under VMS with SOCKETSHR the 2nd parameter
                         * is currently of type (int *) whereas under other
                         * systems it is (void *) if you don't have a cast it
                        /* Note: under VMS with SOCKETSHR the 2nd parameter
                         * is currently of type (int *) whereas under other
                         * systems it is (void *) if you don't have a cast it