Ngx_conf_t args count

From Miller’s http://www.evanmiller.org/nginx-modules-guide.html,
section 5.2:

ngx_http_upstream_hash(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_upstream_srv_conf_t *uscf;
ngx_http_script_compile_t sc;
ngx_str_t *value;
ngx_array_t *vars_lengths, *vars_values;

value = cf->args->elts;

/* the following is necessary to evaluate the argument to "hash"

as a $variable */
ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));

vars_lengths = NULL;
vars_values = NULL;

sc.cf = cf;
sc.source = &value[1];
...

}

How does one know that value[1] is valid? Shouldn’t cf->args->nelts be
checked first? Or does ngx_conf_t always have at least two options?

Related: why was value[0] not chosen?

Jeff

On Sun, Dec 15, 2013 at 04:31:08PM -0500, Jeffrey W. wrote:

}

How does one know that value[1] is valid? Shouldn’t cf->args->nelts be
checked first? Or does ngx_conf_t always have at least two options?
Related: why was value[0] not chosen?

value[0] is the directive name, “hash” in this case. It’s
like argv[] in main().

The “hash” directive can be specified in the “upstream” context
(NGX_HTTP_UPS_CONF) and it takes exactly one argument (NGX_CONF_TAKE1).
The generic configuration parser code ensures that the argument
exists.

http://www.evanmiller.org/nginx-modules-guide.html#directives

On Mon, Dec 16, 2013 at 2:15 AM, Ruslan E. [email protected] wrote:

value = cf->args->elts;
...

(NGX_HTTP_UPS_CONF) and it takes exactly one argument (NGX_CONF_TAKE1).
The generic configuration parser code ensures that the argument
exists.

http://www.evanmiller.org/nginx-modules-guide.html#directives
Ah, thanks. It makes perfect sense.

Jeff

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs