3 static int p5_bio_ex_bio_ptr=0;
4 static int p5_bio_ex_bio_callback=0;
5 static int p5_bio_ex_bio_callback_data=0;
7 static long p5_bio_callback(bio,state,parg,cmd,larg,ret)
18 me=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
19 cb=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_callback);
29 XPUSHs(sv_2mortal(newSViv(state)));
30 XPUSHs(sv_2mortal(newSViv(cmd)));
31 if ((state == BIO_CB_READ) || (state == BIO_CB_WRITE))
33 XPUSHs(sv_2mortal(newSVpv(parg,larg)));
38 XPUSHs(sv_2mortal(newSViv(larg)));
39 XPUSHs(sv_2mortal(newSViv(ret)));
42 i=perl_call_sv(cb,G_SCALAR);
55 croak("Internal error in SSL p5_ssl_info_callback");
63 BIO_get_ex_new_index(0,"SSLeay::BIO",ex_new,NULL,ex_cleanup);
64 p5_bio_ex_bio_callback=
65 BIO_get_ex_new_index(0,"bio_callback",NULL,NULL,
67 p5_bio_ex_bio_callback_data=
68 BIO_get_ex_new_index(0,"bio_callback_data",NULL,NULL,
73 MODULE = SSLeay::BIO PACKAGE = SSLeay::BIO PREFIX = p5_BIO_
78 p5_BIO_new_buffer_ssl_connect(...)
91 if ((arg == NULL) || !(sv_derived_from(arg,"SSLeay::SSL::CTX")))
92 croak("Usage: SSLeay::BIO::new_buffer_ssl_connect(SSL_CTX)");
95 IV tmp=SvIV((SV *)SvRV(arg));
99 bio=BIO_new_buffer_ssl_connect(ctx);
100 arg=new_ref("SSLeay::BIO",(char *)bio,0);
102 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
105 p5_BIO_new_ssl_connect(...)
118 if ((arg == NULL) || !(sv_derived_from(arg,"SSLeay::SSL::CTX")))
119 croak("Usage: SSLeay::BIO::new_ssl_connect(SSL_CTX)");
122 IV tmp=SvIV((SV *)SvRV(arg));
126 bio=BIO_new_ssl_connect(ctx);
127 arg=new_ref("SSLeay::BIO",(char *)bio,0);
129 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
138 pr_name("p5_BIO_new");
139 if ((items == 1) && SvPOK(ST(0)))
141 else if ((items == 2) && SvPOK(ST(1)))
144 croak("Usage: SSLeay::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=new_ref("SSLeay::BIO",(char *)bio,0);
159 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
162 p5_BIO_hostname(bio,name)
166 RETVAL=BIO_set_hostname(bio,name);
171 p5_BIO_set_accept_port(bio,str)
175 RETVAL=BIO_set_accept_port(bio,str);
180 p5_BIO_do_handshake(bio)
183 RETVAL=BIO_do_handshake(bio);
192 /* This reference will be reduced when the reference is
193 * let go, and then when the BIO_free_all() is called
194 * inside the SSLeay library by the BIO with this
197 RETVAL=BIO_push(b,bio);
212 /* This BIO will either be one created in the
213 * perl library, in which case it will have a perl
214 * SV, otherwise it will have been created internally,
215 * inside SSLeay. For the 'pushed in', it needs
216 * the reference count decememted. */
217 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
220 arg=new_ref("SSLeay::BIO",(char *)bio,0);
222 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
226 /* it was pushed in */
229 if (bio->references < 1)
231 /* decrement the reference count */
237 p5_BIO_sysread(bio,in,num, ...)
256 croad("Offset outside string");
260 if ((num+offset) > olen)
262 SvGROW(in,num+offset+1);
264 memset(&(p[olen]),0,(num+offset)-olen+1);
268 i=BIO_read(bio,p+offset,num);
271 SvCUR_set(in,offset+i);
276 p5_BIO_syswrite(bio,in, ...)
288 len=SvOK(ST(2))?SvIV(ST(2)):in_len;
294 if (-offset > in_len)
295 croak("Offset outside string");
298 else if ((offset >= in_len) && (in_len > 0))
299 croak("Offset outside string");
301 if (len >= (in_len-offset))
307 RETVAL=BIO_write(bio,ptr+offset,len);
318 pr_name("p5_BIO_gets");
320 PUSHs(sv_newmortal());
321 sv_setpvn(ST(0),"",0);
324 i=BIO_gets(bio,p,1024);
332 RETVAL=BIO_flush(bio);
340 RETVAL=bio->method->name;
355 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
358 arg=new_ref("SSLeay::BIO",(char *)bio,0);
360 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
377 RETVAL=BIO_puts(bio,ptr);
382 p5_BIO_set_callback(bio,cb,...)
390 croak("Usage: SSLeay::BIO::set_callback(bio,callback[,arg]");
393 arg2=sv_mortalcopy(ST(2));
395 BIO_set_ex_data(bio,p5_bio_ex_bio_callback_data,
398 arg=sv_mortalcopy(ST(1));
400 BIO_set_ex_data(bio,p5_bio_ex_bio_callback,(char *)arg);
401 BIO_set_callback(bio,p5_bio_callback);
409 pr_name_d("p5_BIO_DESTROY",bio->references);
410 printf("p5_BIO_DESTROY <%s> %d\n",bio->method->name,bio->references);
411 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,NULL);
415 p5_BIO_set_ssl(bio,ssl)
419 pr_name("p5_BIO_set_ssl");
421 RETVAL=BIO_set_ssl(bio,ssl,BIO_CLOSE);
426 p5_BIO_number_read(bio)
429 RETVAL=BIO_number_read(bio);
434 p5_BIO_number_written(bio)
437 RETVAL=BIO_number_written(bio);
442 p5_BIO_references(bio)
445 RETVAL=bio->references;