Mercurial > pidgin.yaz
comparison libfaim/aim_info.c @ 445:e4c34ca88d9b
[gaim-migrate @ 455]
Hehehehehe
Libfaim got updated, gaim got updated. btw, gaim/faim can't sign in yet,
don't ask me why. it's not my fault.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 29 Jun 2000 20:40:28 +0000 |
parents | 0f14e6d8a51b |
children | 88f8f98de02d |
comparison
equal
deleted
inserted
replaced
444:e7885c54ed2f | 445:e4c34ca88d9b |
---|---|
23 int i = 0; | 23 int i = 0; |
24 | 24 |
25 if (!sess || !conn || !sn) | 25 if (!sess || !conn || !sn) |
26 return 0; | 26 return 0; |
27 | 27 |
28 if (!(newpacket = aim_tx_new(0x0002, conn, 12+1+strlen(sn)))) | 28 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 12+1+strlen(sn)))) |
29 return -1; | 29 return -1; |
30 | 30 |
31 newpacket->lock = 1; | 31 newpacket->lock = 1; |
32 | 32 |
33 i = aim_putsnac(newpacket->data, 0x0002, 0x0005, 0x0000, sess->snac_nextid); | 33 i = aim_putsnac(newpacket->data, 0x0002, 0x0005, 0x0000, sess->snac_nextid); |
86 /* Send file */ | 86 /* Send file */ |
87 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1, | 87 {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1, |
88 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} | 88 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} |
89 }; | 89 }; |
90 | 90 |
91 u_short aim_getcap(unsigned char *capblock, int buflen) | |
92 { | |
93 u_short ret = 0; | |
94 int y; | |
95 int offset = 0; | |
96 | |
97 while (offset < buflen) { | |
98 for(y=0; y < (sizeof(aim_caps)/0x10); y++) { | |
99 if (memcmp(&aim_caps[y], capblock+offset, 0x10) == 0) { | |
100 switch(y) { | |
101 case 0: ret |= AIM_CAPS_BUDDYICON; break; | |
102 case 1: ret |= AIM_CAPS_VOICE; break; | |
103 case 2: ret |= AIM_CAPS_IMIMAGE; break; | |
104 case 3: ret |= AIM_CAPS_CHAT; break; | |
105 case 4: ret |= AIM_CAPS_GETFILE; break; | |
106 case 5: ret |= AIM_CAPS_SENDFILE; break; | |
107 default: ret |= 0xff00; break; | |
108 } | |
109 } | |
110 } | |
111 offset += 0x10; | |
112 } | |
113 return ret; | |
114 } | |
115 | |
116 int aim_putcap(unsigned char *capblock, int buflen, u_short caps) | |
117 { | |
118 int offset = 0; | |
119 | |
120 if (!capblock) | |
121 return -1; | |
122 | |
123 if ((caps & AIM_CAPS_BUDDYICON) && (offset < buflen)) { | |
124 memcpy(capblock+offset, aim_caps[0], sizeof(aim_caps[0])); | |
125 offset += sizeof(aim_caps[1]); | |
126 } | |
127 if ((caps & AIM_CAPS_VOICE) && (offset < buflen)) { | |
128 memcpy(capblock+offset, aim_caps[1], sizeof(aim_caps[1])); | |
129 offset += sizeof(aim_caps[1]); | |
130 } | |
131 if ((caps & AIM_CAPS_IMIMAGE) && (offset < buflen)) { | |
132 memcpy(capblock+offset, aim_caps[2], sizeof(aim_caps[2])); | |
133 offset += sizeof(aim_caps[2]); | |
134 } | |
135 if ((caps & AIM_CAPS_CHAT) && (offset < buflen)) { | |
136 memcpy(capblock+offset, aim_caps[3], sizeof(aim_caps[3])); | |
137 offset += sizeof(aim_caps[3]); | |
138 } | |
139 if ((caps & AIM_CAPS_GETFILE) && (offset < buflen)) { | |
140 memcpy(capblock+offset, aim_caps[4], sizeof(aim_caps[4])); | |
141 offset += sizeof(aim_caps[4]); | |
142 } | |
143 if ((caps & AIM_CAPS_SENDFILE) && (offset < buflen)) { | |
144 memcpy(capblock+offset, aim_caps[5], sizeof(aim_caps[5])); | |
145 offset += sizeof(aim_caps[5]); | |
146 } | |
147 | |
148 return offset; | |
149 } | |
150 | |
91 /* | 151 /* |
92 * AIM is fairly regular about providing user info. This | 152 * AIM is fairly regular about providing user info. This |
93 * is a generic routine to extract it in its standard form. | 153 * is a generic routine to extract it in its standard form. |
94 */ | 154 */ |
95 int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo) | 155 int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo) |
97 int i = 0; | 157 int i = 0; |
98 int tlvcnt = 0; | 158 int tlvcnt = 0; |
99 int curtlv = 0; | 159 int curtlv = 0; |
100 int tlv1 = 0; | 160 int tlv1 = 0; |
101 u_short curtype; | 161 u_short curtype; |
162 int lastvalid; | |
102 | 163 |
103 | 164 |
104 if (!buf || !outinfo) | 165 if (!buf || !outinfo) |
105 return -1; | 166 return -1; |
106 | 167 |
109 | 170 |
110 /* | 171 /* |
111 * Screen name. Stored as an unterminated string prepended | 172 * Screen name. Stored as an unterminated string prepended |
112 * with an unsigned byte containing its length. | 173 * with an unsigned byte containing its length. |
113 */ | 174 */ |
114 memcpy(outinfo->sn, &(buf[i+1]), buf[i]); | 175 if (buf[i] < MAXSNLEN) { |
115 outinfo->sn[(int)buf[i]] = '\0'; | 176 memcpy(outinfo->sn, &(buf[i+1]), buf[i]); |
177 outinfo->sn[(int)buf[i]] = '\0'; | |
178 } else { | |
179 memcpy(outinfo->sn, &(buf[i+1]), MAXSNLEN-1); | |
180 outinfo->sn[MAXSNLEN] = '\0'; | |
181 } | |
116 i = 1 + (int)buf[i]; | 182 i = 1 + (int)buf[i]; |
117 | 183 |
118 /* | 184 /* |
119 * Warning Level. Stored as an unsigned short. | 185 * Warning Level. Stored as an unsigned short. |
120 */ | 186 */ |
129 i += 2; | 195 i += 2; |
130 | 196 |
131 /* | 197 /* |
132 * Parse out the Type-Length-Value triples as they're found. | 198 * Parse out the Type-Length-Value triples as they're found. |
133 */ | 199 */ |
134 while (curtlv < tlvcnt) | 200 while (curtlv < tlvcnt) { |
135 { | 201 lastvalid = 1; |
136 curtype = aimutil_get16(&buf[i]); | 202 curtype = aimutil_get16(&buf[i]); |
137 switch (curtype) | 203 switch (curtype) { |
138 { | 204 /* |
139 /* | 205 * Type = 0x0000: Invalid |
140 * Type = 0x0001: Member Class. | 206 * |
141 * | 207 * AOL has been trying to throw these in just to break us. |
142 * Specified as any of the following bitwise ORed together: | 208 * They're real nice guys over there at AOL. |
143 * 0x0001 Trial (user less than 60days) | 209 * |
144 * 0x0002 Unknown bit 2 | 210 * Just skip the two zero bytes and continue on. (This doesn't |
145 * 0x0004 AOL Main Service user | 211 * count towards tlvcnt!) |
146 * 0x0008 Unknown bit 4 | 212 */ |
147 * 0x0010 Free (AIM) user | 213 case 0x0000: |
148 * 0x0020 Away | 214 lastvalid = 0; |
149 * | 215 i += 2; |
150 * In some odd cases, we can end up with more | 216 break; |
151 * than one of these. We only want the first, | 217 |
152 * as the others may not be something we want. | 218 /* |
153 * | 219 * Type = 0x0001: Member Class. |
154 */ | 220 * |
155 case 0x0001: | 221 * Specified as any of the following bitwise ORed together: |
156 if (tlv1) /* use only the first */ | 222 * 0x0001 Trial (user less than 60days) |
157 break; | 223 * 0x0002 Unknown bit 2 |
158 outinfo->class = aimutil_get16(&buf[i+4]); | 224 * 0x0004 AOL Main Service user |
159 tlv1++; | 225 * 0x0008 Unknown bit 4 |
226 * 0x0010 Free (AIM) user | |
227 * 0x0020 Away | |
228 * | |
229 * In some odd cases, we can end up with more | |
230 * than one of these. We only want the first, | |
231 * as the others may not be something we want. | |
232 * | |
233 */ | |
234 case 0x0001: | |
235 if (tlv1) /* use only the first */ | |
236 break; | |
237 outinfo->class = aimutil_get16(&buf[i+4]); | |
238 tlv1++; | |
239 break; | |
240 | |
241 /* | |
242 * Type = 0x0002: Member-Since date. | |
243 * | |
244 * The time/date that the user originally | |
245 * registered for the service, stored in | |
246 * time_t format | |
247 */ | |
248 case 0x0002: | |
249 outinfo->membersince = aimutil_get32(&buf[i+4]); | |
250 break; | |
251 | |
252 /* | |
253 * Type = 0x0003: On-Since date. | |
254 * | |
255 * The time/date that the user started | |
256 * their current session, stored in time_t | |
257 * format. | |
258 */ | |
259 case 0x0003: | |
260 outinfo->onlinesince = aimutil_get32(&buf[i+4]); | |
261 break; | |
262 | |
263 /* | |
264 * Type = 0x0004: Idle time. | |
265 * | |
266 * Number of seconds since the user | |
267 * actively used the service. | |
268 */ | |
269 case 0x0004: | |
270 outinfo->idletime = aimutil_get16(&buf[i+4]); | |
271 break; | |
272 | |
273 /* | |
274 * Type = 0x000d | |
275 * | |
276 * Capability information. Not real sure of | |
277 * actual decoding. See comment on aim_bos_setprofile() | |
278 * in aim_misc.c about the capability block, its the same. | |
279 * | |
280 */ | |
281 case 0x000d: | |
282 { | |
283 int len; | |
284 len = aimutil_get16(buf+i+2); | |
285 if (!len) | |
160 break; | 286 break; |
161 | 287 |
162 /* | 288 outinfo->capabilities = aim_getcap(buf+i+4, len); |
163 * Type = 0x0002: Member-Since date. | 289 } |
164 * | 290 break; |
165 * The time/date that the user originally | 291 |
166 * registered for the service, stored in | 292 /* |
167 * time_t format | 293 * Type = 0x000e |
168 */ | 294 * |
169 case 0x0002: | 295 * Unknown. Always of zero length, and always only |
170 outinfo->membersince = aimutil_get32(&buf[i+4]); | 296 * on AOL users. |
171 break; | 297 * |
172 | 298 * Ignore. |
173 /* | 299 * |
174 * Type = 0x0003: On-Since date. | 300 */ |
175 * | 301 case 0x000e: |
176 * The time/date that the user started | 302 break; |
177 * their current session, stored in time_t | 303 |
178 * format. | 304 /* |
179 */ | 305 * Type = 0x000f: Session Length. (AIM) |
180 case 0x0003: | 306 * Type = 0x0010: Session Length. (AOL) |
181 outinfo->onlinesince = aimutil_get32(&buf[i+4]); | 307 * |
182 break; | 308 * The duration, in seconds, of the user's |
183 | 309 * current session. |
184 /* | 310 * |
185 * Type = 0x0004: Idle time. | 311 * Which TLV type this comes in depends |
186 * | 312 * on the service the user is using (AIM or AOL). |
187 * Number of seconds since the user | 313 * |
188 * actively used the service. | 314 */ |
189 */ | 315 case 0x000f: |
190 case 0x0004: | 316 case 0x0010: |
191 outinfo->idletime = aimutil_get16(&buf[i+4]); | 317 outinfo->sessionlen = aimutil_get32(&buf[i+4]); |
192 break; | 318 break; |
193 | 319 |
194 /* | 320 /* |
195 * Type = 0x000d | 321 * Reaching here indicates that either AOL has |
196 * | 322 * added yet another TLV for us to deal with, |
197 * Capability information. Not real sure of | 323 * or the parsing has gone Terribly Wrong. |
198 * actual decoding. See comment on aim_bos_setprofile() | 324 * |
199 * in aim_misc.c about the capability block, its the same. | 325 * Either way, inform the owner and attempt |
200 * | 326 * recovery. |
201 * Ignore. | 327 * |
202 * | 328 */ |
203 */ | 329 default: |
204 case 0x000d: | 330 { |
331 int len,z = 0, y = 0, x = 0; | |
332 char tmpstr[80]; | |
333 printf("faim: userinfo: **warning: unexpected TLV:\n"); | |
334 printf("faim: userinfo: sn =%s\n", outinfo->sn); | |
335 printf("faim: userinfo: curtlv=0x%04x\n", curtlv); | |
336 printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i])); | |
337 printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2])); | |
338 printf("faim: userinfo: data: \n"); | |
339 while (z<len) | |
205 { | 340 { |
206 int z,y; | 341 x = sprintf(tmpstr, "faim: userinfo: "); |
207 int len; | 342 for (y = 0; y < 8; y++) |
208 len = aimutil_get16(buf+i+2); | 343 { |
209 if (!len) | 344 if (z<len) |
210 break; | 345 { |
211 | 346 sprintf(tmpstr+x, "%02x ", buf[i+4+z]); |
212 for (z = 0; z < len; z+=0x10) { | 347 z++; |
213 for(y=0; y < 6; y++) { | 348 x += 3; |
214 if (memcmp(&aim_caps[y], buf+i+4+z, 0x10) == 0) { | |
215 switch(y) { | |
216 case 0: outinfo->capabilities |= AIM_CAPS_BUDDYICON; break; | |
217 case 1: outinfo->capabilities |= AIM_CAPS_VOICE; break; | |
218 case 2: outinfo->capabilities |= AIM_CAPS_IMIMAGE; break; | |
219 case 3: outinfo->capabilities |= AIM_CAPS_CHAT; break; | |
220 case 4: outinfo->capabilities |= AIM_CAPS_GETFILE; break; | |
221 case 5: outinfo->capabilities |= AIM_CAPS_SENDFILE; break; | |
222 default: outinfo->capabilities |= 0xff00; break; | |
223 } | 349 } |
224 } | 350 else |
351 break; | |
225 } | 352 } |
226 } | 353 printf("%s\n", tmpstr); |
227 } | 354 } |
228 break; | 355 } |
229 | 356 break; |
230 /* | 357 } |
231 * Type = 0x000e | 358 /* |
232 * | 359 * No matter what, TLV triplets should always look like this: |
233 * Unknown. Always of zero length, and always only | 360 * |
234 * on AOL users. | 361 * u_short type; |
235 * | 362 * u_short length; |
236 * Ignore. | 363 * u_char data[length]; |
237 * | 364 * |
238 */ | 365 */ |
239 case 0x000e: | 366 if (lastvalid) { |
240 break; | 367 i += (2 + 2 + aimutil_get16(&buf[i+2])); |
241 | |
242 /* | |
243 * Type = 0x000f: Session Length. (AIM) | |
244 * Type = 0x0010: Session Length. (AOL) | |
245 * | |
246 * The duration, in seconds, of the user's | |
247 * current session. | |
248 * | |
249 * Which TLV type this comes in depends | |
250 * on the service the user is using (AIM or AOL). | |
251 * | |
252 */ | |
253 case 0x000f: | |
254 case 0x0010: | |
255 outinfo->sessionlen = aimutil_get32(&buf[i+4]); | |
256 break; | |
257 | |
258 /* | |
259 * Reaching here indicates that either AOL has | |
260 * added yet another TLV for us to deal with, | |
261 * or the parsing has gone Terribly Wrong. | |
262 * | |
263 * Either way, inform the owner and attempt | |
264 * recovery. | |
265 * | |
266 */ | |
267 default: | |
268 { | |
269 int len,z = 0, y = 0, x = 0; | |
270 char tmpstr[80]; | |
271 printf("faim: userinfo: **warning: unexpected TLV:\n"); | |
272 printf("faim: userinfo: sn =%s\n", outinfo->sn); | |
273 printf("faim: userinfo: curtlv=0x%04x\n", curtlv); | |
274 printf("faim: userinfo: type =0x%04x\n",aimutil_get16(&buf[i])); | |
275 printf("faim: userinfo: length=0x%04x\n", len = aimutil_get16(&buf[i+2])); | |
276 printf("faim: userinfo: data: \n"); | |
277 while (z<len) | |
278 { | |
279 x = sprintf(tmpstr, "faim: userinfo: "); | |
280 for (y = 0; y < 8; y++) | |
281 { | |
282 if (z<len) | |
283 { | |
284 sprintf(tmpstr+x, "%02x ", buf[i+4+z]); | |
285 z++; | |
286 x += 3; | |
287 } | |
288 else | |
289 break; | |
290 } | |
291 printf("%s\n", tmpstr); | |
292 } | |
293 } | |
294 break; | |
295 } | |
296 /* | |
297 * No matter what, TLV triplets should always look like this: | |
298 * | |
299 * u_short type; | |
300 * u_short length; | |
301 * u_char data[length]; | |
302 * | |
303 */ | |
304 i += (2 + 2 + aimutil_get16(&buf[i+2])); | |
305 | |
306 curtlv++; | 368 curtlv++; |
307 } | 369 } |
370 } | |
308 | 371 |
309 return i; | 372 return i; |
310 } | 373 } |
311 | 374 |
312 /* | 375 /* |
476 int i = 0; | 539 int i = 0; |
477 | 540 |
478 if (!sess || !conn || !info) | 541 if (!sess || !conn || !info) |
479 return 0; | 542 return 0; |
480 | 543 |
481 if (!(tx = aim_tx_new(0x0002, conn, 1152))) | 544 if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152))) |
482 return -1; | 545 return -1; |
483 | 546 |
484 tx->lock = 1; | 547 tx->lock = 1; |
485 | 548 |
486 i += aimutil_put16(tx->data+i, 0x0003); | 549 i += aimutil_put16(tx->data+i, 0x0003); |
504 int i = 0; | 567 int i = 0; |
505 | 568 |
506 if (!sess || !conn || !sn) | 569 if (!sess || !conn || !sn) |
507 return 0; | 570 return 0; |
508 | 571 |
509 if (!(tx = aim_tx_new(0x0002, conn, 10+1+strlen(sn)))) | 572 if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn)))) |
510 return -1; | 573 return -1; |
511 | 574 |
512 tx->lock = 1; | 575 tx->lock = 1; |
513 | 576 |
514 i += aimutil_put16(tx->data+i, 0x0003); | 577 i += aimutil_put16(tx->data+i, 0x0003); |