Changeset 6e14204
- Timestamp:
- 2009-01-07T01:20:57Z (16 years ago)
- Branches:
- master
- Children:
- 9f2f25f
- Parents:
- 8bbe52a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
skype/skype.c
r8bbe52a r6e14204 287 287 } 288 288 289 static void skype_parse_user(struct im_connection *ic, char *line) 290 { 291 int flags = 0; 292 char *ptr; 293 struct skype_data *sd = ic->proto_data; 294 char *user = strchr(line, ' '); 295 char *status = strrchr(line, ' '); 296 297 status++; 298 ptr = strchr(++user, ' '); 299 if (!ptr) 300 return; 301 *ptr = '\0'; 302 ptr++; 303 if (!strncmp(ptr, "ONLINESTATUS ", 13) && 304 strcmp(user, sd->username) != 0 305 && strcmp(user, "echo123") != 0) { 306 ptr = g_strdup_printf("%s@skype.com", user); 307 imcb_add_buddy(ic, ptr, NULL); 308 if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || !set_getbool(&ic->acc->set, "skypeout_offline"))) 309 flags |= OPT_LOGGED_IN; 310 if (strcmp(status, "ONLINE") != 0 && strcmp(status, "SKYPEME") != 0) 311 flags |= OPT_AWAY; 312 imcb_buddy_status(ic, ptr, flags, NULL, NULL); 313 g_free(ptr); 314 } else if (!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) { 315 char *message = ptr + 20; 316 if (strlen(message)) 317 skype_buddy_ask(ic, user, message); 318 } else if (!strncmp(ptr, "BUDDYSTATUS ", 12)) { 319 char *st = ptr + 12; 320 if (!strcmp(st, "3")) { 321 char *buf = g_strdup_printf("%s@skype.com", user); 322 imcb_add_buddy(ic, buf, NULL); 323 g_free(buf); 324 } 325 } else if (!strncmp(ptr, "FULLNAME ", 9)) 326 sd->info_fullname = g_strdup_printf("%s", ptr + 9); 327 else if (!strncmp(ptr, "PHONE_HOME ", 11)) 328 sd->info_phonehome = g_strdup_printf("%s", ptr + 11); 329 else if (!strncmp(ptr, "PHONE_OFFICE ", 13)) 330 sd->info_phoneoffice = g_strdup_printf("%s", ptr + 13); 331 else if (!strncmp(ptr, "PHONE_MOBILE ", 13)) 332 sd->info_phonemobile = g_strdup_printf("%s", ptr + 13); 333 else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20)) 334 sd->info_nrbuddies = g_strdup_printf("%s", ptr + 20); 335 else if (!strncmp(ptr, "TIMEZONE ", 9)) 336 sd->info_tz = g_strdup_printf("%s", ptr + 9); 337 else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20)) 338 sd->info_seen = g_strdup_printf("%s", ptr + 20); 339 else if (!strncmp(ptr, "BIRTHDAY ", 9)) 340 sd->info_birthday = g_strdup_printf("%s", ptr + 9); 341 else if (!strncmp(ptr, "SEX ", 4)) 342 sd->info_sex = g_strdup_printf("%s", ptr + 4); 343 else if (!strncmp(ptr, "LANGUAGE ", 9)) 344 sd->info_language = g_strdup_printf("%s", ptr + 9); 345 else if (!strncmp(ptr, "COUNTRY ", 8)) 346 sd->info_country = g_strdup_printf("%s", ptr + 8); 347 else if (!strncmp(ptr, "PROVINCE ", 9)) 348 sd->info_province = g_strdup_printf("%s", ptr + 9); 349 else if (!strncmp(ptr, "CITY ", 5)) 350 sd->info_city = g_strdup_printf("%s", ptr + 5); 351 else if (!strncmp(ptr, "HOMEPAGE ", 9)) 352 sd->info_homepage = g_strdup_printf("%s", ptr + 9); 353 else if (!strncmp(ptr, "ABOUT ", 6)) { 354 sd->info_about = g_strdup_printf("%s", ptr + 6); 355 356 GString *st = g_string_new("Contact Information\n"); 357 g_string_append_printf(st, "Skype Name: %s\n", user); 358 if (sd->info_fullname) { 359 if (strlen(sd->info_fullname)) 360 g_string_append_printf(st, "Full Name: %s\n", sd->info_fullname); 361 g_free(sd->info_fullname); 362 } 363 if (sd->info_phonehome) { 364 if (strlen(sd->info_phonehome)) 365 g_string_append_printf(st, "Home Phone: %s\n", sd->info_phonehome); 366 g_free(sd->info_phonehome); 367 } 368 if (sd->info_phoneoffice) { 369 if (strlen(sd->info_phoneoffice)) 370 g_string_append_printf(st, "Office Phone: %s\n", sd->info_phoneoffice); 371 g_free(sd->info_phoneoffice); 372 } 373 if (sd->info_phonemobile) { 374 if (strlen(sd->info_phonemobile)) 375 g_string_append_printf(st, "Mobile Phone: %s\n", sd->info_phonemobile); 376 g_free(sd->info_phonemobile); 377 } 378 g_string_append_printf(st, "Personal Information\n"); 379 if (sd->info_nrbuddies) { 380 if (strlen(sd->info_nrbuddies)) 381 g_string_append_printf(st, "Contacts: %s\n", sd->info_nrbuddies); 382 g_free(sd->info_nrbuddies); 383 } 384 if (sd->info_tz) { 385 if (strlen(sd->info_tz)) { 386 char ib[256]; 387 time_t t = time(NULL); 388 t += atoi(sd->info_tz)-(60*60*24); 389 struct tm *gt = gmtime(&t); 390 strftime(ib, 256, "%H:%M:%S", gt); 391 g_string_append_printf(st, "Local Time: %s\n", ib); 392 } 393 g_free(sd->info_tz); 394 } 395 if (sd->info_seen) { 396 if (strlen(sd->info_seen)) { 397 char ib[256]; 398 time_t it = atoi(sd->info_seen); 399 struct tm *tm = localtime(&it); 400 strftime(ib, 256, ("%Y. %m. %d. %H:%M"), tm); 401 g_string_append_printf(st, "Last Seen: %s\n", ib); 402 } 403 g_free(sd->info_seen); 404 } 405 if (sd->info_birthday) { 406 if (strlen(sd->info_birthday) && strcmp(sd->info_birthday, "0")) { 407 char ib[256]; 408 struct tm tm; 409 strptime(sd->info_birthday, "%Y%m%d", &tm); 410 strftime(ib, 256, "%B %d, %Y", &tm); 411 g_string_append_printf(st, "Birthday: %s\n", ib); 412 413 strftime(ib, 256, "%Y", &tm); 414 int year = atoi(ib); 415 time_t t = time(NULL); 416 struct tm *lt = localtime(&t); 417 g_string_append_printf(st, "Age: %d\n", lt->tm_year+1900-year); 418 } 419 g_free(sd->info_birthday); 420 } 421 if (sd->info_sex) { 422 if (strlen(sd->info_sex)) { 423 char *iptr = sd->info_sex; 424 while (*iptr++) 425 *iptr = tolower(*iptr); 426 g_string_append_printf(st, "Gender: %s\n", sd->info_sex); 427 } 428 g_free(sd->info_sex); 429 } 430 if (sd->info_language) { 431 if (strlen(sd->info_language)) { 432 char *iptr = strchr(sd->info_language, ' '); 433 if (iptr) 434 iptr++; 435 else 436 iptr = sd->info_language; 437 g_string_append_printf(st, "Language: %s\n", iptr); 438 } 439 g_free(sd->info_language); 440 } 441 if (sd->info_country) { 442 if (strlen(sd->info_country)) { 443 char *iptr = strchr(sd->info_country, ' '); 444 if (iptr) 445 iptr++; 446 else 447 iptr = sd->info_country; 448 g_string_append_printf(st, "Country: %s\n", iptr); 449 } 450 g_free(sd->info_country); 451 } 452 if (sd->info_province) { 453 if (strlen(sd->info_province)) 454 g_string_append_printf(st, "Region: %s\n", sd->info_province); 455 g_free(sd->info_province); 456 } 457 if (sd->info_city) { 458 if (strlen(sd->info_city)) 459 g_string_append_printf(st, "City: %s\n", sd->info_city); 460 g_free(sd->info_city); 461 } 462 if (sd->info_homepage) { 463 if (strlen(sd->info_homepage)) 464 g_string_append_printf(st, "Homepage: %s\n", sd->info_homepage); 465 g_free(sd->info_homepage); 466 } 467 if (sd->info_about) { 468 if (strlen(sd->info_about)) 469 g_string_append_printf(st, "%s\n", sd->info_about); 470 g_free(sd->info_about); 471 } 472 imcb_log(ic, "%s", st->str); 473 g_string_free(st, TRUE); 474 } 475 } 476 477 static void skype_parse_chatmessage(struct im_connection *ic, char *line) 478 { 479 struct skype_data *sd = ic->proto_data; 480 char buf[1024]; 481 char *id = strchr(line, ' '); 482 483 if (++id) { 484 char *info = strchr(id, ' '); 485 486 if (!info) 487 return; 488 *info = '\0'; 489 info++; 490 if (!strcmp(info, "STATUS RECEIVED")) { 491 /* New message ID: 492 * (1) Request its from field 493 * (2) Request its body 494 * (3) Request its type 495 * (4) Query chatname 496 */ 497 g_snprintf(buf, 1024, "GET CHATMESSAGE %s FROM_HANDLE\n", id); 498 skype_write(ic, buf); 499 g_snprintf(buf, 1024, "GET CHATMESSAGE %s BODY\n", id); 500 skype_write(ic, buf); 501 g_snprintf(buf, 1024, "GET CHATMESSAGE %s TYPE\n", id); 502 skype_write(ic, buf); 503 g_snprintf(buf, 1024, "GET CHATMESSAGE %s CHATNAME\n", id); 504 skype_write(ic, buf); 505 } else if (!strncmp(info, "FROM_HANDLE ", 12)) { 506 info += 12; 507 /* New from field value. Store 508 * it, then we can later use it 509 * when we got the message's 510 * body. */ 511 g_free(sd->handle); 512 sd->handle = g_strdup_printf("%s@skype.com", info); 513 } else if (!strncmp(info, "EDITED_BY ", 10)) { 514 info += 10; 515 /* This is the same as 516 * FROM_HANDLE, except that we 517 * never request these lines 518 * from Skype, we just get 519 * them. */ 520 g_free(sd->handle); 521 sd->handle = g_strdup_printf("%s@skype.com", info); 522 } else if (!strncmp(info, "BODY ", 5)) { 523 info += 5; 524 sd->body = g_list_append(sd->body, g_strdup(info)); 525 } else if (!strncmp(info, "TYPE ", 5)) { 526 info += 5; 527 g_free(sd->type); 528 sd->type = g_strdup(info); 529 } else if (!strncmp(info, "CHATNAME ", 9)) { 530 info += 9; 531 if (sd->handle && sd->body && sd->type) { 532 struct groupchat *gc = skype_chat_by_name(ic, info); 533 int i; 534 for (i = 0; i < g_list_length(sd->body); i++) { 535 char *body = g_list_nth_data(sd->body, i); 536 if (!strcmp(sd->type, "SAID") || !strcmp(sd->type, "EMOTED")) { 537 if (!strcmp(sd->type, "SAID")) 538 g_snprintf(buf, 1024, "%s", body); 539 else 540 g_snprintf(buf, 1024, "/me %s", body); 541 if (!gc) 542 /* Private message */ 543 imcb_buddy_msg(ic, sd->handle, buf, 0, 0); 544 else 545 /* Groupchat message */ 546 imcb_chat_msg(gc, sd->handle, buf, 0, 0); 547 } else if (!strcmp(sd->type, "SETTOPIC")) { 548 if (gc) 549 imcb_chat_topic(gc, sd->handle, body, 0); 550 } else if (!strcmp(sd->type, "LEFT")) { 551 if (gc) 552 imcb_chat_remove_buddy(gc, sd->handle, NULL); 553 } 554 } 555 g_list_free(sd->body); 556 sd->body = NULL; 557 } 558 } 559 } 560 } 561 289 562 static gboolean skype_read_callback(gpointer data, gint fd, 290 563 b_input_condition cond) … … 294 567 char buf[1024]; 295 568 int st; 296 char **lines, **lineptr, *line , *ptr;569 char **lines, **lineptr, *line; 297 570 298 571 if (!sd || sd->fd == -1) … … 313 586 skype_parse_users(ic, line); 314 587 else if (!strncmp(line, "USER ", 5)) { 315 int flags = 0; 316 char *status = strrchr(line, ' '); 317 char *user = strchr(line, ' '); 318 status++; 319 ptr = strchr(++user, ' '); 320 *ptr = '\0'; 321 ptr++; 322 if (!strncmp(ptr, "ONLINESTATUS ", 13) && 323 strcmp(user, sd->username) != 0 324 && strcmp(user, "echo123") != 0) { 325 ptr = g_strdup_printf("%s@skype.com", user); 326 imcb_add_buddy(ic, ptr, NULL); 327 if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || !set_getbool(&ic->acc->set, "skypeout_offline"))) 328 flags |= OPT_LOGGED_IN; 329 if (strcmp(status, "ONLINE") != 0 && strcmp(status, "SKYPEME") != 0) 330 flags |= OPT_AWAY; 331 imcb_buddy_status(ic, ptr, flags, NULL, NULL); 332 g_free(ptr); 333 } else if (!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) { 334 char *message = ptr + 20; 335 if (strlen(message)) 336 skype_buddy_ask(ic, user, message); 337 } else if (!strncmp(ptr, "BUDDYSTATUS ", 12)) { 338 char *st = ptr + 12; 339 if (!strcmp(st, "3")) { 340 char *buf = g_strdup_printf("%s@skype.com", user); 341 imcb_add_buddy(ic, buf, NULL); 342 g_free(buf); 343 } 344 } else if (!strncmp(ptr, "FULLNAME ", 9)) 345 sd->info_fullname = g_strdup_printf("%s", ptr + 9); 346 else if (!strncmp(ptr, "PHONE_HOME ", 11)) 347 sd->info_phonehome = g_strdup_printf("%s", ptr + 11); 348 else if (!strncmp(ptr, "PHONE_OFFICE ", 13)) 349 sd->info_phoneoffice = g_strdup_printf("%s", ptr + 13); 350 else if (!strncmp(ptr, "PHONE_MOBILE ", 13)) 351 sd->info_phonemobile = g_strdup_printf("%s", ptr + 13); 352 else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20)) 353 sd->info_nrbuddies = g_strdup_printf("%s", ptr + 20); 354 else if (!strncmp(ptr, "TIMEZONE ", 9)) 355 sd->info_tz = g_strdup_printf("%s", ptr + 9); 356 else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20)) 357 sd->info_seen = g_strdup_printf("%s", ptr + 20); 358 else if (!strncmp(ptr, "BIRTHDAY ", 9)) 359 sd->info_birthday = g_strdup_printf("%s", ptr + 9); 360 else if (!strncmp(ptr, "SEX ", 4)) 361 sd->info_sex = g_strdup_printf("%s", ptr + 4); 362 else if (!strncmp(ptr, "LANGUAGE ", 9)) 363 sd->info_language = g_strdup_printf("%s", ptr + 9); 364 else if (!strncmp(ptr, "COUNTRY ", 8)) 365 sd->info_country = g_strdup_printf("%s", ptr + 8); 366 else if (!strncmp(ptr, "PROVINCE ", 9)) 367 sd->info_province = g_strdup_printf("%s", ptr + 9); 368 else if (!strncmp(ptr, "CITY ", 5)) 369 sd->info_city = g_strdup_printf("%s", ptr + 5); 370 else if (!strncmp(ptr, "HOMEPAGE ", 9)) 371 sd->info_homepage = g_strdup_printf("%s", ptr + 9); 372 else if (!strncmp(ptr, "ABOUT ", 6)) { 373 sd->info_about = g_strdup_printf("%s", ptr + 6); 374 375 GString *st = g_string_new("Contact Information\n"); 376 g_string_append_printf(st, "Skype Name: %s\n", user); 377 if (sd->info_fullname) { 378 if (strlen(sd->info_fullname)) 379 g_string_append_printf(st, "Full Name: %s\n", sd->info_fullname); 380 g_free(sd->info_fullname); 381 } 382 if (sd->info_phonehome) { 383 if (strlen(sd->info_phonehome)) 384 g_string_append_printf(st, "Home Phone: %s\n", sd->info_phonehome); 385 g_free(sd->info_phonehome); 386 } 387 if (sd->info_phoneoffice) { 388 if (strlen(sd->info_phoneoffice)) 389 g_string_append_printf(st, "Office Phone: %s\n", sd->info_phoneoffice); 390 g_free(sd->info_phoneoffice); 391 } 392 if (sd->info_phonemobile) { 393 if (strlen(sd->info_phonemobile)) 394 g_string_append_printf(st, "Mobile Phone: %s\n", sd->info_phonemobile); 395 g_free(sd->info_phonemobile); 396 } 397 g_string_append_printf(st, "Personal Information\n"); 398 if (sd->info_nrbuddies) { 399 if (strlen(sd->info_nrbuddies)) 400 g_string_append_printf(st, "Contacts: %s\n", sd->info_nrbuddies); 401 g_free(sd->info_nrbuddies); 402 } 403 if (sd->info_tz) { 404 if (strlen(sd->info_tz)) { 405 char ib[256]; 406 time_t t = time(NULL); 407 t += atoi(sd->info_tz)-(60*60*24); 408 struct tm *gt = gmtime(&t); 409 strftime(ib, 256, "%H:%M:%S", gt); 410 g_string_append_printf(st, "Local Time: %s\n", ib); 411 } 412 g_free(sd->info_tz); 413 } 414 if (sd->info_seen) { 415 if (strlen(sd->info_seen)) { 416 char ib[256]; 417 time_t it = atoi(sd->info_seen); 418 struct tm *tm = localtime(&it); 419 strftime(ib, 256, ("%Y. %m. %d. %H:%M"), tm); 420 g_string_append_printf(st, "Last Seen: %s\n", ib); 421 } 422 g_free(sd->info_seen); 423 } 424 if (sd->info_birthday) { 425 if (strlen(sd->info_birthday) && strcmp(sd->info_birthday, "0")) { 426 char ib[256]; 427 struct tm tm; 428 strptime(sd->info_birthday, "%Y%m%d", &tm); 429 strftime(ib, 256, "%B %d, %Y", &tm); 430 g_string_append_printf(st, "Birthday: %s\n", ib); 431 432 strftime(ib, 256, "%Y", &tm); 433 int year = atoi(ib); 434 time_t t = time(NULL); 435 struct tm *lt = localtime(&t); 436 g_string_append_printf(st, "Age: %d\n", lt->tm_year+1900-year); 437 } 438 g_free(sd->info_birthday); 439 } 440 if (sd->info_sex) { 441 if (strlen(sd->info_sex)) { 442 char *iptr = sd->info_sex; 443 while (*iptr++) 444 *iptr = tolower(*iptr); 445 g_string_append_printf(st, "Gender: %s\n", sd->info_sex); 446 } 447 g_free(sd->info_sex); 448 } 449 if (sd->info_language) { 450 if (strlen(sd->info_language)) { 451 char *iptr = strchr(sd->info_language, ' '); 452 if (iptr) 453 iptr++; 454 else 455 iptr = sd->info_language; 456 g_string_append_printf(st, "Language: %s\n", iptr); 457 } 458 g_free(sd->info_language); 459 } 460 if (sd->info_country) { 461 if (strlen(sd->info_country)) { 462 char *iptr = strchr(sd->info_country, ' '); 463 if (iptr) 464 iptr++; 465 else 466 iptr = sd->info_country; 467 g_string_append_printf(st, "Country: %s\n", iptr); 468 } 469 g_free(sd->info_country); 470 } 471 if (sd->info_province) { 472 if (strlen(sd->info_province)) 473 g_string_append_printf(st, "Region: %s\n", sd->info_province); 474 g_free(sd->info_province); 475 } 476 if (sd->info_city) { 477 if (strlen(sd->info_city)) 478 g_string_append_printf(st, "City: %s\n", sd->info_city); 479 g_free(sd->info_city); 480 } 481 if (sd->info_homepage) { 482 if (strlen(sd->info_homepage)) 483 g_string_append_printf(st, "Homepage: %s\n", sd->info_homepage); 484 g_free(sd->info_homepage); 485 } 486 if (sd->info_about) { 487 if (strlen(sd->info_about)) 488 g_string_append_printf(st, "%s\n", sd->info_about); 489 g_free(sd->info_about); 490 } 491 imcb_log(ic, "%s", st->str); 492 g_string_free(st, TRUE); 493 } 588 skype_parse_user(ic, line); 494 589 } else if (!strncmp(line, "CHATMESSAGE ", 12)) { 495 char *id = strchr(line, ' '); 496 if (++id) { 497 char *info = strchr(id, ' '); 498 *info = '\0'; 499 info++; 500 if (!strcmp(info, "STATUS RECEIVED")) { 501 /* New message ID: 502 * (1) Request its from field 503 * (2) Request its body 504 * (3) Request its type 505 * (4) Query chatname 506 */ 507 g_snprintf(buf, 1024, "GET CHATMESSAGE %s FROM_HANDLE\n", id); 508 skype_write(ic, buf); 509 g_snprintf(buf, 1024, "GET CHATMESSAGE %s BODY\n", id); 510 skype_write(ic, buf); 511 g_snprintf(buf, 1024, "GET CHATMESSAGE %s TYPE\n", id); 512 skype_write(ic, buf); 513 g_snprintf(buf, 1024, "GET CHATMESSAGE %s CHATNAME\n", id); 514 skype_write(ic, buf); 515 } else if (!strncmp(info, "FROM_HANDLE ", 12)) { 516 info += 12; 517 /* New from field value. Store 518 * it, then we can later use it 519 * when we got the message's 520 * body. */ 521 g_free(sd->handle); 522 sd->handle = g_strdup_printf("%s@skype.com", info); 523 } else if (!strncmp(info, "EDITED_BY ", 10)) { 524 info += 10; 525 /* This is the same as 526 * FROM_HANDLE, except that we 527 * never request these lines 528 * from Skype, we just get 529 * them. */ 530 g_free(sd->handle); 531 sd->handle = g_strdup_printf("%s@skype.com", info); 532 } else if (!strncmp(info, "BODY ", 5)) { 533 info += 5; 534 sd->body = g_list_append(sd->body, g_strdup(info)); 535 } else if (!strncmp(info, "TYPE ", 5)) { 536 info += 5; 537 g_free(sd->type); 538 sd->type = g_strdup(info); 539 } else if (!strncmp(info, "CHATNAME ", 9)) { 540 info += 9; 541 if (sd->handle && sd->body && sd->type) { 542 struct groupchat *gc = skype_chat_by_name(ic, info); 543 int i; 544 for (i = 0; i < g_list_length(sd->body); i++) { 545 char *body = g_list_nth_data(sd->body, i); 546 if (!strcmp(sd->type, "SAID") || !strcmp(sd->type, "EMOTED")) { 547 char *st; 548 if (!strcmp(sd->type, "SAID")) 549 st = g_strdup(body); 550 else 551 st = g_strdup_printf("/me %s", body); 552 if (!gc) 553 /* Private message */ 554 imcb_buddy_msg(ic, sd->handle, st, 0, 0); 555 else 556 /* Groupchat message */ 557 imcb_chat_msg(gc, sd->handle, st, 0, 0); 558 g_free(st); 559 } else if (!strcmp(sd->type, "SETTOPIC")) { 560 if (gc) 561 imcb_chat_topic(gc, sd->handle, body, 0); 562 } else if (!strcmp(sd->type, "LEFT")) { 563 if (gc) 564 imcb_chat_remove_buddy(gc, sd->handle, NULL); 565 } 566 } 567 g_list_free(sd->body); 568 sd->body = NULL; 569 } 570 } 571 } 590 skype_parse_chatmessage(ic, line); 572 591 } else if (!strncmp(line, "CALL ", 5)) { 573 592 char *id = strchr(line, ' ');
Note: See TracChangeset
for help on using the changeset viewer.