285 lines
7.0 KiB
C++
285 lines
7.0 KiB
C++
#pragma once
|
||
|
||
#include "..\MobsetApiEx\MobsetApiServiceEx.h"
|
||
#include "..\WxWork\WXBizMsgCrypt.h"
|
||
|
||
#define POCO_NO_UNWINDOWS
|
||
#include <winsvc.h>
|
||
#include "Poco/Net/HTTPServer.h"
|
||
#include "Poco/Net/HTTPRequestHandler.h"
|
||
#include "Poco/Net/HTTPRequestHandlerFactory.h"
|
||
#include "Poco/Net/HTTPServerParams.h"
|
||
#include "Poco/Net/HTTPServerRequest.h"
|
||
#include "Poco/Net/HTTPServerResponse.h"
|
||
#include "Poco/Net/HTTPServerParams.h"
|
||
#include "Poco/Net/HTMLForm.h"
|
||
#include "Poco/Net/PartHandler.h"
|
||
#include "Poco/Net/MessageHeader.h"
|
||
#include "Poco/Net/ServerSocket.h"
|
||
#include "Poco/CountingStream.h"
|
||
#include "Poco/NullStream.h"
|
||
#include "Poco/StreamCopier.h"
|
||
#include "Poco/Exception.h"
|
||
#include "Poco/Util/ServerApplication.h"
|
||
#include "Poco/Util/Option.h"
|
||
#include "Poco/Util/OptionSet.h"
|
||
#include "Poco/Util/HelpFormatter.h"
|
||
#include "Poco/Net/SecureStreamSocket.h"
|
||
#include "Poco/Net/SecureServerSocket.h"
|
||
#include "Poco/Net/X509Certificate.h"
|
||
#include "Poco/Net/SSLManager.h"
|
||
#include "Poco\Net\InvalidCertificateHandler.h"
|
||
#include "Poco\Net\AcceptCertificateHandler.h"
|
||
#include "Poco\Net\KeyConsoleHandler.h"
|
||
#include "Poco\Net\ConsoleCertificateHandler.h"
|
||
#include "Poco\SharedPtr.h"
|
||
#include "Poco/URI.h"
|
||
#include "Poco/String.h"
|
||
#include "Poco/StringTokenizer.h"
|
||
#include "Poco/Net/MediaType.h"
|
||
#include "Poco/JSON/Parser.h"
|
||
#include "Poco/AutoPtr.h"
|
||
#include "Poco/Logger.h"
|
||
#include "Poco/PatternFormatter.h"
|
||
#include "Poco/FormattingChannel.h"
|
||
#include "Poco/FileChannel.h"
|
||
#include "Poco/ConsoleChannel.h"
|
||
|
||
#include <iostream>
|
||
|
||
using namespace Poco;
|
||
|
||
using Poco::Net::ServerSocket;
|
||
using Poco::Net::SocketAddress;
|
||
using Poco::Net::HTTPRequestHandler;
|
||
using Poco::Net::HTTPRequestHandlerFactory;
|
||
using Poco::Net::HTTPServer;
|
||
using Poco::Net::HTTPServerRequest;
|
||
using Poco::Net::HTTPServerResponse;
|
||
using Poco::Net::HTTPServerParams;
|
||
using Poco::Net::MessageHeader;
|
||
using Poco::Net::HTMLForm;
|
||
using Poco::Net::NameValueCollection;
|
||
using Poco::Util::ServerApplication;
|
||
using Poco::Util::Application;
|
||
using Poco::Util::Option;
|
||
using Poco::Util::OptionSet;
|
||
using Poco::Util::HelpFormatter;
|
||
using Poco::CountingInputStream;
|
||
using Poco::NullOutputStream;
|
||
using Poco::StreamCopier;
|
||
using Poco::Net::SSLManager;
|
||
using Poco::Net::SecureServerSocket;
|
||
using Poco::Net::SecureStreamSocket;
|
||
using Poco::Net::Context;
|
||
using Poco::URI;
|
||
using Poco::Net::MediaType;
|
||
using Poco::StringTokenizer;
|
||
using Poco::JSON::Object;
|
||
using Poco::AutoPtr;
|
||
using Poco::FileChannel;
|
||
using Poco::PatternFormatter;
|
||
using Poco::FormattingChannel;
|
||
using Poco::ConsoleChannel;
|
||
using Poco::Logger;
|
||
using Tencent::WXBizMsgCrypt;
|
||
using Tencent::WXBizMsgCryptErrorCode;
|
||
|
||
namespace MobsetHttp {
|
||
|
||
class MobsetHttpEx;
|
||
class HTTPFormServer : public Poco::Util::ServerApplication
|
||
{
|
||
public:
|
||
MobsetHttpEx * m_pMobsetHttpEx;
|
||
ServerSocket * m_psvs;
|
||
HTTPServer * m_psrv;
|
||
long m_lErrCode;
|
||
|
||
public:
|
||
void SetMainHttpEx(MobsetHttpEx * pHttpEx);
|
||
long Web_WaitForRequest(void);
|
||
HTTPFormServer();
|
||
~HTTPFormServer();
|
||
protected:
|
||
void initialize(Application& self);
|
||
void uninitialize();
|
||
void defineOptions(OptionSet& options);
|
||
void handleOption(const std::string& name, const std::string& value);
|
||
void displayHelp();
|
||
int main(const std::vector<std::string>& args);
|
||
private:
|
||
bool _helpRequested;
|
||
};
|
||
|
||
|
||
class HTTPFormServerSSL : public Poco::Util::ServerApplication
|
||
{
|
||
public:
|
||
MobsetHttpEx * m_pMobsetHttpEx;
|
||
ServerSocket * m_psvs;
|
||
HTTPServer * m_psrv;
|
||
long m_lErrCode;
|
||
|
||
public:
|
||
void SetMainHttpEx(MobsetHttpEx * pHttpEx);
|
||
long Web_WaitForRequest(void);
|
||
HTTPFormServerSSL();
|
||
~HTTPFormServerSSL();
|
||
protected:
|
||
void initialize(Application& self);
|
||
void uninitialize();
|
||
void defineOptions(OptionSet& options);
|
||
void handleOption(const std::string& name, const std::string& value);
|
||
void displayHelp();
|
||
int main(const std::vector<std::string>& args);
|
||
private:
|
||
bool _helpRequested;
|
||
};
|
||
|
||
|
||
typedef struct _SQL_Pool
|
||
{
|
||
BOOL bUse;
|
||
long lRandID;
|
||
CAdoConnection adoConnection;
|
||
//CComPtr<IXMLDOMDocument2> spDoc;
|
||
DWORD dwBeginUse;
|
||
DWORD dwEndUse;
|
||
}SQL_Pool;
|
||
|
||
typedef struct _HttpParams
|
||
{
|
||
std::string name; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
long in; //<2F><><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD>0-uri<72><69>1-postdata;
|
||
long begin;
|
||
long end;
|
||
BOOL urlDecode;
|
||
}HttpParams;
|
||
|
||
class SQL_PoolEx
|
||
{
|
||
public:
|
||
SQL_Pool * m_pSQL_Pool;
|
||
|
||
CAdoConnection * GetAdoConnection(void)
|
||
{
|
||
if (m_pSQL_Pool)
|
||
{
|
||
return &m_pSQL_Pool->adoConnection;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
SQL_PoolEx(SQL_Pool * pPool)
|
||
{
|
||
m_pSQL_Pool = NULL;
|
||
try
|
||
{
|
||
if ( pPool )
|
||
{
|
||
m_pSQL_Pool = pPool;
|
||
|
||
m_pSQL_Pool->bUse = true;
|
||
m_pSQL_Pool->dwBeginUse = GetTickCount();
|
||
}
|
||
}
|
||
catch(...)
|
||
{
|
||
m_pSQL_Pool = NULL;
|
||
}
|
||
}
|
||
|
||
~SQL_PoolEx(void)
|
||
{
|
||
try
|
||
{
|
||
if ( m_pSQL_Pool )
|
||
{
|
||
m_pSQL_Pool->bUse = false;
|
||
m_pSQL_Pool->lRandID = 0;
|
||
m_pSQL_Pool->dwEndUse = GetTickCount();
|
||
m_pSQL_Pool = NULL;
|
||
}
|
||
}
|
||
catch(...)
|
||
{
|
||
m_pSQL_Pool = NULL;
|
||
}
|
||
}
|
||
};
|
||
|
||
|
||
class MobsetHttpEx
|
||
{
|
||
|
||
public:
|
||
HANDLE m_hThread;
|
||
HANDLE m_hThreadSSL;
|
||
BOOL m_bStart;
|
||
BOOL m_bCopy; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ƶ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||
|
||
LPVOID m_pParam;
|
||
TCHAR m_strSQL_Provider[32];
|
||
TCHAR m_strSQL_IP[32];
|
||
TCHAR m_strSQL_User[32];
|
||
TCHAR m_strSQL_Passwd[32];
|
||
TCHAR m_strSQL_DB[32];
|
||
|
||
SQL_Pool * m_pSQL;
|
||
long m_lSQLCount;
|
||
CRITICAL_SECTION * m_Critical;
|
||
HTTPFormServer * m_HttpApp;
|
||
HTTPFormServerSSL * m_HttpAppSSL;
|
||
MobsetApi::MobsetApiServiceEx * m_pMobsetAPI;
|
||
CString m_strIP;
|
||
unsigned short m_lPort;
|
||
BOOL m_bSSL;
|
||
CStringA m_privateKeyFile;
|
||
CStringA m_certificateFile;
|
||
CStringA m_caLocation;
|
||
BOOL m_bHttpLog;
|
||
DWORD m_dwReqCount;
|
||
|
||
public:
|
||
MobsetHttpEx(void);
|
||
~MobsetHttpEx(void);
|
||
|
||
MobsetHttpEx(const struct soap&);
|
||
long Web_Exit();
|
||
void SetSQLParam(LPVOID pParam,CString strIP,CString strUser,CString strPasswd,CString strDB,CString strProvider);
|
||
BOOL ConnectSQLServer(SQL_Pool * pSql);
|
||
SQL_Pool * GetBankSQL();
|
||
long GetBankSQLCount(CString & strMsg);
|
||
static DWORD WINAPI Process_Req(LPVOID lpParam);
|
||
static UINT Process_AcceptT(LPVOID sParam);
|
||
static UINT Process_AcceptT_SSL(LPVOID sParam);
|
||
long Web_Init(TCHAR * strIP,long lPort ,BOOL bSSL, TCHAR * privateKeyFile, TCHAR * certificateFile, TCHAR * caLocation, long lSQLConnect, long lMaxIDReq, long lMaxIPReq);
|
||
static void GetCurrentPath(TCHAR *pPath);
|
||
void Http_Log(CString strLog);
|
||
void Http_LogA(CStringA strLog);
|
||
};
|
||
|
||
class MyHttpParamsParser
|
||
{
|
||
private:
|
||
std::string * m_pUrl;
|
||
std::string * m_pPostData;
|
||
std::vector<HttpParams> m_HttpParams;
|
||
public:
|
||
MyHttpParamsParser::MyHttpParamsParser();
|
||
long MyHttpParamsParser::Parser1(std::string * pData, long lType);
|
||
long MyHttpParamsParser::Parser(std::string * pUrl, std::string * pPostData);
|
||
std::string MyHttpParamsParser::get(std::string paramName, std::string default);
|
||
long MyHttpParamsParser::getLength(std::string paramName);
|
||
CStringW MyHttpParamsParser::getAsStringW(std::string paramName, std::string default, long lCharsetType = 0);
|
||
long MyHttpParamsParser::getAsBase64Decode(std::string paramName, void * pData, long lMaxLen);
|
||
std::string URLDecode(std::string& sIn);
|
||
BYTE fromHex(const BYTE &x);
|
||
};
|
||
|
||
|
||
|
||
|
||
}
|