Changeset f4d0975 for buddylist.c


Ignore:
Timestamp:
Oct 10, 2003, 5:12:19 PM (17 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
e374dee
Parents:
12582d3
Message:
Fixed bug with idle times causing broken pipes.
New libfaim
File:
1 edited

Legend:

Unmodified
Added
Removed
  • buddylist.c

    r2404c3a rf4d0975  
    33static const char fileIdent[] = "$Id$";
    44
    5 void owl_buddylist_init(owl_buddylist *b)
     5void owl_buddylist_init(owl_buddylist *bl)
    66{
    7   owl_list_create(&(b->buddies));
    8   owl_list_create(&(b->idletimes));
    9   /* owl_list_create(&(g->buddymsg_queue)); */
     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);
    1038}
    1139
     
    1442 * logged in.
    1543 */
    16 void owl_buddylist_oncoming(owl_buddylist *b, char *screenname)
     44void owl_buddylist_oncoming(owl_buddylist *bl, char *screenname)
    1745{
    18   int *zero;
    1946  owl_message *m;
    2047
    21   if (!owl_buddylist_is_buddy_loggedin(b, screenname)) {
     48  if (!owl_buddylist_is_aim_buddy_loggedin(bl, screenname)) {
    2249
    23     /* add the buddy */
    24     owl_list_append_element(&(b->buddies), owl_strdup(screenname));
    25     zero=owl_malloc(sizeof(int));
    26     *zero=0;
    27     owl_list_append_element(&(b->idletimes), zero);
     50    owl_buddylist_add_aim_buddy(bl, screenname);
    2851
    29     /* do a request for idle time */
    30     owl_buddylist_request_idletime(b, screenname);
    31        
    3252    /* are we ingoring login messages for a while? */
    3353    if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;
     
    4868 * has logged out, and sending a message if they were logged in.
    4969 */
    50 void owl_buddylist_offgoing(owl_buddylist *b, char *screenname)
     70void owl_buddylist_offgoing(owl_buddylist *bl, char *screenname)
    5171{
    52   int index;
    5372  owl_message *m;
    5473
    55   index=owl_buddylist_get_buddy_index(b, screenname);
    56   if (index==-1) return;
    57 
    58   owl_free(owl_list_get_element(&(b->buddies), index));
    59   owl_free(owl_list_get_element(&(b->idletimes), index));
    60   owl_list_remove_element(&(b->buddies), index);
    61   owl_list_remove_element(&(b->idletimes), index);
    62 
     74  owl_buddylist_remove_aim_buddy(bl, screenname);
     75 
    6376  m=owl_malloc(sizeof(owl_message));
    6477  owl_message_create_aim(m,
     
    7184}
    7285
    73 /* send requests to the AIM server to retrieve info
    74  * on all buddies.  The AIM callback then fills in the
    75  * values when the responses are received
     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
    7693 */
    77 void owl_buddylist_request_idletimes(owl_buddylist *b)
     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)
    78106{
    79107  int i, j;
     108  owl_buddy *b;
    80109
    81   j=owl_buddylist_get_size(b);
     110  j=owl_list_get_size(&(bl->buddies));
    82111  for (i=0; i<j; i++) {
    83     owl_aim_get_idle(owl_buddylist_get_buddy(b, i));
     112    b=owl_list_get_element(&(bl->buddies), i);
     113    if (!strcasecmp(name, owl_buddy_get_name(b))) return(b);
    84114  }
    85 }
    86 
    87 /* send request to the AIM server to retrieve info on one buddy.  The
    88  * AIM callback then fills in the values when the responses are
    89  * received.  The buddy must be logged in or no request will be
    90  * performed.
    91  */
    92 void owl_buddylist_request_idletime(owl_buddylist *b, char *screenname)
    93 {
    94   if (!owl_buddylist_is_buddy_loggedin(b, screenname)) return;
    95  
    96   owl_aim_get_idle(screenname);
    97 }
    98 
    99 /* return the number of logged in buddies */
    100 int owl_buddylist_get_size(owl_buddylist *b)
    101 {
    102   return(owl_list_get_size(&(b->buddies)));
    103 }
    104 
    105 /* get buddy number 'n' */
    106 char *owl_buddylist_get_buddy(owl_buddylist *b, int n)
    107 {
    108   if (n > owl_buddylist_get_size(b)-1) return("");
    109   return(owl_list_get_element(&(b->buddies), n));
    110 }
    111 
    112 /* Return the index of the buddy 'screename' or -1
    113  * if the buddy is not logged in.
    114  */
    115 int owl_buddylist_get_buddy_index(owl_buddylist *b, char *screenname)
    116 {
    117   int i, j;
    118  
    119   j=owl_list_get_size(&(b->buddies));
    120   for (i=0; i<j; i++) {
    121     if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
    122       return(i);
    123     }
    124   }
    125   return(-1);
     115  return(NULL);
    126116}
    127117
     
    129119 * otherwise return 0
    130120 */
    131 int owl_buddylist_is_buddy_loggedin(owl_buddylist *b, char *screenname)
     121int owl_buddylist_is_aim_buddy_loggedin(owl_buddylist *bl, char *screenname)
    132122{
    133   if (owl_buddylist_get_buddy_index(b, screenname)!=-1) return(1);
    134   return(0);
    135 }
     123  owl_buddy *b;
    136124
    137 /* get the idle time for buddy number 'n' */
    138 int owl_buddylist_get_idletime(owl_buddylist *b, int n)
    139 {
    140   int *foo;
    141 
    142   foo=owl_list_get_element(&(b->idletimes), n);
    143   return(*foo);
    144 }
    145 
    146 /* Set the idle time for user 'screenname'.  If the given screenname
    147  * is not on the buddy list do nothing.  If there is a queued request
    148  * for this screename, remove it from the queue.
    149  */
    150 void owl_buddylist_set_idletime(owl_buddylist *b, char *screenname, int minutes)
    151 {
    152   int index, *idle;
    153 
    154   index=owl_buddylist_get_buddy_index(b, screenname);
    155   if (index==-1) return;
    156 
    157   owl_free(owl_list_get_element(&(b->idletimes), index));
    158   idle=owl_malloc(sizeof(int));
    159   *idle=minutes;
    160   owl_list_replace_element(&(b->idletimes), index, idle);
     125  b=owl_buddylist_get_aim_buddy(bl, screenname);
     126  if (b==NULL) return(0);
     127  return(1);
    161128}
    162129
    163130/* remove all buddies from the list */
    164 void owl_buddylist_clear(owl_buddylist *b) {
    165   owl_list_free_all(&(b->buddies), owl_free);
    166   owl_list_free_all(&(b->idletimes), owl_free);
    167   owl_list_create(&(b->buddies));
    168   owl_list_create(&(b->idletimes));
     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));
    169135}
     136
     137void owl_buddylist_free(owl_buddylist *bl)
     138{
     139  owl_list_free_all(&(bl->buddies), (void(*)(void*))owl_buddy_free);
     140}
Note: See TracChangeset for help on using the changeset viewer.