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_
72 p5_BIO_new_buffer_ssl_connect(...)
85 if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
86 croak("Usage: OpenSSL::BIO::new_buffer_ssl_connect(SSL_CTX)");
88 IV tmp = SvIV((SV *)SvRV(arg));
92 bio = BIO_new_buffer_ssl_connect(ctx);
93 arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
97 p5_BIO_new_ssl_connect(...)
110 if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
111 croak("Usage: OpenSSL::BIO::new_ssl_connect(SSL_CTX)");
113 IV tmp = SvIV((SV *)SvRV(arg));
114 ctx = (SSL_CTX *)tmp;
117 bio = BIO_new_ssl_connect(ctx);
118 arg = (SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
129 pr_name("p5_BIO_new");
130 if ((items == 1) && SvPOK(ST(0)))
131 type = SvPV(ST(0),na);
132 else if ((items == 2) && SvPOK(ST(1)))
133 type = SvPV(ST(1),na);
135 croak("Usage: OpenSSL::BIO::new(type)");
137 if (strcmp(type, "mem") == 0)
138 bio=BIO_new(BIO_s_mem());
139 else if (strcmp(type, "socket") == 0)
140 bio=BIO_new(BIO_s_socket());
141 else if (strcmp(type, "connect") == 0)
142 bio=BIO_new(BIO_s_connect());
143 else if (strcmp(type, "accept") == 0)
144 bio=BIO_new(BIO_s_accept());
145 else if (strcmp(type, "fd") == 0)
146 bio=BIO_new(BIO_s_fd());
147 else if (strcmp(type, "file") == 0)
148 bio=BIO_new(BIO_s_file());
149 else if (strcmp(type, "null") == 0)
150 bio=BIO_new(BIO_s_null());
151 else if (strcmp(type, "ssl") == 0)
152 bio=BIO_new(BIO_f_ssl());
153 else if (strcmp(type, "buffer") == 0)
154 bio=BIO_new(BIO_f_buffer());
156 croak("unknown BIO type");
157 arg = (SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
161 p5_BIO_hostname(bio, name)
166 RETVAL = BIO_set_conn_hostname(bio, name);
171 p5_BIO_set_accept_port(bio, str)
176 RETVAL = BIO_set_accept_port(bio, str);
181 p5_BIO_do_handshake(bio)
185 RETVAL = BIO_do_handshake(bio);
195 /* This reference will be reduced when the reference is
196 * let go, and then when the BIO_free_all() is called
197 * inside the OpenSSL library by the BIO with this
200 RETVAL = BIO_push(b, bio);
215 /* This BIO will either be one created in the
216 * perl library, in which case it will have a perl
217 * SV, otherwise it will have been created internally,
218 * inside OpenSSL. For the 'pushed in', it needs
219 * the reference count decememted. */
220 arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
222 arg = new_ref("OpenSSL::BIO",(char *)bio,0);
223 BIO_set_ex_data(bio, p5_bio_ex_bio_ptr, (char *)arg);
227 /* it was pushed in */
234 p5_BIO_sysread(bio, in, num, ...)
246 sv_setpvn(in, "", 0);
249 offset = SvIV(ST(3));
252 croak("Offset outside string");
256 if ((num+offset) > olen) {
257 SvGROW(in, num+offset+1);
259 memset(&(p[olen]), 0, (num+offset)-olen+1);
262 i = BIO_read(bio, p+offset, num);
266 SvCUR_set(in, offset+i);
271 p5_BIO_syswrite(bio, in, ...)
281 ptr = SvPV(in, in_len);
283 len = SvOK(ST(2)) ? SvIV(ST(2)) : in_len;
285 offset = SvIV(ST(3));
287 if (-offset > in_len)
288 croak("Offset outside string");
291 else if ((offset >= in_len) && (in_len > 0))
292 croak("Offset outside string");
294 if (len >= (in_len-offset))
299 RETVAL = BIO_write(bio, ptr+offset, len);
311 pr_name("p5_BIO_gets");
313 PUSHs(sv_newmortal());
314 sv_setpvn(ST(0), "", 0);
317 i = BIO_gets(bio, p, 1024);
327 RETVAL = BIO_flush(bio);
336 RETVAL = bio->method->name;
351 arg = (SV *)BIO_get_ex_data(bio, p5_bio_ex_bio_ptr);
353 arg = new_ref("OpenSSL::BIO", (char *)bio, 0);
354 BIO_set_ex_data(bio, p5_bio_ex_bio_ptr, (char *)arg);
373 RETVAL = BIO_puts(bio, ptr);
378 p5_BIO_set_callback(bio, cb,...)
387 croak("Usage: OpenSSL::BIO::set_callback(bio,callback[,arg]");
389 arg2 = sv_mortalcopy(ST(2));
391 BIO_set_ex_data(bio, p5_bio_ex_bio_callback_data, (char *)arg2);
393 arg = sv_mortalcopy(ST(1));
395 BIO_set_ex_data(bio, p5_bio_ex_bio_callback, (char *)arg);
396 /* printf("%08lx < bio_ptr\n",BIO_get_ex_data(bio,p5_bio_ex_bio_ptr)); */
397 BIO_set_callback(bio, p5_bio_callback);
406 pr_name_d("p5_BIO_DESTROY",bio->references);
407 /* printf("p5_BIO_DESTROY <%s> %d\n",bio->method->name,bio->references); */
408 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,NULL);
412 p5_BIO_set_ssl(bio, ssl)
417 pr_name("p5_BIO_set_ssl");
419 RETVAL = BIO_set_ssl(bio, ssl, BIO_CLOSE);
424 p5_BIO_number_read(bio)
428 RETVAL = BIO_number_read(bio);
433 p5_BIO_number_written(bio)
437 RETVAL = BIO_number_written(bio);
442 p5_BIO_references(bio)
446 RETVAL = bio->references;