1 /*
2  * Copyright (C) 2011 Stefan Sayer
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * For a license to use the SEMS software under conditions
12  * other than those described here, or to purchase support for this
13  * software, please contact iptel.org by e-mail at the following addresses:
14  *    info@iptel.org
15  *
16  * SEMS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
~DynRateLimit()22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25 #include "RegexMapper.h"
26 #include "log.h"
27 
28 bool RegexMapper::mapRegex(const string& mapping_name, const char* test_s,
29 			   string& result) {
30   lock();
31   std::map<string, RegexMappingVector>::iterator it=regex_mappings.find(mapping_name);
32   if (it == regex_mappings.end()) {
33     unlock();
34     ERROR("regex mapping '%s' is not loaded!\n", mapping_name.c_str());
35     return false;
36   }
37 
38   bool res = run_regex_mapping(it->second, test_s, result);
39   unlock();
40   return res;
41 }
42 
43 void RegexMapper::setRegexMap(const string& mapping_name, const RegexMappingVector& r) {
44   lock();
RateLimit(unsigned int rate,unsigned int peak,unsigned int time_base_ms)45   std::map<string, RegexMappingVector>::iterator it=regex_mappings.find(mapping_name);
46   if (it != regex_mappings.end()) {
47     for (RegexMappingVector::iterator r_it =
48 	   it->second.begin(); r_it != it->second.end(); r_it++) {
getRate()49       regfree(&r_it->first);
getPeak()50     }
51   }
52   regex_mappings[mapping_name] = r;
53   unlock();
54 }
55 
limit(unsigned int size)56 std::vector<std::string> RegexMapper::getNames() {
57   std::vector<std::string> res;
58   lock();
59   for (std::map<string, RegexMappingVector>::iterator it=
60 	 regex_mappings.begin(); it != regex_mappings.end(); it++)
61     res.push_back(it->first);
62   unlock();
63   return res;
64 }
65 
66