Skip to content

Commit

Permalink
* milter/manager/milter-manager-children.c,
Browse files Browse the repository at this point in the history
  test/manager/test-children.c, test/fixtures/leader/: don't delay
  data event.
  Reported by Kenji Shiono. Thanks!!!
  • Loading branch information
ktou committed Jan 9, 2011
1 parent e1bd924 commit a939f22
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 49 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
2011-01-09 Kouhei Sutou <kou@cozmixng.org>

* milter/manager/milter-manager-children.c,
test/manager/test-children.c, test/fixtures/leader/: don't delay
data event.
Reported by Kenji Shiono. Thanks!!!

* test/tool/test-server.c, test/manager/test-children.c,
test/manager/test-leader.c, test/manager/test-manager.c: use source
directory instead of base directory for fxiture.
Expand Down
93 changes: 53 additions & 40 deletions milter/manager/milter-manager-children.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,10 @@ milter_manager_children_is_waiting_reply (MilterManagerChildren *children)
case MILTER_SERVER_CONTEXT_STATE_HELO:
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_FROM:
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_RECIPIENT:
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_UNKNOWN:
return !g_queue_is_empty(priv->reply_queue);
break;
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_HEADER:
case MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER:
case MILTER_SERVER_CONTEXT_STATE_BODY:
Expand Down Expand Up @@ -975,16 +975,6 @@ send_command_to_child (MilterManagerChildren *children,

priv = MILTER_MANAGER_CHILDREN_GET_PRIVATE(children);
switch (command) {
case MILTER_COMMAND_DATA:
priv->processing_state = MILTER_SERVER_CONTEXT_STATE_DATA;
if (milter_server_context_data(context)) {
status = MILTER_STATUS_PROGRESS;
if (!milter_server_context_need_reply(context,
priv->processing_state)) {
g_signal_emit_by_name(context, "continue");
}
}
break;
case MILTER_COMMAND_HEADER:
status = send_next_header_to_child(children, context);
break;
Expand Down Expand Up @@ -1187,7 +1177,6 @@ cb_continue (MilterServerContext *context, gpointer user_data)
compile_reply_status(children, state, MILTER_STATUS_CONTINUE);

switch (state) {
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER:
status = send_next_command(children, context, state);
break;
Expand Down Expand Up @@ -1262,13 +1251,13 @@ cb_temporary_failure (MilterServerContext *context, gpointer user_data)
milter_server_context_quit(context);
break;
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_FROM:
case MILTER_SERVER_CONTEXT_STATE_DATA:
milter_server_context_set_processing_message(context, FALSE);
remove_child_from_queue(children, context);
break;
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_RECIPIENT:
remove_child_from_queue(children, context);
break;
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_HEADER:
case MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER:
case MILTER_SERVER_CONTEXT_STATE_BODY:
Expand Down Expand Up @@ -1332,13 +1321,13 @@ cb_reject (MilterServerContext *context, gpointer user_data)
milter_server_context_quit(context);
break;
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_FROM:
case MILTER_SERVER_CONTEXT_STATE_DATA:
milter_server_context_set_processing_message(context, FALSE);
remove_child_from_queue(children, context);
break;
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_RECIPIENT:
remove_child_from_queue(children, context);
break;
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_HEADER:
case MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER:
case MILTER_SERVER_CONTEXT_STATE_BODY:
Expand Down Expand Up @@ -1406,6 +1395,7 @@ cb_accept (MilterServerContext *context, gpointer user_data)
milter_server_context_quit(context);
break;
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_FROM:
case MILTER_SERVER_CONTEXT_STATE_DATA:
milter_server_context_set_processing_message(context, FALSE);
remove_child_from_queue(children, context);
break;
Expand All @@ -1414,7 +1404,6 @@ cb_accept (MilterServerContext *context, gpointer user_data)
milter_server_context_set_processing_message(context, FALSE);
remove_child_from_queue(children, context);
break;
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_HEADER:
case MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER:
case MILTER_SERVER_CONTEXT_STATE_BODY:
Expand Down Expand Up @@ -1472,13 +1461,13 @@ cb_discard (MilterServerContext *context, gpointer user_data)

switch (state) {
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_FROM:
case MILTER_SERVER_CONTEXT_STATE_DATA:
milter_server_context_set_processing_message(context, FALSE);
remove_child_from_queue(children, context);
break;
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_RECIPIENT:
remove_child_from_queue(children, context);
break;
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_HEADER:
case MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER:
case MILTER_SERVER_CONTEXT_STATE_BODY:
Expand Down Expand Up @@ -1948,14 +1937,14 @@ cb_stopped (MilterServerContext *context, gpointer user_data)
milter_server_context_quit(context);
break;
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_FROM:
case MILTER_SERVER_CONTEXT_STATE_DATA:
compile_reply_status(children, state, MILTER_STATUS_ACCEPT);
cb_continue(context, user_data);
break;
case MILTER_SERVER_CONTEXT_STATE_ENVELOPE_RECIPIENT:
milter_server_context_set_status(context, MILTER_STATUS_NOT_CHANGE);
cb_continue(context, user_data);
break;
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_HEADER:
case MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER:
case MILTER_SERVER_CONTEXT_STATE_BODY:
Expand Down Expand Up @@ -2193,7 +2182,6 @@ cb_finished (MilterAgent *agent, gpointer user_data)
case MILTER_SERVER_CONTEXT_STATE_NEGOTIATE:
remove_queue_in_negotiate(children, MILTER_MANAGER_CHILD(context));
break;
case MILTER_SERVER_CONTEXT_STATE_DATA:
case MILTER_SERVER_CONTEXT_STATE_HEADER:
case MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER:
case MILTER_SERVER_CONTEXT_STATE_BODY:
Expand Down Expand Up @@ -2724,10 +2712,7 @@ init_command_waiting_child_queue (MilterManagerChildren *children, MilterCommand

context = MILTER_SERVER_CONTEXT(node->data);
if (milter_server_context_is_processing_message(context)) {
MilterMessageResult *result;

result = milter_server_context_get_message_result(context);
if (result && milter_message_result_get_recipients(result)) {
if (milter_server_context_has_accepted_recipient(context)) {
priv->command_waiting_child_queue =
g_list_append(priv->command_waiting_child_queue, context);
} else {
Expand Down Expand Up @@ -3153,35 +3138,63 @@ milter_manager_children_envelope_recipient (MilterManagerChildren *children,
return success;
}

static MilterStatus
send_command_to_first_waiting_child (MilterManagerChildren *children,
MilterCommand command)
{
MilterServerContext *first_child;

first_child = get_first_child_in_command_waiting_child_queue(children);
if (!first_child)
return MILTER_STATUS_NOT_CHANGE;

return send_command_to_child(children, first_child, command);
}

gboolean
milter_manager_children_data (MilterManagerChildren *children)
{
GList *child, *targets;
MilterManagerChildrenPrivate *priv;
gboolean success = FALSE;
gint n_queued_milters;
MilterServerContextState state = MILTER_SERVER_CONTEXT_STATE_DATA;

if (!milter_manager_children_check_processing_message(children))
return FALSE;

priv = MILTER_MANAGER_CHILDREN_GET_PRIVATE(children);

priv->state = MILTER_SERVER_CONTEXT_STATE_DATA;
priv->processing_state = priv->state;
init_command_waiting_child_queue(children, MILTER_COMMAND_DATA);
init_reply_queue(children, state);
for (child = priv->milters; child; child = g_list_next(child)) {
MilterServerContext *context = MILTER_SERVER_CONTEXT(child->data);

return MILTER_STATUS_PROGRESS ==
send_command_to_first_waiting_child(children, MILTER_COMMAND_DATA);
if (milter_server_context_is_processing_message(context)) {
if (milter_server_context_has_accepted_recipient(context)) {
g_queue_push_tail(priv->reply_queue, context);
} else {
milter_server_context_abort(context);
}
}
}

n_queued_milters = priv->reply_queue->length;
targets = g_list_copy(priv->reply_queue->head);
for (child = targets; child; child = g_list_next(child)) {
MilterServerContext *context = MILTER_SERVER_CONTEXT(child->data);
if (milter_server_context_data(context))
success = TRUE;
}
milter_debug("[%u] [children][data][sent] %d", priv->tag, n_queued_milters);
for (child = targets; child; child = g_list_next(child)) {
MilterServerContext *context = MILTER_SERVER_CONTEXT(child->data);
if (!milter_server_context_need_reply(context, state)) {
cb_continue(context, children);
}
}
g_list_free(targets);

return success;
}

static MilterStatus
send_command_to_first_waiting_child (MilterManagerChildren *children,
MilterCommand command)
{
MilterServerContext *first_child;

first_child = get_first_child_in_command_waiting_child_queue(children);
if (!first_child)
return MILTER_STATUS_NOT_CHANGE;

return send_command_to_child(children, first_child, command);
}

gboolean
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/leader/data-again.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ port=10027
command=data

response=data
n_received=1
n_received=2
status=continue

n_alive=2
2 changes: 1 addition & 1 deletion test/fixtures/leader/data-reply-code-reject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ port=10027
command=data

response=data
n_received=1
n_received=2
status=reject
reply_codes=554 5.5.4 Spam: pgrishin

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/leader/data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ port=10027
command=data

response=data
n_received=1
n_received=2
status=continue

n_alive=2
2 changes: 1 addition & 1 deletion test/fixtures/leader/end-of-message-discard-again.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ recipients=kou+receiver2@example.com;kou+receiver2@example.com
command=data

response=data
n_received=1
n_received=2
status=continue

n_alive=2
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/leader/envelope-recipient-reject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ recipients=ok@example.com;ok@example.com
command=data

response=data
n_received=1
n_received=2
status=continue
2 changes: 1 addition & 1 deletion test/fixtures/leader/envelope-recipient-stop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ recipients=ok@example.com;ok@example.com
command=data

response=data
n_received=1
n_received=2
status=continue
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ recipients=ok@example.com;ok@example.com
command=data

response=data
n_received=1
n_received=2
status=continue
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ recipients=ok@example.com;ok@example.com
command=data

response=data
n_received=1
n_received=2
status=continue
4 changes: 3 additions & 1 deletion test/manager/test-children.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ wait_reply_helper (guint expected, guint *actual)
}
milter_event_loop_remove(loop, timeout_waiting_id);

cut_assert_true(timeout_waiting);
cut_assert_true(timeout_waiting,
cut_message("timeout: expect:<%u> actual:<%u>",
expected, *actual));
cut_assert_equal_uint(expected, *actual);
}

Expand Down

0 comments on commit a939f22

Please sign in to comment.