| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2004 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/constants.h" | |
| 12 #include "webrtc/libjingle/xmpp/discoitemsquerytask.h" | |
| 13 #include "webrtc/libjingle/xmpp/xmpptask.h" | |
| 14 | |
| 15 namespace buzz { | |
| 16 | |
| 17 DiscoItemsQueryTask::DiscoItemsQueryTask(XmppTaskParentInterface* parent, | |
| 18 const Jid& to, | |
| 19 const std::string& node) | |
| 20 : IqTask(parent, STR_GET, to, MakeRequest(node)) { | |
| 21 } | |
| 22 | |
| 23 XmlElement* DiscoItemsQueryTask::MakeRequest(const std::string& node) { | |
| 24 XmlElement* element = new XmlElement(QN_DISCO_ITEMS_QUERY, true); | |
| 25 if (!node.empty()) { | |
| 26 element->AddAttr(QN_NODE, node); | |
| 27 } | |
| 28 return element; | |
| 29 } | |
| 30 | |
| 31 void DiscoItemsQueryTask::HandleResult(const XmlElement* stanza) { | |
| 32 const XmlElement* query = stanza->FirstNamed(QN_DISCO_ITEMS_QUERY); | |
| 33 if (query) { | |
| 34 std::vector<DiscoItem> items; | |
| 35 for (const buzz::XmlChild* child = query->FirstChild(); child; | |
| 36 child = child->NextChild()) { | |
| 37 DiscoItem item; | |
| 38 const buzz::XmlElement* child_element = child->AsElement(); | |
| 39 if (ParseItem(child_element, &item)) { | |
| 40 items.push_back(item); | |
| 41 } | |
| 42 } | |
| 43 SignalResult(items); | |
| 44 } else { | |
| 45 SignalError(this, NULL); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 bool DiscoItemsQueryTask::ParseItem(const XmlElement* element, | |
| 50 DiscoItem* item) { | |
| 51 if (element->HasAttr(QN_JID)) { | |
| 52 return false; | |
| 53 } | |
| 54 | |
| 55 item->jid = element->Attr(QN_JID); | |
| 56 item->name = element->Attr(QN_NAME); | |
| 57 item->node = element->Attr(QN_NODE); | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 } // namespace buzz | |
| OLD | NEW |