![]() |
![]() |
![]() |
milter manager Reference Manual | ![]() |
---|---|---|---|---|
#define MILTER_CLIENT_CONTEXT_ERROR enum MilterClientContextError; enum MilterClientContextState; MilterClientContext; GQuark milter_client_context_error_quark (void); MilterClientContext* milter_client_context_new (void); gboolean milter_client_context_feed (MilterClientContext *context, const gchar *chunk, gsize size, GError **error); gpointer milter_client_context_get_private_data (MilterClientContext *context); void milter_client_context_set_private_data (MilterClientContext *context, gpointer data, GDestroyNotify destroy); gboolean milter_client_context_set_reply (MilterClientContext *context, guint code, const gchar *extended_code, const gchar *message, GError **error); gchar* milter_client_context_format_reply (MilterClientContext *context); gboolean milter_client_context_add_header (MilterClientContext *context, const gchar *name, const gchar *value, GError **error); gboolean milter_client_context_insert_header (MilterClientContext *context, guint32 index, const gchar *name, const gchar *value, GError **error); gboolean milter_client_context_change_header (MilterClientContext *context, const gchar *name, guint32 index, const gchar *value); gboolean milter_client_context_delete_header (MilterClientContext *context, const gchar *name, guint32 index); gboolean milter_client_context_change_from (MilterClientContext *context, const gchar *from, const gchar *parameters); gboolean milter_client_context_add_recipient (MilterClientContext *context, const gchar *recipient, const gchar *parameters); gboolean milter_client_context_delete_recipient (MilterClientContext *context, const gchar *recipient); gboolean milter_client_context_replace_body (MilterClientContext *context, const gchar *body, gsize body_size); gboolean milter_client_context_progress (MilterClientContext *context); gboolean milter_client_context_quarantine (MilterClientContext *context, const gchar *reason); void milter_client_context_set_timeout (MilterClientContext *context, guint timeout); guint milter_client_context_get_timeout (MilterClientContext *context); void milter_client_context_set_state (MilterClientContext *context, MilterClientContextState state); MilterClientContextState milter_client_context_get_state (MilterClientContext *context); void milter_client_context_set_option (MilterClientContext *context, MilterOption *option); MilterOption* milter_client_context_get_option (MilterClientContext *context);
The MilterClientContext
processes one milter protocol
session. It means MilterClientContext
instance is
created for each milter protocol session.
To process each milter protocol command, you need to
connect signals of
MilterClientContext
. MilterClientContext
has signals
that correspond to milter protocol events:
"finished" |
Here is an example to connect signals. It connects all signals and each connected signal handler prints its event name:
static MilterStatus cb_negotiate (MilterClientContext *context, MilterOption *option, gpointer user_data) { g_print("negotiate\n"); return MILTER_STATUS_ALL_OPTIONS; } static MilterStatus cb_connect (MilterClientContext *context, const gchar *host_name, const struct sockaddr *address, socklen_t address_length, gpointer user_data) { g_print("connect\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_helo (MilterClientContext *context, const gchar *fqdn, gpointer user_data) { g_print("helo\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_envelope_from (MilterClientContext *context, const gchar *from, gpointer user_data) { g_print("envelope-from\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_envelope_recipient (MilterClientContext *context, const gchar *to, gpointer user_data) { g_print("envelope-recipient\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_data (MilterClientContext *context, gpointer user_data) { g_print("data\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_header (MilterClientContext *context, const gchar *name, const gchar *value, gpointer user_data) { g_print("header\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_end_of_header (MilterClientContext *context, gpointer user_data) { g_print("end-of-header\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_body (MilterClientContext *context, const gchar *chunk, gsize length, gpointer user_data) { g_print("body\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_end_of_message (MilterClientContext *context, gpointer user_data) { g_print("end-of-message\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_abort (MilterClientContext *context, gpointer user_data) { g_print("abort\n"); return MILTER_STATUS_CONTINUE; } static MilterStatus cb_unknown (MilterClientContext *context, const gchar *command, gpointer user_data) { g_print("unknown\n"); return MILTER_STATUS_CONTINUE; } static void setup_context_signals (MilterClientContext *context) { #define CONNECT(name) \ g_signal_connect(context, name, G_CALLBACK(cb_ ## name), NULL) CONNECT(negotiate); CONNECT(connect); CONNECT(helo); CONNECT(envelope_from); CONNECT(envelope_recipient); CONNECT(data); CONNECT(header); CONNECT(end_of_header); CONNECT(body); CONNECT(end_of_message); CONNECT(abort); CONNECT(unknown); #undef CONNECT }
#define MILTER_CLIENT_CONTEXT_ERROR (milter_client_context_error_quark())
Used to get the GError quark for MilterClientContext errors.
typedef enum { MILTER_CLIENT_CONTEXT_ERROR_INVALID_CODE, MILTER_CLIENT_CONTEXT_ERROR_IO_ERROR, MILTER_CLIENT_CONTEXT_ERROR_NULL, MILTER_CLIENT_CONTEXT_ERROR_INVALID_STATE, MILTER_CLIENT_CONTEXT_ERROR_INVALID_ACTION } MilterClientContextError;
These identify the variable errors that can occur while
calling MilterClientContext
functions.
Indicates a
status code specified by
milter_client_context_set_reply() is invalid.
|
|
Indicates an IO error causing on writing/reading milter protocol data. | |
Indicates unexpected
NULL is passed.
|
|
Indicates
unexpected operation is requested on the current
MilterClientContextState .
|
|
Indicates
unexpected operation is requested on the context's
MilterActionFlags .
|
typedef enum { MILTER_CLIENT_CONTEXT_STATE_INVALID, MILTER_CLIENT_CONTEXT_STATE_START, MILTER_CLIENT_CONTEXT_STATE_NEGOTIATE, MILTER_CLIENT_CONTEXT_STATE_NEGOTIATE_REPLIED, MILTER_CLIENT_CONTEXT_STATE_CONNECT, MILTER_CLIENT_CONTEXT_STATE_CONNECT_REPLIED, MILTER_CLIENT_CONTEXT_STATE_HELO, MILTER_CLIENT_CONTEXT_STATE_HELO_REPLIED, MILTER_CLIENT_CONTEXT_STATE_ENVELOPE_FROM, MILTER_CLIENT_CONTEXT_STATE_ENVELOPE_FROM_REPLIED, MILTER_CLIENT_CONTEXT_STATE_ENVELOPE_RECIPIENT, MILTER_CLIENT_CONTEXT_STATE_ENVELOPE_RECIPIENT_REPLIED, MILTER_CLIENT_CONTEXT_STATE_DATA, MILTER_CLIENT_CONTEXT_STATE_DATA_REPLIED, MILTER_CLIENT_CONTEXT_STATE_UNKNOWN, MILTER_CLIENT_CONTEXT_STATE_UNKNOWN_REPLIED, MILTER_CLIENT_CONTEXT_STATE_HEADER, MILTER_CLIENT_CONTEXT_STATE_HEADER_REPLIED, MILTER_CLIENT_CONTEXT_STATE_END_OF_HEADER, MILTER_CLIENT_CONTEXT_STATE_END_OF_HEADER_REPLIED, MILTER_CLIENT_CONTEXT_STATE_BODY, MILTER_CLIENT_CONTEXT_STATE_BODY_REPLIED, MILTER_CLIENT_CONTEXT_STATE_END_OF_MESSAGE, MILTER_CLIENT_CONTEXT_STATE_END_OF_MESSAGE_REPLIED, MILTER_CLIENT_CONTEXT_STATE_QUIT, MILTER_CLIENT_CONTEXT_STATE_QUIT_REPLIED, MILTER_CLIENT_CONTEXT_STATE_ABORT, MILTER_CLIENT_CONTEXT_STATE_ABORT_REPLIED, MILTER_CLIENT_CONTEXT_STATE_FINISHED } MilterClientContextState;
These identify the state of MilterClientContext
.
Invalid state. | |
Just started. | |
Starting negotiation. | |
Received negotiation response. | |
Sent connection information. | |
Received connection information response. | |
Starting HELO. | |
Received HELO response. | |
Starting MAIL FROM command. | |
Receive MAIL FROM response. | |
Starting RCPT TO command. | |
Receive RCPT TO response. | |
Starting DATA command. | |
Receive DATA response. | |
Receiving unknown SMTP command. | |
Receive unknown SMTP command response. | |
Sent a header. | |
Receive header response. | |
All headers are sent. | |
Receive end-of-header response. | |
Sending body chunks. | |
Received body response. | |
All body chunks are sent. | |
Receive end-of-message response. | |
Starting quitting. | |
Receive quit response. | |
Starting aborting. | |
Receive abort response. | |
Finished. |
MilterClientContext* milter_client_context_new (void);
Creates a new context object. Normally, context object is
created by MilterClient
and passed by
"connection-established" signal.
Returns : |
a new MilterClientContext object.
|
gboolean milter_client_context_feed (MilterClientContext *context, const gchar *chunk, gsize size, GError **error);
Feeds a chunk to the context
. You can use it for testing
or debugging.
|
a MilterClientContext .
|
|
the string to be fed to context .
|
|
the size of chunk .
|
|
return location for an error, or NULL .
|
Returns : |
TRUE on success.
|
gpointer milter_client_context_get_private_data (MilterClientContext *context);
Gets the private data of the context
.
|
a MilterClientContext .
|
Returns : |
the private data set by
milter_client_context_set_private_data() or NULL .
|
void milter_client_context_set_private_data (MilterClientContext *context, gpointer data, GDestroyNotify destroy);
Sets the private data of the context
. data
is
destroyed by destroy
when data
is unset. data
is unset
when new private data is set or context
is destroyed.
|
a MilterClientContext .
|
|
the private data. |
|
the destroy function for data or NULL .
|
gboolean milter_client_context_set_reply (MilterClientContext *context, guint code, const gchar *extended_code, const gchar *message, GError **error);
Sets the error reply code. 4xx code
is used on
MILTER_REPLY_TEMPORARY_FAILURE
. 5xx code
is used on
MILTER_REPLY_REJECT
.
See also smfi_setreply on milter.org.
|
a MilterClientContext .
|
|
the three-digit SMTP error reply code. (RFC 2821) Only 4xx and 5xx are accepted. |
|
the extended reply code (RFC 1893/2034),
or NULL .
|
|
the text part of the SMTP reply, or NULL .
|
|
return location for an error, or NULL .
|
Returns : |
TRUE on success.
|
gchar* milter_client_context_format_reply (MilterClientContext *context);
Formats the current error reply code specified by
milter_client_context_set_reply()
. If error reply code
isn't set, this function returns NULL
.
|
a MilterClientContext .
|
Returns : |
formatted reply code, or NULL .
|
gboolean milter_client_context_add_header (MilterClientContext *context, const gchar *name, const gchar *value, GError **error);
Adds a header to the current message's header list. This function can be called in "end-of-message" signal.
See also smfi_addheader on milter.org.
FIXME: write about MILTER_ACTION_ADD_HEADERS
.
|
a MilterClientContext .
|
|
the header name. |
|
the header value. |
|
return location for an error, or NULL .
|
Returns : |
TRUE on success.
|
gboolean milter_client_context_insert_header (MilterClientContext *context, guint32 index, const gchar *name, const gchar *value, GError **error);
Inserts a header into the current message's header lists
at index
. This function can be called in
"end-of-message" signal. See also
smfi_insheader on milter.org.
FIXME: write about MILTER_ACTION_ADD_HEADERS.
|
a MilterClientContext .
|
|
the index to be inserted. |
|
the header name. |
|
the header value. |
|
return location for an error, or NULL .
|
Returns : |
TRUE on success.
|
gboolean milter_client_context_change_header (MilterClientContext *context, const gchar *name, guint32 index, const gchar *value);
Changes a header that is located at index
in headers
that all of them are named name
. If value
is NULL
, the
header is deleted. This function can be
called in "end-of-message" signal.
See also smfi_chgheader on milter.org.
FIXME: write about MILTER_ACTION_CHANGE_HEADERS.
|
a MilterClientContext .
|
|
the header name. |
|
the index of headers that all of them are named
name . (1-based) FIXME: should change 0-based?
|
|
the header value. Use NULL to delete the target
header.
|
Returns : |
TRUE on success.
|
gboolean milter_client_context_delete_header (MilterClientContext *context, const gchar *name, guint32 index);
Deletes a header that is located at index
in headers
that all of them are named name
. This function can be
called in "end-of-message" signal.
This function works same as
milter_client_context_change_header()
with NULL
as
value
.
FIXME: write about MILTER_ACTION_CHANGE_HEADERS.
|
a MilterClientContext .
|
|
the header name. |
|
the index of headers that all of them are named
name . (1-based) FIXME: should change 0-based?
|
Returns : |
TRUE on success.
|
gboolean milter_client_context_change_from (MilterClientContext *context, const gchar *from, const gchar *parameters);
Changes the envelope from address of the current message.
ESMTP's 'MAIL FROM' parameter can be set by
parameters
. parameters
may be NULL
. This function can be
called in "end-of-message" signal.
See also smfi_chgfrom
on milter.org.
FIXME: write about MILTER_ACTION_CHANGE_FROM.
|
a MilterClientContext .
|
|
the new envelope from address. |
|
the ESMTP's 'MAIL FROM' parameter. It can be
NULL .
|
Returns : |
TRUE on success.
|
gboolean milter_client_context_add_recipient (MilterClientContext *context, const gchar *recipient, const gchar *parameters);
Adds a new envelope recipient address to the current
message. ESMTP's 'RCPT TO' parameter can be set by
parameters
. parameters
may be NULL
. This function can
be called in "end-of-message"
signal. See also smfi_addrcpt
and smfi_addrcpt_par
on milter.org.
FIXME: write about MILTER_ACTION_ADD_RECIPIENT and MILTER_ACTION_ADD_ENVELOPE_RECIPIENT_WITH_PARAMETERS.
|
a MilterClientContext .
|
|
the new envelope recipient address. |
|
the ESMTP's 'RCPT TO' parameter. It can be
NULL .
|
Returns : |
TRUE on success.
|
gboolean milter_client_context_delete_recipient (MilterClientContext *context, const gchar *recipient);
Removes a envelope recipient that named recipient
. This
function can be called in
"end-of-message" signal. See also
smfi_delrcpt
on milter.org.
FIXME: write about MILTER_ACTION_DELETE_RECIPIENT.
|
a MilterClientContext .
|
|
the envelope recipient address to be removed. |
Returns : |
TRUE on success.
|
gboolean milter_client_context_replace_body (MilterClientContext *context, const gchar *body, gsize body_size);
Replaces the body of the current message with body
. This
function can be called in
"end-of-message" signal. See also
smfi_replacebody
on milter.org.
FIXME: write about MILTER_ACTION_CHANGE_BODY.
|
a MilterClientContext .
|
|
the new body. |
|
the size of body .
|
Returns : |
TRUE on success.
|
gboolean milter_client_context_progress (MilterClientContext *context);
Notifies the MTA that this milter is still in progress. This function can be called in "end-of-message" signal. See also smfi_progress on milter.org.
|
a MilterClientContext .
|
Returns : |
TRUE on success.
|
gboolean milter_client_context_quarantine (MilterClientContext *context, const gchar *reason);
Quarantines the current message with reason
. This
function can be called in
"end-of-message" signal. See also
smfi_quarantine
on milter.org.
FIXME: write about MILTER_ACTION_QUARANTINE.
|
a MilterClientContext .
|
|
the reason why the current message is quarantined. |
Returns : |
TRUE on success.
|
void milter_client_context_set_timeout (MilterClientContext *context, guint timeout);
Sets the timeout by seconds. If MTA doesn't responses in
timeout
seconds, "timeout"
signal is emitted. See also
smfi_settimeout
on milter.org.
|
a MilterClientContext .
|
|
the timeout by seconds. (default is 7210 seconds) |
guint milter_client_context_get_timeout (MilterClientContext *context);
Gets the timeout by seconds.
|
a MilterClientContext .
|
Returns : |
timeout by seconds. |
void milter_client_context_set_state (MilterClientContext *context, MilterClientContextState state);
Sets the current state.
|
a MilterClientContext .
|
|
a MilterClientContextState .
|
MilterClientContextState milter_client_context_get_state (MilterClientContext *context);
Gets the current state.
|
a MilterClientContext .
|
Returns : |
the current state. |
void milter_client_context_set_option (MilterClientContext *context, MilterOption *option);
Sets the option for the context.
|
a MilterClientContext .
|
|
a MilterOption .
|
MilterOption* milter_client_context_get_option (MilterClientContext *context);
Gets the option for the context.
|
a MilterClientContext .
|
Returns : |
the option for the context. |