summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/serializer.h
blob: df50e428cae6873d7948800536eacd4dedb18844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2004 by Michael Buesch                                  *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2        *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 ***************************************************************************/


/***************************************************************************
 * copyright (C) 2004 by Ulf Schenk
 * This file is originaly based on version 1.1 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#ifndef __SERIALIZER_H
#define __SERIALIZER_H

#include "pwmdoc.h"

#include <qcstring.h>
#include <qdom.h>

#include <vector>

using std::vector;

/** This serializes its input data into
  * the PwManager-XML-datastream, that becomes
  * encrypted and maybe compressed
  */
class Serializer
{
public:
	/** construct an empty serializer document */
	Serializer();
	/** construct a serializer document and parse "buffer" */
	Serializer(const QCString &buffer);
	/** destructor */
	virtual ~Serializer();

	/** clears all data */
	void clear();
	/** parse the given data buffer */
	bool parseXml(const QCString &buffer);
	/** returns the current XML data */
	QCString getXml();
	/** serialize "dta" and store it as XML data */
	//US ENH: we need to serialize and deserialize not only categories, but also synctargets
	bool serialize(PwMItem &dta);
	/** deserialize the (parsed) XML data and store it in "dta" */
	bool deSerialize(PwMItem *dta);
	/** sets the initial default lockStat we should assign */
	void setDefaultLockStat(bool stat)
			{ defaultLockStat = stat; }

protected:
	/** main data holder */
	QDomDocument *domDoc;
	/** default lockStat to assign */
	bool defaultLockStat;

protected:
	/** check if this is valid PwManager XML data */
	bool checkValid();
	/** read the categories in the node "n" */
	bool readCategories(const QDomNode &n,
			    vector<PwMCategoryItem> *dta);
	/** read the entries in the node "n" */
	bool readEntries(const QDomNode &n,
			 vector<PwMDataItem> *dta);
	/** extract the data out of the given item at "n" */
	bool extractEntry(const QDomNode &n,
			  PwMDataItem *dta);
	/** extract the meta-data */
	bool extractMeta(const QDomNode &n,
			 PwMMetaData *dta);
	/** generates a new root node and sets all initial parameters */
	QDomElement genNewRoot();
	/** add new categories to the XML data stream in e */
	bool addCategories(QDomElement *e,
			   const vector<PwMCategoryItem> &dta);
	/** add the given new entries to the XML data stream in e */
	bool addEntries(QDomElement *e,
			const vector<PwMDataItem> &dta);
	/** do serialize and write the given entry to the XML stream */
	bool writeEntry(QDomElement *e,
			const PwMDataItem &_dta);
	/** write the entry meta data to the xml stream */
	bool writeMeta(QDomElement *e,
		       const PwMMetaData &dta);
	/** escape illegal characters out of the given entry data string */
	QString escapeEntryData(QString dta);
	/** un-escape illegal characters out of the given entry data string */
	QString unescapeEntryData(QString dta);



	//US ENH: the following methods are getting used to write/read sync entries
	/** read the syncentries in the node "n" */
	bool readSyncData(const QDomNode &n,
			    vector<PwMSyncItem> *dta);

	/** add new syncentries to the XML data stream in e */
	bool addSyncData(QDomElement *e,
			   const vector<PwMSyncItem> &dta);

};

#endif // __SERIALIZER_H