2021-05-31 05:42:20 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2013-2021 Winlin
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
2014-03-27 04:14:04 +00:00
|
|
|
|
|
|
|
#include <srs_app_http_api.hpp>
|
|
|
|
|
2014-04-02 04:55:10 +00:00
|
|
|
#include <sstream>
|
2015-08-11 07:23:46 +00:00
|
|
|
#include <stdlib.h>
|
2015-08-27 16:01:19 +00:00
|
|
|
#include <signal.h>
|
2020-05-02 23:22:07 +00:00
|
|
|
#include <unistd.h>
|
2014-04-02 04:55:10 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2014-03-27 05:25:08 +00:00
|
|
|
#include <srs_kernel_log.hpp>
|
|
|
|
#include <srs_kernel_error.hpp>
|
2015-06-14 00:43:38 +00:00
|
|
|
#include <srs_app_st.hpp>
|
2014-04-02 04:55:10 +00:00
|
|
|
#include <srs_core_autofree.hpp>
|
2015-08-21 08:20:19 +00:00
|
|
|
#include <srs_protocol_json.hpp>
|
2014-04-19 13:23:34 +00:00
|
|
|
#include <srs_kernel_utility.hpp>
|
2014-05-17 06:53:04 +00:00
|
|
|
#include <srs_app_utility.hpp>
|
2015-01-04 14:47:12 +00:00
|
|
|
#include <srs_app_statistic.hpp>
|
2015-06-13 08:04:59 +00:00
|
|
|
#include <srs_rtmp_stack.hpp>
|
2015-02-21 13:17:59 +00:00
|
|
|
#include <srs_app_dvr.hpp>
|
|
|
|
#include <srs_app_config.hpp>
|
2015-08-11 07:23:46 +00:00
|
|
|
#include <srs_app_source.hpp>
|
2015-05-22 14:34:03 +00:00
|
|
|
#include <srs_app_http_conn.hpp>
|
2015-08-27 10:11:50 +00:00
|
|
|
#include <srs_kernel_consts.hpp>
|
|
|
|
#include <srs_app_server.hpp>
|
2015-09-22 01:05:21 +00:00
|
|
|
#include <srs_protocol_amf0.hpp>
|
2016-01-13 04:52:19 +00:00
|
|
|
#include <srs_protocol_utility.hpp>
|
2018-02-15 12:55:34 +00:00
|
|
|
#include <srs_app_coworkers.hpp>
|
2014-03-27 05:25:08 +00:00
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t srs_api_response_jsonp(ISrsHttpResponseWriter* w, string callback, string data)
|
2015-08-22 10:18:18 +00:00
|
|
|
{
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-22 10:18:18 +00:00
|
|
|
|
|
|
|
SrsHttpHeader* h = w->header();
|
|
|
|
|
|
|
|
h->set_content_length(data.length() + callback.length() + 2);
|
|
|
|
h->set_content_type("text/javascript");
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if (!callback.empty() && (err = w->write((char*)callback.data(), (int)callback.length())) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write jsonp callback");
|
2015-08-22 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char* c0 = (char*)"(";
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = w->write(c0, 1)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write jsonp left token");
|
2015-08-22 10:18:18 +00:00
|
|
|
}
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = w->write((char*)data.data(), (int)data.length())) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write jsonp data");
|
2015-08-22 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char* c1 = (char*)")";
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = w->write(c1, 1)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write jsonp right token");
|
2015-08-22 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
return err;
|
2015-08-22 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callback, int code)
|
2015-08-22 10:18:18 +00:00
|
|
|
{
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-22 10:18:18 +00:00
|
|
|
|
2015-09-19 05:31:57 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(code));
|
2015-08-22 10:18:18 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response_jsonp(w, callback, obj->dumps());
|
2015-08-22 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callback, srs_error_t err)
|
2017-07-29 12:02:38 +00:00
|
|
|
{
|
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
|
|
|
|
|
|
|
obj->set("code", SrsJsonAny::integer(srs_error_code(err)));
|
|
|
|
|
|
|
|
return srs_api_response_jsonp(w, callback, obj->dumps());
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t srs_api_response_json(ISrsHttpResponseWriter* w, string data)
|
2015-08-22 10:18:18 +00:00
|
|
|
{
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
2015-08-22 10:18:18 +00:00
|
|
|
SrsHttpHeader* h = w->header();
|
|
|
|
|
|
|
|
h->set_content_length(data.length());
|
|
|
|
h->set_content_type("application/json");
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = w->write((char*)data.data(), (int)data.length())) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write json");
|
2017-07-29 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2015-08-22 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t srs_api_response_json_code(ISrsHttpResponseWriter* w, int code)
|
2015-08-22 10:18:18 +00:00
|
|
|
{
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-22 10:18:18 +00:00
|
|
|
|
2015-09-19 05:31:57 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(code));
|
2015-08-22 10:18:18 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response_json(w, obj->dumps());
|
2015-08-22 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t srs_api_response_json_code(ISrsHttpResponseWriter* w, srs_error_t code)
|
2017-07-29 12:02:38 +00:00
|
|
|
{
|
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(srs_error_code(code)));
|
2017-07-29 12:02:38 +00:00
|
|
|
|
|
|
|
return srs_api_response_json(w, obj->dumps());
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t srs_api_response(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string json)
|
2015-08-22 10:18:18 +00:00
|
|
|
{
|
|
|
|
// no jsonp, directly response.
|
2015-08-22 16:01:03 +00:00
|
|
|
if (!r->is_jsonp()) {
|
2015-08-22 10:18:18 +00:00
|
|
|
return srs_api_response_json(w, json);
|
|
|
|
}
|
|
|
|
|
|
|
|
// jsonp, get function name from query("callback")
|
2015-08-22 16:01:03 +00:00
|
|
|
string callback = r->query_get("callback");
|
2015-08-22 10:18:18 +00:00
|
|
|
return srs_api_response_jsonp(w, callback, json);
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, int code)
|
2015-08-22 10:18:18 +00:00
|
|
|
{
|
|
|
|
// no jsonp, directly response.
|
2015-08-22 16:01:03 +00:00
|
|
|
if (!r->is_jsonp()) {
|
2015-08-22 10:18:18 +00:00
|
|
|
return srs_api_response_json_code(w, code);
|
|
|
|
}
|
|
|
|
|
|
|
|
// jsonp, get function name from query("callback")
|
2015-08-22 16:01:03 +00:00
|
|
|
string callback = r->query_get("callback");
|
2015-08-22 10:18:18 +00:00
|
|
|
return srs_api_response_jsonp_code(w, callback, code);
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
// @remark we will free the code.
|
|
|
|
srs_error_t srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, srs_error_t code)
|
2017-07-29 12:02:38 +00:00
|
|
|
{
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2017-07-29 12:02:38 +00:00
|
|
|
|
|
|
|
// no jsonp, directly response.
|
|
|
|
if (!r->is_jsonp()) {
|
2017-07-29 13:39:57 +00:00
|
|
|
err = srs_api_response_json_code(w, code);
|
2017-07-29 12:02:38 +00:00
|
|
|
} else {
|
|
|
|
// jsonp, get function name from query("callback")
|
|
|
|
string callback = r->query_get("callback");
|
2017-07-29 13:39:57 +00:00
|
|
|
err = srs_api_response_jsonp_code(w, callback, code);
|
2017-07-29 12:02:38 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
if (code != srs_success) {
|
|
|
|
srs_warn("error %s", srs_error_desc(code).c_str());
|
|
|
|
srs_freep(code);
|
2017-07-29 12:02:38 +00:00
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
return err;
|
2017-07-29 12:02:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiRoot::SrsGoApiRoot()
|
2014-04-02 10:07:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiRoot::~SrsGoApiRoot()
|
2014-04-02 10:07:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiRoot::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-02 10:07:34 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2014-04-03 03:49:14 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* urls = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("urls", urls);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
urls->set("api", SrsJsonAny::str("the api root"));
|
2020-05-04 06:47:58 +00:00
|
|
|
|
|
|
|
if (true) {
|
|
|
|
SrsJsonObject* rtc = SrsJsonAny::object();
|
|
|
|
urls->set("rtc", rtc);
|
|
|
|
|
|
|
|
SrsJsonObject* v1 = SrsJsonAny::object();
|
|
|
|
rtc->set("v1", v1);
|
|
|
|
|
|
|
|
v1->set("play", SrsJsonAny::str("Play stream"));
|
|
|
|
v1->set("publish", SrsJsonAny::str("Publish stream"));
|
|
|
|
v1->set("nack", SrsJsonAny::str("Simulate the NACK"));
|
|
|
|
}
|
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-04-02 11:10:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiApi::SrsGoApiApi()
|
2014-04-02 11:10:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiApi::~SrsGoApiApi()
|
2014-04-02 11:10:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiApi::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-02 11:10:22 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2014-04-03 04:08:22 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* urls = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("urls", urls);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
urls->set("v1", SrsJsonAny::str("the api version 1.0"));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-04-03 04:08:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiV1::SrsGoApiV1()
|
2014-04-03 04:08:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiV1::~SrsGoApiV1()
|
2014-04-03 04:08:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-03 04:08:22 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2014-04-03 04:08:22 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2014-05-18 09:57:20 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* urls = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("urls", urls);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
urls->set("versions", SrsJsonAny::str("the version of SRS"));
|
|
|
|
urls->set("summaries", SrsJsonAny::str("the summary(pid, argv, pwd, cpu, mem) of SRS"));
|
|
|
|
urls->set("rusages", SrsJsonAny::str("the rusage of SRS"));
|
|
|
|
urls->set("self_proc_stats", SrsJsonAny::str("the self process stats"));
|
|
|
|
urls->set("system_proc_stats", SrsJsonAny::str("the system process stats"));
|
|
|
|
urls->set("meminfos", SrsJsonAny::str("the meminfo of system"));
|
|
|
|
urls->set("authors", SrsJsonAny::str("the license, copyright, authors and contributors"));
|
|
|
|
urls->set("features", SrsJsonAny::str("the supported features of SRS"));
|
|
|
|
urls->set("requests", SrsJsonAny::str("the request itself, for http debug"));
|
|
|
|
urls->set("vhosts", SrsJsonAny::str("manage all vhosts or specified vhost"));
|
|
|
|
urls->set("streams", SrsJsonAny::str("manage all streams or specified stream"));
|
|
|
|
urls->set("clients", SrsJsonAny::str("manage all clients or specified client, default query top 10 clients"));
|
|
|
|
urls->set("raw", SrsJsonAny::str("raw api for srs, support CUID srs for instance the config"));
|
2018-02-15 12:55:34 +00:00
|
|
|
urls->set("clusters", SrsJsonAny::str("origin cluster server API"));
|
2020-03-27 05:37:39 +00:00
|
|
|
urls->set("perf", SrsJsonAny::str("System performance stat"));
|
2020-03-25 09:00:16 +00:00
|
|
|
urls->set("tcmalloc", SrsJsonAny::str("tcmalloc api with params ?page=summary|api"));
|
2020-03-27 05:37:39 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* tests = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("tests", tests);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
tests->set("requests", SrsJsonAny::str("show the request info"));
|
|
|
|
tests->set("errors", SrsJsonAny::str("always return an error 100"));
|
|
|
|
tests->set("redirects", SrsJsonAny::str("always redirect to /api/v1/test/errors"));
|
|
|
|
tests->set("[vhost]", SrsJsonAny::str("http vhost for http://error.srs.com:1985/api/v1/tests/errors"));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-05-18 09:57:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiVersion::SrsGoApiVersion()
|
2014-05-18 09:57:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiVersion::~SrsGoApiVersion()
|
2014-05-18 09:57:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiVersion::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-03 04:08:22 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2014-04-03 04:08:22 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2014-04-03 05:48:52 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("data", data);
|
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("major", SrsJsonAny::integer(VERSION_MAJOR));
|
|
|
|
data->set("minor", SrsJsonAny::integer(VERSION_MINOR));
|
|
|
|
data->set("revision", SrsJsonAny::integer(VERSION_REVISION));
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("version", SrsJsonAny::str(RTMP_SIG_SRS_VERSION));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-04-19 13:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSummaries::SrsGoApiSummaries()
|
2014-04-19 13:23:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSummaries::~SrsGoApiSummaries()
|
2014-04-19 13:23:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-19 13:23:34 +00:00
|
|
|
{
|
2015-12-15 04:46:47 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 07:11:11 +00:00
|
|
|
|
2015-12-15 04:46:47 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-12-15 04:46:47 +00:00
|
|
|
|
2015-08-28 07:11:11 +00:00
|
|
|
srs_api_dump_summaries(obj);
|
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-04-19 13:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiRusages::SrsGoApiRusages()
|
2014-04-19 13:23:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiRusages::~SrsGoApiRusages()
|
2014-04-19 13:23:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiRusages::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-19 13:23:34 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2014-04-19 13:23:34 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2014-04-19 13:23:34 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2014-04-19 13:23:34 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("data", data);
|
|
|
|
|
|
|
|
SrsRusage* ru = srs_get_system_rusage();
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("ok", SrsJsonAny::boolean(ru->ok));
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("sample_time", SrsJsonAny::integer(ru->sample_time));
|
|
|
|
data->set("ru_utime", SrsJsonAny::integer(ru->r.ru_utime.tv_sec));
|
|
|
|
data->set("ru_stime", SrsJsonAny::integer(ru->r.ru_stime.tv_sec));
|
|
|
|
data->set("ru_maxrss", SrsJsonAny::integer(ru->r.ru_maxrss));
|
|
|
|
data->set("ru_ixrss", SrsJsonAny::integer(ru->r.ru_ixrss));
|
|
|
|
data->set("ru_idrss", SrsJsonAny::integer(ru->r.ru_idrss));
|
|
|
|
data->set("ru_isrss", SrsJsonAny::integer(ru->r.ru_isrss));
|
|
|
|
data->set("ru_minflt", SrsJsonAny::integer(ru->r.ru_minflt));
|
|
|
|
data->set("ru_majflt", SrsJsonAny::integer(ru->r.ru_majflt));
|
|
|
|
data->set("ru_nswap", SrsJsonAny::integer(ru->r.ru_nswap));
|
|
|
|
data->set("ru_inblock", SrsJsonAny::integer(ru->r.ru_inblock));
|
|
|
|
data->set("ru_oublock", SrsJsonAny::integer(ru->r.ru_oublock));
|
|
|
|
data->set("ru_msgsnd", SrsJsonAny::integer(ru->r.ru_msgsnd));
|
|
|
|
data->set("ru_msgrcv", SrsJsonAny::integer(ru->r.ru_msgrcv));
|
|
|
|
data->set("ru_nsignals", SrsJsonAny::integer(ru->r.ru_nsignals));
|
|
|
|
data->set("ru_nvcsw", SrsJsonAny::integer(ru->r.ru_nvcsw));
|
|
|
|
data->set("ru_nivcsw", SrsJsonAny::integer(ru->r.ru_nivcsw));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-04-19 13:43:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSelfProcStats::SrsGoApiSelfProcStats()
|
2014-04-19 13:43:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSelfProcStats::~SrsGoApiSelfProcStats()
|
2014-04-19 13:43:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-19 13:43:13 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2014-04-19 13:43:13 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2014-04-19 13:43:13 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2014-04-19 13:43:13 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("data", data);
|
|
|
|
|
|
|
|
SrsProcSelfStat* u = srs_get_self_proc_stat();
|
|
|
|
|
|
|
|
string state;
|
|
|
|
state += (char)u->state;
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("ok", SrsJsonAny::boolean(u->ok));
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("sample_time", SrsJsonAny::integer(u->sample_time));
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("percent", SrsJsonAny::number(u->percent));
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("pid", SrsJsonAny::integer(u->pid));
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("comm", SrsJsonAny::str(u->comm));
|
|
|
|
data->set("state", SrsJsonAny::str(state.c_str()));
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("ppid", SrsJsonAny::integer(u->ppid));
|
|
|
|
data->set("pgrp", SrsJsonAny::integer(u->pgrp));
|
|
|
|
data->set("session", SrsJsonAny::integer(u->session));
|
|
|
|
data->set("tty_nr", SrsJsonAny::integer(u->tty_nr));
|
|
|
|
data->set("tpgid", SrsJsonAny::integer(u->tpgid));
|
|
|
|
data->set("flags", SrsJsonAny::integer(u->flags));
|
|
|
|
data->set("minflt", SrsJsonAny::integer(u->minflt));
|
|
|
|
data->set("cminflt", SrsJsonAny::integer(u->cminflt));
|
|
|
|
data->set("majflt", SrsJsonAny::integer(u->majflt));
|
|
|
|
data->set("cmajflt", SrsJsonAny::integer(u->cmajflt));
|
|
|
|
data->set("utime", SrsJsonAny::integer(u->utime));
|
|
|
|
data->set("stime", SrsJsonAny::integer(u->stime));
|
|
|
|
data->set("cutime", SrsJsonAny::integer(u->cutime));
|
|
|
|
data->set("cstime", SrsJsonAny::integer(u->cstime));
|
|
|
|
data->set("priority", SrsJsonAny::integer(u->priority));
|
|
|
|
data->set("nice", SrsJsonAny::integer(u->nice));
|
|
|
|
data->set("num_threads", SrsJsonAny::integer(u->num_threads));
|
|
|
|
data->set("itrealvalue", SrsJsonAny::integer(u->itrealvalue));
|
|
|
|
data->set("starttime", SrsJsonAny::integer(u->starttime));
|
|
|
|
data->set("vsize", SrsJsonAny::integer(u->vsize));
|
|
|
|
data->set("rss", SrsJsonAny::integer(u->rss));
|
|
|
|
data->set("rsslim", SrsJsonAny::integer(u->rsslim));
|
|
|
|
data->set("startcode", SrsJsonAny::integer(u->startcode));
|
|
|
|
data->set("endcode", SrsJsonAny::integer(u->endcode));
|
|
|
|
data->set("startstack", SrsJsonAny::integer(u->startstack));
|
|
|
|
data->set("kstkesp", SrsJsonAny::integer(u->kstkesp));
|
|
|
|
data->set("kstkeip", SrsJsonAny::integer(u->kstkeip));
|
|
|
|
data->set("signal", SrsJsonAny::integer(u->signal));
|
|
|
|
data->set("blocked", SrsJsonAny::integer(u->blocked));
|
|
|
|
data->set("sigignore", SrsJsonAny::integer(u->sigignore));
|
|
|
|
data->set("sigcatch", SrsJsonAny::integer(u->sigcatch));
|
|
|
|
data->set("wchan", SrsJsonAny::integer(u->wchan));
|
|
|
|
data->set("nswap", SrsJsonAny::integer(u->nswap));
|
|
|
|
data->set("cnswap", SrsJsonAny::integer(u->cnswap));
|
|
|
|
data->set("exit_signal", SrsJsonAny::integer(u->exit_signal));
|
|
|
|
data->set("processor", SrsJsonAny::integer(u->processor));
|
|
|
|
data->set("rt_priority", SrsJsonAny::integer(u->rt_priority));
|
|
|
|
data->set("policy", SrsJsonAny::integer(u->policy));
|
|
|
|
data->set("delayacct_blkio_ticks", SrsJsonAny::integer(u->delayacct_blkio_ticks));
|
|
|
|
data->set("guest_time", SrsJsonAny::integer(u->guest_time));
|
|
|
|
data->set("cguest_time", SrsJsonAny::integer(u->cguest_time));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-04-19 13:43:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSystemProcStats::SrsGoApiSystemProcStats()
|
2014-04-19 13:43:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSystemProcStats::~SrsGoApiSystemProcStats()
|
2014-04-19 13:43:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-19 13:43:13 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("data", data);
|
2014-04-19 13:43:13 +00:00
|
|
|
|
|
|
|
SrsProcSystemStat* s = srs_get_system_proc_stat();
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("ok", SrsJsonAny::boolean(s->ok));
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("sample_time", SrsJsonAny::integer(s->sample_time));
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("percent", SrsJsonAny::number(s->percent));
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("user", SrsJsonAny::integer(s->user));
|
|
|
|
data->set("nice", SrsJsonAny::integer(s->nice));
|
|
|
|
data->set("sys", SrsJsonAny::integer(s->sys));
|
|
|
|
data->set("idle", SrsJsonAny::integer(s->idle));
|
|
|
|
data->set("iowait", SrsJsonAny::integer(s->iowait));
|
|
|
|
data->set("irq", SrsJsonAny::integer(s->irq));
|
|
|
|
data->set("softirq", SrsJsonAny::integer(s->softirq));
|
|
|
|
data->set("steal", SrsJsonAny::integer(s->steal));
|
|
|
|
data->set("guest", SrsJsonAny::integer(s->guest));
|
2014-04-19 13:43:13 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-04-19 13:43:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiMemInfos::SrsGoApiMemInfos()
|
2014-04-19 16:15:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiMemInfos::~SrsGoApiMemInfos()
|
2014-04-19 16:15:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-19 16:15:26 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("data", data);
|
2014-04-19 16:15:26 +00:00
|
|
|
|
|
|
|
SrsMemInfo* m = srs_get_meminfo();
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("ok", SrsJsonAny::boolean(m->ok));
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("sample_time", SrsJsonAny::integer(m->sample_time));
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("percent_ram", SrsJsonAny::number(m->percent_ram));
|
|
|
|
data->set("percent_swap", SrsJsonAny::number(m->percent_swap));
|
2015-09-19 06:40:32 +00:00
|
|
|
data->set("MemActive", SrsJsonAny::integer(m->MemActive));
|
|
|
|
data->set("RealInUse", SrsJsonAny::integer(m->RealInUse));
|
|
|
|
data->set("NotInUse", SrsJsonAny::integer(m->NotInUse));
|
|
|
|
data->set("MemTotal", SrsJsonAny::integer(m->MemTotal));
|
|
|
|
data->set("MemFree", SrsJsonAny::integer(m->MemFree));
|
|
|
|
data->set("Buffers", SrsJsonAny::integer(m->Buffers));
|
|
|
|
data->set("Cached", SrsJsonAny::integer(m->Cached));
|
|
|
|
data->set("SwapTotal", SrsJsonAny::integer(m->SwapTotal));
|
|
|
|
data->set("SwapFree", SrsJsonAny::integer(m->SwapFree));
|
2014-04-19 16:15:26 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2014-04-19 16:15:26 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiAuthors::SrsGoApiAuthors()
|
2014-04-03 05:48:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiAuthors::~SrsGoApiAuthors()
|
2014-04-03 05:48:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2014-04-03 05:48:52 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2014-04-03 05:48:52 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2014-04-03 04:08:22 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("data", data);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("license", SrsJsonAny::str(RTMP_SIG_SRS_LICENSE));
|
2020-04-29 12:02:28 +00:00
|
|
|
data->set("contributors", SrsJsonAny::str(SRS_CONSTRIBUTORS));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-01-17 13:58:23 +00:00
|
|
|
}
|
|
|
|
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsGoApiFeatures::SrsGoApiFeatures()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsGoApiFeatures::~SrsGoApiFeatures()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiFeatures::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2015-08-22 03:08:56 +00:00
|
|
|
{
|
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("data", data);
|
|
|
|
|
2020-04-29 12:02:28 +00:00
|
|
|
data->set("options", SrsJsonAny::str(SRS_USER_CONFIGURE));
|
|
|
|
data->set("options2", SrsJsonAny::str(SRS_CONFIGURE));
|
|
|
|
data->set("build", SrsJsonAny::str(SRS_BUILD_DATE));
|
|
|
|
data->set("build2", SrsJsonAny::str(SRS_BUILD_TS));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* features = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
data->set("features", features);
|
2015-08-22 03:08:56 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("ssl", SrsJsonAny::boolean(true));
|
|
|
|
features->set("hls", SrsJsonAny::boolean(true));
|
2020-04-29 12:02:28 +00:00
|
|
|
#ifdef SRS_HDS
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("hds", SrsJsonAny::boolean(true));
|
2015-08-22 03:08:56 +00:00
|
|
|
#else
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("hds", SrsJsonAny::boolean(false));
|
2015-08-22 03:08:56 +00:00
|
|
|
#endif
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("callback", SrsJsonAny::boolean(true));
|
|
|
|
features->set("api", SrsJsonAny::boolean(true));
|
|
|
|
features->set("httpd", SrsJsonAny::boolean(true));
|
|
|
|
features->set("dvr", SrsJsonAny::boolean(true));
|
|
|
|
features->set("transcode", SrsJsonAny::boolean(true));
|
|
|
|
features->set("ingest", SrsJsonAny::boolean(true));
|
|
|
|
features->set("stat", SrsJsonAny::boolean(true));
|
|
|
|
features->set("caster", SrsJsonAny::boolean(true));
|
2015-08-22 03:08:56 +00:00
|
|
|
#ifdef SRS_PERF_COMPLEX_SEND
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("complex_send", SrsJsonAny::boolean(true));
|
2015-08-22 03:08:56 +00:00
|
|
|
#else
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("complex_send", SrsJsonAny::boolean(false));
|
2015-08-22 03:08:56 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SRS_PERF_TCP_NODELAY
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("tcp_nodelay", SrsJsonAny::boolean(true));
|
2015-08-22 03:08:56 +00:00
|
|
|
#else
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("tcp_nodelay", SrsJsonAny::boolean(false));
|
2015-08-22 03:08:56 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SRS_PERF_SO_SNDBUF_SIZE
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("so_sendbuf", SrsJsonAny::boolean(true));
|
2015-08-22 03:08:56 +00:00
|
|
|
#else
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("so_sendbuf", SrsJsonAny::boolean(false));
|
2015-08-22 03:08:56 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SRS_PERF_MERGED_READ
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("mr", SrsJsonAny::boolean(true));
|
2015-08-22 03:08:56 +00:00
|
|
|
#else
|
2015-09-19 04:27:31 +00:00
|
|
|
features->set("mr", SrsJsonAny::boolean(false));
|
2015-08-22 03:08:56 +00:00
|
|
|
#endif
|
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-08-22 03:08:56 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiRequests::SrsGoApiRequests()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsGoApiRequests::~SrsGoApiRequests()
|
|
|
|
{
|
2014-04-02 10:07:34 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiRequests::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
2015-08-22 03:08:56 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2015-01-17 13:58:23 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("data", data);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("uri", SrsJsonAny::str(r->uri().c_str()));
|
|
|
|
data->set("path", SrsJsonAny::str(r->path().c_str()));
|
2015-01-17 13:58:23 +00:00
|
|
|
|
|
|
|
// method
|
2015-09-19 04:27:31 +00:00
|
|
|
data->set("METHOD", SrsJsonAny::str(r->method_str().c_str()));
|
2015-01-17 13:58:23 +00:00
|
|
|
|
|
|
|
// request headers
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* headers = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
data->set("headers", headers);
|
2019-12-16 08:00:02 +00:00
|
|
|
r->header()->dumps(headers);
|
2015-01-17 13:58:23 +00:00
|
|
|
|
|
|
|
// server informations
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* server = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
data->set("headers", server);
|
2015-01-17 13:58:23 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
server->set("sigature", SrsJsonAny::str(RTMP_SIG_SRS_KEY));
|
|
|
|
server->set("version", SrsJsonAny::str(RTMP_SIG_SRS_VERSION));
|
|
|
|
server->set("link", SrsJsonAny::str(RTMP_SIG_SRS_URL));
|
2019-04-10 01:07:03 +00:00
|
|
|
server->set("time", SrsJsonAny::integer(srsu2ms(srs_get_system_time())));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-01-03 04:57:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiVhosts::SrsGoApiVhosts()
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiVhosts::~SrsGoApiVhosts()
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-01-05 04:40:38 +00:00
|
|
|
|
2015-08-21 09:00:52 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2015-01-03 04:57:13 +00:00
|
|
|
|
2015-08-21 09:00:52 +00:00
|
|
|
// path: {pattern}{vhost_id}
|
|
|
|
// e.g. /api/v1/vhosts/100 pattern= /api/v1/vhosts/, vhost_id=100
|
2021-01-07 08:47:49 +00:00
|
|
|
string vid = r->parse_rest_id(entry->pattern);
|
2015-08-21 09:00:52 +00:00
|
|
|
SrsStatisticVhost* vhost = NULL;
|
|
|
|
|
2021-01-07 08:47:49 +00:00
|
|
|
if (!vid.empty() && (vhost = stat->find_vhost_by_id(vid)) == NULL) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_RTMP_VHOST_NOT_FOUND);
|
2015-08-21 09:00:52 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-08-21 09:00:52 +00:00
|
|
|
if (r->is_http_get()) {
|
|
|
|
if (!vhost) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* data = SrsJsonAny::array();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("vhosts", data);
|
2015-08-21 09:00:52 +00:00
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = stat->dumps_vhosts(data)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-28 06:39:29 +00:00
|
|
|
}
|
2015-08-21 09:00:52 +00:00
|
|
|
} else {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("vhost", data);;
|
2015-08-21 09:00:52 +00:00
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = vhost->dumps(data)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-28 06:39:29 +00:00
|
|
|
}
|
2015-08-21 09:00:52 +00:00
|
|
|
}
|
2015-08-28 06:39:29 +00:00
|
|
|
} else {
|
|
|
|
return srs_go_http_error(w, SRS_CONSTS_HTTP_MethodNotAllowed);
|
2015-08-21 09:00:52 +00:00
|
|
|
}
|
2015-01-03 04:57:13 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-01-03 04:57:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiStreams::SrsGoApiStreams()
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiStreams::~SrsGoApiStreams()
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-21 08:12:48 +00:00
|
|
|
|
2015-01-05 04:49:00 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2015-08-21 07:51:20 +00:00
|
|
|
|
|
|
|
// path: {pattern}{stream_id}
|
|
|
|
// e.g. /api/v1/streams/100 pattern= /api/v1/streams/, stream_id=100
|
2021-01-07 08:47:49 +00:00
|
|
|
string sid = r->parse_rest_id(entry->pattern);
|
2015-08-21 07:51:20 +00:00
|
|
|
|
|
|
|
SrsStatisticStream* stream = NULL;
|
2021-01-07 08:47:49 +00:00
|
|
|
if (!sid.empty() && (stream = stat->find_stream(sid)) == NULL) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_RTMP_STREAM_NOT_FOUND);
|
2015-08-21 07:51:20 +00:00
|
|
|
}
|
2015-08-22 05:36:15 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-08-22 05:36:15 +00:00
|
|
|
if (r->is_http_get()) {
|
2015-08-21 07:51:20 +00:00
|
|
|
if (!stream) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* data = SrsJsonAny::array();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("streams", data);
|
2015-08-21 07:51:20 +00:00
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = stat->dumps_streams(data)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-28 06:39:29 +00:00
|
|
|
}
|
2015-08-21 07:51:20 +00:00
|
|
|
} else {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("stream", data);;
|
2015-08-21 07:51:20 +00:00
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = stream->dumps(data)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-28 06:39:29 +00:00
|
|
|
}
|
2015-08-21 07:51:20 +00:00
|
|
|
}
|
2015-08-28 06:39:29 +00:00
|
|
|
} else {
|
|
|
|
return srs_go_http_error(w, SRS_CONSTS_HTTP_MethodNotAllowed);
|
2015-08-11 07:23:46 +00:00
|
|
|
}
|
2015-08-21 07:51:20 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-02-21 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 08:12:48 +00:00
|
|
|
SrsGoApiClients::SrsGoApiClients()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsGoApiClients::~SrsGoApiClients()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2015-08-21 08:12:48 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-21 08:12:48 +00:00
|
|
|
|
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
|
|
|
|
|
|
|
// path: {pattern}{client_id}
|
|
|
|
// e.g. /api/v1/clients/100 pattern= /api/v1/clients/, client_id=100
|
2021-01-07 09:04:11 +00:00
|
|
|
string client_id = r->parse_rest_id(entry->pattern);
|
2015-08-21 08:12:48 +00:00
|
|
|
|
|
|
|
SrsStatisticClient* client = NULL;
|
2021-01-07 09:04:11 +00:00
|
|
|
if (!client_id.empty() && (client = stat->find_client(client_id)) == NULL) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND);
|
2015-08-21 09:00:52 +00:00
|
|
|
}
|
2015-08-21 08:12:48 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2021-01-07 08:47:49 +00:00
|
|
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
2015-08-28 06:39:29 +00:00
|
|
|
|
|
|
|
if (r->is_http_get()) {
|
2015-08-21 09:00:52 +00:00
|
|
|
if (!client) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* data = SrsJsonAny::array();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("clients", data);
|
2015-08-21 09:00:52 +00:00
|
|
|
|
2017-02-03 03:56:02 +00:00
|
|
|
std::string rstart = r->query_get("start");
|
|
|
|
std::string rcount = r->query_get("count");
|
|
|
|
int start = srs_max(0, atoi(rstart.c_str()));
|
|
|
|
int count = srs_max(10, atoi(rcount.c_str()));
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = stat->dumps_clients(data, start, count)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-28 06:39:29 +00:00
|
|
|
}
|
2015-08-21 09:00:52 +00:00
|
|
|
} else {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-28 06:39:29 +00:00
|
|
|
obj->set("client", data);;
|
2015-08-21 09:00:52 +00:00
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = client->dumps(data)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-28 06:39:29 +00:00
|
|
|
}
|
2015-08-21 09:00:52 +00:00
|
|
|
}
|
2015-08-28 10:00:24 +00:00
|
|
|
} else if (r->is_http_delete()) {
|
|
|
|
if (!client) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND);
|
2015-08-28 10:00:24 +00:00
|
|
|
}
|
2020-11-05 03:47:24 +00:00
|
|
|
|
2015-08-28 10:00:24 +00:00
|
|
|
client->conn->expire();
|
2020-07-05 15:26:55 +00:00
|
|
|
srs_warn("kickoff client id=%s ok", client_id.c_str());
|
2015-08-22 05:36:15 +00:00
|
|
|
} else {
|
|
|
|
return srs_go_http_error(w, SRS_CONSTS_HTTP_MethodNotAllowed);
|
2015-08-21 08:12:48 +00:00
|
|
|
}
|
2015-08-28 06:39:29 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-08-21 08:12:48 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 10:11:50 +00:00
|
|
|
SrsGoApiRaw::SrsGoApiRaw(SrsServer* svr)
|
|
|
|
{
|
|
|
|
server = svr;
|
2015-08-28 04:28:18 +00:00
|
|
|
|
|
|
|
raw_api = _srs_config->get_raw_api();
|
|
|
|
allow_reload = _srs_config->get_raw_api_allow_reload();
|
2015-08-28 05:01:04 +00:00
|
|
|
allow_query = _srs_config->get_raw_api_allow_query();
|
2015-08-30 15:08:27 +00:00
|
|
|
allow_update = _srs_config->get_raw_api_allow_update();
|
2015-08-28 04:28:18 +00:00
|
|
|
|
|
|
|
_srs_config->subscribe(this);
|
2015-08-27 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsGoApiRaw::~SrsGoApiRaw()
|
|
|
|
{
|
2015-08-28 04:28:18 +00:00
|
|
|
_srs_config->unsubscribe(this);
|
2015-08-27 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2015-08-27 10:11:50 +00:00
|
|
|
{
|
2017-07-29 12:02:38 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-27 10:11:50 +00:00
|
|
|
|
2015-08-28 05:17:46 +00:00
|
|
|
std::string rpc = r->query_get("rpc");
|
|
|
|
|
|
|
|
// the object to return for request.
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
2015-08-28 05:17:46 +00:00
|
|
|
|
|
|
|
// for rpc=raw, to query the raw api config for http api.
|
|
|
|
if (rpc == "raw") {
|
|
|
|
// query global scope.
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_to_json(obj)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-28 05:17:46 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-08-28 05:17:46 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 10:11:50 +00:00
|
|
|
// whether enabled the HTTP RAW API.
|
2015-08-28 04:28:18 +00:00
|
|
|
if (!raw_api) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED);
|
2015-08-27 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
2015-08-30 15:08:27 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2015-08-27 10:11:50 +00:00
|
|
|
// the rpc is required.
|
2015-08-30 15:08:27 +00:00
|
|
|
// the allowd rpc method check.
|
|
|
|
if (rpc.empty() || (rpc != "reload" && rpc != "query" && rpc != "raw" && rpc != "update")) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW);
|
2015-08-27 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// for rpc=reload, trigger the server to reload the config.
|
|
|
|
if (rpc == "reload") {
|
2015-08-28 04:28:18 +00:00
|
|
|
if (!allow_reload) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED);
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 10:11:50 +00:00
|
|
|
server->on_signal(SRS_SIGNAL_RELOAD);
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SUCCESS);
|
2015-08-27 10:11:50 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-28 05:01:04 +00:00
|
|
|
// for rpc=query, to get the configs of server.
|
2015-08-27 14:46:56 +00:00
|
|
|
// @param scope the scope to query for config, it can be:
|
|
|
|
// global, the configs belongs to the root, donot includes any sub directives.
|
2015-09-01 05:33:49 +00:00
|
|
|
// minimal, the minimal summary of server, for preview stream to got the port serving.
|
2015-08-27 14:46:56 +00:00
|
|
|
// vhost, the configs for specified vhost by @param vhost.
|
|
|
|
// @param vhost the vhost name for @param scope is vhost to query config.
|
|
|
|
// for the default vhost, must be __defaultVhost__
|
2015-08-28 05:01:04 +00:00
|
|
|
if (rpc == "query") {
|
|
|
|
if (!allow_query) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED);
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 14:46:56 +00:00
|
|
|
std::string scope = r->query_get("scope");
|
|
|
|
std::string vhost = r->query_get("vhost");
|
2015-09-01 05:33:49 +00:00
|
|
|
if (scope.empty() || (scope != "global" && scope != "vhost" && scope != "minimal")) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED);
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (scope == "vhost") {
|
|
|
|
// query vhost scope.
|
|
|
|
if (vhost.empty()) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* root = _srs_config->get_root();
|
|
|
|
SrsConfDirective* conf = root->get("vhost", vhost);
|
|
|
|
if (!conf) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
obj->set("vhost", data);
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->vhost_to_json(conf, data)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
2015-09-01 05:33:49 +00:00
|
|
|
} else if (scope == "minimal") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-09-01 05:33:49 +00:00
|
|
|
obj->set("minimal", data);
|
|
|
|
|
|
|
|
// query minimal scope.
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->minimal_to_json(data)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-01 05:33:49 +00:00
|
|
|
}
|
2015-08-27 14:46:56 +00:00
|
|
|
} else {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
obj->set("global", data);
|
|
|
|
|
|
|
|
// query global scope.
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->global_to_json(data)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-30 15:08:27 +00:00
|
|
|
// for rpc=update, to update the configs of server.
|
2015-09-12 13:55:53 +00:00
|
|
|
// @scope the scope to update for config.
|
|
|
|
// @value the updated value for scope.
|
|
|
|
// @param the extra param for scope.
|
2015-09-15 04:15:18 +00:00
|
|
|
// @data the extra data for scope.
|
2015-08-30 15:08:27 +00:00
|
|
|
// possible updates:
|
2015-09-15 04:15:18 +00:00
|
|
|
// @scope @value value-description
|
|
|
|
// listen 1935,1936 the port list.
|
|
|
|
// pid ./objs/srs.pid the pid file of srs.
|
|
|
|
// chunk_size 60000 the global RTMP chunk_size.
|
|
|
|
// ff_log_dir ./objs the dir for ffmpeg log.
|
|
|
|
// srs_log_tank file the tank to log, file or console.
|
|
|
|
// srs_log_level trace the level of log, verbose, info, trace, warn, error.
|
|
|
|
// srs_log_file ./objs/srs.log the log file when tank is file.
|
|
|
|
// max_connections 1000 the max connections of srs.
|
|
|
|
// utc_time false whether enable utc time.
|
|
|
|
// pithy_print_ms 10000 the pithy print interval in ms.
|
2015-09-12 13:55:53 +00:00
|
|
|
// vhost specified updates:
|
2015-09-15 04:15:18 +00:00
|
|
|
// @scope @value @param @data description
|
|
|
|
// vhost ossrs.net create - create vhost ossrs.net
|
|
|
|
// vhost ossrs.net update new.ossrs.net the new name to update vhost
|
2015-09-15 15:00:00 +00:00
|
|
|
// dvr specified updates:
|
|
|
|
// @scope @value @param @data description
|
|
|
|
// dvr ossrs.net enable live/livestream enable the dvr of stream
|
|
|
|
// dvr ossrs.net disable live/livestream disable the dvr of stream
|
2015-08-30 15:08:27 +00:00
|
|
|
if (rpc == "update") {
|
|
|
|
if (!allow_update) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED);
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string scope = r->query_get("scope");
|
|
|
|
std::string value = r->query_get("value");
|
2015-09-09 13:46:29 +00:00
|
|
|
if (scope.empty()) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED);
|
2015-09-09 13:46:29 +00:00
|
|
|
}
|
|
|
|
if (scope != "listen" && scope != "pid" && scope != "chunk_size"
|
2015-09-09 14:44:34 +00:00
|
|
|
&& scope != "ff_log_dir" && scope != "srs_log_tank" && scope != "srs_log_level"
|
2015-09-09 15:32:02 +00:00
|
|
|
&& scope != "srs_log_file" && scope != "max_connections" && scope != "utc_time"
|
2015-09-15 15:00:00 +00:00
|
|
|
&& scope != "pithy_print_ms" && scope != "vhost" && scope != "dvr"
|
2017-03-25 09:21:39 +00:00
|
|
|
) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED);
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 04:06:22 +00:00
|
|
|
bool applied = false;
|
2015-09-15 04:15:18 +00:00
|
|
|
string extra = "";
|
2015-09-01 13:27:04 +00:00
|
|
|
if (scope == "listen") {
|
2015-08-30 15:08:27 +00:00
|
|
|
vector<string> eps = srs_string_split(value, ",");
|
|
|
|
|
|
|
|
bool invalid = eps.empty();
|
|
|
|
for (int i = 0; i < (int)eps.size(); i++) {
|
|
|
|
string ep = eps.at(i);
|
|
|
|
int port = ::atoi(ep.c_str());
|
|
|
|
if (port <= 2 || port >= 65535) {
|
|
|
|
invalid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (invalid) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-08-30 15:18:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_listen(eps, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-31 15:34:03 +00:00
|
|
|
}
|
2015-09-01 13:27:04 +00:00
|
|
|
} else if (scope == "pid") {
|
2015-09-09 13:46:29 +00:00
|
|
|
if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".pid")) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-08-31 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_pid(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-01 13:27:04 +00:00
|
|
|
}
|
|
|
|
} else if (scope == "chunk_size") {
|
|
|
|
int csv = ::atoi(value.c_str());
|
|
|
|
if (csv < 128 || csv > 65535 || !srs_is_digit_number(value)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-01 13:27:04 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_chunk_size(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
2015-09-09 13:46:29 +00:00
|
|
|
} else if (scope == "ff_log_dir") {
|
|
|
|
if (value.empty() || (value != "/dev/null" && !srs_string_starts_with(value, "./", "/tmp/", "/var/"))) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-09 13:46:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_ff_log_dir(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
} else if (scope == "srs_log_tank") {
|
|
|
|
if (value.empty() || (value != "file" && value != "console")) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_srs_log_tank(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
} else if (scope == "srs_log_level") {
|
|
|
|
if (value != "verbose" && value != "info" && value != "trace" && value != "warn" && value != "error") {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_srs_log_level(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
} else if (scope == "srs_log_file") {
|
|
|
|
if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".log")) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_srs_log_file(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-09 13:46:29 +00:00
|
|
|
}
|
2015-09-09 15:32:02 +00:00
|
|
|
} else if (scope == "max_connections") {
|
|
|
|
int mcv = ::atoi(value.c_str());
|
|
|
|
if (mcv < 10 || mcv > 65535 || !srs_is_digit_number(value)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_max_connections(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
} else if (scope == "utc_time") {
|
|
|
|
if (!srs_is_boolean(value)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
if ((err = _srs_config->raw_set_utc_time(srs_config_bool2switch(value), applied)) != srs_success) {
|
|
|
|
return srs_api_response_code(w, r, srs_error_wrap(err, "raw api update utc_time=%s", value.c_str()));
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
} else if (scope == "pithy_print_ms") {
|
|
|
|
int ppmv = ::atoi(value.c_str());
|
|
|
|
if (ppmv < 100 || ppmv > 300000 || !srs_is_digit_number(value)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_set_pithy_print_ms(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
2015-09-12 13:55:53 +00:00
|
|
|
} else if (scope == "vhost") {
|
2015-09-15 04:15:18 +00:00
|
|
|
std::string param = r->query_get("param");
|
|
|
|
std::string data = r->query_get("data");
|
2015-09-15 04:51:14 +00:00
|
|
|
if (param != "create" && param != "update" && param != "delete" && param != "disable" && param != "enable") {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED);
|
2015-09-15 04:15:18 +00:00
|
|
|
}
|
|
|
|
extra += " " + param;
|
|
|
|
|
2015-09-12 13:55:53 +00:00
|
|
|
if (param == "create") {
|
|
|
|
// when create, the vhost must not exists.
|
|
|
|
if (param.empty() || _srs_config->get_vhost(value, false)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-12 13:55:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_create_vhost(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-12 13:55:53 +00:00
|
|
|
}
|
2015-09-15 04:15:18 +00:00
|
|
|
} else if (param == "update") {
|
|
|
|
extra += " to " + data;
|
|
|
|
|
|
|
|
// when update, the vhost must exists and disabled.
|
|
|
|
SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
|
|
|
|
if (data.empty() || data == value || param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-15 04:15:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_update_vhost(value, data, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-15 04:15:18 +00:00
|
|
|
}
|
|
|
|
} else if (param == "delete") {
|
|
|
|
// when delete, the vhost must exists and disabled.
|
|
|
|
SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
|
|
|
|
if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-15 04:15:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_delete_vhost(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-15 04:15:18 +00:00
|
|
|
}
|
2015-09-15 04:51:14 +00:00
|
|
|
} else if (param == "disable") {
|
|
|
|
// when disable, the vhost must exists and enabled.
|
|
|
|
SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
|
|
|
|
if (param.empty() || !vhost || !_srs_config->get_vhost_enabled(vhost)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_disable_vhost(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
|
|
|
} else if (param == "enable") {
|
|
|
|
// when enable, the vhost must exists and disabled.
|
|
|
|
SrsConfDirective* vhost = _srs_config->get_vhost(value, false);
|
|
|
|
if (param.empty() || !vhost || _srs_config->get_vhost_enabled(vhost)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
2015-09-15 04:15:18 +00:00
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_enable_vhost(value, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
2015-09-15 05:03:18 +00:00
|
|
|
} else {
|
|
|
|
// TODO: support other param.
|
2015-09-12 13:55:53 +00:00
|
|
|
}
|
2015-09-15 15:00:00 +00:00
|
|
|
} else if (scope == "dvr") {
|
|
|
|
std::string action = r->query_get("param");
|
|
|
|
std::string stream = r->query_get("data");
|
|
|
|
extra += "/" + stream + " to " + action;
|
|
|
|
|
|
|
|
if (action != "enable" && action != "disable") {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED);
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_srs_config->get_dvr_enabled(value)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED);
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (action == "enable") {
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_enable_dvr(value, stream, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = _srs_config->raw_disable_dvr(value, stream, applied)) != srs_success) {
|
|
|
|
int code = srs_error_code(err);
|
|
|
|
srs_error_reset(err);
|
|
|
|
return srs_api_response_code(w, r, code);
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-15 05:03:18 +00:00
|
|
|
} else {
|
|
|
|
// TODO: support other scope.
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 04:06:22 +00:00
|
|
|
// whether the config applied.
|
|
|
|
if (applied) {
|
|
|
|
server->on_signal(SRS_SIGNAL_PERSISTENCE_CONFIG);
|
2015-09-15 04:15:18 +00:00
|
|
|
srs_trace("raw api update %s=%s%s ok.", scope.c_str(), value.c_str(), extra.c_str());
|
2015-08-31 04:06:22 +00:00
|
|
|
} else {
|
2015-09-15 04:15:18 +00:00
|
|
|
srs_warn("raw api update not applied %s=%s%s.", scope.c_str(), value.c_str(), extra.c_str());
|
2015-08-31 04:06:22 +00:00
|
|
|
}
|
2015-08-30 15:18:14 +00:00
|
|
|
|
2015-09-19 05:37:56 +00:00
|
|
|
return srs_api_response(w, r, obj->dumps());
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
return err;
|
2015-08-27 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsGoApiRaw::on_reload_http_api_raw_api()
|
2015-08-28 04:28:18 +00:00
|
|
|
{
|
|
|
|
raw_api = _srs_config->get_raw_api();
|
|
|
|
allow_reload = _srs_config->get_raw_api_allow_reload();
|
2015-08-28 05:01:04 +00:00
|
|
|
allow_query = _srs_config->get_raw_api_allow_query();
|
2015-08-30 15:08:27 +00:00
|
|
|
allow_update = _srs_config->get_raw_api_allow_update();
|
2015-08-28 04:28:18 +00:00
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return srs_success;
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 12:55:34 +00:00
|
|
|
SrsGoApiClusters::SrsGoApiClusters()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsGoApiClusters::~SrsGoApiClusters()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
|
|
|
{
|
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
|
|
|
|
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
|
|
|
obj->set("data", data);
|
|
|
|
|
|
|
|
string ip = r->query_get("ip");
|
|
|
|
string vhost = r->query_get("vhost");
|
|
|
|
string app = r->query_get("app");
|
|
|
|
string stream = r->query_get("stream");
|
2019-12-01 11:24:17 +00:00
|
|
|
string coworker = r->query_get("coworker");
|
2018-02-15 12:55:34 +00:00
|
|
|
data->set("query", SrsJsonAny::object()
|
|
|
|
->set("ip", SrsJsonAny::str(ip.c_str()))
|
|
|
|
->set("vhost", SrsJsonAny::str(vhost.c_str()))
|
|
|
|
->set("app", SrsJsonAny::str(app.c_str()))
|
|
|
|
->set("stream", SrsJsonAny::str(stream.c_str())));
|
|
|
|
|
|
|
|
SrsCoWorkers* coworkers = SrsCoWorkers::instance();
|
2019-12-01 11:24:17 +00:00
|
|
|
data->set("origin", coworkers->dumps(vhost, coworker, app, stream));
|
2018-02-15 12:55:34 +00:00
|
|
|
|
|
|
|
return srs_api_response(w, r, obj->dumps());
|
|
|
|
}
|
|
|
|
|
2015-08-10 08:41:25 +00:00
|
|
|
SrsGoApiError::SrsGoApiError()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsGoApiError::~SrsGoApiError()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
2015-08-10 08:41:25 +00:00
|
|
|
{
|
2015-08-22 10:18:18 +00:00
|
|
|
return srs_api_response_code(w, r, 100);
|
2015-08-10 08:41:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 12:02:28 +00:00
|
|
|
#ifdef SRS_GPERF
|
2020-03-25 09:00:16 +00:00
|
|
|
#include <gperftools/malloc_extension.h>
|
|
|
|
|
|
|
|
SrsGoApiTcmalloc::SrsGoApiTcmalloc()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsGoApiTcmalloc::~SrsGoApiTcmalloc()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
srs_error_t SrsGoApiTcmalloc::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
|
|
|
{
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
|
|
|
string page = r->query_get("page");
|
2020-04-07 06:43:18 +00:00
|
|
|
srs_trace("query page=%s", page.c_str());
|
2020-03-25 09:00:16 +00:00
|
|
|
|
|
|
|
if (page == "summary") {
|
|
|
|
char buffer[32 * 1024];
|
|
|
|
MallocExtension::instance()->GetStats(buffer, sizeof(buffer));
|
|
|
|
|
|
|
|
string data(buffer);
|
|
|
|
if ((err = w->write((char*)data.data(), (int)data.length())) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write");
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// By default, response the json style response.
|
|
|
|
SrsJsonObject* obj = SrsJsonAny::object();
|
|
|
|
SrsAutoFree(SrsJsonObject, obj);
|
|
|
|
|
|
|
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
|
|
|
SrsJsonObject* data = SrsJsonAny::object();
|
|
|
|
obj->set("data", data);
|
|
|
|
|
2020-04-07 06:43:18 +00:00
|
|
|
if (true) {
|
|
|
|
SrsJsonObject* p = SrsJsonAny::object();
|
|
|
|
data->set("query", p);
|
|
|
|
|
|
|
|
p->set("page", SrsJsonAny::str(page.c_str()));
|
|
|
|
p->set("help", SrsJsonAny::str("?page=summary|detail"));
|
|
|
|
}
|
|
|
|
|
2020-03-25 09:00:16 +00:00
|
|
|
size_t value = 0;
|
|
|
|
|
|
|
|
// @see https://gperftools.github.io/gperftools/tcmalloc.html
|
|
|
|
data->set("release_rate", SrsJsonAny::number(MallocExtension::instance()->GetMemoryReleaseRate()));
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
SrsJsonObject* p = SrsJsonAny::object();
|
|
|
|
data->set("generic", p);
|
|
|
|
|
|
|
|
MallocExtension::instance()->GetNumericProperty("generic.current_allocated_bytes", &value);
|
|
|
|
p->set("current_allocated_bytes", SrsJsonAny::integer(value));
|
|
|
|
|
|
|
|
MallocExtension::instance()->GetNumericProperty("generic.heap_size", &value);
|
|
|
|
p->set("heap_size", SrsJsonAny::integer(value));
|
|
|
|
}
|
2020-03-30 16:39:10 +00:00
|
|
|
|
2020-03-25 09:00:16 +00:00
|
|
|
if (true) {
|
|
|
|
SrsJsonObject* p = SrsJsonAny::object();
|
|
|
|
data->set("tcmalloc", p);
|
|
|
|
|
|
|
|
MallocExtension::instance()->GetNumericProperty("tcmalloc.pageheap_free_bytes", &value);
|
|
|
|
p->set("pageheap_free_bytes", SrsJsonAny::integer(value));
|
|
|
|
|
|
|
|
MallocExtension::instance()->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", &value);
|
|
|
|
p->set("pageheap_unmapped_bytes", SrsJsonAny::integer(value));
|
|
|
|
|
|
|
|
MallocExtension::instance()->GetNumericProperty("tcmalloc.slack_bytes", &value);
|
|
|
|
p->set("slack_bytes", SrsJsonAny::integer(value));
|
|
|
|
|
|
|
|
MallocExtension::instance()->GetNumericProperty("tcmalloc.max_total_thread_cache_bytes", &value);
|
|
|
|
p->set("max_total_thread_cache_bytes", SrsJsonAny::integer(value));
|
|
|
|
|
|
|
|
MallocExtension::instance()->GetNumericProperty("tcmalloc.current_total_thread_cache_bytes", &value);
|
|
|
|
p->set("current_total_thread_cache_bytes", SrsJsonAny::integer(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return srs_api_response(w, r, obj->dumps());
|
|
|
|
}
|
2020-03-31 15:06:07 +00:00
|
|
|
#endif
|
|
|
|
|
2020-11-06 01:51:04 +00:00
|
|
|
SrsHttpApi::SrsHttpApi(bool https, ISrsResourceManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, string cip, int port)
|
2014-03-27 05:25:08 +00:00
|
|
|
{
|
2020-11-06 23:39:50 +00:00
|
|
|
// Create a identify for this client.
|
|
|
|
_srs_context->set_id(_srs_context->generate_id());
|
|
|
|
|
2020-11-05 03:47:24 +00:00
|
|
|
manager = cm;
|
2020-11-06 01:51:04 +00:00
|
|
|
skt = new SrsTcpConnection(fd);
|
2020-11-06 07:05:01 +00:00
|
|
|
|
|
|
|
if (https) {
|
|
|
|
ssl = new SrsSslConnection(skt);
|
|
|
|
conn = new SrsHttpConn(this, ssl, m, cip, port);
|
|
|
|
} else {
|
|
|
|
ssl = NULL;
|
|
|
|
conn = new SrsHttpConn(this, skt, m, cip, port);
|
|
|
|
}
|
2020-11-05 08:46:16 +00:00
|
|
|
|
2015-08-28 04:28:18 +00:00
|
|
|
_srs_config->subscribe(this);
|
2014-03-27 05:25:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 09:13:26 +00:00
|
|
|
SrsHttpApi::~SrsHttpApi()
|
2014-03-27 05:25:08 +00:00
|
|
|
{
|
2020-11-05 03:47:24 +00:00
|
|
|
_srs_config->unsubscribe(this);
|
|
|
|
|
2020-11-05 08:46:16 +00:00
|
|
|
srs_freep(conn);
|
2020-11-06 07:05:01 +00:00
|
|
|
srs_freep(ssl);
|
2020-11-06 01:51:04 +00:00
|
|
|
srs_freep(skt);
|
2015-03-08 11:59:10 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 09:16:59 +00:00
|
|
|
srs_error_t SrsHttpApi::on_start()
|
|
|
|
{
|
2020-11-05 09:57:22 +00:00
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
|
|
|
if ((err = conn->set_jsonp(true)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "set jsonp");
|
|
|
|
}
|
|
|
|
|
2020-11-06 23:39:50 +00:00
|
|
|
if (ssl) {
|
|
|
|
srs_utime_t starttime = srs_update_system_time();
|
|
|
|
string crt_file = _srs_config->get_https_api_ssl_cert();
|
|
|
|
string key_file = _srs_config->get_https_api_ssl_key();
|
|
|
|
if ((err = ssl->handshake(key_file, crt_file)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "handshake");
|
|
|
|
}
|
|
|
|
|
|
|
|
int cost = srsu2msi(srs_update_system_time() - starttime);
|
|
|
|
srs_trace("https: api server done, use key %s and cert %s, cost=%dms",
|
|
|
|
key_file.c_str(), crt_file.c_str(), cost);
|
|
|
|
}
|
2020-11-06 09:22:23 +00:00
|
|
|
|
2020-11-05 09:57:22 +00:00
|
|
|
return err;
|
2020-11-05 09:16:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 10:08:13 +00:00
|
|
|
srs_error_t SrsHttpApi::on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w)
|
2014-03-27 05:25:08 +00:00
|
|
|
{
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2020-07-13 05:52:23 +00:00
|
|
|
|
2020-11-06 07:05:01 +00:00
|
|
|
// After parsed the message, set the schema to https.
|
|
|
|
if (ssl) {
|
|
|
|
SrsHttpMessage* hm = dynamic_cast<SrsHttpMessage*>(r);
|
|
|
|
hm->set_https(true);
|
|
|
|
}
|
|
|
|
|
2020-11-05 10:08:13 +00:00
|
|
|
// TODO: For each API session, we use short-term HTTP connection.
|
|
|
|
//SrsHttpHeader* hdr = w->header();
|
|
|
|
//hdr->set("Connection", "Close");
|
|
|
|
|
2020-11-05 10:34:56 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
srs_error_t SrsHttpApi::on_message_done(ISrsHttpMessage* r, SrsHttpResponseWriter* w)
|
|
|
|
{
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
2020-11-05 08:46:16 +00:00
|
|
|
// read all rest bytes in request body.
|
|
|
|
char buf[SRS_HTTP_READ_CACHE_BYTES];
|
2020-11-05 10:08:13 +00:00
|
|
|
ISrsHttpResponseReader* br = r->body_reader();
|
2020-11-05 08:46:16 +00:00
|
|
|
while (!br->eof()) {
|
|
|
|
if ((err = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "read response");
|
2015-05-22 08:27:48 +00:00
|
|
|
}
|
2014-04-02 04:55:10 +00:00
|
|
|
}
|
2020-11-05 08:46:16 +00:00
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
return err;
|
2014-04-02 04:55:10 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 10:19:43 +00:00
|
|
|
srs_error_t SrsHttpApi::on_conn_done(srs_error_t r0)
|
2014-04-02 04:55:10 +00:00
|
|
|
{
|
2020-11-05 08:46:16 +00:00
|
|
|
// Because we use manager to manage this object,
|
|
|
|
// not the http connection object, so we must remove it here.
|
|
|
|
manager->remove(this);
|
2020-11-05 10:19:43 +00:00
|
|
|
|
|
|
|
// For HTTP-API timeout, we think it's done successfully,
|
|
|
|
// because there may be no request or response for HTTP-API.
|
|
|
|
if (srs_error_code(r0) == ERROR_SOCKET_TIMEOUT) {
|
|
|
|
srs_freep(r0);
|
|
|
|
return srs_success;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r0;
|
2014-03-27 04:14:04 +00:00
|
|
|
}
|
2014-04-01 08:06:32 +00:00
|
|
|
|
2020-11-05 08:46:16 +00:00
|
|
|
std::string SrsHttpApi::desc()
|
2015-08-28 04:28:18 +00:00
|
|
|
{
|
2020-11-06 01:51:04 +00:00
|
|
|
if (ssl) {
|
|
|
|
return "HttpsConn";
|
|
|
|
}
|
2020-11-05 08:46:16 +00:00
|
|
|
return "HttpConn";
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 08:46:16 +00:00
|
|
|
void SrsHttpApi::remark(int64_t* in, int64_t* out)
|
2020-11-05 03:47:24 +00:00
|
|
|
{
|
2020-11-05 08:46:16 +00:00
|
|
|
conn->remark(in, out);
|
2020-11-05 03:47:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 08:46:16 +00:00
|
|
|
srs_error_t SrsHttpApi::on_reload_http_api_crossdomain()
|
2020-11-05 03:47:24 +00:00
|
|
|
{
|
2020-11-05 08:46:16 +00:00
|
|
|
bool v = _srs_config->get_http_api_crossdomain();
|
|
|
|
return conn->set_crossdomain_enabled(v);
|
|
|
|
}
|
2020-11-05 03:47:24 +00:00
|
|
|
|
2020-11-05 08:46:16 +00:00
|
|
|
srs_error_t SrsHttpApi::start()
|
|
|
|
{
|
|
|
|
srs_error_t err = srs_success;
|
2020-11-05 03:47:24 +00:00
|
|
|
|
2020-11-05 08:46:16 +00:00
|
|
|
bool v = _srs_config->get_http_api_crossdomain();
|
|
|
|
if ((err = conn->set_crossdomain_enabled(v)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "set cors=%d", v);
|
2020-11-05 03:47:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 01:51:04 +00:00
|
|
|
if ((err = skt->initialize()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "init socket");
|
|
|
|
}
|
|
|
|
|
2020-11-05 08:46:16 +00:00
|
|
|
return conn->start();
|
2020-11-05 03:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string SrsHttpApi::remote_ip()
|
|
|
|
{
|
2020-11-05 08:46:16 +00:00
|
|
|
return conn->remote_ip();
|
2020-11-05 03:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SrsContextId& SrsHttpApi::get_id()
|
|
|
|
{
|
2020-11-05 08:46:16 +00:00
|
|
|
return conn->get_id();
|
2020-11-05 03:47:24 +00:00
|
|
|
}
|
|
|
|
|