mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-29 06:34:19 +00:00
PCRE2
This commit is contained in:
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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user