Added CSV parsing and export of Symbian-format Event logs that have had their tables...
[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 "EventTypes/iEvent.h"
22
23 #include <QDebug>
24
25 #include <QFile>
26 #include <QSharedPointer>
27 #include <QString>
28
29 using namespace EventParsers;
30
31 iEventParser *MMSParser::IsValid(QFile &eventFile)
32 {
33         qDebug() << "Checking if a MMS file...";
34
35         // A buffer that can hold 3 fields with a single byte value...and a
36         // bonus terminator byte if required (2*3 + 1)
37         char fileIDBuf[0x07];
38         qint64 bytesRead(eventFile.read(fileIDBuf, sizeof(fileIDBuf) - 1));
39         eventFile.seek(0);
40         if(bytesRead == sizeof(fileIDBuf) - 1)
41         {
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;
47                 uint offset = 0;
48                 if(fileIDBuf[offset++] == fieldMessageType)
49                 {
50                         char valueMessageType = fileIDBuf[offset++] ^ 0x80;
51                         qDebug() << "...looks like a MMS file. Message type is: " << valueMessageType;
52
53                         char valueTransactionID = -1;
54                         if(fileIDBuf[offset] == fieldTransactionID)
55                                 valueTransactionID = fileIDBuf[offset++] ^ 0x80;
56
57                         if(fileIDBuf[offset] == fieldMessageMMSVersion)
58                         {
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")
63                                                         .arg(majorVersion)
64                                                         .arg(minorVersion);
65
66                                 // We only support up to version 1.3
67                                 if(majorVersion == 1 && minorVersion <= 3)
68                                         return new MMSParser(eventFile.fileName());
69                                 else
70                                         qDebug() << QString("%1 is an unsupported MMS version")
71                                                                 .arg(eventFile.fileName());
72                         }
73                         else
74                                 qDebug() << QString("%1 is a malformed MMS. Expected %2, got %3")
75                                                         .arg(eventFile.fileName())
76                                                         .arg(fieldMessageMMSVersion).arg(fileIDBuf[offset]);
77 //                              }
78 //                              else
79 //                              {
80 //                                      QString hexs;
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;
84                 }
85         }
86         else
87                 qDebug() << eventFile.fileName() << " has size mismatch.";
88
89         return false;
90 }
91
92 MMSParser::MMSParser(const QString &filename)
93 {
94 }
95
96 EventTypes::EventFromFileList MMSParser::ParseFile(QFile &eventFile, const QList<uint> &recordsToReturn)
97 {
98         qDebug() << "MMS Parsing NYI!";
99         return EventTypes::EventFromFileList();
100 }