winlin

refine the api, response the error code and data.

@@ -152,8 +152,8 @@ int SrsApiV1::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) @@ -152,8 +152,8 @@ int SrsApiV1::do_process_request(SrsStSocket* skt, SrsHttpMessage* req)
152 << __SRS_JFIELD_STR("meminfos", "the meminfo of system") << __SRS_JFIELD_CONT 152 << __SRS_JFIELD_STR("meminfos", "the meminfo of system") << __SRS_JFIELD_CONT
153 << __SRS_JFIELD_STR("authors", "the primary authors and contributors") << __SRS_JFIELD_CONT 153 << __SRS_JFIELD_STR("authors", "the primary authors and contributors") << __SRS_JFIELD_CONT
154 << __SRS_JFIELD_STR("requests", "the request itself, for http debug") << __SRS_JFIELD_CONT 154 << __SRS_JFIELD_STR("requests", "the request itself, for http debug") << __SRS_JFIELD_CONT
155 - << __SRS_JFIELD_STR("vhosts", "list all vhosts") << __SRS_JFIELD_CONT  
156 - << __SRS_JFIELD_STR("streams", "list streams that match the name or vhost") 155 + << __SRS_JFIELD_STR("vhosts", "dumps vhost to json") << __SRS_JFIELD_CONT
  156 + << __SRS_JFIELD_STR("streams", "dumps streams to json")
157 << __SRS_JOBJECT_END 157 << __SRS_JOBJECT_END
158 << __SRS_JOBJECT_END; 158 << __SRS_JOBJECT_END;
159 159
@@ -521,14 +521,18 @@ bool SrsApiVhosts::can_handle(const char* path, int length, const char** /*pchil @@ -521,14 +521,18 @@ bool SrsApiVhosts::can_handle(const char* path, int length, const char** /*pchil
521 521
522 int SrsApiVhosts::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) 522 int SrsApiVhosts::do_process_request(SrsStSocket* skt, SrsHttpMessage* req)
523 { 523 {
524 - int ret = ERROR_SUCCESS; 524 + std::stringstream data;
  525 + SrsStatistic* stat = SrsStatistic::instance();
  526 + int ret = stat->dumps_vhosts(data);
525 527
526 std::stringstream ss; 528 std::stringstream ss;
527 529
528 - SrsStatistic* stat = SrsStatistic::instance();  
529 - if ((ret = stat->dumps_vhosts(ss)) != ERROR_SUCCESS) {  
530 - return ret;  
531 - } 530 + ss << __SRS_JOBJECT_START
  531 + << __SRS_JFIELD_ERROR(ret) << __SRS_JFIELD_CONT
  532 + << __SRS_JFIELD_ORG("vhosts", __SRS_JARRAY_START)
  533 + << data.str()
  534 + << __SRS_JARRAY_END
  535 + << __SRS_JOBJECT_END;
532 536
533 return res_json(skt, req, ss.str()); 537 return res_json(skt, req, ss.str());
534 } 538 }
@@ -548,14 +552,18 @@ bool SrsApiStreams::can_handle(const char* path, int length, const char** /*pchi @@ -548,14 +552,18 @@ bool SrsApiStreams::can_handle(const char* path, int length, const char** /*pchi
548 552
549 int SrsApiStreams::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) 553 int SrsApiStreams::do_process_request(SrsStSocket* skt, SrsHttpMessage* req)
550 { 554 {
551 - int ret = ERROR_SUCCESS; 555 + std::stringstream data;
  556 + SrsStatistic* stat = SrsStatistic::instance();
  557 + int ret = stat->dumps_streams(data);
552 558
553 std::stringstream ss; 559 std::stringstream ss;
554 560
555 - SrsStatistic* stat = SrsStatistic::instance();  
556 - if ((ret = stat->dumps_streams(ss)) != ERROR_SUCCESS) {  
557 - return ret;  
558 - } 561 + ss << __SRS_JOBJECT_START
  562 + << __SRS_JFIELD_ERROR(ret) << __SRS_JFIELD_CONT
  563 + << __SRS_JFIELD_ORG("streams", __SRS_JARRAY_START)
  564 + << data.str()
  565 + << __SRS_JARRAY_END
  566 + << __SRS_JOBJECT_END;
559 567
560 return res_json(skt, req, ss.str()); 568 return res_json(skt, req, ss.str());
561 } 569 }