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