1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-24 06:54:22 +00:00
srs/trunk/src/app/srs_app_refer.cpp

98 lines
3 KiB
C++
Raw Normal View History

2017-03-25 09:21:39 +00:00
/**
* The MIT License (MIT)
*
2017-03-25 13:29:29 +00:00
* Copyright (c) 2013-2017 OSSRS(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()
{
}
2013-11-23 03:36:07 +00:00
int SrsRefer::check(std::string page_url, SrsConfDirective* refer)
{
2014-03-18 03:32:58 +00:00
int ret = ERROR_SUCCESS;
if (!refer) {
srs_verbose("ignore refer check for page_url=%s", page_url.c_str());
return ret;
}
for (int i = 0; i < (int)refer->args.size(); i++) {
if ((ret = check_single_refer(page_url, refer->args.at(i))) == ERROR_SUCCESS) {
srs_verbose("check refer success. page_url=%s, refer=%s",
2017-03-25 09:21:39 +00:00
page_url.c_str(), refer->args.at(i).c_str());
2014-03-18 03:32:58 +00:00
return ret;
}
}
ret = ERROR_RTMP_ACCESS_DENIED;
srs_error("check refer failed. ret=%d", ret);
return ret;
2013-11-23 03:36:07 +00:00
}
int SrsRefer::check_single_refer(std::string page_url, std::string refer)
{
2014-03-18 03:32:58 +00:00
int ret = ERROR_SUCCESS;
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) {
ret = ERROR_RTMP_ACCESS_DENIED;
}
// match primary domain.
if (pos != domain_name.length() - refer.length()) {
ret = ERROR_RTMP_ACCESS_DENIED;
}
if (ret != ERROR_SUCCESS) {
srs_verbose("access denied, page_url=%s, domain_name=%s, refer=%s, ret=%d",
2017-03-25 09:21:39 +00:00
page_url.c_str(), domain_name.c_str(), refer.c_str(), ret);
2014-03-18 03:32:58 +00:00
}
return ret;
2013-11-23 03:36:07 +00:00
}
2014-08-02 14:18:39 +00:00