Ruby  2.4.2p198(2017-09-14revision59899)
ossl_bio.c
Go to the documentation of this file.
1 /*
2  * 'OpenSSL for Ruby' team members
3  * Copyright (C) 2003
4  * All rights reserved.
5  */
6 /*
7  * This program is licensed under the same licence as Ruby.
8  * (See the file 'LICENCE'.)
9  */
10 #include "ossl.h"
11 
12 BIO *
13 ossl_obj2bio(volatile VALUE *pobj)
14 {
15  VALUE obj = *pobj;
16  BIO *bio;
17 
18  if (RB_TYPE_P(obj, T_FILE))
19  obj = rb_funcallv(obj, rb_intern("read"), 0, NULL);
20  StringValue(obj);
21  bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LENINT(obj));
22  if (!bio)
23  ossl_raise(eOSSLError, "BIO_new_mem_buf");
24  *pobj = obj;
25  return bio;
26 }
27 
28 VALUE
30 {
31  VALUE ret;
32  BUF_MEM *buf;
33 
34  BIO_get_mem_ptr(bio, &buf);
35  ret = rb_str_new(buf->data, buf->length);
36 
37  return ret;
38 }
39 
40 VALUE
41 ossl_protect_membio2str(BIO *bio, int *status)
42 {
43  return rb_protect((VALUE (*)(VALUE))ossl_membio2str0, (VALUE)bio, status);
44 }
45 
46 VALUE
47 ossl_membio2str(BIO *bio)
48 {
49  VALUE ret;
50  int status = 0;
51 
52  ret = ossl_protect_membio2str(bio, &status);
53  BIO_free(bio);
54  if(status) rb_jump_tag(status);
55 
56  return ret;
57 }
VALUE ossl_membio2str0(BIO *bio)
Definition: ossl_bio.c:29
VALUE ossl_protect_membio2str(BIO *bio, int *status)
Definition: ossl_bio.c:41
BIO * ossl_obj2bio(volatile VALUE *pobj)
Definition: ossl_bio.c:13
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:891
VALUE ossl_membio2str(BIO *bio)
Definition: ossl_bio.c:47
#define RB_TYPE_P(obj, type)
Definition: ruby.h:527
VALUE eOSSLError
Definition: ossl.c:218
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4309
unsigned long VALUE
Definition: ruby.h:85
void rb_jump_tag(int tag)
Definition: eval.c:788
#define rb_funcallv
Definition: console.c:21
#define RSTRING_PTR(str)
Definition: ruby.h:982
#define T_FILE
Definition: ruby.h:502
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:278
#define RSTRING_LENINT(str)
Definition: ruby.h:990
#define rb_intern(str)
#define NULL
Definition: _sdbm.c:102
#define StringValue(v)
Definition: ruby.h:569
VALUE rb_str_new(const char *, long)
Definition: string.c:736