summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Gadu-Gadu/src/avatar.cpp84
-rw-r--r--protocols/Gadu-Gadu/src/core.cpp1556
-rw-r--r--protocols/Gadu-Gadu/src/dialogs.cpp758
-rw-r--r--protocols/Gadu-Gadu/src/dynstuff.cpp384
-rw-r--r--protocols/Gadu-Gadu/src/filetransfer.cpp764
-rw-r--r--protocols/Gadu-Gadu/src/gg.cpp321
-rw-r--r--protocols/Gadu-Gadu/src/gg_proto.cpp48
-rw-r--r--protocols/Gadu-Gadu/src/gg_proto.h59
-rw-r--r--protocols/Gadu-Gadu/src/groupchat.cpp292
-rw-r--r--protocols/Gadu-Gadu/src/icolib.cpp34
-rw-r--r--protocols/Gadu-Gadu/src/image.cpp427
-rw-r--r--protocols/Gadu-Gadu/src/import.cpp71
-rw-r--r--protocols/Gadu-Gadu/src/keepalive.cpp22
-rw-r--r--protocols/Gadu-Gadu/src/links.cpp8
-rw-r--r--protocols/Gadu-Gadu/src/oauth.cpp114
-rw-r--r--protocols/Gadu-Gadu/src/ownerinfo.cpp2
-rw-r--r--protocols/Gadu-Gadu/src/popups.cpp55
-rw-r--r--protocols/Gadu-Gadu/src/services.cpp78
-rw-r--r--protocols/Gadu-Gadu/src/sessions.cpp309
-rw-r--r--protocols/Gadu-Gadu/src/stdafx.cpp2
-rw-r--r--protocols/Gadu-Gadu/src/token.cpp102
-rw-r--r--protocols/Gadu-Gadu/src/userutils.cpp151
22 files changed, 2851 insertions, 2790 deletions
diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp
index 096ae7bfbe..11b63d37ca 100644
--- a/protocols/Gadu-Gadu/src/avatar.cpp
+++ b/protocols/Gadu-Gadu/src/avatar.cpp
@@ -28,7 +28,7 @@
//
void GGPROTO::getAvatarFilename(MCONTACT hContact, wchar_t *pszDest, int cbLen)
{
- int tPathLen = mir_snwprintf(pszDest, cbLen, L"%s\\%S", VARSW( L"%miranda_avatarcache%"), m_szModuleName);
+ int tPathLen = mir_snwprintf(pszDest, cbLen, L"%s\\%S", VARSW(L"%miranda_avatarcache%"), m_szModuleName);
if (_waccess(pszDest, 0)) {
int ret = CreateDirectoryTreeW(pszDest);
@@ -80,8 +80,7 @@ bool GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts)
return false;
}
- if ((strncmp(resp->pData, "<result>", 8) == 0) || (strncmp(resp->pData, "<?xml", 5) == 0)){
-
+ if ((strncmp(resp->pData, "<result>", 8) == 0) || (strncmp(resp->pData, "<?xml", 5) == 0)) {
//if this url returned xml data (before and after 11.2013 gg convention)
wchar_t *xmlAction = mir_a2u(resp->pData);
HXML hXml = xmlParseString(xmlAction, nullptr, L"result");
@@ -92,7 +91,7 @@ bool GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts)
node = xmlGetChildByPath(hXml, L"users/user/avatars/avatar/timestamp", 0);
*avatarts = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr;
node = xmlGetChildByPath(hXml, L"users/user/avatars/avatar/bigavatar", 0); //new gg convention
- if (node == nullptr){
+ if (node == nullptr) {
node = xmlGetChildByPath(hXml, L"users/user/avatars/avatar/originBigAvatar", 0); //old gg convention
}
*avatarurl = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr;
@@ -100,9 +99,8 @@ bool GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts)
xmlDestroyNode(hXml);
}
mir_free(xmlAction);
-
- } else if (strncmp(resp->pData, "{\"result\":", 10) == 0){
-
+ }
+ else if (strncmp(resp->pData, "{\"result\":", 10) == 0) {
//if this url returns json data (11.2013 gg convention)
JSONNode root = JSONNode::parse(resp->pData);
if (root) {
@@ -150,9 +148,9 @@ void GGPROTO::requestAvatarTransfer(MCONTACT hContact, char *szAvatarURL)
gg_EnterCriticalSection(&avatar_mutex, "requestAvatarTransfer", 1, "avatar_mutex", 1);
if (avatar_transfers.getIndex((GGGETAVATARDATA*)&hContact) == -1) {
- GGGETAVATARDATA *data = (GGGETAVATARDATA*)mir_alloc(sizeof(GGGETAVATARDATA) + mir_strlen(szAvatarURL)+1);
+ GGGETAVATARDATA *data = (GGGETAVATARDATA*)mir_alloc(sizeof(GGGETAVATARDATA) + mir_strlen(szAvatarURL) + 1);
data->hContact = hContact;
- data->szAvatarURL = mir_strcpy((char*)(data+1), szAvatarURL);
+ data->szAvatarURL = mir_strcpy((char*)(data + 1), szAvatarURL);
avatar_transfers.insert(data);
}
gg_LeaveCriticalSection(&avatar_mutex, "requestAvatarTransfer", 1, 1, "avatar_mutex", 1);
@@ -164,7 +162,7 @@ void GGPROTO::requestAvatarInfo(MCONTACT hContact, int iWaitFor)
debugLogA("requestAvatarInfo(): Can not list_add element to avatar_requests list. No pth_avatar.dwThreadId");
return;
}
-
+
if (!getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS))
return;
@@ -195,7 +193,7 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
avatar_requests.remove(0);
mir_free(data);
gg_LeaveCriticalSection(&avatar_mutex, "avatarrequestthread", 3, 1, "avatar_mutex", 1);
-
+
uin_t uin = (uin_t)getDword(hContact, GG_KEY_UIN, 0);
debugLogA("avatarrequestthread() new avatar_requests item for uin=%d.", uin);
@@ -205,7 +203,7 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, nullptr, 0);
}
else {
- if (AvatarURL == nullptr && AvatarTs == nullptr){
+ if (AvatarURL == nullptr && AvatarTs == nullptr) {
delSetting(hContact, GG_KEY_AVATARURL);
delSetting(hContact, GG_KEY_AVATARTS);
if (iWaitFor)
@@ -256,9 +254,9 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
int file_fd;
int avatarType = PA_FORMAT_UNKNOWN;
- if (strncmp(resp->pData,"\xFF\xD8",2) == 0) avatarType = PA_FORMAT_JPEG;
- if (strncmp(resp->pData,"\x47\x49\x46\x38",4) == 0) avatarType = PA_FORMAT_GIF;
- if (strncmp(resp->pData,"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",8) == 0) avatarType = PA_FORMAT_PNG;
+ if (strncmp(resp->pData, "\xFF\xD8", 2) == 0) avatarType = PA_FORMAT_JPEG;
+ if (strncmp(resp->pData, "\x47\x49\x46\x38", 4) == 0) avatarType = PA_FORMAT_GIF;
+ if (strncmp(resp->pData, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 8) == 0) avatarType = PA_FORMAT_PNG;
setByte(data->hContact, GG_KEY_AVATARTYPE, (BYTE)avatarType);
getAvatarFilename(ai.hContact, ai.filename, _countof(ai.filename));
@@ -268,7 +266,8 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
_close(file_fd);
result = 1;
debugLogW(L"avatarrequestthread() new avatar_transfers item. Saved data to file=%s.", ai.filename);
- } else {
+ }
+ else {
debugLogW(L"avatarrequestthread(): _wopen file %s error. errno=%d: %s", ai.filename, errno, ws_strerror(errno));
wchar_t error[512];
mir_snwprintf(error, TranslateT("Cannot create avatar file. ERROR: %d: %s\n%s"), errno, ws_strerror(errno), ai.filename);
@@ -292,10 +291,10 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
gg_sleep(100, FALSE, "avatarrequestthread", 101, 1);
}
- for (int i=0; i < avatar_requests.getCount(); i++)
+ for (int i = 0; i < avatar_requests.getCount(); i++)
mir_free(avatar_requests[i]);
- for (int k=0; k < avatar_transfers.getCount(); k++)
+ for (int k = 0; k < avatar_transfers.getCount(); k++)
mir_free(avatar_transfers[k]);
avatar_requests.destroy();
@@ -328,7 +327,8 @@ void __cdecl GGPROTO::getOwnAvatarThread(void*)
setString(GG_KEY_AVATARURL, AvatarURL);
setString(GG_KEY_AVATARTS, AvatarTs);
mir_free(AvatarURL); mir_free(AvatarTs);
- } else {
+ }
+ else {
delSetting(GG_KEY_AVATARURL);
delSetting(GG_KEY_AVATARTS);
}
@@ -344,7 +344,7 @@ void __cdecl GGPROTO::getOwnAvatarThread(void*)
void GGPROTO::getOwnAvatar()
{
- if (getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS) && getDword(GG_KEY_UIN, 0)){
+ if (getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS) && getDword(GG_KEY_UIN, 0)) {
#ifdef DEBUGMODE
debugLogA("getOwnAvatar(): ForkThread 2 GGPROTO::getOwnAvatarThread");
#endif
@@ -354,7 +354,6 @@ void GGPROTO::getOwnAvatar()
void __cdecl GGPROTO::setavatarthread(void *param)
{
-
debugLogA("setavatarthread(): started. Trying to set user avatar.");
//read file
@@ -371,9 +370,9 @@ void __cdecl GGPROTO::setavatarthread(void *param)
setByte(GG_KEY_AVATARTYPE, prevType);
delSetting(GG_KEY_AVATARTYPEPREV);
getOwnAvatar();
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("setavatarthread(): end. err1");
- #endif
+#endif
return;
}
@@ -402,32 +401,32 @@ void __cdecl GGPROTO::setavatarthread(void *param)
char* token = getStringA(GG_KEY_TOKEN);
//construct request
- NETLIBHTTPREQUEST req = {0};
+ NETLIBHTTPREQUEST req = { 0 };
req.cbSize = sizeof(req);
req.requestType = REQUEST_POST;
req.szUrl = "http://avatars.nowe.gg/upload";
req.flags = NLHRF_NODUMP | NLHRF_HTTP11;
req.headersCount = 10;
NETLIBHTTPHEADER httpHeaders[10];
- httpHeaders[0].szName = "X-Request";
+ httpHeaders[0].szName = "X-Request";
httpHeaders[0].szValue = "JSON";
- httpHeaders[1].szName = "Authorization";
+ httpHeaders[1].szName = "Authorization";
httpHeaders[1].szValue = token;
- httpHeaders[2].szName = "X-Requested-With";
+ httpHeaders[2].szName = "X-Requested-With";
httpHeaders[2].szValue = "XMLHttpRequest";
- httpHeaders[3].szName = "From";
+ httpHeaders[3].szName = "From";
httpHeaders[3].szValue = "avatars to avatars";
- httpHeaders[4].szName = "X-IM-Web-App-Version";
+ httpHeaders[4].szName = "X-IM-Web-App-Version";
httpHeaders[4].szValue = "10,5,2,13164";
- httpHeaders[5].szName = "User-Agent";
+ httpHeaders[5].szName = "User-Agent";
httpHeaders[5].szValue = "avatars to avatars";
- httpHeaders[6].szName = "From";
+ httpHeaders[6].szName = "From";
httpHeaders[6].szValue = NETLIB_USER_AGENT;
- httpHeaders[7].szName = "Content-type";
+ httpHeaders[7].szName = "Content-type";
httpHeaders[7].szValue = "application/x-www-form-urlencoded; charset=utf-8";
- httpHeaders[8].szName = "Accept";
+ httpHeaders[8].szName = "Accept";
httpHeaders[8].szValue = "application/json";
- httpHeaders[9].szName = "Referer";
+ httpHeaders[9].szName = "Referer";
httpHeaders[9].szValue = "http://avatars.nowe.gg/.static/index_new_22.0.2_595nwh.html";
req.headers = httpHeaders;
req.pData = data;
@@ -441,19 +440,21 @@ void __cdecl GGPROTO::setavatarthread(void *param)
if (resp->resultCode == 200 && resp->dataLength > 0 && resp->pData) {
debugLogA("setavatarthread(): 1 resp.data= %s", resp->pData);
resultSuccess = 1;
- } else {
+ }
+ else {
debugLogA("setavatarthread() Invalid response code from HTTP request [%d]", resp->resultCode);
- if (resp->resultCode == 399 || resp->resultCode == 403 || resp->resultCode == 401){
+ if (resp->resultCode == 399 || resp->resultCode == 403 || resp->resultCode == 401) {
needRepeat = 1;
}
}
Netlib_FreeHttpRequest(resp);
- } else {
+ }
+ else {
debugLogA("setavatarthread(): No response from HTTP request");
}
//check if we should repeat request
- if (needRepeat) {
+ if (needRepeat) {
// Access Token expired - force obtain new
oauth_checktoken(1);
mir_free(token);
@@ -490,7 +491,8 @@ void __cdecl GGPROTO::setavatarthread(void *param)
if (resultSuccess) {
debugLogA("setavatarthread(): User avatar set successfully.");
- } else {
+ }
+ else {
int prevType = getByte(GG_KEY_AVATARTYPEPREV, -1);
if (prevType != -1)
setByte(GG_KEY_AVATARTYPE, prevType);
@@ -500,9 +502,9 @@ void __cdecl GGPROTO::setavatarthread(void *param)
mir_free(szFilename);
getOwnAvatar();
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("setavatarthread(): end.");
- #endif
+#endif
}
diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp
index 586c425117..c0492fe247 100644
--- a/protocols/Gadu-Gadu/src/core.cpp
+++ b/protocols/Gadu-Gadu/src/core.cpp
@@ -28,10 +28,10 @@
uint32_t swap32(uint32_t x)
{
return (uint32_t)
- (((x & (uint32_t) 0x000000ffU) << 24) |
- ((x & (uint32_t) 0x0000ff00U) << 8) |
- ((x & (uint32_t) 0x00ff0000U) >> 8) |
- ((x & (uint32_t) 0xff000000U) >> 24));
+ (((x & (uint32_t)0x000000ffU) << 24) |
+ ((x & (uint32_t)0x0000ff00U) << 8) |
+ ((x & (uint32_t)0x00ff0000U) >> 8) |
+ ((x & (uint32_t)0xff000000U) >> 24));
}
////////////////////////////////////////////////////////////
@@ -39,7 +39,6 @@ uint32_t swap32(uint32_t x)
int GGPROTO::isonline()
{
-
int isonline;
gg_EnterCriticalSection(&sess_mutex, "isonline", 76, "sess_mutex", 1);
@@ -47,7 +46,6 @@ int GGPROTO::isonline()
gg_LeaveCriticalSection(&sess_mutex, "isonline", 76, 1, "sess_mutex", 1);
return isonline;
-
}
////////////////////////////////////////////////////////////
@@ -75,6 +73,7 @@ void GGPROTO::disconnect()
db_free(&dbv);
}
break;
+
case ID_STATUS_AWAY:
gg_EnterCriticalSection(&modemsg_mutex, "disconnect", 7, "modemsg_mutex", 1);
szMsg = mir_utf8encodeW(modemsg.away);
@@ -85,6 +84,7 @@ void GGPROTO::disconnect()
db_free(&dbv);
}
break;
+
case ID_STATUS_DND:
gg_EnterCriticalSection(&modemsg_mutex, "disconnect", 8, "modemsg_mutex", 1);
szMsg = mir_utf8encodeW(modemsg.dnd);
@@ -95,6 +95,7 @@ void GGPROTO::disconnect()
db_free(&dbv);
}
break;
+
case ID_STATUS_FREECHAT:
gg_EnterCriticalSection(&modemsg_mutex, "disconnect", 9, "modemsg_mutex", 1);
szMsg = mir_utf8encodeW(modemsg.freechat);
@@ -105,6 +106,7 @@ void GGPROTO::disconnect()
db_free(&dbv);
}
break;
+
case ID_STATUS_INVISIBLE:
gg_EnterCriticalSection(&modemsg_mutex, "disconnect", 10, "modemsg_mutex", 1);
szMsg = mir_utf8encodeW(modemsg.invisible);
@@ -115,6 +117,7 @@ void GGPROTO::disconnect()
db_free(&dbv);
}
break;
+
default:
// Set last status
gg_EnterCriticalSection(&modemsg_mutex, "disconnect", 11, "modemsg_mutex", 1);
@@ -162,7 +165,7 @@ uint32_t gg_dnslookup(GGPROTO *gg, char *host)
he = gethostbyname(host);
if (he)
{
- ip = *(uint32_t *) he->h_addr_list[0];
+ ip = *(uint32_t *)he->h_addr_list[0];
#ifdef DEBUGMODE
gg->debugLogA("gg_dnslookup(): Parameter \"%s\" was resolved to %d.%d.%d.%d.", host,
LOBYTE(LOWORD(ip)), HIBYTE(LOWORD(ip)), LOBYTE(HIWORD(ip)), HIBYTE(HIWORD(ip)));
@@ -180,43 +183,45 @@ typedef struct
char hostname[128];
int port;
} GGHOST;
+
#define ISHOSTALPHA(a) (((a) >= '0' && (a) <= '9') || ((a) >= 'a' && (a) <= 'z') || (a) == '.' || (a) == '-')
+
int gg_decodehosts(char *var, GGHOST *hosts, int max)
{
int hp = 0;
char *hostname = nullptr;
char *portname = nullptr;
- while(var && *var && hp < max)
+ while (var && *var && hp < max)
{
if (ISHOSTALPHA(*var))
{
hostname = var;
- while(var && *var && ISHOSTALPHA(*var)) var ++;
+ while (var && *var && ISHOSTALPHA(*var)) var++;
if (var && *var == ':' && var++ && *var && isdigit(*var))
{
*(var - 1) = 0;
portname = var;
- while(var && *var && isdigit(*var)) var++;
- if (*var) { *var = 0; var ++; }
+ while (var && *var && isdigit(*var)) var++;
+ if (*var) { *var = 0; var++; }
}
else
- if (*var) { *var = 0; var ++; }
+ if (*var) { *var = 0; var++; }
// Insert new item
hosts[hp].hostname[127] = 0;
strncpy(hosts[hp].hostname, hostname, 127);
hosts[hp].port = portname ? atoi(portname) : 443;
- hp ++;
+ hp++;
// Zero the names
hostname = nullptr;
portname = nullptr;
}
else
- var ++;
+ var++;
}
return hp;
}
@@ -226,10 +231,10 @@ int gg_decodehosts(char *var, GGHOST *hosts, int max)
void __cdecl GGPROTO::mainthread(void *)
{
// Miranda variables
- NETLIBUSERSETTINGS nlus = {0};
+ NETLIBUSERSETTINGS nlus = { 0 };
DBVARIANT dbv;
// Gadu-Gadu variables
- gg_login_params p = {0};
+ gg_login_params p = { 0 };
gg_event *e;
struct gg_session *local_sess;
// Host cycling variables
@@ -238,17 +243,17 @@ void __cdecl GGPROTO::mainthread(void *)
// Gadu-gadu login errors
static const struct tagReason { int type; wchar_t *str; } reason[] = {
{ GG_FAILURE_RESOLVING, LPGENW("Miranda was unable to resolve the name of the Gadu-Gadu server to its numeric address.") },
- { GG_FAILURE_CONNECTING, LPGENW("Miranda was unable to make a connection with a server. It is likely that the server is down, in which case you should wait for a while and try again later.") },
- { GG_FAILURE_INVALID, LPGENW("Received invalid server response.") },
- { GG_FAILURE_READING, LPGENW("The connection with the server was abortively closed during the connection attempt. You may have lost your local network connection.") },
- { GG_FAILURE_WRITING, LPGENW("The connection with the server was abortively closed during the connection attempt. You may have lost your local network connection.") },
- { GG_FAILURE_PASSWORD, LPGENW("Your Gadu-Gadu number and password combination was rejected by the Gadu-Gadu server. Please check login details at Options -> Network -> Gadu-Gadu and try again.") },
- { GG_FAILURE_404, LPGENW("Connecting to Gadu-Gadu hub failed.") },
- { GG_FAILURE_TLS, LPGENW("Cannot establish secure connection.") },
- { GG_FAILURE_NEED_EMAIL, LPGENW("Server disconnected asking you for changing your e-mail.") },
- { GG_FAILURE_INTRUDER, LPGENW("Too many login attempts with invalid password.") },
- { GG_FAILURE_UNAVAILABLE, LPGENW("Gadu-Gadu servers are now down. Try again later.") },
- { 0, LPGENW("Unknown") }
+ { GG_FAILURE_CONNECTING, LPGENW("Miranda was unable to make a connection with a server. It is likely that the server is down, in which case you should wait for a while and try again later.") },
+ { GG_FAILURE_INVALID, LPGENW("Received invalid server response.") },
+ { GG_FAILURE_READING, LPGENW("The connection with the server was abortively closed during the connection attempt. You may have lost your local network connection.") },
+ { GG_FAILURE_WRITING, LPGENW("The connection with the server was abortively closed during the connection attempt. You may have lost your local network connection.") },
+ { GG_FAILURE_PASSWORD, LPGENW("Your Gadu-Gadu number and password combination was rejected by the Gadu-Gadu server. Please check login details at Options -> Network -> Gadu-Gadu and try again.") },
+ { GG_FAILURE_404, LPGENW("Connecting to Gadu-Gadu hub failed.") },
+ { GG_FAILURE_TLS, LPGENW("Cannot establish secure connection.") },
+ { GG_FAILURE_NEED_EMAIL, LPGENW("Server disconnected asking you for changing your e-mail.") },
+ { GG_FAILURE_INTRUDER, LPGENW("Too many login attempts with invalid password.") },
+ { GG_FAILURE_UNAVAILABLE, LPGENW("Gadu-Gadu servers are now down. Try again later.") },
+ { 0, LPGENW("Unknown") }
};
time_t logonTime = 0;
time_t timeDeviation = getWord(GG_KEY_TIMEDEVIATION, GG_KEYDEF_TIMEDEVIATION);
@@ -273,12 +278,6 @@ void __cdecl GGPROTO::mainthread(void *)
if (getByte(GG_KEY_SHOWLINKS, GG_KEYDEF_SHOWLINKS))
p.status_flags |= GG_STATUS_FLAG_SPAM;
- // Use audio
- /* p.has_audio = 1; */
-
- // Use async connections
- /* p.async = 1; */
-
// Send Era Omnix info if set
p.era_omnix = getByte("EraOmnix", 0);
@@ -367,12 +366,16 @@ void __cdecl GGPROTO::mainthread(void *)
}
else
debugLogA("mainthread() (%x): Loading forwarding host %s and port %d.", dbv.pszVal, p.external_port, this);
- if (p.external_addr) p.external_port = getWord(GG_KEY_FORWARDPORT, GG_KEYDEF_FORWARDPORT);
+
+ if (p.external_addr)
+ p.external_port = getWord(GG_KEY_FORWARDPORT, GG_KEYDEF_FORWARDPORT);
+
db_free(&dbv);
}
}
// Setup client port
- if (dcc) p.client_port = dcc->port;
+ if (dcc)
+ p.client_port = dcc->port;
retry:
// Loadup startup status & description
@@ -382,44 +385,43 @@ retry:
p.status = status_m2gg(m_iDesiredStatus, p.status_descr != nullptr);
debugLogW(L"mainthread() (%x): Connecting with number %d, status %d and description \"%s\".", this, p.uin, m_iDesiredStatus,
- p.status_descr ? getstatusmsg(m_iDesiredStatus) : L"<none>");
+ p.status_descr ? getstatusmsg(m_iDesiredStatus) : L"<none>");
gg_LeaveCriticalSection(&modemsg_mutex, "mainthread", 13, 1, "modemsg_mutex", 1);
// Check manual hosts
- if (hostnum < hostcount)
- {
- if (!(p.server_addr = gg_dnslookup(this, hosts[hostnum].hostname)))
- {
+ if (hostnum < hostcount) {
+ if (!(p.server_addr = gg_dnslookup(this, hosts[hostnum].hostname))) {
wchar_t error[128];
wchar_t* hostnameT = mir_a2u(hosts[hostnum].hostname);
mir_snwprintf(error, TranslateT("Server hostname %s is invalid. Using default hostname provided by the network."), hostnameT);
mir_free(hostnameT);
showpopup(m_tszUserName, error, GG_POPUP_WARNING | GG_POPUP_ALLOW_MSGBOX);
}
- else
- {
+ else {
p.server_port = hosts[hostnum].port;
debugLogA("mainthread() (%x): Connecting to manually specified host %s (%d.%d.%d.%d) and port %d.", this,
hosts[hostnum].hostname, LOBYTE(LOWORD(p.server_addr)), HIBYTE(LOWORD(p.server_addr)),
LOBYTE(HIWORD(p.server_addr)), HIBYTE(HIWORD(p.server_addr)), p.server_port);
}
}
- else
- p.server_port = p.server_addr = 0;
+ else {
+ p.server_port = 0;
+ p.server_addr = 0;
+ }
// Send login request
- if (!(local_sess = gg_login(&p, &sock, &gg_failno)))
- {
+ if (!(local_sess = gg_login(&p, &sock, &gg_failno))) {
broadcastnewstatus(ID_STATUS_OFFLINE);
// Check if connection attempt wasn't cancelled by the user
- if (m_iDesiredStatus != ID_STATUS_OFFLINE)
- {
+ if (m_iDesiredStatus != ID_STATUS_OFFLINE) {
wchar_t error[128], *perror = nullptr;
// Lookup for error desciption
if (errno == EACCES) {
- for (int i = 0; reason[i].type; i++) if (reason[i].type == gg_failno) {
- perror = TranslateW(reason[i].str);
- break;
+ for (int i = 0; reason[i].type; i++) {
+ if (reason[i].type == gg_failno) {
+ perror = TranslateW(reason[i].str);
+ break;
+ }
}
}
if (!perror) {
@@ -435,11 +437,11 @@ retry:
&& errno == EACCES
&& (getByte(GG_KEY_ARECONNECT, GG_KEYDEF_ARECONNECT) || (hostnum < hostcount - 1)))
{
- DWORD dwInterval = getDword(GG_KEY_RECONNINTERVAL, GG_KEYDEF_RECONNINTERVAL), dwResult;
+ DWORD dwInterval = getDword(GG_KEY_RECONNINTERVAL, GG_KEYDEF_RECONNINTERVAL);
BOOL bRetry = TRUE;
hConnStopEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
- dwResult = WaitForSingleObjectEx(hConnStopEvent, dwInterval, TRUE);
+ DWORD dwResult = WaitForSingleObjectEx(hConnStopEvent, dwInterval, TRUE);
if ((dwResult == WAIT_OBJECT_0 && m_iDesiredStatus == ID_STATUS_OFFLINE)
|| (dwResult == WAIT_IO_COMPLETION && Miranda_IsTerminated()))
bRetry = FALSE;
@@ -447,8 +449,7 @@ retry:
hConnStopEvent = nullptr;
// Reconnect to the next server on the list
- if (bRetry)
- {
+ if (bRetry) {
if (hostnum < hostcount - 1) hostnum++;
mir_free(p.status_descr);
broadcastnewstatus(ID_STATUS_CONNECTING);
@@ -463,8 +464,7 @@ retry:
else
debugLogA("mainthread() (%x)): Connection attempt cancelled by the user.", this);
}
- else
- {
+ else {
// Successfully connected
logonTime = time(nullptr);
setDword(GG_KEY_LOGONTIME, logonTime);
@@ -476,16 +476,16 @@ retry:
// Set startup status
if (m_iDesiredStatus != status_gg2m(p.status))
refreshstatus(m_iDesiredStatus);
- else
- {
+ else {
broadcastnewstatus(m_iDesiredStatus);
// Change status of the contact with our own UIN (if got yourself added to the contact list)
wchar_t *status_descr = mir_utf8decodeW(p.status_descr);
changecontactstatus(p.uin, p.status, status_descr, 0, 0, 0, 0);
mir_free(status_descr);
}
- if (check_first_conn) // First connection to the account
- {
+
+ // First connection to the account
+ if (check_first_conn) {
// Start search for user data
GetInfo(NULL, 0);
// Fetch user avatar
@@ -496,14 +496,13 @@ retry:
//////////////////////////////////////////////////////////////////////////////////
// Main loop
- while(isonline())
+ while (isonline())
{
// Connection broken/closed
#ifdef DEBUGMODE
debugLogA("mainthread(): waiting for gg_watch_fd");
#endif
- if (!(e = gg_watch_fd(sess)))
- {
+ if (!(e = gg_watch_fd(sess))) {
#ifdef DEBUGMODE
debugLogA("mainthread(): waiting for gg_watch_fd - DONE error");
#endif
@@ -521,675 +520,651 @@ retry:
debugLogA("mainthread() (%x): Event: %s", this, ggdebug_eventtype(e));
}
- switch(e->type)
- {
+ switch (e->type) {
// Client connected
- case GG_EVENT_CONN_SUCCESS:
- // Nada
- break;
+ case GG_EVENT_CONN_SUCCESS:
+ // Nada
+ break;
// Client disconnected or connection failure
- case GG_EVENT_CONN_FAILED:
- case GG_EVENT_DISCONNECT:
- gg_EnterCriticalSection(&sess_mutex, "mainthread", 17, "sess_mutex", 1);
- gg_free_session(sess);
- sess = nullptr;
- gg_LeaveCriticalSection(&sess_mutex, "mainthread", 17, 1, "sess_mutex", 1);
- break;
+ case GG_EVENT_CONN_FAILED:
+ case GG_EVENT_DISCONNECT:
+ gg_EnterCriticalSection(&sess_mutex, "mainthread", 17, "sess_mutex", 1);
+ gg_free_session(sess);
+ sess = nullptr;
+ gg_LeaveCriticalSection(&sess_mutex, "mainthread", 17, 1, "sess_mutex", 1);
+ break;
// Client allowed to disconnect
- case GG_EVENT_DISCONNECT_ACK:
- // Send logoff
- gg_logoff(sess);
- break;
+ case GG_EVENT_DISCONNECT_ACK:
+ // Send logoff
+ gg_logoff(sess);
+ break;
// Received ackowledge
- case GG_EVENT_ACK:
- if (e->event.ack.seq && e->event.ack.recipient)
- {
- ProtoBroadcastAck(getcontact((DWORD)e->event.ack.recipient, 0, 0, nullptr),
- ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)e->event.ack.seq, 0);
- }
- break;
+ case GG_EVENT_ACK:
+ if (e->event.ack.seq && e->event.ack.recipient) {
+ ProtoBroadcastAck(getcontact((DWORD)e->event.ack.recipient, 0, 0, nullptr),
+ ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)e->event.ack.seq, 0);
+ }
+ break;
// Statuslist notify (deprecated)
- case GG_EVENT_NOTIFY:
- case GG_EVENT_NOTIFY_DESCR:
- {
- struct gg_notify_reply *n;
+ case GG_EVENT_NOTIFY:
+ case GG_EVENT_NOTIFY_DESCR:
+ {
+ struct gg_notify_reply *n;
- n = (e->type == GG_EVENT_NOTIFY) ? e->event.notify : e->event.notify_descr.notify;
+ n = (e->type == GG_EVENT_NOTIFY) ? e->event.notify : e->event.notify_descr.notify;
- for (; n->uin; n++)
- {
- wchar_t *descrT = (e->type == GG_EVENT_NOTIFY_DESCR) ? mir_utf8decodeW(e->event.notify_descr.descr) : nullptr;
- changecontactstatus(n->uin, n->status, descrT, 0, n->remote_ip, n->remote_port, n->version);
- if (descrT) mir_free(descrT);
- }
- break;
- }
- // Statuslist notify (version >= 6.0)
- case GG_EVENT_NOTIFY60:
- {
- uin_t uin = (uin_t)getDword(GG_KEY_UIN, 0);
- int i;
- for(i = 0; e->event.notify60[i].uin; i++) {
- if (e->event.notify60[i].uin == uin) continue;
- wchar_t *descrT = mir_utf8decodeW(e->event.notify60[i].descr);
- changecontactstatus(e->event.notify60[i].uin, e->event.notify60[i].status, descrT,
- e->event.notify60[i].time, e->event.notify60[i].remote_ip, e->event.notify60[i].remote_port,
- e->event.notify60[i].version);
+ for (; n->uin; n++) {
+ wchar_t *descrT = (e->type == GG_EVENT_NOTIFY_DESCR) ? mir_utf8decodeW(e->event.notify_descr.descr) : nullptr;
+ changecontactstatus(n->uin, n->status, descrT, 0, n->remote_ip, n->remote_port, n->version);
+ if (descrT)
mir_free(descrT);
- requestAvatarInfo(getcontact(e->event.notify60[i].uin, 0, 0, nullptr), 0);
- }
- break;
}
+ break;
+ }
+ // Statuslist notify (version >= 6.0)
+ case GG_EVENT_NOTIFY60:
+ {
+ uin_t uin = (uin_t)getDword(GG_KEY_UIN, 0);
+ for (int i = 0; e->event.notify60[i].uin; i++) {
+ if (e->event.notify60[i].uin == uin)
+ continue;
+
+ wchar_t *descrT = mir_utf8decodeW(e->event.notify60[i].descr);
+ changecontactstatus(e->event.notify60[i].uin, e->event.notify60[i].status, descrT,
+ e->event.notify60[i].time, e->event.notify60[i].remote_ip, e->event.notify60[i].remote_port,
+ e->event.notify60[i].version);
+ mir_free(descrT);
+ requestAvatarInfo(getcontact(e->event.notify60[i].uin, 0, 0, nullptr), 0);
+ }
+ break;
+ }
- // Pubdir search reply && read own data reply
- case GG_EVENT_PUBDIR50_SEARCH_REPLY:
- case GG_EVENT_PUBDIR50_READ:
- case GG_EVENT_PUBDIR50_WRITE:
- {
- gg_pubdir50_t res = e->event.pubdir50;
- int i, count;
+ // Pubdir search reply && read own data reply
+ case GG_EVENT_PUBDIR50_SEARCH_REPLY:
+ case GG_EVENT_PUBDIR50_READ:
+ case GG_EVENT_PUBDIR50_WRITE:
+ {
+ gg_pubdir50_t res = e->event.pubdir50;
- if (e->type == GG_EVENT_PUBDIR50_SEARCH_REPLY)
- {
- debugLogA("mainthread() (%x): Got user info.", this);
- // Store next search UIN
- if (res->seq == GG_SEQ_SEARCH)
- next_uin = gg_pubdir50_next(res);
- }
- else if (e->type == GG_EVENT_PUBDIR50_READ)
- {
- debugLogA("mainthread() (%x): Got owner info.", this);
- }
- else if (e->type == GG_EVENT_PUBDIR50_WRITE)
- {
- debugLogA("mainthread() (%x): Public directory save succesful.", this);
- // Update user details
- GetInfo(NULL, 0);
- }
+ if (e->type == GG_EVENT_PUBDIR50_SEARCH_REPLY) {
+ debugLogA("mainthread() (%x): Got user info.", this);
+ // Store next search UIN
+ if (res->seq == GG_SEQ_SEARCH)
+ next_uin = gg_pubdir50_next(res);
+ }
+ else if (e->type == GG_EVENT_PUBDIR50_READ) {
+ debugLogA("mainthread() (%x): Got owner info.", this);
+ }
+ else if (e->type == GG_EVENT_PUBDIR50_WRITE) {
+ debugLogA("mainthread() (%x): Public directory save succesful.", this);
+ // Update user details
+ GetInfo(NULL, 0);
+ }
- if ((count = gg_pubdir50_count(res)) > 0)
- {
- for (i = 0; i < count; i++)
- {
- // Loadup fields
- const char *__fmnumber = gg_pubdir50_get(res, i, GG_PUBDIR50_UIN);
- wchar_t *__nickname = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_NICKNAME));
- wchar_t *__firstname = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_FIRSTNAME));
- wchar_t *__lastname = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_LASTNAME));
- wchar_t *__familyname = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_FAMILYNAME));
- wchar_t *__city = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_CITY));
- wchar_t *__familycity = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_FAMILYCITY));
- const char *__birthyear = gg_pubdir50_get(res, i, GG_PUBDIR50_BIRTHYEAR);
- const char *__gender = gg_pubdir50_get(res, i, GG_PUBDIR50_GENDER);
- const char *__status = gg_pubdir50_get(res, i, GG_PUBDIR50_STATUS);
- uin_t uin = __fmnumber ? atoi(__fmnumber) : 0;
-
- MCONTACT hContact = (res->seq == GG_SEQ_CHINFO) ? NULL : getcontact(uin, 0, 0, nullptr);
- debugLogA("mainthread() (%x): Search result for uin %d, seq %d.", this, uin, res->seq);
- if (res->seq == GG_SEQ_SEARCH)
- {
- wchar_t strFmt1[64];
- wchar_t strFmt2[64];
-
- wcsncpy_s(strFmt2, pcli->pfnGetStatusModeDescription( status_gg2m(atoi(__status)), 0), _TRUNCATE);
- if (__city) {
- mir_snwprintf(strFmt1, L", %s %s", TranslateT("City:"), __city);
+ int count = gg_pubdir50_count(res);
+ if (count > 0) {
+ for (int i = 0; i < count; i++) {
+ // Loadup fields
+ const char *__fmnumber = gg_pubdir50_get(res, i, GG_PUBDIR50_UIN);
+ wchar_t *__nickname = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_NICKNAME));
+ wchar_t *__firstname = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_FIRSTNAME));
+ wchar_t *__lastname = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_LASTNAME));
+ wchar_t *__familyname = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_FAMILYNAME));
+ wchar_t *__city = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_CITY));
+ wchar_t *__familycity = mir_utf8decodeW(gg_pubdir50_get(res, i, GG_PUBDIR50_FAMILYCITY));
+ const char *__birthyear = gg_pubdir50_get(res, i, GG_PUBDIR50_BIRTHYEAR);
+ const char *__gender = gg_pubdir50_get(res, i, GG_PUBDIR50_GENDER);
+ const char *__status = gg_pubdir50_get(res, i, GG_PUBDIR50_STATUS);
+ uin_t uin = __fmnumber ? atoi(__fmnumber) : 0;
+
+ MCONTACT hContact = (res->seq == GG_SEQ_CHINFO) ? NULL : getcontact(uin, 0, 0, nullptr);
+ debugLogA("mainthread() (%x): Search result for uin %d, seq %d.", this, uin, res->seq);
+ if (res->seq == GG_SEQ_SEARCH) {
+ wchar_t strFmt1[64];
+ wchar_t strFmt2[64];
+
+ wcsncpy_s(strFmt2, pcli->pfnGetStatusModeDescription(status_gg2m(atoi(__status)), 0), _TRUNCATE);
+ if (__city) {
+ mir_snwprintf(strFmt1, L", %s %s", TranslateT("City:"), __city);
+ mir_wstrncat(strFmt2, strFmt1, _countof(strFmt2) - mir_wstrlen(strFmt2));
+ }
+ if (__birthyear) {
+ time_t t = time(nullptr);
+ struct tm *lt = localtime(&t);
+ int br = atoi(__birthyear);
+
+ if (br < (lt->tm_year + 1900) && br > 1900) {
+ mir_snwprintf(strFmt1, L", %s %d", TranslateT("Age:"), (lt->tm_year + 1900) - br);
mir_wstrncat(strFmt2, strFmt1, _countof(strFmt2) - mir_wstrlen(strFmt2));
}
- if (__birthyear) {
- time_t t = time(nullptr);
- struct tm *lt = localtime(&t);
- int br = atoi(__birthyear);
-
- if (br < (lt->tm_year + 1900) && br > 1900) {
- mir_snwprintf(strFmt1, L", %s %d", TranslateT("Age:"), (lt->tm_year + 1900) - br);
- mir_wstrncat(strFmt2, strFmt1, _countof(strFmt2) - mir_wstrlen(strFmt2));
- }
- }
-
- GGSEARCHRESULT psr;
- memset(&psr, 0, sizeof(psr));
- psr.cbSize = sizeof(psr);
- psr.flags = PSR_UNICODE;
- psr.nick.w = __nickname;
- psr.firstName.w = __firstname;
- psr.lastName.w = __lastname;
- psr.email.w = strFmt2;
- psr.id.w = _ultow(uin, strFmt1, 10);
- psr.uin = uin;
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE) 1, (LPARAM)&psr);
}
- if (((res->seq == GG_SEQ_INFO || res->seq == GG_SEQ_GETNICK) && hContact != NULL)
- || res->seq == GG_SEQ_CHINFO)
- {
- // Change nickname if it's not present
- if (__nickname && (res->seq == GG_SEQ_GETNICK || res->seq == GG_SEQ_CHINFO))
- setWString(hContact, GG_KEY_NICK, __nickname);
-
- if (__nickname)
- setWString(hContact, GG_KEY_PD_NICKNAME, __nickname);
- else if (res->seq == GG_SEQ_CHINFO)
- delSetting(GG_KEY_PD_NICKNAME);
-
- // Change other info
- if (__city)
- setWString(hContact, GG_KEY_PD_CITY, __city);
- else if (res->seq == GG_SEQ_CHINFO)
- delSetting(GG_KEY_PD_CITY);
-
- if (__firstname)
- setWString(hContact, GG_KEY_PD_FIRSTNAME, __firstname);
- else if (res->seq == GG_SEQ_CHINFO)
- delSetting(GG_KEY_PD_FIRSTNAME);
-
- if (__lastname)
- setWString(hContact, GG_KEY_PD_LASTNAME, __lastname);
- else if (res->seq == GG_SEQ_CHINFO)
- delSetting(GG_KEY_PD_LASTNAME);
-
- if (__familyname)
- setWString(hContact, GG_KEY_PD_FAMILYNAME, __familyname);
- else if (res->seq == GG_SEQ_CHINFO)
- delSetting(GG_KEY_PD_FAMILYNAME);
-
- if (__familycity)
- setWString(hContact, GG_KEY_PD_FAMILYCITY, __familycity);
- else if (res->seq == GG_SEQ_CHINFO)
- delSetting(GG_KEY_PD_FAMILYCITY);
-
- if (__birthyear)
- {
- time_t t = time(nullptr);
- struct tm *lt = localtime(&t);
- int br = atoi(__birthyear);
- if (br > 0)
- {
- setWord(hContact, GG_KEY_PD_AGE, (WORD)(lt->tm_year + 1900 - br));
- setWord(hContact, GG_KEY_PD_BIRTHYEAR, (WORD)br);
- }
- }
- else if (res->seq == GG_SEQ_CHINFO)
- {
- delSetting(GG_KEY_PD_AGE);
- delSetting(GG_KEY_PD_BIRTHYEAR);
- }
+ GGSEARCHRESULT psr;
+ memset(&psr, 0, sizeof(psr));
+ psr.cbSize = sizeof(psr);
+ psr.flags = PSR_UNICODE;
+ psr.nick.w = __nickname;
+ psr.firstName.w = __firstname;
+ psr.lastName.w = __lastname;
+ psr.email.w = strFmt2;
+ psr.id.w = _ultow(uin, strFmt1, 10);
+ psr.uin = uin;
+ ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
+ }
- // Gadu-Gadu Male <-> Female
- if (__gender)
- {
- if (res->seq == GG_SEQ_CHINFO)
- setByte(hContact, GG_KEY_PD_GANDER,
- (BYTE)(!mir_strcmp(__gender, GG_PUBDIR50_GENDER_SET_MALE) ? 'M' :
- (!mir_strcmp(__gender, GG_PUBDIR50_GENDER_SET_FEMALE) ? 'F' : '?')));
- else
- setByte(hContact, GG_KEY_PD_GANDER,
- (BYTE)(!mir_strcmp(__gender, GG_PUBDIR50_GENDER_MALE) ? 'M' :
- (!mir_strcmp(__gender, GG_PUBDIR50_GENDER_FEMALE) ? 'F' : '?')));
- }
- else if (res->seq == GG_SEQ_CHINFO)
+ if (((res->seq == GG_SEQ_INFO || res->seq == GG_SEQ_GETNICK) && hContact != NULL)
+ || res->seq == GG_SEQ_CHINFO)
+ {
+ // Change nickname if it's not present
+ if (__nickname && (res->seq == GG_SEQ_GETNICK || res->seq == GG_SEQ_CHINFO))
+ setWString(hContact, GG_KEY_NICK, __nickname);
+
+ if (__nickname)
+ setWString(hContact, GG_KEY_PD_NICKNAME, __nickname);
+ else if (res->seq == GG_SEQ_CHINFO)
+ delSetting(GG_KEY_PD_NICKNAME);
+
+ // Change other info
+ if (__city)
+ setWString(hContact, GG_KEY_PD_CITY, __city);
+ else if (res->seq == GG_SEQ_CHINFO)
+ delSetting(GG_KEY_PD_CITY);
+
+ if (__firstname)
+ setWString(hContact, GG_KEY_PD_FIRSTNAME, __firstname);
+ else if (res->seq == GG_SEQ_CHINFO)
+ delSetting(GG_KEY_PD_FIRSTNAME);
+
+ if (__lastname)
+ setWString(hContact, GG_KEY_PD_LASTNAME, __lastname);
+ else if (res->seq == GG_SEQ_CHINFO)
+ delSetting(GG_KEY_PD_LASTNAME);
+
+ if (__familyname)
+ setWString(hContact, GG_KEY_PD_FAMILYNAME, __familyname);
+ else if (res->seq == GG_SEQ_CHINFO)
+ delSetting(GG_KEY_PD_FAMILYNAME);
+
+ if (__familycity)
+ setWString(hContact, GG_KEY_PD_FAMILYCITY, __familycity);
+ else if (res->seq == GG_SEQ_CHINFO)
+ delSetting(GG_KEY_PD_FAMILYCITY);
+
+ if (__birthyear) {
+ time_t t = time(nullptr);
+ struct tm *lt = localtime(&t);
+ int br = atoi(__birthyear);
+ if (br > 0)
{
- delSetting(GG_KEY_PD_GANDER);
+ setWord(hContact, GG_KEY_PD_AGE, (WORD)(lt->tm_year + 1900 - br));
+ setWord(hContact, GG_KEY_PD_BIRTHYEAR, (WORD)br);
}
-
- debugLogA("mainthread() (%x): Setting user info for uin %d.", this, uin);
- ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE) 1, 0);
+ }
+ else if (res->seq == GG_SEQ_CHINFO) {
+ delSetting(GG_KEY_PD_AGE);
+ delSetting(GG_KEY_PD_BIRTHYEAR);
}
- if (__nickname) mir_free(__nickname);
- if (__firstname) mir_free(__firstname);
- if (__lastname) mir_free(__lastname);
- if (__familyname) mir_free(__familyname);
- if (__city) mir_free(__city);
- if (__familycity) mir_free(__familycity);
+ // Gadu-Gadu Male <-> Female
+ if (__gender) {
+ if (res->seq == GG_SEQ_CHINFO)
+ setByte(hContact, GG_KEY_PD_GANDER,
+ (BYTE)(!mir_strcmp(__gender, GG_PUBDIR50_GENDER_SET_MALE) ? 'M' :
+ (!mir_strcmp(__gender, GG_PUBDIR50_GENDER_SET_FEMALE) ? 'F' : '?')));
+ else
+ setByte(hContact, GG_KEY_PD_GANDER,
+ (BYTE)(!mir_strcmp(__gender, GG_PUBDIR50_GENDER_MALE) ? 'M' :
+ (!mir_strcmp(__gender, GG_PUBDIR50_GENDER_FEMALE) ? 'F' : '?')));
+ }
+ else if (res->seq == GG_SEQ_CHINFO) {
+ delSetting(GG_KEY_PD_GANDER);
+ }
+ debugLogA("mainthread() (%x): Setting user info for uin %d.", this, uin);
+ ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0);
}
+
+ if (__nickname) mir_free(__nickname);
+ if (__firstname) mir_free(__firstname);
+ if (__lastname) mir_free(__lastname);
+ if (__familyname) mir_free(__familyname);
+ if (__city) mir_free(__city);
+ if (__familycity) mir_free(__familycity);
}
- if (res->seq == GG_SEQ_SEARCH)
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE) 1, 0);
- break;
}
+ if (res->seq == GG_SEQ_SEARCH)
+ ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
- // Status (deprecated)
- case GG_EVENT_STATUS:
- {
- wchar_t *descrT = mir_utf8decodeW(e->event.status.descr);
- changecontactstatus(e->event.status.uin, e->event.status.status, descrT, 0, 0, 0, 0);
- mir_free(descrT);
- }
- break;
+ break;
+ }
- // Status (version >= 6.0)
- case GG_EVENT_STATUS60:
- {
- MCONTACT hContact = getcontact(e->event.status60.uin, 0, 0, nullptr);
- int oldstatus = getWord(hContact, GG_KEY_STATUS, (WORD)ID_STATUS_OFFLINE);
- uin_t uin = (uin_t)getDword(GG_KEY_UIN, 0);
+ // Status (deprecated)
+ case GG_EVENT_STATUS:
+ {
+ wchar_t *descrT = mir_utf8decodeW(e->event.status.descr);
+ changecontactstatus(e->event.status.uin, e->event.status.status, descrT, 0, 0, 0, 0);
+ mir_free(descrT);
+ }
+ break;
- wchar_t *descrT = mir_utf8decodeW(e->event.status60.descr);
+ // Status (version >= 6.0)
+ case GG_EVENT_STATUS60:
+ {
+ MCONTACT hContact = getcontact(e->event.status60.uin, 0, 0, nullptr);
+ int oldstatus = getWord(hContact, GG_KEY_STATUS, (WORD)ID_STATUS_OFFLINE);
+ uin_t uin = (uin_t)getDword(GG_KEY_UIN, 0);
- if (e->event.status60.uin == uin)
- {
- // Status was changed by the user simultaneously logged on using different Miranda account or IM client
- int iStatus = status_gg2m(e->event.status60.status);
- CallProtoService(m_szModuleName, PS_SETAWAYMSG, iStatus, (LPARAM)descrT);
- CallProtoService(m_szModuleName, PS_SETSTATUS, iStatus, 0);
- }
-
- changecontactstatus(e->event.status60.uin, e->event.status60.status, descrT,
- e->event.status60.time, e->event.status60.remote_ip, e->event.status60.remote_port, e->event.status60.version);
-
- mir_free(descrT);
+ wchar_t *descrT = mir_utf8decodeW(e->event.status60.descr);
- if (oldstatus == ID_STATUS_OFFLINE && getWord(hContact, GG_KEY_STATUS, (WORD)ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE)
- requestAvatarInfo(hContact, 0);
- }
- break;
+ if (e->event.status60.uin == uin) {
+ // Status was changed by the user simultaneously logged on using different Miranda account or IM client
+ int iStatus = status_gg2m(e->event.status60.status);
+ CallProtoService(m_szModuleName, PS_SETAWAYMSG, iStatus, (LPARAM)descrT);
+ CallProtoService(m_szModuleName, PS_SETSTATUS, iStatus, 0);
+ }
- // Received userlist / or put info
- case GG_EVENT_USERLIST:
- switch (e->event.userlist.type) {
- case GG_USERLIST_GET_REPLY:
- if (e->event.userlist.reply) {
- parsecontacts(e->event.userlist.reply);
- MessageBox(nullptr, TranslateT("List import successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
- }
- break;
+ changecontactstatus(e->event.status60.uin, e->event.status60.status, descrT,
+ e->event.status60.time, e->event.status60.remote_ip, e->event.status60.remote_port, e->event.status60.version);
- case GG_USERLIST_PUT_REPLY:
- if (is_list_remove)
- MessageBox(nullptr, TranslateT("List remove successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
- else
- MessageBox(nullptr, TranslateT("List export successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
- break;
- }
- break;
+ mir_free(descrT);
- // Received message
- case GG_EVENT_MSG:
- // This is CTCP request
- if ((e->event.msg.msgclass & GG_CLASS_CTCP))
- {
- dccconnect(e->event.msg.sender);
+ if (oldstatus == ID_STATUS_OFFLINE && getWord(hContact, GG_KEY_STATUS, (WORD)ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE)
+ requestAvatarInfo(hContact, 0);
+ }
+ break;
+
+ // Received userlist / or put info
+ case GG_EVENT_USERLIST:
+ switch (e->event.userlist.type) {
+ case GG_USERLIST_GET_REPLY:
+ if (e->event.userlist.reply) {
+ parsecontacts(e->event.userlist.reply);
+ MessageBox(nullptr, TranslateT("List import successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
}
- // Check if not conference and block
- else if (!e->event.msg.recipients_count || gc_enabled)
- {
- // Check if groupchat
- if (e->event.msg.recipients_count && gc_enabled && !getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF))
- {
- wchar_t *chat = gc_getchat(e->event.msg.sender, e->event.msg.recipients, e->event.msg.recipients_count);
- if (chat)
- {
- wchar_t id[32];
- UIN2IDT(e->event.msg.sender, id);
-
- GCEVENT gce = { m_szModuleName, chat, GC_EVENT_MESSAGE };
- time_t t = time(nullptr);
- gce.ptszUID = id;
- wchar_t* messageT = mir_utf8decodeW(e->event.msg.message);
- gce.ptszText = messageT;
- gce.ptszNick = (wchar_t*) pcli->pfnGetContactDisplayName( getcontact(e->event.msg.sender, 1, 0, nullptr), 0);
- gce.time = (!(e->event.msg.msgclass & GG_CLASS_OFFLINE) || e->event.msg.time > (t - timeDeviation)) ? t : e->event.msg.time;
- gce.dwFlags = GCEF_ADDTOLOG;
- debugLogW(L"mainthread() (%x): Conference message to room %s & id %s.", this, chat, id);
- Chat_Event(&gce);
- mir_free(messageT);
- }
- }
- // Check if not empty message ( who needs it? )
- else if (!e->event.msg.recipients_count && e->event.msg.message && *e->event.msg.message && mir_strcmp(e->event.msg.message, "\xA0\0"))
- {
- PROTORECVEVENT pre = {0};
- time_t t = time(nullptr);
- pre.timestamp = (!(e->event.msg.msgclass & GG_CLASS_OFFLINE) || e->event.msg.time > (t - timeDeviation)) ? t : e->event.msg.time;
- pre.szMessage = e->event.msg.message;
- ProtoChainRecvMsg( getcontact(e->event.msg.sender, 1, 0, nullptr), &pre);
- }
-
- // RichEdit format included (image)
- if (e->event.msg.formats_length &&
- getByte(GG_KEY_IMGRECEIVE, GG_KEYDEF_IMGRECEIVE) &&
- !(db_get_dw(getcontact(e->event.msg.sender, 1, 0, nullptr), "Ignore", "Mask1", 0) & IGNOREEVENT_MESSAGE))
- {
- char *formats = (char*)e->event.msg.formats;
- int len = 0, formats_len = e->event.msg.formats_length, add_ptr;
-
- while (len < formats_len)
- {
- add_ptr = sizeof(struct gg_msg_richtext_format);
- if (((struct gg_msg_richtext_format*)formats)->font & GG_FONT_IMAGE)
- {
- struct gg_msg_richtext_image *image = (struct gg_msg_richtext_image *)(formats + add_ptr);
- gg_EnterCriticalSection(&sess_mutex, "mainthread", 18, "sess_mutex", 1);
- gg_image_request(sess, e->event.msg.sender, image->size, image->crc32);
- gg_LeaveCriticalSection(&sess_mutex, "mainthread", 18, 1, "sess_mutex", 1);
+ break;
- debugLogA("mainthread(): image request sent!");
- add_ptr += sizeof(struct gg_msg_richtext_image);
- }
- if (((struct gg_msg_richtext_format*)formats)->font & GG_FONT_COLOR)
- add_ptr += sizeof(struct gg_msg_richtext_color);
- len += add_ptr;
- formats += add_ptr;
- }
- }
- }
+ case GG_USERLIST_PUT_REPLY:
+ if (is_list_remove)
+ MessageBox(nullptr, TranslateT("List remove successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
+ else
+ MessageBox(nullptr, TranslateT("List export successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
break;
+ }
+ break;
- // Message sent from concurrent user session
- case GG_EVENT_MULTILOGON_MSG:
- if (e->event.multilogon_msg.recipients_count && gc_enabled && !getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF))
- {
- wchar_t *chat = gc_getchat(e->event.multilogon_msg.sender, e->event.multilogon_msg.recipients, e->event.multilogon_msg.recipients_count);
- if (chat)
- {
+ // Received message
+ case GG_EVENT_MSG:
+ // This is CTCP request
+ if ((e->event.msg.msgclass & GG_CLASS_CTCP)) {
+ dccconnect(e->event.msg.sender);
+ }
+ // Check if not conference and block
+ else if (!e->event.msg.recipients_count || gc_enabled) {
+ // Check if groupchat
+ if (e->event.msg.recipients_count && gc_enabled && !getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF)) {
+ wchar_t *chat = gc_getchat(e->event.msg.sender, e->event.msg.recipients, e->event.msg.recipients_count);
+ if (chat) {
wchar_t id[32];
- UIN2IDT(getDword(GG_KEY_UIN, 0), id);
+ UIN2IDT(e->event.msg.sender, id);
GCEVENT gce = { m_szModuleName, chat, GC_EVENT_MESSAGE };
+ time_t t = time(nullptr);
gce.ptszUID = id;
- wchar_t* messageT = mir_utf8decodeW(e->event.multilogon_msg.message);
+ wchar_t* messageT = mir_utf8decodeW(e->event.msg.message);
gce.ptszText = messageT;
- wchar_t* nickT;
- if (!getWString(GG_KEY_NICK, &dbv)){
- nickT = mir_wstrdup(dbv.ptszVal);
- db_free(&dbv);
- }
- else nickT = mir_wstrdup(TranslateT("Me"));
- gce.ptszNick = nickT;
- gce.time = e->event.multilogon_msg.time;
- gce.bIsMe = 1;
+ gce.ptszNick = (wchar_t*)pcli->pfnGetContactDisplayName(getcontact(e->event.msg.sender, 1, 0, nullptr), 0);
+ gce.time = (!(e->event.msg.msgclass & GG_CLASS_OFFLINE) || e->event.msg.time > (t - timeDeviation)) ? t : e->event.msg.time;
gce.dwFlags = GCEF_ADDTOLOG;
- debugLogW(L"mainthread() (%x): Sent conference message to room %s.", this, chat);
+ debugLogW(L"mainthread() (%x): Conference message to room %s & id %s.", this, chat, id);
Chat_Event(&gce);
mir_free(messageT);
- mir_free(nickT);
}
}
- else if (!e->event.multilogon_msg.recipients_count && e->event.multilogon_msg.message && *e->event.multilogon_msg.message
- && mir_strcmp(e->event.multilogon_msg.message, "\xA0\0"))
- {
- DBEVENTINFO dbei = {};
- dbei.szModule = m_szModuleName;
- dbei.timestamp = (DWORD)e->event.multilogon_msg.time;
- dbei.flags = DBEF_SENT | DBEF_UTF;
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = (DWORD)mir_strlen(e->event.multilogon_msg.message) + 1;
- dbei.pBlob = (PBYTE)e->event.multilogon_msg.message;
- db_event_add( getcontact(e->event.multilogon_msg.sender, 1, 0, nullptr), &dbei);
+ // Check if not empty message ( who needs it? )
+ else if (!e->event.msg.recipients_count && e->event.msg.message && *e->event.msg.message && mir_strcmp(e->event.msg.message, "\xA0\0")) {
+ PROTORECVEVENT pre = { 0 };
+ time_t t = time(nullptr);
+ pre.timestamp = (!(e->event.msg.msgclass & GG_CLASS_OFFLINE) || e->event.msg.time > (t - timeDeviation)) ? t : e->event.msg.time;
+ pre.szMessage = e->event.msg.message;
+ ProtoChainRecvMsg(getcontact(e->event.msg.sender, 1, 0, nullptr), &pre);
}
- break;
- // Information on active concurrent sessions
- case GG_EVENT_MULTILOGON_INFO:
+ // RichEdit format included (image)
+ if (e->event.msg.formats_length &&
+ getByte(GG_KEY_IMGRECEIVE, GG_KEYDEF_IMGRECEIVE) &&
+ !(db_get_dw(getcontact(e->event.msg.sender, 1, 0, nullptr), "Ignore", "Mask1", 0) & IGNOREEVENT_MESSAGE))
{
- list_t l;
- int* iIndexes = nullptr, i;
- debugLogA("mainthread(): Concurrent sessions count: %d.", e->event.multilogon_info.count);
- if (e->event.multilogon_info.count > 0)
- iIndexes = (int*)mir_calloc(e->event.multilogon_info.count * sizeof(int));
- gg_EnterCriticalSection(&sessions_mutex, "mainthread", 19, "sess_mutex", 1);
- for (l = sessions; l; l = l->next)
- {
- struct gg_multilogon_session* msess = (struct gg_multilogon_session*)l->data;
- for (i = 0; i < e->event.multilogon_info.count; i++)
- {
- if (!memcmp(&msess->id, &e->event.multilogon_info.sessions[i].id, sizeof(gg_multilogon_id_t)) && iIndexes)
- {
- iIndexes[i]++;
- break;
- }
- }
- mir_free(msess->name);
- mir_free(msess);
- }
- list_destroy(sessions, 0);
- sessions = nullptr;
- for (i = 0; i < e->event.multilogon_info.count; i++)
- {
- gg_multilogon_session* msess = (gg_multilogon_session*)mir_alloc(sizeof(struct gg_multilogon_session));
- memcpy(msess, &e->event.multilogon_info.sessions[i], sizeof(struct gg_multilogon_session));
- msess->name = mir_strdup(*e->event.multilogon_info.sessions[i].name != '\0'
- ? e->event.multilogon_info.sessions[i].name
- : Translate("Unknown client"));
- list_add(&sessions, msess, 0);
- }
- gg_LeaveCriticalSection(&sessions_mutex, "mainthread", 19, 1, "sessions_mutex", 1);
- sessions_updatedlg();
- if (ServiceExists(MS_POPUP_ADDPOPUPCLASS))
+ char *formats = (char*)e->event.msg.formats;
+ int len = 0, formats_len = e->event.msg.formats_length, add_ptr;
+
+ while (len < formats_len)
{
- const wchar_t* szText = time(nullptr) - logonTime > 3
- ? TranslateT("You have logged in at another location")
- : TranslateT("You are logged in at another location");
- for (i = 0; i < e->event.multilogon_info.count; i++)
- {
- wchar_t szMsg[MAX_SECONDLINE];
- if (iIndexes && iIndexes[i])
- continue;
-
- mir_snwprintf(szMsg, L"%s (%s)", szText,
- *e->event.multilogon_info.sessions[i].name != '\0' ?
- _A2T(e->event.multilogon_info.sessions[i].name) : TranslateT("Unknown client"));
- showpopup(m_tszUserName, szMsg, GG_POPUP_MULTILOGON);
+ add_ptr = sizeof(struct gg_msg_richtext_format);
+ if (((struct gg_msg_richtext_format*)formats)->font & GG_FONT_IMAGE) {
+ struct gg_msg_richtext_image *image = (struct gg_msg_richtext_image *)(formats + add_ptr);
+ gg_EnterCriticalSection(&sess_mutex, "mainthread", 18, "sess_mutex", 1);
+ gg_image_request(sess, e->event.msg.sender, image->size, image->crc32);
+ gg_LeaveCriticalSection(&sess_mutex, "mainthread", 18, 1, "sess_mutex", 1);
+
+ debugLogA("mainthread(): image request sent!");
+ add_ptr += sizeof(struct gg_msg_richtext_image);
}
+ if (((struct gg_msg_richtext_format*)formats)->font & GG_FONT_COLOR)
+ add_ptr += sizeof(struct gg_msg_richtext_color);
+ len += add_ptr;
+ formats += add_ptr;
}
- mir_free(iIndexes);
}
- break;
+ }
+ break;
- // Image reply sent
- case GG_EVENT_IMAGE_REPLY:
- // Get rid of empty image
- if (e->event.image_reply.size && e->event.image_reply.image)
+ // Message sent from concurrent user session
+ case GG_EVENT_MULTILOGON_MSG:
+ if (e->event.multilogon_msg.recipients_count && gc_enabled && !getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF))
+ {
+ wchar_t *chat = gc_getchat(e->event.multilogon_msg.sender, e->event.multilogon_msg.recipients, e->event.multilogon_msg.recipients_count);
+ if (chat)
{
- MCONTACT hContact = getcontact(e->event.image_reply.sender, 1, 0, nullptr);
- void *img = (void *)img_loadpicture(e, nullptr);
-
- if (!img)
- break;
-
- if (getByte(GG_KEY_IMGMETHOD, GG_KEYDEF_IMGMETHOD) == 1 || img_opened(e->event.image_reply.sender))
- {
- img_display(hContact, img);
- }
- else if (getByte(GG_KEY_IMGMETHOD, GG_KEYDEF_IMGMETHOD) == 2)
- {
- img_displayasmsg(hContact, img);
+ wchar_t id[32];
+ UIN2IDT(getDword(GG_KEY_UIN, 0), id);
+
+ GCEVENT gce = { m_szModuleName, chat, GC_EVENT_MESSAGE };
+ gce.ptszUID = id;
+ wchar_t* messageT = mir_utf8decodeW(e->event.multilogon_msg.message);
+ gce.ptszText = messageT;
+ wchar_t* nickT;
+ if (!getWString(GG_KEY_NICK, &dbv)) {
+ nickT = mir_wstrdup(dbv.ptszVal);
+ db_free(&dbv);
}
else
+ nickT = mir_wstrdup(TranslateT("Me"));
+
+ gce.ptszNick = nickT;
+ gce.time = e->event.multilogon_msg.time;
+ gce.bIsMe = 1;
+ gce.dwFlags = GCEF_ADDTOLOG;
+ debugLogW(L"mainthread() (%x): Sent conference message to room %s.", this, chat);
+ Chat_Event(&gce);
+ mir_free(messageT);
+ mir_free(nickT);
+ }
+ }
+ else if (!e->event.multilogon_msg.recipients_count && e->event.multilogon_msg.message && *e->event.multilogon_msg.message
+ && mir_strcmp(e->event.multilogon_msg.message, "\xA0\0"))
+ {
+ DBEVENTINFO dbei = {};
+ dbei.szModule = m_szModuleName;
+ dbei.timestamp = (DWORD)e->event.multilogon_msg.time;
+ dbei.flags = DBEF_SENT | DBEF_UTF;
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.cbBlob = (DWORD)mir_strlen(e->event.multilogon_msg.message) + 1;
+ dbei.pBlob = (PBYTE)e->event.multilogon_msg.message;
+ db_event_add(getcontact(e->event.multilogon_msg.sender, 1, 0, nullptr), &dbei);
+ }
+ break;
+
+ // Information on active concurrent sessions
+ case GG_EVENT_MULTILOGON_INFO:
+ {
+ list_t l;
+ int* iIndexes = nullptr, i;
+ debugLogA("mainthread(): Concurrent sessions count: %d.", e->event.multilogon_info.count);
+ if (e->event.multilogon_info.count > 0)
+ iIndexes = (int*)mir_calloc(e->event.multilogon_info.count * sizeof(int));
+ gg_EnterCriticalSection(&sessions_mutex, "mainthread", 19, "sess_mutex", 1);
+ for (l = sessions; l; l = l->next)
+ {
+ struct gg_multilogon_session* msess = (struct gg_multilogon_session*)l->data;
+ for (i = 0; i < e->event.multilogon_info.count; i++)
+ {
+ if (!memcmp(&msess->id, &e->event.multilogon_info.sessions[i].id, sizeof(gg_multilogon_id_t)) && iIndexes)
{
- char service[128];
- mir_snprintf(service, GGS_RECVIMAGE, m_szModuleName);
-
- CLISTEVENT cle = { 0 };
- cle.hContact = hContact;
- cle.hIcon = LoadIconEx("image", FALSE);
- cle.flags = CLEF_URGENT;
- cle.hDbEvent = -98;
- cle.lParam = (LPARAM)img;
- cle.pszService = service;
- cle.szTooltip.a = Translate("Incoming image");
- pcli->pfnAddEvent(&cle);
- ReleaseIconEx("image", FALSE);
+ iIndexes[i]++;
+ break;
}
}
- break;
+ mir_free(msess->name);
+ mir_free(msess);
+ }
+ list_destroy(sessions, 0);
+ sessions = nullptr;
+ for (i = 0; i < e->event.multilogon_info.count; i++)
+ {
+ gg_multilogon_session* msess = (gg_multilogon_session*)mir_alloc(sizeof(struct gg_multilogon_session));
+ memcpy(msess, &e->event.multilogon_info.sessions[i], sizeof(struct gg_multilogon_session));
+ msess->name = mir_strdup(*e->event.multilogon_info.sessions[i].name != '\0'
+ ? e->event.multilogon_info.sessions[i].name
+ : Translate("Unknown client"));
+ list_add(&sessions, msess, 0);
+ }
+ gg_LeaveCriticalSection(&sessions_mutex, "mainthread", 19, 1, "sessions_mutex", 1);
+ sessions_updatedlg();
+ if (ServiceExists(MS_POPUP_ADDPOPUPCLASS))
+ {
+ const wchar_t* szText = time(nullptr) - logonTime > 3
+ ? TranslateT("You have logged in at another location")
+ : TranslateT("You are logged in at another location");
+ for (i = 0; i < e->event.multilogon_info.count; i++)
+ {
+ wchar_t szMsg[MAX_SECONDLINE];
+ if (iIndexes && iIndexes[i])
+ continue;
+
+ mir_snwprintf(szMsg, L"%s (%s)", szText,
+ *e->event.multilogon_info.sessions[i].name != '\0' ?
+ _A2T(e->event.multilogon_info.sessions[i].name) : TranslateT("Unknown client"));
+ showpopup(m_tszUserName, szMsg, GG_POPUP_MULTILOGON);
+ }
+ }
+ mir_free(iIndexes);
+ }
+ break;
+
+ // Image reply sent
+ case GG_EVENT_IMAGE_REPLY:
+ // Get rid of empty image
+ if (e->event.image_reply.size && e->event.image_reply.image)
+ {
+ MCONTACT hContact = getcontact(e->event.image_reply.sender, 1, 0, nullptr);
+ void *img = (void *)img_loadpicture(e, nullptr);
+
+ if (!img)
+ break;
+
+ if (getByte(GG_KEY_IMGMETHOD, GG_KEYDEF_IMGMETHOD) == 1 || img_opened(e->event.image_reply.sender))
+ {
+ img_display(hContact, img);
+ }
+ else if (getByte(GG_KEY_IMGMETHOD, GG_KEYDEF_IMGMETHOD) == 2)
+ {
+ img_displayasmsg(hContact, img);
+ }
+ else
+ {
+ char service[128];
+ mir_snprintf(service, GGS_RECVIMAGE, m_szModuleName);
+
+ CLISTEVENT cle = { 0 };
+ cle.hContact = hContact;
+ cle.hIcon = LoadIconEx("image", FALSE);
+ cle.flags = CLEF_URGENT;
+ cle.hDbEvent = -98;
+ cle.lParam = (LPARAM)img;
+ cle.pszService = service;
+ cle.szTooltip.a = Translate("Incoming image");
+ pcli->pfnAddEvent(&cle);
+ ReleaseIconEx("image", FALSE);
+ }
+ }
+ break;
// Image send request
- case GG_EVENT_IMAGE_REQUEST:
- img_sendonrequest(e);
- break;
+ case GG_EVENT_IMAGE_REQUEST:
+ img_sendonrequest(e);
+ break;
// Incoming direct connection
- case GG_EVENT_DCC7_NEW:
- {
- struct gg_dcc7 *dcc7 = e->event.dcc7_new;
- debugLogA("mainthread() (%x): Incoming direct connection.", this);
- dcc7->contact = (void*)getcontact(dcc7->peer_uin, 0, 0, nullptr);
-
- // Check if user is on the list and if it is my uin
- if (!dcc7->contact || getDword(GG_KEY_UIN, -1) != dcc7->uin) {
- gg_dcc7_free(dcc7);
- e->event.dcc7_new = nullptr;
- break;
- }
+ case GG_EVENT_DCC7_NEW:
+ {
+ struct gg_dcc7 *dcc7 = e->event.dcc7_new;
+ debugLogA("mainthread() (%x): Incoming direct connection.", this);
+ dcc7->contact = (void*)getcontact(dcc7->peer_uin, 0, 0, nullptr);
+
+ // Check if user is on the list and if it is my uin
+ if (!dcc7->contact || getDword(GG_KEY_UIN, -1) != dcc7->uin) {
+ gg_dcc7_free(dcc7);
+ e->event.dcc7_new = nullptr;
+ break;
+ }
- // Add to waiting transfers
- gg_EnterCriticalSection(&ft_mutex, "mainthread", 20, "ft_mutex", 1);
- list_add(&transfers, dcc7, 0);
- gg_LeaveCriticalSection(&ft_mutex, "mainthread", 20, 1, "ft_mutex", 1);
+ // Add to waiting transfers
+ gg_EnterCriticalSection(&ft_mutex, "mainthread", 20, "ft_mutex", 1);
+ list_add(&transfers, dcc7, 0);
+ gg_LeaveCriticalSection(&ft_mutex, "mainthread", 20, 1, "ft_mutex", 1);
- //////////////////////////////////////////////////
- // Add file recv request
+ //////////////////////////////////////////////////
+ // Add file recv request
- debugLogA("mainthread() (%x): Client: %d, File ack filename \"%s\" size %d.", this, dcc7->peer_uin,
- dcc7->filename, dcc7->size);
+ debugLogA("mainthread() (%x): Client: %d, File ack filename \"%s\" size %d.", this, dcc7->peer_uin,
+ dcc7->filename, dcc7->size);
- wchar_t* filenameT = mir_a2u((char*)dcc7->filename);
+ wchar_t* filenameT = mir_a2u((char*)dcc7->filename);
- PROTORECVFILET pre = {0};
- pre.dwFlags = PRFF_UNICODE;
- pre.fileCount = 1;
- pre.timestamp = time(nullptr);
- pre.descr.w = filenameT;
- pre.files.w = &filenameT;
- pre.lParam = (LPARAM)dcc7;
- ProtoChainRecvFile((UINT_PTR)dcc7->contact, &pre);
+ PROTORECVFILET pre = { 0 };
+ pre.dwFlags = PRFF_UNICODE;
+ pre.fileCount = 1;
+ pre.timestamp = time(nullptr);
+ pre.descr.w = filenameT;
+ pre.files.w = &filenameT;
+ pre.lParam = (LPARAM)dcc7;
+ ProtoChainRecvFile((UINT_PTR)dcc7->contact, &pre);
- mir_free(filenameT);
- e->event.dcc7_new = nullptr;
- }
- break;
+ mir_free(filenameT);
+ e->event.dcc7_new = nullptr;
+ }
+ break;
- // Direct connection rejected
- case GG_EVENT_DCC7_REJECT:
- {
- struct gg_dcc7 *dcc7 = e->event.dcc7_reject.dcc7;
- if (dcc7->type == GG_SESSION_DCC7_SEND)
- {
- debugLogA("mainthread() (%x): File transfer denied by client %d (reason = %d).", this, dcc7->peer_uin, e->event.dcc7_reject.reason);
- ProtoBroadcastAck((UINT_PTR)dcc7->contact, ACKTYPE_FILE, ACKRESULT_DENIED, dcc7, 0);
-
- // Remove from watches and free
- gg_EnterCriticalSection(&ft_mutex, "mainthread", 21, "ft_mutex", 1);
- list_remove(&watches, dcc7, 0);
- gg_LeaveCriticalSection(&ft_mutex, "mainthread", 21, 1, "ft_mutex", 1);
- gg_dcc7_free(dcc7);
- }
- else
- {
- debugLogA("mainthread() (%x): File transfer aborted by client %d.", this, dcc7->peer_uin);
+ // Direct connection rejected
+ case GG_EVENT_DCC7_REJECT:
+ {
+ struct gg_dcc7 *dcc7 = e->event.dcc7_reject.dcc7;
+ if (dcc7->type == GG_SESSION_DCC7_SEND)
+ {
+ debugLogA("mainthread() (%x): File transfer denied by client %d (reason = %d).", this, dcc7->peer_uin, e->event.dcc7_reject.reason);
+ ProtoBroadcastAck((UINT_PTR)dcc7->contact, ACKTYPE_FILE, ACKRESULT_DENIED, dcc7, 0);
+
+ // Remove from watches and free
+ gg_EnterCriticalSection(&ft_mutex, "mainthread", 21, "ft_mutex", 1);
+ list_remove(&watches, dcc7, 0);
+ gg_LeaveCriticalSection(&ft_mutex, "mainthread", 21, 1, "ft_mutex", 1);
+ gg_dcc7_free(dcc7);
+ }
+ else
+ {
+ debugLogA("mainthread() (%x): File transfer aborted by client %d.", this, dcc7->peer_uin);
- // Remove transfer from waiting list
- gg_EnterCriticalSection(&ft_mutex, "mainthread", 22, "ft_mutex", 1);
- list_remove(&transfers, dcc7, 0);
- gg_LeaveCriticalSection(&ft_mutex, "mainthread", 22, 1, "ft_mutex", 1);
+ // Remove transfer from waiting list
+ gg_EnterCriticalSection(&ft_mutex, "mainthread", 22, "ft_mutex", 1);
+ list_remove(&transfers, dcc7, 0);
+ gg_LeaveCriticalSection(&ft_mutex, "mainthread", 22, 1, "ft_mutex", 1);
+ }
+ }
+ break;
- }
- }
+ // Direct connection error
+ case GG_EVENT_DCC7_ERROR:
+ {
+ struct gg_dcc7 *dcc7 = e->event.dcc7_error_ex.dcc7;
+ switch (e->event.dcc7_error) {
+ case GG_ERROR_DCC7_HANDSHAKE:
+ debugLogA("mainthread() (%x): Client: %d, Handshake error.", this, dcc7 ? dcc7->peer_uin : 0);
+ break;
+ case GG_ERROR_DCC7_NET:
+ debugLogA("mainthread() (%x): Client: %d, Network error.", this, dcc7 ? dcc7->peer_uin : 0);
+ break;
+ case GG_ERROR_DCC7_FILE:
+ debugLogA("mainthread() (%x): Client: %d, File read/write error.", this, dcc7 ? dcc7->peer_uin : 0);
break;
+ case GG_ERROR_DCC7_EOF:
+ debugLogA("mainthread() (%x): Client: %d, End of file/connection error.", this, dcc7 ? dcc7->peer_uin : 0);
+ break;
+ case GG_ERROR_DCC7_REFUSED:
+ debugLogA("mainthread() (%x): Client: %d, Connection refused error.", this, dcc7 ? dcc7->peer_uin : 0);
+ break;
+ case GG_ERROR_DCC7_RELAY:
+ debugLogA("mainthread() (%x): Client: %d, Relay connection error.", this, dcc7 ? dcc7->peer_uin : 0);
+ break;
+ default:
+ debugLogA("mainthread() (%x): Client: %d, Unknown error.", this, dcc7 ? dcc7->peer_uin : 0);
+ }
- // Direct connection error
- case GG_EVENT_DCC7_ERROR:
- {
- struct gg_dcc7 *dcc7 = e->event.dcc7_error_ex.dcc7;
- switch (e->event.dcc7_error)
- {
- case GG_ERROR_DCC7_HANDSHAKE:
- debugLogA("mainthread() (%x): Client: %d, Handshake error.", this, dcc7 ? dcc7->peer_uin : 0);
- break;
- case GG_ERROR_DCC7_NET:
- debugLogA("mainthread() (%x): Client: %d, Network error.", this, dcc7 ? dcc7->peer_uin : 0);
- break;
- case GG_ERROR_DCC7_FILE:
- debugLogA("mainthread() (%x): Client: %d, File read/write error.", this, dcc7 ? dcc7->peer_uin : 0);
- break;
- case GG_ERROR_DCC7_EOF:
- debugLogA("mainthread() (%x): Client: %d, End of file/connection error.", this, dcc7 ? dcc7->peer_uin : 0);
- break;
- case GG_ERROR_DCC7_REFUSED:
- debugLogA("mainthread() (%x): Client: %d, Connection refused error.", this, dcc7 ? dcc7->peer_uin : 0);
- break;
- case GG_ERROR_DCC7_RELAY:
- debugLogA("mainthread() (%x): Client: %d, Relay connection error.", this, dcc7 ? dcc7->peer_uin : 0);
- break;
- default:
- debugLogA("mainthread() (%x): Client: %d, Unknown error.", this, dcc7 ? dcc7->peer_uin : 0);
- }
- if (!dcc7) break;
+ if (!dcc7)
+ break;
- // Remove from watches
- list_remove(&watches, dcc7, 0);
+ // Remove from watches
+ list_remove(&watches, dcc7, 0);
- // Close file & fail
- if (dcc7->file_fd != -1)
- {
- _close(dcc7->file_fd);
- dcc7->file_fd = -1;
- }
+ // Close file & fail
+ if (dcc7->file_fd != -1) {
+ _close(dcc7->file_fd);
+ dcc7->file_fd = -1;
+ }
- if (dcc7->contact)
- ProtoBroadcastAck((UINT_PTR)dcc7->contact, ACKTYPE_FILE, ACKRESULT_FAILED, dcc7, 0);
+ if (dcc7->contact)
+ ProtoBroadcastAck((UINT_PTR)dcc7->contact, ACKTYPE_FILE, ACKRESULT_FAILED, dcc7, 0);
- // Free dcc
- gg_dcc7_free(dcc7);
- }
- break;
+ // Free dcc
+ gg_dcc7_free(dcc7);
+ }
+ break;
- case GG_EVENT_XML_ACTION:
- if (getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS)) {
- HXML hXml;
- wchar_t *xmlAction;
- wchar_t *tag;
-
- xmlAction = mir_a2u(e->event.xml_action.data);
- tag = mir_a2u("events");
- hXml = xmlParseString(xmlAction, nullptr, tag);
-
- if (hXml != nullptr) {
- HXML node;
- char *type, *sender;
-
- mir_free(tag);
- tag = mir_a2u("event/type");
- node = xmlGetChildByPath(hXml, tag, 0);
- type = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr;
-
- mir_free(tag);
- tag = mir_a2u("event/sender");
- node = xmlGetChildByPath(hXml, tag, 0);
- sender = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr;
- debugLogA("mainthread() (%x): XML Action type: %s.", this, type != nullptr ? type : "unknown");
- // Avatar change notify
- if (type != nullptr && !mir_strcmp(type, "28")) {
- debugLogA("mainthread() (%x): Client %s changed his avatar.", this, sender);
- requestAvatarInfo(getcontact(atoi(sender), 0, 0, nullptr), 0);
- }
- mir_free(type);
- mir_free(sender);
- xmlDestroyNode(hXml);
- }
+ case GG_EVENT_XML_ACTION:
+ if (getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS)) {
+ wchar_t *xmlAction = mir_a2u(e->event.xml_action.data);
+ wchar_t *tag = mir_a2u("events");
+ HXML hXml = xmlParseString(xmlAction, nullptr, tag);
+
+ if (hXml != nullptr) {
mir_free(tag);
- mir_free(xmlAction);
+ tag = mir_a2u("event/type");
+ HXML node = xmlGetChildByPath(hXml, tag, 0);
+ char *type = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr;
+
+ mir_free(tag);
+ tag = mir_a2u("event/sender");
+ node = xmlGetChildByPath(hXml, tag, 0);
+ char *sender = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr;
+ debugLogA("mainthread() (%x): XML Action type: %s.", this, type != nullptr ? type : "unknown");
+ // Avatar change notify
+ if (type != nullptr && !mir_strcmp(type, "28")) {
+ debugLogA("mainthread() (%x): Client %s changed his avatar.", this, sender);
+ requestAvatarInfo(getcontact(atoi(sender), 0, 0, nullptr), 0);
+ }
+ mir_free(type);
+ mir_free(sender);
+ xmlDestroyNode(hXml);
}
- break;
+ mir_free(tag);
+ mir_free(xmlAction);
+ }
+ break;
- case GG_EVENT_TYPING_NOTIFICATION:
- {
- MCONTACT hContact = getcontact(e->event.typing_notification.uin, 0, 0, nullptr);
+ case GG_EVENT_TYPING_NOTIFICATION:
+ {
+ MCONTACT hContact = getcontact(e->event.typing_notification.uin, 0, 0, nullptr);
#ifdef DEBUGMODE
- debugLogA("mainthread() (%x): Typing notification from %d (%d).", this,
- e->event.typing_notification.uin, e->event.typing_notification.length);
+ debugLogA("mainthread() (%x): Typing notification from %d (%d).", this,
+ e->event.typing_notification.uin, e->event.typing_notification.length);
#endif
- CallService(MS_PROTO_CONTACTISTYPING, hContact,
- e->event.typing_notification.length > 0 ? 7 : PROTOTYPE_CONTACTTYPING_OFF);
- }
- break;
+ CallService(MS_PROTO_CONTACTISTYPING, hContact,
+ e->event.typing_notification.length > 0 ? 7 : PROTOTYPE_CONTACTTYPING_OFF);
+ }
+ break;
}
// Free event struct
gg_free_event(e);
@@ -1246,10 +1221,8 @@ retry:
// Change status function
void GGPROTO::broadcastnewstatus(int newStatus)
{
- int oldStatus;
-
gg_EnterCriticalSection(&modemsg_mutex, "broadcastnewstatus", 24, "modemsg_mutex", 1);
- oldStatus = m_iStatus;
+ int oldStatus = m_iStatus;
if (oldStatus == newStatus)
{
gg_LeaveCriticalSection(&modemsg_mutex, "broadcastnewstatus", 24, 1, "modemsg_mutex", 1);
@@ -1258,7 +1231,7 @@ void GGPROTO::broadcastnewstatus(int newStatus)
m_iStatus = newStatus;
gg_LeaveCriticalSection(&modemsg_mutex, "broadcastnewstatus", 24, 2, "modemsg_mutex", 1);
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) oldStatus, newStatus);
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, newStatus);
debugLogA("broadcastnewstatus(): Broadcast new status: %d.", newStatus);
}
@@ -1300,9 +1273,9 @@ int GGPROTO::contactdeleted(WPARAM hContact, LPARAM)
////////////////////////////////////////////////////////////
// When db settings changed
-static wchar_t* sttSettingToTchar( DBVARIANT* value )
+static wchar_t* sttSettingToTchar(DBVARIANT* value)
{
- switch(value->type) {
+ switch (value->type) {
case DBVT_ASCIIZ:
return mir_a2u(value->pszVal);
case DBVT_UTF8:
@@ -1315,7 +1288,7 @@ static wchar_t* sttSettingToTchar( DBVARIANT* value )
int GGPROTO::dbsettingchanged(WPARAM hContact, LPARAM lParam)
{
- DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam;
+ DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam;
#ifdef DEBUGMODE
debugLogA("dbsettingchanged(): fired. szModule=%s szSetting=%s", cws->szModule, cws->szSetting);
@@ -1326,17 +1299,16 @@ int GGPROTO::dbsettingchanged(WPARAM hContact, LPARAM lParam)
return 0;
// If contact has been blocked
- if (!strcmp(cws->szModule, m_szModuleName) && !mir_strcmp(cws->szSetting, GG_KEY_BLOCK))
- {
+ if (!strcmp(cws->szModule, m_szModuleName) && !mir_strcmp(cws->szSetting, GG_KEY_BLOCK)) {
notifyuser(hContact, 1);
return 0;
}
// Contact is being renamed
- if (gc_enabled && !strcmp(cws->szModule, m_szModuleName) && !strcmp(cws->szSetting, GG_KEY_NICK)){
-
+ if (gc_enabled && !strcmp(cws->szModule, m_szModuleName) && !strcmp(cws->szSetting, GG_KEY_NICK)) {
wchar_t* ptszVal = sttSettingToTchar(&(cws->value));
- if(ptszVal==nullptr) return 0;
+ if (ptszVal == nullptr)
+ return 0;
// Groupchat window contact is being renamed
DBVARIANT dbv;
@@ -1353,7 +1325,8 @@ int GGPROTO::dbsettingchanged(WPARAM hContact, LPARAM lParam)
/* FIXME */ cascade = 0;
}
db_free(&dbv);
- } else {
+ }
+ else {
// Change contact name on all chats
gc_changenick(hContact, ptszVal);
}
@@ -1364,9 +1337,11 @@ int GGPROTO::dbsettingchanged(WPARAM hContact, LPARAM lParam)
if (!strcmp(cws->szModule, "CList"))
{
// If name changed... change nick
- if (!strcmp(cws->szSetting, "MyHandle")){
+ if (!strcmp(cws->szSetting, "MyHandle")) {
wchar_t* ptszVal = sttSettingToTchar(&(cws->value));
- if(ptszVal==nullptr) return 0;
+ if (ptszVal == nullptr)
+ return 0;
+
setWString(hContact, GG_KEY_NICK, ptszVal);
mir_free(ptszVal);
}
@@ -1416,12 +1391,14 @@ void GGPROTO::setalloffline()
void GGPROTO::notifyuser(MCONTACT hContact, int refresh)
{
uin_t uin;
- if (!hContact) return;
+ if (!hContact)
+ return;
+
if (isonline() && (uin = (uin_t)getDword(hContact, GG_KEY_UIN, 0)))
{
// Check if user should be invisible
// Or be blocked ?
- if ((getWord(hContact, GG_KEY_APPARENT, (WORD) ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) ||
+ if ((getWord(hContact, GG_KEY_APPARENT, (WORD)ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) ||
db_get_b(hContact, "CList", "NotOnList", 0))
{
gg_EnterCriticalSection(&sess_mutex, "notifyuser", 77, "sess_mutex", 1);
@@ -1456,15 +1433,11 @@ void GGPROTO::notifyuser(MCONTACT hContact, int refresh)
void GGPROTO::notifyall()
{
MCONTACT hContact;
- int count = 0, cc = 0;
- uin_t *uins;
- char *types;
-
debugLogA("notifyall(): Subscribing notification to all users");
// Readup count
-
+ int count = 0;
for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
- count ++;
+ count++;
// Readup list
/* FIXME: If we have nothing on the list but we omit gg_notify_ex we have problem with receiving any contacts */
@@ -1476,33 +1449,35 @@ void GGPROTO::notifyall()
}
return;
}
- uins = (uin_t*)calloc(sizeof(uin_t), count);
- types = (char*)calloc(sizeof(char), count);
+ uin_t *uins = (uin_t*)calloc(sizeof(uin_t), count);
+ char *types = (char*)calloc(sizeof(char), count);
+ int cc = 0;
for (hContact = db_find_first(m_szModuleName); hContact && cc < count; hContact = db_find_next(hContact, m_szModuleName)) {
if (uins[cc] = getDword(hContact, GG_KEY_UIN, 0)) {
- if ((getWord(hContact, GG_KEY_APPARENT, (WORD) ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) ||
+ if ((getWord(hContact, GG_KEY_APPARENT, (WORD)ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) ||
db_get_b(hContact, "CList", "NotOnList", 0))
types[cc] = GG_USER_OFFLINE;
else if (getByte(hContact, GG_KEY_BLOCK, 0))
types[cc] = GG_USER_BLOCKED;
else
types[cc] = GG_USER_NORMAL;
- cc ++;
+ ++cc;
}
}
- if (cc < count) count = cc;
+ if (cc < count)
+ count = cc;
// Send notification
- if (isonline())
- {
+ if (isonline()) {
gg_EnterCriticalSection(&sess_mutex, "notifyall", 30, "sess_mutex", 1);
gg_notify_ex(sess, uins, types, count);
gg_LeaveCriticalSection(&sess_mutex, "notifyall", 30, 1, "sess_mutex", 1);
}
// Free variables
- free(uins); free(types);
+ free(uins);
+ free(types);
}
////////////////////////////////////////////////////////////
@@ -1540,10 +1515,10 @@ MCONTACT GGPROTO::getcontact(uin_t uin, int create, int inlist, wchar_t *szNick)
}
debugLogA("getcontact(): Added buddy: %d", uin);
- if (!inlist)
+ if (!inlist)
db_set_b(hContact, "CList", "NotOnList", 1);
- setDword(hContact, GG_KEY_UIN, (DWORD) uin);
+ setDword(hContact, GG_KEY_UIN, (DWORD)uin);
setWord(hContact, GG_KEY_STATUS, ID_STATUS_OFFLINE);
// If nick specified use it
@@ -1568,8 +1543,7 @@ MCONTACT GGPROTO::getcontact(uin_t uin, int create, int inlist, wchar_t *szNick)
}
// Add to notify list and pull avatar for the new contact
- if (isonline())
- {
+ if (isonline()) {
gg_EnterCriticalSection(&sess_mutex, "getcontact", 32, "sess_mutex", 1);
gg_add_notify_ex(sess, uin, (char)(inlist ? GG_USER_NORMAL : GG_USER_OFFLINE));
gg_LeaveCriticalSection(&sess_mutex, "getcontact", 32, 1, "sess_mutex", 1);
@@ -1600,30 +1574,26 @@ int GGPROTO::status_m2gg(int status, int descr)
// check frends only
int mask = getByte(GG_KEY_FRIENDSONLY, GG_KEYDEF_FRIENDSONLY) ? GG_STATUS_FRIENDS_MASK : 0;
- if (descr)
- {
- switch(status)
- {
- case ID_STATUS_OFFLINE: return GG_STATUS_NOT_AVAIL_DESCR | mask;
- case ID_STATUS_ONLINE: return GG_STATUS_AVAIL_DESCR | mask;
- case ID_STATUS_AWAY: return GG_STATUS_BUSY_DESCR | mask;
- case ID_STATUS_DND: return GG_STATUS_DND_DESCR | mask;
- case ID_STATUS_FREECHAT: return GG_STATUS_FFC_DESCR | mask;
- case ID_STATUS_INVISIBLE: return GG_STATUS_INVISIBLE_DESCR | mask;
- default: return GG_STATUS_BUSY_DESCR | mask;
+ if (descr) {
+ switch (status) {
+ case ID_STATUS_OFFLINE: return GG_STATUS_NOT_AVAIL_DESCR | mask;
+ case ID_STATUS_ONLINE: return GG_STATUS_AVAIL_DESCR | mask;
+ case ID_STATUS_AWAY: return GG_STATUS_BUSY_DESCR | mask;
+ case ID_STATUS_DND: return GG_STATUS_DND_DESCR | mask;
+ case ID_STATUS_FREECHAT: return GG_STATUS_FFC_DESCR | mask;
+ case ID_STATUS_INVISIBLE: return GG_STATUS_INVISIBLE_DESCR | mask;
+ default: return GG_STATUS_BUSY_DESCR | mask;
}
}
- else
- {
- switch(status)
- {
- case ID_STATUS_OFFLINE: return GG_STATUS_NOT_AVAIL | mask;
- case ID_STATUS_ONLINE: return GG_STATUS_AVAIL | mask;
- case ID_STATUS_AWAY: return GG_STATUS_BUSY | mask;
- case ID_STATUS_DND: return GG_STATUS_DND | mask;
- case ID_STATUS_FREECHAT: return GG_STATUS_FFC | mask;
- case ID_STATUS_INVISIBLE: return GG_STATUS_INVISIBLE | mask;
- default: return GG_STATUS_BUSY | mask;
+ else {
+ switch (status) {
+ case ID_STATUS_OFFLINE: return GG_STATUS_NOT_AVAIL | mask;
+ case ID_STATUS_ONLINE: return GG_STATUS_AVAIL | mask;
+ case ID_STATUS_AWAY: return GG_STATUS_BUSY | mask;
+ case ID_STATUS_DND: return GG_STATUS_DND | mask;
+ case ID_STATUS_FREECHAT: return GG_STATUS_FFC | mask;
+ case ID_STATUS_INVISIBLE: return GG_STATUS_INVISIBLE | mask;
+ default: return GG_STATUS_BUSY | mask;
}
}
}
@@ -1638,37 +1608,36 @@ int GGPROTO::status_gg2m(int status)
return ID_STATUS_INVISIBLE;
// rest of cases
- switch(status)
- {
- case GG_STATUS_NOT_AVAIL:
- case GG_STATUS_NOT_AVAIL_DESCR:
- return ID_STATUS_OFFLINE;
+ switch (status) {
+ case GG_STATUS_NOT_AVAIL:
+ case GG_STATUS_NOT_AVAIL_DESCR:
+ return ID_STATUS_OFFLINE;
- case GG_STATUS_AVAIL:
- case GG_STATUS_AVAIL_DESCR:
- return ID_STATUS_ONLINE;
+ case GG_STATUS_AVAIL:
+ case GG_STATUS_AVAIL_DESCR:
+ return ID_STATUS_ONLINE;
- case GG_STATUS_BUSY:
- case GG_STATUS_BUSY_DESCR:
- return ID_STATUS_AWAY;
+ case GG_STATUS_BUSY:
+ case GG_STATUS_BUSY_DESCR:
+ return ID_STATUS_AWAY;
- case GG_STATUS_DND:
- case GG_STATUS_DND_DESCR:
- return ID_STATUS_DND;
+ case GG_STATUS_DND:
+ case GG_STATUS_DND_DESCR:
+ return ID_STATUS_DND;
- case GG_STATUS_FFC:
- case GG_STATUS_FFC_DESCR:
- return ID_STATUS_FREECHAT;
+ case GG_STATUS_FFC:
+ case GG_STATUS_FFC_DESCR:
+ return ID_STATUS_FREECHAT;
- case GG_STATUS_INVISIBLE:
- case GG_STATUS_INVISIBLE_DESCR:
- return ID_STATUS_INVISIBLE;
+ case GG_STATUS_INVISIBLE:
+ case GG_STATUS_INVISIBLE_DESCR:
+ return ID_STATUS_INVISIBLE;
- case GG_STATUS_BLOCKED:
- return ID_STATUS_NA;
+ case GG_STATUS_BLOCKED:
+ return ID_STATUS_NA;
- default:
- return ID_STATUS_OFFLINE;
+ default:
+ return ID_STATUS_OFFLINE;
}
}
@@ -1683,28 +1652,30 @@ void GGPROTO::changecontactstatus(uin_t uin, int status, const wchar_t *idescr,
MCONTACT hContact = getcontact(uin, 0, 0, nullptr);
// Check if contact is on list
- if (!hContact) return;
+ if (!hContact)
+ return;
// Write contact status
setWord(hContact, GG_KEY_STATUS, (WORD)status_gg2m(status));
// Check if there's description and if it's not empty
- if (idescr && *idescr)
- {
+ if (idescr && *idescr) {
debugLogW(L"changecontactstatus(): Saving for %d status descr \"%s\".", uin, idescr);
db_set_ws(hContact, "CList", GG_KEY_STATUSDESCR, idescr);
- } else {
+ }
+ else {
// Remove status if there's nothing
db_unset(hContact, "CList", GG_KEY_STATUSDESCR);
}
// Store contact ip and port
- if (remote_ip) setDword(hContact, GG_KEY_CLIENTIP, (DWORD) swap32(remote_ip));
- if (remote_port) setWord(hContact, GG_KEY_CLIENTPORT, (WORD) remote_port);
- if (version)
- {
+ if (remote_ip)
+ setDword(hContact, GG_KEY_CLIENTIP, (DWORD)swap32(remote_ip));
+ if (remote_port)
+ setWord(hContact, GG_KEY_CLIENTPORT, (WORD)remote_port);
+ if (version) {
char sversion[48];
- setDword(hContact, GG_KEY_CLIENTVERSION, (DWORD) version);
+ setDword(hContact, GG_KEY_CLIENTVERSION, (DWORD)version);
mir_snprintf(sversion, "%sGadu-Gadu %s", (version & 0x00ffffff) > 0x2b ? "Nowe " : "", gg_version2string(version));
setString(hContact, "MirVer", sversion);
}
@@ -1716,66 +1687,65 @@ const char *gg_version2string(int v)
{
const char *pstr = "???";
v &= 0x00ffffff;
- switch(v)
- {
- case 0x2e:
- pstr = "8.0 build 8283"; break;
- case 0x2d:
- pstr = "8.0 build 4881"; break;
- case 0x2b:
- pstr = "< 8.0"; break;
- case 0x2a:
- pstr = "7.7 build 3315"; break;
- case 0x29:
- pstr = "7.6 build 1688"; break;
- case 0x28:
- pstr = "7.5 build 2201"; break;
- case 0x27:
- pstr = "7.0 build 22"; break;
- case 0x26:
- pstr = "7.0 build 20"; break;
- case 0x25:
- pstr = "7.0 build 1"; break;
- case 0x24:
- pstr = "6.1 (155) / 7.6 (1359)"; break;
- case 0x22:
- pstr = "6.0 build 140"; break;
- case 0x21:
- pstr = "6.0 build 133"; break;
- case 0x20:
- pstr = "6.0b"; break;
- case 0x1e:
- pstr = "5.7b build 121"; break;
- case 0x1c:
- pstr = "5.7b"; break;
- case 0x1b:
- pstr = "5.0.5"; break;
- case 0x19:
- pstr = "5.0.3"; break;
- case 0x18:
- pstr = "5.0.0-1"; break;
- case 0x17:
- pstr = "4.9.2"; break;
- case 0x16:
- pstr = "4.9.1"; break;
- case 0x15:
- pstr = "4.8.9"; break;
- case 0x14:
- pstr = "4.8.1-3"; break;
- case 0x11:
- pstr = "4.6.1-10"; break;
- case 0x10:
- pstr = "4.5.15-22"; break;
- case 0x0f:
- pstr = "4.5.12"; break;
- case 0x0b:
- pstr = "4.0.25-30"; break;
- default:
- if (v < 0x0b)
- pstr = "< 4.0.25";
- else if (v > 0x2e)
- pstr = ">= 8.0";
- break;
+ switch (v) {
+ case 0x2e:
+ pstr = "8.0 build 8283"; break;
+ case 0x2d:
+ pstr = "8.0 build 4881"; break;
+ case 0x2b:
+ pstr = "< 8.0"; break;
+ case 0x2a:
+ pstr = "7.7 build 3315"; break;
+ case 0x29:
+ pstr = "7.6 build 1688"; break;
+ case 0x28:
+ pstr = "7.5 build 2201"; break;
+ case 0x27:
+ pstr = "7.0 build 22"; break;
+ case 0x26:
+ pstr = "7.0 build 20"; break;
+ case 0x25:
+ pstr = "7.0 build 1"; break;
+ case 0x24:
+ pstr = "6.1 (155) / 7.6 (1359)"; break;
+ case 0x22:
+ pstr = "6.0 build 140"; break;
+ case 0x21:
+ pstr = "6.0 build 133"; break;
+ case 0x20:
+ pstr = "6.0b"; break;
+ case 0x1e:
+ pstr = "5.7b build 121"; break;
+ case 0x1c:
+ pstr = "5.7b"; break;
+ case 0x1b:
+ pstr = "5.0.5"; break;
+ case 0x19:
+ pstr = "5.0.3"; break;
+ case 0x18:
+ pstr = "5.0.0-1"; break;
+ case 0x17:
+ pstr = "4.9.2"; break;
+ case 0x16:
+ pstr = "4.9.1"; break;
+ case 0x15:
+ pstr = "4.8.9"; break;
+ case 0x14:
+ pstr = "4.8.1-3"; break;
+ case 0x11:
+ pstr = "4.6.1-10"; break;
+ case 0x10:
+ pstr = "4.5.15-22"; break;
+ case 0x0f:
+ pstr = "4.5.12"; break;
+ case 0x0b:
+ pstr = "4.0.25-30"; break;
+ default:
+ if (v < 0x0b)
+ pstr = "< 4.0.25";
+ else if (v > 0x2e)
+ pstr = ">= 8.0";
+ break;
}
return pstr;
}
diff --git a/protocols/Gadu-Gadu/src/dialogs.cpp b/protocols/Gadu-Gadu/src/dialogs.cpp
index ad35aeb2de..ef0ec538a6 100644
--- a/protocols/Gadu-Gadu/src/dialogs.cpp
+++ b/protocols/Gadu-Gadu/src/dialogs.cpp
@@ -37,37 +37,46 @@ extern INT_PTR CALLBACK gg_userutildlgproc(HWND hwndDlg, UINT msg, WPARAM wParam
//
static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule, char *szSetting, int special, int disableIfUndef)
{
- DBVARIANT dbv = {0};
+ DBVARIANT dbv = { 0 };
wchar_t str[256];
wchar_t *ptstr = nullptr;
wchar_t* valT = nullptr;
int unspecified = 0;
dbv.type = DBVT_DELETED;
- if (szModule == nullptr) unspecified = 1;
- else unspecified = db_get(hContact, szModule, szSetting, &dbv);
+ if (szModule == nullptr)
+ unspecified = 1;
+ else
+ unspecified = db_get(hContact, szModule, szSetting, &dbv);
+
if (!unspecified) {
switch (dbv.type) {
case DBVT_BYTE:
if (special == SVS_GENDER) {
- if (dbv.cVal == 'M') ptstr = TranslateT("Male");
- else if (dbv.cVal == 'F') ptstr = TranslateT("Female");
- else unspecified = 1;
+ if (dbv.cVal == 'M')
+ ptstr = TranslateT("Male");
+ else if (dbv.cVal == 'F')
+ ptstr = TranslateT("Female");
+ else
+ unspecified = 1;
}
else if (special == SVS_MONTH) {
if (dbv.bVal > 0 && dbv.bVal <= 12) {
ptstr = str;
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVMONTHNAME1 - 1 + dbv.bVal, str, _countof(str));
}
- else unspecified = 1;
+ else
+ unspecified = 1;
}
else if (special == SVS_TIMEZONE) {
- if (dbv.cVal == -100) unspecified = 1;
+ if (dbv.cVal == -100)
+ unspecified = 1;
else {
ptstr = str;
mir_snwprintf(str, dbv.cVal ? L"GMT%+d:%02d" : L"GMT", -dbv.cVal / 2, (dbv.cVal & 1) * 30);
}
- } else {
+ }
+ else {
unspecified = (special == SVS_ZEROISUNSPEC && dbv.bVal == 0);
ptstr = _itow(special == SVS_SIGNED ? dbv.cVal : dbv.bVal, str, 10);
}
@@ -75,9 +84,10 @@ static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule
case DBVT_WORD:
if (special == SVS_COUNTRY) {
char* pstr = (char*)CallService(MS_UTILS_GETCOUNTRYBYNUMBER, dbv.wVal, 0);
- if (pstr == nullptr){
+ if (pstr == nullptr) {
unspecified = 1;
- } else {
+ }
+ else {
ptstr = str;
mir_snwprintf(str, L"%S", pstr);
}
@@ -93,17 +103,21 @@ static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule
struct in_addr ia;
ia.S_un.S_addr = htonl(dbv.dVal);
char* pstr = inet_ntoa(ia);
- if (pstr == nullptr){
+ if (pstr == nullptr) {
unspecified = 1;
- } else {
+ }
+ else {
ptstr = str;
mir_snwprintf(str, L"%S", pstr);
}
- if (dbv.dVal == 0) unspecified = 1;
- } else if (special == SVS_GGVERSION) {
+ if (dbv.dVal == 0)
+ unspecified = 1;
+ }
+ else if (special == SVS_GGVERSION) {
ptstr = str;
mir_snwprintf(str, L"%S", (char *)gg_version2string(dbv.dVal));
- } else {
+ }
+ else {
ptstr = _itow(special == SVS_SIGNED ? dbv.lVal : dbv.dVal, str, 10);
}
break;
@@ -157,7 +171,8 @@ void GGPROTO::checknewuser(uin_t uin, const char* passwd)
oldpasswd[0] = '\0';
if (!getString(GG_KEY_PASSWORD, &dbv))
{
- if (dbv.pszVal) mir_strcpy(oldpasswd, dbv.pszVal);
+ if (dbv.pszVal)
+ mir_strcpy(oldpasswd, dbv.pszVal);
db_free(&dbv);
}
@@ -201,90 +216,91 @@ static INT_PTR CALLBACK gg_genoptsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
switch (msg) {
case WM_INITDIALOG:
- {
- DBVARIANT dbv;
- DWORD num;
- gg = (GGPROTO *)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
-
- TranslateDialogDefault(hwndDlg);
- if (num = gg->getDword(GG_KEY_UIN, 0))
- {
- SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
- ShowWindow(GetDlgItem(hwndDlg, IDC_CREATEACCOUNT), SW_HIDE);
- }
- else
- {
- ShowWindow(GetDlgItem(hwndDlg, IDC_CHPASS), SW_HIDE);
- ShowWindow(GetDlgItem(hwndDlg, IDC_REMOVEACCOUNT), SW_HIDE);
- ShowWindow(GetDlgItem(hwndDlg, IDC_LOSTPASS), SW_HIDE);
- }
- if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
- db_free(&dbv);
- }
- if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
- db_free(&dbv);
- }
- else
- {
- ShowWindow(GetDlgItem(hwndDlg, IDC_LOSTPASS), SW_HIDE);
- ShowWindow(GetDlgItem(hwndDlg, IDC_CHPASS), SW_HIDE);
- }
-
- CheckDlgButton(hwndDlg, IDC_FRIENDSONLY, gg->getByte(GG_KEY_FRIENDSONLY, GG_KEYDEF_FRIENDSONLY) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_SHOWINVISIBLE, gg->getByte(GG_KEY_SHOWINVISIBLE, GG_KEYDEF_SHOWINVISIBLE) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_LEAVESTATUSMSG, gg->getByte(GG_KEY_LEAVESTATUSMSG, GG_KEYDEF_LEAVESTATUSMSG) ? BST_CHECKED : BST_UNCHECKED);
- if (gg->gc_enabled)
- CheckDlgButton(hwndDlg, IDC_IGNORECONF, gg->getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF) ? BST_CHECKED : BST_UNCHECKED);
- else
- {
- EnableWindow(GetDlgItem(hwndDlg, IDC_IGNORECONF), FALSE);
- CheckDlgButton(hwndDlg, IDC_IGNORECONF, BST_CHECKED);
- }
- CheckDlgButton(hwndDlg, IDC_IMGRECEIVE, gg->getByte(GG_KEY_IMGRECEIVE, GG_KEYDEF_IMGRECEIVE) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_SHOWLINKS, gg->getByte(GG_KEY_SHOWLINKS, GG_KEYDEF_SHOWLINKS) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_ENABLEAVATARS, gg->getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS) ? BST_CHECKED : BST_UNCHECKED);
+ {
+ DBVARIANT dbv;
+ DWORD num;
+ gg = (GGPROTO *)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
- EnableWindow(GetDlgItem(hwndDlg, IDC_LEAVESTATUS), IsDlgButtonChecked(hwndDlg, IDC_LEAVESTATUSMSG));
- EnableWindow(GetDlgItem(hwndDlg, IDC_IMGMETHOD), IsDlgButtonChecked(hwndDlg, IDC_IMGRECEIVE));
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)TranslateT("<Last Status>")); // 0
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_ONLINE, 0));
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_AWAY, 0));
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_DND, 0));
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_FREECHAT, 0));
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_INVISIBLE, 0));
- switch(gg->getWord(GG_KEY_LEAVESTATUS, GG_KEYDEF_LEAVESTATUS)) {
- case ID_STATUS_ONLINE:
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 1, 0);
- break;
- case ID_STATUS_AWAY:
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 2, 0);
- break;
- case ID_STATUS_DND:
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 3, 0);
- break;
- case ID_STATUS_FREECHAT:
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 4, 0);
- break;
- case ID_STATUS_INVISIBLE:
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 5, 0);
- break;
- default:
- SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 0, 0);
- }
+ TranslateDialogDefault(hwndDlg);
+ if (num = gg->getDword(GG_KEY_UIN, 0))
+ {
+ SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
+ ShowWindow(GetDlgItem(hwndDlg, IDC_CREATEACCOUNT), SW_HIDE);
+ }
+ else
+ {
+ ShowWindow(GetDlgItem(hwndDlg, IDC_CHPASS), SW_HIDE);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_REMOVEACCOUNT), SW_HIDE);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_LOSTPASS), SW_HIDE);
+ }
+ if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
+ SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
+ db_free(&dbv);
+ }
+ if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
+ SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
+ db_free(&dbv);
+ }
+ else
+ {
+ ShowWindow(GetDlgItem(hwndDlg, IDC_LOSTPASS), SW_HIDE);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_CHPASS), SW_HIDE);
+ }
- SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("System tray icon"));
- SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("Popup window"));
- SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("Message with [img] BBCode"));
- SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_SETCURSEL, gg->getByte(GG_KEY_IMGMETHOD, GG_KEYDEF_IMGMETHOD), 0);
+ CheckDlgButton(hwndDlg, IDC_FRIENDSONLY, gg->getByte(GG_KEY_FRIENDSONLY, GG_KEYDEF_FRIENDSONLY) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_SHOWINVISIBLE, gg->getByte(GG_KEY_SHOWINVISIBLE, GG_KEYDEF_SHOWINVISIBLE) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_LEAVESTATUSMSG, gg->getByte(GG_KEY_LEAVESTATUSMSG, GG_KEYDEF_LEAVESTATUSMSG) ? BST_CHECKED : BST_UNCHECKED);
+ if (gg->gc_enabled)
+ CheckDlgButton(hwndDlg, IDC_IGNORECONF, gg->getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF) ? BST_CHECKED : BST_UNCHECKED);
+ else
+ {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_IGNORECONF), FALSE);
+ CheckDlgButton(hwndDlg, IDC_IGNORECONF, BST_CHECKED);
}
- break;
+ CheckDlgButton(hwndDlg, IDC_IMGRECEIVE, gg->getByte(GG_KEY_IMGRECEIVE, GG_KEYDEF_IMGRECEIVE) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_SHOWLINKS, gg->getByte(GG_KEY_SHOWLINKS, GG_KEYDEF_SHOWLINKS) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_ENABLEAVATARS, gg->getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS) ? BST_CHECKED : BST_UNCHECKED);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_LEAVESTATUS), IsDlgButtonChecked(hwndDlg, IDC_LEAVESTATUSMSG));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_IMGMETHOD), IsDlgButtonChecked(hwndDlg, IDC_IMGRECEIVE));
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)TranslateT("<Last Status>")); // 0
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_ONLINE, 0));
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_AWAY, 0));
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_DND, 0));
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_FREECHAT, 0));
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(ID_STATUS_INVISIBLE, 0));
+
+ switch (gg->getWord(GG_KEY_LEAVESTATUS, GG_KEYDEF_LEAVESTATUS)) {
+ case ID_STATUS_ONLINE:
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 1, 0);
+ break;
+ case ID_STATUS_AWAY:
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 2, 0);
+ break;
+ case ID_STATUS_DND:
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 3, 0);
+ break;
+ case ID_STATUS_FREECHAT:
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 4, 0);
+ break;
+ case ID_STATUS_INVISIBLE:
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 5, 0);
+ break;
+ default:
+ SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_SETCURSEL, 0, 0);
+ }
+
+ SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("System tray icon"));
+ SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("Popup window"));
+ SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_ADDSTRING, 0, (LPARAM)TranslateT("Message with [img] BBCode"));
+ SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_SETCURSEL, gg->getByte(GG_KEY_IMGMETHOD, GG_KEYDEF_IMGMETHOD), 0);
+ }
+ break;
case WM_COMMAND:
if ((LOWORD(wParam) == IDC_UIN || LOWORD(wParam) == IDC_PASSWORD || LOWORD(wParam) == IDC_EMAIL)
- && (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus()))
+ && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
return 0;
switch (LOWORD(wParam)) {
@@ -302,22 +318,22 @@ static INT_PTR CALLBACK gg_genoptsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
break;
case IDC_LOSTPASS:
- {
- char email[128];
- uin_t uin;
- GetDlgItemTextA(hwndDlg, IDC_UIN, email, _countof(email));
- uin = atoi(email);
- GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
- if (!mir_strlen(email))
- MessageBox(nullptr, TranslateT("You need to specify your registration e-mail first."),
+ {
+ char email[128];
+ uin_t uin;
+ GetDlgItemTextA(hwndDlg, IDC_UIN, email, _countof(email));
+ uin = atoi(email);
+ GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
+ if (!mir_strlen(email))
+ MessageBox(nullptr, TranslateT("You need to specify your registration e-mail first."),
gg->m_tszUserName, MB_OK | MB_ICONEXCLAMATION);
- else if (MessageBox(nullptr,
- TranslateT("Your password will be sent to your registration e-mail.\nDo you want to continue?"),
- gg->m_tszUserName,
- MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
- gg->remindpassword(uin, email);
- return FALSE;
- }
+ else if (MessageBox(nullptr,
+ TranslateT("Your password will be sent to your registration e-mail.\nDo you want to continue?"),
+ gg->m_tszUserName,
+ MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
+ gg->remindpassword(uin, email);
+ return FALSE;
+ }
case IDC_CREATEACCOUNT:
case IDC_REMOVEACCOUNT:
if (gg->isonline())
@@ -333,100 +349,99 @@ static INT_PTR CALLBACK gg_genoptsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
}
case IDC_CHPASS:
case IDC_CHEMAIL:
+ {
+ // Readup data
+ GGUSERUTILDLGDATA dat;
+ int ret;
+ char pass[128], email[128];
+ GetDlgItemTextA(hwndDlg, IDC_UIN, pass, _countof(pass));
+ dat.uin = atoi(pass);
+ GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
+ GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
+ dat.pass = pass;
+ dat.email = email;
+ dat.gg = gg;
+ if (LOWORD(wParam) == IDC_CREATEACCOUNT)
{
- // Readup data
- GGUSERUTILDLGDATA dat;
- int ret;
- char pass[128], email[128];
- GetDlgItemTextA(hwndDlg, IDC_UIN, pass, _countof(pass));
- dat.uin = atoi(pass);
- GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
- GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
- dat.pass = pass;
- dat.email = email;
- dat.gg = gg;
- if (LOWORD(wParam) == IDC_CREATEACCOUNT)
- {
- dat.mode = GG_USERUTIL_CREATE;
- ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CREATEACCOUNT), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
- }
- else if (LOWORD(wParam) == IDC_CHPASS)
- {
- dat.mode = GG_USERUTIL_PASS;
- ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHPASS), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
- }
- else if (LOWORD(wParam) == IDC_CHEMAIL)
- {
- dat.mode = GG_USERUTIL_EMAIL;
- ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHEMAIL), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
- }
+ dat.mode = GG_USERUTIL_CREATE;
+ ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CREATEACCOUNT), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
+ }
+ else if (LOWORD(wParam) == IDC_CHPASS)
+ {
+ dat.mode = GG_USERUTIL_PASS;
+ ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHPASS), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
+ }
+ else if (LOWORD(wParam) == IDC_CHEMAIL)
+ {
+ dat.mode = GG_USERUTIL_EMAIL;
+ ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHEMAIL), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
+ }
+ else
+ {
+ dat.mode = GG_USERUTIL_REMOVE;
+ ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_REMOVEACCOUNT), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
+ }
+
+ if (ret == IDOK)
+ {
+ DBVARIANT dbv;
+ DWORD num;
+ // Show reload required window
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
+
+ // Update uin
+ if (num = gg->getDword(GG_KEY_UIN, 0))
+ SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
else
- {
- dat.mode = GG_USERUTIL_REMOVE;
- ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_REMOVEACCOUNT), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
- }
+ SetDlgItemTextA(hwndDlg, IDC_UIN, "");
- if (ret == IDOK)
- {
- DBVARIANT dbv;
- DWORD num;
- // Show reload required window
- ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
-
- // Update uin
- if (num = gg->getDword(GG_KEY_UIN, 0))
- SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
- else
- SetDlgItemTextA(hwndDlg, IDC_UIN, "");
-
- // Update password
- if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
- db_free(&dbv);
- }
- else SetDlgItemTextA(hwndDlg, IDC_PASSWORD, "");
+ // Update password
+ if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
+ SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
+ db_free(&dbv);
+ }
+ else SetDlgItemTextA(hwndDlg, IDC_PASSWORD, "");
- // Update e-mail
- if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
- db_free(&dbv);
- }
- else SetDlgItemTextA(hwndDlg, IDC_EMAIL, "");
+ // Update e-mail
+ if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
+ SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
+ db_free(&dbv);
+ }
+ else SetDlgItemTextA(hwndDlg, IDC_EMAIL, "");
- // Update links
- gg_optsdlgcheck(hwndDlg);
+ // Update links
+ gg_optsdlgcheck(hwndDlg);
- // Remove details
- if (LOWORD(wParam) != IDC_CHPASS && LOWORD(wParam) != IDC_CHEMAIL)
- {
- gg->delSetting(GG_KEY_NICK);
- gg->delSetting(GG_KEY_PD_NICKNAME);
- gg->delSetting(GG_KEY_PD_CITY);
- gg->delSetting(GG_KEY_PD_FIRSTNAME);
- gg->delSetting(GG_KEY_PD_LASTNAME);
- gg->delSetting(GG_KEY_PD_FAMILYNAME);
- gg->delSetting(GG_KEY_PD_FAMILYCITY );
- gg->delSetting(GG_KEY_PD_AGE);
- gg->delSetting(GG_KEY_PD_BIRTHYEAR);
- gg->delSetting(GG_KEY_PD_GANDER);
- }
+ // Remove details
+ if (LOWORD(wParam) != IDC_CHPASS && LOWORD(wParam) != IDC_CHEMAIL)
+ {
+ gg->delSetting(GG_KEY_NICK);
+ gg->delSetting(GG_KEY_PD_NICKNAME);
+ gg->delSetting(GG_KEY_PD_CITY);
+ gg->delSetting(GG_KEY_PD_FIRSTNAME);
+ gg->delSetting(GG_KEY_PD_LASTNAME);
+ gg->delSetting(GG_KEY_PD_FAMILYNAME);
+ gg->delSetting(GG_KEY_PD_FAMILYCITY);
+ gg->delSetting(GG_KEY_PD_AGE);
+ gg->delSetting(GG_KEY_PD_BIRTHYEAR);
+ gg->delSetting(GG_KEY_PD_GANDER);
}
}
- break;
+ }
+ break;
}
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
case WM_NOTIFY:
- switch (((LPNMHDR) lParam)->code) {
+ switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
int status_flags = GG_STATUS_FLAG_UNKNOWN;
char str[128];
- uin_t uin;
// Write Gadu-Gadu number & password
GetDlgItemTextA(hwndDlg, IDC_UIN, str, _countof(str));
- uin = atoi(str);
+ uin_t uin = atoi(str);
GetDlgItemTextA(hwndDlg, IDC_PASSWORD, str, _countof(str));
gg->checknewuser(uin, str);
gg->setDword(GG_KEY_UIN, uin);
@@ -437,24 +452,24 @@ static INT_PTR CALLBACK gg_genoptsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
gg->setString(GG_KEY_EMAIL, str);
// Write checkboxes
- gg->setByte(GG_KEY_FRIENDSONLY, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_FRIENDSONLY));
- gg->setByte(GG_KEY_SHOWINVISIBLE, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SHOWINVISIBLE));
- gg->setByte(GG_KEY_LEAVESTATUSMSG, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_LEAVESTATUSMSG));
+ gg->setByte(GG_KEY_FRIENDSONLY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_FRIENDSONLY));
+ gg->setByte(GG_KEY_SHOWINVISIBLE, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SHOWINVISIBLE));
+ gg->setByte(GG_KEY_LEAVESTATUSMSG, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_LEAVESTATUSMSG));
if (gg->gc_enabled)
- gg->setByte(GG_KEY_IGNORECONF, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_IGNORECONF));
- gg->setByte(GG_KEY_IMGRECEIVE, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_IMGRECEIVE));
- gg->setByte(GG_KEY_SHOWLINKS, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SHOWLINKS));
+ gg->setByte(GG_KEY_IGNORECONF, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_IGNORECONF));
+ gg->setByte(GG_KEY_IMGRECEIVE, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_IMGRECEIVE));
+ gg->setByte(GG_KEY_SHOWLINKS, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SHOWLINKS));
if (IsDlgButtonChecked(hwndDlg, IDC_SHOWLINKS))
status_flags |= GG_STATUS_FLAG_SPAM;
gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 34, "sess_mutex", 1);
gg_change_status_flags(gg->sess, status_flags);
gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 34, 1, "sess_mutex", 1);
- gg->setByte(GG_KEY_ENABLEAVATARS, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_ENABLEAVATARS));
+ gg->setByte(GG_KEY_ENABLEAVATARS, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ENABLEAVATARS));
gg->setByte(GG_KEY_IMGMETHOD, (BYTE)SendDlgItemMessage(hwndDlg, IDC_IMGMETHOD, CB_GETCURSEL, 0, 0));
// Write leave status
- switch(SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_GETCURSEL, 0, 0)) {
+ switch (SendDlgItemMessage(hwndDlg, IDC_LEAVESTATUS, CB_GETCURSEL, 0, 0)) {
case 1:
gg->setWord(GG_KEY_LEAVESTATUS, ID_STATUS_ONLINE);
break;
@@ -517,13 +532,13 @@ static INT_PTR CALLBACK gg_confoptsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam
case WM_COMMAND:
if ((LOWORD(wParam) == IDC_GC_COUNT_TOTAL || LOWORD(wParam) == IDC_GC_COUNT_UNKNOWN)
- && (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus()))
+ && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
return 0;
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
case WM_NOTIFY:
- switch (((LPNMHDR) lParam)->code) {
+ switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
char str[128];
@@ -592,60 +607,60 @@ static INT_PTR CALLBACK gg_advoptsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
case WM_COMMAND:
if ((LOWORD(wParam) == IDC_DIRECTPORT || LOWORD(wParam) == IDC_FORWARDHOST || LOWORD(wParam) == IDC_FORWARDPORT)
- && (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus()))
+ && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
return 0;
switch (LOWORD(wParam)) {
case IDC_MANUALHOST:
- {
- EnableWindow(GetDlgItem(hwndDlg, IDC_HOST), IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
- EnableWindow(GetDlgItem(hwndDlg, IDC_PORT), IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
- ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
- break;
- }
+ {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_HOST), IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_PORT), IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
+ break;
+ }
case IDC_DIRECTCONNS:
case IDC_FORWARDING:
- {
- EnableWindow(GetDlgItem(hwndDlg, IDC_DIRECTPORT), IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
- EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDING), IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
- EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDPORT), IsDlgButtonChecked(hwndDlg, IDC_FORWARDING) && IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
- EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDHOST), IsDlgButtonChecked(hwndDlg, IDC_FORWARDING) && IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
- ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
- break;
- }
+ {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DIRECTPORT), IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDING), IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDPORT), IsDlgButtonChecked(hwndDlg, IDC_FORWARDING) && IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARDHOST), IsDlgButtonChecked(hwndDlg, IDC_FORWARDING) && IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
+ break;
+ }
}
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
case WM_NOTIFY:
- switch (((LPNMHDR) lParam)->code) {
+ switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
- {
- char str[512];
- gg->setByte(GG_KEY_KEEPALIVE, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_KEEPALIVE));
- gg->setByte(GG_KEY_SHOWCERRORS, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SHOWCERRORS));
- gg->setByte(GG_KEY_ARECONNECT, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_ARECONNECT));
- gg->setByte(GG_KEY_MSGACK, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_MSGACK));
- gg->setByte(GG_KEY_MANUALHOST, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
- gg->setByte(GG_KEY_SSLCONN, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SSLCONN));
-
- // Transfer settings
- gg->setByte(GG_KEY_DIRECTCONNS, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
- gg->setByte(GG_KEY_FORWARDING, (BYTE) IsDlgButtonChecked(hwndDlg, IDC_FORWARDING));
-
- // Write custom servers
- GetDlgItemTextA(hwndDlg, IDC_HOST, str, _countof(str));
- gg->setString(GG_KEY_SERVERHOSTS, str);
-
- // Write direct port
- GetDlgItemTextA(hwndDlg, IDC_DIRECTPORT, str, _countof(str));
- gg->setWord(GG_KEY_DIRECTPORT, (WORD)atoi(str));
- // Write forwarding host
- GetDlgItemTextA(hwndDlg, IDC_FORWARDHOST, str, _countof(str));
- gg->setString(GG_KEY_FORWARDHOST, str);
- GetDlgItemTextA(hwndDlg, IDC_FORWARDPORT, str, _countof(str));
- gg->setWord(GG_KEY_FORWARDPORT, (WORD)atoi(str));
- break;
- }
+ {
+ char str[512];
+ gg->setByte(GG_KEY_KEEPALIVE, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_KEEPALIVE));
+ gg->setByte(GG_KEY_SHOWCERRORS, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SHOWCERRORS));
+ gg->setByte(GG_KEY_ARECONNECT, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ARECONNECT));
+ gg->setByte(GG_KEY_MSGACK, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_MSGACK));
+ gg->setByte(GG_KEY_MANUALHOST, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_MANUALHOST));
+ gg->setByte(GG_KEY_SSLCONN, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SSLCONN));
+
+ // Transfer settings
+ gg->setByte(GG_KEY_DIRECTCONNS, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_DIRECTCONNS));
+ gg->setByte(GG_KEY_FORWARDING, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_FORWARDING));
+
+ // Write custom servers
+ GetDlgItemTextA(hwndDlg, IDC_HOST, str, _countof(str));
+ gg->setString(GG_KEY_SERVERHOSTS, str);
+
+ // Write direct port
+ GetDlgItemTextA(hwndDlg, IDC_DIRECTPORT, str, _countof(str));
+ gg->setWord(GG_KEY_DIRECTPORT, (WORD)atoi(str));
+ // Write forwarding host
+ GetDlgItemTextA(hwndDlg, IDC_FORWARDHOST, str, _countof(str));
+ gg->setString(GG_KEY_FORWARDHOST, str);
+ GetDlgItemTextA(hwndDlg, IDC_FORWARDPORT, str, _countof(str));
+ gg->setWord(GG_KEY_FORWARDPORT, (WORD)atoi(str));
+ break;
+ }
}
break;
}
@@ -670,7 +685,7 @@ static INT_PTR CALLBACK gg_detailsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
{
struct GGDETAILSDLGDATA *dat = (struct GGDETAILSDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
@@ -729,14 +744,14 @@ static INT_PTR CALLBACK gg_detailsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
SetValue(hwndDlg, IDC_BIRTHYEAR, hContact, szProto, GG_KEY_PD_BIRTHYEAR, SVS_ZEROISUNSPEC, hContact != NULL);
SetValue(hwndDlg, IDC_CITY, hContact, szProto, GG_KEY_PD_CITY, SVS_NORMAL, hContact != NULL);
SetValue(hwndDlg, IDC_FAMILYNAME, hContact, szProto, GG_KEY_PD_FAMILYNAME, SVS_NORMAL, hContact != NULL);
- SetValue(hwndDlg, IDC_CITYORIGIN, hContact, szProto, GG_KEY_PD_FAMILYCITY , SVS_NORMAL, hContact != NULL);
+ SetValue(hwndDlg, IDC_CITYORIGIN, hContact, szProto, GG_KEY_PD_FAMILYCITY, SVS_NORMAL, hContact != NULL);
if (hContact)
{
SetValue(hwndDlg, IDC_GENDER, hContact, szProto, GG_KEY_PD_GANDER, SVS_GENDER, hContact != NULL);
SetValue(hwndDlg, IDC_STATUSDESCR, hContact, "CList", GG_KEY_STATUSDESCR, SVS_NORMAL, hContact != NULL);
}
- else switch((char)db_get_b(hContact, gg->m_szModuleName, GG_KEY_PD_GANDER, (BYTE)'?')) {
+ else switch ((char)db_get_b(hContact, gg->m_szModuleName, GG_KEY_PD_GANDER, (BYTE)'?')) {
case 'F':
SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 1, 0);
break;
@@ -758,7 +773,7 @@ static INT_PTR CALLBACK gg_detailsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
- SendMessage(GetParent(hwndDlg),msg,wParam,lParam);
+ SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
break;
case IDC_NICKNAME:
case IDC_FIRSTNAME:
@@ -785,71 +800,71 @@ static INT_PTR CALLBACK gg_detailsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam,
if (!dat || dat->hContact || dat->disableUpdate)
break;
{
- wchar_t text[256];
- GGPROTO *gg = dat->gg;
+ wchar_t text[256];
+ GGPROTO *gg = dat->gg;
- if (!gg->isonline())
- {
- MessageBox(nullptr,
- TranslateT("You have to be logged in before you can change your details."),
- gg->m_tszUserName, MB_OK | MB_ICONSTOP);
- break;
- }
+ if (!gg->isonline())
+ {
+ MessageBox(nullptr,
+ TranslateT("You have to be logged in before you can change your details."),
+ gg->m_tszUserName, MB_OK | MB_ICONSTOP);
+ break;
+ }
- EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), FALSE);
- gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_WRITE);
- if (req == nullptr)
- break;
+ gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_WRITE);
+ if (req == nullptr)
+ break;
- GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, _countof(text));
- if (mir_wstrlen(text))
- gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, T2Utf(text));
+ GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, _countof(text));
+ if (mir_wstrlen(text))
+ gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, T2Utf(text));
- GetDlgItemText(hwndDlg, IDC_LASTNAME, text, _countof(text));
- if (mir_wstrlen(text))
- gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, T2Utf(text));
+ GetDlgItemText(hwndDlg, IDC_LASTNAME, text, _countof(text));
+ if (mir_wstrlen(text))
+ gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, T2Utf(text));
- GetDlgItemText(hwndDlg, IDC_NICKNAME, text, _countof(text));
- if (mir_wstrlen(text))
- gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, T2Utf(text));
+ GetDlgItemText(hwndDlg, IDC_NICKNAME, text, _countof(text));
+ if (mir_wstrlen(text))
+ gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, T2Utf(text));
- GetDlgItemText(hwndDlg, IDC_CITY, text, _countof(text));
- if (mir_wstrlen(text))
- gg_pubdir50_add(req, GG_PUBDIR50_CITY, T2Utf(text));
+ GetDlgItemText(hwndDlg, IDC_CITY, text, _countof(text));
+ if (mir_wstrlen(text))
+ gg_pubdir50_add(req, GG_PUBDIR50_CITY, T2Utf(text));
- // Gadu-Gadu Female <-> Male
- switch(SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0)) {
- case 1:
- gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_FEMALE);
- break;
- case 2:
- gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_MALE);
- break;
- default:
- gg_pubdir50_add(req, GG_PUBDIR50_GENDER, "");
- }
+ // Gadu-Gadu Female <-> Male
+ switch (SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0)) {
+ case 1:
+ gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_FEMALE);
+ break;
+ case 2:
+ gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_MALE);
+ break;
+ default:
+ gg_pubdir50_add(req, GG_PUBDIR50_GENDER, "");
+ }
- GetDlgItemText(hwndDlg, IDC_BIRTHYEAR, text, _countof(text));
- if (mir_wstrlen(text))
- gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, T2Utf(text));
+ GetDlgItemText(hwndDlg, IDC_BIRTHYEAR, text, _countof(text));
+ if (mir_wstrlen(text))
+ gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, T2Utf(text));
- GetDlgItemText(hwndDlg, IDC_FAMILYNAME, text, _countof(text));
- if (mir_wstrlen(text))
- gg_pubdir50_add(req, GG_PUBDIR50_FAMILYNAME, T2Utf(text));
+ GetDlgItemText(hwndDlg, IDC_FAMILYNAME, text, _countof(text));
+ if (mir_wstrlen(text))
+ gg_pubdir50_add(req, GG_PUBDIR50_FAMILYNAME, T2Utf(text));
- GetDlgItemText(hwndDlg, IDC_CITYORIGIN, text, _countof(text));
- if (mir_wstrlen(text))
- gg_pubdir50_add(req, GG_PUBDIR50_FAMILYCITY, T2Utf(text));
+ GetDlgItemText(hwndDlg, IDC_CITYORIGIN, text, _countof(text));
+ if (mir_wstrlen(text))
+ gg_pubdir50_add(req, GG_PUBDIR50_FAMILYCITY, T2Utf(text));
- // Run update
- gg_pubdir50_seq_set(req, GG_SEQ_CHINFO);
- gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_detailsdlgproc", 35, "sess_mutex", 1);
- gg_pubdir50(gg->sess, req);
- gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 35, 1, "sess_mutex", 1);
- dat->updating = TRUE;
+ // Run update
+ gg_pubdir50_seq_set(req, GG_SEQ_CHINFO);
+ gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_detailsdlgproc", 35, "sess_mutex", 1);
+ gg_pubdir50(gg->sess, req);
+ gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 35, 1, "sess_mutex", 1);
+ dat->updating = TRUE;
- gg_pubdir50_free(req);
+ gg_pubdir50_free(req);
}
break;
}
@@ -904,10 +919,11 @@ int GGPROTO::details_init(WPARAM wParam, LPARAM lParam)
MCONTACT hContact = lParam;
char* pszTemplate;
- if (hContact == NULL){
+ if (hContact == NULL) {
// View/Change My Details
pszTemplate = MAKEINTRESOURCEA(IDD_CHINFO_GG);
- } else {
+ }
+ else {
// Other user details
char* szProto = GetContactProto(hContact);
if (szProto == nullptr)
@@ -943,72 +959,73 @@ INT_PTR CALLBACK gg_acc_mgr_guidlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
switch (msg) {
case WM_INITDIALOG:
- {
- DBVARIANT dbv;
- DWORD num;
- gg = (GGPROTO *)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
-
- TranslateDialogDefault(hwndDlg);
- if (num = gg->getDword(GG_KEY_UIN, 0))
- SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
- if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
- db_free(&dbv);
- }
- if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
- db_free(&dbv);
- }
- break;
+ {
+ DBVARIANT dbv;
+ gg = (GGPROTO *)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
+
+ TranslateDialogDefault(hwndDlg);
+ DWORD num = gg->getDword(GG_KEY_UIN, 0);
+ if (num)
+ SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
+ if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
+ SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
+ db_free(&dbv);
+ }
+ if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
+ SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
+ db_free(&dbv);
}
+ break;
+ }
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_CREATEACCOUNT:
+ {
+ // Readup data
+ GGUSERUTILDLGDATA dat;
+ char pass[128], email[128];
+ GetDlgItemTextA(hwndDlg, IDC_UIN, pass, _countof(pass));
+ dat.uin = atoi(pass);
+ GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
+ GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
+ dat.pass = pass;
+ dat.email = email;
+ dat.gg = gg;
+ dat.mode = GG_USERUTIL_CREATE;
+ int ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CREATEACCOUNT), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
+
+ if (ret == IDOK)
{
- // Readup data
- GGUSERUTILDLGDATA dat;
- int ret;
- char pass[128], email[128];
- GetDlgItemTextA(hwndDlg, IDC_UIN, pass, _countof(pass));
- dat.uin = atoi(pass);
- GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
- GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
- dat.pass = pass;
- dat.email = email;
- dat.gg = gg;
- dat.mode = GG_USERUTIL_CREATE;
- ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CREATEACCOUNT), hwndDlg, gg_userutildlgproc, (LPARAM)&dat);
+ DBVARIANT dbv;
+ DWORD num;
+ // Show reload required window
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
- if (ret == IDOK)
- {
- DBVARIANT dbv;
- DWORD num;
- // Show reload required window
- ShowWindow(GetDlgItem(hwndDlg, IDC_RELOADREQD), SW_SHOW);
-
- // Update uin
- if (num = gg->getDword(GG_KEY_UIN, 0))
- SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
- else
- SetDlgItemTextA(hwndDlg, IDC_UIN, "");
-
- // Update password
- if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
- db_free(&dbv);
- }
- else SetDlgItemTextA(hwndDlg, IDC_PASSWORD, "");
+ // Update uin
+ if (num = gg->getDword(GG_KEY_UIN, 0))
+ SetDlgItemTextA(hwndDlg, IDC_UIN, ditoa(num));
+ else
+ SetDlgItemTextA(hwndDlg, IDC_UIN, "");
- // Update e-mail
- if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
- db_free(&dbv);
- }
- else SetDlgItemTextA(hwndDlg, IDC_EMAIL, "");
+ // Update password
+ if (!gg->getString(GG_KEY_PASSWORD, &dbv)) {
+ SetDlgItemTextA(hwndDlg, IDC_PASSWORD, dbv.pszVal);
+ db_free(&dbv);
}
+ else
+ SetDlgItemTextA(hwndDlg, IDC_PASSWORD, "");
+
+ // Update e-mail
+ if (!gg->getString(GG_KEY_EMAIL, &dbv)) {
+ SetDlgItemTextA(hwndDlg, IDC_EMAIL, dbv.pszVal);
+ db_free(&dbv);
+ }
+ else
+ SetDlgItemTextA(hwndDlg, IDC_EMAIL, "");
}
- break;
+ }
+ break;
case IDC_UIN:
case IDC_PASSWORD:
case IDC_EMAIL:
@@ -1020,26 +1037,25 @@ INT_PTR CALLBACK gg_acc_mgr_guidlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
break;
case WM_NOTIFY:
- switch(((LPNMHDR)lParam)->idFrom) {
+ switch (((LPNMHDR)lParam)->idFrom) {
case 0:
- switch (((LPNMHDR) lParam)->code) {
+ switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
- {
- char str[128];
- uin_t uin;
-
- // Write Gadu-Gadu number & password
- GetDlgItemTextA(hwndDlg, IDC_UIN, str, _countof(str));
- uin = atoi(str);
- GetDlgItemTextA(hwndDlg, IDC_PASSWORD, str, _countof(str));
- gg->checknewuser(uin, str);
- gg->setDword(GG_KEY_UIN, uin);
- gg->setString(GG_KEY_PASSWORD, str);
-
- // Write Gadu-Gadu email
- GetDlgItemTextA(hwndDlg, IDC_EMAIL, str, _countof(str));
- gg->setString(GG_KEY_EMAIL, str);
- }
+ {
+ char str[128];
+
+ // Write Gadu-Gadu number & password
+ GetDlgItemTextA(hwndDlg, IDC_UIN, str, _countof(str));
+ uin_t uin = atoi(str);
+ GetDlgItemTextA(hwndDlg, IDC_PASSWORD, str, _countof(str));
+ gg->checknewuser(uin, str);
+ gg->setDword(GG_KEY_UIN, uin);
+ gg->setString(GG_KEY_PASSWORD, str);
+
+ // Write Gadu-Gadu email
+ GetDlgItemTextA(hwndDlg, IDC_EMAIL, str, _countof(str));
+ gg->setString(GG_KEY_EMAIL, str);
+ }
}
}
break;
diff --git a/protocols/Gadu-Gadu/src/dynstuff.cpp b/protocols/Gadu-Gadu/src/dynstuff.cpp
index 520a53bb51..1cc09d33a3 100644
--- a/protocols/Gadu-Gadu/src/dynstuff.cpp
+++ b/protocols/Gadu-Gadu/src/dynstuff.cpp
@@ -1,22 +1,22 @@
/* $Id: dynstuff.c 11259 2010-02-17 04:47:22Z borkra $ */
/*
- * (C) Copyright 2001-2003 Wojtek Kaniewski <wojtekka@irc.pl>
- * Dawid Jarosz <dawjar@poczta.onet.pl>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
+* (C) Copyright 2001-2003 Wojtek Kaniewski <wojtekka@irc.pl>
+* Dawid Jarosz <dawjar@poczta.onet.pl>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License Version 2 as
+* published by the Free Software Foundation.
+*
+* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
#include "gg.h"
@@ -26,19 +26,19 @@
#include <string.h>
/*
- * list_add_sorted()
- *
- * dodaje do listy dany element. przy okazji moїe teї skopiowaж zawarto¶ж.
- * je¶li poda siк jako ostatni parametr funkcjк porуwnuj±c± zawarto¶ж
- * elementуw, moїe posortowaж od razu.
- *
- * - list - wskaјnik do listy,
- * - data - wskaјnik do elementu,
- * - alloc_size - rozmiar elementu, je¶li chcemy go skopiowaж.
- *
- * zwraca wskaјnik zaalokowanego elementu lub NULL w przpadku bікdu.
- */
-void *list_add_sorted(list_t *list, void *data, int alloc_size, int (*comparision)(void *, void *))
+* list_add_sorted()
+*
+* dodaje do listy dany element. przy okazji moїe teї skopiowaж zawarto¶ж.
+* je¶li poda siк jako ostatni parametr funkcjк porуwnuj±c± zawarto¶ж
+* elementуw, moїe posortowaж od razu.
+*
+* - list - wskaјnik do listy,
+* - data - wskaјnik do elementu,
+* - alloc_size - rozmiar elementu, je¶li chcemy go skopiowaж.
+*
+* zwraca wskaјnik zaalokowanego elementu lub NULL w przpadku bікdu.
+*/
+void *list_add_sorted(list_t *list, void *data, int alloc_size, int(*comparision)(void *, void *))
{
if (!list) {
errno = EFAULT;
@@ -58,12 +58,14 @@ void *list_add_sorted(list_t *list, void *data, int alloc_size, int (*comparisio
list_t tmp;
if (!(tmp = *list)) {
*list = newlist;
- } else {
+ }
+ else {
if (!comparision) {
while (tmp->next)
tmp = tmp->next;
tmp->next = newlist;
- } else {
+ }
+ else {
list_t prev = nullptr;
while (comparision(newlist->data, tmp->data) > 0) {
@@ -77,7 +79,8 @@ void *list_add_sorted(list_t *list, void *data, int alloc_size, int (*comparisio
tmp = *list;
*list = newlist;
newlist->next = tmp;
- } else {
+ }
+ else {
prev->next = newlist;
newlist->next = tmp;
}
@@ -88,24 +91,24 @@ void *list_add_sorted(list_t *list, void *data, int alloc_size, int (*comparisio
}
/*
- * list_add()
- *
- * wrapper do list_add_sorted(), ktуry zachowuje poprzedni± skіadniк.
- */
+* list_add()
+*
+* wrapper do list_add_sorted(), ktуry zachowuje poprzedni± skіadniк.
+*/
void *list_add(list_t *list, void *data, int alloc_size)
{
return list_add_sorted(list, data, alloc_size, nullptr);
}
/*
- * list_remove()
- *
- * usuwa z listy wpis z podanym elementem.
- *
- * - list - wskaјnik do listy,
- * - data - element,
- * - free_data - zwolniж pamiкж po elemencie.
- */
+* list_remove()
+*
+* usuwa z listy wpis z podanym elementem.
+*
+* - list - wskaјnik do listy,
+* - data - element,
+* - free_data - zwolniж pamiкж po elemencie.
+*/
int list_remove(list_t *list, void *data, int free_data)
{
list_t tmp, last = nullptr;
@@ -118,7 +121,8 @@ int list_remove(list_t *list, void *data, int free_data)
tmp = *list;
if (tmp->data == data) {
*list = tmp->next;
- } else {
+ }
+ else {
for (; tmp && tmp->data != data; tmp = tmp->next)
last = tmp;
if (!tmp) {
@@ -136,12 +140,12 @@ int list_remove(list_t *list, void *data, int free_data)
}
/*
- * list_count()
- *
- * zwraca ilo¶ж elementуw w danej li¶cie.
- *
- * - list - lista.
- */
+* list_count()
+*
+* zwraca ilo¶ж elementуw w danej li¶cie.
+*
+* - list - lista.
+*/
int list_count(list_t list)
{
int count = 0;
@@ -153,13 +157,13 @@ int list_count(list_t list)
}
/*
- * list_destroy()
- *
- * niszczy wszystkie elementy listy.
- *
- * - list - lista,
- * - free_data - czy zwalniaж bufor danych?
- */
+* list_destroy()
+*
+* niszczy wszystkie elementy listy.
+*
+* - list - lista,
+* - free_data - czy zwalniaж bufor danych?
+*/
int list_destroy(list_t list, int free_data)
{
list_t tmp;
@@ -179,13 +183,13 @@ int list_destroy(list_t list, int free_data)
}
/*
- * string_realloc()
- *
- * upewnia siк, їe w stringu bкdzie wystarczaj±co duїo miejsca.
- *
- * - s - ci±g znakуw,
- * - count - wymagana ilo¶ж znakуw (bez koсcowego '\0').
- */
+* string_realloc()
+*
+* upewnia siк, їe w stringu bкdzie wystarczaj±co duїo miejsca.
+*
+* - s - ci±g znakуw,
+* - count - wymagana ilo¶ж znakуw (bez koсcowego '\0').
+*/
static void string_realloc(string_t s, int count)
{
char *tmp;
@@ -202,14 +206,14 @@ static void string_realloc(string_t s, int count)
}
/*
- * string_append_c()
- *
- * dodaje do danego ci±gu jeden znak, alokuj±c przy tym odpowiedni± ilo¶ж
- * pamiкci.
- *
- * - s - ci±g znakуw.
- * - c - znaczek do dopisania.
- */
+* string_append_c()
+*
+* dodaje do danego ci±gu jeden znak, alokuj±c przy tym odpowiedni± ilo¶ж
+* pamiкci.
+*
+* - s - ci±g znakуw.
+* - c - znaczek do dopisania.
+*/
int string_append_c(string_t s, char c)
{
if (!s) {
@@ -226,14 +230,14 @@ int string_append_c(string_t s, char c)
}
/*
- * string_append_n()
- *
- * dodaje tekst do bufora alokuj±c odpowiedni± ilo¶ж pamiкci.
- *
- * - s - ci±g znakуw,
- * - str - tekst do dopisania,
- * - count - ile znakуw tego tekstu dopisaж? (-1 znaczy, їe caіy).
- */
+* string_append_n()
+*
+* dodaje tekst do bufora alokuj±c odpowiedni± ilo¶ж pamiкci.
+*
+* - s - ci±g znakуw,
+* - str - tekst do dopisania,
+* - count - ile znakуw tego tekstu dopisaж? (-1 znaczy, їe caіy).
+*/
int string_append_n(string_t s, const char *str, int count)
{
if (!s || !str) {
@@ -260,15 +264,15 @@ int string_append(string_t s, const char *str)
}
/*
- * string_insert_n()
- *
- * wstawia tekst w podane miejsce bufora.
- *
- * - s - ci±g znakуw,
- * - index - miejsce, gdzie mamy wpisaж (liczone od 0),
- * - str - tekst do dopisania,
- * - count - ilo¶ж znakуw do dopisania (-1 znaczy, їe wszystkie).
- */
+* string_insert_n()
+*
+* wstawia tekst w podane miejsce bufora.
+*
+* - s - ci±g znakуw,
+* - index - miejsce, gdzie mamy wpisaж (liczone od 0),
+* - str - tekst do dopisania,
+* - count - ilo¶ж znakуw do dopisania (-1 znaczy, їe wszystkie).
+*/
void string_insert_n(string_t s, int index, const char *str, int count)
{
if (!s || !str)
@@ -294,14 +298,14 @@ void string_insert(string_t s, int index, const char *str)
}
/*
- * string_init()
- *
- * inicjuje strukturк string. alokuje pamiкж i przypisuje pierwsz± warto¶ж.
- *
- * - value - je¶li NULL, ci±g jest pusty, inaczej kopiuje tam.
- *
- * zwraca zaalokowan± strukturк `string'.
- */
+* string_init()
+*
+* inicjuje strukturк string. alokuje pamiкж i przypisuje pierwsz± warto¶ж.
+*
+* - value - je¶li NULL, ci±g jest pusty, inaczej kopiuje tam.
+*
+* zwraca zaalokowan± strukturк `string'.
+*/
string_t string_init(const char *value)
{
string_t tmp = (string_t)malloc(sizeof(struct string));
@@ -317,12 +321,12 @@ string_t string_init(const char *value)
}
/*
- * string_clear()
- *
- * czy¶ci zawarto¶ж struktury `string'.
- *
- * - s - ci±g znakуw.
- */
+* string_clear()
+*
+* czy¶ci zawarto¶ж struktury `string'.
+*
+* - s - ci±g znakуw.
+*/
void string_clear(string_t s)
{
if (!s)
@@ -338,16 +342,16 @@ void string_clear(string_t s)
}
/*
- * string_free()
- *
- * zwalnia pamiкж po strukturze string i moїe teї zwolniж pamiкж po samym
- * ci±gu znakуw.
- *
- * - s - struktura, ktуr± wycinamy,
- * - free_string - zwolniж pamiкж po ci±gu znakуw?
- *
- * je¶li free_string=0 zwraca wskaјnik do ci±gu, inaczej NULL.
- */
+* string_free()
+*
+* zwalnia pamiкж po strukturze string i moїe teї zwolniж pamiкж po samym
+* ci±gu znakуw.
+*
+* - s - struktura, ktуr± wycinamy,
+* - free_string - zwolniж pamiкж po ci±gu znakуw?
+*
+* je¶li free_string=0 zwraca wskaјnik do ci±gu, inaczej NULL.
+*/
char *string_free(string_t s, int free_string)
{
char *tmp = nullptr;
@@ -366,17 +370,17 @@ char *string_free(string_t s, int free_string)
}
/*
- * _itoa()
- *
- * prosta funkcja, ktуra zwraca tekstow± reprezentacjк liczby. w obrкbie
- * danego wywoіania jakiej¶ funkcji lub wyraїenia moїe byж wywoіania 10
- * razy, poniewaї tyle mamy statycznych buforуw. lepsze to niї ci±gіe
- * tworzenie tymczasowych buforуw na stosie i sprintf()owanie.
- *
- * - i - liczba do zamiany.
- *
- * zwraca adres do bufora, ktуrego _NIE_NALEЇY_ zwalniaж.
- */
+* _itoa()
+*
+* prosta funkcja, ktуra zwraca tekstow± reprezentacjк liczby. w obrкbie
+* danego wywoіania jakiej¶ funkcji lub wyraїenia moїe byж wywoіania 10
+* razy, poniewaї tyle mamy statycznych buforуw. lepsze to niї ci±gіe
+* tworzenie tymczasowych buforуw na stosie i sprintf()owanie.
+*
+* - i - liczba do zamiany.
+*
+* zwraca adres do bufora, ktуrego _NIE_NALEЇY_ zwalniaж.
+*/
const char *ditoa(long int i)
{
@@ -392,22 +396,22 @@ const char *ditoa(long int i)
}
/*
- * array_make()
- *
- * tworzy tablicк tekstуw z jednego, rozdzielonego podanymi znakami.
- *
- * - string - tekst wej¶ciowy,
- * - sep - lista elementуw oddzielaj±cych,
- * - max - maksymalna ilo¶ж elementуw tablicy. je¶li rуwne 0, nie ma
- * ograniczeс rozmiaru tablicy.
- * - trim - czy wiкksz± ilo¶ж elementуw oddzielaj±cych traktowaж jako
- * jeden (na przykіad spacje, tabulacja itp.)
- * - quotes - czy pola mog± byж zapisywane w cudzysіowiach lub
- * apostrofach z escapowanymi znakami.
- *
- * zaalokowan± tablicк z zaalokowanymi ci±gami znakуw, ktуr± naleїy
- * zwolniж funkcj± array_free()
- */
+* array_make()
+*
+* tworzy tablicк tekstуw z jednego, rozdzielonego podanymi znakami.
+*
+* - string - tekst wej¶ciowy,
+* - sep - lista elementуw oddzielaj±cych,
+* - max - maksymalna ilo¶ж elementуw tablicy. je¶li rуwne 0, nie ma
+* ograniczeс rozmiaru tablicy.
+* - trim - czy wiкksz± ilo¶ж elementуw oddzielaj±cych traktowaж jako
+* jeden (na przykіad spacje, tabulacja itp.)
+* - quotes - czy pola mog± byж zapisywane w cudzysіowiach lub
+* apostrofach z escapowanymi znakami.
+*
+* zaalokowan± tablicк z zaalokowanymi ci±gami znakуw, ktуr± naleїy
+* zwolniж funkcj± array_free()
+*/
char **array_make(const char *string, const char *sep, int max, int trim, int quotes)
{
const char *p, *q;
@@ -439,7 +443,8 @@ char **array_make(const char *string, const char *sep, int max, int trim, int qu
q++;
if (!*q)
break;
- } else if (*q == sep)
+ }
+ else if (*q == sep)
break;
}
@@ -454,21 +459,23 @@ char **array_make(const char *string, const char *sep, int max, int trim, int qu
break;
switch (*q) {
- case 'n':
- *r = '\n';
- break;
- case 'r':
- *r = '\r';
- break;
- case 't':
- *r = '\t';
- break;
- default:
- *r = *q;
+ case 'n':
+ *r = '\n';
+ break;
+ case 'r':
+ *r = '\r';
+ break;
+ case 't':
+ *r = '\t';
+ break;
+ default:
+ *r = *q;
}
- } else if (*q == sep) {
+ }
+ else if (*q == sep) {
break;
- } else
+ }
+ else
*r = *q;
}
@@ -477,7 +484,8 @@ char **array_make(const char *string, const char *sep, int max, int trim, int qu
p = (*q) ? q + 1 : q;
- } else {
+ }
+ else {
for (q = p, len = 0; *q && (last || !strchr(sep, *q)); q++, len++);
token = (char*)calloc(1, len + 1);
strncpy(token, p, len);
@@ -503,10 +511,10 @@ failure:
}
/*
- * array_count()
- *
- * zwraca ilo¶ж elementуw tablicy.
- */
+* array_count()
+*
+* zwraca ilo¶ж elementуw tablicy.
+*/
int array_count(char **array)
{
int result = 0;
@@ -523,10 +531,10 @@ int array_count(char **array)
}
/*
- * array_add()
- *
- * dodaje element do tablicy.
- */
+* array_add()
+*
+* dodaje element do tablicy.
+*/
void array_add(char ***array, char *string)
{
int count = array_count(*array);
@@ -537,16 +545,16 @@ void array_add(char ***array, char *string)
}
/*
- * array_join()
- *
- * і±czy elementy tablicy w jeden string oddzielaj±c elementy odpowiednim
- * separatorem.
- *
- * - array - wskaјnik do tablicy,
- * - sep - seperator.
- *
- * zwrуcony ci±g znakуw naleїy zwolniж.
- */
+* array_join()
+*
+* і±czy elementy tablicy w jeden string oddzielaj±c elementy odpowiednim
+* separatorem.
+*
+* - array - wskaјnik do tablicy,
+* - sep - seperator.
+*
+* zwrуcony ci±g znakуw naleїy zwolniж.
+*/
char *array_join(char **array, const char *sep)
{
if (!array)
@@ -564,16 +572,16 @@ char *array_join(char **array, const char *sep)
}
/*
- * array_contains()
- *
- * stwierdza, czy tablica zawiera podany element.
- *
- * - array - tablica,
- * - string - szukany ci±g znakуw,
- * - casesensitive - czy mamy zwracaж uwagк na wielko¶ж znakуw?
- *
- * 0/1
- */
+* array_contains()
+*
+* stwierdza, czy tablica zawiera podany element.
+*
+* - array - tablica,
+* - string - szukany ci±g znakуw,
+* - casesensitive - czy mamy zwracaж uwagк na wielko¶ж znakуw?
+*
+* 0/1
+*/
int array_contains(char **array, const char *string, int casesensitive)
{
int i;
@@ -592,10 +600,10 @@ int array_contains(char **array, const char *string, int casesensitive)
}
/*
- * array_free()
- *
- * zwalnia pamieж zajmowan± przez tablicк.
- */
+* array_free()
+*
+* zwalnia pamieж zajmowan± przez tablicк.
+*/
void array_free(char **array)
{
char **tmp;
diff --git a/protocols/Gadu-Gadu/src/filetransfer.cpp b/protocols/Gadu-Gadu/src/filetransfer.cpp
index 4b9f547930..d9a40be437 100644
--- a/protocols/Gadu-Gadu/src/filetransfer.cpp
+++ b/protocols/Gadu-Gadu/src/filetransfer.cpp
@@ -27,7 +27,8 @@ void GGPROTO::dccstart()
{
DWORD exitCode = 0;
- if (dcc) return;
+ if (dcc)
+ return;
// Startup dcc thread
GetExitCodeThread(pth_dcc.hThread, &exitCode);
@@ -38,7 +39,8 @@ void GGPROTO::dccstart()
debugLogA("dccstart(): DCC thread still active. Exiting...");
#endif
// Signalize mainthread it's started
- if (hEvent) SetEvent(hEvent);
+ if (hEvent)
+ SetEvent(hEvent);
return;
}
@@ -46,7 +48,8 @@ void GGPROTO::dccstart()
if (!getByte(GG_KEY_DIRECTCONNS, GG_KEYDEF_DIRECTCONNS))
{
debugLogA("dccstart(): No direct connections setup.");
- if (hEvent) SetEvent(hEvent);
+ if (hEvent)
+ SetEvent(hEvent);
return;
}
@@ -61,17 +64,17 @@ void GGPROTO::dccconnect(uin_t uin)
{
struct gg_dcc *local_dcc;
MCONTACT hContact = getcontact(uin, 0, 0, nullptr);
- DWORD ip, myuin; WORD port;
debugLogA("dccconnect(): Connecting to uin %d.", uin);
// If unknown user or not on list ignore
- if (!hContact) return;
+ if (!hContact)
+ return;
// Read user IP and port
- ip = swap32(getDword(hContact, GG_KEY_CLIENTIP, 0));
- port = getWord(hContact, GG_KEY_CLIENTPORT, 0);
- myuin = getDword(GG_KEY_UIN, 0);
+ DWORD ip = swap32(getDword(hContact, GG_KEY_CLIENTIP, 0));
+ WORD port = getWord(hContact, GG_KEY_CLIENTPORT, 0);
+ DWORD myuin = getDword(GG_KEY_UIN, 0);
// If not port nor ip nor my uin (?) specified
if (!ip || !port || !uin) return;
@@ -171,13 +174,14 @@ void __cdecl GGPROTO::dccmainthread(void*)
debugLogA("dccmainthread(): Listening on port %d.", gg_dcc_port);
// Signalize mainthread we started
- if (hEvent) SetEvent(hEvent);
+ if (hEvent)
+ SetEvent(hEvent);
// Add main dcc handler to watches
list_add(&watches, dcc, 0);
// Do while we are in the main server thread
- while(pth_dcc.dwThreadId && dcc)
+ while (pth_dcc.dwThreadId && dcc)
{
// Timeouts
tv.tv_sec = 1;
@@ -230,380 +234,382 @@ void __cdecl GGPROTO::dccmainthread(void*)
switch (local_c->type)
{
- default:
- if (!local_dcc || (!FD_ISSET(local_dcc->fd, &rd) && !FD_ISSET(local_dcc->fd, &wd)))
- continue;
-
- /////////////////////////////////////////////////////////////////
- // Process DCC events
+ default:
+ if (!local_dcc || (!FD_ISSET(local_dcc->fd, &rd) && !FD_ISSET(local_dcc->fd, &wd)))
+ continue;
+
+ /////////////////////////////////////////////////////////////////
+ // Process DCC events
+
+ // Connection broken/closed
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 2, "ft_mutex", 1);
+ if (!(e = gg_dcc_socket_watch_fd(local_dcc)))
+ {
+ debugLogA("dccmainthread(): Socket closed.");
+ // Remove socket and _close
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
+ list_remove(&watches, local_dcc, 0);
+ gg_dcc_socket_free(local_dcc);
+
+ // Check if it's main socket
+ if (local_dcc == dcc) dcc = nullptr;
+ continue;
+ }
+ else {
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
+ debugLogA("dccmainthread(): Event: %s", ggdebug_eventtype(e));
+ }
+
+ switch (e->type)
+ {
+ // Client connected
+ case GG_EVENT_DCC_NEW:
+ list_add(&watches, e->event.dcc_new, 0);
+ e->event.dcc_new = nullptr;
+ break;
- // Connection broken/closed
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 2, "ft_mutex", 1);
- if (!(e = gg_dcc_socket_watch_fd(local_dcc)))
+ //
+ case GG_EVENT_NONE:
+ // If transfer in progress do status
+ if (local_dcc->file_fd != -1 && local_dcc->offset > 0 && (((tick = GetTickCount()) - local_dcc->tick) > GGSTATREFRESHEVERY))
{
- debugLogA("dccmainthread(): Socket closed.");
- // Remove socket and _close
+ PROTOFILETRANSFERSTATUS pfts;
+ local_dcc->tick = tick;
+ mir_snprintf(szFilename, "%s%s", local_dcc->folder, local_dcc->file_info.filename);
+ memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS));
+ pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS);
+ pfts.hContact = (UINT_PTR)local_dcc->contact;
+ pfts.flags = (local_dcc->type == GG_SESSION_DCC_SEND);
+ pfts.pszFiles = nullptr;
+ pfts.totalFiles = 1;
+ pfts.currentFileNumber = 0;
+ pfts.totalBytes = local_dcc->file_info.size;
+ pfts.totalProgress = local_dcc->offset;
+ pfts.szWorkingDir = local_dcc->folder;
+ pfts.szCurrentFile = szFilename;
+ pfts.currentFileSize = local_dcc->file_info.size;
+ pfts.currentFileProgress = local_dcc->offset;
+ pfts.currentFileTime = 0;
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 3, "ft_mutex", 1);
+ ProtoBroadcastAck((UINT_PTR)local_dcc->contact, ACKTYPE_FILE, ACKRESULT_DATA, local_dcc, (LPARAM)&pfts);
gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- list_remove(&watches, local_dcc, 0);
- gg_dcc_socket_free(local_dcc);
+ }
+ break;
- // Check if it's main socket
- if (local_dcc == dcc) dcc = nullptr;
- continue;
- } else {
+ // Connection was successfuly ended
+ case GG_EVENT_DCC_DONE:
+ debugLogA("dccmainthread(): Client: %d, Transfer done ! Closing connection.", dcc->peer_uin);
+ // Remove from watches
+ list_remove(&watches, local_dcc, 0);
+ // Close file & success
+ if (local_dcc->file_fd != -1)
+ {
+ PROTOFILETRANSFERSTATUS pfts;
+ mir_snprintf(szFilename, "%s%s", local_dcc->folder, local_dcc->file_info.filename);
+ memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS));
+ pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS);
+ pfts.hContact = (UINT_PTR)local_dcc->contact;
+ pfts.flags = (local_dcc->type == GG_SESSION_DCC_SEND);
+ pfts.pszFiles = nullptr;
+ pfts.totalFiles = 1;
+ pfts.currentFileNumber = 0;
+ pfts.totalBytes = local_dcc->file_info.size;
+ pfts.totalProgress = local_dcc->file_info.size;
+ pfts.szWorkingDir = local_dcc->folder;
+ pfts.szCurrentFile = szFilename;
+ pfts.currentFileSize = local_dcc->file_info.size;
+ pfts.currentFileProgress = local_dcc->file_info.size;
+ pfts.currentFileTime = 0;
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 4, "ft_mutex", 1);
+ ProtoBroadcastAck((UINT_PTR)local_dcc->contact, ACKTYPE_FILE, ACKRESULT_DATA, local_dcc, (LPARAM)&pfts);
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
+ _close(local_dcc->file_fd); local_dcc->file_fd = -1;
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 5, "ft_mutex", 1);
+ ProtoBroadcastAck((UINT_PTR)local_dcc->contact, ACKTYPE_FILE, ACKRESULT_SUCCESS, local_dcc, 0);
gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- debugLogA("dccmainthread(): Event: %s", ggdebug_eventtype(e));
}
+ // Free dcc
+ gg_free_dcc(local_dcc); if (local_dcc == dcc) dcc = nullptr;
+ break;
- switch(e->type)
+ // Client error
+ case GG_EVENT_DCC_ERROR:
+ switch (e->event.dcc_error)
{
- // Client connected
- case GG_EVENT_DCC_NEW:
- list_add(&watches, e->event.dcc_new, 0);
- e->event.dcc_new = nullptr;
- break;
+ case GG_ERROR_DCC_HANDSHAKE:
+ debugLogA("dccmainthread(): Client: %d, Handshake error.", local_dcc->peer_uin);
+ break;
+ case GG_ERROR_DCC_NET:
+ debugLogA("dccmainthread(): Client: %d, Network error.", local_dcc->peer_uin);
+ break;
+ case GG_ERROR_DCC_FILE:
+ debugLogA("dccmainthread(): Client: %d, File read/write error.", local_dcc->peer_uin);
+ break;
+ case GG_ERROR_DCC_EOF:
+ debugLogA("dccmainthread(): Client: %d, End of file/connection error.", local_dcc->peer_uin);
+ break;
+ case GG_ERROR_DCC_REFUSED:
+ debugLogA("dccmainthread(): Client: %d, Connection refused error.", local_dcc->peer_uin);
+ break;
+ default:
+ debugLogA("dccmainthread(): Client: %d, Unknown error.", local_dcc->peer_uin);
+ }
+ // Don't do anything if it's main socket
+ if (local_dcc == dcc) break;
- //
- case GG_EVENT_NONE:
- // If transfer in progress do status
- if (local_dcc->file_fd != -1 && local_dcc->offset > 0 && (((tick = GetTickCount()) - local_dcc->tick) > GGSTATREFRESHEVERY))
- {
- PROTOFILETRANSFERSTATUS pfts;
- local_dcc->tick = tick;
- mir_snprintf(szFilename, "%s%s", local_dcc->folder, local_dcc->file_info.filename);
- memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS));
- pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS);
- pfts.hContact = (UINT_PTR)local_dcc->contact;
- pfts.flags = (local_dcc->type == GG_SESSION_DCC_SEND);
- pfts.pszFiles = nullptr;
- pfts.totalFiles = 1;
- pfts.currentFileNumber = 0;
- pfts.totalBytes = local_dcc->file_info.size;
- pfts.totalProgress = local_dcc->offset;
- pfts.szWorkingDir = local_dcc->folder;
- pfts.szCurrentFile = szFilename;
- pfts.currentFileSize = local_dcc->file_info.size;
- pfts.currentFileProgress = local_dcc->offset;
- pfts.currentFileTime = 0;
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 3, "ft_mutex", 1);
- ProtoBroadcastAck((UINT_PTR)local_dcc->contact, ACKTYPE_FILE, ACKRESULT_DATA, local_dcc, (LPARAM)&pfts);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- }
- break;
+ // Remove from watches
+ list_remove(&watches, local_dcc, 0);
- // Connection was successfuly ended
- case GG_EVENT_DCC_DONE:
- debugLogA("dccmainthread(): Client: %d, Transfer done ! Closing connection.", dcc->peer_uin);
- // Remove from watches
- list_remove(&watches, local_dcc, 0);
- // Close file & success
- if (local_dcc->file_fd != -1)
- {
- PROTOFILETRANSFERSTATUS pfts;
- mir_snprintf(szFilename, "%s%s", local_dcc->folder, local_dcc->file_info.filename);
- memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS));
- pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS);
- pfts.hContact = (UINT_PTR)local_dcc->contact;
- pfts.flags = (local_dcc->type == GG_SESSION_DCC_SEND);
- pfts.pszFiles = nullptr;
- pfts.totalFiles = 1;
- pfts.currentFileNumber = 0;
- pfts.totalBytes = local_dcc->file_info.size;
- pfts.totalProgress = local_dcc->file_info.size;
- pfts.szWorkingDir = local_dcc->folder;
- pfts.szCurrentFile = szFilename;
- pfts.currentFileSize = local_dcc->file_info.size;
- pfts.currentFileProgress = local_dcc->file_info.size;
- pfts.currentFileTime = 0;
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 4, "ft_mutex", 1);
- ProtoBroadcastAck((UINT_PTR)local_dcc->contact, ACKTYPE_FILE, ACKRESULT_DATA, local_dcc, (LPARAM)&pfts);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- _close(local_dcc->file_fd); local_dcc->file_fd = -1;
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 5, "ft_mutex", 1);
- ProtoBroadcastAck((UINT_PTR)local_dcc->contact, ACKTYPE_FILE, ACKRESULT_SUCCESS, local_dcc, 0);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- }
- // Free dcc
- gg_free_dcc(local_dcc); if (local_dcc == dcc) dcc = nullptr;
- break;
+ // Close file & fail
+ if (local_dcc->contact)
+ {
+ _close(local_dcc->file_fd); local_dcc->file_fd = -1;
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 6, "ft_mutex", 1);
+ ProtoBroadcastAck((UINT_PTR)local_dcc->contact, ACKTYPE_FILE, ACKRESULT_FAILED, local_dcc, 0);
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
+ }
+ // Free dcc
+ gg_free_dcc(local_dcc); if (local_dcc == dcc) dcc = nullptr;
+ break;
- // Client error
- case GG_EVENT_DCC_ERROR:
- switch (e->event.dcc_error)
- {
- case GG_ERROR_DCC_HANDSHAKE:
- debugLogA("dccmainthread(): Client: %d, Handshake error.", local_dcc->peer_uin);
- break;
- case GG_ERROR_DCC_NET:
- debugLogA("dccmainthread(): Client: %d, Network error.", local_dcc->peer_uin);
- break;
- case GG_ERROR_DCC_FILE:
- debugLogA("dccmainthread(): Client: %d, File read/write error.", local_dcc->peer_uin);
- break;
- case GG_ERROR_DCC_EOF:
- debugLogA("dccmainthread(): Client: %d, End of file/connection error.", local_dcc->peer_uin);
- break;
- case GG_ERROR_DCC_REFUSED:
- debugLogA("dccmainthread(): Client: %d, Connection refused error.", local_dcc->peer_uin);
- break;
- default:
- debugLogA("dccmainthread(): Client: %d, Unknown error.", local_dcc->peer_uin);
- }
- // Don't do anything if it's main socket
- if (local_dcc == dcc) break;
-
- // Remove from watches
- list_remove(&watches, local_dcc, 0);
+ // Need file acknowledgement
+ case GG_EVENT_DCC_NEED_FILE_ACK:
+ debugLogA("dccmainthread(): Client: %d, File ack filename \"%s\" size %d.", local_dcc->peer_uin,
+ local_dcc->file_info.filename, local_dcc->file_info.size);
+ // Do not watch for transfer until user accept it
+ list_remove(&watches, local_dcc, 0);
+ // Add to waiting transfers
+ list_add(&transfers, local_dcc, 0);
+
+ //////////////////////////////////////////////////
+ // Add file recv request
+ {
+ // Make new ggtransfer struct
+ local_dcc->contact = (void*)getcontact(local_dcc->peer_uin, 0, 0, nullptr);
+ wchar_t* filenameT = mir_utf8decodeW((char*)dcc->file_info.filename);
+
+ PROTORECVFILET pre = { 0 };
+ pre.dwFlags = PRFF_UNICODE;
+ pre.fileCount = 1;
+ pre.timestamp = time(nullptr);
+ pre.descr.w = filenameT;
+ pre.files.w = &filenameT;
+ pre.lParam = (LPARAM)local_dcc;
+
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 7, "ft_mutex", 1);
+ ProtoChainRecvFile((UINT_PTR)local_dcc->contact, &pre);
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- // Close file & fail
- if (local_dcc->contact)
- {
- _close(local_dcc->file_fd); local_dcc->file_fd = -1;
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 6, "ft_mutex", 1);
- ProtoBroadcastAck((UINT_PTR)local_dcc->contact, ACKTYPE_FILE, ACKRESULT_FAILED, local_dcc, 0);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- }
- // Free dcc
- gg_free_dcc(local_dcc); if (local_dcc == dcc) dcc = nullptr;
- break;
+ mir_free(filenameT);
+ }
+ break;
- // Need file acknowledgement
- case GG_EVENT_DCC_NEED_FILE_ACK:
- debugLogA("dccmainthread(): Client: %d, File ack filename \"%s\" size %d.", local_dcc->peer_uin,
- local_dcc->file_info.filename, local_dcc->file_info.size);
- // Do not watch for transfer until user accept it
- list_remove(&watches, local_dcc, 0);
- // Add to waiting transfers
- list_add(&transfers, local_dcc, 0);
-
- //////////////////////////////////////////////////
- // Add file recv request
- {
- // Make new ggtransfer struct
- local_dcc->contact = (void*)getcontact(local_dcc->peer_uin, 0, 0, nullptr);
- wchar_t* filenameT = mir_utf8decodeW((char*)dcc->file_info.filename);
-
- PROTORECVFILET pre = {0};
- pre.dwFlags = PRFF_UNICODE;
- pre.fileCount = 1;
- pre.timestamp = time(nullptr);
- pre.descr.w = filenameT;
- pre.files.w = &filenameT;
- pre.lParam = (LPARAM)local_dcc;
-
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 7, "ft_mutex", 1);
- ProtoChainRecvFile((UINT_PTR)local_dcc->contact, &pre);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
-
- mir_free(filenameT);
- }
- break;
+ // Need client accept
+ case GG_EVENT_DCC_CLIENT_ACCEPT:
+ debugLogA("dccmainthread(): Client: %d, Client accept.", local_dcc->peer_uin);
+ // Check if user is on the list and if it is my uin
+ if (getcontact(local_dcc->peer_uin, 0, 0, nullptr) &&
+ getDword(GG_KEY_UIN, -1) == local_dcc->uin)
+ break;
+
+ // Kill unauthorized dcc
+ list_remove(&watches, dcc, 0);
+ gg_free_dcc(local_dcc); if (local_dcc == dcc) dcc = nullptr;
+ break;
- // Need client accept
- case GG_EVENT_DCC_CLIENT_ACCEPT:
- debugLogA("dccmainthread(): Client: %d, Client accept.", local_dcc->peer_uin);
- // Check if user is on the list and if it is my uin
- if (getcontact(local_dcc->peer_uin, 0, 0, nullptr) &&
- getDword(GG_KEY_UIN, -1) == local_dcc->uin)
- break;
-
- // Kill unauthorized dcc
- list_remove(&watches, dcc, 0);
- gg_free_dcc(local_dcc); if (local_dcc == dcc) dcc = nullptr;
- break;
+ // Client connected as we wished to (callback)
+ case GG_EVENT_DCC_CALLBACK:
+ {
+ int found = 0;
+ debugLogA("dccmainthread(): Callback from client %d.", local_dcc->peer_uin);
+ // Seek for stored callback request
+ for (l = requests; l; l = l->next)
+ {
+ struct gg_dcc *req = (gg_dcc*)l->data;
- // Client connected as we wished to (callback)
- case GG_EVENT_DCC_CALLBACK:
+ if (req && req->peer_uin == local_dcc->peer_uin)
{
- int found = 0;
- debugLogA("dccmainthread(): Callback from client %d.", local_dcc->peer_uin);
- // Seek for stored callback request
- for (l = requests; l; l = l->next)
- {
- struct gg_dcc *req = (gg_dcc*)l->data;
-
- if (req && req->peer_uin == local_dcc->peer_uin)
- {
- gg_dcc_set_type(local_dcc, GG_SESSION_DCC_SEND);
- found = 1;
-
- // Copy data req ===> dcc
- local_dcc->folder = req->folder;
- local_dcc->contact = req->contact;
- local_dcc->file_fd = req->file_fd;
- memcpy(&local_dcc->file_info, &req->file_info, sizeof(struct gg_file_info));
- // Copy data back to dcc ===> req
- memcpy(req, local_dcc, sizeof(struct gg_dcc));
-
- // Remove request
- list_remove(&requests, req, 0);
- // Remove dcc from watches
- list_remove(&watches, local_dcc, 0);
- // Add request to watches
- list_add(&watches, req, 0);
- // Free old dat
- gg_free_dcc(local_dcc);
- debugLogA("dccmainthread(): Found stored request to client %d, filename \"%s\" size %d, folder \"%s\".",
- req->peer_uin, req->file_info.filename, req->file_info.size, req->folder);
- break;
- }
- }
-
- if (!found)
- {
- debugLogA("dccmainthread(): Unknown request to client %d.", local_dcc->peer_uin);
- // Kill unauthorized dcc
- list_remove(&watches, local_dcc, 0);
- gg_free_dcc(local_dcc); if (local_dcc == dcc) dcc = nullptr;
- }
+ gg_dcc_set_type(local_dcc, GG_SESSION_DCC_SEND);
+ found = 1;
+
+ // Copy data req ===> dcc
+ local_dcc->folder = req->folder;
+ local_dcc->contact = req->contact;
+ local_dcc->file_fd = req->file_fd;
+ memcpy(&local_dcc->file_info, &req->file_info, sizeof(struct gg_file_info));
+ // Copy data back to dcc ===> req
+ memcpy(req, local_dcc, sizeof(struct gg_dcc));
+
+ // Remove request
+ list_remove(&requests, req, 0);
+ // Remove dcc from watches
+ list_remove(&watches, local_dcc, 0);
+ // Add request to watches
+ list_add(&watches, req, 0);
+ // Free old dat
+ gg_free_dcc(local_dcc);
+ debugLogA("dccmainthread(): Found stored request to client %d, filename \"%s\" size %d, folder \"%s\".",
+ req->peer_uin, req->file_info.filename, req->file_info.size, req->folder);
break;
}
}
- // Free event
- gg_free_event(e);
+ if (!found)
+ {
+ debugLogA("dccmainthread(): Unknown request to client %d.", local_dcc->peer_uin);
+ // Kill unauthorized dcc
+ list_remove(&watches, local_dcc, 0);
+ gg_free_dcc(local_dcc); if (local_dcc == dcc) dcc = nullptr;
+ }
+ break;
+ }
+ }
+
+ // Free event
+ gg_free_event(e);
+ break;
+
+ case GG_SESSION_DCC7_SOCKET:
+ case GG_SESSION_DCC7_GET:
+ case GG_SESSION_DCC7_SEND:
+ case GG_SESSION_DCC7_VOICE:
+ if (!local_dcc7 || (!FD_ISSET(local_dcc7->fd, &rd) && !FD_ISSET(local_dcc7->fd, &wd)))
+ continue;
+
+ /////////////////////////////////////////////////////////////////
+ // Process DCC7 events
+
+ // Connection broken/closed
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 8, "ft_mutex", 1);
+ if (!(e = gg_dcc7_watch_fd(local_dcc7)))
+ {
+ debugLogA("dccmainthread(): Socket closed.");
+ // Remove socket and _close
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
+ list_remove(&watches, local_dcc7, 0);
+ gg_dcc7_free(local_dcc7);
+ continue;
+ }
+ else {
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
+ debugLogA("dccmainthread(): Event: %s", ggdebug_eventtype(e));
+ }
+
+ switch (e->type)
+ {
+ //
+ case GG_EVENT_NONE:
+ // If transfer in progress do status
+ if (local_dcc7->file_fd != -1 && local_dcc7->offset > 0 && (((tick = GetTickCount()) - local_dcc7->tick) > GGSTATREFRESHEVERY))
+ {
+ PROTOFILETRANSFERSTATUS pfts;
+ local_dcc7->tick = tick;
+ mir_snprintf(szFilename, "%s%s", local_dcc->folder, local_dcc7->filename);
+ memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS));
+ pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS);
+ pfts.hContact = (UINT_PTR)local_dcc7->contact;
+ pfts.flags = (local_dcc7->type == GG_SESSION_DCC7_SEND);
+ pfts.pszFiles = nullptr;
+ pfts.totalFiles = 1;
+ pfts.currentFileNumber = 0;
+ pfts.totalBytes = local_dcc7->size;
+ pfts.totalProgress = local_dcc7->offset;
+ pfts.szWorkingDir = local_dcc7->folder;
+ pfts.szCurrentFile = szFilename;
+ pfts.currentFileSize = local_dcc7->size;
+ pfts.currentFileProgress = local_dcc7->offset;
+ pfts.currentFileTime = 0;
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 9, "ft_mutex", 1);
+ ProtoBroadcastAck((UINT_PTR)local_dcc7->contact, ACKTYPE_FILE, ACKRESULT_DATA, local_dcc7, (LPARAM)&pfts);
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
+ }
break;
- case GG_SESSION_DCC7_SOCKET:
- case GG_SESSION_DCC7_GET:
- case GG_SESSION_DCC7_SEND:
- case GG_SESSION_DCC7_VOICE:
- if (!local_dcc7 || (!FD_ISSET(local_dcc7->fd, &rd) && !FD_ISSET(local_dcc7->fd, &wd)))
- continue;
-
- /////////////////////////////////////////////////////////////////
- // Process DCC7 events
-
- // Connection broken/closed
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 8, "ft_mutex", 1);
- if (!(e = gg_dcc7_watch_fd(local_dcc7)))
+ // Connection was successfuly ended
+ case GG_EVENT_DCC7_DONE:
+ debugLogA("dccmainthread(): Client: %d, Transfer done ! Closing connection.", dcc->peer_uin);
+ // Remove from watches
+ list_remove(&watches, local_dcc7, 0);
+ // Close file & success
+ if (local_dcc7->file_fd != -1)
{
- debugLogA("dccmainthread(): Socket closed.");
- // Remove socket and _close
+ PROTOFILETRANSFERSTATUS pfts;
+ mir_snprintf(szFilename, "%s%s", local_dcc->folder, local_dcc7->filename);
+ memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS));
+ pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS);
+ pfts.hContact = (UINT_PTR)local_dcc7->contact;
+ pfts.flags = (local_dcc7->type == GG_SESSION_DCC7_SEND);
+ pfts.pszFiles = nullptr;
+ pfts.totalFiles = 1;
+ pfts.currentFileNumber = 0;
+ pfts.totalBytes = local_dcc7->size;
+ pfts.totalProgress = local_dcc7->size;
+ pfts.szWorkingDir = local_dcc7->folder;
+ pfts.szCurrentFile = szFilename;
+ pfts.currentFileSize = local_dcc7->size;
+ pfts.currentFileProgress = local_dcc7->size;
+ pfts.currentFileTime = 0;
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 10, "ft_mutex", 1);
+ ProtoBroadcastAck((UINT_PTR)local_dcc7->contact, ACKTYPE_FILE, ACKRESULT_DATA, local_dcc7, (LPARAM)&pfts);
gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- list_remove(&watches, local_dcc7, 0);
- gg_dcc7_free(local_dcc7);
- continue;
- } else {
+ _close(local_dcc7->file_fd); local_dcc7->file_fd = -1;
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 11, "ft_mutex", 1);
+ ProtoBroadcastAck((UINT_PTR)local_dcc7->contact, ACKTYPE_FILE, ACKRESULT_SUCCESS, local_dcc7, 0);
gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- debugLogA("dccmainthread(): Event: %s", ggdebug_eventtype(e));
}
+ // Free dcc
+ gg_dcc7_free(local_dcc7);
+ break;
- switch(e->type)
+ // Client error
+ case GG_EVENT_DCC7_ERROR:
+ switch (e->event.dcc7_error)
{
- //
- case GG_EVENT_NONE:
- // If transfer in progress do status
- if (local_dcc7->file_fd != -1 && local_dcc7->offset > 0 && (((tick = GetTickCount()) - local_dcc7->tick) > GGSTATREFRESHEVERY))
- {
- PROTOFILETRANSFERSTATUS pfts;
- local_dcc7->tick = tick;
- mir_snprintf(szFilename, "%s%s", local_dcc->folder, local_dcc7->filename);
- memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS));
- pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS);
- pfts.hContact = (UINT_PTR)local_dcc7->contact;
- pfts.flags = (local_dcc7->type == GG_SESSION_DCC7_SEND);
- pfts.pszFiles = nullptr;
- pfts.totalFiles = 1;
- pfts.currentFileNumber = 0;
- pfts.totalBytes = local_dcc7->size;
- pfts.totalProgress = local_dcc7->offset;
- pfts.szWorkingDir = local_dcc7->folder;
- pfts.szCurrentFile = szFilename;
- pfts.currentFileSize = local_dcc7->size;
- pfts.currentFileProgress = local_dcc7->offset;
- pfts.currentFileTime = 0;
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 9, "ft_mutex", 1);
- ProtoBroadcastAck((UINT_PTR)local_dcc7->contact, ACKTYPE_FILE, ACKRESULT_DATA, local_dcc7, (LPARAM)&pfts);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- }
- break;
+ case GG_ERROR_DCC7_HANDSHAKE:
+ debugLogA("dccmainthread(): Client: %d, Handshake error.", local_dcc7->peer_uin);
+ break;
+ case GG_ERROR_DCC7_NET:
+ debugLogA("dccmainthread(): Client: %d, Network error.", local_dcc7->peer_uin);
+ break;
+ case GG_ERROR_DCC7_FILE:
+ debugLogA("dccmainthread(): Client: %d, File read/write error.", local_dcc7->peer_uin);
+ break;
+ case GG_ERROR_DCC7_EOF:
+ debugLogA("dccmainthread(): Client: %d, End of file/connection error.", local_dcc7->peer_uin);
+ break;
+ case GG_ERROR_DCC7_REFUSED:
+ debugLogA("dccmainthread(): Client: %d, Connection refused error.", local_dcc7->peer_uin);
+ break;
+ case GG_ERROR_DCC7_RELAY:
+ debugLogA("dccmainthread(): Client: %d, Relay connection error.", local_dcc7->peer_uin);
+ break;
+ default:
+ debugLogA("dccmainthread(): Client: %d, Unknown error.", local_dcc7->peer_uin);
+ }
+ // Remove from watches
+ list_remove(&watches, local_dcc7, 0);
- // Connection was successfuly ended
- case GG_EVENT_DCC7_DONE:
- debugLogA("dccmainthread(): Client: %d, Transfer done ! Closing connection.", dcc->peer_uin);
- // Remove from watches
- list_remove(&watches, local_dcc7, 0);
- // Close file & success
- if (local_dcc7->file_fd != -1)
- {
- PROTOFILETRANSFERSTATUS pfts;
- mir_snprintf(szFilename, "%s%s", local_dcc->folder, local_dcc7->filename);
- memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS));
- pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS);
- pfts.hContact = (UINT_PTR)local_dcc7->contact;
- pfts.flags = (local_dcc7->type == GG_SESSION_DCC7_SEND);
- pfts.pszFiles = nullptr;
- pfts.totalFiles = 1;
- pfts.currentFileNumber = 0;
- pfts.totalBytes = local_dcc7->size;
- pfts.totalProgress = local_dcc7->size;
- pfts.szWorkingDir = local_dcc7->folder;
- pfts.szCurrentFile = szFilename;
- pfts.currentFileSize = local_dcc7->size;
- pfts.currentFileProgress = local_dcc7->size;
- pfts.currentFileTime = 0;
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 10, "ft_mutex", 1);
- ProtoBroadcastAck((UINT_PTR)local_dcc7->contact, ACKTYPE_FILE, ACKRESULT_DATA, local_dcc7, (LPARAM)&pfts);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- _close(local_dcc7->file_fd); local_dcc7->file_fd = -1;
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 11, "ft_mutex", 1);
- ProtoBroadcastAck((UINT_PTR)local_dcc7->contact, ACKTYPE_FILE, ACKRESULT_SUCCESS, local_dcc7, 0);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- }
- // Free dcc
- gg_dcc7_free(local_dcc7);
- break;
+ // Close file & fail
+ if (local_dcc7->file_fd != -1)
+ {
+ _close(local_dcc7->file_fd);
+ local_dcc7->file_fd = -1;
+ }
- // Client error
- case GG_EVENT_DCC7_ERROR:
- switch (e->event.dcc7_error)
- {
- case GG_ERROR_DCC7_HANDSHAKE:
- debugLogA("dccmainthread(): Client: %d, Handshake error.", local_dcc7->peer_uin);
- break;
- case GG_ERROR_DCC7_NET:
- debugLogA("dccmainthread(): Client: %d, Network error.", local_dcc7->peer_uin);
- break;
- case GG_ERROR_DCC7_FILE:
- debugLogA("dccmainthread(): Client: %d, File read/write error.", local_dcc7->peer_uin);
- break;
- case GG_ERROR_DCC7_EOF:
- debugLogA("dccmainthread(): Client: %d, End of file/connection error.", local_dcc7->peer_uin);
- break;
- case GG_ERROR_DCC7_REFUSED:
- debugLogA("dccmainthread(): Client: %d, Connection refused error.", local_dcc7->peer_uin);
- break;
- case GG_ERROR_DCC7_RELAY:
- debugLogA("dccmainthread(): Client: %d, Relay connection error.", local_dcc7->peer_uin);
- break;
- default:
- debugLogA("dccmainthread(): Client: %d, Unknown error.", local_dcc7->peer_uin);
- }
- // Remove from watches
- list_remove(&watches, local_dcc7, 0);
-
- // Close file & fail
- if (local_dcc7->file_fd != -1)
- {
- _close(local_dcc7->file_fd);
- local_dcc7->file_fd = -1;
- }
-
- if (local_dcc7->contact) {
- gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 12, "ft_mutex", 1);
- ProtoBroadcastAck((UINT_PTR)local_dcc7->contact, ACKTYPE_FILE, ACKRESULT_FAILED, local_dcc7, 0);
- gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
- }
-
- // Free dcc
- gg_dcc7_free(local_dcc7);
- break;
+ if (local_dcc7->contact) {
+ gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 12, "ft_mutex", 1);
+ ProtoBroadcastAck((UINT_PTR)local_dcc7->contact, ACKTYPE_FILE, ACKRESULT_FAILED, local_dcc7, 0);
+ gg_EnterCriticalSection(&ft_mutex, "dccmainthread", 37, "ft_mutex", 1);
}
- // Free event
- gg_free_event(e);
+ // Free dcc
+ gg_dcc7_free(local_dcc7);
break;
+ }
+
+ // Free event
+ gg_free_event(e);
+ break;
}
}
gg_LeaveCriticalSection(&ft_mutex, "dccmainthread", 37, 1, "ft_mutex", 1);
@@ -756,9 +762,14 @@ int GGPROTO::dccfiledeny(HANDLE hTransfer)
// Remove transfer from any list
gg_EnterCriticalSection(&ft_mutex, "dccfiledeny", 42, "ft_mutex", 1);
- if (watches) list_remove(&watches, dcc, 0);
- if (requests) list_remove(&requests, dcc, 0);
- if (transfers) list_remove(&transfers, dcc, 0);
+
+ if (watches)
+ list_remove(&watches, dcc, 0);
+ if (requests)
+ list_remove(&requests, dcc, 0);
+ if (transfers)
+ list_remove(&transfers, dcc, 0);
+
gg_LeaveCriticalSection(&ft_mutex, "dccfiledeny", 42, 1, "ft_mutex", 1);
debugLogA("dccfiledeny(): Rejected file \"%s\" from/to %d.", dcc->file_info.filename, dcc->peer_uin);
@@ -777,8 +788,12 @@ int GGPROTO::dcc7filedeny(HANDLE hTransfer)
// Remove transfer from any list
gg_EnterCriticalSection(&ft_mutex, "dcc7filedeny", 43, "ft_mutex", 1);
- if (watches) list_remove(&watches, dcc7, 0);
- if (transfers) list_remove(&transfers, dcc7, 0);
+
+ if (watches)
+ list_remove(&watches, dcc7, 0);
+ if (transfers)
+ list_remove(&transfers, dcc7, 0);
+
gg_LeaveCriticalSection(&ft_mutex, "dcc7filedeny", 43, 1, "ft_mutex", 1);
debugLogA("dcc7filedeny(): Rejected file \"%s\" from/to %d.", dcc7->filename, dcc7->peer_uin);
@@ -795,9 +810,14 @@ int GGPROTO::dccfilecancel(HANDLE hTransfer)
// Remove transfer from any list
gg_EnterCriticalSection(&ft_mutex, "dccfilecancel", 44, "ft_mutex", 1);
- if (watches) list_remove(&watches, dcc, 0);
- if (requests) list_remove(&requests, dcc, 0);
- if (transfers) list_remove(&transfers, dcc, 0);
+
+ if (watches)
+ list_remove(&watches, dcc, 0);
+ if (requests)
+ list_remove(&requests, dcc, 0);
+ if (transfers)
+ list_remove(&transfers, dcc, 0);
+
gg_LeaveCriticalSection(&ft_mutex, "dccfilecancel", 44, 1, "ft_mutex", 1);
// Send failed info
@@ -826,8 +846,12 @@ int GGPROTO::dcc7filecancel(HANDLE hTransfer)
// Remove transfer from any list
gg_EnterCriticalSection(&ft_mutex, "dcc7filecancel", 45, "ft_mutex", 1);
- if (watches) list_remove(&watches, dcc7, 0);
- if (transfers) list_remove(&transfers, dcc7, 0);
+
+ if (watches)
+ list_remove(&watches, dcc7, 0);
+ if (transfers)
+ list_remove(&transfers, dcc7, 0);
+
gg_LeaveCriticalSection(&ft_mutex, "dcc7filecancel", 45, 1, "ft_mutex", 1);
// Send failed info
@@ -909,9 +933,6 @@ int GGPROTO::RecvFile(MCONTACT hContact, PROTORECVFILET* pre)
HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles)
{
char *bslash, *filename;
- DWORD ip, ver;
- WORD port;
- uin_t myuin, uin;
// Check if main dcc thread is on
if (!isonline())
@@ -920,15 +941,14 @@ HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles
filename = mir_u2a(ppszFiles[0]);
// Read user IP and port
- ip = swap32(getDword(hContact, GG_KEY_CLIENTIP, 0));
- port = getWord(hContact, GG_KEY_CLIENTPORT, 0);
- myuin = getDword(GG_KEY_UIN, 0);
- uin = getDword(hContact, GG_KEY_UIN, 0);
- ver = getDword(hContact, GG_KEY_CLIENTVERSION, 0);
+ DWORD ip = swap32(getDword(hContact, GG_KEY_CLIENTIP, 0));
+ WORD port = getWord(hContact, GG_KEY_CLIENTPORT, 0);
+ uin_t myuin = getDword(GG_KEY_UIN, 0);
+ uin_t uin = getDword(hContact, GG_KEY_UIN, 0);
+ DWORD ver = getDword(hContact, GG_KEY_CLIENTVERSION, 0);
// Use DCC7 if a contact is using at least version 7.6 or unknown version
if ((ver & 0x00ffffff) >= 0x29 || !ver) {
-
gg_EnterCriticalSection(&sess_mutex, "SendFile", 46, "sess_mutex", 1);
struct gg_dcc7 *dcc7 = gg_dcc7_send_file(sess, uin, filename, nullptr, nullptr);
if (!dcc7) {
@@ -997,7 +1017,8 @@ HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles
debugLogA("SendFile(): Sending file \"%s\" to %d in %s mode.", filename, uin, (dcc->fd != -1) ? "active" : "passive");
// Add dcc to watches if not passive
- if (dcc->fd != -1) list_add(&watches, dcc, 0);
+ if (dcc->fd != -1)
+ list_add(&watches, dcc, 0);
// Store handle
dcc->contact = (void*)hContact;
@@ -1013,4 +1034,3 @@ HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles
mir_free(filename);
return dcc;
}
-
diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp
index 48b578b1ec..b07ebcb25c 100644
--- a/protocols/Gadu-Gadu/src/gg.cpp
+++ b/protocols/Gadu-Gadu/src/gg.cpp
@@ -56,75 +56,73 @@ static unsigned long crc_table[256];
//
wchar_t* ws_strerror(int code)
{
- static wchar_t err_desc[160];
-
- // Not a windows error display WinSock
- if (code == 0)
- {
- wchar_t buff[128];
- int len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, WSAGetLastError(), 0, buff, _countof(buff), nullptr);
- if (len == 0)
- mir_snwprintf(err_desc, L"WinSock %u: Unknown error.", WSAGetLastError());
- else
- mir_snwprintf(err_desc, L"WinSock %d: %s", WSAGetLastError(), buff);
- return err_desc;
- }
-
- // Return normal error
- return _tcserror(code);
+ static wchar_t err_desc[160];
+
+ // Not a windows error display WinSock
+ if (code == 0)
+ {
+ wchar_t buff[128];
+ int len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, WSAGetLastError(), 0, buff, _countof(buff), nullptr);
+ if (len == 0)
+ mir_snwprintf(err_desc, L"WinSock %u: Unknown error.", WSAGetLastError());
+ else
+ mir_snwprintf(err_desc, L"WinSock %d: %s", WSAGetLastError(), buff);
+ return err_desc;
+ }
+
+ // Return normal error
+ return _tcserror(code);
}
char* as_strerror(int code)
{
- static char err_desc[160];
-
- // Not a windows error display WinSock
- if (code == 0)
- {
- char buff[128];
- int len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, WSAGetLastError(), 0, buff, _countof(buff), nullptr);
- if (len == 0)
- mir_snprintf(err_desc, "WinSock %u: Unknown error.", WSAGetLastError());
- else
- mir_snprintf(err_desc, "WinSock %d: %s", WSAGetLastError(), buff);
- return err_desc;
- }
-
- // Return normal error
- return strerror(code);
+ static char err_desc[160];
+
+ // Not a windows error display WinSock
+ if (code == 0)
+ {
+ char buff[128];
+ int len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, WSAGetLastError(), 0, buff, _countof(buff), nullptr);
+ if (len == 0)
+ mir_snprintf(err_desc, "WinSock %u: Unknown error.", WSAGetLastError());
+ else
+ mir_snprintf(err_desc, "WinSock %d: %s", WSAGetLastError(), buff);
+ return err_desc;
+ }
+
+ // Return normal error
+ return strerror(code);
}
//////////////////////////////////////////////////////////
// Build the crc table
void crc_gentable(void)
{
- unsigned long crc, poly;
- int i, j;
-
- poly = 0xEDB88320L;
- for (i = 0; i < 256; i++)
- {
- crc = i;
- for (j = 8; j > 0; j--)
- {
- if (crc & 1)
- crc = (crc >> 1) ^ poly;
- else
- crc >>= 1;
- }
- crc_table[i] = crc;
- }
+ unsigned long crc;
+ unsigned long poly = 0xEDB88320L;
+ for (int i = 0; i < 256; i++)
+ {
+ crc = i;
+ for (int j = 8; j > 0; j--)
+ {
+ if (crc & 1)
+ crc = (crc >> 1) ^ poly;
+ else
+ crc >>= 1;
+ }
+ crc_table[i] = crc;
+ }
}
//////////////////////////////////////////////////////////
// Calculate the crc value
unsigned long crc_get(char *mem)
{
- register unsigned long crc = 0xFFFFFFFF;
- while(mem && *mem)
- crc = ((crc>>8) & 0x00FFFFFF) ^ crc_table[(crc ^ *(mem++)) & 0xFF];
+ register unsigned long crc = 0xFFFFFFFF;
+ while (mem && *mem)
+ crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_table[(crc ^ *(mem++)) & 0xFF];
- return (crc ^ 0xFFFFFFFF);
+ return (crc ^ 0xFFFFFFFF);
}
//////////////////////////////////////////////////////////
@@ -133,21 +131,21 @@ unsigned long crc_get(char *mem)
// returns http error text
const wchar_t *http_error_string(int h)
{
- switch (h)
- {
- case 0:
- return (errno == ENOMEM) ? TranslateT("HTTP failed memory") : TranslateT("HTTP failed connecting");
- case GG_ERROR_RESOLVING:
- return TranslateT("HTTP failed resolving");
- case GG_ERROR_CONNECTING:
- return TranslateT("HTTP failed connecting");
- case GG_ERROR_READING:
- return TranslateT("HTTP failed reading");
- case GG_ERROR_WRITING:
- return TranslateT("HTTP failed writing");
- }
-
- return TranslateT("Unknown HTTP error");
+ switch (h)
+ {
+ case 0:
+ return (errno == ENOMEM) ? TranslateT("HTTP failed memory") : TranslateT("HTTP failed connecting");
+ case GG_ERROR_RESOLVING:
+ return TranslateT("HTTP failed resolving");
+ case GG_ERROR_CONNECTING:
+ return TranslateT("HTTP failed connecting");
+ case GG_ERROR_READING:
+ return TranslateT("HTTP failed reading");
+ case GG_ERROR_WRITING:
+ return TranslateT("HTTP failed writing");
+ }
+
+ return TranslateT("Unknown HTTP error");
}
//////////////////////////////////////////////////////////
@@ -155,7 +153,7 @@ const wchar_t *http_error_string(int h)
//
extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD)
{
- return &pluginInfo;
+ return &pluginInfo;
}
extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_PROTOCOL, MIID_LAST};
@@ -169,11 +167,11 @@ void GGPROTO::cleanuplastplugin(DWORD version)
setDword(GG_PLUGINVERSION, pluginInfo.version);
//1. clean files: %miranda_avatarcache%\GG\*.(null)
- if (version < PLUGIN_MAKE_VERSION(0, 11, 0, 2)){
+ if (version < PLUGIN_MAKE_VERSION(0, 11, 0, 2)) {
debugLogA("cleanuplastplugin() 1: version=%d Cleaning junk avatar files from < 0.11.0.2", version);
wchar_t avatarsPath[MAX_PATH];
- mir_snwprintf(avatarsPath, L"%s\\%s", VARSW( L"%miranda_avatarcache%"), m_tszUserName);
+ mir_snwprintf(avatarsPath, L"%s\\%s", VARSW(L"%miranda_avatarcache%"), m_tszUserName);
debugLogW(L"cleanuplastplugin() 1: miranda_avatarcache = %s", avatarsPath);
@@ -183,9 +181,9 @@ void GGPROTO::cleanuplastplugin(DWORD version)
HANDLE hFind = FindFirstFile(spec, &ffd);
if (hFind != INVALID_HANDLE_VALUE) {
do {
- wchar_t filePathT [2*MAX_PATH + 10];
+ wchar_t filePathT[2 * MAX_PATH + 10];
mir_snwprintf(filePathT, L"%s\\%s", avatarsPath, ffd.cFileName);
- if (!_waccess(filePathT, 0)){
+ if (!_waccess(filePathT, 0)) {
debugLogW(L"cleanuplastplugin() 1: remove file = %s", filePathT);
_wremove(filePathT);
}
@@ -200,13 +198,13 @@ void GGPROTO::cleanuplastplugin(DWORD version)
//
static int gg_modulesloaded(WPARAM, LPARAM)
{
- // Get SSL API
- mir_getSI(&sslApi);
+ // Get SSL API
+ mir_getSI(&sslApi);
- // File Association Manager support
- gg_links_init();
+ // File Association Manager support
+ gg_links_init();
- return 0;
+ return 0;
}
//////////////////////////////////////////////////////////
@@ -214,15 +212,15 @@ static int gg_modulesloaded(WPARAM, LPARAM)
//
static GGPROTO* gg_getprotoinstance(MCONTACT hContact)
{
- char* szProto = GetContactProto(hContact);
- if (szProto == nullptr)
- return nullptr;
+ char* szProto = GetContactProto(hContact);
+ if (szProto == nullptr)
+ return nullptr;
- for (int i=0; i < g_Instances.getCount(); i++)
- if (mir_strcmp(szProto, g_Instances[i]->m_szModuleName) == 0)
- return g_Instances[i];
+ for (int i = 0; i < g_Instances.getCount(); i++)
+ if (mir_strcmp(szProto, g_Instances[i]->m_szModuleName) == 0)
+ return g_Instances[i];
- return nullptr;
+ return nullptr;
}
//////////////////////////////////////////////////////////
@@ -230,15 +228,15 @@ static GGPROTO* gg_getprotoinstance(MCONTACT hContact)
//
static int gg_prebuildcontactmenu(WPARAM hContact, LPARAM)
{
- GGPROTO* gg = gg_getprotoinstance(hContact);
- if (gg == nullptr)
- return 0;
+ GGPROTO* gg = gg_getprotoinstance(hContact);
+ if (gg == nullptr)
+ return 0;
- if (gg->getDword(hContact, GG_KEY_UIN, 0) == gg->getByte(GG_KEY_UIN, 0) || gg->isChatRoom(hContact) || db_get_b(hContact, "CList", "NotOnList", 0))
- Menu_ShowItem(gg->hBlockMenuItem, false);
+ if (gg->getDword(hContact, GG_KEY_UIN, 0) == gg->getByte(GG_KEY_UIN, 0) || gg->isChatRoom(hContact) || db_get_b(hContact, "CList", "NotOnList", 0))
+ Menu_ShowItem(gg->hBlockMenuItem, false);
else
Menu_ModifyItem(gg->hBlockMenuItem, gg->getByte(hContact, GG_KEY_BLOCK, 0) ? LPGENW("&Unblock") : LPGENW("&Block"));
- return 0;
+ return 0;
}
//////////////////////////////////////////////////////////
@@ -246,9 +244,9 @@ static int gg_prebuildcontactmenu(WPARAM hContact, LPARAM)
//
INT_PTR GGPROTO::blockuser(WPARAM hContact, LPARAM)
{
- setByte(hContact, GG_KEY_BLOCK, !getByte(hContact, GG_KEY_BLOCK, 0));
- notifyuser(hContact, 1);
- return 0;
+ setByte(hContact, GG_KEY_BLOCK, !getByte(hContact, GG_KEY_BLOCK, 0));
+ notifyuser(hContact, 1);
+ return 0;
}
#define GGS_BLOCKUSER "/BlockUser"
@@ -258,15 +256,15 @@ INT_PTR GGPROTO::blockuser(WPARAM hContact, LPARAM)
//
void GGPROTO::block_init()
{
- CMenuItem mi;
- SET_UID(mi, 0xc6169b8f, 0x53ab, 0x4242, 0xbe, 0x90, 0xe2, 0x4a, 0xa5, 0x73, 0x88, 0x32);
- mi.position = -500050000;
- mi.hIcolibItem = iconList[8].hIcolib;
- mi.name.a = LPGEN("&Block");
+ CMenuItem mi;
+ SET_UID(mi, 0xc6169b8f, 0x53ab, 0x4242, 0xbe, 0x90, 0xe2, 0x4a, 0xa5, 0x73, 0x88, 0x32);
+ mi.position = -500050000;
+ mi.hIcolibItem = iconList[8].hIcolib;
+ mi.name.a = LPGEN("&Block");
mi.pszService = GGS_BLOCKUSER;
hBlockMenuItem = Menu_AddContactMenuItem(&mi, m_szModuleName);
- ::HookEvent(ME_CLIST_PREBUILDCONTACTMENU, gg_prebuildcontactmenu);
+ ::HookEvent(ME_CLIST_PREBUILDCONTACTMENU, gg_prebuildcontactmenu);
}
//////////////////////////////////////////////////////////
@@ -274,7 +272,7 @@ void GGPROTO::block_init()
//
void GGPROTO::block_uninit()
{
- Menu_RemoveItem(hBlockMenuItem);
+ Menu_RemoveItem(hBlockMenuItem);
}
//////////////////////////////////////////////////////////
@@ -283,24 +281,24 @@ void GGPROTO::block_uninit()
void GGPROTO::menus_init()
{
HGENMENU hRoot = Menu_GetProtocolRoot(this);
-
+
CMenuItem mi;
mi.root = hRoot;
- mi.flags = CMIF_UNICODE;
+ mi.flags = CMIF_UNICODE;
- mi.name.w = LPGENW("Conference");
- mi.position = 200001;
- mi.hIcolibItem = iconList[14].hIcolib;
+ mi.name.w = LPGENW("Conference");
+ mi.position = 200001;
+ mi.hIcolibItem = iconList[14].hIcolib;
HGENMENU hGCRoot = Menu_AddProtoMenuItem(&mi, m_szModuleName);
- mi.name.w = LPGENW("Contact list");
- mi.position = 200002;
- mi.hIcolibItem = iconList[7].hIcolib;
- HGENMENU hCLRoot = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+ mi.name.w = LPGENW("Contact list");
+ mi.position = 200002;
+ mi.hIcolibItem = iconList[7].hIcolib;
+ HGENMENU hCLRoot = Menu_AddProtoMenuItem(&mi, m_szModuleName);
- gc_menus_init(hGCRoot);
- import_init(hCLRoot);
- sessions_menus_init(hRoot);
+ gc_menus_init(hGCRoot);
+ import_init(hCLRoot);
+ sessions_menus_init(hRoot);
}
//////////////////////////////////////////////////////////
@@ -308,9 +306,9 @@ void GGPROTO::menus_init()
//
static GGPROTO *gg_proto_init(const char* pszProtoName, const wchar_t* tszUserName)
{
- GGPROTO *gg = new GGPROTO(pszProtoName, tszUserName);
- g_Instances.insert(gg);
- return gg;
+ GGPROTO *gg = new GGPROTO(pszProtoName, tszUserName);
+ g_Instances.insert(gg);
+ return gg;
}
//////////////////////////////////////////////////////////
@@ -318,10 +316,10 @@ static GGPROTO *gg_proto_init(const char* pszProtoName, const wchar_t* tszUserNa
//
static int gg_proto_uninit(PROTO_INTERFACE *proto)
{
- GGPROTO *gg = (GGPROTO *)proto;
- g_Instances.remove(gg);
- delete gg;
- return 0;
+ GGPROTO *gg = (GGPROTO *)proto;
+ g_Instances.remove(gg);
+ delete gg;
+ return 0;
}
//////////////////////////////////////////////////////////
@@ -329,23 +327,23 @@ static int gg_proto_uninit(PROTO_INTERFACE *proto)
//
extern "C" int __declspec(dllexport) Load(void)
{
- mir_getLP(&pluginInfo);
- pcli = Clist_GetInterface();
+ mir_getLP(&pluginInfo);
+ pcli = Clist_GetInterface();
- // Hook system events
- hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, gg_modulesloaded);
+ // Hook system events
+ hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, gg_modulesloaded);
- // Prepare protocol name
+ // Prepare protocol name
PROTOCOLDESCRIPTOR pd = { 0 };
pd.cbSize = sizeof(pd);
- pd.szName = GGDEF_PROTO;
- pd.fnInit = (pfnInitProto)gg_proto_init;
- pd.fnUninit = (pfnUninitProto)gg_proto_uninit;
- pd.type = PROTOTYPE_PROTOCOL;
- Proto_RegisterModule( &pd);
+ pd.szName = GGDEF_PROTO;
+ pd.fnInit = (pfnInitProto)gg_proto_init;
+ pd.fnUninit = (pfnUninitProto)gg_proto_uninit;
+ pd.type = PROTOTYPE_PROTOCOL;
+ Proto_RegisterModule(&pd);
gg_links_instancemenu_init();
- return 0;
+ return 0;
}
//////////////////////////////////////////////////////////
@@ -353,17 +351,18 @@ extern "C" int __declspec(dllexport) Load(void)
//
extern "C" int __declspec(dllexport) Unload()
{
- WSACleanup();
- return 0;
+ WSACleanup();
+ return 0;
}
//////////////////////////////////////////////////////////
// DEBUGING FUNCTIONS
struct
{
- int type;
- char *text;
+ int type;
+ char *text;
}
+
static const ggdebug_eventype2string[] =
{
{GG_EVENT_NONE, "GG_EVENT_NONE"},
@@ -413,11 +412,11 @@ static const ggdebug_eventype2string[] =
const char *ggdebug_eventtype(gg_event *e)
{
- int i;
- for(i = 0; ggdebug_eventype2string[i].type != -1; i++)
- if (ggdebug_eventype2string[i].type == e->type)
- return ggdebug_eventype2string[i].text;
- return ggdebug_eventype2string[i].text;
+ int i;
+ for (i = 0; ggdebug_eventype2string[i].type != -1; i++)
+ if (ggdebug_eventype2string[i].type == e->type)
+ return ggdebug_eventype2string[i].text;
+ return ggdebug_eventype2string[i].text;
}
//////////////////////////////////////////////////////////
@@ -427,22 +426,24 @@ const char *ggdebug_eventtype(gg_event *e)
#ifdef DEBUGMODE
void gg_debughandler(int level, const char *format, va_list ap)
{
- char szText[1024], *szFormat = _strdup(format);
- // Kill end line
- char *nl = strrchr(szFormat, '\n');
- if (nl) *nl = 0;
-
- strncpy(szText + PREFIXLEN, "[libgadu] \0", sizeof(szText) - PREFIXLEN);
-
- char prefix[6];
- mir_snprintf(prefix, "%lu", GetCurrentThreadId());
- size_t prefixLen = mir_strlen(prefix);
- if (prefixLen < PREFIXLEN) memset(prefix + prefixLen, ' ', PREFIXLEN - prefixLen);
- memcpy(szText, prefix, PREFIXLEN);
-
- mir_vsnprintf(szText + mir_strlen(szText), sizeof(szText) - mir_strlen(szText), szFormat, ap);
- Netlib_Log(nullptr, szText);
- free(szFormat);
+ char szText[1024], *szFormat = _strdup(format);
+ // Kill end line
+ char *nl = strrchr(szFormat, '\n');
+ if (nl)
+ *nl = 0;
+
+ strncpy(szText + PREFIXLEN, "[libgadu] \0", sizeof(szText) - PREFIXLEN);
+
+ char prefix[6];
+ mir_snprintf(prefix, "%lu", GetCurrentThreadId());
+ size_t prefixLen = mir_strlen(prefix);
+ if (prefixLen < PREFIXLEN)
+ memset(prefix + prefixLen, ' ', PREFIXLEN - prefixLen);
+ memcpy(szText, prefix, PREFIXLEN);
+
+ mir_vsnprintf(szText + mir_strlen(szText), sizeof(szText) - mir_strlen(szText), szFormat, ap);
+ Netlib_Log(nullptr, szText);
+ free(szFormat);
}
#endif
@@ -451,11 +452,11 @@ void gg_debughandler(int level, const char *format, va_list ap)
//
BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD, LPVOID)
{
- crc_gentable();
- hInstance = hInst;
+ crc_gentable();
+ hInstance = hInst;
#ifdef DEBUGMODE
- gg_debug_level = GG_DEBUG_FUNCTION;
- gg_debug_handler = gg_debughandler;
+ gg_debug_level = GG_DEBUG_FUNCTION;
+ gg_debug_handler = gg_debughandler;
#endif
- return TRUE;
+ return TRUE;
}
diff --git a/protocols/Gadu-Gadu/src/gg_proto.cpp b/protocols/Gadu-Gadu/src/gg_proto.cpp
index 68834738e3..17b2dfd80d 100644
--- a/protocols/Gadu-Gadu/src/gg_proto.cpp
+++ b/protocols/Gadu-Gadu/src/gg_proto.cpp
@@ -179,9 +179,9 @@ int GGPROTO::GetInfo(MCONTACT hContact, int)
// Custom contact info
if (hContact) {
if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH))) {
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("GetInfo(): ForkThread 6 GGPROTO::cmdgetinfothread");
- #endif
+#endif
ForkThread(&GGPROTO::cmdgetinfothread, (void*)hContact);
return 1;
}
@@ -195,9 +195,9 @@ int GGPROTO::GetInfo(MCONTACT hContact, int)
gg_EnterCriticalSection(&sess_mutex, "GetInfo", 48, "sess_mutex", 1);
if (!gg_pubdir50(sess, req)) {
gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 48, 1, "sess_mutex", 1);
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("GetInfo(): ForkThread 7 GGPROTO::cmdgetinfothread");
- #endif
+#endif
ForkThread(&GGPROTO::cmdgetinfothread, (void*)hContact);
return 1;
}
@@ -207,9 +207,9 @@ int GGPROTO::GetInfo(MCONTACT hContact, int)
// Own contact info
else {
if (!(req = gg_pubdir50_new(GG_PUBDIR50_READ))) {
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("GetInfo(): ForkThread 8 GGPROTO::cmdgetinfothread");
- #endif
+#endif
ForkThread(&GGPROTO::cmdgetinfothread, (void*)hContact);
return 1;
}
@@ -222,9 +222,9 @@ int GGPROTO::GetInfo(MCONTACT hContact, int)
gg_EnterCriticalSection(&sess_mutex, "GetInfo", 49, "sess_mutex", 1);
if (!gg_pubdir50(sess, req)) {
gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 49, 1, "sess_mutex", 1);
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("GetInfo(): ForkThread 9 GGPROTO::cmdgetinfothread");
- #endif
+#endif
ForkThread(&GGPROTO::cmdgetinfothread, (void*)hContact);
gg_pubdir50_free(req);
return 1;
@@ -258,9 +258,9 @@ HANDLE GGPROTO::SearchBasic(const wchar_t *id)
gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);
if (!req) {
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("SearchBasic(): ForkThread 10 GGPROTO::searchthread");
- #endif
+#endif
ForkThread(&GGPROTO::searchthread, nullptr);
return (HANDLE)1;
}
@@ -272,9 +272,9 @@ HANDLE GGPROTO::SearchBasic(const wchar_t *id)
gg_EnterCriticalSection(&sess_mutex, "SearchBasic", 50, "sess_mutex", 1);
if (!gg_pubdir50(sess, req)) {
gg_LeaveCriticalSection(&sess_mutex, "SearchBasic", 50, 1, "sess_mutex", 1);
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("SearchBasic(): ForkThread 11 GGPROTO::searchthread");
- #endif
+#endif
ForkThread(&GGPROTO::searchthread, nullptr);
return (HANDLE)1;
}
@@ -299,9 +299,9 @@ HANDLE GGPROTO::SearchByName(const wchar_t *nick, const wchar_t *firstName, cons
gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);
if (req == nullptr) {
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("SearchByName(): ForkThread 12 GGPROTO::searchthread");
- #endif
+#endif
ForkThread(&GGPROTO::searchthread, nullptr);
return (HANDLE)1;
}
@@ -340,9 +340,9 @@ HANDLE GGPROTO::SearchByName(const wchar_t *nick, const wchar_t *firstName, cons
gg_EnterCriticalSection(&sess_mutex, "SearchByName", 51, "sess_mutex", 1);
if (!gg_pubdir50(sess, req)) {
gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 1, "sess_mutex", 1);
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("SearchByName(): ForkThread 13 GGPROTO::searchthread");
- #endif
+#endif
ForkThread(&GGPROTO::searchthread, nullptr);
}
else
@@ -366,9 +366,9 @@ HWND GGPROTO::SearchAdvanced(HWND hwndDlg)
gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);
if (!req) {
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("SearchAdvanced(): ForkThread 14 GGPROTO::searchthread");
- #endif
+#endif
ForkThread(&GGPROTO::searchthread, nullptr);
return (HWND)1;
}
@@ -476,9 +476,9 @@ HWND GGPROTO::SearchAdvanced(HWND hwndDlg)
gg_EnterCriticalSection(&sess_mutex, "SearchAdvanced", 52, "sess_mutex", 1);
if (!gg_pubdir50(sess, req)) {
gg_LeaveCriticalSection(&sess_mutex, "SearchAdvanced", 52, 1, "sess_mutex", 1);
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("SearchAdvanced(): ForkThread 15 GGPROTO::searchthread");
- #endif
+#endif
ForkThread(&GGPROTO::searchthread, nullptr);
return (HWND)1;
}
@@ -547,9 +547,9 @@ int GGPROTO::SendMsg(MCONTACT hContact, int, const char *msg)
if (ack) {
ack->seq = seq;
ack->hContact = hContact;
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("SendMsg(): ForkThread 16 GGPROTO::sendackthread");
- #endif
+#endif
ForkThread(&GGPROTO::sendackthread, ack);
}
}
@@ -664,9 +664,9 @@ int GGPROTO::SetAwayMsg(int iStatus, const wchar_t *newMsg)
if (*msgPtr)
mir_free(*msgPtr);
*msgPtr = newMsg && *newMsg ? mir_wstrdup(newMsg) : nullptr;
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("SetAwayMsg(): Message changed.");
- #endif
+#endif
}
gg_LeaveCriticalSection(&modemsg_mutex, "SetAwayMsg", 55, 3, "modemsg_mutex", 1);
diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h
index 7c5b08cfde..fc6c5de185 100644
--- a/protocols/Gadu-Gadu/src/gg_proto.h
+++ b/protocols/Gadu-Gadu/src/gg_proto.h
@@ -24,41 +24,41 @@
struct GGPROTO : public PROTO<GGPROTO>
{
- GGPROTO( const char*, const wchar_t* );
- ~GGPROTO();
+ GGPROTO(const char*, const wchar_t*);
+ ~GGPROTO();
//====================================================================================
// PROTO_INTERFACE
//====================================================================================
- virtual MCONTACT __cdecl AddToList( int flags, PROTOSEARCHRESULT* psr );
-
- virtual HANDLE __cdecl FileAllow(MCONTACT hContact, HANDLE hTransfer, const wchar_t* szPath );
- virtual int __cdecl FileCancel(MCONTACT hContact, HANDLE hTransfer );
- virtual int __cdecl FileDeny(MCONTACT hContact, HANDLE hTransfer, const wchar_t* szReason );
+ virtual MCONTACT __cdecl AddToList(int flags, PROTOSEARCHRESULT* psr);
- virtual DWORD_PTR __cdecl GetCaps( int type, MCONTACT hContact = NULL );
- virtual int __cdecl GetInfo(MCONTACT hContact, int infoType );
+ virtual HANDLE __cdecl FileAllow(MCONTACT hContact, HANDLE hTransfer, const wchar_t* szPath);
+ virtual int __cdecl FileCancel(MCONTACT hContact, HANDLE hTransfer);
+ virtual int __cdecl FileDeny(MCONTACT hContact, HANDLE hTransfer, const wchar_t* szReason);
- virtual HANDLE __cdecl SearchBasic( const wchar_t* id );
- virtual HANDLE __cdecl SearchByName( const wchar_t* nick, const wchar_t* firstName, const wchar_t* lastName );
- virtual HWND __cdecl SearchAdvanced( HWND owner );
- virtual HWND __cdecl CreateExtendedSearchUI( HWND owner );
+ virtual DWORD_PTR __cdecl GetCaps(int type, MCONTACT hContact = NULL);
+ virtual int __cdecl GetInfo(MCONTACT hContact, int infoType);
- virtual int __cdecl RecvFile(MCONTACT hContact, PROTORECVFILET* );
+ virtual HANDLE __cdecl SearchBasic(const wchar_t* id);
+ virtual HANDLE __cdecl SearchByName(const wchar_t* nick, const wchar_t* firstName, const wchar_t* lastName);
+ virtual HWND __cdecl SearchAdvanced(HWND owner);
+ virtual HWND __cdecl CreateExtendedSearchUI(HWND owner);
- virtual HANDLE __cdecl SendFile(MCONTACT hContact, const wchar_t* szDescription, wchar_t** ppszFiles );
- virtual int __cdecl SendMsg(MCONTACT hContact, int flags, const char* msg );
+ virtual int __cdecl RecvFile(MCONTACT hContact, PROTORECVFILET*);
- virtual int __cdecl SetApparentMode(MCONTACT hContact, int mode );
- virtual int __cdecl SetStatus( int iNewStatus );
+ virtual HANDLE __cdecl SendFile(MCONTACT hContact, const wchar_t* szDescription, wchar_t** ppszFiles);
+ virtual int __cdecl SendMsg(MCONTACT hContact, int flags, const char* msg);
- virtual HANDLE __cdecl GetAwayMsg(MCONTACT hContact );
- virtual int __cdecl SetAwayMsg( int m_iStatus, const wchar_t* msg );
+ virtual int __cdecl SetApparentMode(MCONTACT hContact, int mode);
+ virtual int __cdecl SetStatus(int iNewStatus);
- virtual int __cdecl UserIsTyping(MCONTACT hContact, int type );
+ virtual HANDLE __cdecl GetAwayMsg(MCONTACT hContact);
+ virtual int __cdecl SetAwayMsg(int m_iStatus, const wchar_t* msg);
- virtual int __cdecl OnEvent( PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam );
+ virtual int __cdecl UserIsTyping(MCONTACT hContact, int type);
+
+ virtual int __cdecl OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam);
//////////////////////////////////////////////////////////////////////////////////////
// Services
@@ -242,7 +242,7 @@ struct GGPROTO : public PROTO<GGPROTO>
wchar_t *invisible;
wchar_t *offline;
} modemsg;
-
+
HGENMENU hMainMenu[7];
HGENMENU hBlockMenuItem, hImageMenuItem, hInstanceMenuItem;
HANDLE hPrebuildMenuHook;
@@ -270,14 +270,15 @@ inline void GGPROTO::gg_EnterCriticalSection(CRITICAL_SECTION* mutex, char*, int
#ifdef DEBUGMODE
int logAfter = 0;
extendedLogging = 1;
- if(logging == 1 && mutex->LockCount != -1) {
+ if (logging == 1 && mutex->LockCount != -1) {
logAfter = 1;
debugLogA("%s(): %i before EnterCriticalSection %s LockCount=%ld RecursionCount=%ld OwningThread=%ld", callingFunction, sectionNumber, mutexName, mutex->LockCount, mutex->RecursionCount, mutex->OwningThread);
}
#endif
EnterCriticalSection(mutex);
#ifdef DEBUGMODE
- if(logging == 1 && logAfter == 1) debugLogA("%s(): %i after EnterCriticalSection %s LockCount=%ld RecursionCount=%ld OwningThread=%ld", callingFunction, sectionNumber, mutexName, mutex->LockCount, mutex->RecursionCount, mutex->OwningThread);
+ if (logging == 1 && logAfter == 1)
+ debugLogA("%s(): %i after EnterCriticalSection %s LockCount=%ld RecursionCount=%ld OwningThread=%ld", callingFunction, sectionNumber, mutexName, mutex->LockCount, mutex->RecursionCount, mutex->OwningThread);
extendedLogging = 0;
#endif
@@ -290,19 +291,21 @@ inline void GGPROTO::gg_LeaveCriticalSection(CRITICAL_SECTION* mutex, char *, in
#endif
{
#ifdef DEBUGMODE
- if(logging == 1 && extendedLogging == 1) debugLogA("%s(): %i.%i LeaveCriticalSection %s", callingFunction, sectionNumber, returnNumber, mutexName);
+ if (logging == 1 && extendedLogging == 1)
+ debugLogA("%s(): %i.%i LeaveCriticalSection %s", callingFunction, sectionNumber, returnNumber, mutexName);
#endif
LeaveCriticalSection(mutex);
}
#ifdef DEBUGMODE
-inline void GGPROTO::gg_sleep(DWORD miliseconds, BOOL alterable, char* callingFunction, int sleepNumber, int logging){
+inline void GGPROTO::gg_sleep(DWORD miliseconds, BOOL alterable, char* callingFunction, int sleepNumber, int logging) {
#else
inline void GGPROTO::gg_sleep(DWORD miliseconds, BOOL alterable, char* callingFunction, int, int) {
#endif
SleepEx(miliseconds, alterable);
#ifdef DEBUGMODE
- if(logging == 1 && extendedLogging == 1) debugLogA("%s(): %i after SleepEx(%ld,%u)", callingFunction, sleepNumber, miliseconds, alterable);
+ if (logging == 1 && extendedLogging == 1)
+ debugLogA("%s(): %i after SleepEx(%ld,%u)", callingFunction, sleepNumber, miliseconds, alterable);
#endif
}
diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp
index e88190e763..47d97734bf 100644
--- a/protocols/Gadu-Gadu/src/groupchat.cpp
+++ b/protocols/Gadu-Gadu/src/groupchat.cpp
@@ -44,6 +44,7 @@ int GGPROTO::gc_init()
// create & hook event
mir_snprintf(service, GG_GC_GETCHAT, m_szModuleName);
debugLogA("gc_init(): Registered with groupchat plugin.");
+
return 1;
}
@@ -81,12 +82,13 @@ void GGPROTO::gc_menus_init(HGENMENU hRoot)
int GGPROTO::gc_destroy()
{
list_t l;
- for(l = chats; l; l = l->next)
+ for (l = chats; l; l = l->next)
{
GGGC *chat = (GGGC *)l->data;
free(chat->recipients);
}
list_destroy(chats, 1); chats = nullptr;
+
return 1;
}
@@ -95,7 +97,7 @@ GGGC* GGPROTO::gc_lookup(const wchar_t *id)
GGGC *chat;
list_t l;
- for(l = chats; l; l = l->next)
+ for (l = chats; l; l = l->next)
{
chat = (GGGC *)l->data;
if (chat && !mir_wstrcmp(chat->id, id))
@@ -152,17 +154,18 @@ int GGPROTO::gc_event(WPARAM, LPARAM lParam)
gce.ptszUID = id;
gce.ptszText = gch->ptszText;
wchar_t* nickT;
- if (!getWString(GG_KEY_NICK, &dbv)){
+ if (!getWString(GG_KEY_NICK, &dbv)) {
nickT = mir_wstrdup(dbv.ptszVal);
db_free(&dbv);
}
- else nickT = mir_wstrdup(TranslateT("Me"));
+ else
+ nickT = mir_wstrdup(TranslateT("Me"));
gce.ptszNick = nickT;
// Get rid of CRLF at back
int lc = (int)mir_wstrlen(gch->ptszText) - 1;
- while(lc >= 0 && (gch->ptszText[lc] == '\n' || gch->ptszText[lc] == '\r'))
- gch->ptszText[lc --] = 0;
+ while (lc >= 0 && (gch->ptszText[lc] == '\n' || gch->ptszText[lc] == '\r'))
+ gch->ptszText[lc--] = 0;
gce.time = time(nullptr);
gce.bIsMe = 1;
@@ -170,7 +173,7 @@ int GGPROTO::gc_event(WPARAM, LPARAM lParam)
debugLogW(L"gc_event(): Sending conference message to room %s, \"%s\".", gch->ptszID, gch->ptszText);
Chat_Event(&gce);
mir_free(nickT);
-
+
T2Utf pszText_utf8(gch->ptszText);
gg_EnterCriticalSection(&sess_mutex, "gc_event", 57, "sess_mutex", 1);
gg_send_message_confer(sess, GG_CLASS_CHAT, chat->recipients_count, chat->recipients, pszText_utf8);
@@ -212,7 +215,7 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou
if (!recipients) return nullptr;
// Look for existing chat
- for(l = chats; l; l = l->next)
+ for (l = chats; l; l = l->next)
{
chat = (GGGC *)l->data;
if (!chat) continue;
@@ -230,8 +233,8 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou
}
}
if (sok)
- for(i = 0; i < chat->recipients_count; i++)
- for(j = 0; j < recipients_count; j++)
+ for (i = 0; i < chat->recipients_count; i++)
+ for (j = 0; j < recipients_count; j++)
if (recipients[j] == chat->recipients[i]) found++;
// Found all recipients
if (found == recipients_count)
@@ -247,7 +250,7 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou
// Make new uin list to chat mapping
chat = (GGGC *)malloc(sizeof(GGGC));
- UIN2IDT(gc_id ++, chat->id);
+ UIN2IDT(gc_id++, chat->id);
chat->ignore = FALSE;
// Check groupchat policy (new) / only for incoming
@@ -255,20 +258,20 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou
{
int unknown = (getcontact(sender, 0, 0, nullptr) == NULL),
unknownSender = unknown;
- for(int i = 0; i < recipients_count; i++)
+ for (int i = 0; i < recipients_count; i++)
if (!getcontact(recipients[i], 0, 0, nullptr))
- unknown ++;
+ unknown++;
if ((getWord(GG_KEY_GC_POLICY_DEFAULT, GG_KEYDEF_GC_POLICY_DEFAULT) == 2) ||
- (getWord(GG_KEY_GC_POLICY_TOTAL, GG_KEYDEF_GC_POLICY_TOTAL) == 2 &&
- recipients_count >= getWord(GG_KEY_GC_COUNT_TOTAL, GG_KEYDEF_GC_COUNT_TOTAL)) ||
- (getWord(GG_KEY_GC_POLICY_UNKNOWN, GG_KEYDEF_GC_POLICY_UNKNOWN) == 2 &&
- unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN)))
+ (getWord(GG_KEY_GC_POLICY_TOTAL, GG_KEYDEF_GC_POLICY_TOTAL) == 2 &&
+ recipients_count >= getWord(GG_KEY_GC_COUNT_TOTAL, GG_KEYDEF_GC_COUNT_TOTAL)) ||
+ (getWord(GG_KEY_GC_POLICY_UNKNOWN, GG_KEYDEF_GC_POLICY_UNKNOWN) == 2 &&
+ unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN)))
chat->ignore = TRUE;
if (!chat->ignore && ((getWord(GG_KEY_GC_POLICY_DEFAULT, GG_KEYDEF_GC_POLICY_DEFAULT) == 1) ||
- (getWord(GG_KEY_GC_POLICY_TOTAL, GG_KEYDEF_GC_POLICY_TOTAL) == 1 &&
- recipients_count >= getWord(GG_KEY_GC_COUNT_TOTAL, GG_KEYDEF_GC_COUNT_TOTAL)) ||
- (getWord(GG_KEY_GC_POLICY_UNKNOWN, GG_KEYDEF_GC_POLICY_UNKNOWN) == 1 &&
- unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN))))
+ (getWord(GG_KEY_GC_POLICY_TOTAL, GG_KEYDEF_GC_POLICY_TOTAL) == 1 &&
+ recipients_count >= getWord(GG_KEY_GC_COUNT_TOTAL, GG_KEYDEF_GC_COUNT_TOTAL)) ||
+ (getWord(GG_KEY_GC_POLICY_UNKNOWN, GG_KEYDEF_GC_POLICY_UNKNOWN) == 1 &&
+ unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN))))
{
wchar_t *senderName = unknownSender ?
TranslateT("Unknown") : pcli->pfnGetContactDisplayName(getcontact(sender, 0, 0, nullptr), 0);
@@ -283,7 +286,7 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou
chat->recipients_count = recipients_count + 1;
chat->recipients = (uin_t *)calloc(chat->recipients_count, sizeof(uin_t));
int i = 0;
- for(; i < recipients_count; i++)
+ for (; i < recipients_count; i++)
chat->recipients[i] = recipients[i];
if (sender) chat->recipients[i] = sender;
debugLogW(L"gc_getchat(): Ignoring new chat %s, count %d.", chat->id, chat->recipients_count);
@@ -298,7 +301,7 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou
if (sender)
{
senderName = pcli->pfnGetContactDisplayName(getcontact(sender, 1, 0, nullptr), 0);
- mir_snwprintf(status, TranslateT("%s initiated the conference.") , senderName);
+ mir_snwprintf(status, TranslateT("%s initiated the conference."), senderName);
}
else
{
@@ -333,19 +336,20 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou
mir_free(nickT);
debugLogW(L"gc_getchat(): Myself %s: %s (%s) to the list...", gce.ptszUID, gce.ptszNick, gce.ptszStatus);
}
- else debugLogA("gc_getchat(): Myself adding failed with uin %d !!!", uin);
+ else
+ debugLogA("gc_getchat(): Myself adding failed with uin %d !!!", uin);
// Copy recipient list
chat->recipients_count = recipients_count + (sender ? 1 : 0);
chat->recipients = (uin_t *)calloc(chat->recipients_count, sizeof(uin_t));
int i;
- for(i = 0; i < recipients_count; i++)
+ for (i = 0; i < recipients_count; i++)
chat->recipients[i] = recipients[i];
if (sender)
chat->recipients[i] = sender;
// Add contacts
- for(i = 0; i < chat->recipients_count; i++) {
+ for (i = 0; i < chat->recipients_count; i++) {
MCONTACT hContact = getcontact(chat->recipients[i], 1, 0, nullptr);
UIN2IDT(chat->recipients[i], id);
if (hContact)
@@ -401,142 +405,142 @@ static int gg_gc_countcheckmarks(HWND hwndList)
static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch(message)
+ switch (message)
{
- case WM_INITDIALOG:
- {
- CLCINFOITEM cii = {0};
- HANDLE hMetaContactsEvent;
+ case WM_INITDIALOG:
+ {
+ CLCINFOITEM cii = { 0 };
+ HANDLE hMetaContactsEvent;
- SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
- TranslateDialogDefault(hwndDlg);
- Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_CONFERENCE));
- gg_gc_resetclistopts(GetDlgItem(hwndDlg, IDC_CLIST));
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
+ TranslateDialogDefault(hwndDlg);
+ Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_CONFERENCE));
+ gg_gc_resetclistopts(GetDlgItem(hwndDlg, IDC_CLIST));
- // Hook MetaContacts event (if available)
- hMetaContactsEvent = HookEventMessage(ME_MC_SUBCONTACTSCHANGED, hwndDlg, HM_SUBCONTACTSCHANGED);
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hMetaContactsEvent);
- }
- return TRUE;
+ // Hook MetaContacts event (if available)
+ hMetaContactsEvent = HookEventMessage(ME_MC_SUBCONTACTSCHANGED, hwndDlg, HM_SUBCONTACTSCHANGED);
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hMetaContactsEvent);
+ }
+ return TRUE;
- case WM_COMMAND:
+ case WM_COMMAND:
+ {
+ switch (LOWORD(wParam))
+ {
+ case IDOK:
{
- switch (LOWORD(wParam))
+ HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST);
+ GGPROTO* gg = (GGPROTO*)GetWindowLongPtr(hwndDlg, DWLP_USER);
+ int count = 0, i = 0;
+ // Check if connected
+ if (!gg->isonline())
{
- case IDOK:
- {
- HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST);
- GGPROTO* gg = (GGPROTO*)GetWindowLongPtr(hwndDlg, DWLP_USER);
- int count = 0, i = 0;
- // Check if connected
- if (!gg->isonline())
- {
- MessageBox(nullptr,
- TranslateT("You have to be connected to open new conference."),
- gg->m_tszUserName, MB_OK | MB_ICONSTOP);
- }
- else if (hwndList && (count = gg_gc_countcheckmarks(hwndList)) >= 2)
- {
- // Create new participiants table
- wchar_t* chat;
- uin_t* participants = (uin_t*)calloc(count, sizeof(uin_t));
- gg->debugLogA("gg_gc_openconfdlg(): WM_COMMAND IDOK Opening new conference for %d contacts.", count);
- for (MCONTACT hContact = db_find_first(); hContact && i < count; hContact = db_find_next(hContact)) {
- HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0);
- if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
- MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support
- participants[i++] = db_get_dw(hMetaContact ? hMetaContact : hContact, gg->m_szModuleName, GG_KEY_UIN, 0);
- }
- }
- if (count > i) i = count;
- chat = gg->gc_getchat(0, participants, count);
- if (chat)
- Chat_Control(gg->m_szModuleName, chat, WINDOW_VISIBLE);
-
- free(participants);
+ MessageBox(nullptr,
+ TranslateT("You have to be connected to open new conference."),
+ gg->m_tszUserName, MB_OK | MB_ICONSTOP);
+ }
+ else if (hwndList && (count = gg_gc_countcheckmarks(hwndList)) >= 2)
+ {
+ // Create new participiants table
+ wchar_t* chat;
+ uin_t* participants = (uin_t*)calloc(count, sizeof(uin_t));
+ gg->debugLogA("gg_gc_openconfdlg(): WM_COMMAND IDOK Opening new conference for %d contacts.", count);
+ for (MCONTACT hContact = db_find_first(); hContact && i < count; hContact = db_find_next(hContact)) {
+ HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0);
+ if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) {
+ MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support
+ participants[i++] = db_get_dw(hMetaContact ? hMetaContact : hContact, gg->m_szModuleName, GG_KEY_UIN, 0);
}
}
- // fall through
- case IDCANCEL:
- DestroyWindow(hwndDlg);
- break;
+ if (count > i) i = count;
+ chat = gg->gc_getchat(0, participants, count);
+ if (chat)
+ Chat_Control(gg->m_szModuleName, chat, WINDOW_VISIBLE);
+
+ free(participants);
}
+ }
+ // fall through
+ case IDCANCEL:
+ DestroyWindow(hwndDlg);
break;
}
+ break;
+ }
- case WM_NOTIFY:
+ case WM_NOTIFY:
+ {
+ switch (((NMHDR*)lParam)->idFrom)
+ {
+ case IDC_CLIST:
{
- switch(((NMHDR*)lParam)->idFrom)
+ switch (((NMHDR*)lParam)->code)
{
- case IDC_CLIST:
- {
- switch(((NMHDR*)lParam)->code)
- {
- case CLN_OPTIONSCHANGED:
- gg_gc_resetclistopts(GetDlgItem(hwndDlg, IDC_CLIST));
- break;
-
- case CLN_NEWCONTACT:
- case CLN_CONTACTMOVED:
- case CLN_LISTREBUILT:
- {
- char* szProto;
- uin_t uin;
- GGPROTO* gg = (GGPROTO*)GetWindowLongPtr(hwndDlg, DWLP_USER);
-
- if (!gg) break;
-
- // Delete non-gg contacts
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- MCONTACT hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0);
- if (hItem) {
- MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support
- if (hMetaContact) {
- szProto = gg->m_szModuleName;
- uin = (uin_t)gg->getDword(hMetaContact, GG_KEY_UIN, 0);
- }
- else {
- szProto = GetContactProto(hContact);
- uin = (uin_t)gg->getDword(hContact, GG_KEY_UIN, 0);
- }
-
- if (szProto == nullptr || mir_strcmp(szProto, gg->m_szModuleName) || !uin || uin == gg->getDword(GG_KEY_UIN, 0))
- SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_DELETEITEM, (WPARAM)hItem, 0);
- }
- }
+ case CLN_OPTIONSCHANGED:
+ gg_gc_resetclistopts(GetDlgItem(hwndDlg, IDC_CLIST));
+ break;
+
+ case CLN_NEWCONTACT:
+ case CLN_CONTACTMOVED:
+ case CLN_LISTREBUILT:
+ {
+ char* szProto;
+ uin_t uin;
+ GGPROTO* gg = (GGPROTO*)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
+ if (!gg) break;
+
+ // Delete non-gg contacts
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ MCONTACT hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0);
+ if (hItem) {
+ MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support
+ if (hMetaContact) {
+ szProto = gg->m_szModuleName;
+ uin = (uin_t)gg->getDword(hMetaContact, GG_KEY_UIN, 0);
+ }
+ else {
+ szProto = GetContactProto(hContact);
+ uin = (uin_t)gg->getDword(hContact, GG_KEY_UIN, 0);
}
- break;
- case CLN_CHECKCHANGED:
- EnableWindow(GetDlgItem(hwndDlg, IDOK), gg_gc_countcheckmarks(GetDlgItem(hwndDlg, IDC_CLIST)) >= 2);
- break;
+ if (szProto == nullptr || mir_strcmp(szProto, gg->m_szModuleName) || !uin || uin == gg->getDword(GG_KEY_UIN, 0))
+ SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_DELETEITEM, (WPARAM)hItem, 0);
}
- break;
}
}
break;
- }
- case HM_SUBCONTACTSCHANGED:
- {
- HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST);
- SendMessage(hwndList, CLM_AUTOREBUILD, 0, 0);
- EnableWindow(GetDlgItem(hwndDlg, IDOK), gg_gc_countcheckmarks(hwndList) >= 2);
+ case CLN_CHECKCHANGED:
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), gg_gc_countcheckmarks(GetDlgItem(hwndDlg, IDC_CLIST)) >= 2);
+ break;
+ }
break;
}
+ }
+ break;
+ }
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
+ case HM_SUBCONTACTSCHANGED:
+ {
+ HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST);
+ SendMessage(hwndList, CLM_AUTOREBUILD, 0, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), gg_gc_countcheckmarks(hwndList) >= 2);
+ break;
+ }
- case WM_DESTROY:
- {
- HANDLE hMetaContactsEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- if (hMetaContactsEvent)
- UnhookEvent(hMetaContactsEvent);
- Window_FreeIcon_IcoLib(hwndDlg);
- break;
- }
+ case WM_CLOSE:
+ DestroyWindow(hwndDlg);
+ break;
+
+ case WM_DESTROY:
+ {
+ HANDLE hMetaContactsEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ if (hMetaContactsEvent)
+ UnhookEvent(hMetaContactsEvent);
+ Window_FreeIcon_IcoLib(hwndDlg);
+ break;
+ }
}
return FALSE;
@@ -545,7 +549,7 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa
INT_PTR GGPROTO::gc_clearignored(WPARAM, LPARAM)
{
list_t l = chats; BOOL cleared = FALSE;
- while(l)
+ while (l)
{
GGGC *chat = (GGGC *)l->data;
l = l->next;
@@ -556,10 +560,10 @@ INT_PTR GGPROTO::gc_clearignored(WPARAM, LPARAM)
cleared = TRUE;
}
}
- MessageBox( nullptr,
+ MessageBox(nullptr,
cleared ?
- TranslateT("All ignored conferences are now unignored and the conference policy will act again.") :
- TranslateT("There are no ignored conferences."),
+ TranslateT("All ignored conferences are now unignored and the conference policy will act again.") :
+ TranslateT("There are no ignored conferences."),
m_tszUserName, MB_OK | MB_ICONINFORMATION
);
@@ -590,16 +594,16 @@ int GGPROTO::gc_changenick(MCONTACT hContact, wchar_t *ptszNick)
debugLogA("gc_changenick(): Nickname for uin %d changed. Lookup for chats having this nick", uin);
// Lookup for chats having this nick
- for(l = chats; l; l = l->next) {
+ for (l = chats; l; l = l->next) {
GGGC *chat = (GGGC *)l->data;
if (chat->recipients && chat->recipients_count)
- for(int i = 0; i < chat->recipients_count; i++)
+ for (int i = 0; i < chat->recipients_count; i++)
// Rename this window if it's exising in the chat
if (chat->recipients[i] == uin)
{
wchar_t id[32];
UIN2IDT(uin, id);
-
+
GCEVENT gce = { m_szModuleName, chat->id, GC_EVENT_NICK };
gce.ptszUID = id;
gce.ptszText = ptszNick;
diff --git a/protocols/Gadu-Gadu/src/icolib.cpp b/protocols/Gadu-Gadu/src/icolib.cpp
index b4cf97f5bf..606435f25f 100644
--- a/protocols/Gadu-Gadu/src/icolib.cpp
+++ b/protocols/Gadu-Gadu/src/icolib.cpp
@@ -22,23 +22,23 @@
extern IconItem iconList[] =
{
- { LPGEN("Protocol icon"), "main", IDI_GG },
- { LPGEN("Import list from server"), "importserver", IDI_IMPORT_SERVER },
- { LPGEN("Import list from text file"), "importtext", IDI_IMPORT_TEXT },
- { LPGEN("Remove list from server"), "removeserver", IDI_REMOVE_SERVER },
- { LPGEN("Export list to server"), "exportserver", IDI_EXPORT_SERVER },
- { LPGEN("Export list to text file"), "exporttext", IDI_EXPORT_TEXT },
- { LPGEN("Account settings"), "settings", IDI_SETTINGS },
- { LPGEN("Contact list"), "list", IDI_LIST },
- { LPGEN("Block user"), "block", IDI_BLOCK },
- { LPGEN("Previous image"), "previous", IDI_PREV },
- { LPGEN("Next image"), "next", IDI_NEXT },
- { LPGEN("Send image"), "image", IDI_IMAGE },
- { LPGEN("Save image"), "save", IDI_SAVE },
- { LPGEN("Delete image"), "delete", IDI_DELETE },
- { LPGEN("Open new conference"), "conference", IDI_CONFERENCE },
+ { LPGEN("Protocol icon"), "main", IDI_GG },
+ { LPGEN("Import list from server"), "importserver", IDI_IMPORT_SERVER },
+ { LPGEN("Import list from text file"), "importtext", IDI_IMPORT_TEXT },
+ { LPGEN("Remove list from server"), "removeserver", IDI_REMOVE_SERVER },
+ { LPGEN("Export list to server"), "exportserver", IDI_EXPORT_SERVER },
+ { LPGEN("Export list to text file"), "exporttext", IDI_EXPORT_TEXT },
+ { LPGEN("Account settings"), "settings", IDI_SETTINGS },
+ { LPGEN("Contact list"), "list", IDI_LIST },
+ { LPGEN("Block user"), "block", IDI_BLOCK },
+ { LPGEN("Previous image"), "previous", IDI_PREV },
+ { LPGEN("Next image"), "next", IDI_NEXT },
+ { LPGEN("Send image"), "image", IDI_IMAGE },
+ { LPGEN("Save image"), "save", IDI_SAVE },
+ { LPGEN("Delete image"), "delete", IDI_DELETE },
+ { LPGEN("Open new conference"), "conference", IDI_CONFERENCE },
{ LPGEN("Clear ignored conferences"), "clearignored", IDI_CLEAR_CONFERENCE },
- { LPGEN("Concurrent sessions"), "sessions", IDI_SESSIONS }
+ { LPGEN("Concurrent sessions"), "sessions", IDI_SESSIONS }
};
void gg_icolib_init()
@@ -55,7 +55,7 @@ HICON LoadIconEx(const char* name, bool big)
HANDLE GetIconHandle(int iconId)
{
- for(int i = 0; i < _countof(iconList); i++)
+ for (int i = 0; i < _countof(iconList); i++)
if (iconList[i].defIconID == iconId)
return iconList[i].hIcolib;
diff --git a/protocols/Gadu-Gadu/src/image.cpp b/protocols/Gadu-Gadu/src/image.cpp
index 7202aaad61..df14a3e57f 100644
--- a/protocols/Gadu-Gadu/src/image.cpp
+++ b/protocols/Gadu-Gadu/src/image.cpp
@@ -70,7 +70,7 @@ int GGPROTO::img_init()
{
// Send image contact menu item
CMenuItem mi;
- SET_UID(mi,0xab238938, 0xed85, 0x4cfe, 0x93, 0xb5, 0xb8, 0x83, 0xf4, 0x32, 0xa0, 0xec);
+ SET_UID(mi, 0xab238938, 0xed85, 0x4cfe, 0x93, 0xb5, 0xb8, 0x83, 0xf4, 0x32, 0xa0, 0xec);
mi.position = -2000010000;
mi.hIcolibItem = iconList[11].hIcolib;
mi.name.a = LPGEN("&Image");
@@ -160,11 +160,11 @@ int gg_img_paint(HWND hwnd, GGIMAGEENTRY *dat)
if (dat->hBitmap)
{
HDC hdcBmp = nullptr;
- int nWidth, nHeight;
BITMAP bmp;
GetObject(dat->hBitmap, sizeof(bmp), &bmp);
- nWidth = bmp.bmWidth; nHeight = bmp.bmHeight;
+ int nWidth = bmp.bmWidth;
+ int nHeight = bmp.bmHeight;
hdcBmp = CreateCompatibleDC(hdc);
SelectObject(hdcBmp, dat->hBitmap);
@@ -172,9 +172,9 @@ int gg_img_paint(HWND hwnd, GGIMAGEENTRY *dat)
{
SetStretchBltMode(hdc, HALFTONE);
// Draw bitmap
- if (nWidth > (rc.right-rc.left) || nHeight > (rc.bottom-rc.top))
+ if (nWidth > (rc.right - rc.left) || nHeight > (rc.bottom - rc.top))
{
- if ((double)nWidth / (double)nHeight > (double) (rc.right-rc.left) / (double)(rc.bottom-rc.top))
+ if ((double)nWidth / (double)nHeight > (double)(rc.right - rc.left) / (double)(rc.bottom - rc.top))
{
StretchBlt(hdc,
rc.left,
@@ -224,10 +224,14 @@ wchar_t *gg_img_getfilter(wchar_t *szFilter, int nSize)
// Make up filter
wcsncpy(pFilter, szFilterName, nSize);
pFilter += mir_wstrlen(pFilter) + 1;
- if (pFilter >= szFilter + nSize) return nullptr;
+ if (pFilter >= szFilter + nSize)
+ return nullptr;
+
wcsncpy(pFilter, szFilterMask, nSize - (pFilter - szFilter));
pFilter += mir_wstrlen(pFilter) + 1;
- if (pFilter >= szFilter + nSize) return nullptr;
+ if (pFilter >= szFilter + nSize)
+ return nullptr;
+
*pFilter = 0;
return szFilter;
@@ -249,7 +253,7 @@ int gg_img_saveimage(HWND hwnd, GGIMAGEENTRY *dat)
wchar_t szFileName[MAX_PATH];
wcsncpy(szFileName, dat->lpszFileName, _countof(szFileName));
- OPENFILENAME ofn = {0};
+ OPENFILENAME ofn = { 0 };
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
ofn.hwndOwner = hwnd;
ofn.hInstance = hInstance;
@@ -283,7 +287,6 @@ BOOL gg_img_fit(HWND hwndDlg)
{
GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
RECT dlgRect, imgRect, wrkRect;
- int nWidth, nHeight;
int rWidth = 0, rHeight = 0;
int oWidth = 0, oHeight = 0;
BITMAP bmp;
@@ -307,7 +310,8 @@ BOOL gg_img_fit(HWND hwndDlg)
hdc = GetDC(hwndDlg);
GetObject(img->hBitmap, sizeof(bmp), &bmp);
- nWidth = bmp.bmWidth; nHeight = bmp.bmHeight;
+ int nWidth = bmp.bmWidth;
+ int nHeight = bmp.bmHeight;
SystemParametersInfo(SPI_GETWORKAREA, 0, &wrkRect, 0);
ReleaseDC(hwndDlg, hdc);
@@ -356,16 +360,16 @@ static int sttImageDlgResizer(HWND, LPARAM, UTILRESIZECONTROL *urc)
{
switch (urc->wId)
{
- case IDC_IMG_PREV:
- case IDC_IMG_NEXT:
- case IDC_IMG_DELETE:
- case IDC_IMG_SAVE:
- return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP;
- case IDC_IMG_IMAGE:
- return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORY_HEIGHT | RD_ANCHORX_WIDTH;
- case IDC_IMG_SEND:
- case IDC_IMG_CANCEL:
- return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
+ case IDC_IMG_PREV:
+ case IDC_IMG_NEXT:
+ case IDC_IMG_DELETE:
+ case IDC_IMG_SAVE:
+ return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP;
+ case IDC_IMG_IMAGE:
+ return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORY_HEIGHT | RD_ANCHORX_WIDTH;
+ case IDC_IMG_SEND:
+ case IDC_IMG_CANCEL:
+ return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
}
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
@@ -379,57 +383,56 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
switch (msg) {
case WM_INITDIALOG:
- {
- RECT rect;
-
- TranslateDialogDefault(hwndDlg);
- // This should be already initialized
- // InitCommonControls();
+ {
+ TranslateDialogDefault(hwndDlg);
+ // This should be already initialized
+ // InitCommonControls();
- // Get dialog data
- dat = (GGIMAGEDLGDATA *)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
+ // Get dialog data
+ dat = (GGIMAGEDLGDATA *)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
- // Save dialog handle
- dat->hWnd = hwndDlg;
+ // Save dialog handle
+ dat->hWnd = hwndDlg;
- // Send event if someone's waiting
- if (dat->hEvent) SetEvent(dat->hEvent);
- else dat->gg->debugLogA("gg_img_dlgproc(): WM_INITDIALOG Creation event not found, but someone might be waiting.");
+ // Send event if someone's waiting
+ if (dat->hEvent) SetEvent(dat->hEvent);
+ else dat->gg->debugLogA("gg_img_dlgproc(): WM_INITDIALOG Creation event not found, but someone might be waiting.");
- // Making buttons flat
- SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("previous", FALSE));
- SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Previous image"), BATF_UNICODE);
+ // Making buttons flat
+ SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BUTTONSETASFLATBTN, TRUE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("previous", FALSE));
+ SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Previous image"), BATF_UNICODE);
- SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("next", FALSE));
- SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Next image"), BATF_UNICODE);
+ SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BUTTONSETASFLATBTN, TRUE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("next", FALSE));
+ SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Next image"), BATF_UNICODE);
- SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("save", FALSE));
- SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Save image to disk"), BATF_UNICODE);
+ SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BUTTONSETASFLATBTN, TRUE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("save", FALSE));
+ SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Save image to disk"), BATF_UNICODE);
- SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("delete", FALSE));
- SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete image from the list"), BATF_UNICODE);
+ SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BUTTONSETASFLATBTN, TRUE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("delete", FALSE));
+ SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete image from the list"), BATF_UNICODE);
- // Set main window image
- Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_IMAGE));
+ // Set main window image
+ Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_IMAGE));
- wchar_t *szName = pcli->pfnGetContactDisplayName(dat->hContact, 0), szTitle[128];
- if (dat->bReceiving)
- mir_snwprintf(szTitle, TranslateT("Image from %s"), szName);
- else
- mir_snwprintf(szTitle, TranslateT("Image for %s"), szName);
- SetWindowText(hwndDlg, szTitle);
-
- // Store client extents
- GetClientRect(hwndDlg, &rect);
- dat->minSize.cx = rect.right - rect.left;
- dat->minSize.cy = rect.bottom - rect.top;
- }
- return TRUE;
+ wchar_t *szName = pcli->pfnGetContactDisplayName(dat->hContact, 0), szTitle[128];
+ if (dat->bReceiving)
+ mir_snwprintf(szTitle, TranslateT("Image from %s"), szName);
+ else
+ mir_snwprintf(szTitle, TranslateT("Image for %s"), szName);
+ SetWindowText(hwndDlg, szTitle);
+
+ // Store client extents
+ RECT rect;
+ GetClientRect(hwndDlg, &rect);
+ dat->minSize.cx = rect.right - rect.left;
+ dat->minSize.cy = rect.bottom - rect.top;
+ }
+ return TRUE;
case WM_SIZE:
Utils_ResizeDialog(hwndDlg, hInstance, dat->bReceiving ? MAKEINTRESOURCEA(IDD_IMAGE_RECV) : MAKEINTRESOURCEA(IDD_IMAGE_SEND), sttImageDlgResizer);
@@ -438,24 +441,24 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
return 0;
case WM_SIZING:
+ {
+ RECT *pRect = (RECT *)lParam;
+ if (pRect->right - pRect->left < dat->minSize.cx)
{
- RECT *pRect = (RECT *)lParam;
- if (pRect->right - pRect->left < dat->minSize.cx)
- {
- if (wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT)
- pRect->left = pRect->right - dat->minSize.cx;
- else
- pRect->right = pRect->left + dat->minSize.cx;
- }
- if (pRect->bottom - pRect->top < dat->minSize.cy)
- {
- if (wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOP || wParam == WMSZ_TOPRIGHT)
- pRect->top = pRect->bottom - dat->minSize.cy;
- else
- pRect->bottom = pRect->top + dat->minSize.cy;
- }
+ if (wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT)
+ pRect->left = pRect->right - dat->minSize.cx;
+ else
+ pRect->right = pRect->left + dat->minSize.cx;
}
- return TRUE;
+ if (pRect->bottom - pRect->top < dat->minSize.cy)
+ {
+ if (wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOP || wParam == WMSZ_TOPRIGHT)
+ pRect->top = pRect->bottom - dat->minSize.cy;
+ else
+ pRect->bottom = pRect->top + dat->minSize.cy;
+ }
+ }
+ return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
@@ -471,6 +474,7 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
case WM_ACTIVATE:
if (LOWORD(wParam) != WA_ACTIVE)
break;
+
case WM_MOUSEACTIVATE:
if (KillTimer(hwndDlg, TIMERID_FLASHWND))
FlashWindow(hwndDlg, FALSE);
@@ -480,9 +484,8 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
if (dat->lpImages)
{
GGIMAGEENTRY *img = dat->lpImages;
- int i;
- for (i = 1; img && (i < dat->nImg); i++)
+ for (int i = 1; img && (i < dat->nImg); i++)
img = img->lpNext;
if (!img)
@@ -549,149 +552,149 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
return TRUE;
case IDC_IMG_DELETE:
+ {
+ GGIMAGEENTRY *del, *img = dat->lpImages;
+ if (dat->nImg == 1)
{
- GGIMAGEENTRY *del, *img = dat->lpImages;
- if (dat->nImg == 1)
- {
- del = dat->lpImages;
- dat->lpImages = img->lpNext;
- }
- else
- {
- for (int i = 1; img && (i < dat->nImg - 1); i++)
- img = img->lpNext;
- if (!img)
- {
- dat->gg->debugLogA("gg_img_dlgproc(): IDC_IMG_DELETE Image was not found on the list. Cannot delete it from the list.");
- return FALSE;
- }
- del = img->lpNext;
- img->lpNext = del->lpNext;
- dat->nImg --;
- }
-
- if ((-- dat->nImgTotal) == 0)
- EndDialog(hwndDlg, 0);
- else
- InvalidateRect(hwndDlg, nullptr, FALSE);
-
- gg_img_releasepicture(del);
+ del = dat->lpImages;
+ dat->lpImages = img->lpNext;
}
- return TRUE;
-
- case IDC_IMG_SAVE:
+ else
{
- GGIMAGEENTRY *img = dat->lpImages;
-
- for (int i = 1; img && (i < dat->nImg); i++)
+ for (int i = 1; img && (i < dat->nImg - 1); i++)
img = img->lpNext;
if (!img)
{
- dat->gg->debugLogA("gg_img_dlgproc(): IDC_IMG_SAVE Image was not found on the list. Cannot launch saving.");
+ dat->gg->debugLogA("gg_img_dlgproc(): IDC_IMG_DELETE Image was not found on the list. Cannot delete it from the list.");
return FALSE;
}
- gg_img_saveimage(hwndDlg, img);
+ del = img->lpNext;
+ img->lpNext = del->lpNext;
+ dat->nImg--;
}
- return TRUE;
- case IDC_IMG_SEND:
+ if ((--dat->nImgTotal) == 0)
+ EndDialog(hwndDlg, 0);
+ else
+ InvalidateRect(hwndDlg, nullptr, FALSE);
+
+ gg_img_releasepicture(del);
+ }
+ return TRUE;
+
+ case IDC_IMG_SAVE:
+ {
+ GGIMAGEENTRY *img = dat->lpImages;
+
+ for (int i = 1; img && (i < dat->nImg); i++)
+ img = img->lpNext;
+ if (!img)
{
- unsigned char format[20];
- char *msg = "\xA0\0";
- GGPROTO *gg = dat->gg;
+ dat->gg->debugLogA("gg_img_dlgproc(): IDC_IMG_SAVE Image was not found on the list. Cannot launch saving.");
+ return FALSE;
+ }
+ gg_img_saveimage(hwndDlg, img);
+ }
+ return TRUE;
- if (dat->lpImages && gg->isonline())
- {
- uin_t uin = (uin_t)gg->getDword(dat->hContact, GG_KEY_UIN, 0);
- struct gg_msg_richtext_format *r = nullptr;
- struct gg_msg_richtext_image *p = nullptr;
- int len;
+ case IDC_IMG_SEND:
+ {
+ unsigned char format[20];
+ char *msg = "\xA0\0";
+ GGPROTO *gg = dat->gg;
- ((struct gg_msg_richtext*)format)->flag = 2;
+ if (dat->lpImages && gg->isonline())
+ {
+ uin_t uin = (uin_t)gg->getDword(dat->hContact, GG_KEY_UIN, 0);
+ struct gg_msg_richtext_format *r = nullptr;
+ struct gg_msg_richtext_image *p = nullptr;
+ int len;
- r = (struct gg_msg_richtext_format *)(format + sizeof(struct gg_msg_richtext));
- r->position = 0;
- r->font = GG_FONT_IMAGE;
+ ((struct gg_msg_richtext*)format)->flag = 2;
- p = (struct gg_msg_richtext_image *)(format + sizeof(struct gg_msg_richtext) + sizeof(struct gg_msg_richtext_format));
- p->unknown1 = 0x109;
- p->size = dat->lpImages->nSize;
+ r = (struct gg_msg_richtext_format *)(format + sizeof(struct gg_msg_richtext));
+ r->position = 0;
+ r->font = GG_FONT_IMAGE;
- dat->lpImages->crc32 = p->crc32 = gg_fix32(gg_crc32(0, (BYTE*)dat->lpImages->lpData, dat->lpImages->nSize));
+ p = (struct gg_msg_richtext_image *)(format + sizeof(struct gg_msg_richtext) + sizeof(struct gg_msg_richtext_format));
+ p->unknown1 = 0x109;
+ p->size = dat->lpImages->nSize;
- len = sizeof(struct gg_msg_richtext_format) + sizeof(struct gg_msg_richtext_image);
- ((struct gg_msg_richtext*)format)->length = len;
+ dat->lpImages->crc32 = p->crc32 = gg_fix32(gg_crc32(0, (BYTE*)dat->lpImages->lpData, dat->lpImages->nSize));
- gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_img_dlgproc", 59, "sess_mutex", 1);
- gg_send_message_richtext(gg->sess, GG_CLASS_CHAT, (uin_t)uin, (unsigned char*)msg, format, len + sizeof(struct gg_msg_richtext));
- gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_img_dlgproc", 59, 1, "sess_mutex", 1);
+ len = sizeof(struct gg_msg_richtext_format) + sizeof(struct gg_msg_richtext_image);
+ ((struct gg_msg_richtext*)format)->length = len;
- // Protect dat from releasing
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
+ gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_img_dlgproc", 59, "sess_mutex", 1);
+ gg_send_message_richtext(gg->sess, GG_CLASS_CHAT, (uin_t)uin, (unsigned char*)msg, format, len + sizeof(struct gg_msg_richtext));
+ gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_img_dlgproc", 59, 1, "sess_mutex", 1);
- EndDialog(hwndDlg, 0);
- }
- return TRUE;
+ // Protect dat from releasing
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
+
+ EndDialog(hwndDlg, 0);
}
- break;
+ return TRUE;
+ }
+ break;
}
break;
case WM_ADDIMAGE: // lParam == GGIMAGEENTRY *dat
- {
- GGIMAGEENTRY *lpImage = (GGIMAGEENTRY *)lParam;
- GGIMAGEENTRY *lpImages = dat->lpImages;
+ {
+ GGIMAGEENTRY *lpImage = (GGIMAGEENTRY *)lParam;
+ GGIMAGEENTRY *lpImages = dat->lpImages;
- if (!dat->lpImages) // first image entry
- dat->lpImages = lpImage;
- else // adding at the end of the list
- {
- while (lpImages->lpNext)
- lpImages = lpImages->lpNext;
- lpImages->lpNext = lpImage;
- }
- dat->nImg = ++ dat->nImgTotal;
+ if (!dat->lpImages) // first image entry
+ dat->lpImages = lpImage;
+ else // adding at the end of the list
+ {
+ while (lpImages->lpNext)
+ lpImages = lpImages->lpNext;
+ lpImages->lpNext = lpImage;
}
- // Fit window to image
- if (!gg_img_fit(hwndDlg))
- InvalidateRect(hwndDlg, nullptr, FALSE);
- return TRUE;
+ dat->nImg = ++dat->nImgTotal;
+ }
+ // Fit window to image
+ if (!gg_img_fit(hwndDlg))
+ InvalidateRect(hwndDlg, nullptr, FALSE);
+ return TRUE;
case WM_CHOOSEIMG:
+ {
+ wchar_t szFilter[128];
+ wchar_t szFileName[MAX_PATH];
+ OPENFILENAME ofn = { 0 };
+
+ gg_img_getfilter(szFilter, _countof(szFilter));
+ *szFileName = 0;
+ ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ ofn.hwndOwner = hwndDlg;
+ ofn.hInstance = hInstance;
+ ofn.lpstrFilter = szFilter;
+ ofn.lpstrFile = szFileName;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.lpstrTitle = TranslateT("Select picture to send");
+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
+ if (GetOpenFileName(&ofn))
{
- wchar_t szFilter[128];
- wchar_t szFileName[MAX_PATH];
- OPENFILENAME ofn = {0};
-
- gg_img_getfilter(szFilter, _countof(szFilter));
- *szFileName = 0;
- ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.hwndOwner = hwndDlg;
- ofn.hInstance = hInstance;
- ofn.lpstrFilter = szFilter;
- ofn.lpstrFile = szFileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.lpstrTitle = TranslateT("Select picture to send");
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
- if (GetOpenFileName(&ofn))
- {
- if (dat->lpImages)
- gg_img_releasepicture(dat->lpImages);
- if (!(dat->lpImages = (GGIMAGEENTRY *)dat->gg->img_loadpicture(nullptr, szFileName)))
- {
- EndDialog(hwndDlg, 0);
- return FALSE;
- }
- if (!gg_img_fit(hwndDlg))
- InvalidateRect(hwndDlg, nullptr, FALSE);
- }
- else
+ if (dat->lpImages)
+ gg_img_releasepicture(dat->lpImages);
+ if (!(dat->lpImages = (GGIMAGEENTRY *)dat->gg->img_loadpicture(nullptr, szFileName)))
{
EndDialog(hwndDlg, 0);
return FALSE;
}
- return TRUE;
+ if (!gg_img_fit(hwndDlg))
+ InvalidateRect(hwndDlg, nullptr, FALSE);
}
+ else
+ {
+ EndDialog(hwndDlg, 0);
+ return FALSE;
+ }
+ return TRUE;
+ }
}
return FALSE;
@@ -707,7 +710,7 @@ void __cdecl GGPROTO::img_dlgcallthread(void *param)
debugLogA("img_dlgcallthread(): started.");
GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)param;
DialogBoxParam(hInstance, dat->bReceiving ? MAKEINTRESOURCE(IDD_IMAGE_RECV) : MAKEINTRESOURCE(IDD_IMAGE_SEND),
- hMIWnd, gg_img_dlgproc, (LPARAM) dat);
+ hMIWnd, gg_img_dlgproc, (LPARAM)dat);
#ifdef DEBUGMODE
debugLogA("img_dlgcallthread(): end.");
#endif
@@ -779,11 +782,11 @@ wchar_t *gg_img_hasextension(wchar_t *filename)
size_t len = mir_wstrlen(imgtype);
imgtype++;
if (len == 4 && (mir_wstrcmpi(imgtype, L"bmp") == 0 ||
- mir_wstrcmpi(imgtype, L"gif") == 0 ||
- mir_wstrcmpi(imgtype, L"jpg") == 0 ||
- mir_wstrcmpi(imgtype, L"png") == 0))
+ mir_wstrcmpi(imgtype, L"gif") == 0 ||
+ mir_wstrcmpi(imgtype, L"jpg") == 0 ||
+ mir_wstrcmpi(imgtype, L"png") == 0))
return --imgtype;
- if (len == 5 && mir_wstrcmpi(imgtype, L"jpeg") == 0)
+ if (len == 5 && mir_wstrcmpi(imgtype, L"jpeg") == 0)
return --imgtype;
}
}
@@ -798,10 +801,10 @@ int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img)
GGIMAGEENTRY *dat = (GGIMAGEENTRY *)img;
wchar_t szPath[MAX_PATH], path[MAX_PATH], *pImgext, imgext[6];
size_t tPathLen;
- int i, res;
+ int res;
if (hImagesFolder == nullptr || FoldersGetCustomPathT(hImagesFolder, path, MAX_PATH, L"")) {
- wchar_t *tmpPath = Utils_ReplaceVarsW( L"%miranda_userdata%");
+ wchar_t *tmpPath = Utils_ReplaceVarsW(L"%miranda_userdata%");
tPathLen = mir_snwprintf(szPath, L"%s\\%s\\ImageCache", tmpPath, m_tszUserName);
mir_free(tmpPath);
}
@@ -810,11 +813,12 @@ int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img)
tPathLen = mir_wstrlen(szPath);
}
- if ( _waccess(szPath, 0)){
+ if (_waccess(szPath, 0)) {
int ret = CreateDirectoryTreeW(szPath);
- if (ret == 0){
+ if (ret == 0) {
debugLogW(L"img_displayasmsg(): Created new directory for image cache: %s.", szPath);
- } else {
+ }
+ else {
debugLogW(L"img_displayasmsg(): Can not create directory for image cache: %s. errno=%d: %s", szPath, errno, strerror(errno));
wchar_t error[512];
mir_snwprintf(error, TranslateT("Cannot create image cache directory. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szPath);
@@ -826,7 +830,7 @@ int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img)
if ((pImgext = gg_img_hasextension(szPath)) == nullptr)
pImgext = szPath + mir_wstrlen(szPath);
wcsncpy_s(imgext, pImgext, _TRUNCATE);
- for (i = 1; ; ++i)
+ for (int i = 1; ; i++)
{
if ((res = gg_img_isexists(szPath, dat)) != -1) break;
mir_snwprintf(szPath, L"%.*s (%u)%s", pImgext - szPath, szPath, i, imgext);
@@ -838,7 +842,8 @@ int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img)
if (fp) {
res = fwrite(dat->lpData, dat->nSize, 1, fp) > 0;
fclose(fp);
- } else {
+ }
+ else {
debugLogW(L"img_displayasmsg(): Cannot open file %s for write image. errno=%d: %s", szPath, errno, strerror(errno));
wchar_t error[512];
mir_snwprintf(error, TranslateT("Cannot save received image to file. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szPath);
@@ -852,13 +857,14 @@ int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img)
mir_snwprintf(image_msg, L"[img]%s[/img]", szPath);
T2Utf szMessage(image_msg);
- PROTORECVEVENT pre = {0};
+ PROTORECVEVENT pre = { 0 };
pre.timestamp = time(nullptr);
pre.szMessage = szMessage;
ProtoChainRecvMsg(hContact, &pre);
debugLogW(L"img_displayasmsg(): Image saved to %s.", szPath);
}
- else debugLogW(L"img_displayasmsg(): Cannot save image to %s.", szPath);
+ else
+ debugLogW(L"img_displayasmsg(): Cannot save image to %s.", szPath);
return 0;
}
@@ -1004,7 +1010,7 @@ void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName)
dat->lpData = (char*)malloc(dat->nSize);
memcpy(dat->lpData, e->event.image_reply.image, dat->nSize);
- ptrW tmpFileName( mir_a2u(e->event.image_reply.filename));
+ ptrW tmpFileName(mir_a2u(e->event.image_reply.filename));
if (!gg_img_hasextension(tmpFileName)) {
// Add missing file extension
const wchar_t *szImgType = gg_img_guessfileextension(dat->lpData);
@@ -1018,7 +1024,7 @@ void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName)
}
if (dat->lpszFileName == nullptr)
- dat->lpszFileName = wcsdup( _A2T( e->event.image_reply.filename));
+ dat->lpszFileName = wcsdup(_A2T(e->event.image_reply.filename));
}
////////////////////////////////////////////////////////////////////
@@ -1032,14 +1038,15 @@ void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName)
memio.pBuf = (void *)dat->lpData;
memio.fif = FIF_UNKNOWN; /* detect */
memio.flags = 0;
- dat->hBitmap = (HBITMAP) CallService(MS_IMG_LOADFROMMEM, (WPARAM) &memio, 0);
+ dat->hBitmap = (HBITMAP)CallService(MS_IMG_LOADFROMMEM, (WPARAM)&memio, 0);
}
// Load image from file
else
- dat->hBitmap = (HBITMAP) CallService(MS_IMG_LOAD, (WPARAM) szFileName, IMGL_WCHAR);
+ dat->hBitmap = (HBITMAP)CallService(MS_IMG_LOAD, (WPARAM)szFileName, IMGL_WCHAR);
// If everything is fine return the handle
- if (dat->hBitmap) return dat;
+ if (dat->hBitmap)
+ return dat;
debugLogA("img_loadpicture(): MS_IMG_LOAD(MEM) failed.");
if (dat)
@@ -1060,7 +1067,8 @@ INT_PTR GGPROTO::img_recvimage(WPARAM wParam, LPARAM lParam)
GGIMAGEENTRY *img = (GGIMAGEENTRY *)cle->lParam;
debugLogA("img_recvimage(%x, %x): Popup new image.", wParam, lParam);
- if (!img) return FALSE;
+ if (!img)
+ return FALSE;
img_display(cle->hContact, img);
@@ -1107,12 +1115,11 @@ GGIMAGEDLGDATA* gg_img_find(GGPROTO *gg, uin_t uin, uint32_t crc32)
{
list_t l = gg->imagedlgs;
GGIMAGEDLGDATA *dat;
+ uin_t c_uin;
gg->gg_EnterCriticalSection(&gg->img_mutex, "gg_img_find", 62, "img_mutex", 1);
while (l)
{
- uin_t c_uin;
-
dat = (GGIMAGEDLGDATA *)l->data;
if (!dat) break;
diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp
index d80dc75a35..ed405fb0f0 100644
--- a/protocols/Gadu-Gadu/src/import.cpp
+++ b/protocols/Gadu-Gadu/src/import.cpp
@@ -23,7 +23,6 @@
char *gg_makecontacts(GGPROTO *gg, int cr)
{
string_t s = string_init(nullptr);
- char *contacts;
// Readup contacts
for (MCONTACT hContact = db_find_first(gg->m_szModuleName); hContact; hContact = db_find_next(hContact, gg->m_szModuleName)) {
@@ -62,7 +61,8 @@ char *gg_makecontacts(GGPROTO *gg, int cr)
mir_free(pszValA);
db_free(&dbv2);
}
- else string_append(s, dbvA);
+ else
+ string_append(s, dbvA);
string_append_c(s, ';');
string_append(s, dbvA);
@@ -106,7 +106,7 @@ char *gg_makecontacts(GGPROTO *gg, int cr)
string_append(s, ";0;;0;\n");
}
- contacts = string_free(s, 0);
+ char *contacts = string_free(s, 0);
#ifdef DEBUGMODE
gg->debugLogA("gg_makecontacts(): \n%s", contacts);
@@ -130,10 +130,12 @@ void GGPROTO::parsecontacts(char *contacts)
uin_t uin;
// Skip to proper data
- if (p && p < strchr(contacts, ';')) p++;
- else p = contacts;
+ if (p && p < strchr(contacts, ';'))
+ p++;
+ else
+ p = contacts;
- while(p)
+ while (p)
{
// Processing line
strFirstName = strLastName = strNickname = strNick = strPhone = strGroup = strUin = strMail = nullptr;
@@ -143,28 +145,32 @@ void GGPROTO::parsecontacts(char *contacts)
if (p)
{
n = strchr(p, ';');
- if (n && n != p) strFirstName = strndup(p, (n - p));
+ if (n && n != p)
+ strFirstName = strndup(p, (n - p));
p = (n + 1);
}
// LastName
if (n && p)
{
n = strchr(p, ';');
- if (n && n != p) strLastName = strndup(p, (n - p));
+ if (n && n != p)
+ strLastName = strndup(p, (n - p));
p = (n + 1);
}
// Nickname
if (n && p)
{
n = strchr(p, ';');
- if (n && n != p) strNickname = strndup(p, (n - p));
+ if (n && n != p)
+ strNickname = strndup(p, (n - p));
p = (n + 1);
}
// Nick
if (n && p)
{
n = strchr(p, ';');
- if (n && n != p) strNick = strndup(p, (n - p));
+ if (n && n != p)
+ strNick = strndup(p, (n - p));
p = (n + 1);
}
// Phone
@@ -183,7 +189,8 @@ void GGPROTO::parsecontacts(char *contacts)
if (n && p)
{
n = strchr(p, ';');
- if (n && n != p) strGroup = strndup(p, (n - p));
+ if (n && n != p)
+ strGroup = strndup(p, (n - p));
p = (n + 1);
}
// Uin
@@ -201,11 +208,13 @@ void GGPROTO::parsecontacts(char *contacts)
if (n && p)
{
n = strchr(p, ';');
- if (n && n != p) strMail = strndup(p, (n - p));
+ if (n && n != p)
+ strMail = strndup(p, (n - p));
n = strchr(p, '\n');
p = (n + 1);
}
- if (!n) p = nullptr;
+ if (!n)
+ p = nullptr;
// Loadup contact
if (uin && strNick)
@@ -216,24 +225,26 @@ void GGPROTO::parsecontacts(char *contacts)
#endif
// Write group
if (hContact && strGroup) {
- ptrW tszGrpName( mir_a2u(strGroup));
+ ptrW tszGrpName(mir_a2u(strGroup));
Clist_GroupCreate(0, tszGrpName);
db_set_ws(hContact, "CList", "Group", tszGrpName);
}
// Write misc data
- if (hContact && strFirstName){
+ if (hContact && strFirstName) {
wchar_t *tstrFirstName = mir_a2u(strFirstName);
setWString(hContact, GG_KEY_PD_FIRSTNAME, tstrFirstName);
mir_free(tstrFirstName);
}
- if (hContact && strLastName){
+ if (hContact && strLastName) {
wchar_t *tstrLastName = mir_a2u(strLastName);
setWString(hContact, GG_KEY_PD_LASTNAME, tstrLastName);
mir_free(tstrLastName);
}
- if (hContact && strPhone) db_set_s(hContact, "UserInfo", "MyPhone0", strPhone); // Store now in User Info
- if (hContact && strMail) db_set_s(hContact, "UserInfo", "Mye-mail0", strMail); // Store now in User Info
+ if (hContact && strPhone)
+ db_set_s(hContact, "UserInfo", "MyPhone0", strPhone); // Store now in User Info
+ if (hContact && strMail)
+ db_set_s(hContact, "UserInfo", "Mye-mail0", strMail); // Store now in User Info
}
// Release stuff
@@ -268,8 +279,8 @@ INT_PTR GGPROTO::import_server(WPARAM, LPARAM)
if (password == NULL)
return 0;
- uin_t uin;
- if (!(uin = getDword(GG_KEY_UIN, 0)))
+ uin_t uin = getDword(GG_KEY_UIN, 0);
+ if (!uin)
return 0;
// Making contacts list
@@ -306,8 +317,8 @@ INT_PTR GGPROTO::remove_server(WPARAM, LPARAM)
if (password == NULL)
return 0;
- uin_t uin;
- if (!(uin = getDword(GG_KEY_UIN, 0)))
+ uin_t uin = getDword(GG_KEY_UIN, 0);
+ if (!uin)
return 0;
// Making contacts list
@@ -334,7 +345,7 @@ INT_PTR GGPROTO::import_text(WPARAM, LPARAM)
wchar_t filter[512], *pfilter;
struct _stat st;
- OPENFILENAME ofn = {0};
+ OPENFILENAME ofn = { 0 };
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
wcsncpy(filter, TranslateT("Text files"), _countof(filter));
mir_wstrncat(filter, L" (*.txt)", _countof(filter) - mir_wstrlen(filter));
@@ -371,7 +382,8 @@ INT_PTR GGPROTO::import_text(WPARAM, LPARAM)
#ifdef DEBUGMODE
debugLogA("import_text()");
#endif
- if (!GetOpenFileName(&ofn)) return 0;
+ if (!GetOpenFileName(&ofn))
+ return 0;
FILE *f = _wfopen(str, L"r");
_wstat(str, &st);
@@ -385,6 +397,7 @@ INT_PTR GGPROTO::import_text(WPARAM, LPARAM)
mir_free(contacts);
MessageBox(nullptr, TranslateT("List import successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
+
return 0;
}
else
@@ -395,6 +408,7 @@ INT_PTR GGPROTO::import_text(WPARAM, LPARAM)
debugLogW(L"import_text(): Cannot import list from file \"%s\". errno=%d: %s", str, errno, _tcserror(errno));
if (f)
fclose(f);
+
return 0;
}
}
@@ -402,7 +416,7 @@ INT_PTR GGPROTO::import_text(WPARAM, LPARAM)
INT_PTR GGPROTO::export_text(WPARAM, LPARAM)
{
wchar_t str[MAX_PATH];
- OPENFILENAME ofn = {0};
+ OPENFILENAME ofn = { 0 };
wchar_t filter[512], *pfilter;
wcsncpy(str, TranslateT("contacts"), _countof(str));
@@ -438,7 +452,8 @@ INT_PTR GGPROTO::export_text(WPARAM, LPARAM)
#ifdef DEBUGMODE
debugLogW(L"export_text(%s).", str);
#endif
- if (!GetSaveFileName(&ofn)) return 0;
+ if (!GetSaveFileName(&ofn))
+ return 0;
FILE *f = _wfopen(str, L"w");
if (f) {
@@ -488,7 +503,7 @@ INT_PTR GGPROTO::export_server(WPARAM, LPARAM)
char *contacts = gg_makecontacts(this, 1);
#ifdef DEBUGMODE
- debugLogA("export_server(): gg_userlist_request(%s).", contacts);
+ debugLogA("export_server(): gg_userlist_request(%s).", contacts);
#endif
gg_EnterCriticalSection(&sess_mutex, "export_server", 67, "sess_mutex", 1);
@@ -525,7 +540,7 @@ void GGPROTO::import_init(HGENMENU hRoot)
mi.position = 2000500001;
mi.hIcolibItem = iconList[1].hIcolib;
mi.name.w = LPGENW("Import List From &Server");
- hMainMenu[2] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+ hMainMenu[2] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
// Import from textfile
SET_UID(mi, 0x39c036d5, 0x6eb5, 0x49ae, 0xa8, 0x78, 0x8a, 0x72, 0xeb, 0xf, 0x15, 0x3d);
diff --git a/protocols/Gadu-Gadu/src/keepalive.cpp b/protocols/Gadu-Gadu/src/keepalive.cpp
index 426f72d0f0..ef937e06b3 100644
--- a/protocols/Gadu-Gadu/src/keepalive.cpp
+++ b/protocols/Gadu-Gadu/src/keepalive.cpp
@@ -21,17 +21,17 @@
#include "gg.h"
/* NOTE: Eventhough SetTimer seems to support UINT_PTR for idEvent, it seems that TimerProc
- * does not get full pointer but just 2 byte lower bytes.
- */
+* does not get full pointer but just 2 byte lower bytes.
+*/
#define MAX_TIMERS 8
-GGPROTO *g_timers[MAX_TIMERS] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
+GGPROTO *g_timers[MAX_TIMERS] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
static VOID CALLBACK gg_keepalive(HWND, UINT, UINT_PTR idEvent, DWORD)
{
int i;
-
+
//Search for GGPROTO* context
- for(i = 0; i < MAX_TIMERS; i++)
+ for (i = 0; i < MAX_TIMERS; i++)
if (g_timers[i]->timer == idEvent)
break;
@@ -40,9 +40,9 @@ static VOID CALLBACK gg_keepalive(HWND, UINT, UINT_PTR idEvent, DWORD)
GGPROTO *gg = g_timers[i];
if (gg->isonline())
{
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
gg->debugLogA("gg_keepalive(): Sending keep-alive");
- #endif
+#endif
gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_keepalive", 68, "sess_mutex", 1);
gg_ping(gg->sess);
gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_keepalive", 68, 1, "sess_mutex", 1);
@@ -55,12 +55,12 @@ void GGPROTO::keepalive_init()
if (getByte(GG_KEY_KEEPALIVE, GG_KEYDEF_KEEPALIVE))
{
int i;
- for(i = 0; i < MAX_TIMERS && g_timers[i] != nullptr; i++);
+ for (i = 0; i < MAX_TIMERS && g_timers[i] != nullptr; i++);
if (i < MAX_TIMERS)
{
- #ifdef DEBUGMODE
+#ifdef DEBUGMODE
debugLogA("keepalive_init(): Initializing Timer %d", i);
- #endif
+#endif
timer = SetTimer(nullptr, 0, 1000 * 30, gg_keepalive);
g_timers[i] = this;
}
@@ -76,7 +76,7 @@ void GGPROTO::keepalive_destroy()
{
int i;
KillTimer(nullptr, timer);
- for(i = 0; i < MAX_TIMERS; i++)
+ for (i = 0; i < MAX_TIMERS; i++)
if (g_timers[i] == this) {
g_timers[i] = nullptr;
break;
diff --git a/protocols/Gadu-Gadu/src/links.cpp b/protocols/Gadu-Gadu/src/links.cpp
index 9d720404dd..6caf12722e 100644
--- a/protocols/Gadu-Gadu/src/links.cpp
+++ b/protocols/Gadu-Gadu/src/links.cpp
@@ -39,8 +39,6 @@ static INT_PTR gg_menuchoose(WPARAM wParam, LPARAM lParam)
static INT_PTR gg_parselink(WPARAM, LPARAM lParam)
{
char *arg = (char*)lParam;
- uin_t uin;
- int items = 0;
if (g_Instances.getCount() == 0)
return 0;
@@ -54,13 +52,14 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam)
return 1;
for (++arg; *arg == '/'; ++arg);
- uin = atoi(arg);
+ uin_t uin = atoi(arg);
if (!uin)
return 1;
GGPROTO *gg = nullptr;
- for (int i=0; i < g_Instances.getCount(); i++) {
+ int items = 0;
+ for (int i = 0; i < g_Instances.getCount(); i++) {
gg = g_Instances[i];
if (gg->m_iStatus > ID_STATUS_OFFLINE) {
@@ -89,6 +88,7 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam)
MCONTACT hContact = gg->getcontact(uin, 1, 0, nullptr);
if (hContact != NULL)
CallService(MS_MSG_SENDMESSAGE, hContact, 0);
+
return 0;
}
diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp
index b4ac6782ed..186c34e8f7 100644
--- a/protocols/Gadu-Gadu/src/oauth.cpp
+++ b/protocols/Gadu-Gadu/src/oauth.cpp
@@ -54,13 +54,12 @@ static int paramsortFunc(const OAUTHPARAMETER *p1, const OAUTHPARAMETER *p2)
#define isunreserved(c) ( isalnum((unsigned char)c) || c == '-' || c == '.' || c == '_' || c == '~')
char *oauth_uri_escape(const char *str)
{
- char *res;
- int size, ix = 0;
+ int ix = 0;
if (str == nullptr) return mir_strdup("");
- size = (int)mir_strlen(str) + 1;
- res = (char *)mir_alloc(size);
+ int size = (int)mir_strlen(str) + 1;
+ char *res = (char *)mir_alloc(size);
while (*str) {
if (!isunreserved(*str)) {
@@ -82,13 +81,13 @@ char *oauth_uri_escape(const char *str)
char *oauth_generate_signature(LIST<OAUTHPARAMETER> &params, const char *httpmethod, const char *url)
{
- char *res, *urlenc, *urlnorm;
+ char *res;
OAUTHPARAMETER *p;
- int i, ix = 0, size;
+ int ix = 0;
if (httpmethod == nullptr || url == nullptr || !params.getCount()) return mir_strdup("");
- urlnorm = (char *)mir_alloc(mir_strlen(url) + 1);
+ char *urlnorm = (char *)mir_alloc(mir_strlen(url) + 1);
while (*url) {
if (*url == '?' || *url == '#') break; // see RFC 3986 section 3
urlnorm[ix++] = tolower(*url);
@@ -100,11 +99,11 @@ char *oauth_generate_signature(LIST<OAUTHPARAMETER> &params, const char *httpmet
else if ((res = strstr(urlnorm, ":443")) != nullptr)
memmove(res, res + 4, mir_strlen(res) - 3);
- urlenc = oauth_uri_escape(urlnorm);
+ char *urlenc = oauth_uri_escape(urlnorm);
mir_free(urlnorm);
- size = (int)mir_strlen(httpmethod) + (int)mir_strlen(urlenc) + 1 + 2;
+ int size = (int)mir_strlen(httpmethod) + (int)mir_strlen(urlenc) + 1 + 2;
- for (i = 0; i < params.getCount(); i++) {
+ for (int i = 0; i < params.getCount(); i++) {
p = params[i];
if (!mir_strcmp(p->name, "oauth_signature")) continue;
if (i > 0) size += 3;
@@ -118,7 +117,7 @@ char *oauth_generate_signature(LIST<OAUTHPARAMETER> &params, const char *httpmet
mir_free(urlenc);
mir_strcat(res, "&");
- for (i = 0; i < params.getCount(); i++) {
+ for (int i = 0; i < params.getCount(); i++) {
p = params[i];
if (!mir_strcmp(p->name, "oauth_signature")) continue;
if (i > 0) mir_strcat(res, "%26");
@@ -133,11 +132,11 @@ char *oauth_generate_signature(LIST<OAUTHPARAMETER> &params, const char *httpmet
char *oauth_getparam(LIST<OAUTHPARAMETER> &params, const char *name)
{
OAUTHPARAMETER *p;
- int i;
- if (name == nullptr) return nullptr;
+ if (name == nullptr)
+ return nullptr;
- for (i = 0; i < params.getCount(); i++) {
+ for (int i = 0; i < params.getCount(); i++) {
p = params[i];
if (!mir_strcmp(p->name, name))
return p->value;
@@ -149,11 +148,11 @@ char *oauth_getparam(LIST<OAUTHPARAMETER> &params, const char *name)
void oauth_setparam(LIST<OAUTHPARAMETER> &params, const char *name, const char *value)
{
OAUTHPARAMETER *p;
- int i;
- if (name == nullptr) return;
+ if (name == nullptr)
+ return;
- for (i = 0; i < params.getCount(); i++) {
+ for (int i = 0; i < params.getCount(); i++) {
p = params[i];
if (!mir_strcmp(p->name, name)) {
mir_free(p->value);
@@ -171,9 +170,8 @@ void oauth_setparam(LIST<OAUTHPARAMETER> &params, const char *name, const char *
void oauth_freeparams(LIST<OAUTHPARAMETER> &params)
{
OAUTHPARAMETER *p;
- int i;
- for (i = 0; i < params.getCount(); i++) {
+ for (int i = 0; i < params.getCount(); i++) {
p = params[i];
mir_free(p->name);
mir_free(p->value);
@@ -181,19 +179,21 @@ void oauth_freeparams(LIST<OAUTHPARAMETER> &params)
}
int oauth_sign_request(LIST<OAUTHPARAMETER> &params, const char *httpmethod, const char *url,
- const char *consumer_secret, const char *token_secret)
+ const char *consumer_secret, const char *token_secret)
{
- char *sign = nullptr, *signmethod;
+ char *sign = nullptr;
- if (!params.getCount()) return -1;
+ if (!params.getCount())
+ return -1;
- signmethod = oauth_getparam(params, "oauth_signature_method");
- if (signmethod == nullptr) return -1;
+ char *signmethod = oauth_getparam(params, "oauth_signature_method");
+ if (signmethod == nullptr)
+ return -1;
if (!mir_strcmp(signmethod, "HMAC-SHA1")) {
- ptrA text( oauth_generate_signature(params, httpmethod, url));
- ptrA csenc( oauth_uri_escape(consumer_secret));
- ptrA tsenc( oauth_uri_escape(token_secret));
+ ptrA text(oauth_generate_signature(params, httpmethod, url));
+ ptrA csenc(oauth_uri_escape(consumer_secret));
+ ptrA tsenc(oauth_uri_escape(token_secret));
ptrA key((char *)mir_alloc(mir_strlen(csenc) + mir_strlen(tsenc) + 2));
mir_strcpy(key, csenc);
mir_strcat(key, "&");
@@ -204,8 +204,8 @@ int oauth_sign_request(LIST<OAUTHPARAMETER> &params, const char *httpmethod, con
sign = mir_base64_encode(digest, MIR_SHA1_HASH_SIZE);
}
else { // PLAINTEXT
- ptrA csenc( oauth_uri_escape(consumer_secret));
- ptrA tsenc( oauth_uri_escape(token_secret));
+ ptrA csenc(oauth_uri_escape(consumer_secret));
+ ptrA tsenc(oauth_uri_escape(token_secret));
sign = (char *)mir_alloc(mir_strlen(csenc) + mir_strlen(tsenc) + 2);
mir_strcpy(sign, csenc);
@@ -232,23 +232,23 @@ char* oauth_generate_nonce()
}
char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD signmethod,
- const char *consumer_key, const char *consumer_secret,
- const char *token, const char *token_secret)
+ const char *consumer_key, const char *consumer_secret,
+ const char *token, const char *token_secret)
{
- int i, size;
char *res, timestamp[22];
- if (httpmethod == nullptr || url == nullptr) return nullptr;
+ if (httpmethod == nullptr || url == nullptr)
+ return nullptr;
LIST<OAUTHPARAMETER> oauth_parameters(1, paramsortFunc);
oauth_setparam(oauth_parameters, "oauth_consumer_key", consumer_key);
oauth_setparam(oauth_parameters, "oauth_version", "1.0");
switch (signmethod) {
- case HMACSHA1: oauth_setparam(oauth_parameters, "oauth_signature_method", "HMAC-SHA1"); break;
- case RSASHA1: oauth_setparam(oauth_parameters, "oauth_signature_method", "RSA-SHA1"); break;
- default: oauth_setparam(oauth_parameters, "oauth_signature_method", "PLAINTEXT"); break;
+ case HMACSHA1: oauth_setparam(oauth_parameters, "oauth_signature_method", "HMAC-SHA1"); break;
+ case RSASHA1: oauth_setparam(oauth_parameters, "oauth_signature_method", "RSA-SHA1"); break;
+ default: oauth_setparam(oauth_parameters, "oauth_signature_method", "PLAINTEXT"); break;
};
- mir_snprintf(timestamp, "%ld", time(nullptr));
+ mir_snprintf(timestamp, "%ld", time(nullptr));
oauth_setparam(oauth_parameters, "oauth_timestamp", timestamp);
oauth_setparam(oauth_parameters, "oauth_nonce", ptrA(oauth_generate_nonce()));
if (token != nullptr && *token)
@@ -259,8 +259,8 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD
return nullptr;
}
- size = 7;
- for (i = 0; i < oauth_parameters.getCount(); i++) {
+ int size = 7;
+ for (int i = 0; i < oauth_parameters.getCount(); i++) {
OAUTHPARAMETER *p = oauth_parameters[i];
if (i > 0) size++;
size += (int)mir_strlen(p->name) + (int)mir_strlen(p->value) + 3;
@@ -269,7 +269,7 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD
res = (char *)mir_alloc(size);
mir_strcpy(res, "OAuth ");
- for (i = 0; i < oauth_parameters.getCount(); i++) {
+ for (int i = 0; i < oauth_parameters.getCount(); i++) {
OAUTHPARAMETER *p = oauth_parameters[i];
if (i > 0) mir_strcat(res, ",");
mir_strcat(res, p->name);
@@ -288,7 +288,7 @@ int GGPROTO::oauth_receivetoken()
int res = 0;
HNETLIBCONN nlc = nullptr;
- UIN2IDA( getDword(GG_KEY_UIN, 0), uin);
+ UIN2IDA(getDword(GG_KEY_UIN, 0), uin);
char *password = getStringA(GG_KEY_PASSWORD);
// 1. Obtaining an Unauthorized Request Token
@@ -297,11 +297,11 @@ int GGPROTO::oauth_receivetoken()
str = oauth_auth_header("POST", szUrl, HMACSHA1, uin, password, nullptr, nullptr);
NETLIBHTTPHEADER httpHeaders[3];
- httpHeaders[0].szName = "User-Agent";
+ httpHeaders[0].szName = "User-Agent";
httpHeaders[0].szValue = GG8_VERSION;
- httpHeaders[1].szName = "Authorization";
+ httpHeaders[1].szName = "Authorization";
httpHeaders[1].szValue = str;
- httpHeaders[2].szName = "Accept";
+ httpHeaders[2].szName = "Accept";
httpHeaders[2].szValue = "*/*";
NETLIBHTTPREQUEST req = { sizeof(req) };
@@ -313,7 +313,7 @@ int GGPROTO::oauth_receivetoken()
NETLIBHTTPREQUEST *resp = Netlib_HttpTransaction(m_hNetlibUser, &req);
if (resp) {
- nlc = resp->nlc;
+ nlc = resp->nlc;
if (resp->resultCode == 200 && resp->dataLength > 0 && resp->pData) {
wchar_t *xmlAction = mir_a2u(resp->pData);
HXML hXml = xmlParseString(xmlAction, nullptr, L"result");
@@ -328,10 +328,13 @@ int GGPROTO::oauth_receivetoken()
}
mir_free(xmlAction);
}
- else debugLogA("oauth_receivetoken(): Invalid response code from HTTP request");
+ else
+ debugLogA("oauth_receivetoken(): Invalid response code from HTTP request");
+
Netlib_FreeHttpRequest(resp);
}
- else debugLogA("oauth_receivetoken(): No response from HTTP request");
+ else
+ debugLogA("oauth_receivetoken(): No response from HTTP request");
// 2. Obtaining User Authorization
debugLogA("oauth_receivetoken(): Obtaining User Authorization...");
@@ -339,7 +342,7 @@ int GGPROTO::oauth_receivetoken()
str = oauth_uri_escape("http://www.mojageneracja.pl");
mir_snprintf(szUrl, "callback_url=%s&request_token=%s&uin=%s&password=%s",
- str, token, uin, password);
+ str, token, uin, password);
mir_free(str);
str = mir_strdup(szUrl);
@@ -351,7 +354,7 @@ int GGPROTO::oauth_receivetoken()
req.headersCount = 3;
req.headers = httpHeaders;
mir_strcpy(szUrl, "https://login.gadu-gadu.pl/authorize");
- httpHeaders[1].szName = "Content-Type";
+ httpHeaders[1].szName = "Content-Type";
httpHeaders[1].szValue = "application/x-www-form-urlencoded";
req.pData = str;
req.dataLength = (int)mir_strlen(str);
@@ -380,7 +383,7 @@ int GGPROTO::oauth_receivetoken()
req.nlc = nlc;
req.headersCount = 3;
req.headers = httpHeaders;
- httpHeaders[1].szName = "Authorization";
+ httpHeaders[1].szName = "Authorization";
httpHeaders[1].szValue = str;
resp = Netlib_HttpTransaction(m_hNetlibUser, &req);
@@ -399,11 +402,14 @@ int GGPROTO::oauth_receivetoken()
}
mir_free(xmlAction);
}
- else debugLogA("oauth_receivetoken(): Invalid response code from HTTP request");
+ else
+ debugLogA("oauth_receivetoken(): Invalid response code from HTTP request");
+
Netlib_CloseHandle(resp->nlc);
Netlib_FreeHttpRequest(resp);
}
- else debugLogA("oauth_receivetoken(): No response from HTTP request");
+ else
+ debugLogA("oauth_receivetoken(): No response from HTTP request");
mir_free(password);
mir_free(str);
@@ -430,8 +436,8 @@ int GGPROTO::oauth_checktoken(int force)
if (force)
return oauth_receivetoken();
- ptrA token( getStringA(GG_KEY_TOKEN));
- ptrA token_secret( getStringA(GG_KEY_TOKENSECRET));
+ ptrA token(getStringA(GG_KEY_TOKEN));
+ ptrA token_secret(getStringA(GG_KEY_TOKENSECRET));
if (token == NULL || token_secret == NULL)
return oauth_receivetoken();
diff --git a/protocols/Gadu-Gadu/src/ownerinfo.cpp b/protocols/Gadu-Gadu/src/ownerinfo.cpp
index 49b70004f5..da6a5718c9 100644
--- a/protocols/Gadu-Gadu/src/ownerinfo.cpp
+++ b/protocols/Gadu-Gadu/src/ownerinfo.cpp
@@ -47,7 +47,7 @@ void __cdecl GGPROTO::remindpasswordthread(void *param)
}
// Get token
- if (!gettoken(&token)){
+ if (!gettoken(&token)) {
#ifdef DEBUGMODE
debugLogA("remindpasswordthread(): End. err2");
#endif
diff --git a/protocols/Gadu-Gadu/src/popups.cpp b/protocols/Gadu-Gadu/src/popups.cpp
index c295801810..2e3a7cb476 100644
--- a/protocols/Gadu-Gadu/src/popups.cpp
+++ b/protocols/Gadu-Gadu/src/popups.cpp
@@ -33,35 +33,35 @@ struct PopupData
//
LRESULT CALLBACK PopupWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
+ switch (msg)
{
- case WM_COMMAND:
+ case WM_COMMAND:
+ {
+ PopupData* puData = (PopupData*)PUGetPluginData(hWnd);
+ if (puData != nullptr)
{
- PopupData* puData = (PopupData*)PUGetPluginData(hWnd);
- if (puData != nullptr)
- {
- if (puData->flags & GG_POPUP_MULTILOGON)
- puData->gg->sessions_view(0, 0);
- }
- PUDeletePopup(hWnd);
- break;
+ if (puData->flags & GG_POPUP_MULTILOGON)
+ puData->gg->sessions_view(0, 0);
}
+ PUDeletePopup(hWnd);
+ break;
+ }
- case WM_CONTEXTMENU:
- PUDeletePopup(hWnd);
- break;
+ case WM_CONTEXTMENU:
+ PUDeletePopup(hWnd);
+ break;
- case UM_FREEPLUGINDATA:
+ case UM_FREEPLUGINDATA:
+ {
+ PopupData* puData = (PopupData*)PUGetPluginData(hWnd);
+ if (puData != nullptr && puData != (PopupData*)CALLSERVICE_NOTFOUND)
{
- PopupData* puData = (PopupData*)PUGetPluginData(hWnd);
- if (puData != nullptr && puData != (PopupData*)CALLSERVICE_NOTFOUND)
- {
- mir_free(puData->title);
- mir_free(puData->text);
- mir_free(puData);
- }
- break;
+ mir_free(puData->title);
+ mir_free(puData->text);
+ mir_free(puData);
}
+ break;
+ }
}
return DefWindowProc(hWnd, msg, wParam, lParam);
@@ -75,7 +75,7 @@ void GGPROTO::initpopups()
wchar_t szDescr[256];
char szName[256];
- POPUPCLASS puc = {0};
+ POPUPCLASS puc = { 0 };
puc.cbSize = sizeof(puc);
puc.PluginWindowProc = PopupWindowProc;
puc.flags = PCF_TCHAR;
@@ -83,7 +83,7 @@ void GGPROTO::initpopups()
puc.pszName = szName;
puc.colorBack = RGB(173, 206, 247);
- puc.colorText = GetSysColor(COLOR_WINDOWTEXT);
+ puc.colorText = GetSysColor(COLOR_WINDOWTEXT);
puc.hIcon = CopyIcon(LoadIconEx("main", FALSE));
ReleaseIconEx("main", FALSE);
puc.iSeconds = 4;
@@ -110,12 +110,12 @@ void CALLBACK sttMainThreadCallback(PVOID dwParam)
if (ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
char szName[256];
- POPUPDATACLASS ppd = {sizeof(ppd)};
+ POPUPDATACLASS ppd = { sizeof(ppd) };
ppd.pwszTitle = puData->title;
ppd.pwszText = puData->text;
ppd.PluginData = puData;
ppd.pszClassName = szName;
-
+
if (puData->flags & GG_POPUP_ERROR || puData->flags & GG_POPUP_WARNING)
mir_snprintf(szName, "%s_%s", gg->m_szModuleName, "Error");
else
@@ -151,7 +151,8 @@ void CALLBACK sttMainThreadCallback(PVOID dwParam)
void GGPROTO::showpopup(const wchar_t* nickname, const wchar_t* msg, int flags)
{
- if (Miranda_IsTerminated()) return;
+ if (Miranda_IsTerminated())
+ return;
PopupData *puData = (PopupData*)mir_calloc(sizeof(PopupData));
puData->flags = flags;
diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp
index e7d0b18365..c5ee323b29 100644
--- a/protocols/Gadu-Gadu/src/services.cpp
+++ b/protocols/Gadu-Gadu/src/services.cpp
@@ -27,18 +27,18 @@
char *gg_status2db(int status, const char *suffix)
{
char *prefix;
- switch(status) {
- case ID_STATUS_AWAY: prefix = "Away"; break;
- case ID_STATUS_NA: prefix = "Na"; break;
- case ID_STATUS_DND: prefix = "Dnd"; break;
- case ID_STATUS_OCCUPIED: prefix = "Occupied"; break;
- case ID_STATUS_FREECHAT: prefix = "FreeChat"; break;
- case ID_STATUS_ONLINE: prefix = "On"; break;
- case ID_STATUS_OFFLINE: prefix = "Off"; break;
- case ID_STATUS_INVISIBLE: prefix = "Inv"; break;
- case ID_STATUS_ONTHEPHONE: prefix = "Otp"; break;
- case ID_STATUS_OUTTOLUNCH: prefix = "Otl"; break;
- default: return nullptr;
+ switch (status) {
+ case ID_STATUS_AWAY: prefix = "Away"; break;
+ case ID_STATUS_NA: prefix = "Na"; break;
+ case ID_STATUS_DND: prefix = "Dnd"; break;
+ case ID_STATUS_OCCUPIED: prefix = "Occupied"; break;
+ case ID_STATUS_FREECHAT: prefix = "FreeChat"; break;
+ case ID_STATUS_ONLINE: prefix = "On"; break;
+ case ID_STATUS_OFFLINE: prefix = "Off"; break;
+ case ID_STATUS_INVISIBLE: prefix = "Inv"; break;
+ case ID_STATUS_ONTHEPHONE: prefix = "Otp"; break;
+ case ID_STATUS_OUTTOLUNCH: prefix = "Otl"; break;
+ default: return nullptr;
}
static char str[64];
@@ -51,7 +51,7 @@ char *gg_status2db(int status, const char *suffix)
//
wchar_t* GGPROTO::getstatusmsg(int status)
{
- switch(status) {
+ switch (status) {
case ID_STATUS_ONLINE:
return modemsg.online;
break;
@@ -118,7 +118,7 @@ int GGPROTO::refreshstatus(int status)
gg_LeaveCriticalSection(&sess_mutex, "refreshstatus", 71, 1, "sess_mutex", 1);
}
// Change status of the contact with our own UIN (if got yourself added to the contact list)
- changecontactstatus( getDword(GG_KEY_UIN, 0), status_m2gg(status, szMsg != nullptr), szMsg, 0, 0, 0, 0);
+ changecontactstatus(getDword(GG_KEY_UIN, 0), status_m2gg(status, szMsg != nullptr), szMsg, 0, 0, 0, 0);
broadcastnewstatus(status);
}
@@ -130,12 +130,12 @@ int GGPROTO::refreshstatus(int status)
//
int gg_normalizestatus(int status)
{
- switch(status) {
- case ID_STATUS_ONLINE: return ID_STATUS_ONLINE;
- case ID_STATUS_DND: return ID_STATUS_DND;
- case ID_STATUS_FREECHAT: return ID_STATUS_FREECHAT;
- case ID_STATUS_OFFLINE: return ID_STATUS_OFFLINE;
- case ID_STATUS_INVISIBLE: return ID_STATUS_INVISIBLE;
+ switch (status) {
+ case ID_STATUS_ONLINE: return ID_STATUS_ONLINE;
+ case ID_STATUS_DND: return ID_STATUS_DND;
+ case ID_STATUS_FREECHAT: return ID_STATUS_FREECHAT;
+ case ID_STATUS_OFFLINE: return ID_STATUS_OFFLINE;
+ case ID_STATUS_INVISIBLE: return ID_STATUS_INVISIBLE;
}
return ID_STATUS_AWAY;
}
@@ -189,9 +189,9 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
//directly check if contact has protected user avatar set by AVS, and if yes return it as protocol avatar
DBVARIANT dbv;
if (!db_get_ws(pai->hContact, "ContactPhoto", "Backup", &dbv)) {
- if ((mir_wstrlen(dbv.ptszVal)>0) && db_get_b(pai->hContact, "ContactPhoto", "Locked", 0)){
+ if ((mir_wstrlen(dbv.ptszVal)>0) && db_get_b(pai->hContact, "ContactPhoto", "Locked", 0)) {
debugLogA("getavatarinfo(): Incoming request for avatar information. Contact has assigned Locked ContactPhoto. return GAIR_SUCCESS");
- wcscpy_s(pai->filename, _countof(pai->filename) ,dbv.ptszVal);
+ wcscpy_s(pai->filename, _countof(pai->filename), dbv.ptszVal);
pai->format = ProtoGetAvatarFormat(pai->filename);
db_free(&dbv);
return GAIR_SUCCESS;
@@ -204,7 +204,8 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
if ((wParam & GAIF_FORCE) != 0) {
debugLogA("getavatarinfo(): Incoming request for avatar information. uin=%d. requestAvatarInfo() fired. return GAIR_WAITFOR", uin);
return GAIR_WAITFOR;
- } else {
+ }
+ else {
debugLogA("getavatarinfo(): Incoming request for avatar information. uin=%d. requestAvatarInfo() fired. return GAIR_NOAVATAR", uin);
return GAIR_NOAVATAR;
}
@@ -213,8 +214,8 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
pai->format = getByte(pai->hContact, GG_KEY_AVATARTYPE, GG_KEYDEF_AVATARTYPE);
ptrA AvatarHash(nullptr);
- ptrA AvatarURL( getStringA(pai->hContact, GG_KEY_AVATARURL));
- ptrA AvatarTs( getStringA(pai->hContact, GG_KEY_AVATARTS));
+ ptrA AvatarURL(getStringA(pai->hContact, GG_KEY_AVATARURL));
+ ptrA AvatarTs(getStringA(pai->hContact, GG_KEY_AVATARTS));
if (AvatarURL != NULL && AvatarTs != NULL) {
char *AvatarName = strrchr(AvatarURL, '/');
if (AvatarName)
@@ -225,11 +226,11 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
}
}
- ptrA AvatarSavedHash( getStringA(pai->hContact, GG_KEY_AVATARHASH));
+ ptrA AvatarSavedHash(getStringA(pai->hContact, GG_KEY_AVATARHASH));
if (AvatarHash != NULL && AvatarSavedHash != NULL) {
getAvatarFilename(pai->hContact, pai->filename, _countof(pai->filename));
if (!mir_strcmp(AvatarHash, AvatarSavedHash)) {
- if (_waccess(pai->filename, 0) == 0){
+ if (_waccess(pai->filename, 0) == 0) {
debugLogA("getavatarinfo(): Incoming request for avatar information. uin=%d. Avatar hash unchanged. return GAIR_SUCCESS", uin);
return GAIR_SUCCESS;
}
@@ -239,7 +240,7 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
return GAIR_WAITFOR;
}
if ((wParam & GAIF_FORCE) != 0) {
- if (_wremove(pai->filename) != 0){
+ if (_wremove(pai->filename) != 0) {
debugLogW(L"getavatarinfo(): refresh. _wremove 1 file %s error. errno=%d: %s", pai->filename, errno, _tcserror(errno));
wchar_t error[512];
mir_snwprintf(error, TranslateT("Cannot remove old avatar file before refresh. ERROR: %d: %s\n%s"), errno, _tcserror(errno), pai->filename);
@@ -254,7 +255,7 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
else if ((wParam & GAIF_FORCE) != 0) {
if (AvatarHash == NULL && AvatarSavedHash != NULL) {
getAvatarFilename(pai->hContact, pai->filename, _countof(pai->filename));
- if (_wremove(pai->filename) != 0){
+ if (_wremove(pai->filename) != 0) {
debugLogW(L"getavatarinfo(): delete. _wremove file %s error. errno=%d: %s", pai->filename, errno, _tcserror(errno));
wchar_t error[512];
mir_snwprintf(error, TranslateT("Cannot remove old avatar file. ERROR: %d: %s\n%s"), errno, _tcserror(errno), pai->filename);
@@ -271,9 +272,11 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
debugLogA("getavatarinfo(): Incoming request for avatar information. Contact %d set avatar. requestAvatarTransfer() fired. return GAIR_WAITFOR", uin);
return GAIR_WAITFOR;
}
- else debugLogA("getavatarinfo(): Incoming request for avatar information. uin=%d. AvatarHash==AvatarSavedHash==NULL, with GAIF_FORCE param. return GAIR_NOAVATAR", uin);
+ else
+ debugLogA("getavatarinfo(): Incoming request for avatar information. uin=%d. AvatarHash==AvatarSavedHash==NULL, with GAIF_FORCE param. return GAIR_NOAVATAR", uin);
}
- else debugLogA("getavatarinfo(): Incoming request for avatar information. uin=%d. AvatarHash==null or AvatarSavedHash==null, but no GAIF_FORCE param. return GAIR_NOAVATAR", uin);
+ else
+ debugLogA("getavatarinfo(): Incoming request for avatar information. uin=%d. AvatarHash==null or AvatarSavedHash==null, but no GAIF_FORCE param. return GAIR_NOAVATAR", uin);
return GAIR_NOAVATAR;
}
@@ -298,10 +301,11 @@ INT_PTR GGPROTO::getmyavatar(WPARAM wParam, LPARAM lParam)
}
getAvatarFilename(NULL, szFilename, len);
- if (_waccess(szFilename, 0) == 0){
+ if (_waccess(szFilename, 0) == 0) {
debugLogA("getmyavatar(): Incoming request for self avatar information. returned ok.");
return 0;
- } else {
+ }
+ else {
debugLogW(L"getmyavatar(): Incoming request for self avatar information. saved avatar file %s does not exist. return -1 (error)", szFilename);
return -1;
}
@@ -320,14 +324,14 @@ INT_PTR GGPROTO::setmyavatar(WPARAM, LPARAM lParam)
return -2;
if (szFilename == nullptr) {
- MessageBox(nullptr,
+ MessageBox(nullptr,
TranslateT("To remove your Gadu-Gadu avatar, you must use the gg.pl website."),
m_tszUserName, MB_OK | MB_ICONINFORMATION);
return -1;
}
int iAvType = ProtoGetAvatarFormat(szFilename);
- if ( iAvType == PA_FORMAT_UNKNOWN) {
+ if (iAvType == PA_FORMAT_UNKNOWN) {
debugLogA("setmyavatar(): Failed to set user avatar. File %s has incompatible extension.", szFilename);
return -1;
}
@@ -337,7 +341,7 @@ INT_PTR GGPROTO::setmyavatar(WPARAM, LPARAM lParam)
wchar_t szMyFilename[MAX_PATH];
getAvatarFilename(NULL, szMyFilename, _countof(szMyFilename));
- if ( mir_wstrcmp(szFilename, szMyFilename) && !CopyFile(szFilename, szMyFilename, FALSE)) {
+ if (mir_wstrcmp(szFilename, szMyFilename) && !CopyFile(szFilename, szMyFilename, FALSE)) {
debugLogA("setmyavatar(): Failed to set user avatar. File with type %d could not be created/overwritten.", iAvType);
return -1;
}
@@ -370,7 +374,7 @@ extern INT_PTR CALLBACK gg_acc_mgr_guidlgproc(HWND hwnd, UINT msg, WPARAM wParam
//
INT_PTR GGPROTO::get_acc_mgr_gui(WPARAM, LPARAM lParam)
{
- return (INT_PTR) CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_ACCMGRUI), (HWND)lParam, gg_acc_mgr_guidlgproc, (LPARAM)this);
+ return (INT_PTR)CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_ACCMGRUI), (HWND)lParam, gg_acc_mgr_guidlgproc, (LPARAM)this);
}
//////////////////////////////////////////////////////////
diff --git a/protocols/Gadu-Gadu/src/sessions.cpp b/protocols/Gadu-Gadu/src/sessions.cpp
index 1dedbe005c..52ad6f1efa 100644
--- a/protocols/Gadu-Gadu/src/sessions.cpp
+++ b/protocols/Gadu-Gadu/src/sessions.cpp
@@ -25,21 +25,20 @@
static void gg_clearsessionslist(HWND hwndDlg)
{
HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
- LV_COLUMN column = {0};
- RECT rc;
- int iWidth;
- if (!hList) return;
+ if (!hList)
+ return;
ListView_DeleteAllItems(hList);
while (ListView_DeleteColumn(hList, 0));
+ LV_COLUMN column = { 0 };
column.mask = LVCF_TEXT;
column.cx = 500;
column.pszText = TranslateT("Client Name");
ListView_InsertColumn(hList, 1, &column);
- column.pszText=TranslateT("IP Address");
+ column.pszText = TranslateT("IP Address");
ListView_InsertColumn(hList, 2, &column);
column.pszText = TranslateT("Login Time");
@@ -48,8 +47,9 @@ static void gg_clearsessionslist(HWND hwndDlg)
column.pszText = TranslateT("Action");
ListView_InsertColumn(hList, 4, &column);
+ RECT rc;
GetClientRect(hList, &rc);
- iWidth = rc.right - rc.left;
+ int iWidth = rc.right - rc.left;
ListView_SetColumnWidth(hList, 0, iWidth * 45 / 100);
ListView_SetColumnWidth(hList, 1, iWidth * 20 / 100);
ListView_SetColumnWidth(hList, 2, iWidth * 20 / 100);
@@ -66,15 +66,14 @@ static void ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, char* pszTex
static int gg_insertlistitem(HWND hList, gg_multilogon_id_t* id, const char* clientName, const char* ip, const char* loginTime)
{
- LVITEM item = {0};
- int index;
-
+ LVITEM item = { 0 };
item.iItem = ListView_GetItemCount(hList);
item.mask = LVIF_PARAM;
item.lParam = (LPARAM)id;
- index = ListView_InsertItem(hList, &item);
- if (index < 0) return index;
+ int index = ListView_InsertItem(hList, &item);
+ if (index < 0)
+ return index;
ListView_SetItemTextA(hList, index, 0, (char*)clientName);
ListView_SetItemTextA(hList, index, 1, (char*)ip);
@@ -89,7 +88,8 @@ static void gg_listsessions(GGPROTO* gg, HWND hwndDlg)
HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
list_t l;
- if (!hList) return;
+ if (!hList)
+ return;
gg->gg_EnterCriticalSection(&gg->sessions_mutex, "gg_listsessions", 73, "sessions_mutex", 1);
for (l = gg->sessions; l; l = l->next)
@@ -111,13 +111,14 @@ static int sttSessionsDlgResizer(HWND, LPARAM, UTILRESIZECONTROL* urc)
{
switch (urc->wId)
{
- case IDC_HEADERBAR:
- return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORX_WIDTH;
- case IDC_SESSIONS:
- return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORY_HEIGHT | RD_ANCHORX_WIDTH;
- case IDC_SIGNOUTALL:
- return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
+ case IDC_HEADERBAR:
+ return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORX_WIDTH;
+ case IDC_SESSIONS:
+ return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORY_HEIGHT | RD_ANCHORX_WIDTH;
+ case IDC_SIGNOUTALL:
+ return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
}
+
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
@@ -125,26 +126,24 @@ static BOOL IsOverAction(HWND hwndDlg)
{
HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
LVHITTESTINFO hti;
- RECT rc;
- HDC hdc;
- wchar_t szText[256];
- SIZE textSize;
- int textPosX;
-
GetCursorPos(&hti.pt);
ScreenToClient(hList, &hti.pt);
+ RECT rc;
GetClientRect(hList, &rc);
if (!PtInRect(&rc, hti.pt) || ListView_SubItemHitTest(hList, &hti) == -1
|| hti.iSubItem != 3 || !(hti.flags & LVHT_ONITEMLABEL))
return FALSE;
ListView_GetSubItemRect(hList, hti.iItem, hti.iSubItem, LVIR_LABEL, &rc);
+ wchar_t szText[256];
szText[0] = 0;
ListView_GetItemText(hList, hti.iItem, hti.iSubItem, szText, _countof(szText));
- hdc = GetDC(hList);
+ HDC hdc = GetDC(hList);
+ SIZE textSize;
GetTextExtentPoint32(hdc, szText, (int)mir_wstrlen(szText), &textSize);
ReleaseDC(hList, hdc);
- textPosX = rc.left + (((rc.right - rc.left) - textSize.cx) / 2);
+ int textPosX = rc.left + (((rc.right - rc.left) - textSize.cx) / 2);
+
return (hti.pt.x > textPosX && hti.pt.x < textPosX + textSize.cx);
}
@@ -165,7 +164,6 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
{
wchar_t oldTitle[256], newTitle[256];
- HANDLE hProtoAckEvent;
GetWindowText(hwndDlg, oldTitle, _countof(oldTitle));
mir_snwprintf(newTitle, oldTitle, gg->m_tszUserName);
@@ -174,7 +172,7 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
if (hHandCursor == nullptr)
hHandCursor = LoadCursor(nullptr, IDC_HAND);
- hProtoAckEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_PROTOACK);
+ HANDLE hProtoAckEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_PROTOACK);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hProtoAckEvent);
ListView_SetExtendedListViewStyle(GetDlgItem(hwndDlg, IDC_SESSIONS), LVS_EX_FULLROWSELECT);
@@ -183,18 +181,18 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
}
case HM_PROTOACK:
- {
- ACKDATA* ack = (ACKDATA*)lParam;
- if (!mir_strcmp(ack->szModule, gg->m_szModuleName) && !ack->hContact && ack->type == ACKTYPE_STATUS
- && ack->result == ACKRESULT_SUCCESS && (ack->lParam == ID_STATUS_OFFLINE
+ {
+ ACKDATA* ack = (ACKDATA*)lParam;
+ if (!mir_strcmp(ack->szModule, gg->m_szModuleName) && !ack->hContact && ack->type == ACKTYPE_STATUS
+ && ack->result == ACKRESULT_SUCCESS && (ack->lParam == ID_STATUS_OFFLINE
|| (ack->hProcess == (HANDLE)ID_STATUS_CONNECTING && ack->lParam != ID_STATUS_OFFLINE
- && !ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_SESSIONS)))))
- {
- gg_clearsessionslist(hwndDlg);
- EnableWindow(GetDlgItem(hwndDlg, IDC_SIGNOUTALL), FALSE);
- }
- break;
+ && !ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_SESSIONS)))))
+ {
+ gg_clearsessionslist(hwndDlg);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_SIGNOUTALL), FALSE);
}
+ break;
+ }
case WM_MULTILOGONINFO:
gg_clearsessionslist(hwndDlg);
@@ -205,21 +203,21 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
switch (LOWORD(wParam))
{
case IDC_SIGNOUTALL:
+ {
+ HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
+ LVITEM lvi = { 0 };
+ int iCount = ListView_GetItemCount(hList);
+ lvi.mask = LVIF_PARAM;
+ for (int i = 0; i < iCount; i++)
{
- HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
- LVITEM lvi = {0};
- int iCount = ListView_GetItemCount(hList), i;
- lvi.mask = LVIF_PARAM;
- for (i = 0; i < iCount; i++)
- {
- lvi.iItem = i;
- ListView_GetItem(hList, &lvi);
- gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_sessions_viewdlg", 74, "sess_mutex", 1);
- gg_multilogon_disconnect(gg->sess, *((gg_multilogon_id_t*)lvi.lParam));
- gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_sessions_viewdlg", 74, 1, "sess_mutex", 1);
- }
- break;
+ lvi.iItem = i;
+ ListView_GetItem(hList, &lvi);
+ gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_sessions_viewdlg", 74, "sess_mutex", 1);
+ gg_multilogon_disconnect(gg->sess, *((gg_multilogon_id_t*)lvi.lParam));
+ gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_sessions_viewdlg", 74, 1, "sess_mutex", 1);
}
+ break;
+ }
}
break;
@@ -229,62 +227,62 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
switch (((LPNMHDR)lParam)->code)
{
case NM_CUSTOMDRAW:
+ {
+ LPNMLVCUSTOMDRAW nm = (LPNMLVCUSTOMDRAW)lParam;
+ switch (nm->nmcd.dwDrawStage)
{
- LPNMLVCUSTOMDRAW nm = (LPNMLVCUSTOMDRAW)lParam;
- switch (nm->nmcd.dwDrawStage)
+ case CDDS_PREPAINT:
+ if (ListView_GetItemCount(nm->nmcd.hdr.hwndFrom) == 0)
{
- case CDDS_PREPAINT:
- if (ListView_GetItemCount(nm->nmcd.hdr.hwndFrom) == 0)
- {
- const LPCTSTR szText = gg->isonline()
- ? TranslateT("There are no active concurrent sessions for this account.")
- : TranslateT("You have to be logged in to view concurrent sessions.");
- RECT rc;
- HWND hwndHeader = ListView_GetHeader(nm->nmcd.hdr.hwndFrom);
- GetClientRect(nm->nmcd.hdr.hwndFrom, &rc);
- if (hwndHeader != nullptr) {
- RECT rcHeader;
- GetClientRect(hwndHeader, &rcHeader);
- rc.top += rcHeader.bottom;
- }
- int cbLen = (int)mir_wstrlen(szText);
- SIZE textSize;
- GetTextExtentPoint32(nm->nmcd.hdc, szText, cbLen, &textSize);
- int textPosX = rc.left + (((rc.right - rc.left) - textSize.cx) / 2);
- ExtTextOut(nm->nmcd.hdc, textPosX, rc.top + textSize.cy, ETO_OPAQUE, &rc, szText, cbLen, nullptr);
+ const LPCTSTR szText = gg->isonline()
+ ? TranslateT("There are no active concurrent sessions for this account.")
+ : TranslateT("You have to be logged in to view concurrent sessions.");
+ RECT rc;
+ HWND hwndHeader = ListView_GetHeader(nm->nmcd.hdr.hwndFrom);
+ GetClientRect(nm->nmcd.hdr.hwndFrom, &rc);
+ if (hwndHeader != nullptr) {
+ RECT rcHeader;
+ GetClientRect(hwndHeader, &rcHeader);
+ rc.top += rcHeader.bottom;
}
- // FALL THROUGH
+ int cbLen = (int)mir_wstrlen(szText);
+ SIZE textSize;
+ GetTextExtentPoint32(nm->nmcd.hdc, szText, cbLen, &textSize);
+ int textPosX = rc.left + (((rc.right - rc.left) - textSize.cx) / 2);
+ ExtTextOut(nm->nmcd.hdc, textPosX, rc.top + textSize.cy, ETO_OPAQUE, &rc, szText, cbLen, nullptr);
+ }
+ // FALL THROUGH
- case CDDS_ITEMPREPAINT:
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT , CDRF_NOTIFYSUBITEMDRAW);
- return TRUE;
+ case CDDS_ITEMPREPAINT:
+ SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYSUBITEMDRAW);
+ return TRUE;
- case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
- {
- RECT rc;
- ListView_GetSubItemRect(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, LVIR_LABEL, &rc);
- if (nm->nmcd.hdr.idFrom == IDC_SESSIONS && nm->iSubItem == 3)
- {
- wchar_t szText[256];
- szText[0] = 0;
- ListView_GetItemText(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, szText, _countof(szText));
- FillRect(nm->nmcd.hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
- SetTextColor(nm->nmcd.hdc, RGB(0, 0, 255));
- DrawText(nm->nmcd.hdc, szText, -1, &rc, DT_END_ELLIPSIS | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE | DT_TOP);
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
- return TRUE;
- }
- break;
- }
+ case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
+ {
+ RECT rc;
+ ListView_GetSubItemRect(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, LVIR_LABEL, &rc);
+ if (nm->nmcd.hdr.idFrom == IDC_SESSIONS && nm->iSubItem == 3)
+ {
+ wchar_t szText[256];
+ szText[0] = 0;
+ ListView_GetItemText(nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, szText, _countof(szText));
+ FillRect(nm->nmcd.hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
+ SetTextColor(nm->nmcd.hdc, RGB(0, 0, 255));
+ DrawText(nm->nmcd.hdc, szText, -1, &rc, DT_END_ELLIPSIS | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE | DT_TOP);
+ SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
+ return TRUE;
}
break;
}
+ }
+ break;
+ }
case NM_CLICK:
if (IsOverAction(hwndDlg))
{
LPNMITEMACTIVATE nm = (LPNMITEMACTIVATE)lParam;
- LVITEM lvi = {0};
+ LVITEM lvi = { 0 };
lvi.mask = LVIF_PARAM;
lvi.iItem = nm->iItem;
ListView_GetItem(nm->hdr.hwndFrom, &lvi);
@@ -298,63 +296,62 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
break;
case WM_CONTEXTMENU:
- {
- HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
- POINT pt = {(short)LOWORD(lParam), (short)HIWORD(lParam)}, ptDlg = pt;
- LVHITTESTINFO lvhti = {0};
+ {
+ HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS);
+ POINT pt = { (short)LOWORD(lParam), (short)HIWORD(lParam) }, ptDlg = pt;
+ LVHITTESTINFO lvhti = { 0 };
- ScreenToClient(hwndDlg, &ptDlg);
- if (ChildWindowFromPoint(hwndDlg, ptDlg) == hList)
+ ScreenToClient(hwndDlg, &ptDlg);
+ if (ChildWindowFromPoint(hwndDlg, ptDlg) == hList)
+ {
+ HMENU hMenu;
+
+ lvhti.pt = pt;
+ ScreenToClient(hList, &lvhti.pt);
+ if (ListView_HitTest(hList, &lvhti) == -1) break;
+
+ hMenu = CreatePopupMenu();
+ AppendMenu(hMenu, MFT_STRING, 10001, TranslateT("Copy Text"));
+ AppendMenu(hMenu, MFT_STRING, 10002, TranslateT("Whois"));
+ int iSelection = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, nullptr);
+ switch (iSelection) {
+ case 10001:
{
- HMENU hMenu;
- int iSelection;
-
- lvhti.pt = pt;
- ScreenToClient(hList, &lvhti.pt);
- if (ListView_HitTest(hList, &lvhti) == -1) break;
-
- hMenu = CreatePopupMenu();
- AppendMenu(hMenu, MFT_STRING, 10001, TranslateT("Copy Text"));
- AppendMenu(hMenu, MFT_STRING, 10002, TranslateT("Whois"));
- iSelection = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, nullptr);
- switch (iSelection) {
- case 10001:
- {
- wchar_t szText[512], szClientName[256], szIP[64], szLoginTime[64];
- HGLOBAL hData;
- if (!OpenClipboard(hwndDlg))
- break;
-
- EmptyClipboard();
- szClientName[0] = szIP[0] = szLoginTime[0] = 0;
- ListView_GetItemText(hList, lvhti.iItem, 0, szClientName, _countof(szClientName));
- ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
- ListView_GetItemText(hList, lvhti.iItem, 2, szLoginTime, _countof(szLoginTime));
- mir_snwprintf(szText, L"%s\t%s\t%s", szClientName, szIP, szLoginTime);
- if ((hData = GlobalAlloc(GMEM_MOVEABLE, mir_wstrlen(szText) + 1)) != nullptr)
- {
- mir_wstrcpy((wchar_t*)GlobalLock(hData), szText);
- GlobalUnlock(hData);
- SetClipboardData(CF_TEXT, hData);
- }
- CloseClipboard();
- break;
- }
+ wchar_t szText[512], szClientName[256], szIP[64], szLoginTime[64];
+ HGLOBAL hData;
+ if (!OpenClipboard(hwndDlg))
+ break;
- case 10002:
- {
- wchar_t szUrl[256], szIP[64];
- szIP[0] = 0;
- ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
- mir_snwprintf(szUrl, L"http://whois.domaintools.com/%s", szIP);
- Utils_OpenUrlW(szUrl);
- break;
- }
+ EmptyClipboard();
+ szClientName[0] = szIP[0] = szLoginTime[0] = 0;
+ ListView_GetItemText(hList, lvhti.iItem, 0, szClientName, _countof(szClientName));
+ ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
+ ListView_GetItemText(hList, lvhti.iItem, 2, szLoginTime, _countof(szLoginTime));
+ mir_snwprintf(szText, L"%s\t%s\t%s", szClientName, szIP, szLoginTime);
+ if ((hData = GlobalAlloc(GMEM_MOVEABLE, mir_wstrlen(szText) + 1)) != nullptr)
+ {
+ mir_wstrcpy((wchar_t*)GlobalLock(hData), szText);
+ GlobalUnlock(hData);
+ SetClipboardData(CF_TEXT, hData);
}
- DestroyMenu(hMenu);
+ CloseClipboard();
+ break;
}
- break;
+
+ case 10002:
+ {
+ wchar_t szUrl[256], szIP[64];
+ szIP[0] = 0;
+ ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
+ mir_snwprintf(szUrl, L"http://whois.domaintools.com/%s", szIP);
+ Utils_OpenUrlW(szUrl);
+ break;
+ }
+ }
+ DestroyMenu(hMenu);
}
+ break;
+ }
case WM_GETMINMAXINFO:
((LPMINMAXINFO)lParam)->ptMinTrackSize.x = 620;
@@ -371,7 +368,7 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
SetCursor(hHandCursor);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
- }
+ }
break;
case WM_CLOSE:
@@ -379,13 +376,13 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
break;
case WM_DESTROY:
- {
- HANDLE hProtoAckEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- if (hProtoAckEvent) UnhookEvent(hProtoAckEvent);
- gg->hwndSessionsDlg = nullptr;
- Window_FreeIcon_IcoLib(hwndDlg);
- break;
- }
+ {
+ HANDLE hProtoAckEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ if (hProtoAckEvent) UnhookEvent(hProtoAckEvent);
+ gg->hwndSessionsDlg = nullptr;
+ Window_FreeIcon_IcoLib(hwndDlg);
+ break;
+ }
}
return FALSE;
}
@@ -397,7 +394,9 @@ INT_PTR GGPROTO::sessions_view(WPARAM, LPARAM)
SetForegroundWindow(hwndSessionsDlg);
SetFocus(hwndSessionsDlg);
}
- else CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_SESSIONS), nullptr, gg_sessions_viewdlg, (LPARAM)this);
+ else
+ CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_SESSIONS), nullptr, gg_sessions_viewdlg, (LPARAM)this);
+
return 0;
}
@@ -419,7 +418,7 @@ void GGPROTO::sessions_menus_init(HGENMENU hRoot)
CMenuItem mi;
mi.flags = CMIF_UNICODE;
mi.root = hRoot;
-
+
mi.pszService = GGS_CONCUR_SESS;
CreateProtoService(mi.pszService, &GGPROTO::sessions_view);
mi.position = 200003;
diff --git a/protocols/Gadu-Gadu/src/stdafx.cpp b/protocols/Gadu-Gadu/src/stdafx.cpp
index 2f7e54520d..d67a00cb7e 100644
--- a/protocols/Gadu-Gadu/src/stdafx.cpp
+++ b/protocols/Gadu-Gadu/src/stdafx.cpp
@@ -15,4 +15,4 @@ 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 "gg.h" \ No newline at end of file
+#include "gg.h"
diff --git a/protocols/Gadu-Gadu/src/token.cpp b/protocols/Gadu-Gadu/src/token.cpp
index be13895b5d..5ac569e9e2 100644
--- a/protocols/Gadu-Gadu/src/token.cpp
+++ b/protocols/Gadu-Gadu/src/token.cpp
@@ -40,64 +40,64 @@ INT_PTR CALLBACK gg_tokendlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
{
GGTOKENDLGDATA *dat = (GGTOKENDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- switch(msg)
+ switch (msg)
{
- case WM_INITDIALOG:
+ case WM_INITDIALOG:
+ {
+ RECT rc;
+ TranslateDialogDefault(hwndDlg);
+ GetClientRect(GetDlgItem(hwndDlg, IDC_WHITERECT), &rc);
+ InvalidateRect(hwndDlg, &rc, TRUE);
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
+ return TRUE;
+ }
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
{
- RECT rc;
- TranslateDialogDefault(hwndDlg);
- GetClientRect(GetDlgItem(hwndDlg, IDC_WHITERECT), &rc);
- InvalidateRect(hwndDlg, &rc, TRUE);
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
- return TRUE;
+ case IDOK:
+ {
+ GetDlgItemTextA(hwndDlg, IDC_TOKEN, dat->val, _countof(dat->val));
+ EndDialog(hwndDlg, IDOK);
+ break;
}
-
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDOK:
- {
- GetDlgItemTextA(hwndDlg, IDC_TOKEN, dat->val, _countof(dat->val));
- EndDialog(hwndDlg, IDOK);
- break;
- }
- case IDCANCEL:
- EndDialog(hwndDlg, IDCANCEL);
- break;
- }
+ case IDCANCEL:
+ EndDialog(hwndDlg, IDCANCEL);
break;
+ }
+ break;
- case WM_PAINT:
+ case WM_PAINT:
+ {
+ PAINTSTRUCT paintStruct;
+ HDC hdc = BeginPaint(hwndDlg, &paintStruct);
+ RECT rc;
+ GetClientRect(GetDlgItem(hwndDlg, IDC_WHITERECT), &rc);
+ FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
+
+ if (dat && dat->hBitmap)
{
- PAINTSTRUCT paintStruct;
- HDC hdc = BeginPaint(hwndDlg, &paintStruct);
- RECT rc; GetClientRect(GetDlgItem(hwndDlg, IDC_WHITERECT), &rc);
- FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
+ HDC hdcBmp = nullptr;
+ BITMAP bmp;
+ GetObject(dat->hBitmap, sizeof(bmp), &bmp);
+ int nWidth = bmp.bmWidth;
+ int nHeight = bmp.bmHeight;
- if (dat && dat->hBitmap)
+ if (hdcBmp = CreateCompatibleDC(hdc))
{
- HDC hdcBmp = nullptr;
- int nWidth, nHeight;
- BITMAP bmp;
-
- GetObject(dat->hBitmap, sizeof(bmp), &bmp);
- nWidth = bmp.bmWidth; nHeight = bmp.bmHeight;
-
- if (hdcBmp = CreateCompatibleDC(hdc))
- {
- SelectObject(hdcBmp, dat->hBitmap);
- SetStretchBltMode(hdc, HALFTONE);
- BitBlt(hdc,
- (rc.left + rc.right - nWidth) / 2,
- (rc.top + rc.bottom - nHeight) / 2,
- nWidth, nHeight,
- hdcBmp, 0, 0, SRCCOPY);
- DeleteDC(hdcBmp);
- }
+ SelectObject(hdcBmp, dat->hBitmap);
+ SetStretchBltMode(hdc, HALFTONE);
+ BitBlt(hdc,
+ (rc.left + rc.right - nWidth) / 2,
+ (rc.top + rc.bottom - nHeight) / 2,
+ nWidth, nHeight,
+ hdcBmp, 0, 0, SRCCOPY);
+ DeleteDC(hdcBmp);
}
- EndPaint(hwndDlg, &paintStruct);
- return 0;
}
+ EndPaint(hwndDlg, &paintStruct);
+ return 0;
+ }
}
return FALSE;
}
@@ -130,18 +130,18 @@ int GGPROTO::gettoken(GGTOKEN *token)
}
// Return token id
- GGTOKENDLGDATA dat = {0};
+ GGTOKENDLGDATA dat = { 0 };
strncpy(dat.id, t->tokenid, sizeof(dat.id));
dat.width = t->width;
dat.height = t->height;
// Load bitmap
- IMGSRVC_MEMIO memio = {0};
+ IMGSRVC_MEMIO memio = { 0 };
memio.iLen = h->body_size;
memio.pBuf = h->body;
memio.fif = FIF_UNKNOWN; /* detect */
memio.flags = 0;
- dat.hBitmap = (HBITMAP) CallService(MS_IMG_LOADFROMMEM, (WPARAM) &memio, 0);
+ dat.hBitmap = (HBITMAP)CallService(MS_IMG_LOADFROMMEM, (WPARAM)&memio, 0);
if (dat.hBitmap == nullptr)
{
MessageBox(nullptr, TranslateT("Could not load token image."), m_tszUserName, MB_OK | MB_ICONSTOP);
diff --git a/protocols/Gadu-Gadu/src/userutils.cpp b/protocols/Gadu-Gadu/src/userutils.cpp
index 8136cd8552..771fd60890 100644
--- a/protocols/Gadu-Gadu/src/userutils.cpp
+++ b/protocols/Gadu-Gadu/src/userutils.cpp
@@ -53,7 +53,7 @@ void *gg_doregister(GGPROTO *gg, char *newPass, char *newEmail)
gg->setString(GG_KEY_EMAIL, newEmail);
gg_pubdir_free(h);
gg->debugLogA("gg_doregister(): Account registration succesful.");
- MessageBox( nullptr,
+ MessageBox(nullptr,
TranslateT("You have registered new account.\nPlease fill up your personal details in \"Main menu -> View/change my details...\""),
gg->m_tszUserName, MB_OK | MB_ICONINFORMATION);
}
@@ -78,10 +78,12 @@ void *gg_dounregister(GGPROTO *gg, uin_t uin, char *password)
#ifdef DEBUGMODE
gg->debugLogA("gg_dounregister(): Starting.");
#endif
- if (!uin || !password) return nullptr;
+ if (!uin || !password)
+ return nullptr;
// Load token
- if (!gg->gettoken(&token)) return nullptr;
+ if (!gg->gettoken(&token))
+ return nullptr;
if (!(h = gg_unregister3(uin, password, token.id, token.val, 0)) || !(s = (gg_pubdir*)h->data) || !s->success || s->uin != uin)
{
@@ -113,28 +115,28 @@ void *gg_dounregister(GGPROTO *gg, uin_t uin, char *password)
//
void *gg_dochpass(GGPROTO *gg, uin_t uin, char *password, char *newPass)
{
- // Readup email
- char email[255] = "\0"; DBVARIANT dbv_email;
- // Connection handles
- struct gg_http *h;
- struct gg_pubdir *s = nullptr;
- GGTOKEN token;
-
#ifdef DEBUGMODE
gg->debugLogA("gg_dochpass(): Starting.");
#endif
- if (!uin || !password || !newPass) return nullptr;
+ if (!uin || !password || !newPass)
+ return nullptr;
- if (!gg->getString(GG_KEY_EMAIL, &dbv_email))
+ // Readup email
+ char email[255] = "\0";
+ DBVARIANT dbv_email;
+ if (!gg->getString(GG_KEY_EMAIL, &dbv_email))
{
strncpy(email, dbv_email.pszVal, sizeof(email));
db_free(&dbv_email);
}
// Load token
+ GGTOKEN token;
if (!gg->gettoken(&token))
return nullptr;
+ struct gg_http *h;
+ struct gg_pubdir *s = nullptr;
if (!(h = gg_change_passwd4(uin, email, password, newPass, token.id, token.val, 0)) || !(s = (gg_pubdir*)h->data) || !s->success)
{
wchar_t error[128];
@@ -209,70 +211,72 @@ INT_PTR CALLBACK gg_userutildlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
switch (msg)
{
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_SETTINGS));
- dat = (GGUSERUTILDLGDATA *)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
- if (dat) SetDlgItemTextA(hwndDlg, IDC_EMAIL, dat->email); // Readup email
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam))
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_SETTINGS));
+ dat = (GGUSERUTILDLGDATA *)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
+ if (dat) SetDlgItemTextA(hwndDlg, IDC_EMAIL, dat->email); // Readup email
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case IDC_PASSWORD:
+ case IDC_CPASSWORD:
+ case IDC_CONFIRM:
+ {
+ char pass[128], cpass[128];
+ BOOL enable;
+ GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
+ GetDlgItemTextA(hwndDlg, IDC_CPASSWORD, cpass, _countof(cpass));
+ enable = mir_strlen(pass) && mir_strlen(cpass) && !mir_strcmp(cpass, pass);
+ if (dat && dat->mode == GG_USERUTIL_REMOVE)
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), IsDlgButtonChecked(hwndDlg, IDC_CONFIRM) ? enable : FALSE);
+ else
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), enable);
+ break;
+ }
+
+ case IDOK:
+ {
+ char pass[128], cpass[128], email[128];
+ GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
+ GetDlgItemTextA(hwndDlg, IDC_CPASSWORD, cpass, _countof(cpass));
+ GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
+ EndDialog(hwndDlg, IDOK);
+
+ // Check dialog box mode
+ if (!dat)
+ break;
+
+ switch (dat->mode)
{
- case IDC_PASSWORD:
- case IDC_CPASSWORD:
- case IDC_CONFIRM:
- {
- char pass[128], cpass[128];
- BOOL enable;
- GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
- GetDlgItemTextA(hwndDlg, IDC_CPASSWORD, cpass, _countof(cpass));
- enable = mir_strlen(pass) && mir_strlen(cpass) && !mir_strcmp(cpass, pass);
- if (dat && dat->mode == GG_USERUTIL_REMOVE)
- EnableWindow(GetDlgItem(hwndDlg, IDOK), IsDlgButtonChecked(hwndDlg, IDC_CONFIRM) ? enable : FALSE);
- else
- EnableWindow(GetDlgItem(hwndDlg, IDOK), enable);
- break;
- }
-
- case IDOK:
- {
- char pass[128], cpass[128], email[128];
- GetDlgItemTextA(hwndDlg, IDC_PASSWORD, pass, _countof(pass));
- GetDlgItemTextA(hwndDlg, IDC_CPASSWORD, cpass, _countof(cpass));
- GetDlgItemTextA(hwndDlg, IDC_EMAIL, email, _countof(email));
- EndDialog(hwndDlg, IDOK);
-
- // Check dialog box mode
- if (!dat) break;
- switch (dat->mode)
- {
- case GG_USERUTIL_CREATE:
- gg_doregister(dat->gg, pass, email);
- break;
- case GG_USERUTIL_REMOVE:
- gg_dounregister(dat->gg, dat->uin, pass);
- break;
- case GG_USERUTIL_PASS:
- gg_dochpass(dat->gg, dat->uin, dat->pass, pass);
- break;
- case GG_USERUTIL_EMAIL:
- gg_dochemail(dat->gg, dat->uin, dat->pass, dat->email, email);
- break;
- }
- break;
- }
-
- case IDCANCEL:
- EndDialog(hwndDlg, IDCANCEL);
- break;
+ case GG_USERUTIL_CREATE:
+ gg_doregister(dat->gg, pass, email);
+ break;
+ case GG_USERUTIL_REMOVE:
+ gg_dounregister(dat->gg, dat->uin, pass);
+ break;
+ case GG_USERUTIL_PASS:
+ gg_dochpass(dat->gg, dat->uin, dat->pass, pass);
+ break;
+ case GG_USERUTIL_EMAIL:
+ gg_dochemail(dat->gg, dat->uin, dat->pass, dat->email, email);
+ break;
}
break;
+ }
- case WM_DESTROY:
- Window_FreeIcon_IcoLib(hwndDlg);
+ case IDCANCEL:
+ EndDialog(hwndDlg, IDCANCEL);
break;
+ }
+ break;
+
+ case WM_DESTROY:
+ Window_FreeIcon_IcoLib(hwndDlg);
+ break;
}
return FALSE;
}
@@ -282,9 +286,10 @@ INT_PTR CALLBACK gg_userutildlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
//
void GGPROTO::threadwait(GGTHREAD *thread)
{
- if (!thread->hThread) return;
+ if (!thread->hThread)
+ return;
while (WaitForSingleObjectEx(thread->hThread, INFINITE, TRUE) != WAIT_OBJECT_0);
+
CloseHandle(thread->hThread);
memset(thread, 0, sizeof(GGTHREAD));
}
-