diff options
Diffstat (limited to 'HTTPServer/main.cpp')
-rw-r--r-- | HTTPServer/main.cpp | 126 |
1 files changed, 37 insertions, 89 deletions
diff --git a/HTTPServer/main.cpp b/HTTPServer/main.cpp index 0ff96f6..a8816d1 100644 --- a/HTTPServer/main.cpp +++ b/HTTPServer/main.cpp @@ -15,45 +15,14 @@ //along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#ifdef NDEBUG //release
-#include "AggressiveOptimize.h" //create small code
-#endif
-
-#include <windows.h>
-#include <commctrl.h>
-#include <process.h>
-#include <time.h>
-#include <stdio.h>
-
-#pragma warning( push, 3 )
-
-#include <string>
+#include "Glob.h"
using namespace std;
-#include "newpluginapi.h"
-#include "m_database.h"
-#include "m_clist.h"
-#include "m_skin.h"
-#include "m_langpack.h"
-#include "m_options.h"
-#include "m_system.h"
-#include "m_history.h"
-#include "m_userinfo.h"
-#include "m_netlib.h"
-#include "m_message.h"
-#include "m_popup.h"
-#include "m_protosvc.h"
-
-#pragma warning( pop )
-
-//#include <Winsock2.h>
-//#include <sphelper.h>
#include "m_HTTPServer.h"
#include "FileShareNode.h"
#include "HttpUser.h"
#include "GuiElements.h"
#include "MimeHandling.h"
-#include "Glob.h"
#include "resource.h"
#include "IndexCreation.h"
@@ -90,6 +59,8 @@ HANDLE hDirectBoundPort; HINSTANCE hInstance = NULL;
PLUGINLINK *pluginLink;
+MM_INTERFACE mmi;
+int hLangpack = 0;
string sLogFilePath;
@@ -127,23 +98,6 @@ void (*MirandaFree)(void*); bool bShutdownInProgress = false;
-
-struct NETLIBUSERSETTINGS_V032 {
- int cbSize; //to be filled in before calling
- int useProxy; //1 or 0
- int proxyType; //a PROXYTYPE_
- char* szProxyServer; //can be NULL
- int wProxyPort; //host byte order
- int useProxyAuth; //1 or 0. Always 0 for SOCKS4
- char* szProxyAuthUser; //can be NULL, always used by SOCKS4
- char* szProxyAuthPassword; //can be NULL
- int useProxyAuthNtlm; //1 or 0, only used by HTTP, HTTPS
- int dnsThroughProxy; //1 or 0
- int specifyIncomingPorts; //1 or 0
- char* szIncomingPorts; //can be NULL. Of form "1024-1050,1060-1070,2000"
-} ;
-
-
char* pszVersion = "0.1.2.2";
PLUGININFOEX pluginInfo = {
@@ -156,7 +110,7 @@ PLUGININFOEX pluginInfo = { "",
"© 2003-2009 Kennet Nielsen, Vampik, Houdini",
"http://www.miranda-im.org/download/details.php?action=viewfile&id=2304",
- 0,
+ UNICODE_AWARE,
0,
// {67848B07-83D2-49e9-8844-7E3DE268E304}
{ 0x67848b07, 0x83d2, 0x49e9, { 0x88, 0x44, 0x7e, 0x3d, 0xe2, 0x68, 0xe3, 0x4 } }
@@ -253,12 +207,12 @@ bool bWriteToFile(HANDLE hFile, const char * pszSrc, int nLen = -1) { void LogEvent(const char * pszTitle, const char * 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, "Failed to open or create log file", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to open or create log file"), MSG_BOX_TITEL, MB_OK);
return;
}
if (SetFilePointer(hFile, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER) {
CloseHandle(hFile);
- MessageBox(NULL, "Failed to move to the end of the log file", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to move to the end of the log file"), MSG_BOX_TITEL, MB_OK);
return;
}
@@ -276,7 +230,7 @@ void LogEvent(const char * pszTitle, const char * pszLog) { !bWriteToFile(hFile, " : ") ||
!bWriteToFile(hFile, pszLog, nLogLen) ||
!bWriteToFile(hFile, "\r\n")) {
- MessageBox(NULL, "Failed to write some part of the log file", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to write some part of the log file"), MSG_BOX_TITEL, MB_OK);
}
CloseHandle(hFile);
}
@@ -434,17 +388,17 @@ bool bWriteConfigurationFile() { strcat(szBuf, szConfigFile);
HANDLE hFile = CreateFile(szBuf, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
- MessageBox(NULL, "Failed to open or create file " szConfigFile, MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to open or create file ") szConfigFile, MSG_BOX_TITEL, MB_OK);
return false;
}
DWORD dwBytesWriten = 0;
if (! WriteFile(hFile, szXmlHeader, sizeof(szXmlHeader) - 1, &dwBytesWriten, NULL)) {
- MessageBox(NULL, "Failed to write xml header to file " szConfigFile, MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to write xml header to file ") szConfigFile, MSG_BOX_TITEL, MB_OK);
} else {
CLFileShareNode * pclCur = pclFirstNode;
while (pclCur) {
- DWORD dwBytesToWrite = _snprintf(szBuf, sizeof(szBuf), szXmlData ,
+ DWORD dwBytesToWrite = mir_snprintf(szBuf, sizeof(szBuf), szXmlData ,
pclCur->st.pszSrvPath,
pclCur->pszOrigRealPath,
pclCur->st.nMaxDownloads,
@@ -452,14 +406,14 @@ bool bWriteConfigurationFile() { SplitIpAddress(pclCur->st.dwAllowedMask));
if (! WriteFile(hFile, szBuf, dwBytesToWrite, &dwBytesWriten, NULL)) {
- MessageBox(NULL, "Failed to write xml data to file " szConfigFile, MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to write xml data to file ") szConfigFile, MSG_BOX_TITEL, MB_OK);
break;
}
pclCur = pclCur->pclNext;
}
if (! WriteFile(hFile, szXmlTail, sizeof(szXmlTail) - 1, &dwBytesWriten, NULL)) {
- MessageBox(NULL, "Failed to write xml tail to file " szConfigFile, MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to write xml tail to file ") szConfigFile, MSG_BOX_TITEL, MB_OK);
}
}
SetEndOfFile(hFile);
@@ -482,7 +436,7 @@ bool bWriteConfigurationFile() { // Developer : KN, Houdini, changed By Sergio Vieira Rolanski
/////////////////////////////////////////////////////////////////////
-static long nAddChangeRemoveShare(WPARAM wParam, LPARAM lParam) {
+static INT_PTR nAddChangeRemoveShare(WPARAM wParam, LPARAM lParam) {
if (!lParam)
return 1001;
@@ -570,7 +524,7 @@ static long nAddChangeRemoveShare(WPARAM wParam, LPARAM lParam) { // Developer : KN
/////////////////////////////////////////////////////////////////////
-static long nGetShare(WPARAM /*wParam*/, LPARAM lParam) {
+static INT_PTR nGetShare(WPARAM /*wParam*/, LPARAM lParam) {
if (!lParam)
return 1001;
@@ -609,7 +563,7 @@ static long nGetShare(WPARAM /*wParam*/, LPARAM lParam) { // Developer : KN
/////////////////////////////////////////////////////////////////////
-static long nHttpGetAllShares(WPARAM /*wParam*/, LPARAM /*lParam*/) {/*
+static INT_PTR nHttpGetAllShares(WPARAM /*wParam*/, LPARAM /*lParam*/) {/*
STFileShareInfo ** pTarget = (STFileShareInfo**)lParam;
CLFileShareNode * pclCur;
@@ -700,7 +654,7 @@ static int nProtoAck(WPARAM /*wParam*/, LPARAM lParam) { bIsOnline = ((int)ack->lParam != ID_STATUS_AWAY && (int)ack->lParam != ID_STATUS_NA);
/*
char szTmp[200];
- _snprintf( szTmp, sizeof( szTmp ), "%s New status %d\n" ,ack->szModule, (int)bIsOnline);
+ mir_snprintf( szTmp, sizeof( szTmp ), "%s New status %d\n" ,ack->szModule, (int)bIsOnline);
OutputDebugString( szTmp );*/
return 0;
}
@@ -720,7 +674,7 @@ static int nProtoAck(WPARAM /*wParam*/, LPARAM lParam) { // Developer : KN
/////////////////////////////////////////////////////////////////////
-long nToggelAcceptConnections(WPARAM wparam, LPARAM /*lparam*/) {
+INT_PTR nToggelAcceptConnections(WPARAM wparam, LPARAM /*lparam*/) {
CLISTMENUITEM mi = { 0 };
mi.cbSize = sizeof(mi);
mi.flags = CMIM_NAME | CMIM_ICON;
@@ -729,10 +683,7 @@ long nToggelAcceptConnections(WPARAM wparam, LPARAM /*lparam*/) { NETLIBUSERSETTINGS nus = { 0 };
nus.cbSize = sizeof(nus);
if (! CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM) hNetlibUser, (LPARAM) &nus)) {
- nus.cbSize = sizeof(NETLIBUSERSETTINGS_V032);
- if (! CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM) hNetlibUser, (LPARAM) &nus)) {
- Netlib_Logf(hNetlibUser, "Failed to get NETLIBUSERSETTINGS using MS_NETLIB_GETUSERSETTINGS");
- }
+ Netlib_Logf(hNetlibUser, "Failed to get NETLIBUSERSETTINGS using MS_NETLIB_GETUSERSETTINGS");
}
NETLIBBIND nlb = { 0 };
@@ -741,13 +692,13 @@ long nToggelAcceptConnections(WPARAM wparam, LPARAM /*lparam*/) { if (nus.specifyIncomingPorts && nus.szIncomingPorts && nus.szIncomingPorts[0])
nlb.wPort = 0;
else {
- //MessageBox( NULL, "Debug message using default port!", MSG_BOX_TITEL, MB_OK );
+ //MessageBox( NULL, _T("Debug message using default port!"), MSG_BOX_TITEL, MB_OK );
nlb.wPort = 80;
}
hDirectBoundPort = (HANDLE) CallService(MS_NETLIB_BINDPORT, (WPARAM) hNetlibUser, (LPARAM) & nlb);
if (!hDirectBoundPort) {
char szTemp[200];
- _snprintf(szTemp, sizeof(szTemp), "Failed to bind to port %s\r\nThis is most likely because another program or service is using this port" ,
+ mir_snprintf(szTemp, sizeof(szTemp), "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);
MessageBox(NULL, szTemp, MSG_BOX_TITEL, MB_OK);
return 1001;
@@ -756,13 +707,13 @@ long nToggelAcceptConnections(WPARAM wparam, LPARAM /*lparam*/) { dwLocalIpAddress = nlb.dwInternalIP;
mi.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DISABLE_SERVER));
- mi.pszName = Translate("Disable HTTP server");
+ mi.ptszName = LPGENT("Disable HTTP server");
Netlib_Logf(hNetlibUser, mi.pszName);
} else if (hDirectBoundPort && wparam == 0) {
Netlib_CloseHandle(hDirectBoundPort);
hDirectBoundPort = 0;
mi.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SHARE_NEW_FILE));
- mi.pszName = Translate("Enable HTTP server");
+ mi.ptszName = LPGENT("Enable HTTP server");
Netlib_Logf(hNetlibUser, mi.pszName);
} else {
return 0; // no changes;
@@ -852,12 +803,12 @@ int MainInit(WPARAM /*wparam*/, LPARAM /*lparam*/) { NETLIBUSER nlu = { 0 };
nlu.cbSize = sizeof(nlu);
- nlu.flags = NUF_OUTGOING | NUF_INCOMING /*| NUF_HTTPCONNS*/;
+ nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_TCHAR /*| NUF_HTTPCONNS*/;
nlu.szSettingsModule = MODULE;
- nlu.szDescriptiveName = "HTTP Server";
+ nlu.ptszDescriptiveName = LPGENT("HTTP Server");
hNetlibUser = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM) & nlu);
if (!hNetlibUser) {
- MessageBox(NULL, "Failed to register NetLib user", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to register NetLib user"), MSG_BOX_TITEL, MB_OK);
return 0;
}
@@ -983,48 +934,45 @@ extern "C" { int __declspec(dllexport)Load(PLUGINLINK *link) {
pluginLink = link;
- /*
- MM_INTERFACE stMirandaMMI;
- CallService( MS_SYSTEM_GET_MMI, NULL, (LPARAM) &stMirandaMMI );
- MirandaMalloc = stMirandaMMI.malloc;
- MirandaFree = stMirandaMMI.free;
- */
+ mir_getMMI(&mmi);
+ mir_getLP(&pluginInfo);
+
InitializeCriticalSection(&csFileShareListAccess);
hHttpAcceptConnectionsService = CreateServiceFunction(MS_HTTP_ACCEPT_CONNECTIONS, nToggelAcceptConnections);
if (! hHttpAcceptConnectionsService) {
- MessageBox(NULL, "Failed to CreateServiceFunction MS_HTTP_ACCEPT_CONNECTIONS", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to CreateServiceFunction MS_HTTP_ACCEPT_CONNECTIONS"), MSG_BOX_TITEL, MB_OK);
return 0;
}
hHttpAddChangeRemoveService = CreateServiceFunction(MS_HTTP_ADD_CHANGE_REMOVE, nAddChangeRemoveShare);
if (! hHttpAddChangeRemoveService) {
- MessageBox(NULL, "Failed to CreateServiceFunction MS_HTTP_ADD_CHANGE_REMOVE", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to CreateServiceFunction MS_HTTP_ADD_CHANGE_REMOVE"), MSG_BOX_TITEL, MB_OK);
return 0;
}
hHttpGetShareService = CreateServiceFunction(MS_HTTP_GET_SHARE, nGetShare);
if (! hHttpGetShareService) {
- MessageBox(NULL, "Failed to CreateServiceFunction MS_HTTP_GET_SHARE", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to CreateServiceFunction MS_HTTP_GET_SHARE"), MSG_BOX_TITEL, MB_OK);
return 0;
}
hHttpGetAllShares = CreateServiceFunction(MS_HTTP_GET_ALL_SHARES, nHttpGetAllShares);
if (! hHttpGetAllShares) {
- MessageBox(NULL, "Failed to CreateServiceFunction MS_HTTP_GET_ALL_SHARES", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to CreateServiceFunction MS_HTTP_GET_ALL_SHARES"), MSG_BOX_TITEL, MB_OK);
return 0;
}
hEventSystemInit = HookEvent(ME_SYSTEM_MODULESLOADED, MainInit);
if (!hEventSystemInit) {
- MessageBox(NULL, "Failed to HookEvent ME_SYSTEM_MODULESLOADED", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to HookEvent ME_SYSTEM_MODULESLOADED"), MSG_BOX_TITEL, MB_OK);
return 0;
}
hPreShutdown = HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown);
if (!hPreShutdown) {
- MessageBox(NULL, "Failed to HookEvent ME_SYSTEM_PRESHUTDOWN", MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to HookEvent ME_SYSTEM_PRESHUTDOWN"), MSG_BOX_TITEL, MB_OK);
return 0;
}
@@ -1041,7 +989,7 @@ extern "C" { sLogFilePath += "HTTPServer.log";
if (! bInitMimeHandling()) {
- MessageBox(NULL, "Failed to read configuration file : " szMimeTypeConfigFile, MSG_BOX_TITEL, MB_OK);
+ MessageBox(NULL, _T("Failed to read configuration file : ") szMimeTypeConfigFile, MSG_BOX_TITEL, MB_OK);
}
// Plugin sweeper support
@@ -1058,11 +1006,11 @@ extern "C" { CLISTMENUITEM mi;
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
- mi.flags = 0;
+ mi.flags = CMIF_TCHAR;
mi.pszContactOwner = NULL; //all contacts
mi.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SHARE_NEW_FILE));
mi.position = 1000085000;
- mi.pszName = Translate("Enable HTTP server");
+ mi.ptszName = LPGENT("Enable HTTP server");
mi.pszService = MS_HTTP_ACCEPT_CONNECTIONS;
hAcceptConnectionsMenuItem = (HANDLE)CallService(MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM) & mi);
}
|