| 1 /* |
|
| 2 * Family 0x0015 - Encapsulated ICQ. |
|
| 3 * |
|
| 4 */ |
|
| 5 |
|
| 6 #define FAIM_INTERNAL |
|
| 7 #include <aim.h> |
|
| 8 |
|
| 9 faim_export int aim_icq_reqofflinemsgs(aim_session_t *sess) |
|
| 10 { |
|
| 11 aim_conn_t *conn; |
|
| 12 aim_frame_t *fr; |
|
| 13 aim_snacid_t snacid; |
|
| 14 int bslen; |
|
| 15 |
|
| 16 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 17 return -EINVAL; |
|
| 18 |
|
| 19 bslen = 2 + 4 + 2 + 2; |
|
| 20 |
|
| 21 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
|
| 22 return -ENOMEM; |
|
| 23 |
|
| 24 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 25 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 26 |
|
| 27 /* For simplicity, don't bother using a tlvlist */ |
|
| 28 aimbs_put16(&fr->data, 0x0001); |
|
| 29 aimbs_put16(&fr->data, bslen); |
|
| 30 |
|
| 31 aimbs_putle16(&fr->data, bslen - 2); |
|
| 32 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 33 aimbs_putle16(&fr->data, 0x003c); /* I command thee. */ |
|
| 34 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 35 |
|
| 36 aim_tx_enqueue(sess, fr); |
|
| 37 |
|
| 38 return 0; |
|
| 39 } |
|
| 40 |
|
| 41 faim_export int aim_icq_ackofflinemsgs(aim_session_t *sess) |
|
| 42 { |
|
| 43 aim_conn_t *conn; |
|
| 44 aim_frame_t *fr; |
|
| 45 aim_snacid_t snacid; |
|
| 46 int bslen; |
|
| 47 |
|
| 48 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 49 return -EINVAL; |
|
| 50 |
|
| 51 bslen = 2 + 4 + 2 + 2; |
|
| 52 |
|
| 53 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
|
| 54 return -ENOMEM; |
|
| 55 |
|
| 56 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 57 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 58 |
|
| 59 /* For simplicity, don't bother using a tlvlist */ |
|
| 60 aimbs_put16(&fr->data, 0x0001); |
|
| 61 aimbs_put16(&fr->data, bslen); |
|
| 62 |
|
| 63 aimbs_putle16(&fr->data, bslen - 2); |
|
| 64 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 65 aimbs_putle16(&fr->data, 0x003e); /* I command thee. */ |
|
| 66 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 67 |
|
| 68 aim_tx_enqueue(sess, fr); |
|
| 69 |
|
| 70 return 0; |
|
| 71 } |
|
| 72 |
|
| 73 faim_export int |
|
| 74 aim_icq_setsecurity(aim_session_t *sess, gboolean auth_required, gboolean webaware) |
|
| 75 { |
|
| 76 aim_conn_t *conn; |
|
| 77 aim_frame_t *fr; |
|
| 78 aim_snacid_t snacid; |
|
| 79 int bslen; |
|
| 80 |
|
| 81 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 82 return -EINVAL; |
|
| 83 |
|
| 84 bslen = 2+4+2+2+2+2+2+1+1+1+1+1+1; |
|
| 85 |
|
| 86 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
|
| 87 return -ENOMEM; |
|
| 88 |
|
| 89 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 90 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 91 |
|
| 92 /* For simplicity, don't bother using a tlvlist */ |
|
| 93 aimbs_put16(&fr->data, 0x0001); |
|
| 94 aimbs_put16(&fr->data, bslen); |
|
| 95 |
|
| 96 aimbs_putle16(&fr->data, bslen - 2); |
|
| 97 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 98 aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
|
| 99 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 100 aimbs_putle16(&fr->data, 0x0c3a); /* shrug. */ |
|
| 101 aimbs_putle16(&fr->data, 0x030c); |
|
| 102 aimbs_putle16(&fr->data, 0x0001); |
|
| 103 aimbs_putle8(&fr->data, webaware); |
|
| 104 aimbs_putle8(&fr->data, 0xf8); |
|
| 105 aimbs_putle8(&fr->data, 0x02); |
|
| 106 aimbs_putle8(&fr->data, 0x01); |
|
| 107 aimbs_putle8(&fr->data, 0x00); |
|
| 108 aimbs_putle8(&fr->data, !auth_required); |
|
| 109 |
|
| 110 aim_tx_enqueue(sess, fr); |
|
| 111 |
|
| 112 return 0; |
|
| 113 } |
|
| 114 |
|
| 115 /** |
|
| 116 * Change your ICQ password. |
|
| 117 * |
|
| 118 * @param sess The oscar session |
|
| 119 * @param passwd The new password. If this is longer than 8 characters it |
|
| 120 * will be truncated. |
|
| 121 * @return Return 0 if no errors, otherwise return the error number. |
|
| 122 */ |
|
| 123 faim_export int aim_icq_changepasswd(aim_session_t *sess, const char *passwd) |
|
| 124 { |
|
| 125 aim_conn_t *conn; |
|
| 126 aim_frame_t *fr; |
|
| 127 aim_snacid_t snacid; |
|
| 128 int bslen, passwdlen; |
|
| 129 |
|
| 130 if (!passwd) |
|
| 131 return -EINVAL; |
|
| 132 |
|
| 133 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 134 return -EINVAL; |
|
| 135 |
|
| 136 passwdlen = strlen(passwd); |
|
| 137 if (passwdlen > MAXICQPASSLEN) |
|
| 138 passwdlen = MAXICQPASSLEN; |
|
| 139 bslen = 2+4+2+2+2+2+passwdlen+1; |
|
| 140 |
|
| 141 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
|
| 142 return -ENOMEM; |
|
| 143 |
|
| 144 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 145 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 146 |
|
| 147 /* For simplicity, don't bother using a tlvlist */ |
|
| 148 aimbs_put16(&fr->data, 0x0001); |
|
| 149 aimbs_put16(&fr->data, bslen); |
|
| 150 |
|
| 151 aimbs_putle16(&fr->data, bslen - 2); |
|
| 152 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 153 aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
|
| 154 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 155 aimbs_putle16(&fr->data, 0x042e); /* shrug. */ |
|
| 156 aimbs_putle16(&fr->data, passwdlen+1); |
|
| 157 aimbs_putstr(&fr->data, passwd); |
|
| 158 aimbs_putle8(&fr->data, '\0'); |
|
| 159 |
|
| 160 aim_tx_enqueue(sess, fr); |
|
| 161 |
|
| 162 return 0; |
|
| 163 } |
|
| 164 |
|
| 165 faim_export int aim_icq_getallinfo(aim_session_t *sess, const char *uin) |
|
| 166 { |
|
| 167 aim_conn_t *conn; |
|
| 168 aim_frame_t *fr; |
|
| 169 aim_snacid_t snacid; |
|
| 170 int bslen; |
|
| 171 struct aim_icq_info *info; |
|
| 172 |
|
| 173 if (!uin || uin[0] < '0' || uin[0] > '9') |
|
| 174 return -EINVAL; |
|
| 175 |
|
| 176 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 177 return -EINVAL; |
|
| 178 |
|
| 179 bslen = 2 + 4 + 2 + 2 + 2 + 4; |
|
| 180 |
|
| 181 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
|
| 182 return -ENOMEM; |
|
| 183 |
|
| 184 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 185 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 186 |
|
| 187 /* For simplicity, don't bother using a tlvlist */ |
|
| 188 aimbs_put16(&fr->data, 0x0001); |
|
| 189 aimbs_put16(&fr->data, bslen); |
|
| 190 |
|
| 191 aimbs_putle16(&fr->data, bslen - 2); |
|
| 192 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 193 aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
|
| 194 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 195 aimbs_putle16(&fr->data, 0x04b2); /* shrug. */ |
|
| 196 aimbs_putle32(&fr->data, atoi(uin)); |
|
| 197 |
|
| 198 aim_tx_enqueue(sess, fr); |
|
| 199 |
|
| 200 /* Keep track of this request and the ICQ number and request ID */ |
|
| 201 info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info)); |
|
| 202 info->reqid = snacid; |
|
| 203 info->uin = atoi(uin); |
|
| 204 info->next = sess->icq_info; |
|
| 205 sess->icq_info = info; |
|
| 206 |
|
| 207 return 0; |
|
| 208 } |
|
| 209 |
|
| 210 faim_export int aim_icq_getalias(aim_session_t *sess, const char *uin) |
|
| 211 { |
|
| 212 aim_conn_t *conn; |
|
| 213 aim_frame_t *fr; |
|
| 214 aim_snacid_t snacid; |
|
| 215 int bslen; |
|
| 216 struct aim_icq_info *info; |
|
| 217 |
|
| 218 if (!uin || uin[0] < '0' || uin[0] > '9') |
|
| 219 return -EINVAL; |
|
| 220 |
|
| 221 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 222 return -EINVAL; |
|
| 223 |
|
| 224 bslen = 2 + 4 + 2 + 2 + 2 + 4; |
|
| 225 |
|
| 226 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
|
| 227 return -ENOMEM; |
|
| 228 |
|
| 229 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 230 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 231 |
|
| 232 /* For simplicity, don't bother using a tlvlist */ |
|
| 233 aimbs_put16(&fr->data, 0x0001); |
|
| 234 aimbs_put16(&fr->data, bslen); |
|
| 235 |
|
| 236 aimbs_putle16(&fr->data, bslen - 2); |
|
| 237 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 238 aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
|
| 239 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 240 aimbs_putle16(&fr->data, 0x04ba); /* shrug. */ |
|
| 241 aimbs_putle32(&fr->data, atoi(uin)); |
|
| 242 |
|
| 243 aim_tx_enqueue(sess, fr); |
|
| 244 |
|
| 245 /* Keep track of this request and the ICQ number and request ID */ |
|
| 246 info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info)); |
|
| 247 info->reqid = snacid; |
|
| 248 info->uin = atoi(uin); |
|
| 249 info->next = sess->icq_info; |
|
| 250 sess->icq_info = info; |
|
| 251 |
|
| 252 return 0; |
|
| 253 } |
|
| 254 |
|
| 255 faim_export int aim_icq_getsimpleinfo(aim_session_t *sess, const char *uin) |
|
| 256 { |
|
| 257 aim_conn_t *conn; |
|
| 258 aim_frame_t *fr; |
|
| 259 aim_snacid_t snacid; |
|
| 260 int bslen; |
|
| 261 |
|
| 262 if (!uin || uin[0] < '0' || uin[0] > '9') |
|
| 263 return -EINVAL; |
|
| 264 |
|
| 265 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 266 return -EINVAL; |
|
| 267 |
|
| 268 bslen = 2 + 4 + 2 + 2 + 2 + 4; |
|
| 269 |
|
| 270 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
|
| 271 return -ENOMEM; |
|
| 272 |
|
| 273 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 274 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 275 |
|
| 276 /* For simplicity, don't bother using a tlvlist */ |
|
| 277 aimbs_put16(&fr->data, 0x0001); |
|
| 278 aimbs_put16(&fr->data, bslen); |
|
| 279 |
|
| 280 aimbs_putle16(&fr->data, bslen - 2); |
|
| 281 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 282 aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
|
| 283 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 284 aimbs_putle16(&fr->data, 0x051f); /* shrug. */ |
|
| 285 aimbs_putle32(&fr->data, atoi(uin)); |
|
| 286 |
|
| 287 aim_tx_enqueue(sess, fr); |
|
| 288 |
|
| 289 return 0; |
|
| 290 } |
|
| 291 |
|
| 292 #if 0 |
|
| 293 faim_export int aim_icq_sendxmlreq(aim_session_t *sess, const char *xml) |
|
| 294 { |
|
| 295 aim_conn_t *conn; |
|
| 296 aim_frame_t *fr; |
|
| 297 aim_snacid_t snacid; |
|
| 298 int bslen; |
|
| 299 |
|
| 300 if (!xml || !strlen(xml)) |
|
| 301 return -EINVAL; |
|
| 302 |
|
| 303 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 304 return -EINVAL; |
|
| 305 |
|
| 306 bslen = 2 + 10 + 2 + strlen(xml) + 1; |
|
| 307 |
|
| 308 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
|
| 309 return -ENOMEM; |
|
| 310 |
|
| 311 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 312 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 313 |
|
| 314 /* For simplicity, don't bother using a tlvlist */ |
|
| 315 aimbs_put16(&fr->data, 0x0001); |
|
| 316 aimbs_put16(&fr->data, bslen); |
|
| 317 |
|
| 318 aimbs_putle16(&fr->data, bslen - 2); |
|
| 319 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 320 aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
|
| 321 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 322 aimbs_putle16(&fr->data, 0x0998); /* shrug. */ |
|
| 323 aimbs_putle16(&fr->data, strlen(xml) + 1); |
|
| 324 aimbs_putraw(&fr->data, (fu8_t *)xml, strlen(xml) + 1); |
|
| 325 |
|
| 326 aim_tx_enqueue(sess, fr); |
|
| 327 |
|
| 328 return 0; |
|
| 329 } |
|
| 330 #endif |
|
| 331 |
|
| 332 #if 0 |
|
| 333 /* |
|
| 334 * Send an SMS message. This is the non-US way. The US-way is to IM |
|
| 335 * their cell phone number (+19195551234). |
|
| 336 * |
|
| 337 * We basically construct and send an XML message. The format is: |
|
| 338 * <icq_sms_message> |
|
| 339 * <destination>full_phone_without_leading_+</destination> |
|
| 340 * <text>message</text> |
|
| 341 * <codepage>1252</codepage> |
|
| 342 * <senders_UIN>self_uin</senders_UIN> |
|
| 343 * <senders_name>self_name</senders_name> |
|
| 344 * <delivery_receipt>Yes|No</delivery_receipt> |
|
| 345 * <time>Wkd, DD Mmm YYYY HH:MM:SS TMZ</time> |
|
| 346 * </icq_sms_message> |
|
| 347 * |
|
| 348 * Yeah hi Peter, whaaaat's happening. If there's any way to use |
|
| 349 * a codepage other than 1252 that would be great. Thaaaanks. |
|
| 350 */ |
|
| 351 faim_export int aim_icq_sendsms(aim_session_t *sess, const char *name, const char *msg, const char *alias) |
|
| 352 { |
|
| 353 aim_conn_t *conn; |
|
| 354 aim_frame_t *fr; |
|
| 355 aim_snacid_t snacid; |
|
| 356 int bslen, xmllen; |
|
| 357 char *xml, timestr[30]; |
|
| 358 time_t t; |
|
| 359 struct tm *tm; |
|
| 360 |
|
| 361 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
|
| 362 return -EINVAL; |
|
| 363 |
|
| 364 if (!name || !msg || !alias) |
|
| 365 return -EINVAL; |
|
| 366 |
|
| 367 time(&t); |
|
| 368 tm = gmtime(&t); |
|
| 369 strftime(timestr, 30, "%a, %d %b %Y %T %Z", tm); |
|
| 370 |
|
| 371 /* The length of xml included the null terminating character */ |
|
| 372 xmllen = 225 + strlen(name) + strlen(msg) + strlen(sess->sn) + strlen(alias) + strlen(timestr) + 1; |
|
| 373 |
|
| 374 if (!(xml = (char *)malloc(xmllen*sizeof(char)))) |
|
| 375 return -ENOMEM; |
|
| 376 snprintf(xml, xmllen, "<icq_sms_message>\n" |
|
| 377 "\t<destination>%s</destination>\n" |
|
| 378 "\t<text>%s</text>\n" |
|
| 379 "\t<codepage>1252</codepage>\n" |
|
| 380 "\t<senders_UIN>%s</senders_UIN>\n" |
|
| 381 "\t<senders_name>%s</senders_name>\n" |
|
| 382 "\t<delivery_receipt>Yes</delivery_receipt>\n" |
|
| 383 "\t<time>%s</time>\n" |
|
| 384 "</icq_sms_message>\n", |
|
| 385 name, msg, sess->sn, alias, timestr); |
|
| 386 |
|
| 387 bslen = 37 + xmllen; |
|
| 388 |
|
| 389 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) { |
|
| 390 free(xml); |
|
| 391 return -ENOMEM; |
|
| 392 } |
|
| 393 |
|
| 394 snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
|
| 395 aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
|
| 396 |
|
| 397 /* For simplicity, don't bother using a tlvlist */ |
|
| 398 aimbs_put16(&fr->data, 0x0001); |
|
| 399 aimbs_put16(&fr->data, bslen); |
|
| 400 |
|
| 401 aimbs_putle16(&fr->data, bslen - 2); |
|
| 402 aimbs_putle32(&fr->data, atoi(sess->sn)); |
|
| 403 aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
|
| 404 aimbs_putle16(&fr->data, snacid); /* eh. */ |
|
| 405 |
|
| 406 /* From libicq200-0.3.2/src/SNAC-SRV.cpp */ |
|
| 407 aimbs_putle16(&fr->data, 0x8214); |
|
| 408 aimbs_put16(&fr->data, 0x0001); |
|
| 409 aimbs_put16(&fr->data, 0x0016); |
|
| 410 aimbs_put32(&fr->data, 0x00000000); |
|
| 411 aimbs_put32(&fr->data, 0x00000000); |
|
| 412 aimbs_put32(&fr->data, 0x00000000); |
|
| 413 aimbs_put32(&fr->data, 0x00000000); |
|
| 414 |
|
| 415 aimbs_put16(&fr->data, 0x0000); |
|
| 416 aimbs_put16(&fr->data, xmllen); |
|
| 417 aimbs_putstr(&fr->data, xml); |
|
| 418 |
|
| 419 aim_tx_enqueue(sess, fr); |
|
| 420 |
|
| 421 free(xml); |
|
| 422 |
|
| 423 return 0; |
|
| 424 } |
|
| 425 #endif |
|
| 426 |
|
| 427 static void aim_icq_freeinfo(struct aim_icq_info *info) { |
|
| 428 int i; |
|
| 429 |
|
| 430 if (!info) |
|
| 431 return; |
|
| 432 free(info->nick); |
|
| 433 free(info->first); |
|
| 434 free(info->last); |
|
| 435 free(info->email); |
|
| 436 free(info->homecity); |
|
| 437 free(info->homestate); |
|
| 438 free(info->homephone); |
|
| 439 free(info->homefax); |
|
| 440 free(info->homeaddr); |
|
| 441 free(info->mobile); |
|
| 442 free(info->homezip); |
|
| 443 free(info->personalwebpage); |
|
| 444 if (info->email2) |
|
| 445 for (i = 0; i < info->numaddresses; i++) |
|
| 446 free(info->email2[i]); |
|
| 447 free(info->email2); |
|
| 448 free(info->workcity); |
|
| 449 free(info->workstate); |
|
| 450 free(info->workphone); |
|
| 451 free(info->workfax); |
|
| 452 free(info->workaddr); |
|
| 453 free(info->workzip); |
|
| 454 free(info->workcompany); |
|
| 455 free(info->workdivision); |
|
| 456 free(info->workposition); |
|
| 457 free(info->workwebpage); |
|
| 458 free(info->info); |
|
| 459 free(info); |
|
| 460 } |
|
| 461 |
|
| 462 /** |
|
| 463 * Subtype 0x0003 - Response to 0x0015/0x002, contains an ICQesque packet. |
|
| 464 */ |
|
| 465 static int icqresponse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
|
| 466 { |
|
| 467 int ret = 0; |
|
| 468 aim_tlvlist_t *tl; |
|
| 469 aim_tlv_t *datatlv; |
|
| 470 aim_bstream_t qbs; |
|
| 471 fu32_t ouruin; |
|
| 472 fu16_t cmdlen, cmd, reqid; |
|
| 473 |
|
| 474 if (!(tl = aim_tlvlist_read(bs)) || !(datatlv = aim_tlv_gettlv(tl, 0x0001, 1))) { |
|
| 475 aim_tlvlist_free(&tl); |
|
| 476 gaim_debug_misc("oscar", "corrupt ICQ response\n"); |
|
| 477 return 0; |
|
| 478 } |
|
| 479 |
|
| 480 aim_bstream_init(&qbs, datatlv->value, datatlv->length); |
|
| 481 |
|
| 482 cmdlen = aimbs_getle16(&qbs); |
|
| 483 ouruin = aimbs_getle32(&qbs); |
|
| 484 cmd = aimbs_getle16(&qbs); |
|
| 485 reqid = aimbs_getle16(&qbs); |
|
| 486 |
|
| 487 gaim_debug_misc("oscar", "icq response: %d bytes, %ld, 0x%04x, 0x%04x\n", cmdlen, ouruin, cmd, reqid); |
|
| 488 |
|
| 489 if (cmd == 0x0041) { /* offline message */ |
|
| 490 struct aim_icq_offlinemsg msg; |
|
| 491 aim_rxcallback_t userfunc; |
|
| 492 |
|
| 493 memset(&msg, 0, sizeof(msg)); |
|
| 494 |
|
| 495 msg.sender = aimbs_getle32(&qbs); |
|
| 496 msg.year = aimbs_getle16(&qbs); |
|
| 497 msg.month = aimbs_getle8(&qbs); |
|
| 498 msg.day = aimbs_getle8(&qbs); |
|
| 499 msg.hour = aimbs_getle8(&qbs); |
|
| 500 msg.minute = aimbs_getle8(&qbs); |
|
| 501 msg.type = aimbs_getle8(&qbs); |
|
| 502 msg.flags = aimbs_getle8(&qbs); |
|
| 503 msg.msglen = aimbs_getle16(&qbs); |
|
| 504 msg.msg = aimbs_getstr(&qbs, msg.msglen); |
|
| 505 |
|
| 506 if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG))) |
|
| 507 ret = userfunc(sess, rx, &msg); |
|
| 508 |
|
| 509 free(msg.msg); |
|
| 510 |
|
| 511 } else if (cmd == 0x0042) { |
|
| 512 aim_rxcallback_t userfunc; |
|
| 513 |
|
| 514 if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE))) |
|
| 515 ret = userfunc(sess, rx); |
|
| 516 |
|
| 517 } else if (cmd == 0x07da) { /* information */ |
|
| 518 fu16_t subtype; |
|
| 519 struct aim_icq_info *info; |
|
| 520 aim_rxcallback_t userfunc; |
|
| 521 |
|
| 522 subtype = aimbs_getle16(&qbs); |
|
| 523 aim_bstream_advance(&qbs, 1); /* 0x0a */ |
|
| 524 |
|
| 525 /* find other data from the same request */ |
|
| 526 for (info = sess->icq_info; info && (info->reqid != reqid); info = info->next); |
|
| 527 if (!info) { |
|
| 528 info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info)); |
|
| 529 info->reqid = reqid; |
|
| 530 info->next = sess->icq_info; |
|
| 531 sess->icq_info = info; |
|
| 532 } |
|
| 533 |
|
| 534 switch (subtype) { |
|
| 535 case 0x00a0: { /* hide ip status */ |
|
| 536 /* nothing */ |
|
| 537 } break; |
|
| 538 |
|
| 539 case 0x00aa: { /* password change status */ |
|
| 540 /* nothing */ |
|
| 541 } break; |
|
| 542 |
|
| 543 case 0x00c8: { /* general and "home" information */ |
|
| 544 info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 545 info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 546 info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 547 info->email = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 548 info->homecity = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 549 info->homestate = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 550 info->homephone = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 551 info->homefax = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 552 info->homeaddr = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 553 info->mobile = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 554 info->homezip = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 555 info->homecountry = aimbs_getle16(&qbs); |
|
| 556 /* 0x0a 00 02 00 */ |
|
| 557 /* 1 byte timezone? */ |
|
| 558 /* 1 byte hide email flag? */ |
|
| 559 } break; |
|
| 560 |
|
| 561 case 0x00dc: { /* personal information */ |
|
| 562 info->age = aimbs_getle8(&qbs); |
|
| 563 info->unknown = aimbs_getle8(&qbs); |
|
| 564 info->gender = aimbs_getle8(&qbs); /* Not specified=0x00, Female=0x01, Male=0x02 */ |
|
| 565 info->personalwebpage = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 566 info->birthyear = aimbs_getle16(&qbs); |
|
| 567 info->birthmonth = aimbs_getle8(&qbs); |
|
| 568 info->birthday = aimbs_getle8(&qbs); |
|
| 569 info->language1 = aimbs_getle8(&qbs); |
|
| 570 info->language2 = aimbs_getle8(&qbs); |
|
| 571 info->language3 = aimbs_getle8(&qbs); |
|
| 572 /* 0x00 00 01 00 00 01 00 00 00 00 00 */ |
|
| 573 } break; |
|
| 574 |
|
| 575 case 0x00d2: { /* work information */ |
|
| 576 info->workcity = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 577 info->workstate = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 578 info->workphone = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 579 info->workfax = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 580 info->workaddr = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 581 info->workzip = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 582 info->workcountry = aimbs_getle16(&qbs); |
|
| 583 info->workcompany = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 584 info->workdivision = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 585 info->workposition = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 586 aim_bstream_advance(&qbs, 2); /* 0x01 00 */ |
|
| 587 info->workwebpage = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 588 } break; |
|
| 589 |
|
| 590 case 0x00e6: { /* additional personal information */ |
|
| 591 info->info = aimbs_getstr(&qbs, aimbs_getle16(&qbs)-1); |
|
| 592 } break; |
|
| 593 |
|
| 594 case 0x00eb: { /* email address(es) */ |
|
| 595 int i; |
|
| 596 info->numaddresses = aimbs_getle16(&qbs); |
|
| 597 info->email2 = (char **)calloc(info->numaddresses, sizeof(char *)); |
|
| 598 for (i = 0; i < info->numaddresses; i++) { |
|
| 599 info->email2[i] = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 600 if (i+1 != info->numaddresses) |
|
| 601 aim_bstream_advance(&qbs, 1); /* 0x00 */ |
|
| 602 } |
|
| 603 } break; |
|
| 604 |
|
| 605 case 0x00f0: { /* personal interests */ |
|
| 606 } break; |
|
| 607 |
|
| 608 case 0x00fa: { /* past background and current organizations */ |
|
| 609 } break; |
|
| 610 |
|
| 611 case 0x0104: { /* alias info */ |
|
| 612 info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 613 info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 614 info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 615 aim_bstream_advance(&qbs, aimbs_getle16(&qbs)); /* email address? */ |
|
| 616 /* Then 0x00 02 00 */ |
|
| 617 } break; |
|
| 618 |
|
| 619 case 0x010e: { /* unknown */ |
|
| 620 /* 0x00 00 */ |
|
| 621 } break; |
|
| 622 |
|
| 623 case 0x019a: { /* simple info */ |
|
| 624 aim_bstream_advance(&qbs, 2); |
|
| 625 info->uin = aimbs_getle32(&qbs); |
|
| 626 info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 627 info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 628 info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 629 info->email = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
|
| 630 /* Then 0x00 02 00 00 00 00 00 */ |
|
| 631 } break; |
|
| 632 } /* End switch statement */ |
|
| 633 |
|
| 634 if (!(snac->flags & 0x0001)) { |
|
| 635 if (subtype != 0x0104) |
|
| 636 if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_INFO))) |
|
| 637 ret = userfunc(sess, rx, info); |
|
| 638 |
|
| 639 if (info->uin && info->nick) |
|
| 640 if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_ALIAS))) |
|
| 641 ret = userfunc(sess, rx, info); |
|
| 642 |
|
| 643 if (sess->icq_info == info) { |
|
| 644 sess->icq_info = info->next; |
|
| 645 } else { |
|
| 646 struct aim_icq_info *cur; |
|
| 647 for (cur=sess->icq_info; (cur->next && (cur->next!=info)); cur=cur->next); |
|
| 648 if (cur->next) |
|
| 649 cur->next = cur->next->next; |
|
| 650 } |
|
| 651 aim_icq_freeinfo(info); |
|
| 652 } |
|
| 653 } |
|
| 654 |
|
| 655 aim_tlvlist_free(&tl); |
|
| 656 |
|
| 657 return ret; |
|
| 658 } |
|
| 659 |
|
| 660 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
|
| 661 { |
|
| 662 |
|
| 663 if (snac->subtype == 0x0003) |
|
| 664 return icqresponse(sess, mod, rx, snac, bs); |
|
| 665 |
|
| 666 return 0; |
|
| 667 } |
|
| 668 |
|
| 669 static void icq_shutdown(aim_session_t *sess, aim_module_t *mod) |
|
| 670 { |
|
| 671 struct aim_icq_info *del; |
|
| 672 |
|
| 673 while (sess->icq_info) { |
|
| 674 del = sess->icq_info; |
|
| 675 sess->icq_info = sess->icq_info->next; |
|
| 676 aim_icq_freeinfo(del); |
|
| 677 } |
|
| 678 |
|
| 679 return; |
|
| 680 } |
|
| 681 |
|
| 682 faim_internal int icq_modfirst(aim_session_t *sess, aim_module_t *mod) |
|
| 683 { |
|
| 684 |
|
| 685 mod->family = 0x0015; |
|
| 686 mod->version = 0x0001; |
|
| 687 mod->toolid = 0x0110; |
|
| 688 mod->toolversion = 0x047c; |
|
| 689 mod->flags = 0; |
|
| 690 strncpy(mod->name, "icq", sizeof(mod->name)); |
|
| 691 mod->snachandler = snachandler; |
|
| 692 mod->shutdown = icq_shutdown; |
|
| 693 |
|
| 694 return 0; |
|
| 695 } |
|