Merge branch 'collectd-5.5'
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Tue, 26 Jul 2016 10:50:36 +0000 (12:50 +0200)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Tue, 26 Jul 2016 10:50:36 +0000 (12:50 +0200)
1  2 
src/daemon/meta_data.c
src/network.c

diff --combined src/daemon/meta_data.c
@@@ -28,6 -28,8 +28,6 @@@
  #include "plugin.h"
  #include "meta_data.h"
  
 -#include <pthread.h>
 -
  /*
   * Data types
   */
@@@ -69,7 -71,7 +69,7 @@@ static char *md_strdup (const char *ori
      return (NULL);
  
    sz = strlen (orig) + 1;
 -  dest = (char *) malloc (sz);
 +  dest = malloc (sz);
    if (dest == NULL)
      return (NULL);
  
@@@ -82,12 -84,13 +82,12 @@@ static meta_entry_t *md_entry_alloc (co
  {
    meta_entry_t *e;
  
 -  e = (meta_entry_t *) malloc (sizeof (*e));
 +  e = calloc (1, sizeof (*e));
    if (e == NULL)
    {
 -    ERROR ("md_entry_alloc: malloc failed.");
 +    ERROR ("md_entry_alloc: calloc failed.");
      return (NULL);
    }
 -  memset (e, 0, sizeof (*e));
  
    e->key = md_strdup (key);
    if (e->key == NULL)
    return (e);
  } /* }}} meta_entry_t *md_entry_alloc */
  
 -static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */
 +/* XXX: The lock on md must be held while calling this function! */
 +static meta_entry_t *md_entry_clone_contents (const meta_entry_t *orig) /* {{{ */
  {
    meta_entry_t *copy;
  
 -  if (orig == NULL)
 -    return (NULL);
 +  /* WARNINGS :
 +   *  - we do not check that orig != NULL here. You should have done it before.
 +   *  - we do not set copy->next. DO NOT FORGET TO SET copy->next IN YOUR FUNCTION
 +   */
  
    copy = md_entry_alloc (orig->key);
    if (copy == NULL)
    else
      copy->value = orig->value;
  
 +  return (copy);
 +} /* }}} meta_entry_t *md_entry_clone_contents */
 +
 +static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */
 +{
 +  meta_entry_t *copy;
 +
 +  if (orig == NULL)
 +    return (NULL);
 +
 +  copy = md_entry_clone_contents(orig);
 +
    copy->next = md_entry_clone (orig->next);
    return (copy);
  } /* }}} meta_entry_t *md_entry_clone */
@@@ -210,63 -198,6 +210,63 @@@ static int md_entry_insert (meta_data_
  } /* }}} int md_entry_insert */
  
  /* XXX: The lock on md must be held while calling this function! */
 +static int md_entry_insert_clone (meta_data_t *md, meta_entry_t *orig) /* {{{ */
 +{
 +  meta_entry_t *e;
 +  meta_entry_t *this;
 +  meta_entry_t *prev;
 +
 +  /* WARNINGS :
 +   *  - we do not check that md and e != NULL here. You should have done it before.
 +   *  - we do not use the lock. You should have set it before.
 +   */
 +
 +  e = md_entry_clone_contents(orig);
 +
 +  prev = NULL;
 +  this = md->head;
 +  while (this != NULL)
 +  {
 +    if (strcasecmp (e->key, this->key) == 0)
 +      break;
 +
 +    prev = this;
 +    this = this->next;
 +  }
 +
 +  if (this == NULL)
 +  {
 +    /* This key does not exist yet. */
 +    if (md->head == NULL)
 +      md->head = e;
 +    else
 +    {
 +      assert (prev != NULL);
 +      prev->next = e;
 +    }
 +
 +    e->next = NULL;
 +  }
 +  else /* (this != NULL) */
 +  {
 +    if (prev == NULL)
 +      md->head = e;
 +    else
 +      prev->next = e;
 +
 +    e->next = this->next;
 +  }
 +
 +  if (this != NULL)
 +  {
 +    this->next = NULL;
 +    md_entry_free (this);
 +  }
 +
 +  return (0);
 +} /* }}} int md_entry_insert_clone */
 +
 +/* XXX: The lock on md must be held while calling this function! */
  static meta_entry_t *md_entry_lookup (meta_data_t *md, /* {{{ */
      const char *key)
  {
  } /* }}} meta_entry_t *md_entry_lookup */
  
  /*
+  * Each value_list_t*, as it is going through the system, is handled by exactly
+  * one thread. Plugins which pass a value_list_t* to another thread, e.g. the
+  * rrdtool plugin, must create a copy first. The meta data within a
+  * value_list_t* is not thread safe and doesn't need to be.
+  *
+  * The meta data associated with cache entries are a different story. There, we
+  * need to ensure exclusive locking to prevent leaks and other funky business.
+  * This is ensured by the uc_meta_data_get_*() functions.
+  */
+ /*
   * Public functions
   */
  meta_data_t *meta_data_create (void) /* {{{ */
  {
    meta_data_t *md;
  
 -  md = (meta_data_t *) malloc (sizeof (*md));
 +  md = calloc (1, sizeof (*md));
    if (md == NULL)
    {
 -    ERROR ("meta_data_create: malloc failed.");
 +    ERROR ("meta_data_create: calloc failed.");
      return (NULL);
    }
 -  memset (md, 0, sizeof (*md));
  
 -  md->head = NULL;
    pthread_mutex_init (&md->lock, /* attr = */ NULL);
  
    return (md);
@@@ -319,28 -263,6 +330,28 @@@ meta_data_t *meta_data_clone (meta_data
    return (copy);
  } /* }}} meta_data_t *meta_data_clone */
  
 +int meta_data_clone_merge (meta_data_t **dest, meta_data_t *orig) /* {{{ */
 +{
 +  meta_entry_t *e;
 +
 +  if (orig == NULL)
 +    return (0);
 +
 +  if (*dest == NULL) {
 +    *dest = meta_data_clone(orig);
 +    return(0);
 +  }
 +
 +  pthread_mutex_lock (&orig->lock);
 +  for (e=orig->head; e != NULL; e = e->next)
 +  {
 +    md_entry_insert_clone((*dest), e);
 +  }
 +  pthread_mutex_unlock (&orig->lock);
 +
 +  return (0);
 +} /* }}} int meta_data_clone_merge */
 +
  void meta_data_destroy (meta_data_t *md) /* {{{ */
  {
    if (md == NULL)
@@@ -406,7 -328,7 +417,7 @@@ int meta_data_toc (meta_data_t *md, cha
    pthread_mutex_lock (&md->lock);
  
    for (e = md->head; e != NULL; e = e->next)
 -    ++count;    
 +    ++count;
  
    if (count == 0)
    {
    *toc = calloc(count, sizeof(**toc));
    for (e = md->head; e != NULL; e = e->next)
      (*toc)[i++] = strdup(e->key);
 -  
 +
    pthread_mutex_unlock (&md->lock);
    return count;
  } /* }}} int meta_data_toc */
@@@ -596,7 -518,7 +607,7 @@@ int meta_data_get_string (meta_data_t *
      ERROR ("meta_data_get_string: md_strdup failed.");
      return (-ENOMEM);
    }
 - 
 +
    pthread_mutex_unlock (&md->lock);
  
    *value = temp;
diff --combined src/network.c
  #include "common.h"
  #include "configfile.h"
  #include "utils_fbhash.h"
 -#include "utils_avltree.h"
  #include "utils_cache.h"
  #include "utils_complain.h"
  
  #include "network.h"
  
 -#if HAVE_PTHREAD_H
 -# include <pthread.h>
 -#endif
 -#if HAVE_SYS_SOCKET_H
 -# include <sys/socket.h>
 -#endif
  #if HAVE_NETDB_H
  # include <netdb.h>
  #endif
@@@ -52,6 -59,7 +52,6 @@@
  #endif
  
  #if HAVE_LIBGCRYPT
 -# include <pthread.h>
  # if defined __APPLE__
  /* default xcode compiler throws warnings even when deprecated functionality
   * is not used. -Werror breaks the build because of erroneous warnings.
@@@ -275,8 -283,8 +275,8 @@@ typedef struct receive_list_entry_s rec
  static int network_config_ttl = 0;
  /* Ethernet - (IPv6 + UDP) = 1500 - (40 + 8) = 1452 */
  static size_t network_config_packet_size = 1452;
 -static int network_config_forward = 0;
 -static int network_config_stats = 0;
 +static _Bool network_config_forward = 0;
 +static _Bool network_config_stats = 0;
  
  static sockent_t *sending_sockets = NULL;
  
@@@ -302,7 -310,6 +302,7 @@@ static pthread_t dispatch_thread_id
  static char            *send_buffer;
  static char            *send_buffer_ptr;
  static int              send_buffer_fill;
 +static cdtime_t         send_buffer_last_update;
  static value_list_t     send_buffer_vl = VALUE_LIST_STATIC;
  static pthread_mutex_t  send_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
  
@@@ -346,7 -353,7 +346,7 @@@ static _Bool check_send_okay (const val
    _Bool received = 0;
    int status;
  
 -  if (network_config_forward != 0)
 +  if (network_config_forward)
      return (1);
  
    if (vl->meta == NULL)
@@@ -409,10 -416,10 +409,10 @@@ static int network_dispatch_values (val
  {
    int status;
  
 -  if ((vl->time <= 0)
 -      || (strlen (vl->host) <= 0)
 -      || (strlen (vl->plugin) <= 0)
 -      || (strlen (vl->type) <= 0))
 +  if ((vl->time == 0)
 +      || (strlen (vl->host) == 0)
 +      || (strlen (vl->plugin) == 0)
 +      || (strlen (vl->type) == 0))
      return (-EINVAL);
  
    if (!check_receive_okay (vl))
@@@ -522,7 -529,7 +522,7 @@@ static void network_init_gcrypt (void) 
    err = gcry_control (GCRYCTL_INIT_SECMEM, 32768);
    if (err)
    {
-     ERROR ("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s", gcry_strerror (err));
+     ERROR ("network plugin: gcry_control (GCRYCTL_INIT_SECMEM) failed: %s", gcry_strerror (err));
      abort ();
    }
  
@@@ -628,14 -635,14 +628,14 @@@ static int write_part_values (char **re
        if (*ret_buffer_len < packet_len)
                return (-1);
  
 -      pkg_values_types = (uint8_t *) malloc (num_values * sizeof (uint8_t));
 +      pkg_values_types = malloc (num_values * sizeof (*pkg_values_types));
        if (pkg_values_types == NULL)
        {
                ERROR ("network plugin: write_part_values: malloc failed.");
                return (-1);
        }
  
 -      pkg_values = (value_t *) malloc (num_values * sizeof (value_t));
 +      pkg_values = malloc (num_values * sizeof (*pkg_values));
        if (pkg_values == NULL)
        {
                free (pkg_values_types);
@@@ -779,18 -786,18 +779,18 @@@ static int write_part_string (char **re
  } /* int write_part_string */
  
  static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len,
 -              value_t **ret_values, int *ret_num_values)
 +              value_t **ret_values, size_t *ret_num_values)
  {
        char *buffer = *ret_buffer;
        size_t buffer_len = *ret_buffer_len;
  
        uint16_t tmp16;
        size_t exp_size;
 -      int   i;
 +      size_t i;
  
        uint16_t pkg_length;
        uint16_t pkg_type;
 -      uint16_t pkg_numval;
 +      size_t pkg_numval;
  
        uint8_t *pkg_types;
        value_t *pkg_values;
  
        memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
        buffer += sizeof (tmp16);
 -      pkg_numval = ntohs (tmp16);
 +      pkg_numval = (size_t) ntohs (tmp16);
  
        assert (pkg_type == TYPE_VALUES);
  
                                exp_size, buffer_len);
                return (-1);
        }
 +      assert (pkg_numval <= ((buffer_len - 6) / 9));
  
        if (pkg_length != exp_size)
        {
                return (-1);
        }
  
 -      pkg_types = (uint8_t *) malloc (pkg_numval * sizeof (uint8_t));
 -      pkg_values = (value_t *) malloc (pkg_numval * sizeof (value_t));
 +      pkg_types = calloc (pkg_numval, sizeof (*pkg_types));
 +      pkg_values = calloc (pkg_numval, sizeof (*pkg_values));
        if ((pkg_types == NULL) || (pkg_values == NULL))
        {
                sfree (pkg_types);
                sfree (pkg_values);
 -              ERROR ("network plugin: parse_part_values: malloc failed.");
 +              ERROR ("network plugin: parse_part_values: calloc failed.");
                return (-1);
        }
  
 -      memcpy ((void *) pkg_types, (void *) buffer, pkg_numval * sizeof (uint8_t));
 -      buffer += pkg_numval * sizeof (uint8_t);
 -      memcpy ((void *) pkg_values, (void *) buffer, pkg_numval * sizeof (value_t));
 -      buffer += pkg_numval * sizeof (value_t);
 +      memcpy (pkg_types, buffer, pkg_numval * sizeof (*pkg_types));
 +      buffer += pkg_numval * sizeof (*pkg_types);
 +      memcpy (pkg_values, buffer, pkg_numval * sizeof (*pkg_values));
 +      buffer += pkg_numval * sizeof (*pkg_values);
  
        for (i = 0; i < pkg_numval; i++)
        {
@@@ -944,7 -950,7 +944,7 @@@ static int parse_part_string (void **re
        uint16_t pkg_length;
        size_t payload_size;
  
 -      if (output_len <= 0)
 +      if (output_len == 0)
                return (EINVAL);
  
        if (buffer_len < header_size)
@@@ -1260,7 -1266,7 +1260,7 @@@ static int parse_part_encr_aes256 (sock
    BUFFER_READ (&username_len, sizeof (username_len));
    username_len = ntohs (username_len);
  
 -  if ((username_len <= 0)
 +  if ((username_len == 0)
        || (username_len > (part_size - (PART_ENCRYPTION_AES256_SIZE + 1))))
    {
      NOTICE ("network plugin: parse_part_encr_aes256: "
@@@ -1379,7 -1385,7 +1379,7 @@@ static int parse_part_encr_aes256 (sock
      warning_has_been_printed = 1;
    }
  
 -  *ret_buffer += ph_length;
 +  *ret_buffer = (void *) (((char *) *ret_buffer) + ph_length);
    *ret_buffer_size -= ph_length;
  
    return (0);
@@@ -1418,7 -1424,7 +1418,7 @@@ static int parse_packet (sockent_t *se
                                (void *) buffer,
                                sizeof (pkg_type));
                memcpy ((void *) &pkg_length,
 -                              (void *) (buffer + sizeof (pkg_type)),
 +                              (void *) (((char *) buffer) + sizeof (pkg_type)),
                                sizeof (pkg_length));
  
                pkg_length = ntohs (pkg_length);
                                                "unknown severity %i.",
                                                n.severity);
                        }
 -                      else if (n.time <= 0)
 +                      else if (n.time == 0)
                        {
                                INFO ("network plugin: "
                                                "Ignoring notification with "
                                                "time == 0.");
                        }
 -                      else if (strlen (n.message) <= 0)
 +                      else if (strlen (n.message) == 0)
                        {
                                INFO ("network plugin: "
                                                "Ignoring notification with "
@@@ -2025,9 -2031,10 +2025,9 @@@ static sockent_t *sockent_create (int t
        if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER))
                return (NULL);
  
 -      se = malloc (sizeof (*se));
 +      se = calloc (1, sizeof (*se));
        if (se == NULL)
                return (NULL);
 -      memset (se, 0, sizeof (*se));
  
        se->type = type;
        se->node = NULL;
@@@ -2208,15 -2215,16 +2208,15 @@@ static int sockent_client_connect (sock
                        continue;
                }
  
 -              client->addr = malloc (sizeof (*client->addr));
 +              client->addr = calloc (1, sizeof (*client->addr));
                if (client->addr == NULL)
                {
 -                      ERROR ("network plugin: malloc failed.");
 +                      ERROR ("network plugin: calloc failed.");
                        close (client->fd);
                        client->fd = -1;
                        continue;
                }
  
 -              memset (client->addr, 0, sizeof (*client->addr));
                assert (sizeof (*client->addr) >= ai_ptr->ai_addrlen);
                memcpy (client->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
                client->addrlen = ai_ptr->ai_addrlen;
@@@ -2324,7 -2332,7 +2324,7 @@@ static int sockent_server_listen (socke
  
        freeaddrinfo (ai_list);
  
 -      if (se->data.server.fd_num <= 0)
 +      if (se->data.server.fd_num == 0)
                return (-1);
        return (0);
  } /* }}} int sockent_server_listen */
@@@ -2452,7 -2460,7 +2452,7 @@@ static int network_receive (void) /* {{
        char buffer[network_config_packet_size];
        int  buffer_len;
  
 -      int i;
 +      size_t i;
        int status = 0;
  
        receive_list_entry_t *private_list_head;
                         * these entries in the dispatch thread but put them in
                         * another list, so we don't have to allocate more and
                         * more of these structures. */
 -                      ent = malloc (sizeof (receive_list_entry_t));
 +                      ent = calloc (1, sizeof (*ent));
                        if (ent == NULL)
                        {
 -                              ERROR ("network plugin: malloc failed.");
 +                              ERROR ("network plugin: calloc failed.");
                                status = ENOMEM;
                                break;
                        }
 -                      memset (ent, 0, sizeof (receive_list_entry_t));
 +
                        ent->data = malloc (network_config_packet_size);
                        if (ent->data == NULL)
                        {
@@@ -2593,12 -2601,11 +2593,12 @@@ static void network_init_buffer (void
        memset (send_buffer, 0, network_config_packet_size);
        send_buffer_ptr = send_buffer;
        send_buffer_fill = 0;
 +      send_buffer_last_update = 0;
  
        memset (&send_buffer_vl, 0, sizeof (send_buffer_vl));
  } /* int network_init_buffer */
  
 -static void networt_send_buffer_plain (sockent_t *se, /* {{{ */
 +static void network_send_buffer_plain (sockent_t *se, /* {{{ */
                const char *buffer, size_t buffer_size)
  {
        int status;
  
                break;
        } /* while (42) */
 -} /* }}} void networt_send_buffer_plain */
 +} /* }}} void network_send_buffer_plain */
  
  #if HAVE_LIBGCRYPT
  #define BUFFER_ADD(p,s) do { \
    buffer_offset += (s); \
  } while (0)
  
 -static void networt_send_buffer_signed (sockent_t *se, /* {{{ */
 +static void network_send_buffer_signed (sockent_t *se, /* {{{ */
                const char *in_buffer, size_t in_buffer_size)
  {
    part_signature_sha256_t ps;
    hd = NULL;
  
    buffer_offset = PART_SIGNATURE_SHA256_SIZE + username_len + in_buffer_size;
 -  networt_send_buffer_plain (se, buffer, buffer_offset);
 -} /* }}} void networt_send_buffer_signed */
 +  network_send_buffer_plain (se, buffer, buffer_offset);
 +} /* }}} void network_send_buffer_signed */
  
 -static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */
 +static void network_send_buffer_encrypted (sockent_t *se, /* {{{ */
                const char *in_buffer, size_t in_buffer_size)
  {
    part_encryption_aes256_t pea;
      - sizeof (pea.hash);
  
    assert (buffer_size <= sizeof (buffer));
 -  DEBUG ("network plugin: networt_send_buffer_encrypted: "
 +  DEBUG ("network plugin: network_send_buffer_encrypted: "
        "buffer_size = %zu;", buffer_size);
  
    pea.head.length = htons ((uint16_t) (PART_ENCRYPTION_AES256_SIZE
    }
  
    /* Send it out without further modifications */
 -  networt_send_buffer_plain (se, buffer, buffer_size);
 -} /* }}} void networt_send_buffer_encrypted */
 +  network_send_buffer_plain (se, buffer, buffer_size);
 +} /* }}} void network_send_buffer_encrypted */
  #undef BUFFER_ADD
  #endif /* HAVE_LIBGCRYPT */
  
@@@ -2805,12 -2812,12 +2805,12 @@@ static void network_send_buffer (char *
    {
  #if HAVE_LIBGCRYPT
      if (se->data.client.security_level == SECURITY_LEVEL_ENCRYPT)
 -      networt_send_buffer_encrypted (se, buffer, buffer_len);
 +      network_send_buffer_encrypted (se, buffer, buffer_len);
      else if (se->data.client.security_level == SECURITY_LEVEL_SIGN)
 -      networt_send_buffer_signed (se, buffer, buffer_len);
 +      network_send_buffer_signed (se, buffer, buffer_len);
      else /* if (se->data.client.security_level == SECURITY_LEVEL_NONE) */
  #endif /* HAVE_LIBGCRYPT */
 -      networt_send_buffer_plain (se, buffer, buffer_len);
 +      network_send_buffer_plain (se, buffer, buffer_len);
    } /* for (sending_sockets) */
  } /* }}} void network_send_buffer */
  
@@@ -2933,7 -2940,6 +2933,7 @@@ static int network_write (const data_se
                /* status == bytes added to the buffer */
                send_buffer_fill += status;
                send_buffer_ptr  += status;
 +              send_buffer_last_update = cdtime();
  
                stats_values_sent++;
        }
        return ((status < 0) ? -1 : 0);
  } /* int network_write */
  
 -static int network_config_set_boolean (const oconfig_item_t *ci, /* {{{ */
 -    int *retval)
 -{
 -  if ((ci->values_num != 1)
 -      || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN)
 -        && (ci->values[0].type != OCONFIG_TYPE_STRING)))
 -  {
 -    ERROR ("network plugin: The `%s' config option needs "
 -        "exactly one boolean argument.", ci->key);
 -    return (-1);
 -  }
 -
 -  if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
 -  {
 -    if (ci->values[0].value.boolean)
 -      *retval = 1;
 -    else
 -      *retval = 0;
 -  }
 -  else
 -  {
 -    char *str = ci->values[0].value.string;
 -
 -    if (IS_TRUE (str))
 -      *retval = 1;
 -    else if (IS_FALSE (str))
 -      *retval = 0;
 -    else
 -    {
 -      ERROR ("network plugin: Cannot parse string value `%s' of the `%s' "
 -          "option as boolean value.",
 -          str, ci->key);
 -      return (-1);
 -    }
 -  }
 -
 -  return (0);
 -} /* }}} int network_config_set_boolean */
 -
  static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
  {
 -  int tmp;
 -  if ((ci->values_num != 1)
 -      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
 -  {
 -    WARNING ("network plugin: The `TimeToLive' config option needs exactly "
 -        "one numeric argument.");
 -    return (-1);
 -  }
 +  int tmp = 0;
  
 -  tmp = (int) ci->values[0].value.number;
 -  if ((tmp > 0) && (tmp <= 255))
 +  if (cf_util_get_int (ci, &tmp) != 0)
 +    return (-1);
 +  else if ((tmp > 0) && (tmp <= 255))
      network_config_ttl = tmp;
    else {
      WARNING ("network plugin: The `TimeToLive' must be between 1 and 255.");
  static int network_config_set_interface (const oconfig_item_t *ci, /* {{{ */
      int *interface)
  {
 -  if ((ci->values_num != 1)
 -      || (ci->values[0].type != OCONFIG_TYPE_STRING))
 -  {
 -    WARNING ("network plugin: The `Interface' config option needs exactly "
 -        "one string argument.");
 -    return (-1);
 -  }
 +  char if_name[256];
  
 -  if (interface == NULL)
 +  if (cf_util_get_string_buffer (ci, if_name, sizeof (if_name)) != 0)
      return (-1);
  
 -  *interface = if_nametoindex (ci->values[0].value.string);
 -
 +  *interface = if_nametoindex (if_name);
    return (0);
  } /* }}} int network_config_set_interface */
  
  static int network_config_set_buffer_size (const oconfig_item_t *ci) /* {{{ */
  {
 -  int tmp;
 -  if ((ci->values_num != 1)
 -      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
 -  {
 -    WARNING ("network plugin: The `MaxPacketSize' config option needs exactly "
 -        "one numeric argument.");
 -    return (-1);
 -  }
 +  int tmp = 0;
  
 -  tmp = (int) ci->values[0].value.number;
 -  if ((tmp >= 1024) && (tmp <= 65535))
 +  if (cf_util_get_int (ci, &tmp) != 0)
 +    return (-1);
 +  else if ((tmp >= 1024) && (tmp <= 65535))
      network_config_packet_size = tmp;
 -
 -  return (0);
 -} /* }}} int network_config_set_buffer_size */
 -
 -#if HAVE_LIBGCRYPT
 -static int network_config_set_string (const oconfig_item_t *ci, /* {{{ */
 -    char **ret_string)
 -{
 -  char *tmp;
 -  if ((ci->values_num != 1)
 -      || (ci->values[0].type != OCONFIG_TYPE_STRING))
 -  {
 -    WARNING ("network plugin: The `%s' config option needs exactly "
 -        "one string argument.", ci->key);
 +  else {
 +    WARNING ("network plugin: The `MaxPacketSize' must be between 1024 and 65535.");
      return (-1);
    }
  
 -  tmp = strdup (ci->values[0].value.string);
 -  if (tmp == NULL)
 -    return (-1);
 -
 -  sfree (*ret_string);
 -  *ret_string = tmp;
 -
    return (0);
 -} /* }}} int network_config_set_string */
 -#endif /* HAVE_LIBGCRYPT */
 +} /* }}} int network_config_set_buffer_size */
  
  #if HAVE_LIBGCRYPT
  static int network_config_set_security_level (oconfig_item_t *ci, /* {{{ */
@@@ -3076,14 -3160,15 +3076,14 @@@ static int network_config_add_listen (c
  
  #if HAVE_LIBGCRYPT
      if (strcasecmp ("AuthFile", child->key) == 0)
 -      network_config_set_string (child, &se->data.server.auth_file);
 +      cf_util_get_string (child, &se->data.server.auth_file);
      else if (strcasecmp ("SecurityLevel", child->key) == 0)
        network_config_set_security_level (child,
            &se->data.server.security_level);
      else
  #endif /* HAVE_LIBGCRYPT */
      if (strcasecmp ("Interface", child->key) == 0)
 -      network_config_set_interface (child,
 -          &se->interface);
 +      network_config_set_interface (child, &se->interface);
      else
      {
        WARNING ("network plugin: Option `%s' is not allowed here.",
    status = sockent_server_listen (se);
    if (status != 0)
    {
 -    ERROR ("network plugin: network_config_add_server: sockent_server_listen failed.");
 +    ERROR ("network plugin: network_config_add_listen: sockent_server_listen failed.");
      sockent_destroy (se);
      return (-1);
    }
@@@ -3162,18 -3247,19 +3162,18 @@@ static int network_config_add_server (c
  
  #if HAVE_LIBGCRYPT
      if (strcasecmp ("Username", child->key) == 0)
 -      network_config_set_string (child, &se->data.client.username);
 +      cf_util_get_string (child, &se->data.client.username);
      else if (strcasecmp ("Password", child->key) == 0)
 -      network_config_set_string (child, &se->data.client.password);
 +      cf_util_get_string (child, &se->data.client.password);
      else if (strcasecmp ("SecurityLevel", child->key) == 0)
        network_config_set_security_level (child,
            &se->data.client.security_level);
      else
  #endif /* HAVE_LIBGCRYPT */
      if (strcasecmp ("Interface", child->key) == 0)
 -      network_config_set_interface (child,
 -          &se->interface);
 -              else if (strcasecmp ("ResolveInterval", child->key) == 0)
 -                      cf_util_get_cdtime(child, &se->data.client.resolve_interval);
 +      network_config_set_interface (child, &se->interface);
 +    else if (strcasecmp ("ResolveInterval", child->key) == 0)
 +      cf_util_get_cdtime(child, &se->data.client.resolve_interval);
      else
      {
        WARNING ("network plugin: Option `%s' is not allowed here.",
    }
  
    /* No call to sockent_client_connect() here -- it is called from
 -   * networt_send_buffer_plain(). */
 +   * network_send_buffer_plain(). */
  
    status = sockent_add (se);
    if (status != 0)
@@@ -3242,9 -3328,9 +3242,9 @@@ static int network_config (oconfig_item
      else if (strcasecmp ("MaxPacketSize", child->key) == 0)
        network_config_set_buffer_size (child);
      else if (strcasecmp ("Forward", child->key) == 0)
 -      network_config_set_boolean (child, &network_config_forward);
 +      cf_util_get_boolean (child, &network_config_forward);
      else if (strcasecmp ("ReportStats", child->key) == 0)
 -      network_config_set_boolean (child, &network_config_stats);
 +      cf_util_get_boolean (child, &network_config_stats);
      else
      {
        WARNING ("network plugin: Option `%s' is not allowed here.",
@@@ -3465,7 -3551,7 +3465,7 @@@ static int network_init (void
        network_init_gcrypt ();
  #endif
  
 -      if (network_config_stats != 0)
 +      if (network_config_stats)
                plugin_register_read ("network", network_stats_read);
  
        plugin_register_shutdown ("network", network_shutdown);
   * just send the buffer if `flush'  is called - if the requested value was in
   * there, good. If not, well, then there is nothing to flush.. -octo
   */
 -static int network_flush (__attribute__((unused)) cdtime_t timeout,
 +static int network_flush (cdtime_t timeout,
                __attribute__((unused)) const char *identifier,
                __attribute__((unused)) user_data_t *user_data)
  {
        pthread_mutex_lock (&send_buffer_lock);
  
        if (send_buffer_fill > 0)
 -        flush_buffer ();
 -
 +      {
 +              if (timeout > 0)
 +              {
 +                      cdtime_t now = cdtime ();
 +                      if ((send_buffer_last_update + timeout) > now)
 +                      {
 +                              pthread_mutex_unlock (&send_buffer_lock);
 +                              return (0);
 +                      }
 +              }
 +              flush_buffer ();
 +      }
        pthread_mutex_unlock (&send_buffer_lock);
  
        return (0);