+static void csnmp_oid_init (oid_t *dst, oid const *src, size_t n)
+{
+ assert (n <= STATIC_ARRAY_SIZE (dst->oid));
+ memcpy (dst->oid, src, sizeof (*src) * n);
+ dst->oid_len = n;
+}
+
+static int csnmp_oid_compare (oid_t const *left, oid_t const *right)
+{
+ return (snmp_oid_compare (left->oid, left->oid_len,
+ right->oid, right->oid_len));
+}
+
+static int csnmp_oid_suffix (oid_t *dst, oid_t const *src,
+ oid_t const *root)
+{
+ /* Make sure "src" is in "root"s subtree. */
+ if (src->oid_len <= root->oid_len)
+ return (EINVAL);
+ if (snmp_oid_ncompare (root->oid, root->oid_len,
+ src->oid, src->oid_len,
+ /* n = */ root->oid_len) != 0)
+ return (EINVAL);
+
+ memset (dst, 0, sizeof (*dst));
+ dst->oid_len = src->oid_len - root->oid_len;
+ memcpy (dst->oid, &src->oid[root->oid_len],
+ dst->oid_len * sizeof (dst->oid[0]));
+ return (0);
+}
+
+static int csnmp_oid_to_string (char *buffer, size_t buffer_size,
+ oid_t const *o)
+{
+ char oid_str[MAX_OID_LEN][16];
+ char *oid_str_ptr[MAX_OID_LEN];
+ size_t i;
+
+ for (i = 0; i < o->oid_len; i++)
+ {
+ ssnprintf (oid_str[i], sizeof (oid_str[i]), "%lu", (unsigned long) o->oid[i]);
+ oid_str_ptr[i] = oid_str[i];
+ }
+
+ return (strjoin (buffer, buffer_size,
+ oid_str_ptr, o->oid_len, /* separator = */ "."));
+}
+
+static void csnmp_host_close_session (host_definition_t *host) /* {{{ */
+{
+ if (host->sess_handle == NULL)
+ return;
+
+ snmp_sess_close (host->sess_handle);
+ host->sess_handle = NULL;
+} /* }}} void csnmp_host_close_session */
+
+static void csnmp_host_definition_destroy (void *arg) /* {{{ */
+{
+ host_definition_t *hd;
+
+ hd = arg;
+
+ if (hd == NULL)
+ return;
+
+ if (hd->name != NULL)
+ {
+ DEBUG ("snmp plugin: Destroying host definition for host `%s'.",
+ hd->name);
+ }
+
+ csnmp_host_close_session (hd);
+
+ sfree (hd->name);
+ sfree (hd->address);
+ sfree (hd->community);
+ sfree (hd->data_list);
+
+ sfree (hd);
+} /* }}} void csnmp_host_definition_destroy */
+
+/* Many functions to handle the configuration. {{{ */