Sun, 30 Apr 2000 21:47:04 +0000
[gaim-migrate @ 210]
Made the receive non-blocking, added a cancel button, and a few other updates.
No, sending a file to someone does not work yet. Be patient.
| 2 | 1 | #ifndef __AIM_H__ |
| 2 | #define __AIM_H__ | |
| 3 | ||
| 4 | #include <faimconfig.h> | |
| 5 | ||
| 6 | /* some global includes */ | |
| 7 | #include <stdio.h> | |
| 8 | #include <string.h> | |
| 9 | #include <fcntl.h> | |
| 10 | #include <netdb.h> | |
| 11 | #include <sys/types.h> | |
| 12 | #include <sys/socket.h> | |
| 13 | #include <netinet/in.h> | |
| 14 | #include <sys/time.h> | |
| 15 | #include <unistd.h> | |
| 16 | #include <stdlib.h> | |
| 17 | #include <stdarg.h> | |
| 18 | #include <errno.h> | |
| 19 | ||
| 20 | #define CONNECT_SIG_LEN 10 /* not used anymore, hopefully */ | |
| 21 | #define LOGIN_RESP_LEN 512 /* should only be 334b but no segfault for us! */ | |
| 22 | ||
| 23 | ||
| 24 | /* | |
| 25 | * Error codes | |
| 26 | */ | |
| 27 | #define AIM_CONNECT_ERROR -0x1 | |
| 28 | #define AIM_SIGNON_TOO_SOON -0x4 | |
| 29 | #define AIM_SERVICE_FULL -0x6f | |
| 30 | ||
| 31 | ||
| 32 | struct login_phase1_struct { | |
| 33 | char *screen_name; | |
| 34 | char *BOSIP; | |
| 35 | char *cookie; | |
| 36 | char *email; | |
| 37 | ushort regstatus; | |
| 38 | }; | |
| 39 | ||
| 40 | extern struct login_phase1_struct aim_logininfo; | |
| 41 | ||
| 42 | struct client_info_s { | |
| 43 | char clientstring[100]; /* arbitrary number */ | |
| 44 | int major; | |
| 45 | int minor; | |
| 46 | int build; | |
| 47 | char country[3]; | |
| 48 | char lang[3]; | |
| 49 | }; | |
| 50 | ||
| 51 | struct connection_info_struct { | |
| 52 | unsigned int local_seq_num_origin; /* our first seq num */ | |
| 53 | int local_command_count; | |
| 54 | ||
| 55 | unsigned int remote_seq_num_origin; /* oscar's first seqnum */ | |
| 56 | int remote_command_count; /* command_count + seq_num_origin = cur_seq_num */ | |
| 57 | ||
| 58 | char *sn; /* our screen name */ | |
| 59 | ||
| 60 | int fd; /* socket descriptor */ | |
| 61 | }; | |
| 62 | ||
| 63 | #ifndef TRUE | |
| 64 | #define TRUE 1 | |
| 65 | #define FALSE 0 | |
| 66 | #endif | |
| 67 | ||
| 68 | #define AIM_CONN_MAX 5 | |
| 69 | /* these could be arbitrary, but its easier to use the actual AIM values */ | |
| 70 | #define AIM_CONN_TYPE_AUTH 0x0007 | |
| 71 | #define AIM_CONN_TYPE_ADS 0x0005 | |
| 72 | #define AIM_CONN_TYPE_BOS 2 | |
| 73 | #define AIM_CONN_TYPE_CHAT 0x000e | |
| 74 | #define AIM_CONN_TYPE_CHATNAV 0x000d | |
| 75 | ||
| 76 | #define AIM_CONN_STATUS_READY 0x0001 | |
| 77 | #define AIM_CONN_STATUS_INTERNALERR 0x0002 | |
| 78 | #define AIM_CONN_STATUS_RESOLVERR 0x80 | |
| 79 | #define AIM_CONN_STATUS_CONNERR 0x40 | |
| 80 | ||
| 81 | ||
| 82 | struct aim_conn_t { | |
| 83 | int fd; | |
| 84 | int type; | |
| 85 | int seqnum; | |
| 86 | int status; | |
| 87 | }; | |
| 88 | struct aim_conn_t aim_conns[AIM_CONN_MAX]; | |
| 89 | ||
| 90 | ||
| 91 | /* struct for incoming commands */ | |
| 92 | struct command_rx_struct { | |
| 93 | /* byte 1 assumed to always be 0x2a */ | |
| 94 | char type; /* type code (byte 2) */ | |
| 95 | unsigned int seqnum; /* sequence number (bytes 3 and 4) */ | |
| 96 | unsigned int commandlen; /* total packet len - 6 (bytes 5 and 6) */ | |
| 97 | char *data; /* packet data (from 7 byte on) */ | |
| 98 | unsigned int lock; /* 1 = locked, 0 = open */ | |
| 99 | unsigned int handled; /* 1 = been handled, 0 = new */ | |
| 100 | struct aim_conn_t *conn; /* the connection it came in on... */ | |
| 101 | struct command_rx_struct *next; /* ptr to next struct in list */ | |
| 102 | }; | |
| 103 | ||
| 104 | /* struct for outgoing commands */ | |
| 105 | struct command_tx_struct { | |
| 106 | /* byte 1 assumed to be 0x2a */ | |
| 107 | char type; /* type/family code */ | |
| 108 | unsigned int seqnum; /* seqnum dynamically assigned on tx */ | |
| 109 | unsigned int commandlen; /* SNAC length */ | |
| 110 | char *data; /* packet data */ | |
| 111 | unsigned int lock; /* 1 = locked, 0 = open */ | |
| 112 | unsigned int sent; /* 1 = has been sent, 0 = new */ | |
| 113 | struct aim_conn_t *conn; | |
| 114 | struct command_tx_struct *next; /* ptr to next struct in list */ | |
| 115 | }; | |
| 116 | ||
| 117 | /* TLV-related tidbits */ | |
| 118 | struct aim_tlv_t { | |
| 119 | u_short type; | |
| 120 | u_short length; | |
| 121 | u_char *value; | |
| 122 | }; | |
| 123 | ||
| 124 | struct aim_tlv_t *aim_grabtlv(u_char *src); | |
| 125 | struct aim_tlv_t *aim_grabtlvstr(u_char *src); | |
| 126 | int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv); | |
| 127 | struct aim_tlv_t *aim_createtlv(void); | |
| 128 | int aim_freetlv(struct aim_tlv_t **oldtlv); | |
| 129 | int aim_puttlv_16(u_char *, u_short, u_short); | |
| 130 | ||
| 131 | /* some prototypes... */ | |
| 132 | ||
| 133 | /* implicitly or explicitly called */ | |
| 134 | int aim_get_command(void); | |
| 135 | int aim_rxdispatch(void); | |
| 136 | int aim_logoff(void); | |
| 137 | ||
| 138 | typedef int (*rxcallback_t)(struct command_rx_struct *, ...); | |
| 139 | int aim_register_callbacks(rxcallback_t *); | |
| 140 | ||
| 141 | u_long aim_genericreq_n(struct aim_conn_t *conn, u_short family, u_short subtype); | |
| 142 | u_long aim_genericreq_l(struct aim_conn_t *conn, u_short family, u_short subtype, u_long *); | |
| 143 | u_long aim_genericreq_s(struct aim_conn_t *conn, u_short family, u_short subtype, u_short *); | |
| 144 | ||
| 145 | /* aim_login.c */ | |
| 146 | int aim_send_login (struct aim_conn_t *, char *, char *, struct client_info_s *); | |
| 147 | int aim_encode_password(const char *, char *); | |
| 148 | ||
| 149 | ||
| 150 | struct command_rx_struct *aim_purge_rxqueue(struct command_rx_struct *queue); | |
| 151 | ||
| 152 | ||
| 153 | int aim_parse_unknown(struct command_rx_struct *command, ...); | |
| 154 | int aim_parse_missed_im(struct command_rx_struct *, ...); | |
| 155 | int aim_parse_last_bad(struct command_rx_struct *, ...); | |
| 156 | ||
| 157 | int aim_tx_enqueue(struct command_tx_struct *); | |
| 158 | unsigned int aim_get_next_txseqnum(struct aim_conn_t *); | |
| 159 | int aim_tx_flushqueue(void); | |
| 160 | int aim_tx_printqueue(void); | |
| 161 | int aim_tx_purgequeue(void); | |
| 162 | ||
| 163 | /* queue (linked list) pointers */ | |
| 164 | extern struct command_tx_struct *aim_queue_outgoing; /* incoming commands */ | |
| 165 | extern struct command_rx_struct *aim_queue_incoming; /* outgoing commands */ | |
| 166 | ||
| 167 | /* The default callback handler array */ | |
| 168 | extern rxcallback_t aim_callbacks[]; | |
| 169 | ||
| 170 | extern struct aim_snac_t *aim_outstanding_snacs; | |
| 171 | extern u_long aim_snac_nextid; | |
| 172 | ||
| 173 | #define AIM_CB_INCOMING_IM 0 | |
| 174 | #define AIM_CB_ONCOMING_BUDDY 1 | |
| 175 | #define AIM_CB_OFFGOING_BUDDY 2 | |
| 176 | #define AIM_CB_MISSED_IM 3 | |
| 177 | #define AIM_CB_MISSED_CALL 4 | |
| 178 | #define AIM_CB_LOGIN_P4_C1 5 | |
| 179 | #define AIM_CB_LOGIN_P4_C2 6 | |
| 180 | #define AIM_CB_LOGIN_P2_1 7 | |
| 181 | #define AIM_CB_LOGIN_P2_2 8 | |
| 182 | #define AIM_CB_LOGIN_P3_B 9 | |
| 183 | #define AIM_CB_LOGIN_P3D_A 10 | |
| 184 | #define AIM_CB_LOGIN_P3D_B 11 | |
| 185 | #define AIM_CB_LOGIN_P3D_C 12 | |
| 186 | #define AIM_CB_LOGIN_P3D_D 13 | |
| 187 | #define AIM_CB_LOGIN_P3D_E 14 | |
| 188 | #define AIM_CB_LOGIN_P3D_F 15 | |
| 189 | #define AIM_CB_RATECHANGE 16 | |
| 190 | #define AIM_CB_USERERROR 17 | |
| 191 | #define AIM_CB_UNKNOWN 18 | |
| 192 | #define AIM_CB_USERINFO 19 | |
| 193 | #define AIM_CB_SEARCH_ADDRESS 20 | |
| 194 | #define AIM_CB_SEARCH_NAME 21 | |
| 195 | #define AIM_CB_SEARCH_FAIL 22 | |
| 196 | #define AIM_CB_AUTH_ERROR 23 | |
| 197 | #define AIM_CB_AUTH_SUCCESS 24 | |
| 198 | #define AIM_CB_AUTH_SVRREADY 25 | |
| 199 | #define AIM_CB_AUTH_OTHER 26 | |
| 200 | #define AIM_CB_AUTH_INFOCHNG_REPLY 27 | |
| 201 | #define AIM_CB_CHATNAV_SVRREADY 28 | |
| 202 | ||
| 203 | int Read(int, u_char *, int); | |
| 204 | ||
| 205 | struct aim_snac_t { | |
| 206 | u_long id; | |
| 207 | u_short family; | |
| 208 | u_short type; | |
| 209 | u_short flags; | |
| 210 | void *data; | |
| 211 | time_t issuetime; | |
| 212 | struct aim_snac_t *next; | |
| 213 | }; | |
| 214 | u_long aim_newsnac(struct aim_snac_t *newsnac); | |
| 215 | struct aim_snac_t *aim_remsnac(u_long id); | |
| 216 | int aim_cleansnacs(int maxage); | |
| 217 | int aim_putsnac(u_char *, int, int, int, u_long); | |
| 218 | ||
| 219 | void aim_connrst(void); | |
| 220 | struct aim_conn_t *aim_conn_getnext(void); | |
| 221 | void aim_conn_close(struct aim_conn_t *deadconn); | |
| 222 | struct aim_conn_t *aim_getconn_type(int type); | |
| 223 | struct aim_conn_t *aim_newconn(int type, char *dest); | |
| 224 | int aim_conngetmaxfd(void); | |
| 225 | struct aim_conn_t *aim_select(struct timeval *); | |
| 226 | int aim_conn_isready(struct aim_conn_t *); | |
| 227 | int aim_conn_setstatus(struct aim_conn_t *, int); | |
| 228 | ||
| 229 | /* aim_misc.c */ | |
| 230 | ||
| 231 | #define AIM_VISIBILITYCHANGE_PERMITADD 0x05 | |
| 232 | #define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06 | |
| 233 | #define AIM_VISIBILITYCHANGE_DENYADD 0x07 | |
| 234 | #define AIM_VISIBILITYCHANGE_DENYREMOVE 0x08 | |
| 235 | ||
| 236 | u_long aim_bos_setidle(struct aim_conn_t *, u_long); | |
| 237 | u_long aim_bos_changevisibility(struct aim_conn_t *, int, char *); | |
| 238 | u_long aim_bos_setbuddylist(struct aim_conn_t *, char *); | |
| 239 | u_long aim_bos_setprofile(struct aim_conn_t *, char *); | |
| 240 | u_long aim_bos_setgroupperm(struct aim_conn_t *, u_long); | |
| 241 | u_long aim_bos_clientready(struct aim_conn_t *); | |
| 242 | u_long aim_bos_reqrate(struct aim_conn_t *); | |
| 243 | u_long aim_bos_ackrateresp(struct aim_conn_t *); | |
| 244 | u_long aim_bos_setprivacyflags(struct aim_conn_t *, u_long); | |
| 245 | u_long aim_bos_reqpersonalinfo(struct aim_conn_t *); | |
| 246 | u_long aim_bos_reqservice(struct aim_conn_t *, u_short); | |
| 247 | u_long aim_bos_reqrights(struct aim_conn_t *); | |
| 248 | u_long aim_bos_reqbuddyrights(struct aim_conn_t *); | |
| 249 | u_long aim_bos_reqlocaterights(struct aim_conn_t *); | |
| 250 | u_long aim_bos_reqicbmparaminfo(struct aim_conn_t *); | |
| 251 | ||
| 252 | /* aim_rxhandlers.c */ | |
| 253 | int aim_register_callbacks(rxcallback_t *); | |
| 254 | int aim_rxdispatch(void); | |
| 255 | int aim_authparse(struct command_rx_struct *); | |
| 256 | int aim_handleredirect_middle(struct command_rx_struct *, ...); | |
| 257 | int aim_parse_unknown(struct command_rx_struct *, ...); | |
| 258 | int aim_parse_missed_im(struct command_rx_struct *, ...); | |
| 259 | int aim_parse_last_bad(struct command_rx_struct *, ...); | |
| 260 | int aim_parse_generalerrs(struct command_rx_struct *command, ...); | |
| 261 | ||
| 262 | /* aim_im.c */ | |
| 263 | #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */ | |
| 264 | #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */ | |
| 265 | u_long aim_send_im(struct aim_conn_t *, char *, int, char *); | |
| 266 | int aim_parse_incoming_im_middle(struct command_rx_struct *); | |
| 267 | ||
| 268 | /* aim_info.c */ | |
| 269 | u_long aim_getinfo(struct aim_conn_t *, const char *); | |
| 270 | int aim_parse_userinfo_middle(struct command_rx_struct *); | |
| 271 | ||
| 272 | /* aim_auth.c */ | |
| 273 | int aim_auth_sendcookie(struct aim_conn_t *, char *); | |
| 274 | u_long aim_auth_clientready(struct aim_conn_t *); | |
| 275 | u_long aim_auth_changepasswd(struct aim_conn_t *, char *, char *); | |
| 276 | ||
| 277 | /* aim_buddylist.c */ | |
| 278 | u_long aim_add_buddy(struct aim_conn_t *, char *); | |
| 279 | u_long aim_remove_buddy(struct aim_conn_t *, char *); | |
| 280 | ||
| 281 | /* aim_search.c */ | |
| 282 | u_long aim_usersearch_address(struct aim_conn_t *, char *); | |
| 283 | /* u_long aim_usersearch_name(struct aim_conn_t *, char *); */ | |
| 284 | ||
| 285 | /* aim_util.c */ | |
| 286 | int aimutil_put8(u_char *, u_short); | |
| 287 | int aimutil_put16(u_char *, u_short); | |
| 288 | int aimutil_put32(u_char *, u_long); | |
| 289 | int aimutil_putstr(u_char *, u_char *, int); | |
| 290 | ||
| 291 | /* proxy support */ | |
| 292 | #ifdef ENABLE_PROXY_SUPPORT | |
| 293 | #include "proxy.h" | |
| 294 | #endif | |
| 295 | ||
| 296 | #endif /* __AIM_H__ */ | |
| 297 |