changeset 13253:87a7c3077c19

[gaim-migrate @ 15619] More cleaning up of oscar. Renamed some functions to be more clear. Got rid of some stuff that wasn't used. Inlined some small things in conn.c that were only used once. The goals of all this are 1. Non-blocking I/O for all connections 2. p2p stuff won't use the same struct as oscar connections, because that's stupid 3. The oscar PRPL should be less scary committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 12 Feb 2006 21:27:04 +0000
parents 2871c385c45a
children e9802db22b06
files src/protocols/oscar/conn.c src/protocols/oscar/family_admin.c src/protocols/oscar/family_alert.c src/protocols/oscar/family_auth.c src/protocols/oscar/family_bart.c src/protocols/oscar/family_bos.c src/protocols/oscar/family_buddy.c src/protocols/oscar/family_chat.c src/protocols/oscar/family_chatnav.c src/protocols/oscar/family_feedbag.c src/protocols/oscar/family_icbm.c src/protocols/oscar/family_icq.c src/protocols/oscar/family_locate.c src/protocols/oscar/family_odir.c src/protocols/oscar/family_oservice.c src/protocols/oscar/family_userlookup.c src/protocols/oscar/misc.c src/protocols/oscar/oscar.c src/protocols/oscar/oscar.h src/protocols/oscar/oscar_internal.h src/protocols/oscar/peer.c src/protocols/oscar/snac.c src/protocols/oscar/txqueue.c
diffstat 23 files changed, 343 insertions(+), 401 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/oscar/conn.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/conn.c	Sun Feb 12 21:27:04 2006 +0000
@@ -27,10 +27,6 @@
 
 #include "oscar.h"
 
-/* This is defined in oscar.h, but only when !FAIM_INTERNAL, since the rest of
- * the library is not allowed to call it. */
-faim_export void aim_conn_kill(OscarSession *sess, OscarConnection **deadconn);
-
 #ifndef _WIN32
 #include <netdb.h>
 #include <sys/socket.h>
@@ -44,17 +40,17 @@
 /**
  * In OSCAR, every connection has a set of SNAC groups associated
  * with it.  These are the groups that you can send over this connection
- * without being guaranteed a "Not supported" SNAC error.  
+ * without being guaranteed a "Not supported" SNAC error.
  *
- * The grand theory of things says that these associations transcend 
+ * The grand theory of things says that these associations transcend
  * what libfaim calls "connection types" (conn->type).  You can probably
- * see the elegance here, but since I want to revel in it for a bit, you 
+ * see the elegance here, but since I want to revel in it for a bit, you
  * get to hear it all spelled out.
  *
  * So let us say that you have your core BOS connection running.  One
  * of your modules has just given you a SNAC of the group 0x0004 to send
  * you.  Maybe an IM destined for some twit in Greenland.  So you start
- * at the top of your connection list, looking for a connection that 
+ * at the top of your connection list, looking for a connection that
  * claims to support group 0x0004.  You find one.  Why, that neat BOS
  * connection of yours can do that.  So you send it on its way.
  *
@@ -72,8 +68,8 @@
  * it.  Great, you say.  Now I have something to do.  Off you go, making
  * that connection.  One of the first things you get from this new server
  * is a message saying that indeed it does support the group you were looking
- * for.  So you continue and send rate confirmation and all that.  
- * 
+ * for.  So you continue and send rate confirmation and all that.
+ *
  * Then you remember you had that SNAC to send, and now you have a means to
  * do it, and you do, and everyone is happy.  Except the Greenlander, who is
  * still stuck in the bitter cold.
@@ -86,7 +82,7 @@
  * scheme for quite some time now.  But I still haven't convinced myself
  * to make libfaim work that way.  It would take a fair amount of effort,
  * and probably some client API changes as well.  (Whenever I don't want
- * to do something, I just say it would change the client API.  Then I 
+ * to do something, I just say it would change the client API.  Then I
  * instantly have a couple of supporters of not doing it.)
  *
  * Generally, addgroup is only called by the internal handling of the
@@ -96,32 +92,33 @@
  * about such inane things.
  *
  */
-faim_internal void aim_conn_addgroup(OscarConnection *conn, guint16 group)
+void
+aim_conn_addgroup(OscarConnection *conn, guint16 group)
 {
 	aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
 	struct snacgroup *sg;
 
-	if (!(sg = malloc(sizeof(struct snacgroup))))
-		return;
+	sg = malloc(sizeof(struct snacgroup));
 
 	gaim_debug_misc("oscar", "adding group 0x%04x\n", group);
 	sg->group = group;
 
 	sg->next = ins->groups;
 	ins->groups = sg;
-
-	return;
 }
 
-faim_export OscarConnection *aim_conn_findbygroup(OscarSession *sess, guint16 group)
+OscarConnection *
+aim_conn_findbygroup(OscarSession *sess, guint16 group)
 {
 	OscarConnection *cur;
 
-	for (cur = sess->connlist; cur; cur = cur->next) {
+	for (cur = sess->connlist; cur; cur = cur->next)
+	{
 		aim_conn_inside_t *ins = (aim_conn_inside_t *)cur->inside;
 		struct snacgroup *sg;
 
-		for (sg = ins->groups; sg; sg = sg->next) {
+		for (sg = ins->groups; sg; sg = sg->next)
+		{
 			if (sg->group == group)
 				return cur;
 		}
@@ -130,28 +127,28 @@
 	return NULL;
 }
 
-static void connkill_snacgroups(struct snacgroup **head)
+static void
+connkill_snacgroups(struct snacgroup *head)
 {
 	struct snacgroup *sg;
 
-	for (sg = *head; sg; ) {
+	for (sg = head; sg; )
+	{
 		struct snacgroup *tmp;
 
 		tmp = sg->next;
 		free(sg);
 		sg = tmp;
 	}
-
-	*head = NULL;
-
-	return;
 }
 
-static void connkill_rates(struct rateclass **head)
+static void
+connkill_rates(struct rateclass *head)
 {
 	struct rateclass *rc;
 
-	for (rc = *head; rc; ) {
+	for (rc = head; rc; )
+	{
 		struct rateclass *tmp;
 		struct snacpair *sp;
 
@@ -168,40 +165,36 @@
 
 		rc = tmp;
 	}
-
-	*head = NULL;
-
-	return;
 }
 
-static void connkill_real(OscarSession *sess, OscarConnection **deadconn)
+static void
+connkill_real(OscarSession *sess, OscarConnection *conn)
 {
 
-	aim_rxqueue_cleanbyconn(sess, *deadconn);
-	aim_tx_cleanqueue(sess, *deadconn);
+	aim_rxqueue_cleanbyconn(sess, conn);
+	aim_tx_cleanqueue(sess, conn);
 
-	if ((*deadconn)->fd != -1)
-		aim_conn_close(*deadconn);
+	if (conn->fd != -1)
+		aim_conn_close(conn);
 
 	/*
 	 * This will free ->internal if it necessary...
 	 */
-	if ((*deadconn)->type == AIM_CONN_TYPE_CHAT)
-		aim_conn_kill_chat(sess, *deadconn);
+	if (conn->type == AIM_CONN_TYPE_CHAT)
+		aim_conn_kill_chat(sess, conn);
 
-	if ((*deadconn)->inside) {
-		aim_conn_inside_t *inside = (aim_conn_inside_t *)(*deadconn)->inside;
+	if (conn->inside)
+	{
+		aim_conn_inside_t *inside = (aim_conn_inside_t *)conn->inside;
 
-		connkill_snacgroups(&inside->groups);
-		connkill_rates(&inside->rates);
+		connkill_snacgroups(inside->groups);
+		connkill_rates(inside->rates);
 
 		free(inside);
 	}
 
-	free(*deadconn);
-	*deadconn = NULL;
-
-	return;
+	gaim_circ_buffer_destroy(conn->buffer_outgoing);
+	free(conn);
 }
 
 /**
@@ -218,7 +211,7 @@
 	if (!sess || !conn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x04, 0)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x04, 0)))
 		return -ENOMEM;
 
 	aim_tx_enqueue(sess, fr);
@@ -227,83 +220,31 @@
 }
 
 /**
- * Clears out the connection list, killing remaining connections.
- *
- * @param sess Session to be cleared.
- */
-static void aim_connrst(OscarSession *sess)
-{
-
-	if (sess->connlist) {
-		OscarConnection *cur = sess->connlist, *tmp;
-
-		/* Attempt to send the log-off packet */
-		if (cur->type == AIM_CONN_TYPE_BOS)
-			aim_flap_close(sess, cur);
-
-		while (cur) {
-			tmp = cur->next;
-			aim_conn_close(cur);
-			connkill_real(sess, &cur);
-			cur = tmp;
-		}
-	}
-
-	sess->connlist = NULL;
-
-	return;
-}
-
-/**
- * Initializes and/or resets a connection structure to the default values.
- *
- * @param deadconn Connection to be reset.
- */
-static void aim_conn_init(OscarConnection *deadconn)
-{
-
-	if (!deadconn)
-		return;
-
-	deadconn->fd = -1;
-	deadconn->subtype = -1;
-	deadconn->type = -1;
-	deadconn->seqnum = 0;
-	deadconn->lastactivity = 0;
-	deadconn->forcedlatency = 0;
-	deadconn->handlerlist = NULL;
-	deadconn->priv = NULL;
-	memset(deadconn->inside, 0, sizeof(aim_conn_inside_t));
-
-	return;
-}
-
-/**
  * Allocate a new empty connection structure.
  *
- * @param sess Session
+ * @param sess The oscar session associated with this connection.
  * @return Returns the new connection structure.
  */
-static OscarConnection *aim_conn_getnext(OscarSession *sess)
+static OscarConnection *
+aim_conn_getnext(OscarSession *sess)
 {
-	OscarConnection *newconn;
-
-	if (!(newconn = malloc(sizeof(OscarConnection))))
-		return NULL;
-	memset(newconn, 0, sizeof(OscarConnection));
+	OscarConnection *conn;
 
-	if (!(newconn->inside = malloc(sizeof(aim_conn_inside_t)))) {
-		free(newconn);
-		return NULL;
-	}
-	memset(newconn->inside, 0, sizeof(aim_conn_inside_t));
+	conn = g_new0(OscarConnection, 1);
+	conn->inside = g_new0(aim_conn_inside_t, 1);
+	conn->buffer_outgoing = gaim_circ_buffer_new(-1);
+	conn->fd = -1;
+	conn->subtype = -1;
+	conn->type = -1;
+	conn->seqnum = 0;
+	conn->lastactivity = 0;
+	conn->forcedlatency = 0;
+	conn->handlerlist = NULL;
 
-	aim_conn_init(newconn);
+	conn->next = sess->connlist;
+	sess->connlist = conn;
 
-	newconn->next = sess->connlist;
-	sess->connlist = newconn;
-
-	return newconn;
+	return conn;
 }
 
 /**
@@ -313,7 +254,8 @@
  * @param sess Session for the connection.
  * @param deadconn Connection to be freed.
  */
-faim_export void aim_conn_kill(OscarSession *sess, OscarConnection **deadconn)
+void
+aim_conn_kill(OscarSession *sess, OscarConnection **deadconn)
 {
 	OscarConnection *cur, **prev;
 
@@ -331,15 +273,13 @@
 	if (!cur)
 		return; /* oops */
 
-	connkill_real(sess, &cur);
-
-	return;
+	connkill_real(sess, cur);
 }
 
 /**
  * Close (but not free) a connection.
  *
- * This leaves everything untouched except for clearing the 
+ * This leaves everything untouched except for clearing the
  * handler list and setting the fd to -1 (used to recognize
  * dead connections).  It will also remove cookies if necessary.
  *
@@ -348,7 +288,8 @@
  *
  * @param deadconn The connection to close.
  */
-faim_export void aim_conn_close(OscarConnection *deadconn)
+void
+aim_conn_close(OscarConnection *deadconn)
 {
 	aim_rxcallback_t userfunc;
 
@@ -362,12 +303,10 @@
 
 	if (deadconn->handlerlist)
 		aim_clearhandlers(deadconn);
-
-	return;
 }
 
 /**
- * Locates a connection of the specified type in the 
+ * Locates a connection of the specified type in the
  * specified session.
  *
  * XXX - Except for rendezvous, all uses of this should be removed and
@@ -378,7 +317,8 @@
  * @return Returns the first connection found of the given target type,
  *         or NULL if none could be found.
  */
-faim_export OscarConnection *aim_getconn_type(OscarSession *sess, int type)
+OscarConnection *
+aim_getconn_type(OscarSession *sess, int type)
 {
 	OscarConnection *cur;
 
@@ -391,7 +331,8 @@
 	return cur;
 }
 
-faim_export OscarConnection *aim_getconn_type_all(OscarSession *sess, int type)
+OscarConnection *
+aim_getconn_type_all(OscarSession *sess, int type)
 {
 	OscarConnection *cur;
 
@@ -404,7 +345,8 @@
 }
 
 /* If you pass -1 for the fd, you'll get what you ask for.  Gibberish. */
-faim_export OscarConnection *aim_getconn_fd(OscarSession *sess, int fd)
+OscarConnection *
+aim_getconn_fd(OscarSession *sess, int fd)
 {
 	OscarConnection *cur;
 
@@ -420,15 +362,14 @@
  * Clone an OscarConnection.
  *
  * A new connection is allocated, and the values are filled in
- * appropriately. Note that this function sets the new connnection's
- * ->priv pointer to be equal to that of its parent: only the pointer
- * is copied, not the data it points to.
+ * appropriately.
  *
  * @param sess The session containing this connection.
  * @param src The connection to clone.
  * @return Returns a pointer to the new OscarConnection, or %NULL on error.
  */
-faim_internal OscarConnection *aim_cloneconn(OscarSession *sess, OscarConnection *src)
+OscarConnection *
+aim_cloneconn(OscarSession *sess, OscarConnection *src)
 {
 	OscarConnection *conn;
 
@@ -439,7 +380,6 @@
 	conn->type = src->type;
 	conn->subtype = src->subtype;
 	conn->seqnum = src->seqnum;
-	conn->priv = src->priv;
 	conn->internal = src->internal;
 	conn->lastactivity = src->lastactivity;
 	conn->forcedlatency = src->forcedlatency;
@@ -451,7 +391,7 @@
 		 * XXX should clone this section as well, but since currently
 		 * this function only gets called for some of that rendezvous
 		 * crap, and not on SNAC connections, its probably okay for
-		 * now. 
+		 * now.
 		 *
 		 */
 	}
@@ -470,7 +410,8 @@
  * @param sess Session to create connection in
  * @param type Type of connection to create
  */
-faim_export OscarConnection *aim_newconn(OscarSession *sess, int type)
+OscarConnection *
+aim_newconn(OscarSession *sess, int type)
 {
 	OscarConnection *conn;
 
@@ -518,7 +459,8 @@
  * @param newval Number of seconds to force between transmits.
  * @return Returns -1 if the connection does not exist, zero otherwise.
  */
-faim_export int aim_conn_setlatency(OscarConnection *conn, int newval)
+int
+aim_conn_setlatency(OscarConnection *conn, int newval)
 {
 
 	if (!conn)
@@ -531,25 +473,19 @@
 }
 
 /**
- * Initializes a session structure by setting the initial values
- * stuff in the OscarSession struct.
- *
- * @param sess Session to initialize.
- * @param nonblocking Set to true if you want connections to be non-blocking.
+ * Allocates a new OscarSession and initializes it with default values.
  */
-faim_export void aim_session_init(OscarSession *sess, guint8 nonblocking)
+OscarSession *
+oscar_session_new(void)
 {
+	OscarSession *sess;
 
-	if (!sess)
-		return;
+	sess = g_new(OscarSession, 1);
 
-	memset(sess, 0, sizeof(OscarSession));
-	aim_connrst(sess);
 	sess->queue_outgoing = NULL;
 	sess->queue_incoming = NULL;
 	aim_initsnachash(sess);
 	sess->msgcookies = NULL;
-	sess->nonblocking = nonblocking;
 	sess->modlistv = NULL;
 	sess->snacid_next = 0x00000001;
 
@@ -603,7 +539,7 @@
 	aim__registermodule(sess, auth_modfirst);
 	aim__registermodule(sess, email_modfirst);
 
-	return;
+	return sess;
 }
 
 /**
@@ -611,15 +547,30 @@
  *
  * @param sess Session to kill
  */
-faim_export void aim_session_kill(OscarSession *sess)
+void
+oscar_session_destroy(OscarSession *sess)
 {
 	aim_cleansnacs(sess, -1);
 
-	aim_logoff(sess);
+	if (sess->connlist) {
+		OscarConnection *cur = sess->connlist, *tmp;
+
+		/* Attempt to send the log-off packet */
+		if (cur->type == AIM_CONN_TYPE_BOS)
+			aim_flap_close(sess, cur);
+
+		while (cur) {
+			tmp = cur->next;
+			aim_conn_close(cur);
+			connkill_real(sess, cur);
+			cur = tmp;
+		}
+	}
+	sess->connlist = NULL;
 
 	aim__shutdownmodules(sess);
 
-	return;
+	g_free(sess);
 }
 
 /**
@@ -630,7 +581,8 @@
  *         connecting (or if it just completed and
  *         aim_conn_completeconnect() has yet to be called on it).
  */
-faim_export int aim_conn_isconnecting(OscarConnection *conn)
+int
+aim_conn_isconnecting(OscarConnection *conn)
 {
 
 	if (!conn)
@@ -642,7 +594,8 @@
 /*
  * XXX this is nearly as ugly as proxyconnect().
  */
-faim_export int aim_conn_completeconnect(OscarSession *sess, OscarConnection *conn)
+int
+aim_conn_completeconnect(OscarSession *sess, OscarConnection *conn)
 {
 	aim_rxcallback_t userfunc;
 
@@ -665,7 +618,8 @@
 	return 0;
 }
 
-faim_export OscarSession *aim_conn_getsess(OscarConnection *conn)
+OscarSession *
+aim_conn_getsess(OscarConnection *conn)
 {
 
 	if (!conn)
@@ -675,27 +629,15 @@
 }
 
 /**
- * Close -ALL- open connections.
- *
- * @param sess The session.
- * @return Zero.
- */
-faim_export int aim_logoff(OscarSession *sess)
-{
-	aim_connrst(sess);  /* in case we want to connect again */
-
-	return 0;
-}
-
-/**
  * No-op.  This sends an empty channel 5 SNAC.  WinAIM 4.x and higher
  * sends these _every minute_ to keep the connection alive.
  */
-faim_export int aim_flap_nop(OscarSession *sess, OscarConnection *conn)
+int
+aim_flap_nop(OscarSession *sess, OscarConnection *conn)
 {
 	FlapFrame *fr;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x05, 0)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x05, 0)))
 		return -ENOMEM;
 
 	aim_tx_enqueue(sess, fr);
--- a/src/protocols/oscar/family_admin.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_admin.c	Sun Feb 12 21:27:04 2006 +0000
@@ -42,7 +42,7 @@
 	FlapFrame *fr;
 	aim_snacid_t snacid;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0007, 0x0002, 0x0000, NULL, 0);
@@ -123,7 +123,7 @@
 	aim_snacid_t snacid;
 	aim_tlvlist_t *tl = NULL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newnick))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newnick))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
@@ -150,7 +150,7 @@
 	aim_tlvlist_t *tl = NULL;
 	aim_snacid_t snacid;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
@@ -180,7 +180,7 @@
 	aim_snacid_t snacid;
 	aim_tlvlist_t *tl = NULL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
--- a/src/protocols/oscar/family_alert.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_alert.c	Sun Feb 12 21:27:04 2006 +0000
@@ -46,7 +46,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_ALERT)))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16+16)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16+16)))
 		return -ENOMEM;
 	snacid = aim_cachesnac(sess, 0x0018, 0x0006, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x0018, 0x0006, 0x0000, snacid);
@@ -177,7 +177,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_ALERT)))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+16)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+16)))
 		return -ENOMEM;
 	snacid = aim_cachesnac(sess, 0x0018, 0x0016, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x0018, 0x0016, 0x0000, snacid);
--- a/src/protocols/oscar/family_auth.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_auth.c	Sun Feb 12 21:27:04 2006 +0000
@@ -127,7 +127,7 @@
 {
 	FlapFrame *fr;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4)))
 		return -ENOMEM;
 
 	aimbs_put32(&fr->data, 0x00000001);
@@ -150,7 +150,7 @@
 	FlapFrame *fr;
 	aim_tlvlist_t *tl = NULL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4+2+2+length)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4+2+2+length)))
 		return -ENOMEM;
 
 	aimbs_put32(&fr->data, 0x00000001);
@@ -180,7 +180,7 @@
 	if (passwdlen > MAXICQPASSLEN)
 		passwdlen = MAXICQPASSLEN;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 1152))) {
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 1152))) {
 		free(password_encoded);
 		return -ENOMEM;
 	}
@@ -258,7 +258,7 @@
 		return goddamnicq2(sess, conn, sn, password, ci);
 #endif
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0017, 0x0002, 0x0000, NULL, 0);
@@ -529,7 +529,7 @@
 
 	aim_sendflapver(sess, conn);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(sn)+8 )))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(sn)+8 )))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0017, 0x0006, 0x0000, NULL, 0);
@@ -614,7 +614,7 @@
 
 	len = strlen(securid);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+len)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+len)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, OSCAR_FAMILY_AUTH, OSCAR_SUBTYPE_AUTH_SECURID_RESPONSE, 0x0000, NULL, 0);
--- a/src/protocols/oscar/family_bart.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_bart.c	Sun Feb 12 21:27:04 2006 +0000
@@ -46,7 +46,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !icon || !iconlen)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2+iconlen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2+iconlen)))
 		return -ENOMEM;
 	snacid = aim_cachesnac(sess, 0x0010, 0x0002, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x0010, 0x0002, 0x0000, snacid);
@@ -104,7 +104,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !sn || !strlen(sn) || !iconcsum || !iconcsumlen)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 4 + 1+iconcsumlen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 4 + 1+iconcsumlen)))
 		return -ENOMEM;
 	snacid = aim_cachesnac(sess, 0x0010, 0x0004, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x0010, 0x0004, 0x0000, snacid);
--- a/src/protocols/oscar/family_bos.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_bos.c	Sun Feb 12 21:27:04 2006 +0000
@@ -139,7 +139,7 @@
 	listcount = aimutil_itemcnt(localcpy, '&');
 	packlen = aimutil_tokslen(localcpy, 99, '&') + listcount + 9;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, packlen))) {
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, packlen))) {
 		free(localcpy);
 		return -ENOMEM;
 	}
--- a/src/protocols/oscar/family_buddy.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_buddy.c	Sun Feb 12 21:27:04 2006 +0000
@@ -100,7 +100,7 @@
 	if (!sn || !strlen(sn))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
@@ -141,7 +141,7 @@
 		tmpptr = strtok(NULL, "&");
 	}
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+len)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+len)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, NULL, 0);
@@ -180,7 +180,7 @@
 	if (!sn || !strlen(sn))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
@@ -208,7 +208,7 @@
 	if (!sess || !conn || !info)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0003, 0x000b, 0x0000, NULL, 0);
@@ -235,7 +235,7 @@
 	if (!sess || !conn || !sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0003, 0x000c, 0x0000, NULL, 0);
--- a/src/protocols/oscar/family_chat.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_chat.c	Sun Feb 12 21:27:04 2006 +0000
@@ -359,7 +359,7 @@
 	if (!sess || !conn || !msg || (msglen <= 0))
 		return 0;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x000e, 0x0005, 0x0000, NULL, 0);
--- a/src/protocols/oscar/family_chatnav.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_chatnav.c	Sun Feb 12 21:27:04 2006 +0000
@@ -52,7 +52,7 @@
 	aim_snacid_t snacid;
 	aim_tlvlist_t *tl = NULL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0);
--- a/src/protocols/oscar/family_feedbag.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_feedbag.c	Sun Feb 12 21:27:04 2006 +0000
@@ -1251,7 +1251,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_FEEDBAG)))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+2)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+2)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, OSCAR_FAMILY_FEEDBAG, OSCAR_SUBTYPE_FEEDBAG_REQIFCHANGED, 0x0000, NULL, 0);
@@ -1364,7 +1364,7 @@
 			snaclen += aim_tlvlist_size(&cur->item->data);
 	}
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, snaclen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, snaclen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, OSCAR_FAMILY_FEEDBAG, sess->ssi.pending->action, 0x0000, NULL, 0);
@@ -1712,7 +1712,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_FEEDBAG)) || !sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, OSCAR_FAMILY_FEEDBAG, OSCAR_SUBTYPE_FEEDBAG_SENDAUTH, 0x0000, NULL, 0);
@@ -1787,7 +1787,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_FEEDBAG)) || !sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, OSCAR_FAMILY_FEEDBAG, OSCAR_SUBTYPE_FEEDBAG_SENDAUTHREQ, 0x0000, NULL, 0);
@@ -1865,7 +1865,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_FEEDBAG)) || !sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 1 + 2+(msg ? strlen(msg)+1 : 0) + 2)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 1 + 2+(msg ? strlen(msg)+1 : 0) + 2)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, OSCAR_FAMILY_FEEDBAG, OSCAR_SUBTYPE_FEEDBAG_SENDAUTHREP, 0x0000, NULL, 0);
--- a/src/protocols/oscar/family_icbm.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_icbm.c	Sun Feb 12 21:27:04 2006 +0000
@@ -169,7 +169,7 @@
 	if (!params)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+16)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+16)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0002, 0x0000, NULL, 0);
@@ -314,7 +314,7 @@
 		msgtlvlen += 4 /* charset */ + args->msglen;
 	}
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, msgtlvlen+128)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, msgtlvlen+128)))
 		return -ENOMEM;
 
 	/* XXX - should be optional */
@@ -466,7 +466,7 @@
 
 	aim_icbm_makecookie(cookie);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152+strlen(sn)+strlen(roomname)+strlen(msg))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152+strlen(sn)+strlen(roomname)+strlen(msg))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, sn, strlen(sn)+1);
@@ -546,7 +546,7 @@
 
 	aim_icbm_makecookie(cookie);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn)+2+2+2+8+16+2+2+2+2+2+2+2+4+4+4+iconlen+strlen(AIM_ICONIDENT)+2+2)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn)+2+2+2+8+16+2+2+2+2+2+2+2+4+4+4+iconlen+strlen(AIM_ICONIDENT)+2+2)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
@@ -629,7 +629,7 @@
 
 	aim_icbm_makecookie(cookie);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+128+servdatalen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+128+servdatalen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
@@ -706,7 +706,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 256+strlen(sn))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 256+strlen(sn))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
@@ -903,7 +903,7 @@
 		aim_tlvlist_add_noval(&tl, 0x0003);
 	}
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(peer_connection->sn) + aim_tlvlist_size(&tl))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(peer_connection->sn) + aim_tlvlist_size(&tl))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, AIM_SNACFLAGS_DESTRUCTOR, peer_connection->cookie, sizeof(peer_connection->cookie));
@@ -935,7 +935,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !peer_connection)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(peer_connection->sn) + 4+2+8+16)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(peer_connection->sn) + 4+2+8+16)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
@@ -968,7 +968,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !peer_connection)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(peer_connection->sn) + 4+2+8+16)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(peer_connection->sn) + 4+2+8+16)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
@@ -1009,7 +1009,7 @@
 
 	aim_icbm_makecookie(cookie);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn) + 4+0x5e + 4)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn) + 4+0x5e + 4)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
@@ -1113,7 +1113,7 @@
 	if (!sn || !type || !message)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+3+strlen(sn)+12+strlen(message)+1+4)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+3+strlen(sn)+12+strlen(message)+1+4)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
@@ -2185,7 +2185,7 @@
 	if (!sess || !conn || !sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, strlen(sn)+13)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, strlen(sn)+13)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0008, 0x0000, sn, strlen(sn)+1);
@@ -2243,7 +2243,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sender)+6)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sender)+6)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x000b, 0x0000, NULL, 0);
@@ -2399,7 +2399,7 @@
 	if (!sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+11+strlen(sn)+2)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+11+strlen(sn)+2)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0004, 0x0014, 0x0000, NULL, 0);
--- a/src/protocols/oscar/family_icq.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_icq.c	Sun Feb 12 21:27:04 2006 +0000
@@ -37,7 +37,7 @@
 
 	bslen = 2 + 4 + 2 + 2;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
@@ -69,7 +69,7 @@
 
 	bslen = 2 + 4 + 2 + 2;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
@@ -102,7 +102,7 @@
 
 	bslen = 2+4+2+2+2+2+2+1+1+1+1+1+1;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
@@ -157,7 +157,7 @@
 		passwdlen = MAXICQPASSLEN;
 	bslen = 2+4+2+2+2+2+passwdlen+1;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
@@ -197,7 +197,7 @@
 
 	bslen = 2 + 4 + 2 + 2 + 2 + 4;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
@@ -242,7 +242,7 @@
 
 	bslen = 2 + 4 + 2 + 2 + 2 + 4;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
@@ -286,7 +286,7 @@
 
 	bslen = 2 + 4 + 2 + 2 + 2 + 4;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
@@ -324,7 +324,7 @@
 
 	bslen = 2 + 10 + 2 + strlen(xml) + 1;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
@@ -406,7 +406,7 @@
 
 	bslen = 37 + xmllen;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) {
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) {
 		free(xml);
 		return -ENOMEM;
 	}
--- a/src/protocols/oscar/family_locate.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_locate.c	Sun Feb 12 21:27:04 2006 +0000
@@ -1072,7 +1072,7 @@
 			aim_tlvlist_add_noval(&tl, 0x0004);
 	}
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0);
@@ -1101,7 +1101,7 @@
 
 	aim_tlvlist_add_caps(&tl, 0x0005, caps);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0);
@@ -1133,7 +1133,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_LOCATE)) || !sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 12+1+strlen(sn))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 12+1+strlen(sn))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, NULL, 0);
@@ -1246,7 +1246,7 @@
 	if (street)
 		aim_tlvlist_add_str(&tl, 0x0021, street);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0002, 0x0009, 0x0000, NULL, 0);
@@ -1274,7 +1274,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_LOCATE)) || !sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0002, 0x000b, 0x0000, NULL, 0);
@@ -1318,7 +1318,7 @@
 	if (interest5)
 		aim_tlvlist_add_str(&tl, 0x0000b, interest5);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0002, 0x000f, 0x0000, NULL, 0);
@@ -1353,7 +1353,7 @@
 	if (!sess || !(conn = aim_conn_findbygroup(sess, OSCAR_FAMILY_LOCATE)) || !sn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+1+strlen(sn))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+1+strlen(sn))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0002, 0x0015, 0x0000, sn, strlen(sn)+1);
--- a/src/protocols/oscar/family_odir.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_odir.c	Sun Feb 12 21:27:04 2006 +0000
@@ -53,7 +53,7 @@
 	aim_tlvlist_add_16(&tl, 0x000a, 0x0001); /* Type of search */
 	aim_tlvlist_add_str(&tl, 0x0005, email);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
 		return -ENOMEM;
 	snacid = aim_cachesnac(sess, 0x000f, 0x0002, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x000f, 0x0002, 0x0000, snacid);
@@ -121,7 +121,7 @@
 	if (address)
 		aim_tlvlist_add_str(&tl, 0x0021, address);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
 		return -ENOMEM;
 	snacid = aim_cachesnac(sess, 0x000f, 0x0002, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x000f, 0x0002, 0x0000, snacid);
@@ -158,7 +158,7 @@
 	if (interest)
 		aim_tlvlist_add_str(&tl, 0x0001, interest);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
 		return -ENOMEM;
 	snacid = aim_cachesnac(sess, 0x000f, 0x0002, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x000f, 0x0002, 0x0000, snacid);
--- a/src/protocols/oscar/family_oservice.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_oservice.c	Sun Feb 12 21:27:04 2006 +0000
@@ -38,7 +38,7 @@
 	if (!ins)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0001, 0x0002, 0x0000, NULL, 0);
@@ -131,7 +131,7 @@
 	if (!sess || !conn || !roomname || !strlen(roomname))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
 		return -ENOMEM;
 
 	memset(&csi, 0, sizeof(csi));
@@ -412,7 +412,7 @@
 	aim_snacid_t snacid;
 	struct rateclass *rc;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0001, 0x0008, 0x0000, NULL, 0);
@@ -434,7 +434,7 @@
 	aim_snacid_t snacid;
 	struct rateclass *rc;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 512)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0001, 0x0009, 0x0000, NULL, 0);
@@ -516,7 +516,7 @@
 	aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
 	struct snacgroup *sg;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1024)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1024)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0001, 0x000c, 0x0000, NULL, 0);
@@ -755,7 +755,7 @@
 	if (!ins)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0);
@@ -827,7 +827,7 @@
 
 	data = AIM_ICQ_STATE_HIDEIP | AIM_ICQ_STATE_DIRECTREQUIREAUTH | status;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 8)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 8)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0001, 0x001e, 0x0000, NULL, 0);
@@ -866,7 +866,7 @@
 		return -EINVAL;
 
 	if ((msg != NULL) && *msg != '\0') {
-		if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + strlen(msg) + 8)))
+		if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + strlen(msg) + 8)))
 			return -ENOMEM;
 
 		snacid = aim_cachesnac(sess, 0x0001, 0x001e, 0x0000, NULL, 0);
@@ -881,7 +881,7 @@
 		aimbs_putstr(&fr->data, msg);
 		aimbs_put16(&fr->data, 0x0000);
 	} else {
-		if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + 8)))
+		if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + 8)))
 			return -ENOMEM;
 
 		snacid = aim_cachesnac(sess, 0x0001, 0x001e, 0x0000, NULL, 0);
@@ -972,7 +972,7 @@
 	if (!sess || !conn)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x0001, 0x0020, 0x0000, NULL, 0);
--- a/src/protocols/oscar/family_userlookup.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/family_userlookup.c	Sun Feb 12 21:27:04 2006 +0000
@@ -67,7 +67,7 @@
 	if (!sess || !conn || !address)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+strlen(address))))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+strlen(address))))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, strdup(address), strlen(address)+1);
--- a/src/protocols/oscar/misc.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/misc.c	Sun Feb 12 21:27:04 2006 +0000
@@ -44,7 +44,7 @@
 	FlapFrame *fr;
 	aim_snacid_t snacid = 0x00000000;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10)))
 		return -ENOMEM;
 
 	aim_putsnac(&fr->data, family, subtype, 0x0000, snacid);
@@ -59,7 +59,7 @@
 	FlapFrame *fr;
 	aim_snacid_t snacid;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10)))
 		return -ENOMEM;
 
 	snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0);
@@ -78,7 +78,7 @@
 	if (!longdata)
 		return aim_genericreq_n(sess, conn, family, subtype);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4)))
 		return -ENOMEM; 
 
 	snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0);
@@ -99,7 +99,7 @@
 	if (!shortdata)
 		return aim_genericreq_n(sess, conn, family, subtype);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2)))
 		return -ENOMEM; 
 
 	snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0);
--- a/src/protocols/oscar/oscar.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/oscar.c	Sun Feb 12 21:27:04 2006 +0000
@@ -1842,8 +1842,7 @@
 	}
 	od->buddyinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, oscar_free_buddyinfo);
 
-	sess = g_new0(OscarSession, 1);
-	aim_session_init(sess, TRUE);
+	sess = oscar_session_new();
 	/*
 	 * We need an immediate queue because we don't use a while-loop
 	 * to see if things need to be sent.
@@ -1937,8 +1936,7 @@
 		gaim_timeout_remove(od->getinfotimer);
 	gaim_prefs_disconnect_by_handle(gc);
 
-	aim_session_kill(od->sess);
-	g_free(od->sess);
+	oscar_session_destroy(od->sess);
 	od->sess = NULL;
 	g_free(gc->proto_data);
 	gc->proto_data = NULL;
--- a/src/protocols/oscar/oscar.h	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/oscar.h	Sun Feb 12 21:27:04 2006 +0000
@@ -30,6 +30,7 @@
 #define _OSCAR_H_
 
 #include "debug.h"
+#include "gaim_buffer.h"
 #include "internal.h"
 
 #include <stdio.h>
@@ -390,16 +391,16 @@
 struct _OscarConnection
 {
 	int fd;
+	GaimCircBuffer *buffer_outgoing;
 	guint16 type;
 	guint16 subtype;
 	flap_seqnum_t seqnum;
 	guint32 status;
-	void *priv; /* misc data the client may want to store */
 	void *internal; /* internal conn-specific libfaim data */
 	time_t lastactivity; /* time of last transmit */
 	int forcedlatency;
 	void *handlerlist;
-	void *sessv; /* pointer to parent session */
+	OscarSession *sessv; /* pointer to parent session */
 	void *inside; /* only accessible from inside libfaim */
 	struct _OscarConnection *next;
 };
@@ -510,8 +511,6 @@
 		char password[128];
 	} socksproxy;
 
-	guint8 nonblocking;
-
 	/*
 	 * Outstanding snac handling
 	 *
@@ -579,8 +578,6 @@
 
 faim_export int aim_debugconn_sendconnect(OscarSession *sess, OscarConnection *conn);
 
-faim_export int aim_logoff(OscarSession *);
-
 /* the library should never call aim_conn_kill */
 faim_export void aim_conn_kill(OscarSession *sess, OscarConnection **deadconn);
 
@@ -636,7 +633,6 @@
 
 #define AIM_TX_QUEUED    0 /* default */
 #define AIM_TX_IMMEDIATE 1
-#define AIM_TX_USER      2
 faim_export int aim_tx_setenqueue(OscarSession *sess, int what, int (*func)(OscarSession *, FlapFrame *));
 
 faim_export int aim_tx_flushqueue(OscarSession *);
@@ -657,8 +653,9 @@
 faim_export int aim_conn_completeconnect(OscarSession *sess, OscarConnection *conn);
 faim_export int aim_conn_isconnecting(OscarConnection *conn);
 
-faim_export void aim_session_init(OscarSession *, guint8 nonblocking);
-faim_export void aim_session_kill(OscarSession *);
+OscarSession *oscar_session_new(void);
+void oscar_session_destroy(OscarSession *);
+
 faim_export OscarConnection *aim_getconn_type(OscarSession *, int type);
 faim_export OscarConnection *aim_getconn_type_all(OscarSession *, int type);
 faim_export OscarConnection *aim_getconn_fd(OscarSession *, int fd);
--- a/src/protocols/oscar/oscar_internal.h	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/oscar_internal.h	Sun Feb 12 21:27:04 2006 +0000
@@ -126,10 +126,9 @@
 faim_internal void aim_frame_destroy(FlapFrame *);
 
 /* txqueue.c */
-faim_internal FlapFrame *aim_tx_new(OscarSession *sess, OscarConnection *conn, guint8 framing, guint16 chan, int datalen);
+faim_internal FlapFrame *flap_frame_new(OscarSession *sess, OscarConnection *conn, guint8 framing, guint16 chan, int datalen);
 faim_internal int aim_tx_enqueue(OscarSession *, FlapFrame *);
 faim_internal int aim_bstream_send(ByteStream *bs, OscarConnection *conn, size_t count);
-faim_internal int aim_tx_sendframe(OscarSession *sess, FlapFrame *cur);
 faim_internal void aim_tx_cleanqueue(OscarSession *, OscarConnection *);
 
 /*
@@ -152,7 +151,6 @@
 faim_internal aim_snac_t *aim_remsnac(OscarSession *, aim_snacid_t id);
 faim_internal int aim_putsnac(ByteStream *, guint16 family, guint16 type, guint16 flags, aim_snacid_t id);
 
-/* Stored in ->priv of the service request SNAC for chats. */
 struct chatsnacinfo {
 	guint16 exchange;
 	char name[128];
--- a/src/protocols/oscar/peer.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/peer.c	Sun Feb 12 21:27:04 2006 +0000
@@ -285,7 +285,7 @@
 	if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS))
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0001, 0)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0001, 0)))
 		return -ENOMEM;
 	memcpy(fr->hdr.rend.magic, "ODC2", 4);
 	fr->hdr.rend.hdrlen = hdrlen + 8;
@@ -364,7 +364,7 @@
 	if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !msg)
 		return -EINVAL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, 0)))
+	if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, 0)))
 		return -ENOMEM;
 
 	memcpy(fr->hdr.rend.magic, "ODC2", 4);
@@ -943,7 +943,7 @@
 
 	aim_oft_dirconvert_tostupid(peer_connection->fh.name);
 
-	if (!(fr = aim_tx_new(sess, peer_connection->conn, AIM_FRAMETYPE_OFT, type, 0)))
+	if (!(fr = flap_frame_new(sess, peer_connection->conn, AIM_FRAMETYPE_OFT, type, 0)))
 		return -ENOMEM;
 
 	if (aim_oft_buildheader(&fr->data, &peer_connection->fh) == -1) {
--- a/src/protocols/oscar/snac.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/snac.c	Sun Feb 12 21:27:04 2006 +0000
@@ -35,7 +35,7 @@
 #include "oscar.h"
 
 /*
- * Called from aim_session_init() to initialize the hash.
+ * Called from oscar_session_new() to initialize the hash.
  */
 faim_internal void aim_initsnachash(OscarSession *sess)
 {
--- a/src/protocols/oscar/txqueue.c	Sun Feb 12 19:27:57 2006 +0000
+++ b/src/protocols/oscar/txqueue.c	Sun Feb 12 21:27:04 2006 +0000
@@ -46,31 +46,30 @@
  * chan = channel for FLAP, hdrtype for OFT
  *
  */
-faim_internal FlapFrame *aim_tx_new(OscarSession *sess, OscarConnection *conn, guint8 framing, guint16 chan, int datalen)
+FlapFrame *
+flap_frame_new(OscarSession *sess, OscarConnection *conn, guint8 framing, guint16 chan, int datalen)
 {
 	FlapFrame *fr;
 
 	if (!sess || !conn) {
-		gaim_debug_misc("oscar", "aim_tx_new: No session or no connection specified!\n");
+		gaim_debug_misc("oscar", "flap_frame_new: No session or no connection specified!\n");
 		return NULL;
 	}
 
 	/* For sanity... */
 	if ((conn->type == AIM_CONN_TYPE_RENDEZVOUS) || (conn->type == AIM_CONN_TYPE_LISTENER)) {
 		if (framing != AIM_FRAMETYPE_OFT) {
-			gaim_debug_misc("oscar", "aim_tx_new: attempted to allocate inappropriate frame type for rendezvous connection\n");
+			gaim_debug_misc("oscar", "flap_frame_new: attempted to allocate inappropriate frame type for rendezvous connection\n");
 			return NULL;
 		}
 	} else {
 		if (framing != AIM_FRAMETYPE_FLAP) {
-			gaim_debug_misc("oscar", "aim_tx_new: attempted to allocate inappropriate frame type for FLAP connection\n");
+			gaim_debug_misc("oscar", "flap_frame_new: attempted to allocate inappropriate frame type for FLAP connection\n");
 			return NULL;
 		}
 	}
 
-	if (!(fr = (FlapFrame *)calloc(1, sizeof(FlapFrame))))
-		return NULL;
-
+	fr = g_new0(FlapFrame, 1);
 	fr->conn = conn;
 	fr->hdrtype = framing;
 	if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
@@ -94,125 +93,8 @@
 	return fr;
 }
 
-/* 
- * This increments the tx command count, and returns the seqnum
- * that should be stamped on the next FLAP packet sent.  This is
- * normally called during the final step of packet preparation
- * before enqueuement (in aim_tx_enqueue()).
- */
-static flap_seqnum_t aim_get_next_txseqnum(OscarConnection *conn)
-{
-	flap_seqnum_t ret;
-
-	ret = ++conn->seqnum;
-
-	return ret;
-}
-
-/*
- * The overall purpose here is to enqueue the passed in command struct
- * into the outgoing (tx) queue.  Basically...
- *   1) Make a scope-irrelevant copy of the struct
- *   3) Mark as not-sent-yet
- *   4) Enqueue the struct into the list
- *   6) Return
- *
- * Note that this is only used when doing queue-based transmitting;
- * that is, when sess->tx_enqueue is set to &aim_tx_enqueue__queuebased.
- *
- */
-static int aim_tx_enqueue__queuebased(OscarSession *sess, FlapFrame *fr)
-{
-
-	if (!fr->conn) {
-		gaim_debug_warning("oscar", "aim_tx_enqueue: enqueueing packet with no connecetion\n");
-		fr->conn = aim_getconn_type(sess, AIM_CONN_TYPE_BOS);
-	}
-
-	if (fr->hdrtype == AIM_FRAMETYPE_FLAP) {
-		/* assign seqnum -- XXX should really not assign until hardxmit */
-		fr->hdr.flap.seqnum = aim_get_next_txseqnum(fr->conn);
-	}
-
-	fr->handled = 0; /* not sent yet */
-
-	/* see overhead note in aim_rxqueue counterpart */
-	if (!sess->queue_outgoing)
-		sess->queue_outgoing = fr;
-	else {
-		FlapFrame *cur;
-		for (cur = sess->queue_outgoing; cur->next; cur = cur->next);
-		cur->next = fr;
-	}
-
-	return 0;
-}
-
-/*
- * Parallel to aim_tx_enqueue__queuebased, however, this bypasses
- * the whole queue mess when you want immediate writes to happen.
- *
- * Basically the same as its __queuebased couterpart, however
- * instead of doing a list append, it just calls aim_tx_sendframe()
- * right here.
- *
- */
-static int aim_tx_enqueue__immediate(OscarSession *sess, FlapFrame *fr)
-{
-	int ret;
-
-	if (!fr->conn) {
-		gaim_debug_error("oscar", "aim_tx_enqueue: packet has no connection\n");
-		aim_frame_destroy(fr);
-		return 0;
-	}
-
-	if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
-		fr->hdr.flap.seqnum = aim_get_next_txseqnum(fr->conn);
-
-	fr->handled = 0; /* not sent yet */
-
-	ret = aim_tx_sendframe(sess, fr);
-
-	aim_frame_destroy(fr);
-
-	return ret;
-}
-
-faim_export int aim_tx_setenqueue(OscarSession *sess, int what, int (*func)(OscarSession *, FlapFrame *))
-{
-
-	if (what == AIM_TX_QUEUED)
-		sess->tx_enqueue = &aim_tx_enqueue__queuebased;
-	else if (what == AIM_TX_IMMEDIATE) 
-		sess->tx_enqueue = &aim_tx_enqueue__immediate;
-	else if (what == AIM_TX_USER) {
-		if (!func)
-			return -EINVAL;
-		sess->tx_enqueue = func;
-	} else
-		return -EINVAL; /* unknown action */
-
-	return 0;
-}
-
-faim_internal int aim_tx_enqueue(OscarSession *sess, FlapFrame *fr)
-{
-
-	/*
-	 * If we want to send on a connection that is in progress, we have to force
-	 * them to use the queue based version. Otherwise, use whatever they
-	 * want.
-	 */
-	if (fr && fr->conn &&
-			(fr->conn->status & AIM_CONN_STATUS_INPROGRESS)) {
-		return aim_tx_enqueue__queuebased(sess, fr);
-	}
-
-	return (*sess->tx_enqueue)(sess, fr);
-}
-
-static int aim_send(int fd, const void *buf, size_t count)
+static int
+aim_send(int fd, const void *buf, size_t count)
 {
 	int left, cur;
 
@@ -233,7 +115,8 @@
 	return cur;
 }
 
-faim_internal int aim_bstream_send(ByteStream *bs, OscarConnection *conn, size_t count)
+int
+aim_bstream_send(ByteStream *bs, OscarConnection *conn, size_t count)
 {
 	int wrote = 0;
 
@@ -279,7 +162,8 @@
 	return wrote;
 }
 
-static int sendframe_flap(OscarSession *sess, FlapFrame *fr)
+static int
+sendframe_flap(OscarSession *sess, FlapFrame *fr)
 {
 	ByteStream bs;
 	guint8 *bs_raw;
@@ -315,7 +199,8 @@
 	return err;
 }
 
-static int sendframe_rendezvous(OscarSession *sess, FlapFrame *fr)
+static int
+sendframe_rendezvous(OscarSession *sess, FlapFrame *fr)
 {
 	ByteStream bs;
 	guint8 *bs_raw;
@@ -350,7 +235,8 @@
 	return err;
 }
 
-faim_internal int aim_tx_sendframe(OscarSession *sess, FlapFrame *fr)
+static int
+aim_tx_sendframe(OscarSession *sess, FlapFrame *fr)
 {
 	if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
 		return sendframe_flap(sess, fr);
@@ -360,7 +246,8 @@
 	return -1;
 }
 
-faim_export int aim_tx_flushqueue(OscarSession *sess)
+int
+aim_tx_flushqueue(OscarSession *sess)
 {
 	FlapFrame *cur;
 
@@ -398,11 +285,12 @@
 }
 
 /*
- * This is responsible for removing sent commands from the transmit 
+ * This is responsible for removing sent commands from the transmit
  * queue. This is not a required operation, but it of course helps
- * reduce memory footprint at run time!  
+ * reduce memory footprint at run time!
  */
-faim_export void aim_tx_purgequeue(OscarSession *sess)
+void
+aim_tx_purgequeue(OscarSession *sess)
 {
 	FlapFrame *cur, **prev;
 
@@ -418,14 +306,15 @@
 }
 
 /**
- * Get rid of packets waiting for tx on a dying conn.  For now this 
- * simply marks all packets as sent and lets them disappear without 
+ * Get rid of packets waiting for tx on a dying conn.  For now this
+ * simply marks all packets as sent and lets them disappear without
  * warning.
  *
  * @param sess A session.
  * @param conn Connection that's dying.
  */
-faim_internal void aim_tx_cleanqueue(OscarSession *sess, OscarConnection *conn)
+void
+aim_tx_cleanqueue(OscarSession *sess, OscarConnection *conn)
 {
 	FlapFrame *cur;
 
@@ -436,3 +325,121 @@
 
 	return;
 }
+
+/*
+ * This increments the tx command count, and returns the seqnum
+ * that should be stamped on the next FLAP packet sent.  This is
+ * normally called during the final step of packet preparation
+ * before enqueuement (in aim_tx_enqueue()).
+ */
+static flap_seqnum_t
+aim_get_next_txseqnum(OscarConnection *conn)
+{
+	flap_seqnum_t ret;
+
+	ret = ++conn->seqnum;
+
+	return ret;
+}
+
+/*
+ * The overall purpose here is to enqueue the passed in command struct
+ * into the outgoing (tx) queue.  Basically...
+ *   1) Make a scope-irrelevant copy of the struct
+ *   3) Mark as not-sent-yet
+ *   4) Enqueue the struct into the list
+ *   6) Return
+ *
+ * Note that this is only used when doing queue-based transmitting;
+ * that is, when sess->tx_enqueue is set to &aim_tx_enqueue__queuebased.
+ *
+ */
+static int
+aim_tx_enqueue__queuebased(OscarSession *sess, FlapFrame *fr)
+{
+
+	if (!fr->conn) {
+		gaim_debug_warning("oscar", "aim_tx_enqueue: enqueueing packet with no connecetion\n");
+		fr->conn = aim_getconn_type(sess, AIM_CONN_TYPE_BOS);
+	}
+
+	if (fr->hdrtype == AIM_FRAMETYPE_FLAP) {
+		/* assign seqnum -- XXX should really not assign until hardxmit */
+		fr->hdr.flap.seqnum = aim_get_next_txseqnum(fr->conn);
+	}
+
+	fr->handled = 0; /* not sent yet */
+
+	/* see overhead note in aim_rxqueue counterpart */
+	if (!sess->queue_outgoing)
+		sess->queue_outgoing = fr;
+	else {
+		FlapFrame *cur;
+		for (cur = sess->queue_outgoing; cur->next; cur = cur->next);
+		cur->next = fr;
+	}
+
+	return 0;
+}
+
+/*
+ * Parallel to aim_tx_enqueue__queuebased, however, this bypasses
+ * the whole queue mess when you want immediate writes to happen.
+ *
+ * Basically the same as its __queuebased couterpart, however
+ * instead of doing a list append, it just calls aim_tx_sendframe()
+ * right here.
+ *
+ */
+static int
+aim_tx_enqueue__immediate(OscarSession *sess, FlapFrame *fr)
+{
+	int ret;
+
+	if (!fr->conn) {
+		gaim_debug_error("oscar", "aim_tx_enqueue: packet has no connection\n");
+		aim_frame_destroy(fr);
+		return 0;
+	}
+
+	if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
+		fr->hdr.flap.seqnum = aim_get_next_txseqnum(fr->conn);
+
+	fr->handled = 0; /* not sent yet */
+
+	ret = aim_tx_sendframe(sess, fr);
+
+	aim_frame_destroy(fr);
+
+	return ret;
+}
+
+int
+aim_tx_setenqueue(OscarSession *sess, int what, int (*func)(OscarSession *, FlapFrame *))
+{
+
+	if (what == AIM_TX_QUEUED)
+		sess->tx_enqueue = &aim_tx_enqueue__queuebased;
+	else if (what == AIM_TX_IMMEDIATE)
+		sess->tx_enqueue = &aim_tx_enqueue__immediate;
+	else
+		return -EINVAL; /* unknown action */
+
+	return 0;
+}
+
+int
+aim_tx_enqueue(OscarSession *sess, FlapFrame *fr)
+{
+	/*
+	 * If we want to send on a connection that is in progress, we have to force
+	 * them to use the queue based version. Otherwise, use whatever they
+	 * want.
+	 */
+	if (fr && fr->conn &&
+			(fr->conn->status & AIM_CONN_STATUS_INPROGRESS)) {
+		return aim_tx_enqueue__queuebased(sess, fr);
+	}
+
+	return (*sess->tx_enqueue)(sess, fr);
+}