diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/otr_floater_smp_dialog.cpp | 438 |
1 files changed, 438 insertions, 0 deletions
diff --git a/linden/indra/newview/otr_floater_smp_dialog.cpp b/linden/indra/newview/otr_floater_smp_dialog.cpp new file mode 100644 index 0000000..06acdae --- /dev/null +++ b/linden/indra/newview/otr_floater_smp_dialog.cpp | |||
@@ -0,0 +1,438 @@ | |||
1 | /* otr_floater_smp_dialog.cpp - SMP dialog box | ||
2 | $PLOTR$ See http://www.cypherpunks.ca/otr/ | ||
3 | |||
4 | Copyright (C) 2009 Chris Tuchs | ||
5 | |||
6 | This is free software; you can redistribute it and/or modify it | ||
7 | under the terms of the GNU Lesser General Public License as | ||
8 | published by the Free Software Foundation; either version 2.1 of | ||
9 | the License, or (at your option) any later version. | ||
10 | |||
11 | This is distributed in the hope that it will be useful, but WITHOUT | ||
12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
13 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | ||
14 | License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Lesser General Public | ||
17 | License along with the viewer; if not, write to the Free Software | ||
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
19 | 02111-1307, USA. */ | ||
20 | |||
21 | #include "llviewerprecompiledheaders.h" | ||
22 | |||
23 | #include "llagent.h" | ||
24 | #include "llcachename.h" | ||
25 | #include "llcombobox.h" | ||
26 | #include "llimpanel.h" | ||
27 | #include "lluictrlfactory.h" | ||
28 | #include "llweb.h" | ||
29 | |||
30 | #include "otr_floater_smp_progress.h" | ||
31 | #include "otr_floater_smp_dialog.h" | ||
32 | |||
33 | std::string OtrFloaterSmpDialog::getStringName(const char *message_name) | ||
34 | { | ||
35 | LLUIString message = getString(message_name); | ||
36 | std::string them; | ||
37 | if (!gCacheName->getFullName(mOtherParticipantUUID, them)) them = getString("otr_generic_name"); | ||
38 | message.setArg("[NAME]", them); | ||
39 | return message.getString(); | ||
40 | } | ||
41 | |||
42 | void OtrFloaterSmpDialog::init() | ||
43 | { | ||
44 | LLUICtrlFactory::getInstance()->buildFloater(this, "otr_floater_smp_dialog.xml"); | ||
45 | } | ||
46 | |||
47 | OtrFloaterSmpDialog::OtrFloaterSmpDialog( | ||
48 | LLFloaterIMPanel *im_panel, LLUUID session_id, LLUUID other_id, | ||
49 | std::string my_fingerprint, std::string other_fingerprint) | ||
50 | : LLFloater(std::string("otr_floater_smp_dialog"), std::string("OtrFloaterSmpDialogRect"), LLStringUtil::null), | ||
51 | mIMPanel(im_panel), mIsReply(false), | ||
52 | mSessionUUID(session_id), mOtherParticipantUUID(other_id), | ||
53 | mQuestion(""), | ||
54 | mMyFingerprint(my_fingerprint), mOtherFingerprint(other_fingerprint) | ||
55 | { | ||
56 | init(); | ||
57 | } | ||
58 | |||
59 | OtrFloaterSmpDialog::OtrFloaterSmpDialog( | ||
60 | LLFloaterIMPanel *im_panel, LLUUID session_id, LLUUID other_id, | ||
61 | std::string question, OtrlTLV *tlv) | ||
62 | : LLFloater(std::string("otr_floater_smp_dialog"), std::string("OtrFloaterSmpDialogRect"), LLStringUtil::null), | ||
63 | mIMPanel(im_panel), mIsReply(true), | ||
64 | mSessionUUID(session_id), mOtherParticipantUUID(other_id), | ||
65 | mQuestion(question), | ||
66 | mMyFingerprint(""), mOtherFingerprint("") | ||
67 | { | ||
68 | init(); | ||
69 | LLComboBox *combo = getChild<LLComboBox>("otr_smp_how_combo"); | ||
70 | if (!combo) | ||
71 | { | ||
72 | llwarns << "$PLOTR$ Can't find OTR SMP how combo" << llendl; | ||
73 | return; | ||
74 | } | ||
75 | combo->removeall(); | ||
76 | combo->add(getString("otr_smp_how_by_qa_challenge"), ADD_BOTTOM, TRUE); | ||
77 | combo->selectFirstItem(); | ||
78 | doComboMenu(); | ||
79 | } | ||
80 | |||
81 | OtrFloaterSmpDialog::OtrFloaterSmpDialog( | ||
82 | LLFloaterIMPanel *im_panel, LLUUID session_id, LLUUID other_id, | ||
83 | OtrlTLV *tlv) | ||
84 | : LLFloater(std::string("otr_floater_smp_dialog"), std::string("OtrFloaterSmpDialogRect"), LLStringUtil::null), | ||
85 | mIMPanel(im_panel), mIsReply(true), | ||
86 | mSessionUUID(session_id), mOtherParticipantUUID(other_id), | ||
87 | mQuestion(""), | ||
88 | mMyFingerprint(""), mOtherFingerprint("") | ||
89 | { | ||
90 | init(); | ||
91 | LLComboBox *combo = getChild<LLComboBox>("otr_smp_how_combo"); | ||
92 | if (!combo) | ||
93 | { | ||
94 | llwarns << "$PLOTR$ Can't find OTR SMP how combo" << llendl; | ||
95 | return; | ||
96 | } | ||
97 | combo->removeall(); | ||
98 | combo->add(getString("otr_smp_how_by_ss_challenge"), ADD_BOTTOM, TRUE); | ||
99 | combo->selectFirstItem(); | ||
100 | doComboMenu(); | ||
101 | } | ||
102 | |||
103 | OtrFloaterSmpDialog::~OtrFloaterSmpDialog() | ||
104 | { | ||
105 | } | ||
106 | |||
107 | BOOL OtrFloaterSmpDialog::postBuild() | ||
108 | { | ||
109 | childSetAction("otr_smp_help_btn", onClickHelp, this); | ||
110 | childSetAction("otr_smp_cancel_btn", onClickCancel, this); | ||
111 | childSetAction("otr_smp_auth_btn", onClickAuth, this); | ||
112 | LLComboBox *veri = getChild<LLComboBox>("otr_smp_veri_combo"); | ||
113 | veri->setCommitCallback(onClickVeri); | ||
114 | veri->setCallbackUserData(this); | ||
115 | LLComboBox *combo = getChild<LLComboBox>("otr_smp_how_combo"); | ||
116 | combo->setCommitCallback(onClickCombo); | ||
117 | combo->setCallbackUserData(this); | ||
118 | combo->removeall(); | ||
119 | combo->add(getString("otr_smp_how_by_qa"), ADD_BOTTOM, TRUE); | ||
120 | combo->add(getString("otr_smp_how_by_ss"), ADD_BOTTOM, TRUE); | ||
121 | combo->add(getString("otr_smp_how_by_mfv"), ADD_BOTTOM, TRUE); | ||
122 | combo->selectFirstItem(); | ||
123 | doComboMenu(); | ||
124 | LLTextBox *why = getChild<LLTextBox>("otr_smp_why"); | ||
125 | if (why) why->setWrappedText(getString("otr_smp_why_text")); | ||
126 | LLTextBox *how = getChild<LLTextBox>("otr_smp_how_text"); | ||
127 | if (mIsReply) | ||
128 | { | ||
129 | if (how) how->setWrappedText(getStringName("otr_smp_how_name_challenge_me")); | ||
130 | setTitle(getStringName("otr_smp_name_auth_me")); | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | if (how) how->setWrappedText(getStringName("otr_smp_how_I_challenge_name")); | ||
135 | setTitle(getStringName("otr_smp_I_auth_name")); | ||
136 | } | ||
137 | return TRUE; | ||
138 | } | ||
139 | |||
140 | void OtrFloaterSmpDialog::show() | ||
141 | { | ||
142 | this->open(); /*Flawfinder: ignore*/ | ||
143 | this->setFocus(TRUE); | ||
144 | this->center(); | ||
145 | } | ||
146 | |||
147 | void OtrFloaterSmpDialog::doVeriMenu() | ||
148 | { | ||
149 | LLComboBox *veri = getChild<LLComboBox>("otr_smp_veri_combo"); | ||
150 | if (!veri) | ||
151 | { | ||
152 | llwarns << "$PLOTR$ Can't find OTR SMP verified combo" << llendl; | ||
153 | return; | ||
154 | } | ||
155 | LLButton* auth_btn = getChild<LLButton>("otr_smp_auth_btn"); | ||
156 | if (!auth_btn) | ||
157 | { | ||
158 | llwarns << "$PLOTR$ Can't find OTR SMP authenticate button" << llendl; | ||
159 | return; | ||
160 | } | ||
161 | if (getString("otr_smp_veri_no") == veri->getSimple()) | ||
162 | { | ||
163 | auth_btn->setEnabled(FALSE); | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | auth_btn->setEnabled(TRUE); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | void OtrFloaterSmpDialog::doComboMenu() | ||
172 | { | ||
173 | LLComboBox *combo = getChild<LLComboBox>("otr_smp_how_combo"); | ||
174 | if (!combo) | ||
175 | { | ||
176 | llwarns << "$PLOTR$ Can't find OTR SMP how combo" << llendl; | ||
177 | return; | ||
178 | } | ||
179 | LLTextBox *howto = getChild<LLTextBox>("otr_smp_howto"); | ||
180 | if (!howto) | ||
181 | { | ||
182 | llwarns << "$PLOTR$ Can't find OTR SMP howto control" << llendl; | ||
183 | return; | ||
184 | } | ||
185 | LLTextBox *label1 = getChild<LLTextBox>("otr_smp_label1"); | ||
186 | if (!label1) | ||
187 | { | ||
188 | llwarns << "$PLOTR$ Can't find OTR SMP label1 control" << llendl; | ||
189 | return; | ||
190 | } | ||
191 | LLLineEditor *edit1 = getChild<LLLineEditor>("otr_smp_edit1"); | ||
192 | if (!edit1) | ||
193 | { | ||
194 | llwarns << "$PLOTR$ Can't find OTR SMP edit1 control" << llendl; | ||
195 | return; | ||
196 | } | ||
197 | LLTextBox *label2 = getChild<LLTextBox>("otr_smp_label2"); | ||
198 | if (!label2) | ||
199 | { | ||
200 | llwarns << "$PLOTR$ Can't find OTR SMP label2 control" << llendl; | ||
201 | return; | ||
202 | } | ||
203 | LLLineEditor *edit2 = getChild<LLLineEditor>("otr_smp_edit2"); | ||
204 | if (!edit2) | ||
205 | { | ||
206 | llwarns << "$PLOTR$ Can't find OTR SMP edit2 control" << llendl; | ||
207 | return; | ||
208 | } | ||
209 | LLComboBox *veri = getChild<LLComboBox>("otr_smp_veri_combo"); | ||
210 | if (!veri) | ||
211 | { | ||
212 | llwarns << "$PLOTR$ Can't find OTR SMP verified combo" << llendl; | ||
213 | return; | ||
214 | } | ||
215 | std::string choice = combo->getSimple(); | ||
216 | if (getString("otr_smp_how_by_qa") == choice) | ||
217 | { | ||
218 | howto->setWrappedText(getString("otr_smp_howto_qa")); | ||
219 | label1->setWrappedText(getString("otr_smp_howto_qa_t1")); | ||
220 | edit1->clear(); | ||
221 | edit1->setEnabled(TRUE); | ||
222 | label2->setWrappedText(getString("otr_smp_howto_qa_t2")); | ||
223 | edit2->clear(); | ||
224 | edit2->setEnabled(TRUE); | ||
225 | veri->removeall(); | ||
226 | veri->setLabel(getString("otr_empty_string")); | ||
227 | } | ||
228 | else if (getString("otr_smp_how_by_qa_challenge") == choice) | ||
229 | { | ||
230 | howto->setWrappedText(getString("otr_smp_howto_qa")); | ||
231 | label1->setWrappedText(getString("otr_smp_howto_qa_t1")); | ||
232 | edit1->setText(mQuestion); | ||
233 | edit1->setEnabled(FALSE); | ||
234 | label2->setWrappedText(getString("otr_smp_howto_qa_t2")); | ||
235 | edit2->clear(); | ||
236 | edit2->setEnabled(TRUE); | ||
237 | veri->removeall(); | ||
238 | veri->setLabel(getString("otr_empty_string")); | ||
239 | } | ||
240 | else if (getString("otr_smp_how_by_ss") == choice) | ||
241 | { | ||
242 | howto->setWrappedText(getString("otr_smp_howto_ss")); | ||
243 | label1->setWrappedText(getString("otr_smp_howto_ss_t1")); | ||
244 | edit1->clear(); | ||
245 | edit1->setEnabled(TRUE); | ||
246 | label2->setWrappedText(getString("otr_smp_howto_ss_t2")); | ||
247 | edit2->clear(); | ||
248 | edit2->setEnabled(FALSE); | ||
249 | veri->removeall(); | ||
250 | veri->setLabel(getString("otr_empty_string")); | ||
251 | } | ||
252 | else if (getString("otr_smp_how_by_ss_challenge") == choice) | ||
253 | { | ||
254 | howto->setWrappedText(getString("otr_smp_howto_ss")); | ||
255 | label1->setWrappedText(getString("otr_smp_howto_ss_t1")); | ||
256 | edit1->clear(); | ||
257 | edit1->setEnabled(TRUE); | ||
258 | label2->setWrappedText(getString("otr_smp_howto_ss_t2")); | ||
259 | edit2->clear(); | ||
260 | edit2->setEnabled(FALSE); | ||
261 | veri->removeall(); | ||
262 | veri->setLabel(getString("otr_empty_string")); | ||
263 | } | ||
264 | else if (getString("otr_smp_how_by_mfv") == choice) | ||
265 | { | ||
266 | howto->setWrappedText(getString("otr_smp_howto_mfv")); | ||
267 | label1->setWrappedText(getString("otr_smp_howto_mfv_t1")); | ||
268 | edit1->setText(mMyFingerprint); | ||
269 | edit1->setEnabled(FALSE); | ||
270 | label2->setWrappedText(getString("otr_smp_howto_mfv_t2")); | ||
271 | edit2->setText(mOtherFingerprint); | ||
272 | edit2->setEnabled(FALSE); | ||
273 | veri->add(getString("otr_smp_veri_no"), ADD_BOTTOM, TRUE); | ||
274 | veri->add(getString("otr_smp_veri_yes"), ADD_BOTTOM, TRUE); | ||
275 | veri->selectFirstItem(); | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | llwarns << "$PLOTR$ unknown smp howto choice" << llendl; | ||
280 | } | ||
281 | doVeriMenu(); | ||
282 | } | ||
283 | |||
284 | // static | ||
285 | void OtrFloaterSmpDialog::onClickCombo(LLUICtrl* source, void* userdata) | ||
286 | { | ||
287 | OtrFloaterSmpDialog* self = (OtrFloaterSmpDialog*)userdata; | ||
288 | if (!self) | ||
289 | { | ||
290 | llwarns << "$PLOTR$ can't find OTR SMP dialog." << llendl; | ||
291 | } | ||
292 | else | ||
293 | { | ||
294 | self->doComboMenu(); | ||
295 | } | ||
296 | } | ||
297 | |||
298 | // static | ||
299 | void OtrFloaterSmpDialog::onClickVeri(LLUICtrl* source, void* userdata) | ||
300 | { | ||
301 | OtrFloaterSmpDialog* self = (OtrFloaterSmpDialog*)userdata; | ||
302 | if (!self) | ||
303 | { | ||
304 | llwarns << "$PLOTR$ can't find OTR SMP dialog." << llendl; | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | self->doVeriMenu(); | ||
309 | } | ||
310 | } | ||
311 | |||
312 | // static | ||
313 | void OtrFloaterSmpDialog::onClickHelp(void*) | ||
314 | { | ||
315 | LLWeb::loadURL("http://www.cypherpunks.ca/otr/help/3.2.0/authenticate.php"); | ||
316 | } | ||
317 | |||
318 | // virtual | ||
319 | void OtrFloaterSmpDialog::onClose(bool app_quitting) | ||
320 | { | ||
321 | destroy(); | ||
322 | if (!mIMPanel) | ||
323 | { | ||
324 | llwarns << "$PLOTR$ Can't find mIMPanel." << llendl; | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | mIMPanel->endSmpDialog(); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | // static | ||
333 | void OtrFloaterSmpDialog::onClickCancel(void* userdata) | ||
334 | { | ||
335 | OtrFloaterSmpDialog *self= (OtrFloaterSmpDialog*)userdata; | ||
336 | if (!self) | ||
337 | { | ||
338 | llwarns << "$PLOTR$ can't find OTR SMP dialog." << llendl; | ||
339 | return; | ||
340 | } | ||
341 | self->close(); | ||
342 | } | ||
343 | |||
344 | void OtrFloaterSmpDialog::doClickAuth() | ||
345 | { | ||
346 | LLComboBox *combo = getChild<LLComboBox>("otr_smp_how_combo"); | ||
347 | if (!combo) | ||
348 | { | ||
349 | llwarns << "$PLOTR$ Can't find OTR SMP how combo" << llendl; | ||
350 | return; | ||
351 | } | ||
352 | LLTextBox *howto = getChild<LLTextBox>("otr_smp_howto"); | ||
353 | if (!howto) | ||
354 | { | ||
355 | llwarns << "$PLOTR$ Can't find OTR SMP howto control" << llendl; | ||
356 | return; | ||
357 | } | ||
358 | LLTextBox *label1 = getChild<LLTextBox>("otr_smp_label1"); | ||
359 | if (!label1) | ||
360 | { | ||
361 | llwarns << "$PLOTR$ Can't find OTR SMP label1 control" << llendl; | ||
362 | return; | ||
363 | } | ||
364 | LLLineEditor *edit1 = getChild<LLLineEditor>("otr_smp_edit1"); | ||
365 | if (!edit1) | ||
366 | { | ||
367 | llwarns << "$PLOTR$ Can't find OTR SMP edit1 control" << llendl; | ||
368 | return; | ||
369 | } | ||
370 | LLTextBox *label2 = getChild<LLTextBox>("otr_smp_label2"); | ||
371 | if (!label2) | ||
372 | { | ||
373 | llwarns << "$PLOTR$ Can't find OTR SMP label2 control" << llendl; | ||
374 | return; | ||
375 | } | ||
376 | LLLineEditor *edit2 = getChild<LLLineEditor>("otr_smp_edit2"); | ||
377 | if (!edit2) | ||
378 | { | ||
379 | llwarns << "$PLOTR$ Can't find OTR SMP edit2 control" << llendl; | ||
380 | return; | ||
381 | } | ||
382 | LLComboBox *veri = getChild<LLComboBox>("otr_smp_veri_combo"); | ||
383 | if (!veri) | ||
384 | { | ||
385 | llwarns << "$PLOTR$ Can't find OTR SMP verified combo" << llendl; | ||
386 | return; | ||
387 | } | ||
388 | std::string choice = combo->getSimple(); | ||
389 | if (getString("otr_smp_how_by_qa") == choice) | ||
390 | { | ||
391 | llinfos << "$PLOTR$ OTR SMP QA method chosen" << llendl; | ||
392 | std::string question = edit1->getText(); | ||
393 | std::string answer = edit2->getText(); | ||
394 | mIMPanel->startSmpProgress(mSessionUUID, mOtherParticipantUUID, question, answer); | ||
395 | } | ||
396 | else if (getString("otr_smp_how_by_ss") == choice) | ||
397 | { | ||
398 | llinfos << "$PLOTR$ OTR SMP SS method chosen" << llendl; | ||
399 | std::string secret = edit1->getText(); | ||
400 | mIMPanel->startSmpProgress(mSessionUUID, mOtherParticipantUUID, secret); | ||
401 | } | ||
402 | else if (getString("otr_smp_how_by_mfv") == choice) | ||
403 | { | ||
404 | if (getString("otr_smp_veri_yes") == veri->getSimple()) | ||
405 | { | ||
406 | llinfos << "$PLOTR$ OTR SMP MFV authenticating " << mOtherParticipantUUID << llendl; | ||
407 | otr_authenticate_key(mSessionUUID, "mfv"); | ||
408 | } | ||
409 | } | ||
410 | else if (getString("otr_smp_how_by_qa_challenge") == choice) | ||
411 | { | ||
412 | std::string answer = edit2->getText(); | ||
413 | mIMPanel->startSmpProgress(mSessionUUID, mOtherParticipantUUID, mQuestion, answer, true); | ||
414 | } | ||
415 | else if (getString("otr_smp_how_by_ss_challenge") == choice) | ||
416 | { | ||
417 | std::string secret = edit1->getText(); | ||
418 | mIMPanel->startSmpProgress(mSessionUUID, mOtherParticipantUUID, secret, true); | ||
419 | } | ||
420 | else | ||
421 | { | ||
422 | llwarns << "$PLOTR$ unknown smp howto choice" << llendl; | ||
423 | } | ||
424 | } | ||
425 | |||
426 | // static | ||
427 | void OtrFloaterSmpDialog::onClickAuth(void* userdata) | ||
428 | { | ||
429 | OtrFloaterSmpDialog *self= (OtrFloaterSmpDialog*)userdata; | ||
430 | if (!self) | ||
431 | { | ||
432 | llwarns << "$PLOTR$ can't find OTR SMP dialog." << llendl; | ||
433 | return; | ||
434 | } | ||
435 | self->doClickAuth(); | ||
436 | self->close(); | ||
437 | } | ||
438 | |||