This commit is contained in:
Andrey Volk committed 2025-07-12 01:13:24 +03:00
1 parent 98ce256d9f
commit 404822a890
28 files changed
+246 -171

No files matched your search

+1 -1
View File
@@ -46,9 +46,9 @@ class FSPCRE : public JSBase
{
private:
switch_regex_t *_re;
switch_regex_match_t *_match_data;
char *_str;
int _proceed;
int _ovector[30];
int _freed;
void Init();
@@ -138,10 +138,7 @@ void FSEventHandler::QueueEvent(switch_event_t *event)
}
if (*hp->value == '/') {
switch_regex_t *re = NULL;
int ovector[30];
cmp = !!switch_regex_perform(hval, comp_to, &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
switch_regex_safe_free(re);
cmp = !!switch_regex(hval, comp_to);
} else {
cmp = !strcasecmp(hval, comp_to);
}
+5 -4
View File
@@ -40,6 +40,7 @@ static const char js_class_name[] = "PCRE";
FSPCRE::~FSPCRE(void)
{
if (!_freed && _re) {
switch_regex_match_safe_free(_match_data);
switch_regex_safe_free(_re);
switch_safe_free(_str);
}
@@ -53,9 +54,9 @@ string FSPCRE::GetJSClassName()
void FSPCRE::Init()
{
_re = NULL;
_match_data = NULL;
_str = NULL;
_proceed = 0;
memset(&_ovector, 0, sizeof(_ovector));
_freed = 0;
}
@@ -74,11 +75,11 @@ JS_PCRE_FUNCTION_IMPL(Compile)
String::Utf8Value str2(info[1]);
string = js_safe_str(*str1);
regex_string = js_safe_str(*str2);
switch_regex_match_safe_free(this->_match_data);
switch_regex_safe_free(this->_re);
switch_safe_free(this->_str);
js_strdup(this->_str, string);
this->_proceed = switch_regex_perform(this->_str, regex_string, &this->_re, this->_ovector,
sizeof(this->_ovector) / sizeof(this->_ovector[0]));
this->_proceed = switch_regex_perform(this->_str, regex_string, &this->_re, &this->_match_data);
info.GetReturnValue().Set(this->_proceed ? true : false);
} else {
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid args"));
@@ -103,7 +104,7 @@ JS_PCRE_FUNCTION_IMPL(Substitute)
len = (uint32_t) (strlen(this->_str) + strlen(subst_string) + 10) * this->_proceed;
substituted = (char *)malloc(len);
switch_assert(substituted != NULL);
switch_perform_substitution(this->_re, this->_proceed, subst_string, this->_str, substituted, len, this->_ovector);
switch_perform_substitution(this->_match_data, subst_string, substituted, len);
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), substituted));
free(substituted);
} else {