X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftable.c;h=b0bc95f80bb90c5f999c525d17aa9d94bbc1d8b7;hb=939f4098d43c2934a9a97e076d64a7504613b872;hp=2911bf026a6405371f89a7719864e8a3c711fee0;hpb=3f0d178e58251171272a643e1667abcb9946edce;p=collectd.git diff --git a/src/table.c b/src/table.c index 2911bf02..b0bc95f8 100644 --- a/src/table.c +++ b/src/table.c @@ -1,19 +1,24 @@ /** * collectd - src/table.c - * Copyright (C) 2009 Sebastian Harl + * Copyright (C) 2009 Sebastian Harl * - * 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 @@ -37,12 +42,12 @@ */ typedef struct { - char *type; - char *instance_prefix; - int *instances; - size_t instances_num; - int *values; - size_t values_num; + char *type; + char *instance_prefix; + size_t *instances; + size_t instances_num; + size_t *values; + size_t values_num; const data_set_t *ds; } tbl_result_t; @@ -134,11 +139,11 @@ static int tbl_config_set_s (char *name, char **var, oconfig_item_t *ci) return 0; } /* tbl_config_set_separator */ -static int tbl_config_append_array_i (char *name, int **var, size_t *len, +static int tbl_config_append_array_i (char *name, size_t **var, size_t *len, oconfig_item_t *ci) { - int *tmp; - + size_t *tmp; + size_t num; size_t i; if (1 > ci->values_num) { @@ -146,26 +151,28 @@ static int tbl_config_append_array_i (char *name, int **var, size_t *len, return 1; } - for (i = 0; i < ci->values_num; ++i) { + num = (size_t) ci->values_num; + for (i = 0; i < num; ++i) { if (OCONFIG_TYPE_NUMBER != ci->values[i].type) { log_err ("\"%s\" expects numerical arguments only.", name); return 1; } } - *len += ci->values_num; - tmp = (int *)realloc (*var, *len * sizeof (**var)); + tmp = realloc (*var, ((*len) + num) * sizeof (**var)); if (NULL == tmp) { char errbuf[1024]; log_err ("realloc failed: %s.", sstrerror (errno, errbuf, sizeof (errbuf))); return -1; } - *var = tmp; - for (i = *len - ci->values_num; i < *len; ++i) - (*var)[i] = (int)ci->values[i].value.number; + for (i = 0; i < num; ++i) { + (*var)[*len] = (size_t) ci->values[i].value.number; + (*len)++; + } + return 0; } /* tbl_config_append_array_s */ @@ -174,7 +181,7 @@ static int tbl_config_result (tbl_t *tbl, oconfig_item_t *ci) tbl_result_t *res; int status = 0; - size_t i; + int i; if (0 != ci->values_num) { log_err (" does not expect any arguments."); @@ -261,7 +268,7 @@ static int tbl_config_table (oconfig_item_t *ci) tbl = tables + tables_num - 1; tbl_setup (tbl, ci->values[0].value.string); - for (i = 0; i < ci->children_num; ++i) { + for (i = 0; i < ((size_t) ci->children_num); ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "Separator")) @@ -278,8 +285,9 @@ static int tbl_config_table (oconfig_item_t *ci) if (NULL == tbl->sep) { log_err ("Table \"%s\" does not specify any separator.", tbl->file); status = 1; + } else { + strunescape (tbl->sep, strlen (tbl->sep) + 1); } - strunescape (tbl->sep, strlen (tbl->sep) + 1); if (NULL == tbl->instance) { tbl->instance = sstrdup (tbl->file); @@ -315,7 +323,7 @@ static int tbl_config_table (oconfig_item_t *ci) static int tbl_config (oconfig_item_t *ci) { - size_t i; + int i; for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; @@ -346,9 +354,9 @@ static int tbl_prepare (tbl_t *tbl) return -1; } - if (res->values_num != (size_t)res->ds->ds_num) { + if (res->values_num != res->ds->ds_num) { log_err ("Invalid type \"%s\". Expected %zu data source%s, " - "got %i.", res->type, res->values_num, + "got %zu.", res->type, res->values_num, (1 == res->values_num) ? "" : "s", res->ds->ds_num); return -1; @@ -383,7 +391,7 @@ static int tbl_result_dispatch (tbl_t *tbl, tbl_result_t *res, assert (res->values[i] < fields_num); value = fields[res->values[i]]; - if (0 != parse_value (value, &values[i], res->ds->ds[i])) + if (0 != parse_value (value, &values[i], res->ds->ds[i].type)) return -1; }