add hook to implement ptql re when not compiled with pcre

This commit is contained in:
Doug MacEachern 2007-03-07 05:09:56 +00:00
parent 537863b3c3
commit b615e4b90c
3 changed files with 35 additions and 1 deletions

View File

@ -24,6 +24,7 @@
#endif #endif
#include "sigar_log.h" #include "sigar_log.h"
#include "sigar_ptql.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -54,6 +55,8 @@
int log_level; \ int log_level; \
void *log_data; \ void *log_data; \
sigar_log_impl_t log_impl; \ sigar_log_impl_t log_impl; \
void *ptql_re_data; \
sigar_ptql_re_impl_t ptql_re_impl; \
unsigned int ncpu; \ unsigned int ncpu; \
unsigned long version; \ unsigned long version; \
unsigned long boot_time; \ unsigned long boot_time; \

View File

@ -21,6 +21,11 @@
typedef struct sigar_ptql_query_t sigar_ptql_query_t; typedef struct sigar_ptql_query_t sigar_ptql_query_t;
typedef int (*sigar_ptql_re_impl_t)(void *, char *, char *);
SIGAR_DECLARE(void) sigar_ptql_re_impl_set(sigar_t *sigar, void *data,
sigar_ptql_re_impl_t impl);
SIGAR_DECLARE(int) sigar_ptql_query_create(sigar_ptql_query_t **query, SIGAR_DECLARE(int) sigar_ptql_query_create(sigar_ptql_query_t **query,
char *ptql); char *ptql);

View File

@ -20,6 +20,7 @@
#include "sigar_private.h" #include "sigar_private.h"
#include "sigar_util.h" #include "sigar_util.h"
#include "sigar_ptql.h" #include "sigar_ptql.h"
#include "sigar_os.h"
#ifdef SIGAR_HAS_PCRE #ifdef SIGAR_HAS_PCRE
#include "pcre.h" #include "pcre.h"
@ -1019,7 +1020,8 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed,
branch->value.ptr = re; branch->value.ptr = re;
branch->value_free = pcre_free; branch->value_free = pcre_free;
#else #else
return SIGAR_PTQL_MALFORMED_QUERY; branch->value.ptr = NULL;
branch->value_free = NULL;
#endif #endif
} }
@ -1127,6 +1129,13 @@ SIGAR_DECLARE(int) sigar_ptql_query_destroy(sigar_ptql_query_t *query)
return SIGAR_OK; return SIGAR_OK;
} }
SIGAR_DECLARE(void) sigar_ptql_re_impl_set(sigar_t *sigar, void *data,
sigar_ptql_re_impl_t impl)
{
sigar->ptql_re_data = data;
sigar->ptql_re_impl = impl;
}
SIGAR_DECLARE(int) sigar_ptql_query_match(sigar_t *sigar, SIGAR_DECLARE(int) sigar_ptql_query_match(sigar_t *sigar,
sigar_ptql_query_t *query, sigar_ptql_query_t *query,
sigar_pid_t query_pid) sigar_pid_t query_pid)
@ -1175,7 +1184,24 @@ SIGAR_DECLARE(int) sigar_ptql_query_match(sigar_t *sigar,
matched = ptql_branch_match_ref(branch, ref); matched = ptql_branch_match_ref(branch, ref);
} }
else { else {
#ifdef SIGAR_HAS_PCRE
matched = ptql_branch_match(branch); matched = ptql_branch_match(branch);
#else
if (branch->op_name == PTQL_OP_RE) {
if (sigar->ptql_re_impl) {
matched =
sigar->ptql_re_impl(sigar->ptql_re_data,
(char *)DATA_PTR(branch),
branch->value.str);
}
else {
matched = 0;
}
}
else {
matched = ptql_branch_match(branch);
}
#endif
} }
} }