#include "archive_parser.h" #include #include #include Archive::Archive(QString outbox_filename, ArchiveType archive_type) : outbox_filename(outbox_filename), archive_type(archive_type) {} Archive::InitError Archive::init() { QFile outbox_file(outbox_filename); if (!outbox_file.open(QIODevice::ReadOnly | QIODevice::Text)) return FailedOpeningFile; QJsonParseError json_error; QJsonDocument outbox_json_document = QJsonDocument::fromJson(outbox_file.readAll(), &json_error); outbox_file.close(); if (json_error.error != QJsonParseError::NoError) return JsonParseError; if (outbox_json_document.isEmpty()) return JsonEmpty; if (outbox_json_document.isNull()) return JsonNull; if (outbox_json_document.isObject()) outbox_json = new QJsonObject (outbox_json_document.object()); else return JsonNotObject; // Do some more throughful checks to make sure that the JSON is actually valid. if (not (outbox_json->contains("@context") and outbox_json->value("@context").isString() and (outbox_json->value("@context").toString() == "https://www.w3.org/ns/activitystreams"))) return JsonNotActivityStream; if (outbox_json->contains("orderedItems") and outbox_json->value("orderedItems").isArray()) { outbox_items = new QJsonArray(outbox_json->value("orderedItems").toArray()); // we'll need it during Archive's lifetime } return NoError; } Archive::~Archive() { delete outbox_json; outbox_json = nullptr; delete outbox_items; outbox_items = nullptr; }