Commit 07b9925b authored by Volker Krause's avatar Volker Krause
Browse files

Prepare for supporting other ERA SSB versions as well

Version 1 and 2 seem to be in active use as well, besides the version 3
we already support.
parent edb6fc32
......@@ -32,7 +32,7 @@ set(kitinerary_lib_srcs
engine/extractorscriptengine.cpp
engine/scriptextractor.cpp
era/ssbticket.cpp
era/ssbv3ticket.cpp
extractors/iatabcbpextractor.cpp
......
......@@ -4,7 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "ssbticket.h"
#include "ssbv3ticket.h"
#include <QDebug>
......@@ -18,9 +18,9 @@ enum {
SSB_VERSION = 3,
};
SSBTicket::SSBTicket() = default;
SSBv3Ticket::SSBv3Ticket() = default;
SSBTicket::SSBTicket(const QByteArray &data)
SSBv3Ticket::SSBv3Ticket(const QByteArray &data)
{
if (maybeSSB(data)) {
m_data = data;
......@@ -29,14 +29,14 @@ SSBTicket::SSBTicket(const QByteArray &data)
}
}
SSBTicket::~SSBTicket() = default;
SSBv3Ticket::~SSBv3Ticket() = default;
bool SSBTicket::isValid() const
bool SSBv3Ticket::isValid() const
{
return !m_data.isEmpty();
}
int SSBTicket::readNumber(int start, int length) const
int SSBv3Ticket::readNumber(int start, int length) const
{
if (start < 0 || length < 1 || start / 8 >= m_data.size() || (start + length) / 8 >= m_data.size() || length > 31) {
qWarning() << "invalid SSB read:" << start << length;
......@@ -54,7 +54,7 @@ int SSBTicket::readNumber(int start, int length) const
return num;
}
QString SSBTicket::readString(int start, int length) const
QString SSBv3Ticket::readString(int start, int length) const
{
QString res;
res.resize(length);
......@@ -64,7 +64,7 @@ QString SSBTicket::readString(int start, int length) const
return res;
}
bool SSBTicket::maybeSSB(const QByteArray& data)
bool SSBv3Ticket::maybeSSB(const QByteArray& data)
{
if (data.size() != SSB_DATA_SIZE) {
return false;
......@@ -72,9 +72,9 @@ bool SSBTicket::maybeSSB(const QByteArray& data)
return (data.at(0) >> 4) == SSB_VERSION;
}
QDate SSBTicket::issueDate(const QDate &contextDate)
QDate SSBv3Ticket::issueDate(const QDate &contextDate)
{
if (m_data.isEmpty() || ticketTypeCode() > SSBTicket::RPT) {
if (m_data.isEmpty() || ticketTypeCode() > SSBv3Ticket::RPT) {
return {};
}
......@@ -87,9 +87,9 @@ QDate SSBTicket::issueDate(const QDate &contextDate)
return d;
}
QDate SSBTicket::type1DepartureDay(const QDate& contextDate)
QDate SSBv3Ticket::type1DepartureDay(const QDate& contextDate)
{
if (ticketTypeCode() != SSBTicket::IRT_RES_BOA) {
if (ticketTypeCode() != SSBv3Ticket::IRT_RES_BOA) {
return {};
}
......@@ -97,7 +97,7 @@ QDate SSBTicket::type1DepartureDay(const QDate& contextDate)
return d.addDays(type1DepartureDate());
}
QByteArray SSBTicket::rawData() const
QByteArray SSBv3Ticket::rawData() const
{
return m_data;
}
......@@ -22,10 +22,10 @@ public: \
inline QString Name() const { return readString(Start, Len); } \
Q_PROPERTY(QString Name READ Name)
/** ERA SSB ticket barcode.
/** ERA SSB ticket barcode (version 3).
* @see ERA TAP TSI TD B.12 Digital Security Elements For Rail Passenger Ticketing - §7 SSB - Small Structured Barcode
*/
class KITINERARY_EXPORT SSBTicket {
class KITINERARY_EXPORT SSBv3Ticket {
Q_GADGET
// low-level raw value access
// header
......@@ -112,9 +112,9 @@ class KITINERARY_EXPORT SSBTicket {
Q_PROPERTY(QByteArray rawData READ rawData)
public:
SSBTicket();
explicit SSBTicket(const QByteArray &data);
~SSBTicket();
SSBv3Ticket();
explicit SSBv3Ticket(const QByteArray &data);
~SSBv3Ticket();
/** Returns @c true if this is a valid SSB ticket. */
bool isValid() const;
......@@ -143,5 +143,5 @@ private:
}
Q_DECLARE_METATYPE(KItinerary::SSBTicket)
Q_DECLARE_METATYPE(KItinerary::SSBv3Ticket)
......@@ -6,7 +6,7 @@
#include "barcode.h"
#include "bitarray.h"
#include <era/ssbticket.h>
#include <era/ssbv3ticket.h>
#include <pdf/pdfbarcodeutil_p.h>
#include <KItinerary/BarcodeDecoder>
......@@ -115,7 +115,7 @@ QVariant JsApi::Barcode::decodeVdvTicket(const QVariant &s) const
QVariant JsApi::Barcode::decodeEraSsbTicket(const QVariant &s) const
{
SSBTicket ticket(s.toByteArray());
SSBv3Ticket ticket(s.toByteArray());
return ticket.isValid() ? QVariant::fromValue(ticket) : QVariant();
}
......
......@@ -6,7 +6,7 @@
#include "ssbdocumentprocessor.h"
#include "era/ssbticket.h"
#include "era/ssbv3ticket.h"
#include <KItinerary/ExtractorFilter>
......@@ -16,13 +16,13 @@ using namespace KItinerary;
bool SsbDocumentProcessor::canHandleData(const QByteArray &encodedData, [[maybe_unused]] QStringView fileName) const
{
return SSBTicket::maybeSSB(encodedData);
return SSBv3Ticket::maybeSSB(encodedData);
}
ExtractorDocumentNode SsbDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const
{
ExtractorDocumentNode node;
auto ticket = SSBTicket(encodedData);
auto ticket = SSBv3Ticket(encodedData);
if (ticket.isValid()) {
node.setContent(ticket);
}
......@@ -31,12 +31,12 @@ ExtractorDocumentNode SsbDocumentProcessor::createNodeFromData(const QByteArray
bool SsbDocumentProcessor::matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const
{
const auto ticket = node.content<SSBTicket>();
const auto propIdx = SSBTicket::staticMetaObject.indexOfProperty(filter.fieldName().toUtf8().constData());
const auto ticket = node.content<SSBv3Ticket>();
const auto propIdx = SSBv3Ticket::staticMetaObject.indexOfProperty(filter.fieldName().toUtf8().constData());
if (propIdx < 0) {
return false;
}
const auto prop = SSBTicket::staticMetaObject.property(propIdx);
const auto prop = SSBv3Ticket::staticMetaObject.property(propIdx);
const auto value = prop.readOnGadget(&ticket);
return filter.matches(value.toString());
}
......@@ -4,7 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "../lib/era/ssbticket.h"
#include "../lib/era/ssbv3ticket.h"
#include "../lib/uic9183/uic9183head.h"
#include "../lib/uic9183/uic9183header.h"
#include "../lib/uic9183/vendor0080vublockdata.h"
......@@ -35,11 +35,11 @@ using namespace KItinerary;
static void dumpSsbTicket(const QByteArray &data)
{
SSBTicket ticket(data);
SSBv3Ticket ticket(data);
const auto typePrefix = QByteArray("type" + QByteArray::number(ticket.ticketTypeCode()));
for (auto i = 0; i < SSBTicket::staticMetaObject.propertyCount(); ++i) {
const auto prop = SSBTicket::staticMetaObject.property(i);
for (auto i = 0; i < SSBv3Ticket::staticMetaObject.propertyCount(); ++i) {
const auto prop = SSBv3Ticket::staticMetaObject.property(i);
if (std::strncmp(prop.name(), "type", 4) == 0 && std::strncmp(prop.name(), typePrefix.constData(), 5) != 0) {
continue;
}
......@@ -55,7 +55,7 @@ static void dumpSsbTicket(const QByteArray &data)
}
}
if (ticket.ticketTypeCode() == SSBTicket::IRT_RES_BOA) {
if (ticket.ticketTypeCode() == SSBv3Ticket::IRT_RES_BOA) {
std::cout << std::endl;
std::cout << "Issuing day: " << qPrintable(ticket.issueDate().toString(Qt::ISODate)) << std::endl;
std::cout << "Departure day: " << qPrintable(ticket.type1DepartureDay().toString(Qt::ISODate)) << std::endl;
......@@ -248,7 +248,7 @@ int main(int argc, char **argv)
if (IataBcbpParser::maybeIataBcbp(QString::fromLatin1(data))) {
std::cout << "IATA Barcoded Boarding Pass" << std::endl;
// TODO
} else if (SSBTicket::maybeSSB(data)) {
} else if (SSBv3Ticket::maybeSSB(data)) {
std::cout << "ERA SSB Ticket" << std::endl;
dumpSsbTicket(data);
} else if (Uic9183Parser::maybeUic9183(data)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment