forked from felipec/msn-pecan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
msn.c
1971 lines (1590 loc) · 53 KB
/
msn.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
/**
* Copyright (C) 2007-2009 Felipe Contreras
* Copyright (C) 1998-2006 Pidgin (see pidgin-copyright)
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <glib.h>
#include "page.h"
#include "session.h"
#include "pn_global.h"
#include "pn_util.h"
#include "pn_log.h"
#include "pn_locale.h"
#include "pn_status.h"
#include "pn_buffer.h"
#include "switchboard.h"
#include "notification.h"
#include "sync.h"
#include "session_private.h"
#include "cmd/msg.h"
#include "ab/pn_contact_priv.h"
#include <string.h> /* For strcmp, strstr, strlen */
#if defined(PECAN_CVR)
#include "cvr/pn_peer_link.h"
#include "libpurple/xfer.h"
#endif /* defined(PECAN_CVR) */
/* libpurple stuff. */
#include <debug.h>
#include <privacy.h>
#include <request.h>
#include <accountopt.h>
#include <pluginpref.h>
#include <cmds.h>
#include <version.h>
#include <core.h>
#include <prpl.h>
#include <util.h>
#include <prefs.h>
#if defined(PECAN_CVR)
#if PURPLE_VERSION_CHECK(2,5,0)
#include <smiley.h>
#endif /* PURPLE_VERSION_CHECK(2,5,0) */
#endif /* defined(PECAN_CVR) */
#ifndef ADIUM
#define PLUGIN_ID "prpl-msn-pecan"
#else
#define PLUGIN_ID "prpl-msn_pecan"
#endif
#ifndef STATIC_PECAN
#define PURPLE_MODULE_EXPORT G_MODULE_EXPORT
#define PURPLE_MODULE_NAME(module, x) x
#else
#define PURPLE_MODULE_EXPORT
#define PURPLE_MODULE_NAME(module, x) module ## _ ## x
#endif
typedef struct
{
PurpleConnection *gc;
const char *passport;
} MsnMobileData;
#if PURPLE_VERSION_CHECK(2,5,0)
typedef struct
{
char *smile;
PurpleSmiley *ps;
struct pn_msnobj *obj;
} MsnEmoticon;
#endif /* PURPLE_VERSION_CHECK(2,5,0) */
#if !PURPLE_VERSION_CHECK(2,7,0)
void PURPLE_MODULE_NAME(msn_pecan, set_alias) (PurpleConnection *gc,
const gchar *value);
#endif
static void msn_set_prp(PurpleConnection *gc, const char *type, const char *entry);
static gboolean
contact_is_account_quick (MsnSession *session,
const gchar *passport)
{
gchar *normalized_passport;
normalized_passport = pn_normalize (passport);
if (strcmp (msn_session_get_username (session), normalized_passport) == 0)
{
g_free (normalized_passport);
return TRUE;
}
g_free (normalized_passport);
return FALSE;
}
/** @todo remove this crap */
static const gchar *
normalize (const PurpleAccount *account,
const gchar *str)
{
static gchar buf[0x800];
gchar *tmp;
tmp = pn_normalize (str);
strncpy (buf, tmp, sizeof (buf));
g_free (tmp);
return buf;
}
static gboolean
msn_send_attention(PurpleConnection *gc, const char *username, guint type)
{
MsnMessage *msg;
MsnSession *session;
MsnSwitchBoard *swboard;
msg = msn_message_new_nudge();
session = gc->proto_data;
swboard = msn_session_get_swboard(session, username);
if (swboard == NULL)
return FALSE;
msn_switchboard_send_msg(swboard, msg, TRUE);
msn_message_unref(msg);
return TRUE;
}
static GList *
msn_attention_types(PurpleAccount *account)
{
PurpleAttentionType *attn;
static GList *list = NULL;
if (!list) {
attn = g_new0(PurpleAttentionType, 1);
attn->name = _("Nudge");
attn->incoming_description = _("%s has nudged you!");
attn->outgoing_description = _("Nudging %s...");
list = g_list_append(list, attn);
}
return list;
}
static PurpleCmdRet
msn_cmd_nudge(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
{
PurpleAccount *account = purple_conversation_get_account(conv);
PurpleConnection *gc = purple_account_get_connection(account);
const gchar *username;
username = purple_conversation_get_name(conv);
serv_send_attention(gc, username, 0);
return PURPLE_CMD_RET_OK;
}
static void
set_friendly_name (PurpleConnection *gc,
const gchar *entry)
{
/*
* The server doesn't seem to store the friendly name anymore, so let's do
* that ourselves.
*/
purple_account_set_string (gc->account, "friendly_name", entry);
msn_session_set_public_alias (gc->proto_data, entry);
}
#if PURPLE_VERSION_CHECK(2,7,0)
static void
set_alias(PurpleConnection *pc, const char *alias,
PurpleSetPublicAliasSuccessCallback success_cb,
PurpleSetPublicAliasFailureCallback failure_cb)
{
PurpleAccount *account;
account = purple_connection_get_account(pc);
set_friendly_name(pc, alias);
success_cb(account, alias);
}
#else
PURPLE_MODULE_EXPORT void
PURPLE_MODULE_NAME(msn_pecan, set_alias) (PurpleConnection *gc,
const gchar *value)
{
set_friendly_name (gc, value);
}
#endif
/* TODO do we really need to check for the entry to be empty? */
static void
msn_set_prp(PurpleConnection *gc, const char *type, const char *entry)
{
if (entry && *entry == '\0')
entry = NULL;
msn_session_set_prp (gc->proto_data, type, entry);
}
#ifndef PECAN_USE_PSM
static void
msn_set_personal_message_cb (PurpleConnection *gc, const gchar *entry)
{
MsnSession *session;
session = gc->proto_data;
purple_account_set_string(session->user_data, "personal_message", entry);
pn_update_personal_message (session);
}
#endif /* PECAN_USE_PSM */
static void
msn_set_home_phone_cb(PurpleConnection *gc, const char *entry)
{
msn_set_prp(gc, "PHH", entry);
}
static void
msn_set_work_phone_cb(PurpleConnection *gc, const char *entry)
{
msn_set_prp(gc, "PHW", entry);
}
static void
msn_set_mobile_phone_cb(PurpleConnection *gc, const char *entry)
{
msn_set_prp(gc, "PHM", entry);
}
static void
enable_msn_pages_cb(PurpleConnection *gc)
{
msn_set_prp(gc, "MOB", "Y");
}
static void
disable_msn_pages_cb(PurpleConnection *gc)
{
msn_set_prp(gc, "MOB", "N");
}
static void
send_to_mobile(PurpleConnection *gc, const char *who, const char *entry)
{
MsnTransaction *trans;
MsnSession *session;
MsnCmdProc *cmdproc;
MsnPage *page;
char *payload;
size_t payload_len;
session = gc->proto_data;
cmdproc = session->notification->cmdproc;
page = msn_page_new();
msn_page_set_body(page, entry);
payload = msn_page_gen_payload(page, &payload_len);
trans = msn_transaction_new(cmdproc, "PGD", "%s 1 %d", who, payload_len);
msn_transaction_set_payload(trans, payload, payload_len);
msn_page_destroy(page);
msn_cmdproc_send_trans(cmdproc, trans);
}
static void
send_to_mobile_cb(MsnMobileData *data, const char *entry)
{
send_to_mobile(data->gc, data->passport, entry);
g_free(data);
}
static void
close_mobile_page_cb(MsnMobileData *data, const char *entry)
{
g_free(data);
}
/* -- */
static void
msn_show_set_friendly_name(PurplePluginAction *action)
{
PurpleConnection *gc;
gc = (PurpleConnection *) action->context;
purple_request_input(gc, NULL, _("Set your friendly name."),
_("This is the name that other MSN buddies will "
"see you as."),
purple_connection_get_display_name(gc), FALSE, FALSE, NULL,
_("OK"), G_CALLBACK(set_friendly_name),
_("Cancel"), NULL,
purple_connection_get_account(gc), NULL, NULL,
gc);
}
#ifndef PECAN_USE_PSM
static void
msn_show_set_personal_message (PurplePluginAction *action)
{
PurpleConnection *gc;
MsnSession *session;
gc = (PurpleConnection *) action->context;
session = gc->proto_data;
purple_request_input(gc, NULL, _("Set your personal message."),
_("This is the message that other MSN buddies will "
"see under your name."),
purple_account_get_string (session->user_data, "personal_message", ""),
FALSE, FALSE, NULL,
_("OK"), G_CALLBACK(msn_set_personal_message_cb),
_("Cancel"), NULL,
purple_connection_get_account(gc), NULL, NULL,
gc);
}
#endif /* PECAN_USE_PSM */
static void
msn_show_set_home_phone(PurplePluginAction *action)
{
PurpleConnection *gc;
MsnSession *session;
gc = (PurpleConnection *) action->context;
session = gc->proto_data;
purple_request_input(gc, NULL, _("Set your home phone number."), NULL,
pn_contact_get_home_phone(msn_session_get_contact (session)), FALSE, FALSE, NULL,
_("OK"), G_CALLBACK(msn_set_home_phone_cb),
_("Cancel"), NULL,
purple_connection_get_account(gc), NULL, NULL,
gc);
}
static void
msn_show_set_work_phone(PurplePluginAction *action)
{
PurpleConnection *gc;
MsnSession *session;
gc = (PurpleConnection *) action->context;
session = gc->proto_data;
purple_request_input(gc, NULL, _("Set your work phone number."), NULL,
pn_contact_get_work_phone(msn_session_get_contact (session)), FALSE, FALSE, NULL,
_("OK"), G_CALLBACK(msn_set_work_phone_cb),
_("Cancel"), NULL,
purple_connection_get_account(gc), NULL, NULL,
gc);
}
static void
msn_show_set_mobile_phone(PurplePluginAction *action)
{
PurpleConnection *gc;
MsnSession *session;
gc = (PurpleConnection *) action->context;
session = gc->proto_data;
purple_request_input(gc, NULL, _("Set your mobile phone number."), NULL,
pn_contact_get_mobile_phone(msn_session_get_contact (session)), FALSE, FALSE, NULL,
_("OK"), G_CALLBACK(msn_set_mobile_phone_cb),
_("Cancel"), NULL,
purple_connection_get_account(gc), NULL, NULL,
gc);
}
static void
msn_show_set_mobile_pages(PurplePluginAction *action)
{
PurpleConnection *gc;
gc = (PurpleConnection *) action->context;
purple_request_action(gc, NULL, _("Allow MSN Mobile pages?"),
_("Do you want to allow or disallow people on "
"your buddy list to send you MSN Mobile pages "
"to your cell phone or other mobile device?"),
-1,
purple_connection_get_account(gc), NULL, NULL,
gc, 3,
_("Allow"), G_CALLBACK(enable_msn_pages_cb),
_("Disallow"), G_CALLBACK(disable_msn_pages_cb),
_("Cancel"), NULL);
}
static void
show_hotmail_inbox (PurplePluginAction *action)
{
PurpleConnection *gc;
MsnSession *session;
gc = (PurpleConnection *) action->context;
session = gc->proto_data;
if (session->passport_info.email_enabled != 1)
{
purple_notify_error (gc, NULL, _("This account's email is not enabled."), NULL);
return;
}
/** apparently the correct value is 777 */
if (time (NULL) - session->passport_info.mail_url_timestamp >= 750)
{
MsnTransaction *trans;
MsnCmdProc *cmdproc;
cmdproc = session->notification->cmdproc;
trans = msn_transaction_new (cmdproc, "URL", "%s", "INBOX");
msn_transaction_set_data (trans, GUINT_TO_POINTER (TRUE));
msn_cmdproc_send_trans (cmdproc, trans);
pn_debug ("mail_url update");
return;
}
purple_notify_uri (gc, session->passport_info.mail_url);
}
static void
show_send_to_mobile_cb(PurpleBlistNode *node, gpointer ignored)
{
PurpleBuddy *buddy;
PurpleConnection *gc;
MsnMobileData *data;
g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
buddy = (PurpleBuddy *) node;
gc = purple_account_get_connection(buddy->account);
data = g_new0(MsnMobileData, 1);
data->gc = gc;
data->passport = buddy->name;
purple_request_input(gc, NULL, _("Send a mobile message."), NULL,
NULL, TRUE, FALSE, NULL,
_("Page"), G_CALLBACK(send_to_mobile_cb),
_("Close"), G_CALLBACK(close_mobile_page_cb),
purple_connection_get_account(gc), purple_buddy_get_name(buddy), NULL,
data);
}
static gboolean
msn_offline_message(const PurpleBuddy *buddy) {
return TRUE;
}
static inline MsnSwitchBoard *
new_chat (MsnSession *session,
gint id)
{
MsnSwitchBoard *swboard;
swboard = msn_switchboard_new (session);
swboard->chat_id = id;
/* we should not leave chats on timeouts */
pn_timer_free(swboard->timer);
swboard->timer = NULL;
g_hash_table_insert (session->chats, GINT_TO_POINTER (id), swboard);
msn_switchboard_request (swboard);
return swboard;
}
static const char *get_my_alias(MsnSession *session)
{
const char *alias;
PurpleAccount *account = msn_session_get_user_data(session);
alias = purple_account_get_alias(account);
if (!alias)
alias = purple_connection_get_display_name(account->gc);
if (!alias)
alias = msn_session_get_username(session);
return alias;
}
static void
initiate_chat_cb(PurpleBlistNode *node, gpointer data)
{
PurpleBuddy *buddy;
PurpleConnection *gc;
MsnSession *session;
MsnSwitchBoard *swboard;
g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
buddy = (PurpleBuddy *) node;
gc = purple_account_get_connection(buddy->account);
session = gc->proto_data;
swboard = new_chat (session, session->conv_seq++);
msn_switchboard_request_add_user(swboard, buddy->name);
/* TODO: This might move somewhere else, after USR might be */
swboard->conv = serv_got_joined_chat(gc, swboard->chat_id, "MSN Chat");
purple_conv_chat_add_user(PURPLE_CONV_CHAT(swboard->conv),
get_my_alias(session), NULL, PURPLE_CBFLAGS_NONE, TRUE);
}
#if defined(PECAN_CVR)
static PurpleXfer*
msn_new_xfer(PurpleConnection *gc, const char *who)
{
MsnSession *session;
PurpleXfer *xfer;
session = gc->proto_data;
xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who);
if (!xfer)
return NULL;
xfer->data = msn_session_get_peer_link(session, who); /* temporary */
purple_xfer_set_init_fnc(xfer, purple_pn_xfer_invite);
return xfer;
}
static void
msn_send_file(PurpleConnection *gc, const char *who, const char *file)
{
PurpleXfer *xfer = msn_new_xfer(gc, who);
if (file)
purple_xfer_request_accepted(xfer, file);
else
purple_xfer_request(xfer);
}
static gboolean
msn_can_receive_file(PurpleConnection *gc, const char *who)
{
MsnSession *session;
gchar *normal_who;
gboolean ret;
session = gc->proto_data;
g_return_val_if_fail (session, FALSE);
normal_who = pn_normalize (who);
ret = strcmp(normal_who, msn_session_get_username (session));
g_free (normal_who);
return ret;
}
#endif /* defined(PECAN_CVR) */
/**************************************************************************
* Protocol Plugin ops
**************************************************************************/
static const gchar *
list_icon (PurpleAccount *a,
PurpleBuddy *b)
{
return "msn";
}
static const char *
list_emblems (PurpleBuddy *b)
{
struct pn_contact *contact;
contact = b->proto_data;
if (contact && contact->mobile)
return "mobile";
return NULL;
}
static gchar *
status_text (PurpleBuddy *buddy)
{
struct pn_contact *contact;
contact = buddy->proto_data;
if (!contact)
goto fallback;
if (contact->media.title)
{
switch (contact->media.type)
{
case CURRENT_MEDIA_MUSIC:
{
const gchar *title, *artist, *album;
title = contact->media.title;
artist = contact->media.artist;
album = contact->media.album;
#ifdef ADIUM
return g_strdup_printf ("♫ %s", purple_util_format_song_info (title, artist, album, NULL));
#else
return purple_util_format_song_info (title, artist, album, NULL);
#endif /* ADIUM */
}
case CURRENT_MEDIA_GAMES:
return g_strdup_printf (_("Playing %s"), contact->media.title);
case CURRENT_MEDIA_OFFICE:
return g_strdup_printf (_("Editing %s"), contact->media.title);
default:
break;
}
}
{
const gchar *personal_message;
personal_message = pn_contact_get_personal_message (contact);
if (personal_message)
return g_strdup (personal_message);
}
fallback:
#ifndef ADIUM
{
PurplePresence *presence;
presence = purple_buddy_get_presence (buddy);
if (!purple_presence_is_available (presence) &&
!purple_presence_is_idle (presence))
{
PurpleStatus *status;
status = purple_presence_get_active_status (presence);
return g_strdup (purple_status_get_name (status));
}
}
#endif /* ADIUM */
return NULL;
}
static void
tooltip_text (PurpleBuddy *buddy,
PurpleNotifyUserInfo *user_info,
gboolean full)
{
struct pn_contact *user;
PurplePresence *presence;
PurpleStatus *status;
if (!buddy)
return;
presence = purple_buddy_get_presence (buddy);
status = purple_presence_get_active_status (presence);
user = buddy->proto_data;
if (purple_presence_is_online (presence))
{
purple_notify_user_info_add_pair (user_info, _("Status"),
(purple_presence_is_idle (presence) ? _("Idle") : purple_status_get_name (status)));
}
if (!user)
return;
if (full)
{
if (pn_contact_get_personal_message (user))
{
purple_notify_user_info_add_pair (user_info, _("Personal Message"),
pn_contact_get_personal_message (user));
}
if (user->media.title)
{
if (user->media.type == CURRENT_MEDIA_MUSIC)
{
#ifndef ADIUM
const gchar *title, *artist, *album;
gchar *tmp;
title = user->media.title;
artist = user->media.artist;
album = user->media.album;
tmp = purple_util_format_song_info (title, artist, album, NULL);
purple_notify_user_info_add_pair (user_info, _("Now Listening"), tmp);
g_free(tmp);
#endif /* ADIUM */
}
else if (user->media.type == CURRENT_MEDIA_GAMES)
{
purple_notify_user_info_add_pair (user_info, _("Playing a game"), user->media.title);
}
else if (user->media.type == CURRENT_MEDIA_OFFICE)
{
purple_notify_user_info_add_pair (user_info, _("Working"), user->media.title);
}
}
}
purple_notify_user_info_add_pair (user_info, _("Blocked"),
(pn_contact_is_blocked (user) ? _("Yes") : _("No")));
}
static inline PurpleStatusType *
util_gen_state (PurpleStatusPrimitive primitive,
const gchar *id,
const gchar *name)
{
#ifdef PECAN_USE_PSM
return purple_status_type_new_with_attrs (primitive,
id, name, TRUE, TRUE, FALSE,
"message", _("Message"), purple_value_new (PURPLE_TYPE_STRING),
NULL);
#else
return purple_status_type_new_full (primitive, id, name, TRUE, TRUE, FALSE);
#endif /* PECAN_USE_PSM */
}
static GList *
status_types (PurpleAccount *account)
{
GList *types = NULL;
/* visible states */
types = g_list_append (types, util_gen_state (PURPLE_STATUS_AVAILABLE, NULL, NULL));
types = g_list_append (types, util_gen_state (PURPLE_STATUS_AWAY, NULL, NULL));
types = g_list_append (types, util_gen_state (PURPLE_STATUS_AWAY, "brb", _("Be Right Back")));
types = g_list_append (types, util_gen_state (PURPLE_STATUS_UNAVAILABLE, "busy", _("Busy")));
types = g_list_append (types, util_gen_state (PURPLE_STATUS_UNAVAILABLE, "phone", _("On the Phone")));
types = g_list_append (types, util_gen_state (PURPLE_STATUS_AWAY, "lunch", _("Out to Lunch")));
{
PurpleStatusType *status;
/* non-visible states */
status = purple_status_type_new_full (PURPLE_STATUS_INVISIBLE, NULL, NULL, TRUE, TRUE, FALSE);
types = g_list_append (types, status);
status = purple_status_type_new_full (PURPLE_STATUS_OFFLINE, NULL, NULL, TRUE, TRUE, FALSE);
types = g_list_append (types, status);
/** @todo when do we use this? */
status = purple_status_type_new_full (PURPLE_STATUS_MOBILE, "mobile", NULL, FALSE, FALSE, TRUE);
types = g_list_append (types, status);
status = purple_status_type_new_with_attrs(PURPLE_STATUS_TUNE, "tune", NULL, FALSE, TRUE, TRUE,
PURPLE_TUNE_TITLE, _("Song Title"), purple_value_new (PURPLE_TYPE_STRING),
PURPLE_TUNE_ARTIST, _("Song Artist"), purple_value_new (PURPLE_TYPE_STRING),
PURPLE_TUNE_ALBUM, _("Song Album"), purple_value_new (PURPLE_TYPE_STRING),
"game", _("Game Name"), purple_value_new (PURPLE_TYPE_STRING),
"office", _("Office App Name"), purple_value_new (PURPLE_TYPE_STRING),
NULL);
types = g_list_append(types, status);
}
return types;
}
static GList *
msn_actions(PurplePlugin *plugin, gpointer context)
{
PurpleConnection *gc = (PurpleConnection *)context;
MsnSession *session;
const char *user;
GList *m = NULL;
PurplePluginAction *act;
session = gc->proto_data;
act = purple_plugin_action_new(_("Set Friendly Name..."),
msn_show_set_friendly_name);
m = g_list_append(m, act);
#ifndef PECAN_USE_PSM
act = purple_plugin_action_new(_("Set Personal Message..."),
msn_show_set_personal_message);
m = g_list_append(m, act);
#endif /* PECAN_USE_PSM */
m = g_list_append(m, NULL);
act = purple_plugin_action_new(_("Set Home Phone Number..."),
msn_show_set_home_phone);
m = g_list_append(m, act);
act = purple_plugin_action_new(_("Set Work Phone Number..."),
msn_show_set_work_phone);
m = g_list_append(m, act);
act = purple_plugin_action_new(_("Set Mobile Phone Number..."),
msn_show_set_mobile_phone);
m = g_list_append(m, act);
m = g_list_append(m, NULL);
#if 0
act = purple_plugin_action_new(_("Enable/Disable Mobile Devices..."),
msn_show_set_mobile_support);
m = g_list_append(m, act);
#endif
act = purple_plugin_action_new(_("Allow/Disallow Mobile Pages..."),
msn_show_set_mobile_pages);
m = g_list_append(m, act);
user = msn_session_get_username(session);
if ((strstr(user, "@hotmail.") != NULL) ||
(strstr(user, "@msn.com") != NULL))
{
m = g_list_append(m, NULL);
act = purple_plugin_action_new (_("Open Hotmail Inbox"), show_hotmail_inbox);
m = g_list_append(m, act);
}
return m;
}
static GList *
blist_node_menu (PurpleBlistNode *node)
{
if (!PURPLE_BLIST_NODE_IS_BUDDY (node))
return NULL;
{
PurpleBuddy *buddy;
GList *m = NULL;
PurpleMenuAction *act;
buddy = (PurpleBuddy *) node;
{
struct pn_contact *user;
user = buddy->proto_data;
if (user)
{
if (user->mobile)
{
/** @todo why is there a special way to do this? */
act = purple_menu_action_new (_("Send to Mobile"),
PURPLE_CALLBACK (show_send_to_mobile_cb),
NULL, NULL);
m = g_list_append (m, act);
}
if (!pn_contact_is_account (user))
{
act = purple_menu_action_new (_("Initiate _Chat"),
PURPLE_CALLBACK (initiate_chat_cb),
NULL, NULL);
m = g_list_append(m, act);
}
}
}
return m;
}
}
static void
login (PurpleAccount *account)
{
PurpleConnection *gc;
MsnSession *session;
const char *host;
int port;
gc = purple_account_get_connection (account);
if (!purple_ssl_is_supported ())
{
#if PURPLE_VERSION_CHECK(2,3,0)
purple_connection_error_reason (gc,
PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
_("SSL support is needed for MSN. Please install a supported "
"SSL library."));
#else
purple_connection_error (gc,
_("SSL support is needed for MSN. Please install a supported "
"SSL library."));
#endif
return;
}
host = purple_account_get_string (account, "server", "m1.escargot.log1p.xyz");
port = purple_account_get_int (account, "port", 1863);
session = msn_session_new (purple_account_get_username (account),
purple_account_get_password (account),
purple_account_get_bool (account, "http_method", FALSE));
gc->proto_data = session;
gc->flags |= PURPLE_CONNECTION_HTML | \
PURPLE_CONNECTION_FORMATTING_WBFO | \
PURPLE_CONNECTION_NO_BGCOLOR | \
PURPLE_CONNECTION_NO_FONTSIZE | \
PURPLE_CONNECTION_NO_URLDESC;
#if PURPLE_VERSION_CHECK(2,5,0)
gc->flags |= PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
#endif /* PURPLE_VERSION_CHECK(2,5,0) */
session->user_data = account;
msn_session_set_bool (session, "use_server_alias",
purple_account_get_bool (account, "use_server_alias", FALSE));
#ifdef MSN_DIRECTCONN
msn_session_set_bool (session, "use_direct_conn",
purple_account_get_bool (account, "use_direct_conn", FALSE));
#endif
msn_session_set_bool (session, "use_userdisplay",
purple_account_get_bool (account, "use_userdisplay", TRUE));
session->xfer_invite_cb = purple_pn_xfer_got_invite;
purple_connection_update_progress (gc, _("Connecting"), 1, 2);
if (!msn_session_connect (session, host, port))
purple_connection_error (gc, _("Failed to connect to server."));
}
static void
logout (PurpleConnection *gc)
{
MsnSession *session;
session = gc->proto_data;
g_return_if_fail (session);
msn_session_destroy (session);
gc->proto_data = NULL;
}
#if defined(PECAN_CVR)
#if PURPLE_VERSION_CHECK(2,5,0)
static GString*
msn_msg_emoticon_add(GString *current, MsnEmoticon *emoticon)
{
struct pn_msnobj *obj;
char *strobj;
if (emoticon == NULL)
return current;
obj = emoticon->obj;
if (!obj)
return current;
strobj = pn_msnobj_to_string(obj);
if (current)