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
|
/*
Plugin of Miranda IM for communicating with users of the MSN Messenger protocol.
Copyright (c) 2012-2017 Miranda NG Team
Copyright (c) 2008-2012 Boris Krasnovskiy.
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, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "msn_proto.h"
#include <m_addcontact.h>
#include "m_assocmgr.h"
static MCONTACT GetContact(wchar_t *arg, wchar_t **pemail, CMsnProto *proto)
{
wchar_t* email = NULL;
do {
wchar_t *tok = wcschr(arg, '&'); /* next token */
if (tok != NULL) *tok++ = '\0';
if (wcsnicmp(arg, L"contact=", 8) == 0) {
arg += 8;
UrlDecode(arg);
email = arg;
}
arg = tok;
} while (arg != NULL);
if (email == NULL || email[0] == '\0') {
if (pemail) *pemail = NULL;
return NULL;
}
if (pemail) *pemail = email;
MCONTACT hContact = proto->MSN_HContactFromEmail(UTF8(email), NULL, true, true);
return hContact;
}
/*
add user: msnim:add?contact=netpassport@emailaddress.com
send message: msnim:chat?contact=netpassport@emailaddress.com
voice chat: msnim:voice?contact=netpassport@emailaddress.com
video chat: msnim:video?contact=netpassport@emailaddress.com
*/
static INT_PTR ServiceParseMsnimLink(WPARAM, LPARAM lParam)
{
if (lParam == 0) return 1; /* sanity check */
wchar_t *arg = (wchar_t*)lParam;
/* skip leading prefix */
arg = wcschr(arg, ':');
if (arg == NULL) return 1; /* parse failed */
for (++arg; *arg == '/'; ++arg) {}
arg = NEWWSTR_ALLOCA(arg);
if (g_Instances.getCount() == 0) return 0;
CMsnProto *proto = &g_Instances[0];
for (int i = 0; i < g_Instances.getCount(); ++i) {
if (g_Instances[i].m_iStatus > ID_STATUS_OFFLINE) {
proto = &g_Instances[i];
break;
}
}
if (proto == NULL) return 1;
/* add a contact to the list */
if (wcsnicmp(arg, L"add?", 4) == 0) {
arg += 4;
wchar_t *email;
MCONTACT hContact = GetContact(arg, &email, proto);
if (email == NULL) return 1;
/* does not yet check if email is current user */
if (hContact == NULL) {
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_UNICODE;
psr.nick.w = email;
psr.email.w = email;
ADDCONTACTSTRUCT acs = { 0 };
acs.handleType = HANDLE_SEARCHRESULT;
acs.szProto = proto->m_szModuleName;
acs.psr = &psr;
CallService(MS_ADDCONTACT_SHOW, 0, (LPARAM)&acs);
}
return 0;
}
/* send a message to a contact */
/* "voice" and "video" not yet implemented, perform same action as "chat" */
else if (wcsnicmp(arg, L"chat?", 5) == 0) {
arg += 5;
MCONTACT hContact = GetContact(arg, NULL, proto);
if (hContact != NULL) {
CallService(MS_MSG_SENDMESSAGE, hContact, 0);
return 0;
}
}
else if (wcsnicmp(arg, L"voice?", 6) == 0) {
arg += 6;
MCONTACT hContact = GetContact(arg, NULL, proto);
if (hContact != NULL) {
CallService(MS_MSG_SENDMESSAGE, hContact, 0);
return 0;
}
}
else if (wcsnicmp(arg, L"video?", 6) == 0) {
arg += 6;
MCONTACT hContact = GetContact(arg, NULL, proto);
if (hContact != NULL) {
CallService(MS_MSG_SENDMESSAGE, hContact, 0);
return 0;
}
}
return 1; /* parse failed */
}
void MsnLinks_Init(void)
{
static const char szService[] = "MSN/ParseMsnimLink";
CreateServiceFunction(szService, ServiceParseMsnimLink);
AssocMgr_AddNewUrlTypeT("msnim:", TranslateT("MSN Link Protocol"), g_hInst, IDI_MSN, szService, 0);
}
void MsnLinks_Destroy(void)
{
CallService(MS_ASSOCMGR_REMOVEURLTYPE, 0, (LPARAM)"msnim:");
}
|