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.
31
#include "talk/xmpp/jid.h"
32
#include "talk/xmpp/constants.h"
43
feedback_probation_(false),
44
know_capabilities_(false),
45
voice_capability_(false),
46
pmuc_capability_(false),
47
video_capability_(false),
48
camera_capability_(false) {
53
// These are arranged in "priority order", i.e., if we see
54
// two statuses at the same priority but with different Shows,
55
// we will show the one with the highest show in the following
67
const Jid& jid() const { return jid_; }
68
int priority() const { return pri_; }
69
Show show() const { return show_; }
70
const std::string& status() const { return status_; }
71
const std::string& nick() const { return nick_; }
72
bool available() const { return available_ ; }
73
int error_code() const { return e_code_; }
74
const std::string& error_string() const { return e_str_; }
75
bool know_capabilities() const { return know_capabilities_; }
76
bool voice_capability() const { return voice_capability_; }
77
bool pmuc_capability() const { return pmuc_capability_; }
78
bool video_capability() const { return video_capability_; }
79
bool camera_capability() const { return camera_capability_; }
80
const std::string& caps_node() const { return caps_node_; }
81
const std::string& version() const { return version_; }
82
bool feedback_probation() const { return feedback_probation_; }
83
const std::string& sent_time() const { return sent_time_; }
85
void set_jid(const Jid& jid) { jid_ = jid; }
86
void set_priority(int pri) { pri_ = pri; }
87
void set_show(Show show) { show_ = show; }
88
void set_status(const std::string& status) { status_ = status; }
89
void set_nick(const std::string& nick) { nick_ = nick; }
90
void set_available(bool a) { available_ = a; }
91
void set_error(int e_code, const std::string e_str)
92
{ e_code_ = e_code; e_str_ = e_str; }
93
void set_know_capabilities(bool f) { know_capabilities_ = f; }
94
void set_voice_capability(bool f) { voice_capability_ = f; }
95
void set_pmuc_capability(bool f) { pmuc_capability_ = f; }
96
void set_video_capability(bool f) { video_capability_ = f; }
97
void set_camera_capability(bool f) { camera_capability_ = f; }
98
void set_caps_node(const std::string& f) { caps_node_ = f; }
99
void set_version(const std::string& v) { version_ = v; }
100
void set_feedback_probation(bool f) { feedback_probation_ = f; }
101
void set_sent_time(const std::string& time) { sent_time_ = time; }
103
void UpdateWith(const Status& new_value) {
104
if (!new_value.know_capabilities()) {
105
bool k = know_capabilities();
106
bool p = voice_capability();
107
std::string node = caps_node();
108
std::string v = version();
112
set_know_capabilities(k);
114
set_voice_capability(p);
122
bool HasQuietStatus() const {
125
return !(QuietStatus().empty());
128
// Knowledge of other clients' silly automatic status strings -
130
std::string QuietStatus() const {
131
if (jid_.resource().find("Psi") != std::string::npos) {
132
if (status_ == "Online" ||
133
status_.find("Auto Status") != std::string::npos)
136
if (jid_.resource().find("Gaim") != std::string::npos) {
137
if (status_ == "Sorry, I ran out for a bit!")
140
return TrimStatus(status_);
143
std::string ExplicitStatus() const {
144
std::string result = QuietStatus();
145
if (result.empty()) {
146
result = ShowStatus();
151
std::string ShowStatus() const {
169
result = "Available";
176
static std::string TrimStatus(const std::string& st) {
179
bool collapsing = true;
180
for (unsigned int i = 0; i < s.length(); i+= 1) {
181
if (s[i] <= ' ' && s[i] >= 0) {
197
if (collapsing && j > 0) {
200
s.erase(j, s.length());
213
bool feedback_probation_;
215
// capabilities (valid only if know_capabilities_
216
bool know_capabilities_;
217
bool voice_capability_;
218
bool pmuc_capability_;
219
bool video_capability_;
220
bool camera_capability_;
221
std::string caps_node_;
222
std::string version_;
224
std::string sent_time_; // from the jabber:x:delay element
227
class MucStatus : public Status {