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_refer.cpp

89 lines
2.6 KiB
C++
Raw Normal View History

2017-03-25 09:21:39 +00:00
/**
* The MIT License (MIT)
*
2019-01-01 13:37:28 +00:00
* Copyright (c) 2013-2019 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.
*/
2013-11-23 03:36:07 +00:00
#include <srs_app_refer.hpp>
2013-11-23 03:36:07 +00:00
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_app_config.hpp>
2013-11-23 03:36:07 +00:00
2014-06-27 05:40:17 +00:00
SrsRefer::SrsRefer()
{
}
SrsRefer::~SrsRefer()
{
}
2018-01-01 11:39:57 +00:00
srs_error_t SrsRefer::check(std::string page_url, SrsConfDirective* refer)
2013-11-23 03:36:07 +00:00
{
2018-01-01 11:39:57 +00:00
srs_error_t err = srs_success;
2014-03-18 03:32:58 +00:00
if (!refer) {
2018-01-01 11:39:57 +00:00
return err;
2014-03-18 03:32:58 +00:00
}
for (int i = 0; i < (int)refer->args.size(); i++) {
2018-01-01 11:39:57 +00:00
if ((err = check_single_refer(page_url, refer->args.at(i))) == srs_success) {
return srs_success;
2014-03-18 03:32:58 +00:00
}
2018-01-01 11:39:57 +00:00
srs_error_reset(err);
2014-03-18 03:32:58 +00:00
}
2018-01-01 11:39:57 +00:00
return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied");
2013-11-23 03:36:07 +00:00
}
2018-01-01 11:39:57 +00:00
srs_error_t SrsRefer::check_single_refer(std::string page_url, std::string refer)
2013-11-23 03:36:07 +00:00
{
2018-01-01 11:39:57 +00:00
srs_error_t err = srs_success;
2014-03-18 03:32:58 +00:00
size_t pos = std::string::npos;
std::string domain_name = page_url;
if ((pos = domain_name.find("://")) != std::string::npos) {
domain_name = domain_name.substr(pos + 3);
}
if ((pos = domain_name.find("/")) != std::string::npos) {
domain_name = domain_name.substr(0, pos);
}
if ((pos = domain_name.find(":")) != std::string::npos) {
domain_name = domain_name.substr(0, pos);
}
pos = domain_name.find(refer);
if (pos == std::string::npos) {
2018-01-01 11:39:57 +00:00
return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied");
2014-03-18 03:32:58 +00:00
}
// match primary domain.
if (pos != domain_name.length() - refer.length()) {
2018-01-01 11:39:57 +00:00
return srs_error_new(ERROR_RTMP_ACCESS_DENIED, "access denied");
2014-03-18 03:32:58 +00:00
}
2018-01-01 11:39:57 +00:00
return err;
2013-11-23 03:36:07 +00:00
}
2014-08-02 14:18:39 +00:00