From 87ebf9aee58f2bd53df4a8f143fbf4db4e2eae55 Mon Sep 17 00:00:00 2001 From: Sebastian Becker Date: Mon, 26 Mar 2018 13:52:56 +0200 Subject: [PATCH] Add functions to get all rooms and room lists The new functions get_room_lists(void) and get_rooms(const mailbox&) returns the room lists and the rooms of a room list respectively. --- include/ews/ews.hpp | 123 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/include/ews/ews.hpp b/include/ews/ews.hpp index afd0a8b0..70912a87 100644 --- a/include/ews/ews.hpp +++ b/include/ews/ews.hpp @@ -10141,6 +10141,38 @@ namespace internal std::vector messages_; }; + class get_room_lists_response_message final + : public response_message_with_items + { + public: + // implemented below + static get_room_lists_response_message parse(http_response&&); + + private: + get_room_lists_response_message(response_result&& res, + std::vector&& items) + : response_message_with_items(std::move(res), + std::move(items)) + { + } + }; + + class get_rooms_response_message final + : public response_message_with_items + { + public: + // implemented below + static get_rooms_response_message parse(http_response&&); + + private: + get_rooms_response_message(response_result&& res, + std::vector&& items) + : response_message_with_items(std::move(res), + std::move(items)) + { + } + }; + template class get_item_response_message final : public response_message_with_items @@ -18690,6 +18722,42 @@ class basic_service final return *this; } + //! Gets all room lists in the Exchange store. + std::vector get_room_lists() + { + std::string msg = ""; + auto response = request(msg); + const auto response_message = + internal::get_room_lists_response_message::parse(std::move(response)); + if (!response_message.success()) + { + throw exchange_error(response_message.result()); + } + return response_message.items(); + } + + //! Gets all rooms from a room list in the Exchange store. + std::vector get_rooms(const mailbox& room_list) + { + std::stringstream sstr; + sstr << "" + "" + "" + << room_list.value() + << "" + "" + ""; + + auto response = request(sstr.str()); + const auto response_message = + internal::get_rooms_response_message::parse(std::move(response)); + if (!response_message.success()) + { + throw exchange_error(response_message.result()); + } + return response_message.items(); + } + //! Synchronizes a folder in the Exchange store. sync_folder_items_result sync_folder_items(const folder_id& folder_id, int max_changes_returned = 512) @@ -20891,6 +20959,61 @@ namespace internal return get_folder_response_message(std::move(result), std::move(items)); } + inline get_room_lists_response_message + get_room_lists_response_message::parse(http_response&& response) + { + const auto doc = parse_response(std::move(response)); + auto elem = get_element_by_qname(*doc, "GetRoomListsResponse", + uri<>::microsoft::messages()); + + EWS_ASSERT(elem && + "Expected , got nullptr"); + auto result = parse_response_class_and_code(*elem); + auto room_lists = std::vector(); + auto items_elem = + elem->first_node_ns(uri<>::microsoft::messages(), "RoomLists"); + EWS_ASSERT(items_elem && "Expected element"); + + for_each_child_node( + *items_elem, [&room_lists](const rapidxml::xml_node<>& item_elem) + { + room_lists.emplace_back(mailbox::from_xml_element(item_elem)); + }); + return get_room_lists_response_message(std::move(result), + std::move(room_lists)); + } + + inline get_rooms_response_message + get_rooms_response_message::parse(http_response&& response) + { + const auto doc = parse_response(std::move(response)); + auto elem = get_element_by_qname(*doc, "GetRoomsResponse", + uri<>::microsoft::messages()); + + EWS_ASSERT(elem && + "Expected , got nullptr"); + auto result = parse_response_class_and_code(*elem); + auto rooms = std::vector(); + auto items_elem = + elem->first_node_ns(uri<>::microsoft::messages(), "Rooms"); + if (!items_elem) + { + return get_rooms_response_message(std::move(result), + std::move(rooms)); + } + + for_each_child_node( + *items_elem, [&rooms](const rapidxml::xml_node<>& item_elem) + { + auto room_elem = item_elem.first_node_ns(uri<>::microsoft::types(), + "Id"); + EWS_ASSERT(room_elem && "Expected element"); + rooms.emplace_back(mailbox::from_xml_element(*room_elem)); + }); + return get_rooms_response_message(std::move(result), + std::move(rooms)); + } + inline folder_response_message folder_response_message::parse(http_response&& response) {