@@ -118,7 +118,7 @@ static ngx_int_t ngx_http_c_func_module_init(ngx_cycle_t *cycle);
118118static void ngx_http_c_func_master_exit (ngx_cycle_t * cycle );
119119static void ngx_http_c_func_client_body_handler (ngx_http_request_t * r );
120120static ngx_int_t ngx_http_c_func_proceed_init_calls (ngx_cycle_t * cycle , ngx_http_c_func_srv_conf_t * scf , ngx_http_c_func_main_conf_t * mcf );
121- static u_char * ngx_http_c_func_strdup (ngx_pool_t * pool , const char * src , size_t len );
121+ static u_char * ngx_http_c_func_strdup_with_p (ngx_pool_t * pool , const char * src , size_t len );
122122
123123static ngx_int_t ngx_http_c_func_get_resp_var (ngx_http_request_t * r , ngx_http_variable_value_t * v , uintptr_t data );
124124static void ngx_http_c_func_set_resp_var_with_r (ngx_http_request_t * r , ngx_http_c_func_ctx_t * ctx , const char * resp_content );
@@ -149,6 +149,7 @@ void ngx_http_c_func_log_debug(ngx_http_c_func_ctx_t *ctx, const char* msg);
149149void ngx_http_c_func_log_info (ngx_http_c_func_ctx_t * ctx , const char * msg );
150150void ngx_http_c_func_log_warn (ngx_http_c_func_ctx_t * ctx , const char * msg );
151151void ngx_http_c_func_log_err (ngx_http_c_func_ctx_t * ctx , const char * msg );
152+ char * ngx_http_c_func_strdup (ngx_http_c_func_ctx_t * ctx , const char * src );
152153u_char * ngx_http_c_func_get_header (ngx_http_c_func_ctx_t * ctx , const char * key );
153154void * ngx_http_c_func_get_query_param (ngx_http_c_func_ctx_t * ctx , const char * key );
154155void * ngx_http_c_func_palloc (ngx_http_c_func_ctx_t * ctx , size_t size );
@@ -532,7 +533,7 @@ ngx_http_c_func_post_configuration(ngx_conf_t *cf) {
532533static ngx_int_t
533534ngx_http_c_func_pre_configuration (ngx_conf_t * cf ) {
534535
535- #ifndef ngx_http_c_func_module_version_8
536+ #ifndef ngx_http_c_func_module_version_9
536537 ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "%s" , "the latest ngx_http_c_func_module.h not found in the c header path, \
537538 please copy latest ngx_http_c_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
538539 with read and write permission." );
@@ -1103,8 +1104,19 @@ ngx_http_c_func_log_err(ngx_http_c_func_ctx_t *ctx, const char* msg) {
11031104 ngx_log_error (NGX_LOG_ERR , (ngx_log_t * )ctx -> __log__ , 0 , "%s" , msg );
11041105}
11051106
1107+ char *
1108+ ngx_http_c_func_strdup (ngx_http_c_func_ctx_t * ctx , const char * src ) {
1109+ char * dst ;
1110+ if (src == NULL ) return NULL ;
1111+ size_t len = ngx_strlen (src );
1112+ dst = (char * ) ngx_palloc ((ngx_pool_t * )ctx -> __pl__ , (len + 1 ) * sizeof (char ));
1113+ ngx_memcpy (dst , src , len );
1114+ dst [len ] = '\0' ;
1115+ return dst ;
1116+ }
1117+
11061118static u_char *
1107- ngx_http_c_func_strdup (ngx_pool_t * pool , const char * src , size_t len ) {
1119+ ngx_http_c_func_strdup_with_p (ngx_pool_t * pool , const char * src , size_t len ) {
11081120 u_char * dst ;
11091121 dst = ngx_pcalloc (pool , len + 1 );
11101122 if (dst == NULL ) {
@@ -1404,11 +1416,11 @@ ngx_http_c_func_write_resp(
14041416 /* Set the Content-Type header. */
14051417 if (content_type ) {
14061418 r -> headers_out .content_type .len = ngx_strlen (content_type );
1407- r -> headers_out .content_type .data = ngx_http_c_func_strdup (r -> pool , content_type , r -> headers_out .content_type .len );
1419+ r -> headers_out .content_type .data = ngx_http_c_func_strdup_with_p (r -> pool , content_type , r -> headers_out .content_type .len );
14081420 } else {
14091421 static const char * plaintext_content_type = ngx_http_c_func_content_type_plaintext ;
14101422 r -> headers_out .content_type .len = ngx_strlen (plaintext_content_type );
1411- r -> headers_out .content_type .data = ngx_http_c_func_strdup (r -> pool , plaintext_content_type , r -> headers_out .content_type .len );
1423+ r -> headers_out .content_type .data = ngx_http_c_func_strdup_with_p (r -> pool , plaintext_content_type , r -> headers_out .content_type .len );
14121424 }
14131425
14141426 ngx_buf_t * b ;
@@ -1433,7 +1445,7 @@ ngx_http_c_func_write_resp(
14331445
14341446 if (status_line ) {
14351447 r -> headers_out .status_line .len = ngx_strlen (status_line );
1436- r -> headers_out .status_line .data = ngx_http_c_func_strdup (r -> pool , status_line , r -> headers_out .status_line .len );
1448+ r -> headers_out .status_line .data = ngx_http_c_func_strdup_with_p (r -> pool , status_line , r -> headers_out .status_line .len );
14371449 }
14381450
14391451 /* Get the content length of the body. */
0 commit comments