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