Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
Better jabber presence handling
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerD committed Dec 9, 2010
1 parent 36b3836 commit 9e4e847
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/hooks/jabberhook.cc
Expand Up @@ -193,13 +193,13 @@ static string jidtodisp(const string &jid) {
return user;
}

static imstatus get_presence(std::map<string, pair<char, imstatus> > res) // <resource, <prio, status> >
static imstatus get_presence(std::map<string, pair<int, imstatus> > res) // <resource, <prio, status> >
{
if (res.empty())
return offline;
imstatus result = offline;
char prio = -127;
for (map<string, pair<char, imstatus> >::iterator it = res.begin(); it!= res.end(); it++)
int prio = -127;
for (map<string, pair<int, imstatus> >::iterator it = res.begin(); it!= res.end(); it++)
{
if (it->second.first>prio)
{
Expand Down Expand Up @@ -286,7 +286,9 @@ void jabberhook::connect() {
if(jc){
jab_delete(jc);
}


statuses.clear();

jc = jab_new(cjid, cpass, cserver, acc.port,
acc.additional["ssl"] == "1" ? 1 : 0);

Expand Down Expand Up @@ -319,6 +321,7 @@ void jabberhook::disconnect() {
jab_stop(jc);
jab_delete(jc);
jc = 0;
statuses.clear();
}

void jabberhook::exectimers() {
Expand Down Expand Up @@ -1856,20 +1859,20 @@ string jabberhook::getourjid() {
return jid;
}

imstatus jabberhook::process_presence(string id, string s, char prio, imstatus ust)
imstatus jabberhook::process_presence(string id, string s, int prio, imstatus ust)
{
if (statuses.find(id) == statuses.end()) { // new and only presence
if (ust != offline)
(statuses[id])[s] = pair<char, imstatus>(prio, ust);
(statuses[id])[s] = pair<int, imstatus>(prio, ust);
} else {
if (statuses[id].find(s) == statuses[id].end()) { // unknown resource
if (ust != offline)
(statuses[id])[s] = pair<char, imstatus>(prio, ust);
(statuses[id])[s] = pair<int, imstatus>(prio, ust);
} else {
if (ust == offline) // remove resource
(statuses[id]).erase(s);
else { // known contact
(statuses[id])[s] = pair<char, imstatus>(prio, ust);
(statuses[id])[s] = pair<int, imstatus>(prio, ust);
}
}
ust = get_presence(statuses[id]);
Expand Down Expand Up @@ -2310,7 +2313,7 @@ void jabberhook::packethandler(jconn conn, jpacket packet) {
icqcontact *c = clist.get(ic);

if(c) {
char prio = (char) jutil_priority(packet->x); // priority
int prio = jutil_priority(packet->x); // priority
ust = jhook.process_presence(id, s, prio, ust);
if(c->getstatus() != ust) {
jhook.awaymsgs[ic.nickname] = "";
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/jabberhook.h
Expand Up @@ -27,7 +27,7 @@ class jabberhook: public abstracthook {
map<string, string> full_jids; //little trick to store users full JID's, it required in some xmpp packets
map<imfile, pair<struct send_file *, string> > transferinfo;
map<string, vector<string> > chatmembers;
map<string, map<string, pair<char, imstatus> > > statuses; // <JID, <resource, <prio, status> > >
map<string, map<string, pair<int, imstatus> > > statuses; // <JID, <resource, <prio, status> > >
set<string> ignore_ids; // set of packet IDs to ignore errors from

struct agent {
Expand Down Expand Up @@ -61,7 +61,7 @@ class jabberhook: public abstracthook {

vector<agent> agents;

imstatus process_presence(string id, string s, char prio, imstatus ust);
imstatus process_presence(string id, string s, int prio, imstatus ust);

static void statehandler(jconn conn, int state);
static void packethandler(jconn conn, jpacket packet);
Expand Down

0 comments on commit 9e4e847

Please sign in to comment.