spring cleaning

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2007-03-29 22:31:56 +00:00
parent a021945cef
commit 3a54126261
143 changed files with 22413 additions and 31567 deletions

View File

@@ -32,49 +32,40 @@
#include <switch.h>
#include <pcre.h>
SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
int options,
const char **errorptr,
int *erroroffset,
const unsigned char *tables)
{
return pcre_compile(pattern, options, errorptr, erroroffset, tables);
}
SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject,
int *ovector,
int stringcount,
int stringnumber,
char *buffer,
int size)
SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
int options,
const char **errorptr,
int *erroroffset,
const unsigned char *tables)
{
return pcre_compile(pattern, options, errorptr, erroroffset, tables);
}
SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject,
int *ovector,
pcre_free(data);
}
SWITCH_DECLARE(int) switch_regex_perform(char *field, char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
int stringcount, int stringnumber, char *buffer, int size)
{
return pcre_copy_substring(subject, ovector, stringcount, stringnumber, buffer, size);
}
SWITCH_DECLARE(void) switch_regex_free(void *data)
{
pcre_free(data);
}
SWITCH_DECLARE(int) switch_regex_perform(char *field, char *expression, switch_regex_t **new_re, int *ovector,
uint32_t olen)
re = pcre_compile(expression, /* the pattern */
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
NULL); /* use default character tables */
{
const char *error = NULL;
int erroffset = 0;
pcre *re = NULL;
int match_count = 0;
if (!(field && expression)) {
return 0;
@@ -84,35 +75,36 @@ SWITCH_DECLARE(int) switch_regex_perform(char *field, char *expression, switch_r
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
(int) strlen(field), /* the length of the subject string */
NULL); /* use default character tables */
if (error) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s]\n", erroffset, error);
switch_regex_safe_free(re);
olen); /* number of elements (NOT size in bytes) */
return 0;
}
match_count = pcre_exec(re, /* result of pcre_compile() */
NULL, /* we didn't study the pattern */
field, /* the subject string */
(int) strlen(field), /* the length of the subject string */
*new_re = (switch_regex_t *)re;
0, /* start at offset 0 in the subject */
0, /* default options */
ovector, /* vector of integers for substring information */
olen); /* number of elements (NOT size in bytes) */
if (match_count <= 0) {
SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, char *data, char *field_data, char *substituted, uint32_t len, int *ovector)
switch_regex_safe_free(re);
match_count = 0;
}
*new_re = (switch_regex_t *) re;
return match_count;
for (x = 0; x < (len-1) && x < strlen(data);) {
}
SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, char *data, char *field_data,
char *substituted, uint32_t len, int *ovector)
substituted[y++] = data[x-1];
{
char index[10] = "";
char replace[1024] = "";
uint32_t x, y = 0, z = 0, num = 0;
@@ -123,13 +115,8 @@ SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_c
if (!(data[x] > 47 && data[x] < 58)) {
substituted[y++] = data[x - 1];
if (pcre_copy_substring(field_data,
ovector,
match_count,
num,
replace,
sizeof(replace)) > 0) {
continue;
}
while (data[x] > 47 && data[x] < 58) {
index[z++] = data[x];
@@ -142,14 +129,14 @@ SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_c
if (pcre_copy_substring(field_data, ovector, match_count, num, replace, sizeof(replace)) > 0) {
unsigned int r;
for (r = 0; r < strlen(replace); r++) {
SWITCH_DECLARE(switch_status_t) switch_regex_match(char *target, char *expression) {
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
int offset_vectors[2]; //not used, but has to exist or pcre won't even try to find a match
substituted[y++] = replace[r];
}
}
} else {
substituted[y++] = data[x];
x++;
}
}
substituted[y++] = '\0';
}
@@ -159,17 +146,19 @@ SWITCH_DECLARE(switch_status_t) switch_regex_match(char *target, char *expressio
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
}
//Note our error
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Regular Expression Error expression[%s] error[%s] location[%d]\n", expression, error, error_offset);
int offset_vectors[2]; //not used, but has to exist or pcre won't even try to find a match
//Compile the expression
pcre_prepared = pcre_compile(expression, 0, &error, &error_offset, NULL);
//See if there was an error in the expression
if (error != NULL) {
//Clean up after ourselves
if (pcre_prepared) {
pcre_free(pcre_prepared);
match_count = pcre_exec(pcre_prepared, NULL, target, (int) strlen(target), 0, 0, offset_vectors, sizeof(offset_vectors) / sizeof(offset_vectors[0]));
pcre_prepared = NULL;
}
//Note our error
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Regular Expression Error expression[%s] error[%s] location[%d]\n", expression, error,
error_offset);