/***************************************************************************
                            KSSLCertificate.cpp -  description
                             -------------------
    begin                : Sun Jan 27 16:22:17 2002
    copyright            : (C) 2000-2001 Lost Highway Ltd.
    email                : Richard_Dale@tipitina.demon.co.uk
    generated by         : duke@tipitina on Sun Jan 27 16:22:17 2002, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
***************************************************************************/

#define _BOOL_H_
#include <ksslcertificate.h>
#include <qstring.h>
#include <qcstring.h>

#include <qtjava/QtSupport.h>
#include <kdejava/KDESupport.h>
#include <kdejava/KSSLCertificate.h>

class KSSLCertificateJBridge : public KSSLCertificate
{
public:
	~KSSLCertificateJBridge() {QtSupport::qtKeyDeleted(this);}
	KSSLCertificateJBridge(const KSSLCertificate& x) : KSSLCertificate(x) {}
	KSSLCertificateJBridge() : KSSLCertificate() {}
	void protected_setCert(X509* c) {
		KSSLCertificate::setCert(c);
		return;
	}
	void protected_setChain(void* c) {
		KSSLCertificate::setChain(c);
		return;
	}
	X509 * protected_getCert() {
		return (X509 *) KSSLCertificate::getCert();
	}
	KSSLValidation  protected_processError(int ec) {
		return (KSSLValidation ) KSSLCertificate::processError(ec);
	}
};


JNIEXPORT void JNICALL
Java_org_kde_koala_KSSLCertificate_finalize(JNIEnv *env, jobject obj)
{
	if (QtSupport::allocatedInJavaWorld(env, obj)) {
		delete (KSSLCertificate*)QtSupport::getQt(env, obj);
		QtSupport::setQt(env, obj, 0);
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_KSSLCertificate_dispose(JNIEnv *env, jobject obj)
{
	Java_org_kde_koala_KSSLCertificate_finalize(env, obj);
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_KSSLCertificate_isDisposed(JNIEnv *env, jobject obj)
{
	return (QtSupport::getQt(env, obj) == 0);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_toString(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->toString();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getSubject(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getSubject();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getIssuer(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getIssuer();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getNotBefore(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getNotBefore();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getNotAfter(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getNotAfter();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_KSSLCertificate_getQDTNotBefore(JNIEnv *env, jobject obj)
{
	QDateTime  _qdate;
	_qdate = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getQDTNotBefore();
	return (jobject) QtSupport::fromQDateTime(env, (QDateTime *) &_qdate);
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_KSSLCertificate_getQDTNotAfter(JNIEnv *env, jobject obj)
{
	QDateTime  _qdate;
	_qdate = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getQDTNotAfter();
	return (jobject) QtSupport::fromQDateTime(env, (QDateTime *) &_qdate);
}

JNIEXPORT jbyteArray JNICALL
Java_org_kde_koala_KSSLCertificate_toDer(JNIEnv *env, jobject obj)
{
	QByteArray  _qbyteArray;
	_qbyteArray = ((KSSLCertificate*) QtSupport::getQt(env, obj))->toDer();
	return QtSupport::fromQByteArray(env, &_qbyteArray);
}

JNIEXPORT jbyteArray JNICALL
Java_org_kde_koala_KSSLCertificate_toPem(JNIEnv *env, jobject obj)
{
	QByteArray  _qbyteArray;
	_qbyteArray = ((KSSLCertificate*) QtSupport::getQt(env, obj))->toPem();
	return QtSupport::fromQByteArray(env, &_qbyteArray);
}

JNIEXPORT jbyteArray JNICALL
Java_org_kde_koala_KSSLCertificate_toNetscape(JNIEnv *env, jobject obj)
{
	QByteArray  _qbyteArray;
	_qbyteArray = ((KSSLCertificate*) QtSupport::getQt(env, obj))->toNetscape();
	return QtSupport::fromQByteArray(env, &_qbyteArray);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_toText(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->toText();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getSerialNumber(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getSerialNumber();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getKeyType(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getKeyType();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getPublicKeyText(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getPublicKeyText();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getMD5DigestText(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getMD5DigestText();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_getSignatureText(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((KSSLCertificate*) QtSupport::getQt(env, obj))->getSignatureText();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_KSSLCertificate_isValid(JNIEnv *env, jobject obj)
{
	return (jboolean) ((KSSLCertificate*) QtSupport::getQt(env, obj))->isValid();
}

JNIEXPORT jint JNICALL
Java_org_kde_koala_KSSLCertificate_validate(JNIEnv *env, jobject obj)
{
	return (jint) ((KSSLCertificate*) QtSupport::getQt(env, obj))->validate();
}

JNIEXPORT jint JNICALL
Java_org_kde_koala_KSSLCertificate_revalidate(JNIEnv *env, jobject obj)
{
	return (jint) ((KSSLCertificate*) QtSupport::getQt(env, obj))->revalidate();
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_KSSLCertificate_chain(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)(KSSLCertChain *) &((KSSLCertificate*) QtSupport::getQt(env, obj))->chain(), "org.kde.koala.KSSLCertChain");
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_KSSLCertificate_replicate(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)((KSSLCertificate*) QtSupport::getQt(env, obj))->replicate(), "org.kde.koala.KSSLCertificate");
}

JNIEXPORT void JNICALL
Java_org_kde_koala_KSSLCertificate_newKSSLCertificate__(JNIEnv *env, jobject obj, jobject x)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new KSSLCertificateJBridge((KSSLCertificate&) *(KSSLCertificate *) QtSupport::getQt(env, x)));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_KSSLCertificate_setCert(JNIEnv *env, jobject obj, jstring cert)
{
static QString * _qstring_cert = 0;
	return (jboolean) ((KSSLCertificate*) QtSupport::getQt(env, obj))->setCert((QString&) * (QString *) QtSupport::toQString(env, cert, &_qstring_cert));
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_KSSLCertificate_x509V3Extensions(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)(KSSLX509V3 *) &((KSSLCertificate*) QtSupport::getQt(env, obj))->x509V3Extensions(), "org.kde.koala.KSSLX509V3");
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_KSSLCertificate_isSigner(JNIEnv *env, jobject obj)
{
	return (jboolean) ((KSSLCertificate*) QtSupport::getQt(env, obj))->isSigner();
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_KSSLCertificate_fromString(JNIEnv *env, jclass obj, jstring cert)
{
static QCString * _qcstring_cert = 0;
	return (jobject) QtSupport::objectForQtKey(env, (void *)KSSLCertificateJBridge::fromString((QCString) * (QCString *) QtSupport::toQCString(env, cert, &_qcstring_cert)), "org.kde.koala.KSSLCertificate");
}

//JNIEXPORT jobject JNICALL
//Java_org_kde_koala_KSSLCertificate_fromX509(JNIEnv *env, jclass obj, j x5)
//{
//	return (jobject) QtSupport::objectForQtKey(env, (void *)KSSLCertificateJBridge::fromX509((X509*) x5), "org.kde.koala.KSSLCertificate");
//}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_KSSLCertificate_verifyText(JNIEnv *env, jclass obj, jint x)
{
	QString  _qstring;
	_qstring = KSSLCertificateJBridge::verifyText((KSSLCertificate::KSSLValidation) x);
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT void JNICALL
Java_org_kde_koala_KSSLCertificate_newKSSLCertificate(JNIEnv *env, jobject obj)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new KSSLCertificateJBridge());
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

//JNIEXPORT void JNICALL
//Java_org_kde_koala_KSSLCertificate_setCert__(JNIEnv *env, jobject obj, j c)
//{
//	((KSSLCertificateJBridge*) QtSupport::getQt(env, obj))->protected_setCert((X509*) c);
//	return;
//}

JNIEXPORT void JNICALL
Java_org_kde_koala_KSSLCertificate_setChain(JNIEnv *env, jobject obj, jint c)
{
	((KSSLCertificateJBridge*) QtSupport::getQt(env, obj))->protected_setChain((void*) c);
	return;
}

//JNIEXPORT  JNICALL
//Java_org_kde_koala_KSSLCertificate_getCert(JNIEnv *env, jobject obj)
//{
//	return () ((KSSLCertificateJBridge*) QtSupport::getQt(env, obj))->protected_getCert();
//}

JNIEXPORT jint JNICALL
Java_org_kde_koala_KSSLCertificate_processError(JNIEnv *env, jobject obj, jint ec)
{
	return (jint) ((KSSLCertificateJBridge*) QtSupport::getQt(env, obj))->protected_processError((int) ec);
}

