source: buddylist.c @ ab31454

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