Ignore build stamps.
[qwerkisync] / EventParsers / MMSParser.cpp
1 /*
2  * Copyright (C) 2011, Jamie Thompson
3  *
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.
8  *
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.
13  *
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/>.
17  */
18
19 #include "MMSParser.h"
20
21 #include <QDebug>
22
23 #include <QFile>
24 #include <QSharedPointer>
25 #include <QString>
26
27 using namespace EventParsers;
28
29 iEventParser *MMSParser::IsValid(QFile &eventFile)
30 {
31         qDebug() << "Checking if a MMS file...";
32
33         // A buffer that can hold 3 fields with a single byte value...and a
34         // bonus terminator byte if required (2*3 + 1)
35         char fileIDBuf[0x07];
36         qint64 bytesRead(eventFile.read(fileIDBuf, sizeof(fileIDBuf) - 1));
37         eventFile.seek(0);
38         if(bytesRead == sizeof(fileIDBuf) - 1)
39         {
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;
45                 uint offset = 0;
46                 if(fileIDBuf[offset++] == fieldMessageType)
47                 {
48                         char valueMessageType = fileIDBuf[offset++] ^ 0x80;
49                         qDebug() << "...looks like a MMS file. Message type is: " << valueMessageType;
50
51                         char valueTransactionID = -1;
52                         if(fileIDBuf[offset] == fieldTransactionID)
53                                 valueTransactionID = fileIDBuf[offset++] ^ 0x80;
54
55                         if(fileIDBuf[offset] == fieldMessageMMSVersion)
56                         {
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")
61                                                         .arg(majorVersion)
62                                                         .arg(minorVersion);
63
64                                 // We only support up to version 1.3
65                                 if(majorVersion == 1 && minorVersion <= 3)
66                                         return new MMSParser(eventFile.fileName());
67                                 else
68                                         qDebug() << QString("%1 is an unsupported MMS version")
69                                                                 .arg(eventFile.fileName());
70                         }
71                         else
72                                 qDebug() << QString("%1 is a malformed MMS. Expected %2, got %3")
73                                                         .arg(eventFile.fileName())
74                                                         .arg(fieldMessageMMSVersion).arg(fileIDBuf[offset]);
75 //                              }
76 //                              else
77 //                              {
78 //                                      QString hexs;
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;
82                 }
83         }
84         else
85                 qDebug() << eventFile.fileName() << " has size mismatch.";
86
87         return false;
88 }
89
90 MMSParser::MMSParser(const QString &filename)
91 {
92 }
93
94 EventTypes::EventFromFileList MMSParser::ParseFile(QFile &eventFile, const QList<uint> &recordsToReturn)
95 {
96         qDebug() << "MMS Parsing NYI!";
97         return EventTypes::EventFromFileList();
98 }