[dovecot-cvs] dovecot/src/dict dict-cache.c, 1.4, 1.5 dict-cache.h, 1.2, 1.3 dict-server.c, 1.14, 1.15

tss-movial at dovecot.org tss-movial at dovecot.org
Sun Jul 30 21:49:42 EEST 2006


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

Modified Files:
	dict-cache.c dict-cache.h dict-server.c 
Log Message:
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.



Index: dict-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/dict/dict-cache.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dict-cache.c	31 Jan 2006 06:05:22 -0000	1.4
+++ dict-cache.c	30 Jul 2006 18:49:39 -0000	1.5
@@ -32,6 +32,7 @@
 }
 
 struct dict *dict_cache_get(struct dict_cache *cache, const char *uri,
+			    enum dict_data_type value_type,
 			    const char *username)
 {
 	struct dict_entry *entry;
@@ -39,7 +40,7 @@
 	entry = hash_lookup(cache->dicts, uri);
 	if (entry == NULL) {
 		entry = i_new(struct dict_entry, 1);
-		entry->dict = dict_init(uri, username);
+		entry->dict = dict_init(uri, value_type, username);
 		entry->uri = i_strdup(uri);
 		hash_insert(cache->dicts, entry->uri, entry);
 	}

Index: dict-cache.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/dict/dict-cache.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dict-cache.h	31 Jan 2006 06:05:22 -0000	1.2
+++ dict-cache.h	30 Jul 2006 18:49:39 -0000	1.3
@@ -5,6 +5,7 @@
 void dict_cache_deinit(struct dict_cache *cache);
 
 struct dict *dict_cache_get(struct dict_cache *cache, const char *uri,
+			    enum dict_data_type value_type,
 			    const char *username);
 void dict_cache_unref(struct dict_cache *cache, const char *uri);
 

Index: dict-server.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/dict/dict-server.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- dict-server.c	28 Jun 2006 13:10:31 -0000	1.14
+++ dict-server.c	30 Jul 2006 18:49:39 -0000	1.15
@@ -25,6 +25,7 @@
 	char *username;
 	char *name, *uri;
 	struct dict *dict;
+	enum dict_data_type value_type;
 
 	int fd;
 	struct io *io;
@@ -85,7 +86,7 @@
 		return -1;
 	}
 
-	/* <recurse 1/0> <path> */
+	/* <flags> <path> */
 	o_stream_cork(conn->output);
 	ctx = dict_iterate_init(conn->dict, args[1], atoi(args[0]));
 	while ((ret = dict_iterate(ctx, &key, &value)) > 0) {
@@ -232,6 +233,25 @@
 	return 0;
 }
 
+static int cmd_unset(struct dict_client_connection *conn, const char *line)
+{
+	struct dict_server_transaction *trans;
+	const char *const *args;
+
+	/* <id> <key> */
+	args = t_strsplit(line, "\t");
+	if (strarray_length(args) != 2) {
+		i_error("dict client: UNSET: broken input");
+		return -1;
+	}
+
+	if (dict_server_transaction_lookup_parse(conn, args[0], &trans) < 0)
+		return -1;
+
+        dict_unset(trans->ctx, args[1]);
+	return 0;
+}
+
 static int cmd_atomic_inc(struct dict_client_connection *conn, const char *line)
 {
 	struct dict_server_transaction *trans;
@@ -263,6 +283,7 @@
 	{ DICT_PROTOCOL_CMD_COMMIT, cmd_commit },
 	{ DICT_PROTOCOL_CMD_ROLLBACK, cmd_rollback },
 	{ DICT_PROTOCOL_CMD_SET, cmd_set },
+	{ DICT_PROTOCOL_CMD_UNSET, cmd_unset },
 	{ DICT_PROTOCOL_CMD_ATOMIC_INC, cmd_atomic_inc },
 
 	{ 0, NULL }
@@ -271,7 +292,7 @@
 static int dict_client_parse_handshake(struct dict_client_connection *conn,
 				       const char *line)
 {
-	const char *username, *name;
+	const char *username, *name, *value_type;
 
 	if (*line++ != DICT_PROTOCOL_CMD_HELLO)
 		return -1;
@@ -287,13 +308,20 @@
 	if (*line++ != '\t')
 		return -1;
 
+	/* get value type */
+	value_type = line;
+	while (*line != '\t' && *line != '\0') line++;
+
+	if (*line++ != '\t')
+		return -1;
+	conn->value_type = atoi(t_strdup_until(value_type, line - 1));
+
 	/* get username */
 	username = line;
 	while (*line != '\t' && *line != '\0') line++;
 
 	if (*line++ != '\t')
 		return -1;
-
 	conn->username = i_strdup_until(username, line - 1);
 
 	/* the rest is dict name. since we're looking it with getenv(),
@@ -321,7 +349,7 @@
 
 	conn->uri = i_strdup(uri);
 	conn->dict = dict_cache_get(conn->server->cache, conn->uri,
-				    conn->username);
+				    conn->value_type, conn->username);
 	if (conn->dict == NULL) {
 		/* dictionary initialization failed */
 		i_error("Failed to initialize dictionary '%s'", conn->name);



More information about the dovecot-cvs mailing list