]> andersk Git - libfaim.git/blame - faim/aim.h
- Thu Mar 23 08:45:40 UTC 2000
[libfaim.git] / faim / aim.h
CommitLineData
bd71fa88 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 <faim/faimconfig.h>
10#include <faim/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 * Current Maximum Length for Screen Names (not including NULL)
45 */
46#define MAXSNLEN 16
47
48/*
49 * Standard size of an AIM authorization cookie
50 */
51#define AIM_COOKIELEN 0x100
52
b8d0da45 53#if debug > 0
54#define faimdprintf(l, x...) {if (l >= debug) printf(x); }
55#else
56#define faimdprintf(l, x...)
57#endif
58
bd71fa88 59/*
60 * Login info. Passes information from the Authorization
61 * stage of login to the service (BOS, etc) connection
62 * phase.
63 *
64 */
65struct aim_login_struct {
66 char screen_name[MAXSNLEN+1];
67 char *BOSIP;
68 char cookie[AIM_COOKIELEN];
69 char *email;
70 u_short regstatus;
01b59e1e 71 char *errorurl;
72 u_short errorcode;
bd71fa88 73};
74
75/*
76 * Client info. Filled in by the client and passed
77 * in to aim_login(). The information ends up
78 * getting passed to OSCAR through the initial
79 * login command.
80 *
81 * XXX: Should this be per-session? -mid
82 *
83 */
84struct client_info_s {
85 char clientstring[100]; /* arbitrary size */
86 int major;
87 int minor;
88 int build;
89 char country[3];
90 char lang[3];
91};
92
93#ifndef TRUE
94#define TRUE 1
95#define FALSE 0
96#endif
97
98/*
99 * These could be arbitrary, but its easier to use the actual AIM values
100 */
101#define AIM_CONN_TYPE_AUTH 0x0007
102#define AIM_CONN_TYPE_ADS 0x0005
103#define AIM_CONN_TYPE_BOS 0x0002
104#define AIM_CONN_TYPE_CHAT 0x000e
105#define AIM_CONN_TYPE_CHATNAV 0x000d
106
107/*
108 * Status values returned from aim_conn_new(). ORed together.
109 */
110#define AIM_CONN_STATUS_READY 0x0001
111#define AIM_CONN_STATUS_INTERNALERR 0x0002
112#define AIM_CONN_STATUS_RESOLVERR 0x0080
113#define AIM_CONN_STATUS_CONNERR 0x0040
114
115struct aim_conn_t {
116 int fd;
117 int type;
118 int seqnum;
119 int status;
120 void *priv; /* misc data the client may want to store */
121 time_t lastactivity; /* time of last transmit */
122 int forcedlatency;
123 struct aim_rxcblist_t *handlerlist;
124};
125
126/* struct for incoming commands */
127struct command_rx_struct {
128 /* byte 1 assumed to always be 0x2a */
129 char type; /* type code (byte 2) */
130 u_int seqnum; /* sequence number (bytes 3 and 4) */
131 u_int commandlen; /* total packet len - 6 (bytes 5 and 6) */
132 u_char *data; /* packet data (from 7 byte on) */
133 u_int lock; /* 0 = open, !0 = locked */
134 u_int handled; /* 0 = new, !0 = been handled */
b8d0da45 135 u_int nofree; /* 0 = free data on purge, 1 = only unlink */
bd71fa88 136 struct aim_conn_t *conn; /* the connection it came in on... */
137 struct command_rx_struct *next; /* ptr to next struct in list */
138};
139
140/* struct for outgoing commands */
141struct command_tx_struct {
142 /* byte 1 assumed to be 0x2a */
143 char type; /* type/family code */
144 u_int seqnum; /* seqnum dynamically assigned on tx */
145 u_int commandlen; /* SNAC length */
146 u_char *data; /* packet data */
147 u_int lock; /* 0 = open, !0 = locked */
148 u_int sent; /* 0 = pending, !0 = has been sent */
149 struct aim_conn_t *conn;
150 struct command_tx_struct *next; /* ptr to next struct in list */
151};
152
153
154/*
155 * AIM Session: The main client-data interface.
156 *
157 */
158struct aim_session_t {
159
160 /* ---- Client Accessible ------------------------ */
161 /*
162 * Login information. See definition above.
163 *
164 */
165 struct aim_login_struct logininfo;
166
167 /*
168 * Pointer to anything the client wants to
169 * explicitly associate with this session.
170 */
171 void *aux_data;
172
173
174 /* ---- Internal Use Only ------------------------ */
175 /*
176 * Connection information
177 */
178 struct aim_conn_t conns[AIM_CONN_MAX];
179
180 /*
181 * TX/RX queues
182 */
183 struct command_tx_struct *queue_outgoing;
184 struct command_rx_struct *queue_incoming;
185
0c20631f 186 /*
187 * This is a dreadful solution to the what-room-are-we-joining
188 * problem. (There's no connection between the service
189 * request and the resulting redirect.)
190 */
191 char *pendingjoin;
192
bd71fa88 193 /*
194 * Outstanding snac handling
195 *
196 * XXX: Should these be per-connection? -mid
197 **/
198 struct aim_snac_t *outstanding_snacs;
199 u_long snac_nextid;
200};
201
202
203/*
204 * AIM User Info, Standard Form.
205 */
206struct aim_userinfo_s {
207 char sn[MAXSNLEN+1];
208 u_short warnlevel;
209 u_short idletime;
210 u_short class;
211 u_long membersince;
212 u_long onlinesince;
213 u_long sessionlen;
214};
215
0c20631f 216#define AIM_CLASS_TRIAL 0x0001
217#define AIM_CLASS_UNKNOWN2 0x0002
218#define AIM_CLASS_AOL 0x0004
219#define AIM_CLASS_UNKNOWN4 0x0008
220#define AIM_CLASS_FREE 0x0010
221#define AIM_CLASS_AWAY 0x0020
222#define AIM_CLASS_UNKNOWN40 0x0040
223#define AIM_CLASS_UNKNOWN80 0x0080
224
bd71fa88 225/*
226 * TLV handling
227 */
228
229/* Generic TLV structure. */
230struct aim_tlv_t {
231 u_short type;
232 u_short length;
233 u_char *value;
234};
235
236/* List of above. */
237struct aim_tlvlist_t {
238 struct aim_tlv_t *tlv;
239 struct aim_tlvlist_t *next;
240};
241
242/* TLV-handling functions */
243struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
244void aim_freetlvchain(struct aim_tlvlist_t **list);
245struct aim_tlv_t *aim_grabtlv(u_char *src);
246struct aim_tlv_t *aim_grabtlvstr(u_char *src);
247struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
248char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
249int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
250struct aim_tlv_t *aim_createtlv(void);
251int aim_freetlv(struct aim_tlv_t **oldtlv);
252int aim_puttlv_16(u_char *, u_short, u_short);
01b59e1e 253int aim_puttlv_32(u_char *, u_short, u_long);
254int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v);
0e2be272 255int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list);
256int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val);
e6b05d80 257int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val);
258int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len);
259int aim_counttlvchain(struct aim_tlvlist_t **list);
bd71fa88 260
261/*
262 * Get command from connections / Dispatch commands
263 * already in queue.
264 */
265int aim_get_command(struct aim_session_t *);
266int aim_rxdispatch(struct aim_session_t *);
267
268int aim_logoff(struct aim_session_t *);
269
270
271typedef int (*rxcallback_t)(struct aim_session_t *, struct command_rx_struct *, ...);
272int aim_register_callbacks(rxcallback_t *);
273
274u_long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype);
275u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
276u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
277
278/* aim_login.c */
01b59e1e 279int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
280int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
bd71fa88 281int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *);
282int aim_encode_password(const char *, u_char *);
e6b05d80 283unsigned long aim_sendauthresp(struct aim_session_t *sess,
284 struct aim_conn_t *conn,
285 char *sn, char *bosip,
286 char *cookie, char *email,
287 int regstatus);
288int aim_gencookie(unsigned char *buf);
289int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn);
290unsigned long aim_sendredirect(struct aim_session_t *sess,
291 struct aim_conn_t *conn,
292 unsigned short servid,
293 char *ip,
294 char *cookie);
b8d0da45 295void aim_purge_rxqueue(struct aim_session_t *);
bd71fa88 296
297
298int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
299int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...);
300int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
301
302int aim_tx_enqueue(struct aim_session_t *, struct command_tx_struct *);
303u_int aim_get_next_txseqnum(struct aim_conn_t *);
304int aim_tx_flushqueue(struct aim_session_t *);
305int aim_tx_printqueue(struct aim_session_t *);
b8d0da45 306void aim_tx_purgequeue(struct aim_session_t *);
bd71fa88 307
308struct aim_rxcblist_t {
309 u_short family;
310 u_short type;
311 rxcallback_t handler;
312 u_short flags;
313 struct aim_rxcblist_t *next;
314};
315
316int aim_conn_setlatency(struct aim_conn_t *conn, int newval);
317
318int aim_conn_addhandler(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short type, rxcallback_t newhandler, u_short flags);
319rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
320int aim_clearhandlers(struct aim_conn_t *conn);
321
322/*
323 * Generic SNAC structure. Rarely if ever used.
324 */
325struct aim_snac_t {
326 u_long id;
327 u_short family;
328 u_short type;
329 u_short flags;
330 void *data;
331 time_t issuetime;
332 struct aim_snac_t *next;
333};
334u_long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac);
335struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id);
336int aim_cleansnacs(struct aim_session_t *, int maxage);
337int aim_putsnac(u_char *, int, int, int, u_long);
338
339
340void aim_connrst(struct aim_session_t *);
341struct aim_conn_t *aim_conn_getnext(struct aim_session_t *);
342void aim_conn_close(struct aim_conn_t *deadconn);
343struct aim_conn_t *aim_getconn_type(struct aim_session_t *, int type);
344struct aim_conn_t *aim_newconn(struct aim_session_t *, int type, char *dest);
345int aim_conngetmaxfd(struct aim_session_t *);
b8d0da45 346struct aim_conn_t *aim_select(struct aim_session_t *, struct timeval *, int *);
bd71fa88 347int aim_conn_isready(struct aim_conn_t *);
348int aim_conn_setstatus(struct aim_conn_t *, int);
349void aim_session_init(struct aim_session_t *);
350
351/* aim_misc.c */
352
353#define AIM_VISIBILITYCHANGE_PERMITADD 0x05
354#define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06
355#define AIM_VISIBILITYCHANGE_DENYADD 0x07
356#define AIM_VISIBILITYCHANGE_DENYREMOVE 0x08
357
358u_long aim_bos_setidle(struct aim_session_t *, struct aim_conn_t *, u_long);
359u_long aim_bos_changevisibility(struct aim_session_t *, struct aim_conn_t *, int, char *);
360u_long aim_bos_setbuddylist(struct aim_session_t *, struct aim_conn_t *, char *);
0c20631f 361u_long aim_bos_setprofile(struct aim_session_t *, struct aim_conn_t *, char *, char *);
bd71fa88 362u_long aim_bos_setgroupperm(struct aim_session_t *, struct aim_conn_t *, u_long);
363u_long aim_bos_clientready(struct aim_session_t *, struct aim_conn_t *);
364u_long aim_bos_reqrate(struct aim_session_t *, struct aim_conn_t *);
365u_long aim_bos_ackrateresp(struct aim_session_t *, struct aim_conn_t *);
366u_long aim_bos_setprivacyflags(struct aim_session_t *, struct aim_conn_t *, u_long);
367u_long aim_bos_reqpersonalinfo(struct aim_session_t *, struct aim_conn_t *);
368u_long aim_bos_reqservice(struct aim_session_t *, struct aim_conn_t *, u_short);
369u_long aim_bos_reqrights(struct aim_session_t *, struct aim_conn_t *);
370u_long aim_bos_reqbuddyrights(struct aim_session_t *, struct aim_conn_t *);
371u_long aim_bos_reqlocaterights(struct aim_session_t *, struct aim_conn_t *);
372u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *);
0c20631f 373u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn);
bd71fa88 374
375/* aim_rxhandlers.c */
376int aim_rxdispatch(struct aim_session_t *);
377int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
378int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...);
379int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...);
380int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
381int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...);
01b59e1e 382int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
bd71fa88 383
384/* aim_im.c */
385#define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
386#define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */
387
388u_long aim_send_im(struct aim_session_t *, struct aim_conn_t *, char *, u_int, char *);
389int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *);
390u_long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn);
391int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
392
393/* aim_info.c */
394u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *);
395int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
396int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
397int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);
398int aim_parse_offgoing_middle(struct aim_session_t *, struct command_rx_struct *);
50443ea0 399int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info);
400int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info);
401int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
bd71fa88 402
403/* aim_auth.c */
404int aim_auth_sendcookie(struct aim_session_t *, struct aim_conn_t *, u_char *);
405u_long aim_auth_clientready(struct aim_session_t *, struct aim_conn_t *);
406u_long aim_auth_changepasswd(struct aim_session_t *, struct aim_conn_t *, char *, char *);
407
408/* aim_buddylist.c */
409u_long aim_add_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
410u_long aim_remove_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
411
412/* aim_search.c */
413u_long aim_usersearch_address(struct aim_session_t *, struct aim_conn_t *, char *);
414/* u_long aim_usersearch_name(struct aim_session_t *, struct aim_conn_t *, char *); */
415
0c20631f 416
417struct aim_chat_roominfo {
418 u_short exchange;
419 char *name;
420 u_short instance;
421};
422int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo);
423int aim_chat_parse_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command);
424int aim_chat_parse_joined(struct aim_session_t *sess, struct command_rx_struct *command);
425int aim_chat_parse_leave(struct aim_session_t *sess, struct command_rx_struct *command);
426int aim_chat_parse_incoming(struct aim_session_t *sess, struct command_rx_struct *command);
427u_long aim_chat_send_im(struct aim_session_t *sess, struct aim_conn_t *conn, char *msg);
428u_long aim_chat_join(struct aim_session_t *sess, struct aim_conn_t *conn, u_short exchange, const char *roomname);
429u_long aim_chat_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
430int aim_chat_attachname(struct aim_conn_t *conn, char *roomname);
431char *aim_chat_getname(struct aim_conn_t *conn);
432struct aim_conn_t *aim_chat_getconn(struct aim_session_t *, char *name);
433
434u_long aim_chatnav_reqrights(struct aim_session_t *sess, struct aim_conn_t *conn);
435u_long aim_chatnav_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
436
437u_long aim_chat_invite(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn, char *msg, u_short exchange, char *roomname, u_short instance);
438
439struct aim_chat_exchangeinfo {
440 u_short number;
441 char *name;
442 char *charset1;
443 char *lang1;
444 char *charset2;
445 char *lang2;
446};
447int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command);
448u_long aim_chatnav_createroom(struct aim_session_t *sess, struct aim_conn_t *conn, char *name, u_short exchange);
449int aim_chat_leaveroom(struct aim_session_t *sess, char *name);
450
bd71fa88 451/* aim_util.c */
452int aimutil_put8(u_char *, u_char);
453u_char aimutil_get8(u_char *buf);
454int aimutil_put16(u_char *, u_short);
455u_short aimutil_get16(u_char *);
456int aimutil_put32(u_char *, u_long);
457u_long aimutil_get32(u_char *);
458int aimutil_putstr(u_char *, const u_char *, int);
459int aimutil_tokslen(char *toSearch, int index, char dl);
460int aimutil_itemcnt(char *toSearch, char dl);
461char *aimutil_itemidx(char *toSearch, int index, char dl);
462
e6b05d80 463int aim_snlen(const char *sn);
464int aim_sncmp(const char *sn1, const char *sn2);
465
bd71fa88 466#endif /* __AIM_H__ */
467
This page took 0.115791 seconds and 5 git commands to generate.