winlin

support token auth in connect args. 0.9.128

@@ -60,6 +60,8 @@ SRS_ARM_UBUNTU12=NO @@ -60,6 +60,8 @@ SRS_ARM_UBUNTU12=NO
60 SRS_MIPS_UBUNTU12=NO 60 SRS_MIPS_UBUNTU12=NO
61 # dev, open all features for dev, no gperf/prof/arm. 61 # dev, open all features for dev, no gperf/prof/arm.
62 SRS_DEV=NO 62 SRS_DEV=NO
  63 +# dev, open main server feature for dev, no bwtc/utest/research/librtmp
  64 +SRS_FAST_DEV=NO
63 # raspberry-pi, open hls/ssl/static 65 # raspberry-pi, open hls/ssl/static
64 SRS_PI=NO 66 SRS_PI=NO
65 # cubieboard, donot open ffmpeg/nginx. 67 # cubieboard, donot open ffmpeg/nginx.
@@ -151,6 +153,7 @@ Presets: @@ -151,6 +153,7 @@ Presets:
151 --rtmp-hls only support RTMP+HLS with ssl. 153 --rtmp-hls only support RTMP+HLS with ssl.
152 --disable-all disable all features, only support vp6 RTMP. 154 --disable-all disable all features, only support vp6 RTMP.
153 --dev for dev, open all features, no nginx/gperf/gprof/arm. 155 --dev for dev, open all features, no nginx/gperf/gprof/arm.
  156 + --fast-dev for dev fast compile, the RTMP server, without bwtc/librtmp/utest/research.
154 --full enable all features, no gperf/gprof/arm. 157 --full enable all features, no gperf/gprof/arm.
155 158
156 Conflicts: 159 Conflicts:
@@ -232,6 +235,7 @@ function parse_user_option() { @@ -232,6 +235,7 @@ function parse_user_option() {
232 --pi) SRS_PI=YES ;; 235 --pi) SRS_PI=YES ;;
233 --cubie) SRS_CUBIE=YES ;; 236 --cubie) SRS_CUBIE=YES ;;
234 --dev) SRS_DEV=YES ;; 237 --dev) SRS_DEV=YES ;;
  238 + --fast-dev) SRS_FAST_DEV=YES ;;
235 --fast) SRS_FAST=YES ;; 239 --fast) SRS_FAST=YES ;;
236 --disable-all) SRS_DISABLE_ALL=YES ;; 240 --disable-all) SRS_DISABLE_ALL=YES ;;
237 --pure-rtmp) SRS_PURE_RTMP=YES ;; 241 --pure-rtmp) SRS_PURE_RTMP=YES ;;
@@ -282,12 +286,14 @@ function apply_user_presets() { @@ -282,12 +286,14 @@ function apply_user_presets() {
282 if [ $SRS_DISABLE_ALL = NO ]; then 286 if [ $SRS_DISABLE_ALL = NO ]; then
283 if [ $SRS_ENABLE_ALL = NO ]; then 287 if [ $SRS_ENABLE_ALL = NO ]; then
284 if [ $SRS_DEV = NO ]; then 288 if [ $SRS_DEV = NO ]; then
285 - if [ $SRS_ARM_UBUNTU12 = NO ]; then  
286 - if [ $SRS_MIPS_UBUNTU12 = NO ]; then  
287 - if [ $SRS_PI = NO ]; then  
288 - if [ $SRS_CUBIE = NO ]; then  
289 - if [ $SRS_X86_X64 = NO ]; then  
290 - SRS_X86_X64=YES; opt="--x86-x64 $opt"; 289 + if [ $SRS_FAST_DEV = NO ]; then
  290 + if [ $SRS_ARM_UBUNTU12 = NO ]; then
  291 + if [ $SRS_MIPS_UBUNTU12 = NO ]; then
  292 + if [ $SRS_PI = NO ]; then
  293 + if [ $SRS_CUBIE = NO ]; then
  294 + if [ $SRS_X86_X64 = NO ]; then
  295 + SRS_X86_X64=YES; opt="--x86-x64 $opt";
  296 + fi
291 fi 297 fi
292 fi 298 fi
293 fi 299 fi
@@ -534,6 +540,31 @@ function apply_user_presets() { @@ -534,6 +540,31 @@ function apply_user_presets() {
534 SRS_STATIC=NO 540 SRS_STATIC=NO
535 fi 541 fi
536 542
  543 + # if fast dev specified, open main server features.
  544 + if [ $SRS_FAST_DEV = YES ]; then
  545 + SRS_HLS=YES
  546 + SRS_DVR=YES
  547 + SRS_NGINX=NO
  548 + SRS_SSL=YES
  549 + SRS_FFMPEG_TOOL=NO
  550 + SRS_TRANSCODE=YES
  551 + SRS_INGEST=YES
  552 + SRS_HTTP_PARSER=YES
  553 + SRS_HTTP_CALLBACK=YES
  554 + SRS_HTTP_SERVER=YES
  555 + SRS_HTTP_API=YES
  556 + SRS_LIBRTMP=NO
  557 + SRS_BWTC=NO
  558 + SRS_RESEARCH=NO
  559 + SRS_UTEST=NO
  560 + SRS_GPERF=NO
  561 + SRS_GPERF_MC=NO
  562 + SRS_GPERF_MP=NO
  563 + SRS_GPERF_CP=NO
  564 + SRS_GPROF=NO
  565 + SRS_STATIC=NO
  566 + fi
  567 +
537 # if raspberry-pi specified, open ssl/hls/static features 568 # if raspberry-pi specified, open ssl/hls/static features
538 if [ $SRS_PI = YES ]; then 569 if [ $SRS_PI = YES ]; then
539 SRS_HLS=YES 570 SRS_HLS=YES
@@ -182,6 +182,12 @@ ok_msg "test \" ${item} \"" @@ -182,6 +182,12 @@ ok_msg "test \" ${item} \""
182 ret=$?; if [[ $ret -ne 0 ]]; then failed_msg "test \" ${item} \" failed. ret=$ret"; exit $ret; fi 182 ret=$?; if [[ $ret -ne 0 ]]; then failed_msg "test \" ${item} \" failed. ret=$ret"; exit $ret; fi
183 ok_msg "test \" ${item} \" success" 183 ok_msg "test \" ${item} \" success"
184 184
  185 +item="./configure --fast-dev"
  186 +ok_msg "test \" ${item} \""
  187 +(./configure --dev && make) >>$log 2>&1
  188 +ret=$?; if [[ $ret -ne 0 ]]; then failed_msg "test \" ${item} \" failed. ret=$ret"; exit $ret; fi
  189 +ok_msg "test \" ${item} \" success"
  190 +
185 item="./configure --full" 191 item="./configure --full"
186 ok_msg "test \" ${item} \"" 192 ok_msg "test \" ${item} \""
187 (./configure --dev && make) >>$log 2>&1 193 (./configure --dev && make) >>$log 2>&1
@@ -129,7 +129,7 @@ int SrsEdgeIngester::cycle() @@ -129,7 +129,7 @@ int SrsEdgeIngester::cycle()
129 srs_error("handshake with server failed. ret=%d", ret); 129 srs_error("handshake with server failed. ret=%d", ret);
130 return ret; 130 return ret;
131 } 131 }
132 - if ((ret = client->connect_app(req->app, req->tcUrl)) != ERROR_SUCCESS) { 132 + if ((ret = client->connect_app(req->app, req->tcUrl, req)) != ERROR_SUCCESS) {
133 srs_error("connect with server failed, tcUrl=%s. ret=%d", req->tcUrl.c_str(), ret); 133 srs_error("connect with server failed, tcUrl=%s. ret=%d", req->tcUrl.c_str(), ret);
134 return ret; 134 return ret;
135 } 135 }
@@ -165,6 +165,11 @@ public: @@ -165,6 +165,11 @@ public:
165 SrsPlayEdge(); 165 SrsPlayEdge();
166 virtual ~SrsPlayEdge(); 166 virtual ~SrsPlayEdge();
167 public: 167 public:
  168 + /**
  169 + * always use the req of source,
  170 + * for we assume all client to edge is invalid,
  171 + * if auth open, edge must valid it from origin, then service it.
  172 + */
168 virtual int initialize(SrsSource* source, SrsRequest* req); 173 virtual int initialize(SrsSource* source, SrsRequest* req);
169 /** 174 /**
170 * when client play stream on edge. 175 * when client play stream on edge.
@@ -146,10 +146,10 @@ int SrsRtmpConn::do_cycle() @@ -146,10 +146,10 @@ int SrsRtmpConn::do_cycle()
146 srs_verbose("check vhost success."); 146 srs_verbose("check vhost success.");
147 147
148 srs_trace("connect app, " 148 srs_trace("connect app, "
149 - "tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s", 149 + "tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, args=%s",
150 req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(), 150 req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),
151 req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), 151 req->schema.c_str(), req->vhost.c_str(), req->port.c_str(),
152 - req->app.c_str()); 152 + req->app.c_str(), (req->args? "(obj)":"null"));
153 153
154 ret = service_cycle(); 154 ret = service_cycle();
155 http_hooks_on_close(); 155 http_hooks_on_close();
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "127" 34 +#define VERSION_REVISION "128"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -915,94 +915,15 @@ void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value) @@ -915,94 +915,15 @@ void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value)
915 obj->append(any); 915 obj->append(any);
916 } 916 }
917 917
918 -void __srs_fill_level_spaces(stringstream& ss, int level)  
919 -{  
920 - for (int i = 0; i < level; i++) {  
921 - ss << " ";  
922 - }  
923 -}  
924 -void __srs_amf0_do_print(SrsAmf0Any* any, stringstream& ss, int level)  
925 -{  
926 - if (any->is_boolean()) {  
927 - ss << "Boolean " << (any->to_boolean()? "true":"false") << endl;  
928 - } else if (any->is_number()) {  
929 - ss << "Number " << std::fixed << any->to_number() << endl;  
930 - } else if (any->is_string()) {  
931 - ss << "String " << any->to_str() << endl;  
932 - } else if (any->is_null()) {  
933 - ss << "Null" << endl;  
934 - } else if (any->is_ecma_array()) {  
935 - SrsAmf0EcmaArray* obj = any->to_ecma_array();  
936 - ss << "EcmaArray " << "(" << obj->count() << " items)" << endl;  
937 - for (int i = 0; i < obj->count(); i++) {  
938 - __srs_fill_level_spaces(ss, level + 1);  
939 - ss << "Elem '" << obj->key_at(i) << "' ";  
940 - if (obj->value_at(i)->is_complex_object()) {  
941 - __srs_amf0_do_print(obj->value_at(i), ss, level + 1);  
942 - } else {  
943 - __srs_amf0_do_print(obj->value_at(i), ss, 0);  
944 - }  
945 - }  
946 - } else if (any->is_strict_array()) {  
947 - SrsAmf0StrictArray* obj = any->to_strict_array();  
948 - ss << "StrictArray " << "(" << obj->count() << " items)" << endl;  
949 - for (int i = 0; i < obj->count(); i++) {  
950 - __srs_fill_level_spaces(ss, level + 1);  
951 - ss << "Elem ";  
952 - if (obj->at(i)->is_complex_object()) {  
953 - __srs_amf0_do_print(obj->at(i), ss, level + 1);  
954 - } else {  
955 - __srs_amf0_do_print(obj->at(i), ss, 0);  
956 - }  
957 - }  
958 - } else if (any->is_object()) {  
959 - SrsAmf0Object* obj = any->to_object();  
960 - ss << "Object " << "(" << obj->count() << " items)" << endl;  
961 - for (int i = 0; i < obj->count(); i++) {  
962 - __srs_fill_level_spaces(ss, level + 1);  
963 - ss << "Property '" << obj->key_at(i) << "' ";  
964 - if (obj->value_at(i)->is_complex_object()) {  
965 - __srs_amf0_do_print(obj->value_at(i), ss, level + 1);  
966 - } else {  
967 - __srs_amf0_do_print(obj->value_at(i), ss, 0);  
968 - }  
969 - }  
970 - } else {  
971 - ss << "Unknown" << endl;  
972 - }  
973 -}  
974 -  
975 char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize) 918 char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize)
976 { 919 {
977 if (!amf0) { 920 if (!amf0) {
978 return NULL; 921 return NULL;
979 } 922 }
980 923
981 - stringstream ss;  
982 -  
983 - ss.precision(1);  
984 -  
985 SrsAmf0Any* any = (SrsAmf0Any*)amf0; 924 SrsAmf0Any* any = (SrsAmf0Any*)amf0;
986 925
987 - __srs_amf0_do_print(any, ss, 0);  
988 -  
989 - string str = ss.str();  
990 - if (str.empty()) {  
991 - return NULL;  
992 - }  
993 -  
994 - char* data = new char[str.length() + 1];  
995 - memcpy(data, str.data(), str.length());  
996 - data[str.length()] = 0;  
997 -  
998 - if (pdata) {  
999 - *pdata = data;  
1000 - }  
1001 - if (psize) {  
1002 - *psize = str.length();  
1003 - }  
1004 -  
1005 - return data; 926 + return any->human_print(pdata, psize);
1006 } 927 }
1007 928
1008 #ifdef __cplusplus 929 #ifdef __cplusplus
@@ -244,9 +244,9 @@ srs_amf0_t srs_amf0_strict_array_property_at(srs_amf0_t amf0, int index); @@ -244,9 +244,9 @@ srs_amf0_t srs_amf0_strict_array_property_at(srs_amf0_t amf0, int index);
244 void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value); 244 void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value);
245 /** 245 /**
246 * human readable print 246 * human readable print
247 -* @param pdata, output the heap data, 247 +* @param pdata, output the heap data, NULL to ignore.
248 * user must use srs_amf0_free_bytes to free it. 248 * user must use srs_amf0_free_bytes to free it.
249 -* @return return the *pdata for print. 249 +* @return return the *pdata for print. NULL to ignore.
250 */ 250 */
251 char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize); 251 char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize);
252 252
@@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 25
26 #include <utility> 26 #include <utility>
27 #include <vector> 27 #include <vector>
  28 +#include <sstream>
28 using namespace std; 29 using namespace std;
29 30
30 #include <srs_kernel_log.hpp> 31 #include <srs_kernel_log.hpp>
@@ -330,6 +331,90 @@ bool SrsAmf0Any::is_object_eof() @@ -330,6 +331,90 @@ bool SrsAmf0Any::is_object_eof()
330 return marker == RTMP_AMF0_ObjectEnd; 331 return marker == RTMP_AMF0_ObjectEnd;
331 } 332 }
332 333
  334 +void __srs_fill_level_spaces(stringstream& ss, int level)
  335 +{
  336 + for (int i = 0; i < level; i++) {
  337 + ss << " ";
  338 + }
  339 +}
  340 +void __srs_amf0_do_print(SrsAmf0Any* any, stringstream& ss, int level)
  341 +{
  342 + if (any->is_boolean()) {
  343 + ss << "Boolean " << (any->to_boolean()? "true":"false") << endl;
  344 + } else if (any->is_number()) {
  345 + ss << "Number " << std::fixed << any->to_number() << endl;
  346 + } else if (any->is_string()) {
  347 + ss << "String " << any->to_str() << endl;
  348 + } else if (any->is_null()) {
  349 + ss << "Null" << endl;
  350 + } else if (any->is_ecma_array()) {
  351 + SrsAmf0EcmaArray* obj = any->to_ecma_array();
  352 + ss << "EcmaArray " << "(" << obj->count() << " items)" << endl;
  353 + for (int i = 0; i < obj->count(); i++) {
  354 + __srs_fill_level_spaces(ss, level + 1);
  355 + ss << "Elem '" << obj->key_at(i) << "' ";
  356 + if (obj->value_at(i)->is_complex_object()) {
  357 + __srs_amf0_do_print(obj->value_at(i), ss, level + 1);
  358 + } else {
  359 + __srs_amf0_do_print(obj->value_at(i), ss, 0);
  360 + }
  361 + }
  362 + } else if (any->is_strict_array()) {
  363 + SrsAmf0StrictArray* obj = any->to_strict_array();
  364 + ss << "StrictArray " << "(" << obj->count() << " items)" << endl;
  365 + for (int i = 0; i < obj->count(); i++) {
  366 + __srs_fill_level_spaces(ss, level + 1);
  367 + ss << "Elem ";
  368 + if (obj->at(i)->is_complex_object()) {
  369 + __srs_amf0_do_print(obj->at(i), ss, level + 1);
  370 + } else {
  371 + __srs_amf0_do_print(obj->at(i), ss, 0);
  372 + }
  373 + }
  374 + } else if (any->is_object()) {
  375 + SrsAmf0Object* obj = any->to_object();
  376 + ss << "Object " << "(" << obj->count() << " items)" << endl;
  377 + for (int i = 0; i < obj->count(); i++) {
  378 + __srs_fill_level_spaces(ss, level + 1);
  379 + ss << "Property '" << obj->key_at(i) << "' ";
  380 + if (obj->value_at(i)->is_complex_object()) {
  381 + __srs_amf0_do_print(obj->value_at(i), ss, level + 1);
  382 + } else {
  383 + __srs_amf0_do_print(obj->value_at(i), ss, 0);
  384 + }
  385 + }
  386 + } else {
  387 + ss << "Unknown" << endl;
  388 + }
  389 +}
  390 +
  391 +char* SrsAmf0Any::human_print(char** pdata, int* psize)
  392 +{
  393 + stringstream ss;
  394 +
  395 + ss.precision(1);
  396 +
  397 + __srs_amf0_do_print(this, ss, 0);
  398 +
  399 + string str = ss.str();
  400 + if (str.empty()) {
  401 + return NULL;
  402 + }
  403 +
  404 + char* data = new char[str.length() + 1];
  405 + memcpy(data, str.data(), str.length());
  406 + data[str.length()] = 0;
  407 +
  408 + if (pdata) {
  409 + *pdata = data;
  410 + }
  411 + if (psize) {
  412 + *psize = str.length();
  413 + }
  414 +
  415 + return data;
  416 +}
  417 +
333 SrsAmf0Any* SrsAmf0Any::str(const char* value) 418 SrsAmf0Any* SrsAmf0Any::str(const char* value)
334 { 419 {
335 return new __SrsAmf0String(value); 420 return new __SrsAmf0String(value);
@@ -152,6 +152,14 @@ public: @@ -152,6 +152,14 @@ public:
152 virtual int write(SrsStream* stream) = 0; 152 virtual int write(SrsStream* stream) = 0;
153 virtual SrsAmf0Any* copy() = 0; 153 virtual SrsAmf0Any* copy() = 0;
154 public: 154 public:
  155 + /**
  156 + * human readable print
  157 + * @param pdata, output the heap data, NULL to ignore.
  158 + * user must use srs_amf0_free_bytes to free it.
  159 + * @return return the *pdata for print. NULL to ignore.
  160 + */
  161 + virtual char* human_print(char** pdata, int* psize);
  162 +public:
155 static SrsAmf0Any* str(const char* value = NULL); 163 static SrsAmf0Any* str(const char* value = NULL);
156 static SrsAmf0Any* boolean(bool value = false); 164 static SrsAmf0Any* boolean(bool value = false);
157 static SrsAmf0Any* number(double value = 0.0); 165 static SrsAmf0Any* number(double value = 0.0);
@@ -78,10 +78,12 @@ SrsRequest::SrsRequest() @@ -78,10 +78,12 @@ SrsRequest::SrsRequest()
78 { 78 {
79 objectEncoding = RTMP_SIG_AMF0_VER; 79 objectEncoding = RTMP_SIG_AMF0_VER;
80 duration = -1; 80 duration = -1;
  81 + args = NULL;
81 } 82 }
82 83
83 SrsRequest::~SrsRequest() 84 SrsRequest::~SrsRequest()
84 { 85 {
  86 + srs_freep(args);
85 } 87 }
86 88
87 SrsRequest* SrsRequest::copy() 89 SrsRequest* SrsRequest::copy()
@@ -99,6 +101,9 @@ SrsRequest* SrsRequest::copy() @@ -99,6 +101,9 @@ SrsRequest* SrsRequest::copy()
99 cp->tcUrl = tcUrl; 101 cp->tcUrl = tcUrl;
100 cp->vhost = vhost; 102 cp->vhost = vhost;
101 cp->duration = duration; 103 cp->duration = duration;
  104 + if (args) {
  105 + cp->args = args->copy()->to_object();
  106 + }
102 107
103 return cp; 108 return cp;
104 } 109 }
@@ -451,7 +456,7 @@ int SrsRtmpClient::complex_handshake() @@ -451,7 +456,7 @@ int SrsRtmpClient::complex_handshake()
451 return ret; 456 return ret;
452 } 457 }
453 458
454 -int SrsRtmpClient::connect_app(string app, string tc_url) 459 +int SrsRtmpClient::connect_app(string app, string tc_url, SrsRequest* req)
455 { 460 {
456 int ret = ERROR_SUCCESS; 461 int ret = ERROR_SUCCESS;
457 462
@@ -461,16 +466,29 @@ int SrsRtmpClient::connect_app(string app, string tc_url) @@ -461,16 +466,29 @@ int SrsRtmpClient::connect_app(string app, string tc_url)
461 466
462 pkt->command_object->set("app", SrsAmf0Any::str(app.c_str())); 467 pkt->command_object->set("app", SrsAmf0Any::str(app.c_str()));
463 pkt->command_object->set("flashVer", SrsAmf0Any::str("WIN 12,0,0,41")); 468 pkt->command_object->set("flashVer", SrsAmf0Any::str("WIN 12,0,0,41"));
464 - pkt->command_object->set("swfUrl", SrsAmf0Any::str()); 469 + if (req) {
  470 + pkt->command_object->set("swfUrl", SrsAmf0Any::str(req->swfUrl.c_str()));
  471 + } else {
  472 + pkt->command_object->set("swfUrl", SrsAmf0Any::str());
  473 + }
465 pkt->command_object->set("tcUrl", SrsAmf0Any::str(tc_url.c_str())); 474 pkt->command_object->set("tcUrl", SrsAmf0Any::str(tc_url.c_str()));
466 pkt->command_object->set("fpad", SrsAmf0Any::boolean(false)); 475 pkt->command_object->set("fpad", SrsAmf0Any::boolean(false));
467 pkt->command_object->set("capabilities", SrsAmf0Any::number(239)); 476 pkt->command_object->set("capabilities", SrsAmf0Any::number(239));
468 pkt->command_object->set("audioCodecs", SrsAmf0Any::number(3575)); 477 pkt->command_object->set("audioCodecs", SrsAmf0Any::number(3575));
469 pkt->command_object->set("videoCodecs", SrsAmf0Any::number(252)); 478 pkt->command_object->set("videoCodecs", SrsAmf0Any::number(252));
470 pkt->command_object->set("videoFunction", SrsAmf0Any::number(1)); 479 pkt->command_object->set("videoFunction", SrsAmf0Any::number(1));
471 - pkt->command_object->set("pageUrl", SrsAmf0Any::str()); 480 + if (req) {
  481 + pkt->command_object->set("pageUrl", SrsAmf0Any::str(req->pageUrl.c_str()));
  482 + } else {
  483 + pkt->command_object->set("pageUrl", SrsAmf0Any::str());
  484 + }
472 pkt->command_object->set("objectEncoding", SrsAmf0Any::number(0)); 485 pkt->command_object->set("objectEncoding", SrsAmf0Any::number(0));
473 486
  487 + if (req && req->args) {
  488 + srs_freep(pkt->args);
  489 + pkt->args = req->args->copy()->to_object();
  490 + }
  491 +
474 if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { 492 if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) {
475 return ret; 493 return ret;
476 } 494 }
@@ -825,6 +843,12 @@ int SrsRtmpServer::connect_app(SrsRequest* req) @@ -825,6 +843,12 @@ int SrsRtmpServer::connect_app(SrsRequest* req)
825 req->objectEncoding = prop->to_number(); 843 req->objectEncoding = prop->to_number();
826 } 844 }
827 845
  846 + if (pkt->args) {
  847 + srs_freep(req->args);
  848 + req->args = pkt->args->copy()->to_object();
  849 + srs_info("copy edge traverse to origin auth args.");
  850 + }
  851 +
828 srs_info("get connect app message params success."); 852 srs_info("get connect app message params success.");
829 853
830 return req->discovery_app(); 854 return req->discovery_app();
@@ -43,6 +43,7 @@ class SrsOnMetaDataPacket; @@ -43,6 +43,7 @@ class SrsOnMetaDataPacket;
43 class SrsPlayPacket; 43 class SrsPlayPacket;
44 class SrsMessage; 44 class SrsMessage;
45 class SrsPacket; 45 class SrsPacket;
  46 +class SrsAmf0Object;
46 47
47 /** 48 /**
48 * the original request from client. 49 * the original request from client.
@@ -74,6 +75,11 @@ public: @@ -74,6 +75,11 @@ public:
74 // in ms. 75 // in ms.
75 double duration; 76 double duration;
76 77
  78 + // the token in the connect request,
  79 + // used for edge traverse to origin authentication,
  80 + // @see https://github.com/winlinvip/simple-rtmp-server/issues/104
  81 + SrsAmf0Object* args;
  82 +
77 SrsRequest(); 83 SrsRequest();
78 virtual ~SrsRequest(); 84 virtual ~SrsRequest();
79 85
@@ -173,7 +179,10 @@ public: @@ -173,7 +179,10 @@ public:
173 virtual int simple_handshake(); 179 virtual int simple_handshake();
174 // only use complex handshake 180 // only use complex handshake
175 virtual int complex_handshake(); 181 virtual int complex_handshake();
176 - virtual int connect_app(std::string app, std::string tc_url); 182 + // set req to use the original request of client:
  183 + // pageUrl and swfUrl for refer antisuck.
  184 + // args for edge to origin traverse auth, @see SrsRequest.args
  185 + virtual int connect_app(std::string app, std::string tc_url, SrsRequest* req=NULL);
177 virtual int create_stream(int& stream_id); 186 virtual int create_stream(int& stream_id);
178 virtual int play(std::string stream, int stream_id); 187 virtual int play(std::string stream, int stream_id);
179 // flash publish schema: 188 // flash publish schema:
@@ -1749,11 +1749,14 @@ SrsConnectAppPacket::SrsConnectAppPacket() @@ -1749,11 +1749,14 @@ SrsConnectAppPacket::SrsConnectAppPacket()
1749 command_name = RTMP_AMF0_COMMAND_CONNECT; 1749 command_name = RTMP_AMF0_COMMAND_CONNECT;
1750 transaction_id = 1; 1750 transaction_id = 1;
1751 command_object = SrsAmf0Any::object(); 1751 command_object = SrsAmf0Any::object();
  1752 + // optional
  1753 + args = NULL;
1752 } 1754 }
1753 1755
1754 SrsConnectAppPacket::~SrsConnectAppPacket() 1756 SrsConnectAppPacket::~SrsConnectAppPacket()
1755 { 1757 {
1756 srs_freep(command_object); 1758 srs_freep(command_object);
  1759 + srs_freep(args);
1757 } 1760 }
1758 1761
1759 int SrsConnectAppPacket::decode(SrsStream* stream) 1762 int SrsConnectAppPacket::decode(SrsStream* stream)
@@ -1789,6 +1792,15 @@ int SrsConnectAppPacket::decode(SrsStream* stream) @@ -1789,6 +1792,15 @@ int SrsConnectAppPacket::decode(SrsStream* stream)
1789 return ret; 1792 return ret;
1790 } 1793 }
1791 1794
  1795 + if (!stream->empty()) {
  1796 + srs_freep(args);
  1797 + args = SrsAmf0Any::object();
  1798 + if ((ret = args->read(stream)) != ERROR_SUCCESS) {
  1799 + srs_error("amf0 decode connect args failed. ret=%d", ret);
  1800 + return ret;
  1801 + }
  1802 + }
  1803 +
1792 srs_info("amf0 decode connect packet success"); 1804 srs_info("amf0 decode connect packet success");
1793 1805
1794 return ret; 1806 return ret;
@@ -1806,8 +1818,16 @@ int SrsConnectAppPacket::get_message_type() @@ -1806,8 +1818,16 @@ int SrsConnectAppPacket::get_message_type()
1806 1818
1807 int SrsConnectAppPacket::get_size() 1819 int SrsConnectAppPacket::get_size()
1808 { 1820 {
1809 - return SrsAmf0Size::str(command_name) + SrsAmf0Size::number()  
1810 - + SrsAmf0Size::object(command_object); 1821 + int size = 0;
  1822 +
  1823 + size += SrsAmf0Size::str(command_name);
  1824 + size += SrsAmf0Size::number();
  1825 + size += SrsAmf0Size::object(command_object);
  1826 + if (args) {
  1827 + size += SrsAmf0Size::object(args);
  1828 + }
  1829 +
  1830 + return size;
1811 } 1831 }
1812 1832
1813 int SrsConnectAppPacket::encode_packet(SrsStream* stream) 1833 int SrsConnectAppPacket::encode_packet(SrsStream* stream)
@@ -1832,6 +1852,12 @@ int SrsConnectAppPacket::encode_packet(SrsStream* stream) @@ -1832,6 +1852,12 @@ int SrsConnectAppPacket::encode_packet(SrsStream* stream)
1832 } 1852 }
1833 srs_verbose("encode command_object success."); 1853 srs_verbose("encode command_object success.");
1834 1854
  1855 + if (args && (ret = args->write(stream)) != ERROR_SUCCESS) {
  1856 + srs_error("encode args failed. ret=%d", ret);
  1857 + return ret;
  1858 + }
  1859 + srs_verbose("encode args success.");
  1860 +
1835 srs_info("encode connect app request packet success."); 1861 srs_info("encode connect app request packet success.");
1836 1862
1837 return ret; 1863 return ret;
@@ -486,6 +486,11 @@ public: @@ -486,6 +486,11 @@ public:
486 * so, directly use it, never alloc again. 486 * so, directly use it, never alloc again.
487 */ 487 */
488 SrsAmf0Object* command_object; 488 SrsAmf0Object* command_object;
  489 + /**
  490 + * Object
  491 + * Any optional information
  492 + */
  493 + SrsAmf0Object* args;
489 public: 494 public:
490 SrsConnectAppPacket(); 495 SrsConnectAppPacket();
491 virtual ~SrsConnectAppPacket(); 496 virtual ~SrsConnectAppPacket();