2 * collectd - src/utils_db_query.c
3 * Copyright (C) 2008,2009 Florian octo Forster
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Florian octo Forster <octo at collectd.org>
30 #include "configfile.h"
31 #include "utils_db_query.h"
36 struct udb_result_s; /* {{{ */
37 typedef struct udb_result_s udb_result_t;
41 char *instance_prefix;
52 struct udb_query_s /* {{{ */
58 unsigned int min_version;
59 unsigned int max_version;
61 udb_result_t *results;
64 struct udb_result_preparation_area_s /* {{{ */
67 size_t *instances_pos;
70 char **instances_buffer;
72 char **metadata_buffer;
74 struct udb_result_preparation_area_s *next;
76 typedef struct udb_result_preparation_area_s udb_result_preparation_area_t;
78 struct udb_query_preparation_area_s /* {{{ */
87 udb_result_preparation_area_t *result_prep_areas;
91 * Config Private functions
93 static int udb_config_set_string (char **ret_string, /* {{{ */
98 if ((ci->values_num != 1)
99 || (ci->values[0].type != OCONFIG_TYPE_STRING))
101 WARNING ("db query utils: The `%s' config option "
102 "needs exactly one string argument.", ci->key);
106 string = strdup (ci->values[0].value.string);
109 ERROR ("db query utils: strdup failed.");
113 if (*ret_string != NULL)
115 *ret_string = string;
118 } /* }}} int udb_config_set_string */
120 static int udb_config_add_string (char ***ret_array, /* {{{ */
121 size_t *ret_array_len, oconfig_item_t *ci)
127 if (ci->values_num < 1)
129 WARNING ("db query utils: The `%s' config option "
130 "needs at least one argument.", ci->key);
134 for (i = 0; i < ci->values_num; i++)
136 if (ci->values[i].type != OCONFIG_TYPE_STRING)
138 WARNING ("db query utils: Argument %i to the `%s' option "
139 "is not a string.", i + 1, ci->key);
144 array_len = *ret_array_len;
145 array = (char **) realloc (*ret_array,
146 sizeof (char *) * (array_len + ci->values_num));
149 ERROR ("db query utils: realloc failed.");
154 for (i = 0; i < ci->values_num; i++)
156 array[array_len] = strdup (ci->values[i].value.string);
157 if (array[array_len] == NULL)
159 ERROR ("db query utils: strdup failed.");
160 *ret_array_len = array_len;
166 *ret_array_len = array_len;
168 } /* }}} int udb_config_add_string */
170 static int udb_config_set_uint (unsigned int *ret_value, /* {{{ */
175 if ((ci->values_num != 1)
176 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
178 WARNING ("db query utils: The `%s' config option "
179 "needs exactly one numeric argument.", ci->key);
183 tmp = ci->values[0].value.number;
184 if ((tmp < 0.0) || (tmp > ((double) UINT_MAX)))
187 *ret_value = (unsigned int) (tmp + .5);
189 } /* }}} int udb_config_set_uint */
192 * Result private functions
194 static int udb_result_submit (udb_result_t *r, /* {{{ */
195 udb_result_preparation_area_t *r_area,
196 udb_query_t const *q, udb_query_preparation_area_t *q_area)
198 value_list_t vl = VALUE_LIST_INIT;
203 assert (r_area->ds != NULL);
204 assert (((size_t) r_area->ds->ds_num) == r->values_num);
205 assert (r->values_num > 0);
207 vl.values = (value_t *) calloc (r->values_num, sizeof (value_t));
208 if (vl.values == NULL)
210 ERROR ("db query utils: malloc failed.");
213 vl.values_len = r_area->ds->ds_num;
215 for (i = 0; i < r->values_num; i++)
217 char *value_str = r_area->values_buffer[i];
219 if (0 != parse_value (value_str, &vl.values[i], r_area->ds->ds[i].type))
221 ERROR ("db query utils: udb_result_submit: Parsing `%s' as %s failed.",
222 value_str, DS_TYPE_TO_STRING (r_area->ds->ds[i].type));
228 if (q_area->interval > 0)
229 vl.interval = q_area->interval;
231 sstrncpy (vl.host, q_area->host, sizeof (vl.host));
232 sstrncpy (vl.plugin, q_area->plugin, sizeof (vl.plugin));
233 sstrncpy (vl.plugin_instance, q_area->db_name, sizeof (vl.plugin_instance));
234 sstrncpy (vl.type, r->type, sizeof (vl.type));
236 /* Set vl.type_instance {{{ */
237 if (r->instances_num <= 0)
239 if (r->instance_prefix == NULL)
240 vl.type_instance[0] = 0;
242 sstrncpy (vl.type_instance, r->instance_prefix,
243 sizeof (vl.type_instance));
245 else /* if ((r->instances_num > 0) */
247 if (r->instance_prefix == NULL)
249 strjoin (vl.type_instance, sizeof (vl.type_instance),
250 r_area->instances_buffer, r->instances_num, "-");
254 char tmp[DATA_MAX_NAME_LEN];
256 strjoin (tmp, sizeof (tmp), r_area->instances_buffer,
257 r->instances_num, "-");
258 tmp[sizeof (tmp) - 1] = 0;
260 snprintf (vl.type_instance, sizeof (vl.type_instance), "%s-%s",
261 r->instance_prefix, tmp);
264 vl.type_instance[sizeof (vl.type_instance) - 1] = 0;
267 /* Annotate meta data. {{{ */
268 if (r->metadata_num > 0)
270 vl.meta = meta_data_create ();
273 ERROR ("db query utils:: meta_data_create failed.");
277 for (i = 0; i < r->metadata_num; i++)
279 status = meta_data_add_string (vl.meta, r->metadata[i],
280 r_area->metadata_buffer[i]);
283 ERROR ("db query utils:: meta_data_add_string failed.");
284 meta_data_destroy (vl.meta);
292 plugin_dispatch_values (&vl);
294 if (r->metadata_num > 0)
296 meta_data_destroy (vl.meta);
301 } /* }}} void udb_result_submit */
303 static void udb_result_finish_result (udb_result_t const *r, /* {{{ */
304 udb_result_preparation_area_t *prep_area)
306 if ((r == NULL) || (prep_area == NULL))
309 prep_area->ds = NULL;
310 sfree (prep_area->instances_pos);
311 sfree (prep_area->values_pos);
312 sfree (prep_area->metadata_pos);
313 sfree (prep_area->instances_buffer);
314 sfree (prep_area->values_buffer);
315 sfree (prep_area->metadata_buffer);
316 } /* }}} void udb_result_finish_result */
318 static int udb_result_handle_result (udb_result_t *r, /* {{{ */
319 udb_query_preparation_area_t *q_area,
320 udb_result_preparation_area_t *r_area,
321 udb_query_t const *q, char **column_values)
325 assert (r && q_area && r_area);
327 for (i = 0; i < r->instances_num; i++)
328 r_area->instances_buffer[i] = column_values[r_area->instances_pos[i]];
330 for (i = 0; i < r->values_num; i++)
331 r_area->values_buffer[i] = column_values[r_area->values_pos[i]];
333 for (i = 0; i < r->metadata_num; i++)
334 r_area->metadata_buffer[i] = column_values[r_area->metadata_pos[i]];
336 return udb_result_submit (r, r_area, q, q_area);
337 } /* }}} int udb_result_handle_result */
339 static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */
340 udb_result_preparation_area_t *prep_area,
341 char **column_names, size_t column_num)
345 if ((r == NULL) || (prep_area == NULL))
348 #define BAIL_OUT(status) \
349 prep_area->ds = NULL; \
350 sfree (prep_area->instances_pos); \
351 sfree (prep_area->values_pos); \
352 sfree (prep_area->metadata_pos); \
353 sfree (prep_area->instances_buffer); \
354 sfree (prep_area->values_buffer); \
355 sfree (prep_area->metadata_buffer); \
358 /* Make sure previous preparations are cleaned up. */
359 udb_result_finish_result (r, prep_area);
360 prep_area->instances_pos = NULL;
361 prep_area->values_pos = NULL;
362 prep_area->metadata_pos = NULL;
364 /* Read `ds' and check number of values {{{ */
365 prep_area->ds = plugin_get_ds (r->type);
366 if (prep_area->ds == NULL)
368 ERROR ("db query utils: udb_result_prepare_result: Type `%s' is not "
369 "known by the daemon. See types.db(5) for details.",
374 if (prep_area->ds->ds_num != r->values_num)
376 ERROR ("db query utils: udb_result_prepare_result: The type `%s' "
377 "requires exactly %zu value%s, but the configuration specifies %zu.",
379 prep_area->ds->ds_num, (prep_area->ds->ds_num == 1) ? "" : "s",
385 /* Allocate r->instances_pos, r->values_pos, r->metadata_post,
386 * r->instances_buffer, r->values_buffer, and r->metadata_buffer {{{ */
387 if (r->instances_num > 0)
389 prep_area->instances_pos
390 = (size_t *) calloc (r->instances_num, sizeof (size_t));
391 if (prep_area->instances_pos == NULL)
393 ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
397 prep_area->instances_buffer
398 = (char **) calloc (r->instances_num, sizeof (char *));
399 if (prep_area->instances_buffer == NULL)
401 ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
404 } /* if (r->instances_num > 0) */
406 prep_area->values_pos
407 = (size_t *) calloc (r->values_num, sizeof (size_t));
408 if (prep_area->values_pos == NULL)
410 ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
414 prep_area->values_buffer
415 = (char **) calloc (r->values_num, sizeof (char *));
416 if (prep_area->values_buffer == NULL)
418 ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
422 prep_area->metadata_pos
423 = (size_t *) calloc (r->metadata_num, sizeof (size_t));
424 if (prep_area->metadata_pos == NULL)
426 ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
430 prep_area->metadata_buffer
431 = (char **) calloc (r->metadata_num, sizeof (char *));
432 if (prep_area->metadata_buffer == NULL)
434 ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
440 /* Determine the position of the instance columns {{{ */
441 for (i = 0; i < r->instances_num; i++)
445 for (j = 0; j < column_num; j++)
447 if (strcasecmp (r->instances[i], column_names[j]) == 0)
449 prep_area->instances_pos[i] = j;
456 ERROR ("db query utils: udb_result_prepare_result: "
457 "Column `%s' could not be found.",
461 } /* }}} for (i = 0; i < r->instances_num; i++) */
463 /* Determine the position of the value columns {{{ */
464 for (i = 0; i < r->values_num; i++)
468 for (j = 0; j < column_num; j++)
470 if (strcasecmp (r->values[i], column_names[j]) == 0)
472 prep_area->values_pos[i] = j;
479 ERROR ("db query utils: udb_result_prepare_result: "
480 "Column `%s' could not be found.",
484 } /* }}} for (i = 0; i < r->values_num; i++) */
486 /* Determine the position of the metadata columns {{{ */
487 for (i = 0; i < r->metadata_num; i++)
491 for (j = 0; j < column_num; j++)
493 if (strcasecmp (r->metadata[i], column_names[j]) == 0)
495 prep_area->metadata_pos[i] = j;
502 ERROR ("db query utils: udb_result_prepare_result: "
503 "Metadata column `%s' could not be found.",
507 } /* }}} for (i = 0; i < r->metadata_num; i++) */
511 } /* }}} int udb_result_prepare_result */
513 static void udb_result_free (udb_result_t *r) /* {{{ */
522 for (i = 0; i < r->instances_num; i++)
523 sfree (r->instances[i]);
524 sfree (r->instances);
526 for (i = 0; i < r->values_num; i++)
527 sfree (r->values[i]);
530 for (i = 0; i < r->metadata_num; i++)
531 sfree (r->metadata[i]);
534 udb_result_free (r->next);
537 } /* }}} void udb_result_free */
539 static int udb_result_create (const char *query_name, /* {{{ */
540 udb_result_t **r_head, oconfig_item_t *ci)
546 if (ci->values_num != 0)
548 WARNING ("db query utils: The `Result' block doesn't accept "
549 "any arguments. Ignoring %i argument%s.",
550 ci->values_num, (ci->values_num == 1) ? "" : "s");
553 r = (udb_result_t *) malloc (sizeof (*r));
556 ERROR ("db query utils: malloc failed.");
559 memset (r, 0, sizeof (*r));
561 r->instance_prefix = NULL;
567 /* Fill the `udb_result_t' structure.. */
569 for (i = 0; i < ci->children_num; i++)
571 oconfig_item_t *child = ci->children + i;
573 if (strcasecmp ("Type", child->key) == 0)
574 status = udb_config_set_string (&r->type, child);
575 else if (strcasecmp ("InstancePrefix", child->key) == 0)
576 status = udb_config_set_string (&r->instance_prefix, child);
577 else if (strcasecmp ("InstancesFrom", child->key) == 0)
578 status = udb_config_add_string (&r->instances, &r->instances_num, child);
579 else if (strcasecmp ("ValuesFrom", child->key) == 0)
580 status = udb_config_add_string (&r->values, &r->values_num, child);
581 else if (strcasecmp ("MetadataFrom", child->key) == 0)
582 status = udb_config_add_string (&r->metadata, &r->metadata_num, child);
585 WARNING ("db query utils: Query `%s': Option `%s' not allowed here.",
586 query_name, child->key);
594 /* Check that all necessary options have been given. */
599 WARNING ("db query utils: `Type' not given for "
600 "result in query `%s'", query_name);
603 if (r->values == NULL)
605 WARNING ("db query utils: `ValuesFrom' not given for "
606 "result in query `%s'", query_name);
611 } /* while (status == 0) */
619 /* If all went well, add this result to the list of results. */
629 while (last->next != NULL)
636 } /* }}} int udb_result_create */
639 * Query private functions
641 void udb_query_free_one (udb_query_t *q) /* {{{ */
647 sfree (q->statement);
649 udb_result_free (q->results);
652 } /* }}} void udb_query_free_one */
655 * Query public functions
657 int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */
658 size_t *ret_query_list_len, oconfig_item_t *ci,
659 udb_query_create_callback_t cb)
661 udb_query_t **query_list;
662 size_t query_list_len;
668 if ((ret_query_list == NULL) || (ret_query_list_len == NULL))
670 query_list = *ret_query_list;
671 query_list_len = *ret_query_list_len;
673 if ((ci->values_num != 1)
674 || (ci->values[0].type != OCONFIG_TYPE_STRING))
676 WARNING ("db query utils: The `Query' block "
677 "needs exactly one string argument.");
681 q = (udb_query_t *) malloc (sizeof (*q));
684 ERROR ("db query utils: malloc failed.");
687 memset (q, 0, sizeof (*q));
689 q->max_version = UINT_MAX;
691 status = udb_config_set_string (&q->name, ci);
698 /* Fill the `udb_query_t' structure.. */
699 for (i = 0; i < ci->children_num; i++)
701 oconfig_item_t *child = ci->children + i;
703 if (strcasecmp ("Statement", child->key) == 0)
704 status = udb_config_set_string (&q->statement, child);
705 else if (strcasecmp ("Result", child->key) == 0)
706 status = udb_result_create (q->name, &q->results, child);
707 else if (strcasecmp ("MinVersion", child->key) == 0)
708 status = udb_config_set_uint (&q->min_version, child);
709 else if (strcasecmp ("MaxVersion", child->key) == 0)
710 status = udb_config_set_uint (&q->max_version, child);
712 /* Call custom callbacks */
715 status = (*cb) (q, child);
718 WARNING ("db query utils: The configuration callback failed "
719 "to handle `%s'.", child->key);
724 WARNING ("db query utils: Query `%s': Option `%s' not allowed here.",
725 q->name, child->key);
733 /* Check that all necessary options have been given. */
736 if (q->statement == NULL)
738 WARNING ("db query utils: Query `%s': No `Statement' given.", q->name);
741 if (q->results == NULL)
743 WARNING ("db query utils: Query `%s': No (valid) `Result' block given.",
747 } /* if (status == 0) */
749 /* If all went well, add this query to the list of queries within the
750 * database structure. */
755 temp = (udb_query_t **) realloc (query_list,
756 sizeof (*query_list) * (query_list_len + 1));
759 ERROR ("db query utils: realloc failed");
765 query_list[query_list_len] = q;
772 udb_query_free_one (q);
776 *ret_query_list = query_list;
777 *ret_query_list_len = query_list_len;
780 } /* }}} int udb_query_create */
782 void udb_query_free (udb_query_t **query_list, size_t query_list_len) /* {{{ */
786 if (query_list == NULL)
789 for (i = 0; i < query_list_len; i++)
790 udb_query_free_one (query_list[i]);
793 } /* }}} void udb_query_free */
795 int udb_query_pick_from_list_by_name (const char *name, /* {{{ */
796 udb_query_t **src_list, size_t src_list_len,
797 udb_query_t ***dst_list, size_t *dst_list_len)
802 if ((name == NULL) || (src_list == NULL) || (dst_list == NULL)
803 || (dst_list_len == NULL))
805 ERROR ("db query utils: udb_query_pick_from_list_by_name: "
806 "Invalid argument.");
811 for (i = 0; i < src_list_len; i++)
813 udb_query_t **tmp_list;
816 if (strcasecmp (name, src_list[i]->name) != 0)
819 tmp_list_len = *dst_list_len;
820 tmp_list = (udb_query_t **) realloc (*dst_list, (tmp_list_len + 1)
821 * sizeof (udb_query_t *));
822 if (tmp_list == NULL)
824 ERROR ("db query utils: realloc failed.");
828 tmp_list[tmp_list_len] = src_list[i];
831 *dst_list = tmp_list;
832 *dst_list_len = tmp_list_len;
835 } /* for (i = 0; i < src_list_len; i++) */
839 ERROR ("db query utils: Cannot find query `%s'. Make sure the <Query> "
840 "block is above the database definition!",
846 DEBUG ("db query utils: Added %i versions of query `%s'.",
851 } /* }}} int udb_query_pick_from_list_by_name */
853 int udb_query_pick_from_list (oconfig_item_t *ci, /* {{{ */
854 udb_query_t **src_list, size_t src_list_len,
855 udb_query_t ***dst_list, size_t *dst_list_len)
859 if ((ci == NULL) || (src_list == NULL) || (dst_list == NULL)
860 || (dst_list_len == NULL))
862 ERROR ("db query utils: udb_query_pick_from_list: "
863 "Invalid argument.");
867 if ((ci->values_num != 1)
868 || (ci->values[0].type != OCONFIG_TYPE_STRING))
870 ERROR ("db query utils: The `%s' config option "
871 "needs exactly one string argument.", ci->key);
874 name = ci->values[0].value.string;
876 return (udb_query_pick_from_list_by_name (name,
877 src_list, src_list_len,
878 dst_list, dst_list_len));
879 } /* }}} int udb_query_pick_from_list */
881 const char *udb_query_get_name (udb_query_t *q) /* {{{ */
887 } /* }}} const char *udb_query_get_name */
889 const char *udb_query_get_statement (udb_query_t *q) /* {{{ */
894 return (q->statement);
895 } /* }}} const char *udb_query_get_statement */
897 void udb_query_set_user_data (udb_query_t *q, void *user_data) /* {{{ */
902 q->user_data = user_data;
903 } /* }}} void udb_query_set_user_data */
905 void *udb_query_get_user_data (udb_query_t *q) /* {{{ */
910 return (q->user_data);
911 } /* }}} void *udb_query_get_user_data */
913 int udb_query_check_version (udb_query_t *q, unsigned int version) /* {{{ */
918 if ((version < q->min_version) || (version > q->max_version))
922 } /* }}} int udb_query_check_version */
924 void udb_query_finish_result (udb_query_t const *q, /* {{{ */
925 udb_query_preparation_area_t *prep_area)
927 udb_result_preparation_area_t *r_area;
930 if ((q == NULL) || (prep_area == NULL))
933 prep_area->column_num = 0;
934 sfree (prep_area->host);
935 sfree (prep_area->plugin);
936 sfree (prep_area->db_name);
938 prep_area->interval = 0;
940 for (r = q->results, r_area = prep_area->result_prep_areas;
941 r != NULL; r = r->next, r_area = r_area->next)
943 /* this may happen during error conditions of the caller */
946 udb_result_finish_result (r, r_area);
948 } /* }}} void udb_query_finish_result */
950 int udb_query_handle_result (udb_query_t const *q, /* {{{ */
951 udb_query_preparation_area_t *prep_area, char **column_values)
953 udb_result_preparation_area_t *r_area;
958 if ((q == NULL) || (prep_area == NULL))
961 if ((prep_area->column_num < 1) || (prep_area->host == NULL)
962 || (prep_area->plugin == NULL) || (prep_area->db_name == NULL))
964 ERROR ("db query utils: Query `%s': Query is not prepared; "
965 "can't handle result.", q->name);
969 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG /* {{{ */
974 for (i = 0; i < prep_area->column_num; i++)
976 DEBUG ("db query utils: udb_query_handle_result (%s, %s): "
978 prep_area->db_name, q->name, i, column_values[i]);
984 for (r = q->results, r_area = prep_area->result_prep_areas;
985 r != NULL; r = r->next, r_area = r_area->next)
987 status = udb_result_handle_result (r, prep_area, r_area,
995 ERROR ("db query utils: udb_query_handle_result (%s, %s): "
996 "All results failed.", prep_area->db_name, q->name);
1001 } /* }}} int udb_query_handle_result */
1003 int udb_query_prepare_result (udb_query_t const *q, /* {{{ */
1004 udb_query_preparation_area_t *prep_area,
1005 const char *host, const char *plugin, const char *db_name,
1006 char **column_names, size_t column_num, cdtime_t interval)
1008 udb_result_preparation_area_t *r_area;
1012 if ((q == NULL) || (prep_area == NULL))
1015 udb_query_finish_result (q, prep_area);
1017 prep_area->column_num = column_num;
1018 prep_area->host = strdup (host);
1019 prep_area->plugin = strdup (plugin);
1020 prep_area->db_name = strdup (db_name);
1022 prep_area->interval = interval;
1024 if ((prep_area->host == NULL) || (prep_area->plugin == NULL)
1025 || (prep_area->db_name == NULL))
1027 ERROR ("db query utils: Query `%s': Prepare failed: Out of memory.", q->name);
1028 udb_query_finish_result (q, prep_area);
1032 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG
1037 for (i = 0; i < column_num; i++)
1039 DEBUG ("db query utils: udb_query_prepare_result: "
1040 "query = %s; column[%zu] = %s;",
1041 q->name, i, column_names[i]);
1046 for (r = q->results, r_area = prep_area->result_prep_areas;
1047 r != NULL; r = r->next, r_area = r_area->next)
1051 ERROR ("db query utils: Query `%s': Invalid number of result "
1052 "preparation areas.", q->name);
1053 udb_query_finish_result (q, prep_area);
1057 status = udb_result_prepare_result (r, r_area, column_names, column_num);
1060 udb_query_finish_result (q, prep_area);
1066 } /* }}} int udb_query_prepare_result */
1068 udb_query_preparation_area_t *
1069 udb_query_allocate_preparation_area (udb_query_t *q) /* {{{ */
1071 udb_query_preparation_area_t *q_area;
1072 udb_result_preparation_area_t **next_r_area;
1075 q_area = malloc (sizeof (*q_area));
1078 memset (q_area, 0, sizeof (*q_area));
1080 next_r_area = &q_area->result_prep_areas;
1081 for (r = q->results; r != NULL; r = r->next)
1083 udb_result_preparation_area_t *r_area;
1085 r_area = malloc (sizeof (*r_area));
1088 udb_result_preparation_area_t *a = q_area->result_prep_areas;
1092 udb_result_preparation_area_t *next = a->next;
1101 memset (r_area, 0, sizeof (*r_area));
1103 *next_r_area = r_area;
1104 next_r_area = &r_area->next;
1108 } /* }}} udb_query_preparation_area_t *udb_query_allocate_preparation_area */
1111 udb_query_delete_preparation_area (udb_query_preparation_area_t *q_area) /* {{{ */
1113 udb_result_preparation_area_t *r_area;
1118 r_area = q_area->result_prep_areas;
1119 while (r_area != NULL)
1121 udb_result_preparation_area_t *area = r_area;
1123 r_area = r_area->next;
1125 sfree (area->instances_pos);
1126 sfree (area->values_pos);
1127 sfree (area->instances_buffer);
1128 sfree (area->values_buffer);
1132 sfree (q_area->host);
1133 sfree (q_area->plugin);
1134 sfree (q_area->db_name);
1137 } /* }}} void udb_query_delete_preparation_area */
1139 /* vim: set sw=2 sts=2 et fdm=marker : */