Avoid warnings.
[openssl.git] / crypto / bio / bss_bio.c
index 5b60f541a128917c0092856938d62c1a707e6f98..f026d518076da1a4dd257de8df746af087e4b08a 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <assert.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/err.h>
@@ -45,15 +46,20 @@ BIO_METHOD *BIO_s_bio(void)
 struct bio_bio_st
 {
        BIO *peer;     /* NULL if buf == NULL.
-                                       * If peer != NULL, then peer->ptr is also a bio_bio_st,
-                                       * and its "peer" member points back to us. */
+                       * If peer != NULL, then peer->ptr is also a bio_bio_st,
+                       * and its "peer" member points back to us.
+                       * peer != NULL iff init != 0 in the BIO. */
        
        /* This is for what we write (i.e. reading uses peer's struct): */
-       int closed;    /* valid iff peer != NULL */
-       size_t len;    /* valid iff buf != NULL; 0 if peer == NULL */
-       size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
+       int closed;     /* valid iff peer != NULL */
+       size_t len;     /* valid iff buf != NULL; 0 if peer == NULL */
+       size_t offset;  /* valid iff buf != NULL; 0 if len == 0 */
        size_t size;
-       char *buf;     /* "size" elements (if != NULL) */
+       char *buf;      /* "size" elements (if != NULL) */
+
+       size_t request; /* valid iff peer != NULL; 0 if len != 0;
+                        * otherwise set by peer to number of bytes
+                        * it (unsuccesfully) tried to read. */
 };
 
 static int bio_new(BIO *bio)
@@ -123,6 +129,7 @@ static long bio_ctrl(BIO *bio, int cmd, long num, char *ptr)
                /* - make pair */
                /* - destroy pair */
                /* - get number of bytes that the next write will accept */
+               /* - get number of bytes requested by peer */
                /* - send "close" */
 
        case BIO_CTRL_RESET:
@@ -163,6 +170,8 @@ static long bio_ctrl(BIO *bio, int cmd, long num, char *ptr)
 
        case BIO_CTRL_DUP:
                /* XXX */
+               ret = 1;
+               break;
 
        case BIO_CTRL_FLUSH:
                ret = 1;
@@ -179,7 +188,8 @@ static int bio_puts(BIO *bio, char *str)
        return bio_write(bio, str, strlen(str));
        }
 
-
+/* Until bio_make_pair is used, make a dummy function use it for -pedantic */
+void dummy() { bio_make_pair(NULL,NULL); }
 
 static int bio_make_pair(BIO *bio1, BIO *bio2)
        {
@@ -197,7 +207,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2)
                return 0;
                }
        
-       if (b1->buf != NULL)
+       if (b1->buf == NULL)
                {
                b1->buf = Malloc(b1->size);
                if (b1->buf == NULL)
@@ -209,7 +219,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2)
                b1->offset = 0;
                }
        
-       if (b2->buf != NULL)
+       if (b2->buf == NULL)
                {
                b2->buf = Malloc(b2->size);
                if (b2->buf == NULL)
@@ -222,7 +232,14 @@ static int bio_make_pair(BIO *bio1, BIO *bio2)
                }
        
        b1->peer = bio2;
+       b1->closed = 0;
+       b1->request = 0;
        b2->peer = bio1;
+       b2->closed = 0;
+       b2->request = 0;
+
+       bio1->init = 1;
+       bio2->init = 1;
 
        return 1;
        }