static int put_zfs_value (kstat_t *ksp, char const *k, value_t v) { llentry_t *e; char *k_copy; value_t *v_copy; k_copy = strdup (k); if (k_copy == NULL) return ENOMEM; v_copy = malloc (sizeof (*v_copy)); if (v_copy == NULL) { sfree (k_copy); return ENOMEM; } *v_copy = v; e = llentry_create (k_copy, v_copy); if (e == NULL) { sfree (v_copy); sfree (k_copy); return ENOMEM; } llist_append (ksp, e); return 0; }
static int register_callback (llist_t **list, /* {{{ */ const char *name, callback_func_t *cf) { llentry_t *le; char *key; if (*list == NULL) { *list = llist_create (); if (*list == NULL) { ERROR ("plugin: register_callback: " "llist_create failed."); destroy_callback (cf); return (-1); } } key = strdup (name); if (key == NULL) { ERROR ("plugin: register_callback: strdup failed."); destroy_callback (cf); return (-1); } le = llist_search (*list, name); if (le == NULL) { le = llentry_create (key, cf); if (le == NULL) { ERROR ("plugin: register_callback: " "llentry_create failed."); free (key); destroy_callback (cf); return (-1); } llist_append (*list, le); } else { callback_func_t *old_cf; old_cf = le->value; le->value = cf; WARNING ("plugin: register_callback: " "a callback named `%s' already exists - " "overwriting the old entry!", name); destroy_callback (old_cf); sfree (key); } return (0); } /* }}} int register_callback */
static int mr_config_add_meta_regex(llist_t **meta, /* {{{ */ oconfig_item_t *ci) { char *meta_key; llentry_t *entry; mr_regex_t *re_head; int status; char buffer[1024]; if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) || (ci->values[1].type != OCONFIG_TYPE_STRING)) { log_warn("`%s' needs exactly two string arguments.", ci->key); return -1; } if (*meta == NULL) { *meta = llist_create(); if (*meta == NULL) { log_err("mr_config_add_meta_regex: llist_create failed."); return -1; } } meta_key = ci->values[0].value.string; entry = llist_search(*meta, meta_key); if (entry == NULL) { meta_key = strdup(meta_key); if (meta_key == NULL) { log_err("mr_config_add_meta_regex: strdup failed."); return -1; } entry = llentry_create(meta_key, NULL); if (entry == NULL) { log_err("mr_config_add_meta_regex: llentry_create failed."); sfree(meta_key); return -1; } /* meta_key and entry will now be freed by mr_free_match(). */ llist_append(*meta, entry); } snprintf(buffer, sizeof(buffer), "%s `%s'", ci->key, meta_key); /* Can't pass &entry->value into mr_add_regex, so copy in/out. */ re_head = entry->value; status = mr_add_regex(&re_head, ci->values[1].value.string, buffer); if (status == 0) { entry->value = re_head; } return status; } /* }}} int mr_config_add_meta_regex */
static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ { char *socket_temp; list_item_t *item; int status; int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("powerdns plugin: `%s' needs exactly one string argument.", ci->key); return (-1); } item = (list_item_t *) malloc (sizeof (list_item_t)); if (item == NULL) { ERROR ("powerdns plugin: malloc failed."); return (-1); } memset (item, '\0', sizeof (list_item_t)); item->instance = strdup (ci->values[0].value.string); if (item->instance == NULL) { ERROR ("powerdns plugin: strdup failed."); sfree (item); return (-1); } /* * Set default values for the members of list_item_t */ if (strcasecmp ("Server", ci->key) == 0) { item->server_type = SRV_AUTHORITATIVE; item->func = powerdns_read_server; item->socktype = SOCK_STREAM; socket_temp = strdup (SERVER_SOCKET); } else if (strcasecmp ("Recursor", ci->key) == 0) { item->server_type = SRV_RECURSOR; item->func = powerdns_read_recursor; item->socktype = SOCK_DGRAM; socket_temp = strdup (RECURSOR_SOCKET); } else { /* We must never get here.. */ assert (0); return (-1); } status = 0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; if (strcasecmp ("Collect", option->key) == 0) status = powerdns_config_add_collect (item, option); else if (strcasecmp ("Socket", option->key) == 0) status = powerdns_config_add_string ("Socket", &socket_temp, option); else { ERROR ("powerdns plugin: Option `%s' not allowed here.", option->key); status = -1; } if (status != 0) break; } while (status == 0) { llentry_t *e; if (socket_temp == NULL) { ERROR ("powerdns plugin: socket_temp == NULL."); status = -1; break; } item->sockaddr.sun_family = AF_UNIX; sstrncpy (item->sockaddr.sun_path, socket_temp, sizeof (item->sockaddr.sun_path)); e = llentry_create (item->instance, item); if (e == NULL) { ERROR ("powerdns plugin: llentry_create failed."); status = -1; break; } llist_append (list, e); break; } if (status != 0) { sfree (item); return (-1); } DEBUG ("powerdns plugin: Add server: instance = %s;", item->instance); return (0); } /* }}} int powerdns_config_add_server */
static int cx_config_add_xpath (cx_t *db, oconfig_item_t *ci) /* {{{ */ { cx_xpath_t *xpath; char *name; llentry_t *le; int status; int i; xpath = malloc (sizeof (*xpath)); if (xpath == NULL) { ERROR ("curl_xml plugin: malloc failed."); return (-1); } memset (xpath, 0, sizeof (*xpath)); status = cf_util_get_string (ci, &xpath->path); if (status != 0) { cx_xpath_free (xpath); return (status); } /* error out if xpath->path is an empty string */ if (strlen (xpath->path) == 0) { ERROR ("curl_xml plugin: invalid xpath. " "xpath value can't be an empty string"); cx_xpath_free (xpath); return (-1); } status = 0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Type", child->key) == 0) status = cf_util_get_string (child, &xpath->type); else if (strcasecmp ("InstancePrefix", child->key) == 0) status = cf_util_get_string (child, &xpath->instance_prefix); else if (strcasecmp ("InstanceFrom", child->key) == 0) status = cf_util_get_string (child, &xpath->instance); else if (strcasecmp ("ValuesFrom", child->key) == 0) status = cx_config_add_values ("ValuesFrom", xpath, child); else { WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ if (status != 0) { cx_xpath_free (xpath); return status; } if (xpath->type == NULL) { WARNING ("curl_xml plugin: `Type' missing in `xpath' block."); cx_xpath_free (xpath); return -1; } if (db->list == NULL) { db->list = llist_create(); if (db->list == NULL) { ERROR ("curl_xml plugin: list creation failed."); cx_xpath_free (xpath); return (-1); } } name = strdup (xpath->path); if (name == NULL) { ERROR ("curl_xml plugin: strdup failed."); cx_xpath_free (xpath); return (-1); } le = llentry_create (name, xpath); if (le == NULL) { ERROR ("curl_xml plugin: llentry_create failed."); cx_xpath_free (xpath); sfree (name); return (-1); } llist_append (db->list, le); return (0); } /* }}} int cx_config_add_xpath */
static int cx_config_add_xpath(cx_t *db, oconfig_item_t *ci) /* {{{ */ { cx_xpath_t *xpath = calloc(1, sizeof(*xpath)); if (xpath == NULL) { ERROR("curl_xml plugin: calloc failed."); return -1; } int status = cf_util_get_string(ci, &xpath->path); if (status != 0) { cx_xpath_free(xpath); return status; } /* error out if xpath->path is an empty string */ if (strlen(xpath->path) == 0) { ERROR("curl_xml plugin: invalid xpath. " "xpath value can't be an empty string"); cx_xpath_free(xpath); return -1; } status = 0; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("Type", child->key) == 0) status = cf_util_get_string(child, &xpath->type); else if (strcasecmp("InstancePrefix", child->key) == 0) status = cf_util_get_string(child, &xpath->instance_prefix); else if (strcasecmp("InstanceFrom", child->key) == 0) status = cf_util_get_string(child, &xpath->instance); else if (strcasecmp("PluginInstanceFrom", child->key) == 0) status = cf_util_get_string(child, &xpath->plugin_instance_from); else if (strcasecmp("ValuesFrom", child->key) == 0) status = cx_config_add_values("ValuesFrom", xpath, child); else { WARNING("curl_xml plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ if (status != 0) { cx_xpath_free(xpath); return status; } if (xpath->type == NULL) { WARNING("curl_xml plugin: `Type' missing in `xpath' block."); cx_xpath_free(xpath); return -1; } if (xpath->values_len == 0) { WARNING("curl_xml plugin: `ValuesFrom' missing in `xpath' block."); cx_xpath_free(xpath); return -1; } llentry_t *le = llentry_create(xpath->path, xpath); if (le == NULL) { ERROR("curl_xml plugin: llentry_create failed."); cx_xpath_free(xpath); return -1; } llist_append(db->xpath_list, le); return 0; } /* }}} int cx_config_add_xpath */