2 * Copyright (C) 2011, Jamie Thompson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; If not, see
16 * <http://www.gnu.org/licenses/>.
19 #include "MMSParser.h"
24 #include <QSharedPointer>
27 using namespace EventParsers;
29 iEventParser *MMSParser::IsValid(QFile &eventFile)
31 qDebug() << "Checking if a MMS file...";
33 // A buffer that can hold 3 fields with a single byte value...and a
34 // bonus terminator byte if required (2*3 + 1)
36 qint64 bytesRead(eventFile.read(fileIDBuf, sizeof(fileIDBuf) - 1));
38 if(bytesRead == sizeof(fileIDBuf) - 1)
40 // This is the hex 8c (message type '0c' with high bit set), 80 (transaction id), 8D, 92, 85, 04
41 char fieldMessageType = 0x8C;
42 char fieldTransactionID = 0x98; // Optional
43 char fieldMessageMMSVersion = 0x8D;
44 char fieldMessageDate = 0x85;
46 if(fileIDBuf[offset++] == fieldMessageType)
48 char valueMessageType = fileIDBuf[offset++] ^ 0x80;
49 qDebug() << "...looks like a MMS file. Message type is: " << valueMessageType;
51 char valueTransactionID = -1;
52 if(fileIDBuf[offset] == fieldTransactionID)
53 valueTransactionID = fileIDBuf[offset++] ^ 0x80;
55 if(fileIDBuf[offset] == fieldMessageMMSVersion)
57 char valueMessageMMSVersion = fileIDBuf[offset++] ^ 0x80;
58 int majorVersion(valueMessageMMSVersion >> 4);
59 int minorVersion(valueMessageMMSVersion & 0x0F);
60 qDebug() << QString("...MMS version type is: %1.%2")
64 // We only support up to version 1.3
65 if(majorVersion == 1 && minorVersion <= 3)
66 return new MMSParser(eventFile.fileName());
68 qDebug() << QString("%1 is an unsupported MMS version")
69 .arg(eventFile.fileName());
72 qDebug() << QString("%1 is a malformed MMS. Expected %2, got %3")
73 .arg(eventFile.fileName())
74 .arg(fieldMessageMMSVersion).arg(fileIDBuf[offset]);
79 // for(int i(0); i<0x16; ++i)
80 // hexs.append(QString::number(fileIDBuf[i], 16).rightJustified(2, '0'));
81 // qDebug() << eventFile.fileName() << " has bad signature: " << hexs;
85 qDebug() << eventFile.fileName() << " has size mismatch.";
90 MMSParser::MMSParser(const QString &filename)
94 EventTypes::EventFromFileList MMSParser::ParseFile(QFile &eventFile, const QList<uint> &recordsToReturn)
96 qDebug() << "MMS Parsing NYI!";
97 return EventTypes::EventFromFileList();