]> andersk Git - libfaim.git/blame - aim.h
Misc cleanups.
[libfaim.git] / aim.h
CommitLineData
adca9dcf 1/*
2 * Main libfaim header. Must be included in client for prototypes/macros.
3 *
4 */
5
9de3ca7e 6#ifndef __AIM_H__
7#define __AIM_H__
8
9#include <faimconfig.h>
adca9dcf 10#include <aim_cbtypes.h>
9de3ca7e 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
adca9dcf 50/*
51 * Current Maximum Length for Screen Names (not including NULL)
52 */
9de3ca7e 53#define MAXSNLEN 16
54
55struct login_phase1_struct {
56 char *screen_name;
57 char *BOSIP;
58 char *cookie;
59 char *email;
60 u_short regstatus;
61};
62
63extern struct login_phase1_struct aim_logininfo;
64
65struct 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
9de3ca7e 74#ifndef TRUE
75#define TRUE 1
76#define FALSE 0
77#endif
78
adca9dcf 79/*
80 * These could be arbitrary, but its easier to use the actual AIM values
81 */
9de3ca7e 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
9de3ca7e 93struct aim_conn_t {
94 int fd;
95 int type;
96 int seqnum;
97 int status;
adca9dcf 98 void *priv; /* misc data the client may want to store */
9de3ca7e 99 time_t lastactivity; /* time of last transmit */
100 int forcedlatency;
101 struct aim_rxcblist_t *handlerlist;
102};
103struct aim_conn_t aim_conns[AIM_CONN_MAX];
104
105
106/* struct for incoming commands */
107struct 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 */
120struct 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 */
135struct 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
adca9dcf 145/*
146 * TLV handling
147 */
148
149/* Generic TLV structure. */
9de3ca7e 150struct aim_tlv_t {
151 u_short type;
152 u_short length;
153 u_char *value;
154};
155
adca9dcf 156/* List of above. */
49c8a2fa 157struct aim_tlvlist_t {
158 struct aim_tlv_t *tlv;
159 struct aim_tlvlist_t *next;
160};
adca9dcf 161
162/* TLV-handling functions */
49c8a2fa 163struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
164void aim_freetlvchain(struct aim_tlvlist_t **list);
9de3ca7e 165struct aim_tlv_t *aim_grabtlv(u_char *src);
166struct aim_tlv_t *aim_grabtlvstr(u_char *src);
adca9dcf 167struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
168char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
9de3ca7e 169int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
170struct aim_tlv_t *aim_createtlv(void);
171int aim_freetlv(struct aim_tlv_t **oldtlv);
172int aim_puttlv_16(u_char *, u_short, u_short);
173
9de3ca7e 174
9de3ca7e 175int aim_get_command(void);
176int aim_rxdispatch(void);
177int aim_logoff(void);
178
179typedef int (*rxcallback_t)(struct command_rx_struct *, ...);
180int aim_register_callbacks(rxcallback_t *);
181
182u_long aim_genericreq_n(struct aim_conn_t *conn, u_short family, u_short subtype);
183u_long aim_genericreq_l(struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
184u_long aim_genericreq_s(struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
185
186/* aim_login.c */
187int aim_send_login (struct aim_conn_t *, char *, char *, struct client_info_s *);
188int aim_encode_password(const char *, char *);
189
190
191struct command_rx_struct *aim_purge_rxqueue(struct command_rx_struct *queue);
192
193
194int aim_parse_unknown(struct command_rx_struct *command, ...);
195int aim_parse_missed_im(struct command_rx_struct *, ...);
196int aim_parse_last_bad(struct command_rx_struct *, ...);
197
198int aim_tx_enqueue(struct command_tx_struct *);
199u_int aim_get_next_txseqnum(struct aim_conn_t *);
200int aim_tx_flushqueue(void);
201int aim_tx_printqueue(void);
202int aim_tx_purgequeue(void);
203
204/* queue (linked list) pointers */
205extern struct command_tx_struct *aim_queue_outgoing; /* incoming commands */
206extern struct command_rx_struct *aim_queue_incoming; /* outgoing commands */
207
208/* The default callback handler array */
209extern rxcallback_t aim_callbacks[];
210
211struct 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
219int aim_conn_setlatency(struct aim_conn_t *conn, int newval);
220
221int aim_conn_addhandler(struct aim_conn_t *conn, u_short family, u_short type, rxcallback_t newhandler, u_short flags);
222rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
223int aim_clearhandlers(struct aim_conn_t *conn);
224
225extern struct aim_snac_t *aim_outstanding_snacs;
226extern u_long aim_snac_nextid;
227
adca9dcf 228/*
229 * Generic SNAC structure. Rarely if ever used.
230 */
9de3ca7e 231struct 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};
240u_long aim_newsnac(struct aim_snac_t *newsnac);
241struct aim_snac_t *aim_remsnac(u_long id);
242int aim_cleansnacs(int maxage);
243int aim_putsnac(u_char *, int, int, int, u_long);
244
adca9dcf 245
9de3ca7e 246void aim_connrst(void);
247struct aim_conn_t *aim_conn_getnext(void);
248void aim_conn_close(struct aim_conn_t *deadconn);
249struct aim_conn_t *aim_getconn_type(int type);
250struct aim_conn_t *aim_newconn(int type, char *dest);
251int aim_conngetmaxfd(void);
252struct aim_conn_t *aim_select(struct timeval *);
253int aim_conn_isready(struct aim_conn_t *);
254int 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
263u_long aim_bos_setidle(struct aim_conn_t *, u_long);
264u_long aim_bos_changevisibility(struct aim_conn_t *, int, char *);
265u_long aim_bos_setbuddylist(struct aim_conn_t *, char *);
266u_long aim_bos_setprofile(struct aim_conn_t *, char *);
267u_long aim_bos_setgroupperm(struct aim_conn_t *, u_long);
268u_long aim_bos_clientready(struct aim_conn_t *);
269u_long aim_bos_reqrate(struct aim_conn_t *);
270u_long aim_bos_ackrateresp(struct aim_conn_t *);
271u_long aim_bos_setprivacyflags(struct aim_conn_t *, u_long);
272u_long aim_bos_reqpersonalinfo(struct aim_conn_t *);
273u_long aim_bos_reqservice(struct aim_conn_t *, u_short);
274u_long aim_bos_reqrights(struct aim_conn_t *);
275u_long aim_bos_reqbuddyrights(struct aim_conn_t *);
276u_long aim_bos_reqlocaterights(struct aim_conn_t *);
277u_long aim_bos_reqicbmparaminfo(struct aim_conn_t *);
278
279/* aim_rxhandlers.c */
280int aim_register_callbacks(rxcallback_t *);
281int aim_rxdispatch(void);
282int aim_authparse(struct command_rx_struct *);
283int aim_handleredirect_middle(struct command_rx_struct *, ...);
284int aim_parse_unknown(struct command_rx_struct *, ...);
285int aim_parse_missed_im(struct command_rx_struct *, ...);
286int aim_parse_last_bad(struct command_rx_struct *, ...);
287int 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 */
292u_long aim_send_im(struct aim_conn_t *, char *, int, char *);
293int aim_parse_incoming_im_middle(struct command_rx_struct *);
49c8a2fa 294u_long aim_seticbmparam(struct aim_conn_t *conn);
9de3ca7e 295
296/* aim_info.c */
297u_long aim_getinfo(struct aim_conn_t *, const char *);
298int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
299int aim_parse_userinfo_middle(struct command_rx_struct *);
300int aim_parse_oncoming_middle(struct command_rx_struct *);
301
302/* aim_auth.c */
303int aim_auth_sendcookie(struct aim_conn_t *, char *);
304u_long aim_auth_clientready(struct aim_conn_t *);
305u_long aim_auth_changepasswd(struct aim_conn_t *, char *, char *);
306
307/* aim_buddylist.c */
308u_long aim_add_buddy(struct aim_conn_t *, char *);
309u_long aim_remove_buddy(struct aim_conn_t *, char *);
310
311/* aim_search.c */
312u_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 */
316int aimutil_put8(u_char *, u_char);
49c8a2fa 317u_char aimutil_get8(u_char *buf);
9de3ca7e 318int aimutil_put16(u_char *, u_short);
319u_short aimutil_get16(u_char *);
320int aimutil_put32(u_char *, u_long);
321u_long aimutil_get32(u_char *);
322int aimutil_putstr(u_char *, const u_char *, int);
323int aimutil_tokslen(char *toSearch, int index, char dl);
324int aimutil_itemcnt(char *toSearch, char dl);
325char *aimutil_itemidx(char *toSearch, int index, char dl);
326
9de3ca7e 327#endif /* __AIM_H__ */
328
This page took 0.143085 seconds and 5 git commands to generate.