Mercurial > dovecot > core-2.2
changeset 13627:f63f2b2217c3
lib-imap: Added reference counting to imap parser.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 09 Oct 2011 20:36:28 +0300 |
parents | 2dbc6108f090 |
children | c9594ff166a9 |
files | src/director/director-test.c src/imap-login/client.c src/imap/cmd-append.c src/imap/imap-client.c src/lib-imap-client/imapc-connection.c src/lib-imap/imap-bodystructure.c src/lib-imap/imap-envelope.c src/lib-imap/imap-id.c src/lib-imap/imap-parser.c src/lib-imap/imap-parser.h src/lib-imap/test-imap-parser.c src/plugins/virtual/virtual-config.c |
diffstat | 12 files changed, 30 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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);
--- 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);
--- 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;
--- 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);
--- 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; }
--- 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; }
--- 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; }
--- 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;
--- 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);
--- 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(); }
--- 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; }