[dovecot-cvs] dovecot/src/lib-dict Makefile.am, 1.2, 1.3 dict-private.h, 1.1, 1.2 dict-sql.c, 1.1, 1.2 dict.c, 1.2, 1.3 dict.h, 1.2, 1.3

cras at dovecot.org cras at dovecot.org
Sat Dec 31 00:09:08 EET 2005


Update of /var/lib/cvs/dovecot/src/lib-dict
In directory talvi:/tmp/cvs-serv32553/src/lib-dict

Modified Files:
	Makefile.am dict-private.h dict-sql.c dict.c dict.h 
Log Message:
Added dictinary lookup server and a "proxy" dict implementation to talk to
it.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile.am	10 Dec 2005 22:25:05 -0000	1.2
+++ Makefile.am	30 Dec 2005 22:09:03 -0000	1.3
@@ -7,9 +7,11 @@
 
 libdict_a_SOURCES = \
 	dict.c \
+	dict-client.c \
 	dict-sql.c
 
 noinst_HEADERS = \
 	dict.h \
+	dict-client.h \
 	dict-private.h \
 	dict-sql.h

Index: dict-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/dict-private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dict-private.h	10 Dec 2005 18:59:03 -0000	1.1
+++ dict-private.h	30 Dec 2005 22:09:03 -0000	1.2
@@ -7,7 +7,8 @@
 	struct dict *(*init)(struct dict *dict_class, const char *uri);
 	void (*deinit)(struct dict *dict);
 
-	char *(*lookup)(struct dict *dict, pool_t pool, const char *key);
+	int (*lookup)(struct dict *dict, pool_t pool,
+		      const char *key, const char **value_r);
 
 	struct dict_iterate_context *
 		(*iterate_init)(struct dict *dict, const char *path,

Index: dict-sql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/dict-sql.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dict-sql.c	10 Dec 2005 18:59:03 -0000	1.1
+++ dict-sql.c	30 Dec 2005 22:09:03 -0000	1.2
@@ -27,6 +27,12 @@
 	struct sql_result *result;
 };
 
+struct sql_dict_transaction_context {
+	struct dict_transaction_context ctx;
+
+	struct sql_transaction_context *sql_ctx;
+};
+
 static int sql_dict_read_config(struct sql_dict *dict, const char *path)
 {
 	struct istream *input;
@@ -91,14 +97,16 @@
 	struct sql_dict *dict = (struct sql_dict *)_dict;
 
 	sql_deinit(dict->db);
+	pool_unref(dict->pool);
 }
 
-static char *sql_dict_lookup(struct dict *_dict, pool_t pool, const char *key)
+static int sql_dict_lookup(struct dict *_dict, pool_t pool,
+			   const char *key, const char **value_r)
 {
 	struct sql_dict *dict = (struct sql_dict *)_dict;
 	struct sql_result *result;
 	const char *query;
-	char *ret;
+	int ret;
 
 	t_push();
 	query = t_strdup_printf("SELECT %s FROM %s WHERE %s = '%s'",
@@ -107,10 +115,13 @@
 	result = sql_query_s(dict->db, query);
 	t_pop();
 
-	if (sql_result_next_row(result) <= 0)
-		ret = NULL;
-	else
-                ret = p_strdup(pool, sql_result_get_field_value(result, 0));
+	ret = sql_result_next_row(result);
+	if (ret <= 0)
+		*value_r = NULL;
+	else {
+		*value_r =
+			p_strdup(pool, sql_result_get_field_value(result, 0));
+	}
 
 	sql_result_free(result);
 	return ret;
@@ -162,14 +173,9 @@
 		(struct sql_dict_iterate_context *)_ctx;
 
 	sql_result_free(ctx->result);
+	i_free(ctx);
 }
 
-struct sql_dict_transaction_context {
-	struct dict_transaction_context ctx;
-
-	struct sql_transaction_context *sql_ctx;
-};
-
 static struct dict_transaction_context *
 sql_dict_transaction_init(struct dict *_dict)
 {

Index: dict.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/dict.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dict.c	14 Dec 2005 21:34:28 -0000	1.2
+++ dict.c	30 Dec 2005 22:09:03 -0000	1.3
@@ -7,16 +7,6 @@
 
 static array_t ARRAY_DEFINE(dict_classes, struct dict *);
 
-void dict_class_register_all(void)
-{
-	dict_sql_register();
-}
-
-void dict_class_unregister_all(void)
-{
-	dict_sql_unregister();
-}
-
 static struct dict *dict_class_lookup(const char *name)
 {
 	struct dict *const *dicts;
@@ -86,9 +76,10 @@
 	dict->v.deinit(dict);
 }
 
-char *dict_lookup(struct dict *dict, pool_t pool, const char *key)
+int dict_lookup(struct dict *dict, pool_t pool, const char *key,
+		const char **value_r)
 {
-	return dict->v.lookup(dict, pool, key);
+	return dict->v.lookup(dict, pool, key, value_r);
 }
 
 struct dict_iterate_context *

Index: dict.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/dict.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dict.h	14 Dec 2005 21:34:28 -0000	1.2
+++ dict.h	30 Dec 2005 22:09:03 -0000	1.3
@@ -6,9 +6,6 @@
 
 struct dict;
 
-void dict_class_register_all(void);
-void dict_class_unregister_all(void);
-
 void dict_class_register(struct dict *dict_class);
 void dict_class_unregister(struct dict *dict_class);
 
@@ -18,8 +15,9 @@
 /* Close dictionary. */
 void dict_deinit(struct dict *dict);
 
-/* Return value for key, or NULL if not found. */
-char *dict_lookup(struct dict *dict, pool_t pool, const char *key);
+/* Lookup value for key. Set it to NULL if it's not found.
+   Returns 1 if found, 0 if not found and -1 if lookup failed. */
+int dict_lookup(struct dict *dict, pool_t pool, const char *key, const char **value_r);
 
 /* Iterate through all values in a path. If recurse is FALSE, keys in
    the given path are returned, but not their children. */



More information about the dovecot-cvs mailing list