forked from EionRobb/skype4pidgin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libskype.c
3599 lines (3114 loc) · 106 KB
/
libskype.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Skype plugin for libpurple/Pidgin/Adium
* Written by: Eion Robb <[email protected]>
*
* This plugin uses the Skype API to show your contacts in libpurple, and send/receive
* chat messages.
* It requires the Skype program to be running.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Skype API Terms of Use:
* The following statement must be displayed in the documentation of this appliction:
* This plugin "uses Skype Software" to display contacts, and chat to Skype users from within Pidgin
* "This product uses the Skype API but is not endorsed, certified or otherwise approved in any way by Skype"
*
* The use of this plugin requries your acceptance of the Skype EULA (http://www.skype.com/intl/en/company/legal/eula/index.html)
*
* Skype is the trademark of Skype Limited
*/
#define PURPLE_PLUGIN
#define DBUS_API_SUBJECT_TO_CHANGE
#define _GNU_SOURCE
#define GETTEXT_PACKAGE "skype4pidgin"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <glib.h>
#include <glib/gstdio.h>
#if __GNUC__
# include <unistd.h>
#endif
#include <string.h>
//#include <internal.h>
#undef ENABLE_NLS
#ifdef ENABLE_NLS
# ifdef _WIN32
# include <win32dep.h>
# endif
# include <glib/gi18n-lib.h>
#else
# define _(a) a
#endif
#ifndef G_GNUC_NULL_TERMINATED
# if __GNUC__ >= 4
# define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
# else
# define G_GNUC_NULL_TERMINATED
# endif /* __GNUC__ >= 4 */
#endif /* G_GNUC_NULL_TERMINATED */
#include <notify.h>
#include <core.h>
#include <plugin.h>
#include <version.h>
#include <accountopt.h>
#include <blist.h>
#include <request.h>
#include <cmds.h>
#include <status.h>
#ifndef INSTANTBIRD
#include <mediamanager.h>
gboolean skype_media_initiate(PurpleAccount *account, const char *who, PurpleMediaSessionType type);
PurpleMediaCaps skype_get_media_caps(PurpleAccount *account, const char *who);
static void skype_handle_incoming_call(PurpleConnection *gc, const char *callnumber_string);
static void skype_handle_call_got_ended(const char *callnumber_string);
static void skype_send_call_end(const char *callnumber_string);
static GHashTable *call_media_hash = NULL;
#endif
typedef struct _SkypeBuddy {
PurpleBuddy *buddy;
//this bit used in Get Info
gchar *handle;
gchar *fullname;
gchar *mood;
struct tm *birthday;
gchar *gender;
gchar *language;
gchar *country;
gboolean is_video_capable;
gboolean is_authorized;
gboolean is_blocked;
time_t last_online;
gdouble timezone_offset;
guint number_of_buddies;
gchar *about;
//this bit not used yet
gchar *province;
gchar *city;
gchar *phone_home;
gchar *phone_office;
gchar *phone_mobile;
gchar *homepage;
gboolean has_call_equipment;
gboolean is_voicemail_capable;
gboolean is_callforward_active;
gboolean can_leave_voicemail;
//libpurple buddy stuff
guint typing_stream;
//whether we've populated all fields from skype
gboolean is_skypebuddy_complete;
} SkypeBuddy;
typedef struct _SkypeChat {
PurpleAccount *account;
PurpleConversation *conv;
gint prpl_chat_id;
gchar *name;
gchar **members;
gchar *partner_handle;
PurpleConversationType type;
gchar *topic;
gchar *friendlyname;
int type_request_count; //count the number of times we request the chat type
} SkypeChat;
static GHashTable *chat_link_table = NULL;
static GStaticMutex chat_link_mutex = G_STATIC_MUTEX_INIT;
//This is used for incomming SMS status messages to be associated with a particular phone number
static GHashTable *sms_convo_link_table = NULL;
static guint protocol_version = 7;
#define INCLUDED_LIBSKYPE_C
#include "debug.c"
#include "skype_messaging.c"
static void plugin_init(PurplePlugin *plugin);
gboolean plugin_load(PurplePlugin *plugin);
gboolean plugin_unload(PurplePlugin *plugin);
GList *skype_status_types(PurpleAccount *acct);
void skype_login(PurpleAccount *acct);
void skype_close(PurpleConnection *gc);
int skype_send_im(PurpleConnection *gc, const gchar *who, const gchar *message, PurpleMessageFlags flags);
int skype_send_sms(PurpleConnection *gc, const gchar *who, const gchar *message, PurpleMessageFlags flags);
static void hide_skype();
void skype_get_info(PurpleConnection *gc, const gchar *username);
gchar *skype_get_user_info(const gchar *username, const gchar *property);
void skype_set_status(PurpleAccount *account, PurpleStatus *status);
void skype_set_idle(PurpleConnection *gc, int time);
void skype_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group);
void skype_add_buddy_with_invite(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group, const char *message);
void skype_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group);
void skype_add_deny(PurpleConnection *gc, const char *who);
void skype_rem_deny(PurpleConnection *gc, const char *who);
void skype_add_permit(PurpleConnection *gc, const char *who);
void skype_rem_permit(PurpleConnection *gc, const char *who);
void skype_keepalive(PurpleConnection *gc);
gboolean skype_set_buddies(PurpleAccount *acct);
void skype_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img);
GList *skype_actions(PurplePlugin *plugin, gpointer context);
void skype_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *userinfo, gboolean full);
char *skype_status_text(PurpleBuddy *buddy);
const char *skype_list_icon(PurpleAccount *account, PurpleBuddy *buddy);
const char *skype_normalize(const PurpleAccount *acct, const char *who);
void skype_update_buddy_alias(PurpleBuddy *buddy);
gboolean skype_update_buddy_status(PurpleBuddy *buddy);
void skype_get_account_alias(PurpleAccount *acct);
const char *skype_get_account_username(PurpleAccount *acct);
static PurpleAccount *skype_get_account(PurpleAccount *newaccount);
void skype_update_buddy_icon(PurpleBuddy *buddy);
static GList *skype_node_menu(PurpleBlistNode *node);
static void skype_silence(PurplePlugin *plugin, gpointer data);
void skype_slist_friend_check(gpointer buddy_pointer, gpointer friends_pointer);
int skype_slist_friend_search(gconstpointer buddy_pointer, gconstpointer buddyname_pointer);
static gboolean skype_check_missedmessages(PurpleAccount *account);
static int skype_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags);
static void skype_chat_leave(PurpleConnection *gc, int id);
static void skype_chat_invite(PurpleConnection *gc, int id, const char *msg, const char *who);
static void skype_initiate_chat(PurpleBlistNode *node, gpointer data);
static void skype_set_chat_topic(PurpleConnection *gc, int id, const char *topic);
gchar *skype_cb_real_name(PurpleConnection *gc, int id, const char *who);
GList *skype_join_chat_info(PurpleConnection *gc);
GHashTable *skype_join_chat_info_defaults(PurpleConnection *gc, const char *chat_name);
void skype_alias_buddy(PurpleConnection *gc, const char *who, const char *alias);
gboolean skype_offline_msg(const PurpleBuddy *buddy);
//void skype_slist_remove_messages(gpointer buddy_pointer, gpointer unused);
static void skype_plugin_update_check(void);
void skype_plugin_update_callback(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message);
gchar *timestamp_to_datetime(time_t timestamp);
void skype_show_search_users(PurplePluginAction *action);
static void skype_search_users(PurpleConnection *gc, const gchar *searchterm);
void skype_searchresults_add_buddy(PurpleConnection *gc, GList *row, void *user_data);
gchar *skype_strdup_withhtml(const gchar *src);
void skype_join_chat(PurpleConnection *, GHashTable *components);
gchar *skype_get_chat_name(GHashTable *components);
static void skype_display_skype_credit(PurplePluginAction *action);
unsigned int skype_send_typing(PurpleConnection *, const char *name, PurpleTypingState state);
static PurpleCmdRet skype_cmd_leave(PurpleConversation *, const gchar *, gchar **, gchar **, void *);
static PurpleCmdRet skype_cmd_topic(PurpleConversation *, const gchar *, gchar **, gchar **, void *);
static PurpleCmdRet skype_cmd_kick(PurpleConversation *, const gchar *, gchar **, gchar **, void *);
static PurpleCmdRet skype_cmd_kickban(PurpleConversation *, const gchar *, gchar **, gchar **, void *);
int skype_send_raw(PurpleConnection *, const char *, int);
void skype_group_buddy(PurpleConnection *, const char *who, const char *old_group, const char *new_group);
void skype_rename_group(PurpleConnection *, const char *old_name, PurpleGroup *group, GList *moved_buddies);
void skype_remove_group(PurpleConnection *, PurpleGroup *);
int skype_find_group_with_name(const char *group_name_in);
static gboolean skype_uri_handler(const char *proto, const char *cmd, GHashTable *params);
void skype_buddy_free(PurpleBuddy *buddy);
const char *skype_list_emblem(PurpleBuddy *buddy);
SkypeBuddy *skype_buddy_new(PurpleBuddy *buddy);
static void skype_request_auth_from_blist(PurpleBlistNode *node, gpointer data);
static void skype_open_sms_im(PurpleBlistNode *node, gpointer data);
void skype_got_buddy_icon_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message);
gboolean skype_check_keepalive(PurpleConnection *gc);
void skype_open_verify_mobile_number_step2(gpointer ignore, gchar *mobile_number);
static void skype_open_verify_mobile_number(PurplePlugin *plugin, gpointer data);
void skype_open_verify_mobile_number_step3(gpointer mobile_number, gchar *verification_code);
gchar *skype_set_next_sms_number_for_conversation(PurpleConversation *conv, const gchar *who);
gboolean skype_login_cb(gpointer acct);
void skype_put_buddies_in_groups(void);
gboolean groups_table_find_group(gpointer key, gpointer value, gpointer user_data);
PurpleChat *skype_find_blist_chat(PurpleAccount *account, const char *name);
gboolean skype_login_retry(PurpleAccount *acct);
gboolean skype_login_part2(PurpleAccount *acct);
typedef void (*_account_char_fn)(PurpleAccount *, const char *);
void skype_set_public_alias(PurpleConnection *gc, const char *alias, _account_char_fn success_cb, _account_char_fn failure_cb);
void skype_get_public_alias(PurpleConnection *gc, _account_char_fn success_cb, _account_char_fn failure_cb);
#ifndef SKYPENET
#ifdef _WIN32
static void skype_open_skype_options(void);
#endif
void skype_call_number(gpointer ignore, gchar *number);
void skype_call_number_request(PurplePlugin *plugin, gpointer data);
void skype_program_update_callback(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message);
static void skype_program_update_check(void);
static void skype_send_file_from_blist(PurpleBlistNode *node, gpointer data);
static void skype_call_user_from_blist(PurpleBlistNode *node, gpointer data);
static void skype_end_call_from_blist(PurpleBlistNode *node, gpointer data);
#endif
PurplePluginProtocolInfo prpl_info = {
/* options */
#ifndef SKYPENET
#if _WIN32 || __APPLE__ || SKYPE_DBUS || !USE_XVFB_SERVER
OPT_PROTO_NO_PASSWORD|
#endif
#endif
#if PURPLE_MAJOR_VERSION == 2 && PURPLE_MINOR_VERSION >= 8
OPT_PROTO_INVITE_MESSAGE|
#endif
OPT_PROTO_REGISTER_NOSCREENNAME|OPT_PROTO_CHAT_TOPIC|OPT_PROTO_SLASH_COMMANDS_NATIVE,
NULL, /* user_splits */
NULL, /* protocol_options */
{"png,gif,jpeg", 0, 0, 96, 96, 0, PURPLE_ICON_SCALE_SEND}, /* icon_spec */
skype_list_icon, /* list_icon */
skype_list_emblem, /* list_emblem */
skype_status_text, /* status_text */
skype_tooltip_text, /* tooltip_text */
skype_status_types, /* status_types */
skype_node_menu, /* blist_node_menu */
skype_join_chat_info,/* chat_info */
skype_join_chat_info_defaults,/* chat_info_defaults */
skype_login, /* login */
skype_close, /* close */
skype_send_im, /* send_im */
NULL, /* set_info */
skype_send_typing, /* send_typing */
skype_get_info, /* get_info */
skype_set_status, /* set_status */
skype_set_idle, /* set_idle */
NULL, /* change_passwd */
#if PURPLE_MAJOR_VERSION == 2 && PURPLE_MINOR_VERSION >= 8
skype_add_buddy_with_invite, /* add_buddy */
#else
skype_add_buddy, /* add_buddy */
#endif
NULL, /* add_buddies */
skype_remove_buddy, /* remove_buddy */
NULL, /* remove_buddies */
skype_add_permit, /* add_permit */
skype_add_deny, /* add_deny */
skype_rem_permit, /* rem_permit */
skype_rem_deny, /* rem_deny */
NULL, /* set_permit_deny */
skype_join_chat, /* join_chat */
NULL, /* reject chat invite */
skype_get_chat_name, /* get_chat_name */
skype_chat_invite, /* chat_invite */
/*skype_chat_leave*/NULL, /* chat_leave */
NULL, /* chat_whisper */
skype_chat_send, /* chat_send */
skype_keepalive, /* keepalive */
NULL, /* register_user */
NULL, /* get_cb_info */
NULL, /* get_cb_away */
skype_alias_buddy, /* alias_buddy */
skype_group_buddy, /* group_buddy */
skype_rename_group, /* rename_group */
skype_buddy_free, /* buddy_free */
NULL, /* convo_closed */
skype_normalize, /* normalize */
skype_set_buddy_icon,/* set_buddy_icon */
skype_remove_group, /* remove_group */
/*skype_cb_real_name*/NULL, /* get_cb_real_name */
skype_set_chat_topic,/* set_chat_topic */
NULL, /* find_blist_chat */
NULL, /* roomlist_get_list */
NULL, /* roomlist_cancel */
NULL, /* roomlist_expand_category */
NULL, /* can_receive_file */
NULL, /* send_file */
NULL, /* new_xfer */
skype_offline_msg, /* offline_message */
NULL, /* whiteboard_prpl_ops */
skype_send_raw, /* send_raw */
NULL, /* roomlist_room_serialize */
NULL, /* unregister_user */
NULL, /* send_attention */
NULL, /* attention_types */
#if PURPLE_MAJOR_VERSION == 2 && PURPLE_MINOR_VERSION == 1
(gpointer)
#endif
sizeof(PurplePluginProtocolInfo), /* struct_size */
NULL, /* get_account_text_table */
#ifndef INSTANTBIRD
skype_media_initiate,/* initiate_media */
skype_get_media_caps,/* can_do_media */
#else
NULL, /* initiate_media */
NULL, /* can_do_media */
#endif
NULL, /* get_moods */
skype_set_public_alias, /* set_public_alias */
skype_get_public_alias /* get_public_alias */
#if PURPLE_MAJOR_VERSION == 2 && PURPLE_MINOR_VERSION >= 8
, skype_add_buddy_with_invite, /* add_buddy_with_invite */
NULL /* add_buddies_with_invite */
#endif
};
static PurplePluginInfo info = {
PURPLE_PLUGIN_MAGIC,
/* PURPLE_MAJOR_VERSION,
PURPLE_MINOR_VERSION,
*/
2, 1,
PURPLE_PLUGIN_PROTOCOL, /* type */
NULL, /* ui_requirement */
0, /* flags */
NULL, /* dependencies */
PURPLE_PRIORITY_DEFAULT, /* priority */
#ifdef SKYPENET
"prpl-bigbrownchunx-skypenet",
"Skype (Network)",
#else
#ifdef SKYPE_DBUS
"prpl-bigbrownchunx-skype-dbus", /* id */
"Skype (D-Bus)",
#else
"prpl-bigbrownchunx-skype", /* id */
"Skype", /* name */
#endif
#endif
"2.0", /* version */
"Allows using Skype IM functions from within Pidgin", /* summary */
"Allows using Skype IM functions from within Pidgin", /* description */
"Eion Robb <[email protected]>", /* author */
"http://eion.robbmob.com/", /* homepage */
plugin_load, /* load */
plugin_unload, /* unload */
NULL, /* destroy */
NULL, /* ui_info */
&prpl_info, /* extra_info */
NULL, /* prefs_info */
skype_actions, /* actions */
NULL, /* padding */
NULL,
NULL,
NULL
};
static PurplePlugin *this_plugin;
static void
plugin_init(PurplePlugin *plugin)
{
PurpleAccountOption *option;
#if ( _WIN32 || __APPLE__ ) && ENABLE_NLS
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
#endif
#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32
if (glib_check_version(2, 32, 0))
if (!g_thread_supported ())
g_thread_init (NULL);
#endif
this_plugin = plugin;
/* plugin's path at
this_plugin->path */
#ifdef SKYPENET
option = purple_account_option_string_new(_("Server"), "host", "skype.robbmob.com");
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
option = purple_account_option_int_new(_("Port"), "port", 5000);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
#endif
option = purple_account_option_bool_new(_("Show SkypeOut contacts as 'Online'"), "skypeout_online", TRUE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
option = purple_account_option_bool_new(_("Make Skype online/offline when going online/offline"), "skype_sync", TRUE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
option = purple_account_option_bool_new(_("Update Skype status message"), "update_status", TRUE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
option = purple_account_option_bool_new(_("Display video capability status"), "video_capable", TRUE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
//option = purple_account_option_bool_new(_("Automatically check for updates"), "check_for_updates", TRUE);
//prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
option = purple_account_option_bool_new(_("Automatically reject all authorization requests"), "reject_all_auths", FALSE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
#ifndef SKYPENET
option = purple_account_option_bool_new(_("Auto-start Skype if not running"), "skype_autostart", TRUE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
option = purple_account_option_string_new(_("Skype Path"), "skype_path", "");
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
#endif
//leave
purple_cmd_register("leave", "", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_IM |
PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS,
plugin->info->id, skype_cmd_leave,
_("leave [channel]: Leave the chat"), NULL);
//topic
purple_cmd_register("topic", "s", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_CHAT |
PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS,
plugin->info->id, skype_cmd_topic,
_("topic [<new topic>]: View or change the topic"),
NULL);
//call, as in call person
//kick
purple_cmd_register("kick", "s", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_CHAT |
PURPLE_CMD_FLAG_PRPL_ONLY,
plugin->info->id, skype_cmd_kick,
_("kick <user> [room]: Kick a user from the room."),
NULL);
//kickban
purple_cmd_register("kickban", "s", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_CHAT |
PURPLE_CMD_FLAG_PRPL_ONLY,
plugin->info->id, skype_cmd_kickban,
_("kick <user> [room]: Kick a user from the room."),
NULL);
purple_signal_connect(purple_get_core(), "uri-handler", plugin, PURPLE_CALLBACK(skype_uri_handler), NULL);
}
/* copied from oscar.c to be libpurple 2.1 compatible */
static PurpleAccount *
find_acct(const char *prpl, const char *acct_id)
{
PurpleAccount *acct = NULL;
/* If we have a specific acct, use it */
if (acct_id) {
acct = purple_accounts_find(acct_id, prpl);
if (acct && !purple_account_is_connected(acct))
acct = NULL;
} else { /* Otherwise find an active account for the protocol */
GList *l = purple_accounts_get_all();
while (l) {
if (!strcmp(prpl, purple_account_get_protocol_id(l->data))
&& purple_account_is_connected(l->data)) {
acct = l->data;
break;
}
l = l->next;
}
}
return acct;
}
static PurpleCmdRet
skype_cmd_leave(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
{
PurpleConnection *gc = NULL;
int id = -1;
gc = purple_conversation_get_gc(conv);
id = purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv));
if (gc == NULL || id == -1)
return PURPLE_CMD_RET_FAILED;
skype_chat_leave(gc, id);
return PURPLE_CMD_RET_OK;
}
static PurpleCmdRet
skype_cmd_topic(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
{
PurpleConnection *gc = NULL;
int id = -1;
gc = purple_conversation_get_gc(conv);
id = purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv));
if (gc == NULL || id == -1)
return PURPLE_CMD_RET_FAILED;
skype_set_chat_topic(gc, id, args ? args[0] : NULL);
return PURPLE_CMD_RET_OK;
}
static PurpleCmdRet
skype_cmd_kick(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
{
gchar *temp;
gchar *chat_id;
chat_id = (gchar *)g_hash_table_lookup(conv->data, "chat_id");
temp = skype_send_message("ALTER CHAT %s KICK %s", chat_id, args[0]);
if (!temp || !strlen(temp))
{
g_free(temp);
return PURPLE_CMD_RET_FAILED;
}
return PURPLE_CMD_RET_OK;
}
static PurpleCmdRet
skype_cmd_kickban(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
{
gchar *temp;
gchar *chat_id;
chat_id = (gchar *)g_hash_table_lookup(conv->data, "chat_id");
temp = skype_send_message("ALTER CHAT %s KICKBAN %s", chat_id, args[0]);
if (!temp || !strlen(temp))
{
g_free(temp);
return PURPLE_CMD_RET_FAILED;
}
return PURPLE_CMD_RET_OK;
}
PURPLE_INIT_PLUGIN(skype, plugin_init, info);
static PurpleAccount *
skype_get_account(PurpleAccount *newaccount)
{
static PurpleAccount* account = NULL;
if (newaccount != NULL)
account = newaccount;
return account;
}
#if 0
void skype_ft_debug(PurpleXfer *xfer) {printf("%s\n", xfer->account->protocol_id);}
void skype_ft_new_xfer(PurpleXfer *xfer) {printf("skype_ft_new_xfer\n");skype_ft_debug(xfer);}
void skype_ft_destroy(PurpleXfer *xfer) {printf("skype_ft_destroy\n");skype_ft_debug(xfer);}
void skype_ft_add_xfer(PurpleXfer *xfer) {printf("skype_ft_add_xfer\n");skype_ft_debug(xfer);}
void skype_ft_update_progress(PurpleXfer *xfer, double percent) {printf("skype_ft_update_progress\n");skype_ft_debug(xfer);}
void skype_ft_cancel_local(PurpleXfer *xfer) {printf("skype_ft_cancel_local\n");skype_ft_debug(xfer);}
void skype_ft_cancel_remote(PurpleXfer *xfer) {printf("skype_ft_cancel_remote\n");skype_ft_debug(xfer);}
gboolean
plugin_load(PurplePlugin *plugin)
{
PurpleXferUiOps *ops = purple_xfers_get_ui_ops();
ops->new_xfer = skype_ft_new_xfer;
ops->destroy = skype_ft_destroy;
ops->add_xfer = skype_ft_add_xfer;
ops->update_progress = skype_ft_update_progress;
ops->cancel_local = skype_ft_cancel_local;
ops->cancel_remote = skype_ft_cancel_remote;
return TRUE;
}
#else
gboolean
plugin_load(PurplePlugin *plugin)
{
return TRUE;
}
#endif
gboolean
plugin_unload(PurplePlugin *plugin)
{
return TRUE;
}
static GList *
skype_node_menu(PurpleBlistNode *node)
{
GList *m = NULL;
PurpleMenuAction *act;
PurpleBuddy *buddy;
SkypeBuddy *sbuddy;
gchar *temp;
if(PURPLE_BLIST_NODE_IS_BUDDY(node))
{
buddy = (PurpleBuddy *)node;
sbuddy = (SkypeBuddy *)buddy->proto_data;
#ifndef SKYPENET
#ifndef __APPLE__
act = purple_menu_action_new(_("_Send File"),
PURPLE_CALLBACK(skype_send_file_from_blist),
NULL, NULL);
m = g_list_append(m, act);
#endif
#ifndef INSTANTBIRD
if (!purple_media_manager_get())
{
gint call_id = 0, i, j;
temp = skype_send_message("SEARCH ACTIVECALLS");
if (temp && *temp && temp[5] && temp[6])
{
gchar **ids = g_strsplit(&temp[6], ", ", 0);
gchar **buddy_calls = NULL;
g_free(temp);
temp = skype_send_message("SEARCH CALLS %s", buddy->name);
if (temp && *temp && temp[5] && temp[6])
{
buddy_calls = g_strsplit(&temp[6], ", ", 0);
for (i = 0; ids[i]; i++)
{
for (j = 0; buddy_calls[j]; j++)
{
if (g_str_equal(ids[i], buddy_calls[j]))
{
call_id = atoi(ids[i]);
break;
}
}
if (call_id)
break;
}
}
g_free(temp);
g_strfreev(buddy_calls);
g_strfreev(ids);
}
if (call_id)
{
act = purple_menu_action_new(_("End Call"),
PURPLE_CALLBACK(skype_end_call_from_blist),
GINT_TO_POINTER(call_id), NULL);
m = g_list_append(m, act);
} else {
act = purple_menu_action_new(_("Call..."),
PURPLE_CALLBACK(skype_call_user_from_blist),
NULL, NULL);
m = g_list_append(m, act);
}
}
#endif
#endif
act = purple_menu_action_new(_("Initiate _Chat"),
PURPLE_CALLBACK(skype_initiate_chat),
NULL, NULL);
m = g_list_append(m, act);
if (buddy->name[0] == '+' || (sbuddy && sbuddy->phone_mobile))
{
act = purple_menu_action_new(_("Send SMS"),
PURPLE_CALLBACK(skype_open_sms_im),
NULL, NULL);
m = g_list_append(m, act);
}
if (!PURPLE_BUDDY_IS_ONLINE(buddy))
{
temp = skype_send_message("GET USER %s BUDDYSTATUS", buddy->name);
purple_debug_info("skype", "Offline buddy's status is %c\n", temp[18+strlen(buddy->name)]);
if (temp[18+strlen(buddy->name)] == '2')
{
act = purple_menu_action_new(_("Re-request authorization"),
PURPLE_CALLBACK(skype_request_auth_from_blist),
NULL, NULL);
m = g_list_append(m, act);
}
g_free(temp);
}
} else if (PURPLE_BLIST_NODE_IS_CHAT(node))
{
} else if (PURPLE_BLIST_NODE_IS_GROUP(node))
{
act = purple_menu_action_new(_("Initiate _Chat"),
PURPLE_CALLBACK(skype_initiate_chat),
NULL, NULL);
m = g_list_append(m, act);
}
return m;
}
#ifndef SKYPENET
static void
skype_send_file_from_blist(PurpleBlistNode *node, gpointer data)
{
PurpleBuddy *buddy;
if(PURPLE_BLIST_NODE_IS_BUDDY(node))
{
buddy = (PurpleBuddy *) node;
if (PURPLE_BUDDY_IS_ONLINE(buddy))
{
skype_send_message_nowait("OPEN FILETRANSFER %s", buddy->name);
}
}
}
static void
skype_call_user_from_blist(PurpleBlistNode *node, gpointer data)
{
PurpleBuddy *buddy;
if(PURPLE_BLIST_NODE_IS_BUDDY(node))
{
buddy = (PurpleBuddy *) node;
skype_send_message_nowait("CALL %s", buddy->name);
}
}
static void
skype_end_call_from_blist(PurpleBlistNode *node, gpointer data)
{
gint call_id;
if(PURPLE_BLIST_NODE_IS_BUDDY(node))
{
call_id = GPOINTER_TO_INT(data);
skype_send_message_nowait("ALTER CALL %d HANGUP", call_id);
}
}
#endif
const char *
skype_normalize(const PurpleAccount *acct, const char *who)
{
static gchar *last_normalize = NULL;
g_free(last_normalize);
last_normalize = g_utf8_strdown(who, -1);
return last_normalize;
}
GList *
skype_actions(PurplePlugin *plugin, gpointer context)
{
GList *m = NULL;
PurpleMenuAction *act;
#ifndef SKYPENET
act = purple_menu_action_new(_("Hide Skype"),
PURPLE_CALLBACK(skype_silence),
NULL, NULL);
m = g_list_append(m, act);
act = purple_menu_action_new(_("Check for Skype updates..."),
PURPLE_CALLBACK(skype_program_update_check),
NULL, NULL);
m = g_list_append(m, act);
#endif
if (this_plugin != NULL && this_plugin->path != NULL)
{
act = purple_menu_action_new(_("Check for plugin updates..."),
PURPLE_CALLBACK(skype_plugin_update_check),
NULL, NULL);
m = g_list_append(m, act);
}
act = purple_menu_action_new(_("Search for buddies..."),
PURPLE_CALLBACK(skype_show_search_users),
NULL, NULL);
m = g_list_append(m, act);
act = purple_menu_action_new(_("Check Skype balance..."),
PURPLE_CALLBACK(skype_display_skype_credit),
NULL, NULL);
m = g_list_append(m, act);
#ifndef SKYPENET
act = purple_menu_action_new(_("Call..."),
PURPLE_CALLBACK(skype_call_number_request),
NULL, NULL);
m = g_list_append(m, act);
#ifdef _WIN32
act = purple_menu_action_new(_("Open Skype Options..."),
PURPLE_CALLBACK(skype_open_skype_options),
NULL, NULL);
m = g_list_append(m, act);
#endif
#endif
act = purple_menu_action_new(_("Verify mobile number..."),
PURPLE_CALLBACK(skype_open_verify_mobile_number),
NULL, NULL);
m = g_list_append(m, act);
return m;
}
#if !defined SKYPENET && defined _WIN32
static void
skype_open_skype_options(void)
{
skype_send_message_nowait("OPEN OPTIONS");
}
#endif
static void
skype_silence(PurplePlugin *plugin, gpointer data)
{
skype_send_message_nowait("SET SILENT_MODE ON");
skype_send_message_nowait("MINIMIZE");
hide_skype();
}
static void
skype_open_verify_mobile_number(PurplePlugin *plugin, gpointer data)
{
purple_request_input(plugin, _("Verify mobile number..."), _("Enter the mobile phone number to send verification SMS to"), NULL,
NULL, FALSE, FALSE, NULL, _("OK"), G_CALLBACK(skype_open_verify_mobile_number_step2), _("_Cancel"),
NULL, NULL, NULL, NULL, plugin);
}
void
skype_open_verify_mobile_number_step2(gpointer plugin, gchar *mobile_number)
{
skype_send_message_nowait("CREATE SMS CONFIRMATION_CODE_REQUEST %s", mobile_number);
purple_request_input(plugin, _("Verify mobile number..."), _("Enter the verification code which was sent to your mobile"), NULL,
NULL, FALSE, FALSE, NULL, _("OK"), G_CALLBACK(skype_open_verify_mobile_number_step3), _("_Cancel"),
NULL, NULL, NULL, NULL, mobile_number);
}
void
skype_open_verify_mobile_number_step3(gpointer mobile_number, gchar *verification_code)
{
skype_send_message_nowait("CREATE SMS CONFIRMATION_CODE_SUBMIT %s", mobile_number);
}
static void
skype_plugin_update_check(void)
{
gchar *basename;
struct stat *filestat = g_new(struct stat, 1);
//this_plugin is the PidginPlugin
if (this_plugin == NULL || this_plugin->path == NULL || filestat == NULL || g_stat(this_plugin->path, filestat) == -1)
{
purple_notify_warning(this_plugin, "Warning", "Could not check for updates", NULL);
} else {
basename = g_path_get_basename(this_plugin->path);
purple_util_fetch_url(g_strconcat("http://eion.robbmob.com/version?version=", basename, NULL),
TRUE, NULL, FALSE, skype_plugin_update_callback, (gpointer)filestat);
}
}
void
skype_plugin_update_callback(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
time_t mtime = ((struct stat *) user_data)->st_mtime;
time_t servertime = atoi(url_text);
skype_debug_info("skype", "Server filemtime: %d, Local filemtime: %d\n", servertime, mtime);
if (servertime > mtime)
{
purple_notify_info(this_plugin, _("New Version Available"), _("There is a newer version of the Skype plugin available for download."),
g_strconcat(_("Your version"),": ",timestamp_to_datetime(mtime),"\n",_("Latest version"),": ",timestamp_to_datetime(servertime),"\nLatest version available from: ", this_plugin->info->homepage, NULL));
} else {
purple_notify_info(this_plugin, _("No updates found"), _("No updates found"), _("You have the latest version of the Skype plugin"));
}
}
#ifndef SKYPENET
static void
skype_program_update_check(void)
{
/*
Windows:
http://ui.skype.com/ui/0/3.5.0.239/en/getnewestversion
Linux:
http://ui.skype.com/ui/2/2.0.0.13/en/getnewestversion
Mac:
http://ui.skype.com/ui/3/2.6.0.151/en/getnewestversion
User-Agent: Skype
*/
gchar *version;
gchar *temp;
gchar version_url[60];
int platform_number;
#ifdef _WIN32
platform_number = 0;
#else
# ifdef __APPLE__
platform_number = 3;
# else
platform_number = 2;
# endif
#endif
temp = skype_send_message("GET SKYPEVERSION");
version = g_strdup(&temp[13]);
g_free(temp);
sprintf(version_url, "http://ui.skype.com/ui/%d/%s/en/getnewestversion", platform_number, version);
purple_util_fetch_url(version_url, TRUE, "Skype", TRUE, skype_program_update_callback, (gpointer)version);
}
void
skype_program_update_callback(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
gchar *version = (gchar *)user_data;
int v1, v2, v3, v4;
int s1, s2, s3, s4;
gboolean newer_version = FALSE;
sscanf(version, "%d.%d.%d.%d", &v1, &v2, &v3, &v4);
sscanf(url_text, "%d.%d.%d.%d", &s1, &s2, &s3, &s4);
if (s1 > v1)
newer_version = TRUE;
else if (s1 == v1 && s2 > v2)
newer_version = TRUE;
else if (s1 == v1 && s2 == v2 && s3 > v3)
newer_version = TRUE;
else if (s1 == v1 && s2 == v2 && s3 == v3 && s4 > v4)
newer_version = TRUE;
if (newer_version)
{
purple_notify_info(this_plugin, _("New Version Available"), _("There is a newer version of Skype available for download"), g_strconcat(_("Your version"),": ", version, "\n",_("Latest version"),": ", url_text, "\n\nhttp://www.skype.com/go/download", NULL));
} else {
purple_notify_info(this_plugin, _("No updates found"), _("No updates found"), _("You have the latest version of Skype"));
}
}
void
skype_call_number_request(PurplePlugin *plugin, gpointer data)
{
//http://developer.pidgin.im/doxygen/dev/html/request_8h.html#80ea2f9ad3a45471e05f09a2b5abcd75
purple_request_input(plugin, _("Call..."), _("Enter the phone number or Skype buddy name to call"), NULL,
NULL, FALSE, FALSE, NULL, _("Call..."), G_CALLBACK(skype_call_number), _("_Cancel"),
NULL, NULL, NULL, NULL, NULL);
}
void
skype_call_number(gpointer ignore, gchar *number)
{
skype_send_message_nowait("CALL %s", number);
}
#endif
GList *
skype_status_types(PurpleAccount *acct)
{
GList *types;
PurpleStatusType *status;
skype_debug_info("skype", "returning status types\n");
types = NULL;
/* Statuses are almost all the same. Define a macro to reduce code repetition. */
#define _SKYPE_ADD_NEW_STATUS(prim,id,name) status = \
purple_status_type_new_with_attrs( \