]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: Added reference counting to imap parser.
authorTimo Sirainen <tss@iki.fi>
Sun, 9 Oct 2011 17:36:28 +0000 (20:36 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 9 Oct 2011 17:36:28 +0000 (20:36 +0300)
12 files changed:
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

index d18ec4d55a1510a5bb0727033ca69d571b74db54..a9fa9c902a8614bf5d1f162e2be00279bcfe2f08 100644 (file)
@@ -275,7 +275,7 @@ static void imap_client_destroy(struct imap_client **_client)
        }
 
        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);
index 608a13ef533c7f45fd143a858c58ab0cfe5e5308..4fdd56c89257f80aa6220ab7fd21505aa19da9c4 100644 (file)
@@ -365,7 +365,7 @@ static void imap_client_destroy(struct client *client)
        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 @@ static void imap_client_starttls(struct client *client)
 {
        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);
index d4f61693ac92f038d2a01a46ada281c8e2f8379e..2a9efdd1fa752f9efd1171691f94e6466c33fa68 100644 (file)
@@ -145,7 +145,7 @@ static int validate_args(const struct imap_arg *args,
 
 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);
 
index 4e1402494acfd6122ce96290102ac55c26749b7a..98ce4ee8948853da6958914d33e3287913930539 100644 (file)
@@ -44,7 +44,7 @@ struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
        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 @@ void client_destroy(struct client *client, const char *reason)
        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 @@ void client_command_free(struct client_command_context **_cmd)
                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;
index 5d1b35c4a3a0b62de8ae6c653317ac25fb259aa5..9f28c89cf618e07de1a1db96fe675459e4a182e4 100644 (file)
@@ -318,7 +318,7 @@ void imapc_connection_disconnect(struct imapc_connection *conn)
                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);
index b604a2eeadc99eefb5fb77a6c961b7547ee8eb3e..b98c02c8d9faa8d2df2ecd42e6f77ccc974670b2 100644 (file)
@@ -715,7 +715,7 @@ bool imap_body_parse_from_bodystructure(const char *bodystructure,
        if (!ret)
                i_error("Error parsing IMAP bodystructure: %s", bodystructure);
 
-       imap_parser_destroy(&parser);
+       imap_parser_unref(&parser);
        i_stream_destroy(&input);
        return ret;
 }
index f50cf1f7120176dec1764ba92e26a07b2dcb38e8..837694c39069843f15040472aed21d14fe565d11 100644 (file)
@@ -392,7 +392,7 @@ bool imap_envelope_parse(const char *envelope, enum imap_envelope_field field,
                ret = FALSE;
        }
 
-       imap_parser_destroy(&parser);
+       imap_parser_unref(&parser);
        i_stream_destroy(&input);
        return ret;
 }
index 90c36efdfb628338a7f9f8659853d4a3d6fdb5bd..0e646da244881dd1ed70428b7bccd8f72d681cba 100644 (file)
@@ -118,7 +118,7 @@ const char *imap_id_reply_generate(const char *settings)
        else
                ret = imap_id_reply_generate_from_imap_args(args);
 
-       imap_parser_destroy(&parser);
+       imap_parser_unref(&parser);
        i_stream_destroy(&input);
        return ret;
 }
index 6379a7745b4b921faafa6ab13b5e273ff746307e..e75508fb4a55da1b3ee188c3c2fbbb648a05c01f 100644 (file)
@@ -22,6 +22,7 @@ enum arg_parse_type {
 
 struct imap_parser {
        /* permanent */
+       int refcount;
        pool_t pool;
        struct istream *input;
        struct ostream *output;
@@ -56,6 +57,7 @@ imap_parser_create(struct istream *input, struct ostream *output,
        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 @@ imap_parser_create(struct istream *input, struct ostream *output,
        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;
index 76f1dd58ee8317b1ee7bfc43d43410bda0a31a0f..52f4095f8930b3e4ebe5853f2ddfff623b0aa60b 100644 (file)
@@ -35,7 +35,8 @@ struct imap_parser;
 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);
index e7b1217183e0742311f7f43f415bf12efcc23970..4ff77bf710e17767e597c8d9f1756bab0e3b33c0 100644 (file)
@@ -44,7 +44,7 @@ static void test_imap_parser_crlf(void)
        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();
 }
index a4d1cfdff5574feafdbd996e417b38341bf3cbf1..a660b46c6b4edfa57972e5c93eed79193a95cbdb 100644 (file)
@@ -63,7 +63,7 @@ virtual_search_args_parse(const string_t *rule, const char **error_r)
                mail_search_parser_deinit(&parser);
        }
 
-       imap_parser_destroy(&imap_parser);
+       imap_parser_unref(&imap_parser);
        i_stream_destroy(&input);
        return sargs;
 }