source: buddylist.c @ f4d0975

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