- if ((a->callback != NULL) &&
- ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
- return(i);
-
- if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
- ret=a->method->destroy(a);
- Free(a);
- return(1);
- }
-
-int BIO_read(b,out,outl)
-BIO *b;
-char *out;
-int outl;
- {
- int i;
-
- if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
- {
- BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
-
- if ((b->callback != NULL) &&
- ((i=(int)b->callback(b,BIO_CB_READ,out,outl,0L,1L)) <= 0))
- return(i);
-
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_READ,BIO_R_UNINITALISED);
- return(-2);
- }
-
- i=b->method->bread(b,out,outl);
- if (i > 0) b->num_read+=(unsigned long)i;
-
- if (b->callback != NULL)
- i=(int)b->callback(b,BIO_CB_READ|BIO_CB_RETURN,out,outl,
- 0L,(long)i);
- return(i);
- }
-
-int BIO_write(b,in,inl)
-BIO *b;
-char *in;
-int inl;
- {
- int i;
-
- if ((b == NULL) || (b->method == NULL) || (b->method->bwrite == NULL))
- {
- BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
-
- if ((b->callback != NULL) &&
- ((i=(int)b->callback(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))
- return(i);
-
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITALISED);
- return(-2);
- }
-
- i=b->method->bwrite(b,in,inl);
- if (i > 0) b->num_write+=(unsigned long)i;
-
- if (b->callback != NULL)
- i=(int)b->callback(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
- 0L,(long)i);
- return(i);
- }
-
-int BIO_puts(b,in)
-BIO *b;
-char *in;
- {
- int i;
-
- if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
- {
- BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
-
- if ((b->callback != NULL) &&
- ((i=(int)b->callback(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))
- return(i);
-
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITALISED);
- return(-2);
- }
-
- i=b->method->bputs(b,in);
-
- if (b->callback != NULL)
- i=(int)b->callback(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
- 0L,(long)i);
- return(i);
- }
-
-int BIO_gets(b,in,inl)
-BIO *b;
-char *in;
-int inl;
- {
- int i;
-
- if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL))
- {
- BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
-
- if ((b->callback != NULL) &&
- ((i=(int)b->callback(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0))
- return(i);
-
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITALISED);
- return(-2);
- }
-
- i=b->method->bgets(b,in,inl);
-
- if (b->callback != NULL)
- i=(int)b->callback(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl,
- 0L,(long)i);
- return(i);
- }
-
-long BIO_ctrl_int(b,cmd,larg,iarg)
-BIO *b;
-int cmd;
-long larg;
-int iarg;
- {
- int i;
-
- i=iarg;
- return(BIO_ctrl(b,cmd,larg,(char *)&i));
- }
-
-long BIO_ctrl(b,cmd,larg,parg)
-BIO *b;
-int cmd;
-long larg;
-char *parg;
- {
- long ret;
-
- if (b == NULL) return(0);
-
- if ((b->method == NULL) || (b->method->ctrl == NULL))
- {
- BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
-
- if ((b->callback != NULL) &&
- ((ret=b->callback(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0))
- return(ret);
-
- ret=b->method->ctrl(b,cmd,larg,parg);
-
- if (b->callback != NULL)
- ret=b->callback(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,
- larg,ret);
- return(ret);
- }
+ if ((a->callback != NULL) &&
+ ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0))
+ return (i);
+
+ CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
+
+ if ((a->method != NULL) && (a->method->destroy != NULL))
+ a->method->destroy(a);
+ OPENSSL_free(a);
+ return (1);
+}
+
+void BIO_vfree(BIO *a)
+{
+ BIO_free(a);
+}
+
+void BIO_clear_flags(BIO *b, int flags)
+{
+ b->flags &= ~flags;
+}
+
+int BIO_test_flags(const BIO *b, int flags)
+{
+ return (b->flags & flags);
+}
+
+void BIO_set_flags(BIO *b, int flags)
+{
+ b->flags |= flags;
+}
+
+long (*BIO_get_callback(const BIO *b)) (struct bio_st *, int, const char *,
+ int, long, long) {
+ return b->callback;
+}
+
+void BIO_set_callback(BIO *b,
+ long (*cb) (struct bio_st *, int, const char *, int,
+ long, long))
+{
+ b->callback = cb;
+}
+
+void BIO_set_callback_arg(BIO *b, char *arg)
+{
+ b->cb_arg = arg;
+}
+
+char *BIO_get_callback_arg(const BIO *b)
+{
+ return b->cb_arg;
+}
+
+const char *BIO_method_name(const BIO *b)
+{
+ return b->method->name;
+}
+
+int BIO_method_type(const BIO *b)
+{
+ return b->method->type;
+}
+
+int BIO_read(BIO *b, void *out, int outl)
+{
+ int i;
+ long (*cb) (BIO *, int, const char *, int, long, long);
+
+ if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) {
+ BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
+
+ cb = b->callback;
+ if ((cb != NULL) &&
+ ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0))
+ return (i);
+
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
+
+ i = b->method->bread(b, out, outl);
+
+ if (i > 0)
+ b->num_read += (unsigned long)i;
+
+ if (cb != NULL)
+ i = (int)cb(b, BIO_CB_READ | BIO_CB_RETURN, out, outl, 0L, (long)i);
+ return (i);
+}
+
+int BIO_write(BIO *b, const void *in, int inl)
+{
+ int i;
+ long (*cb) (BIO *, int, const char *, int, long, long);
+
+ if (b == NULL)
+ return (0);
+
+ cb = b->callback;
+ if ((b->method == NULL) || (b->method->bwrite == NULL)) {
+ BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
+
+ if ((cb != NULL) &&
+ ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0))
+ return (i);
+
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
+
+ i = b->method->bwrite(b, in, inl);
+
+ if (i > 0)
+ b->num_write += (unsigned long)i;
+
+ if (cb != NULL)
+ i = (int)cb(b, BIO_CB_WRITE | BIO_CB_RETURN, in, inl, 0L, (long)i);
+ return (i);
+}
+
+int BIO_puts(BIO *b, const char *in)
+{
+ int i;
+ long (*cb) (BIO *, int, const char *, int, long, long);
+
+ if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
+ BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
+
+ cb = b->callback;
+
+ if ((cb != NULL) && ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0))
+ return (i);
+
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
+
+ i = b->method->bputs(b, in);
+
+ if (i > 0)
+ b->num_write += (unsigned long)i;
+
+ if (cb != NULL)
+ i = (int)cb(b, BIO_CB_PUTS | BIO_CB_RETURN, in, 0, 0L, (long)i);
+ return (i);
+}
+
+int BIO_gets(BIO *b, char *in, int inl)
+{
+ int i;
+ long (*cb) (BIO *, int, const char *, int, long, long);
+
+ if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) {
+ BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
+
+ cb = b->callback;
+
+ if ((cb != NULL) && ((i = (int)cb(b, BIO_CB_GETS, in, inl, 0L, 1L)) <= 0))
+ return (i);
+
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
+
+ i = b->method->bgets(b, in, inl);
+
+ if (cb != NULL)
+ i = (int)cb(b, BIO_CB_GETS | BIO_CB_RETURN, in, inl, 0L, (long)i);
+ return (i);
+}
+
+int BIO_indent(BIO *b, int indent, int max)
+{
+ if (indent < 0)
+ indent = 0;
+ if (indent > max)
+ indent = max;
+ while (indent--)
+ if (BIO_puts(b, " ") != 1)
+ return 0;
+ return 1;
+}
+
+long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
+{
+ int i;
+
+ i = iarg;
+ return (BIO_ctrl(b, cmd, larg, (char *)&i));
+}
+
+char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
+{
+ char *p = NULL;
+
+ if (BIO_ctrl(b, cmd, larg, (char *)&p) <= 0)
+ return (NULL);
+ else
+ return (p);
+}
+
+long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
+{
+ long ret;
+ long (*cb) (BIO *, int, const char *, int, long, long);
+
+ if (b == NULL)
+ return (0);
+
+ if ((b->method == NULL) || (b->method->ctrl == NULL)) {
+ BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
+
+ cb = b->callback;
+
+ if ((cb != NULL) &&
+ ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0))
+ return (ret);
+
+ ret = b->method->ctrl(b, cmd, larg, parg);
+
+ if (cb != NULL)
+ ret = cb(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, cmd, larg, ret);
+ return (ret);
+}
+
+long BIO_callback_ctrl(BIO *b, int cmd,
+ void (*fp) (struct bio_st *, int, const char *, int,
+ long, long))
+{
+ long ret;
+ long (*cb) (BIO *, int, const char *, int, long, long);
+
+ if (b == NULL)
+ return (0);
+
+ if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) {
+ BIOerr(BIO_F_BIO_CALLBACK_CTRL, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
+
+ cb = b->callback;
+
+ if ((cb != NULL) &&
+ ((ret = cb(b, BIO_CB_CTRL, (void *)&fp, cmd, 0, 1L)) <= 0))
+ return (ret);
+
+ ret = b->method->callback_ctrl(b, cmd, fp);
+
+ if (cb != NULL)
+ ret = cb(b, BIO_CB_CTRL | BIO_CB_RETURN, (void *)&fp, cmd, 0, ret);
+ return (ret);
+}
+
+/*
+ * It is unfortunate to duplicate in functions what the BIO_(w)pending macros
+ * do; but those macros have inappropriate return type, and for interfacing
+ * from other programming languages, C macros aren't much of a help anyway.
+ */
+size_t BIO_ctrl_pending(BIO *bio)
+{
+ return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
+}
+
+size_t BIO_ctrl_wpending(BIO *bio)
+{
+ return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
+}