1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 $Id: contacts.c,v 1.4 2000/06/17 16:38:45 denis Exp $
4 $Log: contacts.c,v $
5 Revision 1.4  2000/06/17 16:38:45  denis
6 New parameter was added in icq_ContactSetVis() for setting/resetting
7 'Visible to User' status.
8 Port's type was changed to unsigned short in icq_UserOnline callback.
9 
10 Revision 1.3  2000/01/16 03:59:10  bills
11 reworked list code so list_nodes don't need to be inside item structures,
12 removed strlist code and replaced with generic list calls
13 
14 Revision 1.2  1999/07/23 12:28:00  denis
15 Cleaned up.
16 
17 Revision 1.1  1999/07/18 20:11:48  bills
18 added
19 
20 */
21 
22 #include <stdlib.h>
23 #include <stdarg.h>
24 
25 #include "icqtypes.h"
26 #include "util.h"
27 #include "icq.h"
28 #include "list.h"
29 #include "contacts.h"
30 
icq_ContactNew(ICQLINK * link)31 icq_ContactItem *icq_ContactNew(ICQLINK *link)
32 {
33   icq_ContactItem *pcontact=
34     (icq_ContactItem *)malloc(sizeof(icq_ContactItem));
35 
36   if(pcontact)
37     pcontact->icqlink=link;
38 
39   return pcontact;
40 }
41 
icq_ContactDelete(void * p)42 void icq_ContactDelete(void *p)
43 {
44   free(p);
45 }
46 
icq_ContactAdd(ICQLINK * link,DWORD cuin)47 void icq_ContactAdd(ICQLINK *link, DWORD cuin)
48 {
49   icq_ContactItem *p = icq_ContactNew(link);
50   p->uin = cuin;
51   p->vis_list = FALSE;
52 
53   list_enqueue(link->icq_ContactList, p);
54 }
55 
icq_ContactRemove(ICQLINK * link,DWORD cuin)56 void icq_ContactRemove(ICQLINK *link, DWORD cuin)
57 {
58   icq_ContactItem *pcontact=icq_ContactFind(link, cuin);
59 
60   if (pcontact)
61   {
62     list_remove(link->icq_ContactList, pcontact);
63     icq_ContactDelete(pcontact);
64   }
65 }
66 
icq_ContactClear(ICQLINK * link)67 void icq_ContactClear(ICQLINK *link)
68 {
69   list_delete(link->icq_ContactList, icq_ContactDelete);
70   link->icq_ContactList=list_new();
71 }
72 
_icq_ContactFind(void * p,va_list data)73 int _icq_ContactFind(void *p, va_list data)
74 {
75   DWORD uin=va_arg(data, DWORD);
76 
77   return (((icq_ContactItem *)p)->uin == uin);
78 }
79 
icq_ContactFind(ICQLINK * link,DWORD cuin)80 icq_ContactItem *icq_ContactFind(ICQLINK *link, DWORD cuin)
81 {
82   return list_traverse(link->icq_ContactList, _icq_ContactFind, cuin);
83 }
84 
icq_ContactSetVis(ICQLINK * link,DWORD cuin,BYTE vu)85 void icq_ContactSetVis(ICQLINK *link, DWORD cuin, BYTE vu)
86 {
87   icq_ContactItem *p = icq_ContactFind(link, cuin);
88   if(p)
89     p->vis_list = vu;
90 }
91 
icq_ContactGetFirst(ICQLINK * link)92 icq_ContactItem *icq_ContactGetFirst(ICQLINK *link)
93 {
94   return list_first(link->icq_ContactList);
95 }
96 
icq_ContactGetNext(icq_ContactItem * pcontact)97 icq_ContactItem *icq_ContactGetNext(icq_ContactItem *pcontact)
98 {
99   list_node *p=list_find(pcontact->icqlink->icq_ContactList, pcontact);
100 
101   if (p && p->next)
102     return p->next->item;
103   else
104     return 0L;
105 
106 }
107