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 * Login info. Passes information from the Authorization
55 * stage of login to the service (BOS, etc) connection
59 struct aim_login_struct {
60 char screen_name[MAXSNLEN+1];
62 char cookie[AIM_COOKIELEN];
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
75 * XXX: Should this be per-session? -mid
78 struct client_info_s {
79 char clientstring[100]; /* arbitrary size */
93 * These could be arbitrary, but its easier to use the actual AIM values
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
102 * Status values returned from aim_conn_new(). ORed together.
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
114 void *priv; /* misc data the client may want to store */
115 time_t lastactivity; /* time of last transmit */
117 struct aim_rxcblist_t *handlerlist;
120 /* struct for incoming commands */
121 struct 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 */
133 /* struct for outgoing commands */
134 struct 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 */
148 * AIM Session: The main client-data interface.
151 struct aim_session_t {
153 /* ---- Client Accessible ------------------------ */
155 * Login information. See definition above.
158 struct aim_login_struct logininfo;
161 * Pointer to anything the client wants to
162 * explicitly associate with this session.
167 /* ---- Internal Use Only ------------------------ */
169 * Connection information
171 struct aim_conn_t conns[AIM_CONN_MAX];
176 struct command_tx_struct *queue_outgoing;
177 struct command_rx_struct *queue_incoming;
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.)
187 * Outstanding snac handling
189 * XXX: Should these be per-connection? -mid
191 struct aim_snac_t *outstanding_snacs;
197 * AIM User Info, Standard Form.
199 struct aim_userinfo_s {
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
222 /* Generic TLV structure. */
230 struct aim_tlvlist_t {
231 struct aim_tlv_t *tlv;
232 struct aim_tlvlist_t *next;
235 /* TLV-handling functions */
236 struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
237 void aim_freetlvchain(struct aim_tlvlist_t **list);
238 struct aim_tlv_t *aim_grabtlv(u_char *src);
239 struct aim_tlv_t *aim_grabtlvstr(u_char *src);
240 struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
241 char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
242 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
243 struct aim_tlv_t *aim_createtlv(void);
244 int aim_freetlv(struct aim_tlv_t **oldtlv);
245 int aim_puttlv_16(u_char *, u_short, u_short);
246 int aim_puttlv_32(u_char *, u_short, u_long);
247 int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v);
251 * Get command from connections / Dispatch commands
254 int aim_get_command(struct aim_session_t *);
255 int aim_rxdispatch(struct aim_session_t *);
257 int aim_logoff(struct aim_session_t *);
260 typedef int (*rxcallback_t)(struct aim_session_t *, struct command_rx_struct *, ...);
261 int aim_register_callbacks(rxcallback_t *);
263 u_long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype);
264 u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
265 u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
268 int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
269 int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
270 int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *);
271 int aim_encode_password(const char *, u_char *);
274 struct command_rx_struct *aim_purge_rxqueue(struct command_rx_struct *queue);
277 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
278 int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...);
279 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
281 int aim_tx_enqueue(struct aim_session_t *, struct command_tx_struct *);
282 u_int aim_get_next_txseqnum(struct aim_conn_t *);
283 int aim_tx_flushqueue(struct aim_session_t *);
284 int aim_tx_printqueue(struct aim_session_t *);
285 int aim_tx_purgequeue(struct aim_session_t *);
287 struct aim_rxcblist_t {
290 rxcallback_t handler;
292 struct aim_rxcblist_t *next;
295 int aim_conn_setlatency(struct aim_conn_t *conn, int newval);
297 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);
298 rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
299 int aim_clearhandlers(struct aim_conn_t *conn);
302 * Generic SNAC structure. Rarely if ever used.
311 struct aim_snac_t *next;
313 u_long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac);
314 struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id);
315 int aim_cleansnacs(struct aim_session_t *, int maxage);
316 int aim_putsnac(u_char *, int, int, int, u_long);
319 void aim_connrst(struct aim_session_t *);
320 struct aim_conn_t *aim_conn_getnext(struct aim_session_t *);
321 void aim_conn_close(struct aim_conn_t *deadconn);
322 struct aim_conn_t *aim_getconn_type(struct aim_session_t *, int type);
323 struct aim_conn_t *aim_newconn(struct aim_session_t *, int type, char *dest);
324 int aim_conngetmaxfd(struct aim_session_t *);
325 struct aim_conn_t *aim_select(struct aim_session_t *, struct timeval *);
326 int aim_conn_isready(struct aim_conn_t *);
327 int aim_conn_setstatus(struct aim_conn_t *, int);
328 void aim_session_init(struct aim_session_t *);
332 #define AIM_VISIBILITYCHANGE_PERMITADD 0x05
333 #define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06
334 #define AIM_VISIBILITYCHANGE_DENYADD 0x07
335 #define AIM_VISIBILITYCHANGE_DENYREMOVE 0x08
337 u_long aim_bos_setidle(struct aim_session_t *, struct aim_conn_t *, u_long);
338 u_long aim_bos_changevisibility(struct aim_session_t *, struct aim_conn_t *, int, char *);
339 u_long aim_bos_setbuddylist(struct aim_session_t *, struct aim_conn_t *, char *);
340 u_long aim_bos_setprofile(struct aim_session_t *, struct aim_conn_t *, char *, char *);
341 u_long aim_bos_setgroupperm(struct aim_session_t *, struct aim_conn_t *, u_long);
342 u_long aim_bos_clientready(struct aim_session_t *, struct aim_conn_t *);
343 u_long aim_bos_reqrate(struct aim_session_t *, struct aim_conn_t *);
344 u_long aim_bos_ackrateresp(struct aim_session_t *, struct aim_conn_t *);
345 u_long aim_bos_setprivacyflags(struct aim_session_t *, struct aim_conn_t *, u_long);
346 u_long aim_bos_reqpersonalinfo(struct aim_session_t *, struct aim_conn_t *);
347 u_long aim_bos_reqservice(struct aim_session_t *, struct aim_conn_t *, u_short);
348 u_long aim_bos_reqrights(struct aim_session_t *, struct aim_conn_t *);
349 u_long aim_bos_reqbuddyrights(struct aim_session_t *, struct aim_conn_t *);
350 u_long aim_bos_reqlocaterights(struct aim_session_t *, struct aim_conn_t *);
351 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *);
352 u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn);
354 /* aim_rxhandlers.c */
355 int aim_rxdispatch(struct aim_session_t *);
356 int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
357 int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...);
358 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...);
359 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
360 int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...);
361 int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
364 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
365 #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */
367 u_long aim_send_im(struct aim_session_t *, struct aim_conn_t *, char *, u_int, char *);
368 int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *);
369 u_long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn);
370 int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
373 u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *);
374 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
375 int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
376 int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);
377 int aim_parse_offgoing_middle(struct aim_session_t *, struct command_rx_struct *);
380 int aim_auth_sendcookie(struct aim_session_t *, struct aim_conn_t *, u_char *);
381 u_long aim_auth_clientready(struct aim_session_t *, struct aim_conn_t *);
382 u_long aim_auth_changepasswd(struct aim_session_t *, struct aim_conn_t *, char *, char *);
384 /* aim_buddylist.c */
385 u_long aim_add_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
386 u_long aim_remove_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
389 u_long aim_usersearch_address(struct aim_session_t *, struct aim_conn_t *, char *);
390 /* u_long aim_usersearch_name(struct aim_session_t *, struct aim_conn_t *, char *); */
393 struct aim_chat_roominfo {
398 int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo);
399 int aim_chat_parse_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command);
400 int aim_chat_parse_joined(struct aim_session_t *sess, struct command_rx_struct *command);
401 int aim_chat_parse_leave(struct aim_session_t *sess, struct command_rx_struct *command);
402 int aim_chat_parse_incoming(struct aim_session_t *sess, struct command_rx_struct *command);
403 u_long aim_chat_send_im(struct aim_session_t *sess, struct aim_conn_t *conn, char *msg);
404 u_long aim_chat_join(struct aim_session_t *sess, struct aim_conn_t *conn, u_short exchange, const char *roomname);
405 u_long aim_chat_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
406 int aim_chat_attachname(struct aim_conn_t *conn, char *roomname);
407 char *aim_chat_getname(struct aim_conn_t *conn);
408 struct aim_conn_t *aim_chat_getconn(struct aim_session_t *, char *name);
410 u_long aim_chatnav_reqrights(struct aim_session_t *sess, struct aim_conn_t *conn);
411 u_long aim_chatnav_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
413 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);
415 struct aim_chat_exchangeinfo {
423 int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command);
424 u_long aim_chatnav_createroom(struct aim_session_t *sess, struct aim_conn_t *conn, char *name, u_short exchange);
425 int aim_chat_leaveroom(struct aim_session_t *sess, char *name);
428 int aimutil_put8(u_char *, u_char);
429 u_char aimutil_get8(u_char *buf);
430 int aimutil_put16(u_char *, u_short);
431 u_short aimutil_get16(u_char *);
432 int aimutil_put32(u_char *, u_long);
433 u_long aimutil_get32(u_char *);
434 int aimutil_putstr(u_char *, const u_char *, int);
435 int aimutil_tokslen(char *toSearch, int index, char dl);
436 int aimutil_itemcnt(char *toSearch, char dl);
437 char *aimutil_itemidx(char *toSearch, int index, char dl);
439 #endif /* __AIM_H__ */