2015-11-09 00:51:51 +01:00
|
|
|
#include "IncomingConnectionValidator.hpp"
|
|
|
|
|
2015-11-09 01:42:04 +01:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2015-11-09 00:51:51 +01:00
|
|
|
sip::IncomingConnectionValidator::IncomingConnectionValidator(std::string validUriExpression)
|
|
|
|
: validUriExpression(validUriExpression),
|
|
|
|
logger(log4cpp::Category::getInstance("IncomingConnectionValidator")) {
|
|
|
|
|
2015-11-09 01:42:04 +01:00
|
|
|
vector<string> separateUris;
|
|
|
|
boost::split(separateUris, validUriExpression, boost::is_any_of("\t "));
|
|
|
|
for (auto &uri : separateUris) {
|
|
|
|
boost::replace_all(uri, ".", "\\.");
|
2016-04-18 01:46:54 +02:00
|
|
|
boost::replace_all(uri, "*", "[\\+\\.\\w]*");
|
2015-11-23 20:09:32 +01:00
|
|
|
uriRegexVec.push_back(boost::regex(uri));
|
2015-11-09 01:42:04 +01:00
|
|
|
}
|
2015-11-09 00:51:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool sip::IncomingConnectionValidator::validateUri(std::string uri) {
|
2018-08-25 18:20:30 +02:00
|
|
|
return true;
|
2016-04-02 20:04:33 +02:00
|
|
|
boost::regex addressRegex("[\"\\+\\w\\. ]*<?sip:([\\+\\w\\.]+@[\\w\\.]+)>?");
|
2015-11-09 01:42:04 +01:00
|
|
|
|
2015-11-23 20:09:32 +01:00
|
|
|
boost::smatch s;
|
2015-11-09 01:42:04 +01:00
|
|
|
|
2015-11-23 20:09:32 +01:00
|
|
|
if (not boost::regex_match(uri, s, addressRegex)) {
|
2015-11-09 01:42:04 +01:00
|
|
|
logger.warn("URI has invalid format: %s", uri.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string rawAddress = s[1].str();
|
|
|
|
|
|
|
|
for (auto ® : uriRegexVec) {
|
2015-11-23 20:09:32 +01:00
|
|
|
if (boost::regex_match(rawAddress, s, reg)) {
|
2015-11-09 01:42:04 +01:00
|
|
|
logger.info("URI %s is valid.", rawAddress.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("URI %s not valid.", rawAddress.c_str());
|
|
|
|
|
|
|
|
return false;
|
2015-11-09 00:51:51 +01:00
|
|
|
}
|