Mercurial > pidgin.yaz
annotate src/protocols/oscar/chat.c @ 11074:ba630d7a7365
[gaim-migrate @ 13083]
sf patch #1233671, from Ryan McCabe
eliminate the usage of ->priv in libfaim
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 09 Jul 2005 19:26:49 +0000 |
parents | b45613311dab |
children | bd8ac1d4b2f2 |
rev | line source |
---|---|
2086 | 1 /* |
3952 | 2 * Family 0x000e - Routines for the Chat service. |
2086 | 3 * |
4 */ | |
5 | |
6 #define FAIM_INTERNAL | |
10271 | 7 #include <aim.h> |
2086 | 8 |
5927 | 9 #include <string.h> |
10 | |
11074 | 11 /* Stored in the ->internal of chat connections */ |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
12 struct chatconnpriv { |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
13 fu16_t exchange; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
14 char *name; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
15 fu16_t instance; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
16 }; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
17 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
18 faim_internal void aim_conn_kill_chat(aim_session_t *sess, aim_conn_t *conn) |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
19 { |
11074 | 20 struct chatconnpriv *ccp = (struct chatconnpriv *)conn->internal; |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
21 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
22 if (ccp) |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
23 free(ccp->name); |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
24 free(ccp); |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
25 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
26 return; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
27 } |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
28 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
29 faim_export char *aim_chat_getname(aim_conn_t *conn) |
2086 | 30 { |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
31 struct chatconnpriv *ccp; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
33 if (!conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
34 return NULL; |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
35 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
36 if (conn->type != AIM_CONN_TYPE_CHAT) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
37 return NULL; |
2086 | 38 |
11074 | 39 ccp = (struct chatconnpriv *)conn->internal; |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
40 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
41 return ccp->name; |
2086 | 42 } |
43 | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
44 /* XXX get this into conn.c -- evil!! */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
45 faim_export aim_conn_t *aim_chat_getconn(aim_session_t *sess, const char *name) |
2086 | 46 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
47 aim_conn_t *cur; |
2086 | 48 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
49 for (cur = sess->connlist; cur; cur = cur->next) { |
11074 | 50 struct chatconnpriv *ccp = (struct chatconnpriv *)cur->internal; |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
51 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
52 if (cur->type != AIM_CONN_TYPE_CHAT) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
53 continue; |
11074 | 54 if (!cur->internal) { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
55 faimdprintf(sess, 0, "faim: chat: chat connection with no name! (fd = %d)\n", cur->fd); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
56 continue; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
57 } |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
58 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
59 if (strcmp(ccp->name, name) == 0) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
60 break; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
61 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
62 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
63 return cur; |
2086 | 64 } |
65 | |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
66 faim_export int aim_chat_attachname(aim_conn_t *conn, fu16_t exchange, const char *roomname, fu16_t instance) |
2086 | 67 { |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
68 struct chatconnpriv *ccp; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
69 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
70 if (!conn || !roomname) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
71 return -EINVAL; |
2086 | 72 |
11074 | 73 if (conn->internal) |
74 free(conn->internal); | |
2086 | 75 |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
76 if (!(ccp = malloc(sizeof(struct chatconnpriv)))) |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
77 return -ENOMEM; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
78 |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
79 ccp->exchange = exchange; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
80 ccp->name = strdup(roomname); |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
81 ccp->instance = instance; |
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
82 |
11074 | 83 conn->internal = (void *)ccp; |
2086 | 84 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
85 return 0; |
2086 | 86 } |
87 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
88 faim_internal int aim_chat_readroominfo(aim_bstream_t *bs, struct aim_chat_roominfo *outinfo) |
2086 | 89 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
90 int namelen; |
2086 | 91 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
92 if (!bs || !outinfo) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
93 return 0; |
2086 | 94 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
95 outinfo->exchange = aimbs_get16(bs); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
96 namelen = aimbs_get8(bs); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
97 outinfo->name = aimbs_getstr(bs, namelen); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
98 outinfo->instance = aimbs_get16(bs); |
2086 | 99 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
100 return 0; |
2086 | 101 } |
102 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
103 faim_export int aim_chat_leaveroom(aim_session_t *sess, const char *name) |
2086 | 104 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
105 aim_conn_t *conn; |
2086 | 106 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
107 if (!(conn = aim_chat_getconn(sess, name))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
108 return -ENOENT; |
2086 | 109 |
10271 | 110 aim_conn_close(conn); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
111 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
112 return 0; |
2086 | 113 } |
114 | |
115 /* | |
3952 | 116 * Subtype 0x0002 - General room information. Lots of stuff. |
2086 | 117 * |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8283
diff
changeset
|
118 * Values I know are in here but I haven't attached |
2086 | 119 * them to any of the 'Unknown's: |
120 * - Language (English) | |
121 * | |
122 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
123 static int infoupdate(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
2086 | 124 { |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
125 aim_userinfo_t *userinfo = NULL; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
126 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
127 int ret = 0; |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
128 int usercount = 0; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
129 fu8_t detaillevel = 0; |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
130 char *roomname = NULL; |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
131 struct aim_chat_roominfo roominfo; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
132 fu16_t tlvcount = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
133 aim_tlvlist_t *tlvlist; |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
134 char *roomdesc = NULL; |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
135 fu16_t flags = 0; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
136 fu32_t creationtime = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
137 fu16_t maxmsglen = 0, maxvisiblemsglen = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
138 fu16_t unknown_d2 = 0, unknown_d5 = 0; |
2086 | 139 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
140 aim_chat_readroominfo(bs, &roominfo); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
141 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
142 detaillevel = aimbs_get8(bs); |
2086 | 143 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
144 if (detaillevel != 0x02) { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
145 faimdprintf(sess, 0, "faim: chat_roomupdateinfo: detail level %d not supported\n", detaillevel); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
146 return 1; |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
147 } |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
148 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
149 tlvcount = aimbs_get16(bs); |
2086 | 150 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
151 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
152 * Everything else are TLVs. |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
153 */ |
7167 | 154 tlvlist = aim_tlvlist_read(bs); |
2086 | 155 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
156 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
157 * TLV type 0x006a is the room name in Human Readable Form. |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
158 */ |
7167 | 159 if (aim_tlv_gettlv(tlvlist, 0x006a, 1)) |
160 roomname = aim_tlv_getstr(tlvlist, 0x006a, 1); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
161 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
162 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
163 * Type 0x006f: Number of occupants. |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
164 */ |
7167 | 165 if (aim_tlv_gettlv(tlvlist, 0x006f, 1)) |
166 usercount = aim_tlv_get16(tlvlist, 0x006f, 1); | |
2086 | 167 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
168 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
169 * Type 0x0073: Occupant list. |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
170 */ |
7167 | 171 if (aim_tlv_gettlv(tlvlist, 0x0073, 1)) { |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
172 int curoccupant = 0; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
173 aim_tlv_t *tmptlv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
174 aim_bstream_t occbs; |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
175 |
7167 | 176 tmptlv = aim_tlv_gettlv(tlvlist, 0x0073, 1); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
177 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
178 /* Allocate enough userinfo structs for all occupants */ |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
179 userinfo = calloc(usercount, sizeof(aim_userinfo_t)); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
180 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
181 aim_bstream_init(&occbs, tmptlv->value, tmptlv->length); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
182 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
183 while (curoccupant < usercount) |
5836 | 184 aim_info_extract(sess, &occbs, &userinfo[curoccupant++]); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
185 } |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
186 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
187 /* |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
188 * Type 0x00c9: Flags. (AIM_CHATROOM_FLAG) |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
189 */ |
7167 | 190 if (aim_tlv_gettlv(tlvlist, 0x00c9, 1)) |
191 flags = aim_tlv_get16(tlvlist, 0x00c9, 1); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
192 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
193 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
194 * Type 0x00ca: Creation time (4 bytes) |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
195 */ |
7167 | 196 if (aim_tlv_gettlv(tlvlist, 0x00ca, 1)) |
197 creationtime = aim_tlv_get32(tlvlist, 0x00ca, 1); | |
2086 | 198 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
199 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
200 * Type 0x00d1: Maximum Message Length |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
201 */ |
7167 | 202 if (aim_tlv_gettlv(tlvlist, 0x00d1, 1)) |
203 maxmsglen = aim_tlv_get16(tlvlist, 0x00d1, 1); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
204 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
205 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
206 * Type 0x00d2: Unknown. (2 bytes) |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
207 */ |
7167 | 208 if (aim_tlv_gettlv(tlvlist, 0x00d2, 1)) |
209 unknown_d2 = aim_tlv_get16(tlvlist, 0x00d2, 1); | |
2086 | 210 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
211 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
212 * Type 0x00d3: Room Description |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
213 */ |
7167 | 214 if (aim_tlv_gettlv(tlvlist, 0x00d3, 1)) |
215 roomdesc = aim_tlv_getstr(tlvlist, 0x00d3, 1); | |
2086 | 216 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
217 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
218 * Type 0x000d4: Unknown (flag only) |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
219 */ |
7167 | 220 if (aim_tlv_gettlv(tlvlist, 0x000d4, 1)) |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
221 ; |
2086 | 222 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
223 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
224 * Type 0x00d5: Unknown. (1 byte) |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
225 */ |
7167 | 226 if (aim_tlv_gettlv(tlvlist, 0x00d5, 1)) |
227 unknown_d5 = aim_tlv_get8(tlvlist, 0x00d5, 1); | |
2086 | 228 |
229 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
230 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
231 * Type 0x00d6: Encoding 1 ("us-ascii") |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
232 */ |
7167 | 233 if (aim_tlv_gettlv(tlvlist, 0x000d6, 1)) |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
234 ; |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
235 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
236 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
237 * Type 0x00d7: Language 1 ("en") |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
238 */ |
7167 | 239 if (aim_tlv_gettlv(tlvlist, 0x000d7, 1)) |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
240 ; |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
241 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
242 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
243 * Type 0x00d8: Encoding 2 ("us-ascii") |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
244 */ |
7167 | 245 if (aim_tlv_gettlv(tlvlist, 0x000d8, 1)) |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
246 ; |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
247 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
248 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
249 * Type 0x00d9: Language 2 ("en") |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
250 */ |
7167 | 251 if (aim_tlv_gettlv(tlvlist, 0x000d9, 1)) |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
252 ; |
2086 | 253 |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
254 /* |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
255 * Type 0x00da: Maximum visible message length |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
256 */ |
7167 | 257 if (aim_tlv_gettlv(tlvlist, 0x000da, 1)) |
258 maxvisiblemsglen = aim_tlv_get16(tlvlist, 0x00da, 1); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
259 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
260 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
261 ret = userfunc(sess, |
5836 | 262 rx, |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
263 &roominfo, |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
264 roomname, |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
265 usercount, |
5836 | 266 userinfo, |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
267 roomdesc, |
2821
9467e4ee81be
[gaim-migrate @ 2834]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2672
diff
changeset
|
268 flags, |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
269 creationtime, |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
270 maxmsglen, |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
271 unknown_d2, |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
272 unknown_d5, |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
273 maxvisiblemsglen); |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
274 } |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
275 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
276 free(roominfo.name); |
5836 | 277 |
278 while (usercount > 0) | |
279 aim_info_free(&userinfo[--usercount]); | |
280 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
281 free(userinfo); |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
282 free(roomname); |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
283 free(roomdesc); |
7167 | 284 aim_tlvlist_free(&tlvlist); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
285 |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
286 return ret; |
2086 | 287 } |
288 | |
3952 | 289 /* Subtypes 0x0003 and 0x0004 */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
290 static int userlistchange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
2086 | 291 { |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
292 aim_userinfo_t *userinfo = NULL; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
293 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
294 int curcount = 0, ret = 0; |
2086 | 295 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
296 while (aim_bstream_empty(bs)) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
297 curcount++; |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
298 userinfo = realloc(userinfo, curcount * sizeof(aim_userinfo_t)); |
5836 | 299 aim_info_extract(sess, bs, &userinfo[curcount-1]); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
300 } |
2086 | 301 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
302 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
303 ret = userfunc(sess, rx, curcount, userinfo); |
2086 | 304 |
5836 | 305 aim_info_free(userinfo); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
306 free(userinfo); |
2086 | 307 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
308 return ret; |
2086 | 309 } |
310 | |
311 /* | |
3952 | 312 * Subtype 0x0005 - Send a Chat Message. |
313 * | |
314 * Possible flags: | |
315 * AIM_CHATFLAGS_NOREFLECT -- Unset the flag that requests messages | |
316 * should be sent to their sender. | |
317 * AIM_CHATFLAGS_AWAY -- Mark the message as an autoresponse | |
318 * (Note that WinAIM does not honor this, | |
319 * and displays the message as normal.) | |
320 * | |
321 * XXX convert this to use tlvchains | |
322 */ | |
10994 | 323 faim_export int aim_chat_send_im(aim_session_t *sess, aim_conn_t *conn, fu16_t flags, const fu8_t *msg, int msglen, const char *encoding, const char *language) |
8233 | 324 { |
3952 | 325 int i; |
326 aim_frame_t *fr; | |
327 aim_msgcookie_t *cookie; | |
328 aim_snacid_t snacid; | |
329 fu8_t ckstr[8]; | |
330 aim_tlvlist_t *otl = NULL, *itl = NULL; | |
331 | |
332 if (!sess || !conn || !msg || (msglen <= 0)) | |
333 return 0; | |
334 | |
335 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) | |
336 return -ENOMEM; | |
337 | |
338 snacid = aim_cachesnac(sess, 0x000e, 0x0005, 0x0000, NULL, 0); | |
339 aim_putsnac(&fr->data, 0x000e, 0x0005, 0x0000, snacid); | |
340 | |
4901 | 341 /* |
342 * Cookie | |
3952 | 343 * |
344 * XXX mkcookie should generate the cookie and cache it in one | |
345 * operation to preserve uniqueness. | |
346 */ | |
4901 | 347 for (i = 0; i < 8; i++) |
348 ckstr[i] = (fu8_t)rand(); | |
3952 | 349 |
350 cookie = aim_mkcookie(ckstr, AIM_COOKIETYPE_CHAT, NULL); | |
351 cookie->data = NULL; /* XXX store something useful here */ | |
352 | |
353 aim_cachecookie(sess, cookie); | |
354 | |
4901 | 355 /* ICBM Header */ |
356 aimbs_putraw(&fr->data, ckstr, 8); /* Cookie */ | |
357 aimbs_put16(&fr->data, 0x0003); /* Channel */ | |
3952 | 358 |
359 /* | |
360 * Type 1: Flag meaning this message is destined to the room. | |
361 */ | |
7167 | 362 aim_tlvlist_add_noval(&otl, 0x0001); |
3952 | 363 |
364 /* | |
365 * Type 6: Reflect | |
366 */ | |
367 if (!(flags & AIM_CHATFLAGS_NOREFLECT)) | |
7167 | 368 aim_tlvlist_add_noval(&otl, 0x0006); |
3952 | 369 |
370 /* | |
371 * Type 7: Autoresponse | |
372 */ | |
373 if (flags & AIM_CHATFLAGS_AWAY) | |
7167 | 374 aim_tlvlist_add_noval(&otl, 0x0007); |
3952 | 375 |
376 /* | |
377 * SubTLV: Type 1: Message | |
378 */ | |
7167 | 379 aim_tlvlist_add_raw(&itl, 0x0001, msglen, msg); |
3952 | 380 |
8233 | 381 /* |
382 * SubTLV: Type 2: Encoding | |
383 */ | |
384 if (encoding != NULL) | |
10991 | 385 aim_tlvlist_add_str(&itl, 0x0002, encoding); |
8233 | 386 |
387 /* | |
388 * SubTLV: Type 3: Language | |
389 */ | |
390 if (language != NULL) | |
10991 | 391 aim_tlvlist_add_str(&itl, 0x0003, language); |
8219 | 392 |
3952 | 393 /* |
394 * Type 5: Message block. Contains more TLVs. | |
395 * | |
396 * This could include other information... We just | |
397 * put in a message TLV however. | |
398 * | |
399 */ | |
7167 | 400 aim_tlvlist_add_frozentlvlist(&otl, 0x0005, &itl); |
3952 | 401 |
7167 | 402 aim_tlvlist_write(&fr->data, &otl); |
3952 | 403 |
7167 | 404 aim_tlvlist_free(&itl); |
405 aim_tlvlist_free(&otl); | |
3952 | 406 |
407 aim_tx_enqueue(sess, fr); | |
408 | |
409 return 0; | |
410 } | |
411 | |
412 /* | |
413 * Subtype 0x0006 | |
414 * | |
2086 | 415 * We could probably include this in the normal ICBM parsing |
416 * code as channel 0x0003, however, since only the start | |
417 * would be the same, we might as well do it here. | |
418 * | |
419 * General outline of this SNAC: | |
420 * snac | |
421 * cookie | |
422 * channel id | |
423 * tlvlist | |
424 * unknown | |
425 * source user info | |
426 * name | |
427 * evility | |
428 * userinfo tlvs | |
429 * online time | |
430 * etc | |
431 * message metatlv | |
432 * message tlv | |
433 * message string | |
434 * possibly others | |
435 * | |
436 */ | |
8225 | 437 static int incomingim_ch3(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
2086 | 438 { |
8225 | 439 int ret = 0, i; |
440 aim_rxcallback_t userfunc; | |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
441 aim_userinfo_t userinfo; |
8225 | 442 fu8_t cookie[8]; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
443 fu16_t channel; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
444 aim_tlvlist_t *otl; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
445 char *msg = NULL; |
8283 | 446 int len = 0; |
8233 | 447 char *encoding = NULL, *language = NULL; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
448 aim_msgcookie_t *ck; |
2086 | 449 |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2270
diff
changeset
|
450 memset(&userinfo, 0, sizeof(aim_userinfo_t)); |
2086 | 451 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
452 /* |
8225 | 453 * Read ICBM Cookie. |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
454 */ |
8225 | 455 for (i = 0; i < 8; i++) |
456 cookie[i] = aimbs_get8(bs); | |
2086 | 457 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
458 if ((ck = aim_uncachecookie(sess, cookie, AIM_COOKIETYPE_CHAT))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
459 free(ck->data); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
460 free(ck); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
461 } |
2086 | 462 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
463 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
464 * Channel ID |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
465 * |
8225 | 466 * Channel 0x0003 is used for chat messages. |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
467 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
468 */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
469 channel = aimbs_get16(bs); |
2086 | 470 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
471 if (channel != 0x0003) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
472 faimdprintf(sess, 0, "faim: chat_incoming: unknown channel! (0x%04x)\n", channel); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
473 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
474 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
475 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
476 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
477 * Start parsing TLVs right away. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
478 */ |
7167 | 479 otl = aim_tlvlist_read(bs); |
2086 | 480 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
481 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
482 * Type 0x0003: Source User Information |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
483 */ |
7167 | 484 if (aim_tlv_gettlv(otl, 0x0003, 1)) { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
485 aim_tlv_t *userinfotlv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
486 aim_bstream_t tbs; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
487 |
7167 | 488 userinfotlv = aim_tlv_gettlv(otl, 0x0003, 1); |
2086 | 489 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
490 aim_bstream_init(&tbs, userinfotlv->value, userinfotlv->length); |
5836 | 491 aim_info_extract(sess, &tbs, &userinfo); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
492 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
493 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
494 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
495 * Type 0x0001: If present, it means it was a message to the |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
496 * room (as opposed to a whisper). |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
497 */ |
7167 | 498 if (aim_tlv_gettlv(otl, 0x0001, 1)) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
499 ; |
2086 | 500 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
501 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
502 * Type 0x0005: Message Block. Conains more TLVs. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
503 */ |
7167 | 504 if (aim_tlv_gettlv(otl, 0x0005, 1)) { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
505 aim_tlvlist_t *itl; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
506 aim_tlv_t *msgblock; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
507 aim_bstream_t tbs; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
508 |
7167 | 509 msgblock = aim_tlv_gettlv(otl, 0x0005, 1); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
510 aim_bstream_init(&tbs, msgblock->value, msgblock->length); |
7167 | 511 itl = aim_tlvlist_read(&tbs); |
2086 | 512 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
513 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
514 * Type 0x0001: Message. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
515 */ |
8219 | 516 if (aim_tlv_gettlv(itl, 0x0001, 1)) { |
7167 | 517 msg = aim_tlv_getstr(itl, 0x0001, 1); |
8219 | 518 len = aim_tlv_gettlv(itl, 0x0001, 1)->length; |
519 } | |
520 | |
8233 | 521 /* |
522 * Type 0x0002: Encoding. | |
8219 | 523 */ |
524 if (aim_tlv_gettlv(itl, 0x0002, 1)) | |
8233 | 525 encoding = aim_tlv_getstr(itl, 0x0002, 1); |
526 | |
527 /* | |
528 * Type 0x0003: Language. | |
529 */ | |
530 if (aim_tlv_gettlv(itl, 0x0003, 1)) | |
531 language = aim_tlv_getstr(itl, 0x0003, 1); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
532 |
7167 | 533 aim_tlvlist_free(&itl); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
534 } |
2086 | 535 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
536 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
8233 | 537 ret = userfunc(sess, rx, &userinfo, len, msg, encoding, language); |
2086 | 538 |
5836 | 539 aim_info_free(&userinfo); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
540 free(msg); |
7167 | 541 aim_tlvlist_free(&otl); |
2086 | 542 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
543 return ret; |
2086 | 544 } |
545 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
546 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
2086 | 547 { |
548 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
549 if (snac->subtype == 0x0002) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
550 return infoupdate(sess, mod, rx, snac, bs); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
551 else if ((snac->subtype == 0x0003) || (snac->subtype == 0x0004)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
552 return userlistchange(sess, mod, rx, snac, bs); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
553 else if (snac->subtype == 0x0006) |
8225 | 554 return incomingim_ch3(sess, mod, rx, snac, bs); |
2086 | 555 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
556 return 0; |
2086 | 557 } |
558 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
559 faim_internal int chat_modfirst(aim_session_t *sess, aim_module_t *mod) |
2086 | 560 { |
561 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
562 mod->family = 0x000e; |
2672 | 563 mod->version = 0x0001; |
4071 | 564 mod->toolid = 0x0010; |
565 mod->toolversion = 0x0629; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
566 mod->flags = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
567 strncpy(mod->name, "chat", sizeof(mod->name)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
568 mod->snachandler = snachandler; |
2086 | 569 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
570 return 0; |
2086 | 571 } |