dovecot-2.1: lib-imap: Added reference counting to imap parser.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Oct 9 20:28:07 EEST 2011
details: http://hg.dovecot.org/dovecot-2.1/rev/f63f2b2217c3
changeset: 13627:f63f2b2217c3
user: Timo Sirainen <tss at iki.fi>
date: Sun Oct 09 20:36:28 2011 +0300
description:
lib-imap: Added reference counting to imap parser.
diffstat:
src/director/director-test.c | 2 +-
src/imap-login/client.c | 4 ++--
src/imap/cmd-append.c | 2 +-
src/imap/imap-client.c | 6 +++---
src/lib-imap-client/imapc-connection.c | 2 +-
src/lib-imap/imap-bodystructure.c | 2 +-
src/lib-imap/imap-envelope.c | 2 +-
src/lib-imap/imap-id.c | 2 +-
src/lib-imap/imap-parser.c | 16 +++++++++++++++-
src/lib-imap/imap-parser.h | 3 ++-
src/lib-imap/test-imap-parser.c | 2 +-
src/plugins/virtual/virtual-config.c | 2 +-
12 files changed, 30 insertions(+), 15 deletions(-)
diffs (201 lines):
diff -r 2dbc6108f090 -r f63f2b2217c3 src/director/director-test.c
--- a/src/director/director-test.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/director/director-test.c Sun Oct 09 20:36:28 2011 +0300
@@ -275,7 +275,7 @@
}
DLLIST_REMOVE(&imap_clients, client);
- imap_parser_destroy(&client->parser);
+ imap_parser_unref(&client->parser);
io_remove(&client->io);
i_stream_unref(&client->input);
o_stream_unref(&client->output);
diff -r 2dbc6108f090 -r f63f2b2217c3 src/imap-login/client.c
--- a/src/imap-login/client.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/imap-login/client.c Sun Oct 09 20:36:28 2011 +0300
@@ -365,7 +365,7 @@
struct imap_client *imap_client = (struct imap_client *)client;
i_free_and_null(imap_client->proxy_backend_capability);
- imap_parser_destroy(&imap_client->parser);
+ imap_parser_unref(&imap_client->parser);
}
static void imap_client_send_greeting(struct client *client)
@@ -386,7 +386,7 @@
{
struct imap_client *imap_client = (struct imap_client *)client;
- imap_parser_destroy(&imap_client->parser);
+ imap_parser_unref(&imap_client->parser);
imap_client->parser =
imap_parser_create(imap_client->common.input,
imap_client->common.output, MAX_IMAP_LINE);
diff -r 2dbc6108f090 -r f63f2b2217c3 src/imap/cmd-append.c
--- a/src/imap/cmd-append.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/imap/cmd-append.c Sun Oct 09 20:36:28 2011 +0300
@@ -145,7 +145,7 @@
static void cmd_append_finish(struct cmd_append_context *ctx)
{
- imap_parser_destroy(&ctx->save_parser);
+ imap_parser_unref(&ctx->save_parser);
i_assert(ctx->client->input_lock == ctx->cmd);
diff -r 2dbc6108f090 -r f63f2b2217c3 src/imap/imap-client.c
--- a/src/imap/imap-client.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/imap/imap-client.c Sun Oct 09 20:36:28 2011 +0300
@@ -44,7 +44,7 @@
net_set_nonblock(fd_in, TRUE);
net_set_nonblock(fd_out, TRUE);
- pool = pool_alloconly_create("imap client", 1024);
+ pool = pool_alloconly_create("imap client", 2048);
client = p_new(pool, struct client, 1);
client->pool = pool;
client->set = set;
@@ -210,7 +210,7 @@
mail_user_unref(&client->user);
if (client->free_parser != NULL)
- imap_parser_destroy(&client->free_parser);
+ imap_parser_unref(&client->free_parser);
if (client->io != NULL)
io_remove(&client->io);
if (client->to_idle_output != NULL)
@@ -548,7 +548,7 @@
client->mailbox_change_lock = NULL;
if (client->free_parser != NULL)
- imap_parser_destroy(&cmd->parser);
+ imap_parser_unref(&cmd->parser);
else {
imap_parser_reset(cmd->parser);
client->free_parser = cmd->parser;
diff -r 2dbc6108f090 -r f63f2b2217c3 src/lib-imap-client/imapc-connection.c
--- a/src/lib-imap-client/imapc-connection.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/lib-imap-client/imapc-connection.c Sun Oct 09 20:36:28 2011 +0300
@@ -318,7 +318,7 @@
timeout_remove(&conn->to);
if (conn->to_output != NULL)
timeout_remove(&conn->to_output);
- imap_parser_destroy(&conn->parser);
+ imap_parser_unref(&conn->parser);
io_remove(&conn->io);
if (conn->ssl_iostream != NULL)
ssl_iostream_unref(&conn->ssl_iostream);
diff -r 2dbc6108f090 -r f63f2b2217c3 src/lib-imap/imap-bodystructure.c
--- a/src/lib-imap/imap-bodystructure.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/lib-imap/imap-bodystructure.c Sun Oct 09 20:36:28 2011 +0300
@@ -715,7 +715,7 @@
if (!ret)
i_error("Error parsing IMAP bodystructure: %s", bodystructure);
- imap_parser_destroy(&parser);
+ imap_parser_unref(&parser);
i_stream_destroy(&input);
return ret;
}
diff -r 2dbc6108f090 -r f63f2b2217c3 src/lib-imap/imap-envelope.c
--- a/src/lib-imap/imap-envelope.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/lib-imap/imap-envelope.c Sun Oct 09 20:36:28 2011 +0300
@@ -392,7 +392,7 @@
ret = FALSE;
}
- imap_parser_destroy(&parser);
+ imap_parser_unref(&parser);
i_stream_destroy(&input);
return ret;
}
diff -r 2dbc6108f090 -r f63f2b2217c3 src/lib-imap/imap-id.c
--- a/src/lib-imap/imap-id.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/lib-imap/imap-id.c Sun Oct 09 20:36:28 2011 +0300
@@ -118,7 +118,7 @@
else
ret = imap_id_reply_generate_from_imap_args(args);
- imap_parser_destroy(&parser);
+ imap_parser_unref(&parser);
i_stream_destroy(&input);
return ret;
}
diff -r 2dbc6108f090 -r f63f2b2217c3 src/lib-imap/imap-parser.c
--- a/src/lib-imap/imap-parser.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/lib-imap/imap-parser.c Sun Oct 09 20:36:28 2011 +0300
@@ -22,6 +22,7 @@
struct imap_parser {
/* permanent */
+ int refcount;
pool_t pool;
struct istream *input;
struct ostream *output;
@@ -56,6 +57,7 @@
struct imap_parser *parser;
parser = i_new(struct imap_parser, 1);
+ parser->refcount = 1;
parser->pool = pool_alloconly_create(MEMPOOL_GROWING"IMAP parser",
1024*10);
parser->input = input;
@@ -67,8 +69,20 @@
return parser;
}
-void imap_parser_destroy(struct imap_parser **parser)
+void imap_parser_ref(struct imap_parser *parser)
{
+ i_assert(parser->refcount > 0);
+
+ parser->refcount++;
+}
+
+void imap_parser_unref(struct imap_parser **parser)
+{
+ i_assert((*parser)->refcount > 0);
+
+ if (--(*parser)->refcount > 0)
+ return;
+
pool_unref(&(*parser)->pool);
i_free(*parser);
*parser = NULL;
diff -r 2dbc6108f090 -r f63f2b2217c3 src/lib-imap/imap-parser.h
--- a/src/lib-imap/imap-parser.h Sun Oct 09 19:04:27 2011 +0300
+++ b/src/lib-imap/imap-parser.h Sun Oct 09 20:36:28 2011 +0300
@@ -35,7 +35,8 @@
struct imap_parser *
imap_parser_create(struct istream *input, struct ostream *output,
size_t max_line_size);
-void imap_parser_destroy(struct imap_parser **parser);
+void imap_parser_ref(struct imap_parser *parser);
+void imap_parser_unref(struct imap_parser **parser);
/* Reset the parser to initial state. */
void imap_parser_reset(struct imap_parser *parser);
diff -r 2dbc6108f090 -r f63f2b2217c3 src/lib-imap/test-imap-parser.c
--- a/src/lib-imap/test-imap-parser.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/lib-imap/test-imap-parser.c Sun Oct 09 20:36:28 2011 +0300
@@ -44,7 +44,7 @@
test_assert(imap_parser_read_args(parser, 0, 0, &args) == -1);
test_assert(strcmp(imap_parser_get_error(parser, &fatal), "CR sent without LF") == 0 && !fatal);
- imap_parser_destroy(&parser);
+ imap_parser_unref(&parser);
i_stream_destroy(&input);
test_end();
}
diff -r 2dbc6108f090 -r f63f2b2217c3 src/plugins/virtual/virtual-config.c
--- a/src/plugins/virtual/virtual-config.c Sun Oct 09 19:04:27 2011 +0300
+++ b/src/plugins/virtual/virtual-config.c Sun Oct 09 20:36:28 2011 +0300
@@ -63,7 +63,7 @@
mail_search_parser_deinit(&parser);
}
- imap_parser_destroy(&imap_parser);
+ imap_parser_unref(&imap_parser);
i_stream_destroy(&input);
return sargs;
}
More information about the dovecot-cvs
mailing list