2007-03-09 20:44:13 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2014-02-05 21:02:28 +00:00
|
|
|
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-09 20:44:13 +00:00
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Michael Jerris <mike@jerris.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Michael Jerris <mike@jerris.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_regex.c -- PCRE wrapper
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
#include <pcre.h>
|
2007-05-12 14:48:14 +00:00
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
|
2008-05-27 04:30:03 +00:00
|
|
|
int options, const char **errorptr, int *erroroffset, const unsigned char *tables)
|
2007-03-29 22:31:56 +00:00
|
|
|
{
|
2008-05-27 04:30:03 +00:00
|
|
|
|
|
|
|
return pcre_compile(pattern, options, errorptr, erroroffset, tables);
|
2007-05-12 14:48:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject, int *ovector, int stringcount, int stringnumber, char *buffer, int size)
|
2007-03-09 20:44:13 +00:00
|
|
|
{
|
|
|
|
return pcre_copy_substring(subject, ovector, stringcount, stringnumber, buffer, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(void) switch_regex_free(void *data)
|
|
|
|
{
|
2007-03-29 22:31:56 +00:00
|
|
|
pcre_free(data);
|
2007-05-12 14:48:14 +00:00
|
|
|
|
2008-05-27 04:30:03 +00:00
|
|
|
}
|
2007-05-12 14:48:14 +00:00
|
|
|
|
|
|
|
SWITCH_DECLARE(int) switch_regex_perform(const char *field, const char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
|
2007-03-09 20:44:13 +00:00
|
|
|
{
|
|
|
|
const char *error = NULL;
|
|
|
|
int erroffset = 0;
|
|
|
|
pcre *re = NULL;
|
|
|
|
int match_count = 0;
|
2007-11-14 14:18:24 +00:00
|
|
|
char *tmp = NULL;
|
|
|
|
uint32_t flags = 0;
|
2009-05-12 17:10:57 +00:00
|
|
|
char abuf[256] = "";
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2007-03-09 20:44:13 +00:00
|
|
|
if (!(field && expression)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-12 17:10:57 +00:00
|
|
|
if (*expression == '_') {
|
|
|
|
if (switch_ast2regex(expression + 1, abuf, sizeof(abuf))) {
|
|
|
|
expression = abuf;
|
|
|
|
}
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2007-11-14 15:16:03 +00:00
|
|
|
if (*expression == '/') {
|
2007-11-14 14:18:24 +00:00
|
|
|
char *opts = NULL;
|
|
|
|
tmp = strdup(expression + 1);
|
|
|
|
assert(tmp);
|
|
|
|
if ((opts = strrchr(tmp, '/'))) {
|
|
|
|
*opts++ = '\0';
|
2007-11-14 15:16:03 +00:00
|
|
|
} else {
|
2013-12-18 16:19:58 +00:00
|
|
|
/* Note our error */
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
|
|
|
"Regular Expression Error expression[%s] missing ending '/' delimeter\n", expression);
|
2007-11-14 15:16:03 +00:00
|
|
|
goto end;
|
2007-11-14 14:18:24 +00:00
|
|
|
}
|
|
|
|
expression = tmp;
|
|
|
|
if (opts) {
|
|
|
|
if (strchr(opts, 'i')) {
|
|
|
|
flags |= PCRE_CASELESS;
|
|
|
|
}
|
|
|
|
if (strchr(opts, 's')) {
|
|
|
|
flags |= PCRE_DOTALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
re = pcre_compile(expression, /* the pattern */
|
2008-05-27 04:30:03 +00:00
|
|
|
flags, /* default options */
|
2007-03-29 22:31:56 +00:00
|
|
|
&error, /* for error message */
|
|
|
|
&erroffset, /* for error offset */
|
|
|
|
NULL); /* use default character tables */
|
2007-03-09 20:44:13 +00:00
|
|
|
if (error) {
|
2008-01-19 21:54:11 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s][%s]\n", erroffset, error, expression);
|
2007-03-09 20:44:13 +00:00
|
|
|
switch_regex_safe_free(re);
|
2007-11-14 14:18:24 +00:00
|
|
|
goto end;
|
2007-03-09 20:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match_count = pcre_exec(re, /* result of pcre_compile() */
|
|
|
|
NULL, /* we didn't study the pattern */
|
|
|
|
field, /* the subject string */
|
2007-03-29 22:31:56 +00:00
|
|
|
(int) strlen(field), /* the length of the subject string */
|
2007-03-09 20:44:13 +00:00
|
|
|
0, /* start at offset 0 in the subject */
|
|
|
|
0, /* default options */
|
|
|
|
ovector, /* vector of integers for substring information */
|
2007-03-29 22:31:56 +00:00
|
|
|
olen); /* number of elements (NOT size in bytes) */
|
2007-03-09 20:44:13 +00:00
|
|
|
|
2007-12-10 16:27:48 +00:00
|
|
|
|
2007-03-09 20:44:13 +00:00
|
|
|
if (match_count <= 0) {
|
|
|
|
switch_regex_safe_free(re);
|
|
|
|
match_count = 0;
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
*new_re = (switch_regex_t *) re;
|
2007-03-09 20:44:13 +00:00
|
|
|
|
2008-05-27 04:30:03 +00:00
|
|
|
end:
|
2007-11-14 14:18:24 +00:00
|
|
|
switch_safe_free(tmp);
|
2007-03-09 20:44:13 +00:00
|
|
|
return match_count;
|
|
|
|
}
|
|
|
|
|
2007-05-12 14:48:14 +00:00
|
|
|
SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, const char *data, const char *field_data,
|
2007-11-10 12:25:54 +00:00
|
|
|
char *substituted, switch_size_t len, int *ovector)
|
2007-03-09 20:44:13 +00:00
|
|
|
{
|
|
|
|
char index[10] = "";
|
2011-05-25 20:42:36 +00:00
|
|
|
const char *replace = NULL;
|
2007-11-10 12:25:54 +00:00
|
|
|
switch_size_t x, y = 0, z = 0;
|
|
|
|
int num = 0;
|
--resolve FS-5566
When you use $12345 in regex substitutions, it isn't obvious
whenever you mean $1-concatenated-2345 or $12-concatenated-345
or any other variation. In all other languages, in order to
solve this ambiguity, a braces {} are allowed to be used to
separate variable name (or a reference) from surrounding text,
like ${1}2345 or ${12}345. Use the same for freeswitch too.
While at it, fix a buffer overflow as well: the index[] variable
which is used to copy the "variable" name is 10 chars long, but
it is used in the code without bounds checking, so a reference
which is >9 chars long ($1234567890) will overflow the buffer,
crashing freeswitch.
And another overflow is in the way how size of the "substituted"
variable is handled. First, in the outer loop, we compare the
wrong variable with the size of `substituted' buffer (amount of
bytes we took from the source instead of amount of bytes we
used in `substituted'). And second, when actual regex match
is being substitured, amount of room in `substituted' variable
is not checked at all.
Patch contributed by Michael Tokarev <mjt@tls.msk.ru>
2013-07-01 22:03:00 +00:00
|
|
|
int brace;
|
2007-03-09 20:44:13 +00:00
|
|
|
|
--resolve FS-5566
When you use $12345 in regex substitutions, it isn't obvious
whenever you mean $1-concatenated-2345 or $12-concatenated-345
or any other variation. In all other languages, in order to
solve this ambiguity, a braces {} are allowed to be used to
separate variable name (or a reference) from surrounding text,
like ${1}2345 or ${12}345. Use the same for freeswitch too.
While at it, fix a buffer overflow as well: the index[] variable
which is used to copy the "variable" name is 10 chars long, but
it is used in the code without bounds checking, so a reference
which is >9 chars long ($1234567890) will overflow the buffer,
crashing freeswitch.
And another overflow is in the way how size of the "substituted"
variable is handled. First, in the outer loop, we compare the
wrong variable with the size of `substituted' buffer (amount of
bytes we took from the source instead of amount of bytes we
used in `substituted'). And second, when actual regex match
is being substitured, amount of room in `substituted' variable
is not checked at all.
Patch contributed by Michael Tokarev <mjt@tls.msk.ru>
2013-07-01 22:03:00 +00:00
|
|
|
for (x = 0; y < (len - 1) && x < strlen(data);) {
|
2007-03-09 20:44:13 +00:00
|
|
|
if (data[x] == '$') {
|
|
|
|
x++;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
--resolve FS-5566
When you use $12345 in regex substitutions, it isn't obvious
whenever you mean $1-concatenated-2345 or $12-concatenated-345
or any other variation. In all other languages, in order to
solve this ambiguity, a braces {} are allowed to be used to
separate variable name (or a reference) from surrounding text,
like ${1}2345 or ${12}345. Use the same for freeswitch too.
While at it, fix a buffer overflow as well: the index[] variable
which is used to copy the "variable" name is 10 chars long, but
it is used in the code without bounds checking, so a reference
which is >9 chars long ($1234567890) will overflow the buffer,
crashing freeswitch.
And another overflow is in the way how size of the "substituted"
variable is handled. First, in the outer loop, we compare the
wrong variable with the size of `substituted' buffer (amount of
bytes we took from the source instead of amount of bytes we
used in `substituted'). And second, when actual regex match
is being substitured, amount of room in `substituted' variable
is not checked at all.
Patch contributed by Michael Tokarev <mjt@tls.msk.ru>
2013-07-01 22:03:00 +00:00
|
|
|
brace = data[x] == '{';
|
|
|
|
if (brace) {
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
|
2007-03-09 20:44:13 +00:00
|
|
|
if (!(data[x] > 47 && data[x] < 58)) {
|
--resolve FS-5566
When you use $12345 in regex substitutions, it isn't obvious
whenever you mean $1-concatenated-2345 or $12-concatenated-345
or any other variation. In all other languages, in order to
solve this ambiguity, a braces {} are allowed to be used to
separate variable name (or a reference) from surrounding text,
like ${1}2345 or ${12}345. Use the same for freeswitch too.
While at it, fix a buffer overflow as well: the index[] variable
which is used to copy the "variable" name is 10 chars long, but
it is used in the code without bounds checking, so a reference
which is >9 chars long ($1234567890) will overflow the buffer,
crashing freeswitch.
And another overflow is in the way how size of the "substituted"
variable is handled. First, in the outer loop, we compare the
wrong variable with the size of `substituted' buffer (amount of
bytes we took from the source instead of amount of bytes we
used in `substituted'). And second, when actual regex match
is being substitured, amount of room in `substituted' variable
is not checked at all.
Patch contributed by Michael Tokarev <mjt@tls.msk.ru>
2013-07-01 22:03:00 +00:00
|
|
|
x -= brace;
|
2007-03-29 22:31:56 +00:00
|
|
|
substituted[y++] = data[x - 1];
|
2007-03-09 20:44:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
--resolve FS-5566
When you use $12345 in regex substitutions, it isn't obvious
whenever you mean $1-concatenated-2345 or $12-concatenated-345
or any other variation. In all other languages, in order to
solve this ambiguity, a braces {} are allowed to be used to
separate variable name (or a reference) from surrounding text,
like ${1}2345 or ${12}345. Use the same for freeswitch too.
While at it, fix a buffer overflow as well: the index[] variable
which is used to copy the "variable" name is 10 chars long, but
it is used in the code without bounds checking, so a reference
which is >9 chars long ($1234567890) will overflow the buffer,
crashing freeswitch.
And another overflow is in the way how size of the "substituted"
variable is handled. First, in the outer loop, we compare the
wrong variable with the size of `substituted' buffer (amount of
bytes we took from the source instead of amount of bytes we
used in `substituted'). And second, when actual regex match
is being substitured, amount of room in `substituted' variable
is not checked at all.
Patch contributed by Michael Tokarev <mjt@tls.msk.ru>
2013-07-01 22:03:00 +00:00
|
|
|
while (data[x] > 47 && data[x] < 58 && z < sizeof(index) - 1) {
|
2007-03-09 20:44:13 +00:00
|
|
|
index[z++] = data[x];
|
|
|
|
x++;
|
|
|
|
}
|
--resolve FS-5566
When you use $12345 in regex substitutions, it isn't obvious
whenever you mean $1-concatenated-2345 or $12-concatenated-345
or any other variation. In all other languages, in order to
solve this ambiguity, a braces {} are allowed to be used to
separate variable name (or a reference) from surrounding text,
like ${1}2345 or ${12}345. Use the same for freeswitch too.
While at it, fix a buffer overflow as well: the index[] variable
which is used to copy the "variable" name is 10 chars long, but
it is used in the code without bounds checking, so a reference
which is >9 chars long ($1234567890) will overflow the buffer,
crashing freeswitch.
And another overflow is in the way how size of the "substituted"
variable is handled. First, in the outer loop, we compare the
wrong variable with the size of `substituted' buffer (amount of
bytes we took from the source instead of amount of bytes we
used in `substituted'). And second, when actual regex match
is being substitured, amount of room in `substituted' variable
is not checked at all.
Patch contributed by Michael Tokarev <mjt@tls.msk.ru>
2013-07-01 22:03:00 +00:00
|
|
|
if (brace) {
|
|
|
|
if (data[x] != '}') {
|
|
|
|
x -= z - 1;
|
|
|
|
substituted[y++] = data[x - 1];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
2007-03-09 20:44:13 +00:00
|
|
|
index[z++] = '\0';
|
|
|
|
z = 0;
|
2007-12-11 03:28:35 +00:00
|
|
|
num = atoi(index);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2008-05-19 21:33:52 +00:00
|
|
|
if (num < 0 || num > 256) {
|
|
|
|
num = -1;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2011-05-25 20:42:36 +00:00
|
|
|
if (pcre_get_substring(field_data, ovector, match_count, num, &replace) > 0) {
|
2007-11-10 12:25:54 +00:00
|
|
|
switch_size_t r;
|
--resolve FS-5566
When you use $12345 in regex substitutions, it isn't obvious
whenever you mean $1-concatenated-2345 or $12-concatenated-345
or any other variation. In all other languages, in order to
solve this ambiguity, a braces {} are allowed to be used to
separate variable name (or a reference) from surrounding text,
like ${1}2345 or ${12}345. Use the same for freeswitch too.
While at it, fix a buffer overflow as well: the index[] variable
which is used to copy the "variable" name is 10 chars long, but
it is used in the code without bounds checking, so a reference
which is >9 chars long ($1234567890) will overflow the buffer,
crashing freeswitch.
And another overflow is in the way how size of the "substituted"
variable is handled. First, in the outer loop, we compare the
wrong variable with the size of `substituted' buffer (amount of
bytes we took from the source instead of amount of bytes we
used in `substituted'). And second, when actual regex match
is being substitured, amount of room in `substituted' variable
is not checked at all.
Patch contributed by Michael Tokarev <mjt@tls.msk.ru>
2013-07-01 22:03:00 +00:00
|
|
|
for (r = 0; r < strlen(replace) && y < (len - 1); r++) {
|
2007-03-09 20:44:13 +00:00
|
|
|
substituted[y++] = replace[r];
|
|
|
|
}
|
2011-05-25 20:42:36 +00:00
|
|
|
pcre_free_substring(replace);
|
2007-03-09 20:44:13 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
substituted[y++] = data[x];
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
substituted[y++] = '\0';
|
|
|
|
}
|
2007-05-12 14:48:14 +00:00
|
|
|
|
2011-05-25 20:42:36 +00:00
|
|
|
|
|
|
|
SWITCH_DECLARE(void) switch_capture_regex(switch_regex_t *re, int match_count, const char *field_data,
|
|
|
|
int *ovector, const char *var, switch_cap_callback_t callback, void *user_data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
const char *replace;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < match_count; i++) {
|
|
|
|
if (pcre_get_substring(field_data, ovector, match_count, i, &replace) > 0) {
|
|
|
|
callback(var, replace, user_data);
|
|
|
|
pcre_free_substring(replace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-06 03:38:24 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_regex_match_partial(const char *target, const char *expression, int *partial)
|
2007-03-29 22:31:56 +00:00
|
|
|
{
|
2008-09-02 10:46:44 +00:00
|
|
|
const char *error = NULL; /* Used to hold any errors */
|
|
|
|
int error_offset = 0; /* Holds the offset of an error */
|
|
|
|
pcre *pcre_prepared = NULL; /* Holds the compiled regex */
|
|
|
|
int match_count = 0; /* Number of times the regex was matched */
|
2010-02-02 19:02:37 +00:00
|
|
|
int offset_vectors[255]; /* not used, but has to exist or pcre won't even try to find a match */
|
2008-09-23 16:05:12 +00:00
|
|
|
int pcre_flags = 0;
|
2013-12-18 16:19:58 +00:00
|
|
|
uint32_t flags = 0;
|
|
|
|
char *tmp = NULL;
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
if (*expression == '/') {
|
|
|
|
char *opts = NULL;
|
|
|
|
tmp = strdup(expression + 1);
|
|
|
|
assert(tmp);
|
|
|
|
if ((opts = strrchr(tmp, '/'))) {
|
|
|
|
*opts++ = '\0';
|
|
|
|
} else {
|
|
|
|
/* Note our error */
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
|
|
|
"Regular Expression Error expression[%s] missing ending '/' delimeter\n", expression);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
expression = tmp;
|
|
|
|
if (opts) {
|
|
|
|
if (strchr(opts, 'i')) {
|
|
|
|
flags |= PCRE_CASELESS;
|
|
|
|
}
|
|
|
|
if (strchr(opts, 's')) {
|
|
|
|
flags |= PCRE_DOTALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-09-02 10:46:44 +00:00
|
|
|
/* Compile the expression */
|
2013-12-18 16:19:58 +00:00
|
|
|
pcre_prepared = pcre_compile(expression, flags, &error, &error_offset, NULL);
|
2007-03-09 20:44:13 +00:00
|
|
|
|
2008-09-02 10:46:44 +00:00
|
|
|
/* See if there was an error in the expression */
|
2007-03-09 20:44:13 +00:00
|
|
|
if (error != NULL) {
|
2008-09-02 10:46:44 +00:00
|
|
|
/* Clean up after ourselves */
|
2007-03-09 20:44:13 +00:00
|
|
|
if (pcre_prepared) {
|
|
|
|
pcre_free(pcre_prepared);
|
|
|
|
pcre_prepared = NULL;
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
2008-09-02 10:46:44 +00:00
|
|
|
/* Note our error */
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
2007-03-30 00:13:31 +00:00
|
|
|
"Regular Expression Error expression[%s] error[%s] location[%d]\n", expression, error, error_offset);
|
2007-03-09 20:44:13 +00:00
|
|
|
|
2008-09-02 10:46:44 +00:00
|
|
|
/* We definitely didn't match anything */
|
2013-12-18 16:19:58 +00:00
|
|
|
goto end;
|
2007-03-09 20:44:13 +00:00
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-09-23 16:05:12 +00:00
|
|
|
if (*partial) {
|
|
|
|
pcre_flags = PCRE_PARTIAL;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2008-09-02 10:46:44 +00:00
|
|
|
/* So far so good, run the regex */
|
2010-02-06 03:38:24 +00:00
|
|
|
match_count =
|
|
|
|
pcre_exec(pcre_prepared, NULL, target, (int) strlen(target), 0, pcre_flags, offset_vectors, sizeof(offset_vectors) / sizeof(offset_vectors[0]));
|
2007-03-09 20:44:13 +00:00
|
|
|
|
2008-09-02 10:46:44 +00:00
|
|
|
/* Clean up */
|
2007-03-09 20:44:13 +00:00
|
|
|
if (pcre_prepared) {
|
|
|
|
pcre_free(pcre_prepared);
|
|
|
|
pcre_prepared = NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-02 01:36:50 +00:00
|
|
|
/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "number of matches: %d\n", match_count); */
|
2007-03-09 20:44:13 +00:00
|
|
|
|
2008-09-02 10:46:44 +00:00
|
|
|
/* Was it a match made in heaven? */
|
2007-03-09 20:44:13 +00:00
|
|
|
if (match_count > 0) {
|
2008-09-23 16:05:12 +00:00
|
|
|
*partial = 0;
|
2013-12-18 16:19:58 +00:00
|
|
|
switch_goto_status(SWITCH_STATUS_SUCCESS, end);
|
2010-09-23 18:33:33 +00:00
|
|
|
} else if (match_count == PCRE_ERROR_PARTIAL || match_count == PCRE_ERROR_BADPARTIAL) {
|
2008-09-23 16:05:12 +00:00
|
|
|
/* yes it is already set, but the code is clearer this way */
|
|
|
|
*partial = 1;
|
2013-12-18 16:19:58 +00:00
|
|
|
switch_goto_status(SWITCH_STATUS_SUCCESS, end);
|
2007-03-09 20:44:13 +00:00
|
|
|
} else {
|
2013-12-18 16:19:58 +00:00
|
|
|
goto end;
|
2007-03-09 20:44:13 +00:00
|
|
|
}
|
2013-12-18 16:19:58 +00:00
|
|
|
end:
|
|
|
|
switch_safe_free(tmp);
|
|
|
|
return status;
|
2007-03-09 20:44:13 +00:00
|
|
|
}
|
|
|
|
|
2008-09-23 16:05:12 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_regex_match(const char *target, const char *expression)
|
|
|
|
{
|
|
|
|
int partial = 0;
|
|
|
|
return switch_regex_match_partial(target, expression, &partial);
|
|
|
|
}
|
|
|
|
|
2011-06-01 15:48:42 +00:00
|
|
|
SWITCH_DECLARE_NONSTD(void) switch_regex_set_var_callback(const char *var, const char *val, void *user_data)
|
2011-05-25 21:12:42 +00:00
|
|
|
{
|
|
|
|
switch_core_session_t *session = (switch_core_session_t *) user_data;
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_channel_add_variable_var_check(channel, var, val, SWITCH_FALSE, SWITCH_STACK_PUSH);
|
|
|
|
}
|
|
|
|
|
2011-09-21 19:31:10 +00:00
|
|
|
SWITCH_DECLARE_NONSTD(void) switch_regex_set_event_header_callback(const char *var, const char *val, void *user_data)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch_event_t *event = (switch_event_t *) user_data;
|
|
|
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, var, val);
|
|
|
|
}
|
|
|
|
|
2011-05-25 21:12:42 +00:00
|
|
|
|
|
|
|
|
2007-03-09 20:44:13 +00:00
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2007-03-09 20:44:13 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2013-06-25 16:50:17 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
2007-03-09 20:44:13 +00:00
|
|
|
*/
|