source: buddylist.c @ c23f678

release-1.10release-1.6release-1.7release-1.8release-1.9
Last change on this file since c23f678 was 1c4b4ca, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Rename owl_buddylist_free to owl_buddylist_cleanup. Signed-off-by: Anders Kaseorg <andersk@mit.edu> Reviewed-by: Nelson Elhage <nelhage@mit.edu>
  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[aa5f725]1#include "owl.h"
2
[f4d0975]3void owl_buddylist_init(owl_buddylist *bl)
[aa5f725]4{
[f4d0975]5  owl_list_create(&(bl->buddies));
6}
7
8/* add a (logged-in) AIM buddy to the buddy list
9 */
[e19eb97]10void owl_buddylist_add_aim_buddy(owl_buddylist *bl, const char *screenname)
[f4d0975]11{
12  owl_buddy *b;
13  b=owl_malloc(sizeof(owl_buddy));
14 
15  owl_buddy_create(b, OWL_PROTOCOL_AIM, screenname);
16  owl_list_append_element(&(bl->buddies), b);
17}
18
19/* remove an AIM buddy from the buddy list
20 */
[e19eb97]21int owl_buddylist_remove_aim_buddy(owl_buddylist *bl, const char *name)
[f4d0975]22{
23  int i, j;
24  owl_buddy *b;
25
26  j=owl_list_get_size(&(bl->buddies));
27  for (i=0; i<j; i++) {
28    b=owl_list_get_element(&(bl->buddies), i);
29    if (!strcasecmp(name, owl_buddy_get_name(b)) && owl_buddy_is_proto_aim(b)) {
30      owl_list_remove_element(&(bl->buddies), i);
[80b5c42]31      owl_buddy_delete(b);
[f4d0975]32      return(0);
33    }
34  }
35  return(1);
[aa5f725]36}
37
38/* Deal with an "oncoming" message.  This means recognizing the user
[a352335c]39 * has logged in, and displaying a message if they were not already
[aa5f725]40 * logged in.
41 */
[e19eb97]42void owl_buddylist_oncoming(owl_buddylist *bl, const char *screenname)
[aa5f725]43{
[a352335c]44  owl_message *m;
[aa5f725]45
[f4d0975]46  if (!owl_buddylist_is_aim_buddy_loggedin(bl, screenname)) {
[aa5f725]47
[f4d0975]48    owl_buddylist_add_aim_buddy(bl, screenname);
[aa5f725]49
[ceb8cfb]50    /* are we ingoring login messages for a while? */
[b7bb454]51    if (owl_global_is_ignore_aimlogin(&g)) return;
[ceb8cfb]52
[a352335c]53    /* if not, create the login message */
[aa5f725]54    m=owl_malloc(sizeof(owl_message));
[d559df9]55    owl_message_create_aim(m,
56                           screenname,
57                           owl_global_get_aim_screenname(&g),
58                           "",
59                           OWL_MESSAGE_DIRECTION_IN,
60                           1);
[aa5f725]61    owl_global_messagequeue_addmsg(&g, m);
62  }
63}
64
65/* Deal with an "offgoing" message.  This means recognizing the user
66 * has logged out, and sending a message if they were logged in.
67 */
[e19eb97]68void owl_buddylist_offgoing(owl_buddylist *bl, const char *screenname)
[aa5f725]69{
70  owl_message *m;
71
[fe6f1d3]72  if (owl_buddylist_is_aim_buddy_loggedin(bl, screenname)) {
73    m=owl_malloc(sizeof(owl_message));
74    owl_message_create_aim(m,
75                           screenname,
76                           owl_global_get_aim_screenname(&g),
77                           "",
78                           OWL_MESSAGE_DIRECTION_IN,
79                           -1);
80    owl_global_messagequeue_addmsg(&g, m);
81  }
[257a22f]82
83  owl_buddylist_remove_aim_buddy(bl, screenname);
[aa5f725]84}
85
[f4d0975]86/* return the number of logged in buddies */
[35b3518]87int owl_buddylist_get_size(const owl_buddylist *bl)
[de03334]88{
[f4d0975]89  return(owl_list_get_size(&(bl->buddies)));
[de03334]90}
91
[f4d0975]92/* return the buddy with index N.  If out of range, return NULL
[a352335c]93 */
[35b3518]94owl_buddy *owl_buddylist_get_buddy_n(const owl_buddylist *bl, int index)
[a352335c]95{
[f4d0975]96  if (index<0) return(NULL);
97  if (index>(owl_buddylist_get_size(bl)-1)) return(NULL);
[a352335c]98
[f4d0975]99  return(owl_list_get_element(&(bl->buddies), index));
[aa5f725]100}
101
[f4d0975]102/* return the AIM buddy with screenname 'name'.  If
103 * no such buddy is logged in, return NULL.
[a352335c]104 */
[35b3518]105owl_buddy *owl_buddylist_get_aim_buddy(const owl_buddylist *bl, const char *name)
[a352335c]106{
107  int i, j;
[f4d0975]108  owl_buddy *b;
109
110  j=owl_list_get_size(&(bl->buddies));
[a352335c]111  for (i=0; i<j; i++) {
[f4d0975]112    b=owl_list_get_element(&(bl->buddies), i);
113    if (!strcasecmp(name, owl_buddy_get_name(b))) return(b);
[a352335c]114  }
[f4d0975]115  return(NULL);
[a352335c]116}
117
118/* return 1 if the buddy 'screenname' is logged in,
119 * otherwise return 0
120 */
[35b3518]121int owl_buddylist_is_aim_buddy_loggedin(const owl_buddylist *bl, const char *screenname)
[a352335c]122{
[476faed]123  const owl_buddy *b;
[a352335c]124
[f4d0975]125  b=owl_buddylist_get_aim_buddy(bl, screenname);
126  if (b==NULL) return(0);
127  return(1);
[de03334]128}
129
[f4d0975]130/* remove all buddies from the list */
131void owl_buddylist_clear(owl_buddylist *bl)
[de03334]132{
[8c59178]133  owl_list_cleanup(&(bl->buddies), (void (*)(void *))owl_buddy_delete);
[f4d0975]134  owl_list_create(&(bl->buddies));
[de03334]135}
136
[1c4b4ca]137void owl_buddylist_cleanup(owl_buddylist *bl)
[f4d0975]138{
[8c59178]139  owl_list_cleanup(&(bl->buddies), (void (*)(void *))owl_buddy_delete);
[aa5f725]140}
Note: See TracBrowser for help on using the repository browser.