MilterServerContext

MilterServerContext — Process server side milter protocol.

Synopsis

#define             MILTER_SERVER_CONTEXT_ERROR
#define             MILTER_SERVER_CONTEXT_DEFAULT_CONNECTION_TIMEOUT
#define             MILTER_SERVER_CONTEXT_DEFAULT_WRITING_TIMEOUT
#define             MILTER_SERVER_CONTEXT_DEFAULT_READING_TIMEOUT
#define             MILTER_SERVER_CONTEXT_DEFAULT_END_OF_MESSAGE_TIMEOUT
enum                MilterServerContextError;
enum                MilterServerContextState;
                    MilterServerContext;
GQuark              milter_server_context_error_quark   (void);
MilterServerContext* milter_server_context_new          (void);
void                milter_server_context_set_connection_timeout
                                                        (MilterServerContext *context,
                                                         gdouble timeout);
void                milter_server_context_set_writing_timeout
                                                        (MilterServerContext *context,
                                                         gdouble timeout);
void                milter_server_context_set_reading_timeout
                                                        (MilterServerContext *context,
                                                         gdouble timeout);
void                milter_server_context_set_end_of_message_timeout
                                                        (MilterServerContext *context,
                                                         gdouble timeout);
gboolean            milter_server_context_set_connection_spec
                                                        (MilterServerContext *context,
                                                         const gchar *spec,
                                                         GError **error);
gboolean            milter_server_context_establish_connection
                                                        (MilterServerContext *context,
                                                         GError **error);
MilterStatus        milter_server_context_get_status    (MilterServerContext *context);
MilterServerContextState milter_server_context_get_state
                                                        (MilterServerContext *context);
void                milter_server_context_set_state     (MilterServerContext *context,
                                                         MilterServerContextState state);
gboolean            milter_server_context_is_processing (MilterServerContext *context);
gboolean            milter_server_context_negotiate     (MilterServerContext *context,
                                                         MilterOption *option);
gboolean            milter_server_context_connect       (MilterServerContext *context,
                                                         const gchar *host_name,
                                                         struct sockaddr *address,
                                                         socklen_t address_length);
gboolean            milter_server_context_helo          (MilterServerContext *context,
                                                         const gchar *fqdn);
gboolean            milter_server_context_envelope_from (MilterServerContext *context,
                                                         const gchar *from);
gboolean            milter_server_context_envelope_recipient
                                                        (MilterServerContext *context,
                                                         const gchar *recipient);
gboolean            milter_server_context_data          (MilterServerContext *context);
gboolean            milter_server_context_unknown       (MilterServerContext *context,
                                                         const gchar *command);
gboolean            milter_server_context_header        (MilterServerContext *context,
                                                         const gchar *name,
                                                         const gchar *value);
gboolean            milter_server_context_end_of_header (MilterServerContext *context);
gboolean            milter_server_context_body          (MilterServerContext *context,
                                                         const gchar *chunk,
                                                         gsize size);
gboolean            milter_server_context_end_of_message
                                                        (MilterServerContext *context,
                                                         const gchar *chunk,
                                                         gsize size);
gboolean            milter_server_context_quit          (MilterServerContext *context);
gboolean            milter_server_context_abort         (MilterServerContext *context);
gboolean            milter_server_context_is_enable_step
                                                        (MilterServerContext *context,
                                                         MilterStepFlags step);
gboolean            milter_server_context_get_skip_body (MilterServerContext *context);
const gchar*        milter_server_context_get_name      (MilterServerContext *context);
void                milter_server_context_set_name      (MilterServerContext *context,
                                                         const gchar *name);

Description

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

Details

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 by seconds.


MILTER_SERVER_CONTEXT_DEFAULT_WRITING_TIMEOUT

#define MILTER_SERVER_CONTEXT_DEFAULT_WRITING_TIMEOUT         10

The default writing timeout by seconds.


MILTER_SERVER_CONTEXT_DEFAULT_READING_TIMEOUT

#define MILTER_SERVER_CONTEXT_DEFAULT_READING_TIMEOUT         10

The default reading timeout by 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 by seconds.


enum MilterServerContextError

typedef enum
{
    MILTER_SERVER_CONTEXT_ERROR_CONNECTION_FAILURE,
    MILTER_SERVER_CONTEXT_ERROR_NO_SPEC,
    MILTER_SERVER_CONTEXT_ERROR_INVALID_STATE,
    MILTER_SERVER_CONTEXT_ERROR_BUSY,
    MILTER_SERVER_CONTEXT_ERROR_IO_ERROR,
    MILTER_SERVER_CONTEXT_ERROR_NEWER_VERSION_REQUESTED
} MilterServerContextError;

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

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

typedef enum
{
    MILTER_SERVER_CONTEXT_STATE_START,
    MILTER_SERVER_CONTEXT_STATE_DEFINE_MACRO,
    MILTER_SERVER_CONTEXT_STATE_NEGOTIATE,
    MILTER_SERVER_CONTEXT_STATE_CONNECT,
    MILTER_SERVER_CONTEXT_STATE_HELO,
    MILTER_SERVER_CONTEXT_STATE_ENVELOPE_FROM,
    MILTER_SERVER_CONTEXT_STATE_ENVELOPE_RECIPIENT,
    MILTER_SERVER_CONTEXT_STATE_DATA,
    MILTER_SERVER_CONTEXT_STATE_UNKNOWN,
    MILTER_SERVER_CONTEXT_STATE_HEADER,
    MILTER_SERVER_CONTEXT_STATE_END_OF_HEADER,
    MILTER_SERVER_CONTEXT_STATE_BODY,
    MILTER_SERVER_CONTEXT_STATE_END_OF_MESSAGE,
    MILTER_SERVER_CONTEXT_STATE_QUIT,
    MILTER_SERVER_CONTEXT_STATE_ABORT
} MilterServerContextState;

These identify the state of MilterServerContext.

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.

MilterServerContext

typedef struct {
    MilterProtocolAgent object;
} MilterServerContext;


milter_server_context_error_quark ()

GQuark              milter_server_context_error_quark   (void);

Returns :


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 by seconds on connection. If context doesn't connects to client in timeout seconds, "timeout" signal is emitted.

context :

a MilterServerContext.

timeout :

the connection timeout by 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 by seconds on writing. If context doesn't write to client socket in timeout seconds, "timeout" signal is emitted.

context :

a MilterServerContext.

timeout :

the writing timeout by 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 by seconds on reading. If context doesn't receive response from client socket in timeout seconds, "timeout" signal is emitted.

context :

a MilterServerContext.

timeout :

the reading timeout by 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 by 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.

context :

a MilterServerContext.

timeout :

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

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.

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.

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.

context :

a MilterServerContext.

Returns :

the current status.

milter_server_context_get_state ()

MilterServerContextState milter_server_context_get_state
                                                        (MilterServerContext *context);

Gets the current state.

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.

context :

a MilterServerContext.

state :

the new state.

milter_server_context_is_processing ()

gboolean            milter_server_context_is_processing (MilterServerContext *context);

Gets whether waiting response.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

context :

a MilterServerContext.

Returns :

TRUE on success.

milter_server_context_abort ()

gboolean            milter_server_context_abort         (MilterServerContext *context);

Aborts the current connection.

context :

a MilterServerContext.

Returns :

TRUE on success.

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.

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.

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.

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.

context :

a MilterServerContext.

name :

the name.