2 * Main libfaim header. Must be included in client for prototypes/macros.
9 #include <faim/faimconfig.h>
10 #include <faim/aim_cbtypes.h>
15 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
32 /* Portability stuff (DMP) */
36 #define strlen(x) (int)strlen(x) /* win32 has a unsigned size_t */
39 #if defined(_WIN32) || (defined(mach) && defined(__APPLE__))
40 #define gethostbyname2(x,y) gethostbyname(x) /* revert to IPv4 */
44 * Current Maximum Length for Screen Names (not including NULL)
49 * Standard size of an AIM authorization cookie
51 #define AIM_COOKIELEN 0x100
54 #define faimdprintf(l, x...) {if (l >= debug) printf(x); }
56 #define faimdprintf(l, x...)
60 * Login info. Passes information from the Authorization
61 * stage of login to the service (BOS, etc) connection
65 struct aim_login_struct {
66 char screen_name[MAXSNLEN+1];
68 char cookie[AIM_COOKIELEN];
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
81 * XXX: Should this be per-session? -mid
84 struct client_info_s {
85 char clientstring[100]; /* arbitrary size */
99 * These could be arbitrary, but its easier to use the actual AIM values
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
108 * Status values returned from aim_conn_new(). ORed together.
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
120 void *priv; /* misc data the client may want to store */
121 time_t lastactivity; /* time of last transmit */
123 struct aim_rxcblist_t *handlerlist;
126 /* struct for incoming commands */
127 struct 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 */
135 u_int nofree; /* 0 = free data on purge, 1 = only unlink */
136 struct aim_conn_t *conn; /* the connection it came in on... */
137 struct command_rx_struct *next; /* ptr to next struct in list */
140 /* struct for outgoing commands */
141 struct 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 */
155 * AIM Session: The main client-data interface.
158 struct aim_session_t {
160 /* ---- Client Accessible ------------------------ */
162 * Login information. See definition above.
165 struct aim_login_struct logininfo;
168 * Pointer to anything the client wants to
169 * explicitly associate with this session.
174 /* ---- Internal Use Only ------------------------ */
176 * Connection information
178 struct aim_conn_t conns[AIM_CONN_MAX];
183 struct command_tx_struct *queue_outgoing;
184 struct command_rx_struct *queue_incoming;
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.)
194 * Outstanding snac handling
196 * XXX: Should these be per-connection? -mid
198 struct aim_snac_t *outstanding_snacs;
204 * AIM User Info, Standard Form.
206 struct aim_userinfo_s {
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
229 /* Generic TLV structure. */
237 struct aim_tlvlist_t {
238 struct aim_tlv_t *tlv;
239 struct aim_tlvlist_t *next;
242 /* TLV-handling functions */
243 struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
244 void aim_freetlvchain(struct aim_tlvlist_t **list);
245 struct aim_tlv_t *aim_grabtlv(u_char *src);
246 struct aim_tlv_t *aim_grabtlvstr(u_char *src);
247 struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
248 char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
249 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
250 struct aim_tlv_t *aim_createtlv(void);
251 int aim_freetlv(struct aim_tlv_t **oldtlv);
252 int aim_puttlv_16(u_char *, u_short, u_short);
253 int aim_puttlv_32(u_char *, u_short, u_long);
254 int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v);
255 int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list);
256 int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val);
257 int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val);
258 int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len);
259 int aim_counttlvchain(struct aim_tlvlist_t **list);
262 * Get command from connections / Dispatch commands
265 int aim_get_command(struct aim_session_t *, struct aim_conn_t *);
266 int aim_rxdispatch(struct aim_session_t *);
268 int aim_logoff(struct aim_session_t *);
271 typedef int (*rxcallback_t)(struct aim_session_t *, struct command_rx_struct *, ...);
272 int aim_register_callbacks(rxcallback_t *);
274 u_long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype);
275 u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
276 u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
279 int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
280 int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
281 int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *);
282 int aim_encode_password(const char *, u_char *);
283 unsigned long aim_sendauthresp(struct aim_session_t *sess,
284 struct aim_conn_t *conn,
285 char *sn, char *bosip,
286 char *cookie, char *email,
288 int aim_gencookie(unsigned char *buf);
289 int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn);
290 unsigned long aim_sendredirect(struct aim_session_t *sess,
291 struct aim_conn_t *conn,
292 unsigned short servid,
295 void aim_purge_rxqueue(struct aim_session_t *);
298 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
299 int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...);
300 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
302 struct command_tx_struct *aim_tx_new(void);
303 int aim_tx_enqueue(struct aim_session_t *, struct command_tx_struct *);
304 u_int aim_get_next_txseqnum(struct aim_conn_t *);
305 int aim_tx_flushqueue(struct aim_session_t *);
306 int aim_tx_printqueue(struct aim_session_t *);
307 void aim_tx_purgequeue(struct aim_session_t *);
309 struct aim_rxcblist_t {
312 rxcallback_t handler;
314 struct aim_rxcblist_t *next;
317 int aim_conn_setlatency(struct aim_conn_t *conn, int newval);
319 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);
320 rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
321 int aim_clearhandlers(struct aim_conn_t *conn);
324 * Generic SNAC structure. Rarely if ever used.
333 struct aim_snac_t *next;
335 u_long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac);
336 struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id);
337 int aim_cleansnacs(struct aim_session_t *, int maxage);
338 int aim_putsnac(u_char *, int, int, int, u_long);
341 void aim_connrst(struct aim_session_t *);
342 struct aim_conn_t *aim_conn_getnext(struct aim_session_t *);
343 void aim_conn_close(struct aim_conn_t *deadconn);
344 struct aim_conn_t *aim_getconn_type(struct aim_session_t *, int type);
345 struct aim_conn_t *aim_newconn(struct aim_session_t *, int type, char *dest);
346 int aim_conngetmaxfd(struct aim_session_t *);
347 struct aim_conn_t *aim_select(struct aim_session_t *, struct timeval *, int *);
348 int aim_conn_isready(struct aim_conn_t *);
349 int aim_conn_setstatus(struct aim_conn_t *, int);
350 void aim_session_init(struct aim_session_t *);
354 #define AIM_VISIBILITYCHANGE_PERMITADD 0x05
355 #define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06
356 #define AIM_VISIBILITYCHANGE_DENYADD 0x07
357 #define AIM_VISIBILITYCHANGE_DENYREMOVE 0x08
359 u_long aim_bos_setidle(struct aim_session_t *, struct aim_conn_t *, u_long);
360 u_long aim_bos_changevisibility(struct aim_session_t *, struct aim_conn_t *, int, char *);
361 u_long aim_bos_setbuddylist(struct aim_session_t *, struct aim_conn_t *, char *);
362 u_long aim_bos_setprofile(struct aim_session_t *, struct aim_conn_t *, char *, char *);
363 u_long aim_bos_setgroupperm(struct aim_session_t *, struct aim_conn_t *, u_long);
364 u_long aim_bos_clientready(struct aim_session_t *, struct aim_conn_t *);
365 u_long aim_bos_reqrate(struct aim_session_t *, struct aim_conn_t *);
366 u_long aim_bos_ackrateresp(struct aim_session_t *, struct aim_conn_t *);
367 u_long aim_bos_setprivacyflags(struct aim_session_t *, struct aim_conn_t *, u_long);
368 u_long aim_bos_reqpersonalinfo(struct aim_session_t *, struct aim_conn_t *);
369 u_long aim_bos_reqservice(struct aim_session_t *, struct aim_conn_t *, u_short);
370 u_long aim_bos_reqrights(struct aim_session_t *, struct aim_conn_t *);
371 u_long aim_bos_reqbuddyrights(struct aim_session_t *, struct aim_conn_t *);
372 u_long aim_bos_reqlocaterights(struct aim_session_t *, struct aim_conn_t *);
373 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *);
374 u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn);
376 /* aim_rxhandlers.c */
377 int aim_rxdispatch(struct aim_session_t *);
378 int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
379 int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...);
380 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...);
381 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
382 int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...);
383 int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
386 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
387 #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */
389 u_long aim_send_im(struct aim_session_t *, struct aim_conn_t *, char *, u_int, char *);
390 int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *);
391 u_long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn);
392 int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
395 u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *);
396 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
397 int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
398 int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);
399 int aim_parse_offgoing_middle(struct aim_session_t *, struct command_rx_struct *);
400 int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info);
401 int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info);
402 int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
406 int aim_auth_sendcookie(struct aim_session_t *, struct aim_conn_t *, u_char *);
407 u_long aim_auth_clientready(struct aim_session_t *, struct aim_conn_t *);
408 u_long aim_auth_changepasswd(struct aim_session_t *, struct aim_conn_t *, char *, char *);
410 /* aim_buddylist.c */
411 u_long aim_add_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
412 u_long aim_remove_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
415 u_long aim_usersearch_address(struct aim_session_t *, struct aim_conn_t *, char *);
416 /* u_long aim_usersearch_name(struct aim_session_t *, struct aim_conn_t *, char *); */
419 struct aim_chat_roominfo {
424 int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo);
425 int aim_chat_parse_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command);
426 int aim_chat_parse_joined(struct aim_session_t *sess, struct command_rx_struct *command);
427 int aim_chat_parse_leave(struct aim_session_t *sess, struct command_rx_struct *command);
428 int aim_chat_parse_incoming(struct aim_session_t *sess, struct command_rx_struct *command);
429 u_long aim_chat_send_im(struct aim_session_t *sess, struct aim_conn_t *conn, char *msg);
430 u_long aim_chat_join(struct aim_session_t *sess, struct aim_conn_t *conn, u_short exchange, const char *roomname);
431 u_long aim_chat_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
432 int aim_chat_attachname(struct aim_conn_t *conn, char *roomname);
433 char *aim_chat_getname(struct aim_conn_t *conn);
434 struct aim_conn_t *aim_chat_getconn(struct aim_session_t *, char *name);
436 u_long aim_chatnav_reqrights(struct aim_session_t *sess, struct aim_conn_t *conn);
437 u_long aim_chatnav_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
439 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);
441 struct aim_chat_exchangeinfo {
449 int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command);
450 u_long aim_chatnav_createroom(struct aim_session_t *sess, struct aim_conn_t *conn, char *name, u_short exchange);
451 int aim_chat_leaveroom(struct aim_session_t *sess, char *name);
454 #ifdef AIMUTIL_USEMACROS
456 * These are really ugly. You'd think this was LISP. I wish it was.
458 #define aimutil_put8(buf, data) ((*(buf) = (u_char)(data)&0xff),1)
459 #define aimutil_get8(buf) ((*(buf))&0xff)
460 #define aimutil_put16(buf, data) ( \
461 (*(buf) = (u_char)((data)>>8)&0xff), \
462 (*((buf)+1) = (u_char)(data)&0xff), \
464 #define aimutil_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
465 #define aimutil_put32(buf, data) ( \
466 (*((buf)) = (u_char)((data)>>24)&0xff), \
467 (*((buf)+1) = (u_char)((data)>>16)&0xff), \
468 (*((buf)+2) = (u_char)((data)>>8)&0xff), \
469 (*((buf)+3) = (u_char)(data)&0xff), \
471 #define aimutil_get32(buf) ((((*(buf))<<24)&0xff000000) + \
472 (((*((buf)+1))<<16)&0x00ff0000) + \
473 (((*((buf)+2))<< 8)&0x0000ff00) + \
474 (((*((buf)+3) )&0x000000ff)))
476 #warning Not using aimutil macros. May have performance problems.
477 int aimutil_put8(u_char *, u_char);
478 u_char aimutil_get8(u_char *buf);
479 int aimutil_put16(u_char *, u_short);
480 u_short aimutil_get16(u_char *);
481 int aimutil_put32(u_char *, u_long);
482 u_long aimutil_get32(u_char *);
485 int aimutil_putstr(u_char *, const u_char *, int);
486 int aimutil_tokslen(char *toSearch, int index, char dl);
487 int aimutil_itemcnt(char *toSearch, char dl);
488 char *aimutil_itemidx(char *toSearch, int index, char dl);
490 int aim_snlen(const char *sn);
491 int aim_sncmp(const char *sn1, const char *sn2);
493 #endif /* __AIM_H__ */