+static _Bool regex_direct_initialized = 0;
+static regex_t regex_direct;
+
+/**
+ * List of onewire owfs "files" to be directly read
+ */
+typedef struct direct_access_element_s
+{
+ char *path; /**< The whole owfs path */
+ char *address; /**< 1-wire address without family */
+ char *file; /**< owfs file - e.g. temperature */
+ struct direct_access_element_s *next; /**< Next in the list */
+} direct_access_element_t;
+
+static direct_access_element_t * direct_list = NULL;
+
+/* =================================================================================== */
+
+#if COLLECT_DEBUG
+/* Return 1 if the difference is negative, otherwise 0. */
+static int timeval_subtract(struct timeval *result, struct timeval *t2, struct timeval *t1)
+{
+ long int diff = (t2->tv_usec + 1000000 * t2->tv_sec) - (t1->tv_usec + 1000000 * t1->tv_sec);
+ result->tv_sec = diff / 1000000;
+ result->tv_usec = diff % 1000000;
+
+ return (diff<0);
+}
+#endif /* COLLECT_DEBUG */
+
+/* =================================================================================== */
+
+static void direct_list_element_free(direct_access_element_t *el)
+{
+ if (el != NULL)
+ {
+ DEBUG ("onewire plugin: direct_list_element_free - deleting <%s>", el->path);
+ sfree (el->path);
+ sfree (el->address);
+ sfree (el->file);
+ free (el);
+ }
+}
+
+static int direct_list_insert(const char * config)
+{
+ regmatch_t pmatch[3];
+ size_t nmatch = 3;
+ direct_access_element_t *element = NULL;
+
+ DEBUG ("onewire plugin: direct_list_insert <%s>", config);
+
+ element = (direct_access_element_t *) malloc (sizeof(*element));
+ if (element == NULL)
+ {
+ ERROR ("onewire plugin: direct_list_insert - cannot allocate element");
+ return 1;
+ }
+ element->path = NULL;
+ element->address = NULL;
+ element->file = NULL;
+
+ element->path = strdup (config);
+ if (element->path == NULL)
+ {
+ ERROR ("onewire plugin: direct_list_insert - cannot allocate path");
+ direct_list_element_free (element);
+ return 1;
+ }
+
+ DEBUG ("onewire plugin: direct_list_insert - about to match %s", config);
+
+ if (!regex_direct_initialized)
+ {
+ if (regcomp (®ex_direct, regexp_to_match, REG_EXTENDED))
+ {
+ ERROR ("onewire plugin: Cannot compile regex");
+ direct_list_element_free (element);
+ return (1);
+ }
+ regex_direct_initialized = 1;
+ DEBUG ("onewire plugin: Compiled regex!!");
+ }
+
+ if (regexec (®ex_direct, config, nmatch, pmatch, 0))
+ {
+ ERROR ("onewire plugin: direct_list_insert - no regex match");
+ direct_list_element_free (element);
+ return 1;
+ }
+
+ if (pmatch[1].rm_so<0)
+ {
+ ERROR ("onewire plugin: direct_list_insert - no address regex match");
+ direct_list_element_free (element);
+ return 1;
+ }
+ element->address = strndup (config+pmatch[1].rm_so,
+ pmatch[1].rm_eo - pmatch[1].rm_so);
+ if (element->address == NULL)
+ {
+ ERROR ("onewire plugin: direct_list_insert - cannot allocate address");
+ direct_list_element_free (element);
+ return 1;
+ }
+ DEBUG ("onewire plugin: direct_list_insert - found address <%s>",
+ element->address);
+
+ if (pmatch[2].rm_so<0)
+ {
+ ERROR ("onewire plugin: direct_list_insert - no file regex match");
+ direct_list_element_free (element);
+ return 1;
+ }
+ element->file = strndup (config+pmatch[2].rm_so,
+ pmatch[2].rm_eo - pmatch[2].rm_so);
+ if (element->file == NULL)
+ {
+ ERROR ("onewire plugin: direct_list_insert - cannot allocate file");
+ direct_list_element_free (element);
+ return 1;
+ }
+ DEBUG ("onewire plugin: direct_list_insert - found file <%s>", element->file);
+
+ element->next = direct_list;
+ direct_list = element;
+
+ return 0;
+}
+
+static void direct_list_free(void)
+{
+ direct_access_element_t *traverse = direct_list;
+ direct_access_element_t *tmp = NULL;;
+
+ while(traverse != NULL)
+ {
+ tmp = traverse;
+ traverse = traverse->next;
+ direct_list_element_free (tmp);
+ tmp = NULL;
+ }
+}
+
+/* =================================================================================== */
+