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

Side by Side Diff: webrtc/libjingle/xmpp/mucroomlookuptask.cc

Issue 2617443003: Remove webrtc/libjingle/{xmllite,xmpp} (Closed)
Patch Set: 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 2011 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 "webrtc/libjingle/xmpp/mucroomlookuptask.h"
12
13 #include "webrtc/libjingle/xmpp/constants.h"
14 #include "webrtc/base/logging.h"
15
16
17 namespace buzz {
18
19 MucRoomLookupTask*
20 MucRoomLookupTask::CreateLookupTaskForRoomName(XmppTaskParentInterface* parent,
21 const Jid& lookup_server_jid,
22 const std::string& room_name,
23 const std::string& room_domain) {
24 return new MucRoomLookupTask(parent, lookup_server_jid,
25 MakeNameQuery(room_name, room_domain));
26 }
27
28 MucRoomLookupTask*
29 MucRoomLookupTask::CreateLookupTaskForRoomJid(XmppTaskParentInterface* parent,
30 const Jid& lookup_server_jid,
31 const Jid& room_jid) {
32 return new MucRoomLookupTask(parent, lookup_server_jid,
33 MakeJidQuery(room_jid));
34 }
35
36 MucRoomLookupTask*
37 MucRoomLookupTask::CreateLookupTaskForHangoutId(XmppTaskParentInterface* parent,
38 const Jid& lookup_server_jid,
39 const std::string& hangout_id) {
40 return new MucRoomLookupTask(parent, lookup_server_jid,
41 MakeHangoutIdQuery(hangout_id));
42 }
43
44 MucRoomLookupTask*
45 MucRoomLookupTask::CreateLookupTaskForExternalId(
46 XmppTaskParentInterface* parent,
47 const Jid& lookup_server_jid,
48 const std::string& external_id,
49 const std::string& type) {
50 return new MucRoomLookupTask(parent, lookup_server_jid,
51 MakeExternalIdQuery(external_id, type));
52 }
53
54 MucRoomLookupTask::MucRoomLookupTask(XmppTaskParentInterface* parent,
55 const Jid& lookup_server_jid,
56 XmlElement* query)
57 : IqTask(parent, STR_SET, lookup_server_jid, query) {
58 }
59
60 XmlElement* MucRoomLookupTask::MakeNameQuery(
61 const std::string& room_name, const std::string& room_domain) {
62 XmlElement* name_elem = new XmlElement(QN_SEARCH_ROOM_NAME, false);
63 name_elem->SetBodyText(room_name);
64
65 XmlElement* domain_elem = new XmlElement(QN_SEARCH_ROOM_DOMAIN, false);
66 domain_elem->SetBodyText(room_domain);
67
68 XmlElement* query = new XmlElement(QN_SEARCH_QUERY, true);
69 query->AddElement(name_elem);
70 query->AddElement(domain_elem);
71 return query;
72 }
73
74 XmlElement* MucRoomLookupTask::MakeJidQuery(const Jid& room_jid) {
75 XmlElement* jid_elem = new XmlElement(QN_SEARCH_ROOM_JID);
76 jid_elem->SetBodyText(room_jid.Str());
77
78 XmlElement* query = new XmlElement(QN_SEARCH_QUERY);
79 query->AddElement(jid_elem);
80 return query;
81 }
82
83 XmlElement* MucRoomLookupTask::MakeExternalIdQuery(
84 const std::string& external_id, const std::string& type) {
85 XmlElement* external_id_elem = new XmlElement(QN_SEARCH_EXTERNAL_ID);
86 external_id_elem->SetAttr(QN_TYPE, type);
87 external_id_elem->SetBodyText(external_id);
88
89 XmlElement* query = new XmlElement(QN_SEARCH_QUERY);
90 query->AddElement(external_id_elem);
91 return query;
92 }
93
94 // Construct a stanza to lookup the muc jid for a given hangout id. eg:
95 //
96 // <query xmlns="jabber:iq:search">
97 // <hangout-id>0b48ad092c893a53b7bfc87422caf38e93978798e</hangout-id>
98 // </query>
99 XmlElement* MucRoomLookupTask::MakeHangoutIdQuery(
100 const std::string& hangout_id) {
101 XmlElement* hangout_id_elem = new XmlElement(QN_SEARCH_HANGOUT_ID, false);
102 hangout_id_elem->SetBodyText(hangout_id);
103
104 XmlElement* query = new XmlElement(QN_SEARCH_QUERY, true);
105 query->AddElement(hangout_id_elem);
106 return query;
107 }
108
109 // Handle a response like the following:
110 //
111 // <query xmlns="jabber:iq:search">
112 // <item jid="muvc-private-chat-guid@groupchat.google.com">
113 // <room-name>0b48ad092c893a53b7bfc87422caf38e93978798e</room-name>
114 // <room-domain>hangout.google.com</room-domain>
115 // </item>
116 // </query>
117 void MucRoomLookupTask::HandleResult(const XmlElement* stanza) {
118 const XmlElement* query_elem = stanza->FirstNamed(QN_SEARCH_QUERY);
119 if (query_elem == NULL) {
120 SignalError(this, stanza);
121 return;
122 }
123
124 const XmlElement* item_elem = query_elem->FirstNamed(QN_SEARCH_ITEM);
125 if (item_elem == NULL) {
126 SignalError(this, stanza);
127 return;
128 }
129
130 MucRoomInfo room;
131 room.jid = Jid(item_elem->Attr(buzz::QN_JID));
132 if (!room.jid.IsValid()) {
133 SignalError(this, stanza);
134 return;
135 }
136
137 const XmlElement* room_name_elem =
138 item_elem->FirstNamed(QN_SEARCH_ROOM_NAME);
139 if (room_name_elem != NULL) {
140 room.name = room_name_elem->BodyText();
141 }
142
143 const XmlElement* room_domain_elem =
144 item_elem->FirstNamed(QN_SEARCH_ROOM_DOMAIN);
145 if (room_domain_elem != NULL) {
146 room.domain = room_domain_elem->BodyText();
147 }
148
149 const XmlElement* hangout_id_elem =
150 item_elem->FirstNamed(QN_SEARCH_HANGOUT_ID);
151 if (hangout_id_elem != NULL) {
152 room.hangout_id = hangout_id_elem->BodyText();
153 }
154
155 SignalResult(this, room);
156 }
157
158 } // namespace buzz
OLDNEW
« no previous file with comments | « webrtc/libjingle/xmpp/mucroomlookuptask.h ('k') | webrtc/libjingle/xmpp/mucroomlookuptask_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698