From e2955da78f7836ece3a9eb9e5ee85d84af327e64 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 22 May 2015 20:47:27 +0800 Subject: [PATCH] refine code, extract the http protocol sdk to module. --- trunk/configure | 2 +- trunk/ide/srs_upp/srs_upp.upp | 2 ++ trunk/ide/srs_vs2010/srs.vcxproj | 2 ++ .../srs_xcode.xcodeproj/project.pbxproj | 6 ++++ trunk/src/app/srs_app_http.cpp | 2 +- trunk/src/app/srs_app_http.hpp | 3 +- trunk/src/app/srs_app_http_api.cpp | 26 +++++++-------- trunk/src/protocol/srs_http_stack.cpp | 24 ++++++++++++++ trunk/src/protocol/srs_http_stack.hpp | 32 +++++++++++++++++++ 9 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 trunk/src/protocol/srs_http_stack.cpp create mode 100644 trunk/src/protocol/srs_http_stack.hpp diff --git a/trunk/configure b/trunk/configure index 7f8727442..807c0317c 100755 --- a/trunk/configure +++ b/trunk/configure @@ -159,7 +159,7 @@ MODULE_DEPENDS=("CORE" "KERNEL") ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot}) MODULE_FILES=("srs_rtmp_amf0" "srs_rtmp_io" "srs_rtmp_stack" "srs_rtmp_sdk" "srs_rtmp_handshake" "srs_rtmp_utility" "srs_rtmp_msg_array" "srs_rtmp_buffer" - "srs_raw_avc" "srs_rtsp_stack") + "srs_raw_avc" "srs_rtsp_stack" "srs_http_stack") RTMP_INCS="src/protocol"; MODULE_DIR=${RTMP_INCS} . auto/modules.sh RTMP_OBJS="${MODULE_OBJS[@]}" # diff --git a/trunk/ide/srs_upp/srs_upp.upp b/trunk/ide/srs_upp/srs_upp.upp index e302bb98b..23e480c96 100755 --- a/trunk/ide/srs_upp/srs_upp.upp +++ b/trunk/ide/srs_upp/srs_upp.upp @@ -46,6 +46,8 @@ file ../../src/kernel/srs_kernel_utility.hpp, ../../src/kernel/srs_kernel_utility.cpp, protocol readonly separator, + ../../src/protocol/srs_http_stack.hpp, + ../../src/protocol/srs_http_stack.cpp, ../../src/protocol/srs_raw_avc.hpp, ../../src/protocol/srs_raw_avc.cpp, ../../src/protocol/srs_rtmp_amf0.hpp, diff --git a/trunk/ide/srs_vs2010/srs.vcxproj b/trunk/ide/srs_vs2010/srs.vcxproj index f7d0a9ff1..9f1f9ef23 100755 --- a/trunk/ide/srs_vs2010/srs.vcxproj +++ b/trunk/ide/srs_vs2010/srs.vcxproj @@ -119,6 +119,7 @@ + @@ -201,6 +202,7 @@ + diff --git a/trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj b/trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj index 6daf2f9b7..eb41fc695 100644 --- a/trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj +++ b/trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 3C0E1B8D1B0F5ADF003ADEF7 /* srs_http_stack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C0E1B8B1B0F5ADF003ADEF7 /* srs_http_stack.cpp */; }; 3C1231F61AAE652D00CE8F6C /* srs_core_autofree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1231F01AAE652C00CE8F6C /* srs_core_autofree.cpp */; }; 3C1231F71AAE652D00CE8F6C /* srs_core_performance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1231F21AAE652C00CE8F6C /* srs_core_performance.cpp */; }; 3C1231F81AAE652D00CE8F6C /* srs_core.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1231F41AAE652D00CE8F6C /* srs_core.cpp */; }; @@ -122,6 +123,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 3C0E1B8B1B0F5ADF003ADEF7 /* srs_http_stack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_http_stack.cpp; path = ../../../src/protocol/srs_http_stack.cpp; sourceTree = ""; }; + 3C0E1B8C1B0F5ADF003ADEF7 /* srs_http_stack.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_http_stack.hpp; path = ../../../src/protocol/srs_http_stack.hpp; sourceTree = ""; }; 3C1231E51AAE64A400CE8F6C /* srs_xcode */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = srs_xcode; sourceTree = BUILT_PRODUCTS_DIR; }; 3C1231F01AAE652C00CE8F6C /* srs_core_autofree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_core_autofree.cpp; path = ../../../src/core/srs_core_autofree.cpp; sourceTree = ""; }; 3C1231F11AAE652C00CE8F6C /* srs_core_autofree.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_core_autofree.hpp; path = ../../../src/core/srs_core_autofree.hpp; sourceTree = ""; }; @@ -487,6 +490,8 @@ 3C12322C1AAE819900CE8F6C /* protocol */ = { isa = PBXGroup; children = ( + 3C0E1B8B1B0F5ADF003ADEF7 /* srs_http_stack.cpp */, + 3C0E1B8C1B0F5ADF003ADEF7 /* srs_http_stack.hpp */, 3C12322D1AAE81A400CE8F6C /* srs_raw_avc.cpp */, 3C12322E1AAE81A400CE8F6C /* srs_raw_avc.hpp */, 3C12322F1AAE81A400CE8F6C /* srs_rtmp_amf0.cpp */, @@ -886,6 +891,7 @@ 3C1232411AAE81A400CE8F6C /* srs_raw_avc.cpp in Sources */, 3C1232491AAE81A400CE8F6C /* srs_rtmp_utility.cpp in Sources */, 3C663F191AB0155100286D8B /* srs_publish.c in Sources */, + 3C0E1B8D1B0F5ADF003ADEF7 /* srs_http_stack.cpp in Sources */, 3C1232A01AAE81D900CE8F6C /* srs_app_http_client.cpp in Sources */, 3C689F981AB6AAAC00C9CEEE /* key.c in Sources */, 3C12329B1AAE81D900CE8F6C /* srs_app_ffmpeg.cpp in Sources */, diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp index ff7bf19b9..a343f5535 100644 --- a/trunk/src/app/srs_app_http.cpp +++ b/trunk/src/app/srs_app_http.cpp @@ -58,7 +58,7 @@ using namespace std; #define SRS_HTTP_DEFAULT_PAGE "index.html" -int srs_go_http_response_json(ISrsHttpResponseWriter* w, string data) +int srs_http_response_json(ISrsHttpResponseWriter* w, string data) { w->header()->set_content_length(data.length()); w->header()->set_content_type("application/json"); diff --git a/trunk/src/app/srs_app_http.hpp b/trunk/src/app/srs_app_http.hpp index 07b9fee08..685ad3668 100644 --- a/trunk/src/app/srs_app_http.hpp +++ b/trunk/src/app/srs_app_http.hpp @@ -40,6 +40,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include class SrsRequest; class SrsStSocket; @@ -72,7 +73,7 @@ class SrsConnection; #define SRS_HTTP_TS_SEND_BUFFER_SIZE 4096 // helper function: response in json format. -extern int srs_go_http_response_json(ISrsHttpResponseWriter* w, std::string data); +extern int srs_http_response_json(ISrsHttpResponseWriter* w, std::string data); // state of message enum SrsHttpParseState { diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 43652643d..cf9a3cc34 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -59,7 +59,7 @@ int SrsGoApiRoot::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiApi::SrsGoApiApi() @@ -81,7 +81,7 @@ int SrsGoApiApi::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiV1::SrsGoApiV1() @@ -112,7 +112,7 @@ int SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiVersion::SrsGoApiVersion() @@ -137,7 +137,7 @@ int SrsGoApiVersion::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiSummaries::SrsGoApiSummaries() @@ -152,7 +152,7 @@ int SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) { std::stringstream ss; srs_api_dump_summaries(ss); - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiRusages::SrsGoApiRusages() @@ -193,7 +193,7 @@ int SrsGoApiRusages::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* req) << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiSelfProcStats::SrsGoApiSelfProcStats() @@ -263,7 +263,7 @@ int SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiSystemProcStats::SrsGoApiSystemProcStats() @@ -298,7 +298,7 @@ int SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessag << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiMemInfos::SrsGoApiMemInfos() @@ -334,7 +334,7 @@ int SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiAuthors::SrsGoApiAuthors() @@ -359,7 +359,7 @@ int SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiRequests::SrsGoApiRequests() @@ -420,7 +420,7 @@ int SrsGoApiRequests::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JOBJECT_END << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiVhosts::SrsGoApiVhosts() @@ -445,7 +445,7 @@ int SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JFIELD_ORG("vhosts", data.str()) << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsGoApiStreams::SrsGoApiStreams() @@ -470,7 +470,7 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) << SRS_JFIELD_ORG("streams", data.str()) << SRS_JOBJECT_END; - return srs_go_http_response_json(w, ss.str()); + return srs_http_response_json(w, ss.str()); } SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m) diff --git a/trunk/src/protocol/srs_http_stack.cpp b/trunk/src/protocol/srs_http_stack.cpp new file mode 100644 index 000000000..2cbdb333f --- /dev/null +++ b/trunk/src/protocol/srs_http_stack.cpp @@ -0,0 +1,24 @@ +/* + The MIT License (MIT) + + Copyright (c) 2013-2015 SRS(simple-rtmp-server) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include diff --git a/trunk/src/protocol/srs_http_stack.hpp b/trunk/src/protocol/srs_http_stack.hpp new file mode 100644 index 000000000..d1e147da1 --- /dev/null +++ b/trunk/src/protocol/srs_http_stack.hpp @@ -0,0 +1,32 @@ +/* + The MIT License (MIT) + + Copyright (c) 2013-2015 SRS(simple-rtmp-server) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef SRS_PROTOCOL_HTTP_HPP +#define SRS_PROTOCOL_HTTP_HPP + +/* + #include + */ +#include + +#endif