11/*
2- * @file: nginx_moufle_echo .c
2+ * @file: nginx_http_echo_module .c
33 * @brief: Nginx echo command output a string
4- * @author: Panda <vozlt@vozlt .com>
4+ * @author: Panda <itwujunze@163 .com>
55 * @version: 1.0.1
66 * @date: 2017/6/12
77 *
88 * Compile:
9- * shell> ./configure --add-module=/path/to/nginx_moudle_echo .c
9+ * shell> ./configure --add-module=/path/to/nginx_http_echo_module .c
1010 *
1111 */
1212
@@ -34,7 +34,7 @@ static ngx_command_t ngx_http_echo_commands[] = {
3434 NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1 ,
3535 ngx_http_echo ,
3636 NGX_HTTP_LOC_CONF_OFFSET ,
37- offsetof(ngx_http_echo_oc_conf_t , ed ),
37+ offsetof(ngx_http_echo_loc_conf_t , ed ),
3838 NULL ,
3939 },
4040 ngx_null_command ,
@@ -123,11 +123,11 @@ ngx_http_echo_handler(ngx_http_request_t *r)
123123 b = ngx_pcalloc (r -> pool , sizeof (ngx_buf_t ));
124124 if (b == NULL )
125125 {
126- ngx_log_error (NGX_LOG_ERROR , r -> connection -> log , 0 , "Failed to allocate response buffer." );
126+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Failed to allocate response buffer." );
127127 return NGX_HTTP_INTERNAL_SERVER_ERROR ;
128128 }
129129 out .buf = b ;
130- put .next = NULL ;
130+ out .next = NULL ;
131131 b -> pos = elcf -> ed .data ;
132132 b -> last = elcf -> ed .data + (elcf -> ed .len );
133133 b -> memory = 1 ;
@@ -148,12 +148,12 @@ ngx_http_echo_handler(ngx_http_request_t *r)
148148 * @return ngx status code
149149 */
150150static char *
151- ngx_http_echo (ngx_conf_t * f ,ngx_command_t * cmd , void * conf )
151+ ngx_http_echo (ngx_conf_t * cf ,ngx_command_t * cmd , void * conf )
152152{
153153 ngx_http_core_loc_conf_t * clcf ;
154- clcf = ngx_http_conf_get_module_loc_conf (cf ,ngx_http_core_module );
155- clcf -> handle = ngx_http_echo_handler ; //修改核心模块配置(也就是当前location),将其handler替换为我们自己定义的ngx_http_echo_handler
156- ngx_conf_set_str_slot (cf ,cmf ,conf );
154+ clcf = ngx_http_conf_get_module_loc_conf (cf , ngx_http_core_module );
155+ clcf -> handler = ngx_http_echo_handler ; //修改核心模块配置(也就是当前location),将其handler替换为我们自己定义的ngx_http_echo_handler
156+ ngx_conf_set_str_slot (cf ,cmd ,conf );
157157 return NGX_CONF_OK ;
158158}
159159
@@ -164,7 +164,7 @@ ngx_http_echo(ngx_conf_t *f,ngx_command_t *cmd , void *conf)
164164 * @param cf
165165 * @return
166166 */
167- static char *
167+ static void *
168168ngx_http_echo_create_loc_conf (ngx_conf_t * cf )
169169{
170170 ngx_http_echo_loc_conf_t * conf ;
@@ -202,18 +202,6 @@ ngx_http_echo_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
202202static ngx_int_t
203203ngx_http_echo_init (ngx_conf_t * cf )
204204{
205- ngx_http_handler_pt * h ;
206- ngx_http_core_main_conf_t * cmcf ;
207-
208- cmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_core_module );
209-
210- h = ngx_array_push (& cmcf -> phases [NGX_HTTP_CONTENT_PHASE ].handlers );
211- if (h == NULL ) {
212- return NGX_ERROR ;
213- }
214-
215- * h = ngx_http_echo_handler ;
216-
217205 return NGX_OK ;
218206}
219207
0 commit comments