Frameworks/libpurple.framework/Versions/2.10.12r8d2874a79747/Headers/oscar.h
branchadium-1.5.11-merge
changeset 6013 f8d0dc659e3f
parent 5941 307f53385811
parent 6012 200a01709ba4
child 6014 fcb71cb71a3d
child 6015 2b01cc935b7c
equal deleted inserted replaced
5941:307f53385811 6013:f8d0dc659e3f
     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 "internal.h"
       
    33 #include "circbuffer.h"
       
    34 #include "debug.h"
       
    35 #include "eventloop.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  * Found by trial and error.
       
   107  */
       
   108 #define MAXAVAILMSGLEN 251
       
   109 
       
   110 /**
       
   111  * Maximum length for the password of an ICQ account
       
   112  */
       
   113 #define MAXICQPASSLEN 8
       
   114 
       
   115 #define AIM_MD5_STRING "AOL Instant Messenger (SM)"
       
   116 
       
   117 /*
       
   118  * Client info.  Filled in by the client and passed in to
       
   119  * aim_send_login().  The information ends up getting passed to OSCAR
       
   120  * through the initial login command.
       
   121  *
       
   122  */
       
   123 struct _ClientInfo
       
   124 {
       
   125 	const char *clientstring;
       
   126 	guint16 clientid;
       
   127 	guint16 major;
       
   128 	guint16 minor;
       
   129 	guint16 point;
       
   130 	guint16 build;
       
   131 	guint32 distrib;
       
   132 	const char *country; /* two-letter abbrev */
       
   133 	const char *lang; /* two-letter abbrev */
       
   134 };
       
   135 
       
   136 /*
       
   137  * We need to use the major-minor-micro versions from the official
       
   138  * AIM and ICQ programs here or AOL won't let us use certain features.
       
   139  *
       
   140  * 0x00000611 is the distid given to us by AOL for use as the default
       
   141  * libpurple distid.
       
   142  */
       
   143 #define CLIENTINFO_PURPLE_AIM { \
       
   144 	NULL, \
       
   145 	0x0109, \
       
   146 	0x0005, 0x0001, \
       
   147 	0x0000, 0x0bdc, \
       
   148 	0x00000611, \
       
   149 	"us", "en", \
       
   150 }
       
   151 
       
   152 #define CLIENTINFO_PURPLE_ICQ { \
       
   153 	NULL, \
       
   154 	0x010a, \
       
   155 	0x0014, 0x0034, \
       
   156 	0x0000, 0x0c18, \
       
   157 	0x00000611, \
       
   158 	"us", "en", \
       
   159 }
       
   160 
       
   161 typedef enum
       
   162 {
       
   163 	OSCAR_DISCONNECT_DONE, /* not considered an error */
       
   164 	OSCAR_DISCONNECT_LOCAL_CLOSED, /* peer connections only, not considered an error */
       
   165 	OSCAR_DISCONNECT_REMOTE_CLOSED,
       
   166 	OSCAR_DISCONNECT_REMOTE_REFUSED, /* peer connections only */
       
   167 	OSCAR_DISCONNECT_LOST_CONNECTION,
       
   168 	OSCAR_DISCONNECT_INVALID_DATA,
       
   169 	OSCAR_DISCONNECT_COULD_NOT_CONNECT,
       
   170 	OSCAR_DISCONNECT_RETRYING /* peer connections only */
       
   171 } OscarDisconnectReason;
       
   172 
       
   173 #define OSCAR_CAPABILITY_BUDDYICON             0x0000000000000001LL
       
   174 #define OSCAR_CAPABILITY_TALK                  0x0000000000000002LL
       
   175 #define OSCAR_CAPABILITY_DIRECTIM              0x0000000000000004LL
       
   176 #define OSCAR_CAPABILITY_CHAT                  0x0000000000000008LL
       
   177 #define OSCAR_CAPABILITY_GETFILE               0x0000000000000010LL
       
   178 #define OSCAR_CAPABILITY_SENDFILE              0x0000000000000020LL
       
   179 #define OSCAR_CAPABILITY_GAMES                 0x0000000000000040LL
       
   180 #define OSCAR_CAPABILITY_ADDINS                0x0000000000000080LL
       
   181 #define OSCAR_CAPABILITY_SENDBUDDYLIST         0x0000000000000100LL
       
   182 #define OSCAR_CAPABILITY_GAMES2                0x0000000000000200LL
       
   183 #define OSCAR_CAPABILITY_ICQ_DIRECT            0x0000000000000400LL
       
   184 #define OSCAR_CAPABILITY_APINFO                0x0000000000000800LL
       
   185 #define OSCAR_CAPABILITY_ICQRTF                0x0000000000001000LL
       
   186 #define OSCAR_CAPABILITY_EMPTY                 0x0000000000002000LL
       
   187 #define OSCAR_CAPABILITY_ICQSERVERRELAY        0x0000000000004000LL
       
   188 #define OSCAR_CAPABILITY_UNICODEOLD            0x0000000000008000LL
       
   189 #define OSCAR_CAPABILITY_TRILLIANCRYPT         0x0000000000010000LL
       
   190 #define OSCAR_CAPABILITY_UNICODE               0x0000000000020000LL
       
   191 #define OSCAR_CAPABILITY_INTEROPERATE          0x0000000000040000LL
       
   192 #define OSCAR_CAPABILITY_SHORTCAPS             0x0000000000080000LL
       
   193 #define OSCAR_CAPABILITY_HIPTOP                0x0000000000100000LL
       
   194 #define OSCAR_CAPABILITY_SECUREIM              0x0000000000200000LL
       
   195 #define OSCAR_CAPABILITY_SMS                   0x0000000000400000LL
       
   196 #define OSCAR_CAPABILITY_VIDEO                 0x0000000000800000LL
       
   197 #define OSCAR_CAPABILITY_ICHATAV               0x0000000001000000LL
       
   198 #define OSCAR_CAPABILITY_LIVEVIDEO             0x0000000002000000LL
       
   199 #define OSCAR_CAPABILITY_CAMERA                0x0000000004000000LL
       
   200 #define OSCAR_CAPABILITY_ICHAT_SCREENSHARE     0x0000000008000000LL
       
   201 #define OSCAR_CAPABILITY_TYPING                0x0000000010000000LL
       
   202 #define OSCAR_CAPABILITY_NEWCAPS               0x0000000020000000LL
       
   203 #define OSCAR_CAPABILITY_XTRAZ                 0x0000000040000000LL
       
   204 #define OSCAR_CAPABILITY_GENERICUNKNOWN        0x0000000080000000LL
       
   205 #define OSCAR_CAPABILITY_HTML_MSGS             0x0000000100000000LL
       
   206 #define OSCAR_CAPABILITY_LAST                  0x0000000200000000LL
       
   207 
       
   208 #define OSCAR_STATUS_ID_INVISIBLE   "invisible"
       
   209 #define OSCAR_STATUS_ID_OFFLINE     "offline"
       
   210 #define OSCAR_STATUS_ID_AVAILABLE   "available"
       
   211 #define OSCAR_STATUS_ID_AWAY        "away"
       
   212 #define OSCAR_STATUS_ID_DND         "dnd"
       
   213 #define OSCAR_STATUS_ID_NA          "na"
       
   214 #define OSCAR_STATUS_ID_OCCUPIED    "occupied"
       
   215 #define OSCAR_STATUS_ID_FREE4CHAT   "free4chat"
       
   216 #define OSCAR_STATUS_ID_CUSTOM      "custom"
       
   217 #define OSCAR_STATUS_ID_MOBILE	    "mobile"
       
   218 #define OSCAR_STATUS_ID_EVIL        "evil"
       
   219 #define OSCAR_STATUS_ID_DEPRESSION	 "depression"
       
   220 #define OSCAR_STATUS_ID_ATHOME      "athome"
       
   221 #define OSCAR_STATUS_ID_ATWORK      "atwork"
       
   222 #define OSCAR_STATUS_ID_LUNCH       "lunch"
       
   223 
       
   224 /*
       
   225  * Byte Stream type. Sort of.
       
   226  *
       
   227  * Use of this type serves a couple purposes:
       
   228  *   - Buffer/buflen pairs are passed all around everywhere. This turns
       
   229  *     that into one value, as well as abstracting it slightly.
       
   230  *   - Through the abstraction, it is possible to enable bounds checking
       
   231  *     for robustness at the cost of performance.  But a clean failure on
       
   232  *     weird packets is much better than a segfault.
       
   233  *   - I like having variables named "bs".
       
   234  *
       
   235  * Don't touch the insides of this struct.  Or I'll have to kill you.
       
   236  *
       
   237  */
       
   238 struct _ByteStream
       
   239 {
       
   240 	guint8 *data;
       
   241 	size_t len;
       
   242 	size_t offset;
       
   243 };
       
   244 
       
   245 struct _QueuedSnac
       
   246 {
       
   247 	guint16 family;
       
   248 	guint16 subtype;
       
   249 	FlapFrame *frame;
       
   250 };
       
   251 
       
   252 struct _FlapFrame
       
   253 {
       
   254 	guint8 channel;
       
   255 	guint16 seqnum;
       
   256 	ByteStream data;        /* payload stream */
       
   257 };
       
   258 
       
   259 struct _FlapConnection
       
   260 {
       
   261 	OscarData *od;              /**< Pointer to parent session. */
       
   262 	gboolean connected;
       
   263 	time_t lastactivity;             /**< Time of last transmit. */
       
   264 	guint destroy_timeout;
       
   265 	OscarDisconnectReason disconnect_reason;
       
   266 	gchar *error_message;
       
   267 	guint16 disconnect_code;
       
   268 
       
   269 	/* A few variables that are only used when connecting */
       
   270 	PurpleProxyConnectData *connect_data;
       
   271 	guint16 cookielen;
       
   272 	guint8 *cookie;
       
   273 	gpointer new_conn_data;
       
   274 
       
   275 	int fd;
       
   276 	PurpleSslConnection *gsc;
       
   277 	guint8 header[6];
       
   278 	gssize header_received;
       
   279 	FlapFrame buffer_incoming;
       
   280 	PurpleCircBuffer *buffer_outgoing;
       
   281 	guint watcher_incoming;
       
   282 	guint watcher_outgoing;
       
   283 
       
   284 	guint16 type;
       
   285 	guint16 subtype;
       
   286 	guint16 seqnum_out; /**< The sequence number of most recently sent packet. */
       
   287 	guint16 seqnum_in; /**< The sequence number of most recently received packet. */
       
   288 	GSList *groups;
       
   289 	GSList *rateclasses; /* Contains nodes of struct rateclass. */
       
   290 	struct rateclass *default_rateclass;
       
   291 	GHashTable *rateclass_members; /* Key is family and subtype, value is pointer to the rateclass struct to use. */
       
   292 
       
   293 	GQueue *queued_snacs; /**< Contains QueuedSnacs. */
       
   294 	GQueue *queued_lowpriority_snacs; /**< Contains QueuedSnacs to send only once queued_snacs is empty */
       
   295 	guint queued_timeout;
       
   296 
       
   297 	void *internal; /* internal conn-specific libfaim data */
       
   298 };
       
   299 
       
   300 struct _IcbmCookie
       
   301 {
       
   302 	guchar cookie[8];
       
   303 	int type;
       
   304 	void *data;
       
   305 	time_t addtime;
       
   306 	struct _IcbmCookie *next;
       
   307 };
       
   308 
       
   309 #include "peer.h"
       
   310 
       
   311 /*
       
   312  * AIM Session: The main client-data interface.
       
   313  *
       
   314  */
       
   315 struct _OscarData
       
   316 {
       
   317 	/** Only used when connecting with clientLogin */
       
   318 	PurpleUtilFetchUrlData *url_data;
       
   319 
       
   320 	gboolean iconconnecting;
       
   321 	gboolean set_icon;
       
   322 
       
   323 	GSList *create_rooms;
       
   324 
       
   325 	gboolean conf;
       
   326 	gboolean reqemail;
       
   327 	gboolean setemail;
       
   328 	char *email;
       
   329 	gboolean setnick;
       
   330 	char *newformatting;
       
   331 	gboolean chpass;
       
   332 	char *oldp;
       
   333 	char *newp;
       
   334 
       
   335 	GSList *oscar_chats;
       
   336 	GHashTable *buddyinfo;
       
   337 	GSList *requesticon;
       
   338 
       
   339 	gboolean use_ssl;
       
   340 	gboolean icq;
       
   341 	guint getblisttimer;
       
   342 
       
   343 	struct {
       
   344 		guint maxwatchers; /* max users who can watch you */
       
   345 		guint maxbuddies; /* max users you can watch */
       
   346 		guint maxgroups; /* max groups in server list */
       
   347 		guint maxpermits; /* max users on permit list */
       
   348 		guint maxdenies; /* max users on deny list */
       
   349 		guint maxsiglen; /* max size (bytes) of profile */
       
   350 		guint maxawaymsglen; /* max size (bytes) of posted away message */
       
   351 	} rights;
       
   352 
       
   353 	PurpleConnection *gc;
       
   354 
       
   355 	void *modlistv;
       
   356 
       
   357 	/*
       
   358 	 * Outstanding snac handling
       
   359 	 *
       
   360 	 * TODO: Should these be per-connection? -mid
       
   361 	 */
       
   362 	void *snac_hash[FAIM_SNAC_HASH_SIZE];
       
   363 	aim_snacid_t snacid_next;
       
   364 
       
   365 	/*
       
   366 	 * TODO: Data specific to a certain family should go into a
       
   367 	 *       hashtable and the core parts of libfaim shouldn't
       
   368 	 *       need to know about them.
       
   369 	 */
       
   370 
       
   371 	IcbmCookie *msgcookies;
       
   372 	GSList *icq_info;
       
   373 
       
   374 	/** Only used when connecting with the old-style BUCP login. */
       
   375 	struct aim_authresp_info *authinfo;
       
   376 	struct aim_emailinfo *emailinfo;
       
   377 
       
   378 	struct {
       
   379 		struct aim_userinfo_s *userinfo;
       
   380 	} locate;
       
   381 
       
   382 	struct {
       
   383 		gboolean have_rights;
       
   384 	} bos;
       
   385 
       
   386 	/* Server-stored information (ssi) */
       
   387 	struct {
       
   388 		gboolean received_data;
       
   389 		guint16 numitems;
       
   390 		struct aim_ssi_item *official;
       
   391 		struct aim_ssi_item *local;
       
   392 		struct aim_ssi_tmp *pending;
       
   393 		time_t timestamp;
       
   394 		gboolean waiting_for_ack;
       
   395 		gboolean in_transaction;
       
   396 	} ssi;
       
   397 
       
   398 	/** Contains pointers to handler functions for each family/subtype. */
       
   399 	GHashTable *handlerlist;
       
   400 
       
   401 	/** A linked list containing FlapConnections. */
       
   402 	GSList *oscar_connections;
       
   403 	guint16 default_port;
       
   404 
       
   405 	/** A linked list containing PeerConnections. */
       
   406 	GSList *peer_connections;
       
   407 };
       
   408 
       
   409 /* Valid for calling aim_icq_setstatus() and for aim_userinfo_t->icqinfo.status */
       
   410 #define AIM_ICQ_STATE_NORMAL            0x00000000
       
   411 #define AIM_ICQ_STATE_AWAY              0x00000001
       
   412 #define AIM_ICQ_STATE_DND               0x00000002
       
   413 #define AIM_ICQ_STATE_OUT               0x00000004
       
   414 #define AIM_ICQ_STATE_BUSY              0x00000010
       
   415 #define AIM_ICQ_STATE_CHAT              0x00000020
       
   416 #define AIM_ICQ_STATE_INVISIBLE         0x00000100
       
   417 #define AIM_ICQ_STATE_EVIL              0x00003000
       
   418 #define AIM_ICQ_STATE_DEPRESSION        0x00004000
       
   419 #define AIM_ICQ_STATE_ATHOME            0x00005000
       
   420 #define AIM_ICQ_STATE_ATWORK            0x00006000
       
   421 #define AIM_ICQ_STATE_LUNCH             0x00002001
       
   422 #define AIM_ICQ_STATE_EVIL              0x00003000
       
   423 #define AIM_ICQ_STATE_WEBAWARE          0x00010000
       
   424 #define AIM_ICQ_STATE_HIDEIP            0x00020000
       
   425 #define AIM_ICQ_STATE_BIRTHDAY          0x00080000
       
   426 #define AIM_ICQ_STATE_ICQHOMEPAGE       0x00200000
       
   427 #define AIM_ICQ_STATE_DIRECTREQUIREAUTH 0x10000000
       
   428 
       
   429 /**
       
   430  * Only used when connecting with the old-style BUCP login.
       
   431  */
       
   432 struct aim_clientrelease
       
   433 {
       
   434 	char *name;
       
   435 	guint32 build;
       
   436 	char *url;
       
   437 	char *info;
       
   438 };
       
   439 
       
   440 /**
       
   441  * Only used when connecting with the old-style BUCP login.
       
   442  */
       
   443 struct aim_authresp_info
       
   444 {
       
   445 	char *bn;
       
   446 	guint16 errorcode;
       
   447 	char *errorurl;
       
   448 	guint16 regstatus;
       
   449 	char *email;
       
   450 	char *bosip;
       
   451 	guint16 cookielen;
       
   452 	guint8 *cookie;
       
   453 	char *chpassurl;
       
   454 	struct aim_clientrelease latestrelease;
       
   455 	struct aim_clientrelease latestbeta;
       
   456 };
       
   457 
       
   458 /* Callback data for redirect. */
       
   459 struct aim_redirect_data
       
   460 {
       
   461 	guint16 group;
       
   462 	const char *ip;
       
   463 	guint16 cookielen;
       
   464 	const guint8 *cookie;
       
   465 	const char *ssl_cert_cn;
       
   466 	guint8 use_ssl;
       
   467 	struct { /* group == SNAC_FAMILY_CHAT */
       
   468 		guint16 exchange;
       
   469 		const char *room;
       
   470 		guint16 instance;
       
   471 	} chat;
       
   472 };
       
   473 
       
   474 int oscar_connect_to_bos(PurpleConnection *gc, OscarData *od, const char *host, guint16 port, guint8 *cookie, guint16 cookielen, const char *tls_certname);
       
   475 
       
   476 /* family_auth.c */
       
   477 
       
   478 /**
       
   479  * Only used when connecting with the old-style BUCP login.
       
   480  */
       
   481 int aim_request_login(OscarData *od, FlapConnection *conn, const char *bn);
       
   482 
       
   483 /**
       
   484  * Only used when connecting with the old-style BUCP login.
       
   485  */
       
   486 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);
       
   487 
       
   488 /**
       
   489  * Only used when connecting with the old-style BUCP login.
       
   490  */
       
   491 /* 0x000b */ int aim_auth_securid_send(OscarData *od, const char *securid);
       
   492 
       
   493 /**
       
   494  * Only used when connecting with clientLogin.
       
   495  */
       
   496 void send_client_login(OscarData *od, const char *username);
       
   497 
       
   498 /* flap_connection.c */
       
   499 FlapConnection *flap_connection_new(OscarData *, int type);
       
   500 void flap_connection_close(OscarData *od, FlapConnection *conn);
       
   501 void flap_connection_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message);
       
   502 void flap_connection_schedule_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message);
       
   503 FlapConnection *flap_connection_findbygroup(OscarData *od, guint16 group);
       
   504 FlapConnection *flap_connection_getbytype(OscarData *, int type);
       
   505 FlapConnection *flap_connection_getbytype_all(OscarData *, int type);
       
   506 void flap_connection_recv_cb(gpointer data, gint source, PurpleInputCondition cond);
       
   507 void flap_connection_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, PurpleInputCondition cond);
       
   508 
       
   509 void flap_connection_send(FlapConnection *conn, FlapFrame *frame);
       
   510 void flap_connection_send_version(OscarData *od, FlapConnection *conn);
       
   511 void flap_connection_send_version_with_cookie(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy);
       
   512 void flap_connection_send_version_with_cookie_and_clientinfo(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy, ClientInfo *ci, gboolean allow_multiple_login);
       
   513 void flap_connection_send_snac(OscarData *od, FlapConnection *conn, guint16 family, const guint16 subtype, aim_snacid_t snacid, ByteStream *data);
       
   514 void flap_connection_send_snac_with_priority(OscarData *od, FlapConnection *conn, guint16 family, const guint16 subtype, aim_snacid_t snacid, ByteStream *data, gboolean high_priority);
       
   515 void flap_connection_send_keepalive(OscarData *od, FlapConnection *conn);
       
   516 FlapFrame *flap_frame_new(OscarData *od, guint16 channel, int datalen);
       
   517 
       
   518 /* oscar_data.c */
       
   519 typedef int (*aim_rxcallback_t)(OscarData *od, FlapConnection *conn, FlapFrame *frame, ...);
       
   520 
       
   521 OscarData *oscar_data_new(void);
       
   522 void oscar_data_destroy(OscarData *);
       
   523 void oscar_data_addhandler(OscarData *od, guint16 family, guint16 subtype, aim_rxcallback_t newhandler, guint16 flags);
       
   524 aim_rxcallback_t aim_callhandler(OscarData *od, guint16 family, guint16 subtype);
       
   525 
       
   526 /* 0x0001 - family_oservice.c */
       
   527 /* 0x0002 */ void aim_srv_clientready(OscarData *od, FlapConnection *conn);
       
   528 /* 0x0004 */ void aim_srv_requestnew(OscarData *od, guint16 serviceid);
       
   529 /* 0x0006 */ void aim_srv_reqrates(OscarData *od, FlapConnection *conn);
       
   530 /* 0x0008 */ void aim_srv_rates_addparam(OscarData *od, FlapConnection *conn);
       
   531 /* 0x000e */ void aim_srv_reqpersonalinfo(OscarData *od, FlapConnection *conn);
       
   532 /* 0x0011 */ void aim_srv_setidle(OscarData *od, guint32 idletime);
       
   533 /* 0x0017 */ void aim_srv_setversions(OscarData *od, FlapConnection *conn);
       
   534 /* 0x001e */ int aim_srv_setextrainfo(OscarData *od, gboolean seticqstatus, guint32 icqstatus, gboolean setstatusmsg, const char *statusmsg, const char *itmsurl);
       
   535 void aim_srv_set_dc_info(OscarData *od);
       
   536 
       
   537 
       
   538 void aim_bos_reqrights(OscarData *od, FlapConnection *conn);
       
   539 
       
   540 #define AIM_RATE_CODE_LIMIT      0x0003
       
   541 
       
   542 /* family_icbm.c */
       
   543 #define AIM_OFT_SUBTYPE_SEND_DIR	0x0002
       
   544 
       
   545 #define AIM_TRANSFER_DENY_DECLINE	0x0001
       
   546 
       
   547 #define AIM_IMPARAM_FLAG_CHANNEL_MSGS_ALLOWED   0x00000001
       
   548 #define AIM_IMPARAM_FLAG_MISSED_CALLS_ENABLED   0x00000002
       
   549 #define AIM_IMPARAM_FLAG_EVENTS_ALLOWED         0x00000008
       
   550 #define AIM_IMPARAM_FLAG_SMS_SUPPORTED          0x00000010
       
   551 #define AIM_IMPARAM_FLAG_OFFLINE_MSGS_ALLOWED   0x00000100
       
   552 
       
   553 /**
       
   554  * This flag tells the server that we always send HTML in messages
       
   555  * sent from an ICQ account to an ICQ account.  (If this flag is
       
   556  * not sent then plaintext is sent ICQ<-->ICQ (HTML is sent in all
       
   557  * other cases)).
       
   558  *
       
   559  * If we send an HTML message to an old client that doesn't support
       
   560  * HTML messages, then the oscar servers will merrily strip the HTML
       
   561  * for us.
       
   562  *
       
   563  * All incoming IMs are treated as HTML.
       
   564  */
       
   565 #define AIM_IMPARAM_FLAG_USE_HTML_FOR_ICQ       0x00000400
       
   566 
       
   567 struct aim_icbmparameters
       
   568 {
       
   569 	guint16 maxchan;
       
   570 	guint32 flags; /* AIM_IMPARAM_FLAG_ */
       
   571 	guint16 maxmsglen; /* message size that you will accept */
       
   572 	guint16 maxsenderwarn; /* this and below are *10 (999=99.9%) */
       
   573 	guint16 maxrecverwarn;
       
   574 	guint32 minmsginterval; /* in milliseconds? */
       
   575 };
       
   576 
       
   577 /*
       
   578  * TODO: Should probably combine this with struct chat_connection.
       
   579  */
       
   580 struct aim_chat_roominfo
       
   581 {
       
   582 	guint16 exchange;
       
   583 	char *name;
       
   584 	guint8 namelen;
       
   585 	guint16 instance;
       
   586 };
       
   587 
       
   588 struct chat_connection
       
   589 {
       
   590 	char *name;
       
   591 	char *show; /* AOL did something funny to us */
       
   592 	guint16 exchange;
       
   593 	guint16 instance;
       
   594 	FlapConnection *conn;
       
   595 	int id;
       
   596 	PurpleConnection *gc;
       
   597 	PurpleConversation *conv;
       
   598 	guint16 maxlen;
       
   599 	guint16 maxvis;
       
   600 };
       
   601 
       
   602 /*
       
   603  * All this chat struct stuff should be in family_chat.c
       
   604  */
       
   605 void oscar_chat_destroy(struct chat_connection *cc);
       
   606 
       
   607 #define AIM_IMFLAGS_AWAY				0x0001 /* mark as an autoreply */
       
   608 #define AIM_IMFLAGS_ACK					0x0002 /* request a receipt notice */
       
   609 #define AIM_IMFLAGS_BUDDYREQ			0x0010 /* buddy icon requested */
       
   610 #define AIM_IMFLAGS_HASICON				0x0020 /* already has icon */
       
   611 #define AIM_IMFLAGS_SUBENC_MACINTOSH	0x0040 /* damn that Steve Jobs! */
       
   612 #define AIM_IMFLAGS_CUSTOMFEATURES		0x0080 /* features field present */
       
   613 #define AIM_IMFLAGS_OFFLINE				0x0800 /* send to offline user */
       
   614 #define AIM_IMFLAGS_TYPINGNOT			0x1000 /* typing notification */
       
   615 
       
   616 #define AIM_CHARSET_ASCII   0x0000 /* ISO 646 */
       
   617 #define AIM_CHARSET_UNICODE 0x0002 /* ISO 10646 (UTF-16/UCS-2BE) */
       
   618 #define AIM_CHARSET_LATIN_1 0x0003 /* ISO 8859-1 */
       
   619 
       
   620 /*
       
   621  * Arguments to aim_send_im_ext().
       
   622  *
       
   623  * This is really complicated.  But immensely versatile.
       
   624  *
       
   625  */
       
   626 struct aim_sendimext_args
       
   627 {
       
   628 	/* These are _required_ */
       
   629 	const char *destbn;
       
   630 	guint32 flags; /* often 0 */
       
   631 
       
   632 	const char *msg;
       
   633 	gsize msglen;
       
   634 
       
   635 	/* Only used if AIM_IMFLAGS_HASICON is set */
       
   636 	guint32 iconlen;
       
   637 	time_t iconstamp;
       
   638 	guint32 iconsum;
       
   639 
       
   640 	guint16 featureslen;
       
   641 	guint8 *features;
       
   642 
       
   643 	guint16 charset;
       
   644 };
       
   645 
       
   646 /*
       
   647  * This information is provided in the Incoming ICBM callback for
       
   648  * Channel 1 ICBM's.
       
   649  */
       
   650 struct aim_incomingim_ch1_args
       
   651 {
       
   652 	guint32 icbmflags; /* some flags apply only to ->msg, not all mpmsg */
       
   653 	time_t timestamp; /* Only set for offline messages */
       
   654 
       
   655 	gchar *msg;
       
   656 
       
   657 	/* Only provided if AIM_IMFLAGS_HASICON is set */
       
   658 	time_t iconstamp;
       
   659 	guint32 iconlen;
       
   660 	guint16 iconsum;
       
   661 };
       
   662 
       
   663 /* Valid values for channel 2 args->status */
       
   664 #define AIM_RENDEZVOUS_PROPOSE   0x0000
       
   665 #define AIM_RENDEZVOUS_CANCEL    0x0001
       
   666 #define AIM_RENDEZVOUS_CONNECTED 0x0002
       
   667 
       
   668 struct _IcbmArgsCh2
       
   669 {
       
   670 	guint16 status;
       
   671 	guchar cookie[8];
       
   672 	guint64 type; /* One of the OSCAR_CAPABILITY_ constants */
       
   673 	const char *proxyip;
       
   674 	const char *clientip;
       
   675 	const char *verifiedip;
       
   676 	guint16 port;
       
   677 	gboolean use_proxy;
       
   678 	guint16 errorcode;
       
   679 	const char *msg; /* invite message or file description */
       
   680 	guint16 msglen;
       
   681 	const char *encoding;
       
   682 	const char *language;
       
   683 	guint16 requestnumber;
       
   684 	union {
       
   685 		struct {
       
   686 			guint32 checksum;
       
   687 			guint32 length;
       
   688 			time_t timestamp;
       
   689 			guint8 *icon;
       
   690 		} icon;
       
   691 		struct {
       
   692 			struct aim_chat_roominfo roominfo;
       
   693 		} chat;
       
   694 		struct {
       
   695 			guint8 msgtype;
       
   696 			const char *msg;
       
   697 		} rtfmsg;
       
   698 		struct {
       
   699 			guint16 subtype;
       
   700 			guint16 totfiles;
       
   701 			guint32 totsize;
       
   702 			char *filename;
       
   703 		} sendfile;
       
   704 	} info;
       
   705 	void *destructor; /* used internally only */
       
   706 };
       
   707 
       
   708 struct aim_incomingim_ch4_args
       
   709 {
       
   710 	guint32 uin; /* Of the sender of the ICBM */
       
   711 	guint8 type;
       
   712 	guint8 flags;
       
   713 	gchar *msg; /* Reason for auth request, deny, or accept */
       
   714 	int msglen;
       
   715 };
       
   716 
       
   717 /* SNAC sending functions */
       
   718 /* 0x0002 */ int aim_im_setparams(OscarData *od, struct aim_icbmparameters *params);
       
   719 /* 0x0004 */ int aim_im_reqparams(OscarData *od);
       
   720 /* 0x0006 */ int aim_im_sendch1_ext(OscarData *od, struct aim_sendimext_args *args);
       
   721 /* 0x0006 */ int aim_im_sendch1(OscarData *, const char *destbn, guint16 flags, const char *msg);
       
   722 /* 0x0006 */ int aim_im_sendch2_chatinvite(OscarData *od, const char *bn, const char *msg, guint16 exchange, const char *roomname, guint16 instance);
       
   723 /* 0x0006 */ int aim_im_sendch2_icon(OscarData *od, const char *bn, const guint8 *icon, int iconlen, time_t stamp, guint16 iconsum);
       
   724 
       
   725 /* 0x0006 */ void aim_im_sendch2_cancel(PeerConnection *peer_conn);
       
   726 /* 0x0006 */ void aim_im_sendch2_connected(PeerConnection *peer_conn);
       
   727 /* 0x0006 */ void aim_im_sendch2_odc_requestdirect(OscarData *od, guchar *cookie, const char *bn, const guint8 *ip, guint16 port, guint16 requestnumber);
       
   728 /* 0x0006 */ void aim_im_sendch2_odc_requestproxy(OscarData *od, guchar *cookie, const char *bn, const guint8 *ip, guint16 pin, guint16 requestnumber);
       
   729 /* 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);
       
   730 /* 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);
       
   731 
       
   732 /* 0x000b */ int aim_im_denytransfer(OscarData *od, const char *bn, const guchar *cookie, guint16 code);
       
   733 /* 0x0010 */ int aim_im_reqofflinemsgs(OscarData *od);
       
   734 /* 0x0014 */ int aim_im_sendmtn(OscarData *od, guint16 type1, const char *bn, guint16 type2);
       
   735 /* 0x000b */ int icq_relay_xstatus (OscarData *od, const char *sn, const guchar* cookie);
       
   736 void aim_icbm_makecookie(guchar* cookie);
       
   737 void aim_im_send_icq_confirmation(OscarData *od, const char *bn, const guchar *cookie);
       
   738 
       
   739 /* 0x0002 - family_locate.c */
       
   740 /*
       
   741  * AIM User Info, Standard Form.
       
   742  */
       
   743 #define AIM_FLAG_ADMINISTRATOR   0x0002
       
   744 #define AIM_FLAG_AOL             0x0004
       
   745 #define AIM_FLAG_AWAY            0x0020
       
   746 #define AIM_FLAG_WIRELESS        0x0080
       
   747 #define AIM_FLAG_ICQ             0x0040
       
   748 #define AIM_FLAG_ACTIVEBUDDY     0x0400
       
   749 
       
   750 #define AIM_USERINFO_PRESENT_FLAGS        0x00000001
       
   751 #define AIM_USERINFO_PRESENT_MEMBERSINCE  0x00000002
       
   752 #define AIM_USERINFO_PRESENT_ONLINESINCE  0x00000004
       
   753 #define AIM_USERINFO_PRESENT_IDLE         0x00000008
       
   754 #define AIM_USERINFO_PRESENT_ICQEXTSTATUS 0x00000010
       
   755 #define AIM_USERINFO_PRESENT_ICQIPADDR    0x00000020
       
   756 #define AIM_USERINFO_PRESENT_ICQDATA      0x00000040
       
   757 #define AIM_USERINFO_PRESENT_CAPABILITIES 0x00000080
       
   758 #define AIM_USERINFO_PRESENT_SESSIONLEN   0x00000100
       
   759 #define AIM_USERINFO_PRESENT_CREATETIME   0x00000200
       
   760 
       
   761 struct userinfo_node
       
   762 {
       
   763 	char *bn;
       
   764 	struct userinfo_node *next;
       
   765 };
       
   766 
       
   767 typedef struct aim_userinfo_s
       
   768 {
       
   769 	char *bn;
       
   770 	guint16 warnlevel; /* evil percent * 10 (999 = 99.9%) */
       
   771 	guint16 idletime; /* in seconds */
       
   772 	guint16 flags;
       
   773 	guint32 createtime; /* time_t */
       
   774 	guint32 membersince; /* time_t */
       
   775 	guint32 onlinesince; /* time_t */
       
   776 	guint32 sessionlen;  /* in seconds */
       
   777 	guint64 capabilities;
       
   778 	struct {
       
   779 		guint32 status;
       
   780 		guint32 ipaddr;
       
   781 		guint8 crap[0x25]; /* until we figure it out... */
       
   782 	} icqinfo;
       
   783 	guint32 present;
       
   784 
       
   785 	guint8 iconcsumtype;
       
   786 	guint16 iconcsumlen;
       
   787 	guint8 *iconcsum;
       
   788 
       
   789 	char *info;
       
   790 	char *info_encoding;
       
   791 	guint16 info_len;
       
   792 
       
   793 	char *status;
       
   794 	char *status_encoding;
       
   795 	guint16 status_len;
       
   796 
       
   797 	char *itmsurl;
       
   798 	char *itmsurl_encoding;
       
   799 	guint16 itmsurl_len;
       
   800 
       
   801 	char *away;
       
   802 	char *away_encoding;
       
   803 	guint16 away_len;
       
   804 
       
   805 	struct aim_userinfo_s *next;
       
   806 } aim_userinfo_t;
       
   807 
       
   808 #define AIM_SENDMEMBLOCK_FLAG_ISREQUEST  0
       
   809 #define AIM_SENDMEMBLOCK_FLAG_ISHASH     1
       
   810 
       
   811 int aim_sendmemblock(OscarData *od, FlapConnection *conn, guint32 offset, guint32 len, const guint8 *buf, guint8 flag);
       
   812 
       
   813 struct aim_invite_priv
       
   814 {
       
   815 	char *bn;
       
   816 	char *roomname;
       
   817 	guint16 exchange;
       
   818 	guint16 instance;
       
   819 };
       
   820 
       
   821 #define AIM_COOKIETYPE_CHAT     0x01
       
   822 #define AIM_COOKIETYPE_INVITE   0x02
       
   823 
       
   824 aim_userinfo_t *aim_locate_finduserinfo(OscarData *od, const char *bn);
       
   825 void aim_locate_dorequest(OscarData *od);
       
   826 
       
   827 /* 0x0002 */ int aim_locate_reqrights(OscarData *od);
       
   828 /* 0x0004 */ int aim_locate_setcaps(OscarData *od, guint64 caps);
       
   829 /* 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);
       
   830 /* 0x0015 */ int aim_locate_getinfoshort(OscarData *od, const char *bn, guint32 flags);
       
   831 
       
   832 guint64 aim_locate_getcaps(OscarData *od, ByteStream *bs, int len);
       
   833 guint64 aim_locate_getcaps_short(OscarData *od, ByteStream *bs, int len);
       
   834 void aim_info_free(aim_userinfo_t *);
       
   835 int aim_info_extract(OscarData *od, ByteStream *bs, aim_userinfo_t *);
       
   836 int aim_putuserinfo(ByteStream *bs, aim_userinfo_t *info);
       
   837 PurpleMood* icq_get_purple_moods(PurpleAccount *account);
       
   838 const char* icq_get_custom_icon_description(const char *mood);
       
   839 guint8* icq_get_custom_icon_data(const char *mood);
       
   840 int icq_im_xstatus_request(OscarData *od, const char *sn);
       
   841 
       
   842 /* 0x0003 - family_buddy.c */
       
   843 /* 0x0002 */ void aim_buddylist_reqrights(OscarData *, FlapConnection *);
       
   844 
       
   845 
       
   846 /* 0x000a - family_userlookup.c */
       
   847 int aim_search_address(OscarData *, const char *);
       
   848 
       
   849 struct aim_chat_exchangeinfo
       
   850 {
       
   851 	guint16 number;
       
   852 	guint16 flags;
       
   853 	char *name;
       
   854 	char *charset1;
       
   855 	char *lang1;
       
   856 	char *charset2;
       
   857 	char *lang2;
       
   858 };
       
   859 
       
   860 #define AIM_CHATFLAGS_NOREFLECT 0x0001
       
   861 #define AIM_CHATFLAGS_AWAY      0x0002
       
   862 int aim_chat_send_im(OscarData *od, FlapConnection *conn, guint16 flags, const gchar *msg, int msglen, const char *encoding, const char *language);
       
   863 int aim_chat_join(OscarData *od, guint16 exchange, const char *roomname, guint16 instance);
       
   864 
       
   865 void aim_chatnav_reqrights(OscarData *od, FlapConnection *conn);
       
   866 
       
   867 int aim_chatnav_createroom(OscarData *od, FlapConnection *conn, const char *name, guint16 exchange);
       
   868 
       
   869 
       
   870 /* 0x0010 - family_bart.c */
       
   871 int aim_bart_upload(OscarData *od, const guint8 *icon, guint16 iconlen);
       
   872 int aim_bart_request(OscarData *od, const char *bn, guint8 iconcsumtype, const guint8 *iconstr, guint16 iconstrlen);
       
   873 
       
   874 
       
   875 
       
   876 /* 0x0013 - family_feedbag.c */
       
   877 #define AIM_SSI_TYPE_BUDDY		0x0000
       
   878 #define AIM_SSI_TYPE_GROUP		0x0001
       
   879 #define AIM_SSI_TYPE_PERMIT		0x0002
       
   880 #define AIM_SSI_TYPE_DENY		0x0003
       
   881 #define AIM_SSI_TYPE_PDINFO		0x0004
       
   882 #define AIM_SSI_TYPE_PRESENCEPREFS	0x0005
       
   883 #define AIM_SSI_TYPE_ICQDENY		0x000e
       
   884 #define AIM_SSI_TYPE_ICONINFO		0x0014
       
   885 
       
   886 /* These flags are set in the 0x00c9 TLV of SSI type 0x0005 */
       
   887 #define AIM_SSI_PRESENCE_FLAG_SHOWIDLE        0x00000400
       
   888 #define AIM_SSI_PRESENCE_FLAG_NORECENTBUDDIES 0x00020000
       
   889 
       
   890 struct aim_ssi_item
       
   891 {
       
   892 	char *name;
       
   893 	guint16 gid;
       
   894 	guint16 bid;
       
   895 	guint16 type;
       
   896 	GSList *data;
       
   897 	struct aim_ssi_item *next;
       
   898 };
       
   899 
       
   900 struct aim_ssi_tmp
       
   901 {
       
   902 	guint16 action;
       
   903 	guint16 ack;
       
   904 	char *name;
       
   905 	struct aim_ssi_item *item;
       
   906 	struct aim_ssi_tmp *next;
       
   907 };
       
   908 
       
   909 /* These build the actual SNACs and queue them to be sent */
       
   910 /* 0x0002 */ int aim_ssi_reqrights(OscarData *od);
       
   911 /* 0x0004 */ int aim_ssi_reqdata(OscarData *od);
       
   912 /* 0x0007 */ int aim_ssi_enable(OscarData *od);
       
   913 /* 0x0011 */ int aim_ssi_modbegin(OscarData *od);
       
   914 /* 0x0012 */ int aim_ssi_modend(OscarData *od);
       
   915 /* 0x0018 */ int aim_ssi_sendauthrequest(OscarData *od, const char *bn, const char *msg);
       
   916 /* 0x001a */ int aim_ssi_sendauthreply(OscarData *od, const char *bn, guint8 reply, const char *msg);
       
   917 
       
   918 /* Client functions for retrieving SSI data */
       
   919 struct aim_ssi_item *aim_ssi_itemlist_find(struct aim_ssi_item *list, guint16 gid, guint16 bid);
       
   920 struct aim_ssi_item *aim_ssi_itemlist_finditem(struct aim_ssi_item *list, const char *gn, const char *bn, guint16 type);
       
   921 struct aim_ssi_item *aim_ssi_itemlist_exists(struct aim_ssi_item *list, const char *bn);
       
   922 char *aim_ssi_itemlist_findparentname(struct aim_ssi_item *list, const char *bn);
       
   923 int aim_ssi_getpermdeny(struct aim_ssi_item *list);
       
   924 guint32 aim_ssi_getpresence(struct aim_ssi_item *list);
       
   925 char *aim_ssi_getalias(struct aim_ssi_item *list, const char *gn, const char *bn);
       
   926 char *aim_ssi_getcomment(struct aim_ssi_item *list, const char *gn, const char *bn);
       
   927 gboolean aim_ssi_waitingforauth(struct aim_ssi_item *list, const char *gn, const char *bn);
       
   928 
       
   929 /* Client functions for changing SSI data */
       
   930 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);
       
   931 int aim_ssi_delbuddy(OscarData *od, const char *name, const char *group);
       
   932 int aim_ssi_delgroup(OscarData *od, const char *group);
       
   933 int aim_ssi_movebuddy(OscarData *od, const char *oldgn, const char *newgn, const char *bn);
       
   934 int aim_ssi_aliasbuddy(OscarData *od, const char *gn, const char *bn, const char *alias);
       
   935 int aim_ssi_editcomment(OscarData *od, const char *gn, const char *bn, const char *alias);
       
   936 int aim_ssi_rename_group(OscarData *od, const char *oldgn, const char *newgn);
       
   937 int aim_ssi_cleanlist(OscarData *od);
       
   938 int aim_ssi_deletelist(OscarData *od);
       
   939 int aim_ssi_setpermdeny(OscarData *od, guint8 permdeny);
       
   940 int aim_ssi_setpresence(OscarData *od, guint32 presence);
       
   941 int aim_ssi_seticon(OscarData *od, const guint8 *iconsum, guint8 iconsumlen);
       
   942 int aim_ssi_delicon(OscarData *od);
       
   943 int aim_ssi_add_to_private_list(OscarData *od, const char* name, guint16 list_type);
       
   944 int aim_ssi_del_from_private_list(OscarData* od, const char* name, guint16 list_type);
       
   945 
       
   946 guint16 aim_ssi_getdenyentrytype(OscarData* od);
       
   947 
       
   948 struct aim_icq_info
       
   949 {
       
   950 	guint16 reqid;
       
   951 
       
   952 	/* simple */
       
   953 	guint32 uin;
       
   954 
       
   955 	/* general and "home" information (0x00c8) */
       
   956 	char *nick;
       
   957 	char *first;
       
   958 	char *last;
       
   959 	char *email;
       
   960 	char *homecity;
       
   961 	char *homestate;
       
   962 	char *homephone;
       
   963 	char *homefax;
       
   964 	char *homeaddr;
       
   965 	char *mobile;
       
   966 	char *homezip;
       
   967 	guint16 homecountry;
       
   968 /*	guint8 timezone;
       
   969 	guint8 hideemail; */
       
   970 
       
   971 	/* personal (0x00dc) */
       
   972 	guint8 age;
       
   973 	guint8 unknown;
       
   974 	guint8 gender;
       
   975 	char *personalwebpage;
       
   976 	guint16 birthyear;
       
   977 	guint8 birthmonth;
       
   978 	guint8 birthday;
       
   979 	guint8 language1;
       
   980 	guint8 language2;
       
   981 	guint8 language3;
       
   982 
       
   983 	/* work (0x00d2) */
       
   984 	char *workcity;
       
   985 	char *workstate;
       
   986 	char *workphone;
       
   987 	char *workfax;
       
   988 	char *workaddr;
       
   989 	char *workzip;
       
   990 	guint16 workcountry;
       
   991 	char *workcompany;
       
   992 	char *workdivision;
       
   993 	char *workposition;
       
   994 	char *workwebpage;
       
   995 
       
   996 	/* additional personal information (0x00e6) */
       
   997 	char *info;
       
   998 
       
   999 	/* email (0x00eb) */
       
  1000 	guint16 numaddresses;
       
  1001 	char **email2;
       
  1002 
       
  1003 	/* status note info */
       
  1004 	guint8 icbm_cookie[8];
       
  1005 	char *status_note_title;
       
  1006 
       
  1007 	gboolean for_auth_request;
       
  1008 	char *auth_request_reason;
       
  1009 };
       
  1010 
       
  1011 int aim_icq_setsecurity(OscarData *od, gboolean auth_required, gboolean webaware);
       
  1012 int aim_icq_changepasswd(OscarData *od, const char *passwd);
       
  1013 int aim_icq_getalias(OscarData *od, const char *uin, gboolean for_auth_request, char *auth_request_reason);
       
  1014 int aim_icq_getallinfo(OscarData *od, const char *uin);
       
  1015 int aim_icq_sendsms(OscarData *od, const char *name, const char *msg, const char *alias);
       
  1016 
       
  1017 
       
  1018 /* 0x0017 - family_auth.c */
       
  1019 void aim_sendcookie(OscarData *, FlapConnection *, const guint16 length, const guint8 *);
       
  1020 void aim_admin_changepasswd(OscarData *, FlapConnection *, const char *newpw, const char *curpw);
       
  1021 void aim_admin_reqconfirm(OscarData *od, FlapConnection *conn);
       
  1022 void aim_admin_getinfo(OscarData *od, FlapConnection *conn, guint16 info);
       
  1023 void aim_admin_setemail(OscarData *od, FlapConnection *conn, const char *newemail);
       
  1024 void aim_admin_setnick(OscarData *od, FlapConnection *conn, const char *newnick);
       
  1025 
       
  1026 
       
  1027 
       
  1028 /* 0x0018 - family_alert.c */
       
  1029 struct aim_emailinfo
       
  1030 {
       
  1031 	guint8 *cookie16;
       
  1032 	guint8 *cookie8;
       
  1033 	char *url;
       
  1034 	guint16 nummsgs;
       
  1035 	guint8 unread;
       
  1036 	char *domain;
       
  1037 	guint16 flag;
       
  1038 	struct aim_emailinfo *next;
       
  1039 };
       
  1040 
       
  1041 int aim_email_sendcookies(OscarData *od);
       
  1042 int aim_email_activate(OscarData *od);
       
  1043 
       
  1044 
       
  1045 
       
  1046 /* tlv.c - TLV handling */
       
  1047 
       
  1048 /* TLV structure */
       
  1049 typedef struct aim_tlv_s
       
  1050 {
       
  1051 	guint16 type;
       
  1052 	guint16 length;
       
  1053 	guint8 *value;
       
  1054 } aim_tlv_t;
       
  1055 
       
  1056 /* TLV handling functions */
       
  1057 char *aim_tlv_getvalue_as_string(aim_tlv_t *tlv);
       
  1058 
       
  1059 aim_tlv_t *aim_tlv_gettlv(GSList *list, const guint16 type, const int nth);
       
  1060 int aim_tlv_getlength(GSList *list, const guint16 type, const int nth);
       
  1061 char *aim_tlv_getstr(GSList *list, const guint16 type, const int nth);
       
  1062 guint8 aim_tlv_get8(GSList *list, const guint16 type, const int nth);
       
  1063 guint16 aim_tlv_get16(GSList *list, const guint16 type, const int nth);
       
  1064 guint32 aim_tlv_get32(GSList *list, const guint16 type, const int nth);
       
  1065 
       
  1066 /* TLV list handling functions */
       
  1067 GSList *aim_tlvlist_read(ByteStream *bs);
       
  1068 GSList *aim_tlvlist_readnum(ByteStream *bs, guint16 num);
       
  1069 GSList *aim_tlvlist_readlen(ByteStream *bs, guint16 len);
       
  1070 GSList *aim_tlvlist_copy(GSList *orig);
       
  1071 
       
  1072 int aim_tlvlist_count(GSList *list);
       
  1073 int aim_tlvlist_size(GSList *list);
       
  1074 int aim_tlvlist_cmp(GSList *one, GSList *two);
       
  1075 int aim_tlvlist_write(ByteStream *bs, GSList **list);
       
  1076 void aim_tlvlist_free(GSList *list);
       
  1077 
       
  1078 int aim_tlvlist_add_raw(GSList **list, const guint16 type, const guint16 length, const guint8 *value);
       
  1079 int aim_tlvlist_add_noval(GSList **list, const guint16 type);
       
  1080 int aim_tlvlist_add_8(GSList **list, const guint16 type, const guint8 value);
       
  1081 int aim_tlvlist_add_16(GSList **list, const guint16 type, const guint16 value);
       
  1082 int aim_tlvlist_add_32(GSList **list, const guint16 type, const guint32 value);
       
  1083 int aim_tlvlist_add_str(GSList **list, const guint16 type, const char *value);
       
  1084 int aim_tlvlist_add_caps(GSList **list, const guint16 type, const guint64 caps, const char *mood);
       
  1085 int aim_tlvlist_add_userinfo(GSList **list, guint16 type, aim_userinfo_t *userinfo);
       
  1086 int aim_tlvlist_add_chatroom(GSList **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance);
       
  1087 int aim_tlvlist_add_frozentlvlist(GSList **list, guint16 type, GSList **tl);
       
  1088 
       
  1089 int aim_tlvlist_replace_raw(GSList **list, const guint16 type, const guint16 lenth, const guint8 *value);
       
  1090 int aim_tlvlist_replace_str(GSList **list, const guint16 type, const char *str);
       
  1091 int aim_tlvlist_replace_noval(GSList **list, const guint16 type);
       
  1092 int aim_tlvlist_replace_8(GSList **list, const guint16 type, const guint8 value);
       
  1093 int aim_tlvlist_replace_16(GSList **list, const guint16 type, const guint16 value);
       
  1094 int aim_tlvlist_replace_32(GSList **list, const guint16 type, const guint32 value);
       
  1095 
       
  1096 void aim_tlvlist_remove(GSList **list, const guint16 type);
       
  1097 
       
  1098 
       
  1099 
       
  1100 /* util.c */
       
  1101 /* These are really ugly.  You'd think this was LISP.  I wish it was. */
       
  1102 #define aimutil_put8(buf, data) ((*(buf) = (guint8)(data)&0xff),1)
       
  1103 #define aimutil_get8(buf) ((*(buf))&0xff)
       
  1104 #define aimutil_put16(buf, data) ( \
       
  1105 		(*(buf) = (guint8)((data)>>8)&0xff), \
       
  1106 		(*((buf)+1) = (guint8)(data)&0xff),  \
       
  1107 		2)
       
  1108 #define aimutil_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
       
  1109 #define aimutil_put32(buf, data) ( \
       
  1110 		(*((buf)) = (guint8)((data)>>24)&0xff), \
       
  1111 		(*((buf)+1) = (guint8)((data)>>16)&0xff), \
       
  1112 		(*((buf)+2) = (guint8)((data)>>8)&0xff), \
       
  1113 		(*((buf)+3) = (guint8)(data)&0xff), \
       
  1114 		4)
       
  1115 #define aimutil_get32(buf) ((((*(buf))<<24)&0xff000000) + \
       
  1116 		(((*((buf)+1))<<16)&0x00ff0000) + \
       
  1117 		(((*((buf)+2))<< 8)&0x0000ff00) + \
       
  1118 		(((*((buf)+3)    )&0x000000ff)))
       
  1119 
       
  1120 /* Little-endian versions (damn ICQ) */
       
  1121 #define aimutil_putle8(buf, data) ( \
       
  1122 		(*(buf) = (guint8)(data) & 0xff), \
       
  1123 		1)
       
  1124 #define aimutil_getle8(buf) ( \
       
  1125 		(*(buf)) & 0xff \
       
  1126 		)
       
  1127 #define aimutil_putle16(buf, data) ( \
       
  1128 		(*((buf)+0) = (guint8)((data) >> 0) & 0xff),  \
       
  1129 		(*((buf)+1) = (guint8)((data) >> 8) & 0xff), \
       
  1130 		2)
       
  1131 #define aimutil_getle16(buf) ( \
       
  1132 		(((*((buf)+0)) << 0) & 0x00ff) + \
       
  1133 		(((*((buf)+1)) << 8) & 0xff00) \
       
  1134 		)
       
  1135 #define aimutil_putle32(buf, data) ( \
       
  1136 		(*((buf)+0) = (guint8)((data) >>  0) & 0xff), \
       
  1137 		(*((buf)+1) = (guint8)((data) >>  8) & 0xff), \
       
  1138 		(*((buf)+2) = (guint8)((data) >> 16) & 0xff), \
       
  1139 		(*((buf)+3) = (guint8)((data) >> 24) & 0xff), \
       
  1140 		4)
       
  1141 #define aimutil_getle32(buf) ( \
       
  1142 		(((*((buf)+0)) <<  0) & 0x000000ff) + \
       
  1143 		(((*((buf)+1)) <<  8) & 0x0000ff00) + \
       
  1144 		(((*((buf)+2)) << 16) & 0x00ff0000) + \
       
  1145 		(((*((buf)+3)) << 24) & 0xff000000))
       
  1146 
       
  1147 const char *oscar_get_msgerr_reason(size_t reason);
       
  1148 int oscar_get_ui_info_int(const char *str, int default_value);
       
  1149 const char *oscar_get_ui_info_string(const char *str, const char *default_value);
       
  1150 gchar *oscar_get_clientstring(void);
       
  1151 
       
  1152 guint16 aimutil_iconsum(const guint8 *buf, int buflen);
       
  1153 
       
  1154 gboolean oscar_util_valid_name(const char *bn);
       
  1155 gboolean oscar_util_valid_name_icq(const char *bn);
       
  1156 gboolean oscar_util_valid_name_sms(const char *bn);
       
  1157 int oscar_util_name_compare(const char *bn1, const char *bn2);
       
  1158 gchar *oscar_util_format_string(const char *str, const char *name);
       
  1159 gchar *oscar_format_buddies(GSList *buddies, const gchar *no_buddies_message);
       
  1160 
       
  1161 typedef struct {
       
  1162 	guint16 family;
       
  1163 	guint16 subtype;
       
  1164 	guint16 flags;
       
  1165 	guint32 id;
       
  1166 } aim_modsnac_t;
       
  1167 
       
  1168 #define AIM_MODULENAME_MAXLEN 16
       
  1169 #define AIM_MODFLAG_MULTIFAMILY 0x0001
       
  1170 typedef struct aim_module_s
       
  1171 {
       
  1172 	guint16 family;
       
  1173 	guint16 version;
       
  1174 	guint16 toolid;
       
  1175 	guint16 toolversion;
       
  1176 	guint16 flags;
       
  1177 	char name[AIM_MODULENAME_MAXLEN+1];
       
  1178 	int (*snachandler)(OscarData *od, FlapConnection *conn, struct aim_module_s *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs);
       
  1179 	void (*shutdown)(OscarData *od, struct aim_module_s *mod);
       
  1180 	void *priv;
       
  1181 	struct aim_module_s *next;
       
  1182 } aim_module_t;
       
  1183 
       
  1184 int aim__registermodule(OscarData *od, int (*modfirst)(OscarData *, aim_module_t *));
       
  1185 void aim__shutdownmodules(OscarData *od);
       
  1186 aim_module_t *aim__findmodulebygroup(OscarData *od, guint16 group);
       
  1187 aim_module_t *aim__findmodule(OscarData *od, const char *name);
       
  1188 
       
  1189 int admin_modfirst(OscarData *od, aim_module_t *mod);
       
  1190 int buddylist_modfirst(OscarData *od, aim_module_t *mod);
       
  1191 int bos_modfirst(OscarData *od, aim_module_t *mod);
       
  1192 int search_modfirst(OscarData *od, aim_module_t *mod);
       
  1193 int stats_modfirst(OscarData *od, aim_module_t *mod);
       
  1194 int auth_modfirst(OscarData *od, aim_module_t *mod);
       
  1195 int msg_modfirst(OscarData *od, aim_module_t *mod);
       
  1196 int misc_modfirst(OscarData *od, aim_module_t *mod);
       
  1197 int chatnav_modfirst(OscarData *od, aim_module_t *mod);
       
  1198 int chat_modfirst(OscarData *od, aim_module_t *mod);
       
  1199 int locate_modfirst(OscarData *od, aim_module_t *mod);
       
  1200 int service_modfirst(OscarData *od, aim_module_t *mod);
       
  1201 int popups_modfirst(OscarData *od, aim_module_t *mod);
       
  1202 int bart_modfirst(OscarData *od, aim_module_t *mod);
       
  1203 int ssi_modfirst(OscarData *od, aim_module_t *mod);
       
  1204 int icq_modfirst(OscarData *od, aim_module_t *mod);
       
  1205 int email_modfirst(OscarData *od, aim_module_t *mod);
       
  1206 
       
  1207 void aim_genericreq_n(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype);
       
  1208 void aim_genericreq_n_snacid(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype);
       
  1209 void aim_genericreq_l(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint32 *);
       
  1210 
       
  1211 /* bstream.c */
       
  1212 int byte_stream_new(ByteStream *bs, size_t len);
       
  1213 int byte_stream_init(ByteStream *bs, guint8 *data, size_t len);
       
  1214 void byte_stream_destroy(ByteStream *bs);
       
  1215 size_t byte_stream_bytes_left(ByteStream *bs);
       
  1216 int byte_stream_curpos(ByteStream *bs);
       
  1217 int byte_stream_setpos(ByteStream *bs, size_t off);
       
  1218 void byte_stream_rewind(ByteStream *bs);
       
  1219 int byte_stream_advance(ByteStream *bs, int n);
       
  1220 guint8 byte_stream_get8(ByteStream *bs);
       
  1221 guint16 byte_stream_get16(ByteStream *bs);
       
  1222 guint32 byte_stream_get32(ByteStream *bs);
       
  1223 guint8 byte_stream_getle8(ByteStream *bs);
       
  1224 guint16 byte_stream_getle16(ByteStream *bs);
       
  1225 guint32 byte_stream_getle32(ByteStream *bs);
       
  1226 int byte_stream_getrawbuf(ByteStream *bs, guint8 *buf, size_t len);
       
  1227 guint8 *byte_stream_getraw(ByteStream *bs, size_t len);
       
  1228 char *byte_stream_getstr(ByteStream *bs, size_t len);
       
  1229 int byte_stream_put8(ByteStream *bs, guint8 v);
       
  1230 int byte_stream_put16(ByteStream *bs, guint16 v);
       
  1231 int byte_stream_put32(ByteStream *bs, guint32 v);
       
  1232 int byte_stream_putle8(ByteStream *bs, guint8 v);
       
  1233 int byte_stream_putle16(ByteStream *bs, guint16 v);
       
  1234 int byte_stream_putle32(ByteStream *bs, guint32 v);
       
  1235 int byte_stream_putraw(ByteStream *bs, const guint8 *v, size_t len);
       
  1236 int byte_stream_putstr(ByteStream *bs, const char *str);
       
  1237 int byte_stream_putbs(ByteStream *bs, ByteStream *srcbs, size_t len);
       
  1238 int byte_stream_putuid(ByteStream *bs, OscarData *od);
       
  1239 int byte_stream_putcaps(ByteStream *bs, guint64 caps);
       
  1240 
       
  1241 /**
       
  1242  * Inserts a BART asset block into the given byte stream.  The flags
       
  1243  * and length are set appropriately based on the value of data.
       
  1244  */
       
  1245 void byte_stream_put_bart_asset(ByteStream *bs, guint16 type, ByteStream *data);
       
  1246 
       
  1247 /**
       
  1248  * A helper function that calls byte_stream_put_bart_asset with the
       
  1249  * appropriate data ByteStream given the datastr.
       
  1250  */
       
  1251 void byte_stream_put_bart_asset_str(ByteStream *bs, guint16 type, const char *datastr);
       
  1252 
       
  1253 /*
       
  1254  * Generic SNAC structure.  Rarely if ever used.
       
  1255  */
       
  1256 typedef struct aim_snac_s {
       
  1257 	aim_snacid_t id;
       
  1258 	guint16 family;
       
  1259 	guint16 type;
       
  1260 	guint16 flags;
       
  1261 	void *data;
       
  1262 	time_t issuetime;
       
  1263 	struct aim_snac_s *next;
       
  1264 } aim_snac_t;
       
  1265 
       
  1266 /* snac.c */
       
  1267 void aim_initsnachash(OscarData *od);
       
  1268 aim_snacid_t aim_newsnac(OscarData *, aim_snac_t *newsnac);
       
  1269 aim_snacid_t aim_cachesnac(OscarData *od, const guint16 family, const guint16 type, const guint16 flags, const void *data, const int datalen);
       
  1270 aim_snac_t *aim_remsnac(OscarData *, aim_snacid_t id);
       
  1271 void aim_cleansnacs(OscarData *, int maxage);
       
  1272 int aim_putsnac(ByteStream *, guint16 family, guint16 type, aim_snacid_t id);
       
  1273 
       
  1274 struct chatsnacinfo {
       
  1275 	guint16 exchange;
       
  1276 	char name[128];
       
  1277 	guint16 instance;
       
  1278 };
       
  1279 
       
  1280 struct rateclass {
       
  1281 	guint16 classid;
       
  1282 	guint32 windowsize;
       
  1283 	guint32 clear;
       
  1284 	guint32 alert;
       
  1285 	guint32 limit;
       
  1286 	guint32 disconnect;
       
  1287 	guint32 current;
       
  1288 	guint32 max;
       
  1289 	guint8 dropping_snacs;
       
  1290 
       
  1291 	struct timeval last; /**< The time when we last sent a SNAC of this rate class. */
       
  1292 };
       
  1293 
       
  1294 int aim_cachecookie(OscarData *od, IcbmCookie *cookie);
       
  1295 IcbmCookie *aim_uncachecookie(OscarData *od, guint8 *cookie, int type);
       
  1296 IcbmCookie *aim_mkcookie(guint8 *, int, void *);
       
  1297 IcbmCookie *aim_checkcookie(OscarData *, const unsigned char *, const int);
       
  1298 int aim_freecookie(OscarData *od, IcbmCookie *cookie);
       
  1299 int aim_cookie_free(OscarData *od, IcbmCookie *cookie);
       
  1300 
       
  1301 int aim_chat_readroominfo(ByteStream *bs, struct aim_chat_roominfo *outinfo);
       
  1302 
       
  1303 void flap_connection_destroy_chat(OscarData *od, FlapConnection *conn);
       
  1304 
       
  1305 /* userinfo.c - displaying user information */
       
  1306 
       
  1307 void oscar_user_info_append_status(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo, gboolean use_html_status);
       
  1308 void oscar_user_info_append_extra_info(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo);
       
  1309 void oscar_user_info_display_error(OscarData *od, guint16 error_reason, char *buddy);
       
  1310 void oscar_user_info_display_icq(OscarData *od, struct aim_icq_info *info);
       
  1311 void oscar_user_info_display_aim(OscarData *od, aim_userinfo_t *userinfo);
       
  1312 
       
  1313 /* authorization.c - OSCAR authorization requests */
       
  1314 void oscar_auth_sendrequest(PurpleConnection *gc, const char *name, const char *msg);
       
  1315 void oscar_auth_sendrequest_menu(PurpleBlistNode *node, gpointer ignored);
       
  1316 void oscar_auth_recvrequest(PurpleConnection *gc, gchar *name, gchar *nick, gchar *reason);
       
  1317 
       
  1318 void oscar_set_aim_permdeny(PurpleConnection *gc);
       
  1319 
       
  1320 struct buddyinfo
       
  1321 {
       
  1322 	gboolean typingnot;
       
  1323 	guint32 ipaddr;
       
  1324 
       
  1325 	unsigned long ico_me_len;
       
  1326 	unsigned long ico_me_csum;
       
  1327 	time_t ico_me_time;
       
  1328 	gboolean ico_informed;
       
  1329 
       
  1330 	unsigned long ico_len;
       
  1331 	unsigned long ico_csum;
       
  1332 	time_t ico_time;
       
  1333 	gboolean ico_need;
       
  1334 	gboolean ico_sent;
       
  1335 };
       
  1336 
       
  1337 struct name_data
       
  1338 {
       
  1339 	PurpleConnection *gc;
       
  1340 	gchar *name;
       
  1341 	gchar *nick;
       
  1342 };
       
  1343 
       
  1344 void oscar_free_name_data(struct name_data *data);
       
  1345 
       
  1346 #ifdef __cplusplus
       
  1347 }
       
  1348 #endif
       
  1349 
       
  1350 #endif /* _OSCAR_H_ */