JSS_throwMsg(env, SOCKET_EXCEPTION, "PR_NewTCPSocket() returned NULL");
JSS_throwMsgPrErr(env, SOCKET_EXCEPTION, "PR_NewTCPSocket() returned NULL");
Java_org_mozilla_jss_ssl_SocketBase_socketCreate(JNIEnv *env, jobject self,    jobject sockObj, jobject certApprovalCallback,    jobject clientCertSelectionCallback){    jbyteArray sdArray = NULL;    JSSL_SocketData *sockdata;    SECStatus status;    PRFileDesc *newFD;    /* create a TCP socket */    newFD = PR_NewTCPSocket();    if( newFD == NULL ) {        JSS_throwMsg(env, SOCKET_EXCEPTION, "PR_NewTCPSocket() returned NULL");        goto finish;    }    sockdata = JSSL_CreateSocketData(env, sockObj, newFD);    if( sockdata == NULL ) {        goto finish;    }    /* enable SSL on the socket */    sockdata->fd = SSL_ImportFD(NULL, sockdata->fd);    if( sockdata->fd == NULL ) {        JSS_throwMsg(env, SOCKET_EXCEPTION, "SSL_ImportFD() returned NULL");        goto finish;    }    status = SSL_OptionSet(sockdata->fd, SSL_SECURITY, PR_TRUE);    if( status != SECSuccess ) {        JSS_throwMsg(env, SOCKET_EXCEPTION,            "Unable to enable SSL security on socket");        goto finish;    }    /* setup the handshake callback */    status = SSL_HandshakeCallback(sockdata->fd, JSSL_HandshakeCallback,                                    sockdata);    if( status != SECSuccess ) {        JSS_throwMsg(env, SOCKET_EXCEPTION,            "Unable to install handshake callback");    }    /* setup the cert authentication callback */    if( certApprovalCallback != NULL ) {        /* create global reference to the callback object */        sockdata->certApprovalCallback =            (*env)->NewGlobalRef(env, certApprovalCallback);        if( sockdata->certApprovalCallback == NULL ) goto finish;        /* install the Java callback */        status = SSL_AuthCertificateHook(            sockdata->fd, JSSL_JavaCertAuthCallback,            (void*) sockdata->certApprovalCallback);    } else {        /* install the default callback */        status = SSL_AuthCertificateHook(                    sockdata->fd, JSSL_DefaultCertAuthCallback, NULL);    }    if( status != SECSuccess ) {        JSS_throwMsg(env, SOCKET_EXCEPTION,            "Unable to install certificate authentication callback");        goto finish;    }    /* setup the client cert selection callback */    if( clientCertSelectionCallback != NULL ) {        /* create a new global ref */        sockdata->clientCertSelectionCallback =            (*env)->NewGlobalRef(env, clientCertSelectionCallback);        if(sockdata->clientCertSelectionCallback == NULL)  goto finish;        /* install the Java callback */        status = SSL_GetClientAuthDataHook(            sockdata->fd, JSSL_CallCertSelectionCallback,            (void*) sockdata->clientCertSelectionCallback);        if( status != SECSuccess ) {            JSS_throwMsg(env, SOCKET_EXCEPTION,                "Unable to install client certificate selection callback");            goto finish;        }    }    /* pass the pointer back to Java */    sdArray = JSS_ptrToByteArray(env, (void*) sockdata);       if( sdArray == NULL ) {        /* exception was thrown */        goto finish;    }finish:    if( (*env)->ExceptionOccurred(env) != NULL ) {        if( sockdata != NULL ) {            JSSL_DestroySocketData(env, sockdata);        }    } else {        PR_ASSERT( sdArray != NULL );    }    return sdArray;}