aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/oscar/txqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/oscar/txqueue.c')
-rw-r--r--protocols/oscar/txqueue.c103
1 files changed, 60 insertions, 43 deletions
diff --git a/protocols/oscar/txqueue.c b/protocols/oscar/txqueue.c
index e48511fa..7ad2a3dd 100644
--- a/protocols/oscar/txqueue.c
+++ b/protocols/oscar/txqueue.c
@@ -31,10 +31,11 @@ aim_frame_t *aim_tx_new(aim_session_t *sess, aim_conn_t *conn, guint8 framing, g
return NULL;
}
- if (!(fr = (aim_frame_t *)g_new0(aim_frame_t,1)))
+ if (!(fr = (aim_frame_t *) g_new0(aim_frame_t, 1))) {
return NULL;
+ }
- fr->conn = conn;
+ fr->conn = conn;
fr->hdrtype = framing;
@@ -42,13 +43,14 @@ aim_frame_t *aim_tx_new(aim_session_t *sess, aim_conn_t *conn, guint8 framing, g
fr->hdr.flap.type = chan;
- } else
+ } else {
imcb_error(sess->aux_data, "unknown framing");
+ }
if (datalen > 0) {
guint8 *data;
- if (!(data = (unsigned char *)g_malloc(datalen))) {
+ if (!(data = (unsigned char *) g_malloc(datalen))) {
aim_frame_destroy(fr);
return NULL;
}
@@ -89,13 +91,14 @@ static int aim_tx_enqueue__queuebased(aim_session_t *sess, aim_frame_t *fr)
fr->handled = 0; /* not sent yet */
/* see overhead note in aim_rxqueue counterpart */
- if (!sess->queue_outgoing)
+ if (!sess->queue_outgoing) {
sess->queue_outgoing = fr;
- else {
+ } else {
aim_frame_t *cur;
- for (cur = sess->queue_outgoing; cur->next; cur = cur->next)
+ for (cur = sess->queue_outgoing; cur->next; cur = cur->next) {
;
+ }
cur->next = fr;
}
@@ -110,8 +113,8 @@ static int aim_tx_enqueue__queuebased(aim_session_t *sess, aim_frame_t *fr)
*
* Basically the same as its __queuebased couterpart, however
* instead of doing a list append, it just calls aim_tx_sendframe()
- * right here.
- *
+ * right here.
+ *
*/
static int aim_tx_enqueue__immediate(aim_session_t *sess, aim_frame_t *fr)
{
@@ -122,8 +125,9 @@ static int aim_tx_enqueue__immediate(aim_session_t *sess, aim_frame_t *fr)
return 0;
}
- if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
+ if (fr->hdrtype == AIM_FRAMETYPE_FLAP) {
fr->hdr.flap.seqnum = aim_get_next_txseqnum(fr->conn);
+ }
fr->handled = 0; /* not sent yet */
@@ -136,38 +140,40 @@ static int aim_tx_enqueue__immediate(aim_session_t *sess, aim_frame_t *fr)
int aim_tx_setenqueue(aim_session_t *sess, int what, int (*func)(aim_session_t *, aim_frame_t *))
{
-
- if (what == AIM_TX_QUEUED)
+
+ if (what == AIM_TX_QUEUED) {
sess->tx_enqueue = &aim_tx_enqueue__queuebased;
- else if (what == AIM_TX_IMMEDIATE)
+ } else if (what == AIM_TX_IMMEDIATE) {
sess->tx_enqueue = &aim_tx_enqueue__immediate;
- else if (what == AIM_TX_USER) {
- if (!func)
+ } else if (what == AIM_TX_USER) {
+ if (!func) {
return -EINVAL;
+ }
sess->tx_enqueue = func;
- } else
+ } else {
return -EINVAL; /* unknown action */
+ }
return 0;
}
int aim_tx_enqueue(aim_session_t *sess, aim_frame_t *fr)
{
-
+
/*
* If we want to send a connection thats inprogress, 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)) {
+ if (fr && fr->conn &&
+ (fr->conn->status & AIM_CONN_STATUS_INPROGRESS)) {
return aim_tx_enqueue__queuebased(sess, fr);
}
return (*sess->tx_enqueue)(sess, fr);
}
-/*
+/*
* aim_get_next_txseqnum()
*
* This increments the tx command count, and returns the seqnum
@@ -179,7 +185,7 @@ int aim_tx_enqueue(aim_session_t *sess, aim_frame_t *fr)
flap_seqnum_t aim_get_next_txseqnum(aim_conn_t *conn)
{
flap_seqnum_t ret;
-
+
ret = ++conn->seqnum;
return ret;
@@ -192,11 +198,12 @@ static int aim_send(int fd, const void *buf, size_t count)
for (cur = 0, left = count; left; ) {
int ret;
- ret = send(fd, ((unsigned char *)buf)+cur, left, 0);
- if (ret == -1)
+ ret = send(fd, ((unsigned char *) buf) + cur, left, 0);
+ if (ret == -1) {
return -1;
- else if (ret == 0)
+ } else if (ret == 0) {
return cur;
+ }
cur += ret;
left -= ret;
@@ -208,22 +215,25 @@ static int aim_send(int fd, const void *buf, size_t count)
static int aim_bstream_send(aim_bstream_t *bs, aim_conn_t *conn, size_t count)
{
int wrote = 0;
- if (!bs || !conn || (count < 0))
+
+ if (!bs || !conn || (count < 0)) {
return -EINVAL;
+ }
- if (count > aim_bstream_empty(bs))
+ if (count > aim_bstream_empty(bs)) {
count = aim_bstream_empty(bs); /* truncate to remaining space */
+ }
if (count) {
if (count - wrote) {
wrote = wrote + aim_send(conn->fd, bs->data + bs->offset + wrote, count - wrote);
}
-
+
}
-
+
bs->offset += wrote;
- return wrote;
+ return wrote;
}
static int sendframe_flap(aim_session_t *sess, aim_frame_t *fr)
@@ -234,8 +244,9 @@ static int sendframe_flap(aim_session_t *sess, aim_frame_t *fr)
payloadlen = aim_bstream_curpos(&fr->data);
- if (!(obs_raw = g_malloc(6 + payloadlen)))
+ if (!(obs_raw = g_malloc(6 + payloadlen))) {
return -ENOMEM;
+ }
aim_bstream_init(&obs, obs_raw, 6 + payloadlen);
@@ -251,9 +262,10 @@ static int sendframe_flap(aim_session_t *sess, aim_frame_t *fr)
obslen = aim_bstream_curpos(&obs);
aim_bstream_rewind(&obs);
- if (aim_bstream_send(&obs, fr->conn, obslen) != obslen)
+ if (aim_bstream_send(&obs, fr->conn, obslen) != obslen) {
err = -errno;
-
+ }
+
g_free(obs_raw); /* XXX aim_bstream_free */
fr->handled = 1;
@@ -264,8 +276,9 @@ static int sendframe_flap(aim_session_t *sess, aim_frame_t *fr)
int aim_tx_sendframe(aim_session_t *sess, aim_frame_t *fr)
{
- if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
+ if (fr->hdrtype == AIM_FRAMETYPE_FLAP) {
return sendframe_flap(sess, fr);
+ }
return -1;
}
@@ -275,19 +288,21 @@ int aim_tx_flushqueue(aim_session_t *sess)
for (cur = sess->queue_outgoing; cur; cur = cur->next) {
- if (cur->handled)
- continue; /* already been sent */
+ if (cur->handled) {
+ continue; /* already been sent */
- if (cur->conn && (cur->conn->status & AIM_CONN_STATUS_INPROGRESS))
+ }
+ if (cur->conn && (cur->conn->status & AIM_CONN_STATUS_INPROGRESS)) {
continue;
+ }
/*
* And now for the meager attempt to force transmit
* latency and avoid missed messages.
*/
if ((cur->conn->lastactivity + cur->conn->forcedlatency) >= time(NULL)) {
- /*
- * XXX should be a break! we dont want to block the
+ /*
+ * XXX should be a break! we dont want to block the
* upper layers
*
* XXX or better, just do this right.
@@ -308,10 +323,10 @@ int aim_tx_flushqueue(aim_session_t *sess)
/*
* aim_tx_purgequeue()
- *
- * This is responsable for removing sent commands from the transmit
+ *
+ * This is responsable 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!
*
*/
void aim_tx_purgequeue(aim_session_t *sess)
@@ -325,8 +340,9 @@ void aim_tx_purgequeue(aim_session_t *sess)
aim_frame_destroy(cur);
- } else
+ } else {
prev = &cur->next;
+ }
}
return;
@@ -346,8 +362,9 @@ void aim_tx_cleanqueue(aim_session_t *sess, aim_conn_t *conn)
aim_frame_t *cur;
for (cur = sess->queue_outgoing; cur; cur = cur->next) {
- if (cur->conn == conn)
+ if (cur->conn == conn) {
cur->handled = 1;
+ }
}
return;