This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisco_feature.cpp
269 lines (243 loc) · 8.33 KB
/
disco_feature.cpp
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
* kJabber
*
* Please READ & ACCEPT /License.txt FIRST!
*
* Copyright (C)2005,2006 Rafa³ Lindemann, STAMINA
* http://www.stamina.pl/ , http://www.konnekt.info/
*
* $Id: $
*/
#include "stdafx.h"
#include "disco_feature.h"
using namespace JEP;
cFeatureXData::cFeatureXData(cJabber & jab, HWND hwnd, const CStdString & jid, const CStdString & title)
:xData(jab, title, hwnd),jab(jab) {
this->jid = jid;
}
cFeatureXData::~cFeatureXData() {
if (!id.empty())
jab.GetSession().unregisterIQ(id);
}
void cFeatureXData::Create() {
/* Pierwszy pakiet do wys³ania... */
xData.evtCommand.connect(SigC::slot(*this, &cFeatureXData::OnCommand));
Submit(false);
/* Dalej ¿yje ju¿ w³asnym ¿yciem... */
}
void cFeatureXData::OnCommand(int command) {
if (command == IDCANCEL) {
if (xData.GetType() == cXData::tForm)
Submit(true);
delete this;
} else if (command == IDOK) {
if (xData.GetType() == cXData::tForm || xData.GetType() == cXData::tObsolete)
Submit(false);
else
delete this;
}
}
judo::Element * cFeatureXData::BuildIQ(const CStdString & type) {
judo::Element * iq = new judo::Element ("iq");
iq->putAttrib("type", type);
iq->putAttrib("from", jab.GetSession().getLocalJID());
iq->putAttrib("to", jid);
this->id = jab.GetSession().getNextID();
iq->putAttrib("id", id);
return iq;
}
judo::Element * cFeatureXData::BuildX(judo::Element & parent, bool cancel) {
judo::Element * x = parent.addElement("x");
x->putAttrib("xmlns", "jabber:x:data");
if (cancel) {
x->putAttrib("type", "cancel");
} else {
x->putAttrib("type", "submit");
}
return x;
}
bool cFeatureXData::IsError(const judo::Element & e) {
const judo::Element * error = e.findElement("error");
if (error) {
CStdString msg = UTF8ToLocale(error->getCDATA());
if (msg.empty() && error->size())
msg = UTF8ToLocale((*error->begin())->getName());
xData.ProcessError("Kod: " + error->getAttrib("code") + "\r\n" + (msg.empty() ? "Nieznany b³¹d" : msg), xData.IsForm() == false);
return true;
}
return false;
}
void CALLBACK cFeatureXData::SafeOnIQAPC(tSafeOnIQ * soi) {
soi->f(*soi->e);
soi->processed = true;
}
bool cFeatureXData::SafeOnIQ(jabberoo::ElementCallbackFunc f , const judo::Element & e) {
if (jab.GetPlug()->Is_TUS(0)) {
tSafeOnIQ soi;
soi.e = &e;
soi.f = f;
soi.processed = false;
HANDLE thread = (HANDLE)jab.GetPlug()->ICMessage(IMC_GET_MAINTHREAD);
if (!thread)
return true;
QueueUserAPC((PAPCFUNC) SafeOnIQAPC, thread, (ULONG_PTR)&soi);
while (!soi.processed) {
jab.GetPlug()->WMProcess();
}
return false;
} else
return true;
}
// ---------------------------------------------------------------------------
cFeatureNeg::cFeatureNeg(cJabber & jab, HWND hwnd, const CStdString & jid, const CStdString & title, const CStdString & feature)
:cFeatureXData(jab, hwnd, jid, title) {
this->feature = feature;
Create();
}
void cFeatureNeg::Submit(bool cancel) {
xData.ProcessInfo("Czekam na informacje od serwera");
xData.Enable(false);
judo::Element * iq = BuildIQ();
judo::Element * feat = iq->addElement("feature");
feat->putAttrib("xmlns", "http://jabber.org/protocol/feature-neg");
judo::Element * x = BuildX(*feat, cancel);
if (!cancel) {
/* Skoro nie mamy formularza, pobieramy ficzer */
if (xData.GetType() != cXData::tForm) {
judo::Element * field = x->addElement("field");
field->putAttrib("var", feature);
} else {
/* Wstawiamy wynik formularza... */
xData.InjectResult(*feat);
}
jab.GetSession().registerIQ(id, SigC::slot(*this, &cFeatureNeg::OnIQ));
}
jab.GetSession() << jabberoo::Packet(*iq);
}
void cFeatureNeg::OnIQ(const judo::Element & e) {
if (!SafeOnIQ(SigC::slot(*this, &cFeatureNeg::OnIQ), e))
return;
this->id = ""; // odebrany - usuniêty... mo¿na o nim zapomnieæ...
if (IsError(e))
return;
const judo::Element * feat = e.findElement("feature");
if (!feat) {
xData.ProcessError("Z³a odpowiedŸ!");
return;
}
xData.Process(*feat, false);
if (xData.GetState() == cXData::tError) {
xData.ProcessError("Problemy z przetwarzaniem danych...");
}
}
// ---------------------------------------------------------------------------
cFeatureIQRegister::cFeatureIQRegister(cJabber & jab, HWND hwnd, const CStdString & jid, const CStdString & title)
:cFeatureXData(jab, hwnd, jid, title) {
Create();
}
void cFeatureIQRegister::Submit(bool cancel) {
xData.SetButtonSpecial("");
xData.ProcessInfo("Czekam na informacje od serwera");
xData.Enable(false);
judo::Element * iq = BuildIQ(xData.IsForm() ? "set" : "get");
judo::Element * query = iq->addElement("query");
query->putAttrib("xmlns", "jabber:iq:register");
if (xData.IsForm()) {
xData.InjectResult(*query);
} else {
// pierwsza wysy³ka - wystarczy sam get
}
if (!cancel)
jab.GetSession().registerIQ(id, SigC::slot(*this, &cFeatureIQRegister::OnIQ));
jab.GetSession() << jabberoo::Packet(*iq);
}
void cFeatureIQRegister::OnIQ(const judo::Element & e) {
if (!SafeOnIQ(SigC::slot(*this, &cFeatureIQRegister::OnIQ), e))
return;
this->id = ""; // odebrany - usuniêty... mo¿na o nim zapomnieæ...
if (IsError(e))
return;
const judo::Element * query = e.findElement("query");
if (!query || query->size() == 0) { // Potwierdzenie...
xData.ProcessInfo("Operacja siê powiod³a", true);
return;
}
if (query->findElement("registered"))
xData.SetButtonSpecial("Wyrejestruj");
else
xData.SetButtonSpecial("");
xData.Process(*query, false);
if (xData.GetState() == cXData::stError) {
xData.ProcessError("Problemy z przetwarzaniem danych...");
}
}
void cFeatureIQRegister::OnCommand(int command) {
if (command == IDB_SPECIAL) { // unregister
if (! jab.GetPlug()->IMessage(&sIMessage_msgBox(
IMI_CONFIRM, "Na pewno chcesz siê wyrejestrowaæ z " + this->jid + "?", "kJabber"
))) {
return;
}
if (this->jid == jab.GetHost(false) && jab.GetPlug()->IMessage(&sIMessage_msgBox(
IMI_CONFIRM, "Próbujesz wyrejestrowaæ swoje konto na serwerze " + jab.GetHost(false) + ".\r\nZostanie usuniêta z serwera Twoja lista kontaktów i byæ mo¿e ktoœ przejmie Twój identyfikator (" + jab.GetUID() + ")\r\n\r\nCzy na pewno chcesz kontynuowaæ?", "kJabber", MB_ICONWARNING | MB_YESNO
)) == IDNO) {
return;
}
xData.SetButtonSpecial("");
xData.ProcessInfo("Wyrejestrowywujê..." , true);
judo::Element * iq = BuildIQ("set");
judo::Element * query = iq->addElement("query");
query->putAttrib("xmlns", "jabber:iq:register");
query->addElement("remove");
jab.GetSession().registerIQ(id, SigC::slot(*this, &cFeatureIQRegister::OnIQ));
jab.GetSession() << jabberoo::Packet(*iq);
return;
}
__super::OnCommand(command);
}
// ---------------------------------------------------------------------------
cFeatureIQSearch::cFeatureIQSearch(cJabber & jab, HWND hwnd, const CStdString & jid, const CStdString & title)
:cFeatureXData(jab, hwnd, jid, title) {
Create();
}
void cFeatureIQSearch::Submit(bool cancel) {
xData.SetButtonSpecial("");
xData.ProcessInfo("Czekam na informacje od serwera");
xData.Enable(false);
judo::Element * iq = BuildIQ(xData.IsForm() ? "set" : "get");
judo::Element * query = iq->addElement("query");
query->putAttrib("xmlns", "jabber:iq:search");
if (xData.IsForm()) {
xData.InjectResult(*query);
} else {
// pierwsza wysy³ka - wystarczy sam get
}
if (!cancel)
jab.GetSession().registerIQ(id, SigC::slot(*this, &cFeatureIQSearch::OnIQ));
jab.GetSession() << jabberoo::Packet(*iq);
}
void cFeatureIQSearch::OnIQ(const judo::Element & e) {
if (!SafeOnIQ(SigC::slot(*this, &cFeatureIQSearch::OnIQ), e))
return;
this->id = ""; // odebrany - usuniêty... mo¿na o nim zapomnieæ...
if (IsError(e))
return;
const judo::Element * query = e.findElement("query");
if (!query) { // Potwierdzenie...
xData.ProcessError("Z³a odpowiedŸ!");
return;
}
xData.Process(*query, false);
//xData.SetButtonSpecial(xData.IsForm() ? "Do wyszukiwarki" : "");
if (xData.GetState() == cXData::stError) {
xData.ProcessError("Problemy z przetwarzaniem danych...");
}
}
void cFeatureIQSearch::OnCommand(int command) {
if (command == IDB_SPECIAL) { // do wyszukiwarki...
/*TODO: Wysylanie wynikow do wyszukiwarki...*/
xData.SetButtonSpecial("");
return;
}
__super::OnCommand(command);
}