-
Notifications
You must be signed in to change notification settings - Fork 33
/
IncomingConnectionValidator.cpp
42 lines (31 loc) · 1.24 KB
/
IncomingConnectionValidator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "IncomingConnectionValidator.hpp"
#include <boost/algorithm/string.hpp>
using namespace std;
sip::IncomingConnectionValidator::IncomingConnectionValidator(std::string validUriExpression)
: validUriExpression(validUriExpression),
logger(log4cpp::Category::getInstance("IncomingConnectionValidator")) {
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(boost::regex(uri));
}
}
bool sip::IncomingConnectionValidator::validateUri(std::string uri) {
boost::regex addressRegex("[\"\\+\\w\\. ]*<?sip:([\\+\\w\\.]+@[\\w\\.]+)>?");
boost::smatch s;
if (not boost::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 (boost::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;
}