Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: third_party/xmpp/jingleinfotask.cc

Issue 2443903004: Add xmllite and xmpp sources to third_party/ (Closed)
Patch Set: Restored includes in jingle/ as well Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "third_party/xmpp/jingleinfotask.h"
6
7 #include "third_party/xmpp/constants.h"
8 #include "third_party/xmpp/xmppclient.h"
9 #include "third_party/xmpp/xmpptask.h"
10 #include "webrtc/base/socketaddress.h"
11
12 namespace buzz {
13
14 class JingleInfoTask::JingleInfoGetTask : public XmppTask {
15 public:
16 explicit JingleInfoGetTask(XmppTaskParentInterface* parent)
17 : XmppTask(parent, XmppEngine::HL_SINGLE), done_(false) {}
18
19 virtual int ProcessStart() {
20 rtc::scoped_ptr<XmlElement> get(MakeIq(STR_GET, Jid(), task_id()));
21 get->AddElement(new XmlElement(QN_JINGLE_INFO_QUERY, true));
22 if (SendStanza(get.get()) != XMPP_RETURN_OK) {
23 return STATE_ERROR;
24 }
25 return STATE_RESPONSE;
26 }
27 virtual int ProcessResponse() {
28 if (done_)
29 return STATE_DONE;
30 return STATE_BLOCKED;
31 }
32
33 protected:
34 virtual bool HandleStanza(const XmlElement* stanza) {
35 if (!MatchResponseIq(stanza, Jid(), task_id()))
36 return false;
37
38 if (stanza->Attr(QN_TYPE) != STR_RESULT)
39 return false;
40
41 // Queue the stanza with the parent so these don't get handled out of order
42 JingleInfoTask* parent = static_cast<JingleInfoTask*>(GetParent());
43 parent->QueueStanza(stanza);
44
45 // Wake ourselves so we can go into the done state
46 done_ = true;
47 Wake();
48 return true;
49 }
50
51 bool done_;
52 };
53
54 void JingleInfoTask::RefreshJingleInfoNow() {
55 JingleInfoGetTask* get_task = new JingleInfoGetTask(this);
56 get_task->Start();
57 }
58
59 bool JingleInfoTask::HandleStanza(const XmlElement* stanza) {
60 if (!MatchRequestIq(stanza, "set", QN_JINGLE_INFO_QUERY))
61 return false;
62
63 // only respect relay push from the server
64 Jid from(stanza->Attr(QN_FROM));
65 if (!from.IsEmpty() && !from.BareEquals(GetClient()->jid()) &&
66 from != Jid(GetClient()->jid().domain()))
67 return false;
68
69 QueueStanza(stanza);
70 return true;
71 }
72
73 int JingleInfoTask::ProcessStart() {
74 std::vector<std::string> relay_hosts;
75 std::vector<rtc::SocketAddress> stun_hosts;
76 std::string relay_token;
77 const XmlElement* stanza = NextStanza();
78 if (stanza == NULL)
79 return STATE_BLOCKED;
80 const XmlElement* query = stanza->FirstNamed(QN_JINGLE_INFO_QUERY);
81 if (query == NULL)
82 return STATE_START;
83 const XmlElement* stun = query->FirstNamed(QN_JINGLE_INFO_STUN);
84 if (stun) {
85 for (const XmlElement* server = stun->FirstNamed(QN_JINGLE_INFO_SERVER);
86 server != NULL; server = server->NextNamed(QN_JINGLE_INFO_SERVER)) {
87 std::string host = server->Attr(QN_JINGLE_INFO_HOST);
88 std::string port = server->Attr(QN_JINGLE_INFO_UDP);
89 if (host != STR_EMPTY && host != STR_EMPTY) {
90 stun_hosts.push_back(rtc::SocketAddress(host, atoi(port.c_str())));
91 }
92 }
93 }
94
95 const XmlElement* relay = query->FirstNamed(QN_JINGLE_INFO_RELAY);
96 if (relay) {
97 relay_token = relay->TextNamed(QN_JINGLE_INFO_TOKEN);
98 for (const XmlElement* server = relay->FirstNamed(QN_JINGLE_INFO_SERVER);
99 server != NULL; server = server->NextNamed(QN_JINGLE_INFO_SERVER)) {
100 std::string host = server->Attr(QN_JINGLE_INFO_HOST);
101 if (host != STR_EMPTY) {
102 relay_hosts.push_back(host);
103 }
104 }
105 }
106 SignalJingleInfo(relay_token, relay_hosts, stun_hosts);
107 return STATE_START;
108 }
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698