source: buddylist.c @ 6e05655

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 6e05655 was b2b0773, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Changes to help build on OSX
  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "owl.h"
2
3void owl_buddylist_init(owl_buddylist *b)
4{
5  owl_list_create(&(b->buddies));
6}
7
8/* Deal with an "oncoming" message.  This means recognizing the user
9 * has logged in, and sending a message if they were not already
10 * logged in.
11 */
12void owl_buddylist_oncoming(owl_buddylist *b, char *screenname)
13{
14  int i, j, found;
15  owl_message *m;
16
17  found=0;
18  j=owl_list_get_size(&(b->buddies));
19  for (i=0; i<j; i++) {
20    if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
21      found=1;
22      break;
23    }
24  }
25
26  if (!found) {
27    owl_list_append_element(&(b->buddies), owl_strdup(screenname));
28
29    m=owl_malloc(sizeof(owl_message));
30    owl_message_create_aim(m,
31                           screenname,
32                           owl_global_get_aim_screenname(&g),
33                           "",
34                           OWL_MESSAGE_DIRECTION_IN,
35                           1);
36    owl_global_messagequeue_addmsg(&g, m);
37  }
38}
39
40/* Deal with an "offgoing" message.  This means recognizing the user
41 * has logged out, and sending a message if they were logged in.
42 */
43void owl_buddylist_offgoing(owl_buddylist *b, char *screenname)
44{
45  int i, j, found;
46  owl_message *m;
47
48  found=0;
49  j=owl_list_get_size(&(b->buddies));
50  for (i=0; i<j; i++) {
51    if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
52      found=1;
53      owl_free(owl_list_get_element(&(b->buddies), i));
54      owl_list_remove_element(&(b->buddies), i);
55      break;
56    }
57  }
58
59  if (found) {
60    m=owl_malloc(sizeof(owl_message));
61    owl_message_create_aim(m,
62                           screenname,
63                           owl_global_get_aim_screenname(&g),
64                           "",
65                           OWL_MESSAGE_DIRECTION_IN,
66                           -1);
67
68    owl_global_messagequeue_addmsg(&g, m);
69  }
70}
71
72/* return the number of logged in buddies */
73int owl_buddylist_get_size(owl_buddylist *b)
74{
75  return(owl_list_get_size(&(b->buddies)));
76}
77
78/* get buddy number 'n' */
79char *owl_buddylist_get_buddy(owl_buddylist *b, int n)
80{
81  return(owl_list_get_element(&(b->buddies), n));
82}
83
84/* remove all buddies from the list */
85void owl_buddylist_clear(owl_buddylist *b) {
86  owl_list_free_all(&(b->buddies), owl_free);
87  owl_list_create(&(b->buddies));
88}
Note: See TracBrowser for help on using the repository browser.