Frameworks/libpurple.framework/Versions/0.6.2/Headers/oscar.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 2571 Frameworks/libpurple.framework/Versions/0.6.0/Headers/oscar.h@75fb8ee8f2e6
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /*
     2  * Purple's oscar protocol plugin
     3  * This file is the legal property of its developers.
     4  * Please see the AUTHORS file distributed alongside this file.
     5  *
     6  * This library is free software; you can redistribute it and/or
     7  * modify it under the terms of the GNU Lesser General Public
     8  * License as published by the Free Software Foundation; either
     9  * version 2 of the License, or (at your option) any later version.
    10  *
    11  * This library is distributed in the hope that it will be useful,
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    14  * Lesser General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU Lesser General Public
    17  * License along with this library; if not, write to the Free Software
    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
    19 */
    20 
    21 /*
    22  * Main libfaim header.  Must be included in client for prototypes/macros.
    23  *
    24  * "come on, i turned a chick lesbian; i think this is the hackish equivalent"
    25  *                                                -- Josh Myer
    26  *
    27  */
    28 
    29 #ifndef _OSCAR_H_
    30 #define _OSCAR_H_
    31 
    32 #include "circbuffer.h"
    33 #include "debug.h"
    34 #include "eventloop.h"
    35 #include "internal.h"
    36 #include "proxy.h"
    37 #include "sslconn.h"
    38 
    39 #include <stdio.h>
    40 #include <string.h>
    41 #include <fcntl.h>
    42 #include <sys/types.h>
    43 #include <stdlib.h>
    44 #include <stdarg.h>
    45 #include <errno.h>
    46 #include <time.h>
    47 
    48 #ifndef _WIN32
    49 #include <sys/time.h>
    50 #include <unistd.h>
    51 #include <netdb.h>
    52 #include <netinet/in.h>
    53 #include <sys/socket.h>
    54 #else
    55 #include "libc_interface.h"
    56 #endif
    57 
    58 typedef struct _ByteStream         ByteStream;
    59 typedef struct _ClientInfo         ClientInfo;
    60 typedef struct _FlapConnection     FlapConnection;
    61 typedef struct _FlapFrame          FlapFrame;
    62 typedef struct _IcbmArgsCh2        IcbmArgsCh2;
    63 typedef struct _IcbmCookie         IcbmCookie;
    64 typedef struct _OscarData          OscarData;
    65 typedef struct _QueuedSnac         QueuedSnac;
    66 
    67 typedef guint32 aim_snacid_t;
    68 
    69 #include "snactypes.h"
    70 
    71 #ifdef __cplusplus
    72 extern "C" {
    73 #endif
    74 
    75 #define FAIM_SNAC_HASH_SIZE 16
    76 
    77 /*
    78  * Current Maximum Length for usernames (not including NULL)
    79  *
    80  * Currently only names up to 16 characters can be registered
    81  * however it is apparently legal for them to be larger.
    82  */
    83 #define MAXSNLEN 97
    84 
    85 /*
    86  * Current Maximum Length for Instant Messages
    87  *
    88  * This was found basically by experiment, but not wholly
    89  * accurate experiment.  It should not be regarded
    90  * as completely correct.  But its a decent approximation.
    91  *
    92  * Note that although we can send this much, its impossible
    93  * for WinAIM clients (up through the latest (4.0.1957)) to
    94  * send any more than 1kb.  Amaze all your windows friends
    95  * with utterly oversized instant messages!
    96  */
    97 #define MAXMSGLEN 2544
    98 
    99 /*
   100  * Maximum size of a Buddy Icon.
   101  */
   102 #define MAXICONLEN 7168
   103 #define AIM_ICONIDENT "AVT1picture.id"
   104 
   105 /*
   106  * Current Maximum Length for Chat Room Messages
   107  *
   108  * This is actually defined by the protocol to be
   109  * dynamic, but I have yet to see due cause to
   110  * define it dynamically here.  Maybe later.
   111  *
   112  */
   113 #define MAXCHATMSGLEN 512
   114 
   115 /*
   116  * Found by trial and error.
   117  */
   118 #define MAXAVAILMSGLEN 251
   119 
   120 /**
   121  * Maximum length for the password of an ICQ account
   122  */
   123 #define MAXICQPASSLEN 8
   124 
   125 #define AIM_MD5_STRING "AOL Instant Messenger (SM)"
   126 
   127 /*
   128  * Client info.  Filled in by the client and passed in to
   129  * aim_send_login().  The information ends up getting passed to OSCAR
   130  * through the initial login command.
   131  *
   132  */
   133 struct _ClientInfo
   134 {
   135 	const char *clientstring;
   136 	guint16 clientid;
   137 	guint16 major;
   138 	guint16 minor;
   139 	guint16 point;
   140 	guint16 build;
   141 	guint32 distrib;
   142 	const char *country; /* two-letter abbrev */
   143 	const char *lang; /* two-letter abbrev */
   144 };
   145 
   146 /* Needs to be checked */
   147 #define CLIENTINFO_AIM_3_5_1670 { \
   148 	"AOL Instant Messenger (SM), version 3.5.1670/WIN32", \
   149 	0x0004, \
   150 	0x0003, 0x0005, \
   151 	0x0000, 0x0686, \
   152 	0x0000002a, \
   153 	"us", "en", \
   154 }
   155 
   156 /* Needs to be checked */
   157 /* Latest winaim without ssi */
   158 #define CLIENTINFO_AIM_4_1_2010 { \
   159 	"AOL Instant Messenger (SM), version 4.1.2010/WIN32", \
   160 	0x0004, \
   161 	0x0004, 0x0001, \
   162 	0x0000, 0x07da, \
   163 	0x0000004b, \
   164 	"us", "en", \
   165 }
   166 
   167 /* Needs to be checked */
   168 #define CLIENTINFO_AIM_4_3_2188 { \
   169 	"AOL Instant Messenger (SM), version 4.3.2188/WIN32", \
   170 	0x0109, \
   171 	0x0400, 0x0003, \
   172 	0x0000, 0x088c, \
   173 	0x00000086, \
   174 	"us", "en", \
   175 }
   176 
   177 /* Needs to be checked */
   178 #define CLIENTINFO_AIM_4_8_2540 { \
   179 	"AOL Instant Messenger (SM), version 4.8.2540/WIN32", \
   180 	0x0109, \
   181 	0x0004, 0x0008, \
   182 	0x0000, 0x09ec, \
   183 	0x000000af, \
   184 	"us", "en", \
   185 }
   186 
   187 /* Needs to be checked */
   188 #define CLIENTINFO_AIM_5_0_2938 { \
   189 	"AOL Instant Messenger, version 5.0.2938/WIN32", \
   190 	0x0109, \
   191 	0x0005, 0x0000, \
   192 	0x0000, 0x0b7a, \
   193 	0x00000000, \
   194 	"us", "en", \
   195 }
   196 
   197 #define CLIENTINFO_AIM_5_1_3036 { \
   198 	"AOL Instant Messenger, version 5.1.3036/WIN32", \
   199 	0x0109, \
   200 	0x0005, 0x0001, \
   201 	0x0000, 0x0bdc, \
   202 	0x000000d2, \
   203 	"us", "en", \
   204 }
   205 
   206 #define CLIENTINFO_AIM_5_5_3415 { \
   207 	"AOL Instant Messenger, version 5.5.3415/WIN32", \
   208 	0x0109, \
   209 	0x0005, 0x0005, \
   210 	0x0000, 0x0057, \
   211 	0x000000ef, \
   212 	"us", "en", \
   213 }
   214 
   215 #define CLIENTINFO_AIM_5_9_3702 { \
   216 	"AOL Instant Messenger, version 5.9.3702/WIN32", \
   217 	0x0109, \
   218 	0x0005, 0x0009, \
   219 	0x0000, 0x0e76, \
   220 	0x00000111, \
   221 	"us", "en", \
   222 }
   223 
   224 #define CLIENTINFO_ICHAT_1_0 { \
   225 	"Apple iChat", \
   226 	0x311a, \
   227 	0x0001, 0x0000, \
   228 	0x0000, 0x003c, \
   229 	0x000000c6, \
   230 	"us", "en", \
   231 }
   232 
   233 /* Needs to be checked */
   234 #define CLIENTINFO_ICQ_4_65_3281 { \
   235 	"ICQ Inc. - Product of ICQ (TM) 2000b.4.65.1.3281.85", \
   236 	0x010a, \
   237 	0x0004, 0x0041, \
   238 	0x0001, 0x0cd1, \
   239 	0x00000055, \
   240 	"us", "en", \
   241 }
   242 
   243 /* Needs to be checked */
   244 #define CLIENTINFO_ICQ_5_34_3728 { \
   245 	"ICQ Inc. - Product of ICQ (TM).2002a.5.34.1.3728.85", \
   246 	0x010a, \
   247 	0x0005, 0x0022, \
   248 	0x0001, 0x0e8f, \
   249 	0x00000055, \
   250 	"us", "en", \
   251 }
   252 
   253 #define CLIENTINFO_ICQ_5_45_3777 { \
   254 	"ICQ Inc. - Product of ICQ (TM).2003a.5.45.1.3777.85", \
   255 	0x010a, \
   256 	0x0005, 0x002d, \
   257 	0x0001, 0x0ec1, \
   258 	0x00000055, \
   259 	"us", "en", \
   260 }
   261 
   262 #define CLIENTINFO_ICQ6_6_0_6059 { \
   263 	"ICQ Client", \
   264 	0x010a, \
   265 	0x0006, 0x0000, \
   266 	0x0000, 0x17ab, \
   267 	0x00007535, \
   268 	"us", "en", \
   269 }
   270 
   271 #define CLIENTINFO_ICQBASIC_14_3_1068 { \
   272 	"ICQBasic", \
   273 	0x010a, \
   274 	0x0014, 0x0003, \
   275 	0x0000, 0x042c, \
   276 	0x0000043d, \
   277 	"us", "en", \
   278 }
   279 
   280 #define CLIENTINFO_ICQBASIC_14_34_3000 { \
   281 	"ICQBasic", \
   282 	0x010a, \
   283 	0x0014, 0x0034, \
   284 	0x0000, 0x0bb8, \
   285 	0x0000043d, \
   286 	"us", "en", \
   287 }
   288 
   289 #define CLIENTINFO_ICQBASIC_14_34_3096 { \
   290 	"ICQBasic", \
   291 	0x010a, \
   292 	0x0014, 0x0034, \
   293 	0x0000, 0x0c18, \
   294 	0x0000043d, \
   295 	"us", "en", \
   296 }
   297 
   298 #define CLIENTINFO_NETSCAPE_7_0_1 { \
   299 	"Netscape 2000 an approved user of AOL Instant Messenger (SM)", \
   300 	0x1d0d, \
   301 	0x0007, 0x0000, \
   302 	0x0001, 0x0000, \
   303 	0x00000058, \
   304 	"us", "en", \
   305 }
   306 
   307 /*
   308  * We need to use the major-minor-micro versions from the official
   309  * AIM and ICQ programs here or AOL won't let us use certain features.
   310  *
   311  * 0x00000611 is the distid given to us by AOL for use as the default
   312  * libpurple distid.
   313  */
   314 #define CLIENTINFO_PURPLE_AIM { \
   315 	NULL, \
   316 	0x0109, \
   317 	0x0005, 0x0001, \
   318 	0x0000, 0x0bdc, \
   319 	0x00000611, \
   320 	"us", "en", \
   321 }
   322 
   323 #define CLIENTINFO_PURPLE_ICQ { \
   324 	NULL, \
   325 	0x010a, \
   326 	0x0014, 0x0034, \
   327 	0x0000, 0x0c18, \
   328 	0x00000611, \
   329 	"us", "en", \
   330 }
   331 
   332 #define CLIENTINFO_AIM_KNOWNGOOD CLIENTINFO_AIM_5_1_3036
   333 #define CLIENTINFO_ICQ_KNOWNGOOD CLIENTINFO_ICQBASIC_14_34_3096
   334 
   335 typedef enum
   336 {
   337 	OSCAR_DISCONNECT_DONE, /* not considered an error */
   338 	OSCAR_DISCONNECT_LOCAL_CLOSED, /* peer connections only, not considered an error */
   339 	OSCAR_DISCONNECT_REMOTE_CLOSED,
   340 	OSCAR_DISCONNECT_REMOTE_REFUSED, /* peer connections only */
   341 	OSCAR_DISCONNECT_LOST_CONNECTION,
   342 	OSCAR_DISCONNECT_INVALID_DATA,
   343 	OSCAR_DISCONNECT_COULD_NOT_CONNECT,
   344 	OSCAR_DISCONNECT_RETRYING /* peer connections only */
   345 } OscarDisconnectReason;
   346 
   347 typedef enum
   348 {
   349 	OSCAR_CAPABILITY_BUDDYICON            = 0x00000001,
   350 	OSCAR_CAPABILITY_TALK                 = 0x00000002,
   351 	OSCAR_CAPABILITY_DIRECTIM             = 0x00000004,
   352 	OSCAR_CAPABILITY_CHAT                 = 0x00000008,
   353 	OSCAR_CAPABILITY_GETFILE              = 0x00000010,
   354 	OSCAR_CAPABILITY_SENDFILE             = 0x00000020,
   355 	OSCAR_CAPABILITY_GAMES                = 0x00000040,
   356 	OSCAR_CAPABILITY_ADDINS               = 0x00000080,
   357 	OSCAR_CAPABILITY_SENDBUDDYLIST        = 0x00000100,
   358 	OSCAR_CAPABILITY_GAMES2               = 0x00000200,
   359 	OSCAR_CAPABILITY_ICQ_DIRECT           = 0x00000400,
   360 	OSCAR_CAPABILITY_APINFO               = 0x00000800,
   361 	OSCAR_CAPABILITY_ICQRTF               = 0x00001000,
   362 	OSCAR_CAPABILITY_EMPTY                = 0x00002000,
   363 	OSCAR_CAPABILITY_ICQSERVERRELAY       = 0x00004000,
   364 	OSCAR_CAPABILITY_UNICODEOLD           = 0x00008000,
   365 	OSCAR_CAPABILITY_TRILLIANCRYPT        = 0x00010000,
   366 	OSCAR_CAPABILITY_UNICODE              = 0x00020000,
   367 	OSCAR_CAPABILITY_INTEROPERATE         = 0x00040000,
   368 	OSCAR_CAPABILITY_SHORTCAPS            = 0x00080000,
   369 	OSCAR_CAPABILITY_HIPTOP               = 0x00100000,
   370 	OSCAR_CAPABILITY_SECUREIM             = 0x00200000,
   371 	OSCAR_CAPABILITY_SMS                  = 0x00400000,
   372 	OSCAR_CAPABILITY_VIDEO                = 0x00800000,
   373 	OSCAR_CAPABILITY_ICHATAV              = 0x01000000,
   374 	OSCAR_CAPABILITY_LIVEVIDEO            = 0x02000000,
   375 	OSCAR_CAPABILITY_CAMERA               = 0x04000000,
   376 	OSCAR_CAPABILITY_ICHAT_SCREENSHARE    = 0x08000000,
   377 	OSCAR_CAPABILITY_TYPING               = 0x10000000,
   378 	OSCAR_CAPABILITY_GENERICUNKNOWN       = 0x20000000,
   379 	OSCAR_CAPABILITY_LAST                 = 0x40000000
   380 } OscarCapability;
   381 
   382 /*
   383  * Byte Stream type. Sort of.
   384  *
   385  * Use of this type serves a couple purposes:
   386  *   - Buffer/buflen pairs are passed all around everywhere. This turns
   387  *     that into one value, as well as abstracting it slightly.
   388  *   - Through the abstraction, it is possible to enable bounds checking
   389  *     for robustness at the cost of performance.  But a clean failure on
   390  *     weird packets is much better than a segfault.
   391  *   - I like having variables named "bs".
   392  *
   393  * Don't touch the insides of this struct.  Or I'll have to kill you.
   394  *
   395  */
   396 struct _ByteStream
   397 {
   398 	guint8 *data;
   399 	guint32 len;
   400 	guint32 offset;
   401 };
   402 
   403 struct _QueuedSnac
   404 {
   405 	guint16 family;
   406 	guint16 subtype;
   407 	FlapFrame *frame;
   408 };
   409 
   410 struct _FlapFrame
   411 {
   412 	guint8 channel;
   413 	guint16 seqnum;
   414 	ByteStream data;        /* payload stream */
   415 };
   416 
   417 struct _FlapConnection
   418 {
   419 	OscarData *od;              /**< Pointer to parent session. */
   420 	gboolean connected;
   421 	time_t lastactivity;             /**< Time of last transmit. */
   422 	guint destroy_timeout;
   423 	OscarDisconnectReason disconnect_reason;
   424 	gchar *error_message;
   425 	guint16 disconnect_code;
   426 
   427 	/* A few variables that are only used when connecting */
   428 	PurpleProxyConnectData *connect_data;
   429 	guint16 cookielen;
   430 	guint8 *cookie;
   431 	gpointer new_conn_data;
   432 
   433 	int fd;
   434 	PurpleSslConnection *gsc;
   435 	guint8 header[6];
   436 	gssize header_received;
   437 	FlapFrame buffer_incoming;
   438 	PurpleCircBuffer *buffer_outgoing;
   439 	guint watcher_incoming;
   440 	guint watcher_outgoing;
   441 
   442 	guint16 type;
   443 	guint16 subtype;
   444 	guint16 seqnum_out; /**< The sequence number of most recently sent packet. */
   445 	guint16 seqnum_in; /**< The sequence number of most recently received packet. */
   446 	GSList *groups;
   447 	GSList *rateclasses; /* Contains nodes of struct rateclass. */
   448 
   449 	GQueue *queued_snacs; /**< Contains QueuedSnacs. */
   450 	GQueue *queued_lowpriority_snacs; /**< Contains QueuedSnacs to send only once queued_snacs is empty */
   451 	guint queued_timeout;
   452 
   453 	void *internal; /* internal conn-specific libfaim data */
   454 };
   455 
   456 struct _IcbmCookie
   457 {
   458 	guchar cookie[8];
   459 	int type;
   460 	void *data;
   461 	time_t addtime;
   462 	struct _IcbmCookie *next;
   463 };
   464 
   465 #include "peer.h"
   466 
   467 /*
   468  * AIM Session: The main client-data interface.
   469  *
   470  */
   471 struct _OscarData
   472 {
   473 	/** Only used when connecting with clientLogin */
   474 	PurpleUtilFetchUrlData *url_data;
   475 
   476 	gboolean iconconnecting;
   477 	gboolean set_icon;
   478 
   479 	GSList *create_rooms;
   480 
   481 	gboolean conf;
   482 	gboolean reqemail;
   483 	gboolean setemail;
   484 	char *email;
   485 	gboolean setnick;
   486 	char *newformatting;
   487 	gboolean chpass;
   488 	char *oldp;
   489 	char *newp;
   490 
   491 	GSList *oscar_chats;
   492 	GHashTable *buddyinfo;
   493 	GSList *requesticon;
   494 
   495 	gboolean use_ssl;
   496 	gboolean icq;
   497 	guint getblisttimer;
   498 
   499 	struct {
   500 		guint maxwatchers; /* max users who can watch you */
   501 		guint maxbuddies; /* max users you can watch */
   502 		guint maxgroups; /* max groups in server list */
   503 		guint maxpermits; /* max users on permit list */
   504 		guint maxdenies; /* max users on deny list */
   505 		guint maxsiglen; /* max size (bytes) of profile */
   506 		guint maxawaymsglen; /* max size (bytes) of posted away message */
   507 	} rights;
   508 
   509 	PurpleConnection *gc;
   510 
   511 	void *modlistv;
   512 
   513 	/*
   514 	 * Outstanding snac handling
   515 	 *
   516 	 * TODO: Should these be per-connection? -mid
   517 	 */
   518 	void *snac_hash[FAIM_SNAC_HASH_SIZE];
   519 	aim_snacid_t snacid_next;
   520 
   521 	/*
   522 	 * TODO: Data specific to a certain family should go into a
   523 	 *       hashtable and the core parts of libfaim shouldn't
   524 	 *       need to know about them.
   525 	 */
   526 
   527 	IcbmCookie *msgcookies;
   528 	struct aim_icq_info *icq_info;
   529 
   530 	/** Only used when connecting with the old-style BUCP login. */
   531 	struct aim_authresp_info *authinfo;
   532 	struct aim_emailinfo *emailinfo;
   533 
   534 	struct {
   535 		struct aim_userinfo_s *userinfo;
   536 	} locate;
   537 
   538 	/* Server-stored information (ssi) */
   539 	struct {
   540 		gboolean received_data;
   541 		guint16 numitems;
   542 		struct aim_ssi_item *official;
   543 		struct aim_ssi_item *local;
   544 		struct aim_ssi_tmp *pending;
   545 		time_t timestamp;
   546 		gboolean waiting_for_ack;
   547 		gboolean in_transaction;
   548 	} ssi;
   549 
   550 	/** Contains pointers to handler functions for each family/subtype. */
   551 	GHashTable *handlerlist;
   552 
   553 	/** A linked list containing FlapConnections. */
   554 	GSList *oscar_connections;
   555 	guint16 default_port;
   556 
   557 	/** A linked list containing PeerConnections. */
   558 	GSList *peer_connections;
   559 };
   560 
   561 /* Valid for calling aim_icq_setstatus() and for aim_userinfo_t->icqinfo.status */
   562 #define AIM_ICQ_STATE_NORMAL            0x00000000
   563 #define AIM_ICQ_STATE_AWAY              0x00000001
   564 #define AIM_ICQ_STATE_DND               0x00000002
   565 #define AIM_ICQ_STATE_OUT               0x00000004
   566 #define AIM_ICQ_STATE_BUSY              0x00000010
   567 #define AIM_ICQ_STATE_CHAT              0x00000020
   568 #define AIM_ICQ_STATE_INVISIBLE         0x00000100
   569 #define AIM_ICQ_STATE_WEBAWARE          0x00010000
   570 #define AIM_ICQ_STATE_HIDEIP            0x00020000
   571 #define AIM_ICQ_STATE_BIRTHDAY          0x00080000
   572 #define AIM_ICQ_STATE_DIRECTDISABLED    0x00100000
   573 #define AIM_ICQ_STATE_ICQHOMEPAGE       0x00200000
   574 #define AIM_ICQ_STATE_DIRECTREQUIREAUTH 0x10000000
   575 #define AIM_ICQ_STATE_DIRECTCONTACTLIST 0x20000000
   576 
   577 /**
   578  * Only used when connecting with the old-style BUCP login.
   579  */
   580 struct aim_clientrelease
   581 {
   582 	char *name;
   583 	guint32 build;
   584 	char *url;
   585 	char *info;
   586 };
   587 
   588 /**
   589  * Only used when connecting with the old-style BUCP login.
   590  */
   591 struct aim_authresp_info
   592 {
   593 	char *bn;
   594 	guint16 errorcode;
   595 	char *errorurl;
   596 	guint16 regstatus;
   597 	char *email;
   598 	char *bosip;
   599 	guint16 cookielen;
   600 	guint8 *cookie;
   601 	char *chpassurl;
   602 	struct aim_clientrelease latestrelease;
   603 	struct aim_clientrelease latestbeta;
   604 };
   605 
   606 /* Callback data for redirect. */
   607 struct aim_redirect_data
   608 {
   609 	guint16 group;
   610 	const char *ip;
   611 	guint16 cookielen;
   612 	const guint8 *cookie;
   613 	const char *ssl_cert_cn;
   614 	guint8 use_ssl;
   615 	struct { /* group == SNAC_FAMILY_CHAT */
   616 		guint16 exchange;
   617 		const char *room;
   618 		guint16 instance;
   619 	} chat;
   620 };
   621 
   622 int oscar_connect_to_bos(PurpleConnection *gc, OscarData *od, const char *host, guint16 port, guint8 *cookie, guint16 cookielen);
   623 
   624 /* family_auth.c */
   625 
   626 /**
   627  * Only used when connecting with the old-style BUCP login.
   628  */
   629 int aim_request_login(OscarData *od, FlapConnection *conn, const char *bn);
   630 
   631 /**
   632  * Only used when connecting with the old-style BUCP login.
   633  */
   634 int aim_send_login(OscarData *od, FlapConnection *conn, const char *bn, const char *password, gboolean truncate_pass, ClientInfo *ci, const char *key, gboolean allow_multiple_logins);
   635 
   636 /**
   637  * Only used when connecting with the old-style BUCP login.
   638  */
   639 /* 0x000b */ int aim_auth_securid_send(OscarData *od, const char *securid);
   640 
   641 /**
   642  * Only used when connecting with clientLogin.
   643  */
   644 void send_client_login(OscarData *od, const char *username);
   645 
   646 /* flap_connection.c */
   647 FlapConnection *flap_connection_new(OscarData *, int type);
   648 void flap_connection_close(OscarData *od, FlapConnection *conn);
   649 void flap_connection_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message);
   650 void flap_connection_schedule_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message);
   651 FlapConnection *flap_connection_findbygroup(OscarData *od, guint16 group);
   652 FlapConnection *flap_connection_getbytype(OscarData *, int type);
   653 FlapConnection *flap_connection_getbytype_all(OscarData *, int type);
   654 void flap_connection_recv_cb(gpointer data, gint source, PurpleInputCondition cond);
   655 void flap_connection_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, PurpleInputCondition cond);
   656 
   657 void flap_connection_send(FlapConnection *conn, FlapFrame *frame);
   658 void flap_connection_send_version(OscarData *od, FlapConnection *conn);
   659 void flap_connection_send_version_with_cookie(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy);
   660 void flap_connection_send_version_with_cookie_and_clientinfo(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy, ClientInfo *ci);
   661 void flap_connection_send_snac(OscarData *od, FlapConnection *conn, guint16 family, const guint16 subtype, guint16 flags, aim_snacid_t snacid, ByteStream *data);
   662 void flap_connection_send_snac_with_priority(OscarData *od, FlapConnection *conn, guint16 family, const guint16 subtype, guint16 flags, aim_snacid_t snacid, ByteStream *data, gboolean high_priority);
   663 void flap_connection_send_keepalive(OscarData *od, FlapConnection *conn);
   664 FlapFrame *flap_frame_new(OscarData *od, guint16 channel, int datalen);
   665 
   666 /* oscar_data.c */
   667 typedef int (*aim_rxcallback_t)(OscarData *od, FlapConnection *conn, FlapFrame *frame, ...);
   668 
   669 OscarData *oscar_data_new(void);
   670 void oscar_data_destroy(OscarData *);
   671 void oscar_data_addhandler(OscarData *od, guint16 family, guint16 subtype, aim_rxcallback_t newhandler, guint16 flags);
   672 aim_rxcallback_t aim_callhandler(OscarData *od, guint16 family, guint16 subtype);
   673 
   674 /* misc.c */
   675 #define AIM_VISIBILITYCHANGE_PERMITADD    0x05
   676 #define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06
   677 #define AIM_VISIBILITYCHANGE_DENYADD      0x07
   678 #define AIM_VISIBILITYCHANGE_DENYREMOVE   0x08
   679 
   680 #define AIM_PRIVFLAGS_ALLOWIDLE           0x01
   681 #define AIM_PRIVFLAGS_ALLOWMEMBERSINCE    0x02
   682 
   683 #define AIM_WARN_ANON                     0x01
   684 
   685 
   686 
   687 /* 0x0001 - family_oservice.c */
   688 /* 0x0002 */ void aim_srv_clientready(OscarData *od, FlapConnection *conn);
   689 /* 0x0004 */ void aim_srv_requestnew(OscarData *od, guint16 serviceid);
   690 /* 0x0006 */ void aim_srv_reqrates(OscarData *od, FlapConnection *conn);
   691 /* 0x0008 */ void aim_srv_rates_addparam(OscarData *od, FlapConnection *conn);
   692 /* 0x0009 */ void aim_srv_rates_delparam(OscarData *od, FlapConnection *conn);
   693 /* 0x000c */ void aim_srv_sendpauseack(OscarData *od, FlapConnection *conn);
   694 /* 0x000e */ void aim_srv_reqpersonalinfo(OscarData *od, FlapConnection *conn);
   695 /* 0x0011 */ void aim_srv_setidle(OscarData *od, guint32 idletime);
   696 /* 0x0014 */ void aim_srv_setprivacyflags(OscarData *od, FlapConnection *conn, guint32);
   697 /* 0x0016 */ void aim_srv_nop(OscarData *od, FlapConnection *conn);
   698 /* 0x0017 */ void aim_srv_setversions(OscarData *od, FlapConnection *conn);
   699 /* 0x001e */ int aim_srv_setextrainfo(OscarData *od, gboolean seticqstatus, guint32 icqstatus, gboolean setstatusmsg, const char *statusmsg, const char *itmsurl);
   700 
   701 
   702 void aim_bos_reqrights(OscarData *od, FlapConnection *conn);
   703 int aim_bos_changevisibility(OscarData *od, FlapConnection *conn, int, const char *);
   704 void aim_bos_setgroupperm(OscarData *od, FlapConnection *conn, guint32 mask);
   705 
   706 
   707 
   708 #define AIM_CLIENTTYPE_UNKNOWN  0x0000
   709 #define AIM_CLIENTTYPE_MC       0x0001
   710 #define AIM_CLIENTTYPE_WINAIM   0x0002
   711 #define AIM_CLIENTTYPE_WINAIM41 0x0003
   712 #define AIM_CLIENTTYPE_AOL_TOC  0x0004
   713 guint16 aim_im_fingerprint(const guint8 *msghdr, int len);
   714 
   715 #define AIM_RATE_CODE_CHANGE     0x0001
   716 #define AIM_RATE_CODE_WARNING    0x0002
   717 #define AIM_RATE_CODE_LIMIT      0x0003
   718 #define AIM_RATE_CODE_CLEARLIMIT 0x0004
   719 void aim_ads_requestads(OscarData *od, FlapConnection *conn);
   720 
   721 
   722 
   723 /* family_icbm.c */
   724 #define AIM_OFT_SUBTYPE_SEND_FILE	0x0001
   725 #define AIM_OFT_SUBTYPE_SEND_DIR	0x0002
   726 #define AIM_OFT_SUBTYPE_GET_FILE	0x0011
   727 #define AIM_OFT_SUBTYPE_GET_LIST	0x0012
   728 
   729 #define AIM_TRANSFER_DENY_NOTSUPPORTED	0x0000
   730 #define AIM_TRANSFER_DENY_DECLINE	0x0001
   731 #define AIM_TRANSFER_DENY_NOTACCEPTING	0x0002
   732 
   733 #define AIM_IMPARAM_FLAG_CHANNEL_MSGS_ALLOWED   0x00000001
   734 #define AIM_IMPARAM_FLAG_MISSED_CALLS_ENABLED   0x00000002
   735 #define AIM_IMPARAM_FLAG_EVENTS_ALLOWED         0x00000008
   736 #define AIM_IMPARAM_FLAG_SMS_SUPPORTED          0x00000010
   737 #define AIM_IMPARAM_FLAG_OFFLINE_MSGS_ALLOWED   0x00000100
   738 
   739 /* This is what the server will give you if you don't set them yourself. */
   740 /* This is probably out of date. */
   741 #define AIM_IMPARAM_DEFAULTS { \
   742 	0, \
   743 	AIM_IMPARAM_FLAG_CHANNEL_MSGS_ALLOWED | AIM_IMPARAM_FLAG_MISSED_CALLS_ENABLED, \
   744 	512, /* !! Note how small this is. */ \
   745 	(99.9)*10, (99.9)*10, \
   746 	1000 /* !! And how large this is. */ \
   747 }
   748 
   749 /* This is what most AIM versions use. */
   750 /* This is probably out of date. */
   751 #define AIM_IMPARAM_REASONABLE { \
   752 	0, \
   753 	AIM_IMPARAM_FLAG_CHANNEL_MSGS_ALLOWED | AIM_IMPARAM_FLAG_MISSED_CALLS_ENABLED, \
   754 	8000, \
   755 	(99.9)*10, (99.9)*10, \
   756 	0 \
   757 }
   758 
   759 struct aim_icbmparameters
   760 {
   761 	guint16 maxchan;
   762 	guint32 flags; /* AIM_IMPARAM_FLAG_ */
   763 	guint16 maxmsglen; /* message size that you will accept */
   764 	guint16 maxsenderwarn; /* this and below are *10 (999=99.9%) */
   765 	guint16 maxrecverwarn;
   766 	guint32 minmsginterval; /* in milliseconds? */
   767 };
   768 
   769 /*
   770  * TODO: Should probably combine this with struct chat_connection.
   771  */
   772 struct aim_chat_roominfo
   773 {
   774 	guint16 exchange;
   775 	char *name;
   776 	guint8 namelen;
   777 	guint16 instance;
   778 };
   779 
   780 struct chat_connection
   781 {
   782 	char *name;
   783 	char *show; /* AOL did something funny to us */
   784 	guint16 exchange;
   785 	guint16 instance;
   786 	FlapConnection *conn;
   787 	int id;
   788 	PurpleConnection *gc;
   789 	PurpleConversation *conv;
   790 	int maxlen;
   791 	int maxvis;
   792 };
   793 
   794 /*
   795  * All this chat struct stuff should be in family_chat.c
   796  */
   797 void oscar_chat_destroy(struct chat_connection *cc);
   798 
   799 #define AIM_IMFLAGS_AWAY				0x0001 /* mark as an autoreply */
   800 #define AIM_IMFLAGS_ACK					0x0002 /* request a receipt notice */
   801 #define AIM_IMFLAGS_BUDDYREQ			0x0010 /* buddy icon requested */
   802 #define AIM_IMFLAGS_HASICON				0x0020 /* already has icon */
   803 #define AIM_IMFLAGS_SUBENC_MACINTOSH	0x0040 /* damn that Steve Jobs! */
   804 #define AIM_IMFLAGS_CUSTOMFEATURES		0x0080 /* features field present */
   805 #define AIM_IMFLAGS_EXTDATA				0x0100
   806 #define AIM_IMFLAGS_X					0x0200
   807 #define AIM_IMFLAGS_MULTIPART			0x0400 /* ->mpmsg section valid */
   808 #define AIM_IMFLAGS_OFFLINE				0x0800 /* send to offline user */
   809 #define AIM_IMFLAGS_TYPINGNOT			0x1000 /* typing notification */
   810 
   811 #define AIM_CHARSET_ASCII		0x0000
   812 #define AIM_CHARSET_UNICODE	0x0002 /* UTF-16BE */
   813 #define AIM_CHARSET_CUSTOM	0x0003
   814 
   815 /*
   816  * Multipart message structures.
   817  */
   818 typedef struct aim_mpmsg_section_s
   819 {
   820 	guint16 charset;
   821 	guint16 charsubset;
   822 	gchar *data;
   823 	guint16 datalen;
   824 	struct aim_mpmsg_section_s *next;
   825 } aim_mpmsg_section_t;
   826 
   827 typedef struct aim_mpmsg_s
   828 {
   829 	unsigned int numparts;
   830 	aim_mpmsg_section_t *parts;
   831 } aim_mpmsg_t;
   832 
   833 int aim_mpmsg_init(OscarData *od, aim_mpmsg_t *mpm);
   834 int aim_mpmsg_addraw(OscarData *od, aim_mpmsg_t *mpm, guint16 charset, guint16 charsubset, const gchar *data, guint16 datalen);
   835 int aim_mpmsg_addascii(OscarData *od, aim_mpmsg_t *mpm, const char *ascii);
   836 int aim_mpmsg_addunicode(OscarData *od, aim_mpmsg_t *mpm, const guint16 *unicode, guint16 unicodelen);
   837 void aim_mpmsg_free(OscarData *od, aim_mpmsg_t *mpm);
   838 
   839 /*
   840  * Arguments to aim_send_im_ext().
   841  *
   842  * This is really complicated.  But immensely versatile.
   843  *
   844  */
   845 struct aim_sendimext_args
   846 {
   847 
   848 	/* These are _required_ */
   849 	const char *destbn;
   850 	guint32 flags; /* often 0 */
   851 
   852 	/* Only required if not using multipart messages */
   853 	const char *msg;
   854 	int msglen;
   855 
   856 	/* Required if ->msg is not provided */
   857 	aim_mpmsg_t *mpmsg;
   858 
   859 	/* Only used if AIM_IMFLAGS_HASICON is set */
   860 	guint32 iconlen;
   861 	time_t iconstamp;
   862 	guint32 iconsum;
   863 
   864 	/* Only used if AIM_IMFLAGS_CUSTOMFEATURES is set */
   865 	guint16 featureslen;
   866 	guint8 *features;
   867 
   868 	/* Only used if AIM_IMFLAGS_CUSTOMCHARSET is set and mpmsg not used */
   869 	guint16 charset;
   870 	guint16 charsubset;
   871 };
   872 
   873 /*
   874  * Arguments to aim_send_rtfmsg().
   875  */
   876 struct aim_sendrtfmsg_args
   877 {
   878 	const char *destbn;
   879 	guint32 fgcolor;
   880 	guint32 bgcolor;
   881 	const char *rtfmsg; /* must be in RTF */
   882 };
   883 
   884 /*
   885  * This information is provided in the Incoming ICBM callback for
   886  * Channel 1 ICBM's.
   887  *
   888  * Note that although CUSTOMFEATURES and CUSTOMCHARSET say they
   889  * are optional, both are always set by the current libfaim code.
   890  * That may or may not change in the future.  It is mainly for
   891  * consistency with aim_sendimext_args.
   892  *
   893  * Multipart messages require some explanation. If you want to use them,
   894  * I suggest you read all the comments in family_icbm.c.
   895  *
   896  */
   897 struct aim_incomingim_ch1_args
   898 {
   899 
   900 	/* Always provided */
   901 	aim_mpmsg_t mpmsg;
   902 	guint32 icbmflags; /* some flags apply only to ->msg, not all mpmsg */
   903 	time_t timestamp; /* Only set for offline messages */
   904 
   905 	/* Only provided if message has a human-readable section */
   906 	gchar *msg;
   907 	int msglen;
   908 
   909 	/* Only provided if AIM_IMFLAGS_HASICON is set */
   910 	time_t iconstamp;
   911 	guint32 iconlen;
   912 	guint16 iconsum;
   913 
   914 	/* Only provided if AIM_IMFLAGS_CUSTOMFEATURES is set */
   915 	guint8 *features;
   916 	guint8 featureslen;
   917 
   918 	/* Only provided if AIM_IMFLAGS_EXTDATA is set */
   919 	guint8 extdatalen;
   920 	guint8 *extdata;
   921 
   922 	/* Only used if AIM_IMFLAGS_CUSTOMCHARSET is set */
   923 	guint16 charset;
   924 	guint16 charsubset;
   925 };
   926 
   927 /* Valid values for channel 2 args->status */
   928 #define AIM_RENDEZVOUS_PROPOSE   0x0000
   929 #define AIM_RENDEZVOUS_CANCEL    0x0001
   930 #define AIM_RENDEZVOUS_CONNECTED 0x0002
   931 
   932 struct _IcbmArgsCh2
   933 {
   934 	guint16 status;
   935 	guchar cookie[8];
   936 	int type; /* One of the OSCAR_CAPABILITY_ constants */
   937 	const char *proxyip;
   938 	const char *clientip;
   939 	const char *verifiedip;
   940 	guint16 port;
   941 	gboolean use_proxy;
   942 	guint16 errorcode;
   943 	const char *msg; /* invite message or file description */
   944 	guint16 msglen;
   945 	const char *encoding;
   946 	const char *language;
   947 	guint16 requestnumber;
   948 	union {
   949 		struct {
   950 			guint32 checksum;
   951 			guint32 length;
   952 			time_t timestamp;
   953 			guint8 *icon;
   954 		} icon;
   955 		struct {
   956 			struct aim_chat_roominfo roominfo;
   957 		} chat;
   958 		struct {
   959 			guint16 msgtype;
   960 			guint32 fgcolor;
   961 			guint32 bgcolor;
   962 			const char *rtfmsg;
   963 		} rtfmsg;
   964 		struct {
   965 			guint16 subtype;
   966 			guint16 totfiles;
   967 			guint32 totsize;
   968 			char *filename;
   969 		} sendfile;
   970 	} info;
   971 	void *destructor; /* used internally only */
   972 };
   973 
   974 /* Valid values for channel 4 args->type */
   975 #define AIM_ICQMSG_AUTHREQUEST	0x0006
   976 #define AIM_ICQMSG_AUTHDENIED	0x0007
   977 #define AIM_ICQMSG_AUTHGRANTED	0x0008
   978 
   979 struct aim_incomingim_ch4_args
   980 {
   981 	guint32 uin; /* Of the sender of the ICBM */
   982 	guint8 type;
   983 	guint8 flags;
   984 	gchar *msg; /* Reason for auth request, deny, or accept */
   985 	int msglen;
   986 };
   987 
   988 /* SNAC sending functions */
   989 /* 0x0002 */ int aim_im_setparams(OscarData *od, struct aim_icbmparameters *params);
   990 /* 0x0004 */ int aim_im_reqparams(OscarData *od);
   991 /* 0x0006 */ int aim_im_sendch1_ext(OscarData *od, struct aim_sendimext_args *args);
   992 /* 0x0006 */ int aim_im_sendch1(OscarData *, const char *destbn, guint16 flags, const char *msg);
   993 /* 0x0006 */ int aim_im_sendch2_chatinvite(OscarData *od, const char *bn, const char *msg, guint16 exchange, const char *roomname, guint16 instance);
   994 /* 0x0006 */ int aim_im_sendch2_icon(OscarData *od, const char *bn, const guint8 *icon, int iconlen, time_t stamp, guint16 iconsum);
   995 /* 0x0006 */ int aim_im_sendch2_rtfmsg(OscarData *od, struct aim_sendrtfmsg_args *args);
   996 
   997 /* 0x0006 */ void aim_im_sendch2_cancel(PeerConnection *peer_conn);
   998 /* 0x0006 */ void aim_im_sendch2_connected(PeerConnection *peer_conn);
   999 /* 0x0006 */ void aim_im_sendch2_odc_requestdirect(OscarData *od, guchar *cookie, const char *bn, const guint8 *ip, guint16 port, guint16 requestnumber);
  1000 /* 0x0006 */ void aim_im_sendch2_odc_requestproxy(OscarData *od, guchar *cookie, const char *bn, const guint8 *ip, guint16 pin, guint16 requestnumber);
  1001 /* 0x0006 */ void aim_im_sendch2_sendfile_requestdirect(OscarData *od, guchar *cookie, const char *bn, const guint8 *ip, guint16 port, guint16 requestnumber, const gchar *filename, guint32 size, guint16 numfiles);
  1002 /* 0x0006 */ void aim_im_sendch2_sendfile_requestproxy(OscarData *od, guchar *cookie, const char *bn, const guint8 *ip, guint16 pin, guint16 requestnumber, const gchar *filename, guint32 size, guint16 numfiles);
  1003 
  1004 /* 0x0006 */ int aim_im_sendch2_geticqaway(OscarData *od, const char *bn, int type);
  1005 /* 0x0006 */ int aim_im_sendch4(OscarData *od, const char *bn, guint16 type, const char *message);
  1006 /* 0x0008 */ int aim_im_warn(OscarData *od, FlapConnection *conn, const char *destbn, guint32 flags);
  1007 /* 0x000b */ int aim_im_denytransfer(OscarData *od, const char *bn, const guchar *cookie, guint16 code);
  1008 /* 0x0010 */ int aim_im_reqofflinemsgs(OscarData *od);
  1009 /* 0x0014 */ int aim_im_sendmtn(OscarData *od, guint16 type1, const char *bn, guint16 type2);
  1010 void aim_icbm_makecookie(guchar* cookie);
  1011 gchar *oscar_encoding_extract(const char *encoding);
  1012 gchar *oscar_encoding_to_utf8(PurpleAccount *account, const char *encoding, const char *text, int textlen);
  1013 gchar *purple_plugin_oscar_decode_im_part(PurpleAccount *account, const char *sourcebn, guint16 charset, guint16 charsubset, const gchar *data, gsize datalen);
  1014 
  1015 
  1016 /* 0x0002 - family_locate.c */
  1017 /*
  1018  * AIM User Info, Standard Form.
  1019  */
  1020 #define AIM_FLAG_UNCONFIRMED     0x0001 /* "damned transients" */
  1021 #define AIM_FLAG_ADMINISTRATOR   0x0002
  1022 #define AIM_FLAG_AOL             0x0004
  1023 #define AIM_FLAG_OSCAR_PAY       0x0008
  1024 #define AIM_FLAG_FREE            0x0010
  1025 #define AIM_FLAG_AWAY            0x0020
  1026 #define AIM_FLAG_ICQ             0x0040
  1027 #define AIM_FLAG_WIRELESS        0x0080
  1028 #define AIM_FLAG_UNKNOWN100      0x0100
  1029 #define AIM_FLAG_UNKNOWN200      0x0200
  1030 #define AIM_FLAG_ACTIVEBUDDY     0x0400
  1031 #define AIM_FLAG_UNKNOWN800      0x0800
  1032 #define AIM_FLAG_ABINTERNAL      0x1000
  1033 #define AIM_FLAG_ALLUSERS        0x001f
  1034 
  1035 #define AIM_USERINFO_PRESENT_FLAGS        0x00000001
  1036 #define AIM_USERINFO_PRESENT_MEMBERSINCE  0x00000002
  1037 #define AIM_USERINFO_PRESENT_ONLINESINCE  0x00000004
  1038 #define AIM_USERINFO_PRESENT_IDLE         0x00000008
  1039 #define AIM_USERINFO_PRESENT_ICQEXTSTATUS 0x00000010
  1040 #define AIM_USERINFO_PRESENT_ICQIPADDR    0x00000020
  1041 #define AIM_USERINFO_PRESENT_ICQDATA      0x00000040
  1042 #define AIM_USERINFO_PRESENT_CAPABILITIES 0x00000080
  1043 #define AIM_USERINFO_PRESENT_SESSIONLEN   0x00000100
  1044 #define AIM_USERINFO_PRESENT_CREATETIME   0x00000200
  1045 
  1046 struct userinfo_node
  1047 {
  1048 	char *bn;
  1049 	struct userinfo_node *next;
  1050 };
  1051 
  1052 typedef struct aim_userinfo_s
  1053 {
  1054 	char *bn;
  1055 	guint16 warnlevel; /* evil percent * 10 (999 = 99.9%) */
  1056 	guint16 idletime; /* in seconds */
  1057 	guint16 flags;
  1058 	guint32 createtime; /* time_t */
  1059 	guint32 membersince; /* time_t */
  1060 	guint32 onlinesince; /* time_t */
  1061 	guint32 sessionlen;  /* in seconds */
  1062 	guint32 capabilities;
  1063 	struct {
  1064 		guint32 status;
  1065 		guint32 ipaddr;
  1066 		guint8 crap[0x25]; /* until we figure it out... */
  1067 	} icqinfo;
  1068 	guint32 present;
  1069 
  1070 	guint8 iconcsumtype;
  1071 	guint16 iconcsumlen;
  1072 	guint8 *iconcsum;
  1073 
  1074 	char *info;
  1075 	char *info_encoding;
  1076 	guint16 info_len;
  1077 
  1078 	char *status;
  1079 	char *status_encoding;
  1080 	guint16 status_len;
  1081 
  1082 	char *itmsurl;
  1083 	char *itmsurl_encoding;
  1084 	guint16 itmsurl_len;
  1085 
  1086 	char *away;
  1087 	char *away_encoding;
  1088 	guint16 away_len;
  1089 
  1090 	struct aim_userinfo_s *next;
  1091 } aim_userinfo_t;
  1092 
  1093 #define AIM_SENDMEMBLOCK_FLAG_ISREQUEST  0
  1094 #define AIM_SENDMEMBLOCK_FLAG_ISHASH     1
  1095 
  1096 int aim_sendmemblock(OscarData *od, FlapConnection *conn, guint32 offset, guint32 len, const guint8 *buf, guint8 flag);
  1097 
  1098 struct aim_invite_priv
  1099 {
  1100 	char *bn;
  1101 	char *roomname;
  1102 	guint16 exchange;
  1103 	guint16 instance;
  1104 };
  1105 
  1106 #define AIM_COOKIETYPE_UNKNOWN  0x00
  1107 #define AIM_COOKIETYPE_ICBM     0x01
  1108 #define AIM_COOKIETYPE_ADS      0x02
  1109 #define AIM_COOKIETYPE_BOS      0x03
  1110 #define AIM_COOKIETYPE_IM       0x04
  1111 #define AIM_COOKIETYPE_CHAT     0x05
  1112 #define AIM_COOKIETYPE_CHATNAV  0x06
  1113 #define AIM_COOKIETYPE_INVITE   0x07
  1114 /* we'll move OFT up a bit to give breathing room.  not like it really
  1115  * matters. */
  1116 #define AIM_COOKIETYPE_OFTIM    0x10
  1117 #define AIM_COOKIETYPE_OFTGET   0x11
  1118 #define AIM_COOKIETYPE_OFTSEND  0x12
  1119 #define AIM_COOKIETYPE_OFTVOICE 0x13
  1120 #define AIM_COOKIETYPE_OFTIMAGE 0x14
  1121 #define AIM_COOKIETYPE_OFTICON  0x15
  1122 
  1123 aim_userinfo_t *aim_locate_finduserinfo(OscarData *od, const char *bn);
  1124 void aim_locate_dorequest(OscarData *od);
  1125 
  1126 /* 0x0002 */ int aim_locate_reqrights(OscarData *od);
  1127 /* 0x0004 */ int aim_locate_setcaps(OscarData *od, guint32 caps);
  1128 /* 0x0004 */ int aim_locate_setprofile(OscarData *od, const char *profile_encoding, const gchar *profile, const int profile_len, const char *awaymsg_encoding, const gchar *awaymsg, const int awaymsg_len);
  1129 /* 0x0005 */ int aim_locate_getinfo(OscarData *od, const char *, guint16);
  1130 /* 0x0009 */ int aim_locate_setdirinfo(OscarData *od, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, guint16 privacy);
  1131 /* 0x000b */ int aim_locate_000b(OscarData *od, const char *bn);
  1132 /* 0x000f */ int aim_locate_setinterests(OscarData *od, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, guint16 privacy);
  1133 /* 0x0015 */ int aim_locate_getinfoshort(OscarData *od, const char *bn, guint32 flags);
  1134 
  1135 guint32 aim_locate_getcaps(OscarData *od, ByteStream *bs, int len);
  1136 guint32 aim_locate_getcaps_short(OscarData *od, ByteStream *bs, int len);
  1137 void aim_info_free(aim_userinfo_t *);
  1138 int aim_info_extract(OscarData *od, ByteStream *bs, aim_userinfo_t *);
  1139 int aim_putuserinfo(ByteStream *bs, aim_userinfo_t *info);
  1140 
  1141 
  1142 
  1143 /* 0x0003 - family_buddy.c */
  1144 /* 0x0002 */ void aim_buddylist_reqrights(OscarData *, FlapConnection *);
  1145 /* 0x0004 */ int aim_buddylist_set(OscarData *, FlapConnection *, const char *);
  1146 /* 0x0004 */ int aim_buddylist_addbuddy(OscarData *, FlapConnection *, const char *);
  1147 /* 0x0005 */ int aim_buddylist_removebuddy(OscarData *, FlapConnection *, const char *);
  1148 
  1149 
  1150 
  1151 /* 0x000a - family_userlookup.c */
  1152 int aim_search_address(OscarData *, const char *);
  1153 
  1154 
  1155 
  1156 /* 0x000d - family_chatnav.c */
  1157 /* 0x000e - family_chat.c */
  1158 /* These apply to exchanges as well. */
  1159 #define AIM_CHATROOM_FLAG_EVILABLE 0x0001
  1160 #define AIM_CHATROOM_FLAG_NAV_ONLY 0x0002
  1161 #define AIM_CHATROOM_FLAG_INSTANCING_ALLOWED 0x0004
  1162 #define AIM_CHATROOM_FLAG_OCCUPANT_PEEK_ALLOWED 0x0008
  1163 
  1164 struct aim_chat_exchangeinfo
  1165 {
  1166 	guint16 number;
  1167 	guint16 flags;
  1168 	char *name;
  1169 	char *charset1;
  1170 	char *lang1;
  1171 	char *charset2;
  1172 	char *lang2;
  1173 };
  1174 
  1175 #define AIM_CHATFLAGS_NOREFLECT 0x0001
  1176 #define AIM_CHATFLAGS_AWAY      0x0002
  1177 int aim_chat_send_im(OscarData *od, FlapConnection *conn, guint16 flags, const gchar *msg, int msglen, const char *encoding, const char *language);
  1178 int aim_chat_join(OscarData *od, guint16 exchange, const char *roomname, guint16 instance);
  1179 int aim_chat_attachname(FlapConnection *conn, guint16 exchange, const char *roomname, guint16 instance);
  1180 char *aim_chat_getname(FlapConnection *conn);
  1181 FlapConnection *aim_chat_getconn(OscarData *, const char *name);
  1182 
  1183 void aim_chatnav_reqrights(OscarData *od, FlapConnection *conn);
  1184 
  1185 int aim_chatnav_createroom(OscarData *od, FlapConnection *conn, const char *name, guint16 exchange);
  1186 int aim_chat_leaveroom(OscarData *od, const char *name);
  1187 
  1188 
  1189 
  1190 /* 0x000f - family_odir.c */
  1191 struct aim_odir
  1192 {
  1193 	char *first;
  1194 	char *last;
  1195 	char *middle;
  1196 	char *maiden;
  1197 	char *email;
  1198 	char *country;
  1199 	char *state;
  1200 	char *city;
  1201 	char *bn;
  1202 	char *interest;
  1203 	char *nick;
  1204 	char *zip;
  1205 	char *region;
  1206 	char *address;
  1207 	struct aim_odir *next;
  1208 };
  1209 
  1210 int aim_odir_email(OscarData *, const char *, const char *);
  1211 int aim_odir_name(OscarData *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *);
  1212 int aim_odir_interest(OscarData *, const char *, const char *);
  1213 
  1214 
  1215 
  1216 /* 0x0010 - family_bart.c */
  1217 int aim_bart_upload(OscarData *od, const guint8 *icon, guint16 iconlen);
  1218 int aim_bart_request(OscarData *od, const char *bn, guint8 iconcsumtype, const guint8 *iconstr, guint16 iconstrlen);
  1219 
  1220 
  1221 
  1222 /* 0x0013 - family_feedbag.c */
  1223 #define AIM_SSI_TYPE_BUDDY		0x0000
  1224 #define AIM_SSI_TYPE_GROUP		0x0001
  1225 #define AIM_SSI_TYPE_PERMIT		0x0002
  1226 #define AIM_SSI_TYPE_DENY		0x0003
  1227 #define AIM_SSI_TYPE_PDINFO		0x0004
  1228 #define AIM_SSI_TYPE_PRESENCEPREFS	0x0005
  1229 #define AIM_SSI_TYPE_ICONINFO		0x0014
  1230 
  1231 #define AIM_SSI_ACK_SUCCESS		0x0000
  1232 #define AIM_SSI_ACK_ITEMNOTFOUND	0x0002
  1233 #define AIM_SSI_ACK_IDNUMINUSE		0x000a
  1234 #define AIM_SSI_ACK_ATMAX		0x000c
  1235 #define AIM_SSI_ACK_INVALIDNAME		0x000d
  1236 #define AIM_SSI_ACK_AUTHREQUIRED	0x000e
  1237 
  1238 /* These flags are set in the 0x00c9 TLV of SSI teyp 0x0005 */
  1239 #define AIM_SSI_PRESENCE_FLAG_SHOWIDLE        0x00000400
  1240 #define AIM_SSI_PRESENCE_FLAG_NORECENTBUDDIES 0x00020000
  1241 
  1242 struct aim_ssi_item
  1243 {
  1244 	char *name;
  1245 	guint16 gid;
  1246 	guint16 bid;
  1247 	guint16 type;
  1248 	GSList *data;
  1249 	struct aim_ssi_item *next;
  1250 };
  1251 
  1252 struct aim_ssi_tmp
  1253 {
  1254 	guint16 action;
  1255 	guint16 ack;
  1256 	char *name;
  1257 	struct aim_ssi_item *item;
  1258 	struct aim_ssi_tmp *next;
  1259 };
  1260 
  1261 /* These build the actual SNACs and queue them to be sent */
  1262 /* 0x0002 */ int aim_ssi_reqrights(OscarData *od);
  1263 /* 0x0004 */ int aim_ssi_reqdata(OscarData *od);
  1264 /* 0x0005 */ int aim_ssi_reqifchanged(OscarData *od, time_t localstamp, guint16 localrev);
  1265 /* 0x0007 */ int aim_ssi_enable(OscarData *od);
  1266 /* 0x0011 */ int aim_ssi_modbegin(OscarData *od);
  1267 /* 0x0012 */ int aim_ssi_modend(OscarData *od);
  1268 /* 0x0014 */ int aim_ssi_sendauth(OscarData *od, char *bn, char *msg);
  1269 /* 0x0018 */ int aim_ssi_sendauthrequest(OscarData *od, char *bn, const char *msg);
  1270 /* 0x001a */ int aim_ssi_sendauthreply(OscarData *od, char *bn, guint8 reply, const char *msg);
  1271 
  1272 /* Client functions for retrieving SSI data */
  1273 struct aim_ssi_item *aim_ssi_itemlist_find(struct aim_ssi_item *list, guint16 gid, guint16 bid);
  1274 struct aim_ssi_item *aim_ssi_itemlist_finditem(struct aim_ssi_item *list, const char *gn, const char *bn, guint16 type);
  1275 struct aim_ssi_item *aim_ssi_itemlist_exists(struct aim_ssi_item *list, const char *bn);
  1276 char *aim_ssi_itemlist_findparentname(struct aim_ssi_item *list, const char *bn);
  1277 int aim_ssi_getpermdeny(struct aim_ssi_item *list);
  1278 guint32 aim_ssi_getpresence(struct aim_ssi_item *list);
  1279 char *aim_ssi_getalias(struct aim_ssi_item *list, const char *gn, const char *bn);
  1280 char *aim_ssi_getcomment(struct aim_ssi_item *list, const char *gn, const char *bn);
  1281 gboolean aim_ssi_waitingforauth(struct aim_ssi_item *list, const char *gn, const char *bn);
  1282 
  1283 /* Client functions for changing SSI data */
  1284 int aim_ssi_addbuddy(OscarData *od, const char *name, const char *group, GSList *tlvlist, const char *alias, const char *comment, const char *smsnum, gboolean needauth);
  1285 int aim_ssi_addpermit(OscarData *od, const char *name);
  1286 int aim_ssi_adddeny(OscarData *od, const char *name);
  1287 int aim_ssi_delbuddy(OscarData *od, const char *name, const char *group);
  1288 int aim_ssi_delgroup(OscarData *od, const char *group);
  1289 int aim_ssi_delpermit(OscarData *od, const char *name);
  1290 int aim_ssi_deldeny(OscarData *od, const char *name);
  1291 int aim_ssi_movebuddy(OscarData *od, const char *oldgn, const char *newgn, const char *bn);
  1292 int aim_ssi_aliasbuddy(OscarData *od, const char *gn, const char *bn, const char *alias);
  1293 int aim_ssi_editcomment(OscarData *od, const char *gn, const char *bn, const char *alias);
  1294 int aim_ssi_rename_group(OscarData *od, const char *oldgn, const char *newgn);
  1295 int aim_ssi_cleanlist(OscarData *od);
  1296 int aim_ssi_deletelist(OscarData *od);
  1297 int aim_ssi_setpermdeny(OscarData *od, guint8 permdeny, guint32 vismask);
  1298 int aim_ssi_setpresence(OscarData *od, guint32 presence);
  1299 int aim_ssi_seticon(OscarData *od, const guint8 *iconsum, guint8 iconsumlen);
  1300 int aim_ssi_delicon(OscarData *od);
  1301 
  1302 
  1303 
  1304 /* 0x0015 - family_icq.c */
  1305 #define AIM_ICQ_INFO_SIMPLE	0x001
  1306 #define AIM_ICQ_INFO_SUMMARY	0x002
  1307 #define AIM_ICQ_INFO_EMAIL	0x004
  1308 #define AIM_ICQ_INFO_PERSONAL	0x008
  1309 #define AIM_ICQ_INFO_ADDITIONAL	0x010
  1310 #define AIM_ICQ_INFO_WORK	0x020
  1311 #define AIM_ICQ_INFO_INTERESTS	0x040
  1312 #define AIM_ICQ_INFO_ORGS	0x080
  1313 #define AIM_ICQ_INFO_UNKNOWN	0x100
  1314 #define AIM_ICQ_INFO_HAVEALL	0x1ff
  1315 
  1316 #ifdef OLDSTYLE_ICQ_OFFLINEMSGS
  1317 struct aim_icq_offlinemsg
  1318 {
  1319 	guint32 sender;
  1320 	guint16 year;
  1321 	guint8 month, day, hour, minute;
  1322 	guint8 type;
  1323 	guint8 flags;
  1324 	char *msg;
  1325 	int msglen;
  1326 };
  1327 #endif /* OLDSTYLE_ICQ_OFFLINEMSGS */
  1328 
  1329 struct aim_icq_info
  1330 {
  1331 	guint16 reqid;
  1332 
  1333 	/* simple */
  1334 	guint32 uin;
  1335 
  1336 	/* general and "home" information (0x00c8) */
  1337 	char *nick;
  1338 	char *first;
  1339 	char *last;
  1340 	char *email;
  1341 	char *homecity;
  1342 	char *homestate;
  1343 	char *homephone;
  1344 	char *homefax;
  1345 	char *homeaddr;
  1346 	char *mobile;
  1347 	char *homezip;
  1348 	guint16 homecountry;
  1349 /*	guint8 timezone;
  1350 	guint8 hideemail; */
  1351 
  1352 	/* personal (0x00dc) */
  1353 	guint8 age;
  1354 	guint8 unknown;
  1355 	guint8 gender;
  1356 	char *personalwebpage;
  1357 	guint16 birthyear;
  1358 	guint8 birthmonth;
  1359 	guint8 birthday;
  1360 	guint8 language1;
  1361 	guint8 language2;
  1362 	guint8 language3;
  1363 
  1364 	/* work (0x00d2) */
  1365 	char *workcity;
  1366 	char *workstate;
  1367 	char *workphone;
  1368 	char *workfax;
  1369 	char *workaddr;
  1370 	char *workzip;
  1371 	guint16 workcountry;
  1372 	char *workcompany;
  1373 	char *workdivision;
  1374 	char *workposition;
  1375 	char *workwebpage;
  1376 
  1377 	/* additional personal information (0x00e6) */
  1378 	char *info;
  1379 
  1380 	/* email (0x00eb) */
  1381 	guint16 numaddresses;
  1382 	char **email2;
  1383 
  1384 	/* we keep track of these in a linked list because we're 1337 */
  1385 	struct aim_icq_info *next;
  1386 
  1387 	/* status note info */
  1388 	guint8 icbm_cookie[8];
  1389 	char *status_note_title;
  1390 };
  1391 
  1392 #ifdef OLDSTYLE_ICQ_OFFLINEMSGS
  1393 int aim_icq_reqofflinemsgs(OscarData *od);
  1394 int aim_icq_ackofflinemsgs(OscarData *od);
  1395 #endif
  1396 int aim_icq_setsecurity(OscarData *od, gboolean auth_required, gboolean webaware);
  1397 int aim_icq_changepasswd(OscarData *od, const char *passwd);
  1398 int aim_icq_getsimpleinfo(OscarData *od, const char *uin);
  1399 int aim_icq_getalias(OscarData *od, const char *uin);
  1400 int aim_icq_getallinfo(OscarData *od, const char *uin);
  1401 int aim_icq_sendsms(OscarData *od, const char *name, const char *msg, const char *alias);
  1402 
  1403 
  1404 /* 0x0017 - family_auth.c */
  1405 void aim_sendcookie(OscarData *, FlapConnection *, const guint16 length, const guint8 *);
  1406 void aim_admin_changepasswd(OscarData *, FlapConnection *, const char *newpw, const char *curpw);
  1407 void aim_admin_reqconfirm(OscarData *od, FlapConnection *conn);
  1408 void aim_admin_getinfo(OscarData *od, FlapConnection *conn, guint16 info);
  1409 void aim_admin_setemail(OscarData *od, FlapConnection *conn, const char *newemail);
  1410 void aim_admin_setnick(OscarData *od, FlapConnection *conn, const char *newnick);
  1411 
  1412 
  1413 
  1414 /* 0x0018 - family_alert.c */
  1415 struct aim_emailinfo
  1416 {
  1417 	guint8 *cookie16;
  1418 	guint8 *cookie8;
  1419 	char *url;
  1420 	guint16 nummsgs;
  1421 	guint8 unread;
  1422 	char *domain;
  1423 	guint16 flag;
  1424 	struct aim_emailinfo *next;
  1425 };
  1426 
  1427 int aim_email_sendcookies(OscarData *od);
  1428 int aim_email_activate(OscarData *od);
  1429 
  1430 
  1431 
  1432 /* tlv.c - TLV handling */
  1433 
  1434 /* TLV structure */
  1435 typedef struct aim_tlv_s
  1436 {
  1437 	guint16 type;
  1438 	guint16 length;
  1439 	guint8 *value;
  1440 } aim_tlv_t;
  1441 
  1442 /* TLV handling functions */
  1443 char *aim_tlv_getvalue_as_string(aim_tlv_t *tlv);
  1444 
  1445 aim_tlv_t *aim_tlv_gettlv(GSList *list, const guint16 type, const int nth);
  1446 int aim_tlv_getlength(GSList *list, const guint16 type, const int nth);
  1447 char *aim_tlv_getstr(GSList *list, const guint16 type, const int nth);
  1448 guint8 aim_tlv_get8(GSList *list, const guint16 type, const int nth);
  1449 guint16 aim_tlv_get16(GSList *list, const guint16 type, const int nth);
  1450 guint32 aim_tlv_get32(GSList *list, const guint16 type, const int nth);
  1451 
  1452 /* TLV list handling functions */
  1453 GSList *aim_tlvlist_read(ByteStream *bs);
  1454 GSList *aim_tlvlist_readnum(ByteStream *bs, guint16 num);
  1455 GSList *aim_tlvlist_readlen(ByteStream *bs, guint16 len);
  1456 GSList *aim_tlvlist_copy(GSList *orig);
  1457 
  1458 int aim_tlvlist_count(GSList *list);
  1459 int aim_tlvlist_size(GSList *list);
  1460 int aim_tlvlist_cmp(GSList *one, GSList *two);
  1461 int aim_tlvlist_write(ByteStream *bs, GSList **list);
  1462 void aim_tlvlist_free(GSList *list);
  1463 
  1464 int aim_tlvlist_add_raw(GSList **list, const guint16 type, const guint16 length, const guint8 *value);
  1465 int aim_tlvlist_add_noval(GSList **list, const guint16 type);
  1466 int aim_tlvlist_add_8(GSList **list, const guint16 type, const guint8 value);
  1467 int aim_tlvlist_add_16(GSList **list, const guint16 type, const guint16 value);
  1468 int aim_tlvlist_add_32(GSList **list, const guint16 type, const guint32 value);
  1469 int aim_tlvlist_add_str(GSList **list, const guint16 type, const char *value);
  1470 int aim_tlvlist_add_caps(GSList **list, const guint16 type, const guint32 caps);
  1471 int aim_tlvlist_add_userinfo(GSList **list, guint16 type, aim_userinfo_t *userinfo);
  1472 int aim_tlvlist_add_chatroom(GSList **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance);
  1473 int aim_tlvlist_add_frozentlvlist(GSList **list, guint16 type, GSList **tl);
  1474 
  1475 int aim_tlvlist_replace_raw(GSList **list, const guint16 type, const guint16 lenth, const guint8 *value);
  1476 int aim_tlvlist_replace_str(GSList **list, const guint16 type, const char *str);
  1477 int aim_tlvlist_replace_noval(GSList **list, const guint16 type);
  1478 int aim_tlvlist_replace_8(GSList **list, const guint16 type, const guint8 value);
  1479 int aim_tlvlist_replace_16(GSList **list, const guint16 type, const guint16 value);
  1480 int aim_tlvlist_replace_32(GSList **list, const guint16 type, const guint32 value);
  1481 
  1482 void aim_tlvlist_remove(GSList **list, const guint16 type);
  1483 
  1484 
  1485 
  1486 /* util.c */
  1487 /* These are really ugly.  You'd think this was LISP.  I wish it was. */
  1488 #define aimutil_put8(buf, data) ((*(buf) = (guint8)(data)&0xff),1)
  1489 #define aimutil_get8(buf) ((*(buf))&0xff)
  1490 #define aimutil_put16(buf, data) ( \
  1491 		(*(buf) = (guint8)((data)>>8)&0xff), \
  1492 		(*((buf)+1) = (guint8)(data)&0xff),  \
  1493 		2)
  1494 #define aimutil_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
  1495 #define aimutil_put32(buf, data) ( \
  1496 		(*((buf)) = (guint8)((data)>>24)&0xff), \
  1497 		(*((buf)+1) = (guint8)((data)>>16)&0xff), \
  1498 		(*((buf)+2) = (guint8)((data)>>8)&0xff), \
  1499 		(*((buf)+3) = (guint8)(data)&0xff), \
  1500 		4)
  1501 #define aimutil_get32(buf) ((((*(buf))<<24)&0xff000000) + \
  1502 		(((*((buf)+1))<<16)&0x00ff0000) + \
  1503 		(((*((buf)+2))<< 8)&0x0000ff00) + \
  1504 		(((*((buf)+3)    )&0x000000ff)))
  1505 
  1506 /* Little-endian versions (damn ICQ) */
  1507 #define aimutil_putle8(buf, data) ( \
  1508 		(*(buf) = (guint8)(data) & 0xff), \
  1509 		1)
  1510 #define aimutil_getle8(buf) ( \
  1511 		(*(buf)) & 0xff \
  1512 		)
  1513 #define aimutil_putle16(buf, data) ( \
  1514 		(*((buf)+0) = (guint8)((data) >> 0) & 0xff),  \
  1515 		(*((buf)+1) = (guint8)((data) >> 8) & 0xff), \
  1516 		2)
  1517 #define aimutil_getle16(buf) ( \
  1518 		(((*((buf)+0)) << 0) & 0x00ff) + \
  1519 		(((*((buf)+1)) << 8) & 0xff00) \
  1520 		)
  1521 #define aimutil_putle32(buf, data) ( \
  1522 		(*((buf)+0) = (guint8)((data) >>  0) & 0xff), \
  1523 		(*((buf)+1) = (guint8)((data) >>  8) & 0xff), \
  1524 		(*((buf)+2) = (guint8)((data) >> 16) & 0xff), \
  1525 		(*((buf)+3) = (guint8)((data) >> 24) & 0xff), \
  1526 		4)
  1527 #define aimutil_getle32(buf) ( \
  1528 		(((*((buf)+0)) <<  0) & 0x000000ff) + \
  1529 		(((*((buf)+1)) <<  8) & 0x0000ff00) + \
  1530 		(((*((buf)+2)) << 16) & 0x00ff0000) + \
  1531 		(((*((buf)+3)) << 24) & 0xff000000))
  1532 
  1533 int oscar_get_ui_info_int(const char *str, int default_value);
  1534 const char *oscar_get_ui_info_string(const char *str, const char *default_value);
  1535 gchar *oscar_get_clientstring(void);
  1536 
  1537 guint16 aimutil_iconsum(const guint8 *buf, int buflen);
  1538 int aimutil_tokslen(char *toSearch, int theindex, char dl);
  1539 int aimutil_itemcnt(char *toSearch, char dl);
  1540 char *aimutil_itemindex(char *toSearch, int theindex, char dl);
  1541 
  1542 gboolean oscar_util_valid_name(const char *bn);
  1543 gboolean oscar_util_valid_name_icq(const char *bn);
  1544 gboolean oscar_util_valid_name_sms(const char *bn);
  1545 int oscar_util_name_compare(const char *bn1, const char *bn2);
  1546 
  1547 
  1548 
  1549 
  1550 typedef struct {
  1551 	guint16 family;
  1552 	guint16 subtype;
  1553 	guint16 flags;
  1554 	guint32 id;
  1555 } aim_modsnac_t;
  1556 
  1557 #define AIM_MODULENAME_MAXLEN 16
  1558 #define AIM_MODFLAG_MULTIFAMILY 0x0001
  1559 typedef struct aim_module_s
  1560 {
  1561 	guint16 family;
  1562 	guint16 version;
  1563 	guint16 toolid;
  1564 	guint16 toolversion;
  1565 	guint16 flags;
  1566 	char name[AIM_MODULENAME_MAXLEN+1];
  1567 	int (*snachandler)(OscarData *od, FlapConnection *conn, struct aim_module_s *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs);
  1568 	void (*shutdown)(OscarData *od, struct aim_module_s *mod);
  1569 	void *priv;
  1570 	struct aim_module_s *next;
  1571 } aim_module_t;
  1572 
  1573 int aim__registermodule(OscarData *od, int (*modfirst)(OscarData *, aim_module_t *));
  1574 void aim__shutdownmodules(OscarData *od);
  1575 aim_module_t *aim__findmodulebygroup(OscarData *od, guint16 group);
  1576 aim_module_t *aim__findmodule(OscarData *od, const char *name);
  1577 
  1578 int admin_modfirst(OscarData *od, aim_module_t *mod);
  1579 int buddylist_modfirst(OscarData *od, aim_module_t *mod);
  1580 int bos_modfirst(OscarData *od, aim_module_t *mod);
  1581 int search_modfirst(OscarData *od, aim_module_t *mod);
  1582 int stats_modfirst(OscarData *od, aim_module_t *mod);
  1583 int auth_modfirst(OscarData *od, aim_module_t *mod);
  1584 int msg_modfirst(OscarData *od, aim_module_t *mod);
  1585 int misc_modfirst(OscarData *od, aim_module_t *mod);
  1586 int chatnav_modfirst(OscarData *od, aim_module_t *mod);
  1587 int chat_modfirst(OscarData *od, aim_module_t *mod);
  1588 int locate_modfirst(OscarData *od, aim_module_t *mod);
  1589 int service_modfirst(OscarData *od, aim_module_t *mod);
  1590 int invite_modfirst(OscarData *od, aim_module_t *mod);
  1591 int translate_modfirst(OscarData *od, aim_module_t *mod);
  1592 int popups_modfirst(OscarData *od, aim_module_t *mod);
  1593 int adverts_modfirst(OscarData *od, aim_module_t *mod);
  1594 int odir_modfirst(OscarData *od, aim_module_t *mod);
  1595 int bart_modfirst(OscarData *od, aim_module_t *mod);
  1596 int ssi_modfirst(OscarData *od, aim_module_t *mod);
  1597 int icq_modfirst(OscarData *od, aim_module_t *mod);
  1598 int email_modfirst(OscarData *od, aim_module_t *mod);
  1599 
  1600 void aim_genericreq_n(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype);
  1601 void aim_genericreq_n_snacid(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype);
  1602 void aim_genericreq_l(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint32 *);
  1603 void aim_genericreq_s(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint16 *);
  1604 
  1605 /* bstream.c */
  1606 int byte_stream_new(ByteStream *bs, guint32 len);
  1607 int byte_stream_init(ByteStream *bs, guint8 *data, int len);
  1608 void byte_stream_destroy(ByteStream *bs);
  1609 int byte_stream_empty(ByteStream *bs);
  1610 int byte_stream_curpos(ByteStream *bs);
  1611 int byte_stream_setpos(ByteStream *bs, unsigned int off);
  1612 void byte_stream_rewind(ByteStream *bs);
  1613 int byte_stream_advance(ByteStream *bs, int n);
  1614 guint8 byte_stream_get8(ByteStream *bs);
  1615 guint16 byte_stream_get16(ByteStream *bs);
  1616 guint32 byte_stream_get32(ByteStream *bs);
  1617 guint8 byte_stream_getle8(ByteStream *bs);
  1618 guint16 byte_stream_getle16(ByteStream *bs);
  1619 guint32 byte_stream_getle32(ByteStream *bs);
  1620 int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, int len);
  1621 guint8 *byte_stream_getraw(ByteStream *bs, int len);
  1622 char *byte_stream_getstr(ByteStream *bs, int len);
  1623 int byte_stream_put8(ByteStream *bs, guint8 v);
  1624 int byte_stream_put16(ByteStream *bs, guint16 v);
  1625 int byte_stream_put32(ByteStream *bs, guint32 v);
  1626 int byte_stream_putle8(ByteStream *bs, guint8 v);
  1627 int byte_stream_putle16(ByteStream *bs, guint16 v);
  1628 int byte_stream_putle32(ByteStream *bs, guint32 v);
  1629 int byte_stream_putraw(ByteStream *bs, const guint8 *v, int len);
  1630 int byte_stream_putstr(ByteStream *bs, const char *str);
  1631 int byte_stream_putbs(ByteStream *bs, ByteStream *srcbs, int len);
  1632 int byte_stream_putuid(ByteStream *bs, OscarData *od);
  1633 int byte_stream_putcaps(ByteStream *bs, guint32 caps);
  1634 
  1635 /**
  1636  * Inserts a BART asset block into the given byte stream.  The flags
  1637  * and length are set appropriately based on the value of data.
  1638  */
  1639 void byte_stream_put_bart_asset(ByteStream *bs, guint16 type, ByteStream *data);
  1640 
  1641 /**
  1642  * A helper function that calls byte_stream_put_bart_asset with the
  1643  * appropriate data ByteStream given the datastr.
  1644  */
  1645 void byte_stream_put_bart_asset_str(ByteStream *bs, guint16 type, const char *datastr);
  1646 
  1647 /*
  1648  * Generic SNAC structure.  Rarely if ever used.
  1649  */
  1650 typedef struct aim_snac_s {
  1651 	aim_snacid_t id;
  1652 	guint16 family;
  1653 	guint16 type;
  1654 	guint16 flags;
  1655 	void *data;
  1656 	time_t issuetime;
  1657 	struct aim_snac_s *next;
  1658 } aim_snac_t;
  1659 
  1660 /* snac.c */
  1661 void aim_initsnachash(OscarData *od);
  1662 aim_snacid_t aim_newsnac(OscarData *, aim_snac_t *newsnac);
  1663 aim_snacid_t aim_cachesnac(OscarData *od, const guint16 family, const guint16 type, const guint16 flags, const void *data, const int datalen);
  1664 aim_snac_t *aim_remsnac(OscarData *, aim_snacid_t id);
  1665 void aim_cleansnacs(OscarData *, int maxage);
  1666 int aim_putsnac(ByteStream *, guint16 family, guint16 type, guint16 flags, aim_snacid_t id);
  1667 
  1668 struct chatsnacinfo {
  1669 	guint16 exchange;
  1670 	char name[128];
  1671 	guint16 instance;
  1672 };
  1673 
  1674 struct rateclass {
  1675 	guint16 classid;
  1676 	guint32 windowsize;
  1677 	guint32 clear;
  1678 	guint32 alert;
  1679 	guint32 limit;
  1680 	guint32 disconnect;
  1681 	guint32 current;
  1682 	guint32 max;
  1683 	guint8 unknown[5]; /* only present in versions >= 3 */
  1684 	GHashTable *members; /* Key is family and subtype, value is TRUE. */
  1685 
  1686 	struct timeval last; /**< The time when we last sent a SNAC of this rate class. */
  1687 };
  1688 
  1689 int aim_cachecookie(OscarData *od, IcbmCookie *cookie);
  1690 IcbmCookie *aim_uncachecookie(OscarData *od, guint8 *cookie, int type);
  1691 IcbmCookie *aim_mkcookie(guint8 *, int, void *);
  1692 IcbmCookie *aim_checkcookie(OscarData *, const unsigned char *, const int);
  1693 int aim_freecookie(OscarData *od, IcbmCookie *cookie);
  1694 int aim_msgcookie_gettype(int type);
  1695 int aim_cookie_free(OscarData *od, IcbmCookie *cookie);
  1696 
  1697 int aim_chat_readroominfo(ByteStream *bs, struct aim_chat_roominfo *outinfo);
  1698 
  1699 void flap_connection_destroy_chat(OscarData *od, FlapConnection *conn);
  1700 
  1701 #ifdef __cplusplus
  1702 }
  1703 #endif
  1704 
  1705 #endif /* _OSCAR_H_ */