Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Better jabber presence handling

  • Loading branch information...
commit 9e4e847fb0942fc2e9ea82fef0fffd33063eb1ce 1 parent 36b3836
RogerD authored December 09, 2010
21  src/hooks/jabberhook.cc
@@ -193,13 +193,13 @@ static string jidtodisp(const string &jid) {
193 193
     return user;
194 194
 }
195 195
 
196  
-static imstatus get_presence(std::map<string, pair<char, imstatus> > res) // <resource, <prio, status> >
  196
+static imstatus get_presence(std::map<string, pair<int, imstatus> > res) // <resource, <prio, status> >
197 197
 {
198 198
 	if (res.empty())
199 199
 		return offline;
200 200
 	imstatus result = offline;
201  
-	char prio = -127;
202  
-	for (map<string, pair<char, imstatus> >::iterator it = res.begin(); it!= res.end(); it++)
  201
+	int prio = -127;
  202
+	for (map<string, pair<int, imstatus> >::iterator it = res.begin(); it!= res.end(); it++)
203 203
 	{
204 204
 		if (it->second.first>prio)
205 205
 		{
@@ -286,7 +286,9 @@ void jabberhook::connect() {
286 286
     if(jc){
287 287
       jab_delete(jc);
288 288
     }
289  
-
  289
+    
  290
+    statuses.clear();
  291
+    
290 292
     jc = jab_new(cjid, cpass, cserver, acc.port,
291 293
 	acc.additional["ssl"] == "1" ? 1 : 0);
292 294
 
@@ -319,6 +321,7 @@ void jabberhook::disconnect() {
319 321
     jab_stop(jc);
320 322
     jab_delete(jc);
321 323
     jc = 0;
  324
+    statuses.clear();
322 325
 }
323 326
 
324 327
 void jabberhook::exectimers() {
@@ -1856,20 +1859,20 @@ string jabberhook::getourjid() {
1856 1859
     return jid;
1857 1860
 }
1858 1861
 
1859  
-imstatus jabberhook::process_presence(string id, string s, char prio, imstatus ust)
  1862
+imstatus jabberhook::process_presence(string id, string s, int prio, imstatus ust)
1860 1863
 {
1861 1864
 	if (statuses.find(id) == statuses.end()) { // new and only presence
1862 1865
 		if (ust != offline)
1863  
-			(statuses[id])[s] = pair<char, imstatus>(prio, ust);
  1866
+			(statuses[id])[s] = pair<int, imstatus>(prio, ust);
1864 1867
 	} else {
1865 1868
 		if (statuses[id].find(s) == statuses[id].end()) { // unknown resource
1866 1869
 			if (ust != offline)
1867  
-				(statuses[id])[s] = pair<char, imstatus>(prio, ust);
  1870
+				(statuses[id])[s] = pair<int, imstatus>(prio, ust);
1868 1871
 		} else {
1869 1872
 			if (ust == offline) // remove resource
1870 1873
 				(statuses[id]).erase(s);
1871 1874
 			else { // known contact
1872  
-				(statuses[id])[s] = pair<char, imstatus>(prio, ust);
  1875
+				(statuses[id])[s] = pair<int, imstatus>(prio, ust);
1873 1876
 			}
1874 1877
 		}
1875 1878
 		ust = get_presence(statuses[id]);
@@ -2310,7 +2313,7 @@ void jabberhook::packethandler(jconn conn, jpacket packet) {
2310 2313
 		icqcontact *c = clist.get(ic);
2311 2314
 		
2312 2315
 		if(c) {
2313  
-			char prio = (char) jutil_priority(packet->x); // priority
  2316
+			int prio = jutil_priority(packet->x); // priority
2314 2317
 			ust = jhook.process_presence(id, s, prio, ust);
2315 2318
 		    if(c->getstatus() != ust) {
2316 2319
 			jhook.awaymsgs[ic.nickname] = "";
4  src/hooks/jabberhook.h
@@ -27,7 +27,7 @@ class jabberhook: public abstracthook {
27 27
 	map<string, string> full_jids; //little trick to store users full JID's, it required in some xmpp packets
28 28
 	map<imfile, pair<struct send_file *, string> > transferinfo;
29 29
 	map<string, vector<string> > chatmembers;
30  
-	map<string, map<string, pair<char, imstatus> > > statuses;  // <JID, <resource, <prio, status> > >
  30
+	map<string, map<string, pair<int, imstatus> > > statuses;  // <JID, <resource, <prio, status> > >
31 31
 	set<string> ignore_ids; // set of packet IDs to ignore errors from
32 32
 
33 33
 	struct agent {
@@ -61,7 +61,7 @@ class jabberhook: public abstracthook {
61 61
 
62 62
 	vector<agent> agents;
63 63
 
64  
-	imstatus process_presence(string id, string s, char prio, imstatus ust);
  64
+	imstatus process_presence(string id, string s, int prio, imstatus ust);
65 65
 
66 66
 	static void statehandler(jconn conn, int state);
67 67
 	static void packethandler(jconn conn, jpacket packet);

0 notes on commit 9e4e847

Please sign in to comment.
Something went wrong with that request. Please try again.