Hello OpenSSL Developers,
We're using the "openssl s_client" command in a script and needed a way to timeout
the `openssl s_client` call (which normally would wait forever).
For that reason we introduced a "-timeout <seconds>" argument. The modifications are
shown below.
Example call:
echo "GET /" | openssl s_client -connect testca1:443 -timeout 3
openssl-SNAP-20000330/apps/s_client.c
-----------------------------------------------------------------------------
59,68d58
< /*
< * This is a modified version of s_client. It introduces a -timeout commandline
argument, which can be used
< * for specifying a timeout for scripted ("synchronous") use of the asynchrounous
s_client
< * These patches are done by:
< *
< * media transfer GmbH, Darmstadt/Germany
< * last modified: 23/03/2000, AB
< *
< */
<
141,145d130
<
< /* begin media transfer changes */
< BIO_printf(bio_err," -timeout arg - time in seconds to wait until something
happens on the r/w fds\n");
< /* end media transfer changes */
<
195,214d179
<
< /* begin media transfer changes */
< /*
< * Some variables needed for the new features
< *
< * stdin_open: flag; when reading from file, read() returns 0 occasionally.
< * Hereafter FD_SET must not be set for (stdin).
< * timeout_sec: is set by commandline argument to the timeout value in seconds.
< * Initialized with zero, which means do not timeout.
< * tv: simple timeval structure for handing the timeout over to
select()
< *
< */
<
< /* before: nothing here */
<
< int stdin_open;
< int timeout_sec=0;
< struct timeval tv;
< /* end media transfer changes */
<
280,293d244
< /* begin media transfer changes */
<
< /* New commandline argument -timeout arg. arg is converted to int and
stored in timeout_sec. */
< /* before: nothing here */
<
< else if (strcmp(*argv,"-timeout") == 0)
< {
< if (--argc < 1) goto bad;
< timeout_sec=atoi(*(++argv));
< BIO_printf(bio_err,"timeout is %d sec\n",timeout_sec);
< }
<
< /* end media transfer changes */
<
498,506d448
< /* begin media transfer changes */
<
< /* set stdin_open initially to TRUE, may change later to FALSE */
< /* before: nothing here */
<
< stdin_open=1;
<
< /* end media transfer changes */
<
545,553c487
< /* begin media transfer changes */
<
< /* only do FD_SET on (stdin) if stdin_open is TRUE */
< /* before: if (read_tty)
FD_SET(fileno(stdin),&readfds); */
<
< if (read_tty && stdin_open)
FD_SET(fileno(stdin),&readfds);
<
< /* end media transfer changes */
<
---
> if (read_tty) FD_SET(fileno(stdin),&readfds);
597,627c531,532
<
< /* begin media transfer changes */
<
< /* if timeout is not set (timeout_sec=0), behave as before,
namely wait infinitely on fd's for
< something to happen. This is applicable for keyboard input,
but not for scripting
< */
<
< /* before for the whole begin/end-block:i=select(width,(void
*)&readfds,(void *)&writefds,NULL,NULL); */
<
< if (timeout_sec == 0)
< i=select(width,(void *)&readfds,(void
*)&writefds,NULL,NULL);
<
< /* if timeout is set, then make select return FALSE after a
specified amount of time */
< /* before: nothing here */
<
< else
< {
< tv.tv_sec = timeout_sec;
< tv.tv_usec = 0;
<
< i=select(width,(void *)&readfds,(void
*)&writefds,NULL,&tv);
< }
<
< /* if select returns FALSE, do a clean shutdown and exit the
mainloop */
<
< /* case i==0 is handled seperately */
< if (i == 0)
< goto shut;
<
< /* end media transfer changes */
<
---
> i=select(width,(void *)&readfds,(void *)&writefds,
> NULL,NULL);
629d533
<
800,810d703
< /* begin media transfer changes */
<
< /* see below for meaning */
<
< if ((i == 0))
< {
< stdin_open=0;
< }
<
< /* end media transfer changes */
<
829,835c722
< /* begin media transfer changes */
<
< /* case i==0 is handled below separately */
< /* before: if ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == 'Q')))
*/
< if ((!c_ign_eof) && ((i < 0) || (cbuf[0] == 'Q')))
<
< /* end media transfer changes */
---
> if ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == 'Q')))
841,852d727
< /* begin media transfer changes */
<
< /* if read() returned FALSE, then do no FD_SET on stdin any
more */
< /* before: nothing here */
<
< if ((i == 0))
< {
< stdin_open=0;
< }
<
< /* end media transfer changes */
<
-----------------------------------------------------------------------------
Regards,
Guus Gerrits
--------------------------
Media Transfer GmbH
| 01.05.2000 ==>
Kleyerstrasse 8 | Dolivostra�e 11
D-64295 Darmstadt | D-64293 Darmstadt
Germany
EMail: [EMAIL PROTECTED]
Web: http://www.mtgnet.de
Tel: +49 6151 8193 17
Fax: +49 6151 8193 41
--------------------------
s_client.c