[dovecot-cvs] dovecot/src/lib-index mail-index-view.c, 1.39, 1.40 mail-index.h, 1.154, 1.155

cras at dovecot.org cras at dovecot.org
Fri Jan 6 20:57:09 EET 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv9245

Modified Files:
	mail-index-view.c mail-index.h 
Log Message:
mail_index_ext_get_size() hadn't been implemented even though it was in
mail-index.h. Implemented it and changed mail_index_lookup_keywords() to use
it.



Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- mail-index-view.c	6 Jan 2006 18:38:01 -0000	1.39
+++ mail-index-view.c	6 Jan 2006 18:57:05 -0000	1.40
@@ -417,10 +417,9 @@
 	const struct mail_index_ext *ext;
 	uint32_t idx;
 
-	if (map != NULL) {
-		if (mail_index_view_lock(view) < 0)
-			return -1;
-	} else {
+	/* if we have a mapping, the view where it's from is already locked */
+	if (map == NULL) {
+		/* no mapping given, use head mapping */
 		if (mail_index_view_lock_head(view, FALSE) < 0)
 			return -1;
 
@@ -428,6 +427,7 @@
 	}
 
 	if (!mail_index_map_get_ext_idx(map, ext_id, &idx)) {
+		/* extension doesn't exist in this index file */
 		*data_r = NULL;
 		*data_size_r = 0;
 		return 0;
@@ -478,24 +478,31 @@
 {
 	ARRAY_SET_TYPE(keyword_idx, unsigned int);
 	struct mail_index_map *map;
-	const struct mail_index_ext *ext;
 	const void *data;
+	const unsigned char *keyword_data;
 	const unsigned int *keyword_idx_map;
 	unsigned int i, j, keyword_count, index_idx;
 	uint32_t ext_id, idx;
+	uint16_t record_size;
 	int ret;
 
 	array_clear(keyword_idx);
 
+	/* get the keywords data. */
 	ext_id = view->index->keywords_ext_id;
 	ret = mail_index_lookup_ext_full(view, seq, ext_id, &map, &data);
 	if (ret < 0)
 		return -1;
 
-	if (!mail_index_map_get_ext_idx(map, ext_id, &idx))
+	if (data == NULL) {
+		/* no keywords at all in index */
 		return ret;
+	}
 
-	ext = array_idx(&map->extensions, idx);
+	(void)mail_index_ext_get_size(view, ext_id, map, NULL,
+				      &record_size, NULL);
+
+	/* keyword_idx_map[] contains file => index keyword mapping */
 	if (!array_is_created(&map->keyword_idx_map)) {
 		keyword_idx_map = NULL;
 		keyword_count = 0;
@@ -504,13 +511,15 @@
 					    &keyword_count);
 	}
 
-	for (i = 0, idx = 0; i < ext->record_size; i++) {
-		if (((const unsigned char *)data)[i] == 0)
+        keyword_data = data;
+	for (i = 0, idx = 0; i < record_size; i++) {
+		/* first do the quick check to see if there's keywords at all */
+		if (keyword_data[i] == 0)
 			continue;
 
 		idx = i * CHAR_BIT;
 		for (j = 0; j < CHAR_BIT; j++, idx++) {
-			if ((((const unsigned char *)data)[i] & (1 << j)) == 0)
+			if ((keyword_data[i] & (1 << j)) == 0)
 				continue;
 
 			if (idx >= keyword_count) {
@@ -524,6 +533,7 @@
 				if (!array_is_created(&map->keyword_idx_map))
 					return ret;
 
+				/* pointer may have changed. update it. */
 				keyword_idx_map =
 					array_get(&map->keyword_idx_map,
 						  &keyword_count);
@@ -592,6 +602,37 @@
 					    data_r, data_size_r);
 }
 
+int mail_index_ext_get_size(struct mail_index_view *view __attr_unused__,
+			    uint32_t ext_id, struct mail_index_map *map,
+			    uint32_t *hdr_size_r, uint16_t *record_size_r,
+			    uint16_t *record_align_r)
+{
+	const struct mail_index_ext *ext;
+	uint32_t idx;
+
+	i_assert(map != NULL);
+
+	if (!mail_index_map_get_ext_idx(map, ext_id, &idx)) {
+		/* extension doesn't exist in this index file */
+		if (hdr_size_r != NULL)
+			*hdr_size_r = 0;
+		if (record_size_r != NULL)
+			*record_size_r = 0;
+		if (record_align_r != NULL)
+			*record_align_r = 0;
+		return 0;
+	}
+
+	ext = array_idx(&map->extensions, idx);
+	if (hdr_size_r != NULL)
+		*hdr_size_r = ext->hdr_size;
+	if (record_size_r != NULL)
+		*record_size_r = ext->record_size;
+	if (record_align_r != NULL)
+		*record_align_r = ext->record_align;
+	return 0;
+}
+
 static struct mail_index_view_methods view_methods = {
 	_view_close,
 	_view_get_messages_count,

Index: mail-index.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -d -r1.154 -r1.155
--- mail-index.h	6 Jan 2006 17:37:30 -0000	1.154
+++ mail-index.h	6 Jan 2006 18:57:05 -0000	1.155
@@ -368,11 +368,6 @@
 				 uint32_t default_hdr_size,
 				 uint16_t default_record_size,
 				 uint16_t default_record_align);
-/* Get current extension sizes. Returns 1 if ok, 0 if extension doesn't exist
-   in view. */
-int mail_index_ext_get_size(struct mail_index_view *view, uint32_t ext_id,
-			    uint32_t *hdr_size_r, uint16_t *record_size_r,
-			    uint16_t *record_align_r);
 /* Resize existing extension data. If size is grown, the new data will be
    zero-filled. If size is shrinked, the data is simply dropped. */
 void mail_index_ext_resize(struct mail_index_transaction *t, uint32_t ext_id,
@@ -398,6 +393,12 @@
 int mail_index_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
 			       uint32_t ext_id, struct mail_index_map **map_r,
 			       const void **data_r);
+/* Get current extension sizes. Returns 1 if ok, 0 if extension doesn't exist
+   in view. Any of the _r parameters may be NULL. */
+int mail_index_ext_get_size(struct mail_index_view *view,
+			    uint32_t ext_id, struct mail_index_map *map,
+			    uint32_t *hdr_size_r, uint16_t *record_size_r,
+			    uint16_t *record_align_r);
 /* Update extension header field. */
 void mail_index_update_header_ext(struct mail_index_transaction *t,
 				  uint32_t ext_id, size_t offset,



More information about the dovecot-cvs mailing list