eagle sbc sbc19861004 at
Fri Dec 31 14:18:33 MSK 2010

hi, nn hust:
   First, the 'cf->ctx' is a context variable. When in the DIRECT_CONF or
MAIN_CONF context, it point to 'void*[MAX_MODULE]'  array, while in the HTTP
context, it point to a 'ngx_http_conf_ctx_t', which is a structure with
there pointers each point to a 'void *[MAX_HTTP_MODULE]' array. Other CORE
module act the same as HTTP.
   I draw a diagram to make seems more clear :
[image: cf.jpg]

Every module structure has a 'index' member and 'ctx_index' member. 'index'
 indicate its own data position in the glocal 'void *' array, while
'ctx_index' indicate the context related. (According to what I understand,
The module type already choose which kind of array it will use, so the two
index is not necessary)

The different between DIRECT and MAIN is:  DIRECT means the memory is
already allocated, and the cmd's set function can directly use it, so pass
the pointer to the allocated memory; MAIN means the memory to be allocated
depend on the module, so pass the pointer to the pointer in the array.

cmd's 'conf' member indicate which context it will store its data. As in
HTTP, we can choose MAIN, SRV, LOC.

And I think the code is now easy to understand.
On Fri, Dec 31, 2010 at 4:46 PM, nn hust <nzjemail at> wrote:

> I am confused by the multi dimensions pointer of the module configure
> structure
> if (cmd->type & NGX_DIRECT_CONF) {
>                 conf = ((void **) cf->ctx)[ngx_modules[i]->index];
>             } else if (cmd->type & NGX_MAIN_CONF) {
>                 conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
>             } else if (cf->ctx) {
>                 confp = *(void **) ((char *) cf->ctx + cmd->conf);
>                 if (confp) {
>                     conf = confp[ngx_modules[i]->ctx_index];
>                 }
>             }
>             rv = cmd->set(cf, cmd, conf);
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 42505 bytes
Desc: not available
URL: <>

More information about the nginx-devel mailing list