comparison src/http/ngx_http_upstream.c @ 5728:63d7d69d0fe4

Upstream: reduced diffs to the plus version of nginx. No functional changes.
author Ruslan Ermilov <ru@nginx.com>
date Fri, 20 Jun 2014 12:55:41 +0400
parents efc84a5723b3
children c8bdde1c8c97
comparison
equal deleted inserted replaced
5727:675bda8dcfdb 5728:63d7d69d0fe4
4849 4849
4850 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf; 4850 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf;
4851 } 4851 }
4852 } 4852 }
4853 4853
4854 uscf->servers = ngx_array_create(cf->pool, 4,
4855 sizeof(ngx_http_upstream_server_t));
4856 if (uscf->servers == NULL) {
4857 return NGX_CONF_ERROR;
4858 }
4859
4854 4860
4855 /* parse inside upstream{} */ 4861 /* parse inside upstream{} */
4856 4862
4857 pcf = *cf; 4863 pcf = *cf;
4858 cf->ctx = ctx; 4864 cf->ctx = ctx;
4864 4870
4865 if (rv != NGX_CONF_OK) { 4871 if (rv != NGX_CONF_OK) {
4866 return rv; 4872 return rv;
4867 } 4873 }
4868 4874
4869 if (uscf->servers == NULL) { 4875 if (uscf->servers->nelts == 0) {
4870 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 4876 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4871 "no servers are inside upstream"); 4877 "no servers are inside upstream");
4872 return NGX_CONF_ERROR; 4878 return NGX_CONF_ERROR;
4873 } 4879 }
4874 4880
4886 ngx_url_t u; 4892 ngx_url_t u;
4887 ngx_int_t weight, max_fails; 4893 ngx_int_t weight, max_fails;
4888 ngx_uint_t i; 4894 ngx_uint_t i;
4889 ngx_http_upstream_server_t *us; 4895 ngx_http_upstream_server_t *us;
4890 4896
4891 if (uscf->servers == NULL) {
4892 uscf->servers = ngx_array_create(cf->pool, 4,
4893 sizeof(ngx_http_upstream_server_t));
4894 if (uscf->servers == NULL) {
4895 return NGX_CONF_ERROR;
4896 }
4897 }
4898
4899 us = ngx_array_push(uscf->servers); 4897 us = ngx_array_push(uscf->servers);
4900 if (us == NULL) { 4898 if (us == NULL) {
4901 return NGX_CONF_ERROR; 4899 return NGX_CONF_ERROR;
4902 } 4900 }
4903 4901
4904 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); 4902 ngx_memzero(us, sizeof(ngx_http_upstream_server_t));
4905 4903
4906 value = cf->args->elts; 4904 value = cf->args->elts;
4905
4906 weight = 1;
4907 max_fails = 1;
4908 fail_timeout = 10;
4909
4910 for (i = 2; i < cf->args->nelts; i++) {
4911
4912 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) {
4913
4914 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) {
4915 goto invalid;
4916 }
4917
4918 weight = ngx_atoi(&value[i].data[7], value[i].len - 7);
4919
4920 if (weight == NGX_ERROR || weight == 0) {
4921 goto invalid;
4922 }
4923
4924 continue;
4925 }
4926
4927 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) {
4928
4929 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) {
4930 goto invalid;
4931 }
4932
4933 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10);
4934
4935 if (max_fails == NGX_ERROR) {
4936 goto invalid;
4937 }
4938
4939 continue;
4940 }
4941
4942 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) {
4943
4944 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) {
4945 goto invalid;
4946 }
4947
4948 s.len = value[i].len - 13;
4949 s.data = &value[i].data[13];
4950
4951 fail_timeout = ngx_parse_time(&s, 1);
4952
4953 if (fail_timeout == (time_t) NGX_ERROR) {
4954 goto invalid;
4955 }
4956
4957 continue;
4958 }
4959
4960 if (ngx_strcmp(value[i].data, "backup") == 0) {
4961
4962 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) {
4963 goto invalid;
4964 }
4965
4966 us->backup = 1;
4967
4968 continue;
4969 }
4970
4971 if (ngx_strcmp(value[i].data, "down") == 0) {
4972
4973 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) {
4974 goto invalid;
4975 }
4976
4977 us->down = 1;
4978
4979 continue;
4980 }
4981
4982 goto invalid;
4983 }
4907 4984
4908 ngx_memzero(&u, sizeof(ngx_url_t)); 4985 ngx_memzero(&u, sizeof(ngx_url_t));
4909 4986
4910 u.url = value[1]; 4987 u.url = value[1];
4911 u.default_port = 80; 4988 u.default_port = 80;
4915 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 4992 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4916 "%s in upstream \"%V\"", u.err, &u.url); 4993 "%s in upstream \"%V\"", u.err, &u.url);
4917 } 4994 }
4918 4995
4919 return NGX_CONF_ERROR; 4996 return NGX_CONF_ERROR;
4920 }
4921
4922 weight = 1;
4923 max_fails = 1;
4924 fail_timeout = 10;
4925
4926 for (i = 2; i < cf->args->nelts; i++) {
4927
4928 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) {
4929
4930 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) {
4931 goto invalid;
4932 }
4933
4934 weight = ngx_atoi(&value[i].data[7], value[i].len - 7);
4935
4936 if (weight == NGX_ERROR || weight == 0) {
4937 goto invalid;
4938 }
4939
4940 continue;
4941 }
4942
4943 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) {
4944
4945 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) {
4946 goto invalid;
4947 }
4948
4949 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10);
4950
4951 if (max_fails == NGX_ERROR) {
4952 goto invalid;
4953 }
4954
4955 continue;
4956 }
4957
4958 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) {
4959
4960 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) {
4961 goto invalid;
4962 }
4963
4964 s.len = value[i].len - 13;
4965 s.data = &value[i].data[13];
4966
4967 fail_timeout = ngx_parse_time(&s, 1);
4968
4969 if (fail_timeout == (time_t) NGX_ERROR) {
4970 goto invalid;
4971 }
4972
4973 continue;
4974 }
4975
4976 if (ngx_strcmp(value[i].data, "backup") == 0) {
4977
4978 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) {
4979 goto invalid;
4980 }
4981
4982 us->backup = 1;
4983
4984 continue;
4985 }
4986
4987 if (ngx_strcmp(value[i].data, "down") == 0) {
4988
4989 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) {
4990 goto invalid;
4991 }
4992
4993 us->down = 1;
4994
4995 continue;
4996 }
4997
4998 goto invalid;
4999 } 4997 }
5000 4998
5001 us->name = u.url; 4999 us->name = u.url;
5002 us->addrs = u.addrs; 5000 us->addrs = u.addrs;
5003 us->naddrs = u.naddrs; 5001 us->naddrs = u.naddrs;