annotate src/protocols/oscar/rxqueue.c @ 9554:8b2451878e26

[gaim-migrate @ 10387] " This patch adds chat user status icons (voice / halfop / op / founder) to chats There's a screenshot here, showing ops, voices and ignored ops and voices http://nosnilmot.com/gaim/chatusers.png This required some changes in how the core stores the list of users in chats to be able to store the status too, which are detailed below. I also fixed up some memory leaks as I came across them (string values returned by gtk_tree_model_get() not being g_free()'d) and a minor bug in signals-test.c Conversation API: Changed: gaim_conv_chat_add_user() (added flags parameter) gaim_conv_chat_add_users() now (added GList of flags parameter) gaim_conv_chat_get_users() now returns a GList of GaimChatBuddy's gaim_conv_chat_set_users() now expects a GList of GaimChatBuddy's Added: gaim_conv_chat_set_user_flags() gaim_conv_chat_get_user_flags() gaim_conv_chat_find_user() gaim_conv_chat_cb_new() gaim_conv_chat_cb_find() gaim_conv_chat_cb_destroy() gaim_conv_chat_cb_get_name() Conversation UI ops: added: chat_update_user() Signals: Changed: chat-buddy-joining & chat-buddy-joined now include the user's flags Added: chat-buddy-flags for when user's flags change Added: gaim_marshal_VOID__POINTER_POINTER_POINTER_UINT_UINT (required for the new chat-buddy-flags signal) Protocol Plugins: All updated to work with above changes (obviously) User flags support added to IRC, Jabber and SILC New Files: pixmaps/status/default/ voice.svg halfop.svg op.svg founder.svg " --Stu Tomlinson committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sat, 17 Jul 2004 18:11:12 +0000
parents ec3e041dc3bd
children 9cafe038c95e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * This file contains the management routines for the receive
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 * (incoming packet) queue. The actual packet handlers are in
8880
ec3e041dc3bd [gaim-migrate @ 9649]
Mark Doliner <mark@kingant.net>
parents: 8735
diff changeset
4 * rxhandlers.c.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 #define FAIM_INTERNAL
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 #include <aim.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #ifndef _WIN32
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 #include <sys/socket.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 #endif
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 faim_internal int aim_recv(int fd, void *buf, size_t count)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
19 int left, cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
20
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
21 for (cur = 0, left = count; left; ) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
22 int ret;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
23
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
24 ret = recv(fd, ((unsigned char *)buf)+cur, left, 0);
2808
e79f30457998 [gaim-migrate @ 2821]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2706
diff changeset
25
e79f30457998 [gaim-migrate @ 2821]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2706
diff changeset
26 /* Of course EOF is an error, only morons disagree with that. */
e79f30457998 [gaim-migrate @ 2821]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2706
diff changeset
27 if (ret <= 0)
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
28 return -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
29
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
30 cur += ret;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
31 left -= ret;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
32 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
33
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
34 return cur;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
35 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
36
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
37 /*
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
38 * Read into a byte stream. Will not read more than count, but may read
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
39 * less if there is not enough room in the stream buffer.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
40 */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
41 faim_internal int aim_bstream_recv(aim_bstream_t *bs, int fd, size_t count)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
42 {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
43 int red = 0;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
44
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
45 if (!bs || (fd < 0) || (count < 0))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
46 return -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
47
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
48 if (count > (bs->len - bs->offset))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
49 count = bs->len - bs->offset; /* truncate to remaining space */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
50
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
51 if (count) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
52
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
53 red = aim_recv(fd, bs->data + bs->offset, count);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
54
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
55 if (red <= 0)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
56 return -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
57 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
58
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
59 bs->offset += red;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
60
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
61 return red;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
62 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
63
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
64 /**
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
65 * Free an aim_frame_t
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
66 *
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
67 * @param frame The frame to free.
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
68 * @return -1 on error; 0 on success.
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
69 */
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
70 faim_internal void aim_frame_destroy(aim_frame_t *frame)
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
71 {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
72
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
73 free(frame->data.data); /* XXX aim_bstream_free */
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
74 free(frame);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
75
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
76 return;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
77 }
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
78
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 /*
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
80 * Read a FLAP header from conn into fr, and return the number of
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
81 * bytes in the payload.
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
82 *
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
83 * @return -1 on error, otherwise return the length of the payload.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 */
5414
2d9f7d2e3558 [gaim-migrate @ 5790]
Mark Doliner <mark@kingant.net>
parents: 4617
diff changeset
85 static int aim_get_command_flap(aim_session_t *sess, aim_conn_t *conn, aim_frame_t *fr)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 {
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
87 fu8_t hdr_raw[6];
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
88 aim_bstream_t hdr;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
89
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
90 fr->hdrtype = AIM_FRAMETYPE_FLAP;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
92 /*
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
93 * Read FLAP header. Six bytes total.
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
94 *
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
95 * Byte # | Description
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
96 * -------|-------------
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
97 * 0x00 | Always 0x2a
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
98 * 0x01 | Channel number, usually "2." "1" is used during login,
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
99 * | 4 is used during logoff.
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
100 * 0x02 | Sequence number, 2 bytes.
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
101 * 0x04 | Number of data bytes that follow, 2 bytes.
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
102 */
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
103 aim_bstream_init(&hdr, hdr_raw, sizeof(hdr_raw));
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
104 if (aim_bstream_recv(&hdr, conn->fd, 6) < 6) {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
105 aim_conn_close(conn);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
106 return -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
107 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
109 aim_bstream_rewind(&hdr);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
110
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
111 /*
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
112 * This shouldn't happen unless the socket breaks, the server breaks,
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
113 * or we break. We must handle it just in case.
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
114 */
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
115 if (aimbs_get8(&hdr) != 0x2a) {
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
116 faimdprintf(sess, 0, "Invalid FLAP frame received on FLAP connection!");
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
117 aim_conn_close(conn);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
118 return -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
119 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
121 fr->hdr.flap.channel = aimbs_get8(&hdr);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
122 fr->hdr.flap.seqnum = aimbs_get16(&hdr);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
123
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
124 return aimbs_get16(&hdr);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
125 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
126
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
127 /*
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
128 * Read a rendezvous header from conn into fr, and return the number of
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
129 * bytes in the payload.
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
130 *
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
131 * @return -1 on error, otherwise return the length of the payload.
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
132 */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
133 static int aim_get_command_rendezvous(aim_session_t *sess, aim_conn_t *conn, aim_frame_t *fr)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
134 {
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
135 fu8_t hdr_raw[8];
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
136 aim_bstream_t hdr;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
137
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
138 fr->hdrtype = AIM_FRAMETYPE_OFT;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
139
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
140 /*
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
141 * Read rendezvous header
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
142 */
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
143 aim_bstream_init(&hdr, hdr_raw, sizeof(hdr_raw));
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
144 if (aim_bstream_recv(&hdr, conn->fd, 8) < 8) {
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
145 aim_conn_close(conn);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
146 return -1;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
147 }
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
148
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
149 aim_bstream_rewind(&hdr);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
150
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
151 aimbs_getrawbuf(&hdr, fr->hdr.rend.magic, 4);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
152 fr->hdr.rend.hdrlen = aimbs_get16(&hdr);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
153 fr->hdr.rend.type = aimbs_get16(&hdr);
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
154
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
155 return fr->hdr.rend.hdrlen - 8;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
156 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
158 /*
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
159 * Grab a single command sequence off the socket, and enqueue it in the incoming event queue
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
160 * in a separate struct.
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
161 *
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
162 * @return 0 on success, otherwise return the error number.
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
163 */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
164 faim_export int aim_get_command(aim_session_t *sess, aim_conn_t *conn)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
165 {
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
166 aim_frame_t *fr;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
167 int payloadlen;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
168
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
169 if (!sess || !conn)
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 3960
diff changeset
170 return -EINVAL;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
171
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
172 if (conn->fd == -1)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
173 return -1; /* it's an aim_conn_close()'d connection */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
174
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
175 if (conn->fd < 3) /* can happen when people abuse the interface */
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
176 return -1;
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
177
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
178 if (conn->status & AIM_CONN_STATUS_INPROGRESS)
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
179 return aim_conn_completeconnect(sess, conn);
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
180
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
181 if (!(fr = (aim_frame_t *)calloc(sizeof(aim_frame_t), 1)))
4617
858979ab3867 [gaim-migrate @ 4908]
Mark Doliner <mark@kingant.net>
parents: 3960
diff changeset
182 return -ENOMEM;
3952
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
183
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
184 /*
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
185 * Rendezvous (client to client) connections do not speak FLAP, so this
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
186 * function will break on them.
07283934dedd [gaim-migrate @ 4133]
Mark Doliner <mark@kingant.net>
parents: 2931
diff changeset
187 */
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
188 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS)
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
189 payloadlen = aim_get_command_rendezvous(sess, conn, fr);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
190 else if (conn->type == AIM_CONN_TYPE_LISTENER) {
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
191 faimdprintf(sess, 0, "AIM_CONN_TYPE_LISTENER on fd %d\n", conn->fd);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
192 free(fr);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
193 return -1;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
194 } else
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
195 payloadlen = aim_get_command_flap(sess, conn, fr);
5927
04dc7fe68889 [gaim-migrate @ 6367]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
196
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
197 if (payloadlen < 0) {
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
198 free(fr);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
199 return -1;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
200 }
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
201
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
202 if (payloadlen > 0) {
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
203 fu8_t *payload = NULL;
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
204
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
205 if (!(payload = (fu8_t *) malloc(payloadlen))) {
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
206 aim_frame_destroy(fr);
5927
04dc7fe68889 [gaim-migrate @ 6367]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
207 return -1;
04dc7fe68889 [gaim-migrate @ 6367]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
208 }
04dc7fe68889 [gaim-migrate @ 6367]
Mark Doliner <mark@kingant.net>
parents: 5414
diff changeset
209
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
210 aim_bstream_init(&fr->data, payload, payloadlen);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
212 /* read the payload */
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
213 if (aim_bstream_recv(&fr->data, conn->fd, payloadlen) < payloadlen) {
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
214 aim_frame_destroy(fr); /* free's payload */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
215 aim_conn_close(conn);
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
216 return -1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
217 }
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
218 } else
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
219 aim_bstream_init(&fr->data, NULL, 0);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
221 aim_bstream_rewind(&fr->data);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
223 fr->conn = conn;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
224
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
225 /* Enqueue this puppy */
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
226 fr->next = NULL; /* this will always be at the bottom */
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
227 if (sess->queue_incoming == NULL)
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
228 sess->queue_incoming = fr;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
229 else {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
230 aim_frame_t *cur;
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
231 for (cur = sess->queue_incoming; cur->next; cur = cur->next);
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
232 cur->next = fr;
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
233 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
234
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
235 fr->conn->lastactivity = time(NULL);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
236
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
237 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 /*
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 7806
diff changeset
241 * Purge receive queue of all handled commands (->handled==1).
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
244 faim_export void aim_purge_rxqueue(aim_session_t *sess)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
246 aim_frame_t *cur, **prev;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
248 for (prev = &sess->queue_incoming; (cur = *prev); ) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
249 if (cur->handled) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
250 *prev = cur->next;
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
251 aim_frame_destroy(cur);
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
252 } else
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
253 prev = &cur->next;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
254 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
256 return;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260 * Since aim_get_command will aim_conn_kill dead connections, we need
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261 * to clean up the rxqueue of unprocessed connections on that socket.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
262 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 * XXX: this is something that was handled better in the old connection
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
264 * handling method, but eh.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
265 */
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
266 faim_internal void aim_rxqueue_cleanbyconn(aim_session_t *sess, aim_conn_t *conn)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267 {
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
268 aim_frame_t *currx;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
270 for (currx = sess->queue_incoming; currx; currx = currx->next) {
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
271 if ((!currx->handled) && (currx->conn == conn))
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
272 currx->handled = 1;
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
273 }
7806
c86f075b269a [gaim-migrate @ 8453]
Mark Doliner <mark@kingant.net>
parents: 5927
diff changeset
274
2246
933346315b9b [gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
275 return;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276 }