2 * Main libfaim header. Must be included in client for prototypes/macros.
9 #include <faimconfig.h>
10 #include <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 */
46 #define AIM_CONNECT_ERROR -0x1
47 #define AIM_SIGNON_TOO_SOON -0x4
48 #define AIM_SERVICE_FULL -0x6f
51 * Current Maximum Length for Screen Names (not including NULL)
55 struct login_phase1_struct {
63 extern struct login_phase1_struct aim_logininfo;
65 struct client_info_s {
66 char clientstring[100]; /* arbitrary number */
80 * These could be arbitrary, but its easier to use the actual AIM values
82 #define AIM_CONN_TYPE_AUTH 0x0007
83 #define AIM_CONN_TYPE_ADS 0x0005
84 #define AIM_CONN_TYPE_BOS 2
85 #define AIM_CONN_TYPE_CHAT 0x000e
86 #define AIM_CONN_TYPE_CHATNAV 0x000d
88 #define AIM_CONN_STATUS_READY 0x0001
89 #define AIM_CONN_STATUS_INTERNALERR 0x0002
90 #define AIM_CONN_STATUS_RESOLVERR 0x80
91 #define AIM_CONN_STATUS_CONNERR 0x40
98 void *priv; /* misc data the client may want to store */
99 time_t lastactivity; /* time of last transmit */
101 struct aim_rxcblist_t *handlerlist;
103 struct aim_conn_t aim_conns[AIM_CONN_MAX];
106 /* struct for incoming commands */
107 struct command_rx_struct {
108 /* byte 1 assumed to always be 0x2a */
109 char type; /* type code (byte 2) */
110 u_int seqnum; /* sequence number (bytes 3 and 4) */
111 u_int commandlen; /* total packet len - 6 (bytes 5 and 6) */
112 u_char *data; /* packet data (from 7 byte on) */
113 u_int lock; /* 0 = open, !0 = locked */
114 u_int handled; /* 0 = new, !0 = been handled */
115 struct aim_conn_t *conn; /* the connection it came in on... */
116 struct command_rx_struct *next; /* ptr to next struct in list */
119 /* struct for outgoing commands */
120 struct command_tx_struct {
121 /* byte 1 assumed to be 0x2a */
122 char type; /* type/family code */
123 u_int seqnum; /* seqnum dynamically assigned on tx */
124 u_int commandlen; /* SNAC length */
125 u_char *data; /* packet data */
126 u_int lock; /* 0 = open, !0 = locked */
127 u_int sent; /* 0 = pending, !0 = has been sent */
128 struct aim_conn_t *conn;
129 struct command_tx_struct *next; /* ptr to next struct in list */
133 * AIM User Info, Standard Form.
135 struct aim_userinfo_s {
149 /* Generic TLV structure. */
157 struct aim_tlvlist_t {
158 struct aim_tlv_t *tlv;
159 struct aim_tlvlist_t *next;
162 /* TLV-handling functions */
163 struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
164 void aim_freetlvchain(struct aim_tlvlist_t **list);
165 struct aim_tlv_t *aim_grabtlv(u_char *src);
166 struct aim_tlv_t *aim_grabtlvstr(u_char *src);
167 struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
168 char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
169 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
170 struct aim_tlv_t *aim_createtlv(void);
171 int aim_freetlv(struct aim_tlv_t **oldtlv);
172 int aim_puttlv_16(u_char *, u_short, u_short);
175 int aim_get_command(void);
176 int aim_rxdispatch(void);
177 int aim_logoff(void);
179 typedef int (*rxcallback_t)(struct command_rx_struct *, ...);
180 int aim_register_callbacks(rxcallback_t *);
182 u_long aim_genericreq_n(struct aim_conn_t *conn, u_short family, u_short subtype);
183 u_long aim_genericreq_l(struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
184 u_long aim_genericreq_s(struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
187 int aim_send_login (struct aim_conn_t *, char *, char *, struct client_info_s *);
188 int aim_encode_password(const char *, char *);
191 struct command_rx_struct *aim_purge_rxqueue(struct command_rx_struct *queue);
194 int aim_parse_unknown(struct command_rx_struct *command, ...);
195 int aim_parse_missed_im(struct command_rx_struct *, ...);
196 int aim_parse_last_bad(struct command_rx_struct *, ...);
198 int aim_tx_enqueue(struct command_tx_struct *);
199 u_int aim_get_next_txseqnum(struct aim_conn_t *);
200 int aim_tx_flushqueue(void);
201 int aim_tx_printqueue(void);
202 int aim_tx_purgequeue(void);
204 /* queue (linked list) pointers */
205 extern struct command_tx_struct *aim_queue_outgoing; /* incoming commands */
206 extern struct command_rx_struct *aim_queue_incoming; /* outgoing commands */
208 /* The default callback handler array */
209 extern rxcallback_t aim_callbacks[];
211 struct aim_rxcblist_t {
214 rxcallback_t handler;
216 struct aim_rxcblist_t *next;
219 int aim_conn_setlatency(struct aim_conn_t *conn, int newval);
221 int aim_conn_addhandler(struct aim_conn_t *conn, u_short family, u_short type, rxcallback_t newhandler, u_short flags);
222 rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
223 int aim_clearhandlers(struct aim_conn_t *conn);
225 extern struct aim_snac_t *aim_outstanding_snacs;
226 extern u_long aim_snac_nextid;
229 * Generic SNAC structure. Rarely if ever used.
238 struct aim_snac_t *next;
240 u_long aim_newsnac(struct aim_snac_t *newsnac);
241 struct aim_snac_t *aim_remsnac(u_long id);
242 int aim_cleansnacs(int maxage);
243 int aim_putsnac(u_char *, int, int, int, u_long);
246 void aim_connrst(void);
247 struct aim_conn_t *aim_conn_getnext(void);
248 void aim_conn_close(struct aim_conn_t *deadconn);
249 struct aim_conn_t *aim_getconn_type(int type);
250 struct aim_conn_t *aim_newconn(int type, char *dest);
251 int aim_conngetmaxfd(void);
252 struct aim_conn_t *aim_select(struct timeval *);
253 int aim_conn_isready(struct aim_conn_t *);
254 int aim_conn_setstatus(struct aim_conn_t *, int);
258 #define AIM_VISIBILITYCHANGE_PERMITADD 0x05
259 #define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06
260 #define AIM_VISIBILITYCHANGE_DENYADD 0x07
261 #define AIM_VISIBILITYCHANGE_DENYREMOVE 0x08
263 u_long aim_bos_setidle(struct aim_conn_t *, u_long);
264 u_long aim_bos_changevisibility(struct aim_conn_t *, int, char *);
265 u_long aim_bos_setbuddylist(struct aim_conn_t *, char *);
266 u_long aim_bos_setprofile(struct aim_conn_t *, char *);
267 u_long aim_bos_setgroupperm(struct aim_conn_t *, u_long);
268 u_long aim_bos_clientready(struct aim_conn_t *);
269 u_long aim_bos_reqrate(struct aim_conn_t *);
270 u_long aim_bos_ackrateresp(struct aim_conn_t *);
271 u_long aim_bos_setprivacyflags(struct aim_conn_t *, u_long);
272 u_long aim_bos_reqpersonalinfo(struct aim_conn_t *);
273 u_long aim_bos_reqservice(struct aim_conn_t *, u_short);
274 u_long aim_bos_reqrights(struct aim_conn_t *);
275 u_long aim_bos_reqbuddyrights(struct aim_conn_t *);
276 u_long aim_bos_reqlocaterights(struct aim_conn_t *);
277 u_long aim_bos_reqicbmparaminfo(struct aim_conn_t *);
279 /* aim_rxhandlers.c */
280 int aim_register_callbacks(rxcallback_t *);
281 int aim_rxdispatch(void);
282 int aim_authparse(struct command_rx_struct *);
283 int aim_handleredirect_middle(struct command_rx_struct *, ...);
284 int aim_parse_unknown(struct command_rx_struct *, ...);
285 int aim_parse_missed_im(struct command_rx_struct *, ...);
286 int aim_parse_last_bad(struct command_rx_struct *, ...);
287 int aim_parse_generalerrs(struct command_rx_struct *command, ...);
290 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
291 #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */
292 u_long aim_send_im(struct aim_conn_t *, char *, int, char *);
293 int aim_parse_incoming_im_middle(struct command_rx_struct *);
294 u_long aim_seticbmparam(struct aim_conn_t *conn);
297 u_long aim_getinfo(struct aim_conn_t *, const char *);
298 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
299 int aim_parse_userinfo_middle(struct command_rx_struct *);
300 int aim_parse_oncoming_middle(struct command_rx_struct *);
303 int aim_auth_sendcookie(struct aim_conn_t *, char *);
304 u_long aim_auth_clientready(struct aim_conn_t *);
305 u_long aim_auth_changepasswd(struct aim_conn_t *, char *, char *);
307 /* aim_buddylist.c */
308 u_long aim_add_buddy(struct aim_conn_t *, char *);
309 u_long aim_remove_buddy(struct aim_conn_t *, char *);
312 u_long aim_usersearch_address(struct aim_conn_t *, char *);
313 /* u_long aim_usersearch_name(struct aim_conn_t *, char *); */
316 int aimutil_put8(u_char *, u_char);
317 u_char aimutil_get8(u_char *buf);
318 int aimutil_put16(u_char *, u_short);
319 u_short aimutil_get16(u_char *);
320 int aimutil_put32(u_char *, u_long);
321 u_long aimutil_get32(u_char *);
322 int aimutil_putstr(u_char *, const u_char *, int);
323 int aimutil_tokslen(char *toSearch, int index, char dl);
324 int aimutil_itemcnt(char *toSearch, char dl);
325 char *aimutil_itemidx(char *toSearch, int index, char dl);
327 #endif /* __AIM_H__ */