summaryrefslogtreecommitdiff
path: root/protocols/MSN
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-05-27 21:30:30 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-05-27 21:30:30 +0000
commit8549e48fbb8520027d4d8ba74b6f12f3042faebc (patch)
treef4aa951f6c13d179ca711ae5977eb38698dcaf52 /protocols/MSN
parentd27904ad1988ba6f85228f3c0cb7de8379a3147b (diff)
ipv6 sync
git-svn-id: http://svn.miranda-ng.org/main/trunk@205 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/MSN')
-rw-r--r--protocols/MSN/msn_commands.cpp30
-rw-r--r--protocols/MSN/msn_global.h1
-rw-r--r--protocols/MSN/msn_mime.cpp2
-rw-r--r--protocols/MSN/msn_misc.cpp106
-rw-r--r--protocols/MSN/msn_p2p.cpp311
-rw-r--r--protocols/MSN/msn_proto.h2
6 files changed, 239 insertions, 213 deletions
diff --git a/protocols/MSN/msn_commands.cpp b/protocols/MSN/msn_commands.cpp
index 04d2ad7981..a85ff46fe4 100644
--- a/protocols/MSN/msn_commands.cpp
+++ b/protocols/MSN/msn_commands.cpp
@@ -30,30 +30,20 @@ void MSN_ConnectionProc(HANDLE hNewConnection, DWORD /* dwRemoteIP */, void* ext
proto->MSN_DebugLog("File transfer connection accepted");
- WORD localPort = 0;
- SOCKET s = MSN_CallService(MS_NETLIB_GETSOCKET, (WPARAM)hNewConnection, 0);
- if (s != INVALID_SOCKET)
+ NETLIBCONNINFO connInfo = { sizeof(connInfo) };
+ CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hNewConnection, (LPARAM)&connInfo);
+
+ ThreadData* T = proto->MSN_GetThreadByPort(connInfo.wPort);
+ if (T != NULL && T->s == NULL)
{
- SOCKADDR_IN saddr;
- int len = sizeof(saddr);
- if (getsockname(s, (SOCKADDR*)&saddr, &len) != SOCKET_ERROR)
- localPort = ntohs(saddr.sin_port);
+ T->s = hNewConnection;
+ ReleaseSemaphore(T->hWaitEvent, 1, NULL);
}
-
- if (localPort != 0)
+ else
{
- ThreadData* T = proto->MSN_GetThreadByPort(localPort);
- if (T != NULL && T->s == NULL)
- {
- T->s = hNewConnection;
- ReleaseSemaphore(T->hWaitEvent, 1, NULL);
- return;
- }
- proto->MSN_DebugLog("There's no registered file transfers for incoming port #%d, connection closed", localPort);
+ proto->MSN_DebugLog("There's no registered file transfers for incoming port #%u, connection closed", connInfo.wPort);
+ Netlib_CloseHandle(hNewConnection);
}
- else proto->MSN_DebugLog("Unable to determine the local port, file server connection closed.");
-
- Netlib_CloseHandle(hNewConnection);
}
diff --git a/protocols/MSN/msn_global.h b/protocols/MSN/msn_global.h
index 317b834afa..a2c1ba6dd6 100644
--- a/protocols/MSN/msn_global.h
+++ b/protocols/MSN/msn_global.h
@@ -167,6 +167,7 @@ void stripColorCode(char* src);
void parseWLID(char* wlid, char** net, char** email, char** inst);
char* MSN_Base64Decode(const char* str);
+char* GetGlobalIp(void);
template <class chartype> void UrlDecode(chartype* str);
diff --git a/protocols/MSN/msn_mime.cpp b/protocols/MSN/msn_mime.cpp
index 8351673308..b925e101bb 100644
--- a/protocols/MSN/msn_mime.cpp
+++ b/protocols/MSN/msn_mime.cpp
@@ -71,6 +71,8 @@ unsigned MimeHeaders::allocSlot(void)
void MimeHeaders::addString(const char* name, const char* szValue, unsigned flags)
{
+ if (szValue == NULL) return;
+
MimeHeader& H = mVals[allocSlot()];
H.name = name;
H.value = szValue;
diff --git a/protocols/MSN/msn_misc.cpp b/protocols/MSN/msn_misc.cpp
index 0780361b2c..80d9fd46ec 100644
--- a/protocols/MSN/msn_misc.cpp
+++ b/protocols/MSN/msn_misc.cpp
@@ -125,7 +125,7 @@ void CMsnProto::MSN_AddAuthRequest(const char *email, const char *nick, const c
//blob is: UIN=0(DWORD), hContact(DWORD), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), email(ASCIIZ), ""(ASCIIZ)
HANDLE hContact = MSN_HContactFromEmail(email, nick, true, true);
-
+
int emaillen = (int)strlen(email);
if (nick == NULL) nick = "";
@@ -294,7 +294,7 @@ void CMsnProto::MSN_GetAvatarFileName(HANDLE hContact, TCHAR* pszDest, size_t c
} while(_tfindnext(hFile, &c_file) == 0);
_findclose( hFile );
}
-
+
if (!found) pszDest[0] = 0;
}
else
@@ -334,17 +334,17 @@ int MSN_GetImageFormat(void* buf, const TCHAR** ext)
int MSN_GetImageFormat(const TCHAR* file)
{
- const TCHAR *ext = _tcsrchr(file, '.');
- if (ext == NULL)
- return PA_FORMAT_UNKNOWN;
- if (_tcsicmp(ext, _T(".gif")) == 0)
- return PA_FORMAT_GIF;
- else if (_tcsicmp(ext, _T(".bmp")) == 0)
- return PA_FORMAT_BMP;
- else if (_tcsicmp(ext, _T(".png")) == 0)
- return PA_FORMAT_PNG;
- else
- return PA_FORMAT_JPEG;
+ const TCHAR *ext = _tcsrchr(file, '.');
+ if (ext == NULL)
+ return PA_FORMAT_UNKNOWN;
+ if (_tcsicmp(ext, _T(".gif")) == 0)
+ return PA_FORMAT_GIF;
+ else if (_tcsicmp(ext, _T(".bmp")) == 0)
+ return PA_FORMAT_BMP;
+ else if (_tcsicmp(ext, _T(".png")) == 0)
+ return PA_FORMAT_PNG;
+ else
+ return PA_FORMAT_JPEG;
}
int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen)
@@ -363,10 +363,10 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen
NETLIBBASE64 nlb = { szSha1d, sizeof(szSha1d), (PBYTE)sha1d, sizeof(sha1d) };
MSN_CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
}
-
+
mir_sha1_init(&sha1ctx);
ezxml_t xmlp = ezxml_new("msnobj");
-
+
mir_sha1_append(&sha1ctx, (PBYTE)"Creator", 7);
mir_sha1_append(&sha1ctx, (PBYTE)MyOptions.szEmail, (int)strlen(MyOptions.szEmail));
ezxml_set_attr(xmlp, "Creator", MyOptions.szEmail);
@@ -392,15 +392,15 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen
mir_sha1_append(&sha1ctx, (PBYTE)"SHA1D", 5);
mir_sha1_append(&sha1ctx, (PBYTE)szSha1d, (int)strlen(szSha1d));
ezxml_set_attr(xmlp, "SHA1D", szSha1d);
-
+
mir_sha1_finish(&sha1ctx, sha1c);
{
NETLIBBASE64 nlb = { szSha1c, sizeof(szSha1c), (PBYTE)sha1c, sizeof(sha1c) };
MSN_CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
}
-
-// ezxml_set_attr(xmlp, "SHA1C", szSha1c);
+
+ // ezxml_set_attr(xmlp, "SHA1C", szSha1c);
char* szBuffer = ezxml_toxml(xmlp, false);
ezxml_free(xmlp);
@@ -475,7 +475,7 @@ void CMsnProto::MSN_GetCustomSmileyFileName(HANDLE hContact, TCHAR* pszDest, si
dbv.ptszVal = (TCHAR*)mir_alloc(11);
_ui64tot((UINT_PTR)hContact, dbv.ptszVal, 10);
}
-
+
tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), dbv.ptszVal);
DBFreeVariant(&dbv);
}
@@ -485,9 +485,9 @@ void CMsnProto::MSN_GetCustomSmileyFileName(HANDLE hContact, TCHAR* pszDest, si
tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), tszModuleName);
mir_free(tszModuleName);
}
-
+
bool exist = _taccess(pszDest, 0) == 0;
-
+
if (type == 0)
{
if (!exist) pszDest[0] = 0;
@@ -607,10 +607,10 @@ int ThreadData::sendMessage(int msgType, const char* email, int netId, const cha
int seq;
if (netId == NETID_YAHOO || netId == NETID_MOB || (parFlags & MSG_OFFLINE))
seq = sendPacket("UUM", "%s %d %c %d\r\n%s%s", email, netId, msgType,
- strlen(parMsg)+off, buf, parMsg);
+ strlen(parMsg)+off, buf, parMsg);
else
seq = sendPacket("MSG", "%c %d\r\n%s%s", msgType,
- strlen(parMsg)+off, buf, parMsg);
+ strlen(parMsg)+off, buf, parMsg);
return seq;
}
@@ -699,8 +699,8 @@ void CMsnProto::MSN_StartStopTyping(ThreadData* info, bool start)
MSN_SendTyping(info, NULL, 1);
}
else if (!start && info->mTimerId != 0) {
- KillTimer(NULL, info->mTimerId);
- info->mTimerId = 0;
+ KillTimer(NULL, info->mTimerId);
+ info->mTimerId = 0;
}
}
@@ -770,10 +770,10 @@ void CMsnProto::MSN_SendStatusMessage(const char* msg)
sz = mir_snprintf(szMsg, sizeof szMsg,
"<Data>"
- "<PSM>%s</PSM>"
- "<CurrentMedia>%s\\0%s\\01\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0\\0</CurrentMedia>"
- "<MachineGuid>%s</MachineGuid><DDP></DDP><SignatureSound></SignatureSound><Scene></Scene><ColorScheme></ColorScheme>"
- "<DDP></DDP><SignatureSound></SignatureSound><Scene></Scene><ColorScheme></ColorScheme>"
+ "<PSM>%s</PSM>"
+ "<CurrentMedia>%s\\0%s\\01\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0%s\\0\\0</CurrentMedia>"
+ "<MachineGuid>%s</MachineGuid><DDP></DDP><SignatureSound></SignatureSound><Scene></Scene><ColorScheme></ColorScheme>"
+ "<DDP></DDP><SignatureSound></SignatureSound><Scene></Scene><ColorScheme></ColorScheme>"
"</Data>",
msgEnc, szPlayer, szType, szFormatEnc, szTitle, szArtist, szAlbum, szTrack, szYear, szGenre,
szLength, szPlayer, szType, MyOptions.szMachineGuid);
@@ -856,7 +856,7 @@ void CMsnProto::MSN_SetServerStatus(int newStatus)
{
DBVARIANT msnObject = {0};
if (ServiceExists(MS_AV_SETMYAVATAR))
- getString("PictObject", &msnObject);
+ getString("PictObject", &msnObject);
// Capabilties: WLM 2009, Chunking, UUN Bootstrap
myFlags = 0xA0000000 | cap_SupportsChunking | cap_SupportsP2PBootstrap | cap_SupportsSipInvite;
@@ -898,10 +898,10 @@ void CMsnProto::MSN_SetServerStatus(int newStatus)
int sz = mir_snprintf(szMsg, sizeof(szMsg),
"<PrivateEndpointData>"
- "<EpName>%s</EpName>"
- "<Idle>%s</Idle>"
- "<ClientType>1</ClientType>"
- "<State>%s</State>"
+ "<EpName>%s</EpName>"
+ "<Idle>%s</Idle>"
+ "<ClientType>1</ClientType>"
+ "<State>%s</State>"
"</PrivateEndpointData>",
szPlace, newStatus == ID_STATUS_IDLE ? "true" : "false", szStatusName);
msnNsThread->sendPacket("UUX", "%d\r\n%s", sz, szMsg);
@@ -932,7 +932,7 @@ void CMsnProto::MsnInvokeMyURL(bool ismail, const char* url)
static const char postdataM[] = "ct=%u&bver=7&wa=wsignin1.0&ru=%s&pl=MBI";
static const char postdataS[] = "ct=%u&bver=7&id=73625&ru=%s&js=yes&pl=%%3Fid%%3D73625";
const char *postdata = ismail ? postdataM : postdataS;
-
+
char passport[256];
if (getStaticString(NULL, "MsnPassportHost", passport, 256))
strcpy(passport, "https://login.live.com/");
@@ -943,7 +943,7 @@ void CMsnProto::MsnInvokeMyURL(bool ismail, const char* url)
char ruenc[256];
UrlEncode(url, ruenc, sizeof(ruenc));
-
+
const size_t fnpstlen = strlen(postdata) + strlen(ruenc) + 30;
char* fnpst = (char*)alloca(fnpstlen);
@@ -1121,7 +1121,7 @@ void CALLBACK sttMainThreadCallback(PVOID dwParam)
ppd.ptszText = pud->text;
ppd.PluginData = pud;
ppd.pszClassName = name;
-
+
if (pud->flags & MSN_SHOW_ERROR)
mir_snprintf(name, SIZEOF(name), "%s_%s", pud->proto->m_szModuleName, "Error");
else if (pud->flags & (MSN_HOTMAIL_POPUP | MSN_ALERT_POPUP))
@@ -1228,8 +1228,8 @@ int filetransfer::create(void)
if (fileId == -1)
proto->MSN_ShowError("Cannot create file '%s' during a file transfer", std.tszCurrentFile);
-// else if (std.currentFileSize != 0)
-// _chsize(fileId, std.currentFileSize);
+ // else if (std.currentFileSize != 0)
+ // _chsize(fileId, std.currentFileSize);
return fileId;
}
@@ -1261,7 +1261,7 @@ int filetransfer::openNext(void)
{
std.currentFileSize = _filelengthi64(fileId);
std.currentFileProgress = 0;
-
+
p2p_sendmsgid = 0;
p2p_byemsgid = 0;
tType = SERVER_NOTIFICATION;
@@ -1343,8 +1343,7 @@ void directconnection::xNonceToBin(UUID* nonce)
/////////////////////////////////////////////////////////////////////////////////////////
// TWinErrorCode class
-TWinErrorCode::TWinErrorCode() :
- mErrorText(NULL)
+TWinErrorCode::TWinErrorCode() : mErrorText(NULL)
{
mErrorCode = ::GetLastError();
}
@@ -1363,8 +1362,8 @@ char* TWinErrorCode::getText()
if (tBytes == 0)
tBytes = FormatMessageA(
- FORMAT_MESSAGE_FROM_SYSTEM, NULL,
- mErrorCode, LANG_NEUTRAL, mErrorText, 256, NULL);
+ FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+ mErrorCode, LANG_NEUTRAL, mErrorText, 256, NULL);
if (tBytes == 0)
{
@@ -1424,14 +1423,14 @@ bool CMsnProto::MSN_IsMeByContact(HANDLE hContact, char* szEmail)
*emailPtr = 0;
if (getStaticString(hContact, "e-mail", emailPtr, sizeof(tEmail)))
return false;
-
+
return _stricmp(emailPtr, MyOptions.szEmail) == 0;
}
bool MSN_MsgWndExist(HANDLE hContact)
{
MessageWindowInputData msgWinInData =
- { sizeof(MessageWindowInputData), hContact, MSG_WINDOW_UFLAG_MSG_BOTH };
+ { sizeof(MessageWindowInputData), hContact, MSG_WINDOW_UFLAG_MSG_BOTH };
MessageWindowData msgWinData = {0};
msgWinData.cbSize = sizeof(MessageWindowData);
@@ -1471,7 +1470,8 @@ void MSN_MakeDigest(const char* chl, char* dgst)
LONGLONG high=0, low=0;
int* chlStringArray = (int*)chlString;
- for (i=0; i < strlen(chlString)/4; i += 2) {
+ for (i=0; i < strlen(chlString) / 4; i += 2)
+ {
LONGLONG temp = chlStringArray[i];
temp = (0x0E79A9C1 * temp) % 0x7FFFFFFF;
@@ -1498,3 +1498,15 @@ void MSN_MakeDigest(const char* chl, char* dgst)
strcpy(dgst, str);
mir_free(str);
}
+
+char* GetGlobalIp(void)
+{
+ NETLIBIPLIST* ihaddr = (NETLIBIPLIST*)CallService(MS_NETLIB_GETMYIP, 1, 0);
+ for (unsigned i = 0; i < ihaddr->cbNum; ++i)
+ {
+ if (strchr(ihaddr->szIp[i], ':'))
+ return mir_strdup(ihaddr->szIp[i]);
+ }
+ mir_free(ihaddr);
+ return NULL;
+}
diff --git a/protocols/MSN/msn_p2p.cpp b/protocols/MSN/msn_p2p.cpp
index 1e3215b2e5..9c805eb530 100644
--- a/protocols/MSN/msn_p2p.cpp
+++ b/protocols/MSN/msn_p2p.cpp
@@ -81,7 +81,7 @@ void P2PV2_Header::logHeader(CMsnProto *ppro)
bool CMsnProto::p2p_createListener(filetransfer* ft, directconnection *dc, MimeHeaders& chdrs)
{
if (MyConnection.extIP == 0) return false;
-
+
NETLIBBIND nlb = {0};
nlb.cbSize = sizeof(nlb);
nlb.pfnNewConnectionV2 = MSN_ConnectionProc;
@@ -103,22 +103,29 @@ bool CMsnProto::p2p_createListener(filetransfer* ft, directconnection *dc, MimeH
newThread->startThread(&CMsnProto::p2p_filePassiveThread, this);
- char hostname[256] = "";
-
- gethostname(hostname, sizeof(hostname));
- PHOSTENT he = gethostbyname(hostname);
+ char szIpv4[256] = "";
+ char szIpv6[256] = "";
+ const char *szExtIp = MyConnection.GetMyExtIPStr();
- hostname[0] = 0;
bool ipInt = false;
- for (unsigned i = 0; i < sizeof(hostname) / 16; ++i)
- {
- const PIN_ADDR addr = (PIN_ADDR)he->h_addr_list[i];
+ int i4 = 0, i6 = 0;
- if (addr == NULL) break;
- if (i != 0) strcat(hostname, " ");
- ipInt |= (addr->S_un.S_addr == MyConnection.extIP);
- strcat(hostname, inet_ntoa(*addr));
+ NETLIBIPLIST* ihaddr = (NETLIBIPLIST*)CallService(MS_NETLIB_GETMYIP, 1, 0);
+ for (unsigned i = 0; i < ihaddr->cbNum; ++i)
+ {
+ if (strchr(ihaddr->szIp[i], ':'))
+ {
+ if (i6++ != 0) strcat(szIpv6, " ");
+ strcat(szIpv6, ihaddr->szIp[i]);
+ }
+ else
+ {
+ if (i4++ != 0) strcat(szIpv4, " ");
+ ipInt |= (strcmp(ihaddr->szIp[i], szExtIp) == 0);
+ strcat(szIpv4, ihaddr->szIp[i]);
+ }
}
+ mir_free(ihaddr);
chdrs.addString("Bridge", "TCPv1");
chdrs.addBool("Listening", true);
@@ -135,8 +142,13 @@ bool CMsnProto::p2p_createListener(filetransfer* ft, directconnection *dc, MimeH
chdrs.addString("IPv4External-Addrs", mir_strdup(MyConnection.GetMyExtIPStr()), bUbnCall ? 6 : 2);
chdrs.addLong("IPv4External-Port", nlb.wExPort, bUbnCall ? 4 : 0);
}
- chdrs.addString("IPv4Internal-Addrs", mir_strdup(hostname), bUbnCall ? 6 : 2);
+ chdrs.addString("IPv4Internal-Addrs", mir_strdup(szIpv4), bUbnCall ? 6 : 2);
chdrs.addLong("IPv4Internal-Port", nlb.wPort, bUbnCall ? 4 : 0);
+ if (szIpv6[0])
+ {
+ chdrs.addString("IPv6-Addrs", mir_strdup(szIpv6), 2);
+ chdrs.addLong("IPv6-Port", nlb.wPort);
+ }
chdrs.addULong("SessionID", ft->p2p_sessionid);
chdrs.addString("SChannelState", "0");
chdrs.addString("Capabilities-Flags", "1");
@@ -382,19 +394,19 @@ void CMsnProto::p2p_sendMsg(ThreadData* info, const char *wlid, unsigned appId,
char* szEmail;
switch (msgType)
{
- case 0:
- parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL);
- MsgQueue_Add(szEmail, 'D', buf, p - buf);
- break;
+ case 0:
+ parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL);
+ MsgQueue_Add(szEmail, 'D', buf, p - buf);
+ break;
- case 1:
- *(unsigned*)buf = (unsigned)(p - buf - sizeof(unsigned));
- info->send(buf, p - buf);
- break;
+ case 1:
+ *(unsigned*)buf = (unsigned)(p - buf - sizeof(unsigned));
+ info->send(buf, p - buf);
+ break;
- case 2:
- info->sendRawMessage('D', buf, p - buf);
- break;
+ case 2:
+ info->sendRawMessage('D', buf, p - buf);
+ break;
}
offset += portion;
}
@@ -522,7 +534,7 @@ void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders,
case 1603: p += sprintf(p, "MSNSLP/1.0 603 Decline"); break;
default: return;
}
-
+
if (iKind < 0)
{
mir_free(ft->p2p_branch);
@@ -565,9 +577,9 @@ void CMsnProto::p2p_sendSlp(int iKind, filetransfer *ft, MimeHeaders &pHeaders,
switch (iKind)
{
- case -1: case 500: case 603:
- ft->p2p_byemsgid = tHdr.mID;
- break;
+ case -1: case 500: case 603:
+ ft->p2p_byemsgid = tHdr.mID;
+ break;
}
}
@@ -622,7 +634,7 @@ void CMsnProto::p2p_sendNoCall(filetransfer* ft)
MSN_DebugLog(sttVoidSession);
return;
}
-
+
MimeHeaders tHeaders(8);
tHeaders.addString("CSeq", "0 ");
tHeaders.addString("Call-ID", ft->p2p_callID);
@@ -882,7 +894,7 @@ LONG CMsnProto::p2p_sendPortion(filetransfer* ft, ThreadData* T, bool isV2)
// Compute the amount of data to send
unsigned fportion = T->mType == SERVER_P2P_DIRECT ? 1352 : 1202;
if (isV2) fportion += 4;
-
+
const unsigned __int64 dt = ft->std.currentFileSize - ft->std.currentFileProgress;
const unsigned portion = dt > fportion ? fportion : dt;
@@ -975,9 +987,9 @@ void __cdecl CMsnProto::p2p_sendFeedThread(void* arg)
switch(WaitForSingleObject(info->hWaitEvent, 6000))
{
- case WAIT_FAILED:
- MSN_DebugLog("File send wait failed");
- return;
+ case WAIT_FAILED:
+ MSN_DebugLog("File send wait failed");
+ return;
}
HANDLE hLockHandle = NULL;
@@ -1036,7 +1048,7 @@ void __cdecl CMsnProto::p2p_sendFeedThread(void* arg)
WaitForSingleObject(T->hWaitEvent, 5000);
}
ReleaseMutex(hLockHandle);
-
+
if (ft->p2p_appID == MSN_APPID_FILE)
SendBroadcast(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std);
@@ -1213,7 +1225,7 @@ void CMsnProto::p2p_InitFileTransfer(
replaceStr(ft->p2p_branch, szBranch);
ft->p2p_dest = mir_strdup(wlid);
ft->p2p_isV2 = strchr(wlid, ';') != NULL;
- ft->std.hContact = MSN_HContactFromEmail(wlid);
+ ft->std.hContact = MSN_HContactFromEmail(wlid);
p2p_registerSession(ft);
@@ -1292,15 +1304,14 @@ void CMsnProto::p2p_InitFileTransfer(
if (!_stricmp(szEufGuid, "{5D3E02AB-6190-11D3-BBBB-00C04F795683}"))
{
wchar_t* wszFileName = ((HFileContext*)szContext)->wszFileName;
- { for (wchar_t* p = wszFileName; *p != 0; p++)
- {
- switch(*p)
- {
- case ':': case '?': case '/': case '\\': case '*':
- *p = '_';
- }
+ for (wchar_t* p = wszFileName; *p != 0; p++)
+ {
+ switch(*p)
+ {
+ case ':': case '?': case '/': case '\\': case '*':
+ *p = '_';
}
- }
+ }
mir_free(ft->std.tszCurrentFile);
ft->std.tszCurrentFile = mir_u2t(wszFileName);
@@ -1363,12 +1374,12 @@ void CMsnProto::p2p_InitFileTransfer(
void CMsnProto::p2p_InitDirectTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid)
{
- const char *szCallID = tFileInfo["Call-ID"],
- *szBranch = tFileInfo["Via"],
- *szConnType = tFileInfo2["Conn-Type"],
- *szUPnPNat = tFileInfo2["UPnPNat"],
- *szNetID = tFileInfo2["NetID"],
- *szICF = tFileInfo2["ICF"],
+ const char *szCallID = tFileInfo["Call-ID"],
+ *szBranch = tFileInfo["Via"],
+ *szConnType = tFileInfo2["Conn-Type"],
+ *szUPnPNat = tFileInfo2["UPnPNat"],
+ *szNetID = tFileInfo2["NetID"],
+ *szICF = tFileInfo2["ICF"],
*szHashedNonce = tFileInfo2["Hashed-Nonce"];
if (szBranch != NULL)
@@ -1408,8 +1419,8 @@ void CMsnProto::p2p_InitDirectTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFil
/*
if (p2p_isAvatarOnly(ft->std.hContact))
{
- // p2p_sendStatus(ft, 1603);
- // return;
+ p2p_sendStatus(ft, 1603);
+ return;
}
else
SendBroadcast(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0);
@@ -1475,7 +1486,7 @@ void CMsnProto::p2p_InitDirectTransfer(MimeHeaders& tFileInfo, MimeHeaders& tFil
}
-void CMsnProto::p2p_startConnect(const char* wlid, const char* szCallID, const char* addr, const char* port)
+void CMsnProto::p2p_startConnect(const char* wlid, const char* szCallID, const char* addr, const char* port, bool ipv6)
{
if (port == NULL) return;
@@ -1489,7 +1500,8 @@ void CMsnProto::p2p_startConnect(const char* wlid, const char* szCallID, const c
newThread->mType = SERVER_P2P_DIRECT;
newThread->mInitialContactWLID = mir_strdup(wlid);
mir_snprintf(newThread->mCookie, sizeof(newThread->mCookie), "%s", szCallID);
- mir_snprintf(newThread->mServer, sizeof(newThread->mServer), "%s:%s", addr, port);
+ mir_snprintf(newThread->mServer, sizeof(newThread->mServer),
+ ipv6 ? "[%s]:%s" : "%s:%s", addr, port);
newThread->startThread(&CMsnProto::p2p_fileActiveThread, this);
@@ -1499,14 +1511,16 @@ void CMsnProto::p2p_startConnect(const char* wlid, const char* szCallID, const c
void CMsnProto::p2p_InitDirectTransfer2(MimeHeaders& tFileInfo, MimeHeaders& tFileInfo2, const char* wlid)
{
- const char *szCallID = tFileInfo["Call-ID"],
+ const char *szCallID = tFileInfo["Call-ID"],
*szInternalAddress = tFileInfo2["IPv4Internal-Addrs"],
- *szInternalPort = tFileInfo2["IPv4Internal-Port"],
+ *szInternalPort = tFileInfo2["IPv4Internal-Port"],
*szExternalAddress = tFileInfo2["IPv4External-Addrs"],
- *szExternalPort = tFileInfo2["IPv4External-Port"],
- *szNonce = tFileInfo2["Nonce"],
- *szHashedNonce = tFileInfo2["Hashed-Nonce"],
- *szListening = tFileInfo2["Listening"];
+ *szExternalPort = tFileInfo2["IPv4External-Port"],
+ *szNonce = tFileInfo2["Nonce"],
+ *szHashedNonce = tFileInfo2["Hashed-Nonce"],
+ *szListening = tFileInfo2["Listening"],
+ *szV6Address = tFileInfo2["IPv6-Addrs"],
+ *szV6Port = tFileInfo2["IPv6-Port" ];
if ((szNonce == NULL && szHashedNonce == NULL) || szListening == NULL)
{
@@ -1526,8 +1540,9 @@ void CMsnProto::p2p_InitDirectTransfer2(MimeHeaders& tFileInfo, MimeHeaders& tFi
if (!strcmp(szListening, "true") && strcmp(dc->xNonce, sttVoidUid))
{
- p2p_startConnect(wlid, szCallID, szInternalAddress, szInternalPort);
- p2p_startConnect(wlid, szCallID, szExternalAddress, szExternalPort);
+ p2p_startConnect(wlid, szCallID, szV6Address, szV6Port, true);
+ p2p_startConnect(wlid, szCallID, szInternalAddress, szInternalPort, false);
+ p2p_startConnect(wlid, szCallID, szExternalAddress, szExternalPort, false);
}
}
@@ -1622,6 +1637,7 @@ LBL_Close:
chdrs.addString("Conn-Type", MyConnection.GetMyUdpConStr());
chdrs.addBool("UPnPNat", MyConnection.upnpNAT);
chdrs.addBool("ICF", MyConnection.icf);
+ chdrs.addString("IPv6-global", GetGlobalIp(), 2);
chdrs.addString("Hashed-Nonce", dc->mNonceToHash(), 2);
}
else if (!strcmp(szOldContentType, "application/x-msnmsgr-transrespbody"))
@@ -1632,7 +1648,10 @@ LBL_Close:
*szExternalAddress = tFileInfo2["IPv4External-Addrs"],
*szExternalPort = tFileInfo2["IPv4External-Port" ],
*szInternalAddress = tFileInfo2["IPv4Internal-Addrs"],
- *szInternalPort = tFileInfo2["IPv4Internal-Port" ];
+ *szInternalPort = tFileInfo2["IPv4Internal-Port" ],
+ *szV6Address = tFileInfo2["IPv6-Addrs"],
+ *szV6Port = tFileInfo2["IPv6-Port" ];
+
if ((szNonce == NULL && szHashedNonce == NULL) || szListening == NULL)
{
MSN_DebugLog("Invalid data packet, exiting...");
@@ -1653,8 +1672,9 @@ LBL_Close:
// another side reported that it will be a server.
if (!strcmp(szListening, "true") && (szNonce == NULL || strcmp(szNonce, sttVoidUid)))
{
- p2p_startConnect(ft->p2p_dest, szCallID, szInternalAddress, szInternalPort);
- p2p_startConnect(ft->p2p_dest, szCallID, szExternalAddress, szExternalPort);
+ p2p_startConnect(ft->p2p_dest, szCallID, szV6Address, szV6Port, true);
+ p2p_startConnect(ft->p2p_dest, szCallID, szInternalAddress, szInternalPort, false);
+ p2p_startConnect(ft->p2p_dest, szCallID, szExternalAddress, szExternalPort, false);
return;
}
@@ -1788,8 +1808,8 @@ void CMsnProto::p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdr
const char* callID = tFileInfo["Call-ID"];
// application/x-msnmsgr-session-failure-respbody
-
- directconnection *dc = p2p_getDCByCallID(callID, wlid);
+
+ directconnection *dc = p2p_getDCByCallID(callID, wlid);
if (dc != NULL)
{
p2p_unregisterDC(dc);
@@ -1830,7 +1850,7 @@ void CMsnProto::p2p_processSIP(ThreadData* info, char* msgbody, P2PB_Header* hdr
void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char* wlid)
{
P2PV2_Header hdrdata;
-
+
char *msg = hdrdata.parseMsg(msgbody);
hdrdata.logHeader(this);
@@ -1864,7 +1884,7 @@ void CMsnProto::p2p_processMsgV2(ThreadData* info, char* msgbody, const char*
if (hdrdata.mRemSize == 0)
{
- size_t newsize;
+ size_t newsize;
if (getCachedMsg(idx, msgbody, newsize))
{
unsigned id = hdrdata.mID;
@@ -1942,9 +1962,9 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wl
//---- if we got a message
if (LOWORD(hdrdata.mFlags) == 0 && hdrdata.mSessionID == 0)
{
-// MsnContact *cont = Lists_Get(wlid);
-// if (cont && cont->places.getCount())
-// return;
+ // MsnContact *cont = Lists_Get(wlid);
+ // if (cont && cont->places.getCount())
+ // return;
if (hdrdata.mPacketLen < hdrdata.mTotalSize)
{
@@ -2039,7 +2059,7 @@ void CMsnProto::p2p_processMsg(ThreadData* info, char* msgbody, const char* wl
if (LOWORD(hdrdata.mFlags) == 0)
{
//---- accept the data preparation message ------
-// const unsigned* pLongs = (unsigned*)msgbody;
+ // const unsigned* pLongs = (unsigned*)msgbody;
if (hdrdata.mPacketLen == 4 && hdrdata.mTotalSize == 4)
{
p2p_sendAck(ft->p2p_dest, &hdrdata);
@@ -2151,84 +2171,84 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid)
switch (iAppID)
{
- case MSN_APPID_FILE:
+ case MSN_APPID_FILE:
+ {
+ cbContext = sizeof(HFileContext);
+ pContext = (char*)malloc(cbContext);
+ HFileContext* ctx = (HFileContext*)pContext;
+ memset(pContext, 0, cbContext);
+ if (ft->p2p_isV2)
{
- cbContext = sizeof(HFileContext);
- pContext = (char*)malloc(cbContext);
- HFileContext* ctx = (HFileContext*)pContext;
- memset(pContext, 0, cbContext);
- if (ft->p2p_isV2)
- {
- cbContext -= 64;
- ctx->ver = 2;
- }
- else
- {
- ctx->ver = 3;
- ctx->id = 0xffffffff;
- }
- ctx->len = (unsigned)cbContext;
- ctx->type = MSN_TYPEID_FTNOPREVIEW;
- ctx->dwSize = ft->std.currentFileSize;
+ cbContext -= 64;
+ ctx->ver = 2;
+ }
+ else
+ {
+ ctx->ver = 3;
+ ctx->id = 0xffffffff;
+ }
+ ctx->len = (unsigned)cbContext;
+ ctx->type = MSN_TYPEID_FTNOPREVIEW;
+ ctx->dwSize = ft->std.currentFileSize;
- TCHAR* pszFiles = _tcsrchr(ft->std.tszCurrentFile, '\\');
- if (pszFiles)
- pszFiles++;
- else
- pszFiles = ft->std.tszCurrentFile;
+ TCHAR* pszFiles = _tcsrchr(ft->std.tszCurrentFile, '\\');
+ if (pszFiles)
+ pszFiles++;
+ else
+ pszFiles = ft->std.tszCurrentFile;
- wchar_t *fname = mir_t2u(pszFiles);
- wcsncpy(ctx->wszFileName, fname, MAX_PATH);
- mir_free(fname);
+ wchar_t *fname = mir_t2u(pszFiles);
+ wcsncpy(ctx->wszFileName, fname, MAX_PATH);
+ mir_free(fname);
- ft->p2p_appID = MSN_APPID_FILE;
- }
- break;
+ ft->p2p_appID = MSN_APPID_FILE;
+ }
+ break;
- default:
- ft->p2p_appID = MSN_APPID_AVATAR2;
+ default:
+ ft->p2p_appID = MSN_APPID_AVATAR2;
- if (ft->p2p_object == NULL)
- {
- delete ft;
- return;
- }
+ if (ft->p2p_object == NULL)
+ {
+ delete ft;
+ return;
+ }
- ezxml_t xmlo = ezxml_parse_str(NEWSTR_ALLOCA(ft->p2p_object), strlen(ft->p2p_object));
- ezxml_t xmlr = ezxml_new("msnobj");
-
- const char* p;
- p = ezxml_attr(xmlo, "Creator");
- if (p != NULL)
- ezxml_set_attr(xmlr, "Creator", p);
- p = ezxml_attr(xmlo, "Size");
- if (p != NULL) {
- ezxml_set_attr(xmlr, "Size", p);
- ft->std.totalBytes = ft->std.currentFileSize = _atoi64(p);
- }
- p = ezxml_attr(xmlo, "Type");
- if (p != NULL)
- ezxml_set_attr(xmlr, "Type", p);
- p = ezxml_attr(xmlo, "Location");
- if (p != NULL)
- ezxml_set_attr(xmlr, "Location", p);
- p = ezxml_attr(xmlo, "Friendly");
- if (p != NULL)
- ezxml_set_attr(xmlr, "Friendly", p);
- p = ezxml_attr(xmlo, "SHA1D");
- if (p != NULL)
- ezxml_set_attr(xmlr, "SHA1D", p);
- p = ezxml_attr(xmlo, "SHA1C");
- if (p != NULL)
- ezxml_set_attr(xmlr, "SHA1C", p);
-
- pContext = ezxml_toxml(xmlr, false);
- cbContext = strlen(pContext)+1;
-
- ezxml_free(xmlr);
- ezxml_free(xmlo);
+ ezxml_t xmlo = ezxml_parse_str(NEWSTR_ALLOCA(ft->p2p_object), strlen(ft->p2p_object));
+ ezxml_t xmlr = ezxml_new("msnobj");
+
+ const char* p;
+ p = ezxml_attr(xmlo, "Creator");
+ if (p != NULL)
+ ezxml_set_attr(xmlr, "Creator", p);
+ p = ezxml_attr(xmlo, "Size");
+ if (p != NULL) {
+ ezxml_set_attr(xmlr, "Size", p);
+ ft->std.totalBytes = ft->std.currentFileSize = _atoi64(p);
+ }
+ p = ezxml_attr(xmlo, "Type");
+ if (p != NULL)
+ ezxml_set_attr(xmlr, "Type", p);
+ p = ezxml_attr(xmlo, "Location");
+ if (p != NULL)
+ ezxml_set_attr(xmlr, "Location", p);
+ p = ezxml_attr(xmlo, "Friendly");
+ if (p != NULL)
+ ezxml_set_attr(xmlr, "Friendly", p);
+ p = ezxml_attr(xmlo, "SHA1D");
+ if (p != NULL)
+ ezxml_set_attr(xmlr, "SHA1D", p);
+ p = ezxml_attr(xmlo, "SHA1C");
+ if (p != NULL)
+ ezxml_set_attr(xmlr, "SHA1C", p);
+
+ pContext = ezxml_toxml(xmlr, false);
+ cbContext = strlen(pContext)+1;
+
+ ezxml_free(xmlr);
+ ezxml_free(xmlo);
- break;
+ break;
}
bool sessionExist = p2p_sessionRegistered(ft);
@@ -2335,6 +2355,7 @@ void CMsnProto::p2p_inviteDc(filetransfer* ft, const char *wlid)
chdrs.addString("Conn-Type", MyConnection.GetMyUdpConStr());
chdrs.addBool("UPnPNat", MyConnection.upnpNAT);
chdrs.addBool("ICF", MyConnection.icf);
+ chdrs.addString("IPv6-global", GetGlobalIp(), 2);
chdrs.addString("Hashed-Nonce", dc->mNonceToHash(), 2);
chdrs.addString("SessionID", "0");
chdrs.addString("SChannelState", "0");
@@ -2452,7 +2473,7 @@ char* P2PV2_Header::createMsg(char *buf, const char* wlid, CMsnProto *ppro)
*(unsigned*)(buf + 4) = _htonl(mID);
char *buf1 = buf + 8;
-
+
if (mAckUniqueID)
{
*(unsigned char*)buf1 = 2;
@@ -2475,7 +2496,7 @@ char* P2PV2_Header::createMsg(char *buf, const char* wlid, CMsnProto *ppro)
*(unsigned char*)(buf1 + 1) = mTFCode;
*(unsigned short*)(buf1 + 2) = _htons(mPacketNum);
*(unsigned*)(buf1 + 4) = _htonl(mSessionID);
-
+
if (mRemSize)
{
*(unsigned char*)(buf1 + 8) = 1;
diff --git a/protocols/MSN/msn_proto.h b/protocols/MSN/msn_proto.h
index f09ec82ef7..8f6ddfbfd4 100644
--- a/protocols/MSN/msn_proto.h
+++ b/protocols/MSN/msn_proto.h
@@ -369,7 +369,7 @@ struct CMsnProto : public PROTO_INTERFACE
void p2p_savePicture2disk(filetransfer* ft);
bool p2p_createListener(filetransfer* ft, directconnection *dc, MimeHeaders& chdrs);
- void p2p_startConnect(const char* wlid, const char* szCallID, const char* addr, const char* port);
+ void p2p_startConnect(const char* wlid, const char* szCallID, const char* addr, const char* port, bool ipv6);
void p2p_sendAbortSession(filetransfer* ft);
void p2p_sendAck(const char *wlid, P2PB_Header* hdrdata);