~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/xmpp/mucroomhistorytask.cc

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
Import upstream version 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libjingle
 
3
 * Copyright 2011, Google Inc.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
8
 *  1. Redistributions of source code must retain the above copyright notice,
 
9
 *     this list of conditions and the following disclaimer.
 
10
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 
11
 *     this list of conditions and the following disclaimer in the documentation
 
12
 *     and/or other materials provided with the distribution.
 
13
 *  3. The name of the author may not be used to endorse or promote products
 
14
 *     derived from this software without specific prior written permission.
 
15
 *
 
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
17
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
18
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
19
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
20
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
21
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
22
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
23
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
24
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
25
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
26
 */
 
27
 
 
28
#include "talk/xmpp/mucroomhistorytask.h"
 
29
#include "talk/xmpp/constants.h"
 
30
 
 
31
namespace buzz {
 
32
 
 
33
// TODO: Move these to xmpp/constants.cc once it's publicly
 
34
// viewable.
 
35
const char NS_GOOGLE_SETTING[] = "google:setting";
 
36
const StaticQName QN_MEETING_HISTORY = { NS_GOOGLE_SETTING, "meetinghistory" };
 
37
const StaticQName QN_MEETING_ITEM = { NS_GOOGLE_SETTING, "item" };
 
38
 
 
39
MucRoomHistoryGetTask::MucRoomHistoryGetTask(XmppTaskParentInterface* parent,
 
40
                                             const buzz::Jid& user_jid)
 
41
    : IqTask(parent, STR_GET, user_jid, MakeRequest()) {
 
42
}
 
43
 
 
44
//    <iq type='get' id='user-setting-1'>
 
45
//      <meetinghistory xmlns='google:setting' />
 
46
//    </iq>
 
47
XmlElement* MucRoomHistoryGetTask::MakeRequest() {
 
48
  XmlElement* history = new XmlElement(QN_MEETING_HISTORY, true);
 
49
  return history;
 
50
}
 
51
 
 
52
//   <iq type='result'
 
53
//       to='romeo@gmail.com/orchard'
 
54
//       id='user-setting-1'>
 
55
//     <meetinghistory xmlns='google:setting'>
 
56
//       <item jid=’private-muc-abc-...@groupchat.google.com’ name=’Hangout'
 
57
//             time=’2011-01-31T13:20:00Z’ />
 
58
//       <item jid=’private-muc-abc-...@groupchat.google.com’ name=’Planning’
 
59
//             time=’2011-02-11T 14:20:00Z />
 
60
//       <item jid=’private-muc-abc-...@groupchat.google.com’ name=’TGIF’
 
61
//             time=’2011-03-21T15:20:00Z’ />
 
62
//     </meetinghistory>
 
63
//   </iq>
 
64
void MucRoomHistoryGetTask::HandleResult(const XmlElement* stanza) {
 
65
  std::vector<MucRoomHistoryInfo> meeting_rooms;
 
66
 
 
67
  const XmlElement* history = stanza->FirstNamed(QN_MEETING_HISTORY);
 
68
  if (history == NULL) {
 
69
    SignalResult(meeting_rooms);
 
70
    return;
 
71
  }
 
72
 
 
73
  const XmlElement* history_item = history->FirstNamed(QN_MEETING_ITEM);
 
74
  while (history_item != NULL) {
 
75
    MucRoomHistoryInfo room;
 
76
    room.room_name = history_item->Attr(QN_NAME);
 
77
    room.last_enter_time = history_item->Attr(QN_TIME);
 
78
    meeting_rooms.push_back(room);
 
79
 
 
80
    history_item = history_item->NextNamed(QN_MEETING_ITEM);
 
81
  }
 
82
 
 
83
  SignalResult(meeting_rooms);
 
84
}
 
85
 
 
86
MucRoomHistorySetTask::MucRoomHistorySetTask(XmppTaskParentInterface* parent,
 
87
                                             MucRoomHistoryTaskCommand command,
 
88
                                             const buzz::Jid& user_jid,
 
89
                                             const std::string& room_name)
 
90
    : IqTask(parent, STR_SET, user_jid, MakeRequest(command, room_name)) {
 
91
}
 
92
 
 
93
// ADD
 
94
//   <iq type='set'
 
95
//       to='romeo@gmail.com'
 
96
//       id='user-setting-3'>
 
97
//     <meetinghistory xmlns='google:setting'>
 
98
//       <item jid=’private-muc-abc@groupchat.google.com’
 
99
//             name=’Hangout' action=’add’ />
 
100
//     </meetinghistory>
 
101
//   </iq>
 
102
 
 
103
// DELETE
 
104
//   <iq type='set'
 
105
//       to='romeo@gmail.com'
 
106
//       id='user-setting-3'>
 
107
//     <meetinghistory xmlns='google:setting'>
 
108
//       <item jid=’private-muc-abc@groupchat.google.com’
 
109
//             name=’Hangout' action=’remove’ />
 
110
//     </meetinghistory>
 
111
//   </iq>
 
112
 
 
113
// CLEAR ALL
 
114
//   <iq type='set'
 
115
//       from='romeo@gmail.com/orchard'
 
116
//       to='romeo@gmail.com'
 
117
//       id='user-setting-3'>
 
118
//     <meetinghistory xmlns='google:setting' />
 
119
//   </iq>
 
120
XmlElement* MucRoomHistorySetTask::MakeRequest(
 
121
    MucRoomHistoryTaskCommand command, const std::string& room_name) {
 
122
  XmlElement* history = new XmlElement(QN_MEETING_HISTORY, true);
 
123
  if (command != HT_CLEAR_ALL) {
 
124
    XmlElement* item = new XmlElement(QN_MEETING_ITEM, false);
 
125
    // TODO - remove QN_JID attribute when 21446107 is submitted &
 
126
    // deployed.  no harm to leave in after the change is made.
 
127
    item->AddAttr(QN_JID, room_name);
 
128
    item->AddAttr(QN_NAME, room_name);
 
129
    item->AddAttr(QN_ACTION, command == HT_ADD ? "add" : "remove");
 
130
 
 
131
    history->AddElement(item);
 
132
  }
 
133
 
 
134
  return history;
 
135
}
 
136
 
 
137
// MODIFY & CLEAR
 
138
//   <iq type='result'
 
139
//       to='romeo@gmail.com/orchard'
 
140
//       from='romeo@gmail.com'
 
141
//       id='user-setting-3' />
 
142
void MucRoomHistorySetTask::HandleResult(const XmlElement* stanza) {
 
143
  SignalResult();
 
144
}
 
145
 
 
146
}  // namespace buzz