/* crypto/bio/bss_mem.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
#include <stdio.h>
#include <errno.h>
#include "cryptlib.h"
-#include "bio.h"
+#include <openssl/bio.h>
-#ifndef NOPROTO
static int mem_write(BIO *h,char *buf,int num);
static int mem_read(BIO *h,char *buf,int size);
static int mem_puts(BIO *h,char *str);
static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2);
static int mem_new(BIO *h);
static int mem_free(BIO *data);
-#else
-static int mem_write();
-static int mem_read();
-static int mem_puts();
-static int mem_gets();
-static long mem_ctrl();
-static int mem_new();
-static int mem_free();
-#endif
-
static BIO_METHOD mem_method=
{
- BIO_TYPE_MEM,"memory buffer",
+ BIO_TYPE_MEM,
+ "memory buffer",
mem_write,
mem_read,
mem_puts,
mem_free,
};
-BIO_METHOD *BIO_s_mem()
+/* bio->num is used to hold the value to return on 'empty', if it is
+ * 0, should_retry is not set */
+
+BIO_METHOD *BIO_s_mem(void)
{
return(&mem_method);
}
-static int mem_new(bi)
-BIO *bi;
+static int mem_new(BIO *bi)
{
BUF_MEM *b;
return(0);
bi->shutdown=1;
bi->init=1;
- bi->num=0;
+ bi->num= -1;
bi->ptr=(char *)b;
return(1);
}
-static int mem_free(a)
-BIO *a;
+static int mem_free(BIO *a)
{
if (a == NULL) return(0);
if (a->shutdown)
return(1);
}
-static int mem_read(b,out,outl)
-BIO *b;
-char *out;
-int outl;
+static int mem_read(BIO *b, char *out, int outl)
{
int ret= -1;
BUF_MEM *bm;
}
else if (bm->length == 0)
{
- BIO_set_retry_read(b);
- ret= -1;
+ if (b->num != 0)
+ BIO_set_retry_read(b);
+ ret= b->num;
}
return(ret);
}
-static int mem_write(b,in,inl)
-BIO *b;
-char *in;
-int inl;
+static int mem_write(BIO *b, char *in, int inl)
{
int ret= -1;
int blen;
return(ret);
}
-static long mem_ctrl(b,cmd,num,ptr)
-BIO *b;
-int cmd;
-long num;
-char *ptr;
+static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
{
long ret=1;
char **pptr;
case BIO_CTRL_EOF:
ret=(long)(bm->length == 0);
break;
+ case BIO_C_SET_BUF_MEM_EOF_RETURN:
+ b->num=(int)num;
+ break;
case BIO_CTRL_INFO:
ret=(long)bm->length;
if (ptr != NULL)
return(ret);
}
-static int mem_gets(bp,buf,size)
-BIO *bp;
-char *buf;
-int size;
+static int mem_gets(BIO *bp, char *buf, int size)
{
int i,j;
int ret= -1;
return(ret);
}
-static int mem_puts(bp,str)
-BIO *bp;
-char *str;
+static int mem_puts(BIO *bp, char *str)
{
int n,ret;