File: pwmdoc.h

package info (click to toggle)
passwordmaker-cli 1.5%2Bdfsg-5
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 636 kB
  • sloc: cpp: 6,768; javascript: 639; makefile: 15
file content (88 lines) | stat: -rwxr-xr-x 1,877 bytes parent folder | download | duplicates (5)
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
#ifndef PWMDOC_H
#define PWMDOC_H

#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include "tinyxml.h"

struct PWMNode {
	public:
		enum { ntUnknown, ntSeq, ntLi, ntDescription } nodeType;
		std::map<std::string, std::string> attrs;
		std::vector<PWMNode> children;

	public:
		PWMNode() {
			nodeType = ntUnknown;
		}
};

struct PWMDoc {
	public:
		PWMNode mainNode;
		std::string ns;

	public:
		std::string findNamespace(TiXmlHandle *docHandle) {
			std::string ns = "";
			TiXmlElement *defaultNode = docHandle->FirstChildElement("RDF:RDF").Element();
			if(defaultNode) {
				TiXmlAttribute *attrib = defaultNode->FirstAttribute();
				while(attrib) {
					if(!strcmp(attrib->Value(), "http://passwordmaker.mozdev.org/rdf#")) {
						ns = attrib->Name();
						ns.erase(ns.begin(), ns.begin() + (ns.find(':')+1));
						break;
					}
				}
			}

			return ns;
		}

		PWMDoc() {
		}

		TiXmlElement *findSeq(TiXmlHandle *docHandle, std::string about) {
			TiXmlElement *defaultNode = docHandle->FirstChildElement("RDF:RDF").FirstChildElement("RDF:Seq").Element();

			while(defaultNode) {
				if(about.compare(defaultNode->Attribute("RDF:about"))==0)
					break;
				defaultNode = defaultNode->NextSiblingElement("RDF:Seq");
			}

			return defaultNode;
		}

		bool load(std::string filepath) {
			TiXmlDocument document(filepath);
			document.LoadFile();
			if(document.Error()) {
				return false;
			}

			TiXmlHandle docHandle(&document);
			ns = findNamespace(&docHandle);
			if(ns.size()==0)
				return false;
		}

		PWMNode loadSeq(TiXmlHandle *docHandle, TiXmlElement *seqNode) {
			PWMNode node;

			node.nodeType = ntSeq;
			TiXmlAttribute *attrib = seqNode->FirstAttribute();
			while(attrib) {
				node.attrs[std::string(attrib->Name())] = std::string(attrib->Value());
				attrib = attrib->Next();
			}

		}

};

#endif