37 int options, const
char **errorptr,
int *erroroffset, const
unsigned char *tables)
40 return pcre_compile(pattern, options, errorptr, erroroffset, tables);
46 return pcre_copy_substring(subject, ovector, stringcount, stringnumber, buffer, size);
57 const char *error = NULL;
65 if (!(field && expression)) {
69 if (*expression ==
'_') {
75 if (*expression ==
'/') {
77 tmp = strdup(expression + 1);
79 if ((opts = strrchr(tmp,
'/'))) {
84 "Regular Expression Error expression[%s] missing ending '/' delimeter\n", expression);
89 if (strchr(opts,
'i')) {
90 flags |= PCRE_CASELESS;
92 if (strchr(opts,
's')) {
98 re = pcre_compile(expression,
109 match_count = pcre_exec(re,
119 if (match_count <= 0) {
135 const char *replace = NULL;
140 for (x = 0; y < (len - 1) && x < strlen(data);) {
141 if (data[x] ==
'$') {
144 brace = data[x] ==
'{';
149 if (!(data[x] > 47 && data[x] < 58)) {
151 substituted[y++] = data[x - 1];
155 while (data[x] > 47 && data[x] < 58 && z <
sizeof(index) - 1) {
156 index[z++] = data[x];
160 if (data[x] !=
'}') {
162 substituted[y++] = data[x - 1];
173 if (num < 0 || num > 256) {
177 if (pcre_get_substring(field_data, ovector, match_count, num, &replace) > 0) {
179 for (r = 0; r < strlen(replace) && y < (len - 1); r++) {
180 substituted[y++] = replace[r];
182 pcre_free_substring(replace);
185 substituted[y++] = data[x];
189 substituted[y++] =
'\0';
202 for (i = 0; i < match_count; i++) {
203 if (pcre_get_substring(field_data, ovector, match_count, i, &replace) > 0) {
204 callback(var, replace, user_data);
205 pcre_free_substring(replace);
212 const char *error = NULL;
213 int error_offset = 0;
214 pcre *pcre_prepared = NULL;
216 int offset_vectors[255];
222 if (*expression ==
'/') {
224 tmp = strdup(expression + 1);
226 if ((opts = strrchr(tmp,
'/'))) {
231 "Regular Expression Error expression[%s] missing ending '/' delimeter\n", expression);
236 if (strchr(opts,
'i')) {
237 flags |= PCRE_CASELESS;
239 if (strchr(opts,
's')) {
240 flags |= PCRE_DOTALL;
246 pcre_prepared = pcre_compile(expression, flags, &error, &error_offset, NULL);
252 pcre_free(pcre_prepared);
253 pcre_prepared = NULL;
257 "Regular Expression Error expression[%s] error[%s] location[%d]\n", expression, error, error_offset);
264 pcre_flags = PCRE_PARTIAL;
269 pcre_exec(pcre_prepared, NULL, target, (
int) strlen(target), 0, pcre_flags, offset_vectors,
sizeof(offset_vectors) /
sizeof(offset_vectors[0]));
273 pcre_free(pcre_prepared);
274 pcre_prepared = NULL;
280 if (match_count > 0) {
283 }
else if (match_count == PCRE_ERROR_PARTIAL || match_count == PCRE_ERROR_BADPARTIAL) {
#define switch_regex_safe_free(re)
int switch_regex_copy_substring(const char *subject, int *ovector, int stringcount, int stringnumber, char *buffer, int size)
#define SWITCH_CHANNEL_LOG
void switch_perform_substitution(switch_regex_t *re, int match_count, const char *data, const char *field_data, char *substituted, switch_size_t len, int *ovector)
Representation of an event.
struct real_pcre switch_regex_t
switch_status_t switch_regex_match_partial(const char *target, const char *expression, int *partial)
Function to evaluate an expression against a string.
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_status_t switch_channel_add_variable_var_check(switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check, switch_stack_t stack)
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
int switch_regex_perform(const char *field, const char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
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)
switch_status_t
Common return values.
void switch_regex_set_var_callback(const char *var, const char *val, void *user_data)
#define switch_goto_status(_status, _label)
switch_regex_t * switch_regex_compile(const char *pattern, int options, const char **errorptr, int *erroroffset, const unsigned char *tables)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void(* switch_cap_callback_t)(const char *var, const char *val, void *user_data)
switch_bool_t switch_ast2regex(const char *pat, char *rbuf, size_t len)
void switch_regex_set_event_header_callback(const char *var, const char *val, void *user_data)
switch_status_t switch_regex_match(const char *target, const char *expression)
Function to evaluate an expression against a string.
void switch_regex_free(void *data)