null+****@clear*****
null+****@clear*****
2012年 6月 4日 (月) 13:05:33 JST
Ryo Onodera 2012-06-04 13:05:33 +0900 (Mon, 04 Jun 2012) New Revision: 958e3dc61d680d2b2672052a4a40031259e9d9e0 Log: Fix style: indent by 2 spaces Modified files: src/nginx-module/ngx_http_groonga_module.c Modified: src/nginx-module/ngx_http_groonga_module.c (+86 -86) =================================================================== --- src/nginx-module/ngx_http_groonga_module.c 2012-06-04 12:43:41 +0900 (685d2c7) +++ src/nginx-module/ngx_http_groonga_module.c 2012-06-04 13:05:33 +0900 (96c46da) @@ -23,118 +23,118 @@ static char *ngx_http_groonga(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_command_t ngx_http_groonga_commands[] = { - { ngx_string("groonga"), - NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, - ngx_http_groonga, - 0, - 0, - NULL }, - - ngx_null_command + { ngx_string("groonga"), + NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, + ngx_http_groonga, + 0, + 0, + NULL }, + + ngx_null_command }; static u_char ngx_groonga_string[] = "Hello, groonga!"; static ngx_http_module_t ngx_http_groonga_module_ctx = { - NULL, /* preconfiguration */ - NULL, /* postconfiguration */ + NULL, /* preconfiguration */ + NULL, /* postconfiguration */ - NULL, /* create main configuration */ - NULL, /* init main configuration */ + NULL, /* create main configuration */ + NULL, /* init main configuration */ - NULL, /* create server configuration */ - NULL, /* merge server configuration */ + NULL, /* create server configuration */ + NULL, /* merge server configuration */ - NULL, /* create location configuration */ - NULL /* merge location configuration */ + NULL, /* create location configuration */ + NULL /* merge location configuration */ }; ngx_module_t ngx_http_groonga_module = { - NGX_MODULE_V1, - &ngx_http_groonga_module_ctx, /* module context */ - ngx_http_groonga_commands, /* module directives */ - NGX_HTTP_MODULE, /* module type */ - NULL, /* init master */ - NULL, /* init module */ - NULL, /* init process */ - NULL, /* init thread */ - NULL, /* exit thread */ - NULL, /* exit process */ - NULL, /* exit master */ - NGX_MODULE_V1_PADDING + NGX_MODULE_V1, + &ngx_http_groonga_module_ctx, /* module context */ + ngx_http_groonga_commands, /* module directives */ + NGX_HTTP_MODULE, /* module type */ + NULL, /* init master */ + NULL, /* init module */ + NULL, /* init process */ + NULL, /* init thread */ + NULL, /* exit thread */ + NULL, /* exit process */ + NULL, /* exit master */ + NGX_MODULE_V1_PADDING }; static ngx_int_t ngx_http_groonga_handler(ngx_http_request_t *r) { - ngx_int_t rc; - ngx_buf_t *b; - ngx_chain_t out; - - /* we response to 'GET' and 'HEAD' requests only */ - if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) { - return NGX_HTTP_NOT_ALLOWED; - } - - /* discard request body, since we don't need it here */ - rc = ngx_http_discard_request_body(r); - - if (rc != NGX_OK) { - return rc; - } - - /* set the 'Content-type' header */ - r->headers_out.content_type_len = sizeof("text/html") - 1; - r->headers_out.content_type.len = sizeof("text/html") - 1; - r->headers_out.content_type.data = (u_char *) "text/html"; - - /* send the header only, if the request type is http 'HEAD' */ - if (r->method == NGX_HTTP_HEAD) { - r->headers_out.status = NGX_HTTP_OK; - r->headers_out.content_length_n = sizeof(ngx_groonga_string) - 1; - - return ngx_http_send_header(r); - } - - /* allocate a buffer for your response body */ - b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); - if (b == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } - - /* attach this buffer to the buffer chain */ - out.buf = b; - out.next = NULL; - - /* adjust the pointers of the buffer */ - b->pos = ngx_groonga_string; - b->last = ngx_groonga_string + sizeof(ngx_groonga_string) - 1; - b->memory = 1; /* this buffer is in memory */ - b->last_buf = 1; /* this is the last buffer in the buffer chain */ - - /* set the status line */ + ngx_int_t rc; + ngx_buf_t *b; + ngx_chain_t out; + + /* we response to 'GET' and 'HEAD' requests only */ + if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) { + return NGX_HTTP_NOT_ALLOWED; + } + + /* discard request body, since we don't need it here */ + rc = ngx_http_discard_request_body(r); + + if (rc != NGX_OK) { + return rc; + } + + /* set the 'Content-type' header */ + r->headers_out.content_type_len = sizeof("text/html") - 1; + r->headers_out.content_type.len = sizeof("text/html") - 1; + r->headers_out.content_type.data = (u_char *) "text/html"; + + /* send the header only, if the request type is http 'HEAD' */ + if (r->method == NGX_HTTP_HEAD) { r->headers_out.status = NGX_HTTP_OK; r->headers_out.content_length_n = sizeof(ngx_groonga_string) - 1; - /* send the headers of your response */ - rc = ngx_http_send_header(r); + return ngx_http_send_header(r); + } + + /* allocate a buffer for your response body */ + b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); + if (b == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + /* attach this buffer to the buffer chain */ + out.buf = b; + out.next = NULL; + + /* adjust the pointers of the buffer */ + b->pos = ngx_groonga_string; + b->last = ngx_groonga_string + sizeof(ngx_groonga_string) - 1; + b->memory = 1; /* this buffer is in memory */ + b->last_buf = 1; /* this is the last buffer in the buffer chain */ + + /* set the status line */ + r->headers_out.status = NGX_HTTP_OK; + r->headers_out.content_length_n = sizeof(ngx_groonga_string) - 1; + + /* send the headers of your response */ + rc = ngx_http_send_header(r); - if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { - return rc; - } + if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { + return rc; + } - /* send the buffer chain of your response */ - return ngx_http_output_filter(r, &out); + /* send the buffer chain of your response */ + return ngx_http_output_filter(r, &out); } static char * ngx_http_groonga(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_http_core_loc_conf_t *location_conf; + ngx_http_core_loc_conf_t *location_conf; - location_conf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); - /* handler to process the 'groonga' directive */ - location_conf->handler = ngx_http_groonga_handler; + location_conf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); + /* handler to process the 'groonga' directive */ + location_conf->handler = ngx_http_groonga_handler; - return NGX_CONF_OK; + return NGX_CONF_OK; }