X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flibcollectdclient%2Fnetwork_buffer.c;h=7b06620479fafb6e369b0e05162a5963b9e44cc7;hb=67411e0794cfcab38e322b2ebbe2e5207cbdd86a;hp=e7b43ef7c7be820cb35d5671373b90527ebc5f46;hpb=6624c959628fa1188f8cfa4789da1eccccc5f5e4;p=collectd.git diff --git a/src/libcollectdclient/network_buffer.c b/src/libcollectdclient/network_buffer.c index e7b43ef7..7b066204 100644 --- a/src/libcollectdclient/network_buffer.c +++ b/src/libcollectdclient/network_buffer.c @@ -1,23 +1,27 @@ /** * collectd - src/libcollectdclient/network_buffer.c - * Copyright (C) 2010 Florian octo Forster + * Copyright (C) 2010-2012 Florian octo Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; only version 2.1 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 - * Lesser 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 Lesser 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: - * Florian octo Forster + * Florian octo Forster **/ #include "config.h" @@ -32,7 +36,24 @@ #include #if HAVE_LIBGCRYPT -#include +# include +# if defined __APPLE__ +/* default xcode compiler throws warnings even when deprecated functionality + * is not used. -Werror breaks the build because of erroneous warnings. + * http://stackoverflow.com/questions/10556299/compiler-warnings-with-libgcrypt-v1-5-0/12830209#12830209 + */ +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +# endif +/* FreeBSD's copy of libgcrypt extends the existing GCRYPT_NO_DEPRECATED + * to properly hide all deprecated functionality. + * http://svnweb.freebsd.org/ports/head/security/libgcrypt/files/patch-src__gcrypt.h.in + */ +# define GCRYPT_NO_DEPRECATED +# include +# if defined __APPLE__ +/* Re enable deprecation warnings */ +# pragma GCC diagnostic warning "-Wdeprecated-declarations" +# endif GCRY_THREAD_OPTION_PTHREAD_IMPL; #endif @@ -40,12 +61,14 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL; #define TYPE_HOST 0x0000 #define TYPE_TIME 0x0001 +#define TYPE_TIME_HR 0x0008 #define TYPE_PLUGIN 0x0002 #define TYPE_PLUGIN_INSTANCE 0x0003 #define TYPE_TYPE 0x0004 #define TYPE_TYPE_INSTANCE 0x0005 #define TYPE_VALUES 0x0006 #define TYPE_INTERVAL 0x0007 +#define TYPE_INTERVAL_HR 0x0009 /* Types to transmit notifications */ #define TYPE_MESSAGE 0x0100 @@ -83,9 +106,11 @@ struct lcc_network_buffer_s char *username; char *password; +#if HAVE_LIBGCRYPT gcry_cipher_hd_t encr_cypher; size_t encr_header_len; char encr_iv[16]; +#endif }; #define SSTRNCPY(dst,src,sz) do { \ @@ -105,6 +130,7 @@ static _Bool have_gcrypt (void) /* {{{ */ return (result); need_init = 0; +#if HAVE_LIBGCRYPT gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); if (!gcry_check_version (GCRYPT_VERSION)) @@ -115,8 +141,12 @@ static _Bool have_gcrypt (void) /* {{{ */ result = 1; return (1); +#else + return(0); +#endif } /* }}} _Bool have_gcrypt */ +#ifndef HAVE_HTONLL static uint64_t htonll (uint64_t val) /* {{{ */ { static int config = 0; @@ -146,6 +176,7 @@ static uint64_t htonll (uint64_t val) /* {{{ */ return ((((uint64_t) lo) << 32) | ((uint64_t) hi)); } /* }}} uint64_t htonll */ +#endif static double htond (double val) /* {{{ */ { @@ -342,6 +373,15 @@ static int nb_add_number (char **ret_buffer, /* {{{ */ return (0); } /* }}} int nb_add_number */ +static int nb_add_time (char **ret_buffer, /* {{{ */ + size_t *ret_buffer_len, + uint16_t type, double value) +{ + /* Convert to collectd's "cdtime" representation. */ + uint64_t cdtime_value = (uint64_t) (value * 1073741824.0); + return (nb_add_number (ret_buffer, ret_buffer_len, type, cdtime_value)); +} /* }}} int nb_add_time */ + static int nb_add_string (char **ret_buffer, /* {{{ */ size_t *ret_buffer_len, uint16_t type, const char *str, size_t str_len) @@ -442,16 +482,14 @@ static int nb_add_value_list (lcc_network_buffer_t *nb, /* {{{ */ if (nb->state.time != vl->time) { - if (nb_add_number (&buffer, &buffer_size, TYPE_TIME, - (uint64_t) vl->time)) + if (nb_add_time (&buffer, &buffer_size, TYPE_TIME_HR, vl->time)) return (-1); nb->state.time = vl->time; } if (nb->state.interval != vl->interval) { - if (nb_add_number (&buffer, &buffer_size, TYPE_INTERVAL, - (uint64_t) vl->interval)) + if (nb_add_time (&buffer, &buffer_size, TYPE_INTERVAL_HR, vl->interval)) return (-1); nb->state.interval = vl->interval; } @@ -464,6 +502,7 @@ static int nb_add_value_list (lcc_network_buffer_t *nb, /* {{{ */ return (0); } /* }}} int nb_add_value_list */ +#if HAVE_LIBGCRYPT static int nb_add_signature (lcc_network_buffer_t *nb) /* {{{ */ { char *buffer; @@ -590,6 +629,7 @@ static int nb_add_encryption (lcc_network_buffer_t *nb) /* {{{ */ return (0); } /* }}} int nb_add_encryption */ +#endif /* * Public functions @@ -690,6 +730,7 @@ int lcc_network_buffer_initialize (lcc_network_buffer_t *nb) /* {{{ */ nb->ptr = nb->buffer; nb->free = nb->size; +#if HAVE_LIBGCRYPT if (nb->seclevel == SIGN) { size_t username_len; @@ -735,6 +776,7 @@ int lcc_network_buffer_initialize (lcc_network_buffer_t *nb) /* {{{ */ ADD_GENERIC (nb, hash, sizeof (hash)); assert ((nb->encr_header_len + nb->free) == nb->size); } +#endif return (0); } /* }}} int lcc_network_buffer_initialize */ @@ -744,10 +786,12 @@ int lcc_network_buffer_finalize (lcc_network_buffer_t *nb) /* {{{ */ if (nb == NULL) return (EINVAL); +#if HAVE_LIBGCRYPT if (nb->seclevel == SIGN) nb_add_signature (nb); else if (nb->seclevel == ENCRYPT) nb_add_encryption (nb); +#endif return (0); } /* }}} int lcc_network_buffer_finalize */