null+****@clear*****
null+****@clear*****
2012年 6月 4日 (月) 13:34:21 JST
Ryo Onodera 2012-06-04 13:34:21 +0900 (Mon, 04 Jun 2012) New Revision: f5fed1512d68b748af5cd885d70f53e7f8f8ea3d Log: Support groonga_database directive Modified files: src/nginx-module/ngx_http_groonga_module.c Modified: src/nginx-module/ngx_http_groonga_module.c (+46 -2) =================================================================== --- src/nginx-module/ngx_http_groonga_module.c 2012-06-04 13:05:33 +0900 (96c46da) +++ src/nginx-module/ngx_http_groonga_module.c 2012-06-04 13:34:21 +0900 (faf1599) @@ -20,6 +20,10 @@ #include <ngx_core.h> #include <ngx_http.h> +typedef struct { + ngx_str_t database; +} ngx_http_groonga_loc_conf_t; + static char *ngx_http_groonga(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_command_t ngx_http_groonga_commands[] = { @@ -30,11 +34,21 @@ static ngx_command_t ngx_http_groonga_commands[] = { 0, NULL }, + { ngx_string("groonga_database"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_groonga_loc_conf_t, database), + NULL }, + ngx_null_command }; static u_char ngx_groonga_string[] = "Hello, groonga!"; +static void * ngx_http_groonga_create_loc_conf(ngx_conf_t *cf); +static char * ngx_http_groonga_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); + static ngx_http_module_t ngx_http_groonga_module_ctx = { NULL, /* preconfiguration */ NULL, /* postconfiguration */ @@ -45,8 +59,8 @@ static ngx_http_module_t ngx_http_groonga_module_ctx = { NULL, /* create server configuration */ NULL, /* merge server configuration */ - NULL, /* create location configuration */ - NULL /* merge location configuration */ + ngx_http_groonga_create_loc_conf, /* create location configuration */ + ngx_http_groonga_merge_loc_conf, /* merge location configuration */ }; ngx_module_t ngx_http_groonga_module = { @@ -71,6 +85,10 @@ ngx_http_groonga_handler(ngx_http_request_t *r) ngx_buf_t *b; ngx_chain_t out; + ngx_http_groonga_loc_conf_t *loc_conf; + loc_conf = ngx_http_get_module_loc_conf(r, ngx_http_groonga_module); + printf("database: %*s\n", (int)loc_conf->database.len, loc_conf->database.data); + /* we response to 'GET' and 'HEAD' requests only */ if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) { return NGX_HTTP_NOT_ALLOWED; @@ -138,3 +156,29 @@ ngx_http_groonga(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } + +static void * +ngx_http_groonga_create_loc_conf(ngx_conf_t *cf) +{ + ngx_http_groonga_loc_conf_t *conf; + conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_groonga_loc_conf_t)); + if (conf == NULL) { + return NGX_CONF_ERROR; + } + + conf->database.data = NULL; + conf->database.len = 0; + + return conf; +} + +static char * +ngx_http_groonga_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) +{ + ngx_http_groonga_loc_conf_t *prev = parent; + ngx_http_groonga_loc_conf_t *conf = child; + + ngx_conf_merge_str_value(conf->database, prev->database, NULL); + + return NGX_CONF_OK; +}