winlin

for #319, support initialize the parser to whether use jsonp

@@ -1615,68 +1615,66 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj) @@ -1615,68 +1615,66 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj)
1615 SrsStatisticVhost* svhost = stat->find_vhost(dir->arg0()); 1615 SrsStatisticVhost* svhost = stat->find_vhost(dir->arg0());
1616 sobj->set("id", SrsAmf0Any::number(svhost? (double)svhost->id : 0)); 1616 sobj->set("id", SrsAmf0Any::number(svhost? (double)svhost->id : 0));
1617 sobj->set("name", dir->dumps_arg0_to_str()); 1617 sobj->set("name", dir->dumps_arg0_to_str());
  1618 + sobj->set("enabled", SrsAmf0Any::boolean(get_vhost_enabled(dir->arg0())));
1618 1619
1619 - if (get_vhost_enabled(dir->name)) {  
1620 - sobj->set("enabled", SrsAmf0Any::boolean(true));  
1621 - }  
1622 - if (get_dvr_enabled(dir->name)) { 1620 + if (get_dvr_enabled(dir->arg0())) {
1623 sobj->set("dvr", SrsAmf0Any::boolean(true)); 1621 sobj->set("dvr", SrsAmf0Any::boolean(true));
1624 } 1622 }
1625 - if (get_vhost_http_enabled(dir->name)) { 1623 + if (get_vhost_http_enabled(dir->arg0())) {
1626 sobj->set("http_static", SrsAmf0Any::boolean(true)); 1624 sobj->set("http_static", SrsAmf0Any::boolean(true));
1627 } 1625 }
1628 - if (get_vhost_http_remux_enabled(dir->name)) { 1626 + if (get_vhost_http_remux_enabled(dir->arg0())) {
1629 sobj->set("http_remux", SrsAmf0Any::boolean(true)); 1627 sobj->set("http_remux", SrsAmf0Any::boolean(true));
1630 } 1628 }
1631 - if (get_hls_enabled(dir->name)) { 1629 + if (get_hls_enabled(dir->arg0())) {
1632 sobj->set("hls", SrsAmf0Any::boolean(true)); 1630 sobj->set("hls", SrsAmf0Any::boolean(true));
1633 } 1631 }
1634 - if (get_hds_enabled(dir->name)) { 1632 + if (get_hds_enabled(dir->arg0())) {
1635 sobj->set("hds", SrsAmf0Any::boolean(true)); 1633 sobj->set("hds", SrsAmf0Any::boolean(true));
1636 } 1634 }
1637 - if (get_vhost_http_hooks(dir->name)) { 1635 + if (get_vhost_http_hooks(dir->arg0())) {
1638 sobj->set("http_hooks", SrsAmf0Any::boolean(true)); 1636 sobj->set("http_hooks", SrsAmf0Any::boolean(true));
1639 } 1637 }
1640 - if (get_exec_enabled(dir->name)) { 1638 + if (get_exec_enabled(dir->arg0())) {
1641 sobj->set("exec", SrsAmf0Any::boolean(true)); 1639 sobj->set("exec", SrsAmf0Any::boolean(true));
1642 } 1640 }
1643 - if (get_bw_check_enabled(dir->name)) { 1641 + if (get_bw_check_enabled(dir->arg0())) {
1644 sobj->set("bandcheck", SrsAmf0Any::boolean(true)); 1642 sobj->set("bandcheck", SrsAmf0Any::boolean(true));
1645 } 1643 }
1646 - if (!get_vhost_is_edge(dir->name)) { 1644 + if (!get_vhost_is_edge(dir->arg0())) {
1647 sobj->set("origin", SrsAmf0Any::boolean(true)); 1645 sobj->set("origin", SrsAmf0Any::boolean(true));
1648 } 1646 }
1649 - if (get_forward_enabled(dir->name)) { 1647 + if (get_forward_enabled(dir->arg0())) {
1650 sobj->set("forward", SrsAmf0Any::boolean(true)); 1648 sobj->set("forward", SrsAmf0Any::boolean(true));
1651 } 1649 }
1652 1650
1653 - if (get_security_enabled(dir->name)) { 1651 + if (get_security_enabled(dir->arg0())) {
1654 sobj->set("security", SrsAmf0Any::boolean(true)); 1652 sobj->set("security", SrsAmf0Any::boolean(true));
1655 } 1653 }
1656 - if (get_refer_enabled(dir->name)) { 1654 + if (get_refer_enabled(dir->arg0())) {
1657 sobj->set("refer", SrsAmf0Any::boolean(true)); 1655 sobj->set("refer", SrsAmf0Any::boolean(true));
1658 } 1656 }
1659 1657
1660 - if (get_mr_enabled(dir->name)) { 1658 + if (get_mr_enabled(dir->arg0())) {
1661 sobj->set("mr", SrsAmf0Any::boolean(true)); 1659 sobj->set("mr", SrsAmf0Any::boolean(true));
1662 } 1660 }
1663 - if (get_realtime_enabled(dir->name)) { 1661 + if (get_realtime_enabled(dir->arg0())) {
1664 sobj->set("min_latency", SrsAmf0Any::boolean(true)); 1662 sobj->set("min_latency", SrsAmf0Any::boolean(true));
1665 } 1663 }
1666 - if (get_gop_cache(dir->name)) { 1664 + if (get_gop_cache(dir->arg0())) {
1667 sobj->set("gop_cache", SrsAmf0Any::boolean(true)); 1665 sobj->set("gop_cache", SrsAmf0Any::boolean(true));
1668 } 1666 }
1669 - if (get_tcp_nodelay(dir->name)) { 1667 + if (get_tcp_nodelay(dir->arg0())) {
1670 sobj->set("tcp_nodelay", SrsAmf0Any::boolean(true)); 1668 sobj->set("tcp_nodelay", SrsAmf0Any::boolean(true));
1671 } 1669 }
1672 1670
1673 - if (get_mix_correct(dir->name)) { 1671 + if (get_mix_correct(dir->arg0())) {
1674 sobj->set("mix_correct", SrsAmf0Any::boolean(true)); 1672 sobj->set("mix_correct", SrsAmf0Any::boolean(true));
1675 } 1673 }
1676 - if (get_time_jitter(dir->name) != SrsRtmpJitterAlgorithmOFF) { 1674 + if (get_time_jitter(dir->arg0()) != SrsRtmpJitterAlgorithmOFF) {
1677 sobj->set("time_jitter", SrsAmf0Any::boolean(true)); 1675 sobj->set("time_jitter", SrsAmf0Any::boolean(true));
1678 } 1676 }
1679 - if (get_atc(dir->name)) { 1677 + if (get_atc(dir->arg0())) {
1680 sobj->set("atc", SrsAmf0Any::boolean(true)); 1678 sobj->set("atc", SrsAmf0Any::boolean(true));
1681 } 1679 }
1682 1680
@@ -1255,7 +1255,7 @@ int SrsHttpApi::do_cycle() @@ -1255,7 +1255,7 @@ int SrsHttpApi::do_cycle()
1255 srs_trace("api get peer ip success. ip=%s", ip.c_str()); 1255 srs_trace("api get peer ip success. ip=%s", ip.c_str());
1256 1256
1257 // initialize parser 1257 // initialize parser
1258 - if ((ret = parser->initialize(HTTP_REQUEST)) != ERROR_SUCCESS) { 1258 + if ((ret = parser->initialize(HTTP_REQUEST, true)) != ERROR_SUCCESS) {
1259 srs_error("api initialize http parser failed. ret=%d", ret); 1259 srs_error("api initialize http parser failed. ret=%d", ret);
1260 return ret; 1260 return ret;
1261 } 1261 }
@@ -59,7 +59,7 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us) @@ -59,7 +59,7 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us)
59 srs_freep(parser); 59 srs_freep(parser);
60 parser = new SrsHttpParser(); 60 parser = new SrsHttpParser();
61 61
62 - if ((ret = parser->initialize(HTTP_RESPONSE)) != ERROR_SUCCESS) { 62 + if ((ret = parser->initialize(HTTP_RESPONSE, false)) != ERROR_SUCCESS) {
63 srs_error("initialize parser failed. ret=%d", ret); 63 srs_error("initialize parser failed. ret=%d", ret);
64 return ret; 64 return ret;
65 } 65 }
@@ -504,7 +504,7 @@ SrsHttpMessage::~SrsHttpMessage() @@ -504,7 +504,7 @@ SrsHttpMessage::~SrsHttpMessage()
504 srs_freep(_http_ts_send_buffer); 504 srs_freep(_http_ts_send_buffer);
505 } 505 }
506 506
507 -int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body, vector<SrsHttpHeaderField>& headers) 507 +int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, SrsFastBuffer* body, vector<SrsHttpHeaderField>& headers)
508 { 508 {
509 int ret = ERROR_SUCCESS; 509 int ret = ERROR_SUCCESS;
510 510
@@ -572,12 +572,14 @@ int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body, @@ -572,12 +572,14 @@ int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body,
572 } 572 }
573 573
574 // parse jsonp request message. 574 // parse jsonp request message.
  575 + if (allow_jsonp) {
575 if (!query_get("callback").empty()) { 576 if (!query_get("callback").empty()) {
576 jsonp = true; 577 jsonp = true;
577 } 578 }
578 if (jsonp) { 579 if (jsonp) {
579 jsonp_method = query_get("method"); 580 jsonp_method = query_get("method");
580 } 581 }
  582 + }
581 583
582 return ret; 584 return ret;
583 } 585 }
@@ -843,10 +845,12 @@ SrsHttpParser::~SrsHttpParser() @@ -843,10 +845,12 @@ SrsHttpParser::~SrsHttpParser()
843 srs_freep(buffer); 845 srs_freep(buffer);
844 } 846 }
845 847
846 -int SrsHttpParser::initialize(enum http_parser_type type) 848 +int SrsHttpParser::initialize(enum http_parser_type type, bool allow_jsonp)
847 { 849 {
848 int ret = ERROR_SUCCESS; 850 int ret = ERROR_SUCCESS;
849 851
  852 + jsonp = allow_jsonp;
  853 +
850 memset(&settings, 0, sizeof(settings)); 854 memset(&settings, 0, sizeof(settings));
851 settings.on_message_begin = on_message_begin; 855 settings.on_message_begin = on_message_begin;
852 settings.on_url = on_url; 856 settings.on_url = on_url;
@@ -891,7 +895,7 @@ int SrsHttpParser::parse_message(SrsStSocket* skt, SrsConnection* conn, ISrsHttp @@ -891,7 +895,7 @@ int SrsHttpParser::parse_message(SrsStSocket* skt, SrsConnection* conn, ISrsHttp
891 SrsHttpMessage* msg = new SrsHttpMessage(skt, conn); 895 SrsHttpMessage* msg = new SrsHttpMessage(skt, conn);
892 896
893 // initalize http msg, parse url. 897 // initalize http msg, parse url.
894 - if ((ret = msg->update(url, &header, buffer, headers)) != ERROR_SUCCESS) { 898 + if ((ret = msg->update(url, jsonp, &header, buffer, headers)) != ERROR_SUCCESS) {
895 srs_error("initialize http msg failed. ret=%d", ret); 899 srs_error("initialize http msg failed. ret=%d", ret);
896 srs_freep(msg); 900 srs_freep(msg);
897 return ret; 901 return ret;
@@ -1191,7 +1195,7 @@ int SrsHttpConn::do_cycle() @@ -1191,7 +1195,7 @@ int SrsHttpConn::do_cycle()
1191 srs_trace("HTTP client ip=%s", ip.c_str()); 1195 srs_trace("HTTP client ip=%s", ip.c_str());
1192 1196
1193 // initialize parser 1197 // initialize parser
1194 - if ((ret = parser->initialize(HTTP_REQUEST)) != ERROR_SUCCESS) { 1198 + if ((ret = parser->initialize(HTTP_REQUEST, false)) != ERROR_SUCCESS) {
1195 srs_error("http initialize http parser failed. ret=%d", ret); 1199 srs_error("http initialize http parser failed. ret=%d", ret);
1196 return ret; 1200 return ret;
1197 } 1201 }
@@ -214,7 +214,7 @@ public: @@ -214,7 +214,7 @@ public:
214 /** 214 /**
215 * set the original messages, then update the message. 215 * set the original messages, then update the message.
216 */ 216 */
217 - virtual int update(std::string url, http_parser* header, 217 + virtual int update(std::string url, bool allow_jsonp, http_parser* header,
218 SrsFastBuffer* body, std::vector<SrsHttpHeaderField>& headers 218 SrsFastBuffer* body, std::vector<SrsHttpHeaderField>& headers
219 ); 219 );
220 public: 220 public:
@@ -304,6 +304,8 @@ private: @@ -304,6 +304,8 @@ private:
304 http_parser parser; 304 http_parser parser;
305 // the global parse buffer. 305 // the global parse buffer.
306 SrsFastBuffer* buffer; 306 SrsFastBuffer* buffer;
  307 + // whether allow jsonp parse.
  308 + bool jsonp;
307 private: 309 private:
308 // http parse data, reset before parse message. 310 // http parse data, reset before parse message.
309 bool expect_field_name; 311 bool expect_field_name;
@@ -321,8 +323,9 @@ public: @@ -321,8 +323,9 @@ public:
321 /** 323 /**
322 * initialize the http parser with specified type, 324 * initialize the http parser with specified type,
323 * one parser can only parse request or response messages. 325 * one parser can only parse request or response messages.
  326 + * @param allow_jsonp whether allow jsonp parser, which indicates the method in query string.
324 */ 327 */
325 - virtual int initialize(enum http_parser_type type); 328 + virtual int initialize(enum http_parser_type type, bool allow_jsonp);
326 /** 329 /**
327 * always parse a http message, 330 * always parse a http message,
328 * that is, the *ppmsg always NOT-NULL when return success. 331 * that is, the *ppmsg always NOT-NULL when return success.