diff --git a/README.en.md b/README.en.md index 0907c36..333579a 100644 --- a/README.en.md +++ b/README.en.md @@ -24,6 +24,7 @@ this software support following features 6. load balance 7. custom cert proxy protocol(planning) 8. multilevel proxy(planning) +9. HTTP api management ## install diff --git a/README.md b/README.md index f016dea..2651092 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward control service 6. 负载均衡 7. 自定义证书代理协议(planning) 8. 多级代理(planning) +9. HTTP 接口管理 ## 安装教程 diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index f6af639..0f6965a 100644 Binary files a/XEngine_Docment/Docment_en.docx and b/XEngine_Docment/Docment_en.docx differ diff --git a/XEngine_Docment/Docment_zh.docx b/XEngine_Docment/Docment_zh.docx index 6bf8df7..76f3ef4 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Config/HttpCode.types b/XEngine_Release/XEngine_Config/HttpCode.types new file mode 100644 index 0000000..26afa6f --- /dev/null +++ b/XEngine_Release/XEngine_Config/HttpCode.types @@ -0,0 +1,108 @@ +//CodeMessage +100:HTTP/1.1 100 Continue +101:HTTP/1.1 101 Switching Protocols +102:HTTP/1.1 102 Processing +103:HTTP/1.1 103 Early Hints +110:HTTP/1.1 110 (obsoleted) Response is Stale +111:HTTP/1.1 111 (obsoleted) Revalidation Failed +112:HTTP/1.1 112 (obsoleted) Disconnected Operation +113:HTTP/1.1 113 (obsoleted) Heuristic Expiration +199:HTTP/1.1 199 (obsoleted) Miscellaneous Warning +//CodeSuccess +200:HTTP/1.1 200 OK +201:HTTP/1.1 201 Created +202:HTTP/1.1 202 Accepted +203:HTTP/1.1 203 Non-Authoritative Information +204:HTTP/1.1 204 No Content +205:HTTP/1.1 205 Reset Content +206:HTTP/1.1 206 Partial Content +207:HTTP/1.1 207 Multi-Status +208:HTTP/1.1 208 Already Reported +214:HTTP/1.1 214 (obsoleted) Transformation Applied +226:HTTP/1.1 226 IM Used +299:HTTP/1.1 299 (obsoleted) Miscellaneous Persistent Warning +//CodeRedirect +300:HTTP/1.1 300 Multiple Choices +301:HTTP/1.1 301 Moved Permanently +302:HTTP/1.1 302 Moved temporarily +303:HTTP/1.1 303 See Other +304:HTTP/1.1 304 Not Modified +305:HTTP/1.1 305 Use Proxy +306:HTTP/1.1 306 Switch Proxy +307:HTTP/1.1 307 Temporary Redirect +308:HTTP/1.1 308 Permanent Redirect +//CodeRequestFail +400:HTTP/1.1 400 Bad Request +401:HTTP/1.1 401 Unauthorized +402:HTTP/1.1 402 Payment Required +403:HTTP/1.1 403 Forbidden +404:HTTP/1.1 404 Not Found +405:HTTP/1.1 405 Method Not Allowed +406:HTTP/1.1 406 Not Acceptable +407:HTTP/1.1 407 Proxy Authentication Required +408:HTTP/1.1 408 Request Timeout +409:HTTP/1.1 409 Conflict +410:HTTP/1.1 410 Gone +411:HTTP/1.1 411 Length Required +412:HTTP/1.1 412 Precondition Failed +413:HTTP/1.1 413 Request Entity Too Large +414:HTTP/1.1 414 Request-URI Too Long +415:HTTP/1.1 415 Unsupported Media Type +416:HTTP/1.1 416 Requested Range Not Satisfiable +417:HTTP/1.1 417 Expectation Failed +418:HTTP/1.1 418 I'm a teapot +419:HTTP/1.1 419 (Unofficial) Page Expired +420:HTTP/1.1 420 (Unofficial) Method Failure +421:HTTP/1.1 421 too many connections +422:HTTP/1.1 422 Unprocessable Entity +423:HTTP/1.1 423 Locked +424:HTTP/1.1 424 Failed Dependency +425:HTTP/1.1 425 Unordered Collection +426:HTTP/1.1 426 Upgrade Required +428:HTTP/1.1 428 Precondition Required +429:HTTP/1.1 429 Too Many Requests +430:HTTP/1.1 430 (Unofficial) Request Header Fields Too Large +431:HTTP/1.1 431 Request Header Fields Too Large +440:HTTP/1.1 440 (IIS) Login Time-out +444:HTTP/1.1 444 (nginx) No Response +449:HTTP/1.1 449 (IIS) Retry With +450:HTTP/1.1 450 (Unofficial) Blocked by Windows Parental Controls +451:HTTP/1.1 451 (IIS) Redirect +460:HTTP/1.1 460 (AWS) +463:HTTP/1.1 463 (AWS) +494:HTTP/1.1 494 (nginx) Request header too large +495:HTTP/1.1 495 (nginx) SSL Certificate Error +496:HTTP/1.1 496 (nginx) SSL Certificate Required +497:HTTP/1.1 497 (nginx) HTTP Request Sent to HTTPS Port +498:HTTP/1.1 498 (Unofficial) Invalid Token +499:HTTP/1.1 499 (nginx) Token Required +//CodeServerFail +500:HTTP/1.1 500 Internal Server Error +501:HTTP/1.1 501 Not Implemented +502:HTTP/1.1 502 Bad Gateway +503:HTTP/1.1 503 Service Unavailable +504:HTTP/1.1 504 Gateway Timeout +505:HTTP/1.1 505 HTTP Version Not Supported +506:HTTP/1.1 506 Variant Also Negotiates +507:HTTP/1.1 507 Insufficient Storage +508:HTTP/1.1 508 Loop Detected +509:HTTP/1.1 509 (Unofficial) Bandwidth Limit Exceeded +510:HTTP/1.1 510 Not Extended +511:HTTP/1.1 511 Network Authentication Required +520:HTTP/1.1 520 (Cloudflare) Web Server Returned an Unknown Error +521:HTTP/1.1 521 (Cloudflare) Web Server Is Down +522:HTTP/1.1 522 (Cloudflare) Connection Timed Out +523:HTTP/1.1 523 (Cloudflare) Origin Is Unreachable +524:HTTP/1.1 524 (Cloudflare) A Timeout Occurred +525:HTTP/1.1 525 (Cloudflare) SSL Handshake Failed +526:HTTP/1.1 526 (Cloudflare) Invalid SSL Certificate +527:HTTP/1.1 527 (Cloudflare) Railgun Error +529:HTTP/1.1 529 (Unofficial) Site is overloaded +530:HTTP/1.1 530 (Cloudflare) Site is frozen +561:HTTP/1.1 561 (AWS) Unauthorized +598:HTTP/1.1 598 (Unofficial) Network read timeout error +599:HTTP/1.1 599 (Unofficial) Network Connect Timeout Error +600:HTTP/1.1 600 Unparseable Response Headers +//XEngine Code +1001:HTTP/1.1 1001 XEngine Auth Ok +1002:HTTP/1.1 1002 XEngine Auth Failed \ No newline at end of file diff --git a/XEngine_Release/XEngine_Config/HttpMime.types b/XEngine_Release/XEngine_Config/HttpMime.types new file mode 100644 index 0000000..d563ff3 --- /dev/null +++ b/XEngine_Release/XEngine_Config/HttpMime.types @@ -0,0 +1,96 @@ +text/html html htm shtml +text/css css +text/xml xml +text/mathml mml +text/plain txt +text/vnd.sun.j2me.app-descriptor jad +text/vnd.wap.wml wml +text/x-component htc + +image/gif gif +image/jpeg jpeg jpg +image/avif avif +image/png png +image/tiff tif tiff +image/webp webp +image/vnd.wap.wbmp wbmp +image/svg+xml svg svgz +image/x-icon ico +image/x-jng jng +image/x-ms-bmp bmp + +font/woff woff +font/woff2 woff2 + +application/pdf pdf + +application/vnd.google-earth.kml+xml kml +application/vnd.google-earth.kmz kmz + +application/msword doc +application/vnd.ms-excel xls +application/vnd.ms-powerpoint ppt +application/vnd.ms-fontobject eot +application/vnd.oasis.opendocument.graphics odg +application/vnd.oasis.opendocument.presentation odp +application/vnd.oasis.opendocument.spreadsheet ods +application/vnd.oasis.opendocument.text odt +application/vnd.openxmlformats-officedocument.wordprocessingml.document docx +application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx +application/vnd.openxmlformats-officedocument.presentationml.presentation pptx + +application/javascript js +application/atom+xml atom +application/rss+xml rss +application/java-archive jar war ear +application/json json +application/mac-binhex40 hqx +application/postscript ps eps ai +application/rtf rtf +application/vnd.apple.mpegurl m3u8 +application/vnd.wap.wmlc wmlc +application/wasm wasm + +application/x-7z-compressed 7z +application/x-cocoa cco +application/x-java-archive-diff jardiff +application/x-java-jnlp-file jnlp +application/x-makeself run +application/x-perl pl pm +application/x-pilot prc pdb +application/x-rar-compressed rar +application/x-redhat-package-manager rpm +application/x-sea sea +application/x-shockwave-flash swf +application/x-stuffit sit +application/x-tcl tcl tk +application/x-x509-ca-cert der pem crt +application/x-xpinstall xpi +application/xhtml+xml xhtml +application/xspf+xml xspf +application/zip zip + +application/octet-stream bin exe dll +application/octet-stream deb +application/octet-stream dmg +application/octet-stream iso img +application/octet-stream msi msp msm + +audio/midi mid midi kar +audio/mpeg mp3 +audio/ogg ogg +audio/x-m4a m4a +audio/x-realaudio ra + +video/3gpp 3gpp 3gp +video/mp2t ts +video/mp4 mp4 +video/mpeg mpeg mpg +video/quicktime mov +video/webm webm +video/x-flv flv +video/x-m4v m4v +video/x-mng mng +video/x-ms-asf asx asf +video/x-ms-wmv wmv +video/x-msvideo avi \ No newline at end of file diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index adac7ab..1fa6fb8 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -1,44 +1,42 @@ { - "tszIPAddr": "192.168.1.12", - "bDeamon": false, - "nSocksPort": 5400, - "nTunnelPort": 5401, - "nForwardPort": 5402, - "nProxyPort": 5403, - "XMax": { - "nMaxClient": 10000, - "nMaxQueue": 10000, - "nIOThread": 4, - "nForwardThread": 4 - }, - "XTime": { - "nTimeCheck": 3, - "nSocksTimeout": 5, - "nTunnelTimeout": 5, - "nForwardTimeout": 5, - "nProxyTimeout": 5 - }, - "XLog": { - "MaxSize": 1024000, - "MaxCount": 10, - "LogLeave": 32, - "LogType": 17, - "tszLogFile": "./XEngine_Log/XEngine_ProxyServiceApp.log" - }, - "XReport":{ - "bEnable":true, - "tszAPIUrl":"http://app.xyry.org:5501/api?function=machine", - "tszServiceName":"XEngine_ProxyServer" - }, - "XProxy": { - "nRuleMode": 0, - "tszDestIPAddr": [ - "127.0.0.1:5501", - "118.25.14.242:5501" - ], - "tszRuleIPAddr": [ - "10.0.0.1-10.0.4.69:5403", - "10.0.0.2-10.0.4.69:5403" - ] - } + "tszIPAddr": "192.168.1.12", + "bDeamon": false, + "nHttpPort": 5400, + "nSocksPort": 5401, + "nTunnelPort": 5402, + "nForwardPort": 5403, + "nProxyPort": 5404, + "XMax": { + "nMaxClient": 10000, + "nMaxQueue": 10000, + "nIOThread": 4, + "nHTTPThread": 2, + "nForwardThread": 4 + }, + "XTime": { + "nTimeCheck": 3, + "nHttpTimeout": 5, + "nSocksTimeout": 5, + "nTunnelTimeout": 5, + "nForwardTimeout": 5, + "nProxyTimeout": 5 + }, + "XLog": { + "MaxSize": 1024000, + "MaxCount": 10, + "LogLeave": 32, + "LogType": 17, + "tszLogFile": "./XEngine_Log/XEngine_ProxyServiceApp.log" + }, + "XVerification": { + "tszUserName": "xyry", + "tszUserPass": "11", + "nVType": 1, + "bEnable": false + }, + "XReport": { + "bEnable": true, + "tszAPIUrl": "http://app.xyry.org:5501/api?function=machine", + "tszServiceName": "XEngine_ProxyServer" + } } \ No newline at end of file diff --git a/XEngine_Release/XEngine_Config/XEngine_ProxyConfig.json b/XEngine_Release/XEngine_Config/XEngine_ProxyConfig.json new file mode 100644 index 0000000..bd4583a --- /dev/null +++ b/XEngine_Release/XEngine_Config/XEngine_ProxyConfig.json @@ -0,0 +1,11 @@ +{ + "nRuleMode": 0, + "tszDestIPAddr": [ + "127.0.0.1:5501", + "118.25.14.242:5501" + ], + "tszRuleIPAddr": [ + "10.0.0.1-10.0.4.69:5403", + "10.0.0.2-10.0.4.69:5403" + ] +} \ No newline at end of file diff --git a/XEngine_Release/XEngine_Config/XEngine_Version.json b/XEngine_Release/XEngine_Config/XEngine_Version.json index e6bf3e6..f4232d8 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Version.json +++ b/XEngine_Release/XEngine_Config/XEngine_Version.json @@ -1,5 +1,6 @@ { "XVer": [ + "1.15.0.1001 Build20260209", "1.14.0.1001 Build20251020", "1.13.0.1001 Build20250519", "1.12.0.1001 Build20250325", diff --git a/XEngine_Source/Makefile b/XEngine_Source/Makefile index 051bac6..8437ab2 100644 --- a/XEngine_Source/Makefile +++ b/XEngine_Source/Makefile @@ -5,6 +5,7 @@ FLAGS= #要编译的模块 THIRDPART_MODULE_JSONCPP = ./XEngine_DependLibrary/XEngine_Module/jsoncpp THIRDPART_MODULE_REPORT = ./XEngine_DependLibrary/XEngine_Module/XEngine_InfoReport +THIRDPART_MODULE_VERIFICATION = ./XEngine_DependLibrary/XEngine_Module/XEngine_Verification MODULE_CONFIGURE_PATH = ./XEngine_ModuleConfigure MODULE_PROTOCOL_PATH = ./XEngine_ModuleProtocol @@ -18,7 +19,7 @@ else ifeq ($(PLATFORM),mac) FILEEXT = dylib endif -XENGINE_MODULES = libjsoncpp.so libXEngine_InfoReport.so \ +XENGINE_MODULES = libjsoncpp.so libXEngine_InfoReport.so libXEngine_Verification.so \ libXEngine_ModuleConfigure.so libXEngine_ModuleProtocol.so libXEngine_ModuleSession.so libXEngine_ModuleHelp.so \ XEngine_ServiceApp.exe @@ -37,6 +38,13 @@ ifeq ($(FLAGS), InstallAll) else make -C $(THIRDPART_MODULE_REPORT) PLATFORM=$(PLATFORM) UNICODE=$(UNICODE) RELEASE=$(RELEASE) $(FLAGS) endif +libXEngine_Verification.so: +ifeq ($(FLAGS), InstallAll) + cp $(THIRDPART_MODULE_VERIFICATION)/libXEngine_Verification.$(FILEEXT) ../XEngine_Release/ +else + make -C $(THIRDPART_MODULE_VERIFICATION) PLATFORM=$(PLATFORM) UNICODE=$(UNICODE) RELEASE=$(RELEASE) $(FLAGS) +endif + libXEngine_ModuleConfigure.so: make -C $(MODULE_CONFIGURE_PATH) PLATFORM=$(PLATFORM) UNICODE=$(UNICODE) RELEASE=$(RELEASE) $(FLAGS) libXEngine_ModuleProtocol.so: diff --git a/XEngine_Source/VSCopy_Arm64.bat b/XEngine_Source/VSCopy_Arm64.bat index 627ce5e..59ed8a0 100644 --- a/XEngine_Source/VSCopy_Arm64.bat +++ b/XEngine_Source/VSCopy_Arm64.bat @@ -15,6 +15,7 @@ copy /y "%XEngine_LibArm64%\XEngine_NetHelp\NetHelp_XSocket.dll" "./" copy /y "%XEngine_LibArm64%\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" copy /y "%XEngine_LibArm64%\XEngine_HelpComponents\HelpComponents_Packets.dll" "./" copy /y "%XEngine_LibArm64%\XEngine_RfcComponents\RfcComponents_ProxyProtocol.dll" "./" +copy /y "%XEngine_LibArm64%\XEngine_RfcComponents\RfcComponents_HttpProtocol.dll" "./" copy /y "%XEngine_LibArm64%\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" copy /y "%XEngine_LibArm64%\XEngine_SystemSdk\XEngine_SystemConfig.dll" "./" \ No newline at end of file diff --git a/XEngine_Source/VSCopy_Debug.bat b/XEngine_Source/VSCopy_Debug.bat index bd94056..7d57092 100644 --- a/XEngine_Source/VSCopy_Debug.bat +++ b/XEngine_Source/VSCopy_Debug.bat @@ -15,6 +15,7 @@ copy /y "D:\XEngine\XEngine_SourceCode\Debug\NetHelp_APIAddr.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_XLog.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_Packets.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\RfcComponents_ProxyProtocol.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\RfcComponents_HttpProtocol.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_SystemApi.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_SystemConfig.dll" "./" \ No newline at end of file diff --git a/XEngine_Source/VSCopy_x64.bat b/XEngine_Source/VSCopy_x64.bat index 1fd9501..fedafe9 100644 --- a/XEngine_Source/VSCopy_x64.bat +++ b/XEngine_Source/VSCopy_x64.bat @@ -15,6 +15,7 @@ copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_XSocket.dll" "./" copy /y "%XEngine_Lib64%\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" copy /y "%XEngine_Lib64%\XEngine_HelpComponents\HelpComponents_Packets.dll" "./" copy /y "%XEngine_Lib64%\XEngine_RfcComponents\RfcComponents_ProxyProtocol.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_RfcComponents\RfcComponents_HttpProtocol.dll" "./" copy /y "%XEngine_Lib64%\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" copy /y "%XEngine_Lib64%\XEngine_SystemSdk\XEngine_SystemConfig.dll" "./" \ No newline at end of file diff --git a/XEngine_Source/VSCopy_x86.bat b/XEngine_Source/VSCopy_x86.bat index 3e304e9..820003d 100644 --- a/XEngine_Source/VSCopy_x86.bat +++ b/XEngine_Source/VSCopy_x86.bat @@ -15,6 +15,7 @@ copy /y "%XEngine_Lib32%\XEngine_NetHelp\NetHelp_XSocket.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\HelpComponents_Packets.dll" "./" copy /y "%XEngine_Lib32%\XEngine_RfcComponents\RfcComponents_ProxyProtocol.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_RfcComponents\RfcComponents_HttpProtocol.dll" "./" copy /y "%XEngine_Lib32%\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" copy /y "%XEngine_Lib32%\XEngine_SystemSdk\XEngine_SystemConfig.dll" "./" \ No newline at end of file diff --git a/XEngine_Source/XEngine.sln b/XEngine_Source/XEngine.sln index 8b87e47..a9f27f1 100644 --- a/XEngine_Source/XEngine.sln +++ b/XEngine_Source/XEngine.sln @@ -8,6 +8,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_ServiceApp", "XEngi {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2} = {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2} {7A864141-B878-4A5E-B2A1-D5BB4CF58FCB} = {7A864141-B878-4A5E-B2A1-D5BB4CF58FCB} {9512A610-7197-4522-9AEF-1486619C99FE} = {9512A610-7197-4522-9AEF-1486619C99FE} + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256} = {A8E43EC0-698A-4807-8A61-B2BE5FAB7256} {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} = {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} {F54F152C-594F-4465-A44E-2DB915B39760} = {F54F152C-594F-4465-A44E-2DB915B39760} {F6520D2C-BB8E-45BB-964B-F5D6A4318A89} = {F6520D2C-BB8E-45BB-964B-F5D6A4318A89} @@ -41,6 +42,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_InfoReport", "XEngi {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} = {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_Verification", "XEngine_DependLibrary\XEngine_Module\XEngine_Verification\XEngine_Verification.vcxproj", "{A8E43EC0-698A-4807-8A61-B2BE5FAB7256}" + ProjectSection(ProjectDependencies) = postProject + {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} = {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -135,6 +141,18 @@ Global {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x64.Build.0 = Release|x64 {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x86.ActiveCfg = Release|Win32 {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x86.Build.0 = Release|Win32 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Debug|ARM64.Build.0 = Debug|ARM64 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Debug|x64.ActiveCfg = Debug|x64 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Debug|x64.Build.0 = Debug|x64 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Debug|x86.ActiveCfg = Debug|Win32 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Debug|x86.Build.0 = Debug|Win32 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Release|ARM64.ActiveCfg = Release|ARM64 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Release|ARM64.Build.0 = Release|ARM64 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Release|x64.ActiveCfg = Release|x64 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Release|x64.Build.0 = Release|x64 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Release|x86.ActiveCfg = Release|Win32 + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -142,6 +160,7 @@ Global GlobalSection(NestedProjects) = preSolution {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} = {91EFAD20-FF05-4CA9-9472-7CEE32340749} {F6520D2C-BB8E-45BB-964B-F5D6A4318A89} = {91EFAD20-FF05-4CA9-9472-7CEE32340749} + {A8E43EC0-698A-4807-8A61-B2BE5FAB7256} = {91EFAD20-FF05-4CA9-9472-7CEE32340749} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {9B202F91-A601-429E-BB0F-880DDEE096FE} diff --git a/XEngine_Source/XEngine_DependLibrary b/XEngine_Source/XEngine_DependLibrary index 24bde9d..adf48e2 160000 --- a/XEngine_Source/XEngine_DependLibrary +++ b/XEngine_Source/XEngine_DependLibrary @@ -1 +1 @@ -Subproject commit 24bde9d212cd48b822ad8aab90956033972ee46b +Subproject commit adf48e22d68f741ec52f299945f8f8f8fb3df9d2 diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h index 5abadc3..e8e2451 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h @@ -17,6 +17,7 @@ typedef struct tag_XEngine_ServiceConfig { XCHAR tszIPAddr[128]; //本机IP地址,根据需要配置 bool bDeamon; //是否以守护进程启动,LINUX有效 + int nHttpPort; //HTTP服务端口,<=0不启用 int nSocksPort; //Socks端口,<=0不启用 int nTunnelPort; //Tunnel服务端口 int nForwardPort; //数据转发端口 @@ -26,11 +27,13 @@ typedef struct tag_XEngine_ServiceConfig int nMaxClient; //最大客户端个数 int nMaxQueue; //最大队列个数 int nIOThread; //网络IO线程数 + int nHTTPThread; //HTTP处理线程数 int nForwardThread; //转发服务 }st_XMax; struct { int nTimeCheck; //检测次数 + int nHttpTimeout; //HTTP超时时间 int nSocksTimeout; //TCP超时时间 int nTunnelTimeout; //HTTP超时时间 int nForwardTimeout; //转发超时时间 @@ -45,22 +48,29 @@ typedef struct tag_XEngine_ServiceConfig int nLogType; //日志类型 }st_XLog; struct + { + XCHAR tszUserName[XPATH_MAX]; + XCHAR tszUserPass[XPATH_MAX]; + int nVType; + bool bEnable; + }st_XVerifcation; + struct { bool bEnable; XCHAR tszAPIUrl[XPATH_MAX]; XCHAR tszServiceName[128]; }st_XReport; - struct - { - int nRuleMode; //模式 - std::list* pStl_ListDestAddr; - std::list* pStl_ListRuleAddr; - }st_XProxy; struct { list* pStl_ListVer; }st_XVer; }XENGINE_SERVICECONFIG; +typedef struct +{ + int nRuleMode; //模式 + std::list* pStl_ListDestAddr; + std::list* pStl_ListRuleAddr; +}XENGINE_PROXYCONFIG; ////////////////////////////////////////////////////////////////////////// // 导出函数定义 ////////////////////////////////////////////////////////////////////////// @@ -105,4 +115,23 @@ extern "C" bool ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XENGINE_SERVIC 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleConfigure_Json_Version(LPCXSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig); \ No newline at end of file +extern "C" bool ModuleConfigure_Json_Version(LPCXSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig); +/******************************************************************** +函数名称:ModuleConfigure_Json_ProxyFile +函数功能:读取JSON配置文件 + 参数.一:lpszConfigFile + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要读取的配置文件 + 参数.二:pSt_ServerConfig + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出服务配置信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleConfigure_Json_ProxyFile(LPCXSTR lpszConfigFile, XENGINE_PROXYCONFIG* pSt_ServerConfig); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h index 714f03b..9ff051a 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h @@ -18,4 +18,5 @@ #define ERROR_MODULE_CONFIGURE_JSON_XLOG 0xA0006 //读取XLOG配置失败 #define ERROR_MODULE_CONFIGURE_JSON_XVER 0xA0008 //没有版本配置 #define ERROR_MODULE_CONFIGURE_JSON_XREPORT 0xA0009 //没有报告配置 -#define ERROR_MODULE_CONFIGURE_JSON_XPROXY 0xA0010 //没有代理配置 \ No newline at end of file +#define ERROR_MODULE_CONFIGURE_JSON_XPROXY 0xA0010 //没有代理配置 +#define ERROR_MODULE_CONFIGURE_JSON_XVERICATION 0xA0011 //没有验证配置 \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp index c820d5a..70bd524 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp @@ -74,12 +74,13 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE } _tcsxcpy(pSt_ServerConfig->tszIPAddr, st_JsonRoot["tszIPAddr"].asCString()); pSt_ServerConfig->bDeamon = st_JsonRoot["bDeamon"].asBool(); + pSt_ServerConfig->nHttpPort = st_JsonRoot["nHttpPort"].asInt(); pSt_ServerConfig->nSocksPort = st_JsonRoot["nSocksPort"].asInt(); pSt_ServerConfig->nTunnelPort = st_JsonRoot["nTunnelPort"].asInt(); pSt_ServerConfig->nForwardPort = st_JsonRoot["nForwardPort"].asInt(); pSt_ServerConfig->nProxyPort = st_JsonRoot["nProxyPort"].asInt(); - if (st_JsonRoot["XMax"].empty() || (4 != st_JsonRoot["XMax"].size())) + if (st_JsonRoot["XMax"].empty() || (5 != st_JsonRoot["XMax"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XMAX; @@ -89,9 +90,10 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE pSt_ServerConfig->st_XMax.nMaxClient = st_JsonXMax["nMaxClient"].asInt(); pSt_ServerConfig->st_XMax.nMaxQueue = st_JsonXMax["nMaxQueue"].asInt(); pSt_ServerConfig->st_XMax.nIOThread = st_JsonXMax["nIOThread"].asInt(); + pSt_ServerConfig->st_XMax.nHTTPThread = st_JsonXMax["nHTTPThread"].asInt(); pSt_ServerConfig->st_XMax.nForwardThread = st_JsonXMax["nForwardThread"].asInt(); - if (st_JsonRoot["XTime"].empty() || (5 != st_JsonRoot["XTime"].size())) + if (st_JsonRoot["XTime"].empty() || (6 != st_JsonRoot["XTime"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XTIME; @@ -99,6 +101,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE } Json::Value st_JsonXTime = st_JsonRoot["XTime"]; pSt_ServerConfig->st_XTime.nTimeCheck = st_JsonXTime["nTimeCheck"].asInt(); + pSt_ServerConfig->st_XTime.nHttpTimeout = st_JsonXTime["nHttpTimeout"].asInt(); pSt_ServerConfig->st_XTime.nSocksTimeout = st_JsonXTime["nSocksTimeout"].asInt(); pSt_ServerConfig->st_XTime.nTunnelTimeout = st_JsonXTime["nTunnelTimeout"].asInt(); pSt_ServerConfig->st_XTime.nForwardTimeout = st_JsonXTime["nForwardTimeout"].asInt(); @@ -117,6 +120,19 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE pSt_ServerConfig->st_XLog.nLogType = st_JsonXLog["LogType"].asInt(); _tcsxcpy(pSt_ServerConfig->st_XLog.tszLogFile, st_JsonXLog["tszLogFile"].asCString()); + if (st_JsonRoot["XVerification"].empty() || (4 != st_JsonRoot["XVerification"].size())) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XVERICATION; + return false; + } + Json::Value st_JsonXVerifcation = st_JsonRoot["XVerification"]; + + pSt_ServerConfig->st_XVerifcation.bEnable = st_JsonXVerifcation["bEnable"].asBool(); + pSt_ServerConfig->st_XVerifcation.nVType = st_JsonXVerifcation["nVType"].asInt(); + _tcsxcpy(pSt_ServerConfig->st_XVerifcation.tszUserName, st_JsonXVerifcation["tszUserName"].asCString()); + _tcsxcpy(pSt_ServerConfig->st_XVerifcation.tszUserPass, st_JsonXVerifcation["tszUserPass"].asCString()); + if (st_JsonRoot["XReport"].empty() || (3 != st_JsonRoot["XReport"].size())) { Config_IsErrorOccur = true; @@ -129,31 +145,6 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE _tcsxcpy(pSt_ServerConfig->st_XReport.tszAPIUrl, st_JsonXReport["tszAPIUrl"].asCString()); _tcsxcpy(pSt_ServerConfig->st_XReport.tszServiceName, st_JsonXReport["tszServiceName"].asCString()); - if (st_JsonRoot["XProxy"].empty()) - { - Config_IsErrorOccur = true; - Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XPROXY; - return false; - } - Json::Value st_JsonXProxy = st_JsonRoot["XProxy"]; - pSt_ServerConfig->st_XProxy.pStl_ListRuleAddr = new list; - pSt_ServerConfig->st_XProxy.pStl_ListDestAddr = new list; - - pSt_ServerConfig->st_XProxy.nRuleMode = st_JsonXProxy["nRuleMode"].asInt(); - if (!st_JsonXProxy["tszDestIPAddr"].isNull()) - { - for (unsigned int i = 0; i < st_JsonXProxy["tszDestIPAddr"].size(); i++) - { - pSt_ServerConfig->st_XProxy.pStl_ListDestAddr->push_back(st_JsonXProxy["tszDestIPAddr"][i].asCString()); - } - } - if (!st_JsonXProxy["tszRuleIPAddr"].isNull()) - { - for (unsigned int i = 0; i < st_JsonXProxy["tszRuleIPAddr"].size(); i++) - { - pSt_ServerConfig->st_XProxy.pStl_ListRuleAddr->push_back(st_JsonXProxy["tszRuleIPAddr"][i].asCString()); - } - } return true; } /******************************************************************** @@ -220,4 +211,74 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_Version(LPCXSTR lpszConfigFile, pSt_ServerConfig->st_XVer.pStl_ListVer->push_back(st_JsonXVer[i].asCString()); } return true; +} +/******************************************************************** +函数名称:ModuleConfigure_Json_ProxyFile +函数功能:读取JSON配置文件 + 参数.一:lpszConfigFile + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要读取的配置文件 + 参数.二:pSt_ServerConfig + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出服务配置信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleConfigure_Json::ModuleConfigure_Json_ProxyFile(LPCXSTR lpszConfigFile, XENGINE_PROXYCONFIG* pSt_ServerConfig) +{ + Config_IsErrorOccur = false; + + if ((NULL == lpszConfigFile) || (NULL == pSt_ServerConfig)) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARAMENT; + return false; + } + Json::Value st_JsonRoot; + JSONCPP_STRING st_JsonError; + Json::CharReaderBuilder st_JsonBuilder; + //读取配置文件所有内容到缓冲区 + FILE* pSt_File = _xtfopen(lpszConfigFile, _X("rb")); + if (NULL == pSt_File) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_OPENFILE; + return false; + } + XCHAR tszMsgBuffer[8192]; + int nRet = fread(tszMsgBuffer, 1, sizeof(tszMsgBuffer), pSt_File); + fclose(pSt_File); + //开始解析配置文件 + std::unique_ptr const pSt_JsonReader(st_JsonBuilder.newCharReader()); + if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nRet, &st_JsonRoot, &st_JsonError)) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARSE; + return false; + } + pSt_ServerConfig->pStl_ListRuleAddr = new list; + pSt_ServerConfig->pStl_ListDestAddr = new list; + + pSt_ServerConfig->nRuleMode = st_JsonRoot["nRuleMode"].asInt(); + if (!st_JsonRoot["tszDestIPAddr"].isNull()) + { + for (unsigned int i = 0; i < st_JsonRoot["tszDestIPAddr"].size(); i++) + { + pSt_ServerConfig->pStl_ListDestAddr->push_back(st_JsonRoot["tszDestIPAddr"][i].asCString()); + } + } + if (!st_JsonRoot["tszRuleIPAddr"].isNull()) + { + for (unsigned int i = 0; i < st_JsonRoot["tszRuleIPAddr"].size(); i++) + { + pSt_ServerConfig->pStl_ListRuleAddr->push_back(st_JsonRoot["tszRuleIPAddr"][i].asCString()); + } + } + return true; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h index f636423..9e22b32 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h @@ -19,6 +19,7 @@ class CModuleConfigure_Json public: bool ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig); bool ModuleConfigure_Json_Version(LPCXSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig); + bool ModuleConfigure_Json_ProxyFile(LPCXSTR lpszConfigFile, XENGINE_PROXYCONFIG* pSt_ServerConfig); protected: private: }; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def index b94a561..35adf08 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def +++ b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def @@ -4,4 +4,5 @@ EXPORTS ModuleConfigure_GetLastError ModuleConfigure_Json_File - ModuleConfigure_Json_Version \ No newline at end of file + ModuleConfigure_Json_Version + ModuleConfigure_Json_ProxyFile \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/pch.cpp b/XEngine_Source/XEngine_ModuleConfigure/pch.cpp index 45b3f4d..b40f93a 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/pch.cpp +++ b/XEngine_Source/XEngine_ModuleConfigure/pch.cpp @@ -36,4 +36,8 @@ extern "C" bool ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XENGINE_SERVIC extern "C" bool ModuleConfigure_Json_Version(LPCXSTR lpszConfigFile, XENGINE_SERVICECONFIG * pSt_ServerConfig) { return m_ConfigJson.ModuleConfigure_Json_Version(lpszConfigFile, pSt_ServerConfig); +} +extern "C" bool ModuleConfigure_Json_ProxyFile(LPCXSTR lpszConfigFile, XENGINE_PROXYCONFIG* pSt_ServerConfig) +{ + return m_ConfigJson.ModuleConfigure_Json_ProxyFile(lpszConfigFile, pSt_ServerConfig); } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h index 1050015..b233daf 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h @@ -18,6 +18,35 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError = NULL); /* 封包导出函数 */ /************************************************************************/ /******************************************************************** +函数名称:ModuleProtocol_Packet_Comm +函数功能:打包一个通用回复消息 + 参数.一:ptszMSGBuffer + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出打好包的JSON数据信息 + 参数.二:pInt_MSGLen + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出打包大小 + 参数.三:nCode + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入返回的错误码 + 参数.四:lpszMSGBuffer + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入错误信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleProtocol_Packet_Comm(XCHAR* ptszMSGBuffer, int* pInt_MSGLen, int nCode = 0, LPCXSTR lpszMSGBuffer = _X("success")); +/******************************************************************** 函数名称:ModuleProtocol_Packet_ForwardList 函数功能:转发协议封装请求 参数.一:ptszMsgBuffer @@ -51,11 +80,40 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError = NULL); 备注: *********************************************************************/ extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, SESSION_FORWARD * **pppSt_ListUser, int nCount); +/******************************************************************** +函数名称:ModuleProtocol_Packet_GetProxyRuleList +函数功能:代理转发规则列表信息 + 参数.一:ptszMSGBuffer + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出封装好的包 + 参数.二:pInt_MSGLen + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出封装大小 + 参数.三:pppSt_IPCount + In/Out:In + 类型:三级指针 + 可空:N + 意思:输入要处理的列表 + 参数.四:nListCount + In/Out:In + 类型:整数型 + 可空:N + 意思:输入列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleProtocol_Packet_GetProxyRuleList(XCHAR* ptszMSGBuffer, int* pInt_MSGLen, SESSION_IPCONUT*** pppSt_IPCount, int nListCount); /************************************************************************/ /* 解析导出函数 */ /************************************************************************/ /******************************************************************** -函数名称:ModuleProtocol_Packet_ForwardList +函数名称:ModuleProtocol_Parse_ForwardBind 函数功能:转发协议封装请求 参数.一:lpszMsgBuffer In/Out:In diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp index 42e443a..b158cc0 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp @@ -23,6 +23,54 @@ CModuleProtocol_Packet::~CModuleProtocol_Packet() // 公用函数 ////////////////////////////////////////////////////////////////////////// /******************************************************************** +函数名称:ModuleProtocol_Packet_Comm +函数功能:打包一个通用回复消息 + 参数.一:ptszMSGBuffer + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出打好包的JSON数据信息 + 参数.二:pInt_MSGLen + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出打包大小 + 参数.三:nCode + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入返回的错误码 + 参数.四:lpszMSGBuffer + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入错误信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleProtocol_Packet::ModuleProtocol_Packet_Comm(XCHAR* ptszMSGBuffer, int* pInt_MSGLen, int nCode /* = 0 */, LPCXSTR lpszMSGBuffer /* = _X("success") */) +{ + Protocol_IsErrorOccur = false; + + if ((NULL == ptszMSGBuffer) || (NULL == pInt_MSGLen)) + { + Protocol_IsErrorOccur = true; + Protocol_dwErrorCode = ERROR_MODULE_PROTOCOL_PACKET_PARAMENT; + return false; + } + Json::Value st_JsonRoot; + Json::StreamWriterBuilder st_JsonWBuilder; + //JSON赋值 + st_JsonRoot["code"] = nCode; + st_JsonRoot["msg"] = lpszMSGBuffer; + + *pInt_MSGLen = (int)Json::writeString(st_JsonWBuilder, st_JsonRoot).length(); + memcpy(ptszMSGBuffer, Json::writeString(st_JsonWBuilder, st_JsonRoot).c_str(), *pInt_MSGLen); + return true; +} +/******************************************************************** 函数名称:ModuleProtocol_Packet_ForwardList 函数功能:转发协议封装请求 参数.一:ptszMsgBuffer @@ -96,4 +144,64 @@ bool CModuleProtocol_Packet::ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuf memcpy(ptszMsgBuffer, pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR)); memcpy(ptszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), st_JsonRoot.toStyledString().c_str(), pSt_ProtocolHdr->unPacketSize); return true; +} +/******************************************************************** +函数名称:ModuleProtocol_Packet_GetProxyRuleList +函数功能:代理转发规则列表信息 + 参数.一:ptszMSGBuffer + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出封装好的包 + 参数.二:pInt_MSGLen + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出封装大小 + 参数.三:pppSt_IPCount + In/Out:In + 类型:三级指针 + 可空:N + 意思:输入要处理的列表 + 参数.四:nListCount + In/Out:In + 类型:整数型 + 可空:N + 意思:输入列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleProtocol_Packet::ModuleProtocol_Packet_GetProxyRuleList(XCHAR* ptszMSGBuffer, int* pInt_MSGLen, SESSION_IPCONUT*** pppSt_IPCount, int nListCount) +{ + Protocol_IsErrorOccur = false; + + if ((NULL == ptszMSGBuffer) || (NULL == pInt_MSGLen)) + { + Protocol_IsErrorOccur = true; + Protocol_dwErrorCode = ERROR_MODULE_PROTOCOL_PACKET_PARAMENT; + return false; + } + Json::Value st_JsonRoot; + Json::Value st_JsonArray; + Json::StreamWriterBuilder st_JsonWBuilder; + + for (int i = 0; i < nListCount; i++) + { + Json::Value st_JsonObject; + Json::Value st_JsonSub; + st_JsonObject["nIPCount"] = (*pppSt_IPCount)[i]->nIPCount; + st_JsonObject["tszIPAddr"] = (*pppSt_IPCount)[i]->tszIPAddr; + st_JsonArray.append(st_JsonObject); + } + st_JsonRoot["code"] = 0; + st_JsonRoot["msg"] = "success"; + st_JsonRoot["Count"] = nListCount; + st_JsonRoot["Array"] = st_JsonArray; + + st_JsonWBuilder["emitUTF8"] = true; + *pInt_MSGLen = (int)Json::writeString(st_JsonWBuilder, st_JsonRoot).length(); + memcpy(ptszMSGBuffer, Json::writeString(st_JsonWBuilder, st_JsonRoot).c_str(), *pInt_MSGLen); + return true; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h index 4367f0e..5d1e2b0 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h @@ -17,6 +17,8 @@ class CModuleProtocol_Packet CModuleProtocol_Packet(); ~CModuleProtocol_Packet(); public: + bool ModuleProtocol_Packet_Comm(XCHAR* ptszMSGBuffer, int* pInt_MSGLen, int nCode = 0, LPCXSTR lpszMSGBuffer = _X("success")); bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, SESSION_FORWARD*** pppSt_ListUser, int nCount); + bool ModuleProtocol_Packet_GetProxyRuleList(XCHAR* ptszMSGBuffer, int* pInt_MSGLen, SESSION_IPCONUT*** pppSt_IPCount, int nListCount); private: }; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def index 5d5832c..c5c1cf9 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def +++ b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def @@ -3,6 +3,8 @@ LIBRARY EXPORTS ModuleProtocol_GetLastError + ModuleProtocol_Packet_Comm ModuleProtocol_Packet_ForwardList + ModuleProtocol_Packet_GetProxyRuleList ModuleProtocol_Parse_ForwardBind \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/pch.cpp b/XEngine_Source/XEngine_ModuleProtocol/pch.cpp index 0a6fc70..ab467ab 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/pch.cpp +++ b/XEngine_Source/XEngine_ModuleProtocol/pch.cpp @@ -31,10 +31,18 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError) /************************************************************************/ /* 封包导出函数 */ /************************************************************************/ +extern "C" bool ModuleProtocol_Packet_Comm(XCHAR* ptszMSGBuffer, int* pInt_MSGLen, int nCode, LPCXSTR lpszMSGBuffer) +{ + return m_ProtocolPacket.ModuleProtocol_Packet_Comm(ptszMSGBuffer, pInt_MSGLen, nCode, lpszMSGBuffer); +} extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR * ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, SESSION_FORWARD * **pppSt_ListUser, int nCount) { return m_ProtocolPacket.ModuleProtocol_Packet_ForwardList(ptszMsgBuffer, pInt_Len, pSt_ProtocolHdr, pppSt_ListUser, nCount); } +extern "C" bool ModuleProtocol_Packet_GetProxyRuleList(XCHAR* ptszMSGBuffer, int* pInt_MSGLen, SESSION_IPCONUT*** pppSt_IPCount, int nListCount) +{ + return m_ProtocolPacket.ModuleProtocol_Packet_GetProxyRuleList(ptszMSGBuffer, pInt_MSGLen, pppSt_IPCount, nListCount); +} /************************************************************************/ /* 解析导出函数 */ /************************************************************************/ diff --git a/XEngine_Source/XEngine_ServiceApp/Makefile b/XEngine_Source/XEngine_ServiceApp/Makefile index b324945..44a8ebd 100644 --- a/XEngine_Source/XEngine_ServiceApp/Makefile +++ b/XEngine_Source/XEngine_ServiceApp/Makefile @@ -2,12 +2,12 @@ CC = g++ -Wall -std=c++20 PLATVER = LOADHDR = -I ./ -I ../XEngine_DependLibrary/XEngine_Module/jsoncpp LOADSO = -L ../XEngine_ModuleConfigure -L ../XEngine_ModuleSession -L ../XEngine_ModuleProtocol -L ../XEngine_ModuleHelp \ - -L ../XEngine_DependLibrary/XEngine_Module/jsoncpp -L ../XEngine_DependLibrary/XEngine_Module/XEngine_InfoReport -LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_Cryption -lXEngine_ManagePool -lXClient_Socket -lXClient_APIHelp -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_ProxyProtocol -lNetHelp_APIHelp -lNetHelp_APIAddr -lNetHelp_XSocket \ + -L ../XEngine_DependLibrary/XEngine_Module/jsoncpp -L ../XEngine_DependLibrary/XEngine_Module/XEngine_InfoReport -L ../XEngine_DependLibrary/XEngine_Module/XEngine_Verification +LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_Cryption -lXEngine_ManagePool -lXClient_Socket -lXClient_APIHelp -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_ProxyProtocol -lRfcComponents_HttpProtocol -lNetHelp_APIHelp -lNetHelp_APIAddr -lNetHelp_XSocket \ -lXEngine_ModuleConfigure -lXEngine_ModuleSession -lXEngine_ModuleProtocol -lXEngine_ModuleHelp \ - -ljsoncpp -lXEngine_InfoReport + -ljsoncpp -lXEngine_InfoReport -lXEngine_Verification LIBEX = -OBJECTS = XEngine_Configure.o XEngine_Network.o XEngine_SocksTask.o XEngine_TunnelTask.o XEngine_ForwardTask.o XEngine_ProxyTask.o XEngine_ServiceApp.o +OBJECTS = XEngine_Configure.o XEngine_Network.o XEngine_HTTPTask.o XEngine_SocksTask.o XEngine_TunnelTask.o XEngine_ForwardTask.o XEngine_ProxyTask.o XEngine_ServiceApp.o ifeq ($(RELEASE),1) FLAGS = -c -D _RELEASE @@ -50,6 +50,8 @@ XEngine_Configure.o:./XEngine_Configure.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_Configure.cpp XEngine_Network.o:./XEngine_Network.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_Network.cpp +XEngine_HTTPTask.o:./XEngine_HTTPTask.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_HTTPTask.cpp XEngine_SocksTask.o:./XEngine_SocksTask.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_SocksTask.cpp XEngine_TunnelTask.o:./XEngine_TunnelTask.cpp diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp index b537342..349f5a0 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp @@ -14,6 +14,7 @@ bool XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pS { LPCXSTR lpszConfigFile = _X("./XEngine_Config/XEngine_Config.json"); LPCXSTR lpszConfigVersion = _X("./XEngine_Config/XEngine_Version.json"); + LPCXSTR lpszConfigProxy = _X("./XEngine_Config/XEngine_ProxyConfig.json"); if (!ModuleConfigure_Json_File(lpszConfigFile, pSt_Configure)) { @@ -25,6 +26,11 @@ bool XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pS printf("解析配置文件失败,ModuleConfigure_Json_Version:%lX\n", ModuleConfigure_GetLastError()); return false; } + if (!ModuleConfigure_Json_ProxyFile(lpszConfigProxy, &st_ProxyConfig)) + { + printf("解析配置文件失败,ModuleConfigure_Json_Version:%lX\n", ModuleConfigure_GetLastError()); + return false; + } for (int i = 0; i < argc; i++) { diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HTTPTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_HTTPTask.cpp new file mode 100644 index 0000000..ad474c6 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HTTPTask.cpp @@ -0,0 +1,206 @@ +#include "XEngine_Hdr.h" +/******************************************************************** +// Created: 2026/02/05 16:00:12 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp\XEngine_HTTPTask.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_HTTPTask +// File Ext: cpp +// Project: XEngine +// Author: qyt +// Purpose: HTTP任务处理代码 +// History: +*********************************************************************/ +XHTHREAD XCALLBACK XEngine_HTTPTask_Thread(XPVOID lParam) +{ + //任务池是编号1开始的. + int nThreadPos = *(int*)lParam; + nThreadPos++; + + while (bIsRun) + { + //等待编号1的任务池触发一个组完包的事件 + if (!HttpProtocol_Server_EventWaitEx(xhHTTPPacket, nThreadPos)) + { + continue; + } + int nListCount = 0; + XENGINE_MANAGEPOOL_TASKEVENT** ppSst_ListAddr; + //获得编号1的所有待处理任务的客户端列表(也就是客户端发送过来的数据已经组好了一个包,需要我们处理) + HttpProtocol_Server_GetPoolEx(xhHTTPPacket, nThreadPos, &ppSst_ListAddr, &nListCount); + //先循环客户端 + for (int i = 0; i < nListCount; i++) + { + //再循环客户端拥有的任务个数 + for (int j = 0; j < ppSst_ListAddr[i]->nPktCount; j++) + { + int nMsgLen = 0; //客户端发送的数据大小,不包括头 + int nHdrCount = 0; //客户端的HTTP头字段数 + XCHAR** ppszHdrList; //客户端的HTTP头字段列表 + XCHAR* ptszMsgBuffer = NULL; //客户端发送的数据 + RFCCOMPONENTS_HTTP_REQPARAM st_HTTPReqparam; //客户端的请求参数 + + memset(&st_HTTPReqparam, '\0', sizeof(RFCCOMPONENTS_HTTP_REQPARAM)); + //得到一个指定客户端的完整数据包 + if (HttpProtocol_Server_GetMemoryEx(xhHTTPPacket, ppSst_ListAddr[i]->tszClientAddr, &ptszMsgBuffer, &nMsgLen, &st_HTTPReqparam, &ppszHdrList, &nHdrCount)) + { + //在另外一个函数里面处理数据 + XEngine_HTTPTask_Handle(&st_HTTPReqparam, ppSst_ListAddr[i]->tszClientAddr, ptszMsgBuffer, nMsgLen, ppszHdrList, nHdrCount); + //释放内存 + BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + BaseLib_Memory_Free((XPPPMEM)&ppszHdrList, nHdrCount); + } + } + } + BaseLib_Memory_Free((XPPPMEM)&ppSst_ListAddr, nListCount); + } + return 0; +} + +bool HTTPTask_TastPost_Verification(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXSTR lpszClientAddr, XCHAR** pptszHDRList, int nHDRCount) +{ + //http验证 + int nVType = 0; + int nSDLen = 0; + XCHAR tszSDBuffer[XPATH_MAX] = {}; + RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam = {}; + + st_HDRParam.nHttpCode = 401; + st_HDRParam.bIsClose = true; + st_HDRParam.bAuth = true; + //打包验证信息 + int nHDRLen = 0; + XCHAR tszHDRBuffer[XPATH_MAX] = {}; + if (1 == st_ServiceConfig.st_XVerifcation.nVType) + { + Verification_HTTP_BasicServerPacket(tszHDRBuffer, &nHDRLen); + } + else + { + XCHAR tszNonceStr[64] = {}; + XCHAR tszOpaqueStr[64] = {}; + Verification_HTTP_DigestServerPacket(tszHDRBuffer, &nHDRLen, tszNonceStr, tszOpaqueStr); + } + //后去验证方法 + if (!Verification_HTTP_GetType(pptszHDRList, nHDRCount, &nVType)) + { + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, tszSDBuffer, &nSDLen, &st_HDRParam, NULL, 0, tszHDRBuffer); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户验证失败,验证方式:%d,错误:%lX"), lpszClientAddr, st_ServiceConfig.st_XVerifcation.nVType, Verification_GetLastError()); + return false; + } + //验证方式是否一致 + if (st_ServiceConfig.st_XVerifcation.nVType != nVType) + { + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, tszSDBuffer, &nSDLen, &st_HDRParam, NULL, 0, tszHDRBuffer); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户验证失败,验证方式错误,请求:%d,需求:%d"), lpszClientAddr, nVType, st_ServiceConfig.st_XVerifcation.nVType); + return false; + } + bool bRet = false; + if (1 == nVType) + { + bRet = Verification_HTTP_Basic(st_ServiceConfig.st_XVerifcation.tszUserName, st_ServiceConfig.st_XVerifcation.tszUserPass, pptszHDRList, nHDRCount); + } + else if (2 == nVType) + { + bRet = Verification_HTTP_Digest(st_ServiceConfig.st_XVerifcation.tszUserName, st_ServiceConfig.st_XVerifcation.tszUserPass, pSt_HTTPParam->tszHttpMethod, pptszHDRList, nHDRCount); + } + + if (!bRet) + { + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, tszSDBuffer, &nSDLen, &st_HDRParam, NULL, 0, tszHDRBuffer); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户验证失败,验证处理错误,可能用户密码登信息不匹配,类型:%d"), lpszClientAddr, nVType); + return false; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,HTTP验证类型:%d 通过"), lpszClientAddr, nVType); + return true; +} + +bool XEngine_HTTPTask_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR** pptszListHdr, int nHdrCount) +{ + int nSDLen = 0; + int nListCount = 0; + XCHAR** pptszList; + + LPCXSTR lpszMethodPost = _X("POST"); + LPCXSTR lpszMethodGet = _X("GET"); + XCHAR tszSDBuffer[4096] = {}; + + HttpProtocol_ServerHelp_GetParament(pSt_HTTPParam->tszHttpUri, &pptszList, &nListCount); + if (nListCount < 1) + { + ModuleProtocol_Packet_Comm(tszSDBuffer, &nSDLen, 400, "Bad Request,parament is incorrent"); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + BaseLib_Memory_Free((XPPPMEM)&pptszList, nListCount); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的URL请求参数不正确:%s"), lpszClientAddr, pSt_HTTPParam->tszHttpUri); + return false; + } + //http验证 + if (st_ServiceConfig.st_XVerifcation.bEnable) + { + //全面验证 + if (!HTTPTask_TastPost_Verification(pSt_HTTPParam, lpszClientAddr, pptszListHdr, nHdrCount)) + { + return false; + } + } + XCHAR tszKey[128] = {}; + XCHAR tszValue[128] = {}; + LPCXSTR lpszAPIProxyRule = _X("proxyrule"); + LPCXSTR lpszAPIReload = _X("reload"); + //获得函数名 + BaseLib_String_GetKeyValue(pptszList[0], "=", tszKey, tszValue); + //得到客户端请求的方法 + if (0 == _tcsxnicmp(lpszMethodPost, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodPost))) + { + if (0 == _tcsxnicmp(lpszAPIProxyRule, tszValue, _tcsxlen(lpszAPIProxyRule))) + { + //http://127.0.0.1:5400/api?function=get&value=proxyrule + } + else + { + ModuleProtocol_Packet_Comm(tszSDBuffer, &nSDLen, ERROR_XENGINE_PROXY_PROTOCOL_NOTSUPPORT, _X("unknow protocol")); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("HTTP客户端:%s,发送POST请求:%s,处理失败,不支持"), lpszClientAddr, pSt_HTTPParam->tszHttpUri); + } + } + else if (0 == _tcsxnicmp(lpszMethodGet, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodGet))) + { + if (0 == _tcsxnicmp(lpszAPIReload, tszValue, _tcsxlen(lpszAPIReload))) + { + delete st_ProxyConfig.pStl_ListDestAddr; + delete st_ProxyConfig.pStl_ListRuleAddr; + //http://127.0.0.1:5400/api?function=reload&type=0 + LPCXSTR lpszConfigProxy = _X("./XEngine_Config/XEngine_ProxyConfig.json"); + ModuleConfigure_Json_ProxyFile(lpszConfigProxy, &st_ProxyConfig); + ModuleProtocol_Packet_Comm(tszSDBuffer, &nSDLen); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("HTTP客户端:%s,发送重载配置请求成功"), lpszClientAddr); + } + else if (0 == _tcsxnicmp(lpszAPIProxyRule, tszValue, _tcsxlen(lpszAPIProxyRule))) + { + //http://127.0.0.1:5400/api?function=proxyrule + int nListCount = 0; + SESSION_IPCONUT** ppSt_IPCountList; + ModuleSession_ProxyRule_GetList(&ppSt_IPCountList, &nListCount); + ModuleProtocol_Packet_GetProxyRuleList(tszSDBuffer, &nSDLen, &ppSt_IPCountList, nListCount); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + BaseLib_Memory_Free((XPPPMEM)&ppSt_IPCountList, nListCount); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送获取转发规则列表请求处理成功"), lpszClientAddr, pSt_HTTPParam->tszHttpUri); + } + else + { + ModuleProtocol_Packet_Comm(tszSDBuffer, &nSDLen, ERROR_XENGINE_PROXY_PROTOCOL_NOTSUPPORT, _X("unknow protocol")); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("HTTP客户端:%s,发送GET请求:%s,处理失败,不支持"), lpszClientAddr, pSt_HTTPParam->tszHttpUri); + } + } + else + { + ModuleProtocol_Packet_Comm(tszSDBuffer, &nSDLen, ERROR_XENGINE_PROXY_PROTOCOL_NOTSUPPORT, _X("unknow protocol")); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_HTTP); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("HTTP客户端:%s,协议错误"), lpszClientAddr); + } + return true; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HTTPTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_HTTPTask.h new file mode 100644 index 0000000..50c2c2a --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HTTPTask.h @@ -0,0 +1,16 @@ +#pragma once +/******************************************************************** +// Created: 2026/02/05 16:00:07 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp\XEngine_HTTPTask.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_HTTPTask +// File Ext: h +// Project: XEngine +// Author: qyt +// Purpose: HTTP任务处理代码 +// History: +*********************************************************************/ +//任务处理池,用来获取一个完整包 +XHTHREAD XCALLBACK XEngine_HTTPTask_Thread(XPVOID lParam); +//任务处理相关函数,处理包的内容 +bool XEngine_HTTPTask_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR** pptszListHdr, int nHdrCount); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h index e961ca0..a7c1e0d 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -47,12 +47,16 @@ using namespace std; #include #include #include +#include +#include #include #include //加载项目相关头文件 #include "../XEngine_UserProtocol.h" #include "../XEngine_DependLibrary/XEngine_Module/XEngine_InfoReport/InfoReport_Define.h" #include "../XEngine_DependLibrary/XEngine_Module/XEngine_InfoReport/InfoReport_Error.h" +#include "../XEngine_DependLibrary/XEngine_Module/XEngine_Verification/Verification_Define.h" +#include "../XEngine_DependLibrary/XEngine_Module/XEngine_Verification/Verification_Error.h" #include "../XEngine_ModuleConfigure/ModuleConfig_Define.h" #include "../XEngine_ModuleConfigure/ModuleConfig_Error.h" #include "../XEngine_ModuleSession/ModuleSession_Define.h" @@ -64,6 +68,7 @@ using namespace std; //加载自己的头文件 #include "XEngine_Configure.h" #include "XEngine_Network.h" +#include "XEngine_HTTPTask.h" #include "XEngine_SocksTask.h" #include "XEngine_TunnelTask.h" #include "XEngine_ForwardTask.h" @@ -100,10 +105,17 @@ extern XHANDLE xhForwardClient; extern XHANDLE xhProxySocket; extern XHANDLE xhProxyHeart; extern XHANDLE xhProxyClient; +//HTTP服务器 +extern XHANDLE xhHTTPSocket; +extern XHANDLE xhHTTPHeart; +extern XHANDLE xhHTTPPacket; +extern XHANDLE xhHTTPPool; //配置文件 extern XENGINE_SERVICECONFIG st_ServiceConfig; +extern XENGINE_PROXYCONFIG st_ProxyConfig; //网络类型定义 +#define XENGINE_CLIENT_NETTYPE_HTTP 0 #define XENGINE_CLIENT_NETTYPE_SOCKS 1 #define XENGINE_CLIENT_NETTYPE_TUNNEL 2 #define XENGINE_CLIENT_NETTYPE_FORWARD 3 @@ -126,23 +138,27 @@ extern XENGINE_SERVICECONFIG st_ServiceConfig; #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_Packets.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol.lib") +#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_HttpProtocol.lib") #pragma comment(lib,"Ws2_32.lib") #pragma comment(lib,"Dbghelp.lib") #ifdef _DEBUG #ifdef _M_X64 #pragma comment(lib,"../x64/Debug/XEngine_InfoReport.lib") +#pragma comment(lib,"../x64/Debug/XEngine_Verification.lib") #pragma comment(lib,"../x64/Debug/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../x64/Debug/XEngine_ModuleSession.lib") #pragma comment(lib,"../x64/Debug/XEngine_ModuleProtocol.lib") #pragma comment(lib,"../x64/Debug/XEngine_ModuleHelp.lib") #elif _M_ARM64 #pragma comment(lib,"../ARM64/Debug/XEngine_InfoReport.lib") +#pragma comment(lib,"../ARM64/Debug/XEngine_Verification.lib") #pragma comment(lib,"../ARM64/Debug/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../ARM64/Debug/XEngine_ModuleSession.lib") #pragma comment(lib,"../ARM64/Debug/XEngine_ModuleProtocol.lib") #pragma comment(lib,"../ARM64/Debug/XEngine_ModuleHelp.lib") #elif _M_IX86 #pragma comment(lib,"../Debug/XEngine_InfoReport.lib") +#pragma comment(lib,"../Debug/XEngine_Verification.lib") #pragma comment(lib,"../Debug/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../Debug/XEngine_ModuleSession.lib") #pragma comment(lib,"../Debug/XEngine_ModuleProtocol.lib") @@ -151,18 +167,21 @@ extern XENGINE_SERVICECONFIG st_ServiceConfig; #else #ifdef _M_X64 #pragma comment(lib,"../x64/Release/XEngine_InfoReport.lib") +#pragma comment(lib,"../x64/Release/XEngine_Verification.lib") #pragma comment(lib,"../x64/Release/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../x64/Release/XEngine_ModuleSession.lib") #pragma comment(lib,"../x64/Release/XEngine_ModuleProtocol.lib") #pragma comment(lib,"../x64/Release/XEngine_ModuleHelp.lib") #elif _M_ARM64 #pragma comment(lib,"../ARM64/Release/XEngine_InfoReport.lib") +#pragma comment(lib,"../ARM64/Release/XEngine_Verification.lib") #pragma comment(lib,"../ARM64/Release/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../ARM64/Release/XEngine_ModuleSession.lib") #pragma comment(lib,"../ARM64/Release/XEngine_ModuleProtocol.lib") #pragma comment(lib,"../ARM64/Release/XEngine_ModuleHelp.lib") #elif _M_IX86 #pragma comment(lib,"../Release/XEngine_InfoReport.lib") +#pragma comment(lib,"../Release/XEngine_Verification.lib") #pragma comment(lib,"../Release/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../Release/XEngine_ModuleSession.lib") #pragma comment(lib,"../Release/XEngine_ModuleProtocol.lib") diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp index ea2da0c..a64a0ef 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -10,6 +10,32 @@ // Purpose: 网络IO相关代码 // History: *********************************************************************/ +//////////////////////////////////////////////////////////////////////////下面是HTTP网络IO相关代码处理函数 +bool XCALLBACK Network_Callback_HTTPLogin(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam) +{ + SocketOpt_HeartBeat_InsertAddrEx(xhHTTPHeart, lpszClientAddr); + HttpProtocol_Server_CreateClientEx(xhHTTPPacket, lpszClientAddr, 0); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DETAIL, _X("HTTP客户端:%s,连接到服务器"), lpszClientAddr); + return true; +} +void XCALLBACK Network_Callback_HTTPRecv(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszRecvMsg, int nMsgLen, XPVOID lParam) +{ + if (!HttpProtocol_Server_InserQueueEx(xhHTTPPacket, lpszClientAddr, lpszRecvMsg, nMsgLen)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,投递HTTP数据包到消息队列失败,错误:%lX"), lpszClientAddr, HttpProtocol_GetLastError()); + return; + } + SocketOpt_HeartBeat_ActiveAddrEx(xhHTTPHeart, lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _X("HTTP客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); +} +void XCALLBACK Network_Callback_HTTPLeave(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam) +{ + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_HTTP, XENGINE_CLIENT_CLOSE_NETWORK); +} +void XCALLBACK Network_Callback_HTTPHeart(LPCXSTR lpszClientAddr, XSOCKET hSocket, int nStatus, XPVOID lParam) +{ + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_HTTP, XENGINE_CLIENT_CLOSE_HEARTBEAT); +} //////////////////////////////////////////////////////////////////////////下面是SOCKS网络IO相关代码处理函数 bool XCALLBACK Network_Callback_SocksLogin(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam) { @@ -248,7 +274,25 @@ void XEngine_Network_Close(LPCXSTR lpszClientAddr, int nIPProto, int nCloseType) bool XEngine_Network_Send(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, int nIPProto) { //根据客户端类型来处理发送业务逻辑 - if (XENGINE_CLIENT_NETTYPE_SOCKS == nIPProto) + if (XENGINE_CLIENT_NETTYPE_HTTP == nIPProto) + { + int nMSGSize = 0; //发送数据的大小 + XCHAR tszMSGBuffer[4096] = {}; //发送数据的缓冲区 + RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam = {}; + st_HDRParam.nHttpCode = 200; + st_HDRParam.bIsClose = true; + + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, tszMSGBuffer, &nMSGSize, &st_HDRParam, lpszMsgBuffer, nMsgLen); + //发送数据给指定客户端 + if (!NetCore_TCPXCore_SendEx(xhHTTPSocket, lpszClientAddr, tszMSGBuffer, nMSGSize, 1, 1)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + return false; + } + //发送成功激活一次心跳 + SocketOpt_HeartBeat_ActiveAddrEx(xhHTTPHeart, lpszClientAddr); + } + else if (XENGINE_CLIENT_NETTYPE_SOCKS == nIPProto) { //发送数据给指定客户端 if (!NetCore_TCPXCore_SendEx(xhSocksSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen, 1, 1)) diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h index c7f65e2..904c6bf 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h @@ -10,6 +10,11 @@ // Purpose: 网络IO相关代码 // History: *********************************************************************/ +//HTTP相关 +bool XCALLBACK Network_Callback_HTTPLogin(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam); +void XCALLBACK Network_Callback_HTTPRecv(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszRecvMsg, int nMsgLen, XPVOID lParam); +void XCALLBACK Network_Callback_HTTPLeave(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam); +void XCALLBACK Network_Callback_HTTPHeart(LPCXSTR lpszClientAddr, XSOCKET hSocket, int nStatus, XPVOID lParam); //SOCKS相关 bool XCALLBACK Network_Callback_SocksLogin(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam); //用户连接 void XCALLBACK Network_Callback_SocksRecv(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszRecvMsg, int nMsgLen, XPVOID lParam); //接受到数据 diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.cpp index d2fff8c..7a6b4b9 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.cpp @@ -23,10 +23,10 @@ bool XEngine_Proxy_Connect(LPCXSTR lpszClientAddr) _tcsxcpy(tszSrcIPAddr, lpszClientAddr); APIAddr_IPAddr_SegAddr(tszSrcIPAddr, &nSrcPort); //是否有单独的转发规则 - if (!st_ServiceConfig.st_XProxy.pStl_ListRuleAddr->empty()) + if (!st_ProxyConfig.pStl_ListRuleAddr->empty()) { //有规则,需要进行匹配 - for (auto stl_ListIterator = st_ServiceConfig.st_XProxy.pStl_ListRuleAddr->begin(); stl_ListIterator != st_ServiceConfig.st_XProxy.pStl_ListRuleAddr->end(); stl_ListIterator++) + for (auto stl_ListIterator = st_ProxyConfig.pStl_ListRuleAddr->begin(); stl_ListIterator != st_ProxyConfig.pStl_ListRuleAddr->end(); stl_ListIterator++) { XCHAR tszTmpIPAddr[128] = {}; _stxscanf(stl_ListIterator->c_str(), _X("%[^-]-%s"), tszTmpIPAddr, tszDstIPAddr); @@ -44,7 +44,7 @@ bool XEngine_Proxy_Connect(LPCXSTR lpszClientAddr) if (!bFound) { //没有匹配到 - if (0 == st_ServiceConfig.st_XProxy.nRuleMode) + if (0 == st_ProxyConfig.nRuleMode) { int nIPCount = 0; SESSION_IPCONUT** ppSt_IPCount; @@ -56,22 +56,22 @@ bool XEngine_Proxy_Connect(LPCXSTR lpszClientAddr) APIAddr_IPAddr_SegAddr(tszDstIPAddr, &nDstPort); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Proxy客户端:%s,代理转发规则地址未命中,使用最小原则规则地址:%s:%d"), lpszClientAddr, tszDstIPAddr, nDstPort); } - else if (1 == st_ServiceConfig.st_XProxy.nRuleMode) + else if (1 == st_ProxyConfig.nRuleMode) { size_t nHashValue = std::hash{}(tszSrcIPAddr); - size_t nIndex = nHashValue % st_ServiceConfig.st_XProxy.pStl_ListDestAddr->size(); - auto stl_ListIterator = st_ServiceConfig.st_XProxy.pStl_ListDestAddr->begin(); + size_t nIndex = nHashValue % st_ProxyConfig.pStl_ListDestAddr->size(); + auto stl_ListIterator = st_ProxyConfig.pStl_ListDestAddr->begin(); std::advance(stl_ListIterator, nIndex); _tcsxcpy(tszIPAddr, stl_ListIterator->c_str()); _tcsxcpy(tszDstIPAddr, stl_ListIterator->c_str()); APIAddr_IPAddr_SegAddr(tszDstIPAddr, &nDstPort); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Proxy客户端:%s,代理转发规则地址未命中,使用HASH规则,规则地址:%s:%d"), lpszClientAddr, tszDstIPAddr, nDstPort); } - else if (2 == st_ServiceConfig.st_XProxy.nRuleMode) + else if (2 == st_ProxyConfig.nRuleMode) { XNETHANDLE xhIndex = 0; - BaseLib_Handle_Create(&xhIndex, 0, st_ServiceConfig.st_XProxy.pStl_ListDestAddr->size()); - auto stl_ListIterator = st_ServiceConfig.st_XProxy.pStl_ListDestAddr->begin(); + BaseLib_Handle_Create(&xhIndex, 0, st_ProxyConfig.pStl_ListDestAddr->size()); + auto stl_ListIterator = st_ProxyConfig.pStl_ListDestAddr->begin(); std::advance(stl_ListIterator, xhIndex); _tcsxcpy(tszIPAddr, stl_ListIterator->c_str()); _tcsxcpy(tszDstIPAddr, stl_ListIterator->c_str()); diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp index 21e8cdc..1fba077 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp @@ -21,8 +21,14 @@ XHANDLE xhForwardClient = NULL; XHANDLE xhProxySocket = NULL; XHANDLE xhProxyHeart = NULL; XHANDLE xhProxyClient = NULL; + +XHANDLE xhHTTPSocket = NULL; +XHANDLE xhHTTPHeart = NULL; +XHANDLE xhHTTPPacket = NULL; +XHANDLE xhHTTPPool = NULL; //配置文件 -XENGINE_SERVICECONFIG st_ServiceConfig; +XENGINE_SERVICECONFIG st_ServiceConfig = {}; +XENGINE_PROXYCONFIG st_ProxyConfig = {}; void ServiceApp_Stop(int signo) { @@ -127,10 +133,11 @@ int main(int argc, char** argv) #endif bIsRun = true; int nRet = 0; + LPCXSTR lpszHTTPMime = _X("./XEngine_Config/HttpMime.types"); + LPCXSTR lpszHTTPCode = _X("./XEngine_Config/HttpCode.types"); XENGINE_LIBVERSION st_VERXEngine = {}; HELPCOMPONENTS_XLOG_CONFIGURE st_XLogConfig = {}; - - memset(&st_ServiceConfig, '\0', sizeof(XENGINE_SERVICECONFIG)); + THREADPOOL_PARAMENT** ppSt_ListHTTPParam; //初始化参数 if (!XEngine_Configure_Parament(argc, argv, &st_ServiceConfig)) { @@ -159,6 +166,73 @@ int main(int argc, char** argv) signal(SIGTERM, ServiceApp_Stop); signal(SIGABRT, ServiceApp_Stop); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化信号量处理程序成功")); + + if (st_ServiceConfig.st_XVerifcation.bEnable) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启用HTTP验证,验证模式为:%d"), st_ServiceConfig.st_XVerifcation.nVType); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,HTTP验证服务没有启用")); + } + if (st_ServiceConfig.nHttpPort > 0) + { + //HTTP包处理器 + xhHTTPPacket = HttpProtocol_Server_InitEx(lpszHTTPCode, lpszHTTPMime, st_ServiceConfig.st_XMax.nHTTPThread); + if (NULL == xhHTTPPacket) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化HTTP组包失败,错误:%lX"), HttpProtocol_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化HTTP组包成功,IO线程个数:%d"), st_ServiceConfig.st_XMax.nIOThread); + //启动心跳 + if (st_ServiceConfig.st_XTime.nTimeCheck > 0) + { + xhHTTPHeart = SocketOpt_HeartBeat_InitEx(st_ServiceConfig.st_XTime.nHttpTimeout, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_HTTPHeart); + if (NULL == xhHTTPHeart) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化HTTP心跳服务失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化HTTP心跳服务成功,时间:%d,次数:%d"), st_ServiceConfig.st_XTime.nHttpTimeout, st_ServiceConfig.st_XTime.nTimeCheck); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,HTTP心跳服务被设置为不启用")); + } + //网络 + xhHTTPSocket = NetCore_TCPXCore_StartEx(st_ServiceConfig.nHttpPort, st_ServiceConfig.st_XMax.nMaxClient, st_ServiceConfig.st_XMax.nIOThread); + if (NULL == xhHTTPSocket) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动HTTP网络端口:%d 服务器失败,错误:%lX"), st_ServiceConfig.nHttpPort, NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动HTTP网络服务器成功,HTTP端口:%d,IO:%d"), st_ServiceConfig.nHttpPort, st_ServiceConfig.st_XMax.nIOThread); + NetCore_TCPXCore_RegisterCallBackEx(xhHTTPSocket, Network_Callback_HTTPLogin, Network_Callback_HTTPRecv, Network_Callback_HTTPLeave); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,注册HTTP网络事件成功")); + //HTTP任务池 + BaseLib_Memory_Malloc((XPPPMEM)&ppSt_ListHTTPParam, st_ServiceConfig.st_XMax.nHTTPThread, sizeof(THREADPOOL_PARAMENT)); + for (int i = 0; i < st_ServiceConfig.st_XMax.nHTTPThread; i++) + { + int* pInt_Pos = new int; + + *pInt_Pos = i; + ppSt_ListHTTPParam[i]->lParam = pInt_Pos; + ppSt_ListHTTPParam[i]->fpCall_ThreadsTask = XEngine_HTTPTask_Thread; + } + xhHTTPPool = ManagePool_Thread_NQCreate(&ppSt_ListHTTPParam, st_ServiceConfig.st_XMax.nHTTPThread); + if (NULL == xhHTTPPool) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动HTTP线程池服务失败,错误:%lX"), ManagePool_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动HTTP线程池服务成功,启动个数:%d"), st_ServiceConfig.st_XMax.nHTTPThread); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,HTTP消息服务没有被启用")); + } + //启动Socks服务相关代码 if (st_ServiceConfig.nSocksPort > 0) { @@ -334,7 +408,7 @@ int main(int argc, char** argv) XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动Proxy网络服务器失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动Proxy网络服务器成功,Proxy端口:%d,转发目标个数:%d 规则个数:%d,IO:%d"), st_ServiceConfig.nProxyPort, st_ServiceConfig.st_XProxy.pStl_ListDestAddr->size(), st_ServiceConfig.st_XProxy.pStl_ListRuleAddr->size(), st_ServiceConfig.st_XMax.nIOThread); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动Proxy网络服务器成功,Proxy端口:%d,转发目标个数:%d 规则个数:%d,IO:%d"), st_ServiceConfig.nProxyPort, st_ProxyConfig.pStl_ListDestAddr->size(), st_ProxyConfig.pStl_ListRuleAddr->size(), st_ServiceConfig.st_XMax.nIOThread); NetCore_TCPXCore_RegisterCallBackEx(xhProxySocket, Network_Callback_ProxyLogin, Network_Callback_ProxyRecv, Network_Callback_ProxyLeave); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,注册Proxy网络事件成功")); //客户端 @@ -346,11 +420,11 @@ int main(int argc, char** argv) } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动Proxy客户端服务成功")); - for (auto stl_ListIterator = st_ServiceConfig.st_XProxy.pStl_ListDestAddr->begin(); stl_ListIterator != st_ServiceConfig.st_XProxy.pStl_ListDestAddr->end(); stl_ListIterator++) + for (auto stl_ListIterator = st_ProxyConfig.pStl_ListDestAddr->begin(); stl_ListIterator != st_ProxyConfig.pStl_ListDestAddr->end(); stl_ListIterator++) { ModuleSession_ProxyRule_Insert(stl_ListIterator->c_str()); } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化负载均衡后台服务端成功,个数:%d"), st_ServiceConfig.st_XProxy.pStl_ListDestAddr->size()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化负载均衡后台服务端成功,个数:%d"), st_ProxyConfig.pStl_ListDestAddr->size()); } else { diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj index a0e1363..1397cf6 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj @@ -236,6 +236,7 @@ + @@ -246,6 +247,7 @@ + diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters index 71f8003..d309d84 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters @@ -36,6 +36,9 @@ 源文件 + + 源文件 + @@ -59,5 +62,8 @@ 头文件 + + 头文件 + \ No newline at end of file