winlin

fix #751,#756, refine code

@@ -791,24 +791,6 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -791,24 +791,6 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
791 // e.g. /api/v1/clients/100 pattern= /api/v1/clients/, client_id=100 791 // e.g. /api/v1/clients/100 pattern= /api/v1/clients/, client_id=100
792 int cid = r->parse_rest_id(entry->pattern); 792 int cid = r->parse_rest_id(entry->pattern);
793 793
794 - std::string start = r->query_get("start");  
795 - std::string count = r->query_get("count");  
796 - int cst = 0;  
797 - int cct = 10;  
798 - if(!start.empty()){  
799 - cst = atoi(start.c_str());  
800 - }  
801 - if(!count.empty()){  
802 - cct = atoi(count.c_str());  
803 - }  
804 - if(cst<0){  
805 - cst = 0;  
806 - }  
807 - if(cct<=0){  
808 - cct = 10;  
809 - }  
810 -  
811 -  
812 SrsStatisticClient* client = NULL; 794 SrsStatisticClient* client = NULL;
813 if (cid >= 0 && (client = stat->find_client(cid)) == NULL) { 795 if (cid >= 0 && (client = stat->find_client(cid)) == NULL) {
814 ret = ERROR_RTMP_CLIENT_NOT_FOUND; 796 ret = ERROR_RTMP_CLIENT_NOT_FOUND;
@@ -827,7 +809,11 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -827,7 +809,11 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
827 SrsJsonArray* data = SrsJsonAny::array(); 809 SrsJsonArray* data = SrsJsonAny::array();
828 obj->set("clients", data); 810 obj->set("clients", data);
829 811
830 - if ((ret = stat->dumps_clients(data, cst, cct)) != ERROR_SUCCESS) { 812 + std::string rstart = r->query_get("start");
  813 + std::string rcount = r->query_get("count");
  814 + int start = srs_max(0, atoi(rstart.c_str()));
  815 + int count = srs_max(10, atoi(rcount.c_str()));
  816 + if ((ret = stat->dumps_clients(data, start, count)) != ERROR_SUCCESS) {
831 return srs_api_response_code(w, r, ret); 817 return srs_api_response_code(w, r, ret);
832 } 818 }
833 } else { 819 } else {