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