2 * Main libfaim header. Must be included in client for prototypes/macros.
9 #define FAIM_VERSION_MAJOR 0
10 #define FAIM_VERSION_MINOR 99
11 #define FAIM_VERSION_MINORMINOR 0
13 #include <faim/faimconfig.h>
14 #include <faim/aim_cbtypes.h>
16 #ifndef FAIM_USEPTHREADS
17 #error pthreads are currently required.
23 #include <sys/types.h>
28 #ifdef FAIM_USEPTHREADS
30 #define faim_mutex_t pthread_mutex_t
31 #define faim_mutex_init pthread_mutex_init
32 #define faim_mutex_lock pthread_mutex_lock
33 #define faim_mutex_unlock pthread_mutex_unlock
42 #include <sys/socket.h>
43 #include <netinet/in.h>
48 /* Portability stuff (DMP) */
52 #define strlen(x) (int)strlen(x) /* win32 has a unsigned size_t */
55 #if defined(mach) && defined(__APPLE__)
56 #define gethostbyname(x) gethostbyname2(x, AF_INET)
60 * Current Maximum Length for Screen Names (not including NULL)
65 * Current Maximum Length for Instant Messages
67 * This was found basically by experiment, but not wholly
68 * accurate experiment. It should not be regarded
69 * as completely correct. But its a decent approximation.
71 * Note that although we can send this much, its impossible
72 * for WinAIM clients (up through the latest (4.0.1957)) to
73 * send any more than 1kb. Amaze all your windows friends
74 * with utterly oversized instant messages!
77 #define MAXMSGLEN 7987
80 * Current Maximum Length for Chat Room Messages
82 * This is actually defined by the protocol to be
83 * dynamic, but I have yet to see due cause to
84 * define it dynamically here. Maybe later.
87 #define MAXCHATMSGLEN 512
90 * Standard size of an AIM authorization cookie
92 #define AIM_COOKIELEN 0x100
95 #define faimdprintf(l, x...) {if (l >= debug) printf(x); }
97 #define faimdprintf(l, x...)
101 * Login info. Passes information from the Authorization
102 * stage of login to the service (BOS, etc) connection
106 struct aim_login_struct {
107 char screen_name[MAXSNLEN+1];
109 char cookie[AIM_COOKIELEN];
117 * Client info. Filled in by the client and passed
118 * in to aim_login(). The information ends up
119 * getting passed to OSCAR through the initial
122 * XXX: Should this be per-session? -mid
125 struct client_info_s {
126 char clientstring[100]; /* arbitrary size */
140 * These could be arbitrary, but its easier to use the actual AIM values
142 #define AIM_CONN_TYPE_AUTH 0x0007
143 #define AIM_CONN_TYPE_ADS 0x0005
144 #define AIM_CONN_TYPE_BOS 0x0002
145 #define AIM_CONN_TYPE_CHAT 0x000e
146 #define AIM_CONN_TYPE_CHATNAV 0x000d
147 #define AIM_CONN_TYPE_RENDEZVOUS 0x0101 /* these do not speak OSCAR! */
150 * Status values returned from aim_conn_new(). ORed together.
152 #define AIM_CONN_STATUS_READY 0x0001
153 #define AIM_CONN_STATUS_INTERNALERR 0x0002
154 #define AIM_CONN_STATUS_RESOLVERR 0x0080
155 #define AIM_CONN_STATUS_CONNERR 0x0040
157 #define AIM_FRAMETYPE_OSCAR 0x0000
158 #define AIM_FRAMETYPE_OFT 0x0001
165 void *priv; /* misc data the client may want to store */
166 time_t lastactivity; /* time of last transmit */
168 struct aim_rxcblist_t *handlerlist;
169 faim_mutex_t active; /* lock around read/writes */
170 faim_mutex_t seqnum_lock; /* lock around ->seqnum changes */
171 struct aim_conn_t *next;
174 /* struct for incoming commands */
175 struct command_rx_struct {
176 unsigned char hdrtype; /* defines which piece of the union to use */
180 unsigned short seqnum;
184 unsigned short hdr2len;
185 unsigned char *hdr2; /* rest of bloated header */
188 unsigned short commandlen; /* total payload length */
189 unsigned char *data; /* packet data (from 7 byte on) */
190 unsigned char lock; /* 0 = open, !0 = locked */
191 unsigned char handled; /* 0 = new, !0 = been handled */
192 unsigned char nofree; /* 0 = free data on purge, 1 = only unlink */
193 struct aim_conn_t *conn; /* the connection it came in on... */
194 struct command_rx_struct *next; /* ptr to next struct in list */
197 /* struct for outgoing commands */
198 struct command_tx_struct {
199 unsigned char hdrtype; /* defines which piece of the union to use */
203 unsigned short seqnum;
207 unsigned short hdr2len;
213 u_int lock; /* 0 = open, !0 = locked */
214 u_int sent; /* 0 = pending, !0 = has been sent */
215 struct aim_conn_t *conn;
216 struct command_tx_struct *next; /* ptr to next struct in list */
221 * AIM Session: The main client-data interface.
224 struct aim_session_t {
226 /* ---- Client Accessible ------------------------ */
228 * Login information. See definition above.
231 struct aim_login_struct logininfo;
234 * Pointer to anything the client wants to
235 * explicitly associate with this session.
240 /* ---- Internal Use Only ------------------------ */
242 * Connection information
244 struct aim_conn_t *connlist;
245 faim_mutex_t connlistlock;
250 struct command_tx_struct *queue_outgoing;
251 struct command_rx_struct *queue_incoming;
254 * Tx Enqueuing function
256 int (*tx_enqueue)(struct aim_session_t *, struct command_tx_struct *);
259 * This is a dreadful solution to the what-room-are-we-joining
260 * problem. (There's no connection between the service
261 * request and the resulting redirect.)
266 * Outstanding snac handling
268 * XXX: Should these be per-connection? -mid
270 struct aim_snac_t *outstanding_snacs;
273 struct aim_msgcookie_t *msgcookies;
278 * AIM User Info, Standard Form.
280 struct aim_userinfo_s {
288 u_short capabilities;
291 #define AIM_CLASS_TRIAL 0x0001
292 #define AIM_CLASS_UNKNOWN2 0x0002
293 #define AIM_CLASS_AOL 0x0004
294 #define AIM_CLASS_UNKNOWN4 0x0008
295 #define AIM_CLASS_FREE 0x0010
296 #define AIM_CLASS_AWAY 0x0020
297 #define AIM_CLASS_UNKNOWN40 0x0040
298 #define AIM_CLASS_UNKNOWN80 0x0080
304 /* Generic TLV structure. */
312 struct aim_tlvlist_t {
313 struct aim_tlv_t *tlv;
314 struct aim_tlvlist_t *next;
317 /* TLV-handling functions */
318 struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
319 void aim_freetlvchain(struct aim_tlvlist_t **list);
320 struct aim_tlv_t *aim_grabtlv(u_char *src);
321 struct aim_tlv_t *aim_grabtlvstr(u_char *src);
322 struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
323 char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
324 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
325 struct aim_tlv_t *aim_createtlv(void);
326 int aim_freetlv(struct aim_tlv_t **oldtlv);
327 int aim_puttlv_16(u_char *, u_short, u_short);
328 int aim_puttlv_32(u_char *, u_short, u_long);
329 int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v);
330 int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list);
331 int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val);
332 int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val);
333 int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len);
334 int aim_counttlvchain(struct aim_tlvlist_t **list);
337 * Get command from connections / Dispatch commands
340 int aim_get_command(struct aim_session_t *, struct aim_conn_t *);
341 int aim_rxdispatch(struct aim_session_t *);
343 int aim_logoff(struct aim_session_t *);
345 void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn);
347 typedef int (*rxcallback_t)(struct aim_session_t *, struct command_rx_struct *, ...);
348 int aim_register_callbacks(rxcallback_t *);
350 u_long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype);
351 u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
352 u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
355 int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
356 int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
357 int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *);
358 int aim_encode_password(const char *, u_char *);
359 int aimicq_encode_password(const char *password, u_char *encoded);
360 unsigned long aim_sendauthresp(struct aim_session_t *sess,
361 struct aim_conn_t *conn,
362 char *sn, char *bosip,
363 char *cookie, char *email,
365 int aim_gencookie(unsigned char *buf);
366 int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn);
367 unsigned long aim_sendredirect(struct aim_session_t *sess,
368 struct aim_conn_t *conn,
369 unsigned short servid,
372 void aim_purge_rxqueue(struct aim_session_t *);
375 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
376 int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...);
377 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
380 struct command_tx_struct *aim_tx_new(unsigned short framing, int chan, struct aim_conn_t *conn, int datalen);
381 int aim_tx_enqueue__queuebased(struct aim_session_t *, struct command_tx_struct *);
382 int aim_tx_enqueue__immediate(struct aim_session_t *, struct command_tx_struct *);
383 #define aim_tx_enqueue(x, y) ((*(x->tx_enqueue))(x, y))
384 int aim_tx_sendframe(struct command_tx_struct *cur);
385 u_int aim_get_next_txseqnum(struct aim_conn_t *);
386 int aim_tx_flushqueue(struct aim_session_t *);
387 int aim_tx_printqueue(struct aim_session_t *);
388 void aim_tx_purgequeue(struct aim_session_t *);
390 struct aim_rxcblist_t {
393 rxcallback_t handler;
395 struct aim_rxcblist_t *next;
398 int aim_conn_setlatency(struct aim_conn_t *conn, int newval);
400 int aim_conn_addhandler(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short type, rxcallback_t newhandler, u_short flags);
401 rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
402 int aim_clearhandlers(struct aim_conn_t *conn);
405 * Generic SNAC structure. Rarely if ever used.
414 struct aim_snac_t *next;
416 u_long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac);
417 struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id);
418 int aim_cleansnacs(struct aim_session_t *, int maxage);
419 int aim_putsnac(u_char *, int, int, int, u_long);
422 void aim_connrst(struct aim_session_t *);
423 struct aim_conn_t *aim_conn_getnext(struct aim_session_t *);
424 void aim_conn_close(struct aim_conn_t *deadconn);
425 struct aim_conn_t *aim_getconn_type(struct aim_session_t *, int type);
426 struct aim_conn_t *aim_newconn(struct aim_session_t *, int type, char *dest);
427 int aim_conngetmaxfd(struct aim_session_t *);
428 struct aim_conn_t *aim_select(struct aim_session_t *, struct timeval *, int *);
429 int aim_conn_isready(struct aim_conn_t *);
430 int aim_conn_setstatus(struct aim_conn_t *, int);
431 void aim_session_init(struct aim_session_t *);
435 #define AIM_VISIBILITYCHANGE_PERMITADD 0x05
436 #define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06
437 #define AIM_VISIBILITYCHANGE_DENYADD 0x07
438 #define AIM_VISIBILITYCHANGE_DENYREMOVE 0x08
440 u_long aim_bos_nop(struct aim_session_t *, struct aim_conn_t *);
441 u_long aim_bos_setidle(struct aim_session_t *, struct aim_conn_t *, u_long);
442 u_long aim_bos_changevisibility(struct aim_session_t *, struct aim_conn_t *, int, char *);
443 u_long aim_bos_setbuddylist(struct aim_session_t *, struct aim_conn_t *, char *);
444 u_long aim_bos_setprofile(struct aim_session_t *, struct aim_conn_t *, char *, char *, unsigned int);
445 u_long aim_bos_setgroupperm(struct aim_session_t *, struct aim_conn_t *, u_long);
446 u_long aim_bos_clientready(struct aim_session_t *, struct aim_conn_t *);
447 u_long aim_bos_reqrate(struct aim_session_t *, struct aim_conn_t *);
448 u_long aim_bos_ackrateresp(struct aim_session_t *, struct aim_conn_t *);
449 u_long aim_bos_setprivacyflags(struct aim_session_t *, struct aim_conn_t *, u_long);
450 u_long aim_bos_reqpersonalinfo(struct aim_session_t *, struct aim_conn_t *);
451 u_long aim_bos_reqservice(struct aim_session_t *, struct aim_conn_t *, u_short);
452 u_long aim_bos_reqrights(struct aim_session_t *, struct aim_conn_t *);
453 u_long aim_bos_reqbuddyrights(struct aim_session_t *, struct aim_conn_t *);
454 u_long aim_bos_reqlocaterights(struct aim_session_t *, struct aim_conn_t *);
455 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *);
456 u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn);
458 /* aim_rxhandlers.c */
459 int aim_rxdispatch(struct aim_session_t *);
460 int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
461 int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...);
462 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...);
463 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
464 int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...);
465 int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
468 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
469 #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */
471 u_long aim_send_im(struct aim_session_t *, struct aim_conn_t *, char *, u_int, char *);
472 int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *);
473 u_long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn);
474 int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
475 int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command);
478 #define AIM_CAPS_BUDDYICON 0x01
479 #define AIM_CAPS_VOICE 0x02
480 #define AIM_CAPS_IMIMAGE 0x04
481 #define AIM_CAPS_CHAT 0x08
482 #define AIM_CAPS_GETFILE 0x10
483 #define AIM_CAPS_SENDFILE 0x20
485 extern u_char aim_caps[6][16];
486 u_short aim_getcap(unsigned char *capblock, int buflen);
487 int aim_putcap(unsigned char *capblock, int buflen, u_short caps);
489 #define AIM_GETINFO_GENERALINFO 0x00001
490 #define AIM_GETINFO_AWAYMESSAGE 0x00003
492 struct aim_msgcookie_t {
493 unsigned char cookie[8];
497 struct aim_msgcookie_t *next;
500 struct aim_filetransfer_t {
501 char sender[MAXSNLEN];
505 int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
506 struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie);
507 int aim_purgecookies(struct aim_session_t *sess);
509 #define AIM_TRANSFER_DENY_NOTSUPPORTED 0x0000
510 #define AIM_TRANSFER_DENY_DECLINE 0x0001
511 #define AIM_TRANSFER_DENY_NOTACCEPTING 0x0002
512 u_long aim_denytransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short code);
513 u_long aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short rendid);
515 u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short);
516 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
517 int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
518 int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);
519 int aim_parse_offgoing_middle(struct aim_session_t *, struct command_rx_struct *);
520 int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info);
521 int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info);
522 int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
526 int aim_auth_sendcookie(struct aim_session_t *, struct aim_conn_t *, u_char *);
527 u_long aim_auth_clientready(struct aim_session_t *, struct aim_conn_t *);
528 u_long aim_auth_changepasswd(struct aim_session_t *, struct aim_conn_t *, char *, char *);
530 /* aim_buddylist.c */
531 u_long aim_add_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
532 u_long aim_remove_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
535 u_long aim_usersearch_address(struct aim_session_t *, struct aim_conn_t *, char *);
536 /* u_long aim_usersearch_name(struct aim_session_t *, struct aim_conn_t *, char *); */
539 struct aim_chat_roominfo {
544 int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo);
545 int aim_chat_parse_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command);
546 int aim_chat_parse_joined(struct aim_session_t *sess, struct command_rx_struct *command);
547 int aim_chat_parse_leave(struct aim_session_t *sess, struct command_rx_struct *command);
548 int aim_chat_parse_incoming(struct aim_session_t *sess, struct command_rx_struct *command);
549 u_long aim_chat_send_im(struct aim_session_t *sess, struct aim_conn_t *conn, char *msg);
550 u_long aim_chat_join(struct aim_session_t *sess, struct aim_conn_t *conn, u_short exchange, const char *roomname);
551 u_long aim_chat_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
552 int aim_chat_attachname(struct aim_conn_t *conn, char *roomname);
553 char *aim_chat_getname(struct aim_conn_t *conn);
554 struct aim_conn_t *aim_chat_getconn(struct aim_session_t *, char *name);
556 u_long aim_chatnav_reqrights(struct aim_session_t *sess, struct aim_conn_t *conn);
557 u_long aim_chatnav_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
559 u_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);
561 struct aim_chat_exchangeinfo {
569 int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command);
570 u_long aim_chatnav_createroom(struct aim_session_t *sess, struct aim_conn_t *conn, char *name, u_short exchange);
571 int aim_chat_leaveroom(struct aim_session_t *sess, char *name);
574 #ifdef AIMUTIL_USEMACROS
576 * These are really ugly. You'd think this was LISP. I wish it was.
578 #define aimutil_put8(buf, data) ((*(buf) = (u_char)(data)&0xff),1)
579 #define aimutil_get8(buf) ((*(buf))&0xff)
580 #define aimutil_put16(buf, data) ( \
581 (*(buf) = (u_char)((data)>>8)&0xff), \
582 (*((buf)+1) = (u_char)(data)&0xff), \
584 #define aimutil_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
585 #define aimutil_put32(buf, data) ( \
586 (*((buf)) = (u_char)((data)>>24)&0xff), \
587 (*((buf)+1) = (u_char)((data)>>16)&0xff), \
588 (*((buf)+2) = (u_char)((data)>>8)&0xff), \
589 (*((buf)+3) = (u_char)(data)&0xff), \
591 #define aimutil_get32(buf) ((((*(buf))<<24)&0xff000000) + \
592 (((*((buf)+1))<<16)&0x00ff0000) + \
593 (((*((buf)+2))<< 8)&0x0000ff00) + \
594 (((*((buf)+3) )&0x000000ff)))
596 #warning Not using aimutil macros. May have performance problems.
597 int aimutil_put8(u_char *, u_char);
598 u_char aimutil_get8(u_char *buf);
599 int aimutil_put16(u_char *, u_short);
600 u_short aimutil_get16(u_char *);
601 int aimutil_put32(u_char *, u_long);
602 u_long aimutil_get32(u_char *);
605 int aimutil_putstr(u_char *, const u_char *, int);
606 int aimutil_tokslen(char *toSearch, int index, char dl);
607 int aimutil_itemcnt(char *toSearch, char dl);
608 char *aimutil_itemidx(char *toSearch, int index, char dl);
610 int aim_snlen(const char *sn);
611 int aim_sncmp(const char *sn1, const char *sn2);
614 char *aim_getbuilddate(void);
615 char *aim_getbuildtime(void);
616 char *aim_getbuildstring(void);
618 #endif /* __AIM_H__ */