]> andersk Git - libfaim.git/blob - aim.h
Misc cleanups.
[libfaim.git] / aim.h
1 /* 
2  * Main libfaim header.  Must be included in client for prototypes/macros.
3  *
4  */
5
6 #ifndef __AIM_H__
7 #define __AIM_H__
8
9 #include <faimconfig.h>
10 #include <aim_cbtypes.h>
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <fcntl.h>
15 #include <sys/types.h>
16 #include <stdlib.h>
17 #include <stdarg.h>
18 #include <errno.h>
19
20 #ifdef _WIN32
21 #include <windows.h>
22 #include <time.h>
23 #include <io.h>
24 #else
25 #include <netdb.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <sys/time.h>
29 #include <unistd.h>
30 #endif
31
32 /* Portability stuff (DMP) */
33
34 #ifdef _WIN32
35 #define sleep Sleep
36 #define strlen(x) (int)strlen(x)  /* win32 has a unsigned size_t */
37 #endif
38
39 #if defined(_WIN32) || (defined(mach) && defined(__APPLE__)) 
40 #define gethostbyname2(x,y) gethostbyname(x) /* revert to IPv4 */
41 #endif 
42
43 /*
44  * Login Error codes
45  */
46 #define AIM_CONNECT_ERROR       -0x1
47 #define AIM_SIGNON_TOO_SOON     -0x4
48 #define AIM_SERVICE_FULL        -0x6f
49
50 /* 
51  * Current Maximum Length for Screen Names (not including NULL) 
52  */
53 #define MAXSNLEN 16
54
55 struct login_phase1_struct {
56   char *screen_name;
57   char *BOSIP;
58   char *cookie;
59   char *email;
60   u_short regstatus;
61 };
62
63 extern struct login_phase1_struct aim_logininfo;
64
65 struct client_info_s {
66   char clientstring[100]; /* arbitrary number */
67   int major;
68   int minor;
69   int build;
70   char country[3];
71   char lang[3];
72 };
73
74 #ifndef TRUE
75 #define TRUE 1
76 #define FALSE 0
77 #endif
78
79 /* 
80  * These could be arbitrary, but its easier to use the actual AIM values 
81  */
82 #define AIM_CONN_TYPE_AUTH 0x0007
83 #define AIM_CONN_TYPE_ADS 0x0005
84 #define AIM_CONN_TYPE_BOS 2
85 #define AIM_CONN_TYPE_CHAT 0x000e
86 #define AIM_CONN_TYPE_CHATNAV 0x000d
87
88 #define AIM_CONN_STATUS_READY 0x0001
89 #define AIM_CONN_STATUS_INTERNALERR 0x0002
90 #define AIM_CONN_STATUS_RESOLVERR 0x80
91 #define AIM_CONN_STATUS_CONNERR 0x40
92
93 struct aim_conn_t {
94   int fd;
95   int type;
96   int seqnum;
97   int status;
98   void *priv; /* misc data the client may want to store */
99   time_t lastactivity; /* time of last transmit */
100   int forcedlatency; 
101   struct aim_rxcblist_t *handlerlist;
102 };
103 struct aim_conn_t aim_conns[AIM_CONN_MAX];
104
105
106 /* struct for incoming commands */
107 struct command_rx_struct {
108                             /* byte 1 assumed to always be 0x2a */
109   char type;                /* type code (byte 2) */
110   u_int seqnum;             /* sequence number (bytes 3 and 4) */
111   u_int commandlen;         /* total packet len - 6 (bytes 5 and 6) */
112   u_char *data;             /* packet data (from 7 byte on) */
113   u_int lock;               /* 0 = open, !0 = locked */
114   u_int handled;            /* 0 = new, !0 = been handled */
115   struct aim_conn_t *conn;  /* the connection it came in on... */
116   struct command_rx_struct *next; /* ptr to next struct in list */
117 };
118
119 /* struct for outgoing commands */
120 struct command_tx_struct {
121                             /* byte 1 assumed to be 0x2a */
122   char type;                /* type/family code */
123   u_int seqnum;             /* seqnum dynamically assigned on tx */
124   u_int commandlen;         /* SNAC length */
125   u_char *data;             /* packet data */
126   u_int lock;               /* 0 = open, !0 = locked */
127   u_int sent;               /* 0 = pending, !0 = has been sent */
128   struct aim_conn_t *conn; 
129   struct command_tx_struct *next; /* ptr to next struct in list */
130 };
131
132 /*
133  * AIM User Info, Standard Form.
134  */
135 struct aim_userinfo_s {
136   char sn[MAXSNLEN+1];
137   u_short warnlevel;
138   u_short idletime;
139   u_short class;
140   u_long membersince;
141   u_long onlinesince;
142   u_long sessionlen;  
143 };
144
145 /*
146  * TLV handling
147  */
148
149 /* Generic TLV structure. */
150 struct aim_tlv_t {
151   u_short type;
152   u_short length;
153   u_char *value;
154 };
155
156 /* List of above. */
157 struct aim_tlvlist_t {
158   struct aim_tlv_t *tlv;
159   struct aim_tlvlist_t *next;
160 };
161
162 /* TLV-handling functions */
163 struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
164 void aim_freetlvchain(struct aim_tlvlist_t **list);
165 struct aim_tlv_t *aim_grabtlv(u_char *src);
166 struct aim_tlv_t *aim_grabtlvstr(u_char *src);
167 struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
168 char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
169 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
170 struct aim_tlv_t *aim_createtlv(void);
171 int aim_freetlv(struct aim_tlv_t **oldtlv);
172 int aim_puttlv_16(u_char *, u_short, u_short);
173
174
175 int aim_get_command(void);
176 int aim_rxdispatch(void);
177 int aim_logoff(void);
178
179 typedef int (*rxcallback_t)(struct command_rx_struct *, ...);
180 int aim_register_callbacks(rxcallback_t *);
181
182 u_long aim_genericreq_n(struct aim_conn_t *conn, u_short family, u_short subtype);
183 u_long aim_genericreq_l(struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
184 u_long aim_genericreq_s(struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
185
186 /* aim_login.c */
187 int aim_send_login (struct aim_conn_t *, char *, char *, struct client_info_s *);
188 int aim_encode_password(const char *, char *);
189
190
191 struct command_rx_struct *aim_purge_rxqueue(struct command_rx_struct *queue);
192
193
194 int aim_parse_unknown(struct command_rx_struct *command, ...);
195 int aim_parse_missed_im(struct command_rx_struct *, ...);
196 int aim_parse_last_bad(struct command_rx_struct *, ...);
197
198 int aim_tx_enqueue(struct command_tx_struct *);
199 u_int aim_get_next_txseqnum(struct aim_conn_t *);
200 int aim_tx_flushqueue(void);
201 int aim_tx_printqueue(void);
202 int aim_tx_purgequeue(void);
203
204 /* queue (linked list) pointers */
205 extern struct command_tx_struct *aim_queue_outgoing; /* incoming commands */
206 extern struct command_rx_struct *aim_queue_incoming; /* outgoing commands */
207
208 /* The default callback handler array */
209 extern rxcallback_t aim_callbacks[];
210
211 struct aim_rxcblist_t {
212   u_short family;
213   u_short type;
214   rxcallback_t handler;
215   u_short flags;
216   struct aim_rxcblist_t *next;
217 };
218
219 int aim_conn_setlatency(struct aim_conn_t *conn, int newval);
220
221 int aim_conn_addhandler(struct aim_conn_t *conn, u_short family, u_short type, rxcallback_t newhandler, u_short flags);
222 rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
223 int aim_clearhandlers(struct aim_conn_t *conn);
224
225 extern struct aim_snac_t *aim_outstanding_snacs;
226 extern u_long aim_snac_nextid;
227
228 /*
229  * Generic SNAC structure.  Rarely if ever used.
230  */
231 struct aim_snac_t {
232   u_long id;
233   u_short family;
234   u_short type;
235   u_short flags;
236   void *data;
237   time_t issuetime;
238   struct aim_snac_t *next;
239 };
240 u_long aim_newsnac(struct aim_snac_t *newsnac);
241 struct aim_snac_t *aim_remsnac(u_long id);
242 int aim_cleansnacs(int maxage);
243 int aim_putsnac(u_char *, int, int, int, u_long);
244
245
246 void aim_connrst(void);
247 struct aim_conn_t *aim_conn_getnext(void);
248 void aim_conn_close(struct aim_conn_t *deadconn);
249 struct aim_conn_t *aim_getconn_type(int type);
250 struct aim_conn_t *aim_newconn(int type, char *dest);
251 int aim_conngetmaxfd(void);
252 struct aim_conn_t *aim_select(struct timeval *);
253 int aim_conn_isready(struct aim_conn_t *);
254 int aim_conn_setstatus(struct aim_conn_t *, int);
255
256 /* aim_misc.c */
257
258 #define AIM_VISIBILITYCHANGE_PERMITADD 0x05
259 #define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06
260 #define AIM_VISIBILITYCHANGE_DENYADD 0x07
261 #define AIM_VISIBILITYCHANGE_DENYREMOVE 0x08
262
263 u_long aim_bos_setidle(struct aim_conn_t *, u_long);
264 u_long aim_bos_changevisibility(struct aim_conn_t *, int, char *);
265 u_long aim_bos_setbuddylist(struct aim_conn_t *, char *);
266 u_long aim_bos_setprofile(struct aim_conn_t *, char *);
267 u_long aim_bos_setgroupperm(struct aim_conn_t *, u_long);
268 u_long aim_bos_clientready(struct aim_conn_t *);
269 u_long aim_bos_reqrate(struct aim_conn_t *);
270 u_long aim_bos_ackrateresp(struct aim_conn_t *);
271 u_long aim_bos_setprivacyflags(struct aim_conn_t *, u_long);
272 u_long aim_bos_reqpersonalinfo(struct aim_conn_t *);
273 u_long aim_bos_reqservice(struct aim_conn_t *, u_short);
274 u_long aim_bos_reqrights(struct aim_conn_t *);
275 u_long aim_bos_reqbuddyrights(struct aim_conn_t *);
276 u_long aim_bos_reqlocaterights(struct aim_conn_t *);
277 u_long aim_bos_reqicbmparaminfo(struct aim_conn_t *);
278
279 /* aim_rxhandlers.c */
280 int aim_register_callbacks(rxcallback_t *);
281 int aim_rxdispatch(void);
282 int aim_authparse(struct command_rx_struct *);
283 int aim_handleredirect_middle(struct command_rx_struct *, ...);
284 int aim_parse_unknown(struct command_rx_struct *, ...);
285 int aim_parse_missed_im(struct command_rx_struct *, ...);
286 int aim_parse_last_bad(struct command_rx_struct *, ...);
287 int aim_parse_generalerrs(struct command_rx_struct *command, ...);
288
289 /* aim_im.c */
290 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
291 #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */
292 u_long aim_send_im(struct aim_conn_t *, char *, int, char *);
293 int aim_parse_incoming_im_middle(struct command_rx_struct *);
294 u_long aim_seticbmparam(struct aim_conn_t *conn);
295
296 /* aim_info.c */
297 u_long aim_getinfo(struct aim_conn_t *, const char *);
298 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
299 int aim_parse_userinfo_middle(struct command_rx_struct *);
300 int aim_parse_oncoming_middle(struct command_rx_struct *);
301
302 /* aim_auth.c */
303 int aim_auth_sendcookie(struct aim_conn_t *, char *);
304 u_long aim_auth_clientready(struct aim_conn_t *);
305 u_long aim_auth_changepasswd(struct aim_conn_t *, char *, char *);
306
307 /* aim_buddylist.c */
308 u_long aim_add_buddy(struct aim_conn_t *, char *);
309 u_long aim_remove_buddy(struct aim_conn_t *, char *);
310
311 /* aim_search.c */
312 u_long aim_usersearch_address(struct aim_conn_t *, char *);
313 /* u_long aim_usersearch_name(struct aim_conn_t *, char *); */
314
315 /* aim_util.c */
316 int aimutil_put8(u_char *, u_char);
317 u_char aimutil_get8(u_char *buf);
318 int aimutil_put16(u_char *, u_short);
319 u_short aimutil_get16(u_char *);
320 int aimutil_put32(u_char *, u_long);
321 u_long aimutil_get32(u_char *);
322 int aimutil_putstr(u_char *, const u_char *, int);
323 int aimutil_tokslen(char *toSearch, int index, char dl);
324 int aimutil_itemcnt(char *toSearch, char dl);
325 char *aimutil_itemidx(char *toSearch, int index, char dl);
326
327 #endif /* __AIM_H__ */
328
This page took 0.060085 seconds and 5 git commands to generate.