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"
21 #include "EventTypes/iEvent.h"
26 #include <QSharedPointer>
29 using namespace EventParsers;
31 iEventParser *MMSParser::IsValid(QFile &eventFile)
33 qDebug() << "Checking if a MMS file...";
35 // A buffer that can hold 3 fields with a single byte value...and a
36 // bonus terminator byte if required (2*3 + 1)
38 qint64 bytesRead(eventFile.read(fileIDBuf, sizeof(fileIDBuf) - 1));
40 if(bytesRead == sizeof(fileIDBuf) - 1)
42 // This is the hex 8c (message type '0c' with high bit set), 80 (transaction id), 8D, 92, 85, 04
43 char fieldMessageType = 0x8C;
44 char fieldTransactionID = 0x98; // Optional
45 char fieldMessageMMSVersion = 0x8D;
46 char fieldMessageDate = 0x85;
48 if(fileIDBuf[offset++] == fieldMessageType)
50 char valueMessageType = fileIDBuf[offset++] ^ 0x80;
51 qDebug() << "...looks like a MMS file. Message type is: " << valueMessageType;
53 char valueTransactionID = -1;
54 if(fileIDBuf[offset] == fieldTransactionID)
55 valueTransactionID = fileIDBuf[offset++] ^ 0x80;
57 if(fileIDBuf[offset] == fieldMessageMMSVersion)
59 char valueMessageMMSVersion = fileIDBuf[offset++] ^ 0x80;
60 int majorVersion(valueMessageMMSVersion >> 4);
61 int minorVersion(valueMessageMMSVersion & 0x0F);
62 qDebug() << QString("...MMS version type is: %1.%2")
66 // We only support up to version 1.3
67 if(majorVersion == 1 && minorVersion <= 3)
68 return new MMSParser(eventFile.fileName());
70 qDebug() << QString("%1 is an unsupported MMS version")
71 .arg(eventFile.fileName());
74 qDebug() << QString("%1 is a malformed MMS. Expected %2, got %3")
75 .arg(eventFile.fileName())
76 .arg(fieldMessageMMSVersion).arg(fileIDBuf[offset]);
81 // for(int i(0); i<0x16; ++i)
82 // hexs.append(QString::number(fileIDBuf[i], 16).rightJustified(2, '0'));
83 // qDebug() << eventFile.fileName() << " has bad signature: " << hexs;
87 qDebug() << eventFile.fileName() << " has size mismatch.";
92 MMSParser::MMSParser(const QString &filename)
96 EventTypes::EventFromFileList MMSParser::ParseFile(QFile &eventFile, const QList<uint> &recordsToReturn)
98 qDebug() << "MMS Parsing NYI!";
99 return EventTypes::EventFromFileList();