Perl code patch contributed by "Kurt J. Pires" <kjpires@iat.com>
[openssl.git] / perl / openssl_ssl.xs
index 0583479..146c1ac 100644 (file)
@@ -1,4 +1,5 @@
-#include "p5SSLeay.h"
+
+#include "openssl.h"
 
 static int p5_ssl_ex_ssl_ptr=0;
 static int p5_ssl_ex_ssl_info_callback=0;
@@ -44,7 +45,7 @@ int ret;
 int boot_ssl()
        {
        p5_ssl_ex_ssl_ptr=              
-               SSL_get_ex_new_index(0,"SSLeay::SSL",ex_new,NULL,ex_cleanup);
+               SSL_get_ex_new_index(0,"OpenSSL::SSL",ex_new,NULL,ex_cleanup);
        p5_ssl_ex_ssl_info_callback=
                SSL_get_ex_new_index(0,"ssl_info_callback",NULL,NULL,
                        ex_cleanup);
@@ -57,8 +58,9 @@ int boot_ssl()
        return(1);
        }
 
-MODULE =  SSLeay::SSL  PACKAGE = SSLeay::SSL::CTX PREFIX = p5_SSL_CTX_
+MODULE =  OpenSSL::SSL PACKAGE = OpenSSL::SSL::CTX PREFIX = p5_SSL_CTX_
 
+PROTOTYPES: ENABLE
 VERSIONCHECK: DISABLE
 
 void
@@ -70,11 +72,11 @@ p5_SSL_CTX_new(...)
        PPCODE:
                pr_name("p5_SSL_CTX_new");
                if ((items == 1) && SvPOK(ST(0)))
-                       method=SvPV(ST(0),na);
+                       method=SvPV_nolen(ST(0));
                else if ((items == 2) && SvPOK(ST(1)))
-                       method=SvPV(ST(1),na);
+                       method=SvPV_nolen(ST(1));
                else
-                       croak("Usage: SSLeay::SSL_CTX::new(type)");
+                       croak("Usage: OpenSSL::SSL::CTX::new(type)");
                        
                if (strcmp(method,"SSLv3") == 0)
                        meth=SSLv3_method();
@@ -94,14 +96,20 @@ p5_SSL_CTX_new(...)
                        meth=SSLv2_client_method();
                else if (strcmp(method,"SSLv2_server") == 0)
                        meth=SSLv2_server_method();
+               else if (strcmp(method,"TLSv1") == 0)
+                       meth=TLSv1_method();
+               else if (strcmp(method,"TLSv1_client") == 0)
+                       meth=TLSv1_client_method();
+               else if (strcmp(method,"TLSv1_server") == 0)
+                       meth=TLSv1_server_method();
                else
                        {
-                       croak("Not passed a valid SSL method name, should be 'SSLv[23] [client|server]'");
+                       croak("Not a valid SSL method name, should be 'SSLv[23] [client|server]'");
                        }
                EXTEND(sp,1);
                PUSHs(sv_newmortal());
                ctx=SSL_CTX_new(meth);
-               sv_setref_pv(ST(0), "SSLeay::SSL::CTX", (void*)ctx);
+               sv_setref_pv(ST(0), "OpenSSL::SSL::CTX", (void*)ctx);
 
 int
 p5_SSL_CTX_use_PrivateKey_file(ctx,file,...)
@@ -113,10 +121,10 @@ p5_SSL_CTX_use_PrivateKey_file(ctx,file,...)
        CODE:
                pr_name("p5_SSL_CTX_use_PrivateKey_file");
                if (items > 3)
-                       croak("SSLeay::SSL::CTX::use_PrivateKey_file(ssl_ctx,file[,type])");
+                       croak("OpenSSL::SSL::CTX::use_PrivateKey_file(ssl_ctx,file[,type])");
                if (items == 3)
                        {
-                       ptr=SvPV(ST(2),na);
+                       ptr=SvPV_nolen(ST(2));
                        if (strcmp(ptr,"der") == 0)
                                i=SSL_FILETYPE_ASN1;
                        else
@@ -139,8 +147,8 @@ p5_SSL_CTX_set_options(ctx,...)
                for (i=1; i<items; i++)
                        {
                        if (!SvPOK(ST(i)))
-                               croak("Usage: SSLeay::SSL_CTX::set_options(ssl_ctx[,option,value]+)");
-                       ptr=SvPV(ST(i),na);
+                               croak("Usage: OpenSSL::SSL_CTX::set_options(ssl_ctx[,option,value]+)");
+                       ptr=SvPV_nolen(ST(i));
                        if (strcmp(ptr,"-info_callback") == 0)
                                {
                                SSL_CTX_set_info_callback(ctx,
@@ -154,7 +162,7 @@ p5_SSL_CTX_set_options(ctx,...)
                                }
                        else
                                {
-                               croak("SSLeay::SSL_CTX::set_options(): unknown option");
+                               croak("OpenSSL::SSL_CTX::set_options(): unknown option");
                                }
                        }
 
@@ -167,7 +175,7 @@ p5_SSL_CTX_DESTROY(ctx)
                pr_name_d("p5_SSL_CTX_DESTROY",ctx->references);
                SSL_CTX_free(ctx);
 
-MODULE =  SSLeay::SSL  PACKAGE = SSLeay::SSL PREFIX = p5_SSL_
+MODULE =  OpenSSL::SSL PACKAGE = OpenSSL::SSL PREFIX = p5_SSL_
 
 void
 p5_SSL_new(...)
@@ -175,30 +183,29 @@ p5_SSL_new(...)
                SV *sv_ctx;
                SSL_CTX *ctx;
                SSL *ssl;
-               int i;
                SV *arg;
        PPCODE:
                pr_name("p5_SSL_new");
                if ((items != 1) && (items != 2))
-                       croak("Usage: SSLeay::SSL::new(ssl_ctx)");
-               if (sv_derived_from(ST(items-1),"SSLeay::SSL::CTX"))
+                       croak("Usage: OpenSSL::SSL::new(ssl_ctx)");
+               if (sv_derived_from(ST(items-1),"OpenSSL::SSL::CTX"))
                        {
                        IV tmp = SvIV((SV*)SvRV(ST(items-1)));
                        ctx=(SSL_CTX *)tmp;
                        sv_ctx=ST(items-1);
                        }
                else
-                       croak("ssl_ctx is not of type SSLeay::SSL::CTX");
+                       croak("ssl_ctx is not of type OpenSSL::SSL::CTX");
 
                EXTEND(sp,1);
                PUSHs(sv_newmortal());
                ssl=SSL_new(ctx);
-               sv_setref_pv(ST(0), "SSLeay::SSL", (void*)ssl);
+               sv_setref_pv(ST(0), "OpenSSL::SSL", (void*)ssl);
 
                /* Now this is being a little hairy, we keep a pointer to
                 * our perl reference.  We need to do a different one
-                * to the one we return because it will have it's reference
-                * count droped to 0 apon return and if we up its reference
+                * to the one we return because it will have its reference
+                * count dropped to 0 upon return and if we up its reference
                 * count, it will never be DESTROYED */
                arg=newSVsv(ST(0));
                SSL_set_ex_data(ssl,p5_ssl_ex_ssl_ptr,(char *)arg);
@@ -317,8 +324,8 @@ p5_SSL_set_options(ssl,...)
                for (i=1; i<items; i++)
                        {
                        if (!SvPOK(ST(i)))
-                               croak("Usage: SSLeay::SSL::set_options(ssl[,option,value]+)");
-                       ptr=SvPV(ST(i),na);
+                               croak("Usage: OpenSSL::SSL::set_options(ssl[,option,value]+)");
+                       ptr=SvPV_nolen(ST(i));
                        if (strcmp(ptr,"-info_callback") == 0)
                                {
                                SSL_set_info_callback(ssl,
@@ -339,7 +346,7 @@ p5_SSL_set_options(ssl,...)
                                }
                        else
                                {
-                               croak("SSLeay::SSL::set_options(): unknown option");
+                               croak("OpenSSL::SSL::set_options(): unknown option");
                                }
                        }
 
@@ -362,7 +369,9 @@ p5_SSL_DESTROY(ssl)
        SSL *ssl;
        CODE:
        pr_name_dd("p5_SSL_DESTROY",ssl->references,ssl->ctx->references);
+#ifdef DEBUG
        fprintf(stderr,"SSL_DESTROY %d\n",ssl->references);
+#endif
        SSL_free(ssl);
 
 int
@@ -421,7 +430,7 @@ p5_SSL_get_peer_certificate(ssl)
        OUTPUT:
                RETVAL
 
-MODULE =  SSLeay::SSL  PACKAGE = SSLeay::SSL::CIPHER PREFIX = p5_SSL_CIPHER_
+MODULE =  OpenSSL::SSL PACKAGE = OpenSSL::SSL::CIPHER PREFIX = p5_SSL_CIPHER_
 
 int
 p5_SSL_CIPHER_get_bits(sc)
@@ -452,7 +461,7 @@ p5_SSL_CIPHER_get_name(sc)
        OUTPUT:
                RETVAL
 
-MODULE =  SSLeay::SSL  PACKAGE = SSLeay::BIO PREFIX = p5_BIO_
+MODULE =  OpenSSL::SSL PACKAGE = OpenSSL::BIO PREFIX = p5_BIO_
 
 void
 p5_BIO_get_ssl(bio)
@@ -468,7 +477,7 @@ p5_BIO_get_ssl(bio)
                        ret=sv_mortalcopy(ret);
                        }
                else
-                       ret= &sv_undef;
+                       ret= &PL_sv_undef;
                EXTEND(sp,1);
                PUSHs(ret);