1 /* $Id: contact.h 2831 2009-08-20 21:48:15Z kuhlmann $ */
2 
3 #ifndef CLIMM_CONTACT_H
4 #define CLIMM_CONTACT_H
5 
6 #include "util_opts.h"
7 
8 typedef struct ContactMetaGeneral_s  MetaGeneral;
9 typedef struct ContactMetaWork_s     MetaWork;
10 typedef struct ContactMetaMore_s     MetaMore;
11 typedef struct ContactMetaObsolete_s MetaObsolete;
12 typedef struct ContactDC_s           ContactDC;
13 typedef struct ContactMeta_s         ContactMeta;
14 typedef struct ContactIDs_s          ContactIDs;
15 
16 struct ContactMetaGeneral_s
17 {
18     char  *nick,   *first,  *last,
19           *email,  *city,   *state,
20           *phone,  *fax,    *zip,
21           *street, *cellular;
22     UWORD  country;
23     SBYTE  tz;
24     BOOL   auth, webaware, hideip;
25 };
26 
27 struct ContactMetaWork_s
28 {
29     char  *wcity,    *wstate,   *wphone,
30           *wfax,     *waddress, *wzip,
31           *wcompany, *wdepart,  *wposition,
32           *whomepage;
33     UWORD  wcountry, woccupation;
34 };
35 
36 struct ContactMetaMore_s
37 {
38     char  *homepage;
39     UWORD  age, year, unknown;
40     UBYTE  sex, month, day, lang1, lang2, lang3;
41 };
42 
43 struct ContactMetaObsolete_s
44 {
45     char  *description;
46     UWORD  unknown;
47     UBYTE  given, empty;
48 };
49 
50 struct ContactDC_s
51 {
52     time_t id1, id2, id3;
53     UDWORD ip_loc, ip_rem, port, cookie;
54     UWORD  version;
55     UBYTE  type;
56 };
57 
58 struct ContactGroup_s
59 {
60     ContactGroup  *more;
61     Contact       *contacts[32];
62     Server        *serv;
63     char          *name;
64     Opt            copts;
65     UWORD          id;
66     UBYTE          used;
67     UBYTE          temp;
68 };
69 
70 struct ContactAlias_s
71 {
72     ContactAlias *more;
73     char         *alias;
74 };
75 
76 struct ContactMeta_s
77 {
78     ContactMeta *next;
79     UWORD data;
80     char *text;
81 };
82 
83 struct ContactIDs_s
84 {
85     ContactIDs *next;
86     UWORD type;
87     UWORD id;
88     UWORD tag;
89     UWORD issbl;
90 };
91 
92 struct Contact_s
93 {
94     Server *serv;
95     ContactGroup *group;
96     char  *nick;
97     char  *screen;
98     UDWORD uin;
99     status_t status;
100     statusflag_t flags;
101     UDWORD nativestatus;
102     UDWORD oldflags;
103     Opt copts;
104     UDWORD caps[2];
105     UBYTE  v1, v2, v3, v4;
106 #if ENABLE_CONT_HIER
107     Contact *parent;
108     Contact *firstchild;
109     Contact *next;
110 #endif
111     ContactIDs *ids;
112 
113     char  *version;
114     char  *last_message;
115     time_t last_time;
116     char  *status_message;
117     char  *cap_string;
118 
119     ContactAlias *alias; /* alias of this entry */
120 
121     UWORD  updated; /* which meta_* has been updated */
122 
123     ContactDC       *dc;
124     MetaGeneral     *meta_general;
125     MetaWork        *meta_work;
126     MetaMore        *meta_more;
127     char            *meta_about;
128     MetaObsolete    *meta_obsolete;
129     ContactMeta     *meta_email, *meta_interest, *meta_background, *meta_affiliation;
130 };
131 
132 
133 ContactGroup *ContactGroupC       (Server *serv, UWORD id, const char *name DEBUGPARAM);
134 ContactGroup *ContactGroupFind    (Server *serv, UWORD id, const char *name);
135 ContactGroup *ContactGroupIndex   (int i);
136 UWORD         ContactGroupID      (ContactGroup *group);
137 UDWORD        ContactGroupCount   (ContactGroup *group);
138 void          ContactGroupD       (ContactGroup *group DEBUGPARAM);
139 typedef int (*contact_sort_func_t)(Contact *a, Contact *b, int mode);
140 void          ContactGroupSort    (ContactGroup *group, contact_sort_func_t sort, int mode);
141 void          ContactGroupAdd     (ContactGroup *group, ContactGroup *add);
142 void          ContactGroupSub     (ContactGroup *group, ContactGroup *add);
143 ContactGroup *ContactGroupFor     (Contact *cont, ContactGroup *except);
144 
145 /* NULL ContactGroup accesses global list */
146 Contact      *ContactIndex        (ContactGroup *group, int i);
147 Contact      *ContactUIN          (Server *serv, UDWORD uin DEBUGPARAM);
148 Contact      *ContactScreen       (Server *serv, const char *screen DEBUGPARAM);
149 #if ENABLE_CONT_HIER
150 Contact      *ContactScreenP      (Server *serv, Contact *parent, const char *screen DEBUGPARAM);
151 #endif
152 void          ContactCreate       (Server *serv, Contact *cont DEBUGPARAM);
153 Contact      *ContactFind         (Server *serv, const char *nick);
154 const char   *ContactFindAlias    (Contact *cont, const char *nick);
155 Contact      *ContactFindUIN      (ContactGroup *group, UDWORD uin);
156 Contact      *ContactFindScreen   (ContactGroup *group, const char *screen);
157 #if ENABLE_CONT_HIER
158 Contact      *ContactFindScreenP  (ContactGroup *group, Contact *parent, const char *screen);
159 #endif
160 BOOL          ContactAdd          (ContactGroup *group, Contact *cont DEBUGPARAM);
161 BOOL          ContactHas          (ContactGroup *group, Contact *cont);
162 BOOL          ContactRem          (ContactGroup *group, Contact *cont DEBUGPARAM);
163 void          ContactD            (Contact *cont DEBUGPARAM);
164 
165 int           ContactAddAlias     (Contact *cont, const char *nick DEBUGPARAM);
166 int           ContactRemAlias     (Contact *cont, const char *nick DEBUGPARAM);
167 
168 #define ContactGroupC(s,i,n)       ContactGroupC(s,i,n DEBUGARGS)
169 #define ContactGroupD(g)           ContactGroupD(g DEBUGARGS)
170 #define ContactUIN(c,u)            ContactUIN(c,u DEBUGARGS)
171 #define ContactScreen(c,s)         ContactScreen(c,s DEBUGARGS)
172 #if ENABLE_CONT_HIER
173 #define ContactScreenP(c,p,s)      ContactScreenP(c,p,s DEBUGARGS)
174 #endif
175 #define ContactCreate(g,c)         ContactCreate(g,c DEBUGARGS)
176 #define ContactAdd(g,c)            ContactAdd(g,c DEBUGARGS)
177 #define ContactRem(g,c)            ContactRem(g,c DEBUGARGS)
178 #define ContactD(c)                ContactD(c DEBUGARGS)
179 #define ContactAddAlias(c,n)       ContactAddAlias(c,n DEBUGARGS)
180 #define ContactRemAlias(c,n)       ContactRemAlias(c,n DEBUGARGS)
181 
182 ContactIDs   *ContactID           (Contact *cont, UWORD type);
183 ContactIDs   *ContactIDHas        (Contact *cont, UWORD type);
184 UWORD         ContactIDGet        (Contact *cont, UWORD type);
185 void          ContactIDSet        (Contact *cont, UWORD type, UWORD id, UWORD tag);
186 void          ContactSetCap       (Contact *cont, Cap *cap);
187 void          ContactSetVersion   (Contact *cont);
188 
189 void          ContactMetaD        (ContactMeta *m);
190 void          ContactMetaAdd      (ContactMeta **m, UWORD val, const char *text);
191 BOOL          ContactMetaSave     (Contact *cont);
192 BOOL          ContactMetaLoad     (Contact *cont);
193 
194 val_t         ContactGroupPrefVal (ContactGroup *cg, UDWORD flag);
195 
196 const char   *ContactPrefStr      (Contact *cont, UDWORD flag);
197 val_t         ContactPrefVal      (Contact *cont, UDWORD flag);
198 val_t         ContactPrefValCg    (Contact *ocont, ContactGroup *cg, UDWORD flag);
199 
200 BOOL          ContactStatus       (const char **args, status_t *stat);
201 const char   *ContactStatusStr    (status_t status);
202 
203 int           ContactStatusCmp    (status_t a, status_t b);
ContactCopyInv(status_t inv,status_noi_t status)204 static inline status_t ContactCopyInv (status_t inv, status_noi_t status)
205 {
206     if (status == imr_offline)
207         return ims_offline;
208     return (status_t)(status | (inv & ims_inv));
209 }
ContactClearInv(status_t status)210 static inline status_noi_t ContactClearInv (status_t status) { return (status_noi_t)(status & ~ims_inv); }
ContactIsInv(status_t inv)211 static inline BOOL ContactIsInv (status_t inv) { return (inv & ims_inv) ? TRUE : FALSE; }
212 
213 #define CONTACT_GENERAL(cont)  ((cont)->meta_general  ? (cont)->meta_general  : ((cont)->meta_general  = calloc (1, sizeof (MetaGeneral))))
214 #define CONTACT_WORK(cont)     ((cont)->meta_work     ? (cont)->meta_work     : ((cont)->meta_work     = calloc (1, sizeof (MetaWork))))
215 #define CONTACT_MORE(cont)     ((cont)->meta_more     ? (cont)->meta_more     : ((cont)->meta_more     = calloc (1, sizeof (MetaMore))))
216 #define CONTACT_OBSOLETE(cont) ((cont)->meta_obsolete ? (cont)->meta_obsolete : ((cont)->meta_obsolete = calloc (1, sizeof (MetaObsolete))))
217 #define CONTACT_DC(cont)       ((cont)->dc            ? (cont)->dc            : ((cont)->dc            = calloc (1, sizeof (ContactDC))))
218 
219 #define CONT_UTF8(cont,mt) (HAS_CAP((cont)->caps, CAP_UTF8) && (((mt) == 1) || HAS_CAP((cont)->caps, CAP_MICQ) || HAS_CAP((cont)->caps, CAP_CLIMM)))
220 
221 #define CONT_SEENAUTO  32UL /* has seen auto response. */
222 #define CONT_ISEDITED  64UL /* meta data was edited by hand. */
223 
224 #define UPF_GENERAL_A   0x0001
225 #define UPF_GENERAL_B   0x0002
226 #define UPF_WORK        0x0004
227 #define UPF_MORE        0x0008
228 #define UPF_ABOUT       0x0010
229 #define UPF_EMAIL       0x0020
230 #define UPF_INTEREST    0x0040
231 #define UPF_BACKGROUND  0x0080
232 #define UPF_AFFILIATION 0x0100
233 #define UPF_OBSOLETE    0x0200
234 #define UPF_GENERAL_C   0x0400
235 #define UPF_GENERAL_E   0x0800
236 
237 #define UPF_DISC        0x1000
238 #define UPF_SERVER      0x2000
239 #define UPF_AUTOFINGER  0x4000
240 
241 #define UP_ALL          (UPF_DISC | UPF_SERVER)
242 #define UP_INFO         (UPF_GENERAL_A  | UPF_GENERAL_B | UPF_WORK | UPF_MORE \
243                          | UPF_ABOUT    | UPF_INTEREST  | UPF_BACKGROUND  \
244                          | UPF_EMAIL    | UPF_OBSOLETE  | UPF_AFFILIATION)
245 
246 #endif /* CLIMM_CONTACT_H */
247