@@ -205,6 +205,25 @@ void *hashtable_search(const struct hashtable *h, const void *k)
return e ? e->v : NULL;
}
+int hashtable_replace(struct hashtable *h, const void *k, void *v)
+{
+ struct entry *e;
+
+ e = hashtable_search_entry(h, k);
+ if (!e)
+ return ENOENT;
+
+ if (h->flags & HASHTABLE_FREE_VALUE)
+ {
+ talloc_free(e->v);
+ talloc_steal(e, v);
+ }
+
+ e->v = v;
+
+ return 0;
+}
+
void
hashtable_remove(struct hashtable *h, const void *k)
{
@@ -45,6 +45,22 @@ create_hashtable(const void *ctx, const char *name,
int
hashtable_add(struct hashtable *h, const void *k, void *v);
+/*****************************************************************************
+ * hashtable_replace
+
+ * @name hashtable_nsert
+ * @param h the hashtable to insert into
+ * @param k the key - hashtable claims ownership and will free on removal
+ * @param v the value - does not claim ownership
+ * @return zero for successful insertion
+ *
+ * This function does check for an entry being present before replacing it
+ * with a new value.
+ */
+
+int
+hashtable_replace(struct hashtable *h, const void *k, void *v);
+
/*****************************************************************************
* hashtable_search