diff --git a/apps/sbc/ParamReplacer.cpp b/apps/sbc/ParamReplacer.cpp
index 13dfe6ad..628f36e1 100644
--- a/apps/sbc/ParamReplacer.cpp
+++ b/apps/sbc/ParamReplacer.cpp
@@ -28,6 +28,8 @@
#include "log.h"
#include "AmSipHeaders.h"
#include "AmUtils.h"
+#include "SBC.h" // for RegexMapper SBCFactory::regex_mappings
+
void replaceParsedParam(const string& s, size_t p,
AmUriParser& parsed, string& res) {
@@ -273,6 +275,53 @@ string replaceParameters(const string& s,
skip_chars = skip_p-p;
} break;
+ case 'M': { // regex map
+ if (s[p+1] != '(') {
+ WARN("Error parsing $M regex map replacement (missing '(')\n");
+ break;
+ }
+ if (s.length()
");
+ if (spos == string::npos) {
+ skip_chars = skip_p-p;
+ WARN("Error parsing $M regex map replacement: no => found in '%s'\n",
+ map_str.c_str());
+ break;
+ }
+
+ string map_val = map_str.substr(0, spos);
+ string map_val_replaced = replaceParameters(map_val, r_type, req, app_param,
+ ruri_parser, from_parser, to_parser);
+ string mapping_name = map_str.substr(spos+2);
+
+ string map_res;
+ if (SBCFactory::regex_mappings.
+ mapRegex(mapping_name, map_val_replaced.c_str(), map_res)) {
+ DBG("matched regex mapping '%s' (orig '%s) in '%s'\n",
+ map_val_replaced.c_str(), map_val.c_str(), mapping_name.c_str());
+ res+=map_res;
+ } else {
+ DBG("no match in regex mapping '%s' (orig '%s') in '%s'\n",
+ map_val_replaced.c_str(), map_val.c_str(), mapping_name.c_str());
+ }
+
+ skip_chars = skip_p-p;
+ } break;
+
default: {
WARN("unknown replace pattern $%c%c\n",
s[p], s[p+1]);
diff --git a/apps/sbc/RegexMapper.cpp b/apps/sbc/RegexMapper.cpp
new file mode 100644
index 00000000..8ca93e88
--- /dev/null
+++ b/apps/sbc/RegexMapper.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011 Stefan Sayer
+ *
+ * This file is part of SEMS, a free SIP media server.
+ *
+ * SEMS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * For a license to use the SEMS software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ * info@iptel.org
+ *
+ * SEMS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include "RegexMapper.h"
+#include "log.h"
+
+bool RegexMapper::mapRegex(const string& mapping_name, const char* test_s,
+ string& result) {
+ lock();
+ std::map::iterator it=regex_mappings.find(mapping_name);
+ if (it == regex_mappings.end()) {
+ unlock();
+ ERROR("regex mapping '%s' is not loaded!\n", mapping_name.c_str());
+ return false;
+ }
+
+ bool res = run_regex_mapping(it->second, test_s, result);
+ unlock();
+ return res;
+}
+
+void RegexMapper::setRegexMap(const string& mapping_name, const RegexMappingVector& r) {
+ lock();
+ std::map::iterator it=regex_mappings.find(mapping_name);
+ if (it != regex_mappings.end()) {
+ for (RegexMappingVector::iterator r_it =
+ it->second.begin(); r_it != it->second.end(); r_it++) {
+ regfree(&r_it->first);
+ }
+ }
+ regex_mappings[mapping_name] = r;
+ unlock();
+}
+
+std::vector RegexMapper::getNames() {
+ std::vector res;
+ lock();
+ for (std::map::iterator it=
+ regex_mappings.begin(); it != regex_mappings.end(); it++)
+ res.push_back(it->first);
+ unlock();
+ return res;
+}
+
diff --git a/apps/sbc/RegexMapper.h b/apps/sbc/RegexMapper.h
new file mode 100644
index 00000000..f35a0055
--- /dev/null
+++ b/apps/sbc/RegexMapper.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 Stefan Sayer
+ *
+ * This file is part of SEMS, a free SIP media server.
+ *
+ * SEMS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * For a license to use the SEMS software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ * info@iptel.org
+ *
+ * SEMS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _RegexMapper_h_
+#define _RegexMapper_h_
+
+#include "AmUtils.h"
+
+#include