Skip to content

Commit

Permalink
for #319, support initialize the parser to whether use jsonp
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 12, 2015
1 parent 491ec11 commit 01308ec
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
42 changes: 20 additions & 22 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 13 additions & 9 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class SrsHttpMessage : public ISrsHttpMessage
/**
* 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:
Expand Down Expand Up @@ -304,6 +304,8 @@ class SrsHttpParser
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;
Expand All @@ -321,8 +323,9 @@ class SrsHttpParser
/**
* 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.
Expand Down

0 comments on commit 01308ec

Please sign in to comment.