Changeset 5ebff60 for protocols/skype
- Timestamp:
- 2015-02-20T22:50:54Z (10 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/skype/skype.c
raf359b4 r5ebff60 30 30 #define SKYPE_DEFAULT_PORT "2727" 31 31 #define IRC_LINE_SIZE 16384 32 #define ARRAY_SIZE(x) (sizeof(x) /sizeof(x[0]))32 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) 33 33 34 34 /* … … 151 151 { "SKYPEME", "Skype Me" }, 152 152 { "ONLINE", "Online" }, 153 { NULL, NULL }153 { NULL, NULL } 154 154 }; 155 155 … … 163 163 struct pollfd pfd[1]; 164 164 165 if (!sd->ssl) 165 if (!sd->ssl) { 166 166 return FALSE; 167 } 167 168 168 169 pfd[0].fd = sd->fd; … … 196 197 { 197 198 struct skype_buddy_ask_data *bla = data; 199 198 200 skype_printf(bla->ic, "SET USER %s ISAUTHORIZED TRUE\n", 199 201 bla->handle); 200 202 g_free(bla->handle); 201 203 g_free(bla); … … 205 207 { 206 208 struct skype_buddy_ask_data *bla = data; 209 207 210 skype_printf(bla->ic, "SET USER %s ISAUTHORIZED FALSE\n", 208 211 bla->handle); 209 212 g_free(bla->handle); 210 213 g_free(bla); … … 214 217 { 215 218 struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, 216 219 1); 217 220 char *buf; 218 221 … … 228 231 { 229 232 struct skype_buddy_ask_data *bla = data; 233 230 234 skype_printf(bla->ic, "SET CALL %s STATUS INPROGRESS\n", 231 235 bla->handle); 232 236 g_free(bla->handle); 233 237 g_free(bla); … … 237 241 { 238 242 struct skype_buddy_ask_data *bla = data; 243 239 244 skype_printf(bla->ic, "SET CALL %s STATUS FINISHED\n", 240 245 bla->handle); 241 246 g_free(bla->handle); 242 247 g_free(bla); … … 246 251 { 247 252 struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, 248 253 1); 249 254 250 255 bla->ic = ic; … … 297 302 struct skype_group *sg = g_list_nth_data(sd->groups, i); 298 303 for (j = 0; j < g_list_length(sg->users); j++) { 299 if (!strcmp(g_list_nth_data(sg->users, j), username)) 304 if (!strcmp(g_list_nth_data(sg->users, j), username)) { 300 305 return sg->name; 306 } 301 307 } 302 308 } … … 311 317 for (i = 0; i < g_list_length(sd->groups); i++) { 312 318 struct skype_group *sg = g_list_nth_data(sd->groups, i); 313 if (!strcmp(sg->name, name)) 319 if (!strcmp(sg->name, name)) { 314 320 return sg; 321 } 315 322 } 316 323 return NULL; … … 339 346 status++; 340 347 ptr = strchr(++user, ' '); 341 if (!ptr) 348 if (!ptr) { 342 349 return; 350 } 343 351 *ptr = '\0'; 344 352 ptr++; 345 353 if (!strncmp(ptr, "ONLINESTATUS ", 13)) { 346 if (!strlen(user) || !strcmp(user, sd->username)) 354 if (!strlen(user) || !strcmp(user, sd->username)) { 347 355 return; 356 } 348 357 if (!set_getbool(&ic->acc->set, "test_join") 349 && !strcmp(user, "echo123"))358 && !strcmp(user, "echo123")) { 350 359 return; 360 } 351 361 ptr = g_strdup_printf("%s@skype.com", user); 352 362 imcb_add_buddy(ic, ptr, skype_group_by_username(ic, user)); 353 363 if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || 354 !set_getbool(&ic->acc->set, "skypeout_offline")))364 !set_getbool(&ic->acc->set, "skypeout_offline"))) { 355 365 flags |= OPT_LOGGED_IN; 356 if (strcmp(status, "ONLINE") && strcmp(status, "SKYPEME")) 366 } 367 if (strcmp(status, "ONLINE") && strcmp(status, "SKYPEME")) { 357 368 flags |= OPT_AWAY; 369 } 358 370 imcb_buddy_status(ic, ptr, flags, NULL, NULL); 359 371 g_free(ptr); 360 372 } else if (!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) { 361 373 char *message = ptr + 20; 362 if (strlen(message)) 374 if (strlen(message)) { 363 375 skype_buddy_ask(ic, user, message); 376 } 364 377 } else if (!strncmp(ptr, "BUDDYSTATUS ", 12)) { 365 378 char *st = ptr + 12; … … 374 387 g_free(buf); 375 388 buf = ptr + 10; 376 if (bu) 389 if (bu) { 377 390 imcb_buddy_status(ic, bu->handle, bu->flags, NULL, 378 *buf ? buf : NULL); 379 if (set_getbool(&ic->acc->set, "show_moods")) 391 *buf ? buf : NULL); 392 } 393 if (set_getbool(&ic->acc->set, "show_moods")) { 380 394 imcb_log(ic, "User `%s' changed mood text to `%s'", user, buf); 395 } 381 396 } else if (!strncmp(ptr, "FULLNAME ", 9)) { 382 397 char *name = ptr + 9; … … 389 404 g_free(buf); 390 405 } 391 } else if (!strncmp(ptr, "PHONE_HOME ", 11)) 406 } else if (!strncmp(ptr, "PHONE_HOME ", 11)) { 392 407 sd->info_phonehome = g_strdup(ptr + 11); 393 else if (!strncmp(ptr, "PHONE_OFFICE ", 13))408 } else if (!strncmp(ptr, "PHONE_OFFICE ", 13)) { 394 409 sd->info_phoneoffice = g_strdup(ptr + 13); 395 else if (!strncmp(ptr, "PHONE_MOBILE ", 13))410 } else if (!strncmp(ptr, "PHONE_MOBILE ", 13)) { 396 411 sd->info_phonemobile = g_strdup(ptr + 13); 397 else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20))412 } else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20)) { 398 413 sd->info_nrbuddies = g_strdup(ptr + 20); 399 else if (!strncmp(ptr, "TIMEZONE ", 9))414 } else if (!strncmp(ptr, "TIMEZONE ", 9)) { 400 415 sd->info_tz = g_strdup(ptr + 9); 401 else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20))416 } else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20)) { 402 417 sd->info_seen = g_strdup(ptr + 20); 403 else if (!strncmp(ptr, "SEX ", 4))418 } else if (!strncmp(ptr, "SEX ", 4)) { 404 419 sd->info_sex = g_strdup(ptr + 4); 405 else if (!strncmp(ptr, "LANGUAGE ", 9))420 } else if (!strncmp(ptr, "LANGUAGE ", 9)) { 406 421 sd->info_language = g_strdup(ptr + 9); 407 else if (!strncmp(ptr, "COUNTRY ", 8))422 } else if (!strncmp(ptr, "COUNTRY ", 8)) { 408 423 sd->info_country = g_strdup(ptr + 8); 409 else if (!strncmp(ptr, "PROVINCE ", 9))424 } else if (!strncmp(ptr, "PROVINCE ", 9)) { 410 425 sd->info_province = g_strdup(ptr + 9); 411 else if (!strncmp(ptr, "CITY ", 5))426 } else if (!strncmp(ptr, "CITY ", 5)) { 412 427 sd->info_city = g_strdup(ptr + 5); 413 else if (!strncmp(ptr, "HOMEPAGE ", 9))428 } else if (!strncmp(ptr, "HOMEPAGE ", 9)) { 414 429 sd->info_homepage = g_strdup(ptr + 9); 415 else if (!strncmp(ptr, "ABOUT ", 6)) {430 } else if (!strncmp(ptr, "ABOUT ", 6)) { 416 431 /* Support multiple about lines. */ 417 if (!sd->info_about) 432 if (!sd->info_about) { 418 433 sd->info_about = g_strdup(ptr + 6); 419 else {434 } else { 420 435 GString *st = g_string_new(sd->info_about); 421 436 g_string_append_printf(st, "\n%s", ptr + 6); … … 430 445 g_string_append_printf(st, "Skype Name: %s\n", user); 431 446 if (sd->info_fullname) { 432 if (strlen(sd->info_fullname)) 447 if (strlen(sd->info_fullname)) { 433 448 g_string_append_printf(st, "Full Name: %s\n", 434 sd->info_fullname); 449 sd->info_fullname); 450 } 435 451 g_free(sd->info_fullname); 436 452 sd->info_fullname = NULL; 437 453 } 438 454 if (sd->info_phonehome) { 439 if (strlen(sd->info_phonehome)) 455 if (strlen(sd->info_phonehome)) { 440 456 g_string_append_printf(st, "Home Phone: %s\n", 441 sd->info_phonehome); 457 sd->info_phonehome); 458 } 442 459 g_free(sd->info_phonehome); 443 460 sd->info_phonehome = NULL; 444 461 } 445 462 if (sd->info_phoneoffice) { 446 if (strlen(sd->info_phoneoffice)) 463 if (strlen(sd->info_phoneoffice)) { 447 464 g_string_append_printf(st, "Office Phone: %s\n", 448 sd->info_phoneoffice); 465 sd->info_phoneoffice); 466 } 449 467 g_free(sd->info_phoneoffice); 450 468 sd->info_phoneoffice = NULL; 451 469 } 452 470 if (sd->info_phonemobile) { 453 if (strlen(sd->info_phonemobile)) 471 if (strlen(sd->info_phonemobile)) { 454 472 g_string_append_printf(st, "Mobile Phone: %s\n", 455 sd->info_phonemobile); 473 sd->info_phonemobile); 474 } 456 475 g_free(sd->info_phonemobile); 457 476 sd->info_phonemobile = NULL; … … 459 478 g_string_append_printf(st, "Personal Information\n"); 460 479 if (sd->info_nrbuddies) { 461 if (strlen(sd->info_nrbuddies)) 480 if (strlen(sd->info_nrbuddies)) { 462 481 g_string_append_printf(st, 463 "Contacts: %s\n", sd->info_nrbuddies); 482 "Contacts: %s\n", sd->info_nrbuddies); 483 } 464 484 g_free(sd->info_nrbuddies); 465 485 sd->info_nrbuddies = NULL; … … 469 489 char ib[256]; 470 490 time_t t = time(NULL); 471 t += atoi(sd->info_tz) -(60*60*24);491 t += atoi(sd->info_tz) - (60 * 60 * 24); 472 492 struct tm *gt = gmtime(&t); 473 493 strftime(ib, 256, "%H:%M:%S", gt); 474 494 g_string_append_printf(st, 475 495 "Local Time: %s\n", ib); 476 496 } 477 497 g_free(sd->info_tz); … … 485 505 strftime(ib, 256, ("%Y. %m. %d. %H:%M"), tm); 486 506 g_string_append_printf(st, 487 507 "Last Seen: %s\n", ib); 488 508 } 489 509 g_free(sd->info_seen); … … 492 512 if (sd->info_birthday) { 493 513 if (strlen(sd->info_birthday) && 494 514 strcmp(sd->info_birthday, "0")) { 495 515 char ib[256]; 496 516 struct tm tm; … … 498 518 strftime(ib, 256, "%B %d, %Y", &tm); 499 519 g_string_append_printf(st, 500 520 "Birthday: %s\n", ib); 501 521 502 522 strftime(ib, 256, "%Y", &tm); … … 505 525 struct tm *lt = localtime(&t); 506 526 g_string_append_printf(st, 507 "Age: %d\n", lt->tm_year+1900-year);527 "Age: %d\n", lt->tm_year + 1900 - year); 508 528 } 509 529 g_free(sd->info_birthday); … … 513 533 if (strlen(sd->info_sex)) { 514 534 char *iptr = sd->info_sex; 515 while (*iptr++) 535 while (*iptr++) { 516 536 *iptr = g_ascii_tolower(*iptr); 537 } 517 538 g_string_append_printf(st, 518 539 "Gender: %s\n", sd->info_sex); 519 540 } 520 541 g_free(sd->info_sex); … … 524 545 if (strlen(sd->info_language)) { 525 546 char *iptr = strchr(sd->info_language, ' '); 526 if (iptr) 547 if (iptr) { 527 548 iptr++; 528 else549 } else { 529 550 iptr = sd->info_language; 551 } 530 552 g_string_append_printf(st, 531 553 "Language: %s\n", iptr); 532 554 } 533 555 g_free(sd->info_language); … … 537 559 if (strlen(sd->info_country)) { 538 560 char *iptr = strchr(sd->info_country, ' '); 539 if (iptr) 561 if (iptr) { 540 562 iptr++; 541 else563 } else { 542 564 iptr = sd->info_country; 565 } 543 566 g_string_append_printf(st, 544 567 "Country: %s\n", iptr); 545 568 } 546 569 g_free(sd->info_country); … … 548 571 } 549 572 if (sd->info_province) { 550 if (strlen(sd->info_province)) 573 if (strlen(sd->info_province)) { 551 574 g_string_append_printf(st, 552 "Region: %s\n", sd->info_province); 575 "Region: %s\n", sd->info_province); 576 } 553 577 g_free(sd->info_province); 554 578 sd->info_province = NULL; 555 579 } 556 580 if (sd->info_city) { 557 if (strlen(sd->info_city)) 581 if (strlen(sd->info_city)) { 558 582 g_string_append_printf(st, 559 "City: %s\n", sd->info_city); 583 "City: %s\n", sd->info_city); 584 } 560 585 g_free(sd->info_city); 561 586 sd->info_city = NULL; 562 587 } 563 588 if (sd->info_homepage) { 564 if (strlen(sd->info_homepage)) 589 if (strlen(sd->info_homepage)) { 565 590 g_string_append_printf(st, 566 "Homepage: %s\n", sd->info_homepage); 591 "Homepage: %s\n", sd->info_homepage); 592 } 567 593 g_free(sd->info_homepage); 568 594 sd->info_homepage = NULL; 569 595 } 570 596 if (sd->info_about) { 571 if (strlen(sd->info_about)) 597 if (strlen(sd->info_about)) { 572 598 g_string_append_printf(st, "%s\n", 573 sd->info_about); 599 sd->info_about); 600 } 574 601 g_free(sd->info_about); 575 602 sd->info_about = NULL; … … 584 611 struct skype_data *sd = ic->proto_data; 585 612 char buf[IRC_LINE_SIZE]; 613 586 614 if (!strcmp(sd->type, "SAID")) { 587 if (!sd->is_edit) 615 if (!sd->is_edit) { 588 616 g_snprintf(buf, IRC_LINE_SIZE, "%s", body); 589 else {617 } else { 590 618 g_snprintf(buf, IRC_LINE_SIZE, "%s %s", set_getstr(&ic->acc->set, "edit_prefix"), body); 591 619 sd->is_edit = 0; 592 620 } 593 } else 621 } else { 594 622 g_snprintf(buf, IRC_LINE_SIZE, "/me %s", body); 595 if (!gc) 623 } 624 if (!gc) { 596 625 /* Private message */ 597 626 imcb_buddy_msg(ic, sd->handle, buf, 0, 0); 598 else627 } else { 599 628 /* Groupchat message */ 600 629 imcb_chat_msg(gc, sd->handle, buf, 0, 0); 630 } 601 631 } 602 632 … … 606 636 char *id = strchr(line, ' '); 607 637 608 if (!++id) 638 if (!++id) { 609 639 return; 640 } 610 641 char *info = strchr(id, ' '); 611 642 612 if (!info) 643 if (!info) { 613 644 return; 645 } 614 646 *info = '\0'; 615 647 info++; … … 622 654 */ 623 655 skype_printf(ic, "GET CHATMESSAGE %s FROM_HANDLE\n", id); 624 if (!strcmp(info, "STATUS RECEIVED")) 656 if (!strcmp(info, "STATUS RECEIVED")) { 625 657 skype_printf(ic, "GET CHATMESSAGE %s BODY\n", id); 626 else658 } else { 627 659 sd->is_edit = 1; 660 } 628 661 skype_printf(ic, "GET CHATMESSAGE %s TYPE\n", id); 629 662 skype_printf(ic, "GET CHATMESSAGE %s CHATNAME\n", id); … … 648 681 info += 5; 649 682 sd->body = g_list_append(sd->body, g_strdup(info)); 650 } 683 } else if (!strncmp(info, "TYPE ", 5)) { 651 684 info += 5; 652 685 g_free(sd->type); … … 660 693 char *body = g_list_nth_data(sd->body, i); 661 694 if (!strcmp(sd->type, "SAID") || 662 695 !strcmp(sd->type, "EMOTED")) { 663 696 skype_parse_chatmessage_said_emoted(ic, gc, body); 664 } else if (!strcmp(sd->type, "SETTOPIC") && gc) 697 } else if (!strcmp(sd->type, "SETTOPIC") && gc) { 665 698 imcb_chat_topic(gc, 666 667 else if (!strcmp(sd->type, "LEFT") && gc)699 sd->handle, body, 0); 700 } else if (!strcmp(sd->type, "LEFT") && gc) { 668 701 imcb_chat_remove_buddy(gc, 669 sd->handle, NULL); 702 sd->handle, NULL); 703 } 670 704 } 671 705 g_list_free(sd->body); … … 681 715 char buf[IRC_LINE_SIZE]; 682 716 683 if (!++id) 717 if (!++id) { 684 718 return; 719 } 685 720 char *info = strchr(id, ' '); 686 721 687 if (!info) 722 if (!info) { 688 723 return; 724 } 689 725 *info = '\0'; 690 726 info++; 691 if (!strncmp(info, "FAILUREREASON ", 14)) 727 if (!strncmp(info, "FAILUREREASON ", 14)) { 692 728 sd->failurereason = atoi(strchr(info, ' ')); 693 else if (!strcmp(info, "STATUS RINGING")) {694 if (sd->call_id) 729 } else if (!strcmp(info, "STATUS RINGING")) { 730 if (sd->call_id) { 695 731 g_free(sd->call_id); 732 } 696 733 sd->call_id = g_strdup(id); 697 734 skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); … … 710 747 sd->call_status = SKYPE_CALL_REFUSED; 711 748 } else if (!strcmp(info, "STATUS UNPLACED")) { 712 if (sd->call_id) 749 if (sd->call_id) { 713 750 g_free(sd->call_id); 751 } 714 752 /* Save the ID for later usage (Cancel/Finish). */ 715 753 sd->call_id = g_strdup(id); … … 717 755 } else if (!strcmp(info, "STATUS FAILED")) { 718 756 imcb_error(ic, "Call failed: %s", 719 757 skype_call_strerror(sd->failurereason)); 720 758 sd->call_id = NULL; 721 759 } else if (!strncmp(info, "DURATION ", 9)) { 722 if (sd->call_duration) 760 if (sd->call_duration) { 723 761 g_free(sd->call_duration); 724 sd->call_duration = g_strdup(info+9); 762 } 763 sd->call_duration = g_strdup(info + 9); 725 764 } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { 726 765 info += 15; 727 if (!sd->call_status) 766 if (!sd->call_status) { 728 767 return; 768 } 729 769 switch (sd->call_status) { 730 770 case SKYPE_CALL_RINGING: 731 if (sd->call_out) 771 if (sd->call_out) { 732 772 imcb_log(ic, "You are currently ringing the user %s.", info); 733 else {773 } else { 734 774 g_snprintf(buf, IRC_LINE_SIZE, 735 736 775 "The user %s is currently ringing you.", 776 info); 737 777 skype_call_ask(ic, sd->call_id, buf); 738 778 } … … 740 780 case SKYPE_CALL_MISSED: 741 781 imcb_log(ic, "You have missed a call from user %s.", 742 782 info); 743 783 break; 744 784 case SKYPE_CALL_CANCELLED: 745 785 imcb_log(ic, "You cancelled the call to the user %s.", 746 786 info); 747 787 sd->call_status = 0; 748 788 sd->call_out = FALSE; 749 789 break; 750 790 case SKYPE_CALL_REFUSED: 751 if (sd->call_out) 791 if (sd->call_out) { 752 792 imcb_log(ic, "The user %s refused the call.", 753 754 else793 info); 794 } else { 755 795 imcb_log(ic, 756 "You refused the call from user %s.", 757 info); 796 "You refused the call from user %s.", 797 info); 798 } 758 799 sd->call_out = FALSE; 759 800 break; 760 801 case SKYPE_CALL_FINISHED: 761 if (sd->call_duration) 802 if (sd->call_duration) { 762 803 imcb_log(ic, 763 764 765 766 else804 "You finished the call to the user %s " 805 "(duration: %s seconds).", 806 info, sd->call_duration); 807 } else { 767 808 imcb_log(ic, 768 "You finished the call to the user %s.", 769 info); 809 "You finished the call to the user %s.", 810 info); 811 } 770 812 sd->call_out = FALSE; 771 813 break; … … 783 825 char *id = strchr(line, ' '); 784 826 785 if (!++id) 827 if (!++id) { 786 828 return; 829 } 787 830 char *info = strchr(id, ' '); 788 831 789 if (!info) 832 if (!info) { 790 833 return; 834 } 791 835 *info = '\0'; 792 836 info++; 793 837 if (!strcmp(info, "STATUS NEW")) { 794 838 skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", 795 839 id); 796 840 sd->filetransfer_status = SKYPE_FILETRANSFER_NEW; 797 841 } else if (!strcmp(info, "STATUS FAILED")) { 798 842 skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", 799 843 id); 800 844 sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED; 801 845 } else if (!strcmp(info, "STATUS COMPLETED")) { … … 810 854 } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { 811 855 info += 15; 812 if (!sd->filetransfer_status) 856 if (!sd->filetransfer_status) { 813 857 return; 858 } 814 859 switch (sd->filetransfer_status) { 815 860 case SKYPE_FILETRANSFER_NEW: 816 861 imcb_log(ic, "The user %s offered a new file for you.", 817 862 info); 818 863 break; 819 864 case SKYPE_FILETRANSFER_FAILED: 820 865 imcb_log(ic, "Failed to transfer file from user %s.", 821 866 info); 822 867 break; 823 868 case SKYPE_FILETRANSFER_COMPLETED: … … 826 871 case SKYPE_FILETRANSFER_TRANSFERRING: 827 872 if (sd->filetransfer_path) { 828 imcb_log(ic, "File transfer from user %s started, saving to %s.", info, sd->filetransfer_path); 873 imcb_log(ic, "File transfer from user %s started, saving to %s.", info, 874 sd->filetransfer_path); 829 875 g_free(sd->filetransfer_path); 830 876 sd->filetransfer_path = NULL; … … 842 888 843 889 for (i = 0; i < g_list_length(sd->groups); i++) { 844 struct skype_group *sg = (struct skype_group *) g_list_nth_data(sd->groups, i);845 846 if (sg->id == id) 890 struct skype_group *sg = (struct skype_group *) g_list_nth_data(sd->groups, i); 891 892 if (sg->id == id) { 847 893 return sg; 894 } 848 895 } 849 896 return NULL; … … 859 906 } 860 907 sg->users = NULL; 861 if (usersonly) 908 if (usersonly) { 862 909 return; 910 } 863 911 g_free(sg->name); 864 912 g_free(sg); … … 883 931 char *id = strchr(line, ' '); 884 932 885 if (!++id) 933 if (!++id) { 886 934 return; 935 } 887 936 888 937 char *info = strchr(id, ' '); 889 938 890 if (!info) 939 if (!info) { 891 940 return; 941 } 892 942 *info = '\0'; 893 943 info++; … … 923 973 g_strfreev(users); 924 974 skype_group_users(ic, sg); 925 } else 975 } else { 926 976 log_message(LOGLVL_ERROR, 927 "No skype group with id %s. That's probably a bug.", id); 977 "No skype group with id %s. That's probably a bug.", id); 978 } 928 979 } else if (!strncmp(info, "NROFUSERS ", 10)) { 929 980 if (!sd->pending_user) { … … 942 993 g_free(sd->pending_user); 943 994 sd->pending_user = NULL; 944 } else 995 } else { 945 996 log_message(LOGLVL_ERROR, 946 "No skype group with id %s. That's probably a bug.", id); 947 } else if (!strcmp(info, "TYPE CUSTOM_GROUP")) 997 "No skype group with id %s. That's probably a bug.", id); 998 } 999 } else if (!strcmp(info, "TYPE CUSTOM_GROUP")) { 948 1000 /* This one is interesting, query its users. */ 949 1001 skype_printf(ic, "GET GROUP %s USERS\n", id); 1002 } 950 1003 } 951 1004 … … 956 1009 char *id = strchr(line, ' '); 957 1010 958 if (!++id) 1011 if (!++id) { 959 1012 return; 1013 } 960 1014 struct groupchat *gc; 961 1015 char *info = strchr(id, ' '); 962 1016 963 if (!info) 1017 if (!info) { 964 1018 return; 1019 } 965 1020 *info = '\0'; 966 1021 info++; 967 1022 /* Remove fake chat if we created one in skype_chat_with() */ 968 1023 gc = bee_chat_by_title(ic->bee, ic, ""); 969 if (gc) 1024 if (gc) { 970 1025 imcb_chat_free(gc); 1026 } 971 1027 if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) { 972 1028 gc = bee_chat_by_title(ic->bee, ic, id); … … 988 1044 /*skype_printf(ic, "OPEN CHAT %s\n", id);*/ 989 1045 g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", 990 1046 sd->groupchat_with); 991 1047 imcb_chat_add_buddy(gc, buf); 992 1048 imcb_chat_add_buddy(gc, sd->username); … … 997 1053 } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) { 998 1054 gc = bee_chat_by_title(ic->bee, ic, id); 999 if (gc) 1000 gc->data = (void *)FALSE; 1055 if (gc) { 1056 gc->data = (void *) FALSE; 1057 } 1001 1058 } else if (!strncmp(info, "ADDER ", 6)) { 1002 1059 info += 6; … … 1015 1072 sd->adder = NULL; 1016 1073 } 1017 } else if (!strncmp(info, "MEMBERS ", 8) || !strncmp(info, "ACTIVEMEMBERS ", 14) 1018 if (!strncmp(info, "MEMBERS ", 8)) 1074 } else if (!strncmp(info, "MEMBERS ", 8) || !strncmp(info, "ACTIVEMEMBERS ", 14)) { 1075 if (!strncmp(info, "MEMBERS ", 8)) { 1019 1076 info += 8; 1020 else1077 } else { 1021 1078 info += 14; 1079 } 1022 1080 gc = bee_chat_by_title(ic->bee, ic, id); 1023 1081 /* Hack! We set ->data to TRUE … … 1025 1083 * so that we won't rejoin 1026 1084 * after a /part. */ 1027 if (!gc || gc->data) 1085 if (!gc || gc->data) { 1028 1086 return; 1087 } 1029 1088 char **members = g_strsplit(info, " ", 0); 1030 1089 int i; 1031 1090 for (i = 0; members[i]; i++) { 1032 if (!strcmp(members[i], sd->username)) 1091 if (!strcmp(members[i], sd->username)) { 1033 1092 continue; 1093 } 1034 1094 g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", 1035 1095 members[i]); 1036 1096 if (!g_list_find_custom(gc->in_room, buf, 1037 (GCompareFunc)strcmp))1097 (GCompareFunc) strcmp)) { 1038 1098 imcb_chat_add_buddy(gc, buf); 1099 } 1039 1100 } 1040 1101 imcb_chat_add_buddy(gc, sd->username); … … 1045 1106 static void skype_parse_password(struct im_connection *ic, char *line) 1046 1107 { 1047 if (!strncmp(line +9, "OK", 2))1108 if (!strncmp(line + 9, "OK", 2)) { 1048 1109 imcb_connected(ic); 1049 else {1110 } else { 1050 1111 imcb_error(ic, "Authentication Failed"); 1051 1112 imc_logout(ic, TRUE); … … 1055 1116 static void skype_parse_profile(struct im_connection *ic, char *line) 1056 1117 { 1057 imcb_log(ic, "SkypeOut balance value is '%s'.", line +21);1118 imcb_log(ic, "SkypeOut balance value is '%s'.", line + 21); 1058 1119 } 1059 1120 … … 1081 1142 static void skype_parse_groups(struct im_connection *ic, char *line) 1082 1143 { 1083 if (!set_getbool(&ic->acc->set, "read_groups")) 1144 if (!set_getbool(&ic->acc->set, "read_groups")) { 1084 1145 return; 1146 } 1085 1147 1086 1148 char **i; … … 1100 1162 char *id = line + strlen("ALTER GROUP"); 1101 1163 1102 if (!++id) 1164 if (!++id) { 1103 1165 return; 1166 } 1104 1167 1105 1168 char *info = strchr(id, ' '); 1106 1169 1107 if (!info) 1170 if (!info) { 1108 1171 return; 1172 } 1109 1173 *info = '\0'; 1110 1174 info++; … … 1119 1183 imcb_add_buddy(ic, buf, sg->name); 1120 1184 g_free(buf); 1121 } else 1185 } else { 1122 1186 log_message(LOGLVL_ERROR, 1123 "No skype group with id %s. That's probably a bug.", id); 1187 "No skype group with id %s. That's probably a bug.", id); 1188 } 1124 1189 } 1125 1190 } … … 1128 1193 1129 1194 static gboolean skype_read_callback(gpointer data, gint fd, 1130 1195 b_input_condition cond) 1131 1196 { 1132 1197 struct im_connection *ic = data; … … 1158 1223 cond = cond; 1159 1224 1160 if (!sd || sd->fd == -1) 1225 if (!sd || sd->fd == -1) { 1161 1226 return FALSE; 1227 } 1162 1228 /* Read the whole data. */ 1163 1229 st = ssl_read(sd->ssl, buf, sizeof(buf)); 1164 if (st >= IRC_LINE_SIZE -1) {1230 if (st >= IRC_LINE_SIZE - 1) { 1165 1231 /* As we don't buffer incoming data, if IRC_LINE_SIZE amount of bytes 1166 1232 * were received, there's a good chance last message was truncated … … 1175 1241 lineptr = lines; 1176 1242 while ((line = *lineptr)) { 1177 if (!strlen(line)) 1243 if (!strlen(line)) { 1178 1244 break; 1179 if (set_getbool(&ic->acc->set, "skypeconsole_receive")) 1245 } 1246 if (set_getbool(&ic->acc->set, "skypeconsole_receive")) { 1180 1247 imcb_buddy_msg(ic, "skypeconsole", line, 0, 0); 1181 for (i = 0; i < ARRAY_SIZE(parsers); i++) 1248 } 1249 for (i = 0; i < ARRAY_SIZE(parsers); i++) { 1182 1250 if (!strncmp(line, parsers[i].k, 1183 1251 strlen(parsers[i].k))) { 1184 1252 parsers[i].v(ic, line); 1185 1253 break; 1186 1254 } 1255 } 1187 1256 lineptr++; 1188 1257 } … … 1205 1274 int st; 1206 1275 1207 if (!sd) 1276 if (!sd) { 1208 1277 return FALSE; 1209 1210 if (sd->bfd <= 0) 1278 } 1279 1280 if (sd->bfd <= 0) { 1211 1281 sd->bfd = b_input_add(sd->fd, B_EV_IO_READ, 1212 skype_read_callback, ic); 1282 skype_read_callback, ic); 1283 } 1213 1284 1214 1285 /* Log in */ … … 1260 1331 imcb_log(ic, "Connecting"); 1261 1332 sd->ssl = ssl_connect(set_getstr(&acc->set, "server"), 1262 1333 set_getint(&acc->set, "port"), FALSE, skype_connected, ic); 1263 1334 sd->fd = sd->ssl ? ssl_getfd(sd->ssl) : -1; 1264 1335 sd->username = g_strdup(acc->user); … … 1266 1337 sd->ic = ic; 1267 1338 1268 if (set_getbool(&acc->set, "skypeconsole")) 1339 if (set_getbool(&acc->set, "skypeconsole")) { 1269 1340 imcb_add_buddy(ic, "skypeconsole", NULL); 1341 } 1270 1342 } 1271 1343 … … 1277 1349 skype_printf(ic, "SET USERSTATUS OFFLINE\n"); 1278 1350 1279 while (ic->groupchats) 1351 while (ic->groupchats) { 1280 1352 imcb_chat_free(ic->groupchats->data); 1353 } 1281 1354 1282 1355 for (i = 0; i < g_list_length(sd->groups); i++) { 1283 struct skype_group *sg = (struct skype_group *) g_list_nth_data(sd->groups, i);1356 struct skype_group *sg = (struct skype_group *) g_list_nth_data(sd->groups, i); 1284 1357 skype_group_free(sg, FALSE); 1285 1358 } 1286 1359 1287 if (sd->ssl) 1360 if (sd->ssl) { 1288 1361 ssl_disconnect(sd->ssl); 1362 } 1289 1363 1290 1364 g_free(sd->username); … … 1295 1369 1296 1370 static int skype_buddy_msg(struct im_connection *ic, char *who, char *message, 1297 1371 int flags) 1298 1372 { 1299 1373 char *ptr, *nick; … … 1305 1379 nick = g_strdup(who); 1306 1380 ptr = strchr(nick, '@'); 1307 if (ptr) 1381 if (ptr) { 1308 1382 *ptr = '\0'; 1309 1310 if (!strncmp(who, "skypeconsole", 12)) 1383 } 1384 1385 if (!strncmp(who, "skypeconsole", 12)) { 1311 1386 st = skype_printf(ic, "%s\n", message); 1312 else1387 } else { 1313 1388 st = skype_printf(ic, "MESSAGE %s %s\n", nick, message); 1389 } 1314 1390 g_free(nick); 1315 1391 … … 1321 1397 int i; 1322 1398 1323 for (i = 0; skype_away_state_list[i].full_name; i++) 1324 if (g_strcasecmp(skype_away_state_list[i].full_name, name) == 0) 1399 for (i = 0; skype_away_state_list[i].full_name; i++) { 1400 if (g_strcasecmp(skype_away_state_list[i].full_name, name) == 0) { 1325 1401 return skype_away_state_list + i; 1402 } 1403 } 1326 1404 1327 1405 return NULL; … … 1329 1407 1330 1408 static void skype_set_away(struct im_connection *ic, char *state_txt, 1331 1409 char *message) 1332 1410 { 1333 1411 const struct skype_away_state *state; … … 1336 1414 message = message; 1337 1415 1338 if (state_txt == NULL) 1416 if (state_txt == NULL) { 1339 1417 state = skype_away_state_by_name("Online"); 1340 else1418 } else { 1341 1419 state = skype_away_state_by_name(state_txt); 1420 } 1342 1421 skype_printf(ic, "SET USERSTATUS %s\n", state->code); 1343 1422 } … … 1351 1430 ic = ic; 1352 1431 1353 if (l == NULL) 1354 for (i = 0; skype_away_state_list[i].full_name; i++) 1432 if (l == NULL) { 1433 for (i = 0; skype_away_state_list[i].full_name; i++) { 1355 1434 l = g_list_append(l, 1356 (void *)skype_away_state_list[i].full_name); 1435 (void *) skype_away_state_list[i].full_name); 1436 } 1437 } 1357 1438 1358 1439 return l; … … 1391 1472 char *ptr = strchr(nick, '@'); 1392 1473 1393 if (ptr) 1474 if (ptr) { 1394 1475 *ptr = '\0'; 1476 } 1395 1477 skype_printf(ic, "CALL %s\n", nick); 1396 1478 g_free(nick); … … 1403 1485 if (sd->call_id) { 1404 1486 skype_printf(ic, "SET CALL %s STATUS FINISHED\n", 1405 1487 sd->call_id); 1406 1488 g_free(sd->call_id); 1407 1489 sd->call_id = 0; 1408 } else 1490 } else { 1409 1491 imcb_error(ic, "There are no active calls currently."); 1492 } 1410 1493 } 1411 1494 … … 1415 1498 struct im_connection *ic = acc->ic; 1416 1499 1417 if (value) 1500 if (value) { 1418 1501 skype_call(ic, value); 1419 else1502 } else { 1420 1503 skype_hangup(ic); 1504 } 1421 1505 return value; 1422 1506 } … … 1429 1513 nick = g_strdup(who); 1430 1514 ptr = strchr(nick, '@'); 1431 if (ptr) 1515 if (ptr) { 1432 1516 *ptr = '\0'; 1517 } 1433 1518 1434 1519 if (!group) { 1435 1520 skype_printf(ic, "SET USER %s BUDDYSTATUS 2 Please authorize me\n", 1436 1521 nick); 1437 1522 g_free(nick); 1438 1523 } else { … … 1459 1544 nick = g_strdup(who); 1460 1545 ptr = strchr(nick, '@'); 1461 if (ptr) 1546 if (ptr) { 1462 1547 *ptr = '\0'; 1548 } 1463 1549 skype_printf(ic, "SET USER %s BUDDYSTATUS 1\n", nick); 1464 1550 g_free(nick); … … 1478 1564 { 1479 1565 struct im_connection *ic = gc->ic; 1566 1480 1567 skype_printf(ic, "ALTER CHAT %s LEAVE\n", gc->title); 1481 gc->data = (void *) TRUE;1568 gc->data = (void *) TRUE; 1482 1569 } 1483 1570 … … 1489 1576 nick = g_strdup(who); 1490 1577 ptr = strchr(nick, '@'); 1491 if (ptr) 1578 if (ptr) { 1492 1579 *ptr = '\0'; 1580 } 1493 1581 skype_printf(ic, "ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick); 1494 1582 g_free(nick); … … 1499 1587 struct im_connection *ic = gc->ic; 1500 1588 struct skype_data *sd = ic->proto_data; 1589 1501 1590 skype_printf(ic, "ALTER CHAT %s SETTOPIC %s\n", 1502 1591 gc->title, message); 1503 1592 sd->topic_wait = 1; 1504 1593 } … … 1508 1597 struct skype_data *sd = ic->proto_data; 1509 1598 char *ptr, *nick; 1599 1510 1600 nick = g_strdup(who); 1511 1601 ptr = strchr(nick, '@'); 1512 if (ptr) 1602 if (ptr) { 1513 1603 *ptr = '\0'; 1604 } 1514 1605 skype_printf(ic, "CHAT CREATE %s\n", nick); 1515 1606 sd->groupchat_with = g_strdup(nick); … … 1524 1615 struct skype_data *sd = ic->proto_data; 1525 1616 char *ptr, *nick; 1617 1526 1618 nick = g_strdup(who); 1527 1619 ptr = strchr(nick, '@'); 1528 if (ptr) 1620 if (ptr) { 1529 1621 *ptr = '\0'; 1622 } 1530 1623 sd->is_info = TRUE; 1531 1624 skype_printf(ic, "GET USER %s FULLNAME\n", nick); … … 1556 1649 1557 1650 s = set_add(&acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, 1558 1651 acc); 1559 1652 s->flags |= ACC_SET_OFFLINE_ONLY; 1560 1653 … … 1563 1656 1564 1657 s = set_add(&acc->set, "display_name", NULL, skype_set_display_name, 1565 1658 acc); 1566 1659 s->flags |= SET_NOSAVE | ACC_SET_ONLINE_ONLY; 1567 1660 … … 1581 1674 1582 1675 s = set_add(&acc->set, "skypeconsole_receive", "false", set_eval_bool, 1583 1676 acc); 1584 1677 s->flags |= ACC_SET_OFFLINE_ONLY; 1585 1678 … … 1593 1686 1594 1687 s = set_add(&acc->set, "edit_prefix", "EDIT:", 1595 1688 NULL, acc); 1596 1689 1597 1690 s = set_add(&acc->set, "read_groups", "false", set_eval_bool, acc); … … 1608 1701 if (ret == NULL) { 1609 1702 static const struct buddy_action ba[2] = { 1610 { "CALL", "Initiate a call" },1611 { "HANGUP", "Hang up a call" },1703 { "CALL", "Initiate a call" }, 1704 { "HANGUP", "Hang up a call" }, 1612 1705 }; 1613 1706 int i; 1614 1707 1615 for (i = 0; i < ARRAY_SIZE(ba); i++) 1616 ret = g_list_prepend(ret, (void *)(ba + i)); 1708 for (i = 0; i < ARRAY_SIZE(ba); i++) { 1709 ret = g_list_prepend(ret, (void *) (ba + i)); 1710 } 1617 1711 } 1618 1712 … … 1626 1720 data = data; 1627 1721 1628 if (!g_strcasecmp(action, "CALL")) 1722 if (!g_strcasecmp(action, "CALL")) { 1629 1723 skype_call(bu->ic, bu->handle); 1630 else if (!g_strcasecmp(action, "HANGUP"))1724 } else if (!g_strcasecmp(action, "HANGUP")) { 1631 1725 skype_hangup(bu->ic); 1726 } 1632 1727 1633 1728 return NULL;
Note: See TracChangeset
for help on using the changeset viewer.