# Module API and srv structure initialization

**URL:** <https://www.ruby-forum.com/t/module-api-and-srv-structure-initialization/216101>\
**Category:** NGINX\
**Created:** [January 25, 2012, 9:50am UTC](https://www.ruby-forum.com/t/module-api-and-srv-structure-initialization/216101 "2012-01-25T09:50:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 25, 2012, 9:50am UTC](https://www.ruby-forum.com/t/module-api-and-srv-structure-initialization/216101/1 "2012-01-25T09:50:31Z")

</div>

Hi guys, i’m new to this forum (already introduced myself ^^).

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 ?

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.

Posted at Nginx Forum:

> **[Module API and srv structure initialization.](https://forum.nginx.org/read.php?2,221610,221610#msg-221610)**
>
> Hi guys, i'm new to this forum (already introduced myself ^^). 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...

---

<div class="post-metadata">

**Author:** ![evilsocket](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/4bbf92/32.png) [@evilsocket](https://www.ruby-forum.com/u/evilsocket)\
**Post date:** [January 25, 2012, 3:35pm UTC](https://www.ruby-forum.com/t/module-api-and-srv-structure-initialization/216101/2 "2012-01-25T15:35:44Z")

</div>

Hello!

On Wed, Jan 25, 2012 at 03:49:40AM -0500, evilsocket wrote:

> Hi guys, i’m new to this forum (already introduced myself ^^).
> 
> 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:

[…]

See nginx-devel@ for the reply. Cross-posting isn’t really good  
idea.

Maxim D.

---

<div class="post-metadata">

**Author:** ![evilsocket](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/4bbf92/32.png) [@evilsocket](https://www.ruby-forum.com/u/evilsocket)\
**Post date:** [January 25, 2012, 3:42pm UTC](https://www.ruby-forum.com/t/module-api-and-srv-structure-initialization/216101/3 "2012-01-25T15:42:33Z")

</div>

I guess i’m gonna load it as a main configuration inside the post  
configuration handler, thanks so much 🙂

Posted at Nginx Forum:

> **[Re: Module API and srv structure initialization.](https://forum.nginx.org/read.php?2,221610,221637#msg-221637)**
>
> Hi guys, i'm new to this forum (already introduced myself ^^). 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...
