d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina Pavel Březina <pbrezina@redhat.com>
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina Copyright (C) 2016 Red Hat
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina This program is free software; you can redistribute it and/or modify
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina it under the terms of the GNU General Public License as published by
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina the Free Software Foundation; either version 3 of the License, or
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina (at your option) any later version.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina This program is distributed in the hope that it will be useful,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina GNU General Public License for more details.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina You should have received a copy of the GNU General Public License
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#include "providers/data_provider/dp_private.h"
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinadp_sbus_req_item_destructor(struct dp_sbus_req_item *item)
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinadp_table_value_destructor(struct dp_table_value *value)
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Removing [%s] from reply table\n", value->key);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina for (item = value->list; item != NULL; item = next_item) {
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinadp_sbus_req_item_new(struct dp_table_value *value,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina /* Attach to sbus_request so we ensure that this sbus_req is removed
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * from the list when it is unexpectedly freed, for example when
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * client connection is dropped. */
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina item = talloc_zero(sbus_req, struct dp_sbus_req_item);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero() failed\n");
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina talloc_set_destructor(item, dp_sbus_req_item_destructor);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *str = custom_part == NULL ? "(null)" : custom_part;
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina return talloc_asprintf(mem_ctx, "%u:%u:%#.4x:%s",
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinaerrno_t dp_req_table_init(TALLOC_CTX *mem_ctx, hash_table_t **_table)
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinastruct dp_table_value *dp_req_table_lookup(hash_table_t *table,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *key)
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to search hash table [%d]\n", hret);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinastatic errno_t dp_req_table_new_item(hash_table_t *table,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *key,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina /* Attach it to request. */
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina table_value = talloc_zero(req, struct dp_table_value);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina table_value->key = talloc_strdup(table_value, key);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina table_value->list = dp_sbus_req_item_new(table_value, sbus_req);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina talloc_set_destructor(table_value, dp_table_value_destructor);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to enter value into hash table "
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinastatic errno_t dp_req_table_mod_item(hash_table_t *table,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina item = dp_sbus_req_item_new(table_value, sbus_req);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *key,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "SBUS request cannot be NULL\n");
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina table_value = dp_req_table_lookup(table, key);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Tevent request cannot be NULL\n");
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina return dp_req_table_new_item(table, key, req, sbus_req);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina return dp_req_table_mod_item(table, table_value, sbus_req);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *key)
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina if (hret != HASH_SUCCESS && hret != HASH_ERROR_KEY_NOT_FOUND) {
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to remove key from table [%d]\n",
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinavoid dp_req_table_del_and_free(hash_table_t *table,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *key)
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina /* We're done here. */
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *key)