view ui/certificatelist.cpp @ 145:27ebd96798c4

Fixed mox error ranges -- return codes can only use 8 bit.
author Sascha Wilde <wilde@intevation.de>
date Mon, 24 Mar 2014 16:25:32 +0100
parents e478deca18f5
children 60c5df8e7980
line wrap: on
line source
#include "certificatelist.h"

#include <QDebug>

#define PARSER_VERSION "1"

CertificateList::CertificateList() : mStatus(NoList)
{
}

list_status_t CertificateList::readList(const char *fileName)
{
    char *data = NULL;
    size_t size = 0;

    mStatus = read_and_verify_list(fileName, &data, &size);

    if (!isValid()) {
        return mStatus;
    }

    // Take the data into the Qt Universe where memory is plentiful
    // and CPU's are fast :)
    mData = QString::fromLatin1(data, size);
    free(data);
    data = NULL;
    QStringList lines = mData.split("\n");

    for (int i = 0; i < lines.size(); ++i) {
        QString curLine = lines[i].trimmed();
        if (curLine.startsWith("F:")) {
            if (curLine.right(1) != PARSER_VERSION) {
                qDebug() << "Invalid Format Version";
                mStatus = IncompatibleVersion;
                return mStatus;
            }
        } else if (curLine.startsWith("D:")) {
            bool ok = false;
            qlonglong timestamp = 0;

            curLine.remove(0, 2);
            timestamp = curLine.toLongLong(&ok);
            if (!ok) {
                qDebug() << "Invalid Date";
                mStatus = InvalidFormat;
                return mStatus;
            }

            mDate = QDateTime::fromMSecsSinceEpoch(timestamp * 1000);
        } else if (curLine.startsWith("I:")) {
            mCertificatesInstall << Certificate(curLine);
        } else if (curLine.startsWith("R:")) {
            mCertificatesRemove << Certificate(curLine);
        } else if (curLine.startsWith("S:")) {
            // Signature is verified in read_and_verify_list
            continue;
        } else if (!curLine.isEmpty()){
            qDebug () << "Don't know how to handle: " << curLine;
        }
    }
    return mStatus;
}

CertificateList::CertificateList(const char *fileName) : mStatus(NoList)
{
    readList(fileName);
}

const QList<Certificate>& CertificateList::getInstallCertificates() const {
    return mCertificatesInstall;
}

const QList<Certificate>& CertificateList::getRemoveCertificates() const {
    return mCertificatesRemove;
}

http://wald.intevation.org/projects/trustbridge/