summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-04-08 22:01:14 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-04-08 22:01:14 +0000
commit0e830877dda255b570b9939ba92727a323987448 (patch)
treecbdacf572c14341494979632422431831a6c9717 /src
parent2e6e01bc25249ff2ac70bf99bbe384f86141dc91 (diff)
fixes for errors from Coverity
git-svn-id: http://svn.miranda-ng.org/main/trunk@12687 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/modules/netlib/netlibupnp.cpp249
-rw-r--r--src/modules/options/descbutton.cpp134
-rw-r--r--src/modules/options/options.cpp36
-rw-r--r--src/modules/plugins/newplugins.cpp29
4 files changed, 187 insertions, 261 deletions
diff --git a/src/modules/netlib/netlibupnp.cpp b/src/modules/netlib/netlibupnp.cpp
index d85a8a736e..3ab139cf30 100644
--- a/src/modules/netlib/netlibupnp.cpp
+++ b/src/modules/netlib/netlibupnp.cpp
@@ -168,27 +168,23 @@ void parseURL(char* szUrl, char* szHost, unsigned short* sPort, char* szPath)
pport = strchr(phost, ':');
if (pport == NULL) pport = ppath;
- if (szHost != NULL)
- {
+ if (szHost != NULL) {
sz = pport - phost + 1;
- if (sz>256) sz = 256;
+ if (sz > 256) sz = 256;
strncpy(szHost, phost, sz);
- szHost[sz-1] = 0;
+ szHost[sz - 1] = 0;
}
- if (sPort != NULL)
- {
- if (pport < ppath)
- {
- long prt = atol(pport+1);
+ if (sPort != NULL) {
+ if (pport < ppath) {
+ long prt = atol(pport + 1);
*sPort = prt != 0 ? (unsigned short)prt : 80;
}
else
*sPort = 80;
}
- if (szPath != NULL)
- {
+ if (szPath != NULL) {
strncpy(szPath, ppath, 256);
szPath[255] = 0;
}
@@ -201,8 +197,7 @@ static void LongLog(char* szData)
static void closeRouterConnection(void)
{
- if (sock != INVALID_SOCKET)
- {
+ if (sock != INVALID_SOCKET) {
closesocket(sock);
sock = INVALID_SOCKET;
}
@@ -221,8 +216,7 @@ static void validateSocket(void)
FD_ZERO(&rfd);
FD_SET(sock, &rfd);
- switch (select(1, &rfd, NULL, NULL, &tv))
- {
+ switch (select(1, &rfd, NULL, NULL, &tv)) {
case SOCKET_ERROR:
opened = false;
break;
@@ -259,41 +253,39 @@ static int httpTransact(char* szUrl, char* szResult, int resSize, char* szAction
else
validateSocket();
- while(true)
- {
+ while (true) {
retryCount = 0;
- switch(reqtype)
- {
+ switch (reqtype) {
case DeviceGetReq:
- sz = mir_snprintf (szData, 4096, xml_get_hdr, szPath, szHost, sPort);
+ sz = mir_snprintf(szData, 4096, xml_get_hdr, szPath, szHost, sPort);
break;
case ControlAction:
- {
- char szData1[1024];
+ {
+ char szData1[1024];
- szReq = mir_strdup(szResult);
- sz = mir_snprintf (szData1, SIZEOF(szData1),
- soap_action, szActionName, szDev, szReq, szActionName);
+ szReq = mir_strdup(szResult);
+ sz = mir_snprintf(szData1, SIZEOF(szData1),
+ soap_action, szActionName, szDev, szReq, szActionName);
- sz = mir_snprintf (szData, 4096,
- szPostHdr, szPath, szHost, sPort,
- sz, szDev, szActionName, szData1);
- }
- break;
+ sz = mir_snprintf(szData, 4096,
+ szPostHdr, szPath, szHost, sPort,
+ sz, szDev, szActionName, szData1);
+ }
+ break;
case ControlQuery:
- {
- char szData1[1024];
+ {
+ char szData1[1024];
- sz = mir_snprintf (szData1, SIZEOF(szData1),
- soap_query, szActionName);
+ sz = mir_snprintf(szData1, SIZEOF(szData1),
+ soap_query, szActionName);
- sz = mir_snprintf (szData, 4096,
- szPostHdr, szPath, szHost, sPort,
- sz, "urn:schemas-upnp-org:control-1-0", "QueryStateVariable", szData1);
- }
- break;
+ sz = mir_snprintf(szData, 4096,
+ szPostHdr, szPath, szHost, sPort,
+ sz, "urn:schemas-upnp-org:control-1-0", "QueryStateVariable", szData1);
+ }
+ break;
}
szResult[0] = 0;
{
@@ -304,8 +296,7 @@ static int httpTransact(char* szUrl, char* szResult, int resSize, char* szAction
SOCKADDR_IN enetaddr;
retrycon:
- if (sock == INVALID_SOCKET)
- {
+ if (sock == INVALID_SOCKET) {
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
enetaddr.sin_family = AF_INET;
@@ -313,8 +304,7 @@ retrycon:
enetaddr.sin_addr.s_addr = inet_addr(szHost);
// Resolve host name if needed
- if (enetaddr.sin_addr.s_addr == INADDR_NONE)
- {
+ if (enetaddr.sin_addr.s_addr == INADDR_NONE) {
PHOSTENT he = gethostbyname(szHost);
if (he)
enetaddr.sin_addr.s_addr = *(unsigned*)he->h_addr_list[0];
@@ -332,26 +322,22 @@ retrycon:
ioctlsocket(sock, FIONBIO, &mode);
// Connect to the remote host
- if (connect(sock, (SOCKADDR*)&enetaddr, sizeof(enetaddr)) == SOCKET_ERROR)
- {
+ if (connect(sock, (SOCKADDR*)&enetaddr, sizeof(enetaddr)) == SOCKET_ERROR) {
int err = WSAGetLastError();
// Socket connection failed
- if (err != WSAEWOULDBLOCK)
- {
+ if (err != WSAEWOULDBLOCK) {
closeRouterConnection();
NetlibLogf(NULL, "UPnP connect failed %d", err);
break;
}
// Wait for socket to connect
- else if (select(1, &rfd, &wfd, &efd, &tv) != 1)
- {
+ else if (select(1, &rfd, &wfd, &efd, &tv) != 1) {
closeRouterConnection();
NetlibLogf(NULL, "UPnP connect timeout");
break;
}
- else if (!FD_ISSET(sock, &wfd))
- {
+ else if (!FD_ISSET(sock, &wfd)) {
closeRouterConnection();
NetlibLogf(NULL, "UPnP connect failed");
break;
@@ -360,17 +346,14 @@ retrycon:
strcpy(szConnHost, szHost); sConnPort = sPort;
}
- if (send(sock, szData, sz, 0) != SOCKET_ERROR)
- {
+ if (send(sock, szData, sz, 0) != SOCKET_ERROR) {
char *hdrend = NULL;
int acksz = 0, pktsz = 0;
- if (szActionName == NULL)
- {
+ if (szActionName == NULL) {
int len = sizeof(locIP);
getsockname(sock, (SOCKADDR*)&locIP, &len);
- if (locIP.sin_addr.S_un.S_addr == 0x0100007f)
- {
+ if (locIP.sin_addr.S_un.S_addr == 0x0100007f) {
struct hostent *he;
gethostname(szPath, sizeof(szPath));
@@ -382,30 +365,26 @@ retrycon:
LongLog(szData);
sz = 0;
- while(true)
- {
+ while (true) {
int bytesRecv;
FD_ZERO(&rfd);
FD_SET(sock, &rfd);
// Wait for the next packet
- if (select(1, &rfd, NULL, NULL, &tv) != 1)
- {
+ if (select(1, &rfd, NULL, NULL, &tv) != 1) {
closeRouterConnection();
NetlibLogf(NULL, "UPnP recieve timeout");
break;
}
//
- bytesRecv = recv(sock, &szResult[sz], resSize-sz, 0);
+ bytesRecv = recv(sock, &szResult[sz], resSize - sz, 0);
// Connection closed or aborted, all data received
- if (bytesRecv == 0 || bytesRecv == SOCKET_ERROR)
- {
+ if (bytesRecv == 0 || bytesRecv == SOCKET_ERROR) {
closeRouterConnection();
- if ((bytesRecv == SOCKET_ERROR || sz == 0) && retryCount < 2)
- {
+ if ((bytesRecv == SOCKET_ERROR || sz == 0) && retryCount < 2) {
++retryCount;
goto retrycon;
}
@@ -415,21 +394,18 @@ retrycon:
sz += bytesRecv;
// Insert null terminator to use string functions
- if (sz >= (resSize-1))
- {
- szResult[resSize-1] = 0;
+ if (sz >= (resSize - 1)) {
+ szResult[resSize - 1] = 0;
break;
}
else
szResult[sz] = 0;
// HTTP header found?
- if (hdrend == NULL)
- {
+ if (hdrend == NULL) {
// Find HTTP header end
hdrend = strstr(szResult, "\r\n\r\n");
- if (hdrend == NULL)
- {
+ if (hdrend == NULL) {
hdrend = strstr(szResult, "\n\n");
if (hdrend) hdrend += 2;
}
@@ -437,47 +413,39 @@ retrycon:
else
hdrend += 4;
- if (hdrend != NULL)
- {
+ if (hdrend != NULL) {
// Get packet size if provided
- if (txtParseParam(szResult, NULL, "Content-Length:", "\n", szRes, sizeof(szRes)) ||
- txtParseParam(szResult, NULL, "CONTENT-LENGTH:", "\n", szRes, sizeof(szRes)))
- {
+ if (txtParseParam(szResult, NULL, "Content-Length:", "\n", szRes, sizeof(szRes)) ||
+ txtParseParam(szResult, NULL, "CONTENT-LENGTH:", "\n", szRes, sizeof(szRes))) {
// Add size of HTTP header to the packet size to compute full transmission size
pktsz = atol(ltrimp(szRes)) + (hdrend - szResult);
}
// Get encoding type if provided
- else if (txtParseParam(szResult, NULL, "Transfer-Encoding:", "\n", szRes, sizeof(szRes)))
- {
+ else if (txtParseParam(szResult, NULL, "Transfer-Encoding:", "\n", szRes, sizeof(szRes))) {
if (_stricmp(lrtrimp(szRes), "Chunked") == 0)
acksz = hdrend - szResult;
}
- if (txtParseParam(szResult, NULL, "Connection:", "\n", szRes, sizeof(szRes)))
- {
+ if (txtParseParam(szResult, NULL, "Connection:", "\n", szRes, sizeof(szRes))) {
needClose = (_stricmp(lrtrimp(szRes), "close") == 0);
}
}
}
// Content-Length bytes reached, all data received
- if (sz >= pktsz && pktsz != 0)
- {
+ if (sz >= pktsz && pktsz != 0) {
szResult[pktsz] = 0;
break;
}
// Chunked encoding processing
- if (sz > acksz && acksz != 0)
- {
+ if (sz > acksz && acksz != 0) {
retry:
// Parse out chunk size
char* data = szResult + acksz;
char* peol1 = data == hdrend ? data - 1 : strchr(data, '\n');
- if (peol1 != NULL)
- {
+ if (peol1 != NULL) {
char *peol2 = strchr(++peol1, '\n');
- if (peol2 != NULL)
- {
+ if (peol2 != NULL) {
// Get chunk size
int chunkBytes = strtol(peol1, NULL, 16);
acksz += chunkBytes;
@@ -495,10 +463,8 @@ retry:
}
LongLog(szResult);
}
- else
- {
- if (retryCount < 2)
- {
+ else {
+ if (retryCount < 2) {
closeRouterConnection();
++retryCount;
goto retrycon;
@@ -542,21 +508,19 @@ static bool getUPnPURLs(char* szUrl, size_t sizeUrl)
char* szData = (char*)mir_alloc(8192);
gatewayFound = httpTransact(szUrl, szData, 8192, NULL, DeviceGetReq) == 200;
- if (gatewayFound)
- {
+ if (gatewayFound) {
char szTemp[256], *rpth;
size_t ctlLen;
txtParseParam(szData, NULL, "<URLBase>", "</URLBase>", szTemp, sizeof(szTemp));
strncpy(szCtlUrl, szTemp[0] ? szTemp : szUrl, sizeof(szCtlUrl));
- szCtlUrl[sizeof(szCtlUrl)-1] = 0;
+ szCtlUrl[sizeof(szCtlUrl) - 1] = 0;
mir_snprintf(szTemp, SIZEOF(szTemp), search_device, szDev);
txtParseParam(szData, szTemp, "<controlURL>", "</controlURL>", szUrl, sizeUrl);
// URL combining per RFC 2396
- if (szUrl[0] != 0)
- {
+ if (szUrl[0] != 0) {
if (strstr(szUrl, "://") != NULL) // absolute URI
rpth = szCtlUrl;
else if (strncmp(szUrl, "//", 2) == 0) // relative URI net_path
@@ -572,20 +536,18 @@ static bool getUPnPURLs(char* szUrl, size_t sizeUrl)
rpth = strchr(rpth, '/');
if (rpth == NULL) rpth = szCtlUrl + strlen(szCtlUrl);
}
- else
- { // relative URI rel_path
+ else { // relative URI rel_path
size_t ctlCLen = strlen(szCtlUrl);
rpth = szCtlUrl + ctlCLen;
- if (ctlCLen != 0 && *(rpth-1) != '/')
+ if (ctlCLen != 0 && *(rpth - 1) != '/')
strncpy(rpth++, "/", sizeof(szCtlUrl) - ctlCLen);
}
ctlLen = sizeof(szCtlUrl) - (rpth - szCtlUrl);
strncpy(rpth, szUrl, ctlLen);
- szCtlUrl[sizeof(szCtlUrl)-1] = 0;
+ szCtlUrl[sizeof(szCtlUrl) - 1] = 0;
}
- else
- {
+ else {
szCtlUrl[0] = 0;
gatewayFound = false;
}
@@ -620,8 +582,7 @@ static void discoverUPnP(void)
gethostname(hostname, sizeof(hostname));
he = gethostbyname(hostname);
- if (he)
- {
+ if (he) {
while (he->h_addr_list[nip]) ++nip;
ips = (unsigned*)mir_alloc(nip * sizeof(unsigned));
@@ -632,10 +593,8 @@ static void discoverUPnP(void)
buf = (char*)mir_alloc(1500);
- for (i = 3; --i && szUrl[0] == 0;)
- {
- for (j = 0; j < nip; j++)
- {
+ for (i = 3; --i && szUrl[0] == 0;) {
+ for (j = 0; j < nip; j++) {
if (ips)
setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&ips[j], sizeof(unsigned));
@@ -653,17 +612,14 @@ static void discoverUPnP(void)
FD_ZERO(&readfd);
FD_SET(sock, &readfd);
- while (select(1, &readfd, NULL, NULL, &tv) >= 1)
- {
+ while (select(1, &readfd, NULL, NULL, &tv) >= 1) {
buflen = recv(sock, buf, 1500, 0);
- if (buflen != SOCKET_ERROR)
- {
+ if (buflen != SOCKET_ERROR) {
buf[buflen] = 0;
LongLog(buf);
- if (txtParseParam(buf, NULL, "LOCATION:", "\n", szUrl, sizeof(szUrl)) ||
- txtParseParam(buf, NULL, "Location:", "\n", szUrl, sizeof(szUrl)))
- {
+ if (txtParseParam(buf, NULL, "LOCATION:", "\n", szUrl, sizeof(szUrl)) ||
+ txtParseParam(buf, NULL, "Location:", "\n", szUrl, sizeof(szUrl))) {
char age[30];
char szHostNew[256], szHostExist[256];
@@ -671,8 +627,7 @@ static void discoverUPnP(void)
parseURL(szUrl, szHostNew, NULL, NULL);
parseURL(szCtlUrl, szHostExist, NULL, NULL);
- if (strcmp(szHostNew, szHostExist) == 0)
- {
+ if (strcmp(szHostNew, szHostExist) == 0) {
gatewayFound = true;
break;
}
@@ -682,8 +637,7 @@ static void discoverUPnP(void)
expireTime = atoi(lrtrimp(age));
lrtrim(szDev);
- if (getUPnPURLs(szUrl, sizeof(szUrl)))
- {
+ if (getUPnPURLs(szUrl, sizeof(szUrl))) {
gatewayFound = getExtIP() != 0;
if (gatewayFound) break;
}
@@ -702,14 +656,12 @@ static void discoverUPnP(void)
static bool findUPnPGateway(void)
{
- if ((time(NULL) - lastDiscTime) >= expireTime)
- {
+ if ((time(NULL) - lastDiscTime) >= expireTime) {
WaitForSingleObject(portListMutex, INFINITE);
time_t curTime = time(NULL);
- if ((curTime - lastDiscTime) >= expireTime)
- {
+ if ((curTime - lastDiscTime) >= expireTime) {
gatewayFound = false;
discoverUPnP();
@@ -728,8 +680,7 @@ bool NetlibUPnPAddPortMapping(WORD intport, char *proto, WORD *extport, DWORD *e
{
int res = 0, i = 5;
- if (findUPnPGateway())
- {
+ if (findUPnPGateway()) {
char* szData = (char*)mir_alloc(4096);
char szExtIP[30];
@@ -738,21 +689,18 @@ bool NetlibUPnPAddPortMapping(WORD intport, char *proto, WORD *extport, DWORD *e
WaitForSingleObject(portListMutex, INFINITE);
- do
- {
+ do {
++*extport;
mir_snprintf(szData, 4096, add_port_mapping,
*extport, proto, intport, inet_ntoa(locIP.sin_addr));
res = httpTransact(szCtlUrl, szData, 4096, "AddPortMapping", ControlAction);
txtParseParam(szData, NULL, "<errorCode>", "</errorCode>", szExtIP, sizeof(szExtIP));
- }
- while (search && res == 500 && atol(szExtIP) == 718 && --i);
+ } while (search && res == 500 && atol(szExtIP) == 718 && --i);
mir_free(szData);
- if (res == 200)
- {
+ if (res == 200) {
unsigned ip = getExtIP();
if (ip) *extip = ip;
@@ -774,8 +722,7 @@ void NetlibUPnPDeletePortMapping(WORD extport, char* proto)
// findUPnPGateway();
- if (gatewayFound)
- {
+ if (gatewayFound) {
unsigned i;
char* szData = (char*)mir_alloc(4096);
@@ -783,9 +730,9 @@ void NetlibUPnPDeletePortMapping(WORD extport, char* proto)
mir_snprintf(szData, 4096, delete_port_mapping, extport, proto);
httpTransact(szCtlUrl, szData, 4096, "DeletePortMapping", ControlAction);
- for (i=0; i < numports; i++)
+ for (i = 0; i < numports; i++)
if (portList[i] == extport && --numports > 0)
- memmove(&portList[i], &portList[i+1], (numports - i) * sizeof(WORD));
+ memmove(&portList[i], &portList[i + 1], (numports - i) * sizeof(WORD));
mir_free(szData);
ReleaseMutex(portListMutex);
@@ -794,14 +741,14 @@ void NetlibUPnPDeletePortMapping(WORD extport, char* proto)
void NetlibUPnPCleanup(void*)
{
+ // upnp is disabled globally, no need for a cleanup
if (db_get_b(NULL, "Netlib", "NLEnableUPnP", 1) == 0)
- // upnp is disabled globally, no need for a cleanup
return;
{
int incoming = 0;
mir_cslock lck(csNetlibUser);
- for (int i=0; i < netlibUser.getCount(); i++)
+ for (int i = 0; i < netlibUser.getCount(); i++)
if (netlibUser[i]->user.flags & NUF_INCOMING) {
incoming = 1;
break;
@@ -811,15 +758,12 @@ void NetlibUPnPCleanup(void*)
return;
}
- if (findUPnPGateway())
- {
- char* szData = (char*)alloca(4096);
+ if (findUPnPGateway()) {
+ char *szData = (char*)alloca(4096);
char buf[50], lip[50];
- unsigned i, j = 0, k, num = 100;
+ unsigned j = 0, k, num = 100;
- WORD ports[30];
-
- strcpy(lip, inet_ntoa(locIP.sin_addr));
+ strncpy_s(lip, inet_ntoa(locIP.sin_addr), _TRUNCATE);
WaitForSingleObject(portListMutex, INFINITE);
@@ -827,8 +771,8 @@ void NetlibUPnPCleanup(void*)
txtParseParam(szData, "QueryStateVariableResponse", "<return>", "<", buf, sizeof(buf)))
num = atol(buf);
- for (i=0; i<num && !Miranda_Terminated(); i++)
- {
+ WORD ports[30];
+ for (int i = 0; i < num && !Miranda_Terminated(); i++) {
mir_snprintf(szData, 4096, get_port_mapping, i);
ReleaseMutex(portListMutex);
@@ -843,14 +787,13 @@ void NetlibUPnPCleanup(void*)
if (!txtParseParam(szData, "<NewInternalClient", ">", "<", buf, sizeof(buf)) || strcmp(buf, lip) != 0)
continue;
- if (txtParseParam(szData, "<NewExternalPort", ">", "<", buf, sizeof(buf)))
- {
+ if (txtParseParam(szData, "<NewExternalPort", ">", "<", buf, sizeof(buf))) {
WORD mport = (WORD)atol(buf);
if (j >= SIZEOF(ports))
break;
- for (k = 0; k<numports; ++k)
+ for (k = 0; k < numports; ++k)
if (portList[k] == mport)
break;
@@ -861,7 +804,7 @@ void NetlibUPnPCleanup(void*)
ReleaseMutex(portListMutex);
- for (i=0; i<j && !Miranda_Terminated(); i++)
+ for (int i = 0; i < j && !Miranda_Terminated(); i++)
NetlibUPnPDeletePortMapping(ports[i], "TCP");
}
}
diff --git a/src/modules/options/descbutton.cpp b/src/modules/options/descbutton.cpp
index 6d98cbf747..f6b66eb041 100644
--- a/src/modules/options/descbutton.cpp
+++ b/src/modules/options/descbutton.cpp
@@ -38,30 +38,31 @@ extern HINSTANCE hInst;
static LRESULT CALLBACK MDescButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// structure is used for storing list of tab info
-typedef struct {
- HWND hwnd;
- BOOL bSharedIcon;
- HICON hIcon;
- TCHAR *lpzTitle;
- TCHAR *lpzDescription;
+struct MDescButtonCtrl
+{
+ HWND hwnd;
+ BOOL bSharedIcon;
+ HICON hIcon;
+ TCHAR *lpzTitle;
+ TCHAR *lpzDescription;
// UI info
- BOOL bMouseInside;
- RECT rc;
- int width, height;
- HFONT hfntTitle;
+ BOOL bMouseInside;
+ RECT rc;
+ int width, height;
+ HFONT hfntTitle;
// control colors
- RGBQUAD rgbBkgTop, rgbBkgBottom;
- RGBQUAD rgbSelTop, rgbSelBottom;
- RGBQUAD rgbHotTop, rgbHotBottom;
- COLORREF clText, clBackground;
- COLORREF clSelText, clSelBorder;
- COLORREF clHotText, clHotBorder;
+ RGBQUAD rgbBkgTop, rgbBkgBottom;
+ RGBQUAD rgbSelTop, rgbSelBottom;
+ RGBQUAD rgbHotTop, rgbHotBottom;
+ COLORREF clText, clBackground;
+ COLORREF clSelText, clSelBorder;
+ COLORREF clHotText, clHotBorder;
// fonts
HFONT hFont;
-} MDescButtonCtrl;
+};
int LoadDescButtonModule()
{
@@ -74,48 +75,46 @@ int LoadDescButtonModule()
wc.hCursor = LoadCursor(NULL, IDC_HAND);
wc.cbWndExtra = sizeof(MDescButtonCtrl *);
wc.hbrBackground = 0; //GetStockObject(WHITE_BRUSH);
- wc.style = CS_GLOBALCLASS|CS_SAVEBITS;
+ wc.style = CS_GLOBALCLASS | CS_SAVEBITS;
RegisterClassEx(&wc);
return 0;
}
static void MDescButton_SetupColors(MDescButtonCtrl *dat)
{
- COLORREF cl;
-
- cl = GetSysColor(COLOR_WINDOW);
- dat->rgbBkgBottom.rgbRed = (dat->rgbBkgTop.rgbRed = GetRValue(cl)) * .95;
- dat->rgbBkgBottom.rgbGreen = (dat->rgbBkgTop.rgbGreen = GetGValue(cl)) * .95;
- dat->rgbBkgBottom.rgbBlue = (dat->rgbBkgTop.rgbBlue = GetBValue(cl)) * .95;
+ COLORREF cl = GetSysColor(COLOR_WINDOW);
+ dat->rgbBkgBottom.rgbRed = (dat->rgbBkgTop.rgbRed = GetRValue(cl)) * .95;
+ dat->rgbBkgBottom.rgbGreen = (dat->rgbBkgTop.rgbGreen = GetGValue(cl)) * .95;
+ dat->rgbBkgBottom.rgbBlue = (dat->rgbBkgTop.rgbBlue = GetBValue(cl)) * .95;
cl = GetSysColor(COLOR_HIGHLIGHT);
- dat->rgbSelTop.rgbRed = (dat->rgbSelBottom.rgbRed = GetRValue(cl)) * .75;
- dat->rgbSelTop.rgbGreen = (dat->rgbSelBottom.rgbGreen = GetGValue(cl)) * .75;
- dat->rgbSelTop.rgbBlue = (dat->rgbSelBottom.rgbBlue = GetBValue(cl)) * .75;
+ dat->rgbSelTop.rgbRed = (dat->rgbSelBottom.rgbRed = GetRValue(cl)) * .75;
+ dat->rgbSelTop.rgbGreen = (dat->rgbSelBottom.rgbGreen = GetGValue(cl)) * .75;
+ dat->rgbSelTop.rgbBlue = (dat->rgbSelBottom.rgbBlue = GetBValue(cl)) * .75;
- dat->rgbHotTop.rgbRed = (dat->rgbSelTop.rgbRed + 255) / 2;
- dat->rgbHotTop.rgbGreen = (dat->rgbSelTop.rgbGreen + 255) / 2;
- dat->rgbHotTop.rgbBlue = (dat->rgbSelTop.rgbBlue + 255) / 2;
+ dat->rgbHotTop.rgbRed = (dat->rgbSelTop.rgbRed + 255) / 2;
+ dat->rgbHotTop.rgbGreen = (dat->rgbSelTop.rgbGreen + 255) / 2;
+ dat->rgbHotTop.rgbBlue = (dat->rgbSelTop.rgbBlue + 255) / 2;
- dat->rgbHotBottom.rgbRed = (dat->rgbSelBottom.rgbRed + 255) / 2;
- dat->rgbHotBottom.rgbGreen = (dat->rgbSelBottom.rgbGreen + 255) / 2;
- dat->rgbHotBottom.rgbBlue = (dat->rgbSelBottom.rgbBlue + 255) / 2;
+ dat->rgbHotBottom.rgbRed = (dat->rgbSelBottom.rgbRed + 255) / 2;
+ dat->rgbHotBottom.rgbGreen = (dat->rgbSelBottom.rgbGreen + 255) / 2;
+ dat->rgbHotBottom.rgbBlue = (dat->rgbSelBottom.rgbBlue + 255) / 2;
- dat->clBackground = GetSysColor(COLOR_3DFACE);
- dat->clText = GetSysColor(COLOR_WINDOWTEXT);
- dat->clSelText = GetSysColor(COLOR_HIGHLIGHTTEXT);
- dat->clSelBorder = RGB(dat->rgbSelTop.rgbRed, dat->rgbSelTop.rgbGreen, dat->rgbSelTop.rgbBlue);
- dat->clHotBorder = RGB(dat->rgbHotTop.rgbRed, dat->rgbHotTop.rgbGreen, dat->rgbHotTop.rgbBlue);
+ dat->clBackground = GetSysColor(COLOR_3DFACE);
+ dat->clText = GetSysColor(COLOR_WINDOWTEXT);
+ dat->clSelText = GetSysColor(COLOR_HIGHLIGHTTEXT);
+ dat->clSelBorder = RGB(dat->rgbSelTop.rgbRed, dat->rgbSelTop.rgbGreen, dat->rgbSelTop.rgbBlue);
+ dat->clHotBorder = RGB(dat->rgbHotTop.rgbRed, dat->rgbHotTop.rgbGreen, dat->rgbHotTop.rgbBlue);
if (!dat->hFont) dat->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
}
static void MDescButton_FillRect(HDC hdc, int x, int y, int width, int height, COLORREF cl)
{
- int oldMode = SetBkMode(hdc, OPAQUE);
- COLORREF oldColor = SetBkColor(hdc, cl);
+ int oldMode = SetBkMode(hdc, OPAQUE);
+ COLORREF oldColor = SetBkColor(hdc, cl);
- RECT rc; SetRect(&rc, x, y, x+width, y+height);
+ RECT rc; SetRect(&rc, x, y, x + width, y + height);
ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, "", 0, 0);
SetBkMode(hdc, oldMode);
@@ -124,15 +123,15 @@ static void MDescButton_FillRect(HDC hdc, int x, int y, int width, int height, C
static void MDescButton_DrawGradient(HDC hdc, int x, int y, int width, int height, RGBQUAD *rgb0, RGBQUAD *rgb1)
{
- int oldMode = SetBkMode(hdc, OPAQUE);
- COLORREF oldColor = SetBkColor(hdc, 0);
+ int oldMode = SetBkMode(hdc, OPAQUE);
+ COLORREF oldColor = SetBkColor(hdc, 0);
- RECT rc; SetRect(&rc, x, 0, x+width, 0);
- for (int i = y+height; --i >= y;) {
+ RECT rc; SetRect(&rc, x, 0, x + width, 0);
+ for (int i = y + height; --i >= y;) {
COLORREF color = RGB(
- ((height-i-1)*rgb0->rgbRed + i*rgb1->rgbRed) / height,
- ((height-i-1)*rgb0->rgbGreen + i*rgb1->rgbGreen) / height,
- ((height-i-1)*rgb0->rgbBlue + i*rgb1->rgbBlue) / height);
+ ((height - i - 1)*rgb0->rgbRed + i*rgb1->rgbRed) / height,
+ ((height - i - 1)*rgb0->rgbGreen + i*rgb1->rgbGreen) / height,
+ ((height - i - 1)*rgb0->rgbBlue + i*rgb1->rgbBlue) / height);
rc.top = rc.bottom = i;
++rc.bottom;
SetBkColor(hdc, color);
@@ -146,26 +145,23 @@ static void MDescButton_DrawGradient(HDC hdc, int x, int y, int width, int heigh
static LRESULT MDescButton_OnPaint(HWND hwndDlg, MDescButtonCtrl *dat, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
- HBITMAP hBmp, hOldBmp;
- RECT temprc;
- HFONT hfntSave;
-
HDC hdc = BeginPaint(hwndDlg, &ps);
HDC tempDC = CreateCompatibleDC(hdc);
- SIZE titleSize = {0};
+ SIZE titleSize = { 0 };
- hBmp = CreateCompatibleBitmap(hdc, dat->width, dat->height);
- hOldBmp = (HBITMAP)SelectObject(tempDC, hBmp);
+ HBITMAP hBmp = CreateCompatibleBitmap(hdc, dat->width, dat->height);
+ HBITMAP hOldBmp = (HBITMAP)SelectObject(tempDC, hBmp);
+ RECT temprc;
temprc.left = 0;
temprc.right = dat->width;
temprc.top = 0;
- //Draw background
+ // Draw background
if (dat->bMouseInside || (GetFocus() == hwndDlg)) {
MDescButton_FillRect(tempDC, 0, 0, dat->width, dat->height, dat->clSelBorder);
- MDescButton_DrawGradient(tempDC, 1, 1, dat->width-2, dat->height-2, &dat->rgbSelTop, &dat->rgbSelBottom);
+ MDescButton_DrawGradient(tempDC, 1, 1, dat->width - 2, dat->height - 2, &dat->rgbSelTop, &dat->rgbSelBottom);
SetTextColor(tempDC, dat->clSelText);
}
else {
@@ -176,24 +172,22 @@ static LRESULT MDescButton_OnPaint(HWND hwndDlg, MDescButtonCtrl *dat, UINT msg
if (dat->hIcon)
DrawIcon(tempDC, DBC_BORDER_SIZE, DBC_BORDER_SIZE, dat->hIcon);
- hfntSave = (HFONT)SelectObject(tempDC, dat->hFont);
+ HFONT hfntSave = (HFONT)SelectObject(tempDC, dat->hFont);
SetBkMode(tempDC, TRANSPARENT);
if (dat->lpzTitle) {
LOGFONT lf;
- RECT textRect;
- HFONT hfntSave;
-
GetObject(dat->hFont, sizeof(lf), &lf);
lf.lfWeight = FW_BOLD;
lf.lfHeight *= 1.5;
- hfntSave = (HFONT)SelectObject(tempDC, CreateFontIndirect(&lf));
+ HFONT hfntSave = (HFONT)SelectObject(tempDC, CreateFontIndirect(&lf));
- textRect.left = DBC_BORDER_SIZE + dat->hIcon ? 32 + DBC_VSPACING : 0;
+ RECT textRect;
+ textRect.left = DBC_BORDER_SIZE + (dat->hIcon ? 32 + DBC_VSPACING : 0);
textRect.right = dat->width - DBC_BORDER_SIZE;
textRect.top = DBC_BORDER_SIZE;
textRect.bottom = dat->height - DBC_BORDER_SIZE;
- DrawText(tempDC, dat->lpzTitle, -1, &textRect, DT_TOP|DT_LEFT|DT_END_ELLIPSIS);
+ DrawText(tempDC, dat->lpzTitle, -1, &textRect, DT_TOP | DT_LEFT | DT_END_ELLIPSIS);
GetTextExtentPoint32(tempDC, dat->lpzTitle, (int)mir_tstrlen(dat->lpzTitle), &titleSize);
DeleteObject(SelectObject(tempDC, hfntSave));
@@ -201,11 +195,11 @@ static LRESULT MDescButton_OnPaint(HWND hwndDlg, MDescButtonCtrl *dat, UINT msg
if (dat->lpzDescription) {
RECT textRect;
- textRect.left = DBC_BORDER_SIZE + dat->hIcon ? 32 + DBC_VSPACING : 0;
+ textRect.left = DBC_BORDER_SIZE + (dat->hIcon ? 32 + DBC_VSPACING : 0);
textRect.right = dat->width - DBC_BORDER_SIZE;
textRect.top = DBC_BORDER_SIZE + titleSize.cy ? titleSize.cy + DBC_HSPACING : 0;
textRect.bottom = dat->height - DBC_BORDER_SIZE;
- DrawText(tempDC, dat->lpzDescription, -1, &textRect, DT_TOP|DT_LEFT|DT_WORDBREAK|DT_END_ELLIPSIS);
+ DrawText(tempDC, dat->lpzDescription, -1, &textRect, DT_TOP | DT_LEFT | DT_WORDBREAK | DT_END_ELLIPSIS);
GetTextExtentPoint32(tempDC, dat->lpzTitle, (int)mir_tstrlen(dat->lpzTitle), &titleSize);
}
@@ -224,7 +218,7 @@ static LRESULT MDescButton_OnPaint(HWND hwndDlg, MDescButtonCtrl *dat, UINT msg
static LRESULT CALLBACK MDescButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
MDescButtonCtrl *dat = (MDescButtonCtrl *)GetWindowLongPtr(hwndDlg, 0);
- switch(msg) {
+ switch (msg) {
case WM_NCCREATE:
dat = (MDescButtonCtrl*)mir_alloc(sizeof(MDescButtonCtrl));
if (dat == NULL)
@@ -241,8 +235,8 @@ static LRESULT CALLBACK MDescButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wPara
case WM_SIZE:
GetClientRect(hwndDlg, &dat->rc);
- dat->width = dat->rc.right-dat->rc.left;
- dat->height = dat->rc.bottom-dat->rc.top;
+ dat->width = dat->rc.right - dat->rc.left;
+ dat->height = dat->rc.bottom - dat->rc.top;
return TRUE;
case WM_THEMECHANGED:
@@ -252,7 +246,7 @@ static LRESULT CALLBACK MDescButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wPara
case WM_MOUSEMOVE:
if (!dat->bMouseInside) {
- TRACKMOUSEEVENT tme = {0};
+ TRACKMOUSEEVENT tme = { 0 };
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwndDlg;
diff --git a/src/modules/options/options.cpp b/src/modules/options/options.cpp
index 73b05346c8..bfdcb82147 100644
--- a/src/modules/options/options.cpp
+++ b/src/modules/options/options.cpp
@@ -91,7 +91,7 @@ struct OptionsPageData
}
};
-struct OptionsDlgData
+struct OptionsDlgData : public MZeroedObject
{
OptionsDlgData() :
arOpd(10)
@@ -316,7 +316,7 @@ static LRESULT CALLBACK OptionsFilterSubclassProc(HWND hWnd, UINT message, WPARA
static bool CheckPageShow(HWND hdlg, OptionsDlgData *dat, int i)
{
OptionsPageData *opd = dat->arOpd[i];
- if (dat->szFilterString && dat->szFilterString[0] && !MatchesFilter(opd, dat->szFilterString))
+ if (dat->szFilterString[0] && !MatchesFilter(opd, dat->szFilterString))
return false;
return true;
}
@@ -497,20 +497,18 @@ static void FillFilterCombo(HWND hDlg, OptionsDlgData* dat)
static void RebuildPageTree(HWND hdlg, OptionsDlgData *dat)
{
- BOOL bRemoveFocusFromFilter = FALSE;
- HINSTANCE FilterInst = NULL;
-
LPARAM oldSel = SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, CB_GETEDITSEL, 0, 0);
GetDlgItemText(hdlg, IDC_KEYWORD_FILTER, dat->szFilterString, SIZEOF(dat->szFilterString));
- //if filter string is set to all modules then make the filter string empty (this will return all modules)
+ // if filter string is set to all modules then make the filter string empty (this will return all modules)
+ BOOL bRemoveFocusFromFilter = FALSE;
if (_tcscmp(dat->szFilterString, TranslateT(ALL_MODULES_FILTER)) == 0) {
dat->szFilterString[0] = 0;
bRemoveFocusFromFilter = TRUE;
}
- //if filter string is set to core modules replace it with the name of the executable (this will return all core modules)
+ // if filter string is set to core modules replace it with the name of the executable (this will return all core modules)
else if (_tcscmp(dat->szFilterString, TranslateT(CORE_MODULES_FILTER)) == 0) {
- //replace string with process name - that will show core settings
+ // replace string with process name - that will show core settings
TCHAR szFileName[300];
GetModuleFileName(NULL, szFileName, SIZEOF(szFileName));
TCHAR *pos = _tcsrchr(szFileName, _T('\\'));
@@ -541,6 +539,7 @@ static void RebuildPageTree(HWND hdlg, OptionsDlgData *dat)
HWND oldWnd = NULL;
HWND oldTab = NULL;
+ CMString fullTitle;
OptionsPageData *opd = dat->getCurrent();
if (opd != NULL) {
@@ -560,28 +559,18 @@ static void RebuildPageTree(HWND hdlg, OptionsDlgData *dat)
tvis.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
tvis.item.state = tvis.item.stateMask = TVIS_EXPANDED;
for (int i = 0; i < dat->arOpd.getCount(); i++) {
- static TCHAR *fullTitle = NULL;
- mir_free(fullTitle); fullTitle = NULL;
if (!CheckPageShow(hdlg, dat, i))
continue;
opd = dat->arOpd[i];
TCHAR *ptszGroup = TranslateTH(opd->hLangpack, opd->ptszGroup);
- TCHAR *ptszTitle = opd->getString(opd->ptszTitle);
+ TCHAR *ptszTitle = opd->getString(opd->ptszTitle), *useTitle;
TCHAR *ptszTab = TranslateTH(opd->hLangpack, opd->ptszTab);
tvis.hParent = NULL;
- if (FilterInst != NULL) {
- size_t sz = ptszGroup ? _tcslen(ptszGroup) + 1 : 0;
- if (sz) sz += 3;
- sz += ptszTitle ? _tcslen(ptszTitle) + 1 : 0;
- fullTitle = (TCHAR*)mir_alloc(sz*sizeof(TCHAR));
- mir_sntprintf(fullTitle, sz, (ptszGroup && ptszTitle) ? _T("%s - %s") : _T("%s%s"),
- ptszGroup ? ptszGroup : _T(""),
- ptszTitle ? ptszTitle : _T(""));
- }
- TCHAR *useTitle = fullTitle ? fullTitle : ptszTitle;
- if (ptszGroup != NULL && FilterInst == NULL) {
+ useTitle = ptszTitle;
+
+ if (ptszGroup != NULL) {
tvis.hParent = FindNamedTreeItemAtRoot(hwndTree, ptszGroup);
if (tvis.hParent == NULL) {
tvis.item.lParam = -1;
@@ -628,9 +617,6 @@ static void RebuildPageTree(HWND hdlg, OptionsDlgData *dat)
opd->hTreeItem = TreeView_InsertItem(hwndTree, &tvis);
if (i == dat->currentPage)
dat->hCurrentPage = opd->hTreeItem;
-
- if (fullTitle) mir_free(fullTitle);
- fullTitle = NULL;
}
char str[128];
diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp
index 5c16845279..511ab1fdd4 100644
--- a/src/modules/plugins/newplugins.cpp
+++ b/src/modules/plugins/newplugins.cpp
@@ -479,7 +479,7 @@ int isPluginOnWhiteList(const TCHAR* pluginname)
bool TryLoadPlugin(pluginEntry *p, bool bDynamic)
{
- TCHAR exe[MAX_PATH];
+ TCHAR exe[MAX_PATH], tszFullPath[MAX_PATH];
GetModuleFileName(NULL, exe, SIZEOF(exe));
TCHAR* slice = _tcsrchr(exe, '\\');
if (slice)
@@ -491,8 +491,8 @@ bool TryLoadPlugin(pluginEntry *p, bool bDynamic)
if (!(p->pclass & PCLASS_BASICAPI)) {
BASIC_PLUGIN_INFO bpi;
- mir_sntprintf(slice, &exe[SIZEOF(exe)] - slice, _T("\\%s\\%s"), (p->pclass & PCLASS_CORE) ? _T("Core") : _T("Plugins"), p->pluginname);
- if (!checkAPI(exe, &bpi, mirandaVersion, CHECKAPI_NONE)) {
+ mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\%s\\%s"), exe, (p->pclass & PCLASS_CORE) ? _T("Core") : _T("Plugins"), p->pluginname);
+ if (!checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
p->pclass |= PCLASS_FAILED;
return false;
}
@@ -599,22 +599,24 @@ static bool loadClistModule(TCHAR* exe, pluginEntry *p)
return false;
}
-static pluginEntry* getCListModule(TCHAR *exe, TCHAR *slice)
+static pluginEntry* getCListModule(TCHAR *exe)
{
+ TCHAR tszFullPath[MAX_PATH];
+
for (int i = 0; i < clistPlugins.getCount(); i++) {
pluginEntry *p = clistPlugins[i];
- mir_sntprintf(slice, &exe[MAX_PATH] - slice, _T("\\Plugins\\%s"), p->pluginname);
if (!isPluginOnWhiteList(p->pluginname))
continue;
- if (loadClistModule(exe, p))
+ mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\Plugins\\%s"), exe, p->pluginname);
+ if (loadClistModule(tszFullPath, p))
return p;
}
MuuidReplacement& stdClist = pluginDefault[11];
if (LoadCorePlugin(stdClist)) {
- mir_sntprintf(slice, &exe[MAX_PATH] - slice, _T("\\Core\\%s.dll"), stdClist.stdplugname);
- if (loadClistModule(exe, stdClist.pImpl))
+ mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\Core\\%s.dll"), exe, stdClist.stdplugname);
+ if (loadClistModule(tszFullPath, stdClist.pImpl))
return stdClist.pImpl;
}
@@ -752,10 +754,11 @@ int LoadNewPluginsModule(void)
int i;
// make full path to the plugin
- TCHAR exe[MAX_PATH];
+ TCHAR exe[MAX_PATH], fullPath[MAX_PATH];
GetModuleFileName(NULL, exe, SIZEOF(exe));
TCHAR *slice = _tcsrchr(exe, '\\');
- if (slice) *slice = 0;
+ if (slice)
+ *slice = 0;
// remember some useful options
askAboutIgnoredPlugins = (UINT)GetPrivateProfileInt(_T("PluginLoader"), _T("AskAboutIgnoredPlugins"), 0, mirandabootini);
@@ -768,8 +771,8 @@ int LoadNewPluginsModule(void)
// if freeimage is present, load it to provide the basic core functions
if (plugin_freeimg != NULL) {
BASIC_PLUGIN_INFO bpi;
- mir_sntprintf(slice, &exe[SIZEOF(exe)] - slice, _T("\\Plugins\\%s"), plugin_freeimg->pluginname);
- if (checkAPI(exe, &bpi, mirandaVersion, CHECKAPI_NONE)) {
+ mir_sntprintf(fullPath, SIZEOF(fullPath), _T("%s\\Plugins\\%s"), exe, plugin_freeimg->pluginname);
+ if (checkAPI(fullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
plugin_freeimg->bpi = bpi;
plugin_freeimg->pclass |= PCLASS_OK | PCLASS_BASICAPI;
if (bpi.Load() == 0)
@@ -780,7 +783,7 @@ int LoadNewPluginsModule(void)
}
// first load the clist cos alot of plugins need that to be present at Load(void)
- pluginEntry* clist = getCListModule(exe, slice);
+ pluginEntry* clist = getCListModule(exe);
/* the loop above will try and get one clist DLL to work, if all fail then just bail now */
if (clist == NULL) {