1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/src/app/srs_app_http_api.hpp

302 lines
8 KiB
C++
Raw Normal View History

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>
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;
class SrsJsonObject;
2020-03-30 07:16:29 +00:00
class SrsSdp;
2020-05-04 12:42:30 +00:00
class SrsRequest;
2020-05-17 11:40:45 +00:00
class ISrsHttpResponseWriter;
class SrsHttpConn;
2020-05-17 11:40:45 +00:00
#include <string>
2014-04-02 04:55:10 +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>
#include <srs_app_reload.hpp>
#include <srs_app_http_conn.hpp>
2014-04-02 10:07:34 +00:00
2020-05-17 11:40:45 +00:00
extern srs_error_t srs_api_response(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string json);
extern srs_error_t srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, int code);
extern srs_error_t srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, srs_error_t code);
2019-04-30 00:24:52 +00:00
// For http root.
class SrsGoApiRoot : public ISrsHttpHandler
2014-04-02 10:07:34 +00:00
{
public:
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);
};
class SrsGoApiApi : public ISrsHttpHandler
{
public:
SrsGoApiApi();
virtual ~SrsGoApiApi();
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
};
class SrsGoApiV1 : public ISrsHttpHandler
{
public:
SrsGoApiV1();
virtual ~SrsGoApiV1();
public:
2017-07-29 13:39:57 +00:00
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiVersion : public ISrsHttpHandler
{
public:
SrsGoApiVersion();
virtual ~SrsGoApiVersion();
public:
2017-07-29 13:39:57 +00:00
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiSummaries : public ISrsHttpHandler
{
public:
SrsGoApiSummaries();
virtual ~SrsGoApiSummaries();
public:
2017-07-29 13:39:57 +00:00
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiRusages : public ISrsHttpHandler
2014-04-19 13:23:34 +00:00
{
public:
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
};
class SrsGoApiSelfProcStats : public ISrsHttpHandler
2014-04-19 13:23:34 +00:00
{
public:
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
};
class SrsGoApiSystemProcStats : public ISrsHttpHandler
2014-04-19 13:43:13 +00:00
{
public:
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
};
class SrsGoApiMemInfos : public ISrsHttpHandler
2014-04-19 13:43:13 +00:00
{
public:
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
};
class SrsGoApiAuthors : public ISrsHttpHandler
2014-04-19 16:15:26 +00:00
{
public:
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
};
class SrsGoApiRequests : public ISrsHttpHandler
2014-04-03 05:48:52 +00:00
{
public:
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
};
class SrsGoApiVhosts : public ISrsHttpHandler
2015-01-03 04:57:13 +00:00
{
public:
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
};
class SrsGoApiStreams : public ISrsHttpHandler
2015-01-03 04:57:13 +00:00
{
public:
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
};
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);
};
class SrsGoApiRaw : virtual public ISrsHttpHandler, virtual public ISrsReloadHandler
2015-08-27 10:11:50 +00:00
{
private:
SrsServer* server;
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
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
};
#ifdef SRS_GB28181
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-25 09:00:16 +00:00
#endif
#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);
};
#endif
2020-11-05 03:47:24 +00:00
// Handle the HTTP API request.
class SrsHttpApi : virtual public ISrsStartableConneciton, virtual public ISrsHttpConnOwner
, virtual public ISrsReloadHandler
2014-03-27 04:14:04 +00:00
{
2014-04-02 04:55:10 +00:00
private:
2020-11-05 03:47:24 +00:00
// The manager object to manage the connection.
ISrsResourceManager* manager;
SrsHttpConn* conn;
2014-03-27 04:14:04 +00:00
public:
2020-09-19 02:30:05 +00:00
SrsHttpApi(ISrsResourceManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, std::string cip, int port);
2014-03-27 04:14:04 +00:00
virtual ~SrsHttpApi();
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual srs_error_t on_conn_done(srs_error_t r0);
2020-09-19 02:30:05 +00:00
// Interface ISrsResource.
public:
virtual std::string desc();
2019-04-30 00:30:13 +00:00
// Interface ISrsKbpsDelta
public:
2019-01-01 09:36:27 +00:00
virtual void remark(int64_t* in, int64_t* out);
2019-04-30 00:30:13 +00:00
// Interface ISrsReloadHandler
public:
2017-07-29 13:39:57 +00:00
virtual srs_error_t on_reload_http_api_crossdomain();
2020-11-05 03:47:24 +00:00
// Extract APIs from SrsTcpConnection.
// Interface ISrsStartable
public:
// Start the client green thread.
// when server get a client from listener,
// 1. server will create an concrete connection(for instance, RTMP connection),
// 2. then add connection to its connection manager,
// 3. start the client thread by invoke this start()
// when client cycle thread stop, invoke the on_thread_stop(), which will use server
// To remove the client by server->remove(this).
virtual srs_error_t start();
// Interface ISrsConnection.
public:
virtual std::string remote_ip();
virtual const SrsContextId& get_id();
2014-03-27 04:14:04 +00:00
};
#endif
2014-04-01 08:06:32 +00:00