2017-03-25 09:21:39 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2019-12-30 02:10:35 +00:00
|
|
|
* Copyright (c) 2013-2020 Winlin
|
2017-03-25 09:21:39 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2014-03-27 04:14:04 +00:00
|
|
|
|
|
|
|
#ifndef SRS_APP_HTTP_API_HPP
|
|
|
|
#define SRS_APP_HTTP_API_HPP
|
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2014-07-26 12:08:37 +00:00
|
|
|
class SrsStSocket;
|
2015-05-22 14:24:05 +00:00
|
|
|
class ISrsHttpMessage;
|
2014-04-02 04:55:10 +00:00
|
|
|
class SrsHttpParser;
|
2014-04-02 10:07:34 +00:00
|
|
|
class SrsHttpHandler;
|
2015-08-27 10:11:50 +00:00
|
|
|
class SrsServer;
|
2020-03-06 15:01:48 +00:00
|
|
|
class SrsRtcServer;
|
2020-03-21 11:00:47 +00:00
|
|
|
class SrsJsonObject;
|
2020-03-30 07:16:29 +00:00
|
|
|
class SrsSdp;
|
2020-05-04 12:42:30 +00:00
|
|
|
class SrsRequest;
|
2014-04-02 04:55:10 +00:00
|
|
|
|
2014-03-27 05:25:08 +00:00
|
|
|
#include <srs_app_st.hpp>
|
|
|
|
#include <srs_app_conn.hpp>
|
2015-05-22 14:34:03 +00:00
|
|
|
#include <srs_http_stack.hpp>
|
2015-08-28 04:28:18 +00:00
|
|
|
#include <srs_app_reload.hpp>
|
2014-04-02 10:07:34 +00:00
|
|
|
|
2019-04-30 00:24:52 +00:00
|
|
|
// For http root.
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiRoot : public ISrsHttpHandler
|
2014-04-02 10:07:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiRoot();
|
|
|
|
virtual ~SrsGoApiRoot();
|
2014-04-02 10:07:34 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-02 11:10:22 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiApi : public ISrsHttpHandler
|
2014-04-02 11:10:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiApi();
|
|
|
|
virtual ~SrsGoApiApi();
|
2014-04-02 11:10:22 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-02 10:07:34 +00:00
|
|
|
};
|
2014-03-27 05:25:08 +00:00
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiV1 : public ISrsHttpHandler
|
2014-04-03 04:08:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiV1();
|
|
|
|
virtual ~SrsGoApiV1();
|
2014-04-03 04:08:22 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-03 04:08:22 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiVersion : public ISrsHttpHandler
|
2014-05-18 09:57:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiVersion();
|
|
|
|
virtual ~SrsGoApiVersion();
|
2014-05-18 09:57:20 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-05-18 09:57:20 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiSummaries : public ISrsHttpHandler
|
2014-04-03 04:08:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSummaries();
|
|
|
|
virtual ~SrsGoApiSummaries();
|
2014-04-03 04:08:22 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-03 04:08:22 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiRusages : public ISrsHttpHandler
|
2014-04-19 13:23:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiRusages();
|
|
|
|
virtual ~SrsGoApiRusages();
|
2014-04-19 13:23:34 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-19 13:23:34 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiSelfProcStats : public ISrsHttpHandler
|
2014-04-19 13:23:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSelfProcStats();
|
|
|
|
virtual ~SrsGoApiSelfProcStats();
|
2014-04-19 13:23:34 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-19 13:23:34 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiSystemProcStats : public ISrsHttpHandler
|
2014-04-19 13:43:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiSystemProcStats();
|
|
|
|
virtual ~SrsGoApiSystemProcStats();
|
2014-04-19 13:43:13 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-19 13:43:13 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiMemInfos : public ISrsHttpHandler
|
2014-04-19 13:43:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiMemInfos();
|
|
|
|
virtual ~SrsGoApiMemInfos();
|
2014-04-19 13:43:13 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-19 13:43:13 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiAuthors : public ISrsHttpHandler
|
2014-04-19 16:15:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiAuthors();
|
|
|
|
virtual ~SrsGoApiAuthors();
|
2014-04-19 16:15:26 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-19 16:15:26 +00:00
|
|
|
};
|
|
|
|
|
2015-08-22 03:08:56 +00:00
|
|
|
class SrsGoApiFeatures : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsGoApiFeatures();
|
|
|
|
virtual ~SrsGoApiFeatures();
|
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2015-08-22 03:08:56 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiRequests : public ISrsHttpHandler
|
2014-04-03 05:48:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiRequests();
|
|
|
|
virtual ~SrsGoApiRequests();
|
2014-04-03 05:48:52 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2014-04-03 05:48:52 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiVhosts : public ISrsHttpHandler
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiVhosts();
|
|
|
|
virtual ~SrsGoApiVhosts();
|
2015-01-03 04:57:13 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2015-01-03 04:57:13 +00:00
|
|
|
};
|
|
|
|
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsGoApiStreams : public ISrsHttpHandler
|
2015-01-03 04:57:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-17 13:58:23 +00:00
|
|
|
SrsGoApiStreams();
|
|
|
|
virtual ~SrsGoApiStreams();
|
2015-01-03 04:57:13 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2015-01-03 04:57:13 +00:00
|
|
|
};
|
|
|
|
|
2020-04-29 12:02:28 +00:00
|
|
|
#ifdef SRS_RTC
|
2020-03-30 07:16:29 +00:00
|
|
|
class SrsGoApiRtcPlay : public ISrsHttpHandler
|
2020-02-21 15:50:22 +00:00
|
|
|
{
|
2020-03-30 07:16:29 +00:00
|
|
|
public:
|
|
|
|
static uint32_t ssrc_num;
|
2020-02-23 15:19:40 +00:00
|
|
|
private:
|
2020-05-03 05:49:53 +00:00
|
|
|
SrsRtcServer* server_;
|
2020-02-21 15:50:22 +00:00
|
|
|
public:
|
2020-05-03 05:49:53 +00:00
|
|
|
SrsGoApiRtcPlay(SrsRtcServer* server);
|
2020-03-30 07:16:29 +00:00
|
|
|
virtual ~SrsGoApiRtcPlay();
|
2020-02-21 15:50:22 +00:00
|
|
|
public:
|
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2020-03-21 11:00:47 +00:00
|
|
|
private:
|
|
|
|
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res);
|
2020-05-04 12:42:30 +00:00
|
|
|
srs_error_t exchange_sdp(SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp);
|
2020-03-30 07:16:29 +00:00
|
|
|
srs_error_t check_remote_sdp(const SrsSdp& remote_sdp);
|
2020-02-21 15:50:22 +00:00
|
|
|
};
|
2020-04-23 09:08:21 +00:00
|
|
|
|
|
|
|
class SrsGoApiRtcPublish : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static uint32_t ssrc_num;
|
|
|
|
private:
|
2020-05-03 05:49:53 +00:00
|
|
|
SrsRtcServer* server_;
|
2020-04-23 09:08:21 +00:00
|
|
|
public:
|
2020-05-03 05:49:53 +00:00
|
|
|
SrsGoApiRtcPublish(SrsRtcServer* server);
|
2020-04-23 09:08:21 +00:00
|
|
|
virtual ~SrsGoApiRtcPublish();
|
|
|
|
public:
|
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
|
|
|
private:
|
|
|
|
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res);
|
2020-05-04 12:42:30 +00:00
|
|
|
srs_error_t exchange_sdp(SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp);
|
2020-04-23 09:08:21 +00:00
|
|
|
srs_error_t check_remote_sdp(const SrsSdp& remote_sdp);
|
|
|
|
};
|
2020-05-04 06:47:58 +00:00
|
|
|
|
|
|
|
class SrsGoApiRtcNACK : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SrsRtcServer* server_;
|
|
|
|
public:
|
|
|
|
SrsGoApiRtcNACK(SrsRtcServer* server);
|
|
|
|
virtual ~SrsGoApiRtcNACK();
|
|
|
|
public:
|
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
|
|
|
private:
|
|
|
|
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res);
|
|
|
|
};
|
2020-03-22 10:17:05 +00:00
|
|
|
#endif
|
2020-02-21 15:50:22 +00:00
|
|
|
|
2015-08-21 08:12:48 +00:00
|
|
|
class SrsGoApiClients : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsGoApiClients();
|
|
|
|
virtual ~SrsGoApiClients();
|
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2015-08-21 08:12:48 +00:00
|
|
|
};
|
|
|
|
|
2015-08-28 04:28:18 +00:00
|
|
|
class SrsGoApiRaw : virtual public ISrsHttpHandler, virtual public ISrsReloadHandler
|
2015-08-27 10:11:50 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
SrsServer* server;
|
2015-08-28 04:28:18 +00:00
|
|
|
private:
|
|
|
|
bool raw_api;
|
|
|
|
bool allow_reload;
|
2015-08-28 05:01:04 +00:00
|
|
|
bool allow_query;
|
2015-08-30 15:08:27 +00:00
|
|
|
bool allow_update;
|
2015-08-27 10:11:50 +00:00
|
|
|
public:
|
|
|
|
SrsGoApiRaw(SrsServer* svr);
|
|
|
|
virtual ~SrsGoApiRaw();
|
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2019-04-30 00:30:13 +00:00
|
|
|
// Interface ISrsReloadHandler
|
2015-08-28 04:28:18 +00:00
|
|
|
public:
|
2017-09-22 08:14:30 +00:00
|
|
|
virtual srs_error_t on_reload_http_api_raw_api();
|
2015-08-27 10:11:50 +00:00
|
|
|
};
|
|
|
|
|
2018-02-15 12:55:34 +00:00
|
|
|
class SrsGoApiClusters : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsGoApiClusters();
|
|
|
|
virtual ~SrsGoApiClusters();
|
|
|
|
public:
|
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
|
|
|
};
|
|
|
|
|
2020-03-27 05:37:39 +00:00
|
|
|
class SrsGoApiPerf : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsGoApiPerf();
|
|
|
|
virtual ~SrsGoApiPerf();
|
|
|
|
public:
|
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
|
|
|
};
|
|
|
|
|
2015-08-10 08:41:25 +00:00
|
|
|
class SrsGoApiError : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsGoApiError();
|
|
|
|
virtual ~SrsGoApiError();
|
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2015-08-10 08:41:25 +00:00
|
|
|
};
|
|
|
|
|
2020-04-29 12:02:28 +00:00
|
|
|
#ifdef SRS_GB28181
|
2020-03-30 16:39:10 +00:00
|
|
|
class SrsGoApiGb28181 : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsGoApiGb28181();
|
|
|
|
virtual ~SrsGoApiGb28181();
|
|
|
|
public:
|
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2020-04-21 07:25:50 +00:00
|
|
|
private:
|
|
|
|
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2020-03-30 16:39:10 +00:00
|
|
|
};
|
2020-03-25 09:00:16 +00:00
|
|
|
#endif
|
2020-03-30 16:39:10 +00:00
|
|
|
|
2020-04-29 12:02:28 +00:00
|
|
|
#ifdef SRS_GPERF
|
2020-03-25 09:00:16 +00:00
|
|
|
class SrsGoApiTcmalloc : public ISrsHttpHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsGoApiTcmalloc();
|
|
|
|
virtual ~SrsGoApiTcmalloc();
|
|
|
|
public:
|
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
|
|
|
};
|
2020-03-31 15:06:07 +00:00
|
|
|
#endif
|
|
|
|
|
2015-08-28 04:28:18 +00:00
|
|
|
class SrsHttpApi : virtual public SrsConnection, virtual public ISrsReloadHandler
|
2014-03-27 04:14:04 +00:00
|
|
|
{
|
2014-04-02 04:55:10 +00:00
|
|
|
private:
|
|
|
|
SrsHttpParser* parser;
|
2016-12-15 07:00:08 +00:00
|
|
|
SrsHttpCorsMux* cors;
|
2015-03-04 05:09:35 +00:00
|
|
|
SrsHttpServeMux* mux;
|
2014-03-27 04:14:04 +00:00
|
|
|
public:
|
2017-05-30 01:05:02 +00:00
|
|
|
SrsHttpApi(IConnectionManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, std::string cip);
|
2014-03-27 04:14:04 +00:00
|
|
|
virtual ~SrsHttpApi();
|
2019-04-30 00:30:13 +00:00
|
|
|
// Interface ISrsKbpsDelta
|
2014-06-19 07:28:05 +00:00
|
|
|
public:
|
2019-01-01 09:36:27 +00:00
|
|
|
virtual void remark(int64_t* in, int64_t* out);
|
2014-03-27 05:25:08 +00:00
|
|
|
protected:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t do_cycle();
|
2014-04-02 04:55:10 +00:00
|
|
|
private:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2019-04-30 00:30:13 +00:00
|
|
|
// Interface ISrsReloadHandler
|
2015-08-28 04:28:18 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t on_reload_http_api_crossdomain();
|
2014-03-27 04:14:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2014-04-01 08:06:32 +00:00
|
|
|
|