3
* Copyright 2004--2005, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
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.
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.
28
#include "talk/xmpp/constants.h"
29
#include "talk/examples/call/mucinviterecvtask.h"
33
const char* types[] = {
39
const char* statuses[] = {
48
AvailableMediaEntry::TypeAsString(type_t type) {
49
// The values of the constants have been chosen such that this is correct.
54
AvailableMediaEntry::StatusAsString(status_t status) {
55
// The values of the constants have been chosen such that this is correct.
56
return statuses[status];
59
int bodytext_to_array_pos(const XmlElement* elem, const char* array[],
60
int len, int defval = -1) {
62
const std::string& body(elem->BodyText());
63
for (int i = 0; i < len; ++i) {
64
if (body == array[i]) {
70
// If we get here, it's not any value in the array.
75
MucInviteRecvTask::HandleStanza(const XmlElement* stanza) {
76
// Figuring out that we want to handle this is a lot of the work of
77
// actually handling it, so we handle it right here instead of queueing it.
78
const XmlElement* xstanza;
79
const XmlElement* invite;
80
if (stanza->Name() != QN_MESSAGE) return false;
81
xstanza = stanza->FirstNamed(QN_MUC_USER_X);
82
if (!xstanza) return false;
83
invite = xstanza->FirstNamed(QN_MUC_USER_INVITE);
84
if (!invite) return false;
85
// Else it's an invite and we definitely want to handle it. Parse the
86
// available-media, if any.
87
std::vector<AvailableMediaEntry> v;
88
const XmlElement* avail =
89
invite->FirstNamed(QN_GOOGLE_MUC_USER_AVAILABLE_MEDIA);
91
for (const XmlElement* entry = avail->FirstNamed(QN_GOOGLE_MUC_USER_ENTRY);
93
entry = entry->NextNamed(QN_GOOGLE_MUC_USER_ENTRY)) {
94
AvailableMediaEntry tmp;
95
// In the interest of debugging, we accept as much valid-looking data
97
tmp.label = atoi(entry->Attr(QN_LABEL).c_str());
98
tmp.type = static_cast<AvailableMediaEntry::type_t>(
99
bodytext_to_array_pos(
100
entry->FirstNamed(QN_GOOGLE_MUC_USER_TYPE),
102
sizeof(types)/sizeof(const char*),
103
AvailableMediaEntry::TYPE_UNKNOWN));
104
tmp.status = static_cast<AvailableMediaEntry::status_t>(
105
bodytext_to_array_pos(
106
entry->FirstNamed(QN_GOOGLE_MUC_USER_STATUS),
108
sizeof(statuses)/sizeof(const char*),
109
AvailableMediaEntry::STATUS_UNKNOWN));
113
SignalInviteReceived(Jid(invite->Attr(QN_FROM)), Jid(stanza->Attr(QN_FROM)),
119
MucInviteRecvTask::ProcessStart() {
120
// We never queue anything so we are always blocked.
121
return STATE_BLOCKED;