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.
30
#include "talk/base/stringencode.h"
31
#include "talk/examples/call/presenceouttask.h"
32
#include "talk/xmpp/constants.h"
33
#include "talk/xmpp/xmppclient.h"
38
PresenceOutTask::Send(const Status & s) {
39
if (GetState() != STATE_INIT && GetState() != STATE_START)
40
return XMPP_RETURN_BADSTATE;
42
XmlElement * presence = TranslateStatus(s);
43
QueueStanza(presence);
45
return XMPP_RETURN_OK;
49
PresenceOutTask::SendDirected(const Jid & j, const Status & s) {
50
if (GetState() != STATE_INIT && GetState() != STATE_START)
51
return XMPP_RETURN_BADSTATE;
53
XmlElement * presence = TranslateStatus(s);
54
presence->AddAttr(QN_TO, j.Str());
55
QueueStanza(presence);
57
return XMPP_RETURN_OK;
60
XmppReturnStatus PresenceOutTask::SendProbe(const Jid & jid) {
61
if (GetState() != STATE_INIT && GetState() != STATE_START)
62
return XMPP_RETURN_BADSTATE;
64
XmlElement * presence = new XmlElement(QN_PRESENCE);
65
presence->AddAttr(QN_TO, jid.Str());
66
presence->AddAttr(QN_TYPE, "probe");
68
QueueStanza(presence);
70
return XMPP_RETURN_OK;
74
PresenceOutTask::ProcessStart() {
75
const XmlElement * stanza = NextStanza();
79
if (SendStanza(stanza) != XMPP_RETURN_OK)
86
PresenceOutTask::TranslateStatus(const Status & s) {
87
XmlElement * result = new XmlElement(QN_PRESENCE);
89
result->AddAttr(QN_TYPE, STR_UNAVAILABLE);
92
if (s.show() != Status::SHOW_ONLINE && s.show() != Status::SHOW_OFFLINE) {
93
result->AddElement(new XmlElement(QN_SHOW));
96
result->AddText(STR_SHOW_AWAY, 1);
99
result->AddText(STR_SHOW_XA, 1);
101
case Status::SHOW_DND:
102
result->AddText(STR_SHOW_DND, 1);
104
case Status::SHOW_CHAT:
105
result->AddText(STR_SHOW_CHAT, 1);
110
result->AddElement(new XmlElement(QN_STATUS));
111
result->AddText(s.status(), 1);
113
if (!s.nick().empty()) {
114
result->AddElement(new XmlElement(QN_NICKNAME));
115
result->AddText(s.nick(), 1);
119
talk_base::ToString(s.priority(), &pri);
121
result->AddElement(new XmlElement(QN_PRIORITY));
122
result->AddText(pri, 1);
124
if (s.know_capabilities()) {
125
result->AddElement(new XmlElement(QN_CAPS_C, true));
126
result->AddAttr(QN_NODE, s.caps_node(), 1);
127
result->AddAttr(QN_VER, s.version(), 1);
130
caps.append(s.voice_capability() ? "voice-v1" : "");
131
caps.append(s.pmuc_capability() ? " pmuc-v1" : "");
132
caps.append(s.video_capability() ? " video-v1" : "");
133
caps.append(s.camera_capability() ? " camera-v1" : "");
135
result->AddAttr(QN_EXT, caps, 1);
138
// Put the delay mark on the presence according to JEP-0091
140
result->AddElement(new XmlElement(kQnDelayX, true));
142
// This here is why we *love* the C runtime
143
time_t current_time_seconds;
144
time(¤t_time_seconds);
145
struct tm* current_time = gmtime(¤t_time_seconds);
147
strftime(output, ARRAY_SIZE(output), "%Y%m%dT%H:%M:%S", current_time);
148
result->AddAttr(kQnStamp, output, 1);