diff src/mail/ngx_mail.h @ 1487:f69493e8faab

ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
author Igor Sysoev <igor@sysoev.ru>
date Sat, 15 Sep 2007 16:51:16 +0000
parents 4606dce4f416
children cd042416586c
line wrap: on
line diff
--- a/src/mail/ngx_mail.h
+++ b/src/mail/ngx_mail.h
@@ -73,57 +73,27 @@ typedef struct {
 #define NGX_MAIL_IMAP_PROTOCOL  1
 #define NGX_MAIL_SMTP_PROTOCOL  2
 
-typedef struct {
-    ngx_msec_t              timeout;
-    ngx_msec_t              smtp_greeting_delay;
+
+typedef struct ngx_mail_protocol_s  ngx_mail_protocol_t;
+
 
-    size_t                  imap_client_buffer_size;
-    size_t                  smtp_client_buffer_size;
+typedef struct {
+    ngx_mail_protocol_t    *protocol;
 
-    ngx_uint_t              protocol;
+    ngx_msec_t              timeout;
 
     ngx_flag_t              so_keepalive;
 
-    ngx_str_t               pop3_capability;
-    ngx_str_t               pop3_starttls_capability;
-    ngx_str_t               pop3_starttls_only_capability;
-    ngx_str_t               pop3_auth_capability;
-
-    ngx_str_t               imap_capability;
-    ngx_str_t               imap_starttls_capability;
-    ngx_str_t               imap_starttls_only_capability;
+    ngx_str_t               server_name;
 
-    ngx_str_t               smtp_capability;
-    ngx_str_t               smtp_starttls_capability;
-    ngx_str_t               smtp_starttls_only_capability;
-
-    ngx_str_t               server_name;
-    ngx_str_t               smtp_server_name;
-    ngx_str_t               smtp_greeting;
-
-    ngx_uint_t              pop3_auth_methods;
-    ngx_uint_t              imap_auth_methods;
-    ngx_uint_t              smtp_auth_methods;
-
-    ngx_array_t             pop3_capabilities;
-    ngx_array_t             imap_capabilities;
-    ngx_array_t             smtp_capabilities;
+    u_char                 *file_name;
+    ngx_int_t               line;
 
     /* server ctx */
     ngx_mail_conf_ctx_t    *ctx;
 } ngx_mail_core_srv_conf_t;
 
 
-typedef struct {
-    void                 *(*create_main_conf)(ngx_conf_t *cf);
-    char                 *(*init_main_conf)(ngx_conf_t *cf, void *conf);
-
-    void                 *(*create_srv_conf)(ngx_conf_t *cf);
-    char                 *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
-                                void *conf);
-} ngx_mail_module_t;
-
-
 typedef enum {
     ngx_pop3_start = 0,
     ngx_pop3_user,
@@ -181,9 +151,9 @@ typedef struct {
 
     ngx_uint_t              mail_state;
 
+    unsigned                protocol:3;
     unsigned                blocked:1;
     unsigned                quit:1;
-    unsigned                protocol:2;
     unsigned                quoted:1;
     unsigned                backslash:1;
     unsigned                no_sync_literal:1;
@@ -208,7 +178,7 @@ typedef struct {
 
     ngx_uint_t              login_attempt;
 
-    /* used to parse IMAP/POP3/SMTP command */
+    /* used to parse POP3/IMAP/SMTP command */
 
     ngx_uint_t              state;
     u_char                 *cmd_start;
@@ -282,10 +252,43 @@ typedef struct {
 #define NGX_MAIL_PARSE_INVALID_COMMAND  20
 
 
-#define NGX_MAIL_MODULE      0x4C49414D     /* "MAIL" */
+typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s,
+    ngx_connection_t *c);
+typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev);
+typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev);
+typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s);
+
+
+struct ngx_mail_protocol_s {
+    ngx_str_t                   name;
+    in_port_t                   port[4];
+    ngx_uint_t                  type;
+
+    ngx_mail_init_session_pt    init_session;
+    ngx_mail_init_protocol_pt   init_protocol;
+    ngx_mail_parse_command_pt   parse_command;
+    ngx_mail_auth_state_pt      auth_state;
 
-#define NGX_MAIL_MAIN_CONF   0x02000000
-#define NGX_MAIL_SRV_CONF    0x04000000
+    ngx_str_t                   internal_server_error;
+};
+
+
+typedef struct {
+    ngx_mail_protocol_t        *protocol;
+
+    void                       *(*create_main_conf)(ngx_conf_t *cf);
+    char                       *(*init_main_conf)(ngx_conf_t *cf, void *conf);
+
+    void                       *(*create_srv_conf)(ngx_conf_t *cf);
+    char                       *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
+                                      void *conf);
+} ngx_mail_module_t;
+
+
+#define NGX_MAIL_MODULE         0x4C49414D     /* "MAIL" */
+
+#define NGX_MAIL_MAIN_CONF      0x02000000
+#define NGX_MAIL_SRV_CONF       0x04000000
 
 
 #define NGX_MAIL_MAIN_CONF_OFFSET  offsetof(ngx_mail_conf_ctx_t, main_conf)
@@ -306,12 +309,6 @@ typedef struct {
 #define ngx_mail_conf_get_module_srv_conf(cf, module)                        \
     ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
 
-typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s,
-    ngx_connection_t *c);
-typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev);
-typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev);
-typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s);
-
 
 #if (NGX_MAIL_SSL)
 void ngx_mail_starttls_handler(ngx_event_t *rev);
@@ -321,10 +318,6 @@ ngx_int_t ngx_mail_starttls_only(ngx_mai
 
 void ngx_mail_init_connection(ngx_connection_t *c);
 
-void ngx_mail_pop3_auth_state(ngx_event_t *rev);
-void ngx_mail_imap_auth_state(ngx_event_t *rev);
-void ngx_mail_smtp_auth_state(ngx_event_t *rev);
-
 ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
     ngx_mail_core_srv_conf_t *cscf);
 ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c,
@@ -336,6 +329,7 @@ ngx_int_t ngx_mail_auth_login_password(n
 ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s,
     ngx_connection_t *c, char *prefix, size_t len);
 ngx_int_t ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c);
+ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c);
 
 void ngx_mail_send(ngx_event_t *wev);
 ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c);
@@ -345,18 +339,7 @@ void ngx_mail_session_internal_server_er
 u_char *ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len);
 
 
-void ngx_mail_pop3_init_session(ngx_mail_session_t *s, ngx_connection_t *c);
-void ngx_mail_imap_init_session(ngx_mail_session_t *s, ngx_connection_t *c);
-void ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c);
-
-void ngx_mail_pop3_init_protocol(ngx_event_t *rev);
-void ngx_mail_imap_init_protocol(ngx_event_t *rev);
-void ngx_mail_smtp_init_protocol(ngx_event_t *rev);
-
-ngx_int_t ngx_mail_pop3_parse_command(ngx_mail_session_t *s);
-ngx_int_t ngx_mail_imap_parse_command(ngx_mail_session_t *s);
-ngx_int_t ngx_mail_smtp_parse_command(ngx_mail_session_t *s);
-ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c);
+char *ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 
 
 /* STUB */