X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmatch_regex.c;h=4fa6ce78d5d0c0007629a98e43fe4c5b3fbc2973;hb=81a5fd5046c6a39f580a8fc1a3af837fd5f5aa5c;hp=3b6db4337cdbd0b982cad7cbaa944fcedce3648d;hpb=ad4295bdbc56ad7286446b0b5d5e06c8c27b084a;p=collectd.git diff --git a/src/match_regex.c b/src/match_regex.c index 3b6db433..4fa6ce78 100644 --- a/src/match_regex.c +++ b/src/match_regex.c @@ -1,24 +1,29 @@ /** * collectd - src/match_regex.c - * Copyright (C) 2008 Sebastian Harl - * Copyright (C) 2008 Florian Forster + * Copyright (C) 2008 Sebastian Harl + * Copyright (C) 2008 Florian Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Sebastian Harl - * Florian Forster + * Florian Forster **/ /* @@ -58,7 +63,7 @@ struct mr_match_s mr_regex_t *plugin_instance; mr_regex_t *type; mr_regex_t *type_instance; - int invert; + _Bool invert; }; /* @@ -123,25 +128,6 @@ static int mr_match_regexen (mr_regex_t *re_head, /* {{{ */ return (FC_MATCH_MATCHES); } /* }}} int mr_match_regexen */ -static int mr_config_add_boolean (int *ret_value, /* {{{ */ - oconfig_item_t *ci) -{ - - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) - { - ERROR ("`regex' match: `%s' needs exactly one boolean argument.", - ci->key); - return (-1); - } - - if (ci->values[0].value.boolean) - *ret_value = 1; - else - *ret_value = 0; - - return (0); -} /* }}} int mv_config_add_boolean */ - static int mr_config_add_regex (mr_regex_t **re_head, /* {{{ */ oconfig_item_t *ci) { @@ -216,7 +202,7 @@ static int mr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ } memset (m, 0, sizeof (*m)); - m->invert = 0; + m->invert = 0; status = 0; for (i = 0; i < ci->children_num; i++) @@ -235,7 +221,7 @@ static int mr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ else if (strcasecmp ("TypeInstance", child->key) == 0) status = mr_config_add_regex (&m->type_instance, child); else if (strcasecmp ("Invert", child->key) == 0) - status = mr_config_add_boolean(&m->invert, child); + status = cf_util_get_boolean(child, &m->invert); else { log_err ("The `%s' configuration option is not understood and " @@ -287,21 +273,20 @@ static int mr_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */ void **user_data) { mr_match_t *m; + int match_value = FC_MATCH_MATCHES; + int nomatch_value = FC_MATCH_NO_MATCH; if ((user_data == NULL) || (*user_data == NULL)) return (-1); m = *user_data; - - int match_value = FC_MATCH_MATCHES; - int nomatch_value = FC_MATCH_NO_MATCH; - - if (m->invert) - { - match_value = FC_MATCH_NO_MATCH; - nomatch_value = FC_MATCH_MATCHES; - } - + + if (m->invert) + { + match_value = FC_MATCH_NO_MATCH; + nomatch_value = FC_MATCH_MATCHES; + } + if (mr_match_regexen (m->host, vl->host) == FC_MATCH_NO_MATCH) return (nomatch_value); if (mr_match_regexen (m->plugin, vl->plugin) == FC_MATCH_NO_MATCH)