annotate libfaim/aim_rxqueue.c @ 763:4aeb969c70c9

[gaim-migrate @ 773] away messages should stop overwriting each other now committer: Tailor Script <tailor@pidgin.im>
author Todd Kulesza <fflewddur>
date Fri, 25 Aug 2000 02:59:42 +0000
parents 6e318907bcce
children 9a123b171f46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
2 * aim_rxqueue.c
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
3 *
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
4 * This file contains the management routines for the receive
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
5 * (incoming packet) queue. The actual packet handlers are in
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
6 * aim_rxhandlers.c.
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8
283
0f14e6d8a51b [gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 279
diff changeset
9 #include <faim/aim.h>
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 /*
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
12 * Grab a single command sequence off the socket, and enqueue
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
13 * it in the incoming event queue in a seperate struct.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
14 */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
15 int aim_get_command(struct aim_session_t *sess, struct aim_conn_t *conn)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 {
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
17 unsigned char generic[6];
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
18 struct command_rx_struct *newrx = NULL;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
20 if (!sess || !conn)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
21 return 0;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
23 if (conn->fd < 3) /* can happen when people abuse the interface */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
24 return 0;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
26 /*
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
27 * Rendezvous (client-client) connections do not speak
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
28 * FLAP, so this function will break on them.
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
29 */
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
30 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS)
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
31 return aim_get_command_rendezvous(sess, conn);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
32 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
33 return 0;
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
34
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
35 /*
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
36 * Read FLAP header. Six bytes:
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
37 *
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
38 * 0 char -- Always 0x2a
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
39 * 1 char -- Channel ID. Usually 2 -- 1 and 4 are used during login.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
40 * 2 short -- Sequence number
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
41 * 4 short -- Number of data bytes that follow.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
42 */
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
43 faim_mutex_lock(&conn->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
44 if (read(conn->fd, generic, 6) < 6){
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
45 aim_conn_close(conn);
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
46 faim_mutex_unlock(&conn->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
47 return -1;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
48 }
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
50 /*
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
51 * This shouldn't happen unless the socket breaks, the server breaks,
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
52 * or we break. We must handle it just in case.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
53 */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
54 if (generic[0] != 0x2a) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
55 faimdprintf(1, "Bad incoming data!");
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
56 aim_conn_close(conn);
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
57 faim_mutex_unlock(&conn->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
58 return -1;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
59 }
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61 /* allocate a new struct */
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
62 if (!(newrx = (struct command_rx_struct *)malloc(sizeof(struct command_rx_struct)))) {
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
63 faim_mutex_unlock(&conn->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
64 return -1;
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
65 }
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
66 memset(newrx, 0x00, sizeof(struct command_rx_struct));
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
67
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
68 newrx->lock = 1; /* lock the struct */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
69
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
70 /* we're doing OSCAR if we're here */
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
71 newrx->hdrtype = AIM_FRAMETYPE_OSCAR;
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
72
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
73 /* store channel -- byte 2 */
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
74 newrx->hdr.oscar.type = (char) generic[1];
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
76 /* store seqnum -- bytes 3 and 4 */
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
77 newrx->hdr.oscar.seqnum = aimutil_get16(generic+2);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 /* store commandlen -- bytes 5 and 6 */
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
80 newrx->commandlen = aimutil_get16(generic+4);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
81
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
82 newrx->nofree = 0; /* free by default */
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84 /* malloc for data portion */
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
85 if (!(newrx->data = (u_char *) malloc(newrx->commandlen))) {
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
86 free(newrx);
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
87 faim_mutex_unlock(&conn->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
88 return -1;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
89 }
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 /* read the data portion of the packet */
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
92 if (read(conn->fd, newrx->data, newrx->commandlen) < newrx->commandlen){
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
93 free(newrx->data);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
94 free(newrx);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
95 aim_conn_close(conn);
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
96 faim_mutex_unlock(&conn->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
97 return -1;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
98 }
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
99 faim_mutex_unlock(&conn->active);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
101 newrx->conn = conn;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
103 newrx->next = NULL; /* this will always be at the bottom */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
104 newrx->lock = 0; /* unlock */
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 /* enqueue this packet */
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
107 if (sess->queue_incoming == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
108 sess->queue_incoming = newrx;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
109 } else {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
110 struct command_rx_struct *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
111
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
112 /*
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
113 * This append operation takes a while. It might be faster
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
114 * if we maintain a pointer to the last entry in the queue
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
115 * and just update that. Need to determine if the overhead
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
116 * to maintain that is lower than the overhead for this loop.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
117 */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
118 for (cur = sess->queue_incoming; cur->next; cur = cur->next)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
119 ;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
120 cur->next = newrx;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
121 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
122
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
123 newrx->conn->lastactivity = time(NULL);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
124
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
125 return 0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
126 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
127
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
128 /*
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
129 * Purge recieve queue of all handled commands (->handled==1). Also
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
130 * allows for selective freeing using ->nofree so that the client can
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
131 * keep the data for various purposes.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
132 *
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
133 * If ->nofree is nonzero, the frame will be delinked from the global list,
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
134 * but will not be free'ed. The client _must_ keep a pointer to the
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
135 * data -- libfaim will not! If the client marks ->nofree but
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
136 * does not keep a pointer, it's lost forever.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
137 *
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
138 */
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
139 void aim_purge_rxqueue(struct aim_session_t *sess)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140 {
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
141 struct command_rx_struct *cur = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
142 struct command_rx_struct *tmp;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
143
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
144 if (sess->queue_incoming == NULL)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
145 return;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
146
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
147 if (sess->queue_incoming->next == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
148 if (sess->queue_incoming->handled) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
149 tmp = sess->queue_incoming;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
150 sess->queue_incoming = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
151
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
152 if (!tmp->nofree) {
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
153 if (tmp->hdrtype == AIM_FRAMETYPE_OFT)
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
154 free(tmp->hdr.oft.hdr2);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
155 free(tmp->data);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
156 free(tmp);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
157 } else
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
158 tmp->next = NULL;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
159 }
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
160 return;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
161 }
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
163 for(cur = sess->queue_incoming; cur->next != NULL; ) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
164 if (cur->next->handled) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
165 tmp = cur->next;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
166 cur->next = tmp->next;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
167 if (!tmp->nofree) {
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
168 if (tmp->hdrtype == AIM_FRAMETYPE_OFT)
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
169 free(tmp->hdr.oft.hdr2);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
170 free(tmp->data);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
171 free(tmp);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
172 } else
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
173 tmp->next = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
174 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
175 cur = cur->next;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
176
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
177 /*
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
178 * Be careful here. Because of the way we just
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
179 * manipulated the pointer, cur may be NULL and
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
180 * the for() will segfault doing the check unless
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
181 * we find this case first.
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
182 */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
183 if (cur == NULL)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
184 break;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
185 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
186
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
187 return;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
188 }
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
189
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
190 /*
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
191 * Since aim_get_command will aim_conn_kill dead connections, we need
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
192 * to clean up the rxqueue of unprocessed connections on that socket.
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
193 *
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
194 * XXX: this is something that was handled better in the old connection
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
195 * handling method, but eh.
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
196 */
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
197 void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn)
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
198 {
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
199 struct command_rx_struct *currx;
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
200
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
201 for (currx = sess->queue_incoming; currx; currx = currx->next) {
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
202 if ((!currx->handled) && (currx->conn == conn))
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
203 currx->handled = 1;
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
204 }
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
205 return;
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
206 }