diff mcabber/src/roster.c @ 265:49e9e02dd6d0

Add "/roster search" command
author mikael@frmp8452
date Sat, 02 Jul 2005 19:23:45 +0100
parents 57f9005b8844
children efcbd3c1ad15
line wrap: on
line diff
--- a/mcabber/src/roster.c	Sat Jul 02 12:06:10 2005 +0100
+++ b/mcabber/src/roster.c	Sat Jul 02 19:23:45 2005 +0100
@@ -19,6 +19,7 @@
  * USA
  */
 
+#define _GNU_SOURCE     /* for strcasestr() */
 #include <string.h>
 
 #include "roster.h"
@@ -627,6 +628,31 @@
   return roster_usr->flags;
 }
 
+//  buddy_search(string)
+// Look for a buddy whose name or jid contains string.
+// Search begins at current_buddy; if no match is found in the the buddylist,
+// return NULL;
+GList *buddy_search(char *string)
+{
+  GList *buddy = current_buddy;
+  roster *roster_usr;
+  if (!buddylist || !current_buddy) return NULL;
+  for (;;) {
+    buddy = g_list_next(buddy);
+    if (!buddy)
+      buddy = buddylist;
+
+    roster_usr = (roster*)buddy->data;
+    if (roster_usr->jid && strcasestr(roster_usr->jid, string))
+      return buddy;
+    if (roster_usr->name && strcasestr(roster_usr->name, string))
+      return buddy;
+
+    if (buddy == current_buddy)
+      return NULL; // Back to the beginning, and no match found
+  }
+}
+
 //  compl_list(type)
 // Returns a list of jid's or groups.  (For commands completion)
 // type: ROSTER_TYPE_USER (jid's) or ROSTER_TYPE_GROUP (group names)