diff options
author | George Hazan <george.hazan@gmail.com> | 2013-08-12 22:17:40 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-08-12 22:17:40 +0000 |
commit | 858fb2dfc3f198d5c0c861528115411d4d6904d6 (patch) | |
tree | 7e304e42c9339e54a7a4abfb4a1ae638a24f8959 | |
parent | 9f06e7ffdd6458dd25bfd5b915cb788bab03bea0 (diff) |
netlib moved to the core logger
git-svn-id: http://svn.miranda-ng.org/main/trunk@5665 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | bin10/lib/mir_core.lib | bin | 50032 -> 49958 bytes | |||
-rw-r--r-- | bin10/lib/mir_core64.lib | bin | 45590 -> 45476 bytes | |||
-rw-r--r-- | bin11/lib/mir_core.lib | bin | 50032 -> 49958 bytes | |||
-rw-r--r-- | bin11/lib/mir_core64.lib | bin | 45590 -> 45476 bytes | |||
-rw-r--r-- | include/m_core.h | 2 | ||||
-rw-r--r-- | src/mir_core/logger.cpp | 218 | ||||
-rw-r--r-- | src/modules/netlib/netlib.cpp | 20 | ||||
-rw-r--r-- | src/modules/netlib/netlib.h | 36 | ||||
-rw-r--r-- | src/modules/netlib/netlibbind.cpp | 4 | ||||
-rw-r--r-- | src/modules/netlib/netlibhttp.cpp | 8 | ||||
-rw-r--r-- | src/modules/netlib/netlibhttpproxy.cpp | 14 | ||||
-rw-r--r-- | src/modules/netlib/netliblog.cpp | 39 | ||||
-rw-r--r-- | src/modules/netlib/netlibopenconn.cpp | 12 | ||||
-rw-r--r-- | src/modules/netlib/netlibpktrecver.cpp | 2 |
14 files changed, 277 insertions, 78 deletions
diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib Binary files differindex 46ad2b046b..db16ef5188 100644 --- a/bin10/lib/mir_core.lib +++ b/bin10/lib/mir_core.lib diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib Binary files differindex 643c58ccf0..d936d51975 100644 --- a/bin10/lib/mir_core64.lib +++ b/bin10/lib/mir_core64.lib diff --git a/bin11/lib/mir_core.lib b/bin11/lib/mir_core.lib Binary files differindex d149aa9bb3..553bbe2092 100644 --- a/bin11/lib/mir_core.lib +++ b/bin11/lib/mir_core.lib diff --git a/bin11/lib/mir_core64.lib b/bin11/lib/mir_core64.lib Binary files differindex 61c24cb265..be95d42b45 100644 --- a/bin11/lib/mir_core64.lib +++ b/bin11/lib/mir_core64.lib diff --git a/include/m_core.h b/include/m_core.h index a800afe873..7d80dc6931 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -523,7 +523,7 @@ MIR_CORE_DLL(void) List_ObjCopy(SortedList* s, SortedList* d, size_t item ///////////////////////////////////////////////////////////////////////////////
// logging functions
-MIR_CORE_DLL(HANDLE) mir_createLog(const TCHAR *ptszFile, unsigned options);
+MIR_CORE_DLL(HANDLE) mir_createLog(const char *pszName, const TCHAR *ptszDescr, const TCHAR *ptszFile, unsigned options);
MIR_C_CORE_DLL(int) mir_writeLogA(HANDLE logger, const char *format, ...);
MIR_C_CORE_DLL(int) mir_writeLogW(HANDLE logger, const WCHAR *format, ...);
diff --git a/src/mir_core/logger.cpp b/src/mir_core/logger.cpp new file mode 100644 index 0000000000..4d3781b6bd --- /dev/null +++ b/src/mir_core/logger.cpp @@ -0,0 +1,218 @@ +/*
+
+Miranda IM: the free IM client for Microsoft* Windows*
+
+Copyright 2000-12 Miranda IM, 2012-13 Miranda NG project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "commonheaders.h"
+
+#define SECRET_SIGNATURE 0x87654321
+
+struct Logger
+{
+ Logger(const char* pszName, const TCHAR *ptszDescr, const TCHAR *ptszFilename, unsigned options) :
+ m_name( mir_strdup(pszName)),
+ m_descr( mir_tstrdup(ptszDescr)),
+ m_fileName( mir_tstrdup(ptszFilename)),
+ m_options(options),
+ m_signature(SECRET_SIGNATURE),
+ m_out(NULL),
+ m_lastwrite(0)
+ {
+ InitializeCriticalSection(&m_cs);
+ }
+
+ ~Logger()
+ {
+ if (m_out)
+ fclose(m_out);
+
+ DeleteCriticalSection(&m_cs);
+ }
+
+ int m_signature;
+ ptrA m_name;
+ ptrT m_fileName, m_descr;
+ FILE *m_out;
+ __int64 m_lastwrite;
+ unsigned m_options;
+
+ CRITICAL_SECTION m_cs;
+};
+
+static int CompareLoggers(const Logger *p1, const Logger *p2)
+{ return strcmp(p1->m_name, p2->m_name);
+}
+
+static OBJLIST<Logger> arLoggers(1, CompareLoggers);
+
+static __int64 llIdlePeriod;
+
+void InitLogs()
+{
+ LARGE_INTEGER li;
+ QueryPerformanceFrequency(&li);
+ llIdlePeriod = li.QuadPart * 10; // 10 seconds interval
+}
+
+void UninitLogs()
+{
+ arLoggers.destroy();
+}
+
+void CheckLogs()
+{
+ LARGE_INTEGER li;
+ QueryPerformanceCounter(&li);
+
+ for (int i=0; i < arLoggers.getCount(); i++) {
+ Logger &p = arLoggers[i];
+
+ mir_cslock lck(p.m_cs);
+ if (p.m_out && li.QuadPart - p.m_lastwrite > llIdlePeriod) {
+ fclose(p.m_out);
+ p.m_out = NULL;
+ }
+ else fflush(p.m_out);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////
+
+MIR_CORE_DLL(HANDLE) mir_createLog(const char* pszName, const TCHAR *ptszDescr, const TCHAR *ptszFile, unsigned options)
+{
+ if (ptszFile == NULL)
+ return NULL;
+
+ Logger *result = new Logger(pszName, ptszDescr, ptszFile, options);
+ if (result == NULL)
+ return NULL;
+
+ int idx = arLoggers.getIndex(result);
+ if (idx != -1) {
+ delete result;
+ return &arLoggers[idx];
+ }
+
+ FILE *fp = _tfopen(ptszFile, _T("ab"));
+ if (fp == NULL) {
+ TCHAR tszPath[MAX_PATH];
+ _tcsncpy_s(tszPath, SIZEOF(tszPath), ptszFile, _TRUNCATE);
+ CreatePathToFileT(tszPath);
+ }
+ else fclose(fp);
+
+ DeleteFile(ptszFile);
+ arLoggers.insert(result);
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////
+
+static Logger* prepareLogger(HANDLE logger)
+{
+ if (logger == NULL)
+ return NULL;
+
+ Logger *p = (Logger*)logger;
+ return (p->m_signature == SECRET_SIGNATURE) ? p : NULL;
+}
+
+MIR_C_CORE_DLL(int) mir_writeLogA(HANDLE logger, const char *format, ...)
+{
+ Logger *p = prepareLogger(logger);
+ if (p == NULL)
+ return 1;
+
+ mir_cslock lck(p->m_cs);
+ if (p->m_out == NULL)
+ if ((p->m_out = _tfopen(p->m_fileName, _T("ab"))) == NULL)
+ return 2;
+
+ va_list args;
+ va_start(args, format);
+ vfprintf(p->m_out, format, args);
+
+ LARGE_INTEGER li;
+ QueryPerformanceCounter(&li);
+ p->m_lastwrite = li.QuadPart;
+ return 0;
+}
+
+MIR_C_CORE_DLL(int) mir_writeLogW(HANDLE logger, const WCHAR *format, ...)
+{
+ Logger *p = prepareLogger(logger);
+ if (p == NULL)
+ return 1;
+
+ mir_cslock lck(p->m_cs);
+ if (p->m_out == NULL)
+ if ((p->m_out = _tfopen(p->m_fileName, _T("ab"))) == NULL)
+ return 2;
+
+ va_list args;
+ va_start(args, format);
+ vfwprintf(p->m_out, format, args);
+
+ LARGE_INTEGER li;
+ QueryPerformanceCounter(&li);
+ p->m_lastwrite = li.QuadPart;
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////
+
+MIR_CORE_DLL(int) mir_writeLogVA(HANDLE logger, const char *format, va_list args)
+{
+ Logger *p = prepareLogger(logger);
+ if (p == NULL)
+ return 1;
+
+ mir_cslock lck(p->m_cs);
+ if (p->m_out == NULL)
+ if ((p->m_out = _tfopen(p->m_fileName, _T("ab"))) == NULL)
+ return 2;
+
+ vfprintf(p->m_out, format, args);
+
+ LARGE_INTEGER li;
+ QueryPerformanceCounter(&li);
+ p->m_lastwrite = li.QuadPart;
+ return 0;
+}
+
+MIR_CORE_DLL(int) mir_writeLogVW(HANDLE logger, const WCHAR *format, va_list args)
+{
+ Logger *p = prepareLogger(logger);
+ if (p == NULL)
+ return 1;
+
+ mir_cslock lck(p->m_cs);
+ if (p->m_out == NULL)
+ if ((p->m_out = _tfopen(p->m_fileName, _T("ab"))) == NULL)
+ return 2;
+
+ vfwprintf(p->m_out, format, args);
+
+ LARGE_INTEGER li;
+ QueryPerformanceCounter(&li);
+ p->m_lastwrite = li.QuadPart;
+ return 0;
+}
diff --git a/src/modules/netlib/netlib.cpp b/src/modules/netlib/netlib.cpp index 701c61cb19..e56cf59811 100644 --- a/src/modules/netlib/netlib.cpp +++ b/src/modules/netlib/netlib.cpp @@ -52,21 +52,21 @@ void NetlibFreeUserSettingsStruct(NETLIBUSERSETTINGS *settings) mir_free(settings->szProxyServer);
}
-void NetlibInitializeNestedCS(struct NetlibNestedCriticalSection *nlncs)
+void NetlibInitializeNestedCS(NetlibNestedCriticalSection *nlncs)
{
nlncs->dwOwningThreadId = 0;
nlncs->lockCount = 0;
nlncs->hMutex = CreateMutex(NULL, FALSE, NULL);
}
-void NetlibDeleteNestedCS(struct NetlibNestedCriticalSection *nlncs)
+void NetlibDeleteNestedCS(NetlibNestedCriticalSection *nlncs)
{
CloseHandle(nlncs->hMutex);
}
-int NetlibEnterNestedCS(struct NetlibConnection *nlc, int which)
+int NetlibEnterNestedCS(NetlibConnection *nlc, int which)
{
- struct NetlibNestedCriticalSection *nlncs;
+ NetlibNestedCriticalSection *nlncs;
DWORD dwCurrentThreadId = GetCurrentThreadId();
WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
@@ -92,7 +92,7 @@ int NetlibEnterNestedCS(struct NetlibConnection *nlc, int which) return 1;
}
-void NetlibLeaveNestedCS(struct NetlibNestedCriticalSection *nlncs)
+void NetlibLeaveNestedCS(NetlibNestedCriticalSection *nlncs)
{
if (--nlncs->lockCount == 0) {
nlncs->dwOwningThreadId = 0;
@@ -138,7 +138,7 @@ static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam) return 0;
}
- NetlibUser *thisUser = (struct NetlibUser*)mir_calloc(sizeof(struct NetlibUser));
+ NetlibUser *thisUser = (NetlibUser*)mir_calloc(sizeof(NetlibUser));
thisUser->handleType = NLH_USER;
thisUser->user = *nlu;
@@ -201,7 +201,7 @@ static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam) static INT_PTR NetlibGetUserSettings(WPARAM wParam, LPARAM lParam)
{
NETLIBUSERSETTINGS *nlus = (NETLIBUSERSETTINGS*)lParam;
- struct NetlibUser *nlu = (struct NetlibUser*)wParam;
+ NetlibUser *nlu = (NetlibUser*)wParam;
if (GetNetlibHandleType(nlu) != NLH_USER || nlus == NULL || nlus->cbSize != sizeof(NETLIBUSERSETTINGS)) {
SetLastError(ERROR_INVALID_PARAMETER);
@@ -214,7 +214,7 @@ static INT_PTR NetlibGetUserSettings(WPARAM wParam, LPARAM lParam) static INT_PTR NetlibSetUserSettings(WPARAM wParam, LPARAM lParam)
{
NETLIBUSERSETTINGS *nlus = (NETLIBUSERSETTINGS*)lParam;
- struct NetlibUser *nlu = (struct NetlibUser*)wParam;
+ NetlibUser *nlu = (NetlibUser*)wParam;
if (GetNetlibHandleType(nlu) != NLH_USER || nlus == NULL || nlus->cbSize != sizeof(NETLIBUSERSETTINGS)) {
SetLastError(ERROR_INVALID_PARAMETER);
@@ -245,7 +245,7 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) {
case NLH_USER:
{
- struct NetlibUser *nlu = (struct NetlibUser*)wParam;
+ NetlibUser *nlu = (NetlibUser*)wParam;
{
mir_cslock lck(csNetlibUser);
int i = netlibUser.getIndex(nlu);
@@ -263,7 +263,7 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) }
case NLH_CONNECTION:
{
- struct NetlibConnection *nlc = (struct NetlibConnection*)wParam;
+ NetlibConnection *nlc = (struct NetlibConnection*)wParam;
HANDLE waitHandles[4];
DWORD waitResult;
diff --git a/src/modules/netlib/netlib.h b/src/modules/netlib/netlib.h index c7ca929e0c..290d9b44b6 100644 --- a/src/modules/netlib/netlib.h +++ b/src/modules/netlib/netlib.h @@ -48,7 +48,7 @@ struct NetlibNestedCriticalSection struct NetlibHTTPProxyPacketQueue
{
- struct NetlibHTTPProxyPacketQueue *next;
+ NetlibHTTPProxyPacketQueue *next;
PBYTE dataBuffer;
int dataBufferLen;
};
@@ -68,16 +68,16 @@ struct NetlibConnection bool proxyAuthNeeded;
bool dnsThroughProxy;
bool termRequested;
- struct NetlibUser *nlu;
+ NetlibUser *nlu;
NETLIBHTTPPROXYINFO nlhpi;
PBYTE dataBuffer;
int dataBufferLen;
CRITICAL_SECTION csHttpSequenceNums;
HANDLE hOkToCloseEvent;
LONG dontCloseNow;
- struct NetlibNestedCriticalSection ncsSend, ncsRecv;
+ NetlibNestedCriticalSection ncsSend, ncsRecv;
HSSL hSsl;
- struct NetlibHTTPProxyPacketQueue * pHttpProxyPacketQueue;
+ NetlibHTTPProxyPacketQueue * pHttpProxyPacketQueue;
char *szNewUrl;
char *szProxyServer;
WORD wProxyPort;
@@ -93,7 +93,7 @@ struct NetlibBoundPort { SOCKET s6;
WORD wPort;
WORD wExPort;
- struct NetlibUser *nlu;
+ NetlibUser *nlu;
NETLIBNEWCONNECTIONPROC_V2 pfnNewConnectionV2;
HANDLE hThread;
void *pExtra;
@@ -101,7 +101,7 @@ struct NetlibBoundPort { struct NetlibPacketRecver {
int handleType;
- struct NetlibConnection *nlc;
+ NetlibConnection *nlc;
NETLIBPACKETRECVER packetRecver;
};
@@ -109,12 +109,12 @@ struct NetlibPacketRecver { void NetlibFreeUserSettingsStruct(NETLIBUSERSETTINGS *settings);
void NetlibDoClose(NetlibConnection *nlc, bool noShutdown = false);
INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM lParam);
-void NetlibInitializeNestedCS(struct NetlibNestedCriticalSection *nlncs);
-void NetlibDeleteNestedCS(struct NetlibNestedCriticalSection *nlncs);
+void NetlibInitializeNestedCS(NetlibNestedCriticalSection *nlncs);
+void NetlibDeleteNestedCS(NetlibNestedCriticalSection *nlncs);
#define NLNCS_SEND 0
#define NLNCS_RECV 1
-int NetlibEnterNestedCS(struct NetlibConnection *nlc, int which);
-void NetlibLeaveNestedCS(struct NetlibNestedCriticalSection *nlncs);
+int NetlibEnterNestedCS(NetlibConnection *nlc, int which);
+void NetlibLeaveNestedCS(NetlibNestedCriticalSection *nlncs);
INT_PTR NetlibBase64Encode(WPARAM wParam, LPARAM lParam);
INT_PTR NetlibBase64Decode(WPARAM wParam, LPARAM lParam);
INT_PTR NetlibHttpUrlEncode(WPARAM wParam, LPARAM lParam);
@@ -129,7 +129,7 @@ char* NetlibGetIeProxy(char *szUrl); bool NetlibGetIeProxyConn(NetlibConnection *nlc, bool forceHttps);
//netlibbind.c
-int NetlibFreeBoundPort(struct NetlibBoundPort *nlbp);
+int NetlibFreeBoundPort(NetlibBoundPort *nlbp);
INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam);
bool BindSocketToPort(const char *szPorts, SOCKET s, SOCKET s6, int* portn);
@@ -143,9 +143,9 @@ NETLIBHTTPREQUEST* NetlibHttpRecv(NetlibConnection* nlc, DWORD hflags, DWORD dfl void NetlibConnFromUrl(const char* szUrl, bool secur, NETLIBOPENCONNECTION &nloc);
//netlibhttpproxy.c
-int NetlibInitHttpConnection(struct NetlibConnection *nlc, struct NetlibUser *nlu, NETLIBOPENCONNECTION *nloc);
-int NetlibHttpGatewayRecv(struct NetlibConnection *nlc, char *buf, int len, int flags);
-int NetlibHttpGatewayPost(struct NetlibConnection *nlc, const char *buf, int len, int flags);
+int NetlibInitHttpConnection(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENCONNECTION *nloc);
+int NetlibHttpGatewayRecv(NetlibConnection *nlc, char *buf, int len, int flags);
+int NetlibHttpGatewayPost(NetlibConnection *nlc, const char *buf, int len, int flags);
void HttpGatewayRemovePacket(NetlibConnection *nlc, int pck);
INT_PTR NetlibHttpGatewaySetInfo(WPARAM wParam, LPARAM lParam);
@@ -154,13 +154,13 @@ INT_PTR NetlibHttpSetSticky(WPARAM wParam, LPARAM lParam); //netliblog.c
void NetlibLogShowOptions(void);
-void NetlibDumpData(struct NetlibConnection *nlc, PBYTE buf, int len, int sent, int flags);
+void NetlibDumpData(NetlibConnection *nlc, PBYTE buf, int len, int sent, int flags);
void NetlibLogf(NetlibUser* nlu, const char *fmt, ...);
void NetlibLogInit(void);
void NetlibLogShutdown(void);
//netlibopenconn.c
-DWORD DnsLookup(struct NetlibUser *nlu, const char *szHost);
+DWORD DnsLookup(NetlibUser *nlu, const char *szHost);
int WaitUntilReadable(SOCKET s, DWORD dwTimeout, bool check = false);
int WaitUntilWritable(SOCKET s, DWORD dwTimeout);
bool NetlibDoConnect(NetlibConnection *nlc);
@@ -209,12 +209,12 @@ HANDLE NetlibInitSecurityProvider(const char* szProvider, const char* szPrincipa char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, const TCHAR* login, const TCHAR* psw,
bool http, unsigned& complete);
-static __inline INT_PTR NLSend(struct NetlibConnection *nlc, const char *buf, int len, int flags) {
+static __inline INT_PTR NLSend(NetlibConnection *nlc, const char *buf, int len, int flags) {
NETLIBBUFFER nlb = {(char*)buf, len, flags};
return NetlibSend((WPARAM)nlc, (LPARAM)&nlb);
}
-static __inline INT_PTR NLRecv(struct NetlibConnection *nlc, char *buf, int len, int flags) {
+static __inline INT_PTR NLRecv(NetlibConnection *nlc, char *buf, int len, int flags) {
NETLIBBUFFER nlb = {buf, len, flags};
return NetlibRecv((WPARAM)nlc, (LPARAM)&nlb);
}
diff --git a/src/modules/netlib/netlibbind.cpp b/src/modules/netlib/netlibbind.cpp index 24aca3c492..10ac9b3725 100644 --- a/src/modules/netlib/netlibbind.cpp +++ b/src/modules/netlib/netlibbind.cpp @@ -123,7 +123,7 @@ static void NetlibBindAcceptThread(void* param) SOCKET s;
SOCKADDR_INET_M sin;
int sinLen;
- struct NetlibConnection *nlc;
+ NetlibConnection *nlc;
struct NetlibBoundPort *nlbp = (NetlibBoundPort*)param;
NetlibLogf(nlbp->nlu, "(%u) Port %u opened for incoming connections", nlbp->s, nlbp->wPort);
@@ -173,7 +173,7 @@ static void NetlibBindAcceptThread(void* param) INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam)
{
NETLIBBIND *nlb = (NETLIBBIND*)lParam;
- struct NetlibUser *nlu = (struct NetlibUser*)wParam;
+ NetlibUser *nlu = (NetlibUser*)wParam;
struct NetlibBoundPort *nlbp;
SOCKADDR_IN sin = {0};
SOCKADDR_IN6 sin6 = {0};
diff --git a/src/modules/netlib/netlibhttp.cpp b/src/modules/netlib/netlibhttp.cpp index 5830198596..9aafc3d066 100644 --- a/src/modules/netlib/netlibhttp.cpp +++ b/src/modules/netlib/netlibhttp.cpp @@ -104,7 +104,7 @@ static void AppendToCharBuffer(struct ResizableCharBuffer *rcb, const char *fmt, rcb->iEnd += charsDone;
}
-static int RecvWithTimeoutTime(struct NetlibConnection *nlc, unsigned dwTimeoutTime, char *buf, int len, int flags)
+static int RecvWithTimeoutTime(NetlibConnection *nlc, unsigned dwTimeoutTime, char *buf, int len, int flags)
{
DWORD dwTimeNow;
@@ -363,7 +363,7 @@ static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, return 1;
}
-static int SendHttpRequestAndData(struct NetlibConnection *nlc, struct ResizableCharBuffer *httpRequest, NETLIBHTTPREQUEST *nlhr, int sendContentLengthHeader)
+static int SendHttpRequestAndData(NetlibConnection *nlc, struct ResizableCharBuffer *httpRequest, NETLIBHTTPREQUEST *nlhr, int sendContentLengthHeader)
{
bool sendData = (nlhr->requestType == REQUEST_POST || nlhr->requestType == REQUEST_PUT);
@@ -396,7 +396,7 @@ static int SendHttpRequestAndData(struct NetlibConnection *nlc, struct Resizable INT_PTR NetlibHttpSendRequest(WPARAM wParam, LPARAM lParam)
{
- struct NetlibConnection *nlc = (struct NetlibConnection*)wParam;
+ NetlibConnection *nlc = (struct NetlibConnection*)wParam;
NETLIBHTTPREQUEST *nlhr = (NETLIBHTTPREQUEST*)lParam;
NETLIBHTTPREQUEST *nlhrReply = NULL;
HttpSecurityContext httpSecurity;
@@ -725,7 +725,7 @@ INT_PTR NetlibHttpFreeRequestStruct(WPARAM, LPARAM lParam) INT_PTR NetlibHttpRecvHeaders(WPARAM wParam, LPARAM lParam)
{
- struct NetlibConnection *nlc = (struct NetlibConnection*)wParam;
+ NetlibConnection *nlc = (struct NetlibConnection*)wParam;
if ( !NetlibEnterNestedCS(nlc, NLNCS_RECV))
return 0;
diff --git a/src/modules/netlib/netlibhttpproxy.cpp b/src/modules/netlib/netlibhttpproxy.cpp index efdb0a5ab4..efcaca9e3b 100644 --- a/src/modules/netlib/netlibhttpproxy.cpp +++ b/src/modules/netlib/netlibhttpproxy.cpp @@ -62,7 +62,7 @@ void HttpGatewayRemovePacket(NetlibConnection *nlc, int pck) }
}
-static bool NetlibHttpGatewaySend(struct NetlibConnection *nlc, RequestType reqType, const char *buf, int len)
+static bool NetlibHttpGatewaySend(NetlibConnection *nlc, RequestType reqType, const char *buf, int len)
{
NETLIBHTTPREQUEST nlhrSend = {0};
char szUrl[512];
@@ -222,7 +222,7 @@ static bool NetlibHttpGatewayOscarPost(NetlibConnection *nlc, const char *buf, i return res;
}
- int NetlibHttpGatewayPost(struct NetlibConnection *nlc, const char *buf, int len, int flags)
+ int NetlibHttpGatewayPost(NetlibConnection *nlc, const char *buf, int len, int flags)
{
if (nlc->nlhpi.szHttpGetUrl != NULL)
return NetlibHttpGatewayOscarPost(nlc, buf, len, flags) ? len : SOCKET_ERROR;
@@ -267,7 +267,7 @@ static bool NetlibHttpGatewayOscarPost(NetlibConnection *nlc, const char *buf, i #define NETLIBHTTP_RETRYCOUNT 3
#define NETLIBHTTP_RETRYTIMEOUT 2000
-int NetlibHttpGatewayRecv(struct NetlibConnection *nlc, char *buf, int len, int flags)
+int NetlibHttpGatewayRecv(NetlibConnection *nlc, char *buf, int len, int flags)
{
bool peek = (flags & MSG_PEEK) != 0;
@@ -399,7 +399,7 @@ int NetlibHttpGatewayRecv(struct NetlibConnection *nlc, char *buf, int len, int return SOCKET_ERROR;
}
-int NetlibInitHttpConnection(struct NetlibConnection *nlc, struct NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
+int NetlibInitHttpConnection(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
{
NETLIBHTTPREQUEST *nlhrReply = NULL;
@@ -449,7 +449,7 @@ int NetlibInitHttpConnection(struct NetlibConnection *nlc, struct NetlibUser *nl INT_PTR NetlibHttpGatewaySetInfo(WPARAM wParam, LPARAM lParam)
{
NETLIBHTTPPROXYINFO *nlhpi = (NETLIBHTTPPROXYINFO*)lParam;
- struct NetlibConnection *nlc = (struct NetlibConnection*)wParam;
+ NetlibConnection *nlc = (struct NetlibConnection*)wParam;
if (GetNetlibHandleType(nlc) != NLH_CONNECTION || nlhpi == NULL ||
nlhpi->cbSize < (sizeof(NETLIBHTTPPROXYINFO) - sizeof(int)) ||
@@ -474,7 +474,7 @@ INT_PTR NetlibHttpGatewaySetInfo(WPARAM wParam, LPARAM lParam) INT_PTR NetlibHttpSetSticky(WPARAM wParam, LPARAM lParam)
{
- struct NetlibUser * nu = (struct NetlibUser*)wParam;
+ NetlibUser * nu = (NetlibUser*)wParam;
if (GetNetlibHandleType(nu) != NLH_USER) return ERROR_INVALID_PARAMETER;
mir_free(nu->szStickyHeaders);
nu->szStickyHeaders = mir_strdup((char*)lParam); // pointer is ours
@@ -484,7 +484,7 @@ INT_PTR NetlibHttpSetSticky(WPARAM wParam, LPARAM lParam) INT_PTR NetlibHttpSetPollingTimeout(WPARAM wParam, LPARAM lParam)
{
int oldTimeout;
- struct NetlibConnection *nlc = (struct NetlibConnection*)wParam;
+ NetlibConnection *nlc = (struct NetlibConnection*)wParam;
if (GetNetlibHandleType(nlc) != NLH_CONNECTION) return -1;
oldTimeout = nlc->pollingTimeout;
nlc->pollingTimeout = lParam;
diff --git a/src/modules/netlib/netliblog.cpp b/src/modules/netlib/netliblog.cpp index b8567a494f..4f0aecff29 100644 --- a/src/modules/netlib/netliblog.cpp +++ b/src/modules/netlib/netliblog.cpp @@ -37,13 +37,12 @@ struct { int toOutputDebugString;
int toFile;
int toLog;
- TCHAR* szFile;
- TCHAR* szUserFile;
+ TCHAR *szFile;
+ TCHAR *szUserFile;
int timeFormat;
int showUser;
int dumpSent, dumpRecv, dumpProxy, dumpSsl;
int textDumps, autoDetectText;
- CRITICAL_SECTION cs;
int save;
} logOptions = {0};
@@ -55,6 +54,7 @@ typedef struct { static __int64 mirandaStartTime, perfCounterFreq;
static int bIsActive = TRUE;
static HANDLE hLogEvent = NULL;
+static HANDLE hLogger = NULL;
static const TCHAR* szTimeFormats[] =
{
@@ -210,8 +210,6 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa db_set_ts(NULL, "Netlib", "RunAtStart", str);
db_set_b(NULL, "Netlib", "ShowLogOptsAtStart", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SHOWTHISDLGATSTART));
- mir_cslock lck(logOptions.cs);
-
mir_free(logOptions.szUserFile);
GetWindowText( GetDlgItem(hwndDlg, IDC_FILENAME), str, MAX_PATH);
logOptions.szUserFile = mir_tstrdup(str);
@@ -309,8 +307,8 @@ static INT_PTR ShowOptions(WPARAM, LPARAM) static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam)
{
- struct NetlibUser *nlu = (struct NetlibUser*)wParam;
- struct NetlibUser nludummy;
+ NetlibUser *nlu = (NetlibUser*)wParam;
+ NetlibUser nludummy;
const char *pszMsg = (const char*)lParam;
char szTime[32], szHead[128];
LARGE_INTEGER liTimeNow;
@@ -374,18 +372,8 @@ static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam) }
if (logOptions.toFile && logOptions.szFile[0]) {
- mir_cslock lck(logOptions.cs);
-
- FILE *fp = _tfopen(logOptions.szFile, _T("ab"));
- if ( !fp) {
- CreatePathToFileT(logOptions.szFile);
- fp = _tfopen(logOptions.szFile, _T("at"));
- }
- if (fp) {
- size_t len = strlen(pszMsg);
- fprintf(fp, "%s%s%s", szHead, pszMsg, pszMsg[len-1] == '\n' ? "" : "\r\n");
- fclose(fp);
- }
+ size_t len = strlen(pszMsg);
+ mir_writeLogA(hLogger, "%s%s%s", szHead, pszMsg, pszMsg[len-1] == '\n' ? "" : "\r\n");
}
LOGMSG logMsg = { szHead, pszMsg };
@@ -424,13 +412,13 @@ void NetlibLogf(NetlibUser* nlu, const char *fmt, ...) NetlibLog((WPARAM)nlu, (LPARAM)szText);
}
-void NetlibDumpData(struct NetlibConnection *nlc, PBYTE buf, int len, int sent, int flags)
+void NetlibDumpData(NetlibConnection *nlc, PBYTE buf, int len, int sent, int flags)
{
int isText = 1;
char szTitleLine[128];
char *szBuf;
int titleLineLen;
- struct NetlibUser *nlu;
+ NetlibUser *nlu;
bool useStack = false;
// This section checks a number of conditions and aborts
@@ -550,7 +538,6 @@ void NetlibLogInit(void) CreateServiceFunction(MS_NETLIB_LOGW, NetlibLogW);
hLogEvent = CreateHookableEvent(ME_NETLIB_FASTDUMP);
- InitializeCriticalSection(&logOptions.cs);
logOptions.dumpRecv = db_get_b(NULL, "Netlib", "DumpRecv", 1);
logOptions.dumpSent = db_get_b(NULL, "Netlib", "DumpSent", 1);
logOptions.dumpProxy = db_get_b(NULL, "Netlib", "DumpProxy", 1);
@@ -577,12 +564,7 @@ void NetlibLogInit(void) logOptions.szFile = Utils_ReplaceVarsT(logOptions.szUserFile);
}
- if (logOptions.toFile && logOptions.szFile[0]) {
- FILE *fp;
- fp = _tfopen(logOptions.szFile, _T("wt"));
- if (fp)
- fclose(fp);
- }
+ hLogger = mir_createLog("Netlib", LPGENT("Standard netlib log"), logOptions.szFile, 0);
if (db_get_b(NULL, "Netlib", "ShowLogOptsAtStart", 0))
NetlibLogShowOptions();
@@ -603,7 +585,6 @@ void NetlibLogShutdown(void) DestroyHookableEvent(hLogEvent); hLogEvent = NULL;
if (IsWindow(logOptions.hwndOpts))
DestroyWindow(logOptions.hwndOpts);
- DeleteCriticalSection(&logOptions.cs);
mir_free(logOptions.szFile);
mir_free(logOptions.szUserFile);
}
diff --git a/src/modules/netlib/netlibopenconn.cpp b/src/modules/netlib/netlibopenconn.cpp index 4b4a5ea4d8..57c83ed507 100644 --- a/src/modules/netlib/netlibopenconn.cpp +++ b/src/modules/netlib/netlibopenconn.cpp @@ -33,7 +33,7 @@ static int iUPnPCleanup = 0; #define RECV_DEFAULT_TIMEOUT 60000
//returns in network byte order
-DWORD DnsLookup(struct NetlibUser *nlu, const char *szHost)
+DWORD DnsLookup(NetlibUser *nlu, const char *szHost)
{
HOSTENT* host;
DWORD ip = inet_addr(szHost);
@@ -91,7 +91,7 @@ int WaitUntilWritable(SOCKET s, DWORD dwTimeout) return 1;
}
-bool RecvUntilTimeout(struct NetlibConnection *nlc, char *buf, int len, int flags, DWORD dwTimeout)
+bool RecvUntilTimeout(NetlibConnection *nlc, char *buf, int len, int flags, DWORD dwTimeout)
{
int nReceived = 0;
DWORD dwTimeNow, dwCompleteTime = GetTickCount() + dwTimeout;
@@ -156,7 +156,7 @@ static int NetlibInitSocks4Connection(NetlibConnection *nlc, NetlibUser *nlu, NE return 0;
}
-static int NetlibInitSocks5Connection(struct NetlibConnection *nlc, struct NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
+static int NetlibInitSocks5Connection(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
{
//rfc1928
BYTE buf[258];
@@ -297,7 +297,7 @@ static int NetlibInitSocks5Connection(struct NetlibConnection *nlc, struct Netli return 1;
}
-static bool NetlibInitHttpsConnection(struct NetlibConnection *nlc, struct NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
+static bool NetlibInitHttpsConnection(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
{
//rfc2817
NETLIBHTTPREQUEST nlhrSend = {0}, *nlhrReply;
@@ -344,7 +344,7 @@ static bool NetlibInitHttpsConnection(struct NetlibConnection *nlc, struct Netli return true;
}
-static void FreePartiallyInitedConnection(struct NetlibConnection *nlc)
+static void FreePartiallyInitedConnection(NetlibConnection *nlc)
{
DWORD dwOriginalLastError = GetLastError();
@@ -672,7 +672,7 @@ static bool my_connect(NetlibConnection *nlc, NETLIBOPENCONNECTION * nloc) return MyGetaddrinfo && MyFreeaddrinfo ? my_connectIPv6(nlc, nloc) : my_connectIPv4(nlc, nloc);
}
-static int NetlibHttpFallbackToDirect(struct NetlibConnection *nlc, struct NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
+static int NetlibHttpFallbackToDirect(NetlibConnection *nlc, NetlibUser *nlu, NETLIBOPENCONNECTION *nloc)
{
NetlibDoClose(nlc, true);
diff --git a/src/modules/netlib/netlibpktrecver.cpp b/src/modules/netlib/netlibpktrecver.cpp index 45e39344c5..aa41bf6c8a 100644 --- a/src/modules/netlib/netlibpktrecver.cpp +++ b/src/modules/netlib/netlibpktrecver.cpp @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. INT_PTR NetlibPacketRecverCreate(WPARAM wParam, LPARAM lParam)
{
- struct NetlibConnection *nlc = (struct NetlibConnection*)wParam;
+ NetlibConnection *nlc = (struct NetlibConnection*)wParam;
struct NetlibPacketRecver *nlpr;
if (GetNetlibHandleType(nlc) != NLH_CONNECTION || lParam == 0) {
|