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 <string>
12 #include <vector>
13
14 #include "webrtc/libjingle/xmpp/mucroomconfigtask.h"
15
16 #include "webrtc/libjingle/xmpp/constants.h"
17 #include "webrtc/base/scoped_ptr.h"
18
19 namespace buzz {
20
MucRoomConfigTask(XmppTaskParentInterface * parent,const Jid & room_jid,const std::string & room_name,const std::vector<std::string> & room_features)21 MucRoomConfigTask::MucRoomConfigTask(
22 XmppTaskParentInterface* parent,
23 const Jid& room_jid,
24 const std::string& room_name,
25 const std::vector<std::string>& room_features)
26 : IqTask(parent, STR_SET, room_jid,
27 MakeRequest(room_name, room_features)),
28 room_jid_(room_jid) {
29 }
30
MakeRequest(const std::string & room_name,const std::vector<std::string> & room_features)31 XmlElement* MucRoomConfigTask::MakeRequest(
32 const std::string& room_name,
33 const std::vector<std::string>& room_features) {
34 buzz::XmlElement* owner_query = new
35 buzz::XmlElement(buzz::QN_MUC_OWNER_QUERY, true);
36
37 buzz::XmlElement* x_form = new buzz::XmlElement(buzz::QN_XDATA_X, true);
38 x_form->SetAttr(buzz::QN_TYPE, buzz::STR_FORM);
39
40 buzz::XmlElement* roomname_field =
41 new buzz::XmlElement(buzz::QN_XDATA_FIELD, false);
42 roomname_field->SetAttr(buzz::QN_VAR, buzz::STR_MUC_ROOMCONFIG_ROOMNAME);
43 roomname_field->SetAttr(buzz::QN_TYPE, buzz::STR_TEXT_SINGLE);
44
45 buzz::XmlElement* roomname_value =
46 new buzz::XmlElement(buzz::QN_XDATA_VALUE, false);
47 roomname_value->SetBodyText(room_name);
48
49 roomname_field->AddElement(roomname_value);
50 x_form->AddElement(roomname_field);
51
52 buzz::XmlElement* features_field =
53 new buzz::XmlElement(buzz::QN_XDATA_FIELD, false);
54 features_field->SetAttr(buzz::QN_VAR, buzz::STR_MUC_ROOMCONFIG_FEATURES);
55 features_field->SetAttr(buzz::QN_TYPE, buzz::STR_LIST_MULTI);
56
57 for (std::vector<std::string>::const_iterator feature = room_features.begin();
58 feature != room_features.end(); ++feature) {
59 buzz::XmlElement* features_value =
60 new buzz::XmlElement(buzz::QN_XDATA_VALUE, false);
61 features_value->SetBodyText(*feature);
62 features_field->AddElement(features_value);
63 }
64
65 x_form->AddElement(features_field);
66 owner_query->AddElement(x_form);
67 return owner_query;
68 }
69
HandleResult(const XmlElement * element)70 void MucRoomConfigTask::HandleResult(const XmlElement* element) {
71 SignalResult(this);
72 }
73
74 } // namespace buzz
75