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;
8 static long p5_bio_callback(bio,state,parg,cmd,larg,ret)
19 me=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
20 cb=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_callback);
29 XPUSHs(sv_2mortal(newSViv(me)));
30 XPUSHs(sv_2mortal(newSViv(state)));
31 XPUSHs(sv_2mortal(newSViv(cmd)));
32 if ((state == BIO_CB_READ) || (state == BIO_CB_WRITE))
34 XPUSHs(sv_2mortal(newSVpv(parg,larg)));
39 XPUSHs(sv_2mortal(newSViv(larg)));
40 XPUSHs(sv_2mortal(newSViv(ret)));
43 i=perl_call_sv(cb,G_SCALAR);
56 croak("Internal error in SSL p5_ssl_info_callback");
64 BIO_get_ex_new_index(0,"OpenSSL::BIO",ex_new,NULL,
66 p5_bio_ex_bio_callback=
67 BIO_get_ex_new_index(0,"bio_callback",NULL,NULL,
69 p5_bio_ex_bio_callback_data=
70 BIO_get_ex_new_index(0,"bio_callback_data",NULL,NULL,
75 MODULE = OpenSSL::BIO PACKAGE = OpenSSL::BIO PREFIX = p5_BIO_
80 p5_BIO_new_buffer_ssl_connect(...)
93 if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
94 croak("Usage: OpenSSL::BIO::new_buffer_ssl_connect(SSL_CTX)");
97 IV tmp=SvIV((SV *)SvRV(arg));
101 bio=BIO_new_buffer_ssl_connect(ctx);
102 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
106 p5_BIO_new_ssl_connect(...)
119 if ((arg == NULL) || !(sv_derived_from(arg,"OpenSSL::SSL::CTX")))
120 croak("Usage: OpenSSL::BIO::new_ssl_connect(SSL_CTX)");
123 IV tmp=SvIV((SV *)SvRV(arg));
127 bio=BIO_new_ssl_connect(ctx);
128 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
138 pr_name("p5_BIO_new");
139 if ((items == 1) && SvPOK(ST(0)))
141 else if ((items == 2) && SvPOK(ST(1)))
144 croak("Usage: OpenSSL::BIO::new(type)");
147 if (strcmp(type,"connect") == 0)
148 bio=BIO_new(BIO_s_connect());
149 else if (strcmp(type,"accept") == 0)
150 bio=BIO_new(BIO_s_accept());
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)
165 RETVAL=BIO_set_conn_hostname(bio,name);
170 p5_BIO_set_accept_port(bio,str)
174 RETVAL=BIO_set_accept_port(bio,str);
179 p5_BIO_do_handshake(bio)
182 RETVAL=BIO_do_handshake(bio);
191 /* This reference will be reduced when the reference is
192 * let go, and then when the BIO_free_all() is called
193 * inside the OpenSSL library by the BIO with this
196 RETVAL=BIO_push(b,bio);
211 /* This BIO will either be one created in the
212 * perl library, in which case it will have a perl
213 * SV, otherwise it will have been created internally,
214 * inside OpenSSL. For the 'pushed in', it needs
215 * the reference count decememted. */
216 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
219 arg=new_ref("OpenSSL::BIO",(char *)bio,0);
220 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
225 /* it was pushed in */
228 #if 0 /* This does not need to be done. */
229 if (bio->references < 1)
231 /* decrement the reference count */
238 p5_BIO_sysread(bio,in,num, ...)
257 croak("Offset outside string");
261 if ((num+offset) > olen)
263 SvGROW(in,num+offset+1);
265 memset(&(p[olen]),0,(num+offset)-olen+1);
269 i=BIO_read(bio,p+offset,num);
272 SvCUR_set(in,offset+i);
277 p5_BIO_syswrite(bio,in, ...)
289 len=SvOK(ST(2))?SvIV(ST(2)):in_len;
295 if (-offset > in_len)
296 croak("Offset outside string");
299 else if ((offset >= in_len) && (in_len > 0))
300 croak("Offset outside string");
302 if (len >= (in_len-offset))
308 RETVAL=BIO_write(bio,ptr+offset,len);
319 pr_name("p5_BIO_gets");
321 PUSHs(sv_newmortal());
322 sv_setpvn(ST(0),"",0);
325 i=BIO_gets(bio,p,1024);
333 RETVAL=BIO_flush(bio);
341 RETVAL=bio->method->name;
356 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
359 arg=new_ref("OpenSSL::BIO",(char *)bio,0);
360 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
379 RETVAL=BIO_puts(bio,ptr);
384 p5_BIO_set_callback(bio,cb,...)
392 croak("Usage: OpenSSL::BIO::set_callback(bio,callback[,arg]");
395 arg2=sv_mortalcopy(ST(2));
397 BIO_set_ex_data(bio,p5_bio_ex_bio_callback_data,
400 arg=sv_mortalcopy(ST(1));
402 BIO_set_ex_data(bio,p5_bio_ex_bio_callback,(char *)arg);
403 printf("%08lx < bio_ptr\n",BIO_get_ex_data(bio,p5_bio_ex_bio_ptr));
404 BIO_set_callback(bio,p5_bio_callback);
412 pr_name_d("p5_BIO_DESTROY",bio->references);
413 printf("p5_BIO_DESTROY <%s> %d\n",bio->method->name,bio->references);
414 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,NULL);
418 p5_BIO_set_ssl(bio,ssl)
422 pr_name("p5_BIO_set_ssl");
424 RETVAL=BIO_set_ssl(bio,ssl,BIO_CLOSE);
429 p5_BIO_number_read(bio)
432 RETVAL=BIO_number_read(bio);
437 p5_BIO_number_written(bio)
440 RETVAL=BIO_number_written(bio);
445 p5_BIO_references(bio)
448 RETVAL=bio->references;