Skip to content
s_server.c 25.1 KiB
Newer Older
				{
				BIO_puts(io,text);
				BIO_printf(io,"Error accessing '%s'\r\n",p);
				ERR_print_errors(io);
				break;
				}
			if (S_ISDIR(st_buf.st_mode))
				{
				strcat(p,"/index.html");
				}

			if ((file=BIO_new_file(p,"r")) == NULL)
				{
				BIO_puts(io,text);
				BIO_printf(io,"Error opening '%s'\r\n",p);
				ERR_print_errors(io);
				break;
				}

			if (!s_quiet)
				BIO_printf(bio_err,"FILE:%s\n",p);

			i=strlen(p);
			if (	((i > 5) && (strcmp(&(p[i-5]),".html") == 0)) ||
				((i > 4) && (strcmp(&(p[i-4]),".php") == 0)) ||
				((i > 4) && (strcmp(&(p[i-4]),".htm") == 0)))
				BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/html\r\n\r\n");
			else
				BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/plain\r\n\r\n");
			/* send the file */
			for (;;)
				{
				i=BIO_read(file,buf,1024);
				if (i <= 0) break;

				for (j=0; j<i; )
					{
					k=BIO_write(io,&(buf[j]),i-j);
					if (k <= 0)
						{
						if (!BIO_should_retry(io))
							break;
						else
							{
							BIO_printf(bio_s_out,"rwrite W BLOCK\n");
							}
						}
					else
						{
						j+=k;
						}
					}
				}
			BIO_free(file);
			break;
			}
		}

	for (;;)
		{
		i=(int)BIO_flush(io);
		if (i <= 0)
			{
			if (!BIO_should_retry(io))
				break;
			}
		else
			break;
		}
end:
#if 0
	/* make sure we re-use sessions */
	SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
#else
	/* This kills performace */
	SSL_shutdown(con);
#endif

err:

	if (ret >= 0)
		BIO_printf(bio_s_out,"ACCEPT\n");

	if (io != NULL) BIO_free_all(io);
/*	if (ssl_bio != NULL) BIO_free(ssl_bio); */
	return(ret);
	}

static RSA MS_CALLBACK *tmp_rsa_cb(s,export)
SSL *s;
int export;
	{
	static RSA *rsa_tmp=NULL;

	if (rsa_tmp == NULL)
		{
		if (!s_quiet)
			{
			BIO_printf(bio_err,"Generating temp (512 bit) RSA key...");
			BIO_flush(bio_err);
			}
#ifndef NO_RSA
		rsa_tmp=RSA_generate_key(512,RSA_F4,NULL);
#endif
		if (!s_quiet)
			{
			BIO_printf(bio_err,"\n");
			BIO_flush(bio_err);
			}
		}
	return(rsa_tmp);
	}