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);
28 XPUSHs(sv_2mortal(newSViv(me)));
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,
65 p5_bio_ex_bio_callback=
66 BIO_get_ex_new_index(0,"bio_callback",NULL,NULL,
68 p5_bio_ex_bio_callback_data=
69 BIO_get_ex_new_index(0,"bio_callback_data",NULL,NULL,
74 MODULE = SSLeay::BIO PACKAGE = SSLeay::BIO PREFIX = p5_BIO_
79 p5_BIO_new_buffer_ssl_connect(...)
92 if ((arg == NULL) || !(sv_derived_from(arg,"SSLeay::SSL::CTX")))
93 croak("Usage: SSLeay::BIO::new_buffer_ssl_connect(SSL_CTX)");
96 IV tmp=SvIV((SV *)SvRV(arg));
100 bio=BIO_new_buffer_ssl_connect(ctx);
101 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
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=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
137 pr_name("p5_BIO_new");
138 if ((items == 1) && SvPOK(ST(0)))
140 else if ((items == 2) && SvPOK(ST(1)))
143 croak("Usage: SSLeay::BIO::new(type)");
146 if (strcmp(type,"connect") == 0)
147 bio=BIO_new(BIO_s_connect());
148 else if (strcmp(type,"accept") == 0)
149 bio=BIO_new(BIO_s_accept());
150 else if (strcmp(type,"ssl") == 0)
151 bio=BIO_new(BIO_f_ssl());
152 else if (strcmp(type,"buffer") == 0)
153 bio=BIO_new(BIO_f_buffer());
155 croak("unknown BIO type");
156 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
160 p5_BIO_hostname(bio,name)
164 RETVAL=BIO_set_conn_hostname(bio,name);
169 p5_BIO_set_accept_port(bio,str)
173 RETVAL=BIO_set_accept_port(bio,str);
178 p5_BIO_do_handshake(bio)
181 RETVAL=BIO_do_handshake(bio);
190 /* This reference will be reduced when the reference is
191 * let go, and then when the BIO_free_all() is called
192 * inside the SSLeay library by the BIO with this
195 RETVAL=BIO_push(b,bio);
210 /* This BIO will either be one created in the
211 * perl library, in which case it will have a perl
212 * SV, otherwise it will have been created internally,
213 * inside SSLeay. For the 'pushed in', it needs
214 * the reference count decememted. */
215 arg=(SV *)BIO_get_ex_data(bio,p5_bio_ex_bio_ptr);
218 arg=new_ref("SSLeay::BIO",(char *)bio,0);
219 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
224 /* it was pushed in */
227 #if 0 /* This does not need to be done. */
228 if (bio->references < 1)
230 /* decrement the reference count */
237 p5_BIO_sysread(bio,in,num, ...)
256 croak("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);
359 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,(char *)arg);
378 RETVAL=BIO_puts(bio,ptr);
383 p5_BIO_set_callback(bio,cb,...)
391 croak("Usage: SSLeay::BIO::set_callback(bio,callback[,arg]");
394 arg2=sv_mortalcopy(ST(2));
396 BIO_set_ex_data(bio,p5_bio_ex_bio_callback_data,
399 arg=sv_mortalcopy(ST(1));
401 BIO_set_ex_data(bio,p5_bio_ex_bio_callback,(char *)arg);
402 printf("%08lx < bio_ptr\n",BIO_get_ex_data(bio,p5_bio_ex_bio_ptr));
403 BIO_set_callback(bio,p5_bio_callback);
411 pr_name_d("p5_BIO_DESTROY",bio->references);
412 printf("p5_BIO_DESTROY <%s> %d\n",bio->method->name,bio->references);
413 BIO_set_ex_data(bio,p5_bio_ex_bio_ptr,NULL);
417 p5_BIO_set_ssl(bio,ssl)
421 pr_name("p5_BIO_set_ssl");
423 RETVAL=BIO_set_ssl(bio,ssl,BIO_CLOSE);
428 p5_BIO_number_read(bio)
431 RETVAL=BIO_number_read(bio);
436 p5_BIO_number_written(bio)
439 RETVAL=BIO_number_written(bio);
444 p5_BIO_references(bio)
447 RETVAL=bio->references;