15#define RESIPROCATE_SUBSYSTEM Subsystem::REPRO
21const std::regex_constants::syntax_option_type
DefaultFlags = std::regex_constants::ECMAScript;
23bool RouteStore::RouteOp::operator<(
const RouteOp& rhs)
const
25 return routeRecord.mOrder < rhs.routeRecord.mOrder;
32 while ( !key.
empty() )
35 route.routeRecord = mDb.
getRoute(key);
40 if(!route.routeRecord.mMatchingPattern.empty())
43 if(route.routeRecord.mRewriteExpression.find(
"$") ==
Data::npos)
45 flags |= std::regex_constants::nosubs;
49 route.preq =
new std::regex(route.routeRecord.mMatchingPattern.c_str(),
flags);
51 catch (std::regex_error& e)
54 ErrLog(<<
"Routing rule has invalid match expression: "
55 << route.routeRecord.mMatchingPattern
56 <<
", ex=" << e.what());
61 mRouteOperators.insert( route );
67 for (RouteOpList::iterator it = mRouteOperators.begin(); it != mRouteOperators.end();)
69 if (!it->key.prefix(
";"))
75 it = mRouteOperators.begin();
84 mCursor = mRouteOperators.begin();
89 for(RouteOpList::iterator i = mRouteOperators.begin(); i != mRouteOperators.end(); i++)
99 mRouteOperators.clear();
113 Key key = buildKey(method, event, matchingPattern, order);
115 if(findKey(key))
return false;
117 route.routeRecord.mMethod = method;
118 route.routeRecord.mEvent = event;
119 route.routeRecord.mMatchingPattern = matchingPattern;
120 route.routeRecord.mRewriteExpression = rewriteExpression;
121 route.routeRecord.mOrder = order;
123 if(!mDb.
addRoute(key, route.routeRecord))
130 if (!route.routeRecord.mMatchingPattern.empty())
133 if (route.routeRecord.mRewriteExpression.find(
"$") ==
Data::npos)
135 flags |= std::regex_constants::nosubs;
139 route.preq =
new std::regex(route.routeRecord.mMatchingPattern.c_str(),
flags);
141 catch (std::regex_error& e)
144 ErrLog(<<
"Routing rule has invalid match expression: "
145 << route.routeRecord.mMatchingPattern
146 <<
", ex=" << e.what());
153 mRouteOperators.insert( route );
155 mCursor = mRouteOperators.begin();
182 Key key = buildKey(method, event, matchingPattern, order);
194 RouteOpList::iterator it = mRouteOperators.begin();
195 while ( it != mRouteOperators.end() )
199 RouteOpList::iterator i = it;
208 mRouteOperators.erase(i);
216 mCursor = mRouteOperators.begin();
228 return addRoute(method, event, matchingPattern, rewriteExpression, order);
236 mCursor = mRouteOperators.begin();
237 if ( mCursor == mRouteOperators.end() )
246RouteStore::findKey(
const Key& key)
249 if ( mCursor != mRouteOperators.end() )
251 if ( mCursor->key == key )
258 mCursor = mRouteOperators.begin();
259 while ( mCursor != mRouteOperators.end() )
261 if ( mCursor->key == key )
282 if ( mCursor == mRouteOperators.end() )
299 return mCursor->routeRecord;
308 if(mRouteOperators.empty())
return targetSet;
314 for (RouteOpList::iterator it = mRouteOperators.begin();
315 it != mRouteOperators.end(); it++)
318 <<
" reqUri=" << ruri
319 <<
" method=" << method
320 <<
" event=" << event );
328 DebugLog( <<
" Skipped - method did not match" );
337 DebugLog( <<
" Skipped - event did not match" );
349 if(!std::regex_search(uri.
c_str(), matches, *it->preq))
352 DebugLog( <<
" Skipped - request URI "<< uri <<
" did not match " << match );
357 Data target = rewrite;
361 for (
int i=1; i<(int)matches.size(); i++)
363 Data subExp(matches[i]);
364 DebugLog( <<
" subExpression[" <<i <<
"]="<< subExp );
397 targetUri =
Uri(target);
401 ErrLog( <<
"Routing rule transform " << rewrite <<
" gave invalid URI " << target );
404 targetUri =
Uri(
Data(
"sip:")+target);
408 ErrLog( <<
"Routing rule transform " << rewrite <<
" gave invalid URI sip:" << target );
412 targetSet.push_back( targetUri );
423 const short order)
const
430 Data pKey =
";" +
Data((
int32_t)order) +
":" + method +
" : " +
event +
" : " + matchingPattern;
const std::regex_constants::syntax_option_type DefaultFlags
const std::regex_constants::syntax_option_type DefaultFlags
static const struct nv flags[]
resip::Data mRewriteExpression
resip::Data mMatchingPattern
virtual RouteRecord getRoute(const Key &key) const
virtual void eraseRoute(const Key &key)
virtual Key firstRouteKey()
virtual Key nextRouteKey()
virtual bool addRoute(const Key &key, const RouteRecord &rec)
std::vector< resip::Uri > UriList
UriList process(const resip::Uri &ruri, const resip::Data &method, const resip::Data &event)
bool addRoute(const resip::Data &method, const resip::Data &event, const resip::Data &matchingPattern, const resip::Data &rewriteExpression, const short order)
AbstractDb::RouteRecord getRouteRecord(const resip::Data &key)
void eraseRoute(const resip::Data &method, const resip::Data &event, const resip::Data &matchingPattern, const short order)
RouteStore(AbstractDb &db)
bool updateRoute(const resip::Data &originalKey, const resip::Data &method, const resip::Data &event, const resip::Data &matchingPattern, const resip::Data &rewriteExpression, const short order)
The abstract base-class for all exceptions thrown by resip code.
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
static const Data Empty
Constant that represents a zero-length data.
const char * c_str() const
Returns a null-terminated string representing.
bool empty() const noexcept
Checks whether the Data is empty.
static Data from(const T &x)
Converts from arbitrary other type to Data.
size_type find(const Data &match, size_type start=0) const
Finds a specified sequence of bytes in this Data.
static const size_type npos
Represents an impossible position; returned to indicate failure to find.
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToChars(const char *cs)
CurrentPosition position() const
CurrentPosition skipN(size_t count)
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)