summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/libiris/006_private_storage.patch
blob: 288d24c564a61cd3cafd030e9071456b05071445 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Index: iris/xmpp-im/xmpp_tasks.h
===================================================================
--- iris/xmpp-im/xmpp_tasks.h	(revision 499691)
+++ iris/xmpp-im/xmpp_tasks.h	(working copy)
@@ -459,6 +459,27 @@
 		class Private;
 		Private *d;
 	};
+	
+	class JT_PrivateStorage : public Task
+	{
+		Q_OBJECT
+	public:
+		JT_PrivateStorage(Task *parent);
+		~JT_PrivateStorage();
+
+		void set(const QDomElement &);
+		void get(const QString &tag, const QString& xmlns);
+		
+		QDomElement element();
+
+		void onGo();
+		bool take(const QDomElement &);
+		
+	private:
+		class Private;
+		Private *d;
+	};
+	
 }
 
 #endif
Index: iris/xmpp-im/xmpp_tasks.cpp
===================================================================
--- iris/xmpp-im/xmpp_tasks.cpp	(revision 499691)
+++ iris/xmpp-im/xmpp_tasks.cpp	(working copy)
@@ -2028,3 +2028,93 @@
 	send(tag);
 	setSuccess();
 }
+
+
+//----------------------------------------------------------------------------
+// JT_PrivateStorage
+//----------------------------------------------------------------------------
+class JT_PrivateStorage::Private
+{
+	public:
+		Private() : type(-1) {}
+
+		QDomElement iq;
+		QDomElement elem;
+		int type;
+};
+
+JT_PrivateStorage::JT_PrivateStorage(Task *parent)
+	:Task(parent)
+{
+	d = new Private;
+}
+
+JT_PrivateStorage::~JT_PrivateStorage()
+{
+	delete d;
+}
+
+void JT_PrivateStorage::get(const QString& tag, const QString& xmlns)
+{
+	d->type = 0;
+	d->iq = createIQ(doc(), "get" , QString() , id() );
+	QDomElement query = doc()->createElement("query");
+	query.setAttribute("xmlns", "jabber:iq:private");
+	d->iq.appendChild(query);
+	QDomElement s = doc()->createElement(tag);
+	if(!xmlns.isEmpty())
+		s.setAttribute("xmlns", xmlns);
+	query.appendChild(s);
+}
+
+void JT_PrivateStorage::set(const QDomElement& element)
+{
+	d->type = 1;
+	d->elem=element;
+	QDomNode n=doc()->importNode(element,true);
+
+	d->iq = createIQ(doc(), "set" , QString() , id() );
+	QDomElement query = doc()->createElement("query");
+	query.setAttribute("xmlns", "jabber:iq:private");
+	d->iq.appendChild(query);
+	query.appendChild(n);
+}
+
+void JT_PrivateStorage::onGo()
+{
+	send(d->iq);
+}
+
+bool JT_PrivateStorage::take(const QDomElement &x)
+{
+	QString to = client()->host();
+	if(!iqVerify(x, to, id()))
+		return false;
+
+	if(x.attribute("type") == "result") {
+		if(d->type == 0) {
+			QDomElement q = queryTag(x);
+			for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) {
+				QDomElement i = n.toElement();
+				if(i.isNull())
+					continue;
+				d->elem=i;
+				break;
+			}
+		}
+		setSuccess();
+		return true;
+	}
+	else {
+		setError(x);
+	}
+
+	return true;
+}
+
+
+QDomElement JT_PrivateStorage::element( )
+{
+	return d->elem;
+}
+