3
* Copyright 2006, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
#include "libjingleplus.h"
31
#include "talk/base/win32socketserver.h"
33
#include "talk/base/physicalsocketserver.h"
34
#include "talk/base/logging.h"
35
#include "talk/examples/login/xmppauth.h"
36
#include "talk/examples/login/xmppsocket.h"
37
#include "talk/examples/login/xmpppump.h"
38
#include "presencepushtask.h"
39
#include "talk/app/status.h"
40
#include "talk/app/message.h"
41
#include "rostertask.h"
42
#include "talk/app/iqtask.h"
43
#include "talk/app/presenceouttask.h"
44
#include "talk/app/receivemessagetask.h"
45
#include "talk/app/rostersettask.h"
46
#include "talk/app/sendmessagetask.h"
51
// main thread to worker
55
MSG_SEND_DIRECTED_PRESENCE,
56
MSG_SEND_DIRECTED_MUC_PRESENCE,
57
MSG_SEND_XMPP_MESSAGE,
59
MSG_UPDATE_ROSTER_ITEM,
60
MSG_REMOVE_ROSTER_ITEM,
62
// worker thread to main thread
66
MSG_ROSTER_REFRESH_STARTED,
67
MSG_ROSTER_REFRESH_FINISHED,
68
MSG_ROSTER_ITEM_UPDATED,
69
MSG_ROSTER_ITEM_REMOVED,
71
MSG_ROSTER_UNSUBSCRIBE,
72
MSG_ROSTER_SUBSCRIBED,
73
MSG_ROSTER_UNSUBSCRIBED,
80
class LibjinglePlusWorker : public talk_base::MessageHandler,
81
public XmppPumpNotify,
82
public sigslot::has_slots<> {
84
LibjinglePlusWorker(LibjinglePlus *ljp, LibjinglePlusNotify *notify) :
85
worker_thread_(NULL), ljp_(ljp), notify_(notify),
86
ppt_(NULL), rmt_(NULL), rt_(NULL), is_test_login_(false) {
88
main_thread_.reset(new talk_base::AutoThread());
90
ss_.reset(new talk_base::Win32SocketServer(main_thread_.get()));
91
main_thread_->set_socketserver(ss_.get());
94
pump_.reset(new XmppPump(this));
96
pump_->client()->SignalLogInput.connect(this, &LibjinglePlusWorker::OnInputDebug);
97
pump_->client()->SignalLogOutput.connect(this, &LibjinglePlusWorker::OnOutputDebug);
98
//pump_->client()->SignalStateChange.connect(this, &LibjinglePlusWorker::OnStateChange);
101
~LibjinglePlusWorker() {
102
if (worker_thread_) {
103
worker_thread_->Send(this, MSG_DISCONNECT);
104
delete worker_thread_;
108
virtual void OnMessage(talk_base::Message *msg) {
109
switch (msg->message_id) {
116
case MSG_SEND_XMPP_MESSAGE:
117
SendXmppMessageW(static_cast<SendMessageData*>(msg->pdata)->m_);
120
case MSG_SEND_XMPP_IQ:
121
SendXmppIqW(static_cast<SendIqData*>(msg->pdata)->to_jid_,
122
static_cast<SendIqData*>(msg->pdata)->is_get_,
123
static_cast<SendIqData*>(msg->pdata)->xml_element_);
126
case MSG_SEND_PRESENCE:
127
SendPresenceW(static_cast<SendPresenceData*>(msg->pdata)->s_);
130
case MSG_SEND_DIRECTED_PRESENCE:
131
SendDirectedPresenceW(static_cast<SendDirectedPresenceData*>(msg->pdata)->j_,
132
static_cast<SendDirectedPresenceData*>(msg->pdata)->s_);
135
case MSG_SEND_DIRECTED_MUC_PRESENCE:
136
SendDirectedMUCPresenceW(static_cast<SendDirectedMUCPresenceData*>(msg->pdata)->j_,
137
static_cast<SendDirectedMUCPresenceData*>(msg->pdata)->s_,
138
static_cast<SendDirectedMUCPresenceData*>(msg->pdata)->un_,
139
static_cast<SendDirectedMUCPresenceData*>(msg->pdata)->ac_,
140
static_cast<SendDirectedMUCPresenceData*>(msg->pdata)->am_,
141
static_cast<SendDirectedMUCPresenceData*>(msg->pdata)->role_);
144
case MSG_UPDATE_ROSTER_ITEM:
145
UpdateRosterItemW(static_cast<UpdateRosterItemData*>(msg->pdata)->jid_,
146
static_cast<UpdateRosterItemData*>(msg->pdata)->n_,
147
static_cast<UpdateRosterItemData*>(msg->pdata)->g_,
148
static_cast<UpdateRosterItemData*>(msg->pdata)->grt_);
151
case MSG_REMOVE_ROSTER_ITEM:
152
RemoveRosterItemW(static_cast<JidData*>(msg->pdata)->jid_);
159
case MSG_STATUS_UPDATE:
160
OnStatusUpdateW(static_cast<SendPresenceData*>(msg->pdata)->s_);
163
case MSG_STATUS_ERROR:
164
OnStatusErrorW(static_cast<StatusErrorData*>(msg->pdata)->stanza_);
167
case MSG_STATE_CHANGE:
168
OnStateChangeW(static_cast<StateChangeData*>(msg->pdata)->s_);
171
case MSG_ROSTER_REFRESH_STARTED:
172
OnRosterRefreshStartedW();
174
case MSG_ROSTER_REFRESH_FINISHED:
175
OnRosterRefreshFinishedW();
177
case MSG_ROSTER_ITEM_UPDATED:
178
OnRosterItemUpdatedW(static_cast<RosterItemData*>(msg->pdata)->ri_);
181
case MSG_ROSTER_ITEM_REMOVED:
182
OnRosterItemRemovedW(static_cast<RosterItemData*>(msg->pdata)->ri_);
185
case MSG_ROSTER_SUBSCRIBE:
186
OnRosterSubscribeW(static_cast<JidData*>(msg->pdata)->jid_);
189
case MSG_ROSTER_UNSUBSCRIBE:
190
OnRosterUnsubscribeW(static_cast<JidData*>(msg->pdata)->jid_);
193
case MSG_ROSTER_SUBSCRIBED:
194
OnRosterSubscribedW(static_cast<JidData*>(msg->pdata)->jid_);
197
case MSG_ROSTER_UNSUBSCRIBED:
198
OnRosterUnsubscribedW(static_cast<JidData*>(msg->pdata)->jid_);
201
case MSG_INCOMING_MESSAGE:
202
OnIncomingMessageW(static_cast<XmppMessageData*>(msg->pdata)->m_);
205
case MSG_IQ_COMPLETE:
206
OnIqCompleteW(static_cast<IqCompleteData*>(msg->pdata)->success_,
207
static_cast<IqCompleteData*>(msg->pdata)->stanza_);
210
case MSG_XMPP_OUTPUT:
211
OnOutputDebugW(static_cast<StringData*>(msg->pdata)->s_);
215
OnInputDebugW(static_cast<StringData*>(msg->pdata)->s_);
221
void Login(const std::string &jid, const std::string &password,
222
const std::string &machine_address, bool is_test, bool cookie_auth) {
223
is_test_login_ = is_test;
227
xcs_.set_auth_cookie(password);
229
talk_base::InsecureCryptStringImpl pass;
230
pass.password() = password;
231
xcs_.set_pass(talk_base::CryptString(pass));
233
xcs_.set_host(is_test ? "google.com" : "gmail.com");
234
xcs_.set_resource("libjingleplus");
235
xcs_.set_server(talk_base::SocketAddress(machine_address, 5222));
236
xcs_.set_use_tls(!is_test);
238
xcs_.set_allow_plain(true);
241
worker_thread_ = new talk_base::Thread(&pss_);
242
worker_thread_->Start();
243
worker_thread_->Send(this, MSG_START);
246
void SendXmppMessage(const buzz::XmppMessage &m) {
247
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
248
worker_thread_->Post(this, MSG_SEND_XMPP_MESSAGE, new SendMessageData(m));
251
void SendXmppIq(const buzz::Jid &to_jid, bool is_get,
252
const buzz::XmlElement *xml_element) {
253
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
254
worker_thread_->Post(this, MSG_SEND_XMPP_IQ,
255
new SendIqData(to_jid, is_get, xml_element));
258
void SendPresence(const buzz::Status & s) {
259
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
260
worker_thread_->Post(this, MSG_SEND_PRESENCE, new SendPresenceData(s));
263
void SendDirectedPresence (const buzz::Jid &j, const buzz::Status &s) {
264
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
265
worker_thread_->Post(this, MSG_SEND_DIRECTED_PRESENCE, new SendDirectedPresenceData(j,s));
268
void SendDirectedMUCPresence(const buzz::Jid &j, const buzz::Status &s,
269
const std::string &un, const std::string &ac,
270
const std::string &am, const std::string &role) {
271
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
272
worker_thread_->Post(this, MSG_SEND_DIRECTED_MUC_PRESENCE, new SendDirectedMUCPresenceData(j,s,un,ac,am, role));
275
void UpdateRosterItem(const buzz::Jid & jid, const std::string & name,
276
const std::vector<std::string> & groups, buzz::GrType grt) {
277
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
278
worker_thread_->Post(this, MSG_UPDATE_ROSTER_ITEM, new UpdateRosterItemData(jid,name,groups,grt));
281
void RemoveRosterItemW(const buzz::Jid &jid) {
282
buzz::RosterSetTask *rst = new buzz::RosterSetTask(pump_.get()->client());
287
void RemoveRosterItem(const buzz::Jid &jid) {
288
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
289
worker_thread_->Post(this, MSG_REMOVE_ROSTER_ITEM, new JidData(jid));
293
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
294
talk_base::Message m;
295
while (main_thread_->Get(&m, 0)) {
296
main_thread_->Dispatch(&m);
302
struct UpdateRosterItemData : public talk_base::MessageData {
303
UpdateRosterItemData(const buzz::Jid &jid, const std::string &name,
304
const std::vector<std::string> &groups, buzz::GrType grt) :
305
jid_(jid), n_(name), g_(groups), grt_(grt) {}
308
std::vector<std::string> g_;
312
void UpdateRosterItemW(const buzz::Jid &jid, const std::string &name,
313
const std::vector<std::string> &groups, buzz::GrType grt) {
314
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
315
buzz::RosterSetTask *rst = new buzz::RosterSetTask(pump_.get()->client());
316
rst->Update(jid, name, groups, grt);
320
struct StringData : public talk_base::MessageData {
321
StringData(std::string s) : s_(s) {}
325
void OnInputDebugW(const std::string &data) {
326
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
328
notify_->OnXmppInput(data);
331
void OnInputDebug(const char *data, int len) {
332
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
333
main_thread_->Post(this, MSG_XMPP_INPUT, new StringData(std::string(data,len)));
335
notify_->WakeupMainThread();
338
void OnOutputDebugW(const std::string &data) {
339
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
341
notify_->OnXmppOutput(data);
344
void OnOutputDebug(const char *data, int len) {
345
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
346
main_thread_->Post(this, MSG_XMPP_OUTPUT, new StringData(std::string(data,len)));
348
notify_->WakeupMainThread();
351
struct StateChangeData : public talk_base::MessageData {
352
StateChangeData(buzz::XmppEngine::State state) : s_(state) {}
353
buzz::XmppEngine::State s_;
356
void OnStateChange(buzz::XmppEngine::State state) {
357
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
359
case buzz::XmppEngine::STATE_OPEN:
360
ppt_ = new buzz::PresencePushTask(pump_.get()->client());
361
ppt_->SignalStatusUpdate.connect(this,
362
&LibjinglePlusWorker::OnStatusUpdate);
363
ppt_->SignalStatusError.connect(this,
364
&LibjinglePlusWorker::OnStatusError);
367
rmt_ = new buzz::ReceiveMessageTask(pump_.get()->client(), buzz::XmppEngine::HL_ALL);
368
rmt_->SignalIncomingMessage.connect(this, &LibjinglePlusWorker::OnIncomingMessage);
371
rt_ = new buzz::RosterTask(pump_.get()->client());
372
rt_->SignalRosterItemUpdated.connect(this, &LibjinglePlusWorker::OnRosterItemUpdated);
373
rt_->SignalRosterItemRemoved.connect(this, &LibjinglePlusWorker::OnRosterItemRemoved);
374
rt_->SignalSubscribe.connect(this, &LibjinglePlusWorker::OnRosterSubscribe);
375
rt_->SignalUnsubscribe.connect(this, &LibjinglePlusWorker::OnRosterUnsubscribe);
376
rt_->SignalSubscribed.connect(this, &LibjinglePlusWorker::OnRosterSubscribed);
377
rt_->SignalUnsubscribed.connect(this, &LibjinglePlusWorker::OnRosterUnsubscribed);
378
rt_->SignalRosterRefreshStarted.connect(this, &LibjinglePlusWorker::OnRosterRefreshStarted);
379
rt_->SignalRosterRefreshFinished.connect(this, &LibjinglePlusWorker::OnRosterRefreshFinished);
381
rt_->RefreshRosterNow();
385
main_thread_->Post(this, MSG_STATE_CHANGE, new StateChangeData(state));
387
notify_->WakeupMainThread();
390
void OnStateChangeW(buzz::XmppEngine::State state) {
391
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
393
notify_->OnStateChange(state);
396
struct RosterItemData : public talk_base::MessageData {
397
RosterItemData(const buzz::RosterItem &ri) : ri_(ri) {}
398
buzz::RosterItem ri_;
401
void OnRosterItemUpdatedW(const buzz::RosterItem &ri) {
402
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
404
notify_->OnRosterItemUpdated(ri);
407
void OnRosterItemUpdated(const buzz::RosterItem &ri, bool huh) {
408
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
409
main_thread_->Post(this, MSG_ROSTER_ITEM_UPDATED, new RosterItemData(ri));
411
notify_->WakeupMainThread();
414
void OnRosterItemRemovedW(const buzz::RosterItem &ri) {
415
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
417
notify_->OnRosterItemRemoved(ri);
420
void OnRosterItemRemoved(const buzz::RosterItem &ri) {
421
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
422
main_thread_->Post(this, MSG_ROSTER_ITEM_REMOVED, new RosterItemData(ri));
424
notify_->WakeupMainThread();
427
struct JidData : public talk_base::MessageData {
428
JidData(const buzz::Jid& jid) : jid_(jid) {}
429
const buzz::Jid jid_;
432
void OnRosterSubscribeW(const buzz::Jid& jid) {
433
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
435
notify_->OnRosterSubscribe(jid);
438
void OnRosterSubscribe(const buzz::Jid& jid) {
439
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
440
main_thread_->Post(this, MSG_ROSTER_SUBSCRIBE, new JidData(jid));
442
notify_->WakeupMainThread();
445
void OnRosterUnsubscribeW(const buzz::Jid &jid) {
446
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
448
notify_->OnRosterUnsubscribe(jid);
451
void OnRosterUnsubscribe(const buzz::Jid &jid) {
452
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
453
main_thread_->Post(this, MSG_ROSTER_UNSUBSCRIBE, new JidData(jid));
455
notify_->WakeupMainThread();
458
void OnRosterSubscribedW(const buzz::Jid &jid) {
459
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
461
notify_->OnRosterSubscribed(jid);
464
void OnRosterSubscribed(const buzz::Jid &jid) {
465
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
466
main_thread_->Post(this, MSG_ROSTER_SUBSCRIBED, new JidData(jid));
468
notify_->WakeupMainThread();
471
void OnRosterUnsubscribedW(const buzz::Jid &jid) {
472
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
474
notify_->OnRosterUnsubscribed(jid);
477
void OnRosterUnsubscribed(const buzz::Jid &jid) {
478
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
479
main_thread_->Post(this, MSG_ROSTER_UNSUBSCRIBED, new JidData(jid));
481
notify_->WakeupMainThread();
484
void OnRosterRefreshStartedW() {
485
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
487
notify_->OnRosterRefreshStarted();
490
void OnRosterRefreshStarted() {
491
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
492
main_thread_->Post(this, MSG_ROSTER_REFRESH_STARTED);
494
notify_->WakeupMainThread();
497
void OnRosterRefreshFinishedW() {
498
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
500
notify_->OnRosterRefreshFinished();
503
void OnRosterRefreshFinished() {
504
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
505
main_thread_->Post(this, MSG_ROSTER_REFRESH_FINISHED);
507
notify_->WakeupMainThread();
510
struct XmppMessageData : talk_base::MessageData {
511
XmppMessageData(const buzz::XmppMessage &m) : m_(m) {}
512
buzz::XmppMessage m_;
515
void OnIncomingMessageW(const buzz::XmppMessage &msg) {
516
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
518
notify_->OnMessage(msg);
521
void OnIncomingMessage(const buzz::XmppMessage &msg) {
522
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
523
main_thread_->Post(this, MSG_INCOMING_MESSAGE, new XmppMessageData(msg));
525
notify_->WakeupMainThread();
528
void OnStatusUpdateW (const buzz::Status &status) {
529
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
531
notify_->OnStatusUpdate(status);
534
void OnStatusUpdate (const buzz::Status &status) {
535
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
536
main_thread_->Post(this, MSG_STATUS_UPDATE, new SendPresenceData(status));
538
notify_->WakeupMainThread();
541
struct StatusErrorData : talk_base::MessageData {
542
StatusErrorData(const buzz::XmlElement &stanza) : stanza_(stanza) {}
543
buzz::XmlElement stanza_;
546
void OnStatusErrorW (const buzz::XmlElement &stanza) {
547
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
549
notify_->OnStatusError(stanza);
552
void OnStatusError (const buzz::XmlElement &stanza) {
553
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
554
main_thread_->Post(this, MSG_STATUS_ERROR, new StatusErrorData(stanza));
556
notify_->WakeupMainThread();
560
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
561
XmppSocket* socket = new XmppSocket(true);
562
pump_->DoLogin(xcs_, socket, is_test_login_ ? NULL : new XmppAuth());
563
socket->SignalCloseEvent.connect(this,
564
&LibjinglePlusWorker::OnXmppSocketClose);
568
assert(talk_base::ThreadManager::CurrentThread() == worker_thread_);
569
pump_->DoDisconnect();
572
void SendXmppMessageW(const buzz::XmppMessage &m) {
573
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
574
buzz::SendMessageTask * smt = new buzz::SendMessageTask(pump_.get()->client());
579
void SendXmppIqW(const buzz::Jid &to_jid, bool is_get,
580
const buzz::XmlElement *xml_element) {
581
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
582
buzz::IqTask *iq_task = new buzz::IqTask(pump_.get()->client(),
583
is_get, to_jid, const_cast<buzz::XmlElement *>(xml_element));
584
iq_task->SignalDone.connect(this, &LibjinglePlusWorker::OnIqComplete);
588
struct IqCompleteData : public talk_base::MessageData {
589
IqCompleteData(bool success, const buzz::XmlElement *stanza) :
590
success_(success), stanza_(*stanza) {}
592
buzz::XmlElement stanza_;
595
void OnIqCompleteW(bool success, const buzz::XmlElement& stanza) {
596
assert(talk_base::ThreadManager::CurrentThread() != worker_thread_);
598
notify_->OnIqDone(success, stanza);
601
void OnIqComplete(bool success, const buzz::XmlElement *stanza) {
602
assert(talk_base::ThreadManager::CurrentThread() == worker_thread_);
603
main_thread_->Post(this, MSG_IQ_COMPLETE,
604
new IqCompleteData(success, stanza));
606
notify_->WakeupMainThread();
609
void SendPresenceW(const buzz::Status & s) {
610
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
611
buzz::PresenceOutTask *pot = new buzz::PresenceOutTask(pump_.get()->client());
617
void SendDirectedMUCPresenceW(const buzz::Jid & j, const buzz::Status & s,
618
const std::string &user_nick, const std::string &api_capability,
619
const std::string &api_message, const std::string &role) {
620
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
621
buzz::PresenceOutTask *pot = new buzz::PresenceOutTask(pump_.get()->client());
622
pot->SendDirectedMUC(j,s,user_nick,api_capability,api_message, role);
626
void SendDirectedPresenceW(const buzz::Jid & j, const buzz::Status & s) {
627
assert (talk_base::ThreadManager::CurrentThread() == worker_thread_);
628
buzz::PresenceOutTask *pot = new buzz::PresenceOutTask(pump_.get()->client());
629
pot->SendDirected(j,s);
633
void OnXmppSocketClose(int error) {
634
notify_->OnSocketClose(error);
637
struct SendMessageData : public talk_base::MessageData {
638
SendMessageData(const buzz::XmppMessage &m) : m_(m) {}
639
buzz::XmppMessage m_;
642
struct SendIqData : public talk_base::MessageData {
643
SendIqData(const buzz::Jid &jid, bool is_get, const buzz::XmlElement *m)
644
: to_jid_(jid), is_get_(is_get), xml_element_(m) {}
647
const buzz::XmlElement *xml_element_;
650
struct SendPresenceData : public talk_base::MessageData {
651
SendPresenceData(const buzz::Status &s) : s_(s) {}
655
struct SendDirectedPresenceData : public talk_base::MessageData {
656
SendDirectedPresenceData(const buzz::Jid &j, const buzz::Status &s) : j_(j), s_(s) {}
661
struct SendDirectedMUCPresenceData : public talk_base::MessageData {
662
SendDirectedMUCPresenceData(const buzz::Jid &j, const buzz::Status &s,
663
const std::string &un, const std::string &ac,
664
const std::string &am, const std::string &role)
665
: j_(j), s_(s), un_(un), ac_(ac), am_(am), role_(role) {}
674
talk_base::scoped_ptr<talk_base::Win32SocketServer> ss_;
675
talk_base::scoped_ptr<talk_base::Thread> main_thread_;
676
talk_base::Thread *worker_thread_;
679
LibjinglePlusNotify *notify_;
680
buzz::XmppClientSettings xcs_;
681
talk_base::PhysicalSocketServer pss_;
683
talk_base::scoped_ptr<XmppPump> pump_;
684
buzz::PresencePushTask * ppt_;
685
buzz::ReceiveMessageTask * rmt_;
686
buzz::RosterTask * rt_;
691
LibjinglePlus::LibjinglePlus(LibjinglePlusNotify *notify)
693
worker_ = new LibjinglePlusWorker(this, notify);
696
LibjinglePlus::~LibjinglePlus()
702
void LibjinglePlus::Login(const std::string &jid,
703
const std::string &password,
704
const std::string &machine_address,
705
bool is_test, bool cookie_auth) {
706
worker_->Login(jid, password, machine_address, is_test, cookie_auth);
709
void LibjinglePlus::SendPresence(const buzz::Status & s) {
710
worker_->SendPresence(s);
713
void LibjinglePlus::SendDirectedPresence(const buzz::Jid & j, const buzz::Status & s) {
714
worker_->SendDirectedPresence(j,s);
717
void LibjinglePlus::SendDirectedMUCPresence(const buzz::Jid & j,
718
const buzz::Status & s, const std::string &user_nick,
719
const std::string &api_capability, const std::string &api_message,
720
const std::string &role) {
721
worker_->SendDirectedMUCPresence(j,s,user_nick,api_capability,api_message,
725
void LibjinglePlus::SendXmppMessage(const buzz::XmppMessage & m) {
726
worker_->SendXmppMessage(m);
729
void LibjinglePlus::SendXmppIq(const buzz::Jid &to_jid, bool is_get,
730
const buzz::XmlElement *iq_element) {
731
worker_->SendXmppIq(to_jid, is_get, iq_element);
734
void LibjinglePlus::DoCallbacks() {
735
worker_->DoCallbacks();