winlin

add http library, support in build script

@@ -25,23 +25,25 @@ if [ ! -f ${SRS_OBJS}/st-1.9/obj/libst.so ]; then echo "build st-1.9 failed."; e @@ -25,23 +25,25 @@ if [ ! -f ${SRS_OBJS}/st-1.9/obj/libst.so ]; then echo "build st-1.9 failed."; e
25 ##################################################################################### 25 #####################################################################################
26 # http-parser-2.1 26 # http-parser-2.1
27 ##################################################################################### 27 #####################################################################################
28 -if [[ -f ${SRS_OBJS}/http-parser-2.1/http_parser.h && -f ${SRS_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then  
29 - echo "http-parser-2.1 is ok.";  
30 -else  
31 - echo "build http-parser-2.1";  
32 - (  
33 - rm -rf ${SRS_OBJS}/http-parser-2.1 && cd ${SRS_OBJS} && unzip -q ../3rdparty/http-parser-2.1.zip &&  
34 - cd http-parser-2.1 &&  
35 - sed -i "s/CPPFLAGS_FAST +=.*$/CPPFLAGS_FAST = \$\(CPPFLAGS_DEBUG\)/g" Makefile &&  
36 - sed -i "s/CFLAGS_FAST =.*$/CFLAGS_FAST = \$\(CFLAGS_DEBUG\)/g" Makefile &&  
37 - make package &&  
38 - cd .. && rm -f hp && ln -sf http-parser-2.1 hp  
39 - ) 28 +if [ $SRS_HTTP = YES ]; then
  29 + if [[ -f ${SRS_OBJS}/http-parser-2.1/http_parser.h && -f ${SRS_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then
  30 + echo "http-parser-2.1 is ok.";
  31 + else
  32 + echo "build http-parser-2.1";
  33 + (
  34 + rm -rf ${SRS_OBJS}/http-parser-2.1 && cd ${SRS_OBJS} && unzip -q ../3rdparty/http-parser-2.1.zip &&
  35 + cd http-parser-2.1 &&
  36 + sed -i "s/CPPFLAGS_FAST +=.*$/CPPFLAGS_FAST = \$\(CPPFLAGS_DEBUG\)/g" Makefile &&
  37 + sed -i "s/CFLAGS_FAST =.*$/CFLAGS_FAST = \$\(CFLAGS_DEBUG\)/g" Makefile &&
  38 + make package &&
  39 + cd .. && rm -f hp && ln -sf http-parser-2.1 hp
  40 + )
  41 + fi
  42 + # check status
  43 + ret=$?; if [[ $ret -ne 0 ]]; then echo "build http-parser-2.1 failed, ret=$ret"; exit $ret; fi
  44 + if [[ ! -f ${SRS_OBJS}/http-parser-2.1/http_parser.h ]]; then echo "build http-parser-2.1 failed"; exit -1; fi
  45 + if [[ ! -f ${SRS_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then echo "build http-parser-2.1 failed"; exit -1; fi
40 fi 46 fi
41 -# check status  
42 -ret=$?; if [[ $ret -ne 0 ]]; then echo "build http-parser-2.1 failed, ret=$ret"; exit $ret; fi  
43 -if [[ ! -f ${SRS_OBJS}/http-parser-2.1/http_parser.h ]]; then echo "build http-parser-2.1 failed"; exit -1; fi  
44 -if [[ ! -f ${SRS_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then echo "build http-parser-2.1 failed"; exit -1; fi  
45 47
46 ##################################################################################### 48 #####################################################################################
47 # nginx for HLS, nginx-1.5.0 49 # nginx for HLS, nginx-1.5.0
@@ -95,13 +95,18 @@ END @@ -95,13 +95,18 @@ END
95 # Libraries 95 # Libraries
96 LibSTRoot="${SRS_OBJS}/st" 96 LibSTRoot="${SRS_OBJS}/st"
97 LibSTfile="${LibSTRoot}/libst.a" 97 LibSTfile="${LibSTRoot}/libst.a"
98 -LibHttpParserRoot="${SRS_OBJS}/hp"  
99 -LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a" 98 +if [ $SRS_HTTP = YES ]; then
  99 + LibHttpParserRoot="${SRS_OBJS}/hp"
  100 + LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a"
  101 +fi
100 102
101 #Core Module 103 #Core Module
102 MODULE_ID="CORE" 104 MODULE_ID="CORE"
103 MODULE_DEPENDS=() 105 MODULE_DEPENDS=()
104 -ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) 106 +ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS})
  107 +if [ $SRS_HTTP = YES ]; then
  108 + ModuleLibIncs="${ModuleLibIncs[@]} ${LibHttpParserRoot}"
  109 +fi
105 MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" 110 MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server"
106 "srs_core_error" "srs_core_conn" "srs_core_client" 111 "srs_core_error" "srs_core_conn" "srs_core_client"
107 "srs_core_rtmp" "srs_core_socket" "srs_core_buffer" 112 "srs_core_rtmp" "srs_core_socket" "srs_core_buffer"
@@ -109,7 +114,8 @@ MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" @@ -109,7 +114,8 @@ MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server"
109 "srs_core_stream" "srs_core_source" "srs_core_codec" 114 "srs_core_stream" "srs_core_source" "srs_core_codec"
110 "srs_core_handshake" "srs_core_pithy_print" 115 "srs_core_handshake" "srs_core_pithy_print"
111 "srs_core_config" "srs_core_refer" "srs_core_reload" 116 "srs_core_config" "srs_core_refer" "srs_core_reload"
112 - "srs_core_hls" "srs_core_forward" "srs_core_encoder") 117 + "srs_core_hls" "srs_core_forward" "srs_core_encoder"
  118 + "srs_core_http")
113 MODULE_DIR="src/core" . auto/modules.sh 119 MODULE_DIR="src/core" . auto/modules.sh
114 CORE_OBJS="${MODULE_OBJS[@]}" 120 CORE_OBJS="${MODULE_OBJS[@]}"
115 121
@@ -125,7 +131,10 @@ MAIN_OBJS="${MODULE_OBJS[@].o}" @@ -125,7 +131,10 @@ MAIN_OBJS="${MODULE_OBJS[@].o}"
125 MAIN_ENTRANCES=("srs_main_server") 131 MAIN_ENTRANCES=("srs_main_server")
126 132
127 # srs(simple rtmp server) over st(state-threads) 133 # srs(simple rtmp server) over st(state-threads)
128 -ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile}) 134 +ModuleLibFiles=(${LibSTfile})
  135 +if [ $SRS_HTTP = YES ]; then
  136 + ModuleLibFiles="${ModuleLibFiles[@]} ${LibHttpParserfile}"
  137 +fi
129 MODULE_OBJS="${CORE_OBJS[@]} ${CONFIG_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}" 138 MODULE_OBJS="${CORE_OBJS[@]} ${CONFIG_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}"
130 if [ $SRS_SSL = YES ]; then 139 if [ $SRS_SSL = YES ]; then
131 LINK_OPTIONS="-ldl -lssl -lcrypto" 140 LINK_OPTIONS="-ldl -lssl -lcrypto"
1 -/*  
2 -The MIT License (MIT)  
3 -  
4 -Copyright (c) 2013 winlin  
5 -  
6 -Permission is hereby granted, free of charge, to any person obtaining a copy of  
7 -this software and associated documentation files (the "Software"), to deal in  
8 -the Software without restriction, including without limitation the rights to  
9 -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of  
10 -the Software, and to permit persons to whom the Software is furnished to do so,  
11 -subject to the following conditions:  
12 -  
13 -The above copyright notice and this permission notice shall be included in all  
14 -copies or substantial portions of the Software.  
15 -  
16 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
17 -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS  
18 -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR  
19 -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER  
20 -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN  
21 -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
22 -*/  
23 -  
24 -#include <srs_core.hpp>  
25 -  
26 -#include <sys/time.h>  
27 -#include <netdb.h>  
28 -#include <arpa/inet.h>  
29 -  
30 -#include <srs_core_log.hpp>  
31 -  
32 -static int64_t _srs_system_time_us_cache = 0;  
33 -  
34 -int64_t srs_get_system_time_ms()  
35 -{  
36 - return _srs_system_time_us_cache / 1000;  
37 -}  
38 -  
39 -void srs_update_system_time_ms()  
40 -{  
41 - timeval now;  
42 -  
43 - gettimeofday(&now, NULL);  
44 -  
45 - // we must convert the tv_sec/tv_usec to int64_t.  
46 - _srs_system_time_us_cache = now.tv_sec * 1000 * 1000 + now.tv_usec;  
47 -  
48 - _srs_system_time_us_cache = srs_max(0, _srs_system_time_us_cache);  
49 -}  
50 -  
51 -std::string srs_replace(std::string str, std::string old_str, std::string new_str)  
52 -{  
53 - std::string ret = str;  
54 -  
55 - if (old_str == new_str) {  
56 - return ret;  
57 - }  
58 -  
59 - size_t pos = 0;  
60 - while ((pos = ret.find(old_str, pos)) != std::string::npos) {  
61 - ret = ret.replace(pos, old_str.length(), new_str);  
62 - pos += new_str.length();  
63 - }  
64 -  
65 - return ret;  
66 -}  
67 -  
68 -std::string srs_dns_resolve(std::string host)  
69 -{  
70 - if (inet_addr(host.c_str()) != INADDR_NONE) {  
71 - return host;  
72 - }  
73 -  
74 - hostent* answer = gethostbyname(host.c_str());  
75 - if (answer == NULL) {  
76 - srs_error("dns resolve host %s error.", host.c_str());  
77 - return "";  
78 - }  
79 -  
80 - char ipv4[16];  
81 - memset(ipv4, 0, sizeof(ipv4));  
82 - for (int i = 0; i < answer->h_length; i++) {  
83 - inet_ntop(AF_INET, answer->h_addr_list[i], ipv4, sizeof(ipv4));  
84 - srs_info("dns resolve host %s to %s.", host.c_str(), ipv4);  
85 - break;  
86 - }  
87 -  
88 - return ipv4;  
89 -}  
90 -  
91 -void srs_vhost_resolve(std::string& vhost, std::string& app)  
92 -{  
93 - app = srs_replace(app, "...", "?");  
94 -  
95 - size_t pos = 0;  
96 - if ((pos = app.find("?")) == std::string::npos) {  
97 - return;  
98 - }  
99 -  
100 - std::string query = app.substr(pos + 1);  
101 - app = app.substr(0, pos);  
102 -  
103 - if ((pos = query.find("vhost?")) != std::string::npos  
104 - || (pos = query.find("vhost=")) != std::string::npos  
105 - || (pos = query.find("Vhost?")) != std::string::npos  
106 - || (pos = query.find("Vhost=")) != std::string::npos  
107 - ) {  
108 - query = query.substr(pos + 6);  
109 - if (!query.empty()) {  
110 - vhost = query;  
111 - }  
112 - }  
113 -} 1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_core.hpp>
  25 +
  26 +#include <sys/time.h>
  27 +#include <netdb.h>
  28 +#include <arpa/inet.h>
  29 +
  30 +#include <srs_core_log.hpp>
  31 +
  32 +static int64_t _srs_system_time_us_cache = 0;
  33 +
  34 +int64_t srs_get_system_time_ms()
  35 +{
  36 + return _srs_system_time_us_cache / 1000;
  37 +}
  38 +
  39 +void srs_update_system_time_ms()
  40 +{
  41 + timeval now;
  42 +
  43 + gettimeofday(&now, NULL);
  44 +
  45 + // we must convert the tv_sec/tv_usec to int64_t.
  46 + _srs_system_time_us_cache = now.tv_sec * 1000 * 1000 + now.tv_usec;
  47 +
  48 + _srs_system_time_us_cache = srs_max(0, _srs_system_time_us_cache);
  49 +}
  50 +
  51 +std::string srs_replace(std::string str, std::string old_str, std::string new_str)
  52 +{
  53 + std::string ret = str;
  54 +
  55 + if (old_str == new_str) {
  56 + return ret;
  57 + }
  58 +
  59 + size_t pos = 0;
  60 + while ((pos = ret.find(old_str, pos)) != std::string::npos) {
  61 + ret = ret.replace(pos, old_str.length(), new_str);
  62 + pos += new_str.length();
  63 + }
  64 +
  65 + return ret;
  66 +}
  67 +
  68 +std::string srs_dns_resolve(std::string host)
  69 +{
  70 + if (inet_addr(host.c_str()) != INADDR_NONE) {
  71 + return host;
  72 + }
  73 +
  74 + hostent* answer = gethostbyname(host.c_str());
  75 + if (answer == NULL) {
  76 + srs_error("dns resolve host %s error.", host.c_str());
  77 + return "";
  78 + }
  79 +
  80 + char ipv4[16];
  81 + memset(ipv4, 0, sizeof(ipv4));
  82 + for (int i = 0; i < answer->h_length; i++) {
  83 + inet_ntop(AF_INET, answer->h_addr_list[i], ipv4, sizeof(ipv4));
  84 + srs_info("dns resolve host %s to %s.", host.c_str(), ipv4);
  85 + break;
  86 + }
  87 +
  88 + return ipv4;
  89 +}
  90 +
  91 +void srs_vhost_resolve(std::string& vhost, std::string& app)
  92 +{
  93 + app = srs_replace(app, "...", "?");
  94 +
  95 + size_t pos = 0;
  96 + if ((pos = app.find("?")) == std::string::npos) {
  97 + return;
  98 + }
  99 +
  100 + std::string query = app.substr(pos + 1);
  101 + app = app.substr(0, pos);
  102 +
  103 + if ((pos = query.find("vhost?")) != std::string::npos
  104 + || (pos = query.find("vhost=")) != std::string::npos
  105 + || (pos = query.find("Vhost?")) != std::string::npos
  106 + || (pos = query.find("Vhost=")) != std::string::npos
  107 + ) {
  108 + query = query.substr(pos + 6);
  109 + if (!query.empty()) {
  110 + vhost = query;
  111 + }
  112 + }
  113 +}
@@ -242,6 +242,15 @@ int SrsClient::check_vhost() @@ -242,6 +242,15 @@ int SrsClient::check_vhost()
242 req->vhost = vhost->arg0(); 242 req->vhost = vhost->arg0();
243 } 243 }
244 244
  245 +#ifdef SRS_HTTP
  246 + // HTTP: on_connect
  247 + std::string on_connect = config->get_vhost_on_connect(req->vhost);
  248 + if (on_connect.empty()) {
  249 + srs_info("ignore the empty http callback: on_connect");
  250 + return ret;
  251 + }
  252 +#endif
  253 +
245 return ret; 254 return ret;
246 } 255 }
247 256
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_core_http.hpp>
  25 +
  26 +#ifdef SRS_HTTP
  27 +#endif
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_CORE_HTTP_HPP
  25 +#define SRS_CORE_HTTP_HPP
  26 +
  27 +/*
  28 +#include <srs_core_http.hpp>
  29 +*/
  30 +#include <srs_core.hpp>
  31 +
  32 +#ifdef SRS_HTTP
  33 +#endif
  34 +
  35 +#endif
@@ -22,6 +22,8 @@ file @@ -22,6 +22,8 @@ file
22 ..\core\srs_core_conn.cpp, 22 ..\core\srs_core_conn.cpp,
23 ..\core\srs_core_client.hpp, 23 ..\core\srs_core_client.hpp,
24 ..\core\srs_core_client.cpp, 24 ..\core\srs_core_client.cpp,
  25 + ..\core\srs_core_http.hpp,
  26 + ..\core\srs_core_http.cpp,
25 ..\core\srs_core_source.hpp, 27 ..\core\srs_core_source.hpp,
26 ..\core\srs_core_source.cpp, 28 ..\core\srs_core_source.cpp,
27 ..\core\srs_core_forward.hpp, 29 ..\core\srs_core_forward.hpp,