[ekg2-commit] r3737 - trunk/plugins/ncurses: trunk/plugins/ncurses/contacts.c

SVN commit svn w toxygen.net
Pon, 4 Lut 2008, 22:52:54 CET


Author: darkjames
Date: 2008-02-04 22:52:54 +0100 (Mon, 04 Feb 2008)
New Revision: 3737

Modified:
   trunk/plugins/ncurses/contacts.c
Log:
- move userlist duplcation code to userlist_dup()
- info about bug.


Modified: trunk/plugins/ncurses/contacts.c
===================================================================
--- trunk/plugins/ncurses/contacts.c	2008-02-04 21:39:29 UTC (rev 3736)
+++ trunk/plugins/ncurses/contacts.c	2008-02-04 21:52:54 UTC (rev 3737)
@@ -320,7 +320,28 @@
 	return xstrcasecmp(a->nickname, b->nickname);
 }
 
+/*
+ * userlist_dup()
+ *
+ * Duplicate entry, with private set to priv.
+ *
+ * @note
+ * 	It just copy pointers, so if you delete entry which is shown in userlist, and don't call USERLIST_CHANGED. [We do it for instance in irc plugin]
+ * 	It'll be faulty :)
+ */
 
+static inline userlist_t *userlist_dup(userlist_t *up, void *priv) {
+	userlist_t *u = xmalloc(sizeof(userlist_t));
+
+	u->uid		= up->uid;
+	u->nickname	= up->nickname;
+	u->descr	= up->descr;
+	u->status	= up->status;
+	u->xstate	= up->xstate;
+	u->private	= priv;
+	return u;
+}
+
 /*
  * ncurses_contacts_update()
  *
@@ -422,45 +443,25 @@
 		list_t l;
 
 		for (l = sessions; l; l = l->next) {
+			session_t *s = l->data;
 			list_t lp;
-			session_t *s = l->data;
 
 			if (!s->userlist)
 				continue;
 
 			for (lp = s->userlist; lp; lp = lp->next) {
-				userlist_t *u;
-				userlist_t *up = lp->data;
+				userlist_t *u = lp->data;
 
-				if (!up)
-					continue;
-				u = xmalloc(sizeof(userlist_t));
-				u->uid = up->uid;
-				u->nickname = up->nickname;
-				u->descr = up->descr;
-				u->status = up->status;
-				u->private = (void *) s;
-				u->xstate = up->xstate;
-				list_add_sorted(&sorted_all, u, 0, comp);
+				list_add_sorted(&sorted_all, userlist_dup(u, s), 0, comp);
 			}
 
 			comp = contacts_compare;		/* turn on sorting */
 		}
 
 		for (l = c ? c->participants : window_current->userlist; l; l = l->next) {
-			userlist_t *up = l->data;
-			userlist_t *u;
+			userlist_t *u = l->data;
 
-			if (!up)
-				continue;
-			u = xmalloc(sizeof(userlist_t));
-			u->uid = up->uid;
-			u->nickname = up->nickname;
-			u->descr = up->descr;
-			u->status = up->status;
-			u->private = (void *) w->session;
-			u->xstate = up->xstate;
-			list_add_sorted(&sorted_all, u, 0, comp /* contacts_compare : NULL */);
+			list_add_sorted(&sorted_all, userlist_dup(u, w->session), 0, comp);
 		}
 
 		if (sorted_all) comp = contacts_compare;	/* like above */
@@ -477,6 +478,7 @@
 
 			if (!m || !i || !up)
 				continue;
+
 			u = xmalloc(sizeof(userlist_t));
 			u->status = up->status;
 			u->descr = up->descr;
@@ -484,7 +486,7 @@
 			u->private = (void *) 2;
 			u->xstate = up->xstate;
 
-			list_add_sorted(&sorted_all, u, 0, comp /* contacts_compare ; NULL */);
+			list_add_sorted(&sorted_all, u, 0, comp);
 
 			/* Remove contacts contained in this metacontact. */
 			if ( config_contacts_metacontacts_swallow )



Więcej informacji o liście dyskusyjnej ekg2-commit