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, ".", "\\.");
|
|
|
|
boost::replace_all(uri, "*", "\\w*");
|
|
|
|
uriRegexVec.push_back(regex(uri));
|
|
|
|
}
|
2015-11-09 00:51:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool sip::IncomingConnectionValidator::validateUri(std::string uri) {
|
2015-11-09 01:42:04 +01:00
|
|
|
regex addressRegex("[\"\\w ]*<sip:([\\w\\.]+@[\\w\\.]+)>");
|
|
|
|
|
|
|
|
smatch s;
|
|
|
|
|
|
|
|
if (not regex_match(uri, s, addressRegex)) {
|
|
|
|
logger.warn("URI has invalid format: %s", uri.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string rawAddress = s[1].str();
|
|
|
|
|
|
|
|
for (auto ® : uriRegexVec) {
|
|
|
|
if (regex_match(rawAddress, s, reg)) {
|
|
|
|
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
|
|
|
}
|