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