mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Get rid of filename2bytearray and QString2filename
We now use QFile or its derivate XFile, who smoothly handle unicode filenames also on windows. The lt_dlopen() only handles "char *" not wchar_t. Try to convert the filename with all known codecs until we can open it. filename2QString() remains to differently encode filenames provided on the commandline on Windows.
This commit is contained in:
parent
2d0980d4f6
commit
500f11c9b3
@ -301,15 +301,6 @@ QString getFullFilename(const QString & filename, const QString & selectedFilter
|
||||
return rv;
|
||||
}
|
||||
|
||||
QByteArray filename2bytearray(const QString &fname)
|
||||
{
|
||||
#if defined(Q_OS_WIN32)
|
||||
return fname.toLocal8Bit();
|
||||
#else
|
||||
return fname.toUtf8();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString filename2QString(const char *fname)
|
||||
{
|
||||
#if defined(Q_OS_WIN32)
|
||||
|
||||
@ -37,7 +37,6 @@ const QStringList getLibExtensions();
|
||||
QString hostId();
|
||||
|
||||
QString formatHash(const QByteArray &data, QString sep = ":", int width = 2);
|
||||
QByteArray filename2bytearray(const QString &fname);
|
||||
QString filename2QString(const char *fname);
|
||||
QString compressFilename(QString filename, int maxlen = 50);
|
||||
|
||||
@ -69,8 +68,6 @@ void *d2i_bytearray(void *(*d2i)(void*, unsigned char**, long),
|
||||
#define I2D_VOID(a) ((int (*)(const void *, unsigned char **))(a))
|
||||
#define D2I_VOID(a) ((void *(*)(void *, unsigned char **, long))(a))
|
||||
|
||||
#define QString2filename(str) filename2bytearray(str).constData()
|
||||
|
||||
static inline QString htmlEscape(const QString &html)
|
||||
{
|
||||
#if QT_VERSION < 0x050000
|
||||
|
||||
@ -14,9 +14,38 @@
|
||||
|
||||
#include <openssl/rand.h>
|
||||
#include <QMessageBox>
|
||||
#include <QTextCodec>
|
||||
#include <ltdl.h>
|
||||
#include "ui_SelectToken.h"
|
||||
|
||||
QByteArray find_filecodec(const QString &file)
|
||||
{
|
||||
#if defined(Q_OS_WIN32)
|
||||
QList<QByteArray> codecs = QTextCodec::availableCodecs();
|
||||
QString fil = nativeSeparator(file);
|
||||
|
||||
foreach(QByteArray codec, QTextCodec::availableCodecs())
|
||||
{
|
||||
auto tc = QTextCodec::codecForName(codec);
|
||||
bool can = tc->canEncode(file);
|
||||
int fd = -1;
|
||||
QByteArray fn;
|
||||
if (can) {
|
||||
fn = tc->fromUnicode(fil);
|
||||
fd = open(fn, O_RDONLY);
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
}
|
||||
qDebug() << "TestCodec" << codec << can << fn << fd;
|
||||
if (fd != -1)
|
||||
return fn;
|
||||
}
|
||||
return fil.toLocal8Bit();
|
||||
#else
|
||||
return file.toUtf8();
|
||||
#endif
|
||||
}
|
||||
|
||||
pkcs11_lib::pkcs11_lib(const QString &f)
|
||||
{
|
||||
CK_RV (*c_get_function_list)(CK_FUNCTION_LIST_PTR_PTR);
|
||||
@ -30,7 +59,7 @@ pkcs11_lib::pkcs11_lib(const QString &f)
|
||||
lt_dlinit();
|
||||
|
||||
try {
|
||||
dl_handle = lt_dlopen(QString2filename(file));
|
||||
dl_handle = lt_dlopen(find_filecodec(file));
|
||||
if (dl_handle == NULL)
|
||||
throw errorEx(QObject::tr("Failed to open PKCS11 library: %1: %2").arg(file).arg(lt_dlerror()));
|
||||
|
||||
@ -40,8 +69,7 @@ pkcs11_lib::pkcs11_lib(const QString &f)
|
||||
if (!c_get_function_list)
|
||||
throw errorEx(QObject::tr("This does not look like a PKCS#11 library. Symbol 'C_GetFunctionList' not found."));
|
||||
|
||||
qDebug("Trying to load PKCS#11 provider %s",
|
||||
QString2filename(file));
|
||||
qDebug() << "Trying to load PKCS#11 provider" << file;
|
||||
rv = c_get_function_list(&p11);
|
||||
if (rv != CKR_OK)
|
||||
pk11error("C_GetFunctionList", rv);
|
||||
@ -50,8 +78,7 @@ pkcs11_lib::pkcs11_lib(const QString &f)
|
||||
if (rv != CKR_OK && rv != CKR_CRYPTOKI_ALREADY_INITIALIZED)
|
||||
pk11error("C_Initialize", rv);
|
||||
|
||||
qDebug("Successfully loaded PKCS#11 provider %s",
|
||||
QString2filename(file));
|
||||
qDebug() << "Successfully loaded PKCS#11 provider" << file;
|
||||
} catch (errorEx &err) {
|
||||
load_error = err.getString();
|
||||
WAITCURSOR_END;
|
||||
@ -60,8 +87,7 @@ pkcs11_lib::pkcs11_lib(const QString &f)
|
||||
if (dl_handle)
|
||||
lt_dlclose(dl_handle);
|
||||
lt_dlexit();
|
||||
qDebug("Failed to load PKCS#11 provider %s",
|
||||
QString2filename(file));
|
||||
qDebug() << "Failed to load PKCS#11 provider" << file;
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,11 +97,11 @@ pkcs11_lib::~pkcs11_lib()
|
||||
(void)rv;
|
||||
if (!isLoaded())
|
||||
return;
|
||||
qDebug("Unloading PKCS#11 provider %s", QString2filename(file));
|
||||
qDebug() << "Unloading PKCS#11 provider" << file;
|
||||
CALL_P11_C(this, C_Finalize, NULL);
|
||||
lt_dlclose(dl_handle);
|
||||
lt_dlexit();
|
||||
qDebug("Unloaded PKCS#11 provider %s", QString2filename(file));
|
||||
qDebug() << "Unloaded PKCS#11 provider" << file;
|
||||
}
|
||||
|
||||
QList<unsigned long> pkcs11_lib::getSlotList()
|
||||
|
||||
@ -25,13 +25,9 @@ pki_pkcs7::~pki_pkcs7()
|
||||
PKCS7_free(p7);
|
||||
}
|
||||
|
||||
void pki_pkcs7::encryptFile(pki_x509 *crt, QString filename)
|
||||
void pki_pkcs7::encryptFile(pki_x509 *crt, const QString &filename)
|
||||
{
|
||||
BIO *bio = NULL;
|
||||
bio = BIO_new_file(QString2filename(filename), "r");
|
||||
openssl_error();
|
||||
encryptBio(crt, bio);
|
||||
BIO_free(bio);
|
||||
encryptBio(crt, XFile(filename).bio());
|
||||
}
|
||||
|
||||
void pki_pkcs7::encryptBio(pki_x509 *crt, BIO *bio)
|
||||
@ -81,15 +77,10 @@ void pki_pkcs7::signBio(pki_x509 *crt, BIO *bio)
|
||||
sk_X509_free(certstack);
|
||||
}
|
||||
|
||||
void pki_pkcs7::signFile(pki_x509 *crt, QString filename)
|
||||
void pki_pkcs7::signFile(pki_x509 *crt, const QString &filename)
|
||||
{
|
||||
BIO *bio;
|
||||
if (!crt)
|
||||
return;
|
||||
bio = BIO_new_file(QString2filename(filename), "r");
|
||||
openssl_error();
|
||||
signBio(crt, bio);
|
||||
BIO_free(bio);
|
||||
if (crt)
|
||||
signBio(crt, XFile(filename).bio());
|
||||
}
|
||||
|
||||
void pki_pkcs7::signCert(pki_x509 *crt, pki_x509 *contCert)
|
||||
|
||||
@ -23,15 +23,15 @@ class pki_pkcs7: public pki_base
|
||||
pki_pkcs7(const QString name = "");
|
||||
virtual ~pki_pkcs7();
|
||||
|
||||
void signFile(pki_x509 *crt, QString filename);
|
||||
void signFile(pki_x509 *crt, const QString &filename);
|
||||
void signCert(pki_x509 *crt, pki_x509 *contCert);
|
||||
void encryptFile(pki_x509 *crt, QString filename);
|
||||
void encryptFile(pki_x509 *crt, const QString &filename);
|
||||
void writeP7(XFile &file, bool PEM) const;
|
||||
void fromPEM_BIO(BIO *bio, const QString &name);
|
||||
void fload(const QString &fname);
|
||||
pki_x509 *getCert(int x);
|
||||
void addCert(pki_x509 *crt);
|
||||
int numCert(); // number of certs;
|
||||
int numCert();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -246,7 +246,7 @@ int MainWindow::init_database(QString dbName)
|
||||
QSqlError err;
|
||||
QString oldDbFile;
|
||||
|
||||
qDebug("Opening database: %s", QString2filename(dbName));
|
||||
qDebug() << "Opening database:" << dbName;
|
||||
|
||||
if (checkForOldDbFormat(dbName)) {
|
||||
QString newname = dbName;
|
||||
@ -510,7 +510,7 @@ void MainWindow::close_database()
|
||||
return;
|
||||
}
|
||||
killTimer(dbTimer);
|
||||
qDebug("Closing database: %s", QString2filename(currentDB));
|
||||
qDebug() << "Closing database:" << currentDB;
|
||||
Settings["mw_geometry"] = QString("%1,%2,%3")
|
||||
.arg(size().width())
|
||||
.arg(size().height())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user