diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2014-06-14 22:35:16 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2014-06-14 22:35:16 +0000 |
commit | 3942df7207beeb9f2fc08a6deb1d375badbe066a (patch) | |
tree | 10cff5e3f6b525410e00207d05578b30025c7d9f /plugins/HTTPServer/src/main.cpp | |
parent | c5fb4140e75fe56e24caa98fda1f13b14955efe9 (diff) |
plugin unicoded
git-svn-id: http://svn.miranda-ng.org/main/trunk@9488 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/HTTPServer/src/main.cpp')
-rw-r--r-- | plugins/HTTPServer/src/main.cpp | 149 |
1 files changed, 77 insertions, 72 deletions
diff --git a/plugins/HTTPServer/src/main.cpp b/plugins/HTTPServer/src/main.cpp index f2b57ce946..7f0099609a 100644 --- a/plugins/HTTPServer/src/main.cpp +++ b/plugins/HTTPServer/src/main.cpp @@ -18,27 +18,27 @@ #include "Glob.h"
-#define szConfigFile "HTTPServer.xml"
+#define szConfigFile _T("HTTPServer.xml")
const char szXmlHeader[] = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n"
"<?xml-stylesheet type=\"text/xsl\" href=\"HTTPServer.xsl\"?>\r\n"
"<config>\r\n";
-const char szXmlData[] = "\t<share>\r\n"
- "\t\t<name>%s</name>\r\n"
- "\t\t<file>%s</file>\r\n"
- "\t\t<max_downloads>%d</max_downloads>\r\n"
- "\t\t<ip_address>%d.%d.%d.%d</ip_address>\r\n"
- "\t\t<ip_mask>%d.%d.%d.%d</ip_mask>\r\n"
- "\t</share>\r\n";
+const TCHAR szXmlData[] = _T("\t<share>\r\n")
+ _T("\t\t<name>%s</name>\r\n")
+ _T("\t\t<file>%s</file>\r\n")
+ _T("\t\t<max_downloads>%d</max_downloads>\r\n")
+ _T("\t\t<ip_address>%d.%d.%d.%d</ip_address>\r\n")
+ _T("\t\t<ip_mask>%d.%d.%d.%d</ip_mask>\r\n")
+ _T("\t</share>\r\n");
const char szXmlTail[] = "</config>";
-const char* pszDefaultShares[] = {
- "htdocs\\@settings\\favicon.ico", "/favicon.ico",
- "htdocs\\@settings\\index.xsl", "/index.xsl",
- "htdocs\\@settings\\theme\\", "/theme/",
- "htdocs\\", "/",
+const TCHAR* pszDefaultShares[] = {
+ _T("htdocs\\@settings\\favicon.ico"), _T("/favicon.ico"),
+ _T("htdocs\\@settings\\index.xsl"), _T("/index.xsl"),
+ _T("htdocs\\@settings\\theme\\"), _T("/theme/"),
+ _T("htdocs\\"), _T("/"),
0, 0
};
@@ -50,7 +50,7 @@ HANDLE hDirectBoundPort; HINSTANCE hInstance = NULL;
-string sLogFilePath;
+tstring sLogFilePath;
// static so they can not be used from other modules ( sourcefiles )
static HANDLE hEventSystemInit = 0;
@@ -63,7 +63,7 @@ static HANDLE hHttpGetAllShares = 0; static HGENMENU hAcceptConnectionsMenuItem = 0;
-char szPluginPath[MAX_PATH] = {0};
+TCHAR szPluginPath[MAX_PATH] = {0};
int nPluginPathLen = 0;
DWORD dwLocalIpAddress = 0;
@@ -125,9 +125,10 @@ bool bOpenLogFile() { }
-bool bWriteToFile(HANDLE hFile, const char * pszSrc, int nLen = -1) {
+bool bWriteToFile(HANDLE hFile, const TCHAR *pszSrc, int nLen = -1)
+{
if (nLen < 0)
- nLen = (int)strlen(pszSrc);
+ nLen = (int)_tcslen(pszSrc);
DWORD dwBytesWritten;
return WriteFile(hFile, pszSrc, nLen, &dwBytesWritten, NULL) && (dwBytesWritten == (DWORD)nLen);
}
@@ -147,7 +148,8 @@ bool bWriteToFile(HANDLE hFile, const char * pszSrc, int nLen = -1) { // Developer : KN
/////////////////////////////////////////////////////////////////////
-void LogEvent(const TCHAR * pszTitle, const char * pszLog) {
+void LogEvent(const TCHAR *pszTitle, const TCHAR *pszLog)
+{
HANDLE hFile = CreateFile(sLogFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
MessageBox(NULL, TranslateT("Failed to open or create log file"), MSG_BOX_TITEL, MB_OK);
@@ -159,20 +161,20 @@ void LogEvent(const TCHAR * pszTitle, const char * pszLog) { return;
}
- char szTmp[128];
+ TCHAR szTmp[128];
time_t now;
time(&now);
- int nLen = (int)strftime(szTmp, sizeof(szTmp), "%d-%m-%Y %H:%M:%S -- ", localtime(&now));
+ int nLen = (int)_tcsftime(szTmp, SIZEOF(szTmp), _T("%d-%m-%Y %H:%M:%S -- "), localtime(&now));
- int nLogLen = (int)strlen(pszLog);
+ int nLogLen = (int)_tcslen(pszLog);
while (nLogLen > 0 && (pszLog[nLogLen-1] == '\r' || pszLog[nLogLen-1] == '\n'))
nLogLen--;
if (!bWriteToFile(hFile, szTmp, nLen) ||
!bWriteToFile(hFile, pszTitle) ||
- !bWriteToFile(hFile, " : ") ||
+ !bWriteToFile(hFile, _T(" : ")) ||
!bWriteToFile(hFile, pszLog, nLogLen) ||
- !bWriteToFile(hFile, "\r\n")) {
+ !bWriteToFile(hFile, _T("\r\n"))) {
MessageBox(NULL, TranslateT("Failed to write some part of the log file"), MSG_BOX_TITEL, MB_OK);
}
CloseHandle(hFile);
@@ -193,11 +195,12 @@ void LogEvent(const TCHAR * pszTitle, const char * pszLog) { // Developer : KN
/////////////////////////////////////////////////////////////////////
-DWORD dwReadIPAddress(char * pszStr, bool &bError) {
+DWORD dwReadIPAddress(TCHAR *pszStr, bool &bError)
+{
DWORD ip = 0;
- char *pszEnd;
+ TCHAR *pszEnd;
for (int n = 0 ; n < 4 ; n++) {
- int nVal = strtol(pszStr, &pszEnd, 10);
+ int nVal = _tcstol(pszStr, &pszEnd, 10);
if (pszEnd <= pszStr || (n != 3 && pszEnd[0] != '.') || (nVal < 0 || nVal > 255)) {
bError = true;
return 0;
@@ -221,20 +224,21 @@ DWORD dwReadIPAddress(char * pszStr, bool &bError) { // Developer : KN
/////////////////////////////////////////////////////////////////////
-bool bReadConfigurationFile() {
+bool bReadConfigurationFile()
+{
CLFileShareListAccess clCritSection;
CLFileShareNode * pclLastNode = NULL;
- char szBuf[1000];
- strcpy(szBuf, szPluginPath);
- strcat(szBuf, szConfigFile);
+ TCHAR szBuf[1000];
+ _tcscpy(szBuf, szPluginPath);
+ _tcscat(szBuf, szConfigFile);
HANDLE hFile = CreateFile(szBuf, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return false;
- char *pszCurPos = szBuf;
+ TCHAR *pszCurPos = szBuf;
bool bEof = false;
while (!bEof) {
@@ -242,33 +246,33 @@ bool bReadConfigurationFile() { // move rest of buffer to front
if (pszCurPos && pszCurPos != szBuf) {
- dwBytesInBuffer = DWORD(sizeof(szBuf) - (pszCurPos - szBuf));
+ dwBytesInBuffer = DWORD(SIZEOF(szBuf) - (pszCurPos - szBuf));
memmove(szBuf, pszCurPos, dwBytesInBuffer);
}
// append data to buffer
DWORD dwBytesRead = 0;
- bEof = !ReadFile(hFile, &szBuf[dwBytesInBuffer], sizeof(szBuf) - dwBytesInBuffer,
+ bEof = !ReadFile(hFile, &szBuf[dwBytesInBuffer], SIZEOF(szBuf) - dwBytesInBuffer,
&dwBytesRead, NULL) || dwBytesRead <= 0;
pszCurPos = szBuf;
if (pszCurPos) {
- while (pszCurPos && (pszCurPos = strstr(pszCurPos, "<share>")) != NULL) {
+ while (pszCurPos && (pszCurPos = _tcsstr(pszCurPos, _T("<share>"))) != NULL) {
pszCurPos += 7;
- char * pszColData[5] = {NULL};
+ TCHAR *pszColData[5] = {NULL};
for (int n = 0 ; n < 5 ; n++) {
- pszColData[n] = strstr(pszCurPos, ">");
+ pszColData[n] = _tcsstr(pszCurPos, _T(">"));
if (!pszColData[n])
break;
pszColData[n] += 1;
- pszCurPos = strstr(pszColData[n], "</");
+ pszCurPos = _tcsstr(pszColData[n], _T("</"));
if (!pszCurPos)
break;
pszCurPos[0] = 0;// NULL terminate row data, we overwrite the '<'
- pszCurPos = strstr(pszCurPos + 3, ">");
+ pszCurPos = _tcsstr(pszCurPos + 3, _T(">"));
if (!pszCurPos)
break;
@@ -280,9 +284,9 @@ bool bReadConfigurationFile() { CLFileShareNode * pcl = new CLFileShareNode(pszColData[0], pszColData[1]);
bool bError = false;
- char * pszEnd;
+ TCHAR * pszEnd;
- pcl->st.nMaxDownloads = strtol(pszColData[2], &pszEnd, NULL);
+ pcl->st.nMaxDownloads = _tcstol(pszColData[2], &pszEnd, NULL);
if (!pszEnd || *pszEnd != NULL)
bError = true;
@@ -324,28 +328,29 @@ bool bReadConfigurationFile() { // Developer : KN
/////////////////////////////////////////////////////////////////////
-bool bWriteConfigurationFile() {
+bool bWriteConfigurationFile()
+{
CLFileShareListAccess clCritSection;
- char szBuf[1000];
- strcpy(szBuf, szPluginPath);
- strcat(szBuf, szConfigFile);
+ TCHAR szBuf[1000];
+ _tcscpy(szBuf, szPluginPath);
+ _tcscat(szBuf, szConfigFile);
HANDLE hFile = CreateFile(szBuf, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
TCHAR temp[200];
- mir_sntprintf(temp, SIZEOF(temp), _T("%s%s"), TranslateT("Failed to open or create file "), _T(szConfigFile));
- MessageBox(NULL, temp , MSG_BOX_TITEL, MB_OK);
+ mir_sntprintf(temp, SIZEOF(temp), _T("%s%s"), TranslateT("Failed to open or create file "), szConfigFile);
+ MessageBox(NULL, temp, MSG_BOX_TITEL, MB_OK);
return false;
}
DWORD dwBytesWriten = 0;
if (! WriteFile(hFile, szXmlHeader, sizeof(szXmlHeader) - 1, &dwBytesWriten, NULL)) {
TCHAR temp[200];
- mir_sntprintf(temp, SIZEOF(temp), _T("%s%s"), TranslateT("Failed to write xml header to file "), _T(szConfigFile));
+ mir_sntprintf(temp, SIZEOF(temp), _T("%s%s"), TranslateT("Failed to write xml header to file "), szConfigFile);
MessageBox(NULL, temp, MSG_BOX_TITEL, MB_OK);
} else {
CLFileShareNode * pclCur = pclFirstNode;
while (pclCur) {
- DWORD dwBytesToWrite = mir_snprintf(szBuf, sizeof(szBuf), szXmlData ,
+ DWORD dwBytesToWrite = mir_sntprintf(szBuf, SIZEOF(szBuf), szXmlData,
pclCur->st.pszSrvPath,
pclCur->pszOrigRealPath,
pclCur->st.nMaxDownloads,
@@ -354,7 +359,7 @@ bool bWriteConfigurationFile() { if (! WriteFile(hFile, szBuf, dwBytesToWrite, &dwBytesWriten, NULL)) {
TCHAR temp[200];
- mir_sntprintf(temp, SIZEOF(temp), _T("%s%s"), TranslateT("Failed to write xml data to file "), _T(szConfigFile));
+ mir_sntprintf(temp, SIZEOF(temp), _T("%s%s"), TranslateT("Failed to write xml data to file "), szConfigFile);
MessageBox(NULL, temp, MSG_BOX_TITEL, MB_OK);
break;
}
@@ -363,7 +368,7 @@ bool bWriteConfigurationFile() { if (! WriteFile(hFile, szXmlTail, sizeof(szXmlTail) - 1, &dwBytesWriten, NULL)) {
TCHAR temp[200];
- mir_sntprintf(temp, SIZEOF(temp), _T("%s%s"), TranslateT("Failed to write xml tail to file "), _T(szConfigFile));
+ mir_sntprintf(temp, SIZEOF(temp), _T("%s%s"), TranslateT("Failed to write xml tail to file "), szConfigFile);
MessageBox(NULL, temp, MSG_BOX_TITEL, MB_OK);
}
}
@@ -394,9 +399,9 @@ static INT_PTR nAddChangeRemoveShare(WPARAM wParam, LPARAM lParam) { STFileShareInfo * pclNew = (STFileShareInfo*)lParam;
// make the server path lowercase
- char* pszPos = pclNew->pszSrvPath;
+ TCHAR *pszPos = pclNew->pszSrvPath;
while (*pszPos) {
- *pszPos = (char)tolower(*pszPos);
+ *pszPos = tolower(*pszPos);
pszPos++;
}
@@ -404,7 +409,7 @@ static INT_PTR nAddChangeRemoveShare(WPARAM wParam, LPARAM lParam) { return 1002;
CLFileShareListAccess clCritSection;
- bool bIsDirectory = (pclNew->pszSrvPath[strlen(pclNew->pszSrvPath)-1] == '/');
+ bool bIsDirectory = (pclNew->pszSrvPath[_tcslen(pclNew->pszSrvPath)-1] == '/');
CLFileShareNode **pclPrev = &pclFirstNode;
CLFileShareNode * pclCur = pclFirstNode;
@@ -418,7 +423,7 @@ static INT_PTR nAddChangeRemoveShare(WPARAM wParam, LPARAM lParam) { }
while (pclCur) {
- if (_stricmp(pclCur->st.pszSrvPath, pclNew->pszSrvPath) == 0) {
+ if (_tcsicmp(pclCur->st.pszSrvPath, pclNew->pszSrvPath) == 0) {
if (pclCur->bAnyUsers()) {
// Some downloads are in progress we will try an terminate them !!
// we try for 5 sec.
@@ -484,10 +489,10 @@ static INT_PTR nGetShare(WPARAM /*wParam*/, LPARAM lParam) { STFileShareInfo * pclShare = (STFileShareInfo*)lParam;
CLFileShareNode * pclCur = pclFirstNode;
while (pclCur) {
- if (strcmp(pclCur->st.pszSrvPath, pclShare->pszSrvPath) == 0) {
- if (pclShare->dwMaxRealPath <= strlen(pclCur->st.pszRealPath) + 1)
+ if (_tcscmp(pclCur->st.pszSrvPath, pclShare->pszSrvPath) == 0) {
+ if (pclShare->dwMaxRealPath <= _tcslen(pclCur->st.pszRealPath) + 1)
return 1003;
- strcpy(pclShare->pszRealPath, pclCur->st.pszRealPath);
+ _tcscpy(pclShare->pszRealPath, pclCur->st.pszRealPath);
pclShare->dwAllowedIP = pclCur->st.dwAllowedIP;
pclShare->dwAllowedMask = pclCur->st.dwAllowedMask;
pclShare->nMaxDownloads = pclCur->st.nMaxDownloads;
@@ -643,8 +648,8 @@ INT_PTR nToggelAcceptConnections(WPARAM wparam, LPARAM /*lparam*/) { hDirectBoundPort = (HANDLE) CallService(MS_NETLIB_BINDPORT, (WPARAM) hNetlibUser, (LPARAM) & nlb);
if (!hDirectBoundPort) {
TCHAR szTemp[200];
- mir_snprintf(szTemp, SIZEOF(szTemp), TranslateT("Failed to bind to port %s\r\nThis is most likely because another program or service is using this port") ,
- nlb.wPort == 80 ? "80" : nus.szIncomingPorts);
+ mir_sntprintf(szTemp, SIZEOF(szTemp), TranslateT("Failed to bind to port %s\r\nThis is most likely because another program or service is using this port") ,
+ nlb.wPort == 80 ? _T("80") : _A2T(nus.szIncomingPorts));
MessageBox(NULL, szTemp, MSG_BOX_TITEL, MB_OK);
return 1001;
}
@@ -716,11 +721,11 @@ int MainInit(WPARAM /*wparam*/, LPARAM /*lparam*/) { if (! bReadConfigurationFile()) {
//MessageBox( NULL, "Failed to read configuration file : " szConfigFile, MSG_BOX_TITEL, MB_OK );
- char szRealPath[MAX_PATH];
- char szSrvPath[MAX_PATH] = {0};
+ TCHAR szRealPath[MAX_PATH];
+ TCHAR szSrvPath[MAX_PATH] = {0};
STFileShareInfo share;
- const char** p = pszDefaultShares;
+ const TCHAR** p = pszDefaultShares;
while (*p) {
memset(&share, 0, sizeof(share));
share.lStructSize = sizeof(share);
@@ -729,12 +734,12 @@ int MainInit(WPARAM /*wparam*/, LPARAM /*lparam*/) { share.nMaxDownloads = -1;
share.pszRealPath = szRealPath;
- share.dwMaxRealPath = sizeof(szRealPath);
- strcpy(share.pszRealPath, p[0]);
+ share.dwMaxRealPath = SIZEOF(szRealPath);
+ _tcscpy(share.pszRealPath, p[0]);
share.pszSrvPath = szSrvPath;
- share.dwMaxSrvPath = sizeof(szSrvPath);
- strcpy(share.pszSrvPath, p[1]);
+ share.dwMaxSrvPath = SIZEOF(szSrvPath);
+ _tcscpy(share.pszSrvPath, p[1]);
if (CallService(MS_HTTP_ADD_CHANGE_REMOVE, 0, (LPARAM)&share))
break;
@@ -904,20 +909,20 @@ int nSystemShutdown(WPARAM /*wparam*/, LPARAM /*lparam*/) { return 1;
}
_tcsncat(szPluginPath,_T("\\HTTPServer\\"), MAX_PATH);
- int err = CreateDirectoryTree(szPluginPath);
+ int err = CreateDirectoryTreeT(szPluginPath);
if((err != 0) && (err != ERROR_ALREADY_EXISTS))
{
MessageBox(NULL, _T("Failed to create HTTPServer directory."), MSG_BOX_TITEL, MB_OK);
return 1;
}
- nPluginPathLen = (int)strlen(szPluginPath);
+ nPluginPathLen = (int)_tcslen(szPluginPath);
sLogFilePath = szPluginPath;
- sLogFilePath += "HTTPServer.log";
+ sLogFilePath += _T("HTTPServer.log");
- if (! bInitMimeHandling()) {
- MessageBox(NULL, "Failed to read configuration file : " szMimeTypeConfigFile, MSG_BOX_TITEL, MB_OK);
+ if (!bInitMimeHandling()) {
+ MessageBox(NULL, _T("Failed to read configuration file : ") szMimeTypeConfigFile, MSG_BOX_TITEL, MB_OK);
}
nMaxUploadSpeed = db_get_dw(NULL, MODULE, "MaxUploadSpeed", nMaxUploadSpeed);
@@ -932,7 +937,7 @@ int nSystemShutdown(WPARAM /*wparam*/, LPARAM /*lparam*/) { mi.pszContactOwner = NULL; //all contacts
mi.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SHARE_NEW_FILE));
mi.position = 1000085000;
- mi.pszName = LPGENT("Enable HTTP server");
+ mi.ptszName = LPGENT("Enable HTTP server");
mi.pszService = MS_HTTP_ACCEPT_CONNECTIONS;
hAcceptConnectionsMenuItem = Menu_AddMainMenuItem(&mi);
}
|