an effective anti-spam with milter - milter manager

MilterServerContext

MilterServerContext — Process server side milter protocol.

Functions

GQuark milter_server_context_error_quark ()
MilterServerContext * milter_server_context_new ()
void milter_server_context_set_connection_timeout ()
void milter_server_context_set_writing_timeout ()
void milter_server_context_set_reading_timeout ()
void milter_server_context_set_end_of_message_timeout ()
void milter_server_context_set_all_timeouts ()
gboolean milter_server_context_set_connection_spec ()
gboolean milter_server_context_establish_connection ()
MilterStatus milter_server_context_get_status ()
void milter_server_context_set_status ()
MilterServerContextState milter_server_context_get_state ()
void milter_server_context_set_state ()
MilterServerContextState milter_server_context_get_last_state ()
gboolean milter_server_context_is_processing ()
gboolean milter_server_context_negotiate ()
gboolean milter_server_context_connect ()
gboolean milter_server_context_helo ()
gboolean milter_server_context_envelope_from ()
gboolean milter_server_context_envelope_recipient ()
gboolean milter_server_context_data ()
gboolean milter_server_context_unknown ()
gboolean milter_server_context_header ()
gboolean milter_server_context_end_of_header ()
gboolean milter_server_context_body ()
gboolean milter_server_context_end_of_message ()
gboolean milter_server_context_quit ()
gboolean milter_server_context_abort ()
void milter_server_context_set_option ()
MilterOption * milter_server_context_get_option ()
gboolean milter_server_context_is_enable_step ()
gboolean milter_server_context_get_skip_body ()
const gchar * milter_server_context_get_name ()
void milter_server_context_set_name ()
gdouble milter_server_context_get_elapsed ()
gboolean milter_server_context_is_negotiated ()
gboolean milter_server_context_is_processing_message ()
void milter_server_context_set_processing_message ()
gboolean milter_server_context_is_quitted ()
void milter_server_context_set_quitted ()
void milter_server_context_reset_message_related_data ()
MilterMessageResult * milter_server_context_get_message_result ()
void milter_server_context_set_message_result ()
gboolean milter_server_context_need_reply ()
gboolean milter_server_context_has_accepted_recipient ()

Properties

gdouble connection-timeout Read / Write / Construct
gdouble end-of-message-timeout Read / Write / Construct
MilterMessageResult * message-result Read / Write
gchar * name Read / Write
gdouble reading-timeout Read / Write / Construct
MilterServerContextState state Read / Write
MilterStatus status Read / Write
gdouble writing-timeout Read / Write / Construct

Object Hierarchy

    GEnum
    ├── MilterServerContextError
    ╰── MilterServerContextState
    GObject
    ╰── MilterAgent
        ╰── MilterProtocolAgent
            ╰── MilterServerContext
                ╰── MilterManagerChild

Description

The MilterServerContext processes one server side milter protocol session. It means MilterServerContext instance is created for each milter protocol session.

Functions

milter_server_context_error_quark ()

GQuark
milter_server_context_error_quark (void);

milter_server_context_new ()

MilterServerContext *
milter_server_context_new (void);

Creates a new context object.

Returns

a new MilterServerContext object.


milter_server_context_set_connection_timeout ()

void
milter_server_context_set_connection_timeout
                               (MilterServerContext *context,
                                gdouble timeout);

Sets the timeout in seconds on connection. If context doesn't connects to client in timeout seconds, “timeout” signal is emitted.

Parameters

context

a MilterServerContext.

 

timeout

the connection timeout in seconds. (default is MILTER_SERVER_CONTEXT_DEFAULT_CONNECTION_TIMEOUT)

 

milter_server_context_set_writing_timeout ()

void
milter_server_context_set_writing_timeout
                               (MilterServerContext *context,
                                gdouble timeout);

Sets the timeout in seconds on writing. If context doesn't write to client socket in timeout seconds, “timeout” signal is emitted.

Parameters

context

a MilterServerContext.

 

timeout

the writing timeout in seconds. (default is MILTER_SERVER_CONTEXT_DEFAULT_WRITING_TIMEOUT)

 

milter_server_context_set_reading_timeout ()

void
milter_server_context_set_reading_timeout
                               (MilterServerContext *context,
                                gdouble timeout);

Sets the timeout in seconds on reading. If context doesn't receive response from client socket in timeout seconds, “timeout” signal is emitted.

Parameters

context

a MilterServerContext.

 

timeout

the reading timeout in seconds. (default is MILTER_SERVER_CONTEXT_DEFAULT_READING_TIMEOUT)

 

milter_server_context_set_end_of_message_timeout ()

void
milter_server_context_set_end_of_message_timeout
                               (MilterServerContext *context,
                                gdouble timeout);

Sets the timeout in seconds on end-of-message. If context doesn't receive response for end-of-message from client socket in timeout seconds, “timeout” signal is emitted.

Parameters

context

a MilterServerContext.

 

timeout

the timeout in seconds on end-of-message. (default is MILTER_SERVER_CONTEXT_DEFAULT_END_OF_MESSAGE_TIMEOUT)

 

milter_server_context_set_all_timeouts ()

void
milter_server_context_set_all_timeouts
                               (MilterServerContext *context,
                                gdouble timeout);

Sets the timeout in seconds on connection, writing, reading and end-of-message at once.

See the comments of the fllowing functions about each timeout:

  1. milter_server_context_set_connection_timeout()

  2. milter_server_context_set_writing_timeout()

  3. milter_server_context_set_reading_timeout()

  4. milter_server_context_set_end_of_message_timeout()

Parameters

context

a MilterServerContext.

 

timeout

the timeout in seconds.

 

Since: 2.1.0


milter_server_context_set_connection_spec ()

gboolean
milter_server_context_set_connection_spec
                               (MilterServerContext *context,
                                const gchar *spec,
                                GError **error);

Sets a connection specification of client. If spec is invalid format and error is not NULL, error detail is stored into error .

Parameters

context

a MilterServerContext.

 

spec

the connection spec of client.

 

error

return location for an error, or NULL.

 

Returns

TRUE on success.


milter_server_context_establish_connection ()

gboolean
milter_server_context_establish_connection
                               (MilterServerContext *context,
                                GError **error);

Establishes a connection to client. If establishing is failed and error is not NULL, error detail is stored into error .

Parameters

context

a MilterServerContext.

 

error

return location for an error, or NULL.

 

Returns

TRUE on success.


milter_server_context_get_status ()

MilterStatus
milter_server_context_get_status (MilterServerContext *context);

Gets the current status.

Parameters

context

a MilterServerContext.

 

Returns

the current status.


milter_server_context_set_status ()

void
milter_server_context_set_status (MilterServerContext *context,
                                  MilterStatus status);

Sets the current status.

Parameters

context

a MilterServerContext.

 

status

the new status.

 

milter_server_context_get_state ()

MilterServerContextState
milter_server_context_get_state (MilterServerContext *context);

Gets the current state.

Parameters

context

a MilterServerContext.

 

Returns

the current state.


milter_server_context_set_state ()

void
milter_server_context_set_state (MilterServerContext *context,
                                 MilterServerContextState state);

Sets the current state.

Parameters

context

a MilterServerContext.

 

state

the new state.

 

milter_server_context_get_last_state ()

MilterServerContextState
milter_server_context_get_last_state (MilterServerContext *context);

Gets the last state. It's one of start, negotiate, connect, helo, envelope-from, envelope-recipient, data, unknown, header, end-of-header, body and end-of-message.

Parameters

context

a MilterServerContext.

 

Returns

the last state.


milter_server_context_is_processing ()

gboolean
milter_server_context_is_processing (MilterServerContext *context);

Gets whether waiting response.

Parameters

context

a MilterServerContext.

 

Returns

TRUE if any response is received after the last writing, FALSE otherwise.


milter_server_context_negotiate ()

gboolean
milter_server_context_negotiate (MilterServerContext *context,
                                 MilterOption *option);

Negotiates with client.

Parameters

context

a MilterServerContext.

 

option

the negotiate option.

 

Returns

TRUE on success.


milter_server_context_connect ()

gboolean
milter_server_context_connect (MilterServerContext *context,
                               const gchar *host_name,
                               struct sockaddr *address,
                               socklen_t address_length);

Sends connected SMTP client information.

Parameters

context

a MilterServerContext.

 

host_name

the host name of connected SMTP client.

 

address

the address of connected SMTP client.

 

address_length

the length of address .

 

Returns

TRUE on success.


milter_server_context_helo ()

gboolean
milter_server_context_helo (MilterServerContext *context,
                            const gchar *fqdn);

Sends the FQDN passed on HELO.

Parameters

context

a MilterServerContext.

 

fqdn

the FQDN.

 

Returns

TRUE on success.


milter_server_context_envelope_from ()

gboolean
milter_server_context_envelope_from (MilterServerContext *context,
                                     const gchar *from);

Sends the parameter passed on MAIL FROM.

Parameters

context

a MilterServerContext.

 

from

the envelope from address.

 

Returns

TRUE on success.


milter_server_context_envelope_recipient ()

gboolean
milter_server_context_envelope_recipient
                               (MilterServerContext *context,
                                const gchar *recipient);

Sends the parameter passed on RCPT TO.

Parameters

context

a MilterServerContext.

 

recipient

the envelope recipient address.

 

Returns

TRUE on success.


milter_server_context_data ()

gboolean
milter_server_context_data (MilterServerContext *context);

Notifies DATA is received.

Parameters

context

a MilterServerContext.

 

Returns

TRUE on success.


milter_server_context_unknown ()

gboolean
milter_server_context_unknown (MilterServerContext *context,
                               const gchar *command);

Sends received unknown SMTP command.

Parameters

context

a MilterServerContext.

 

command

the unknown SMTP command.

 

Returns

TRUE on success.


milter_server_context_header ()

gboolean
milter_server_context_header (MilterServerContext *context,
                              const gchar *name,
                              const gchar *value);

Sends a header.

Parameters

context

a MilterServerContext.

 

name

the header name.

 

value

the header value.

 

Returns

TRUE on success.


milter_server_context_end_of_header ()

gboolean
milter_server_context_end_of_header (MilterServerContext *context);

Notifies all headers are sent.

Parameters

context

a MilterServerContext.

 

Returns

TRUE on success.


milter_server_context_body ()

gboolean
milter_server_context_body (MilterServerContext *context,
                            const gchar *chunk,
                            gsize size);

Sends a body chunk.

Parameters

context

a MilterServerContext.

 

chunk

the body chunk.

 

size

the size of chunk .

 

Returns

TRUE on success.


milter_server_context_end_of_message ()

gboolean
milter_server_context_end_of_message (MilterServerContext *context,
                                      const gchar *chunk,
                                      gsize size);

Notifies all body chunks are sent with optional the last body chunk.

Parameters

context

a MilterServerContext.

 

chunk

the body chunk. maybe NULL.

 

size

the size of chunk .

 

Returns

TRUE on success.


milter_server_context_quit ()

gboolean
milter_server_context_quit (MilterServerContext *context);

Quits the current connection.

Parameters

context

a MilterServerContext.

 

Returns

TRUE on success.


milter_server_context_abort ()

gboolean
milter_server_context_abort (MilterServerContext *context);

Aborts the current connection.

Parameters

context

a MilterServerContext.

 

Returns

TRUE on success.


milter_server_context_set_option ()

void
milter_server_context_set_option (MilterServerContext *context,
                                  MilterOption *option);

Set negotiate option.

Parameters

context

a MilterServerContext.

 

option

the negotiate option.

 

milter_server_context_get_option ()

MilterOption *
milter_server_context_get_option (MilterServerContext *context);

Get negotiate option.

Parameters

context

a MilterServerContext.

 

milter_server_context_is_enable_step ()

gboolean
milter_server_context_is_enable_step (MilterServerContext *context,
                                      MilterStepFlags step);

Gets whether step flag is enabled in the context 's option.

Parameters

context

a MilterServerContext.

 

step

the step flag.

 

Returns

TRUE if step flags is enabled, FALSE otherwise.


milter_server_context_get_skip_body ()

gboolean
milter_server_context_get_skip_body (MilterServerContext *context);

Gets whether context received skip response on sending body chunks.

Parameters

context

a MilterServerContext.

 

Returns

TRUE if body chunks are skipped, FALSE otherwise.


milter_server_context_get_name ()

const gchar *
milter_server_context_get_name (MilterServerContext *context);

Gets the name of context .

Parameters

context

a MilterServerContext.

 

Returns

the name of context .


milter_server_context_set_name ()

void
milter_server_context_set_name (MilterServerContext *context,
                                const gchar *name);

Sets the name of context .

Parameters

context

a MilterServerContext.

 

name

the name.

 

milter_server_context_get_elapsed ()

gdouble
milter_server_context_get_elapsed (MilterServerContext *context);

Gets the elapsed time.

Parameters

context

a MilterServerContext.

 

Returns

the elapsed time of context .


milter_server_context_is_negotiated ()

gboolean
milter_server_context_is_negotiated (MilterServerContext *context);

Gets whether negotiation is succeeded.

Parameters

context

a MilterServerContext.

 

Returns

TRUE if context is negotiated, FALSE otherwise.


milter_server_context_is_processing_message ()

gboolean
milter_server_context_is_processing_message
                               (MilterServerContext *context);

Gets whether the context is processing message.

Parameters

context

a MilterServerContext.

 

Returns

TRUE if context is processing message, FALSE otherwise.


milter_server_context_set_processing_message ()

void
milter_server_context_set_processing_message
                               (MilterServerContext *context,
                                gboolean processing_message);

Sets whether the context is processing message.

Parameters

context

a MilterServerContext.

 

processing

whether the context is processing message.

 

milter_server_context_is_quitted ()

gboolean
milter_server_context_is_quitted (MilterServerContext *context);

Gets whether the context is quitted.

Parameters

context

a MilterServerContext.

 

Returns

TRUE if context is quitted, FALSE otherwise.


milter_server_context_set_quitted ()

void
milter_server_context_set_quitted (MilterServerContext *context,
                                   gboolean quitted);

Sets whether the context is quitted.

Parameters

context

a MilterServerContext.

 

quitted

whether the context is quitted.

 

milter_server_context_reset_message_related_data ()

void
milter_server_context_reset_message_related_data
                               (MilterServerContext *context);

Resets message related data in the context. It should be called before each 2nd or later messages in the same milter session. There are no bad effects if it is called before 1st message.

Parameters

context

a MilterServerContext.

 

milter_server_context_get_message_result ()

MilterMessageResult *
milter_server_context_get_message_result
                               (MilterServerContext *context);

Gets the message result of context .

Parameters

context

a MilterServerContext.

 

Returns

the message result of context .


milter_server_context_set_message_result ()

void
milter_server_context_set_message_result
                               (MilterServerContext *context,
                                MilterMessageResult *result);

Sets the message result of context .

Parameters

context

a MilterServerContext.

 

result

the message result.

 

milter_server_context_need_reply ()

gboolean
milter_server_context_need_reply (MilterServerContext *context,
                                  MilterServerContextState state);

Gets whether the context needs to reply on state .

Parameters

context

a MilterServerContext.

 

state

a MilterServerContextState.

 

Returns

TRUE if context needs to reply on state , FALSE otherwise.


milter_server_context_has_accepted_recipient ()

gboolean
milter_server_context_has_accepted_recipient
                               (MilterServerContext *context);

Returns TRUE if the context has one or more accepted recipients. If the context doesn't know about recipients, it always returns FALSE.

Parameters

context

a MilterServerContext.

 

Returns

TRUE if context has one or more accepted recipients, FALSE otherwise.

Types and Values

MILTER_SERVER_CONTEXT_ERROR

#define MILTER_SERVER_CONTEXT_ERROR           (milter_server_context_error_quark())

Used to get the GError quark for MilterServerContext errors.


MILTER_SERVER_CONTEXT_DEFAULT_CONNECTION_TIMEOUT

#define MILTER_SERVER_CONTEXT_DEFAULT_CONNECTION_TIMEOUT     300

The default connection timeout in seconds.


MILTER_SERVER_CONTEXT_DEFAULT_WRITING_TIMEOUT

#define MILTER_SERVER_CONTEXT_DEFAULT_WRITING_TIMEOUT         10

The default writing timeout in seconds.


MILTER_SERVER_CONTEXT_DEFAULT_READING_TIMEOUT

#define MILTER_SERVER_CONTEXT_DEFAULT_READING_TIMEOUT         10

The default reading timeout in seconds.


MILTER_SERVER_CONTEXT_DEFAULT_END_OF_MESSAGE_TIMEOUT

#define MILTER_SERVER_CONTEXT_DEFAULT_END_OF_MESSAGE_TIMEOUT 300

The default end-of-message response timeout in seconds.


enum MilterServerContextError

These identify the variable errors that can occur while calling MilterServerContext functions.

Members

MILTER_SERVER_CONTEXT_ERROR_CONNECTION_FAILURE

Indicates a connection failure.

 

MILTER_SERVER_CONTEXT_ERROR_NO_SPEC

Indicates the connection spec isn't set.

 

MILTER_SERVER_CONTEXT_ERROR_INVALID_STATE

Indicates unexpected response is received on the current MilterServerContextState.

 

MILTER_SERVER_CONTEXT_ERROR_BUSY

Indicates a new operation is requested before the previous operation's response is received.

 

MILTER_SERVER_CONTEXT_ERROR_IO_ERROR

Indicates an IO error causing on writing/reading milter protocol data.

 

MILTER_SERVER_CONTEXT_ERROR_NEWER_VERSION_REQUESTED

Indicates unsupported newer version is requested.

 

enum MilterServerContextState

These identify the state of MilterServerContext.

Members

MILTER_SERVER_CONTEXT_STATE_INVALID

Invalid state.

 

MILTER_SERVER_CONTEXT_STATE_START

Just started.

 

MILTER_SERVER_CONTEXT_STATE_DEFINE_MACRO

Sent macro definition.

 

MILTER_SERVER_CONTEXT_STATE_NEGOTIATE

Negotiating.

 

MILTER_SERVER_CONTEXT_STATE_CONNECT

Sent connection information.

 

MILTER_SERVER_CONTEXT_STATE_HELO

Sent HELO information.

 

MILTER_SERVER_CONTEXT_STATE_ENVELOPE_FROM

Sent MAIL FROM command information.

 

MILTER_SERVER_CONTEXT_STATE_ENVELOPE_RECIPIENT

Sent RCPT TO command information.

 

MILTER_SERVER_CONTEXT_STATE_DATA

Sent DATA command information.

 

MILTER_SERVER_CONTEXT_STATE_UNKNOWN

Sent unknown SMTP command.

 

MILTER_SERVER_CONTEXT_STATE_HEADER

Sent a header.

 

MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER

Sent all headers.

 

MILTER_SERVER_CONTEXT_STATE_BODY

Sent a body chunk.

 

MILTER_SERVER_CONTEXT_STATE_END_OF_MESSAGE

Sent all body chunks.

 

MILTER_SERVER_CONTEXT_STATE_QUIT

Sent quit request.

 

MILTER_SERVER_CONTEXT_STATE_ABORT

Sent abort request.

 

Property Details

The “connection-timeout” property

  “connection-timeout”       gdouble

The timeout seconds for connecting to a filter.

Flags: Read / Write / Construct

Allowed values: >= 0

Default value: 300


The “end-of-message-timeout” property

  “end-of-message-timeout”   gdouble

The timeout seconds between sending end-of-message to a filter and waiting for its reply.

Flags: Read / Write / Construct

Allowed values: >= 0

Default value: 300


The “message-result” property

  “message-result”           MilterMessageResult *

Result of the current processing message.

Flags: Read / Write


The “name” property

  “name”                     gchar *

The name of the MilterServerContext.

Flags: Read / Write

Default value: NULL


The “reading-timeout” property

  “reading-timeout”          gdouble

The timeout seconds for reading reply from a filter.

Flags: Read / Write / Construct

Allowed values: >= 0

Default value: 10


The “state” property

  “state”                    MilterServerContextState

The state of the MilterServerContext.

Flags: Read / Write

Default value: MILTER_SERVER_CONTEXT_STATE_START


The “status” property

  “status”                   MilterStatus

The status of the MilterServerContext.

Flags: Read / Write

Default value: MILTER_STATUS_NOT_CHANGE


The “writing-timeout” property

  “writing-timeout”          gdouble

The timeout seconds for writing information from MTA to a filter.

Flags: Read / Write / Construct

Allowed values: >= 0

Default value: 10

Signal Details

The “connection-timeout” signal

void
user_function (MilterServerContext *milterservercontext,
               gpointer             user_data)

Flags: Run Last


The “end-of-message-timeout” signal

void
user_function (MilterServerContext *milterservercontext,
               gpointer             user_data)

Flags: Run Last


The “message-processed” signal

void
user_function (MilterServerContext *milterservercontext,
               MilterMessageResult *arg1,
               gpointer             user_data)

Flags: Run Last


The “reading-timeout” signal

void
user_function (MilterServerContext *milterservercontext,
               gpointer             user_data)

Flags: Run Last


The “ready” signal

void
user_function (MilterServerContext *milterservercontext,
               gpointer             user_data)

Flags: Run Last


The “state-transited” signal

void
user_function (MilterServerContext     *milterservercontext,
               MilterServerContextState arg1,
               gpointer                 user_data)

Flags: Run Last


The “stop-on-body” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gchar               *arg1,
               guint64              arg2,
               gpointer             user_data)

Flags: Run Last


The “stop-on-connect” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gchar               *arg1,
               gpointer             arg2,
               guint                arg3,
               gpointer             user_data)

Flags: Run Last


The “stop-on-data” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gpointer             user_data)

Flags: Run Last


The “stop-on-end-of-header” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gpointer             user_data)

Flags: Run Last


The “stop-on-end-of-message” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gchar               *arg1,
               guint64              arg2,
               gpointer             user_data)

Flags: Run Last


The “stop-on-envelope-from” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gchar               *arg1,
               gpointer             user_data)

Flags: Run Last


The “stop-on-envelope-recipient” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gchar               *arg1,
               gpointer             user_data)

Flags: Run Last


The “stop-on-header” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gchar               *arg1,
               gchar               *arg2,
               gpointer             user_data)

Flags: Run Last


The “stop-on-helo” signal

gboolean
user_function (MilterServerContext *milterservercontext,
               gchar               *arg1,
               gpointer             user_data)

Flags: Run Last


The “stopped” signal

void
user_function (MilterServerContext *milterservercontext,
               gpointer             user_data)

Flags: Run Last


The “writing-timeout” signal

void
user_function (MilterServerContext *milterservercontext,
               gpointer             user_data)

Flags: Run Last