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

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

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

Powered by Google App Engine
This is Rietveld 408576698