diff mcabber/libjabber/pproxy.c @ 417:c3ae9251c197

Sync libjabber with upstream Sync with jabberd-1.4.4.
author Mikael Berthe <mikael@lilotux.net>
date Thu, 01 Sep 2005 23:29:21 +0200
parents bf3d6e241714
children
line wrap: on
line diff
--- a/mcabber/libjabber/pproxy.c	Thu Sep 01 21:18:19 2005 +0200
+++ b/mcabber/libjabber/pproxy.c	Thu Sep 01 23:29:21 2005 +0200
@@ -13,8 +13,31 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- *  Jabber
- *  Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
+ * Copyrights
+ *
+ * Portions created by or assigned to Jabber.com, Inc. are
+ * Copyright (c) 1999-2002 Jabber.com, Inc.  All Rights Reserved.  Contact
+ * information for Jabber.com, Inc. is available at http://www.jabber.com/.
+ *
+ * Portions Copyright (c) 1998-1999 Jeremie Miller.
+ *
+ * Acknowledgements
+ *
+ * Special thanks to the Jabber Open Source Contributors for their
+ * suggestions and support of Jabber.
+ *
+ *
+ */
+
+/**
+ * @file pproxy.c
+ * @brief presence proxy database - DEPRECATED
+ *
+ * @deprecated these functions are not used by jabberd itself (but aim-t uses them), they will be removed from jabberd
+ *
+ * The presence proxy database is used to store presences for different resources of a JID.
+ *
+ * these aren't the most efficient things in the world, a hash optimized for tiny spaces would be far better
  */
 
 #include "jabber.h"
@@ -42,25 +65,24 @@
     if(db == NULL || id == NULL) return NULL;
 
     for(cur = db->next; cur != NULL; cur = cur->next)
-	if(jid_cmp(cur->id,id) == 0) return cur;
+        if(jid_cmp(cur->id,id) == 0) return cur;
 
     return NULL;
 }
 
 ppdb ppdb_insert(ppdb db, jid id, xmlnode x)
 {
-    char *res;
     ppdb cur, curu;
     pool p;
 
     if(id == NULL || id->server == NULL || x == NULL)
-	return db;
+        return db;
 
     /* new ppdb list dummy holder */
     if(db == NULL)
     {
-	p = pool_heap(1024);
-	db = _ppdb_new(p,id);
+        p = pool_heap(1024);
+        db = _ppdb_new(p,NULL);
     }
 
     cur = _ppdb_get(db,id);
@@ -68,10 +90,10 @@
     /* just update it */
     if(cur != NULL)
     {
-	xmlnode_free(cur->x);
-	cur->x = xmlnode_dup(x);
-	cur->pri = jutil_priority(x);
-	return db;
+        xmlnode_free(cur->x);
+        cur->x = xmlnode_dup(x);
+        cur->pri = jutil_priority(x);
+        return db;
     }
 
     /* make an entry for it */
@@ -81,28 +103,20 @@
     cur->next = db->next;
     db->next = cur;
 
-    /* this is a presence from a resource, make an entry for just the user */
-    if(id->user != NULL && id->resource != NULL)
+    /* if this is a user's resource presence, get the the user entry */
+    if(id->user != NULL && (curu = _ppdb_get(db,jid_user(id))) != cur)
     {
-	/* modify the id to just user@host */
-	res = id->resource;
-	jid_set(id,NULL,JID_RESOURCE);
-	curu = _ppdb_get(db,id);
+        /* no user entry, make one */
+        if(curu == NULL)
+        {
+            curu = _ppdb_new(db->p,jid_user(id));
+            curu->next = db->next;
+            db->next = curu;
+        }
 
-	/* no user entry, make one */
-	if(curu == NULL)
-	{
-	    curu = _ppdb_new(db->p,id);
-	    curu->next = db->next;
-	    db->next = curu;
-	}
-
-	/* restore the id */
-	jid_set(id,res,JID_RESOURCE);
-
-	/* insert this resource into the user list */
-	cur->user = curu->user;
-	curu->user = cur;
+        /* insert this resource into the user list */
+        cur->user = curu->user;
+        curu->user = cur;
     }
 
     return db;
@@ -123,7 +137,7 @@
 
     top = cur;
     for(cur = cur->user; cur != NULL; cur = cur->user)
-	if(cur->pri >= top->pri) top = cur;
+        if(cur->pri >= top->pri) top = cur;
 
     if(top != NULL && top->pri >= 0) return top->x;
 
@@ -141,18 +155,18 @@
     /* MODE: if this is NOT just user@host addy, return just the single entry */
     if(id->user == NULL || id->resource != NULL)
     {
-	/* we were just here, return now */
-	if(last != NULL)
-	{
-	    last = NULL;
-	    return NULL;
-	}
+        /* we were just here, return now */
+        if(last != NULL)
+        {
+            last = NULL;
+            return NULL;
+        }
 
-	last = _ppdb_get(db,id);
-	if(last != NULL)
-	    return last->x;
-	else
-	    return NULL;
+        last = _ppdb_get(db,id);
+        if(last != NULL)
+            return last->x;
+        else
+            return NULL;
     }
 
     /* handle looping for user@host */
@@ -160,15 +174,15 @@
     /* we're already in the loop */
     if(last != NULL)
     {
-	/* this is the last entry in the list */
-	if(last->user == NULL)
-	{
-	    last = NULL;
-	    return NULL;
-	}
+        /* this is the last entry in the list */
+        if(last->user == NULL)
+        {
+            last = NULL;
+            return NULL;
+        }
 
-	last = last->user;
-	return last->x;
+        last = last->user;
+        return last->x;
     }
 
     /* start a new loop */
@@ -178,9 +192,9 @@
 
     last = cur->user;
     if(last != NULL)
-	return last->x;
+        return last->x;
     else
-	return NULL;
+        return NULL;
 }
 
 
@@ -191,7 +205,7 @@
     if(db == NULL) return;
 
     for(cur = db; cur != NULL; cur = cur->next)
-	xmlnode_free(cur->x);
+        xmlnode_free(cur->x);
 
     pool_free(db->p);
 }