size_t ret_len;
if ((begin < 0) || (end < 0) || (begin >= end))
- return (NULL);
+ return NULL;
if ((size_t)end > (strlen(str) + 1)) {
ERROR("utils_match: match_substr: `end' points after end of string.");
- return (NULL);
+ return NULL;
}
ret_len = end - begin;
ret = malloc(ret_len + 1);
if (ret == NULL) {
ERROR("utils_match: match_substr: malloc failed.");
- return (NULL);
+ return NULL;
}
sstrncpy(ret, str + begin, ret_len + 1);
- return (ret);
+ return ret;
} /* char *match_substr */
static int default_callback(const char __attribute__((unused)) * str,
if (data->ds_type & UTILS_MATCH_CF_GAUGE_INC) {
data->value.gauge = isnan(data->value.gauge) ? 1 : data->value.gauge + 1;
data->values_num++;
- return (0);
+ return 0;
}
if (matches_num < 2)
- return (-1);
+ return -1;
value = (gauge_t)strtod(matches[1], &endptr);
if (matches[1] == endptr)
- return (-1);
+ return -1;
if (data->ds_type & UTILS_MATCH_CF_GAUGE_DIST) {
latency_counter_add(data->latency, DOUBLE_TO_CDTIME_T(value));
data->values_num++;
- return (0);
+ return 0;
}
if ((data->values_num == 0) ||
data->value.gauge += value;
} else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
- return (-1);
+ return -1;
}
data->values_num++;
if (data->ds_type & UTILS_MATCH_CF_COUNTER_INC) {
data->value.counter++;
data->values_num++;
- return (0);
+ return 0;
}
if (matches_num < 2)
- return (-1);
+ return -1;
value = (counter_t)strtoull(matches[1], &endptr, 0);
if (matches[1] == endptr)
- return (-1);
+ return -1;
if (data->ds_type & UTILS_MATCH_CF_COUNTER_SET)
data->value.counter = value;
data->value.counter += value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
- return (-1);
+ return -1;
}
data->values_num++;
if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC) {
data->value.derive++;
data->values_num++;
- return (0);
+ return 0;
}
if (matches_num < 2)
- return (-1);
+ return -1;
value = (derive_t)strtoll(matches[1], &endptr, 0);
if (matches[1] == endptr)
- return (-1);
+ return -1;
if (data->ds_type & UTILS_MATCH_CF_DERIVE_SET)
data->value.derive = value;
data->value.derive += value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
- return (-1);
+ return -1;
}
data->values_num++;
char *endptr = NULL;
if (matches_num < 2)
- return (-1);
+ return -1;
value = (absolute_t)strtoull(matches[1], &endptr, 0);
if (matches[1] == endptr)
- return (-1);
+ return -1;
if (data->ds_type & UTILS_MATCH_CF_ABSOLUTE_SET)
data->value.absolute = value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
- return (-1);
+ return -1;
}
data->values_num++;
} else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
} /* int default_callback */
static void match_simple_free(void *data) {
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
- return (NULL);
+ return NULL;
status = regcomp(&obj->regex, regex, REG_EXTENDED | REG_NEWLINE);
if (status != 0) {
ERROR("Compiling the regular expression \"%s\" failed.", regex);
sfree(obj);
- return (NULL);
+ return NULL;
}
obj->flags |= UTILS_MATCH_FLAGS_REGEX;
ERROR("Compiling the excluding regular expression \"%s\" failed.",
excluderegex);
sfree(obj);
- return (NULL);
+ return NULL;
}
obj->flags |= UTILS_MATCH_FLAGS_EXCLUDE_REGEX;
}
obj->user_data = user_data;
obj->free = free_user_data;
- return (obj);
+ return obj;
} /* cu_match_t *match_create_callback */
cu_match_t *match_create_simple(const char *regex, const char *excluderegex,
user_data = calloc(1, sizeof(*user_data));
if (user_data == NULL)
- return (NULL);
+ return NULL;
user_data->ds_type = match_ds_type;
if ((match_ds_type & UTILS_MATCH_DS_TYPE_GAUGE) &&
if (user_data->latency == NULL) {
ERROR("match_create_simple(): latency_counter_create() failed.");
free(user_data);
- return (NULL);
+ return NULL;
}
}
latency_counter_destroy(user_data->latency);
sfree(user_data);
- return (NULL);
+ return NULL;
}
- return (obj);
+ return obj;
} /* cu_match_t *match_create_simple */
void match_value_reset(cu_match_value_t *mv) {
/* Reset GAUGE metrics only and except GAUGE_PERSIST. */
if ((mv->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) &&
!(mv->ds_type & UTILS_MATCH_CF_GAUGE_PERSIST)) {
- mv->value.gauge = NAN;
+ mv->value.gauge = (mv->ds_type & UTILS_MATCH_CF_GAUGE_INC) ? 0 : NAN;
mv->values_num = 0;
}
} /* }}} void match_value_reset */
size_t matches_num;
if ((obj == NULL) || (str == NULL))
- return (-1);
+ return -1;
if (obj->flags & UTILS_MATCH_FLAGS_EXCLUDE_REGEX) {
status =
/* Regex did match, so exclude this line */
if (status == 0) {
DEBUG("ExludeRegex matched, don't count that line\n");
- return (0);
+ return 0;
}
}
/* Regex did not match */
if (status != 0)
- return (0);
+ return 0;
for (matches_num = 0; matches_num < STATIC_ARRAY_SIZE(matches);
matches_num++) {
sfree(matches[i]);
}
- return (status);
+ return status;
} /* int match_apply */
void *match_get_user_data(cu_match_t *obj) {
if (obj == NULL)
- return (NULL);
- return (obj->user_data);
+ return NULL;
+ return obj->user_data;
} /* void *match_get_user_data */