diff options
author | Stef Walter <stef@memberwebs.com> | 2006-03-30 00:35:39 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2006-03-30 00:35:39 +0000 |
commit | 1a8556d49b78ba9e2f366944183326efc027213d (patch) | |
tree | 73ec0091140ebd5cdaa93548f92afc4e93ccff85 | |
parent | 40bfafee2377c27bc01ffb4bb5e0e868611c6c28 (diff) |
Add support for strings, which should have us covered for the various data types.
-rw-r--r-- | module/bsnmp-regex.c | 79 | ||||
-rw-r--r-- | module/regex-tree.def | 3 |
2 files changed, 38 insertions, 44 deletions
diff --git a/module/bsnmp-regex.c b/module/bsnmp-regex.c index 49bda3e..3696820 100644 --- a/module/bsnmp-regex.c +++ b/module/bsnmp-regex.c @@ -77,7 +77,7 @@ static u_int reg_index = 0; enum { TYPE_UNKNOWN = 0, TYPE_COUNTER, - TYPE_INTEGER + TYPE_VALUE }; struct data_entry { @@ -96,7 +96,8 @@ struct data_entry { char *result; uint64_t last_update; - uint64_t value; + int64_t value_int; + char *value_str; }; TAILQ_HEAD(data_entry_list, data_entry); @@ -252,25 +253,34 @@ static int process_match (struct data_entry *data, char *result) { char *t; - int i; + int64_t i; switch(data->type) { + case TYPE_COUNTER: - data->value++; + data->value_int++; + if (result) + free (result); break; - case TYPE_INTEGER: + + case TYPE_VALUE: if (!result) { emsg ("match, but no result data for '%s'", data->descr); return -1; } - i = strtol (result, &t, 10); - if (*t) { - emsg ("invalid integer for '%s': %s", data->descr, result); - return -1; - } + /* Integer value */ + i = strtoll (result, &t, 10); + if (!*t) + data->value_int = i; + else + data->value_int = 0; + + /* String value */ + if (data->value_str) + free (data->value_str); + data->value_str = result; - data->value = i; break; default: @@ -281,8 +291,8 @@ process_match (struct data_entry *data, char *result) data->last_update = getcurrticks (); /* - fprintf(stderr, "updated '%s' to value '%lld' at '%lld'\n", - data->descr, data->value, data->last_update); + fprintf(stderr, "updated '%s' to value '%d' at '%lld'\n", + data->descr, data->value_str, data->last_update); */ return 0; @@ -420,7 +430,6 @@ process_log (char *line, int len) #endif process_match (data, result); - free (result); } } @@ -632,6 +641,9 @@ config_free (struct data_entry *data) regfree (&(data->regex)); #endif + if (data->value_str) + free (data->value_str); + free (data); } @@ -646,7 +658,7 @@ config_free_all () } static int -config_entry (struct data_entry *data, char *name, char type, char *regex, +config_entry (struct data_entry *data, char *name, char *regex, char *result, char *flags, int line) { #ifdef WITH_PCRE @@ -661,23 +673,10 @@ config_entry (struct data_entry *data, char *name, char type, char *regex, ASSERT (regex); ASSERT (flags); ASSERT (data); - ASSERT (type); ASSERT (name); - /* Figure out the type first */ - switch (type) { - case 'c': - data->type = TYPE_COUNTER; - break; - case 'i': - data->type = TYPE_INTEGER; - break; - case '\0': - return -2; - default: - emsg ("[line %d] invalid or unknown entry type: %c", line, type); - return -1; - } + /* No result area means this is a counter */ + data->type = result ? TYPE_VALUE : TYPE_COUNTER; /* Parse any options we have */ for (; *flags; flags++) { @@ -716,10 +715,6 @@ config_entry (struct data_entry *data, char *name, char type, char *regex, #endif /* Replacement data */ - if (data->type != TYPE_COUNTER && !result) { - emsg ("[line %d] no match text specified in entry", line); - return -1; - } data->result = result; return 0; @@ -732,7 +727,6 @@ config_line (char *name, char *value, int line) char *regex = NULL; char *result = NULL; char *flags = NULL; - char type; char delimiter; char *t; int r; @@ -740,11 +734,7 @@ config_line (char *name, char *value, int line) /* config_parse trims this for us */ ASSERT (!isspace(value[0])); - /* The type of entry */ - type = value[0]; - ++value; - - /* Next thing is the delimiter */ + /* First thing is the delimiter */ if (!*value) return -2; delimiter = value[0]; @@ -777,7 +767,7 @@ config_line (char *name, char *value, int line) } /* Now make an entry out of it all */ - r = config_entry (data, name, type, regex, result, flags, line); + r = config_entry (data, name, regex, result, flags, line); if (r < 0) { free (data); @@ -1067,10 +1057,13 @@ op_regexentry (struct snmp_context *ctx, struct snmp_value *value, } break; - case LEAF_regexValue: - value->v.uint32 = data->value; + case LEAF_regexInteger: + value->v.uint32 = data->value_int; break; + case LEAF_regexValue: + return (string_get (value, data->value_str ? data->value_str : "", -1)); + default: ASSERT(0); break; diff --git a/module/regex-tree.def b/module/regex-tree.def index 366dc0e..2a7b068 100644 --- a/module/regex-tree.def +++ b/module/regex-tree.def @@ -13,7 +13,8 @@ (1 regexIndex INTEGER GET) (2 regexDescr OCTETSTRING GET) (3 regexLast TIMETICKS GET) - (4 regexValue INTEGER GET) + (4 regexInteger INTEGER GET) + (5 regexValue OCTETSTRING GET) ) ) ) |