Welcome! Log In Create A New Profile

Advanced

Re: Module API and srv structure initialization.

Maxim Dounin
January 25, 2012 09:36AM
Hello!

On Wed, Jan 25, 2012 at 09:40:13AM +0100, Simone Margaritelli wrote:

> Hi guys, i'm new to this mailing list.
>
> I'm writing a nginx handler module and i need to load a file in
> a server directive inside the config, let's assume it's
> something like:
>
> server {
> ...
> mymodule-ruleset /etc/nginx/mymodule-rules.json;
> ...
> }
>
> So i have a server structure like:
>
> typedef struct {
> ...
> ngx_str_t ruleset;
> ...
> }
> ngx_mymodule_srv_conf_t;
>
> I initialize the ruleset attribute inside the merge_srv_conf
> handler:
>
> ngx_conf_merge_str_value( conf->ruleset_path, prev->ruleset_path, DEFAULT_RULESET_PATH );
>
> ( Where DEFAULT_RULESET_PATH is a constant #defined my me ).
>
> The problem is, i have to load this file only once for server
> directive, but the user could ignore the mymodule-ruleset using
> its default value, so i can't use an handler to load it (it
> could be never called).
>
> Where's the best place to load this file? In the
> postconfiguration handler ? If so, how do i retrieve the
> srv_conf_t inside the postconfiguration handler ?

If you don't care much about the same file loaded multiple times
if used in different server{}'s, easiest way is to load files in
a merge server configuration handler.

Postconfiguration handler may be used as well, but you need main
config then, and reference files you need to load there. See e.g.
access log module for an example of using of postconfiguration
handler for a similar task (it uses postconfiguration handler to
compile "combined" log format if it's used in config).

Maxim Dounin


>
> Thanks for your time, i'm new to nginx developing and i'm
> finding some trouble to understand its structure.
>
> PS: I've already read the guides specified in the wiki, but
> there's nothing so specific.



>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Module API and srv structure initialization.

evilsocket 1627 January 25, 2012 03:42AM

Re: Module API and srv structure initialization.

Maxim Dounin 573 January 25, 2012 09:36AM

Re: Module API and srv structure initialization.

evilsocket 856 January 25, 2012 09:44AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 157
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready