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

@@ -2014,7 +2014,7 @@ SWITCH_STANDARD_API(replace_function)
SWITCH_STANDARD_API(regex_function)
{
switch_regex_t *re = NULL;
int ovector[30];
switch_regex_match_t *match_data = NULL;
int argc;
char *mydata = NULL, *argv[4];
size_t len = 0;
@@ -2054,7 +2054,7 @@ SWITCH_STANDARD_API(regex_function)
goto error;
}
proceed = switch_regex_perform(argv[0], argv[1], &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
proceed = switch_regex_perform(argv[0], argv[1], &re, &match_data);
if (argc > 2) {
char *flags = "";
@@ -2069,7 +2069,7 @@ SWITCH_STANDARD_API(regex_function)
switch_assert(substituted);
memset(substituted, 0, len);
switch_replace_char(argv[2], '%', '$', SWITCH_FALSE);
switch_perform_substitution(re, proceed, argv[2], argv[0], substituted, len, ovector);
switch_perform_substitution(match_data, argv[2], substituted, len);
stream->write_function(stream, "%s", substituted);
free(substituted);
@@ -2091,6 +2091,7 @@ SWITCH_STANDARD_API(regex_function)
error:
stream->write_function(stream, "-ERR");
ok:
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
@@ -3211,15 +3211,17 @@ SWITCH_STANDARD_APP(capture_function)
{
char *argv[3] = { 0 };
switch_regex_t *re = NULL;
int ovector[30] = {0};
switch_regex_match_t *match_data = NULL;
char *lbuf;
int proceed;
if (!zstr(data) && (lbuf = switch_core_session_strdup(session, data))
&& switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0]))) == 3) {
if ((proceed = switch_regex_perform(argv[1], argv[2], &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_capture_regex(re, proceed, argv[1], ovector, argv[0], switch_regex_set_var_callback, session);
if ((proceed = switch_regex_perform(argv[1], argv[2], &re, &match_data))) {
switch_capture_regex(match_data, proceed, argv[0], switch_regex_set_var_callback, session);
}
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No data specified.\n");
+11 -5
View File
@@ -365,7 +365,8 @@ static void parse_naptr(const ldns_rr *naptr, const char *number, enum_record_t
if (service && regex && replace) {
switch_regex_t *re = NULL, *re2 = NULL;
int proceed = 0, ovector[30];
switch_regex_match_t *match_data = NULL, *match_data2 = NULL;
int proceed = 0;
char *substituted = NULL;
char *substituted_2 = NULL;
char *orig_uri;
@@ -374,17 +375,18 @@ static void parse_naptr(const ldns_rr *naptr, const char *number, enum_record_t
int supported = 0;
uint32_t len = 0;
if ((proceed = switch_regex_perform(number, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ((proceed = switch_regex_perform(number, regex, &re, &match_data))) {
if (strchr(regex, '(')) {
len = (uint32_t) (strlen(number) + strlen(replace) + 10) * proceed;
if (!(substituted = malloc(len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
goto end;
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, replace, number, substituted, len, ovector);
switch_perform_substitution(match_data, replace, substituted, len);
orig_uri = substituted;
} else {
orig_uri = replace;
@@ -398,7 +400,7 @@ static void parse_naptr(const ldns_rr *naptr, const char *number, enum_record_t
continue;
}
if ((proceed = switch_regex_perform(uri, route->regex, &re2, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ((proceed = switch_regex_perform(uri, route->regex, &re2, &match_data2))) {
switch_event_t *event = NULL;
if (strchr(route->regex, '(')) {
@@ -406,6 +408,8 @@ static void parse_naptr(const ldns_rr *naptr, const char *number, enum_record_t
if (!(substituted_2 = malloc(len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
switch_safe_free(substituted);
switch_regex_match_safe_free(match_data);
switch_regex_match_safe_free(match_data2);
switch_regex_safe_free(re);
switch_regex_safe_free(re2);
switch_mutex_unlock(MUTEX);
@@ -413,7 +417,7 @@ static void parse_naptr(const ldns_rr *naptr, const char *number, enum_record_t
}
memset(substituted_2, 0, len);
switch_perform_substitution(re2, proceed, route->replace, uri, substituted_2, len, ovector);
switch_perform_substitution(match_data2, route->replace, substituted_2, len);
uri = substituted_2;
} else {
uri = route->replace;
@@ -434,6 +438,7 @@ static void parse_naptr(const ldns_rr *naptr, const char *number, enum_record_t
}
switch_safe_free(uri_expanded);
switch_safe_free(substituted_2);
switch_regex_match_safe_free(match_data2);
switch_regex_safe_free(re2);
}
switch_mutex_unlock(MUTEX);
@@ -443,6 +448,7 @@ static void parse_naptr(const ldns_rr *naptr, const char *number, enum_record_t
}
switch_safe_free(substituted);
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
}
}
+6 -3
View File
@@ -166,7 +166,8 @@ static void lcr_destroy(lcr_route route)
static const char *do_cid(switch_memory_pool_t *pool, const char *cid, const char *number, switch_core_session_t *session)
{
switch_regex_t *re = NULL;
int proceed = 0, ovector[30];
switch_regex_match_t *match_data = NULL;
int proceed = 0;
char *substituted = NULL;
uint32_t len = 0;
char *src = NULL;
@@ -230,23 +231,25 @@ static const char *do_cid(switch_memory_pool_t *pool, const char *cid, const cha
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "expanded src: %s, dst: %s\n", src, dst);
}
if ((proceed = switch_regex_perform(number, src, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ((proceed = switch_regex_perform(number, src, &re, &match_data))) {
len = (uint32_t) (strlen(src) + strlen(dst) + 10) * proceed; /* guestimate size */
if (!(substituted = switch_core_alloc(pool, len))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Memory Error!\n");
goto done;
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, dst, number, substituted, len, ovector);
switch_perform_substitution(match_data, dst, substituted, len);
} else {
goto done;
}
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
return substituted;
done:
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
switch_safe_free(tmp_regex);
return number;
+7 -4
View File
@@ -124,6 +124,7 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
int proceed = 0;
char *expression_expanded = NULL, *field_expanded = NULL;
switch_regex_t *re = NULL;
switch_regex_match_t *match_data = NULL;
const char *to = switch_event_get_header(event, "to");
const char *tzoff = NULL, *tzname_ = NULL;
int offset = 0;
@@ -143,7 +144,6 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
char *do_break_a = NULL;
char *expression = NULL;
const char *field_data = NULL;
int ovector[30];
switch_bool_t anti_action = SWITCH_TRUE;
break_t do_break_i = BREAK_ON_FALSE;
int time_match;
@@ -214,7 +214,7 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
field_data = "";
}
if ((proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ((proceed = switch_regex_perform(field_data, expression, &re, &match_data))) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s Regex (PASS) [%s] %s(%s) =~ /%s/ break=%s\n",
to, exten_name, field, field_data, expression, do_break_a ? do_break_a : "on-false");
@@ -271,7 +271,7 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
} else {
if (field && strchr(expression, '(')) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "DP_MATCH", NULL);
switch_capture_regex(re, proceed, field_data, ovector, "DP_MATCH", switch_regex_set_event_header_callback, event);
switch_capture_regex(match_data, proceed, "DP_MATCH", switch_regex_set_event_header_callback, event);
}
for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
@@ -297,7 +297,7 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
abort();
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, data, field_data, substituted, len, ovector);
switch_perform_substitution(match_data, data, substituted, len);
app_data = substituted;
} else {
app_data = data;
@@ -326,6 +326,8 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
switch_safe_free(substituted);
}
}
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
if (((anti_action == SWITCH_FALSE && do_break_i == BREAK_ON_TRUE) ||
@@ -335,6 +337,7 @@ static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_
}
done:
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
switch_safe_free(field_expanded);
switch_safe_free(expression_expanded);
@@ -170,9 +170,8 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
char *expression = NULL, expression_buf[1024] = { 0 };
char substituted[2048] = "";
const char *field_data = caller_profile->destination_number;
int proceed = 0;
switch_regex_t *re = NULL;
int ovector[30] = { 0 };
switch_regex_match_t *match_data = NULL;
char *cid = NULL;
expression = expression_buf;
@@ -221,7 +220,8 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
field_data = "";
}
if (!(proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if (!(switch_regex_perform(field_data, expression, &re, &match_data))) {
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
switch_safe_free(field_expanded);
continue;
@@ -267,10 +267,11 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
}
if (strchr(expression, '(')) {
switch_perform_substitution(re, proceed, argument, field_data, substituted, sizeof(substituted), ovector);
switch_perform_substitution(match_data, argument, substituted, sizeof(substituted));
argument = substituted;
}
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
if (!extension) {
@@ -103,6 +103,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
int proceed = 0, save_proceed = 0;
char *expression_expanded = NULL, *field_expanded = NULL;
switch_regex_t *re = NULL, *save_re = NULL;
switch_regex_match_t *match_data = NULL, *save_match_data = NULL;
int offset = 0;
const char *tmp, *tzoff = NULL, *tzname_ = NULL, *req_nesta = NULL;
char nbuf[128] = "";
@@ -170,7 +171,6 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
char *expression = NULL, *save_expression = NULL, *save_field_data = NULL;
char *regex_rule = NULL;
const char *field_data = NULL;
int ovector[30];
switch_bool_t anti_action = SWITCH_TRUE;
break_t do_break_i = BREAK_ON_FALSE;
int time_match;
@@ -292,7 +292,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
field_data = "";
}
if ((proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ((proceed = switch_regex_perform(field_data, expression, &re, &match_data))) {
if ( switch_core_test_flag(SCF_DIALPLAN_TIMESTAMPS) ) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"%sDialplan: %s Regex (PASS) [%s] %s(%s) =~ /%s/ match=%s\n", space,
@@ -344,20 +344,23 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
switch_snprintf(var, sizeof(var), "DP_REGEX_MATCH_%d", total);
switch_channel_set_variable(channel, var, NULL);
switch_capture_regex(re, proceed, field_data, ovector, var, switch_regex_set_var_callback, session);
switch_capture_regex(match_data, proceed, var, switch_regex_set_var_callback, session);
switch_safe_free(save_expression);
switch_safe_free(save_field_data);
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(save_re);
save_expression = strdup(expression);
save_field_data = strdup(field_data);
save_re = re;
save_match_data = match_data;
save_proceed = proceed;
re = NULL;
}
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
switch_safe_free(field_expanded);
@@ -406,7 +409,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
field_data = "";
}
if ((proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ((proceed = switch_regex_perform(field_data, expression, &re, &match_data))) {
if ( switch_core_test_flag(SCF_DIALPLAN_TIMESTAMPS) ) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"%sDialplan: %s Regex (PASS) [%s] %s(%s) =~ /%s/ break=%s\n", space,
@@ -446,7 +449,9 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
if (save_re) {
re = save_re;
match_data = save_match_data;
save_re = NULL;
save_match_data = NULL;
expression = expression_expanded = save_expression;
save_expression = NULL;
@@ -506,7 +511,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
} else {
if (field && expression && strchr(expression, '(')) {
switch_channel_set_variable(channel, "DP_MATCH", NULL);
switch_capture_regex(re, proceed, field_data, ovector, "DP_MATCH", switch_regex_set_var_callback, session);
switch_capture_regex(match_data, proceed, "DP_MATCH", switch_regex_set_var_callback, session);
}
for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
@@ -534,7 +539,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
goto done;
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, data, field_data, substituted, len, ovector);
switch_perform_substitution(match_data, data, substituted, len);
app_data = substituted;
} else {
app_data = data;
@@ -571,6 +576,8 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
switch_safe_free(substituted);
}
}
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
if (((anti_action == SWITCH_FALSE && do_break_i == BREAK_ON_TRUE) ||
@@ -591,6 +598,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
}
done:
switch_regex_match_safe_free(match_data);
switch_regex_safe_free(re);
switch_safe_free(field_expanded);
switch_safe_free(expression_expanded);
+1 -4
View File
@@ -911,8 +911,6 @@ char *sofia_glue_get_extra_headers(switch_channel_t *channel, const char *prefix
switch_stream_handle_t stream = { 0 };
switch_event_header_t *hi = NULL;
const char *exclude_regex = NULL;
switch_regex_t *re = NULL;
int ovector[30] = {0};
exclude_regex = switch_channel_get_variable(channel, "exclude_outgoing_extra_header");
SWITCH_STANDARD_STREAM(stream);
@@ -926,12 +924,11 @@ char *sofia_glue_get_extra_headers(switch_channel_t *channel, const char *prefix
}
if (!strncasecmp(name, prefix, strlen(prefix))) {
if ( !exclude_regex || !(/*proceed*/ switch_regex_perform(name, exclude_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ( !exclude_regex || !(/*proceed*/ switch_regex(name, exclude_regex))) {
const char *hname = name + strlen(prefix);
stream.write_function(&stream, "%s: %s\r\n", hname, value);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ignoring Extra Header [%s] , matches exclude_outgoing_extra_header [%s]\n", name, exclude_regex);
switch_regex_safe_free(re);
}
}
}
+1 -5
View File
@@ -1882,23 +1882,19 @@ authed:
if (vhost->rewrites) {
switch_event_header_t *rule = vhost->rewrites->headers;
switch_regex_t *re = NULL;
int ovector[30];
int proceed;
while(rule) {
char *expression = rule->name;
if ((proceed = switch_regex_perform(request->uri, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ((proceed = switch_regex(request->uri, expression))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"%d request [%s] matched expr [%s]\n", proceed, request->uri, expression);
request->uri = rule->value;
switch_regex_safe_free(re);
break;
}
rule = rule->next;
switch_regex_safe_free(re);
}
}
@@ -349,10 +349,7 @@ static void event_handler(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);
}
+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 {