Beispiel #1
0
/**
 * @brief print all the values in a list if debugging is enabled
 * @param list the list
 * @param str a string to print before the results.
 *
 * XXX: move this to msg.c?
 */
void
saslc__list_log(list_t *list, const char *str)
{
	list_t *l;

	if (!saslc_debug)
		return;

	saslc__msg_dbg("%s", str);
	for (l = list; l != NULL; l = l->next)
		saslc__msg_dbg("  value: '%s'\n",
		    l->value ? l->value : "<null>");
}
Beispiel #2
0
/**
 * @brief removes node from the dictionary using key
 * @param dict dictionary
 * @param key node key
 * @return DICT_OK on success, DICT_KEYNOTFOUND if node was not found (key
 * does not exist in the dictionary.
 */
saslc__dict_result_t
saslc__dict_remove(saslc__dict_t *dict, const char *key)
{
    saslc__dict_node_t *node;

    node = saslc__dict_get_node_by_key(dict, key);
    if (node == NULL)
        return DICT_KEYNOTFOUND;

    saslc__dict_list_node_destroy(node);
    saslc__msg_dbg("%s: removed key %s", __func__, key);
    return DICT_OK;
}
Beispiel #3
0
/**
 * @brief inserts node into dictionary
 * @param dict dictionary
 * @param key node key
 * @param val node value
 * @return
 * DICT_OK - on success,
 * DICT_KEYINVALID - if node key is illegal,
 * DICT_VALBAD - if node value is illegal,
 * DICT_KEYEXISTS - if node with the same key already exists in the
 * dictionary,
 * DICT_NOMEM - on allocation failure
 */
saslc__dict_result_t
saslc__dict_insert(saslc__dict_t *dict, const char *key, const char *val)
{
    char *d_key, *d_val;
    saslc__dict_node_t *node;

    if (key == NULL || saslc__dict_valid_key(key) == false) {
        saslc__msg_dbg("%s: invalid key: %s", __func__,
                       key ? key : "<null>");
        return DICT_KEYINVALID;
    }
    if (val == NULL) {
        saslc__msg_dbg("%s: NULL value for key %s", __func__, key);
        return DICT_VALBAD;
    }
    /* check if key exists in dictionary */
    if (saslc__dict_get(dict, key) != NULL) {
        saslc__msg_dbg("%s: key exists (ignoring): %s", __func__, key);
        return DICT_KEYEXISTS;
    }
    if ((d_key = strdup(key)) == NULL)
        goto nomem;

    if ((d_val = strdup(val)) == NULL) {
        free(d_key);
        goto nomem;
    }
    if ((node = calloc(1, sizeof(*node))) == NULL) {
        free(d_val);
        free(d_key);
        goto nomem;
    }
    dict = saslc__dict_hash(dict, key);
    if (!LIST_EMPTY(dict))
        saslc__msg_dbg("%s: hash collision: '%s' vs '%s'\n",
                       __func__, key, LIST_FIRST(dict)->key);

    saslc__msg_dbg("%s: %s=\"%s\"", __func__, d_key, d_val);
    LIST_INSERT_HEAD(dict, node, nodes);
    node->key = d_key;
    node->value = d_val;
    node->value_len = strlen(node->value);
    return DICT_OK;
nomem:
    saslc__msg_dbg("%s: %s", __func__, strerror(errno));
    return DICT_NOMEM;
}