| 1 | /* |
|---|
| 2 | * aim_info.c |
|---|
| 3 | * |
|---|
| 4 | * The functions here are responsible for requesting and parsing information- |
|---|
| 5 | * gathering SNACs. Or something like that. |
|---|
| 6 | * |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | #define FAIM_INTERNAL |
|---|
| 10 | #include <aim.h> |
|---|
| 11 | |
|---|
| 12 | struct aim_priv_inforeq { |
|---|
| 13 | char sn[MAXSNLEN+1]; |
|---|
| 14 | fu16_t infotype; |
|---|
| 15 | }; |
|---|
| 16 | |
|---|
| 17 | faim_export int aim_getinfo(aim_session_t *sess, aim_conn_t *conn, const char *sn, fu16_t infotype) |
|---|
| 18 | { |
|---|
| 19 | struct aim_priv_inforeq privdata; |
|---|
| 20 | aim_frame_t *fr; |
|---|
| 21 | aim_snacid_t snacid; |
|---|
| 22 | |
|---|
| 23 | if (!sess || !conn || !sn) |
|---|
| 24 | return -EINVAL; |
|---|
| 25 | |
|---|
| 26 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 12+1+strlen(sn)))) |
|---|
| 27 | return -ENOMEM; |
|---|
| 28 | |
|---|
| 29 | strncpy(privdata.sn, sn, sizeof(privdata.sn)); |
|---|
| 30 | privdata.infotype = infotype; |
|---|
| 31 | snacid = aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq)); |
|---|
| 32 | |
|---|
| 33 | aim_putsnac(&fr->data, 0x0002, 0x0005, 0x0000, snacid); |
|---|
| 34 | aimbs_put16(&fr->data, infotype); |
|---|
| 35 | aimbs_put8(&fr->data, strlen(sn)); |
|---|
| 36 | aimbs_putraw(&fr->data, sn, strlen(sn)); |
|---|
| 37 | |
|---|
| 38 | aim_tx_enqueue(sess, fr); |
|---|
| 39 | |
|---|
| 40 | return 0; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | faim_export const char *aim_userinfo_sn(aim_userinfo_t *ui) |
|---|
| 44 | { |
|---|
| 45 | |
|---|
| 46 | if (!ui) |
|---|
| 47 | return NULL; |
|---|
| 48 | |
|---|
| 49 | return ui->sn; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | faim_export fu16_t aim_userinfo_flags(aim_userinfo_t *ui) |
|---|
| 53 | { |
|---|
| 54 | |
|---|
| 55 | if (!ui) |
|---|
| 56 | return 0; |
|---|
| 57 | |
|---|
| 58 | return ui->flags; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | faim_export fu16_t aim_userinfo_idle(aim_userinfo_t *ui) |
|---|
| 62 | { |
|---|
| 63 | |
|---|
| 64 | if (!ui) |
|---|
| 65 | return 0; |
|---|
| 66 | |
|---|
| 67 | return ui->idletime; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | faim_export float aim_userinfo_warnlevel(aim_userinfo_t *ui) |
|---|
| 71 | { |
|---|
| 72 | |
|---|
| 73 | if (!ui) |
|---|
| 74 | return 0.00; |
|---|
| 75 | |
|---|
| 76 | return (ui->warnlevel / 10); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | faim_export time_t aim_userinfo_createtime(aim_userinfo_t *ui) |
|---|
| 80 | { |
|---|
| 81 | |
|---|
| 82 | if (!ui) |
|---|
| 83 | return 0; |
|---|
| 84 | |
|---|
| 85 | return (time_t)ui->createtime; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | faim_export time_t aim_userinfo_membersince(aim_userinfo_t *ui) |
|---|
| 89 | { |
|---|
| 90 | |
|---|
| 91 | if (!ui) |
|---|
| 92 | return 0; |
|---|
| 93 | |
|---|
| 94 | return (time_t)ui->membersince; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | faim_export time_t aim_userinfo_onlinesince(aim_userinfo_t *ui) |
|---|
| 98 | { |
|---|
| 99 | |
|---|
| 100 | if (!ui) |
|---|
| 101 | return 0; |
|---|
| 102 | |
|---|
| 103 | return (time_t)ui->onlinesince; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | faim_export fu32_t aim_userinfo_sessionlen(aim_userinfo_t *ui) |
|---|
| 107 | { |
|---|
| 108 | |
|---|
| 109 | if (!ui) |
|---|
| 110 | return 0; |
|---|
| 111 | |
|---|
| 112 | return ui->sessionlen; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | faim_export int aim_userinfo_hascap(aim_userinfo_t *ui, fu32_t cap) |
|---|
| 116 | { |
|---|
| 117 | |
|---|
| 118 | if (!ui || !(ui->present & AIM_USERINFO_PRESENT_CAPABILITIES)) |
|---|
| 119 | return -1; |
|---|
| 120 | |
|---|
| 121 | return !!(ui->capabilities & cap); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | /* |
|---|
| 126 | * Capability blocks. |
|---|
| 127 | * |
|---|
| 128 | * These are CLSIDs. They should actually be of the form: |
|---|
| 129 | * |
|---|
| 130 | * {0x0946134b, 0x4c7f, 0x11d1, |
|---|
| 131 | * {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, |
|---|
| 132 | * |
|---|
| 133 | * But, eh. |
|---|
| 134 | */ |
|---|
| 135 | static const struct { |
|---|
| 136 | fu32_t flag; |
|---|
| 137 | fu8_t data[16]; |
|---|
| 138 | } aim_caps[] = { |
|---|
| 139 | |
|---|
| 140 | /* |
|---|
| 141 | * Chat is oddball. |
|---|
| 142 | */ |
|---|
| 143 | {AIM_CAPS_CHAT, |
|---|
| 144 | {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1, |
|---|
| 145 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 146 | |
|---|
| 147 | /* |
|---|
| 148 | * These are mostly in order. |
|---|
| 149 | */ |
|---|
| 150 | {AIM_CAPS_VOICE, |
|---|
| 151 | {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 152 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 153 | |
|---|
| 154 | {AIM_CAPS_SENDFILE, |
|---|
| 155 | {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 156 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 157 | |
|---|
| 158 | /* |
|---|
| 159 | * Advertised by the EveryBuddy client. |
|---|
| 160 | */ |
|---|
| 161 | {AIM_CAPS_ICQ, |
|---|
| 162 | {0x09, 0x46, 0x13, 0x44, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 163 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 164 | |
|---|
| 165 | {AIM_CAPS_IMIMAGE, |
|---|
| 166 | {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 167 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 168 | |
|---|
| 169 | {AIM_CAPS_BUDDYICON, |
|---|
| 170 | {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 171 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 172 | |
|---|
| 173 | {AIM_CAPS_SAVESTOCKS, |
|---|
| 174 | {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 175 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 176 | |
|---|
| 177 | {AIM_CAPS_GETFILE, |
|---|
| 178 | {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 179 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 180 | |
|---|
| 181 | {AIM_CAPS_ICQSERVERRELAY, |
|---|
| 182 | {0x09, 0x46, 0x13, 0x49, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 183 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 184 | |
|---|
| 185 | /* |
|---|
| 186 | * Indeed, there are two of these. The former appears to be correct, |
|---|
| 187 | * but in some versions of winaim, the second one is set. Either they |
|---|
| 188 | * forgot to fix endianness, or they made a typo. It really doesn't |
|---|
| 189 | * matter which. |
|---|
| 190 | */ |
|---|
| 191 | {AIM_CAPS_GAMES, |
|---|
| 192 | {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 193 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 194 | {AIM_CAPS_GAMES2, |
|---|
| 195 | {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 196 | 0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 197 | |
|---|
| 198 | {AIM_CAPS_SENDBUDDYLIST, |
|---|
| 199 | {0x09, 0x46, 0x13, 0x4b, 0x4c, 0x7f, 0x11, 0xd1, |
|---|
| 200 | 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}, |
|---|
| 201 | |
|---|
| 202 | {AIM_CAPS_ICQRTF, |
|---|
| 203 | {0x97, 0xb1, 0x27, 0x51, 0x24, 0x3c, 0x43, 0x34, |
|---|
| 204 | 0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x92}}, |
|---|
| 205 | |
|---|
| 206 | {AIM_CAPS_ICQUNKNOWN, |
|---|
| 207 | {0x2e, 0x7a, 0x64, 0x75, 0xfa, 0xdf, 0x4d, 0xc8, |
|---|
| 208 | 0x88, 0x6f, 0xea, 0x35, 0x95, 0xfd, 0xb6, 0xdf}}, |
|---|
| 209 | |
|---|
| 210 | {AIM_CAPS_EMPTY, |
|---|
| 211 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|---|
| 212 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, |
|---|
| 213 | |
|---|
| 214 | {AIM_CAPS_TRILLIANCRYPT, |
|---|
| 215 | {0xf2, 0xe7, 0xc7, 0xf4, 0xfe, 0xad, 0x4d, 0xfb, |
|---|
| 216 | 0xb2, 0x35, 0x36, 0x79, 0x8b, 0xdf, 0x00, 0x00}}, |
|---|
| 217 | |
|---|
| 218 | {AIM_CAPS_APINFO, |
|---|
| 219 | {0xAA, 0x4A, 0x32, 0xB5, |
|---|
| 220 | 0xF8, 0x84, |
|---|
| 221 | 0x48, 0xc6, |
|---|
| 222 | 0xA3, 0xD7, |
|---|
| 223 | 0x8C, 0x50, 0x97, 0x19, 0xFD, 0x5B}}, |
|---|
| 224 | |
|---|
| 225 | {AIM_CAPS_LAST} |
|---|
| 226 | }; |
|---|
| 227 | |
|---|
| 228 | /* |
|---|
| 229 | * This still takes a length parameter even with a bstream because capabilities |
|---|
| 230 | * are not naturally bounded. |
|---|
| 231 | * |
|---|
| 232 | */ |
|---|
| 233 | faim_internal fu32_t aim_getcap(aim_session_t *sess, aim_bstream_t *bs, int len) |
|---|
| 234 | { |
|---|
| 235 | fu32_t flags = 0; |
|---|
| 236 | int offset; |
|---|
| 237 | |
|---|
| 238 | for (offset = 0; aim_bstream_empty(bs) && (offset < len); offset += 0x10) { |
|---|
| 239 | fu8_t *cap; |
|---|
| 240 | int i, identified; |
|---|
| 241 | |
|---|
| 242 | cap = aimbs_getraw(bs, 0x10); |
|---|
| 243 | |
|---|
| 244 | for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) { |
|---|
| 245 | |
|---|
| 246 | if (memcmp(&aim_caps[i].data, cap, 0x10) == 0) { |
|---|
| 247 | flags |= aim_caps[i].flag; |
|---|
| 248 | identified++; |
|---|
| 249 | break; /* should only match once... */ |
|---|
| 250 | |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | if (!identified) { |
|---|
| 255 | faimdprintf(sess, 0, "unknown capability: {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n", |
|---|
| 256 | cap[0], cap[1], cap[2], cap[3], |
|---|
| 257 | cap[4], cap[5], |
|---|
| 258 | cap[6], cap[7], |
|---|
| 259 | cap[8], cap[9], |
|---|
| 260 | cap[10], cap[11], cap[12], cap[13], |
|---|
| 261 | cap[14], cap[15]); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | free(cap); |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | return flags; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | faim_internal int aim_putcap(aim_bstream_t *bs, fu32_t caps) |
|---|
| 271 | { |
|---|
| 272 | int i; |
|---|
| 273 | |
|---|
| 274 | if (!bs) |
|---|
| 275 | return -EINVAL; |
|---|
| 276 | |
|---|
| 277 | for (i = 0; aim_bstream_empty(bs); i++) { |
|---|
| 278 | |
|---|
| 279 | if (aim_caps[i].flag == AIM_CAPS_LAST) |
|---|
| 280 | break; |
|---|
| 281 | |
|---|
| 282 | if (caps & aim_caps[i].flag) |
|---|
| 283 | aimbs_putraw(bs, aim_caps[i].data, 0x10); |
|---|
| 284 | |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | return 0; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | static void dumptlv(aim_session_t *sess, fu16_t type, aim_bstream_t *bs, fu8_t len) |
|---|
| 291 | { |
|---|
| 292 | int i; |
|---|
| 293 | |
|---|
| 294 | if (!sess || !bs || !len) |
|---|
| 295 | return; |
|---|
| 296 | |
|---|
| 297 | faimdprintf(sess, 0, "userinfo: type =0x%04x\n", type); |
|---|
| 298 | faimdprintf(sess, 0, "userinfo: length=0x%04x\n", len); |
|---|
| 299 | |
|---|
| 300 | faimdprintf(sess, 0, "userinfo: value:\n"); |
|---|
| 301 | |
|---|
| 302 | for (i = 0; i < len; i++) { |
|---|
| 303 | if ((i % 8) == 0) |
|---|
| 304 | faimdprintf(sess, 0, "\nuserinfo: "); |
|---|
| 305 | |
|---|
| 306 | faimdprintf(sess, 0, "0x%2x ", aimbs_get8(bs)); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | faimdprintf(sess, 0, "\n"); |
|---|
| 310 | |
|---|
| 311 | return; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | /* |
|---|
| 315 | * AIM is fairly regular about providing user info. This is a generic |
|---|
| 316 | * routine to extract it in its standard form. |
|---|
| 317 | */ |
|---|
| 318 | faim_internal int aim_extractuserinfo(aim_session_t *sess, aim_bstream_t *bs, aim_userinfo_t *outinfo) |
|---|
| 319 | { |
|---|
| 320 | int curtlv, tlvcnt; |
|---|
| 321 | fu8_t snlen; |
|---|
| 322 | |
|---|
| 323 | if (!bs || !outinfo) |
|---|
| 324 | return -EINVAL; |
|---|
| 325 | |
|---|
| 326 | /* Clear out old data first */ |
|---|
| 327 | memset(outinfo, 0x00, sizeof(aim_userinfo_t)); |
|---|
| 328 | |
|---|
| 329 | /* |
|---|
| 330 | * Screen name. Stored as an unterminated string prepended with a |
|---|
| 331 | * byte containing its length. |
|---|
| 332 | */ |
|---|
| 333 | snlen = aimbs_get8(bs); |
|---|
| 334 | aimbs_getrawbuf(bs, outinfo->sn, snlen); |
|---|
| 335 | |
|---|
| 336 | /* |
|---|
| 337 | * Warning Level. Stored as an unsigned short. |
|---|
| 338 | */ |
|---|
| 339 | outinfo->warnlevel = aimbs_get16(bs); |
|---|
| 340 | |
|---|
| 341 | /* |
|---|
| 342 | * TLV Count. Unsigned short representing the number of |
|---|
| 343 | * Type-Length-Value triples that follow. |
|---|
| 344 | */ |
|---|
| 345 | tlvcnt = aimbs_get16(bs); |
|---|
| 346 | |
|---|
| 347 | /* |
|---|
| 348 | * Parse out the Type-Length-Value triples as they're found. |
|---|
| 349 | */ |
|---|
| 350 | for (curtlv = 0; curtlv < tlvcnt; curtlv++) { |
|---|
| 351 | int endpos; |
|---|
| 352 | fu16_t type, length; |
|---|
| 353 | |
|---|
| 354 | type = aimbs_get16(bs); |
|---|
| 355 | length = aimbs_get16(bs); |
|---|
| 356 | |
|---|
| 357 | endpos = aim_bstream_curpos(bs) + length; |
|---|
| 358 | |
|---|
| 359 | if (type == 0x0001) { |
|---|
| 360 | /* |
|---|
| 361 | * Type = 0x0001: User flags |
|---|
| 362 | * |
|---|
| 363 | * Specified as any of the following ORed together: |
|---|
| 364 | * 0x0001 Trial (user less than 60days) |
|---|
| 365 | * 0x0002 Unknown bit 2 |
|---|
| 366 | * 0x0004 AOL Main Service user |
|---|
| 367 | * 0x0008 Unknown bit 4 |
|---|
| 368 | * 0x0010 Free (AIM) user |
|---|
| 369 | * 0x0020 Away |
|---|
| 370 | * 0x0400 ActiveBuddy |
|---|
| 371 | * |
|---|
| 372 | */ |
|---|
| 373 | outinfo->flags = aimbs_get16(bs); |
|---|
| 374 | outinfo->present |= AIM_USERINFO_PRESENT_FLAGS; |
|---|
| 375 | |
|---|
| 376 | } else if (type == 0x0002) { |
|---|
| 377 | /* |
|---|
| 378 | * Type = 0x0002: Account creation time. |
|---|
| 379 | * |
|---|
| 380 | * The time/date that the user originally registered for |
|---|
| 381 | * the service, stored in time_t format. |
|---|
| 382 | * |
|---|
| 383 | * I'm not sure how this differs from type 5 ("member |
|---|
| 384 | * since"). |
|---|
| 385 | * |
|---|
| 386 | * Note: This is the field formerly known as "member |
|---|
| 387 | * since". All these years and I finally found out |
|---|
| 388 | * that I got the name wrong. |
|---|
| 389 | */ |
|---|
| 390 | outinfo->createtime = aimbs_get32(bs); |
|---|
| 391 | outinfo->present |= AIM_USERINFO_PRESENT_CREATETIME; |
|---|
| 392 | |
|---|
| 393 | } else if (type == 0x0003) { |
|---|
| 394 | /* |
|---|
| 395 | * Type = 0x0003: On-Since date. |
|---|
| 396 | * |
|---|
| 397 | * The time/date that the user started their current |
|---|
| 398 | * session, stored in time_t format. |
|---|
| 399 | */ |
|---|
| 400 | outinfo->onlinesince = aimbs_get32(bs); |
|---|
| 401 | outinfo->present |= AIM_USERINFO_PRESENT_ONLINESINCE; |
|---|
| 402 | |
|---|
| 403 | } else if (type == 0x0004) { |
|---|
| 404 | /* |
|---|
| 405 | * Type = 0x0004: Idle time. |
|---|
| 406 | * |
|---|
| 407 | * Number of seconds since the user actively used the |
|---|
| 408 | * service. |
|---|
| 409 | * |
|---|
| 410 | * Note that the client tells the server when to start |
|---|
| 411 | * counting idle times, so this may or may not be |
|---|
| 412 | * related to reality. |
|---|
| 413 | */ |
|---|
| 414 | outinfo->idletime = aimbs_get16(bs); |
|---|
| 415 | outinfo->present |= AIM_USERINFO_PRESENT_IDLE; |
|---|
| 416 | |
|---|
| 417 | } else if (type == 0x0005) { |
|---|
| 418 | /* |
|---|
| 419 | * Type = 0x0005: Member since date. |
|---|
| 420 | * |
|---|
| 421 | * The time/date that the user originally registered for |
|---|
| 422 | * the service, stored in time_t format. |
|---|
| 423 | * |
|---|
| 424 | * This is sometimes sent instead of type 2 ("account |
|---|
| 425 | * creation time"), particularly in the self-info. |
|---|
| 426 | */ |
|---|
| 427 | outinfo->membersince = aimbs_get32(bs); |
|---|
| 428 | outinfo->present |= AIM_USERINFO_PRESENT_MEMBERSINCE; |
|---|
| 429 | |
|---|
| 430 | } else if (type == 0x0006) { |
|---|
| 431 | /* |
|---|
| 432 | * Type = 0x0006: ICQ Online Status |
|---|
| 433 | * |
|---|
| 434 | * ICQ's Away/DND/etc "enriched" status. Some decoding |
|---|
| 435 | * of values done by Scott <darkagl@pcnet.com> |
|---|
| 436 | */ |
|---|
| 437 | aimbs_get16(bs); |
|---|
| 438 | outinfo->icqinfo.status = aimbs_get16(bs); |
|---|
| 439 | outinfo->present |= AIM_USERINFO_PRESENT_ICQEXTSTATUS; |
|---|
| 440 | |
|---|
| 441 | } else if (type == 0x000a) { |
|---|
| 442 | /* |
|---|
| 443 | * Type = 0x000a |
|---|
| 444 | * |
|---|
| 445 | * ICQ User IP Address. |
|---|
| 446 | * Ahh, the joy of ICQ security. |
|---|
| 447 | */ |
|---|
| 448 | outinfo->icqinfo.ipaddr = aimbs_get32(bs); |
|---|
| 449 | outinfo->present |= AIM_USERINFO_PRESENT_ICQIPADDR; |
|---|
| 450 | |
|---|
| 451 | } else if (type == 0x000c) { |
|---|
| 452 | /* |
|---|
| 453 | * Type = 0x000c |
|---|
| 454 | * |
|---|
| 455 | * random crap containing the IP address, |
|---|
| 456 | * apparently a port number, and some Other Stuff. |
|---|
| 457 | * |
|---|
| 458 | */ |
|---|
| 459 | aimbs_getrawbuf(bs, outinfo->icqinfo.crap, 0x25); |
|---|
| 460 | outinfo->present |= AIM_USERINFO_PRESENT_ICQDATA; |
|---|
| 461 | |
|---|
| 462 | } else if (type == 0x000d) { |
|---|
| 463 | /* |
|---|
| 464 | * Type = 0x000d |
|---|
| 465 | * |
|---|
| 466 | * Capability information. |
|---|
| 467 | * |
|---|
| 468 | */ |
|---|
| 469 | outinfo->capabilities = aim_getcap(sess, bs, length); |
|---|
| 470 | outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES; |
|---|
| 471 | |
|---|
| 472 | } else if (type == 0x000e) { |
|---|
| 473 | /* |
|---|
| 474 | * Type = 0x000e |
|---|
| 475 | * |
|---|
| 476 | * Unknown. Always of zero length, and always only |
|---|
| 477 | * on AOL users. |
|---|
| 478 | * |
|---|
| 479 | * Ignore. |
|---|
| 480 | * |
|---|
| 481 | */ |
|---|
| 482 | |
|---|
| 483 | } else if ((type == 0x000f) || (type == 0x0010)) { |
|---|
| 484 | /* |
|---|
| 485 | * Type = 0x000f: Session Length. (AIM) |
|---|
| 486 | * Type = 0x0010: Session Length. (AOL) |
|---|
| 487 | * |
|---|
| 488 | * The duration, in seconds, of the user's current |
|---|
| 489 | * session. |
|---|
| 490 | * |
|---|
| 491 | * Which TLV type this comes in depends on the |
|---|
| 492 | * service the user is using (AIM or AOL). |
|---|
| 493 | * |
|---|
| 494 | */ |
|---|
| 495 | outinfo->sessionlen = aimbs_get32(bs); |
|---|
| 496 | outinfo->present |= AIM_USERINFO_PRESENT_SESSIONLEN; |
|---|
| 497 | |
|---|
| 498 | } else if (type == 0x001d) { |
|---|
| 499 | /* |
|---|
| 500 | * Type 29: Unknown. |
|---|
| 501 | * |
|---|
| 502 | * Currently very rare. Always 18 bytes of mostly zero. |
|---|
| 503 | */ |
|---|
| 504 | |
|---|
| 505 | } else if (type == 0x001e) { |
|---|
| 506 | /* |
|---|
| 507 | * Type 30: Unknown. |
|---|
| 508 | * |
|---|
| 509 | * Always four bytes, but it doesn't look like an int. |
|---|
| 510 | */ |
|---|
| 511 | } else { |
|---|
| 512 | |
|---|
| 513 | /* |
|---|
| 514 | * Reaching here indicates that either AOL has |
|---|
| 515 | * added yet another TLV for us to deal with, |
|---|
| 516 | * or the parsing has gone Terribly Wrong. |
|---|
| 517 | * |
|---|
| 518 | * Either way, inform the owner and attempt |
|---|
| 519 | * recovery. |
|---|
| 520 | * |
|---|
| 521 | */ |
|---|
| 522 | faimdprintf(sess, 0, "userinfo: **warning: unexpected TLV:\n"); |
|---|
| 523 | faimdprintf(sess, 0, "userinfo: sn =%s\n", outinfo->sn); |
|---|
| 524 | dumptlv(sess, type, bs, length); |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | /* Save ourselves. */ |
|---|
| 528 | aim_bstream_setpos(bs, endpos); |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | return 0; |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | /* |
|---|
| 535 | * Inverse of aim_extractuserinfo() |
|---|
| 536 | */ |
|---|
| 537 | faim_internal int aim_putuserinfo(aim_bstream_t *bs, aim_userinfo_t *info) |
|---|
| 538 | { |
|---|
| 539 | aim_tlvlist_t *tlvlist = NULL; |
|---|
| 540 | |
|---|
| 541 | if (!bs || !info) |
|---|
| 542 | return -EINVAL; |
|---|
| 543 | |
|---|
| 544 | aimbs_put8(bs, strlen(info->sn)); |
|---|
| 545 | aimbs_putraw(bs, info->sn, strlen(info->sn)); |
|---|
| 546 | |
|---|
| 547 | aimbs_put16(bs, info->warnlevel); |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | if (info->present & AIM_USERINFO_PRESENT_FLAGS) |
|---|
| 551 | aim_addtlvtochain16(&tlvlist, 0x0001, info->flags); |
|---|
| 552 | if (info->present & AIM_USERINFO_PRESENT_MEMBERSINCE) |
|---|
| 553 | aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince); |
|---|
| 554 | if (info->present & AIM_USERINFO_PRESENT_ONLINESINCE) |
|---|
| 555 | aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince); |
|---|
| 556 | if (info->present & AIM_USERINFO_PRESENT_IDLE) |
|---|
| 557 | aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime); |
|---|
| 558 | |
|---|
| 559 | #if ICQ_OSCAR_SUPPORT |
|---|
| 560 | if (atoi(info->sn) != 0) { |
|---|
| 561 | if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS) |
|---|
| 562 | aim_addtlvtochain16(&tlvlist, 0x0006, info->icqinfo.status); |
|---|
| 563 | if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR) |
|---|
| 564 | aim_addtlvtochain32(&tlvlist, 0x000a, info->icqinfo.ipaddr); |
|---|
| 565 | } |
|---|
| 566 | #endif |
|---|
| 567 | |
|---|
| 568 | if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES) |
|---|
| 569 | aim_addtlvtochain_caps(&tlvlist, 0x000d, info->capabilities); |
|---|
| 570 | |
|---|
| 571 | if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN) |
|---|
| 572 | aim_addtlvtochain32(&tlvlist, (fu16_t)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen); |
|---|
| 573 | |
|---|
| 574 | aimbs_put16(bs, aim_counttlvchain(&tlvlist)); |
|---|
| 575 | aim_writetlvchain(bs, &tlvlist); |
|---|
| 576 | aim_freetlvchain(&tlvlist); |
|---|
| 577 | |
|---|
| 578 | return 0; |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | faim_export int aim_sendbuddyoncoming(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *info) |
|---|
| 582 | { |
|---|
| 583 | aim_frame_t *fr; |
|---|
| 584 | aim_snacid_t snacid; |
|---|
| 585 | |
|---|
| 586 | if (!sess || !conn || !info) |
|---|
| 587 | return -EINVAL; |
|---|
| 588 | |
|---|
| 589 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) |
|---|
| 590 | return -ENOMEM; |
|---|
| 591 | |
|---|
| 592 | snacid = aim_cachesnac(sess, 0x0003, 0x000b, 0x0000, NULL, 0); |
|---|
| 593 | |
|---|
| 594 | aim_putsnac(&fr->data, 0x0003, 0x000b, 0x0000, snacid); |
|---|
| 595 | aim_putuserinfo(&fr->data, info); |
|---|
| 596 | |
|---|
| 597 | aim_tx_enqueue(sess, fr); |
|---|
| 598 | |
|---|
| 599 | return 0; |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | faim_export int aim_sendbuddyoffgoing(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
|---|
| 603 | { |
|---|
| 604 | aim_frame_t *fr; |
|---|
| 605 | aim_snacid_t snacid; |
|---|
| 606 | |
|---|
| 607 | if (!sess || !conn || !sn) |
|---|
| 608 | return -EINVAL; |
|---|
| 609 | |
|---|
| 610 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
|---|
| 611 | return -ENOMEM; |
|---|
| 612 | |
|---|
| 613 | snacid = aim_cachesnac(sess, 0x0003, 0x000c, 0x0000, NULL, 0); |
|---|
| 614 | |
|---|
| 615 | aim_putsnac(&fr->data, 0x0003, 0x000c, 0x0000, snacid); |
|---|
| 616 | aimbs_put8(&fr->data, strlen(sn)); |
|---|
| 617 | aimbs_putraw(&fr->data, sn, strlen(sn)); |
|---|
| 618 | |
|---|
| 619 | aim_tx_enqueue(sess, fr); |
|---|
| 620 | |
|---|
| 621 | return 0; |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | /* |
|---|
| 625 | * Huh? What is this? |
|---|
| 626 | */ |
|---|
| 627 | faim_export int aim_0002_000b(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
|---|
| 628 | { |
|---|
| 629 | aim_frame_t *fr; |
|---|
| 630 | aim_snacid_t snacid; |
|---|
| 631 | |
|---|
| 632 | if (!sess || !conn || !sn) |
|---|
| 633 | return -EINVAL; |
|---|
| 634 | |
|---|
| 635 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
|---|
| 636 | return -ENOMEM; |
|---|
| 637 | |
|---|
| 638 | snacid = aim_cachesnac(sess, 0x0002, 0x000b, 0x0000, NULL, 0); |
|---|
| 639 | |
|---|
| 640 | aim_putsnac(&fr->data, 0x0002, 0x000b, 0x0000, snacid); |
|---|
| 641 | aimbs_put8(&fr->data, strlen(sn)); |
|---|
| 642 | aimbs_putraw(&fr->data, sn, strlen(sn)); |
|---|
| 643 | |
|---|
| 644 | aim_tx_enqueue(sess, fr); |
|---|
| 645 | |
|---|
| 646 | return 0; |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | /* |
|---|
| 650 | * Normally contains: |
|---|
| 651 | * t(0001) - short containing max profile length (value = 1024) |
|---|
| 652 | * t(0002) - short - unknown (value = 16) [max MIME type length?] |
|---|
| 653 | * t(0003) - short - unknown (value = 10) |
|---|
| 654 | */ |
|---|
| 655 | static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
|---|
| 656 | { |
|---|
| 657 | aim_tlvlist_t *tlvlist; |
|---|
| 658 | aim_rxcallback_t userfunc; |
|---|
| 659 | int ret = 0; |
|---|
| 660 | fu16_t maxsiglen = 0; |
|---|
| 661 | |
|---|
| 662 | tlvlist = aim_readtlvchain(bs); |
|---|
| 663 | |
|---|
| 664 | if (aim_gettlv(tlvlist, 0x0001, 1)) |
|---|
| 665 | maxsiglen = aim_gettlv16(tlvlist, 0x0001, 1); |
|---|
| 666 | |
|---|
| 667 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
|---|
| 668 | ret = userfunc(sess, rx, maxsiglen); |
|---|
| 669 | |
|---|
| 670 | aim_freetlvchain(&tlvlist); |
|---|
| 671 | |
|---|
| 672 | return ret; |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | static int userinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
|---|
| 676 | { |
|---|
| 677 | aim_userinfo_t userinfo; |
|---|
| 678 | char *text_encoding = NULL, *text = NULL; |
|---|
| 679 | aim_rxcallback_t userfunc; |
|---|
| 680 | aim_tlvlist_t *tlvlist; |
|---|
| 681 | aim_snac_t *origsnac = NULL; |
|---|
| 682 | struct aim_priv_inforeq *inforeq; |
|---|
| 683 | int ret = 0; |
|---|
| 684 | |
|---|
| 685 | origsnac = aim_remsnac(sess, snac->id); |
|---|
| 686 | |
|---|
| 687 | if (!origsnac || !origsnac->data) { |
|---|
| 688 | faimdprintf(sess, 0, "parse_userinfo_middle: major problem: no snac stored!\n"); |
|---|
| 689 | return 0; |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | inforeq = (struct aim_priv_inforeq *)origsnac->data; |
|---|
| 693 | |
|---|
| 694 | if ((inforeq->infotype != AIM_GETINFO_GENERALINFO) && |
|---|
| 695 | (inforeq->infotype != AIM_GETINFO_AWAYMESSAGE) && |
|---|
| 696 | (inforeq->infotype != AIM_GETINFO_CAPABILITIES)) { |
|---|
| 697 | faimdprintf(sess, 0, "parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype); |
|---|
| 698 | return 0; |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | aim_extractuserinfo(sess, bs, &userinfo); |
|---|
| 702 | |
|---|
| 703 | tlvlist = aim_readtlvchain(bs); |
|---|
| 704 | |
|---|
| 705 | /* |
|---|
| 706 | * Depending on what informational text was requested, different |
|---|
| 707 | * TLVs will appear here. |
|---|
| 708 | * |
|---|
| 709 | * Profile will be 1 and 2, away message will be 3 and 4, caps |
|---|
| 710 | * will be 5. |
|---|
| 711 | */ |
|---|
| 712 | if (inforeq->infotype == AIM_GETINFO_GENERALINFO) { |
|---|
| 713 | text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1); |
|---|
| 714 | text = aim_gettlv_str(tlvlist, 0x0002, 1); |
|---|
| 715 | } else if (inforeq->infotype == AIM_GETINFO_AWAYMESSAGE) { |
|---|
| 716 | text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1); |
|---|
| 717 | text = aim_gettlv_str(tlvlist, 0x0004, 1); |
|---|
| 718 | } else if (inforeq->infotype == AIM_GETINFO_CAPABILITIES) { |
|---|
| 719 | aim_tlv_t *ct; |
|---|
| 720 | |
|---|
| 721 | if ((ct = aim_gettlv(tlvlist, 0x0005, 1))) { |
|---|
| 722 | aim_bstream_t cbs; |
|---|
| 723 | |
|---|
| 724 | aim_bstream_init(&cbs, ct->value, ct->length); |
|---|
| 725 | |
|---|
| 726 | userinfo.capabilities = aim_getcap(sess, &cbs, ct->length); |
|---|
| 727 | userinfo.present = AIM_USERINFO_PRESENT_CAPABILITIES; |
|---|
| 728 | } |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
|---|
| 732 | ret = userfunc(sess, rx, &userinfo, inforeq->infotype, text_encoding, text); |
|---|
| 733 | |
|---|
| 734 | free(text_encoding); |
|---|
| 735 | free(text); |
|---|
| 736 | |
|---|
| 737 | aim_freetlvchain(&tlvlist); |
|---|
| 738 | |
|---|
| 739 | if (origsnac) |
|---|
| 740 | free(origsnac->data); |
|---|
| 741 | free(origsnac); |
|---|
| 742 | |
|---|
| 743 | return ret; |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
|---|
| 747 | { |
|---|
| 748 | |
|---|
| 749 | if (snac->subtype == 0x0003) |
|---|
| 750 | return rights(sess, mod, rx, snac, bs); |
|---|
| 751 | else if (snac->subtype == 0x0006) |
|---|
| 752 | return userinfo(sess, mod, rx, snac, bs); |
|---|
| 753 | |
|---|
| 754 | return 0; |
|---|
| 755 | } |
|---|
| 756 | |
|---|
| 757 | faim_internal int locate_modfirst(aim_session_t *sess, aim_module_t *mod) |
|---|
| 758 | { |
|---|
| 759 | |
|---|
| 760 | mod->family = 0x0002; |
|---|
| 761 | mod->version = 0x0001; |
|---|
| 762 | mod->toolid = 0x0101; |
|---|
| 763 | mod->toolversion = 0x047b; |
|---|
| 764 | mod->flags = 0; |
|---|
| 765 | strncpy(mod->name, "locate", sizeof(mod->name)); |
|---|
| 766 | mod->snachandler = snachandler; |
|---|
| 767 | |
|---|
| 768 | return 0; |
|---|
| 769 | } |
|---|