changeset 89:d39f15683c34

[/trunk] Changeset 103 by mikael * Can now use a TYPE mask combination. * Add roster_settype() and roster_gettype().
author mikael
date Mon, 18 Apr 2005 17:14:12 +0000
parents 3c51989b0982
children ac48ace7ee19
files mcabber/src/roster.c mcabber/src/roster.h
diffstat 2 files changed, 37 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/roster.c	Mon Apr 18 03:23:17 2005 +0000
+++ b/mcabber/src/roster.c	Mon Apr 18 17:14:12 2005 +0000
@@ -54,7 +54,7 @@
 
 // Comparison function used to search in the roster (compares jids and types)
 gint roster_compare_jid_type(roster *a, roster *b) {
-  if (a->type != b->type)
+  if (! (a->type & b->type))
     return -1; // arbitrary (but should be != , of course)
   return strcasecmp(a->jid, b->jid);
 }
@@ -65,6 +65,7 @@
 }
 
 // Finds a roster element (user, group, agent...), by jid or name
+// If roster_type is 0, returns match of any type.
 // Returns the roster GSList element, or NULL if jid/name not found
 GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type)
 {
@@ -76,6 +77,9 @@
   if (!jidname)
     return NULL;    // should not happen
 
+  if (!roster_type)
+    roster_type = ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_GROUP;
+
   sample.type = roster_type;
   if (type == jidsearch) {
     sample.jid = jidname;
@@ -168,7 +172,8 @@
   GSList **sl_group_listptr;
   roster *roster_usr;
 
-  if ((sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER)) == NULL)
+  sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
+  if (sl_user == NULL)
     return;
   // Let's free memory (jid, name)
   roster_usr = (roster*)sl_user->data;
@@ -195,7 +200,8 @@
   GSList *sl_user;
   roster *roster_usr;
 
-  if ((sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER)) == NULL)
+  sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
+  if (sl_user == NULL)
     return;
 
   roster_usr = (roster*)sl_user->data;
@@ -209,7 +215,8 @@
   GSList *sl_user;
   roster *roster_usr;
 
-  if ((sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER)) == NULL)
+  sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
+  if (sl_user == NULL)
     return;
 
   roster_usr = (roster*)sl_user->data;
@@ -219,9 +226,32 @@
     roster_usr->flags &= ~flags;
 }
     
+void roster_settype(const char *jid, guint type)
+{
+  GSList *sl_user;
+  roster *roster_usr;
+
+  if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
+    return;
+
+  roster_usr = (roster*)sl_user->data;
+  roster_usr->type = type;
+}
+
+guint roster_gettype(const char *jid)
+{
+  GSList *sl_user;
+  roster *roster_usr;
+
+  if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
+    return 0;
+
+  roster_usr = (roster*)sl_user->data;
+  return roster_usr->type;
+}
+
 // char *roster_getgroup(...)   / Or *GSList?  Which use??
 // ... setgroup(char*) ??
-// guint  roster_gettype(...)   / settype
 // guchar roster_getflags(...)
 // guchar roster_getname(...)   / setname ??
 // roster_del_group?
--- a/mcabber/src/roster.h	Mon Apr 18 03:23:17 2005 +0000
+++ b/mcabber/src/roster.h	Mon Apr 18 17:14:12 2005 +0000
@@ -40,6 +40,8 @@
 void    roster_del_user(const char *jid);
 void    roster_setstatus(const char *jid, enum imstatus bstat);
 void    roster_setflags(const char *jid, guint flags, guint value);
+void    roster_settype(const char *jid, guint type);
+guint   roster_gettype(const char *jid);
 
 void buddylist_hide_offline_buddies(int hide);
 void buddy_hide_group(gpointer rosterdata, int hide);