mumsi/IncomingConnectionValidator.cpp

44 lines
1.3 KiB
C++
Raw Permalink Normal View History

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]*");
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) {
return true;
boost::regex addressRegex("[\"\\+\\w\\. ]*<?sip:([\\+\\w\\.]+@[\\w\\.]+)>?");
2015-11-09 01:42:04 +01:00
boost::smatch s;
2015-11-09 01:42:04 +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 &reg : uriRegexVec) {
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
}