4 static int p5_bio_ex_bio_ptr = 0;
5 static int p5_bio_ex_bio_callback = 0;
6 static int p5_bio_ex_bio_callback_data = 0;
9 p5_bio_callback(bio,state,parg,cmd,larg,ret)
20 me = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
21 cb = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_callback);
29 XPUSHs(sv_2mortal(newSVsv(me)));
30 XPUSHs(sv_2mortal(newSViv(state)));
31 XPUSHs(sv_2mortal(newSViv(cmd)));
32 if ((state == BIO_CB_READ) || (state == BIO_CB_WRITE))
33 XPUSHs(sv_2mortal(newSVpv(parg,larg)));
37 XPUSHs(sv_2mortal(newSViv(larg)));
38 XPUSHs(sv_2mortal(newSViv(ret)));
41 i = perl_call_sv(cb,G_SCALAR);
53 croak("Internal error in p5_bio_callback");
61 p5_bio_ex_bio_ptr = BIO_get_ex_new_index(0, "OpenSSL::BIO", ex_new, NULL, ex_cleanup);
62 p5_bio_ex_bio_callback = BIO_get_ex_new_index(0, "bio_callback", NULL, NULL, ex_cleanup);
63 p5_bio_ex_bio_callback_data = BIO_get_ex_new_index(0, "bio_callback_data", NULL, NULL, ex_cleanup);
67 MODULE = OpenSSL::BIO PACKAGE = OpenSSL::BIO PREFIX = p5_BIO_
73 p5_BIO_new_buffer_ssl_connect(...)
86 if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
87 croak("Usage: OpenSSL::BIO::new_buffer_ssl_connect(SSL_CTX)");
89 IV tmp = SvIV((SV *)SvRV(arg));
93 bio = BIO_new_buffer_ssl_connect(ctx);
94 arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
98 p5_BIO_new_ssl_connect(...)
111 if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
112 croak("Usage: OpenSSL::BIO::new_ssl_connect(SSL_CTX)");
114 IV tmp = SvIV((SV *)SvRV(arg));
115 ctx = (SSL_CTX *)tmp;
118 bio = BIO_new_ssl_connect(ctx);
119 arg = (SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
130 pr_name("p5_BIO_new");
131 if ((items == 1) && SvPOK(ST(0)))
132 type = SvPV(ST(0),na);
133 else if ((items == 2) && SvPOK(ST(1)))
134 type = SvPV(ST(1),na);
136 croak("Usage: OpenSSL::BIO::new(type)");
138 if (strcmp(type, "mem") == 0)
139 bio=BIO_new(BIO_s_mem());
140 else if (strcmp(type, "socket") == 0)
141 bio=BIO_new(BIO_s_socket());
142 else if (strcmp(type, "connect") == 0)
143 bio=BIO_new(BIO_s_connect());
144 else if (strcmp(type, "accept") == 0)
145 bio=BIO_new(BIO_s_accept());
146 else if (strcmp(type, "fd") == 0)
147 bio=BIO_new(BIO_s_fd());
148 else if (strcmp(type, "file") == 0)
149 bio=BIO_new(BIO_s_file());
150 else if (strcmp(type, "null") == 0)
151 bio=BIO_new(BIO_s_null());
152 else if (strcmp(type, "ssl") == 0)
153 bio=BIO_new(BIO_f_ssl());
154 else if (strcmp(type, "buffer") == 0)
155 bio=BIO_new(BIO_f_buffer());
157 croak("unknown BIO type");
158 arg = (SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
162 p5_BIO_hostname(bio, name)
167 RETVAL = BIO_set_conn_hostname(bio, name);
172 p5_BIO_set_accept_port(bio, str)
177 RETVAL = BIO_set_accept_port(bio, str);
182 p5_BIO_do_handshake(bio)
186 RETVAL = BIO_do_handshake(bio);
196 /* This reference will be reduced when the reference is
197 * let go, and then when the BIO_free_all() is called
198 * inside the OpenSSL library by the BIO with this
201 RETVAL = BIO_push(b, bio);
216 /* This BIO will either be one created in the
217 * perl library, in which case it will have a perl
218 * SV, otherwise it will have been created internally,
219 * inside OpenSSL. For the 'pushed in', it needs
220 * the reference count decremented. */
221 arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
223 arg = new_ref("OpenSSL::BIO",(char *)bio,0);
224 BIO_set_ex_data(bio, p5_bio_ex_bio_ptr, (char *)arg);
228 /* it was pushed in */
235 p5_BIO_sysread(bio, in, num, ...)
247 sv_setpvn(in, "", 0);
250 offset = SvIV(ST(3));
253 croak("Offset outside string");
257 if ((num+offset) > olen) {
258 SvGROW(in, num+offset+1);
260 memset(&(p[olen]), 0, (num+offset)-olen+1);
263 i = BIO_read(bio, p+offset, num);
267 SvCUR_set(in, offset+i);
272 p5_BIO_syswrite(bio, in, ...)
282 ptr = SvPV(in, in_len);
284 len = SvOK(ST(2)) ? SvIV(ST(2)) : in_len;
286 offset = SvIV(ST(3));
288 if (-offset > in_len)
289 croak("Offset outside string");
292 else if ((offset >= in_len) && (in_len > 0))
293 croak("Offset outside string");
295 if (len >= (in_len-offset))
300 RETVAL = BIO_write(bio, ptr+offset, len);
312 pr_name("p5_BIO_gets");
314 PUSHs(sv_newmortal());
315 sv_setpvn(ST(0), "", 0);
318 i = BIO_gets(bio, p, 1024);
328 RETVAL = BIO_flush(bio);
337 RETVAL = bio->method->name;
352 arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
354 arg = new_ref("OpenSSL::BIO", (char *)bio, 0);
355 BIO_set_ex_data(bio, p5_bio_ex_bio_ptr, (char *)arg);
374 RETVAL = BIO_puts(bio, ptr);
379 p5_BIO_set_callback(bio, cb,...)
388 croak("Usage: OpenSSL::BIO::set_callback(bio,callback[,arg]");
390 arg2 = sv_mortalcopy(ST(2));
392 BIO_set_ex_data(bio, p5_bio_ex_bio_callback_data, (char *)arg2);
394 arg = sv_mortalcopy(ST(1));
396 BIO_set_ex_data(bio, p5_bio_ex_bio_callback, (char *)arg);
397 /* printf("%08lx < bio_ptr\n",BIO_get_ex_data(bio,p5_bio_ex_bio_ptr)); */
398 BIO_set_callback(bio, p5_bio_callback);
407 pr_name_d("p5_BIO_DESTROY",bio->references);
408 /* printf("p5_BIO_DESTROY <%s> %d\n",bio->method->name,bio->references); */
409 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,NULL);
413 p5_BIO_set_ssl(bio, ssl)
418 pr_name("p5_BIO_set_ssl");
420 RETVAL = BIO_set_ssl(bio, ssl, BIO_CLOSE);
425 p5_BIO_number_read(bio)
429 RETVAL = BIO_number_read(bio);
434 p5_BIO_number_written(bio)
438 RETVAL = BIO_number_written(bio);
443 p5_BIO_references(bio)
447 RETVAL = bio->references;