File indexing completed on 2024-04-28 03:50:26

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2008 Shashank Singh <shashank.personal@gmail.com>
0004 //
0005 
0006 #ifndef JSONPARSER_H
0007 #define JSONPARSER_H
0008 
0009 #include <QtScript>
0010 #include <QList>
0011 #include <QDebug>
0012 #include <QScriptValue>
0013 #include <QScriptEngine>
0014 /**
0015 This is a generic class built up for parsing Json that is JavaScript Object Notification
0016 FIXME: the class presently has no sanity checking mechanism, it just can't check whether the input given to it is only JSON or Javascript ; a point of potential breach for the software.
0017 sanity checking would include :
0018 (1)regex matching for following characters "" {} , [a-zA-Z] everything else should be discarded (but some unicode names could pose problem)
0019 (2)checking for javascript constructs and eliminating them.
0020 (3)some other plan that i have yet not thought upon :)
0021     @author Shashank Singh
0022 */
0023 struct twitterDataStructure
0024 {
0025 //defining the only parts that are required ,, all oher fields are hence left
0026     QString user;
0027     QString location;
0028     QString text;
0029 };
0030 
0031 struct googleMapDataStructure
0032 {
0033     qreal lat;
0034     qreal lon;
0035 };
0036 
0037 class jsonParser 
0038 {
0039     
0040 public:
0041     jsonParser();
0042 
0043     ~jsonParser();
0044 
0045    twitterDataStructure parseObjectOnPosition(const QString &content, int requiredObjectPosition);   //for parsing single object
0046 
0047     QList<twitterDataStructure> parseAllObjects(const QString &content, int numberOfObjects);   //for parsing a list objects
0048 
0049     googleMapDataStructure geoCodingAPIparseObject(QString content);//google geocoding api parser
0050 
0051 private:
0052     QList <twitterDataStructure> parsedJsonOutput;
0053 
0054     twitterDataStructure dataStorage;
0055 
0056     QScriptEngine myEngine;
0057 
0058 };
0059 
0060 
0061 #endif