Changeset f4d0975 for buddylist.c
- Timestamp:
- Oct 10, 2003, 5:12:19 PM (21 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- e374dee
- Parents:
- 12582d3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
buddylist.c
r2404c3a rf4d0975 3 3 static const char fileIdent[] = "$Id$"; 4 4 5 void owl_buddylist_init(owl_buddylist *b )5 void owl_buddylist_init(owl_buddylist *bl) 6 6 { 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 */ 12 void 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 */ 23 int 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); 10 38 } 11 39 … … 14 42 * logged in. 15 43 */ 16 void owl_buddylist_oncoming(owl_buddylist *b , char *screenname)44 void owl_buddylist_oncoming(owl_buddylist *bl, char *screenname) 17 45 { 18 int *zero;19 46 owl_message *m; 20 47 21 if (!owl_buddylist_is_ buddy_loggedin(b, screenname)) {48 if (!owl_buddylist_is_aim_buddy_loggedin(bl, screenname)) { 22 49 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); 28 51 29 /* do a request for idle time */30 owl_buddylist_request_idletime(b, screenname);31 32 52 /* are we ingoring login messages for a while? */ 33 53 if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return; … … 48 68 * has logged out, and sending a message if they were logged in. 49 69 */ 50 void owl_buddylist_offgoing(owl_buddylist *b , char *screenname)70 void owl_buddylist_offgoing(owl_buddylist *bl, char *screenname) 51 71 { 52 int index;53 72 owl_message *m; 54 73 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 63 76 m=owl_malloc(sizeof(owl_message)); 64 77 owl_message_create_aim(m, … … 71 84 } 72 85 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 */ 87 int 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 76 93 */ 77 void owl_buddylist_request_idletimes(owl_buddylist *b) 94 owl_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 */ 105 owl_buddy *owl_buddylist_get_aim_buddy(owl_buddylist *bl, char *name) 78 106 { 79 107 int i, j; 108 owl_buddy *b; 80 109 81 j=owl_ buddylist_get_size(b);110 j=owl_list_get_size(&(bl->buddies)); 82 111 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); 84 114 } 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); 126 116 } 127 117 … … 129 119 * otherwise return 0 130 120 */ 131 int owl_buddylist_is_ buddy_loggedin(owl_buddylist *b, char *screenname)121 int owl_buddylist_is_aim_buddy_loggedin(owl_buddylist *bl, char *screenname) 132 122 { 133 if (owl_buddylist_get_buddy_index(b, screenname)!=-1) return(1); 134 return(0); 135 } 123 owl_buddy *b; 136 124 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); 161 128 } 162 129 163 130 /* 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)); 131 void 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)); 169 135 } 136 137 void 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.