Permalink
Browse files

add check type of smtp and some test cases

  • Loading branch information...
yaoweibin committed Mar 31, 2010
1 parent 2c053b7 commit dd222aecc72a38162719564aa7854067442d3c7c
View
@@ -20,6 +20,7 @@ typedef struct ngx_tcp_upstream_resolved_s ngx_tcp_upstream_resolved_t;
typedef struct ngx_tcp_check_peer_conf_s ngx_tcp_check_peer_conf_t;
typedef struct ngx_tcp_check_peers_conf_s ngx_tcp_check_peers_conf_t;
+typedef struct check_conf_s check_conf_t;
/* make nginx-0.8.22+ happy */
#if defined(nginx_version) && nginx_version >= 8022
View
@@ -56,14 +56,21 @@ static ngx_command_t ngx_tcp_upstream_commands[] = {
NGX_TCP_UPS_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_TCP_SRV_CONF_OFFSET,
- offsetof(ngx_tcp_upstream_srv_conf_t, check_http_conf.send),
+ offsetof(ngx_tcp_upstream_srv_conf_t, send),
+ NULL },
+
+ { ngx_string("check_smtp_send"),
+ NGX_TCP_UPS_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_TCP_SRV_CONF_OFFSET,
+ offsetof(ngx_tcp_upstream_srv_conf_t, send),
NULL },
{ ngx_string("check_http_expect_alive"),
NGX_TCP_UPS_CONF|NGX_CONF_1MORE,
ngx_conf_set_bitmask_slot,
NGX_TCP_SRV_CONF_OFFSET,
- offsetof(ngx_tcp_upstream_srv_conf_t, check_http_conf.status_alive),
+ offsetof(ngx_tcp_upstream_srv_conf_t, status_alive),
&ngx_check_http_expect_alive_masks },
{ ngx_string("check_shm_size"),
@@ -923,15 +930,14 @@ ngx_tcp_upstream_check(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
ngx_tcp_upstream_srv_conf_t *uscf = conf;
ngx_str_t *value, s;
- ngx_uint_t i, rise, fall, type;
+ ngx_uint_t i, rise, fall;
ngx_msec_t interval, timeout;
/*set default*/
rise = 2;
fall = 5;
interval = 30000;
timeout = 1000;
- type = NGX_TCP_CHECK_TCP;
value = cf->args->elts;
@@ -941,25 +947,13 @@ ngx_tcp_upstream_check(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
s.len = value[i].len - 5;
s.data = value[i].data + 5;
- if (ngx_strncmp(s.data, "tcp", s.len) == 0) {
- type = NGX_TCP_CHECK_TCP;
- continue;
- }
- else if (ngx_strncmp(s.data, "http", s.len) == 0 ) {
- type = NGX_TCP_CHECK_HTTP;
- continue;
- }
- else if (ngx_strncmp(s.data, "ssl_hello", s.len) == 0 ) {
- type = NGX_TCP_CHECK_SSL_HELLO;
- continue;
- }
- else if (ngx_strncmp(s.data, "smtp", s.len) == 0 ) {
- type = NGX_TCP_CHECK_SMTP;
- continue;
- }
- else {
+ uscf->check_type_conf = ngx_tcp_get_check_type_conf(&s);
+
+ if ( uscf->check_type_conf == NULL) {
goto invalid_check_parameter;
}
+
+ continue;
}
if (ngx_strncmp(value[i].data, "interval=", 9) == 0) {
@@ -1013,12 +1007,18 @@ ngx_tcp_upstream_check(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
goto invalid_check_parameter;
}
- uscf->check_type = type;
uscf->check_interval = interval;
uscf->check_timeout = timeout;
uscf->fall_count = fall;
uscf->rise_count = rise;
+ if (uscf->check_type_conf == NULL) {
+ s.len = sizeof("tcp") - 1;
+ s.data =(u_char *) "tcp";
+
+ uscf->check_type_conf = ngx_tcp_get_check_type_conf(&s);
+ }
+
return NGX_CONF_OK;
invalid_check_parameter:
View
@@ -93,26 +93,8 @@ typedef struct {
#define NGX_TCP_UPSTREAM_SRUN_ID 0x0040
#define NGX_TCP_UPSTREAM_MAX_BUSY 0x0080
-
-#define NGX_TCP_CHECK_TCP 0x0001
-#define NGX_TCP_CHECK_HTTP 0x0002
-#define NGX_TCP_CHECK_SSL_HELLO 0x0004
-#define NGX_TCP_CHECK_SMTP 0x0008
-
-
-#define NGX_CHECK_HTTP_2XX 0x0002
-#define NGX_CHECK_HTTP_3XX 0x0004
-#define NGX_CHECK_HTTP_4XX 0x0008
-#define NGX_CHECK_HTTP_5XX 0x0010
-#define NGX_CHECK_HTTP_6XX 0x0020
-#define NGX_CHECK_HTTP_ERR 0x8000
-
-typedef struct {
- ngx_str_t send;
- ngx_uint_t status_alive;
-} http_check_conf_t;
-
struct ngx_tcp_upstream_srv_conf_s {
+
ngx_tcp_upstream_peer_t peer;
void **srv_conf;
@@ -130,9 +112,14 @@ struct ngx_tcp_upstream_srv_conf_s {
ngx_uint_t rise_count;
ngx_msec_t check_interval;
ngx_msec_t check_timeout;
- ngx_uint_t check_type;
- http_check_conf_t check_http_conf;
+ check_conf_t *check_type_conf;
+ ngx_str_t send;
+
+ union {
+ ngx_uint_t return_code;
+ ngx_uint_t status_alive;
+ };
};
Oops, something went wrong.

0 comments on commit dd222ae

Please sign in to comment.