[dovecot-cvs] dovecot/src/lib-mail message-body-search.c, 1.35, 1.36 message-header-search.c, 1.20, 1.21
tss at dovecot.org
tss at dovecot.org
Wed Apr 4 12:28:21 EEST 2007
Update of /var/lib/cvs/dovecot/src/lib-mail
In directory talvi:/tmp/cvs-serv25349
Modified Files:
message-body-search.c message-header-search.c
Log Message:
Use str_find_*() to perform the actual search.
Index: message-body-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-body-search.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- message-body-search.c 4 Apr 2007 09:27:32 -0000 1.35
+++ message-body-search.c 4 Apr 2007 09:28:16 -0000 1.36
@@ -3,6 +3,7 @@
#include "lib.h"
#include "buffer.h"
#include "istream.h"
+#include "str-find.h"
#include "charset-utf8.h"
#include "message-decoder.h"
#include "message-parser.h"
@@ -16,7 +17,7 @@
char *key_charset;
unsigned int key_len;
- buffer_t *match_buf;
+ struct str_find_context *str_find_ctx;
struct message_decoder_context *decoder;
unsigned int search_header:1;
@@ -37,55 +38,6 @@
t_pop();
}
-static bool
-message_search_decoded_block(struct message_body_search_context *ctx,
- const unsigned char *data, size_t size)
-{
- const unsigned char *p, *end, *key;
- unsigned int key_len;
- size_t *matches, match_count, value;
- ssize_t i;
-
- key = (const unsigned char *)ctx->key;
- key_len = ctx->key_len;
-
- matches = buffer_get_modifiable_data(ctx->match_buf, &match_count);
- match_count /= sizeof(size_t);
-
- end = data + size;
- for (p = data; p != end; p++) {
- for (i = match_count-1; i >= 0; i--) {
- if (key[matches[i]] == *p) {
- if (++matches[i] == key_len) {
- /* full match */
- p++;
- return TRUE;
- }
- } else {
- /* non-match */
- buffer_delete(ctx->match_buf,
- i * sizeof(size_t),
- sizeof(size_t));
- match_count--;
- }
- }
-
- if (*p == key[0]) {
- if (key_len == 1) {
- /* only one character in search key */
- p++;
- return TRUE;
- }
-
- value = 1;
- buffer_append(ctx->match_buf, &value, sizeof(value));
- match_count++;
- }
- }
-
- return FALSE;
-}
-
int message_body_search_init(pool_t pool, const char *key, const char *charset,
bool search_header,
struct message_body_search_context **ctx_r)
@@ -111,9 +63,7 @@
ctx->key_charset = p_strdup(pool, charset);
ctx->search_header = search_header;
ctx->decoder = message_decoder_init_ucase();
- ctx->match_buf =
- buffer_create_static_hard(pool, sizeof(size_t) * ctx->key_len);
-
+ ctx->str_find_ctx = str_find_init(pool, ctx->key);
t_pop();
return 1;
}
@@ -123,8 +73,8 @@
struct message_body_search_context *ctx = *_ctx;
*_ctx = NULL;
+ str_find_deinit(&ctx->str_find_ctx);
message_decoder_deinit(&ctx->decoder);
- buffer_free(ctx->match_buf);
p_free(ctx->pool, ctx->key);
p_free(ctx->pool, ctx->key_charset);
p_free(ctx->pool, ctx);
@@ -148,13 +98,12 @@
static bool search_header(struct message_body_search_context *ctx,
const struct message_header_line *hdr)
{
- return message_search_decoded_block(ctx,
- (const unsigned char *)hdr->name,
- hdr->name_len) ||
- message_search_decoded_block(ctx, hdr->middle,
- hdr->middle_len) ||
- message_search_decoded_block(ctx, hdr->full_value,
- hdr->full_value_len);
+ return str_find_more(ctx->str_find_ctx,
+ (const unsigned char *)hdr->name, hdr->name_len) ||
+ str_find_more(ctx->str_find_ctx,
+ hdr->middle, hdr->middle_len) ||
+ str_find_more(ctx->str_find_ctx, hdr->full_value,
+ hdr->full_value_len);
}
int message_body_search(struct message_body_search_context *ctx,
@@ -188,7 +137,7 @@
} else if (raw_block.size == 0) {
/* part changes */
ctx->content_type_text = TRUE;
- buffer_reset(ctx->match_buf);
+ str_find_reset(ctx->str_find_ctx);
continue;
} else {
/* body */
@@ -205,8 +154,8 @@
break;
}
} else {
- if (message_search_decoded_block(ctx, block.data,
- block.size)) {
+ if (str_find_more(ctx->str_find_ctx,
+ block.data, block.size)) {
ret = 1;
break;
}
Index: message-header-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-header-search.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- message-header-search.c 3 Apr 2007 18:18:57 -0000 1.20
+++ message-header-search.c 4 Apr 2007 09:28:18 -0000 1.21
@@ -3,6 +3,7 @@
#include "lib.h"
#include "base64.h"
#include "buffer.h"
+#include "str-find.h"
#include "charset-utf8.h"
#include "quoted-printable.h"
#include "message-parser.h"
@@ -18,10 +19,10 @@
size_t key_len;
char *key_charset;
- buffer_t *match_buf;
+ struct str_find_context *str_find_ctx;
unsigned int found:1;
- unsigned int last_newline:1;
+ unsigned int last_lf:1;
unsigned int unknown_charset:1;
};
@@ -50,10 +51,9 @@
ctx->key_len = key_len;
ctx->key_charset = p_strdup(pool, charset);
ctx->unknown_charset = charset == NULL;
+ ctx->str_find_ctx = str_find_init(pool, key);
i_assert(ctx->key_len <= SSIZE_T_MAX/sizeof(size_t));
- ctx->match_buf = buffer_create_static_hard(pool, sizeof(size_t) *
- ctx->key_len);
t_pop();
return 1;
}
@@ -65,7 +65,7 @@
*_ctx = NULL;
- buffer_free(ctx->match_buf);
+ str_find_deinit(&ctx->str_find_ctx);
pool = ctx->pool;
p_free(pool, ctx->key);
@@ -73,71 +73,11 @@
p_free(pool, ctx);
}
-static void search_loop(struct message_header_search_context *ctx,
- const unsigned char *data, size_t size)
-{
- size_t pos, *matches, match_count, value;
- ssize_t i;
- unsigned char chr;
- bool last_newline;
-
- matches = buffer_get_modifiable_data(ctx->match_buf, &match_count);
- match_count /= sizeof(size_t);
-
- last_newline = ctx->last_newline;
- for (pos = 0; pos < size; pos++) {
- chr = data[pos];
-
- if (last_newline) {
- if (!IS_LWSP(chr)) {
- /* not a long header, reset matches */
- buffer_set_used_size(ctx->match_buf, 0);
- match_count = 0;
- }
- chr = ' ';
- }
- last_newline = chr == '\n';
-
- if (chr == '\r' || chr == '\n')
- continue;
-
- for (i = match_count-1; i >= 0; i--) {
- if (ctx->key[matches[i]] == chr) {
- if (++matches[i] == ctx->key_len) {
- /* full match */
- ctx->found = TRUE;
- return;
- }
- } else {
- /* non-match */
- buffer_delete(ctx->match_buf,
- i * sizeof(size_t),
- sizeof(size_t));
- match_count--;
- }
- }
-
- if (chr == ctx->key[0]) {
- if (ctx->key_len == 1) {
- /* only one character in search key */
- ctx->found = TRUE;
- break;
- }
-
- value = 1;
- buffer_append(ctx->match_buf, &value, sizeof(value));
- match_count++;
- }
- }
-
- ctx->last_newline = last_newline;
-}
-
-static void search_with_charset(const unsigned char *data, size_t size,
+static bool search_with_charset(const unsigned char *data, size_t size,
const char *charset,
struct message_header_search_context *ctx)
{
- const void *utf8_data;
+ const char *utf8_data;
size_t utf8_size;
if (ctx->unknown_charset) {
@@ -161,7 +101,7 @@
utf8_size = size;
}
- search_loop(ctx, utf8_data, utf8_size);
+ return str_find_more(ctx->str_find_ctx, utf8_data, utf8_size);
}
static bool search_block(const unsigned char *data, size_t size,
@@ -170,7 +110,7 @@
struct message_header_search_context *ctx = context;
t_push();
- search_with_charset(data, size, charset, ctx);
+ ctx->found = search_with_charset(data, size, charset, ctx);
t_pop();
return !ctx->found;
}
@@ -185,6 +125,7 @@
void message_header_search_reset(struct message_header_search_context *ctx)
{
- buffer_set_used_size(ctx->match_buf, 0);
+ str_find_reset(ctx->str_find_ctx);
+ ctx->last_lf = FALSE;
ctx->found = FALSE;
}
More information about the dovecot-cvs
mailing list