summaryrefslogtreecommitdiff
path: root/protocols/EmLanProto/src/mlan.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/EmLanProto/src/mlan.cpp')
-rw-r--r--protocols/EmLanProto/src/mlan.cpp164
1 files changed, 85 insertions, 79 deletions
diff --git a/protocols/EmLanProto/src/mlan.cpp b/protocols/EmLanProto/src/mlan.cpp
index 107effffdb..6cd8255697 100644
--- a/protocols/EmLanProto/src/mlan.cpp
+++ b/protocols/EmLanProto/src/mlan.cpp
@@ -35,8 +35,6 @@ CMLan::CMLan()
m_mirStatus = ID_STATUS_OFFLINE;
m_pRootContact = nullptr;
-
- m_pRootContact = nullptr;
m_hCheckThread = nullptr;
m_handleId = 1;
@@ -73,7 +71,7 @@ CMLan::~CMLan()
void CMLan::DeleteCache()
{
- TContact* pCont = m_pRootContact;
+ TContact *pCont = m_pRootContact;
m_pRootContact = nullptr;
while (pCont) {
delete[] pCont->m_nick;
@@ -190,8 +188,9 @@ void CMLan::RequestStatus(bool answer, u_long addr)
TPacket pak;
memset(&pak, 0, sizeof(pak));
pak.flReqStatus = answer;
- pak.strName = m_name;
+ pak.strName = mir_u2a(m_name);
SendPacketExt(pak, addr);
+ mir_free(pak.strName);
}
void CMLan::SendPacketExt(TPacket& pak, u_long addr)
@@ -283,9 +282,6 @@ void CMLan::OnRecvPacket(u_char* mes, int len, in_addr from)
u_int rip = cont->m_addr.S_un.S_addr;
int tip = (rip << 24) | ((rip & 0xff00) << 8) | ((rip & 0xff0000) >> 8) | (rip >> 24);
db_set_dw(hContact, PROTONAME, "IP", tip);
- // HOSTENT* host = gethostbyaddr((const char*)&rip, sizeof(rip), AF_INET);
- // if (host)
- // db_set_s(hContact, PROTONAME, "UID", host->h_name);
}
}
}
@@ -325,24 +321,22 @@ void CMLan::OnRecvPacket(u_char* mes, int len, in_addr from)
}
if (pak.idReqAwayMessage && cont) {
- MCONTACT hContact = FindContact(cont->m_addr, cont->m_nick, true, false, false);
// Removed - it causes that whoisreadingawaymessage plugin was not working
- // if (hContact)
- // {
- // int IcqStatus = 0;
- // switch (m_mirStatus)
- // {
- // case ID_STATUS_AWAY: IcqStatus = ICQ_MSGTYPE_GETAWAYMSG; break;
- // case ID_STATUS_NA: IcqStatus = ICQ_MSGTYPE_GETNAMSG; break;
- // case ID_STATUS_OCCUPIED: IcqStatus = ICQ_MSGTYPE_GETOCCUMSG; break;
- // case ID_STATUS_DND: IcqStatus = ICQ_MSGTYPE_GETDNDMSG; break;
- // case ID_STATUS_FREECHAT: IcqStatus = ICQ_MSGTYPE_GETFFCMSG; break;
- // }
- // // HACK: this is a real hack
- // db_set_dw(hContact, "ICQ", "UIN", 1/*0xffffffff*/);
- // NotifyEventHooks(m_hookIcqMsgReq, IcqStatus, 1/*0xffffffff*/);
- // db_unset(hContact, "ICQ", "UIN");
- // }
+ // MCONTACT hContact = FindContact(cont->m_addr, cont->m_nick, true, false, false);
+ // if (hContact) {
+ // int IcqStatus = 0;
+ // switch (m_mirStatus) {
+ // case ID_STATUS_AWAY: IcqStatus = ICQ_MSGTYPE_GETAWAYMSG; break;
+ // case ID_STATUS_NA: IcqStatus = ICQ_MSGTYPE_GETNAMSG; break;
+ // case ID_STATUS_OCCUPIED: IcqStatus = ICQ_MSGTYPE_GETOCCUMSG; break;
+ // case ID_STATUS_DND: IcqStatus = ICQ_MSGTYPE_GETDNDMSG; break;
+ // case ID_STATUS_FREECHAT: IcqStatus = ICQ_MSGTYPE_GETFFCMSG; break;
+ // }
+ // // HACK: this is a real hack
+ // db_set_dw(hContact, "ICQ", "UIN", 1/*0xffffffff*/);
+ // NotifyEventHooks(m_hookIcqMsgReq, IcqStatus, 1/*0xffffffff*/);
+ // db_unset(hContact, "ICQ", "UIN");
+ // }
mir_cslock lck(m_csAccessAwayMes);
@@ -370,7 +364,12 @@ void CMLan::OnRecvPacket(u_char* mes, int len, in_addr from)
void CMLan::RecvMessageUrl(CCSDATA* ccs)
{
PROTORECVEVENT *pre = (PROTORECVEVENT*)ccs->lParam;
- ptrA szMessage(Utf8Encode(pre->szMessage));
+ ptrA szMessage;
+ // input string might be already utf8-encoded
+ if (Utf8CheckString(pre->szMessage))
+ szMessage = mir_strdup(pre->szMessage);
+ else
+ szMessage = Utf8Encode(pre->szMessage);
DBEVENTINFO dbei = {};
if (!mir_strcmp(ccs->szProtoService, PSR_MESSAGE))
@@ -410,31 +409,31 @@ INT_PTR CMLan::AddToContactList(u_int flags, EMPSEARCHRESULT *psr)
int CMLan::SendMessageUrl(CCSDATA* ccs, bool isUrl)
{
int cid = GetRandomProcId();
- size_t len;
+ size_t len = 0;
if (isUrl) {
len = mir_strlen((char*)ccs->lParam);
((char*)ccs->lParam)[len] = 1;
}
- TDataHolder* hold = new TDataHolder(ccs, cid, isUrl ? LEXT_SENDURL : LEXT_SENDMESSAGE, this);
+ TDataHolder *hold = new TDataHolder(ccs, cid, isUrl ? LEXT_SENDURL : LEXT_SENDMESSAGE, this);
if (isUrl) {
((char*)ccs->lParam)[len] = 0;
hold->msg[len] = 0;
}
- mir_forkthread(LaunchExt, (void*)hold);
+ mir_forkthread(LaunchExt, hold);
return cid;
}
int CMLan::Search(const char* name)
{
int cid = GetRandomProcId();
- mir_forkthread(LaunchExt, (void*)new TDataHolder(name, cid, LEXT_SEARCH, this));
+ mir_forkthread(LaunchExt, new TDataHolder(name, cid, LEXT_SEARCH, this));
return cid;
}
int CMLan::GetAwayMsg(CCSDATA* ccs)
{
int cid = GetRandomProcId();
- mir_forkthread(LaunchExt, (void*)new TDataHolder(ccs, cid, LEXT_GETAWAYMSG, this));
+ mir_forkthread(LaunchExt, new TDataHolder(ccs, cid, LEXT_GETAWAYMSG, this));
return cid;
}
@@ -484,10 +483,23 @@ void CMLan::SearchExt(TDataHolder* hold)
psr.ipaddr = cont->m_addr.S_un.S_addr;
psr.stat = cont->m_status;
psr.ver = cont->m_ver;
-
ProtoBroadcastAck(PROTONAME, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)hold->id, (LPARAM)&psr);
}
}
+
+ // search string might contain some ip address
+ ULONG addr = inet_addr(hold->msg);
+ if (addr != INADDR_NONE) {
+ psr.nick.a = hold->msg;
+ psr.firstName.a = "";
+ psr.lastName.a = "";
+ psr.email.a = hold->msg;
+ psr.ipaddr = addr;
+ psr.stat = ID_STATUS_OFFLINE;
+ psr.ver = 0;
+ ProtoBroadcastAck(PROTONAME, NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)hold->id, (LPARAM)&psr);
+ }
+
ProtoBroadcastAck(PROTONAME, NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)hold->id, 0);
delete hold;
}
@@ -582,7 +594,7 @@ u_char* CMLan::CreatePacket(TPacket& pak, int* pBufLen)
if (pak.idStatus)
len += 1 + 1 + 2;
- size_t nameLen;
+ size_t nameLen = 0;
if (pak.strName) {
nameLen = mir_strlen(pak.strName);
len += 1 + 1 + nameLen + 1;
@@ -760,23 +772,17 @@ void CMLan::LoadSettings()
m_RequiredIp = db_get_dw(NULL, PROTONAME, "ipaddr", 0);
m_UseHostName = db_get_b(NULL, PROTONAME, "UseHostName", 1) != 0;
if (m_UseHostName) {
- gethostname(m_name, MAX_HOSTNAME_LEN);
+ m_nameLen = MAX_HOSTNAME_LEN;
+ GetComputerName(m_name, &m_nameLen);
CharLower(m_name);
}
else {
- DBVARIANT dbv;
- // Deleting old 'Name' value - using 'Nick' instead of it now
- if (db_get_s(NULL, PROTONAME, "Nick", &dbv)) {
- if (db_get_s(NULL, PROTONAME, "Name", &dbv))
- dbv.pszVal = "EmLan_User";
- else
- db_unset(NULL, PROTONAME, "Name");
- }
- if (!dbv.pszVal[0])
- dbv.pszVal = "EmLan_User";
- mir_strcpy(m_name, dbv.pszVal);
+ ptrW nick(db_get_wsa(NULL, PROTONAME, "Nick"));
+ if (!nick)
+ nick = mir_wstrdup(L"EmLan_User");
+ mir_wstrcpy(m_name, nick);
}
- m_nameLen = (int)mir_strlen(m_name);
+ m_nameLen = (int)mir_wstrlen(m_name);
if (GetStatus() != LM_LISTEN) {
int ipcount = GetHostAddrCount();
@@ -794,7 +800,7 @@ void CMLan::SaveSettings()
{
db_set_dw(NULL, PROTONAME, "ipaddr", m_RequiredIp);
db_set_b(NULL, PROTONAME, "UseHostName", m_UseHostName);
- db_set_s(NULL, PROTONAME, "Nick", m_name);
+ db_set_ws(NULL, PROTONAME, "Nick", m_name);
}
//////////////////////////////////////////////////////////////////////////
@@ -812,7 +818,7 @@ CMLan::TFileConnection::~TFileConnection()
}
delete[] m_szDescription;
if (m_szFiles) {
- char** cp = m_szFiles;
+ wchar_t** cp = m_szFiles;
while (*cp) {
delete[] * cp;
cp++;
@@ -1029,11 +1035,11 @@ void CMLan::OnInTCPConnection(u_long addr, SOCKET in_sock)
char* pf_to = pre.szMessage + 4;
char* pf_fr = (char*)conn->m_buf + 1 + 4 + 4;
- conn->m_szFiles = new char*[rcTotalFiles + 1];
+ conn->m_szFiles = new wchar_t*[rcTotalFiles + 1];
conn->m_szFiles[rcTotalFiles] = nullptr;
for (int i = 0; i < rcTotalFiles; i++) {
- conn->m_szFiles[i] = _strdup(pf_fr);
+ conn->m_szFiles[i] = mir_a2u(pf_fr);
if (i)
*pf_to++ = ' ';
while (*pf_fr)
@@ -1074,12 +1080,12 @@ void CMLan::OnInTCPConnection(u_long addr, SOCKET in_sock)
}
// Getting current directory
- char path[MAX_PATH];
- char* pathpart;
+ wchar_t path[MAX_PATH];
+ wchar_t* pathpart;
GetFullPathName(conn->m_szDir, MAX_PATH, path, &pathpart);
if (!SetCurrentDirectory(path)) {
if (rcTotalFiles == 1)
- conn->m_szRenamedFile = _strdup(pathpart);
+ conn->m_szRenamedFile = mir_wstrdup(pathpart);
*pathpart = 0;
if (!SetCurrentDirectory(path)) {
conn->Send(nullptr, 0);
@@ -1094,13 +1100,13 @@ void CMLan::OnInTCPConnection(u_long addr, SOCKET in_sock)
PROTOFILETRANSFERSTATUS fts;
fts.cbSize = sizeof(fts);
+ fts.flags = PFTS_UNICODE;
+ fts.hContact = conn->m_hContact;
fts.totalBytes = rcTotalSize;
fts.totalFiles = rcTotalFiles;
fts.totalProgress = 0;
- fts.szWorkingDir = conn->m_szDir;
- fts.flags = false;
- fts.hContact = conn->m_hContact;
- fts.pszFiles = conn->m_szFiles;
+ fts.wszWorkingDir = conn->m_szDir;
+ fts.pwszFiles = conn->m_szFiles;
bool err = false;
@@ -1150,7 +1156,7 @@ void CMLan::OnInTCPConnection(u_long addr, SOCKET in_sock)
}
EMLOG("Still processing");
- char* filename = conn->m_szRenamedFile;
+ wchar_t* filename = conn->m_szRenamedFile;
if (!filename)
filename = conn->m_szFiles[fileNo];
@@ -1238,7 +1244,7 @@ void CMLan::OnInTCPConnection(u_long addr, SOCKET in_sock)
delete conn;
}
-void CMLan::OnOutTCPConnection(u_long addr, SOCKET out_socket, LPVOID lpParameter)
+void CMLan::OnOutTCPConnection(u_long, SOCKET out_socket, LPVOID lpParameter)
{
EMLOG("Sending OUT TCP connection");
TFileConnection* conn = (TFileConnection*)lpParameter;
@@ -1258,13 +1264,13 @@ void CMLan::OnOutTCPConnection(u_long addr, SOCKET out_socket, LPVOID lpParamete
FileAddToList(conn);
u_char buf[FILE_SEND_BLOCK + 1];
- char name[MAX_PATH + 8];
+ wchar_t name[MAX_PATH + 8];
buf[0] = FCODE_SND_FILEREQ;
int len = 1 + 4 + 4;
int size = 0;
int filecount = 0;
- char** pf = conn->m_szFiles;
+ wchar_t** pf = conn->m_szFiles;
while (*pf) {
// TODO: FIX IT !
EMLOG("Opening file");
@@ -1279,33 +1285,33 @@ void CMLan::OnOutTCPConnection(u_long addr, SOCKET out_socket, LPVOID lpParamete
filecount++;
CloseHandle(hFile);
- char* filepart;
- GetFullPathName(*pf, MAX_PATH, (char*)name, &filepart);
+ wchar_t* filepart;
+ GetFullPathName(*pf, MAX_PATH, name, &filepart);
free(*pf);
- *pf = _strdup(name);
- mir_strcpy((char*)buf + len, filepart);
- len += (int)mir_strlen(filepart) + 1;
+ *pf = mir_wstrdup(name);
+ mir_strcpy((char*)buf + len, _T2A(filepart));
+ len += (int)mir_wstrlen(filepart) + 1;
pf++;
}
- mir_strcpy((char*)buf + len, conn->m_szDescription);
- len += (int)mir_strlen(conn->m_szDescription) + 1;
+ mir_strcpy((char*)buf + len, _T2A(conn->m_szDescription));
+ len += (int)mir_wstrlen(conn->m_szDescription) + 1;
*((int*)(buf + 1)) = size;
*((int*)(buf + 1 + 4)) = filecount;
GetCurrentDirectory(MAX_PATH, name);
- conn->m_szDir = _strdup(name);
+ conn->m_szDir = mir_wstrdup(name);
PROTOFILETRANSFERSTATUS fts;
fts.cbSize = sizeof(fts);
+ fts.flags = PFTS_SENDING | PFTS_UNICODE;
+ fts.hContact = conn->m_hContact;
fts.totalBytes = size;
fts.totalFiles = filecount;
fts.totalProgress = 0;
- fts.szWorkingDir = conn->m_szDir;
- fts.flags = PFTS_SENDING;
- fts.hContact = conn->m_hContact;
- fts.pszFiles = conn->m_szFiles;
+ fts.wszWorkingDir = conn->m_szDir;
+ fts.pwszFiles = conn->m_szFiles;
EMLOG("Sending file size");
if (conn->Send(buf, len)) {
@@ -1388,7 +1394,7 @@ void CMLan::OnOutTCPConnection(u_long addr, SOCKET out_socket, LPVOID lpParamete
EMLOG("Ok");
buf[0] = FCODE_SND_FILEDATA;
- if (readbytes != tosend) {
+ if ((int)readbytes != tosend) {
EMLOG("Error during reading file. File was changed");
CloseHandle(hFile);
conn->Send(nullptr, 0);
@@ -1455,14 +1461,14 @@ int CMLan::SendFile(CCSDATA* ccs)
conn->m_cid = cid;
conn->m_hContact = ccs->hContact;
- conn->m_szDescription = _strdup((char*)ccs->wParam);
+ conn->m_szDescription = mir_wstrdup((wchar_t*)ccs->wParam);
int files = 0;
- char** ppszFiles = (char**)ccs->lParam;
+ wchar_t** ppszFiles = (wchar_t**)ccs->lParam;
while (ppszFiles[files])
files++;
- conn->m_szFiles = new char*[files + 1];
+ conn->m_szFiles = new wchar_t*[files + 1];
for (int i = 0; i < files; i++)
- conn->m_szFiles[i] = _strdup(ppszFiles[i]);
+ conn->m_szFiles[i] = mir_wstrdup(ppszFiles[i]);
conn->m_szFiles[files] = nullptr;
u_long addr = db_get_dw(ccs->hContact, PROTONAME, "ipaddr", 0);
@@ -1485,7 +1491,7 @@ int CMLan::FileAllow(CCSDATA* ccs)
mir_cslock connLck(conn->m_csAccess);
conn->m_state = TFileConnection::FCS_ALLOW;
- conn->m_szDir = _strdup((char*)ccs->lParam);
+ conn->m_szDir = mir_wstrdup((wchar_t*)ccs->lParam);
return cid;
}
@@ -1546,7 +1552,7 @@ int CMLan::FileResume(int cid, PROTOFILERESUME* pfr)
case FILERESUME_RENAME:
conn->m_state = TFileConnection::FCS_RENAME;
delete[] conn->m_szRenamedFile;
- conn->m_szRenamedFile = _strdup((char*)pfr->szFilename);
+ conn->m_szRenamedFile = mir_wstrdup(pfr->szFilename);
break;
case FILERESUME_SKIP:
conn->m_state = TFileConnection::FCS_SKIP;