1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

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

This commit is contained in:
winlin 2015-09-12 22:22:33 +08:00
parent 491ec11833
commit 01308ecc98
5 changed files with 40 additions and 35 deletions

View file

@ -1615,68 +1615,66 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj)
SrsStatisticVhost* svhost = stat->find_vhost(dir->arg0());
sobj->set("id", SrsAmf0Any::number(svhost? (double)svhost->id : 0));
sobj->set("name", dir->dumps_arg0_to_str());
sobj->set("enabled", SrsAmf0Any::boolean(get_vhost_enabled(dir->arg0())));
if (get_vhost_enabled(dir->name)) {
sobj->set("enabled", SrsAmf0Any::boolean(true));
}
if (get_dvr_enabled(dir->name)) {
if (get_dvr_enabled(dir->arg0())) {
sobj->set("dvr", SrsAmf0Any::boolean(true));
}
if (get_vhost_http_enabled(dir->name)) {
if (get_vhost_http_enabled(dir->arg0())) {
sobj->set("http_static", SrsAmf0Any::boolean(true));
}
if (get_vhost_http_remux_enabled(dir->name)) {
if (get_vhost_http_remux_enabled(dir->arg0())) {
sobj->set("http_remux", SrsAmf0Any::boolean(true));
}
if (get_hls_enabled(dir->name)) {
if (get_hls_enabled(dir->arg0())) {
sobj->set("hls", SrsAmf0Any::boolean(true));
}
if (get_hds_enabled(dir->name)) {
if (get_hds_enabled(dir->arg0())) {
sobj->set("hds", SrsAmf0Any::boolean(true));
}
if (get_vhost_http_hooks(dir->name)) {
if (get_vhost_http_hooks(dir->arg0())) {
sobj->set("http_hooks", SrsAmf0Any::boolean(true));
}
if (get_exec_enabled(dir->name)) {
if (get_exec_enabled(dir->arg0())) {
sobj->set("exec", SrsAmf0Any::boolean(true));
}
if (get_bw_check_enabled(dir->name)) {
if (get_bw_check_enabled(dir->arg0())) {
sobj->set("bandcheck", SrsAmf0Any::boolean(true));
}
if (!get_vhost_is_edge(dir->name)) {
if (!get_vhost_is_edge(dir->arg0())) {
sobj->set("origin", SrsAmf0Any::boolean(true));
}
if (get_forward_enabled(dir->name)) {
if (get_forward_enabled(dir->arg0())) {
sobj->set("forward", SrsAmf0Any::boolean(true));
}
if (get_security_enabled(dir->name)) {
if (get_security_enabled(dir->arg0())) {
sobj->set("security", SrsAmf0Any::boolean(true));
}
if (get_refer_enabled(dir->name)) {
if (get_refer_enabled(dir->arg0())) {
sobj->set("refer", SrsAmf0Any::boolean(true));
}
if (get_mr_enabled(dir->name)) {
if (get_mr_enabled(dir->arg0())) {
sobj->set("mr", SrsAmf0Any::boolean(true));
}
if (get_realtime_enabled(dir->name)) {
if (get_realtime_enabled(dir->arg0())) {
sobj->set("min_latency", SrsAmf0Any::boolean(true));
}
if (get_gop_cache(dir->name)) {
if (get_gop_cache(dir->arg0())) {
sobj->set("gop_cache", SrsAmf0Any::boolean(true));
}
if (get_tcp_nodelay(dir->name)) {
if (get_tcp_nodelay(dir->arg0())) {
sobj->set("tcp_nodelay", SrsAmf0Any::boolean(true));
}
if (get_mix_correct(dir->name)) {
if (get_mix_correct(dir->arg0())) {
sobj->set("mix_correct", SrsAmf0Any::boolean(true));
}
if (get_time_jitter(dir->name) != SrsRtmpJitterAlgorithmOFF) {
if (get_time_jitter(dir->arg0()) != SrsRtmpJitterAlgorithmOFF) {
sobj->set("time_jitter", SrsAmf0Any::boolean(true));
}
if (get_atc(dir->name)) {
if (get_atc(dir->arg0())) {
sobj->set("atc", SrsAmf0Any::boolean(true));
}

View file

@ -1255,7 +1255,7 @@ int SrsHttpApi::do_cycle()
srs_trace("api get peer ip success. ip=%s", ip.c_str());
// initialize parser
if ((ret = parser->initialize(HTTP_REQUEST)) != ERROR_SUCCESS) {
if ((ret = parser->initialize(HTTP_REQUEST, true)) != ERROR_SUCCESS) {
srs_error("api initialize http parser failed. ret=%d", ret);
return ret;
}

View file

@ -59,7 +59,7 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us)
srs_freep(parser);
parser = new SrsHttpParser();
if ((ret = parser->initialize(HTTP_RESPONSE)) != ERROR_SUCCESS) {
if ((ret = parser->initialize(HTTP_RESPONSE, false)) != ERROR_SUCCESS) {
srs_error("initialize parser failed. ret=%d", ret);
return ret;
}

View file

@ -504,7 +504,7 @@ SrsHttpMessage::~SrsHttpMessage()
srs_freep(_http_ts_send_buffer);
}
int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body, vector<SrsHttpHeaderField>& headers)
int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, SrsFastBuffer* body, vector<SrsHttpHeaderField>& headers)
{
int ret = ERROR_SUCCESS;
@ -572,11 +572,13 @@ int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body,
}
// parse jsonp request message.
if (!query_get("callback").empty()) {
jsonp = true;
}
if (jsonp) {
jsonp_method = query_get("method");
if (allow_jsonp) {
if (!query_get("callback").empty()) {
jsonp = true;
}
if (jsonp) {
jsonp_method = query_get("method");
}
}
return ret;
@ -843,10 +845,12 @@ SrsHttpParser::~SrsHttpParser()
srs_freep(buffer);
}
int SrsHttpParser::initialize(enum http_parser_type type)
int SrsHttpParser::initialize(enum http_parser_type type, bool allow_jsonp)
{
int ret = ERROR_SUCCESS;
jsonp = allow_jsonp;
memset(&settings, 0, sizeof(settings));
settings.on_message_begin = on_message_begin;
settings.on_url = on_url;
@ -891,7 +895,7 @@ int SrsHttpParser::parse_message(SrsStSocket* skt, SrsConnection* conn, ISrsHttp
SrsHttpMessage* msg = new SrsHttpMessage(skt, conn);
// initalize http msg, parse url.
if ((ret = msg->update(url, &header, buffer, headers)) != ERROR_SUCCESS) {
if ((ret = msg->update(url, jsonp, &header, buffer, headers)) != ERROR_SUCCESS) {
srs_error("initialize http msg failed. ret=%d", ret);
srs_freep(msg);
return ret;
@ -1191,7 +1195,7 @@ int SrsHttpConn::do_cycle()
srs_trace("HTTP client ip=%s", ip.c_str());
// initialize parser
if ((ret = parser->initialize(HTTP_REQUEST)) != ERROR_SUCCESS) {
if ((ret = parser->initialize(HTTP_REQUEST, false)) != ERROR_SUCCESS) {
srs_error("http initialize http parser failed. ret=%d", ret);
return ret;
}

View file

@ -214,7 +214,7 @@ public:
/**
* set the original messages, then update the message.
*/
virtual int update(std::string url, http_parser* header,
virtual int update(std::string url, bool allow_jsonp, http_parser* header,
SrsFastBuffer* body, std::vector<SrsHttpHeaderField>& headers
);
public:
@ -304,6 +304,8 @@ private:
http_parser parser;
// the global parse buffer.
SrsFastBuffer* buffer;
// whether allow jsonp parse.
bool jsonp;
private:
// http parse data, reset before parse message.
bool expect_field_name;
@ -321,8 +323,9 @@ public:
/**
* initialize the http parser with specified type,
* one parser can only parse request or response messages.
* @param allow_jsonp whether allow jsonp parser, which indicates the method in query string.
*/
virtual int initialize(enum http_parser_type type);
virtual int initialize(enum http_parser_type type, bool allow_jsonp);
/**
* always parse a http message,
* that is, the *ppmsg always NOT-NULL when return success.