From 087173d06f4848f19d186b6902d399ce9b7225e1 Mon Sep 17 00:00:00 2001 From: Goraf <22941576+Goraf@users.noreply.github.com> Date: Sat, 20 Jan 2018 16:25:13 +0100 Subject: Gadu-Gadu: code cleaning --- protocols/Gadu-Gadu/src/core.cpp | 61 ++++++++-------- protocols/Gadu-Gadu/src/dialogs.cpp | 2 +- protocols/Gadu-Gadu/src/dynstuff.h | 2 - protocols/Gadu-Gadu/src/filetransfer.cpp | 56 +++++++++------ protocols/Gadu-Gadu/src/gg.cpp | 12 ++-- protocols/Gadu-Gadu/src/gg.h | 25 +++---- protocols/Gadu-Gadu/src/gg_proto.cpp | 7 +- protocols/Gadu-Gadu/src/gg_proto.h | 9 +-- protocols/Gadu-Gadu/src/groupchat.cpp | 52 +++++++++----- protocols/Gadu-Gadu/src/icolib.cpp | 1 + protocols/Gadu-Gadu/src/image.cpp | 115 +++++++++++++++++++------------ protocols/Gadu-Gadu/src/import.cpp | 20 ++++-- protocols/Gadu-Gadu/src/keepalive.cpp | 1 + protocols/Gadu-Gadu/src/links.cpp | 4 +- protocols/Gadu-Gadu/src/oauth.cpp | 27 +++++--- protocols/Gadu-Gadu/src/ownerinfo.cpp | 10 +-- protocols/Gadu-Gadu/src/services.cpp | 5 ++ protocols/Gadu-Gadu/src/sessions.cpp | 7 +- protocols/Gadu-Gadu/src/token.cpp | 1 + protocols/Gadu-Gadu/src/userutils.cpp | 8 +-- 20 files changed, 255 insertions(+), 170 deletions(-) (limited to 'protocols/Gadu-Gadu') diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index e89ab034ea..008a073aad 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -151,10 +151,7 @@ void GGPROTO::disconnect() // DNS lookup function uint32_t gg_dnslookup(GGPROTO *gg, char *host) { - uint32_t ip; - struct hostent *he; - - ip = inet_addr(host); + uint32_t ip = inet_addr(host); if (ip != INADDR_NONE) { #ifdef DEBUGMODE @@ -162,7 +159,8 @@ uint32_t gg_dnslookup(GGPROTO *gg, char *host) #endif return ip; } - he = gethostbyname(host); + + hostent *he = gethostbyname(host); if (he) { ip = *(uint32_t *)he->h_addr_list[0]; @@ -172,17 +170,19 @@ uint32_t gg_dnslookup(GGPROTO *gg, char *host) #endif return ip; } + gg->debugLogA("gg_dnslookup(): Cannot resolve hostname \"%s\".", host); + return 0; } //////////////////////////////////////////////////////////// // Host list decoder -typedef struct +struct GGHOST { char hostname[128]; int port; -} GGHOST; +}; #define ISHOSTALPHA(a) (((a) >= '0' && (a) <= '9') || ((a) >= 'a' && (a) <= 'z') || (a) == '.' || (a) == '-') @@ -230,30 +230,20 @@ int gg_decodehosts(char *var, GGHOST *hosts, int max) // Main connection session thread void __cdecl GGPROTO::mainthread(void *) { - // Miranda variables - NETLIBUSERSETTINGS nlus = { 0 }; - DBVARIANT dbv; - // Gadu-Gadu variables - gg_login_params p = { 0 }; - gg_event *e; - struct gg_session *local_sess; - // Host cycling variables - int hostnum = 0, hostcount = 0; - GGHOST hosts[64]; // 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); @@ -270,6 +260,7 @@ void __cdecl GGPROTO::mainthread(void *) broadcastnewstatus(ID_STATUS_CONNECTING); // Client version and misc settings + gg_login_params p = { 0 }; p.client_version = GG_DEFAULT_CLIENT_VERSION; p.protocol_version = GG_DEFAULT_PROTOCOL_VERSION; p.protocol_features = GG_FEATURE_DND_FFC | GG_FEATURE_UNKNOWN_100 | GG_FEATURE_USER_DATA | GG_FEATURE_MSG_ACK | GG_FEATURE_TYPING_NOTIFICATION | GG_FEATURE_MULTILOGON; @@ -282,6 +273,7 @@ void __cdecl GGPROTO::mainthread(void *) p.era_omnix = getByte("EraOmnix", 0); // Setup proxy + NETLIBUSERSETTINGS nlus = { 0 }; nlus.cbSize = sizeof(nlus); if (Netlib_GetUserSettings(m_hNetlibUser, &nlus)) { if (nlus.useProxy) @@ -301,6 +293,10 @@ void __cdecl GGPROTO::mainthread(void *) } // Check out manual host setting + DBVARIANT dbv; + int hostcount = 0; + GGHOST hosts[64]; + if (getByte(GG_KEY_MANUALHOST, GG_KEYDEF_MANUALHOST)) { if (!getString(GG_KEY_SERVERHOSTS, &dbv)) { hostcount = gg_decodehosts(dbv.pszVal, hosts, 64); @@ -377,6 +373,8 @@ void __cdecl GGPROTO::mainthread(void *) if (dcc) p.client_port = dcc->port; + int hostnum = 0; + retry: // Loadup startup status & description gg_EnterCriticalSection(&modemsg_mutex, "mainthread", 13, "modemsg_mutex", 1); @@ -410,6 +408,7 @@ retry: } // Send login request + struct gg_session *local_sess; if (!(local_sess = gg_login(&p, &sock, &gg_failno))) { broadcastnewstatus(ID_STATUS_OFFLINE); // Check if connection attempt wasn't cancelled by the user @@ -450,7 +449,9 @@ retry: // Reconnect to the next server on the list if (bRetry) { - if (hostnum < hostcount - 1) hostnum++; + if (hostnum < hostcount - 1) + ++hostnum; + mir_free(p.status_descr); broadcastnewstatus(ID_STATUS_CONNECTING); goto retry; @@ -496,6 +497,8 @@ retry: ////////////////////////////////////////////////////////////////////////////////// // Main loop + gg_event *e; + while (isonline()) { // Connection broken/closed diff --git a/protocols/Gadu-Gadu/src/dialogs.cpp b/protocols/Gadu-Gadu/src/dialogs.cpp index 123f32b53e..96c272940f 100644 --- a/protocols/Gadu-Gadu/src/dialogs.cpp +++ b/protocols/Gadu-Gadu/src/dialogs.cpp @@ -166,7 +166,6 @@ void GGPROTO::checknewuser(uin_t uin, const char* passwd) { char oldpasswd[128]; DBVARIANT dbv; - uin_t olduin = (uin_t)getDword(GG_KEY_UIN, 0); oldpasswd[0] = '\0'; if (!getString(GG_KEY_PASSWORD, &dbv)) @@ -176,6 +175,7 @@ void GGPROTO::checknewuser(uin_t uin, const char* passwd) db_free(&dbv); } + uin_t olduin = (uin_t)getDword(GG_KEY_UIN, 0); if (uin > 0 && mir_strlen(passwd) > 0 && (uin != olduin || mir_strcmp(oldpasswd, passwd))) check_first_conn = 1; } diff --git a/protocols/Gadu-Gadu/src/dynstuff.h b/protocols/Gadu-Gadu/src/dynstuff.h index c176207076..8ec92ed4f8 100644 --- a/protocols/Gadu-Gadu/src/dynstuff.h +++ b/protocols/Gadu-Gadu/src/dynstuff.h @@ -1,5 +1,3 @@ -/* $Id: dynstuff.h 4366 2006-12-20 22:40:37Z ono $ */ - /* * (C) Copyright 2001-2002 Wojtek Kaniewski * Dawid Jarosz diff --git a/protocols/Gadu-Gadu/src/filetransfer.cpp b/protocols/Gadu-Gadu/src/filetransfer.cpp index d9a40be437..2876acea02 100644 --- a/protocols/Gadu-Gadu/src/filetransfer.cpp +++ b/protocols/Gadu-Gadu/src/filetransfer.cpp @@ -62,7 +62,6 @@ void GGPROTO::dccstart() void GGPROTO::dccconnect(uin_t uin) { - struct gg_dcc *local_dcc; MCONTACT hContact = getcontact(uin, 0, 0, nullptr); debugLogA("dccconnect(): Connecting to uin %d.", uin); @@ -79,7 +78,8 @@ void GGPROTO::dccconnect(uin_t uin) // If not port nor ip nor my uin (?) specified if (!ip || !port || !uin) return; - if (!(local_dcc = gg_dcc_get_file(ip, port, myuin, uin))) + gg_dcc *local_dcc = gg_dcc_get_file(ip, port, myuin, uin); + if (!local_dcc) return; // Add client dcc to watches @@ -131,23 +131,15 @@ HANDLE ftfail(GGPROTO *gg, MCONTACT hContact) // void __cdecl GGPROTO::dccmainthread(void*) { - uin_t uin; - gg_event *e; - struct timeval tv; - fd_set rd, wd; - int ret; - SOCKET maxfd; - DWORD tick; - list_t l; - char szFilename[MAX_PATH]; - // Zero up lists + list_t l; watches = transfers = requests = l = nullptr; debugLogA("dccmainthread(): started. DCC Server Thread Starting"); // Readup number - if (!(uin = getDword(GG_KEY_UIN, 0))) + uin_t uin = getDword(GG_KEY_UIN, 0); + if (!uin) { debugLogA("dccmainthread(): No Gadu-Gadu number specified. Exiting."); if (hEvent) SetEvent(hEvent); @@ -181,6 +173,14 @@ void __cdecl GGPROTO::dccmainthread(void*) list_add(&watches, dcc, 0); // Do while we are in the main server thread + gg_event *e; + timeval tv; + fd_set rd, wd; + int ret; + SOCKET maxfd; + DWORD tick; + char szFilename[MAX_PATH]; + while (pth_dcc.dwThreadId && dcc) { // Timeouts @@ -199,7 +199,8 @@ void __cdecl GGPROTO::dccmainthread(void*) continue; // Check if it's proper descriptor - if (w->fd == -1) continue; + if (w->fd == -1) + continue; if (w->fd > maxfd) maxfd = w->fd; @@ -219,6 +220,7 @@ void __cdecl GGPROTO::dccmainthread(void*) debugLogA("dccmainthread(): Bad descriptor on select()."); else if (errno != EINTR) debugLogA("dccmainthread(): Unknown error on select()."); + continue; } @@ -689,6 +691,7 @@ HANDLE GGPROTO::dccfileallow(HANDLE hTransfer, const wchar_t* szPath) ProtoBroadcastAck((UINT_PTR)dcc->contact, ACKTYPE_FILE, ACKRESULT_FAILED, dcc, 0); // Free transfer gg_free_dcc(dcc); + return nullptr; } @@ -707,7 +710,7 @@ HANDLE GGPROTO::dccfileallow(HANDLE hTransfer, const wchar_t* szPath) HANDLE GGPROTO::dcc7fileallow(HANDLE hTransfer, const wchar_t* szPath) { - struct gg_dcc7 *dcc7 = (struct gg_dcc7 *) hTransfer; + gg_dcc7 *dcc7 = (gg_dcc7 *) hTransfer; char fileName[MAX_PATH], *path = mir_u2a(szPath); mir_snprintf(fileName, "%s%s", path, dcc7->filename); dcc7->folder = _strdup((char*)path); @@ -725,6 +728,7 @@ HANDLE GGPROTO::dcc7fileallow(HANDLE hTransfer, const wchar_t* szPath) ProtoBroadcastAck((UINT_PTR)dcc7->contact, ACKTYPE_FILE, ACKRESULT_DENIED, dcc7, 0); // Free transfer gg_dcc7_free(dcc7); + return nullptr; } @@ -739,6 +743,7 @@ HANDLE GGPROTO::dcc7fileallow(HANDLE hTransfer, const wchar_t* szPath) ProtoBroadcastAck((UINT_PTR)dcc7->contact, ACKTYPE_FILE, ACKRESULT_FAILED, dcc7, 0); // Free transfer gg_dcc7_free(dcc7); + return nullptr; } @@ -758,7 +763,7 @@ HANDLE GGPROTO::dcc7fileallow(HANDLE hTransfer, const wchar_t* szPath) int GGPROTO::dccfiledeny(HANDLE hTransfer) { - struct gg_dcc *dcc = (struct gg_dcc *) hTransfer; + gg_dcc *dcc = (gg_dcc *) hTransfer; // Remove transfer from any list gg_EnterCriticalSection(&ft_mutex, "dccfiledeny", 42, "ft_mutex", 1); @@ -782,7 +787,7 @@ int GGPROTO::dccfiledeny(HANDLE hTransfer) int GGPROTO::dcc7filedeny(HANDLE hTransfer) { - struct gg_dcc7 *dcc7 = (struct gg_dcc7 *) hTransfer; + gg_dcc7 *dcc7 = (gg_dcc7 *) hTransfer; gg_dcc7_reject(dcc7, GG_DCC7_REJECT_USER); @@ -806,7 +811,7 @@ int GGPROTO::dcc7filedeny(HANDLE hTransfer) int GGPROTO::dccfilecancel(HANDLE hTransfer) { - struct gg_dcc *dcc = (struct gg_dcc *) hTransfer; + gg_dcc *dcc = (gg_dcc *) hTransfer; // Remove transfer from any list gg_EnterCriticalSection(&ft_mutex, "dccfilecancel", 44, "ft_mutex", 1); @@ -839,7 +844,7 @@ int GGPROTO::dccfilecancel(HANDLE hTransfer) int GGPROTO::dcc7filecancel(HANDLE hTransfer) { - struct gg_dcc7 *dcc7 = (struct gg_dcc7 *) hTransfer; + gg_dcc7 *dcc7 = (gg_dcc7 *) hTransfer; if (dcc7->type == GG_SESSION_DCC7_SEND && dcc7->state == GG_STATE_WAITING_FOR_ACCEPT) gg_dcc7_abort(dcc7); @@ -877,7 +882,7 @@ int GGPROTO::dcc7filecancel(HANDLE hTransfer) HANDLE GGPROTO::FileAllow(MCONTACT, HANDLE hTransfer, const wchar_t* szPath) { // Check if its proper dcc - struct gg_common *c = (struct gg_common *) hTransfer; + gg_common *c = (gg_common *) hTransfer; if (!c) return nullptr; @@ -893,7 +898,7 @@ HANDLE GGPROTO::FileAllow(MCONTACT, HANDLE hTransfer, const wchar_t* szPath) int GGPROTO::FileCancel(MCONTACT, HANDLE hTransfer) { // Check if its proper dcc - struct gg_common *c = (struct gg_common *) hTransfer; + gg_common *c = (gg_common *) hTransfer; if (!c) return 0; @@ -909,7 +914,7 @@ int GGPROTO::FileCancel(MCONTACT, HANDLE hTransfer) int GGPROTO::FileDeny(MCONTACT, HANDLE hTransfer, const wchar_t *) { // Check if its proper dcc - struct gg_common *c = (struct gg_common *) hTransfer; + gg_common *c = (gg_common *) hTransfer; if (!c) return 0; @@ -954,7 +959,9 @@ HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles if (!dcc7) { gg_LeaveCriticalSection(&sess_mutex, "SendFile", 46, 1, "sess_mutex", 1); debugLogA("SendFile(): Failed to send file \"%s\".", filename); + mir_free(filename); + return ftfail(this, hContact); } gg_LeaveCriticalSection(&sess_mutex, "SendFile", 46, 2, "sess_mutex", 1); @@ -974,7 +981,9 @@ HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles *(bslash + 1) = 0; else *(dcc7->folder) = 0; + mir_free(filename); + return dcc7; } @@ -983,6 +992,7 @@ HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles { debugLogA("SendFile(): Bad contact uin or my uin. Exit."); mir_free(filename); + return ftfail(this, hContact); } @@ -1011,6 +1021,7 @@ HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles debugLogA("SendFile(): Cannot open and file fileinfo \"%s\".", filename); gg_free_dcc(dcc); mir_free(filename); + return ftfail(this, hContact); } @@ -1032,5 +1043,6 @@ HANDLE GGPROTO::SendFile(MCONTACT hContact, const wchar_t *, wchar_t** ppszFiles *(dcc->folder) = 0; mir_free(filename); + return dcc; } diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp index 958d7a5bac..f437a5032a 100644 --- a/protocols/Gadu-Gadu/src/gg.cpp +++ b/protocols/Gadu-Gadu/src/gg.cpp @@ -45,10 +45,6 @@ CLIST_INTERFACE *pcli; int hLangpack; LIST g_Instances(1, PtrKeySortT); -// Event hooks -static HANDLE hHookModulesLoaded = nullptr; -static HANDLE hHookPreShutdown = nullptr; - static unsigned long crc_table[256]; ////////////////////////////////////////////////////////// @@ -67,6 +63,7 @@ wchar_t* ws_strerror(int code) mir_snwprintf(err_desc, L"WinSock %u: Unknown error.", WSAGetLastError()); else mir_snwprintf(err_desc, L"WinSock %d: %s", WSAGetLastError(), buff); + return err_desc; } @@ -87,6 +84,7 @@ char* as_strerror(int code) mir_snprintf(err_desc, "WinSock %u: Unknown error.", WSAGetLastError()); else mir_snprintf(err_desc, "WinSock %d: %s", WSAGetLastError(), buff); + return err_desc; } @@ -244,6 +242,7 @@ static int gg_prebuildcontactmenu(WPARAM hContact, LPARAM) Menu_ShowItem(gg->hBlockMenuItem, false); else Menu_ModifyItem(gg->hBlockMenuItem, gg->getByte(hContact, GG_KEY_BLOCK, 0) ? LPGENW("&Unblock") : LPGENW("&Block")); + return 0; } @@ -254,6 +253,7 @@ INT_PTR GGPROTO::blockuser(WPARAM hContact, LPARAM) { setByte(hContact, GG_KEY_BLOCK, !getByte(hContact, GG_KEY_BLOCK, 0)); notifyuser(hContact, 1); + return 0; } @@ -338,8 +338,7 @@ extern "C" int __declspec(dllexport) Load(void) mir_getLP(&pluginInfo); pcli = Clist_GetInterface(); - // Hook system events - hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, gg_modulesloaded); + HookEvent(ME_SYSTEM_MODULESLOADED, gg_modulesloaded); // Prepare protocol name PROTOCOLDESCRIPTOR pd = { 0 }; @@ -423,6 +422,7 @@ const char *ggdebug_eventtype(gg_event *e) 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; } diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h index 2a2bc879a4..5be2a69f04 100644 --- a/protocols/Gadu-Gadu/src/gg.h +++ b/protocols/Gadu-Gadu/src/gg.h @@ -31,8 +31,6 @@ #endif // Windows headers -// Visual C++ .NET tries to include winsock.h -// which is very ver bad #include #include #include @@ -43,7 +41,7 @@ #include #include -// Miranda IM headers +// Miranda NG headers #include #include #include @@ -69,18 +67,13 @@ #include #include #include - -// Custom profile folders plugin header -#include "m_folders.h" - -// Visual C++ extras -#define GGINLINE +#include // Plugin headers #include "resource.h" // libgadu headers -#include "libgadu/libgadu.h" +#include "libgadu.h" #include "dynstuff.h" // Search @@ -90,25 +83,25 @@ struct GGSEARCHRESULT : public PROTOSEARCHRESULT uin_t uin; }; -typedef struct +struct GGTHREAD { HANDLE hThread; UINT dwThreadId; -} GGTHREAD; +}; -typedef struct +struct GGGC { uin_t *recipients; int recipients_count; wchar_t id[32]; BOOL ignore; -} GGGC; +}; -typedef struct +struct GGTOKEN { char id[256]; char val[256]; -} GGTOKEN; +}; struct GGREQUESTAVATARDATA { diff --git a/protocols/Gadu-Gadu/src/gg_proto.cpp b/protocols/Gadu-Gadu/src/gg_proto.cpp index 74bfcbd60a..fbc1421b78 100644 --- a/protocols/Gadu-Gadu/src/gg_proto.cpp +++ b/protocols/Gadu-Gadu/src/gg_proto.cpp @@ -512,11 +512,11 @@ HWND GGPROTO::CreateExtendedSearchUI(HWND owner) MAKEINTRESOURCE(IDD_GGADVANCEDSEARCH), owner, gg_advancedsearchdlgproc, (LPARAM)this); } -typedef struct +struct GG_SEQ_ACK { MCONTACT hContact; int seq; -} GG_SEQ_ACK; +}; void __cdecl GGPROTO::sendackthread(void *ack) { @@ -553,6 +553,7 @@ int GGPROTO::SendMsg(MCONTACT hContact, int, const char *msg) ForkThread(&GGPROTO::sendackthread, ack); } } + return seq; } @@ -563,6 +564,7 @@ int GGPROTO::SetApparentMode(MCONTACT hContact, int mode) { setWord(hContact, GG_KEY_APPARENT, (WORD)mode); notifyuser(hContact, 1); + return 0; } @@ -741,5 +743,6 @@ int GGPROTO::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam) case EV_PROTO_DBSETTINGSCHANGED: return dbsettingchanged(wParam, lParam); } + return TRUE; } diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h index fc6c5de185..f1ffb37947 100644 --- a/protocols/Gadu-Gadu/src/gg_proto.h +++ b/protocols/Gadu-Gadu/src/gg_proto.h @@ -233,7 +233,7 @@ struct GGPROTO : public PROTO HANDLE hConnStopEvent; SOCKET sock; UINT_PTR timer; - struct + struct Modemsg { wchar_t *online; wchar_t *away; @@ -241,7 +241,8 @@ struct GGPROTO : public PROTO wchar_t *freechat; wchar_t *invisible; wchar_t *offline; - } modemsg; + }; + Modemsg modemsg; HGENMENU hMainMenu[7]; HGENMENU hBlockMenuItem, hImageMenuItem, hInstanceMenuItem; @@ -251,14 +252,14 @@ struct GGPROTO : public PROTO HANDLE hPopupNotify, hPopupError; }; -typedef struct +struct GGUSERUTILDLGDATA { int mode; uin_t uin; char *pass; char *email; GGPROTO *gg; -} GGUSERUTILDLGDATA; +}; #ifdef DEBUGMODE diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp index 47d97734bf..1736caf285 100644 --- a/protocols/Gadu-Gadu/src/groupchat.cpp +++ b/protocols/Gadu-Gadu/src/groupchat.cpp @@ -160,6 +160,7 @@ int GGPROTO::gc_event(WPARAM, LPARAM lParam) } else nickT = mir_wstrdup(TranslateT("Me")); + gce.ptszNick = nickT; // Get rid of CRLF at back @@ -208,11 +209,10 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou { list_t l; GGGC *chat; - wchar_t id[32]; - uin_t uin; debugLogA("gc_getchat(): Count %d.", recipients_count); - if (!recipients) return nullptr; + if (!recipients) + return nullptr; // Look for existing chat for (l = chats; l; l = l->next) @@ -222,9 +222,9 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou if (chat->recipients_count == recipients_count + (sender ? 1 : 0)) { - int i, j, found = 0, sok = (sender == 0); + int sok = (sender == 0); if (!sok) { - for (i = 0; i < chat->recipients_count; i++) { + for (int i = 0; i < chat->recipients_count; i++) { if (sender == chat->recipients[i]) { sok = 1; @@ -232,10 +232,14 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou } } } + + int found = 0; if (sok) - for (i = 0; i < chat->recipients_count; i++) - for (j = 0; j < recipients_count; j++) - if (recipients[j] == chat->recipients[i]) found++; + for (int i = 0; i < chat->recipients_count; i++) + for (int j = 0; j < recipients_count; j++) + if (recipients[j] == chat->recipients[i]) + ++found; + // Found all recipients if (found == recipients_count) { @@ -260,13 +264,17 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou unknownSender = unknown; 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))) + { 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)) || @@ -280,6 +288,7 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou senderName, recipients_count + 1, unknown); chat->ignore = MessageBox(nullptr, error, m_tszUserName, MB_OKCANCEL | MB_ICONEXCLAMATION) != IDOK; } + if (chat->ignore) { // Copy recipient list @@ -317,12 +326,15 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou // Add normal group Chat_AddGroup(m_szModuleName, chat->id, TranslateT("Participants")); + wchar_t id[32]; + GCEVENT gce = { m_szModuleName, chat->id, GC_EVENT_JOIN }; gce.ptszUID = id; gce.dwFlags = GCEF_ADDTOLOG; // Add myself - if (uin = getDword(GG_KEY_UIN, 0)) + uin_t uin = getDword(GG_KEY_UIN, 0); + if (uin) { UIN2IDT(uin, id); @@ -367,6 +379,7 @@ wchar_t* GGPROTO::gc_getchat(uin_t sender, uin_t *recipients, int recipients_cou debugLogW(L"gc_getchat(): Returning new chat window %s, count %d.", chat->id, chat->recipients_count); list_add(&chats, chat, 0); + return chat->id; } @@ -382,7 +395,8 @@ static MCONTACT gg_getsubcontact(GGPROTO* gg, MCONTACT hContact) return hMetaContact; } } - return NULL; + + return 0; } static void gg_gc_resetclistopts(HWND hwndList) @@ -396,8 +410,9 @@ static int gg_gc_countcheckmarks(HWND hwndList) for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) - count++; + ++count; } + return count; } @@ -442,7 +457,6 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa 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)) { @@ -452,8 +466,10 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa 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 (count > i) + i = count; + + wchar_t *chat = gg->gc_getchat(0, participants, count); if (chat) Chat_Control(gg->m_szModuleName, chat, WINDOW_VISIBLE); @@ -488,7 +504,8 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa uin_t uin; GGPROTO* gg = (GGPROTO*)GetWindowLongPtr(hwndDlg, DWLP_USER); - if (!gg) break; + if (!gg) + break; // Delete non-gg contacts for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { @@ -548,7 +565,8 @@ 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; + list_t l = chats; + BOOL cleared = FALSE; while (l) { GGGC *chat = (GGGC *)l->data; diff --git a/protocols/Gadu-Gadu/src/icolib.cpp b/protocols/Gadu-Gadu/src/icolib.cpp index 606435f25f..53d9ed7159 100644 --- a/protocols/Gadu-Gadu/src/icolib.cpp +++ b/protocols/Gadu-Gadu/src/icolib.cpp @@ -50,6 +50,7 @@ HICON LoadIconEx(const char* name, bool big) { char szSettingName[100]; mir_snprintf(szSettingName, "%s_%s", GGDEF_PROTO, name); + return IcoLib_GetIcon(szSettingName, big); } diff --git a/protocols/Gadu-Gadu/src/image.cpp b/protocols/Gadu-Gadu/src/image.cpp index df14a3e57f..7cb803d91d 100644 --- a/protocols/Gadu-Gadu/src/image.cpp +++ b/protocols/Gadu-Gadu/src/image.cpp @@ -47,7 +47,7 @@ typedef struct _GGIMAGEENTRY uint32_t crc32; } GGIMAGEENTRY; -typedef struct +struct GGIMAGEDLGDATA { MCONTACT hContact; HANDLE hEvent; @@ -58,7 +58,7 @@ typedef struct SIZE minSize; BOOL bReceiving; GGPROTO *gg; -} GGIMAGEDLGDATA; +}; // Prototypes int gg_img_remove(GGIMAGEDLGDATA *dat); @@ -79,6 +79,7 @@ int GGPROTO::img_init() // Receive image CreateProtoService(GGS_RECVIMAGE, &GGPROTO::img_recvimage); + return FALSE; } @@ -124,6 +125,7 @@ int GGPROTO::img_destroy() // Destroy list list_destroy(imagedlgs, 1); Menu_RemoveItem(hImageMenuItem); + return FALSE; } @@ -134,6 +136,7 @@ static int gg_img_releasepicture(void *img) { if (!img) return FALSE; + free(((GGIMAGEENTRY *)img)->lpszFileName); if (((GGIMAGEENTRY *)img)->hBitmap) DeleteObject(((GGIMAGEENTRY *)img)->hBitmap); @@ -159,14 +162,13 @@ int gg_img_paint(HWND hwnd, GGIMAGEENTRY *dat) if (dat->hBitmap) { - HDC hdcBmp = nullptr; BITMAP bmp; GetObject(dat->hBitmap, sizeof(bmp), &bmp); int nWidth = bmp.bmWidth; int nHeight = bmp.bmHeight; - hdcBmp = CreateCompatibleDC(hdc); + HDC hdcBmp = CreateCompatibleDC(hdc); SelectObject(hdcBmp, dat->hBitmap); if (hdcBmp) { @@ -214,14 +216,12 @@ int gg_img_paint(HWND hwnd, GGIMAGEENTRY *dat) // wchar_t *gg_img_getfilter(wchar_t *szFilter, int nSize) { - wchar_t *szFilterName, *szFilterMask; - wchar_t *pFilter = szFilter; - // Match relative to ImgDecoder presence - szFilterName = TranslateT("Image files (*.bmp,*.gif,*.jpeg,*.jpg,*.png)"); - szFilterMask = L"*.bmp;*.gif;*.jpeg;*.jpg;*.png"; + wchar_t *szFilterName = TranslateT("Image files (*.bmp,*.gif,*.jpeg,*.jpg,*.png)"); + wchar_t *szFilterMask = L"*.bmp;*.gif;*.jpeg;*.jpg;*.png"; // Make up filter + wchar_t *pFilter = szFilter; wcsncpy(pFilter, szFilterName, nSize); pFilter += mir_wstrlen(pFilter) + 1; if (pFilter >= szFilter + nSize) @@ -286,38 +286,39 @@ int gg_img_saveimage(HWND hwnd, GGIMAGEENTRY *dat) BOOL gg_img_fit(HWND hwndDlg) { GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - RECT dlgRect, imgRect, wrkRect; - int rWidth = 0, rHeight = 0; - int oWidth = 0, oHeight = 0; - BITMAP bmp; - GGIMAGEENTRY *img = nullptr; - HDC hdc; // Check if image is loaded if (!dat || !dat->lpImages || !dat->lpImages->hBitmap) return FALSE; - img = dat->lpImages; + GGIMAGEENTRY *img = dat->lpImages; // Go to last image while (img->lpNext && dat->lpImages->hBitmap) img = img->lpNext; // Get rects of display + RECT dlgRect, imgRect; GetWindowRect(hwndDlg, &dlgRect); GetClientRect(GetDlgItem(hwndDlg, IDC_IMG_IMAGE), &imgRect); - hdc = GetDC(hwndDlg); + HDC hdc = GetDC(hwndDlg); + BITMAP bmp; GetObject(img->hBitmap, sizeof(bmp), &bmp); int nWidth = bmp.bmWidth; int nHeight = bmp.bmHeight; + + RECT wrkRect; SystemParametersInfo(SPI_GETWORKAREA, 0, &wrkRect, 0); ReleaseDC(hwndDlg, hdc); + int rWidth = 0; if ((imgRect.right - imgRect.left) < nWidth) rWidth = nWidth - imgRect.right + imgRect.left; + + int rHeight = 0; if ((imgRect.bottom - imgRect.top) < nHeight) rHeight = nHeight - imgRect.bottom + imgRect.top; @@ -325,8 +326,8 @@ BOOL gg_img_fit(HWND hwndDlg) if (!rWidth && !rHeight) return FALSE; - oWidth = dlgRect.right - dlgRect.left + rWidth; - oHeight = dlgRect.bottom - dlgRect.top + rHeight; + int oWidth = dlgRect.right - dlgRect.left + rWidth; + int oHeight = dlgRect.bottom - dlgRect.top + rHeight; if (oHeight > wrkRect.bottom - wrkRect.top) { @@ -371,6 +372,7 @@ static int sttImageDlgResizer(HWND, LPARAM, UTILRESIZECONTROL *urc) case IDC_IMG_CANCEL: return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM; } + return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; } @@ -396,8 +398,10 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP 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."); + 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); @@ -502,6 +506,7 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP } else SetDlgItemText(hwndDlg, IDC_IMG_NAME, img->lpszFileName); + gg_img_paint(hwndDlg, img); } break; @@ -605,28 +610,24 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP 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; + ((gg_msg_richtext*)format)->flag = 2; - ((struct gg_msg_richtext*)format)->flag = 2; - - r = (struct gg_msg_richtext_format *)(format + sizeof(struct gg_msg_richtext)); + gg_msg_richtext_format *r = (gg_msg_richtext_format *)(format + sizeof(struct gg_msg_richtext)); r->position = 0; r->font = GG_FONT_IMAGE; - p = (struct gg_msg_richtext_image *)(format + sizeof(struct gg_msg_richtext) + sizeof(struct gg_msg_richtext_format)); + gg_msg_richtext_image *p = (gg_msg_richtext_image *)(format + sizeof(struct gg_msg_richtext) + sizeof(struct gg_msg_richtext_format)); p->unknown1 = 0x109; p->size = dat->lpImages->nSize; dat->lpImages->crc32 = p->crc32 = gg_fix32(gg_crc32(0, (BYTE*)dat->lpImages->lpData, dat->lpImages->nSize)); - len = sizeof(struct gg_msg_richtext_format) + sizeof(struct gg_msg_richtext_image); - ((struct gg_msg_richtext*)format)->length = len; + int len = sizeof(struct gg_msg_richtext_format) + sizeof(struct gg_msg_richtext_image); + ((gg_msg_richtext*)format)->length = len; + uin_t uin = (uin_t)gg->getDword(dat->hContact, GG_KEY_UIN, 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_send_message_richtext(gg->sess, GG_CLASS_CHAT, 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); // Protect dat from releasing @@ -705,16 +706,16 @@ static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LP // void __cdecl GGPROTO::img_dlgcallthread(void *param) { - HWND hMIWnd = nullptr; - debugLogA("img_dlgcallthread(): started."); + + HWND hMIWnd = nullptr; GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)param; DialogBoxParam(hInstance, dat->bReceiving ? MAKEINTRESOURCE(IDD_IMAGE_RECV) : MAKEINTRESOURCE(IDD_IMAGE_SEND), hMIWnd, gg_img_dlgproc, (LPARAM)dat); + #ifdef DEBUGMODE debugLogA("img_dlgcallthread(): end."); #endif - } //////////////////////////////////////////////////////////////////////////// @@ -733,6 +734,7 @@ GGIMAGEDLGDATA *gg_img_recvdlg(GGPROTO *gg, MCONTACT hContact) gg->debugLogA("gg_img_recvdlg(): ForkThread 18 GGPROTO::img_dlgcallthread"); #endif gg->ForkThread(&GGPROTO::img_dlgcallthread, dat); + return dat; } @@ -790,6 +792,7 @@ wchar_t *gg_img_hasextension(wchar_t *filename) return --imgtype; } } + return nullptr; } @@ -798,10 +801,8 @@ wchar_t *gg_img_hasextension(wchar_t *filename) // int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img) { - GGIMAGEENTRY *dat = (GGIMAGEENTRY *)img; - wchar_t szPath[MAX_PATH], path[MAX_PATH], *pImgext, imgext[6]; + wchar_t szPath[MAX_PATH], path[MAX_PATH]; size_t tPathLen; - int res; if (hImagesFolder == nullptr || FoldersGetCustomPathT(hImagesFolder, path, MAX_PATH, L"")) { wchar_t *tmpPath = Utils_ReplaceVarsW(L"%miranda_userdata%"); @@ -826,13 +827,22 @@ int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img) } } + GGIMAGEENTRY *dat = (GGIMAGEENTRY *)img; mir_snwprintf(szPath + tPathLen, MAX_PATH - tPathLen, L"\\%s", dat->lpszFileName); - if ((pImgext = gg_img_hasextension(szPath)) == nullptr) + wchar_t *pImgext = gg_img_hasextension(szPath); + if (pImgext == nullptr) pImgext = szPath + mir_wstrlen(szPath); + + wchar_t imgext[6]; wcsncpy_s(imgext, pImgext, _TRUNCATE); + + int res = -1; for (int i = 1; ; i++) { - if ((res = gg_img_isexists(szPath, dat)) != -1) break; + res = gg_img_isexists(szPath, dat); + if (res != -1) + break; + mir_snwprintf(szPath, L"%.*s (%u)%s", pImgext - szPath, szPath, i, imgext); } @@ -848,6 +858,7 @@ int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img) wchar_t error[512]; mir_snwprintf(error, TranslateT("Cannot save received image to file. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szPath); showpopup(m_tszUserName, error, GG_POPUP_ERROR); + return 0; } } @@ -880,8 +891,10 @@ BOOL GGPROTO::img_opened(uin_t uin) GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)l->data; if (dat->uin == uin) return TRUE; + l = l->next; } + return FALSE; } @@ -893,7 +906,8 @@ int GGPROTO::img_display(MCONTACT hContact, void *img) list_t l = imagedlgs; GGIMAGEDLGDATA *dat = nullptr; - if (!img) return FALSE; + if (!img) + return FALSE; // Look for already open dialog gg_EnterCriticalSection(&img_mutex, "img_display", 60, "img_mutex", 1); @@ -902,10 +916,12 @@ int GGPROTO::img_display(MCONTACT hContact, void *img) dat = (GGIMAGEDLGDATA *)l->data; if (dat->bReceiving && dat->hContact == hContact) break; + l = l->next; } - if (!l) dat = nullptr; + if (!l) + dat = nullptr; if (!dat) { @@ -913,6 +929,7 @@ int GGPROTO::img_display(MCONTACT hContact, void *img) dat->uin = getDword(hContact, GG_KEY_UIN, 0); while (WaitForSingleObjectEx(dat->hEvent, INFINITE, TRUE) != WAIT_OBJECT_0); + CloseHandle(dat->hEvent); dat->hEvent = nullptr; @@ -923,7 +940,9 @@ int GGPROTO::img_display(MCONTACT hContact, void *img) SendMessage(dat->hWnd, WM_ADDIMAGE, 0, (LPARAM)img); if (/*db_get_b(NULL, "Chat", "bFlashWindowHighlight", 0) != 0 && */ GetActiveWindow() != dat->hWnd && GetForegroundWindow() != dat->hWnd) + { SetTimer(dat->hWnd, TIMERID_FLASHWND, 900, nullptr); + } return TRUE; } @@ -944,6 +963,7 @@ const wchar_t *gg_img_guessfileextension(const char *lpData) if (memcmp(lpData, "\x89PNG", 4) == 0) return L".png"; } + return L""; } @@ -972,6 +992,7 @@ void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName) showpopup(m_tszUserName, error, GG_POPUP_ERROR); return nullptr; } + fseek(fp, 0, SEEK_END); dat->nSize = ftell(fp); if (dat->nSize <= 0) @@ -981,6 +1002,7 @@ void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName) debugLogW(L"img_loadpicture(): Zero file size \"%s\" failed.", szFileName); return nullptr; } + // Maximum acceptable image size if (dat->nSize > 255 * 1024) { @@ -990,6 +1012,7 @@ void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName) MessageBox(nullptr, TranslateT("Image exceeds maximum allowed size of 255 KB."), m_tszUserName, MB_OK | MB_ICONEXCLAMATION); return nullptr; } + fseek(fp, 0, SEEK_SET); dat->lpData = (char*)malloc(dat->nSize); if (fread(dat->lpData, 1, dat->nSize, fp) < dat->nSize) @@ -1000,6 +1023,7 @@ void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName) debugLogW(L"img_loadpicture(): Reading file \"%s\" failed.", szFileName); return nullptr; } + fclose(fp); dat->lpszFileName = wcsdup(szFileName); } @@ -1055,6 +1079,7 @@ void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName) free(dat->lpszFileName); free(dat); } + return nullptr; } @@ -1087,7 +1112,9 @@ int gg_img_remove(GGIMAGEDLGDATA *dat) GGIMAGEENTRY *temp = nullptr, *img = nullptr; GGPROTO *gg; - if (!dat) return FALSE; + if (!dat) + return FALSE; + gg = dat->gg; gg->gg_EnterCriticalSection(&gg->img_mutex, "gg_img_remove", 61, "img_mutex", 1); @@ -1136,6 +1163,7 @@ GGIMAGEDLGDATA* gg_img_find(GGPROTO *gg, uin_t uin, uint32_t crc32) gg->gg_LeaveCriticalSection(&gg->img_mutex, "gg_img_find", 62, 2, "img_mutex", 1); gg->debugLogA("gg_img_find(): Image not found on the list. It might be released before calling this function."); + return nullptr; } @@ -1183,6 +1211,7 @@ INT_PTR GGPROTO::img_sendimg(WPARAM hContact, LPARAM) ForkThread(&GGPROTO::img_dlgcallthread, dat); while (WaitForSingleObjectEx(dat->hEvent, INFINITE, TRUE) != WAIT_OBJECT_0); + CloseHandle(dat->hEvent); dat->hEvent = nullptr; diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index ed405fb0f0..076af51c6b 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -120,6 +120,7 @@ char *strndup(char *str, int c) char *ret = (char*)malloc(c + 1); ret[c] = 0; strncpy(ret, str, c); + return ret; } @@ -342,14 +343,14 @@ INT_PTR GGPROTO::remove_server(WPARAM, LPARAM) INT_PTR GGPROTO::import_text(WPARAM, LPARAM) { wchar_t str[MAX_PATH]; - wchar_t filter[512], *pfilter; + wchar_t filter[512]; struct _stat st; 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)); - pfilter = filter + mir_wstrlen(filter) + 1; + wchar_t *pfilter = filter + mir_wstrlen(filter) + 1; if (pfilter >= filter + _countof(filter)) return 0; @@ -415,33 +416,38 @@ INT_PTR GGPROTO::import_text(WPARAM, LPARAM) INT_PTR GGPROTO::export_text(WPARAM, LPARAM) { - wchar_t str[MAX_PATH]; - OPENFILENAME ofn = { 0 }; - wchar_t filter[512], *pfilter; + wchar_t str[MAX_PATH]; wcsncpy(str, TranslateT("contacts"), _countof(str)); mir_wstrncat(str, L".txt", _countof(str) - mir_wstrlen(str)); - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + wchar_t filter[512]; wcsncpy(filter, TranslateT("Text files"), _countof(filter)); mir_wstrncat(filter, L" (*.txt)", _countof(filter) - mir_wstrlen(filter)); - pfilter = filter + mir_wstrlen(filter) + 1; + wchar_t *pfilter = filter + mir_wstrlen(filter) + 1; if (pfilter >= filter + _countof(filter)) return 0; + wcsncpy(pfilter, L"*.TXT", _countof(filter) - (pfilter - filter)); pfilter = pfilter + mir_wstrlen(pfilter) + 1; if (pfilter >= filter + _countof(filter)) return 0; + wcsncpy(pfilter, TranslateT("All Files"), _countof(filter) - (pfilter - filter)); mir_wstrncat(pfilter, L" (*)", _countof(filter) - (pfilter - filter) - mir_wstrlen(pfilter)); pfilter = pfilter + mir_wstrlen(pfilter) + 1; if (pfilter >= filter + _countof(filter)) return 0; + wcsncpy(pfilter, L"*", _countof(filter) - (pfilter - filter)); pfilter = pfilter + mir_wstrlen(pfilter) + 1; if (pfilter >= filter + _countof(filter)) return 0; + *pfilter = '\0'; + + OPENFILENAME ofn = { 0 }; + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; ofn.lpstrFilter = filter; ofn.lpstrFile = str; ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; diff --git a/protocols/Gadu-Gadu/src/keepalive.cpp b/protocols/Gadu-Gadu/src/keepalive.cpp index f6b70dd07f..df01face9c 100644 --- a/protocols/Gadu-Gadu/src/keepalive.cpp +++ b/protocols/Gadu-Gadu/src/keepalive.cpp @@ -56,6 +56,7 @@ void GGPROTO::keepalive_init() { int i; for (i = 0; i < MAX_TIMERS && g_timers[i] != nullptr; i++); + if (i < MAX_TIMERS) { #ifdef DEBUGMODE diff --git a/protocols/Gadu-Gadu/src/links.cpp b/protocols/Gadu-Gadu/src/links.cpp index 6caf12722e..e8622cad4b 100644 --- a/protocols/Gadu-Gadu/src/links.cpp +++ b/protocols/Gadu-Gadu/src/links.cpp @@ -33,6 +33,7 @@ static INT_PTR gg_menuchoose(WPARAM wParam, LPARAM lParam) { if (lParam) *(void**)lParam = (void*)wParam; + return 0; } @@ -66,7 +67,8 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam) ++items; Menu_ModifyItem(gg->hInstanceMenuItem, nullptr, Skin_LoadProtoIcon(gg->m_szModuleName, gg->m_iStatus)); } - else Menu_ShowItem(gg->hInstanceMenuItem, false); + else + Menu_ShowItem(gg->hInstanceMenuItem, false); } if (items > 1) { diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp index 186c34e8f7..a38e3ad7d5 100644 --- a/protocols/Gadu-Gadu/src/oauth.cpp +++ b/protocols/Gadu-Gadu/src/oauth.cpp @@ -31,18 +31,18 @@ // RSA-SHA1 signature method (see RFC 3447 section 8.2 // and RSASSA-PKCS1-v1_5 algorithm) is unimplemented -typedef struct +struct OAUTHPARAMETER { char *name; char *value; -} OAUTHPARAMETER; +}; -typedef enum +enum OAUTHSIGNMETHOD { HMACSHA1, RSASHA1, PLAINTEXT -} OAUTHSIGNMETHOD; +}; static int paramsortFunc(const OAUTHPARAMETER *p1, const OAUTHPARAMETER *p2) { @@ -228,6 +228,7 @@ char* oauth_generate_nonce() BYTE digest[16]; mir_md5_hash((BYTE*)str.GetString(), str.GetLength(), digest); + return bin2hex(digest, sizeof(digest), (char *)mir_alloc(32 + 1)); } @@ -244,9 +245,17 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD 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)); oauth_setparam(oauth_parameters, "oauth_timestamp", timestamp); @@ -284,7 +293,7 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD int GGPROTO::oauth_receivetoken() { - char szUrl[256], uin[32], *str, *token = nullptr, *token_secret = nullptr; + char szUrl[256], uin[32], *token = nullptr, *token_secret = nullptr; int res = 0; HNETLIBCONN nlc = nullptr; @@ -294,7 +303,7 @@ int GGPROTO::oauth_receivetoken() // 1. Obtaining an Unauthorized Request Token debugLogA("oauth_receivetoken(): Obtaining an Unauthorized Request Token..."); mir_strcpy(szUrl, "http://api.gadu-gadu.pl/request_token"); - str = oauth_auth_header("POST", szUrl, HMACSHA1, uin, password, nullptr, nullptr); + char *str = oauth_auth_header("POST", szUrl, HMACSHA1, uin, password, nullptr, nullptr); NETLIBHTTPHEADER httpHeaders[3]; httpHeaders[0].szName = "User-Agent"; diff --git a/protocols/Gadu-Gadu/src/ownerinfo.cpp b/protocols/Gadu-Gadu/src/ownerinfo.cpp index da6a5718c9..86928a99e5 100644 --- a/protocols/Gadu-Gadu/src/ownerinfo.cpp +++ b/protocols/Gadu-Gadu/src/ownerinfo.cpp @@ -20,11 +20,11 @@ #include "gg.h" -typedef struct +struct GG_REMIND_PASS { uin_t uin; const char *email; -} GG_REMIND_PASS; +}; ////////////////////////////////////////////////////////// // remind password @@ -32,9 +32,7 @@ typedef struct void __cdecl GGPROTO::remindpasswordthread(void *param) { // Connection handle - struct gg_http *h; GG_REMIND_PASS *rp = (GG_REMIND_PASS *)param; - GGTOKEN token; debugLogA("remindpasswordthread(): Started."); if (!rp || !rp->email || !rp->uin || !mir_strlen(rp->email)) @@ -47,6 +45,7 @@ void __cdecl GGPROTO::remindpasswordthread(void *param) } // Get token + GGTOKEN token; if (!gettoken(&token)) { #ifdef DEBUGMODE debugLogA("remindpasswordthread(): End. err2"); @@ -54,7 +53,8 @@ void __cdecl GGPROTO::remindpasswordthread(void *param) return; } - if (!(h = gg_remind_passwd3(rp->uin, rp->email, token.id, token.val, 0))) + gg_http *h = gg_remind_passwd3(rp->uin, rp->email, token.id, token.val, 0); + if (!h) { wchar_t error[128]; mir_snwprintf(error, TranslateT("Password could not be reminded because of error:\n\t%s (Error: %d)"), ws_strerror(errno), errno); diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp index c5ee323b29..0947a24906 100644 --- a/protocols/Gadu-Gadu/src/services.cpp +++ b/protocols/Gadu-Gadu/src/services.cpp @@ -43,6 +43,7 @@ char *gg_status2db(int status, const char *suffix) static char str[64]; mir_snprintf(str, "%s%s", prefix, suffix); + return str; } @@ -137,6 +138,7 @@ int gg_normalizestatus(int status) case ID_STATUS_OFFLINE: return ID_STATUS_OFFLINE; case ID_STATUS_INVISIBLE: return ID_STATUS_INVISIBLE; } + return ID_STATUS_AWAY; } @@ -162,6 +164,7 @@ INT_PTR GGPROTO::getavatarcaps(WPARAM wParam, LPARAM lParam) case AF_FETCHIFCONTACTOFFLINE: return 1; } + return 0; } @@ -347,6 +350,7 @@ INT_PTR GGPROTO::setmyavatar(WPARAM, LPARAM lParam) } setAvatar(szMyFilename); + return 0; } @@ -363,6 +367,7 @@ INT_PTR GGPROTO::getmyawaymsg(WPARAM wParam, LPARAM lParam) if (isonline() && szMsg) res = (lParam & SGMA_UNICODE) ? (INT_PTR)mir_wstrdup(szMsg) : (INT_PTR)mir_u2a(szMsg); gg_LeaveCriticalSection(&modemsg_mutex, "refreshstatus", 72, 1, "modemsg_mutex", 1); + return res; } diff --git a/protocols/Gadu-Gadu/src/sessions.cpp b/protocols/Gadu-Gadu/src/sessions.cpp index 52ad6f1efa..5c3396d035 100644 --- a/protocols/Gadu-Gadu/src/sessions.cpp +++ b/protocols/Gadu-Gadu/src/sessions.cpp @@ -86,11 +86,11 @@ static int gg_insertlistitem(HWND hList, gg_multilogon_id_t* id, const char* cli static void gg_listsessions(GGPROTO* gg, HWND hwndDlg) { HWND hList = GetDlgItem(hwndDlg, IDC_SESSIONS); - list_t l; - if (!hList) return; + list_t l; + gg->gg_EnterCriticalSection(&gg->sessions_mutex, "gg_listsessions", 73, "sessions_mutex", 1); for (l = gg->sessions; l; l = l->next) { @@ -104,6 +104,7 @@ static void gg_listsessions(GGPROTO* gg, HWND hwndDlg) gg_insertlistitem(hList, &sess->id, sess->name, ip, loginTime); } gg->gg_LeaveCriticalSection(&gg->sessions_mutex, "gg_listsessions", 73, 1, "sessions_mutex", 1); + EnableWindow(GetDlgItem(hwndDlg, IDC_SIGNOUTALL), ListView_GetItemCount(hList) > 0); } @@ -384,6 +385,7 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w break; } } + return FALSE; } @@ -410,6 +412,7 @@ BOOL GGPROTO::sessions_closedlg() { if (hwndSessionsDlg && IsWindow(hwndSessionsDlg)) return PostMessage(hwndSessionsDlg, WM_CLOSE, 0, 0); + return FALSE; } diff --git a/protocols/Gadu-Gadu/src/token.cpp b/protocols/Gadu-Gadu/src/token.cpp index 5ac569e9e2..6dc91860ca 100644 --- a/protocols/Gadu-Gadu/src/token.cpp +++ b/protocols/Gadu-Gadu/src/token.cpp @@ -99,6 +99,7 @@ INT_PTR CALLBACK gg_tokendlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l return 0; } } + return FALSE; } diff --git a/protocols/Gadu-Gadu/src/userutils.cpp b/protocols/Gadu-Gadu/src/userutils.cpp index 771fd60890..6c5dec1799 100644 --- a/protocols/Gadu-Gadu/src/userutils.cpp +++ b/protocols/Gadu-Gadu/src/userutils.cpp @@ -135,8 +135,8 @@ void *gg_dochpass(GGPROTO *gg, uin_t uin, char *password, char *newPass) if (!gg->gettoken(&token)) return nullptr; - struct gg_http *h; - struct gg_pubdir *s = nullptr; + gg_http *h; + 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]; @@ -177,8 +177,8 @@ void *gg_dochemail(GGPROTO *gg, uin_t uin, char *password, char *email, char *ne return nullptr; // Connection handles - struct gg_pubdir *s = nullptr; - struct gg_http *h = gg_change_passwd4(uin, newEmail, password, password, token.id, token.val, 0); + gg_pubdir *s = nullptr; + gg_http *h = gg_change_passwd4(uin, newEmail, password, password, token.id, token.val, 0); if (!h || !(s = (gg_pubdir*)h->data) || !s->success) { wchar_t error[128]; -- cgit v1.2.3