├── auto ├── data │ ├── prefixes │ ├── header_files │ ├── headers │ ├── action_replacements │ ├── module_dependencies │ ├── modules_optional │ ├── conf_args │ ├── contexts │ ├── action_types │ ├── conf_locs │ └── conf_macros ├── src │ ├── palloc.h │ ├── array.h │ ├── conf_cmd_basic.h │ └── conf_merge.h ├── text │ └── autogen └── actions │ ├── palloc │ └── array ├── .gitignore ├── src ├── ndk_log.c ├── ndk_uri.h ├── ndk_http.h ├── ndk_buf.h ├── ndk_encoding.h ├── ndk_process.h ├── ndk_regex.h ├── ndk_process.c ├── ndk_upstream_list.h ├── ndk_string_util.h ├── ndk_complex_value.h ├── ndk_rewrite.h ├── ndk_path.h ├── ndk_buf.c ├── ndk_uri.c ├── ndk.h ├── ndk_hash.h ├── ndk_complex_path.h ├── ndk_string.h ├── ndk_encoding.c ├── ndk_debug.c ├── ndk_set_var.h ├── hash │ ├── murmurhash2.c │ ├── md5.h │ └── sha.h ├── ndk_hash.c ├── ndk_conf_file.h ├── ndk_http_headers.h ├── ndk_complex_path.c ├── ndk_rewrite.c ├── ndk_parse.h ├── ndk_http.c ├── ndk.c ├── ndk_complex_value.c ├── ndk_upstream_list.c ├── ndk_regex.c ├── ndk_debug.h ├── ndk_string.c ├── ndk_conf_file.c ├── ndk_log.h └── ndk_path.c ├── examples ├── http │ └── set_var │ │ ├── config │ │ └── ngx_http_set_var_examples_module.c └── README ├── patches ├── auto_config ├── rewrite_phase_handler └── expose_rewrite_functions ├── notes ├── CHANGES └── LICENSE ├── docs ├── upstream │ └── list ├── core │ ├── conf_cmds │ └── action_macros ├── patches │ └── more_logging_info └── modules │ └── set_var ├── objs ├── ndk_includes.h ├── ndk_config.c ├── ndk_config.h ├── ndk_palloc.h ├── ndk_array.h └── ndk_conf_merge.h ├── LICENSE ├── config └── README.md /auto/data/prefixes: -------------------------------------------------------------------------------- 1 | ngx 2 | ndk 3 | -------------------------------------------------------------------------------- /auto/data/header_files: -------------------------------------------------------------------------------- 1 | array 2 | palloc 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | cscope.* 3 | *~ 4 | *.swp 5 | -------------------------------------------------------------------------------- /auto/data/headers: -------------------------------------------------------------------------------- 1 | http_headers 2 | log 3 | parse 4 | string_util 5 | -------------------------------------------------------------------------------- /src/ndk_log.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* TODO : the required functions if the compiler does not have variadic macros */ 4 | -------------------------------------------------------------------------------- /auto/data/action_replacements: -------------------------------------------------------------------------------- 1 | 2 | OK NGX_OK 3 | E NGX_ERROR 4 | CE NGX_CONF_ERROR 5 | COK NGX_CONF_OK 6 | -------------------------------------------------------------------------------- /src/ndk_uri.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | u_char * ndk_map_uri_to_path_add_suffix (ngx_http_request_t *r, ngx_str_t *path, ngx_str_t *suffix, ngx_int_t dot); 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/ndk_http.h: -------------------------------------------------------------------------------- 1 | 2 | ngx_uint_t ndk_http_count_phase_handlers (ngx_http_core_main_conf_t *cmcf); 3 | ngx_uint_t ndk_http_parse_request_method (ngx_str_t *m); 4 | -------------------------------------------------------------------------------- /auto/data/module_dependencies: -------------------------------------------------------------------------------- 1 | complex_path complex_value path 2 | conf_file string 3 | hash string 4 | set_var rewrite 5 | upstream_list http_create_main_conf 6 | -------------------------------------------------------------------------------- /src/ndk_buf.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | ngx_int_t ndk_copy_chain_to_str (ngx_pool_t *pool, ngx_chain_t *in, ngx_str_t *str); 4 | char * ndk_copy_chain_to_charp (ngx_pool_t *pool, ngx_chain_t *in); 5 | 6 | -------------------------------------------------------------------------------- /auto/data/modules_optional: -------------------------------------------------------------------------------- 1 | buf 2 | complex_path 3 | complex_value 4 | conf_file 5 | encoding 6 | hash 7 | http 8 | path 9 | process 10 | regex 11 | rewrite 12 | set_var 13 | string 14 | upstream_list * 15 | uri 16 | -------------------------------------------------------------------------------- /examples/http/set_var/config: -------------------------------------------------------------------------------- 1 | ngx_addon_name=ngx_http_set_var_examples_module 2 | HTTP_MODULES="$HTTP_MODULES ngx_http_set_var_examples_module" 3 | NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_set_var_examples_module.c" 4 | have=NDK_SET_VAR . auto/have -------------------------------------------------------------------------------- /auto/data/conf_args: -------------------------------------------------------------------------------- 1 | 2 | TAKE1 3 | TAKE2 4 | TAKE3 5 | TAKE4 6 | TAKE5 7 | TAKE6 8 | TAKE7 9 | TAKE8 10 | TAKE12 11 | TAKE13 12 | TAKE23 13 | TAKE123 14 | TAKE1234 15 | 1MORE 16 | 2MORE 17 | ANY 18 | FLAG 19 | BLOCK 20 | MULTI 21 | ARGS_NUMBER 22 | 23 | -------------------------------------------------------------------------------- /src/ndk_encoding.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | typedef struct { 6 | char *from; 7 | char *to; 8 | } ndk_encoding_t; 9 | 10 | 11 | char * ndk_conf_set_encoding_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 12 | 13 | -------------------------------------------------------------------------------- /src/ndk_process.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | typedef struct { 4 | int signo; 5 | char *signame; 6 | char *name; 7 | void (*handler)(int signo); 8 | } ngx_signal_t; 9 | 10 | 11 | ngx_int_t ndk_init_signals (ngx_signal_t *sig, ngx_log_t *log); 12 | 13 | -------------------------------------------------------------------------------- /auto/data/contexts: -------------------------------------------------------------------------------- 1 | 2 | MAIN 3 | SRV 4 | SIF 5 | LOC 6 | LIF 7 | 8 | MAIN_SRV 9 | MAIN_SIF 10 | MAIN_LOC 11 | MAIN_LIF 12 | SRV_LOC 13 | SRV_LIF 14 | SIF_LOC 15 | SIF_LIF 16 | 17 | MAIN_SRV_LOC 18 | MAIN_SRV_LIF 19 | MAIN_SIF_LOC 20 | MAIN_SIF_LIF 21 | ANY_MAIN 22 | 23 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | 2 | 2010 (C) Marcus Clyne 3 | 4 | 5 | Examples 6 | -------- 7 | 8 | In this section there are a number of examples of the various features of the tools 9 | module. These have been given in the form of dummy modules, to make it easier to 10 | use as templates for your own module should you choose to do so. 11 | 12 | 13 | -------------------------------------------------------------------------------- /auto/src/palloc.h: -------------------------------------------------------------------------------- 1 | 2 | #define %2%_pallocp(p,pl) p = %1%_palloc (pl,sizeof(*p)) 3 | #define %2%_pallocpn(p,pl,n) p = %1%_palloc (pl,sizeof(*p)*(n)) 4 | 5 | #define %2%_pcallocp(p,pl) p = %1%_pcalloc (pl,sizeof(*p)) 6 | #define %2%_pcallocpn(p,pl,n) p = %1%_pcalloc (pl,sizeof(*p)*(n)) 7 | -------------------------------------------------------------------------------- /auto/text/autogen: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | * 5 | * DO NOT EDIT THIS FILE MANUALLY 6 | * ------------------------------ 7 | * This file has been generated automatically from scripts in the $base/auto dir and 8 | * data in the $base/auto/data dir. If you wish to edit the output of this file, then 9 | * you should edit these files instead. 10 | * 11 | */ 12 | 13 | -------------------------------------------------------------------------------- /auto/data/action_types: -------------------------------------------------------------------------------- 1 | r0 return 0 2 | r1 return 1 3 | r_1 return -1 4 | rok return %OK% 5 | rce return %CE% 6 | rcok return %COK% 7 | re return %E% 8 | rn return NULL 9 | rse {ngx_script_error (e); return;} 10 | sce {ngx_script_configure_error (c); return;} 11 | g(_lb) goto _lb 12 | ge goto error 13 | -------------------------------------------------------------------------------- /src/ndk_regex.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | char * ndk_conf_set_regex_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 4 | char * ndk_conf_set_regex_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 5 | char * ndk_conf_set_regex_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 6 | char * ndk_conf_set_regex_array_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 7 | 8 | -------------------------------------------------------------------------------- /auto/actions/palloc: -------------------------------------------------------------------------------- 1 | 2 | palloc (p,pl,sz) p = %1%_palloc (pl,sz); if (p == NULL) %A% 3 | pallocp (p,pl) %2%_pallocp (p,pl); if (p == NULL) %A% 4 | pallocpn (p,pl,n) %2%_pallocpn (p,pl,n); if (p == NULL) %A% 5 | pcalloc (p,pl,sz) p = %1%_pcalloc (pl,sz); if (p == NULL) %A% 6 | pcallocp (p,pl) %2%_pcallocp (p,pl); if (p == NULL) %A% 7 | pcallocpn (p,pl,n) %2%_pcallocpn (p,pl,n); if (p == NULL) %A% 8 | 9 | -------------------------------------------------------------------------------- /auto/src/array.h: -------------------------------------------------------------------------------- 1 | 2 | #define %2%_array_count(a) ((a)->nelts) 3 | #define %2%_array_get_first(a) ((a)->elts) 4 | #define %2%_array_get_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * n)) 5 | #define %2%_array_get_last(a) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1))) 6 | #define %2%_array_get_reverse_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1 - n))) 7 | #define %2%_array_push_clean(p,a) {p = %1%_array_push (a); %2%_zerop (p);} 8 | -------------------------------------------------------------------------------- /src/ndk_process.c: -------------------------------------------------------------------------------- 1 | 2 | ngx_int_t 3 | ndk_init_signals (ngx_signal_t *sig, ngx_log_t *log) 4 | { 5 | struct sigaction sa; 6 | 7 | for ( ; sig->signo != 0; sig++) { 8 | ndk_zerov (sa); 9 | sa.sa_handler = sig->handler; 10 | sigemptyset (&sa.sa_mask); 11 | 12 | if (sigaction (sig->signo, &sa, NULL) == -1) { 13 | ngx_log_error (NGX_LOG_EMERG, log, ngx_errno, 14 | "sigaction(%s) failed", sig->signame); 15 | return NGX_ERROR; 16 | } 17 | } 18 | 19 | return NGX_OK; 20 | } 21 | -------------------------------------------------------------------------------- /auto/actions/array: -------------------------------------------------------------------------------- 1 | 2 | array_create (a,pl,n,sz) a = %1%_array_create (pl,n,sz); if (a == NULL) %A% 3 | array_init (a,pl,n,sz) if (%1%_array_init (a,pl,n,sz) == %E%) %A% 4 | array_push (p,a) p = %1%_array_push (a); if (p == NULL) %A% 5 | array_push_clean (p,a) p = %1%_array_push (a); if (p == NULL) %A%; %2%_zerop (p) 6 | array_push_n (p,a,n) p = %1%_array_push_n (a,n); if (p == NULL) %A% 7 | array_push_n_clean (p,a,n) p = %1%_array_push_n (a,n); if (p == NULL) %A%; %2%_zeropn (p,n) 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /patches/auto_config: -------------------------------------------------------------------------------- 1 | diff -pNr a/src/core/ngx_config.h b/src/core/ngx_config.h 2 | *** a/src/core/ngx_config.h 2008-09-19 13:47:13.000000000 +0100 3 | --- b/src/core/ngx_config.h 2010-10-09 17:14:13.000000000 +0100 4 | *************** typedef intptr_t ngx_flag_t; 5 | *** 127,131 **** 6 | #define NGX_MAX_UINT32_VALUE (uint32_t) 0xffffffff 7 | #endif 8 | 9 | ! 10 | #endif /* _NGX_CONFIG_H_INCLUDED_ */ 11 | --- 127,131 ---- 12 | #define NGX_MAX_UINT32_VALUE (uint32_t) 0xffffffff 13 | #endif 14 | 15 | ! #include 16 | #endif /* _NGX_CONFIG_H_INCLUDED_ */ 17 | -------------------------------------------------------------------------------- /src/ndk_upstream_list.h: -------------------------------------------------------------------------------- 1 | 2 | #if (NDK_UPSTREAM_LIST_CMDS) 3 | 4 | /* TODO : use the generated commands */ 5 | 6 | { 7 | ngx_string ("upstream_list"), 8 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_2MORE, 9 | ndk_upstream_list, 10 | 0, 11 | 0, 12 | NULL 13 | }, 14 | 15 | #else 16 | 17 | typedef struct { 18 | ngx_str_t **elts; 19 | ngx_uint_t nelts; 20 | ngx_str_t name; 21 | } ndk_upstream_list_t; 22 | 23 | 24 | ndk_upstream_list_t * 25 | ndk_get_upstream_list (ndk_http_main_conf_t *mcf, u_char *data, size_t len); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/ndk_string_util.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #define ndk_str_init(ns,s) {(ns).data = (u_char*) s; (ns).len = sizeof (s) - 1;} 4 | #define ndk_strp_init(ns,s) {(ns)->data = (u_char*) s; (ns)->len = sizeof (s) - 1;} 5 | 6 | #define ndk_zero(p,sz) memset (p,'\0',sz) 7 | #define ndk_zerop(p) ndk_zero (p,sizeof(*p)) 8 | #define ndk_zeropn(p,n) ndk_zero (p,sizeof(*p)*(n)) 9 | #define ndk_zerov(v) ndk_zero (&v,sizeof(v)) 10 | 11 | #define ngx_null_enum { ngx_null_string, 0 } 12 | 13 | #define ndk_memcpyp(d,s) ngx_memcpy(d,s,sizeof(*s)) 14 | 15 | -------------------------------------------------------------------------------- /patches/rewrite_phase_handler: -------------------------------------------------------------------------------- 1 | diff -p -r a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c 2 | *** a/src/http/ngx_http_core_module.c 2010-09-27 12:48:12.000000000 +0100 3 | --- b/src/http/ngx_http_core_module.c 2010-10-09 13:44:09.000000000 +0100 4 | *************** ngx_http_core_rewrite_phase(ngx_http_req 5 | *** 910,915 **** 6 | --- 910,922 ---- 7 | return NGX_AGAIN; 8 | } 9 | 10 | + #if defined(nginx_version) && nginx_version >= 8042 && (NDK_REWRITE_PHASE) 11 | + 12 | + if (rc == NGX_AGAIN || rc == NGX_DONE) { 13 | + return NGX_OK; 14 | + } 15 | + 16 | + #endif 17 | /* rc == NGX_OK || rc == NGX_ERROR || rc == NGX_HTTP_... */ 18 | 19 | ngx_http_finalize_request(r, rc); 20 | -------------------------------------------------------------------------------- /notes/CHANGES: -------------------------------------------------------------------------------- 1 | Changelog 2 | --------- 3 | 4 | 0.1 feature : set_var functions 5 | 0.1.1 feature : upstream_list directive and functions 6 | 0.2 feature : conf merge functions 7 | feature : conf command macros 8 | feature : 'action' macros 9 | 0.2.1 bugfix : ndk_map_uri_to_path_add_suffix 10 | 0.2.2 feature : regex conf functions 11 | 0.2.3 feature : version number 12 | 0.2.4 change : the auto/build script is now executed automatically on compilation 13 | 0.2.9 feature : ngx_auto_lib included with source 14 | 0.2.11 bugfix : hash functions did not display properly 15 | 0.2.12 feature : patches for rewrite functions and rewrite phase handler 16 | 0.2.13 change : revert to old behaviour rewrite functions 17 | change : pre-generated config and macro files now provided -------------------------------------------------------------------------------- /src/ndk_complex_value.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | typedef struct { 4 | ngx_str_t key; 5 | ngx_http_complex_value_t value; 6 | } ndk_http_complex_keyval_t; 7 | 8 | 9 | 10 | /* create/compile functions */ 11 | 12 | ngx_int_t ndk_http_complex_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value); 13 | ngx_array_t * ndk_http_complex_value_array_create (ngx_conf_t *cf, char **s, ngx_int_t n); 14 | ngx_int_t ndk_http_complex_value_array_compile (ngx_conf_t *cf, ngx_array_t *a); 15 | 16 | 17 | /* conf set slot functions */ 18 | 19 | char * ndk_conf_set_http_complex_keyval_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 20 | char * ndk_conf_set_http_complex_value_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 21 | char * ndk_conf_set_http_complex_value_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 22 | -------------------------------------------------------------------------------- /src/ndk_rewrite.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* TODO : should remove this when not needed */ 4 | 5 | 6 | 7 | /* used for plugging into the rewrite module (taken from the rewrite module) */ 8 | 9 | typedef struct { 10 | ngx_array_t *codes; /* uintptr_t */ 11 | ngx_uint_t stack_size; 12 | ngx_flag_t log; 13 | ngx_flag_t uninitialized_variable_warn; 14 | } ndk_http_rewrite_loc_conf_t; 15 | 16 | 17 | extern ngx_module_t ngx_http_rewrite_module; 18 | extern uintptr_t ndk_http_script_exit_code; 19 | 20 | char * ndk_http_rewrite_value (ngx_conf_t *cf, ndk_http_rewrite_loc_conf_t *lcf, 21 | ngx_str_t *value); 22 | ngx_int_t ndk_http_rewrite_var (ngx_http_request_t *r, 23 | ngx_http_variable_value_t *v, uintptr_t data); 24 | 25 | #define ndk_http_script_exit (u_char *) &ndk_http_script_exit_code 26 | 27 | -------------------------------------------------------------------------------- /src/ndk_path.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* path conversion functions */ 4 | 5 | void ndk_clean_path (ngx_str_t *path, ngx_uint_t complex, size_t off); 6 | void ndk_path_to_dir_safe (ngx_str_t *path, ngx_uint_t complex, size_t off); 7 | 8 | /* path create functions */ 9 | 10 | ngx_array_t * ndk_split_path_create (ngx_conf_t *cf, ngx_str_t *path); 11 | ngx_array_t * ndk_split_path_create_raw (ngx_conf_t *cf, char *path); 12 | 13 | /* conf set functions */ 14 | 15 | char * ndk_conf_set_full_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 16 | char * ndk_conf_set_split_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 17 | 18 | /* conf set post functions */ 19 | 20 | char * ndk_conf_set_full_path (ngx_conf_t *cf, void *data, ngx_str_t *path); 21 | char * ndk_conf_set_full_conf_path (ngx_conf_t *cf, void *data, ngx_str_t *path); 22 | 23 | -------------------------------------------------------------------------------- /src/ndk_buf.c: -------------------------------------------------------------------------------- 1 | 2 | ngx_int_t 3 | ndk_copy_chain_to_str (ngx_pool_t *pool, ngx_chain_t *in, ngx_str_t *str) 4 | { 5 | ngx_chain_t *cl; 6 | size_t len; 7 | u_char *p; 8 | ngx_buf_t *b; 9 | 10 | len = 0; 11 | for (cl = in; cl; cl = cl->next) 12 | len += ngx_buf_size (cl->buf); 13 | 14 | ndk_palloc_re (p, pool, len + 1); 15 | 16 | str->data = p; 17 | str->len = len; 18 | 19 | for (cl = in; cl; cl = cl->next) { 20 | 21 | b = cl->buf; 22 | 23 | if (ngx_buf_in_memory (b)) { 24 | p = ngx_cpymem (p, b->pos, b->last - b->pos); 25 | } 26 | } 27 | 28 | *p = '\0'; 29 | 30 | return NGX_OK; 31 | } 32 | 33 | 34 | char * 35 | ndk_copy_chain_to_charp (ngx_pool_t *pool, ngx_chain_t *in) 36 | { 37 | ngx_str_t str; 38 | 39 | if (ndk_copy_chain_to_str (pool, in, &str) != NGX_OK) 40 | return NULL; 41 | 42 | return (char *) str.data; 43 | } -------------------------------------------------------------------------------- /src/ndk_uri.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* TODO : check that this is correct */ 4 | 5 | u_char * 6 | ndk_map_uri_to_path_add_suffix (ngx_http_request_t *r, ngx_str_t *path, ngx_str_t *suffix, ngx_int_t dot) 7 | { 8 | size_t root_size; 9 | u_char *p; 10 | 11 | if (suffix->len) { 12 | 13 | if (dot) { 14 | 15 | p = ngx_http_map_uri_to_path (r, path, &root_size, suffix->len + 1); 16 | 17 | if (p == NULL) 18 | return NULL; 19 | 20 | *p = '.'; 21 | p++; 22 | 23 | } else { 24 | 25 | p = ngx_http_map_uri_to_path (r, path, &root_size, suffix->len); 26 | 27 | if (p == NULL) 28 | return NULL; 29 | } 30 | 31 | path->len--; 32 | 33 | p = ngx_cpymem (p, suffix->data, suffix->len); 34 | *p = '\0'; 35 | 36 | return p; 37 | } 38 | 39 | p = ngx_http_map_uri_to_path (r, path, &root_size, 0); 40 | 41 | path->len--; 42 | 43 | return p; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/ndk.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | */ 5 | 6 | 7 | #ifndef NDK_H 8 | #define NDK_H 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | #define ndk_version 3004 17 | #define NDK_VERSION "0.3.4" 18 | 19 | 20 | #if (NGX_DEBUG) 21 | #ifndef NDK_DEBUG 22 | #define NDK_DEBUG 1 23 | #endif 24 | #else 25 | #ifndef NDK_DEBUG 26 | #define NDK_DEBUG 0 27 | #endif 28 | #endif 29 | 30 | 31 | #include 32 | 33 | 34 | #if (NDK_HTTP_CREATE_MAIN_CONF) 35 | 36 | #define ndk_http_conf_get_main_conf(cf) ngx_http_conf_get_module_main_conf (cf, ndk_http_module) 37 | #define ndk_http_get_main_conf(r) ngx_http_get_module_main_conf (r, ndk_http_module) 38 | 39 | typedef struct { 40 | #if (NDK_UPSTREAM_LIST) 41 | ngx_array_t *upstreams; 42 | #endif 43 | } ndk_http_main_conf_t; 44 | 45 | #endif /* NDK_HTTP_CREATE_MAIN_CONF */ 46 | 47 | #include 48 | 49 | 50 | extern ngx_module_t ndk_http_module; 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/ndk_hash.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef NDK_HASH_H 3 | #define NDK_HASH_H 4 | 5 | #ifdef NDK_HASH_ALL 6 | 7 | #ifndef NDK_MD5 8 | #define NDK_MD5 9 | #endif 10 | 11 | #ifndef NDK_MURMUR2 12 | #define NDK_MURMUR2 13 | #endif 14 | 15 | #ifndef NDK_SHA1 16 | #define NDK_SHA1 17 | #endif 18 | 19 | #endif 20 | 21 | #include 22 | #include 23 | typedef void (*ndk_hash_pt) (u_char *p, char *data, size_t len); 24 | 25 | 26 | #ifdef NDK_MD5 27 | #include 28 | void ndk_md5_hash (u_char *p, char *data, size_t len); 29 | void ndk_md5_hash_upper (u_char *p, char *data, size_t len); 30 | #endif 31 | 32 | #ifdef NDK_MURMUR2 33 | #define MURMURHASH2_DIGEST_LENGTH 4 34 | void ndk_murmur2_hash (u_char *p, char *data, size_t len); 35 | void ndk_murmur2_hash_upper (u_char *p, char *data, size_t len); 36 | #endif 37 | 38 | #ifdef NDK_SHA1 39 | #include 40 | void ndk_sha1_hash (u_char *p, char *data, size_t len); 41 | void ndk_sha1_hash_upper (u_char *p, char *data, size_t len); 42 | #endif 43 | 44 | #endif /* NDK_HASH_H */ 45 | 46 | -------------------------------------------------------------------------------- /auto/data/conf_locs: -------------------------------------------------------------------------------- 1 | 2 | HTTP_MAIN HTTP_MAIN main 3 | HTTP_SRV HTTP_SRV srv 4 | HTTP_SIF HTTP_SRV srv 5 | HTTP_LOC HTTP_LOC loc 6 | HTTP_LIF HTTP_LOC loc 7 | 8 | HTTP_MAIN_SRV HTTP_SRV srv 9 | HTTP_MAIN_SIF HTTP_SRV srv 10 | HTTP_MAIN_LOC HTTP_LOC loc 11 | HTTP_MAIN_LIF HTTP_LOC loc 12 | 13 | HTTP_SRV_LOC HTTP_LOC loc 14 | HTTP_SRV_LIF HTTP_LOC loc 15 | HTTP_SIF_LOC HTTP_LOC loc 16 | HTTP_SIF_LIF HTTP_LOC loc 17 | 18 | HTTP_MAIN_SRV_LOC HTTP_LOC loc 19 | HTTP_MAIN_SRV_LIF HTTP_LOC loc 20 | HTTP_MAIN_SIF_LOC HTTP_LOC loc 21 | HTTP_MAIN_SRV_SIF_LOC HTTP_LOC loc 22 | HTTP HTTP_LOC loc 23 | HTTP_UPS HTTP_LOC loc 24 | HTTP_ANY HTTP_LOC loc 25 | ANY HTTP_LOC loc 26 | -------------------------------------------------------------------------------- /src/ndk_complex_path.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | typedef struct { 4 | ngx_array_t *a; 5 | ngx_uint_t prefix; 6 | } ndk_http_complex_path_t; 7 | 8 | typedef struct { 9 | ngx_http_complex_value_t val; 10 | ngx_flag_t dynamic; 11 | } ndk_http_complex_path_elt_t; 12 | 13 | typedef struct { 14 | ngx_str_t val; 15 | ngx_flag_t dynamic; 16 | } ndk_http_complex_path_value_t; 17 | 18 | typedef struct { 19 | ndk_http_complex_path_value_t *elts; 20 | ngx_uint_t nelts; 21 | } ndk_http_complex_path_values_t; 22 | 23 | 24 | extern ndk_http_complex_path_value_t ndk_empty_http_complex_path_value; 25 | 26 | 27 | ngx_array_t * ndk_http_complex_path_create_compile (ngx_conf_t *cf, ngx_str_t *path, ngx_uint_t prefix); 28 | ngx_int_t ndk_http_complex_path_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, 29 | ngx_str_t *value, ngx_uint_t prefix); 30 | char * ndk_conf_set_http_complex_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 31 | -------------------------------------------------------------------------------- /src/ndk_string.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if 1 4 | /* TODO : set ndk_hex_dump for older versions of Nginx */ 5 | #define ndk_hex_dump ngx_hex_dump 6 | #endif 7 | 8 | typedef struct { 9 | size_t len; 10 | u_char *data; 11 | ngx_flag_t escaped; 12 | } ndk_estr_t; 13 | 14 | int64_t ndk_atoi64 (u_char *line, size_t n); 15 | 16 | ngx_int_t ndk_strcntc (ngx_str_t *s, char c); 17 | ngx_int_t ndk_strccnt (char *s, char c); 18 | ngx_array_t * ndk_str_array_create (ngx_pool_t *pool, char **s, ngx_int_t n); 19 | u_char * ndk_catstrf (ngx_pool_t *pool, ngx_str_t *dest, const char *fmt, ...); 20 | ngx_int_t ndk_cmpstr (ngx_str_t *s1, ngx_str_t *s2); 21 | u_char * ndk_dupstr (ngx_pool_t *pool, ngx_str_t *dest, ngx_str_t *src); 22 | 23 | static ngx_inline void 24 | ndk_strtoupper (u_char *p, size_t len) 25 | { 26 | u_char *e = p + len; 27 | for ( ; poffset); 15 | if (ep->from && ep->to) 16 | return "is duplicate"; 17 | 18 | value = cf->args->elts; 19 | 20 | 21 | if (ep->from) { 22 | 23 | ep->to = (char *) value[1].data; 24 | len = strlen (ep->from); 25 | 26 | } else if (ep->to) { 27 | 28 | ep->from = (char *) value[1].data; 29 | len = strlen (ep->to); 30 | 31 | } else { 32 | return "has no base encoding"; 33 | } 34 | 35 | 36 | if (len == value[1].len && !strncasecmp (ep->to, ep->from, len)) { 37 | 38 | ngx_log_error (NGX_LOG_WARN, cf->log, 0, 39 | "\"%V\" '%V' encoding is ignored (no conversion)", &value[0], &value[1]); 40 | 41 | return NGX_CONF_OK; 42 | } 43 | 44 | 45 | ic = iconv_open (ep->to, ep->from); 46 | if (ic == (iconv_t)-1) 47 | return "has an invalid encoding"; 48 | 49 | 50 | if (iconv_close (ic)) { 51 | ngx_log_error (NGX_LOG_EMERG, cf->log, errno, "iconv_close()"); 52 | return NGX_CONF_ERROR; 53 | } 54 | 55 | return NGX_CONF_OK; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /objs/ndk_includes.h: -------------------------------------------------------------------------------- 1 | /* optional includes */ 2 | 3 | #if (NDK_BUF) 4 | #include 5 | #endif 6 | #if (NDK_COMPLEX_PATH) 7 | #include 8 | #endif 9 | #if (NDK_COMPLEX_VALUE) 10 | #include 11 | #endif 12 | #if (NDK_CONF_FILE) 13 | #include 14 | #endif 15 | #if (NDK_ENCODING) 16 | #include 17 | #endif 18 | #if (NDK_HASH) 19 | #include 20 | #endif 21 | #if (NDK_HTTP) 22 | #include 23 | #endif 24 | #if (NDK_PATH) 25 | #include 26 | #endif 27 | #if (NDK_PROCESS) 28 | #include 29 | #endif 30 | #if (NDK_REGEX) 31 | #include 32 | #endif 33 | #if (NDK_REWRITE) 34 | #include 35 | #endif 36 | #if (NDK_SET_VAR) 37 | #include 38 | #endif 39 | #if (NDK_STRING) 40 | #include 41 | #endif 42 | #if (NDK_UPSTREAM_LIST) 43 | #include 44 | #endif 45 | #if (NDK_URI) 46 | #include 47 | #endif 48 | 49 | 50 | /* non-optional includes */ 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | 58 | /* auto-generated headers */ 59 | 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | 66 | 67 | -------------------------------------------------------------------------------- /auto/data/conf_macros: -------------------------------------------------------------------------------- 1 | 2 | BITMASK 1MORE bitmask 3 | BUFS TAKE1 bufs 4 | COMPLEX_KEYVAL TAKE2 http_complex_keyval 5 | COMPLEX_PATH TAKE1 http_complex_path 6 | COMPLEX_VALUE TAKE1 http_complex_value 7 | COMPLEX_VALUE_ARRAY 1MORE http_complex_value_array 8 | ENCODING TAKE1 encoding 9 | ENUM TAKE1 enum 10 | FALSE NOARGS false 11 | FULL_PATH TAKE1 full_path 12 | KEYVAL TAKE2 keyval 13 | KEYVAL1 TAKE2 keyval1 14 | MSEC TAKE1 msec 15 | NULL NOARGS null 16 | NUM TAKE1 num 17 | NUM64 TAKE1 num64 18 | NUM_FLAG TAKE1 num_flag 19 | ONOFF FLAG flag 20 | OFF TAKE1 off 21 | PATH TAKE1 split_path 22 | REXEX TAKE1 regex 23 | REGEX_CL TAKE1 regex_caseless 24 | REGEX_ARRAY 1MORE regex_array 25 | REGEX_ARRAY_CL 1MORE regex_array_caseless 26 | PTR NOARGS ptr 27 | SEC TAKE1 sec 28 | SEC_FLAG TAKE2 sec_flag 29 | SIZE TAKE1 size 30 | STR TAKE1 str 31 | STR_ARRAY 1MORE str_array_multi 32 | STR_ARRAY1 TAKE1 str_array 33 | TRUE NOARGS true 34 | 35 | 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2018, Marcus Clyne 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 | -------------------------------------------------------------------------------- /notes/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Marcus Clyne, Simpl (simpl.it) 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the organization (Simpl) nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL MARCUS CLYNE OR SIMPL BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /objs/ndk_config.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | * 5 | * DO NOT EDIT THIS FILE MANUALLY 6 | * ------------------------------ 7 | * This file has been generated automatically from scripts in the $base/auto dir and 8 | * data in the $base/auto/data dir. If you wish to edit the output of this file, then 9 | * you should edit these files instead. 10 | * 11 | */ 12 | 13 | 14 | /* optional includes */ 15 | 16 | #if (NDK_BUF) 17 | #include 18 | #endif 19 | #if (NDK_COMPLEX_PATH) 20 | #include 21 | #endif 22 | #if (NDK_COMPLEX_VALUE) 23 | #include 24 | #endif 25 | #if (NDK_CONF_FILE) 26 | #include 27 | #endif 28 | #if (NDK_ENCODING) 29 | #include 30 | #endif 31 | #if (NDK_HASH) 32 | #include 33 | #endif 34 | #if (NDK_HTTP) 35 | #include 36 | #endif 37 | #if (NDK_PATH) 38 | #include 39 | #endif 40 | #if (NDK_PROCESS) 41 | #include 42 | #endif 43 | #if (NDK_REGEX) 44 | #include 45 | #endif 46 | #if (NDK_REWRITE) 47 | #include 48 | #endif 49 | #if (NDK_SET_VAR) 50 | #include 51 | #endif 52 | #if (NDK_STRING) 53 | #include 54 | #endif 55 | #if (NDK_UPSTREAM_LIST) 56 | #include 57 | #endif 58 | #if (NDK_URI) 59 | #include 60 | #endif 61 | 62 | 63 | /* module commands */ 64 | 65 | static ngx_command_t ndk_http_commands[] = { 66 | #if (NDK_UPSTREAM_LIST) 67 | #define NDK_UPSTREAM_LIST_CMDS 1 68 | #include 69 | #undef NDK_UPSTREAM_LIST_CMDS 70 | #endif 71 | ngx_null_command 72 | }; 73 | -------------------------------------------------------------------------------- /src/ndk_debug.c: -------------------------------------------------------------------------------- 1 | 2 | #if (NGX_DEBUG) 3 | 4 | void 5 | ndk_debug_helper (const char *func, const char *fmt, ...) 6 | { 7 | size_t len, flen, tlen; 8 | char *s, *p, *e; 9 | 10 | /* check to see if the format is empty */ 11 | 12 | flen = strlen (fmt); 13 | 14 | /* build func name */ 15 | 16 | len = strlen (func); 17 | 18 | if (flen == 0) 19 | tlen = len + 1; 20 | else 21 | 22 | char func_name [len + flen + 1]; 23 | 24 | s = func_name; 25 | e = s + len; 26 | 27 | memcpy (s, func, len); 28 | 29 | /* remove initial ngx_ */ 30 | 31 | if (strncmp (s, "ngx_", 4) == 0) 32 | s += 4; 33 | 34 | /* replace '_' with ' ' */ 35 | 36 | for (p=s; pmethod_name.len, r->method_name.data, 55 | (int) r->uri.len, r->uri.data, 56 | (int) r->args.len, r->args.data, 57 | 0/*(int) r->main->count*/, r->main, 58 | r, r->connection->data, r->parent); 59 | 60 | if (r->posted_requests) { 61 | fprintf(stderr, " posted:"); 62 | 63 | for (pr = r->posted_requests; pr; pr = pr->next) { 64 | fprintf (stderr, "%p,", pr); 65 | } 66 | } 67 | 68 | fprintf (stderr, "\n"); 69 | } 70 | 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/ndk_set_var.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 2010 (C) Marcus Clyne 3 | */ 4 | 5 | #ifndef _NDK_SET_VAR_H_INCLUDED_ 6 | #define _NDK_SET_VAR_H_INCLUDED_ 7 | 8 | 9 | typedef ngx_int_t (*ndk_set_var_pt) (ngx_http_request_t *r, ngx_str_t *val); 10 | typedef ngx_int_t (*ndk_set_var_data_pt) (ngx_http_request_t *r, ngx_str_t *val, void *data); 11 | typedef ngx_int_t (*ndk_set_var_value_pt) (ngx_http_request_t *r, ngx_str_t *val, ngx_http_variable_value_t *v); 12 | typedef ngx_int_t (*ndk_set_var_value_data_pt) (ngx_http_request_t *r, ngx_str_t *val, ngx_http_variable_value_t *v, void *data); 13 | typedef void (*ndk_set_var_hash_pt) (u_char *p, char *data, size_t len); 14 | 15 | 16 | typedef struct { 17 | ngx_uint_t type; 18 | void *func; 19 | size_t size; 20 | void *data; 21 | } ndk_set_var_t; 22 | 23 | 24 | enum { 25 | NDK_SET_VAR_BASIC = 0, 26 | NDK_SET_VAR_DATA, 27 | NDK_SET_VAR_VALUE, 28 | NDK_SET_VAR_VALUE_DATA, 29 | NDK_SET_VAR_MULTI_VALUE, 30 | NDK_SET_VAR_MULTI_VALUE_DATA, 31 | NDK_SET_VAR_HASH 32 | }; 33 | 34 | 35 | char * ndk_set_var (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 36 | char * ndk_set_var_value (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 37 | char * ndk_set_var_multi_value (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 38 | 39 | 40 | char * ndk_set_var_core (ngx_conf_t *cf, ngx_str_t *name, ndk_set_var_t *filter); 41 | char * ndk_set_var_value_core (ngx_conf_t *cf, ngx_str_t *name, ngx_str_t *value, ndk_set_var_t *filter); 42 | char * ndk_set_var_multi_value_core (ngx_conf_t *cf, ngx_str_t *name, ngx_str_t *value, ndk_set_var_t *filter); 43 | 44 | #endif /* _NDK_SET_VAR_H_INCLUDED_ */ 45 | -------------------------------------------------------------------------------- /docs/core/conf_cmds: -------------------------------------------------------------------------------- 1 | 2 | Conf command macros 3 | ------------------- 4 | 5 | The build script generates a large number of macros for reducing the code required for command 6 | definitions. 7 | 8 | There are basically three types of macros : 9 | 10 | - combination bitmasks 11 | 12 | e.g. NDK_HTTP_MAIN_SRV_CONF = (NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF) 13 | 14 | - base command structures 15 | 16 | e.g. NDK_HTTP_MAIN_CONF_TAKE1 17 | 18 | - conf-set command structures 19 | 20 | e.g. NDK_HTTP_CONF_STR 21 | 22 | 23 | Combination bitmasks 24 | -------------------- 25 | 26 | Basically combinations of existing bitmasks for locations, with general > specific order 27 | 28 | NDK_HTTP_CONF = (NGX_HTTP_MAIN_CONF | NGX_HTTP_SVR_CONF | NGX_HTTP_SIF_CONF | NGX_HTTP_LOC_CONF | NGX_HTTP_LIF_CONF) 29 | 30 | 31 | Base command structures 32 | ----------------------- 33 | 34 | These macros are basically there as wrappers for the conf-set command structures, and but incorporate 35 | the bitmask element into the name of the macro. 36 | 37 | 38 | Conf-set command structures 39 | --------------------------- 40 | 41 | These macros simplify creating commands that use any of the build-in conf-set functions or any of those 42 | added by the NDK. 43 | 44 | e.g. NGX_HTTP_MAIN_SRV_STR ("name", prop, NULL) 45 | 46 | where prop is the name of the property that is a ngx_str_t. Whether this is in the loc conf, main conf 47 | or svr conf is generated automatically in by the macro. 48 | 49 | NOTE : you need to set the following if they will be used (using macro definitions) : 50 | 51 | ndk_module_main_conf_t 52 | ndk_module_srv_conf_t 53 | ndk_module_loc_conf_t 54 | 55 | e.g 56 | 57 | #define ndk_module_loc_conf_t ngx_http_my_module_loc_conf_t 58 | 59 | 60 | TODO 61 | ---- 62 | Much better documentation for this 63 | -------------------------------------------------------------------------------- /src/hash/murmurhash2.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef MURMURHASH2_C 4 | #define MURMURHASH2_C 5 | 6 | #define MURMURHASH2_DIGEST_LENGTH 4 7 | 8 | /* 9 | * ----------------------------------------------------------------------------- 10 | * MurmurHash2, by Austin Appleby 11 | 12 | * Note - This code makes a few assumptions about how your machine behaves - 13 | 14 | * 1. We can read a 4-byte value from any address without crashing 15 | * 2. sizeof(int) == 4 16 | 17 | * And it has a few limitations - 18 | 19 | * 1. It will not work incrementally. 20 | * 2. It will not produce the same results on little-endian and big-endian 21 | * machines. 22 | */ 23 | 24 | unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed ) 25 | { 26 | /* 27 | * 'm' and 'r' are mixing constants generated offline. 28 | * They're not really 'magic', they just happen to work well. 29 | */ 30 | 31 | const unsigned int m = 0x5bd1e995; 32 | const int r = 24; 33 | 34 | /* Initialize the hash to a 'random' value */ 35 | 36 | unsigned int h = seed ^ len; 37 | 38 | /* Mix 4 bytes at a time into the hash */ 39 | 40 | const unsigned char * data = (const unsigned char *)key; 41 | 42 | while(len >= 4) 43 | { 44 | unsigned int k = *(unsigned int *)data; 45 | 46 | k *= m; 47 | k ^= k >> r; 48 | k *= m; 49 | 50 | h *= m; 51 | h ^= k; 52 | 53 | data += 4; 54 | len -= 4; 55 | } 56 | 57 | /* Handle the last few bytes of the input array */ 58 | 59 | switch(len) 60 | { 61 | case 3: h ^= data[2] << 16; 62 | case 2: h ^= data[1] << 8; 63 | case 1: h ^= data[0]; 64 | h *= m; 65 | }; 66 | 67 | /* Do a few final mixes of the hash to ensure the last few 68 | * bytes are well-incorporated. */ 69 | 70 | h ^= h >> 13; 71 | h *= m; 72 | h ^= h >> 15; 73 | 74 | return h; 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /objs/ndk_config.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | * 5 | * DO NOT EDIT THIS FILE MANUALLY 6 | * ------------------------------ 7 | * This file has been generated automatically from scripts in the $base/auto dir and 8 | * data in the $base/auto/data dir. If you wish to edit the output of this file, then 9 | * you should edit these files instead. 10 | * 11 | */ 12 | 13 | 14 | /* include all optional modules */ 15 | 16 | #ifdef NDK_ALL 17 | 18 | #ifndef NDK_BUF 19 | #define NDK_BUF 1 20 | #endif 21 | #ifndef NDK_COMPLEX_PATH 22 | #define NDK_COMPLEX_PATH 1 23 | #endif 24 | #ifndef NDK_COMPLEX_VALUE 25 | #define NDK_COMPLEX_VALUE 1 26 | #endif 27 | #ifndef NDK_CONF_FILE 28 | #define NDK_CONF_FILE 1 29 | #endif 30 | #ifndef NDK_ENCODING 31 | #define NDK_ENCODING 1 32 | #endif 33 | #ifndef NDK_HASH 34 | #define NDK_HASH 1 35 | #endif 36 | #ifndef NDK_HTTP 37 | #define NDK_HTTP 1 38 | #endif 39 | #ifndef NDK_PATH 40 | #define NDK_PATH 1 41 | #endif 42 | #ifndef NDK_PROCESS 43 | #define NDK_PROCESS 1 44 | #endif 45 | #ifndef NDK_REGEX 46 | #define NDK_REGEX 1 47 | #endif 48 | #ifndef NDK_REWRITE 49 | #define NDK_REWRITE 1 50 | #endif 51 | #ifndef NDK_SET_VAR 52 | #define NDK_SET_VAR 1 53 | #endif 54 | #ifndef NDK_STRING 55 | #define NDK_STRING 1 56 | #endif 57 | #ifndef NDK_UPSTREAM_LIST 58 | #define NDK_UPSTREAM_LIST 1 59 | #endif 60 | #ifndef NDK_URI 61 | #define NDK_URI 1 62 | #endif 63 | 64 | #endif 65 | 66 | 67 | /* module dependencies */ 68 | 69 | #ifdef NDK_COMPLEX_PATH 70 | #ifndef NDK_COMPLEX_VALUE 71 | #define NDK_COMPLEX_VALUE 1 72 | #endif 73 | #ifndef NDK_PATH 74 | #define NDK_PATH 1 75 | #endif 76 | #endif 77 | #ifdef NDK_CONF_FILE 78 | #ifndef NDK_STRING 79 | #define NDK_STRING 1 80 | #endif 81 | #endif 82 | #ifdef NDK_HASH 83 | #ifndef NDK_STRING 84 | #define NDK_STRING 1 85 | #endif 86 | #endif 87 | #ifdef NDK_SET_VAR 88 | #ifndef NDK_REWRITE 89 | #define NDK_REWRITE 1 90 | #endif 91 | #endif 92 | #ifdef NDK_UPSTREAM_LIST 93 | #ifndef NDK_HTTP_CREATE_MAIN_CONF 94 | #define NDK_HTTP_CREATE_MAIN_CONF 1 95 | #endif 96 | #endif 97 | 98 | 99 | -------------------------------------------------------------------------------- /config: -------------------------------------------------------------------------------- 1 | 2 | ############### 3 | ## FUNCTIONS ## 4 | ############### 5 | 6 | # TODO : provide information about checking versions of sed etc 7 | # TODO : an optional patch function 8 | 9 | ndk_generate_files() { 10 | echo "building Nginx Development Kit utility functions and macros ..." 11 | 12 | autobuild="$ngx_addon_dir/auto/build" 13 | chmod +x $autobuild 14 | $autobuild `pwd` $NGX_OBJS/addon/ndk || exit 1 15 | } 16 | 17 | ndk_get_nginx_version() { 18 | # We get the Nginx version number from the string form rather than 19 | # nginx_version because it is available in more (every?) version 20 | 21 | cat src/core/nginx.h | 22 | grep '#define NGINX_VERSION' | 23 | sed -r \ 24 | -e 's/[^0-9.]*([0-9.]+).*/\1/' \ 25 | -e 's/([0-9]+\.[0-9]+\.)([0-9]{1})$/\100\2/' \ 26 | -e 's/([0-9]+\.[0-9]+\.)([0-9]{2})$/\10\2/' \ 27 | -e 's/\.//g' \ 28 | -e 's/^0+(.*)/\1/' 29 | } 30 | 31 | ##################### 32 | ## CONFIG SETTINGS ## 33 | ##################### 34 | 35 | ngx_addon_name=ngx_devel_kit 36 | ngx_objs_dirs="$ngx_addon_dir/objs $NGX_OBJS/addon/ndk" 37 | 38 | NDK_SRCS="$ngx_addon_dir/src/ndk.c" 39 | NDK_DEPS="$ngx_addon_dir/src/ndk.h" 40 | NDK_INCS="$ngx_addon_dir/src $ngx_objs_dirs" 41 | 42 | CORE_INCS="$CORE_INCS $ngx_objs_dirs" 43 | HTTP_INCS="$HTTP_INCS $ngx_addon_dir/src $ngx_objs_dir" 44 | 45 | if test -n "$ngx_module_link"; then 46 | ngx_module_type=HTTP 47 | ngx_module_name="ndk_http_module" 48 | ngx_module_srcs="$NDK_SRCS" 49 | ngx_module_deps="$NDK_DEPS" 50 | ngx_module_incs="$NDK_INCS" 51 | 52 | . auto/module 53 | else 54 | HTTP_MODULES="$HTTP_MODULES ndk_http_module" 55 | NGX_ADDON_SRCS="$NGX_ADDON_SRCS $NDK_SRCS" 56 | NGX_ADDON_DEPS="$NGX_ADDON_SRCS $NDK_DEPS" 57 | fi 58 | 59 | have=NDK . auto/have 60 | 61 | ############## 62 | ## INCLUDES ## 63 | ############## 64 | 65 | . $ngx_addon_dir/ngx_auto_lib_core 66 | -------------------------------------------------------------------------------- /src/ndk_hash.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | 6 | /* openssl hashes */ 7 | 8 | #define NDK_OPENSSL_HASH(type,ctxt_type,upper) \ 9 | u_char md [ctxt_type ## _DIGEST_LENGTH]; \ 10 | ctxt_type ##_CTX c; \ 11 | \ 12 | type ## _Init (&c); \ 13 | type ## _Update (&c, data, len); \ 14 | type ## _Final (md, &c); \ 15 | \ 16 | ndk_hex_dump (p, (u_char *) md, ctxt_type ## _DIGEST_LENGTH); \ 17 | if (upper) { \ 18 | ndk_strtoupper (p, (ctxt_type ## _DIGEST_LENGTH) *2); \ 19 | } 20 | 21 | 22 | #ifdef NDK_MD5 23 | 24 | void 25 | ndk_md5_hash (u_char *p, char *data, size_t len) 26 | { 27 | NDK_OPENSSL_HASH (MD5, MD5, 0); 28 | } 29 | 30 | void 31 | ndk_md5_hash_upper (u_char *p, char *data, size_t len) 32 | { 33 | NDK_OPENSSL_HASH (MD5, MD5, 1); 34 | } 35 | 36 | #endif 37 | #ifdef NDK_SHA1 38 | 39 | void 40 | ndk_sha1_hash (u_char *p, char *data, size_t len) 41 | { 42 | NDK_OPENSSL_HASH (SHA1, SHA, 0); 43 | } 44 | 45 | void 46 | ndk_sha1_hash_upper (u_char *p, char *data, size_t len) 47 | { 48 | NDK_OPENSSL_HASH (SHA1, SHA, 1); 49 | } 50 | 51 | #endif 52 | 53 | 54 | 55 | /* non-openssl hashes */ 56 | 57 | #ifdef NDK_MURMUR2 58 | 59 | #include "hash/murmurhash2.c" 60 | 61 | void 62 | ndk_murmur2_hash (u_char *p, char *data, size_t len) 63 | { 64 | uint32_t hash; 65 | 66 | hash = MurmurHash2 (data, len, 47); 67 | 68 | ndk_hex_dump (p, (u_char*) &hash, 4); 69 | } 70 | 71 | void 72 | ndk_murmur2_hash_upper (u_char *p, char *data, size_t len) 73 | { 74 | uint32_t hash; 75 | 76 | hash = MurmurHash2 (data, len, 47); 77 | 78 | ndk_hex_dump (p, (u_char*) &hash, 4); 79 | ndk_strtoupper (p, 8); 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/ndk_conf_file.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* conf set functions */ 4 | 5 | char * ndk_conf_set_true_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 6 | char * ndk_conf_set_false_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 7 | char * ndk_conf_set_full_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 8 | char * ndk_conf_set_ptr_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 9 | char * ndk_conf_set_null_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 10 | char * ndk_conf_set_str_array_multi_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 11 | char * ndk_conf_set_keyval1_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 12 | char * ndk_conf_set_num_flag (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 13 | char * ndk_conf_set_num64_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 14 | char * ndk_conf_set_sec_flag_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 15 | 16 | ngx_http_conf_ctx_t * ndk_conf_create_http_location (ngx_conf_t *cf); 17 | ngx_http_conf_ctx_t * ngx_conf_create_http_named_location (ngx_conf_t *cf, ngx_str_t *name); 18 | 19 | ngx_int_t ndk_replace_command (ngx_command_t *new_cmd, ngx_uint_t module_type); 20 | 21 | 22 | /* values for conf_set_xxx_flag */ 23 | 24 | #define NDK_CONF_SET_TRUE -2 25 | #define NDK_CONF_SET_FALSE -3 26 | 27 | 28 | /* wrappers for utility macros */ 29 | 30 | #define ndk_conf_set_bitmask_slot ngx_conf_set_bitmask_slot 31 | #define ndk_conf_set_bufs_slot ngx_conf_set_bufs_slot 32 | #define ndk_conf_set_enum_slot ngx_conf_set_enum_slot 33 | #define ndk_conf_set_flag_slot ngx_conf_set_flag_slot 34 | #define ndk_conf_set_keyval_slot ngx_conf_set_keyval_slot 35 | #define ndk_conf_set_msec_slot ngx_conf_set_msec_slot 36 | #define ndk_conf_set_num_slot ngx_conf_set_num_slot 37 | #define ndk_conf_set_off_slot ngx_conf_set_off_slot 38 | #define ndk_conf_set_sec_slot ngx_conf_set_sec_slot 39 | #define ndk_conf_set_size_slot ngx_conf_set_size_slot 40 | #define ndk_conf_set_str_slot ngx_conf_set_str_slot 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/ndk_http_headers.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* TODO : organize and add */ 4 | /* TODO : check - should it be r->main? */ 5 | 6 | #define ndk_http_uri(r) (r)->uri 7 | #define ndk_http_request_uri(r) (r)->unparsed_uri 8 | 9 | #define ndk_http_header_in(r,name) ((r)->headers_in.name ? &(r)->headers_in.name->value : NULL) 10 | #define ndk_http_header_out(r,name) ((r)->headers_out.name ? &(r)->headers_out.name->value : NULL) 11 | 12 | #define ndk_http_host_header(r) ndk_http_header_in (r, host) 13 | #define ndk_http_connection_header(r) ndk_http_header_in (r, connection) 14 | #define ndk_http_if_modified_since_header(r) ndk_http_header_in (r, if_modified_since) 15 | #define ndk_http_user_agent_header(r) ndk_http_header_in (r, user_agent) 16 | #define ndk_http_referer_header(r) ndk_http_header_in (r, referer) 17 | #define ndk_http_content_length_header(r) ndk_http_header_in (r, content_length) 18 | #define ndk_http_content_type_header(r) ndk_http_header_in (r, content_type) 19 | #define ndk_http_range_header(r) ndk_http_header_in (r, range) 20 | #define ndk_http_if_range_header(r) ndk_http_header_in (r, if_range) 21 | #define ndk_http_transfer_encoding_header(r) ndk_http_header_in (r, transfer_encoding) 22 | #define ndk_http_expect_header(r) ndk_http_header_in (r, expect) 23 | #define ndk_http_accept_encoding_header(r) ndk_http_header_in (r, accept_encoding) 24 | #define ndk_http_via_header(r) ndk_http_header_in (r, via) 25 | #define ndk_http_authorization_header(r) ndk_http_header_in (r, authorization) 26 | #define ndk_http_keep_alive_header(r) ndk_http_header_in (r, keep_alive) 27 | #define ndk_http_x_forwarded_for_header(r) ndk_http_header_in (r, x_forwarded_for) 28 | #define ndk_http_x_real_ip_header(r) ndk_http_header_in (r, x_real_ip) 29 | #define ndk_http_accept_header(r) ndk_http_header_in (r, accept) 30 | #define ndk_http_accept_language_header(r) ndk_http_header_in (r, accept_language) 31 | #define ndk_http_depth_header(r) ndk_http_header_in (r, depth) 32 | #define ndk_http_destination_header(r) ndk_http_header_in (r, destination) 33 | #define ndk_http_overwrite_header(r) ndk_http_header_in (r, overwrite) 34 | #define ndk_http_date_header(r) ndk_http_header_in (r, date) 35 | 36 | -------------------------------------------------------------------------------- /auto/src/conf_cmd_basic.h: -------------------------------------------------------------------------------- 1 | 2 | /* TODO : finish this */ 3 | 4 | #define NDK_HTTP_MAIN_CONF NGX_HTTP_MAIN_CONF 5 | #define NDK_HTTP_SRV_CONF NGX_HTTP_SRV_CONF 6 | #define NDK_HTTP_SIF_CONF NGX_HTTP_SIF_CONF 7 | #define NDK_HTTP_LOC_CONF NGX_HTTP_LOC_CONF 8 | #define NDK_HTTP_LIF_CONF NGX_HTTP_LIF_CONF 9 | #define NDK_HTTP_UPS_CONF NGX_HTTP_UPS_CONF 10 | #define NDK_MAIN_CONF NGX_MAIN_CONF 11 | #define NDK_ANY_CONF NGX_ANY_CONF 12 | 13 | 14 | /* compound locations */ 15 | 16 | #define NDK_HTTP_MAIN_SRV_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SRV_CONF 17 | #define NDK_HTTP_MAIN_SIF_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SRV_SIF_CONF 18 | #define NDK_HTTP_MAIN_LOC_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_LOC_CONF 19 | #define NDK_HTTP_MAIN_LIF_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_LOC_LIF_CONF 20 | 21 | #define NDK_HTTP_SRV_SIF_CONF NDK_HTTP_SRV_CONF|NDK_HTTP_SIF_CONF 22 | #define NDK_HTTP_SRV_LOC_CONF NDK_HTTP_SRV_CONF|NDK_HTTP_LOC_CONF 23 | #define NDK_HTTP_SRV_LOC_LIF_CONF NDK_HTTP_SRV_CONF|NDK_HTTP_LOC_LIF_CONF 24 | #define NDK_HTTP_SRV_SIF_LOC_CONF NDK_HTTP_SRV_SIF_CONF|NDK_HTTP_LOC_CONF 25 | #define NDK_HTTP_SRV_SIF_LOC_LIF_CONF NDK_HTTP_SRV_SIF_CONF|NDK_HTTP_LOC_LIF_CONF 26 | 27 | #define NDK_HTTP_LOC_LIF_CONF NDK_HTTP_LOC_CONF|NDK_HTTP_LIF_CONF 28 | 29 | #define NDK_HTTP_MAIN_SRV_LOC_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SRV_LOC_CONF 30 | #define NDK_HTTP_MAIN_SRV_LIF_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SRV_LIF_CONF 31 | #define NDK_HTTP_MAIN_SIF_LOC_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SIF_LOC_CONF 32 | #define NDK_HTTP_MAIN_SRV_SIF_LOC_LIF_CONF NDK_HTTP_SRV_SIF_LOC_LIF_CONF|NDK_MAIN_CONF 33 | #define NDK_HTTP_CONF NDK_HTTP_MAIN_SRV_SIF_LOC_LIF_CONF 34 | #define NDK_HTTP_ANY_CONF NDK_HTTP_CONF|NDK_HTTP_UPS_CONF 35 | 36 | 37 | /* property offsets NOTE : ngx_module_main_conf_t etc should be defined in the module's .c file before the commands */ 38 | 39 | #define NDK_HTTP_MAIN_CONF_PROP(p) NGX_HTTP_MAIN_CONF_OFFSET, offsetof (ndk_module_main_conf_t, p) 40 | #define NDK_HTTP_SRV_CONF_PROP(p) NGX_HTTP_SRV_CONF_OFFSET, offsetof (ndk_module_srv_conf_t, p) 41 | #define NDK_HTTP_LOC_CONF_PROP(p) NGX_HTTP_LOC_CONF_OFFSET, offsetof (ndk_module_loc_conf_t, p) 42 | 43 | 44 | -------------------------------------------------------------------------------- /docs/core/action_macros: -------------------------------------------------------------------------------- 1 | 2 | GENERAL NOTES 3 | ------------- 4 | 5 | These functions and macros have been provided as a tool for Nginx module developers. They have 6 | been created with four main purposes: 7 | 8 | - to speed up code-writing 9 | - to reduce the code you have to read on file 10 | - to add additional generic functionality similar to exising Nginx functions 11 | - to reduce code errors 12 | 13 | Most of the utility macros are just wrappers around commonly used code, especially checking for 14 | NULL and returning a value, zeroing data etc. The functions add things like extra conf_set_X_slot 15 | functions that don't exist in the standard Nginx distribution, but which might be useful in more 16 | than one module. 17 | 18 | A consistent approach has been taken to creating the macros, so that in theory you should be able 19 | to 'know' the macro name from using the few rules below and your knowledge of the existing Nginx 20 | functions. As much as possible, the ordering of variables used within the underlying functions 21 | remain the same, to reduce the learning time. Also, a constent naming pattern has been used to 22 | make it easier to read the macros above. 23 | 24 | Obviously not all programmers will want to use all or any of these macros, but they are provided 25 | as a tool for those who wish to use them. 26 | 27 | If you have any comments about them, including any additions or errors please let me know at 28 | 'eugaia at gmail dot com'. I don't promise to include all additions people send, but if they seem 29 | like they could be of use to multiple developers, I will. 30 | 31 | 32 | UTILITY MACRO PARAMS 33 | -------------------- 34 | p pointer - used to set the result of a function to a pointer 35 | a array 36 | pl pool 37 | n multiplication factor - for allocating multiple pointers & pushing 'n' elts in arrays etc 38 | sz size 39 | l log 40 | rv return value 41 | 42 | 43 | 44 | UTILITY MACRO FUNCTION SUFFIXES 45 | ------------------------------- 46 | 47 | - general 48 | 49 | p p = [FUNCTION] () 50 | _r [ if result of function is NULL | NGX_ERROR (as appropriate) ] return rv 51 | _rce rv = NGX_CONF_ERROR 52 | _re rv = NGX_ERROR 53 | _rn rv = NULL 54 | 55 | - (p)(c)alloc functions 56 | 57 | p p = [function] (pool, sizeof (*p)) 58 | pn p = [function] (pool, sizeof (*p) * n) 59 | 60 | 61 | UTILITY MACRO PARAMS ORDER 62 | -------------------------- 63 | p, pl|a, sz|n, l, rv 64 | -------------------------------------------------------------------------------- /docs/patches/more_logging_info: -------------------------------------------------------------------------------- 1 | When tracking down some potential issues in the nginx constellation, 2 | we've found it useful to understand where particular error messages 3 | are coming from, since many of the same messages are repeated in 4 | various places. This patch will write the source file from which the 5 | message originated, the function name, and the line number if you're 6 | using GCC to compile nginx. Here's an example: 7 | 8 | Old Output: 9 | 2010/01/12 14:43:10 [notice] 67772#0: nginx/0.7.64 10 | 2010/01/12 14:43:10 [notice] 67772#0: built by gcc 4.0.1 (Apple Inc. build 5490) 11 | 2010/01/12 14:43:10 [notice] 67772#0: OS: Darwin 9.8.0 12 | 2010/01/12 14:43:10 [notice] 67772#0: hw.ncpu: 2 13 | 2010/01/12 14:43:10 [notice] 67772#0: net.inet.tcp.sendspace: 65536 14 | 2010/01/12 14:43:10 [notice] 67772#0: kern.ipc.somaxconn: 128 15 | 2010/01/12 14:43:10 [notice] 67772#0: getrlimit(RLIMIT_NOFILE): 16 | 256:9223372036854775807 17 | 2010/01/12 14:43:10 [notice] 67772#0: start worker processes 18 | 2010/01/12 14:43:10 [notice] 67772#0: start worker process 67785 19 | 2010/01/12 14:43:16 [notice] 67772#0: signal 20 (SIGCHLD) received 20 | 21 | New Output: 22 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_posix_init.c 23 | ngx_os_status( 80) nginx/0.7.64 24 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_posix_init.c 25 | ngx_os_status( 83) built by gcc 4.0.1 (Apple Inc. build 5490) 26 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_darwin_init.c 27 | ngx_os_specific_status( 153) OS: Darwin 9.8.0 28 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_darwin_init.c 29 | ngx_os_specific_status( 166) hw.ncpu: 2 30 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_darwin_init.c 31 | ngx_os_specific_status( 166) net.inet.tcp.sendspace: 65536 32 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_darwin_init.c 33 | ngx_os_specific_status( 166) kern.ipc.somaxconn: 128 34 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_posix_init.c 35 | ngx_os_status( 92) getrlimit(RLIMIT_NOFILE): 36 | 2560:9223372036854775807 37 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_process_cycle.c 38 | ngx_start_worker_processes( 337) start worker processes 39 | 2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_process.c 40 | ngx_spawn_process( 201) start worker process 27254 41 | 2010/01/14 16:35:14 [notice] 27241#0: src/os/unix/ngx_process.c 42 | ngx_signal_handler( 420) signal 20 (SIGCHLD) received 43 | 44 | Formatting the filename and function name fields into fixed-width 45 | fields would be nicer, however that would require further changes in 46 | src/core/ngx_string.c 47 | 48 | (C) Brian Moran - bmoran@onehub.com (posted to nginx-devel mailing list on 15/01/10) 49 | -------------------------------------------------------------------------------- /src/ndk_complex_path.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | ndk_http_complex_path_value_t ndk_empty_http_complex_path_value = {{0,NULL},0}; 4 | 5 | 6 | ngx_int_t 7 | ndk_http_complex_path_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value, ngx_uint_t prefix) 8 | { 9 | ngx_http_compile_complex_value_t ccv; 10 | 11 | ngx_memzero (&ccv, sizeof(ngx_http_compile_complex_value_t)); 12 | 13 | ccv.cf = cf; 14 | ccv.value = value; 15 | ccv.complex_value = cv; 16 | 17 | switch (prefix) { 18 | 19 | case 1 : 20 | ccv.root_prefix = 1; 21 | break; 22 | 23 | case 2 : 24 | ccv.conf_prefix = 1; 25 | break; 26 | } 27 | 28 | ndk_path_to_dir_safe (value, 1, 0); 29 | 30 | if (!value->len) 31 | return NGX_OK; 32 | 33 | return ngx_http_compile_complex_value (&ccv); 34 | } 35 | 36 | 37 | 38 | ngx_array_t * 39 | ndk_http_complex_path_create_compile (ngx_conf_t *cf, ngx_str_t *path, ngx_uint_t prefix) 40 | { 41 | ndk_http_complex_path_elt_t *cpe; 42 | ngx_array_t *a; 43 | ngx_int_t n; 44 | u_char *m, *s, *e; 45 | ngx_str_t value; 46 | 47 | n = ndk_strcntc (path, ':') + 1; 48 | 49 | a = ngx_array_create (cf->pool, n, sizeof (ndk_http_complex_path_elt_t)); 50 | if (a == NULL) { 51 | return NULL; 52 | } 53 | 54 | s = path->data; 55 | e = s + path->len; 56 | 57 | 58 | while (s < e) { 59 | 60 | m = s; 61 | 62 | while (m < e && *m != ':') m++; 63 | 64 | if (m == s) { 65 | s = m+1; 66 | continue; 67 | } 68 | 69 | cpe = ngx_array_push (a); 70 | if (cpe == NULL) { 71 | return NULL; 72 | } 73 | 74 | if (*s == '#') { 75 | s++; 76 | cpe->dynamic = 1; 77 | } else { 78 | cpe->dynamic = 0; 79 | } 80 | 81 | value.data = s; 82 | value.len = m - s; 83 | 84 | if (ndk_http_complex_path_value_compile (cf, &cpe->val, &value, prefix) == NGX_ERROR) 85 | return NULL; 86 | 87 | s = m+1; 88 | } 89 | 90 | return a; 91 | } 92 | 93 | 94 | 95 | 96 | char * 97 | ndk_conf_set_http_complex_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 98 | { 99 | char *p = conf; 100 | 101 | ngx_str_t *path; 102 | ngx_conf_post_t *post; 103 | ndk_http_complex_path_t *cp; 104 | 105 | cp = (ndk_http_complex_path_t *) (p + cmd->offset); 106 | 107 | if (cp->a != NGX_CONF_UNSET_PTR) { 108 | return "is duplicate"; 109 | } 110 | 111 | path = cf->args->elts; 112 | path++; 113 | 114 | cp->a = ndk_http_complex_path_create_compile (cf, path, cp->prefix); 115 | if (cp->a == NULL) { 116 | /* TODO : log */ 117 | return NGX_CONF_ERROR; 118 | } 119 | 120 | if (cmd->post) { 121 | post = cmd->post; 122 | return post->post_handler (cf, post, cp->a); 123 | } 124 | 125 | return NGX_CONF_OK; 126 | } 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /src/ndk_rewrite.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* these have been taken from the rewrite module and http_script file 4 | * because those functions are defined as being static - a patch will 5 | * be provided later to un-define them as being static 6 | */ 7 | 8 | 9 | uintptr_t ndk_http_script_exit_code = (uintptr_t) NULL; 10 | 11 | 12 | char * 13 | ndk_http_rewrite_value (ngx_conf_t *cf, ndk_http_rewrite_loc_conf_t *lcf, 14 | ngx_str_t *value) 15 | { 16 | ngx_int_t n; 17 | ngx_http_script_compile_t sc; 18 | ngx_http_script_value_code_t *val; 19 | ngx_http_script_complex_value_code_t *complex; 20 | 21 | n = ngx_http_script_variables_count(value); 22 | 23 | if (n == 0) { 24 | val = ngx_http_script_start_code(cf->pool, &lcf->codes, 25 | sizeof(ngx_http_script_value_code_t)); 26 | if (val == NULL) { 27 | return NGX_CONF_ERROR; 28 | } 29 | 30 | n = ngx_atoi(value->data, value->len); 31 | 32 | if (n == NGX_ERROR) { 33 | n = 0; 34 | } 35 | 36 | val->code = ngx_http_script_value_code; 37 | val->value = (uintptr_t) n; 38 | val->text_len = (uintptr_t) value->len; 39 | val->text_data = (uintptr_t) value->data; 40 | 41 | return NGX_CONF_OK; 42 | } 43 | 44 | complex = ngx_http_script_start_code(cf->pool, &lcf->codes, 45 | sizeof(ngx_http_script_complex_value_code_t)); 46 | if (complex == NULL) { 47 | return NGX_CONF_ERROR; 48 | } 49 | 50 | complex->code = ngx_http_script_complex_value_code; 51 | complex->lengths = NULL; 52 | 53 | ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); 54 | 55 | sc.cf = cf; 56 | sc.source = value; 57 | sc.lengths = &complex->lengths; 58 | sc.values = &lcf->codes; 59 | sc.variables = n; 60 | sc.complete_lengths = 1; 61 | 62 | if (ngx_http_script_compile(&sc) != NGX_OK) { 63 | return NGX_CONF_ERROR; 64 | } 65 | 66 | return NGX_CONF_OK; 67 | } 68 | 69 | 70 | ngx_int_t 71 | ndk_http_rewrite_var (ngx_http_request_t *r, ngx_http_variable_value_t *v, 72 | uintptr_t data) 73 | { 74 | ngx_http_variable_t *var; 75 | ngx_http_core_main_conf_t *cmcf; 76 | ndk_http_rewrite_loc_conf_t *rlcf; 77 | 78 | rlcf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module); 79 | 80 | if (rlcf->uninitialized_variable_warn == 0) { 81 | *v = ngx_http_variable_null_value; 82 | return NGX_OK; 83 | } 84 | 85 | cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); 86 | 87 | var = cmcf->variables.elts; 88 | 89 | /* 90 | * the ngx_http_rewrite_module sets variables directly in r->variables, 91 | * and they should be handled by ngx_http_get_indexed_variable(), 92 | * so the handler is called only if the variable is not initialized 93 | */ 94 | 95 | ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, 96 | "using uninitialized \"%V\" variable", &var[data].name); 97 | 98 | *v = ngx_http_variable_null_value; 99 | 100 | return NGX_OK; 101 | } 102 | 103 | 104 | -------------------------------------------------------------------------------- /src/ndk_parse.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED) 5 | 6 | #define ndk_str3_cmp(m, c0, c1, c2, c3) \ 7 | *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) 8 | 9 | #define ndk_str3Ocmp(m, c0, c1, c2, c3) \ 10 | *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) 11 | 12 | #define ndk_str4cmp(m, c0, c1, c2, c3) \ 13 | *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) 14 | 15 | #define ndk_str5cmp(m, c0, c1, c2, c3, c4) \ 16 | *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \ 17 | && m[4] == c4 18 | 19 | #define ndk_str6cmp(m, c0, c1, c2, c3, c4, c5) \ 20 | *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \ 21 | && (((uint32_t *) m)[1] & 0xffff) == ((c5 << 8) | c4) 22 | 23 | #define ndk_str7_cmp(m, c0, c1, c2, c3, c4, c5, c6, c7) \ 24 | *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \ 25 | && ((uint32_t *) m)[1] == ((c7 << 24) | (c6 << 16) | (c5 << 8) | c4) 26 | 27 | #define ndk_str8cmp(m, c0, c1, c2, c3, c4, c5, c6, c7) \ 28 | *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \ 29 | && ((uint32_t *) m)[1] == ((c7 << 24) | (c6 << 16) | (c5 << 8) | c4) 30 | 31 | #define ndk_str9cmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8) \ 32 | *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \ 33 | && ((uint32_t *) m)[1] == ((c7 << 24) | (c6 << 16) | (c5 << 8) | c4) \ 34 | && m[8] == c8 35 | 36 | #else /* !(NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED) */ 37 | 38 | #define ndk_str3_cmp(m, c0, c1, c2, c3) \ 39 | m[0] == c0 && m[1] == c1 && m[2] == c2 40 | 41 | #define ndk_str3Ocmp(m, c0, c1, c2, c3) \ 42 | m[0] == c0 && m[2] == c2 && m[3] == c3 43 | 44 | #define ndk_str4cmp(m, c0, c1, c2, c3) \ 45 | m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 46 | 47 | #define ndk_str5cmp(m, c0, c1, c2, c3, c4) \ 48 | m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 && m[4] == c4 49 | 50 | #define ndk_str6cmp(m, c0, c1, c2, c3, c4, c5) \ 51 | m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \ 52 | && m[4] == c4 && m[5] == c5 53 | 54 | #define ndk_str7_cmp(m, c0, c1, c2, c3, c4, c5, c6, c7) \ 55 | m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \ 56 | && m[4] == c4 && m[5] == c5 && m[6] == c6 57 | 58 | #define ndk_str8cmp(m, c0, c1, c2, c3, c4, c5, c6, c7) \ 59 | m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \ 60 | && m[4] == c4 && m[5] == c5 && m[6] == c6 && m[7] == c7 61 | 62 | #define ndk_str9cmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8) \ 63 | m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \ 64 | && m[4] == c4 && m[5] == c5 && m[6] == c6 && m[7] == c7 && m[8] == c8 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /src/ndk_http.c: -------------------------------------------------------------------------------- 1 | 2 | ngx_uint_t 3 | ndk_http_count_phase_handlers (ngx_http_core_main_conf_t *cmcf) 4 | { 5 | ngx_http_phase_handler_t *ph; 6 | ngx_uint_t i; 7 | 8 | ph = cmcf->phase_engine.handlers; 9 | 10 | for (i=0; ph[i].checker; i++) /* void */; 11 | 12 | return i; 13 | } 14 | 15 | 16 | ngx_uint_t 17 | ndk_http_parse_request_method (ngx_str_t *m) 18 | { 19 | switch (m->len) { 20 | 21 | case 3: 22 | 23 | #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED) 24 | { 25 | u_char t[4]; 26 | 27 | ngx_memcpy (t, m->data, 3); 28 | t[3] = ' '; 29 | 30 | if (ndk_str3_cmp (t, 'G', 'E', 'T', ' ')) { 31 | return NGX_HTTP_GET; 32 | } 33 | 34 | if (ndk_str3_cmp (t, 'P', 'U', 'T', ' ')) { 35 | return NGX_HTTP_PUT; 36 | } 37 | } 38 | 39 | #else 40 | 41 | if (ndk_str3_cmp (m->data, 'G', 'E', 'T', ' ')) { 42 | return NGX_HTTP_GET; 43 | } 44 | 45 | if (ndk_str3_cmp (m->data, 'P', 'U', 'T', ' ')) { 46 | return NGX_HTTP_PUT; 47 | } 48 | 49 | #endif 50 | break; 51 | 52 | case 4: 53 | 54 | if (m->data[1] == 'O') { 55 | 56 | if (ndk_str3Ocmp (m->data, 'P', 'O', 'S', 'T')) { 57 | return NGX_HTTP_POST; 58 | } 59 | 60 | if (ndk_str3Ocmp (m->data, 'C', 'O', 'P', 'Y')) { 61 | return NGX_HTTP_COPY; 62 | } 63 | 64 | if (ndk_str3Ocmp (m->data, 'M', 'O', 'V', 'E')) { 65 | return NGX_HTTP_MOVE; 66 | } 67 | 68 | if (ndk_str3Ocmp (m->data, 'L', 'O', 'C', 'K')) { 69 | return NGX_HTTP_LOCK; 70 | } 71 | 72 | } else { 73 | 74 | if (ndk_str4cmp (m->data, 'H', 'E', 'A', 'D')) { 75 | return NGX_HTTP_HEAD; 76 | } 77 | } 78 | 79 | break; 80 | 81 | case 5: 82 | 83 | if (ndk_str5cmp (m->data, 'M', 'K', 'C', 'O', 'L')) { 84 | return NGX_HTTP_MKCOL; 85 | } 86 | 87 | if (ndk_str5cmp (m->data, 'P', 'A', 'T', 'C', 'H')) { 88 | return NGX_HTTP_PATCH; 89 | } 90 | 91 | if (ndk_str5cmp (m->data, 'T', 'R', 'A', 'C', 'E')) { 92 | return NGX_HTTP_TRACE; 93 | } 94 | 95 | break; 96 | 97 | case 6: 98 | 99 | if (ndk_str6cmp (m->data, 'D', 'E', 'L', 'E', 'T', 'E')) { 100 | return NGX_HTTP_DELETE; 101 | } 102 | 103 | if (ndk_str6cmp (m->data, 'U', 'N', 'L', 'O', 'C', 'K')) { 104 | return NGX_HTTP_UNLOCK; 105 | } 106 | 107 | break; 108 | 109 | case 7: 110 | 111 | if (ndk_str7_cmp (m->data, 'O', 'P', 'T', 'I', 'O', 'N', 'S', ' ')) 112 | { 113 | return NGX_HTTP_OPTIONS; 114 | } 115 | 116 | break; 117 | 118 | case 8: 119 | 120 | if (ndk_str8cmp (m->data, 'P', 'R', 'O', 'P', 'F', 'I', 'N', 'D')) 121 | { 122 | return NGX_HTTP_PROPFIND; 123 | } 124 | 125 | break; 126 | 127 | case 9: 128 | 129 | if (ndk_str9cmp (m->data, 'P', 'R', 'O', 'P', 'P', 'A', 'T', 'C', 'H')) 130 | { 131 | return NGX_HTTP_PROPPATCH; 132 | } 133 | 134 | break; 135 | } 136 | 137 | return 0; 138 | } -------------------------------------------------------------------------------- /src/ndk.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | */ 5 | 6 | #include 7 | 8 | #include 9 | 10 | 11 | #if (NDK_HTTP_PRE_CONFIG) 12 | static ngx_int_t ndk_http_preconfiguration (ngx_conf_t *cf); 13 | #endif 14 | #if (NDK_HTTP_POST_CONFIG) 15 | static ngx_int_t ndk_http_postconfiguration (ngx_conf_t *cf); 16 | #endif 17 | #if (NDK_HTTP_CREATE_MAIN_CONF) 18 | static void * ndk_http_create_main_conf (ngx_conf_t *cf); 19 | #endif 20 | #if (NDK_HTTP_INIT_MAIN_CONF) 21 | static char * ndk_http_init_main_conf (ngx_conf_t *cf, void *conf); 22 | #endif 23 | #if (NDK_HTTP_CREATE_SRV_CONF) 24 | static void * ndk_http_create_srv_conf (ngx_conf_t *cf); 25 | #endif 26 | #if (NDK_HTTP_MERGE_SRV_CONF) 27 | static char * ndk_http_merge_srv_conf (ngx_conf_t *cf, void *parent, void *child); 28 | #endif 29 | #if (NDK_HTTP_CREATE_LOC_CONF) 30 | static void * ndk_http_create_loc_conf (ngx_conf_t *cf); 31 | #endif 32 | #if (NDK_HTTP_MERGE_LOC_CONF) 33 | static char * ndk_http_merge_loc_conf (ngx_conf_t *cf, void *parent, void *child); 34 | #endif 35 | 36 | 37 | #if (NDK_HTTP_INIT_MASTER) 38 | static ngx_int_t ndk_http_init_master (ngx_log_t *log); 39 | #endif 40 | #if (NDK_HTTP_INIT_MODULE) 41 | static ngx_int_t ndk_http_init_module (ngx_cycle_t *cycle); 42 | #endif 43 | #if (NDK_HTTP_INIT_PROCESS) 44 | static ngx_int_t ndk_http_init_process (ngx_cycle_t *cycle); 45 | #endif 46 | #if (NDK_HTTP_EXIT_PROCESS) 47 | static void ndk_http_exit_process (ngx_cycle_t *cycle); 48 | #endif 49 | #if (NDK_HTTP_EXIT_MASTER) 50 | static void ndk_http_exit_master (ngx_cycle_t *cycle); 51 | #endif 52 | 53 | 54 | ngx_http_module_t ndk_http_module_ctx = { 55 | 56 | #if (NDK_HTTP_PRE_CONFIG) 57 | ndk_http_preconfiguration, 58 | #else 59 | NULL, 60 | #endif 61 | #if (NDK_HTTP_POST_CONFIG) 62 | ndk_http_postconfiguration, 63 | #else 64 | NULL, 65 | #endif 66 | 67 | #if (NDK_HTTP_CREATE_MAIN_CONF) 68 | ndk_http_create_main_conf, 69 | #else 70 | NULL, 71 | #endif 72 | #if (NDK_HTTP_INIT_MAIN_CONF) 73 | ndk_http_merge_main_conf, 74 | #else 75 | NULL, 76 | #endif 77 | 78 | #if (NDK_HTTP_CREATE_SVR_CONF) 79 | ndk_http_create_srv_conf, 80 | #else 81 | NULL, 82 | #endif 83 | #if (NDK_HTTP_MERGE_SVR_CONF) 84 | ndk_http_merge_srv_conf, 85 | #else 86 | NULL, 87 | #endif 88 | 89 | #if (NDK_HTTP_CREATE_LOC_CONF) 90 | ndk_http_create_loc_conf, 91 | #else 92 | NULL, 93 | #endif 94 | #if (NDK_HTTP_MERGE_LOC_CONF) 95 | ndk_http_merge_loc_conf, 96 | #else 97 | NULL, 98 | #endif 99 | 100 | }; 101 | 102 | ngx_module_t ndk_http_module = { 103 | 104 | NGX_MODULE_V1, 105 | &ndk_http_module_ctx, /* module context */ 106 | ndk_http_commands, /* module directives */ 107 | NGX_HTTP_MODULE, /* module type */ 108 | 109 | #if (NDK_HTTP_INIT_MASTER) 110 | ndk_http_init_master, 111 | #else 112 | NULL, 113 | #endif 114 | 115 | #if (NDK_HTTP_INIT_MODULE) 116 | ndk_http_init_module, 117 | #else 118 | NULL, 119 | #endif 120 | #if (NDK_HTTP_INIT_PROCESS) 121 | ndk_http_init_process, 122 | #else 123 | NULL, 124 | #endif 125 | 126 | NULL, /* init thread */ 127 | NULL, /* exit thread */ 128 | 129 | #if (NDK_HTTP_EXIT_PROCESS) 130 | ndk_http_exit_process, 131 | #else 132 | NULL, 133 | #endif 134 | #if (NDK_HTTP_EXIT_MASTER) 135 | ndk_http_exit_master, 136 | #else 137 | NULL, 138 | #endif 139 | NGX_MODULE_V1_PADDING 140 | }; 141 | 142 | 143 | 144 | #if (NDK_HTTP_CREATE_MAIN_CONF) 145 | static void * 146 | ndk_http_create_main_conf (ngx_conf_t *cf) 147 | { 148 | ndk_http_main_conf_t *mcf; 149 | 150 | ndk_pcallocp_rce (mcf, cf->pool); 151 | 152 | return mcf; 153 | } 154 | #endif 155 | 156 | -------------------------------------------------------------------------------- /examples/http/set_var/ngx_http_set_var_examples_module.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | */ 5 | 6 | 7 | #include 8 | 9 | 10 | static ngx_int_t ngx_http_set_var_concat2 (ngx_http_request_t *r, ngx_str_t *val, ngx_http_variable_value_t *v); 11 | static char * ngx_http_set_prepend_hello (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 12 | 13 | 14 | static ndk_set_var_t ngx_http_var_set_concat2 = { 15 | NDK_SET_VAR_MULTI_VALUE, 16 | ngx_http_set_var_concat2, 17 | 2, 18 | NULL 19 | }; 20 | 21 | 22 | static ngx_command_t ngx_http_set_var_examples_commands[] = { 23 | { 24 | ngx_string ("set_concat2"), 25 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE3, 26 | ndk_set_var_multi_value, 27 | 0, 28 | 0, 29 | &ngx_http_var_set_concat2 30 | }, 31 | { 32 | ngx_string ("set_prepend_hello"), 33 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1, 34 | ngx_http_set_prepend_hello, 35 | 0, 36 | 0, 37 | NULL 38 | }, 39 | ngx_null_command 40 | }; 41 | 42 | 43 | ngx_http_module_t ngx_http_set_var_examples_module_ctx = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; 44 | ngx_module_t ngx_http_set_var_examples_module = { 45 | 46 | NGX_MODULE_V1, 47 | &ngx_http_set_var_examples_module_ctx, // module context 48 | ngx_http_set_var_examples_commands, // module directives 49 | NGX_HTTP_MODULE, // module type 50 | NULL, // init master 51 | NULL, // init module 52 | NULL, // init process 53 | NULL, // init thread 54 | NULL, // exit thread 55 | NULL, // exit process 56 | NULL, // exit master 57 | NGX_MODULE_V1_PADDING 58 | }; 59 | 60 | 61 | /* 62 | This function is called by both examples, takes two variable values and concatenates them 63 | to give a third string. 64 | */ 65 | 66 | static ngx_int_t 67 | ngx_http_set_var_concat2 (ngx_http_request_t *r, ngx_str_t *val, ngx_http_variable_value_t *v) 68 | { 69 | size_t len; 70 | ngx_http_variable_value_t *v2; 71 | u_char *p; 72 | 73 | v2 = v + 1; 74 | 75 | len = v->len + v2->len; 76 | 77 | /* 78 | * NDK provided abbreviation for the following code: 79 | * 80 | * p = ngx_palloc (r->pool, len); 81 | * if (p == NULL) 82 | * return NGX_ERROR; 83 | * 84 | * */ 85 | ndk_palloc_re(p, r->pool, len); 86 | 87 | val->data = p; 88 | val->len = len; 89 | 90 | ngx_memzero (p, len); 91 | 92 | p = ngx_cpymem (p, v->data, v->len); 93 | ngx_memcpy (p, v2->data, v2->len); 94 | 95 | return NGX_OK; 96 | } 97 | 98 | 99 | 100 | /* 101 | This function demonstrates using the 'core' function in a function that appends the word 102 | 'hello_' to the beginning of a variable. 103 | 104 | set $var world; 105 | set_prepend_hello $var $var; 106 | 107 | If the arguments used in the variable value filter do not all come directly from the conf 108 | file, or are not given in the order 109 | 110 | direcive $var_name val1 "val2 string $var" ... 111 | 112 | then the _core functions should be used inside the function that is called when the directive 113 | is read. 114 | */ 115 | 116 | static char * 117 | ngx_http_set_prepend_hello (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 118 | { 119 | ngx_str_t s[2], *var_name; 120 | ndk_set_var_t filter; 121 | 122 | var_name = cf->args->elts; 123 | var_name++; 124 | 125 | s[0].data = (u_char*) "hello_"; 126 | s[0].len = 6; 127 | 128 | s[1] = *(var_name + 1); 129 | 130 | filter.type = NDK_SET_VAR_MULTI_VALUE; 131 | filter.func = ngx_http_set_var_concat2; 132 | filter.size = 2; 133 | 134 | return ndk_set_var_multi_value_core (cf, var_name, (ngx_str_t *) s, &filter); 135 | } 136 | 137 | -------------------------------------------------------------------------------- /src/ndk_complex_value.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ngx_int_t 5 | ndk_http_complex_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value) 6 | { 7 | ngx_http_compile_complex_value_t ccv; 8 | 9 | ngx_memzero (&ccv, sizeof(ngx_http_compile_complex_value_t)); 10 | 11 | ccv.cf = cf; 12 | ccv.value = value; 13 | ccv.complex_value = cv; 14 | 15 | return ngx_http_compile_complex_value (&ccv); 16 | } 17 | 18 | 19 | 20 | 21 | ngx_array_t * 22 | ndk_http_complex_value_array_create (ngx_conf_t *cf, char **s, ngx_int_t n) 23 | { 24 | ngx_int_t i; 25 | ngx_http_complex_value_t *cv; 26 | ngx_array_t *a; 27 | ngx_str_t value; 28 | 29 | a = ngx_array_create (cf->pool, n, sizeof (ngx_http_complex_value_t)); 30 | if (a == NULL) 31 | return NULL; 32 | 33 | 34 | for (i=0; ielts; 61 | 62 | for (i=0; inelts; i++, cv++) { 63 | 64 | if (ndk_http_complex_value_compile (cf, cv, &cv->value)) 65 | return NGX_ERROR; 66 | } 67 | 68 | return NGX_OK; 69 | } 70 | 71 | 72 | 73 | char * 74 | ndk_conf_set_http_complex_value_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 75 | { 76 | char *p = conf; 77 | 78 | ngx_http_complex_value_t *cv; 79 | ngx_str_t *value; 80 | ngx_conf_post_t *post; 81 | 82 | cv = (ngx_http_complex_value_t *) (p + cmd->offset); 83 | 84 | if (cv->value.data) { 85 | return "is duplicate"; 86 | } 87 | 88 | value = cf->args->elts; 89 | 90 | if (ndk_http_complex_value_compile (cf, cv, value + 1)) 91 | return NGX_CONF_ERROR; 92 | 93 | if (cmd->post) { 94 | post = cmd->post; 95 | return post->post_handler (cf, post, cv); 96 | } 97 | 98 | return NGX_CONF_OK; 99 | } 100 | 101 | 102 | 103 | char * 104 | ndk_conf_set_http_complex_value_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 105 | { 106 | char *p = conf; 107 | 108 | ngx_str_t *value; 109 | ngx_http_complex_value_t *cv; 110 | ngx_array_t **a; 111 | ngx_conf_post_t *post; 112 | ngx_uint_t i, alloc; 113 | 114 | a = (ngx_array_t **) (p + cmd->offset); 115 | 116 | if (*a == NULL || *a == NGX_CONF_UNSET_PTR) { 117 | 118 | alloc = cf->args->nelts > 4 ? cf->args->nelts : 4; 119 | 120 | *a = ngx_array_create (cf->pool, alloc, sizeof (ngx_http_complex_value_t)); 121 | if (*a == NULL) { 122 | return NGX_CONF_ERROR; 123 | } 124 | } 125 | 126 | value = cf->args->elts; 127 | 128 | for (i=1; iargs->nelts; i++) { 129 | 130 | cv = ngx_array_push (*a); 131 | if (cv == NULL) { 132 | return NGX_CONF_ERROR; 133 | } 134 | 135 | if (ndk_http_complex_value_compile (cf, cv, &value[i]) == NGX_ERROR) 136 | return NGX_CONF_ERROR; 137 | } 138 | 139 | 140 | if (cmd->post) { 141 | post = cmd->post; 142 | return post->post_handler (cf, post, a); 143 | } 144 | 145 | return NGX_CONF_OK; 146 | } 147 | 148 | 149 | char * 150 | ndk_conf_set_http_complex_keyval_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 151 | { 152 | char *p = conf; 153 | 154 | ngx_str_t *value; 155 | ndk_http_complex_keyval_t *ckv; 156 | ngx_array_t **a; 157 | ngx_conf_post_t *post; 158 | ngx_int_t alloc; 159 | 160 | a = (ngx_array_t **) (p + cmd->offset); 161 | 162 | if (*a == NULL || *a == NGX_CONF_UNSET_PTR) { 163 | 164 | alloc = cf->args->nelts > 4 ? cf->args->nelts : 4; 165 | 166 | *a = ngx_array_create (cf->pool, alloc, sizeof (ndk_http_complex_keyval_t)); 167 | if (*a == NULL) { 168 | return NGX_CONF_ERROR; 169 | } 170 | } 171 | 172 | ckv = ngx_array_push (*a); 173 | if (ckv == NULL) { 174 | return NGX_CONF_ERROR; 175 | } 176 | 177 | value = cf->args->elts; 178 | 179 | ckv->key = value[1]; 180 | 181 | if (ndk_http_complex_value_compile (cf, &ckv->value, &value[2]) == NGX_ERROR) 182 | return NGX_CONF_ERROR; 183 | 184 | if (cmd->post) { 185 | post = cmd->post; 186 | return post->post_handler (cf, post, a); 187 | } 188 | 189 | return NGX_CONF_OK; 190 | } 191 | 192 | /* TODO : complex keyval1 */ 193 | -------------------------------------------------------------------------------- /src/hash/md5.h: -------------------------------------------------------------------------------- 1 | /* crypto/md5/md5.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_MD5_H 60 | #define HEADER_MD5_H 61 | 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | #ifdef OPENSSL_NO_MD5 70 | #error MD5 is disabled. 71 | #endif 72 | 73 | /* 74 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 75 | * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then ! 76 | * ! MD5_LONG_LOG2 has to be defined along. ! 77 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 78 | */ 79 | 80 | #if defined(__LP32__) 81 | #define MD5_LONG unsigned long 82 | #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 83 | #define MD5_LONG unsigned long 84 | #define MD5_LONG_LOG2 3 85 | /* 86 | * _CRAY note. I could declare short, but I have no idea what impact 87 | * does it have on performance on none-T3E machines. I could declare 88 | * int, but at least on C90 sizeof(int) can be chosen at compile time. 89 | * So I've chosen long... 90 | * 91 | */ 92 | #else 93 | #define MD5_LONG unsigned int 94 | #endif 95 | 96 | #define MD5_CBLOCK 64 97 | #define MD5_LBLOCK (MD5_CBLOCK/4) 98 | #define MD5_DIGEST_LENGTH 16 99 | 100 | typedef struct MD5state_st 101 | { 102 | MD5_LONG A,B,C,D; 103 | MD5_LONG Nl,Nh; 104 | MD5_LONG data[MD5_LBLOCK]; 105 | unsigned int num; 106 | } MD5_CTX; 107 | 108 | int MD5_Init(MD5_CTX *c); 109 | int MD5_Update(MD5_CTX *c, const void *data, size_t len); 110 | int MD5_Final(unsigned char *md, MD5_CTX *c); 111 | unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); 112 | void MD5_Transform(MD5_CTX *c, const unsigned char *b); 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /src/ndk_upstream_list.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* TODO : generalize this into a generic list module, with weight */ 4 | 5 | 6 | typedef struct { 7 | ngx_uint_t weight; 8 | ngx_str_t s; 9 | ngx_conf_t *cf; 10 | } ndk_upstream_list_parse_t; 11 | 12 | 13 | 14 | static ngx_int_t 15 | ndk_upstream_list_parse_weight (ndk_upstream_list_parse_t *ulp) 16 | { 17 | size_t i; 18 | ngx_str_t *s; 19 | 20 | s = &ulp->s; 21 | 22 | for (i=0; ilen; i++) { 23 | 24 | if (s->data[i] < '0' || s->data[i] > '9') 25 | break; 26 | } 27 | 28 | if (!i) { 29 | ulp->weight = 1; 30 | return NGX_OK; 31 | } 32 | 33 | if (i == s->len) { 34 | ngx_conf_log_error (NGX_LOG_EMERG, ulp->cf, 0, 35 | "upstream list just consists of number \"%V\"", s); 36 | 37 | return NGX_ERROR; 38 | } 39 | 40 | if (s->data[i] != ':') { 41 | ngx_conf_log_error (NGX_LOG_EMERG, ulp->cf, 0, 42 | "upstream list not correct format \"%V\"", s); 43 | 44 | return NGX_ERROR; 45 | } 46 | 47 | 48 | ulp->weight = ngx_atoi (s->data, i); 49 | 50 | s->data += (i + 1); 51 | s->len -= (i + 1); 52 | 53 | return NGX_OK; 54 | } 55 | 56 | 57 | 58 | static char * 59 | ndk_upstream_list (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 60 | { 61 | /* TODO : change this for getting upstream pointer if available */ 62 | 63 | ngx_uint_t buckets, count, i, j; 64 | ngx_str_t *value, **bucket, *us; 65 | ngx_array_t *ula; 66 | ndk_upstream_list_t *ul, *ule; 67 | ndk_upstream_list_parse_t ulp; 68 | 69 | ndk_http_main_conf_t *mcf; 70 | 71 | mcf = ngx_http_conf_get_module_main_conf (cf, ndk_http_module); 72 | 73 | ula = mcf->upstreams; 74 | 75 | /* create array of upstream lists it doesn't already exist */ 76 | 77 | if (ula == NULL) { 78 | 79 | ula = ngx_array_create (cf->pool, 4, sizeof (ndk_upstream_list_t)); 80 | if (ula == NULL) 81 | return NGX_CONF_ERROR; 82 | 83 | mcf->upstreams = ula; 84 | } 85 | 86 | 87 | /* check to see if the list already exists */ 88 | 89 | value = cf->args->elts; 90 | value++; 91 | 92 | ul = ula->elts; 93 | ule = ul + ula->nelts; 94 | 95 | for ( ; ulname.len == value->len && 98 | ngx_strncasecmp (ul->name.data, value->data, value->len) == 0) { 99 | 100 | ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, 101 | "duplicate upstream list name \"%V\"", value); 102 | 103 | return NGX_CONF_ERROR; 104 | } 105 | } 106 | 107 | 108 | /* create a new list */ 109 | 110 | ul = ngx_array_push (ula); 111 | if (ul == NULL) 112 | return NGX_CONF_ERROR; 113 | 114 | ul->name = *value; 115 | 116 | 117 | 118 | /* copy all the upstream names */ 119 | 120 | count = cf->args->nelts - 2; 121 | 122 | us = ngx_palloc (cf->pool, count * sizeof (ngx_str_t)); 123 | if (us == NULL) 124 | return NGX_CONF_ERROR; 125 | 126 | ngx_memcpy (us, value + 1, count * sizeof (ngx_str_t)); 127 | 128 | 129 | /* calculate the total number of buckets */ 130 | 131 | buckets = 0; 132 | 133 | ulp.cf = cf; 134 | 135 | for (i=0; ipool, buckets * sizeof (ngx_str_t *)); 149 | if (bucket == NULL) 150 | return NGX_CONF_ERROR; 151 | 152 | ul->elts = bucket; 153 | ul->nelts = buckets; 154 | 155 | 156 | /* set values for each bucket */ 157 | 158 | us -= count; 159 | 160 | for (i=0; idata = ulp.s.data; 168 | us->len = ulp.s.len; 169 | 170 | /* TODO : check format of upstream */ 171 | /* TODO : add automatic adding of http:// in upstreams? */ 172 | 173 | for (j=0; jupstreams; 188 | 189 | if (ua == NULL) { 190 | return NULL; 191 | } 192 | 193 | ul = ua->elts; 194 | ule = ul + ua->nelts; 195 | 196 | for (; ul < ule; ul++) { 197 | if (ul->name.len == len && ngx_strncasecmp(ul->name.data, data, len) == 0) 198 | { 199 | return ul; 200 | } 201 | } 202 | 203 | return NULL; 204 | } 205 | 206 | -------------------------------------------------------------------------------- /docs/modules/set_var: -------------------------------------------------------------------------------- 1 | 2 | set var tools 3 | ============= 4 | 5 | OVERVIEW 6 | -------- 7 | This collection of tools is designed to make it easier to set Nginx variables 8 | using a common interface. It works by plugging into and extending the features 9 | of the internal rewrite module, and operations performed by this module are 10 | therefore done at the rewrite phase of handling. 11 | 12 | 13 | ADVANTAGES OF USING THIS MODULE 14 | ------------------------------- 15 | 16 | - simple interface - you don't have to worry about lots of http script compiling 17 | - it plugs into the rewrite module, so setting (and getting) vars will happen 18 | in the order you expect based on how they appear in the configuration file 19 | - you do not have to worry about overriding the v->get_handler (useful if 20 | a variable of a specific name could be set in multiple different ways) 21 | 22 | 23 | WHEN TO USE THIS AND WHEN TO USE v->get_handler = my_func 24 | --------------------------------------------------------- 25 | 26 | - if you want a variable to always be generated using a specific function, 27 | and should not be over-ridden by 'set' functions (e.g. $request_uri, 28 | $document_root), then you should use v->get_handler 29 | 30 | - if you want to allow a variable to be set using many possible methods, 31 | including using the 'set' directive, then this module provides an easy way 32 | for you to do so (if you use the v->get_handler method in this case, you may 33 | run into problems because the get_handler may over-ride previous uses of the 34 | set directive) 35 | 36 | 37 | USAGE 38 | ----- 39 | 40 | - decide on the type of function you'll need to write 41 | 42 | type use when there are these requirements 43 | ---- ------------------------------------- 44 | NDK_SET_VAR_BASIC 0 variable values, no extra data 45 | NDK_SET_VAR_DATA 0 variable values, extra data 46 | NDK_SET_VAR_VALUE 1 variable value, no extra data 47 | NDK_SET_VAR_VALUE_DATA 1 variable value, extra data 48 | NDK_SET_VAR_MULTI_VALUE 2+ variable values, no extra data 49 | NDK_SET_VAR_MULTI_VALUE_DATA 2+ variable values, extra data 50 | NDK_SET_VAR_HASH the space needed for the result string 51 | value is known in advance (usually 52 | used in a hash function) 53 | 54 | NOTE : if none of these generic calling types suit your needs, it is 55 | easy to extend the list of types in the .c file (and you if you let me know 56 | I'll add them to the list 57 | 58 | 59 | - define the filter function with the respective prototype 60 | 61 | type prototype 62 | ---- --------- 63 | NDK_SET_VAR_BASIC ndk_set_var_pt 64 | NDK_SET_VAR_DATA ndk_set_var_data_pt 65 | NDK_SET_VAR_VALUE ndk_set_var_value_pt 66 | NDK_SET_VAR_DATA_VALUE ndk_set_var_value_data_pt 67 | NDK_SET_VAR_MULTI_VALUE ndk_set_var_value_pt 68 | NDK_SET_VAR_MULTI_VALUE_DATA ndk_set_var_value_data_pt 69 | NDK_SET_VAR_HASH ndk_set_var_hash_pt 70 | 71 | (See ngx_tools_module.h for the prototype definitions.) 72 | 73 | Note : For the multi_value functions, the variable value pointer is to the 74 | first value (with the others being in an array following it) 75 | 76 | 77 | to use one of the default setup functions 78 | ----------------------------------------- 79 | 80 | - define one or multiple ngx_http_var_filter_t's at the global scope, setting : 81 | 82 | type = (one of types above) 83 | func = function to call 84 | size = (for multi value) the number of variable values 85 | (for hash) length of buffer to allocate 86 | data = (for data functions) additional data (see note below) 87 | 88 | - define a configuration directive (see in the .c file for examples), where the 89 | function is 'ngx_http_set_var' and the 'post' is a pointer your filter definition 90 | 91 | 92 | to setup in a customized way 93 | ---------------------------- 94 | 95 | - define a configuration directive which has your own specific configuration function 96 | 97 | - inside your config function, define one or several ngx_http_var_filter_t's like 98 | above, and call one of the ngx_http_set_var_..._core functions, passing the 99 | variable name and value pointers as appropriate - see examples section 100 | 101 | Note : if you're passing extra data to the function, then you will probably want 102 | to use this second method and store the data either in the loc conf, or just 103 | allocate the space for it using one of the ngx_palloc functions. 104 | 105 | If the values that will be used for processing are in the same order as in the 106 | config file and there aren't any additional values that are input, then you can 107 | just use the (ngx_str_t *) (cf->args->elts) + 1 as your base for the values or 108 | possibly not use the _core versions of the functions. 109 | 110 | 111 | That's it! 112 | 113 | 114 | FEEDBACK 115 | -------- 116 | 117 | If you have any comments (good/bad), or have found any bugs, please let me know at: 118 | ngx.eugaia AT gmail DOT com 119 | 120 | 121 | TODO 122 | ---- 123 | - add more documentation/examples 124 | 125 | -------------------------------------------------------------------------------- /src/ndk_regex.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | char * 4 | ndk_conf_set_regex_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 5 | { 6 | char *p = conf; 7 | 8 | ngx_str_t *value; 9 | ngx_conf_post_t *post; 10 | ngx_regex_elt_t *re; 11 | ngx_regex_compile_t rc; 12 | u_char errstr[NGX_MAX_CONF_ERRSTR]; 13 | 14 | re = (ngx_regex_elt_t *) (p + cmd->offset); 15 | 16 | if (re->name) { 17 | return "is duplicate"; 18 | } 19 | 20 | value = cf->args->elts; 21 | value++; 22 | 23 | ndk_zerov (rc); 24 | 25 | rc.pool = cf->pool; 26 | rc.err.len = NGX_MAX_CONF_ERRSTR; 27 | rc.err.data = errstr; 28 | rc.pattern = *value; 29 | 30 | if (ngx_regex_compile(&rc) != NGX_OK) { 31 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err); 32 | return NGX_CONF_ERROR; 33 | } 34 | 35 | re->regex = rc.regex; 36 | re->name = value->data; 37 | 38 | if (cmd->post) { 39 | post = cmd->post; 40 | return post->post_handler (cf, post, re); 41 | } 42 | 43 | return NGX_CONF_OK; 44 | } 45 | 46 | 47 | char * 48 | ndk_conf_set_regex_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 49 | { 50 | char *p = conf; 51 | 52 | ngx_str_t *value; 53 | ngx_conf_post_t *post; 54 | ngx_regex_elt_t *re; 55 | ngx_regex_compile_t rc; 56 | u_char errstr[NGX_MAX_CONF_ERRSTR]; 57 | 58 | re = (ngx_regex_elt_t *) (p + cmd->offset); 59 | 60 | if (re->name) { 61 | return "is duplicate"; 62 | } 63 | 64 | value = cf->args->elts; 65 | value++; 66 | 67 | ndk_zerov (rc); 68 | 69 | rc.pool = cf->pool; 70 | rc.err.len = NGX_MAX_CONF_ERRSTR; 71 | rc.err.data = errstr; 72 | rc.pattern = *value; 73 | rc.options = NGX_REGEX_CASELESS; 74 | 75 | if (ngx_regex_compile(&rc) != NGX_OK) { 76 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err); 77 | return NGX_CONF_ERROR; 78 | } 79 | 80 | re->regex = rc.regex; 81 | re->name = value->data; 82 | 83 | if (cmd->post) { 84 | post = cmd->post; 85 | return post->post_handler (cf, post, re); 86 | } 87 | 88 | return NGX_CONF_OK; 89 | } 90 | 91 | 92 | 93 | char * 94 | ndk_conf_set_regex_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 95 | { 96 | char *p = conf; 97 | 98 | ngx_str_t *value; 99 | ngx_conf_post_t *post; 100 | ngx_array_t **a; 101 | ngx_regex_elt_t *re; 102 | ngx_regex_compile_t rc; 103 | ngx_uint_t i, n = 0; 104 | u_char errstr[NGX_MAX_CONF_ERRSTR]; 105 | 106 | a = (ngx_array_t **) (p + cmd->offset); 107 | 108 | if (*a != NGX_CONF_UNSET_PTR) { 109 | 110 | n = cf->args->nelts > 4 ? cf->args->nelts : 4; 111 | 112 | *a = ngx_array_create (cf->pool, n, sizeof (ngx_regex_elt_t)); 113 | if (*a == NULL) { 114 | return NGX_CONF_ERROR; 115 | } 116 | } 117 | 118 | ndk_zerov (rc); 119 | 120 | rc.pool = cf->pool; 121 | rc.err.len = NGX_MAX_CONF_ERRSTR; 122 | rc.err.data = errstr; 123 | 124 | value = cf->args->elts; 125 | value++; 126 | 127 | for (i=0; iregex = rc.regex; 141 | re->name = value->data; 142 | } 143 | 144 | 145 | if (cmd->post) { 146 | post = cmd->post; 147 | return post->post_handler (cf, post, a); 148 | } 149 | 150 | return NGX_CONF_OK; 151 | } 152 | 153 | 154 | 155 | char * 156 | ndk_conf_set_regex_array_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 157 | { 158 | char *p = conf; 159 | 160 | ngx_str_t *value; 161 | ngx_conf_post_t *post; 162 | ngx_array_t **a; 163 | ngx_regex_elt_t *re; 164 | ngx_regex_compile_t rc; 165 | ngx_uint_t i, n = 0; 166 | u_char errstr[NGX_MAX_CONF_ERRSTR]; 167 | 168 | a = (ngx_array_t **) (p + cmd->offset); 169 | 170 | if (*a != NGX_CONF_UNSET_PTR) { 171 | 172 | n = cf->args->nelts > 4 ? cf->args->nelts : 4; 173 | 174 | *a = ngx_array_create (cf->pool, n, sizeof (ngx_regex_elt_t)); 175 | if (*a == NULL) { 176 | return NGX_CONF_ERROR; 177 | } 178 | } 179 | 180 | ndk_zerov (rc); 181 | 182 | rc.pool = cf->pool; 183 | rc.err.len = NGX_MAX_CONF_ERRSTR; 184 | rc.err.data = errstr; 185 | 186 | value = cf->args->elts; 187 | value++; 188 | 189 | for (i=0; iregex = rc.regex; 204 | re->name = value->data; 205 | } 206 | 207 | 208 | if (cmd->post) { 209 | post = cmd->post; 210 | return post->post_handler (cf, post, a); 211 | } 212 | 213 | return NGX_CONF_OK; 214 | } 215 | 216 | -------------------------------------------------------------------------------- /src/ndk_debug.h: -------------------------------------------------------------------------------- 1 | #ifndef NDK_DEBUG_H 2 | #define NDK_DEBUG_H 3 | 4 | 5 | /* TODO : use the Nginx printf function */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | /* TODO 12 | - andk_debug variety of debugging formats 13 | - global include file for all debugging - can pass declaration to cflags for the option 14 | */ 15 | 16 | 17 | #if (NDK_DEBUG) 18 | 19 | #if (NGX_HAVE_VARIADIC_MACROS) 20 | 21 | #define ndk_debug(...) ndk_debug_helper (__func__,__VA_ARGS__) 22 | 23 | #define ndk_debug_helper(func,...) \ 24 | fprintf(stderr, "%-60s", func); \ 25 | fprintf(stderr, (const char *)__VA_ARGS__); \ 26 | fprintf(stderr,"\n"); 27 | /*fprintf(stderr, " at %s line %d.\n", __FILE__, __LINE__)*/ 28 | 29 | #else 30 | 31 | /* NOTE : these includes might not be necessary since they're probably included with the core */ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | static void ndk_debug (const char * fmt, ...) { 38 | } 39 | 40 | #endif 41 | 42 | #if NDK_DEBUG > 1 43 | 44 | #define ndk_debug_request() ndk_debug_request_helper(r, __func__) 45 | 46 | static ngx_inline void 47 | ndk_debug_request_helper (ngx_http_request_t *r, const char *func) 48 | { 49 | ngx_http_posted_request_t *pr; 50 | 51 | /* TODO : improve the format */ 52 | 53 | fprintf (stderr, "%s %.*s %.*s?%.*s c:%d m:%p r:%p ar:%p pr:%p", 54 | func, 55 | (int) r->method_name.len, r->method_name.data, 56 | (int) r->uri.len, r->uri.data, 57 | (int) r->args.len, r->args.data, 58 | 0/*(int) r->main->count*/, r->main, 59 | r, r->connection->data, r->parent); 60 | 61 | if (r->posted_requests) { 62 | fprintf(stderr, " posted:"); 63 | 64 | for (pr = r->posted_requests; pr; pr = pr->next) { 65 | fprintf (stderr, "%p,", pr); 66 | } 67 | } 68 | 69 | fprintf (stderr, "\n"); 70 | } 71 | 72 | 73 | #else 74 | 75 | #define ndk_debug_request() 76 | 77 | #endif 78 | 79 | 80 | static ngx_inline void 81 | ndk_debug_print_posted_requests (ngx_http_request_t *r) 82 | { 83 | ngx_http_posted_request_t *pr; 84 | 85 | ndk_request_log_debug_http (r, "ndk debug - http posted requests"); 86 | 87 | for (pr = r->main->posted_requests; pr; pr = pr->next) { 88 | 89 | if (!pr->request) 90 | continue; 91 | 92 | ndk_request_log_debug_http (r, "ndk debug - http posted request:%V", &pr->request->uri); 93 | } 94 | } 95 | 96 | 97 | #define ndk_debug_http_conf_location(cf) ndk_debug_http_conf_location_helper (cf, __func__) 98 | 99 | static ngx_inline void 100 | ndk_debug_http_conf_location_helper (ngx_conf_t *cf, const char *func) 101 | { 102 | ngx_http_core_loc_conf_t *lcf; 103 | 104 | lcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_core_module); 105 | 106 | ndk_debug_helper (func, "[%s]", lcf->name.data); 107 | } 108 | 109 | /* 110 | static void 111 | ndk_debug_log_chain (ngx_log_t *log, ngx_chain_t *cl) 112 | { 113 | 114 | 115 | } 116 | */ 117 | 118 | #else 119 | 120 | #if (NGX_HAVE_VARIADIC_MACROS) 121 | 122 | #define ndk_debug(...) 123 | #define ndk_debug_request() 124 | 125 | #else 126 | 127 | #include 128 | 129 | static void ndk_debug (const char * fmt, ...) { 130 | } 131 | 132 | static void ndk_debug_request() { 133 | } 134 | 135 | #endif 136 | 137 | #define ndk_debug_http_conf_location(cf) 138 | 139 | #endif 140 | 141 | #if (NDK_DEBUG) 142 | 143 | #define ndk_debug_check_read_event_handler(r) \ 144 | \ 145 | ndk_debug("r->read_event_handler = %s", \ 146 | r->read_event_handler == ngx_http_block_reading ? \ 147 | "ngx_http_block_reading" : \ 148 | r->read_event_handler == ngx_http_test_reading ? \ 149 | "ngx_http_test_reading" : \ 150 | r->read_event_handler == ngx_http_request_empty_handler ? \ 151 | "ngx_http_request_empty_handler" : "UNKNOWN") 152 | 153 | #define ndk_debug_check_write_event_handler(r) \ 154 | \ 155 | ndk_debug ("r->write_event_handler = %s", \ 156 | r->write_event_handler == ngx_http_handler ? \ 157 | "ngx_http_handler" : \ 158 | r->write_event_handler == ngx_http_core_run_phases ? \ 159 | "ngx_http_core_run_phases" : \ 160 | r->write_event_handler == ngx_http_request_empty_handler ? \ 161 | "ngx_http_request_empty_handler" : "UNKNOWN") 162 | 163 | #else 164 | 165 | #define ndk_debug_check_read_event_handler(r) 166 | #define ndk_debug_check_write_event_handler(r) 167 | 168 | #endif 169 | 170 | #endif /* NDK_DEBUG_H */ 171 | 172 | -------------------------------------------------------------------------------- /auto/src/conf_merge.h: -------------------------------------------------------------------------------- 1 | 2 | /* TODO : check that all the main types have a corresponding merge function */ 3 | 4 | #define ndk_conf_merge_value ngx_conf_merge_value 5 | #define ndk_conf_merge_off_value ngx_conf_merge_off_value 6 | #define ndk_conf_merge_ptr_value ngx_conf_merge_ptr_value 7 | #define ndk_conf_merge_str_value ngx_conf_merge_str_value 8 | #define ndk_conf_merge_size_value ngx_conf_merge_size_value 9 | 10 | 11 | #define ndk_conf_merge_keyval_value(conf,prev,default) \ 12 | \ 13 | conf = prev ? prev : default; 14 | 15 | #define ndk_conf_merge_str_array_value(conf,prev,val1,...) \ 16 | \ 17 | if (conf == NGX_CONF_UNSET_PTR) { \ 18 | if (prev == NGX_CONF_UNSET_PTR) { \ 19 | if (val1 == NULL) { \ 20 | conf = NULL; \ 21 | } else { \ 22 | char * elts[] = {val1,##__VA_ARGS__}; \ 23 | int n = sizeof(elts)/sizeof(char*); \ 24 | \ 25 | conf = ndk_str_array_create (cf->pool, elts, n); \ 26 | \ 27 | if (conf == NULL) \ 28 | return NGX_CONF_ERROR; \ 29 | } \ 30 | } else { \ 31 | conf = prev; \ 32 | } \ 33 | } 34 | 35 | #define ndk_conf_merge_http_complex_value_value(conf,prev,default) \ 36 | \ 37 | if (!conf.str.len) { \ 38 | if (prev.str.len) { \ 39 | conf = prev; \ 40 | } else { \ 41 | conf.str.data = (u_char *) default; \ 42 | conf.str.len = sizeof (default) - 1; \ 43 | \ 44 | if (ndk_http_complex_value_compile (cf, &conf)) \ 45 | return NGX_CONF_ERROR; \ 46 | } \ 47 | } 48 | 49 | #define ndk_conf_merge_http_complex_value_array_value(conf,prev,val1,...) \ 50 | \ 51 | if (conf == NGX_CONF_UNSET_PTR) { \ 52 | if (prev == NGX_CONF_UNSET_PTR) { \ 53 | if (val1 == NULL) \ 54 | conf = NULL; \ 55 | else { \ 56 | char * elts[] = {val1,##__VA_ARGS__}; \ 57 | int n = sizeof(elts)/sizeof(char*); \ 58 | \ 59 | conf = ndk_http_complex_value_array_create (cf, elts, n); \ 60 | \ 61 | if (conf == NULL) \ 62 | return NGX_CONF_ERROR; \ 63 | } \ 64 | } else { \ 65 | conf = prev; \ 66 | } \ 67 | } 68 | 69 | #define ndk_conf_merge_http_complex_path_value(conf,prev,...) \ 70 | ndk_conf_merge_http_complex_value_array_value (conf.a, prev.a, __VA_ARGS__) 71 | 72 | #define ndk_conf_merge_split_path_value(conf,prev,path) \ 73 | \ 74 | if (conf == NGX_CONF_UNSET_PTR) { \ 75 | conf = (prev == NGX_CONF_UNSET_PTR ? \ 76 | ndk_split_path_create_raw (cf, path) : prev); \ 77 | } 78 | 79 | -------------------------------------------------------------------------------- /src/hash/sha.h: -------------------------------------------------------------------------------- 1 | /* crypto/sha/sha.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_SHA_H 60 | #define HEADER_SHA_H 61 | 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | #if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) 70 | #error SHA is disabled. 71 | #endif 72 | 73 | #if defined(OPENSSL_FIPS) 74 | #define FIPS_SHA_SIZE_T size_t 75 | #endif 76 | 77 | /* 78 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 79 | * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then ! 80 | * ! SHA_LONG_LOG2 has to be defined along. ! 81 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 82 | */ 83 | 84 | #if defined(__LP32__) 85 | #define SHA_LONG unsigned long 86 | #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 87 | #define SHA_LONG unsigned long 88 | #define SHA_LONG_LOG2 3 89 | #else 90 | #define SHA_LONG unsigned int 91 | #endif 92 | 93 | #define SHA_LBLOCK 16 94 | #define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a 95 | * contiguous array of 32 bit 96 | * wide big-endian values. */ 97 | #define SHA_LAST_BLOCK (SHA_CBLOCK-8) 98 | #define SHA_DIGEST_LENGTH 20 99 | 100 | typedef struct SHAstate_st 101 | { 102 | SHA_LONG h0,h1,h2,h3,h4; 103 | SHA_LONG Nl,Nh; 104 | SHA_LONG data[SHA_LBLOCK]; 105 | unsigned int num; 106 | } SHA_CTX; 107 | 108 | #ifndef OPENSSL_NO_SHA0 109 | int SHA_Init(SHA_CTX *c); 110 | int SHA_Update(SHA_CTX *c, const void *data, size_t len); 111 | int SHA_Final(unsigned char *md, SHA_CTX *c); 112 | unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md); 113 | void SHA_Transform(SHA_CTX *c, const unsigned char *data); 114 | #endif 115 | #ifndef OPENSSL_NO_SHA1 116 | int SHA1_Init(SHA_CTX *c); 117 | int SHA1_Update(SHA_CTX *c, const void *data, size_t len); 118 | int SHA1_Final(unsigned char *md, SHA_CTX *c); 119 | unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); 120 | void SHA1_Transform(SHA_CTX *c, const unsigned char *data); 121 | #endif 122 | 123 | #define SHA256_CBLOCK (SHA_LBLOCK*4) /* SHA-256 treats input data as a 124 | * contiguous array of 32 bit 125 | * wide big-endian values. */ 126 | #define SHA224_DIGEST_LENGTH 28 127 | #define SHA256_DIGEST_LENGTH 32 128 | 129 | typedef struct SHA256state_st 130 | { 131 | SHA_LONG h[8]; 132 | SHA_LONG Nl,Nh; 133 | SHA_LONG data[SHA_LBLOCK]; 134 | unsigned int num,md_len; 135 | } SHA256_CTX; 136 | 137 | #ifndef OPENSSL_NO_SHA256 138 | int SHA224_Init(SHA256_CTX *c); 139 | int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); 140 | int SHA224_Final(unsigned char *md, SHA256_CTX *c); 141 | unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md); 142 | int SHA256_Init(SHA256_CTX *c); 143 | int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); 144 | int SHA256_Final(unsigned char *md, SHA256_CTX *c); 145 | unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md); 146 | void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); 147 | #endif 148 | 149 | #define SHA384_DIGEST_LENGTH 48 150 | #define SHA512_DIGEST_LENGTH 64 151 | 152 | #ifndef OPENSSL_NO_SHA512 153 | /* 154 | * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 155 | * being exactly 64-bit wide. See Implementation Notes in sha512.c 156 | * for further details. 157 | */ 158 | #define SHA512_CBLOCK (SHA_LBLOCK*8) /* SHA-512 treats input data as a 159 | * contiguous array of 64 bit 160 | * wide big-endian values. */ 161 | #if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) 162 | #define SHA_LONG64 unsigned __int64 163 | #define U64(C) C##UI64 164 | #elif defined(__arch64__) 165 | #define SHA_LONG64 unsigned long 166 | #define U64(C) C##UL 167 | #else 168 | #define SHA_LONG64 unsigned long long 169 | #define U64(C) C##ULL 170 | #endif 171 | 172 | typedef struct SHA512state_st 173 | { 174 | SHA_LONG64 h[8]; 175 | SHA_LONG64 Nl,Nh; 176 | union { 177 | SHA_LONG64 d[SHA_LBLOCK]; 178 | unsigned char p[SHA512_CBLOCK]; 179 | } u; 180 | unsigned int num,md_len; 181 | } SHA512_CTX; 182 | #endif 183 | 184 | #ifndef OPENSSL_NO_SHA512 185 | int SHA384_Init(SHA512_CTX *c); 186 | int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); 187 | int SHA384_Final(unsigned char *md, SHA512_CTX *c); 188 | unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md); 189 | int SHA512_Init(SHA512_CTX *c); 190 | int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); 191 | int SHA512_Final(unsigned char *md, SHA512_CTX *c); 192 | unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md); 193 | void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); 194 | #endif 195 | 196 | #ifdef __cplusplus 197 | } 198 | #endif 199 | 200 | #endif 201 | -------------------------------------------------------------------------------- /objs/ndk_palloc.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | * 5 | * DO NOT EDIT THIS FILE MANUALLY 6 | * ------------------------------ 7 | * This file has been generated automatically from scripts in the $base/auto dir and 8 | * data in the $base/auto/data dir. If you wish to edit the output of this file, then 9 | * you should edit these files instead. 10 | * 11 | */ 12 | 13 | 14 | /* Non-generated macros */ 15 | 16 | #define ndk_pallocp(p,pl) p = ngx_palloc (pl,sizeof(*p)) 17 | #define ndk_pallocpn(p,pl,n) p = ngx_palloc (pl,sizeof(*p)*(n)) 18 | 19 | #define ndk_pcallocp(p,pl) p = ngx_pcalloc (pl,sizeof(*p)) 20 | #define ndk_pcallocpn(p,pl,n) p = ngx_pcalloc (pl,sizeof(*p)*(n)) 21 | 22 | 23 | /* base action macro macros */ 24 | 25 | #define ndk_palloc_ac(p,pl,sz,ac) {p = ngx_palloc (pl,sz); if (p == NULL) ac;} 26 | #define ndk_pallocp_ac(p,pl,ac) {ndk_pallocp (p,pl); if (p == NULL) ac;} 27 | #define ndk_pallocpn_ac(p,pl,n,ac) {ndk_pallocpn (p,pl,n); if (p == NULL) ac;} 28 | #define ndk_pcalloc_ac(p,pl,sz,ac) {p = ngx_pcalloc (pl,sz); if (p == NULL) ac;} 29 | #define ndk_pcallocp_ac(p,pl,ac) {ndk_pcallocp (p,pl); if (p == NULL) ac;} 30 | #define ndk_pcallocpn_ac(p,pl,n,ac) {ndk_pcallocpn (p,pl,n); if (p == NULL) ac;} 31 | 32 | 33 | /* generated action macros */ 34 | 35 | #define ndk_palloc_r0(p,pl,sz) ndk_palloc_ac (p,pl,sz,return 0) 36 | #define ndk_palloc_r1(p,pl,sz) ndk_palloc_ac (p,pl,sz,return 1) 37 | #define ndk_palloc_r_1(p,pl,sz) ndk_palloc_ac (p,pl,sz,return -1) 38 | #define ndk_palloc_rok(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NGX_OK) 39 | #define ndk_palloc_rce(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NGX_CONF_ERROR) 40 | #define ndk_palloc_rcok(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NGX_CONF_OK) 41 | #define ndk_palloc_re(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NGX_ERROR) 42 | #define ndk_palloc_rn(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NULL) 43 | #define ndk_palloc_rse(p,pl,sz) ndk_palloc_ac (p,pl,sz,{ngx_script_error (e); return;}) 44 | #define ndk_palloc_sce(p,pl,sz) ndk_palloc_ac (p,pl,sz,{ngx_script_configure_error (c); return;}) 45 | #define ndk_palloc_g(p,pl,sz,_lb) ndk_palloc_ac (p,pl,sz,goto _lb) 46 | #define ndk_palloc_ge(p,pl,sz) ndk_palloc_ac (p,pl,sz,goto error) 47 | 48 | #define ndk_pallocp_r0(p,pl) ndk_pallocp_ac (p,pl,return 0) 49 | #define ndk_pallocp_r1(p,pl) ndk_pallocp_ac (p,pl,return 1) 50 | #define ndk_pallocp_r_1(p,pl) ndk_pallocp_ac (p,pl,return -1) 51 | #define ndk_pallocp_rok(p,pl) ndk_pallocp_ac (p,pl,return NGX_OK) 52 | #define ndk_pallocp_rce(p,pl) ndk_pallocp_ac (p,pl,return NGX_CONF_ERROR) 53 | #define ndk_pallocp_rcok(p,pl) ndk_pallocp_ac (p,pl,return NGX_CONF_OK) 54 | #define ndk_pallocp_re(p,pl) ndk_pallocp_ac (p,pl,return NGX_ERROR) 55 | #define ndk_pallocp_rn(p,pl) ndk_pallocp_ac (p,pl,return NULL) 56 | #define ndk_pallocp_rse(p,pl) ndk_pallocp_ac (p,pl,{ngx_script_error (e); return;}) 57 | #define ndk_pallocp_sce(p,pl) ndk_pallocp_ac (p,pl,{ngx_script_configure_error (c); return;}) 58 | #define ndk_pallocp_g(p,pl,_lb) ndk_pallocp_ac (p,pl,goto _lb) 59 | #define ndk_pallocp_ge(p,pl) ndk_pallocp_ac (p,pl,goto error) 60 | 61 | #define ndk_pallocpn_r0(p,pl,n) ndk_pallocpn_ac (p,pl,n,return 0) 62 | #define ndk_pallocpn_r1(p,pl,n) ndk_pallocpn_ac (p,pl,n,return 1) 63 | #define ndk_pallocpn_r_1(p,pl,n) ndk_pallocpn_ac (p,pl,n,return -1) 64 | #define ndk_pallocpn_rok(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NGX_OK) 65 | #define ndk_pallocpn_rce(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NGX_CONF_ERROR) 66 | #define ndk_pallocpn_rcok(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NGX_CONF_OK) 67 | #define ndk_pallocpn_re(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NGX_ERROR) 68 | #define ndk_pallocpn_rn(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NULL) 69 | #define ndk_pallocpn_rse(p,pl,n) ndk_pallocpn_ac (p,pl,n,{ngx_script_error (e); return;}) 70 | #define ndk_pallocpn_sce(p,pl,n) ndk_pallocpn_ac (p,pl,n,{ngx_script_configure_error (c); return;}) 71 | #define ndk_pallocpn_g(p,pl,n,_lb) ndk_pallocpn_ac (p,pl,n,goto _lb) 72 | #define ndk_pallocpn_ge(p,pl,n) ndk_pallocpn_ac (p,pl,n,goto error) 73 | 74 | #define ndk_pcalloc_r0(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return 0) 75 | #define ndk_pcalloc_r1(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return 1) 76 | #define ndk_pcalloc_r_1(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return -1) 77 | #define ndk_pcalloc_rok(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NGX_OK) 78 | #define ndk_pcalloc_rce(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NGX_CONF_ERROR) 79 | #define ndk_pcalloc_rcok(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NGX_CONF_OK) 80 | #define ndk_pcalloc_re(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NGX_ERROR) 81 | #define ndk_pcalloc_rn(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NULL) 82 | #define ndk_pcalloc_rse(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,{ngx_script_error (e); return;}) 83 | #define ndk_pcalloc_sce(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,{ngx_script_configure_error (c); return;}) 84 | #define ndk_pcalloc_g(p,pl,sz,_lb) ndk_pcalloc_ac (p,pl,sz,goto _lb) 85 | #define ndk_pcalloc_ge(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,goto error) 86 | 87 | #define ndk_pcallocp_r0(p,pl) ndk_pcallocp_ac (p,pl,return 0) 88 | #define ndk_pcallocp_r1(p,pl) ndk_pcallocp_ac (p,pl,return 1) 89 | #define ndk_pcallocp_r_1(p,pl) ndk_pcallocp_ac (p,pl,return -1) 90 | #define ndk_pcallocp_rok(p,pl) ndk_pcallocp_ac (p,pl,return NGX_OK) 91 | #define ndk_pcallocp_rce(p,pl) ndk_pcallocp_ac (p,pl,return NGX_CONF_ERROR) 92 | #define ndk_pcallocp_rcok(p,pl) ndk_pcallocp_ac (p,pl,return NGX_CONF_OK) 93 | #define ndk_pcallocp_re(p,pl) ndk_pcallocp_ac (p,pl,return NGX_ERROR) 94 | #define ndk_pcallocp_rn(p,pl) ndk_pcallocp_ac (p,pl,return NULL) 95 | #define ndk_pcallocp_rse(p,pl) ndk_pcallocp_ac (p,pl,{ngx_script_error (e); return;}) 96 | #define ndk_pcallocp_sce(p,pl) ndk_pcallocp_ac (p,pl,{ngx_script_configure_error (c); return;}) 97 | #define ndk_pcallocp_g(p,pl,_lb) ndk_pcallocp_ac (p,pl,goto _lb) 98 | #define ndk_pcallocp_ge(p,pl) ndk_pcallocp_ac (p,pl,goto error) 99 | 100 | #define ndk_pcallocpn_r0(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return 0) 101 | #define ndk_pcallocpn_r1(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return 1) 102 | #define ndk_pcallocpn_r_1(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return -1) 103 | #define ndk_pcallocpn_rok(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NGX_OK) 104 | #define ndk_pcallocpn_rce(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NGX_CONF_ERROR) 105 | #define ndk_pcallocpn_rcok(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NGX_CONF_OK) 106 | #define ndk_pcallocpn_re(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NGX_ERROR) 107 | #define ndk_pcallocpn_rn(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NULL) 108 | #define ndk_pcallocpn_rse(p,pl,n) ndk_pcallocpn_ac (p,pl,n,{ngx_script_error (e); return;}) 109 | #define ndk_pcallocpn_sce(p,pl,n) ndk_pcallocpn_ac (p,pl,n,{ngx_script_configure_error (c); return;}) 110 | #define ndk_pcallocpn_g(p,pl,n,_lb) ndk_pcallocpn_ac (p,pl,n,goto _lb) 111 | #define ndk_pcallocpn_ge(p,pl,n) ndk_pcallocpn_ac (p,pl,n,goto error) 112 | 113 | -------------------------------------------------------------------------------- /objs/ndk_array.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | * 5 | * DO NOT EDIT THIS FILE MANUALLY 6 | * ------------------------------ 7 | * This file has been generated automatically from scripts in the $base/auto dir and 8 | * data in the $base/auto/data dir. If you wish to edit the output of this file, then 9 | * you should edit these files instead. 10 | * 11 | */ 12 | 13 | 14 | /* Non-generated macros */ 15 | 16 | #define ndk_array_count(a) ((a)->nelts) 17 | #define ndk_array_get_first(a) ((a)->elts) 18 | #define ndk_array_get_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * n)) 19 | #define ndk_array_get_last(a) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1))) 20 | #define ndk_array_get_reverse_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1 - n))) 21 | #define ndk_array_push_clean(p,a) {p = ngx_array_push (a); ndk_zerop (p);} 22 | 23 | 24 | /* base action macro macros */ 25 | 26 | #define ndk_array_create_ac(a,pl,n,sz,ac) {a = ngx_array_create (pl,n,sz); if (a == NULL) ac;} 27 | #define ndk_array_init_ac(a,pl,n,sz,ac) {if (ngx_array_init (a,pl,n,sz) == NGX_ERROR) ac;} 28 | #define ndk_array_push_ac(p,a,ac) {p = ngx_array_push (a); if (p == NULL) ac;} 29 | #define ndk_array_push_clean_ac(p,a,ac) {p = ngx_array_push (a); if (p == NULL) ac; ndk_zerop (p);} 30 | #define ndk_array_push_n_ac(p,a,n,ac) {p = ngx_array_push_n (a,n); if (p == NULL) ac;} 31 | #define ndk_array_push_n_clean_ac(p,a,n,ac) {p = ngx_array_push_n (a,n); if (p == NULL) ac; ndk_zeropn (p,n);} 32 | 33 | 34 | /* generated action macros */ 35 | 36 | #define ndk_array_create_r0(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return 0) 37 | #define ndk_array_create_r1(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return 1) 38 | #define ndk_array_create_r_1(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return -1) 39 | #define ndk_array_create_rok(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NGX_OK) 40 | #define ndk_array_create_rce(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NGX_CONF_ERROR) 41 | #define ndk_array_create_rcok(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NGX_CONF_OK) 42 | #define ndk_array_create_re(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NGX_ERROR) 43 | #define ndk_array_create_rn(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NULL) 44 | #define ndk_array_create_rse(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,{ngx_script_error (e); return;}) 45 | #define ndk_array_create_sce(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,{ngx_script_configure_error (c); return;}) 46 | #define ndk_array_create_g(a,pl,n,sz,_lb) ndk_array_create_ac (a,pl,n,sz,goto _lb) 47 | #define ndk_array_create_ge(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,goto error) 48 | 49 | #define ndk_array_init_r0(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return 0) 50 | #define ndk_array_init_r1(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return 1) 51 | #define ndk_array_init_r_1(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return -1) 52 | #define ndk_array_init_rok(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NGX_OK) 53 | #define ndk_array_init_rce(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NGX_CONF_ERROR) 54 | #define ndk_array_init_rcok(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NGX_CONF_OK) 55 | #define ndk_array_init_re(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NGX_ERROR) 56 | #define ndk_array_init_rn(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NULL) 57 | #define ndk_array_init_rse(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,{ngx_script_error (e); return;}) 58 | #define ndk_array_init_sce(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,{ngx_script_configure_error (c); return;}) 59 | #define ndk_array_init_g(a,pl,n,sz,_lb) ndk_array_init_ac (a,pl,n,sz,goto _lb) 60 | #define ndk_array_init_ge(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,goto error) 61 | 62 | #define ndk_array_push_r0(p,a) ndk_array_push_ac (p,a,return 0) 63 | #define ndk_array_push_r1(p,a) ndk_array_push_ac (p,a,return 1) 64 | #define ndk_array_push_r_1(p,a) ndk_array_push_ac (p,a,return -1) 65 | #define ndk_array_push_rok(p,a) ndk_array_push_ac (p,a,return NGX_OK) 66 | #define ndk_array_push_rce(p,a) ndk_array_push_ac (p,a,return NGX_CONF_ERROR) 67 | #define ndk_array_push_rcok(p,a) ndk_array_push_ac (p,a,return NGX_CONF_OK) 68 | #define ndk_array_push_re(p,a) ndk_array_push_ac (p,a,return NGX_ERROR) 69 | #define ndk_array_push_rn(p,a) ndk_array_push_ac (p,a,return NULL) 70 | #define ndk_array_push_rse(p,a) ndk_array_push_ac (p,a,{ngx_script_error (e); return;}) 71 | #define ndk_array_push_sce(p,a) ndk_array_push_ac (p,a,{ngx_script_configure_error (c); return;}) 72 | #define ndk_array_push_g(p,a,_lb) ndk_array_push_ac (p,a,goto _lb) 73 | #define ndk_array_push_ge(p,a) ndk_array_push_ac (p,a,goto error) 74 | 75 | #define ndk_array_push_clean_r0(p,a) ndk_array_push_clean_ac (p,a,return 0) 76 | #define ndk_array_push_clean_r1(p,a) ndk_array_push_clean_ac (p,a,return 1) 77 | #define ndk_array_push_clean_r_1(p,a) ndk_array_push_clean_ac (p,a,return -1) 78 | #define ndk_array_push_clean_rok(p,a) ndk_array_push_clean_ac (p,a,return NGX_OK) 79 | #define ndk_array_push_clean_rce(p,a) ndk_array_push_clean_ac (p,a,return NGX_CONF_ERROR) 80 | #define ndk_array_push_clean_rcok(p,a) ndk_array_push_clean_ac (p,a,return NGX_CONF_OK) 81 | #define ndk_array_push_clean_re(p,a) ndk_array_push_clean_ac (p,a,return NGX_ERROR) 82 | #define ndk_array_push_clean_rn(p,a) ndk_array_push_clean_ac (p,a,return NULL) 83 | #define ndk_array_push_clean_rse(p,a) ndk_array_push_clean_ac (p,a,{ngx_script_error (e); return;}) 84 | #define ndk_array_push_clean_sce(p,a) ndk_array_push_clean_ac (p,a,{ngx_script_configure_error (c); return;}) 85 | #define ndk_array_push_clean_g(p,a,_lb) ndk_array_push_clean_ac (p,a,goto _lb) 86 | #define ndk_array_push_clean_ge(p,a) ndk_array_push_clean_ac (p,a,goto error) 87 | 88 | #define ndk_array_push_n_r0(p,a,n) ndk_array_push_n_ac (p,a,n,return 0) 89 | #define ndk_array_push_n_r1(p,a,n) ndk_array_push_n_ac (p,a,n,return 1) 90 | #define ndk_array_push_n_r_1(p,a,n) ndk_array_push_n_ac (p,a,n,return -1) 91 | #define ndk_array_push_n_rok(p,a,n) ndk_array_push_n_ac (p,a,n,return NGX_OK) 92 | #define ndk_array_push_n_rce(p,a,n) ndk_array_push_n_ac (p,a,n,return NGX_CONF_ERROR) 93 | #define ndk_array_push_n_rcok(p,a,n) ndk_array_push_n_ac (p,a,n,return NGX_CONF_OK) 94 | #define ndk_array_push_n_re(p,a,n) ndk_array_push_n_ac (p,a,n,return NGX_ERROR) 95 | #define ndk_array_push_n_rn(p,a,n) ndk_array_push_n_ac (p,a,n,return NULL) 96 | #define ndk_array_push_n_rse(p,a,n) ndk_array_push_n_ac (p,a,n,{ngx_script_error (e); return;}) 97 | #define ndk_array_push_n_sce(p,a,n) ndk_array_push_n_ac (p,a,n,{ngx_script_configure_error (c); return;}) 98 | #define ndk_array_push_n_g(p,a,n,_lb) ndk_array_push_n_ac (p,a,n,goto _lb) 99 | #define ndk_array_push_n_ge(p,a,n) ndk_array_push_n_ac (p,a,n,goto error) 100 | 101 | #define ndk_array_push_n_clean_r0(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return 0) 102 | #define ndk_array_push_n_clean_r1(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return 1) 103 | #define ndk_array_push_n_clean_r_1(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return -1) 104 | #define ndk_array_push_n_clean_rok(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NGX_OK) 105 | #define ndk_array_push_n_clean_rce(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NGX_CONF_ERROR) 106 | #define ndk_array_push_n_clean_rcok(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NGX_CONF_OK) 107 | #define ndk_array_push_n_clean_re(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NGX_ERROR) 108 | #define ndk_array_push_n_clean_rn(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NULL) 109 | #define ndk_array_push_n_clean_rse(p,a,n) ndk_array_push_n_clean_ac (p,a,n,{ngx_script_error (e); return;}) 110 | #define ndk_array_push_n_clean_sce(p,a,n) ndk_array_push_n_clean_ac (p,a,n,{ngx_script_configure_error (c); return;}) 111 | #define ndk_array_push_n_clean_g(p,a,n,_lb) ndk_array_push_n_clean_ac (p,a,n,goto _lb) 112 | #define ndk_array_push_n_clean_ge(p,a,n) ndk_array_push_n_clean_ac (p,a,n,goto error) 113 | 114 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Name 2 | ==== 3 | 4 | Nginx Development Kit (NDK) 5 | 6 | Table of Contents 7 | ================= 8 | 9 | * [Name](#name) 10 | * [Synopsis](#synopsis) 11 | * [Status](#status) 12 | * [Features](#features) 13 | * [Design](#design) 14 | * [modular](#modular) 15 | * [auto-generated & easily extensible](#auto-generated--easily-extensible) 16 | * [Usage for users](#usage-for-users) 17 | * [Building as a dynamic module](#building-as-a-dynamic-module) 18 | * [Usage for developers](#usage-for-developers) 19 | * [Warning: using NDK_ALL](#warning-using-ndk_all) 20 | * [Modules using NDK](#modules-using-ndk) 21 | * [TODO](#todo) 22 | * [License](#license) 23 | * [Contributing / Feedback](#contributing--feedback) 24 | * [Authors](#authors) 25 | * [Special Thanks](#special-thanks) 26 | 27 | Synopsis 28 | ======== 29 | 30 | The NDK is an Nginx module that is designed to extend the core functionality of the 31 | excellent Nginx webserver in a way that can be used as a basis of other Nginx modules. 32 | 33 | It has functions and macros to deal with generic tasks that don't currently have 34 | generic code as part of the core distribution. The NDK itself adds few features 35 | that are seen from a user's point of view - it's just designed to help reduce the 36 | code that Nginx module developers need to write. 37 | 38 | Nginx module developers wishing to use any of the features in the NDK should specify 39 | that the NDK is a dependency of their module, and that users will need to compile 40 | it as well when they compile their own modules. They will also need to declare in 41 | their own modules which features of the NDK they wish to use (explained below). 42 | 43 | If you are not an Nginx module developer, then the only useful part of this project 44 | will be the 'usage for users' section below. 45 | 46 | [Back to TOC](#table-of-contents) 47 | 48 | Status 49 | ====== 50 | 51 | The NDK is now considered to be stable. It is already being used in quite a few third 52 | party modules (see list below). 53 | 54 | [Back to TOC](#table-of-contents) 55 | 56 | Features 57 | ======== 58 | 59 | * additional conf_set functions for regexes, complex/script values, paths... 60 | * macros to simplify tasks like checking for NULL values when doing ngx_array_push 61 | * patches to the main source code 62 | * ngx_auto_lib_core generic external library handler is included (see separate readme) 63 | 64 | [Back to TOC](#table-of-contents) 65 | 66 | Design 67 | ====== 68 | 69 | modular 70 | ------- 71 | 72 | The kit itself is designed in a modular way, so that only the required code is compiled. 73 | It's possible to add just a single NDK module, a few or all of them. 74 | 75 | [Back to TOC](#table-of-contents) 76 | 77 | auto-generated & easily extensible 78 | ---------------------------------- 79 | 80 | Many of the macros available in the NDK are auto-generated from simple configuration 81 | files. This makes creating similar macros for your own code very simple - it's usually 82 | just the case of adding an extra line to a config file and re-running the build script. 83 | 84 | [Back to TOC](#table-of-contents) 85 | 86 | Usage for users 87 | =============== 88 | 89 | If another Nginx module you wish to use specifies that the NDK is a dependency, you 90 | will need to do the following : 91 | 92 | 1. download the source (https://github.com/simpl/ngx_devel_kit) 93 | 2. unpack the source (tar -xzf $name) 94 | 3. compile Nginx with the following extra option `--add-module=/path/to/ngx_devel_kit`. 95 | 96 | e.g. 97 | 98 | ```bash 99 | ./configure --add-module=/path/to/ngx_devel_kit \ 100 | --add-module=/path/to/another/module 101 | ``` 102 | 103 | [Back to TOC](#table-of-contents) 104 | 105 | Building as a dynamic module 106 | ---------------------------- 107 | 108 | Starting from NGINX 1.9.11, you can also compile this module as a dynamic module, by using the `--add-dynamic-module=PATH` option instead of `--add-module=PATH` on the 109 | `./configure` command line above. And then you can explicitly load the module in your `nginx.conf` via the [load_module](http://nginx.org/en/docs/ngx_core_module.html#load_module) 110 | directive, for example, 111 | 112 | ```nginx 113 | load_module /path/to/modules/ndk_http_module.so; 114 | load_module /path/to/another/module.so; 115 | ``` 116 | 117 | [Back to TOC](#table-of-contents) 118 | 119 | Usage for developers 120 | ==================== 121 | 122 | To use the NDK in your own module, you need to add the following: 123 | 124 | 1. add this line to your module 125 | 126 | ```C 127 | #include 128 | ``` 129 | 130 | Note: since the NDK includes the following lines 131 | 132 | ```C 133 | #include 134 | #include 135 | #include 136 | ``` 137 | 138 | you can replace these with the single include above. 139 | 2. add the following line in the config file for your module: 140 | 141 | ```bash 142 | have=NDK_[module_name] . auto/have 143 | ``` 144 | 145 | for each NDK module that you wish to use (you need to include auto/have multiple 146 | times if you wish to use multiple NDK modules. 147 | 148 | Note: the old method of setting 149 | 150 | ```config 151 | CFLAGS="$CFLAGS -DNDK_[module_name]" 152 | ``` 153 | 154 | is now deprecated. It will still work, but results in unnecessary lines being 155 | displayed when compiling Nginx. 156 | 157 | [Back to TOC](#table-of-contents) 158 | 159 | Warning: Using NDK_ALL 160 | ---------------------- 161 | 162 | You can also set `NDK_ALL` to include all the NDK modules. This is primarily as 163 | a convenience in the early stages of development of another module. However, 164 | 165 | DO NOT LEAVE `NDK_ALL` IN YOUR CONFIG FILE WHEN PUBLISHING 166 | 167 | Although the NDK is fairly small now, it could in time become a large repository 168 | of code that would, if using NDK_ALL, result in considerably more code being compiled 169 | than is necessary. 170 | 171 | [Back to TOC](#table-of-contents) 172 | 173 | Modules using NDK 174 | ================= 175 | 176 | The following 3rd-party modules make use of NDK. 177 | 178 | * [ngx_http_lua_module](https://github.com/openresty/lua-nginx-module#readme) 179 | * [ngx_http_set_misc_module](https://github.com/openresty/set-misc-nginx-module#readme) 180 | * [ngx_http_encrypted_session_module](https://github.com/openresty/encrypted-session-nginx-module#readme) 181 | * [ngx_http_form_input_module](https://github.com/calio/form-input-nginx-module#readme) 182 | * [ngx_http_iconv_module](https://github.com/calio/iconv-nginx-module#readme) 183 | * [ngx_http_array_var_module](https://github.com/openresty/array-var-nginx-module#readme) 184 | 185 | If you would like to add your module to this list, please let us know. 186 | 187 | [Back to TOC](#table-of-contents) 188 | 189 | TODO 190 | ==== 191 | 192 | * documentation for modules that don't already have it 193 | * additional phase-handler functions 194 | * generically testing for needing to add a handler 195 | * remove dependency of set_var on OpenSSL being compiled in 196 | * for backward compatability, add the ndk_macros 197 | 198 | [Back to TOC](#table-of-contents) 199 | 200 | License 201 | ======= 202 | 203 | Copyright (c) 2010-2018, Marcus Clyne 204 | 205 | All rights reserved. 206 | 207 | Redistribution and use in source and binary forms, with or without modification, are 208 | permitted provided that the following conditions are met: 209 | 210 | 1. Redistributions of source code must retain the above copyright notice, this list of 211 | conditions and the following disclaimer. 212 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of 213 | conditions and the following disclaimer in the documentation and/or other materials 214 | provided with the distribution. 215 | 3. Neither the name of the copyright holder nor the names of its contributors may be used 216 | to endorse or promote products derived from this software without specific prior 217 | written permission. 218 | 219 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 220 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 221 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 222 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 223 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 224 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 225 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 226 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 227 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 228 | 229 | [Back to TOC](#table-of-contents) 230 | 231 | Contributing / Feedback 232 | ======================= 233 | 234 | If you are an Nginx module developer, and have developed some functions that are 235 | generic in nature (or would be easily adapted to be so), then please send them to 236 | me at the address below, and I'll addmclyne to the kit. 237 | 238 | [Back to TOC](#table-of-contents) 239 | 240 | Author 241 | ====== 242 | 243 | [Marcus Clyne](https://github.com/mclyne) 244 | 245 | [Back to TOC](#table-of-contents) 246 | 247 | 248 | Special Thanks 249 | ============== 250 | 251 | A special thanks goes to [Yichun Zhang](https://github.com/agentzh) for helping to maintain 252 | this module. 253 | 254 | [Back to TOC](#table-of-contents) 255 | -------------------------------------------------------------------------------- /patches/expose_rewrite_functions: -------------------------------------------------------------------------------- 1 | diff -rNp a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c 2 | *** a/src/http/modules/ngx_http_rewrite_module.c 2010-06-18 16:15:20.000000000 +0100 3 | --- b/src/http/modules/ngx_http_rewrite_module.c 2010-10-09 14:47:10.000000000 +0100 4 | *************** 5 | *** 8,14 **** 6 | #include 7 | #include 8 | 9 | ! 10 | typedef struct { 11 | ngx_array_t *codes; /* uintptr_t */ 12 | 13 | --- 8,14 ---- 14 | #include 15 | #include 16 | 17 | ! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS) 18 | typedef struct { 19 | ngx_array_t *codes; /* uintptr_t */ 20 | 21 | *************** typedef struct { 22 | *** 17,23 **** 23 | ngx_flag_t log; 24 | ngx_flag_t uninitialized_variable_warn; 25 | } ngx_http_rewrite_loc_conf_t; 26 | ! 27 | 28 | static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf); 29 | static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, 30 | --- 17,23 ---- 31 | ngx_flag_t log; 32 | ngx_flag_t uninitialized_variable_warn; 33 | } ngx_http_rewrite_loc_conf_t; 34 | ! #endif 35 | 36 | static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf); 37 | static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, 38 | *************** static char *ngx_http_rewrite_return(ngx 39 | *** 28,44 **** 40 | void *conf); 41 | static char *ngx_http_rewrite_break(ngx_conf_t *cf, ngx_command_t *cmd, 42 | void *conf); 43 | static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, 44 | void *conf); 45 | static char * ngx_http_rewrite_if_condition(ngx_conf_t *cf, 46 | ngx_http_rewrite_loc_conf_t *lcf); 47 | static char *ngx_http_rewrite_variable(ngx_conf_t *cf, 48 | ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value); 49 | static char *ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, 50 | void *conf); 51 | static char * ngx_http_rewrite_value(ngx_conf_t *cf, 52 | ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value); 53 | ! 54 | 55 | static ngx_command_t ngx_http_rewrite_commands[] = { 56 | 57 | --- 28,47 ---- 58 | void *conf); 59 | static char *ngx_http_rewrite_break(ngx_conf_t *cf, ngx_command_t *cmd, 60 | void *conf); 61 | + #if !(NDK_EXPOSE_REWRITE_FUNCTIONS) 62 | static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, 63 | void *conf); 64 | static char * ngx_http_rewrite_if_condition(ngx_conf_t *cf, 65 | ngx_http_rewrite_loc_conf_t *lcf); 66 | static char *ngx_http_rewrite_variable(ngx_conf_t *cf, 67 | ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value); 68 | + #endif 69 | static char *ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, 70 | void *conf); 71 | + #if !(NDK_EXPOSE_REWRITE_FUNCTIONS) 72 | static char * ngx_http_rewrite_value(ngx_conf_t *cf, 73 | ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value); 74 | ! #endif 75 | 76 | static ngx_command_t ngx_http_rewrite_commands[] = { 77 | 78 | *************** ngx_http_rewrite_handler(ngx_http_reques 79 | *** 178,185 **** 80 | return r->err_status; 81 | } 82 | 83 | ! 84 | ! static ngx_int_t 85 | ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v, 86 | uintptr_t data) 87 | { 88 | --- 181,190 ---- 89 | return r->err_status; 90 | } 91 | 92 | ! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS) 93 | ! static 94 | ! #endif 95 | ! ngx_int_t 96 | ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v, 97 | uintptr_t data) 98 | { 99 | *************** ngx_http_rewrite_break(ngx_conf_t *cf, n 100 | *** 511,517 **** 101 | } 102 | 103 | 104 | ! static char * 105 | ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 106 | { 107 | ngx_http_rewrite_loc_conf_t *lcf = conf; 108 | --- 516,525 ---- 109 | } 110 | 111 | 112 | ! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS) 113 | ! static 114 | ! #endif 115 | ! char * 116 | ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 117 | { 118 | ngx_http_rewrite_loc_conf_t *lcf = conf; 119 | *************** ngx_http_rewrite_if(ngx_conf_t *cf, ngx_ 120 | *** 627,633 **** 121 | } 122 | 123 | 124 | ! static char * 125 | ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf) 126 | { 127 | u_char *p; 128 | --- 635,644 ---- 129 | } 130 | 131 | 132 | ! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS) 133 | ! static 134 | ! #endif 135 | ! char * 136 | ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf) 137 | { 138 | u_char *p; 139 | *************** ngx_http_rewrite_if_condition(ngx_conf_t 140 | *** 847,853 **** 141 | } 142 | 143 | 144 | ! static char * 145 | ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf, 146 | ngx_str_t *value) 147 | { 148 | --- 858,867 ---- 149 | } 150 | 151 | 152 | ! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS) 153 | ! static 154 | ! #endif 155 | ! char * 156 | ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf, 157 | ngx_str_t *value) 158 | { 159 | *************** ngx_http_rewrite_set(ngx_conf_t *cf, ngx 160 | *** 948,954 **** 161 | } 162 | 163 | 164 | ! static char * 165 | ngx_http_rewrite_value(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf, 166 | ngx_str_t *value) 167 | { 168 | --- 962,971 ---- 169 | } 170 | 171 | 172 | ! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS) 173 | ! static 174 | ! #endif 175 | ! char * 176 | ngx_http_rewrite_value(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf, 177 | ngx_str_t *value) 178 | { 179 | diff -rNp a/src/http/modules/ngx_http_rewrite_module.h b/src/http/modules/ngx_http_rewrite_module.h 180 | *** a/src/http/modules/ngx_http_rewrite_module.h 1970-01-01 01:00:00.000000000 +0100 181 | --- b/src/http/modules/ngx_http_rewrite_module.h 2010-10-09 14:38:04.000000000 +0100 182 | *************** 183 | *** 0 **** 184 | --- 1,47 ---- 185 | + 186 | + /* 187 | + * Copyright (C) Marcus Clyne 188 | + * 189 | + * Note : this file has been created by the Nginx Development Kit using 190 | + * some code from ngx_http_rewrite_module.c 191 | + */ 192 | + 193 | + #if (NDK_EXPOSE_REWRITE_FUNCTIONS) 194 | + 195 | + #ifndef _NGX_HTTP_REWRITE_H_INCLUDED_ 196 | + #define _NGX_HTTP_REWRITE_H_INCLUDED_ 197 | + 198 | + #include 199 | + #include 200 | + #include 201 | + 202 | + 203 | + extern ngx_module_t ngx_http_rewrite_module; 204 | + 205 | + 206 | + typedef struct { 207 | + ngx_array_t *codes; /* uintptr_t */ 208 | + 209 | + ngx_uint_t stack_size; 210 | + 211 | + ngx_flag_t log; 212 | + ngx_flag_t uninitialized_variable_warn; 213 | + } ngx_http_rewrite_loc_conf_t; 214 | + 215 | + 216 | + char * 217 | + ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 218 | + char * 219 | + ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf); 220 | + char * 221 | + ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf, 222 | + ngx_str_t *value); 223 | + char * 224 | + ngx_http_rewrite_value(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf, 225 | + ngx_str_t *value); 226 | + ngx_int_t 227 | + ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v, 228 | + uintptr_t data); 229 | + 230 | + #endif 231 | + #endif 232 | diff -rNp a/src/http/ngx_http.h b/src/http/ngx_http.h 233 | *** a/src/http/ngx_http.h 2010-06-15 16:13:34.000000000 +0100 234 | --- b/src/http/ngx_http.h 2010-10-09 14:25:56.000000000 +0100 235 | *************** typedef u_char *(*ngx_http_log_handler_p 236 | *** 43,48 **** 237 | --- 43,52 ---- 238 | #include 239 | #endif 240 | 241 | + #if (NDK_EXPOSE_REWRITE_FUNCTIONS) 242 | + #include 243 | + #endif 244 | + 245 | 246 | struct ngx_http_log_ctx_s { 247 | ngx_connection_t *connection; 248 | diff -rNp a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c 249 | *** a/src/http/ngx_http_script.c 2010-09-13 13:44:43.000000000 +0100 250 | --- b/src/http/ngx_http_script.c 2010-10-09 14:36:10.000000000 +0100 251 | *************** static size_t ngx_http_script_full_name_ 252 | *** 26,35 **** 253 | --- 26,43 ---- 254 | static void ngx_http_script_full_name_code(ngx_http_script_engine_t *e); 255 | 256 | 257 | + #if (NDK_EXPOSE_REWRITE_FUNCTIONS) 258 | + 259 | + uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL; 260 | + 261 | + #else 262 | + 263 | #define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code 264 | 265 | static uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL; 266 | 267 | + #endif 268 | + 269 | 270 | void 271 | ngx_http_script_flush_complex_value(ngx_http_request_t *r, 272 | diff -rNp a/src/http/ngx_http_script.h b/src/http/ngx_http_script.h 273 | *** a/src/http/ngx_http_script.h 2010-09-13 13:44:43.000000000 +0100 274 | --- b/src/http/ngx_http_script.h 2010-10-09 14:33:40.000000000 +0100 275 | *************** 276 | *** 12,17 **** 277 | --- 12,25 ---- 278 | #include 279 | #include 280 | 281 | + #if (NDK_EXPOSE_REWRITE_FUNCTIONS) 282 | + 283 | + #define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code 284 | + 285 | + extern uintptr_t ngx_http_script_exit_code; 286 | + 287 | + #endif 288 | + 289 | 290 | typedef struct { 291 | u_char *ip; 292 | -------------------------------------------------------------------------------- /src/ndk_string.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int64_t 4 | ndk_atoi64 (u_char *line, size_t n) 5 | { 6 | int64_t value; 7 | 8 | if (n == 0ll) { 9 | return NGX_ERROR; 10 | } 11 | 12 | for (value = 0ll; n--; line++) { 13 | if (*line < '0' || *line > '9') { 14 | return NGX_ERROR; 15 | } 16 | 17 | value = value * 10ll + (*line - '0'); 18 | } 19 | 20 | if (value < 0ll) { 21 | return NGX_ERROR; 22 | } 23 | 24 | return value; 25 | } 26 | 27 | 28 | ngx_int_t 29 | ndk_strcntc (ngx_str_t *s, char c) 30 | { 31 | ngx_int_t n; 32 | size_t i; 33 | u_char *p; 34 | 35 | i = s->len; 36 | p = s->data; 37 | 38 | for (n=0; i; i--, p++) { 39 | 40 | if (*p == (u_char) c) 41 | n++; 42 | } 43 | 44 | return n; 45 | } 46 | 47 | 48 | ngx_int_t 49 | ndk_strccnt (char *s, char c) 50 | { 51 | ngx_int_t n; 52 | 53 | n = 0; 54 | 55 | while (*s != '\0') { 56 | 57 | if (*s == 'c') 58 | n++; 59 | 60 | s++; 61 | } 62 | 63 | return n; 64 | } 65 | 66 | 67 | 68 | ngx_array_t * 69 | ndk_str_array_create (ngx_pool_t *pool, char **s, ngx_int_t n) 70 | { 71 | ngx_int_t i; 72 | ngx_str_t *str; 73 | ngx_array_t *a; 74 | 75 | a = ngx_array_create (pool, n, sizeof (ngx_str_t)); 76 | if (a == NULL) 77 | return NULL; 78 | 79 | 80 | for (i=0; idata = (u_char *) *s; 85 | str->len = strlen (*s); 86 | } 87 | 88 | return a; 89 | } 90 | 91 | 92 | 93 | u_char * 94 | ndk_vcatstrf (ngx_pool_t *pool, ngx_str_t *dest, const char *fmt, va_list args) 95 | { 96 | size_t len, l, el; 97 | int argc; 98 | u_char *p, *m, *e, c, c1, *cp; 99 | 100 | argc = strlen (fmt); 101 | 102 | ngx_str_t *s; 103 | ndk_estr_t *sp, *sp2, ss [argc]; 104 | u_char cs [argc]; 105 | 106 | sp = sp2 = ss; 107 | cp = cs; 108 | 109 | len = 0; 110 | 111 | /* TODO : maybe have 'e' at the beginning? */ 112 | 113 | /* parse format to get strings */ 114 | 115 | while (*fmt) { 116 | 117 | switch (*fmt) { 118 | 119 | case 'S' : 120 | 121 | s = va_arg (args, ngx_str_t *); 122 | 123 | sp->data = s->data; 124 | sp->len = s->len; 125 | sp->escaped = 0; 126 | 127 | len += sp->len; 128 | break; 129 | 130 | case 's' : 131 | 132 | sp->data = va_arg (args, u_char *); 133 | sp->len = (size_t) ngx_strlen (sp->data); 134 | sp->escaped = 0; 135 | 136 | len += sp->len; 137 | break; 138 | 139 | case 'l' : 140 | 141 | sp->data = va_arg (args, u_char *); 142 | sp->len = (size_t) va_arg (args, int); 143 | sp->escaped = 0; 144 | 145 | len += sp->len; 146 | break; 147 | 148 | case 'L' : 149 | 150 | sp->data = va_arg (args, u_char *); 151 | sp->len = va_arg (args, size_t); 152 | sp->escaped = 0; 153 | 154 | len += sp->len; 155 | break; 156 | 157 | case 'e' : 158 | 159 | p = va_arg (args, u_char *); 160 | 161 | sp->data = p; 162 | 163 | l = 0; 164 | el = 0; 165 | c = *p; 166 | 167 | while (c != '\0') { 168 | 169 | if (c == '\\') { 170 | l += 2; 171 | p += 2; 172 | } else { 173 | l++; 174 | p++; 175 | } 176 | 177 | el++; 178 | c = *p; 179 | } 180 | 181 | sp->len = l; 182 | sp->escaped = 1; 183 | 184 | len += el; 185 | break; 186 | 187 | case 'E' : 188 | 189 | s = va_arg (args, ngx_str_t *); 190 | 191 | sp->data = s->data; 192 | sp->len = s->len; 193 | 194 | p = sp->data; 195 | 196 | el = 0; 197 | e = p + sp->len; 198 | 199 | while (p < e) { 200 | 201 | c = *p; 202 | 203 | if (c == '\\') { 204 | p += 2; 205 | } else { 206 | p++; 207 | } 208 | 209 | el++; 210 | } 211 | 212 | sp->escaped = 1; 213 | 214 | len += el; 215 | break; 216 | 217 | case 'n' : 218 | 219 | sp->data = va_arg (args, u_char *); 220 | sp->len = (size_t) va_arg (args, int); 221 | 222 | p = sp->data; 223 | 224 | el = 0; 225 | e = p + sp->len; 226 | 227 | while (p < e) { 228 | 229 | c = *p; 230 | 231 | if (c == '\\') { 232 | p += 2; 233 | } else { 234 | p++; 235 | } 236 | 237 | el++; 238 | } 239 | 240 | sp->escaped = 1; 241 | 242 | len += el; 243 | break; 244 | 245 | case 'c' : 246 | 247 | *cp = (u_char) va_arg (args, int); 248 | 249 | sp->data = cp; 250 | sp->len = (size_t) 1; 251 | 252 | len++; 253 | cp++; 254 | 255 | break; 256 | 257 | default : 258 | 259 | ndk_log_alert (pool->log, 0, "catstrf () : format [%s] incorrect", fmt); 260 | 261 | return NULL; 262 | 263 | } 264 | 265 | sp++; 266 | fmt++; 267 | } 268 | 269 | 270 | 271 | /* create space for string (assumes no NULL's in strings) */ 272 | 273 | ndk_palloc_rn (p, pool, len + 1); 274 | 275 | dest->data = p; 276 | dest->len = len; 277 | 278 | /* copy other strings */ 279 | 280 | if (len) { 281 | 282 | while (sp2 < sp) { 283 | 284 | if (sp2->escaped) { 285 | 286 | m = sp2->data; 287 | e = m + sp2->len; 288 | 289 | while (m < e) { 290 | 291 | c = *m; 292 | 293 | if (c == '\\') { 294 | 295 | if (m == e - 1) { 296 | *p = '\\'; 297 | p++; 298 | break; 299 | } 300 | 301 | c1 = m[1]; 302 | 303 | switch (c1) { 304 | 305 | case 'n' : 306 | *p = '\n'; 307 | break; 308 | 309 | case 't' : 310 | *p = '\t'; 311 | break; 312 | 313 | case '0' : 314 | *p = '\0'; 315 | break; 316 | 317 | case '\\' : 318 | *p = '\\'; 319 | break; 320 | 321 | case 's' : 322 | *p = ' '; 323 | break; 324 | 325 | case 'b' : 326 | *p = '\b'; 327 | break; 328 | 329 | case 'r' : 330 | *p = '\r'; 331 | break; 332 | 333 | default : 334 | 335 | *p = c1; 336 | break; 337 | } 338 | 339 | m += 2; 340 | 341 | } else { 342 | 343 | *p = c; 344 | m++; 345 | } 346 | 347 | p++; 348 | } 349 | 350 | } else { 351 | 352 | p = ngx_cpymem (p, sp2->data, sp2->len); 353 | } 354 | 355 | sp2++; 356 | } 357 | } 358 | 359 | *p = '\0'; 360 | 361 | return dest->data; 362 | } 363 | 364 | 365 | u_char * 366 | ndk_catstrf (ngx_pool_t *pool, ngx_str_t *dest, const char *fmt, ...) 367 | { 368 | u_char *p; 369 | va_list args; 370 | 371 | va_start (args, fmt); 372 | p = ndk_vcatstrf (pool, dest, fmt, args); 373 | va_end (args); 374 | 375 | return p; 376 | } 377 | 378 | 379 | ngx_int_t 380 | ndk_cmpstr (ngx_str_t *s1, ngx_str_t *s2) 381 | { 382 | ngx_int_t rv; 383 | size_t len1, len2; 384 | 385 | len1 = s1->len; 386 | len2 = s2->len; 387 | 388 | if (len1 == len2) { 389 | return ngx_strncmp (s1->data, s2->data, len1); 390 | } 391 | 392 | if (len1 > len2) { 393 | 394 | rv = ngx_strncmp (s1->data, s2->data, len2); 395 | if (rv == 0) 396 | return 1; 397 | 398 | return rv; 399 | } 400 | 401 | rv = ngx_strncmp (s1->data, s2->data, len1); 402 | if (rv == 0) 403 | return -1; 404 | 405 | return rv; 406 | } 407 | 408 | 409 | u_char * 410 | ndk_dupstr (ngx_pool_t *pool, ngx_str_t *dest, ngx_str_t *src) 411 | { 412 | u_char *d; 413 | size_t n; 414 | 415 | n = src->len; 416 | 417 | ndk_palloc_rn (d, pool, n + 1); 418 | ndk_strncpy (d, src->data, n); 419 | 420 | dest->data = d; 421 | dest->len = n; 422 | 423 | return d; 424 | } 425 | 426 | /* 427 | ngx_keyval_t * 428 | ndk_url_args_to_keyval_list (ngx_pool_t *pool, ngx_str_t *str) 429 | { 430 | ngx_keyval_t *kv; 431 | ngx_st 432 | 433 | } 434 | */ 435 | -------------------------------------------------------------------------------- /src/ndk_conf_file.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* NOTE : you will find other conf_set functions in the following files : 4 | * 5 | * complex_value.c 6 | * encoding.c 7 | * path.c 8 | * 9 | */ 10 | 11 | 12 | char * 13 | ndk_conf_set_true_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 14 | { 15 | char *p = conf; 16 | 17 | ngx_flag_t *fp; 18 | ngx_conf_post_t *post; 19 | 20 | fp = (ngx_flag_t*) (p + cmd->offset); 21 | 22 | if (*fp != NGX_CONF_UNSET) { 23 | return "is duplicate"; 24 | } 25 | 26 | *fp = 1; 27 | 28 | if (cmd->post) { 29 | post = cmd->post; 30 | return post->post_handler (cf, post, fp); 31 | } 32 | 33 | return NGX_CONF_OK; 34 | } 35 | 36 | 37 | 38 | char * 39 | ndk_conf_set_false_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 40 | { 41 | char *p = conf; 42 | 43 | ngx_flag_t *fp; 44 | ngx_conf_post_t *post; 45 | 46 | fp = (ngx_flag_t*) (p + cmd->offset); 47 | 48 | if (*fp != NGX_CONF_UNSET) { 49 | return "is duplicate"; 50 | } 51 | 52 | *fp = 0; 53 | 54 | if (cmd->post) { 55 | post = cmd->post; 56 | return post->post_handler (cf, post, fp); 57 | } 58 | 59 | return NGX_CONF_OK; 60 | } 61 | 62 | 63 | 64 | 65 | char * 66 | ndk_conf_set_ptr_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 67 | { 68 | char *p = conf; 69 | 70 | void **ptr; 71 | 72 | ptr = (void**) (p + cmd->offset); 73 | 74 | if (*ptr != NGX_CONF_UNSET_PTR) { 75 | return "is duplicate"; 76 | } 77 | 78 | *ptr = cmd->post; 79 | 80 | return NGX_CONF_OK; 81 | } 82 | 83 | 84 | 85 | char * 86 | ndk_conf_set_null_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 87 | { 88 | char *p = conf; 89 | 90 | void **pp; 91 | ngx_conf_post_t *post; 92 | 93 | pp = (void **) (p + cmd->offset); 94 | 95 | if (*pp != NGX_CONF_UNSET_PTR) { 96 | return "is duplicate"; 97 | } 98 | 99 | *pp = NULL; 100 | 101 | if (cmd->post) { 102 | post = cmd->post; 103 | return post->post_handler (cf, post, pp); 104 | } 105 | 106 | return NGX_CONF_OK; 107 | } 108 | 109 | 110 | char * 111 | ndk_conf_set_num64_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 112 | { 113 | char *p = conf; 114 | 115 | int64_t *np; 116 | ngx_str_t *value; 117 | ngx_conf_post_t *post; 118 | 119 | 120 | np = (int64_t *) (p + cmd->offset); 121 | 122 | if (*np != NGX_CONF_UNSET) { 123 | return "is duplicate"; 124 | } 125 | 126 | value = cf->args->elts; 127 | *np = ndk_atoi64 (value[1].data, value[1].len); 128 | if (*np == NGX_ERROR) { 129 | return "invalid number"; 130 | } 131 | 132 | if (cmd->post) { 133 | post = cmd->post; 134 | return post->post_handler(cf, post, np); 135 | } 136 | 137 | return NGX_CONF_OK; 138 | } 139 | 140 | 141 | char * 142 | ndk_conf_set_str_array_multi_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 143 | { 144 | char *p = conf; 145 | 146 | ngx_str_t *value, *s; 147 | ngx_array_t **a; 148 | ngx_conf_post_t *post; 149 | ngx_uint_t i; 150 | 151 | a = (ngx_array_t **) (p + cmd->offset); 152 | 153 | if (*a == NGX_CONF_UNSET_PTR) { 154 | *a = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t)); 155 | if (*a == NULL) { 156 | return NGX_CONF_ERROR; 157 | } 158 | } 159 | 160 | s = NULL; 161 | 162 | for (i=cf->args->nelts-1; i; i--) { 163 | 164 | s = ngx_array_push(*a); 165 | if (s == NULL) { 166 | return NGX_CONF_ERROR; 167 | } 168 | 169 | value = cf->args->elts; 170 | 171 | *s = value[i]; 172 | } 173 | 174 | if (cmd->post) { 175 | post = cmd->post; 176 | return post->post_handler(cf, post, s); 177 | } 178 | 179 | return NGX_CONF_OK; 180 | } 181 | 182 | 183 | 184 | char * 185 | ndk_conf_set_keyval1_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 186 | { 187 | char *p = conf; 188 | 189 | ngx_str_t *value; 190 | ngx_keyval_t *kv; 191 | ngx_conf_post_t *post; 192 | 193 | kv = (ngx_keyval_t *) (p + cmd->offset); 194 | 195 | if (kv->key.data) 196 | return "is duplicate"; 197 | 198 | value = cf->args->elts; 199 | 200 | kv->key = value[1]; 201 | kv->value = value[2]; 202 | 203 | if (cmd->post) { 204 | post = cmd->post; 205 | return post->post_handler (cf, post, kv); 206 | } 207 | 208 | return NGX_CONF_OK; 209 | } 210 | 211 | 212 | 213 | char * 214 | ndk_conf_set_num_flag_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 215 | { 216 | char *p = conf; 217 | 218 | ngx_int_t *np; 219 | ngx_str_t *value; 220 | ngx_conf_post_t *post; 221 | 222 | np = (ngx_int_t *) (p + cmd->offset); 223 | 224 | if (*np != NGX_CONF_UNSET) { 225 | return "is duplicate"; 226 | } 227 | 228 | value = cf->args->elts; 229 | 230 | if (ngx_strcasecmp (value[1].data, (u_char *) "on") == 0) { 231 | *np = NDK_CONF_SET_TRUE; 232 | 233 | } else if (ngx_strcasecmp (value[1].data, (u_char *) "off") == 0) { 234 | *np = NDK_CONF_SET_FALSE; 235 | 236 | } else { 237 | *np = ngx_atoi (value[1].data, value[1].len); 238 | if (*np == NGX_ERROR) { 239 | return "invalid number and not 'on'/'off'"; 240 | } 241 | } 242 | 243 | if (cmd->post) { 244 | post = cmd->post; 245 | return post->post_handler (cf, post, np); 246 | } 247 | 248 | return NGX_CONF_OK; 249 | } 250 | 251 | 252 | 253 | char * 254 | ndk_conf_set_sec_flag_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 255 | { 256 | char *p = conf; 257 | 258 | time_t *tp; 259 | ngx_str_t *value; 260 | ngx_conf_post_t *post; 261 | 262 | tp = (time_t *) (p + cmd->offset); 263 | 264 | if (*tp != NGX_CONF_UNSET) { 265 | return "is duplicate"; 266 | } 267 | 268 | value = cf->args->elts; 269 | 270 | if (ngx_strcasecmp (value[1].data, (u_char *) "on") == 0) { 271 | *tp = NDK_CONF_SET_TRUE; 272 | 273 | } else if (ngx_strcasecmp (value[1].data, (u_char *) "off") == 0) { 274 | *tp = NDK_CONF_SET_FALSE; 275 | 276 | } else { 277 | *tp = ngx_parse_time (&value[1], 1); 278 | if (*tp == NGX_ERROR) { 279 | return "has an invalid time and not 'on'/'off'"; 280 | } 281 | } 282 | 283 | if (cmd->post) { 284 | post = cmd->post; 285 | return post->post_handler (cf, post, tp); 286 | } 287 | 288 | return NGX_CONF_OK; 289 | } 290 | 291 | 292 | 293 | ngx_http_conf_ctx_t * 294 | ndk_conf_create_http_location (ngx_conf_t *cf) 295 | { 296 | ngx_http_conf_ctx_t *ctx, *pctx; 297 | void *mconf; 298 | ngx_http_core_loc_conf_t *clcf, *pclcf; 299 | ngx_uint_t i; 300 | ngx_http_module_t *module; 301 | 302 | ndk_pcallocp_rce (ctx, cf->pool); 303 | 304 | pctx = cf->ctx; 305 | ctx->main_conf = pctx->main_conf; 306 | ctx->srv_conf = pctx->srv_conf; 307 | 308 | ndk_pcalloc_rce (ctx->loc_conf, cf->pool, sizeof(void *) * ngx_http_max_module); 309 | 310 | 311 | for (i = 0; ngx_modules[i]; i++) { 312 | if (ngx_modules[i]->type != NGX_HTTP_MODULE) { 313 | continue; 314 | } 315 | 316 | module = ngx_modules[i]->ctx; 317 | 318 | if (module->create_loc_conf) { 319 | 320 | mconf = module->create_loc_conf(cf); 321 | if (mconf == NULL) { 322 | return NGX_CONF_ERROR; 323 | } 324 | 325 | ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf; 326 | } 327 | } 328 | 329 | pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index]; 330 | 331 | clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; 332 | clcf->loc_conf = ctx->loc_conf; 333 | clcf->name = pclcf->name; 334 | clcf->noname = 1; 335 | 336 | if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) { 337 | return NGX_CONF_ERROR; 338 | } 339 | 340 | return ctx; 341 | } 342 | 343 | 344 | ngx_http_conf_ctx_t * 345 | ngx_conf_create_http_named_location (ngx_conf_t *cf, ngx_str_t *name) 346 | { 347 | ngx_http_conf_ctx_t *ctx; 348 | ngx_http_core_loc_conf_t *clcf; 349 | 350 | ctx = ndk_conf_create_http_location (cf); 351 | if (ctx == NGX_CONF_ERROR) 352 | return NGX_CONF_ERROR; 353 | 354 | clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; 355 | 356 | /* in case the developer forgets to add '@' at the beginning of the named location */ 357 | 358 | if (name->data[0] != '@' && ndk_catstrf (cf->pool, name, "sS", "@", name) == NULL) 359 | return NGX_CONF_ERROR; 360 | 361 | clcf->name = *name; /* TODO : copy? */ 362 | clcf->noname = 0; 363 | clcf->named = 1; 364 | 365 | return ctx; 366 | } 367 | 368 | 369 | ngx_int_t 370 | ndk_replace_command (ngx_command_t *new_cmd, ngx_uint_t module_type) 371 | { 372 | ngx_uint_t i; 373 | ngx_command_t *cmd; 374 | 375 | for (i = 0; ngx_modules[i]; i++) { 376 | 377 | if (ngx_modules[i]->type != module_type) 378 | continue; 379 | 380 | cmd = ngx_modules[i]->commands; 381 | if (cmd == NULL) { 382 | continue; 383 | } 384 | 385 | for ( /* void */ ; cmd->name.len; cmd++) { 386 | 387 | if (ndk_cmpstr (&new_cmd->name, &cmd->name) == 0) { 388 | 389 | ndk_memcpyp (cmd, new_cmd); 390 | return NGX_OK; 391 | } 392 | } 393 | } 394 | 395 | return NGX_DECLINED; 396 | } 397 | -------------------------------------------------------------------------------- /src/ndk_log.h: -------------------------------------------------------------------------------- 1 | 2 | /* TODO : fix the conf_log macros */ 3 | 4 | #define NGX_LOG_DEBUG_SCRIPT NGX_LOG_DEBUG_HTTP /* TODO : add new section to log/conf directives */ 5 | 6 | #define ndk_conf_to_log(cf) ((cf)->log) 7 | 8 | #ifndef ndk_request_to_log 9 | #define ndk_request_to_log(r) ((r)->connection->log) 10 | #endif 11 | 12 | 13 | /*********************************/ 14 | 15 | #if (NGX_HAVE_C99_VARIADIC_MACROS) 16 | 17 | #define ndk_log_stderr(log,...) ngx_log_error (NGX_LOG_STDERR, log, 0, __VA_ARGS__) 18 | #define ndk_log_emerg(log,...) ngx_log_error (NGX_LOG_EMERG, log, 0, __VA_ARGS__) 19 | #define ndk_log_alert(log,...) ngx_log_error (NGX_LOG_ALERT, log, 0, __VA_ARGS__) 20 | #define ndk_log_crit(log,...) ngx_log_error (NGX_LOG_CRIT, log, 0, __VA_ARGS__) 21 | #define ndk_log_err(log,...) ngx_log_error (NGX_LOG_ERR, log, 0, __VA_ARGS__) 22 | #define ndk_log_warning(log,...) ngx_log_error (NGX_LOG_WARN, log, 0, __VA_ARGS__) 23 | #define ndk_log_notice(log,...) ngx_log_error (NGX_LOG_NOTICE, log, 0, __VA_ARGS__) 24 | #define ndk_log_info(log,...) ngx_log_error (NGX_LOG_INFO, log, 0, __VA_ARGS__) 25 | 26 | #define ndk_conf_log_stderr(cf,...) ngx_conf_log_error (NGX_LOG_STDERR, cf, 0, __VA_ARGS__) 27 | #define ndk_conf_log_emerg(cf,...) ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, __VA_ARGS__) 28 | #define ndk_conf_log_alert(cf,...) ngx_conf_log_error (NGX_LOG_ALERT, cf, 0, __VA_ARGS__) 29 | #define ndk_conf_log_crit(cf,...) ngx_conf_log_error (NGX_LOG_CRIT, cf, 0, __VA_ARGS__) 30 | #define ndk_conf_log_err(cf,...) ngx_conf_log_error (NGX_LOG_ERR, cf, 0, __VA_ARGS__) 31 | #define ndk_conf_log_warning(cf,...) ngx_conf_log_error (NGX_LOG_WARN, cf, 0, __VA_ARGS__) 32 | #define ndk_conf_log_notice(cf,...) ngx_conf_log_error (NGX_LOG_NOTICE, cf, 0, __VA_ARGS__) 33 | #define ndk_conf_log_info(cf,...) ngx_conf_log_error (NGX_LOG_INFO, cf, 0, __VA_ARGS__) 34 | 35 | #define ndk_request_log_stderr(r,...) ndk_log_stderr (ndk_request_to_log(r), __VA_ARGS__) 36 | #define ndk_request_log_emerg(r,...) ndk_log_emerg (ndk_request_to_log(r), __VA_ARGS__) 37 | #define ndk_request_log_alert(r,...) ndk_log_alert (ndk_request_to_log(r), __VA_ARGS__) 38 | #define ndk_request_log_crit(r,...) ndk_log_crit (ndk_request_to_log(r), __VA_ARGS__) 39 | #define ndk_request_log_err(r,...) ndk_log_err (ndk_request_to_log(r), __VA_ARGS__) 40 | #define ndk_request_log_warning(r,...) ndk_log_warning (ndk_request_to_log(r), __VA_ARGS__) 41 | #define ndk_request_log_notice(r,...) ndk_log_notice (ndk_request_to_log(r), __VA_ARGS__) 42 | #define ndk_request_log_info(r,...) ndk_log_info (ndk_request_to_log(r), __VA_ARGS__) 43 | 44 | 45 | #if (NGX_DEBUG) 46 | 47 | #define ndk_log_debug_core(log,...) ngx_log_debug (NGX_LOG_DEBUG_CORE, log, 0, __VA_ARGS__) 48 | #define ndk_log_debug_alloc(log,...) ngx_log_debug (NGX_LOG_DEBUG_ALLOC, log, 0, __VA_ARGS__) 49 | #define ndk_log_debug_mutex(log,...) ngx_log_debug (NGX_LOG_DEBUG_MUTEX, log, 0, __VA_ARGS__) 50 | #define ndk_log_debug_event(log,...) ngx_log_debug (NGX_LOG_DEBUG_EVENT, log, 0, __VA_ARGS__) 51 | #define ndk_log_debug_http(log,...) ngx_log_debug (NGX_LOG_DEBUG_HTTP, log, 0, __VA_ARGS__) 52 | #define ndk_log_debug_mail(log,...) ngx_log_debug (NGX_LOG_DEBUG_MAIL, log, 0, __VA_ARGS__) 53 | #define ndk_log_debug_mysql(log,...) ngx_log_debug (NGX_LOG_DEBUG_MYSQL, log, 0, __VA_ARGS__) 54 | 55 | #define ndk_conf_log_debug_core(r,...) ndk_log_debug_core (ndk_conf_to_log(r), __VA_ARGS__) 56 | #define ndk_conf_log_debug_alloc(r,...) ndk_log_debug_alloc (ndk_conf_to_log(r), __VA_ARGS__) 57 | #define ndk_conf_log_debug_mutex(r,...) ndk_log_debug_mutex (ndk_conf_to_log(r), __VA_ARGS__) 58 | #define ndk_conf_log_debug_event(r,...) ndk_log_debug_event (ndk_conf_to_log(r), __VA_ARGS__) 59 | #define ndk_conf_log_debug_http(r,...) ndk_log_debug_http (ndk_conf_to_log(r), __VA_ARGS__) 60 | #define ndk_conf_log_debug_mail(r,...) ndk_log_debug_mail (ndk_conf_to_log(r), __VA_ARGS__) 61 | #define ndk_conf_log_debug_mysql(r,...) ndk_log_debug_mysql (ndk_conf_to_log(r), __VA_ARGS__) 62 | 63 | #define ndk_request_log_debug_core(r,...) ndk_log_debug_core (ndk_request_to_log(r), __VA_ARGS__) 64 | #define ndk_request_log_debug_alloc(r,...) ndk_log_debug_alloc (ndk_request_to_log(r), __VA_ARGS__) 65 | #define ndk_request_log_debug_mutex(r,...) ndk_log_debug_mutex (ndk_request_to_log(r), __VA_ARGS__) 66 | #define ndk_request_log_debug_event(r,...) ndk_log_debug_event (ndk_request_to_log(r), __VA_ARGS__) 67 | #define ndk_request_log_debug_http(r,...) ndk_log_debug_http (ndk_request_to_log(r), __VA_ARGS__) 68 | #define ndk_request_log_debug_mail(r,...) ndk_log_debug_mail (ndk_request_to_log(r), __VA_ARGS__) 69 | #define ndk_request_log_debug_mysql(r,...) ndk_log_debug_mysql (ndk_request_to_log(r), __VA_ARGS__) 70 | 71 | #else 72 | 73 | #define ndk_log_debug_core(log,...) 74 | #define ndk_log_debug_alloc(log,...) 75 | #define ndk_log_debug_mutex(log,...) 76 | #define ndk_log_debug_event(log,...) 77 | #define ndk_log_debug_http(log,...) 78 | #define ndk_log_debug_mail(log,...) 79 | #define ndk_log_debug_mysql(log,...) 80 | 81 | #define ndk_conf_log_debug_core(r,...) 82 | #define ndk_conf_log_debug_alloc(r,...) 83 | #define ndk_conf_log_debug_mutex(r,...) 84 | #define ndk_conf_log_debug_event(r,...) 85 | #define ndk_conf_log_debug_http(r,...) 86 | #define ndk_conf_log_debug_mail(r,...) 87 | #define ndk_conf_log_debug_mysql(r,...) 88 | 89 | #define ndk_request_log_debug_core(r,...) 90 | #define ndk_request_log_debug_alloc(r,...) 91 | #define ndk_request_log_debug_mutex(r,...) 92 | #define ndk_request_log_debug_event(r,...) 93 | #define ndk_request_log_debug_http(r,...) 94 | #define ndk_request_log_debug_mail(r,...) 95 | #define ndk_request_log_debug_mysql(r,...) 96 | 97 | #endif 98 | 99 | 100 | /*********************************/ 101 | 102 | #elif (NGX_HAVE_GCC_VARIADIC_MACROS) 103 | 104 | #define ndk_log_stderr(log,args...) ngx_log_error (NGX_LOG_STDERR, log, 0, args) 105 | #define ndk_log_emerg(log,args...) ngx_log_error (NGX_LOG_EMERG, log, 0, args) 106 | #define ndk_log_alert(log,args...) ngx_log_error (NGX_LOG_ALERT, log, 0, args) 107 | #define ndk_log_crit(log,args...) ngx_log_error (NGX_LOG_CRIT, log, 0, args) 108 | #define ndk_log_err(log,args...) ngx_log_error (NGX_LOG_ERR, log, 0, args) 109 | #define ndk_log_warning(log,args...) ngx_log_error (NGX_LOG_WARN, log, 0, args) 110 | #define ndk_log_notice(log,args...) ngx_log_error (NGX_LOG_NOTICE, log, 0, args) 111 | #define ndk_log_info(log,args...) ngx_log_error (NGX_LOG_INFO, log, 0, args) 112 | 113 | #define ndk_log_debug_core(log,args...) ngx_log_debug (NGX_LOG_DEBUG_CORE, log, 0, args) 114 | #define ndk_log_debug_alloc(log,args...) ngx_log_debug (NGX_LOG_DEBUG_ALLOC, log, 0, args) 115 | #define ndk_log_debug_mutex(log,args...) ngx_log_debug (NGX_LOG_DEBUG_MUTEX, log, 0, args) 116 | #define ndk_log_debug_event(log,args...) ngx_log_debug (NGX_LOG_DEBUG_EVENT, log, 0, args) 117 | #define ndk_log_debug_http(log,args...) ngx_log_debug (NGX_LOG_DEBUG_HTTP, log, 0, args) 118 | #define ndk_log_debug_mail(log,args...) ngx_log_debug (NGX_LOG_DEBUG_MAIL, log, 0, args) 119 | #define ndk_log_debug_mysql(log,args...) ngx_log_debug (NGX_LOG_DEBUG_MYSQL, log, 0, args) 120 | #define ndk_log_debug_script(log,args...) ngx_log_debug (NGX_LOG_DEBUG_SCRIPT, log, 0, args) 121 | 122 | #define ndk_conf_log_stderr(cf,args...) ngx_conf_log_error (NGX_LOG_STDERR, cf, 0, args) 123 | #define ndk_conf_log_emerg(cf,args...) ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, args) 124 | #define ndk_conf_log_alert(cf,args...) ngx_conf_log_error (NGX_LOG_ALERT, cf, 0, args) 125 | #define ndk_conf_log_crit(cf,args...) ngx_conf_log_error (NGX_LOG_CRIT, cf, 0, args) 126 | #define ndk_conf_log_err(cf,args...) ngx_conf_log_error (NGX_LOG_ERR, cf, 0, args) 127 | #define ndk_conf_log_warning(cf,args...) ngx_conf_log_error (NGX_LOG_WARN, cf, 0, args) 128 | #define ndk_conf_log_notice(cf,args...) ngx_conf_log_error (NGX_LOG_NOTICE, cf, 0, args) 129 | #define ndk_conf_log_info(cf,args...) ngx_conf_log_error (NGX_LOG_INFO, cf, 0, args) 130 | 131 | #define ndk_conf_log_debug_core(r,args...) ndk_log_debug_core (ndk_conf_to_log(r), args) 132 | #define ndk_conf_log_debug_alloc(r,args...) ndk_log_debug_alloc (ndk_conf_to_log(r), args) 133 | #define ndk_conf_log_debug_mutex(r,args...) ndk_log_debug_mutex (ndk_conf_to_log(r), args) 134 | #define ndk_conf_log_debug_event(r,args...) ndk_log_debug_event (ndk_conf_to_log(r), args) 135 | #define ndk_conf_log_debug_http(r,args...) ndk_log_debug_http (ndk_conf_to_log(r), args) 136 | #define ndk_conf_log_debug_mail(r,args...) ndk_log_debug_mail (ndk_conf_to_log(r), args) 137 | #define ndk_conf_log_debug_mysql(r,args...) ndk_log_debug_mysql (ndk_conf_to_log(r), args) 138 | #define ndk_conf_log_debug_script(r,args...) ndk_log_debug_script (ndk_conf_to_log(r), args) 139 | 140 | #define ndk_request_log_stderr(r,args...) ndk_log_stderr (ndk_request_to_log(r), args) 141 | #define ndk_request_log_emerg(r,args...) ndk_log_emerg (ndk_request_to_log(r), args) 142 | #define ndk_request_log_alert(r,args...) ndk_log_alert (ndk_request_to_log(r), args) 143 | #define ndk_request_log_crit(r,args...) ndk_log_crit (ndk_request_to_log(r), args) 144 | #define ndk_request_log_err(r,args...) ndk_log_err (ndk_request_to_log(r), args) 145 | #define ndk_request_log_warning(r,args...) ndk_log_warning (ndk_request_to_log(r), args) 146 | #define ndk_request_log_notice(r,args...) ndk_log_notice (ndk_request_to_log(r), args) 147 | #define ndk_request_log_info(r,args...) ndk_log_info (ndk_request_to_log(r), args) 148 | 149 | #define ndk_request_log_debug_core(r,args...) ndk_log_debug_core (ndk_request_to_log(r), args) 150 | #define ndk_request_log_debug_alloc(r,args...) ndk_log_debug_alloc (ndk_request_to_log(r), args) 151 | #define ndk_request_log_debug_mutex(r,args...) ndk_log_debug_mutex (ndk_request_to_log(r), args) 152 | #define ndk_request_log_debug_event(r,args...) ndk_log_debug_event (ndk_request_to_log(r), args) 153 | #define ndk_request_log_debug_http(r,args...) ndk_log_debug_http (ndk_request_to_log(r), args) 154 | #define ndk_request_log_debug_mail(r,args...) ndk_log_debug_mail (ndk_request_to_log(r), args) 155 | #define ndk_request_log_debug_mysql(r,args...) ndk_log_debug_mysql (ndk_request_to_log(r), args) 156 | #define ndk_request_log_debug_script(r,args...) ndk_log_debug_script (ndk_request_to_log(r), args) 157 | 158 | /*********************************/ 159 | 160 | #else /* NO VARIADIC MACROS */ 161 | 162 | /* #warning does not work on Windows */ 163 | #pragma message("Nginx Devel Kit logging without variadic macros not yet implemented") 164 | 165 | #endif /* VARIADIC MACROS */ 166 | -------------------------------------------------------------------------------- /objs/ndk_conf_merge.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | * 5 | * DO NOT EDIT THIS FILE MANUALLY 6 | * ------------------------------ 7 | * This file has been generated automatically from scripts in the $base/auto dir and 8 | * data in the $base/auto/data dir. If you wish to edit the output of this file, then 9 | * you should edit these files instead. 10 | * 11 | */ 12 | 13 | 14 | /* conf-merge-value macros */ 15 | 16 | /* TODO : check that all the main types have a corresponding merge function */ 17 | 18 | #define ndk_conf_merge_value ngx_conf_merge_value 19 | #define ndk_conf_merge_off_value ngx_conf_merge_off_value 20 | #define ndk_conf_merge_ptr_value ngx_conf_merge_ptr_value 21 | #define ndk_conf_merge_str_value ngx_conf_merge_str_value 22 | #define ndk_conf_merge_size_value ngx_conf_merge_size_value 23 | 24 | 25 | #define ndk_conf_merge_keyval_value(conf,prev,default) \ 26 | \ 27 | conf = prev ? prev : default; 28 | 29 | #define ndk_conf_merge_str_array_value(conf,prev,val1,...) \ 30 | \ 31 | if (conf == NGX_CONF_UNSET_PTR) { \ 32 | if (prev == NGX_CONF_UNSET_PTR) { \ 33 | if (val1 == NULL) { \ 34 | conf = NULL; \ 35 | } else { \ 36 | char * elts[] = {val1,##__VA_ARGS__}; \ 37 | int n = sizeof(elts)/sizeof(char*); \ 38 | \ 39 | conf = ndk_str_array_create (cf->pool, elts, n); \ 40 | \ 41 | if (conf == NULL) \ 42 | return NGX_CONF_ERROR; \ 43 | } \ 44 | } else { \ 45 | conf = prev; \ 46 | } \ 47 | } 48 | 49 | #define ndk_conf_merge_http_complex_value_value(conf,prev,default) \ 50 | \ 51 | if (!conf.str.len) { \ 52 | if (prev.str.len) { \ 53 | conf = prev; \ 54 | } else { \ 55 | conf.str.data = (u_char *) default; \ 56 | conf.str.len = sizeof (default) - 1; \ 57 | \ 58 | if (ndk_http_complex_value_compile (cf, &conf)) \ 59 | return NGX_CONF_ERROR; \ 60 | } \ 61 | } 62 | 63 | #define ndk_conf_merge_http_complex_value_array_value(conf,prev,val1,...) \ 64 | \ 65 | if (conf == NGX_CONF_UNSET_PTR) { \ 66 | if (prev == NGX_CONF_UNSET_PTR) { \ 67 | if (val1 == NULL) \ 68 | conf = NULL; \ 69 | else { \ 70 | char * elts[] = {val1,##__VA_ARGS__}; \ 71 | int n = sizeof(elts)/sizeof(char*); \ 72 | \ 73 | conf = ndk_http_complex_value_array_create (cf, elts, n); \ 74 | \ 75 | if (conf == NULL) \ 76 | return NGX_CONF_ERROR; \ 77 | } \ 78 | } else { \ 79 | conf = prev; \ 80 | } \ 81 | } 82 | 83 | #define ndk_conf_merge_http_complex_path_value(conf,prev,...) \ 84 | ndk_conf_merge_http_complex_value_array_value (conf.a, prev.a, __VA_ARGS__) 85 | 86 | #define ndk_conf_merge_split_path_value(conf,prev,path) \ 87 | \ 88 | if (conf == NGX_CONF_UNSET_PTR) { \ 89 | conf = (prev == NGX_CONF_UNSET_PTR ? \ 90 | ndk_split_path_create_raw (cf, path) : prev); \ 91 | } 92 | 93 | 94 | /* conf-merge-prop macros */ 95 | 96 | #define ndk_conf_merge_prop(prop,default)\ 97 | ndk_conf_merge_value\ 98 | (conf->prop, prev->prop, default) 99 | 100 | #define ndk_conf_merge_bitmask_prop(prop,default,...)\ 101 | ndk_conf_merge_bitmask_value\ 102 | (conf->prop, prev->prop, default,##__VA_ARGS__) 103 | 104 | #define ndk_conf_merge_bufs_prop(prop,default,...)\ 105 | ndk_conf_merge_bufs_value\ 106 | (conf->prop, prev->prop, default,##__VA_ARGS__) 107 | 108 | #define ndk_conf_merge_encoding_prop(prop,default,...)\ 109 | ndk_conf_merge_encoding_value\ 110 | (conf->prop, prev->prop, default,##__VA_ARGS__) 111 | 112 | #define ndk_conf_merge_enum_prop(prop,default,...)\ 113 | ndk_conf_merge_enum_value\ 114 | (conf->prop, prev->prop, default,##__VA_ARGS__) 115 | 116 | #define ndk_conf_merge_false_prop(prop,default,...)\ 117 | ndk_conf_merge_false_value\ 118 | (conf->prop, prev->prop, default,##__VA_ARGS__) 119 | 120 | #define ndk_conf_merge_flag_prop(prop,default,...)\ 121 | ndk_conf_merge_flag_value\ 122 | (conf->prop, prev->prop, default,##__VA_ARGS__) 123 | 124 | #define ndk_conf_merge_full_path_prop(prop,default,...)\ 125 | ndk_conf_merge_full_path_value\ 126 | (conf->prop, prev->prop, default,##__VA_ARGS__) 127 | 128 | #define ndk_conf_merge_http_complex_keyval_prop(prop,default,...)\ 129 | ndk_conf_merge_http_complex_keyval_value\ 130 | (conf->prop, prev->prop, default,##__VA_ARGS__) 131 | 132 | #define ndk_conf_merge_http_complex_path_prop(prop,default,...)\ 133 | ndk_conf_merge_http_complex_path_value\ 134 | (conf->prop, prev->prop, default,##__VA_ARGS__) 135 | 136 | #define ndk_conf_merge_http_complex_value_prop(prop,default,...)\ 137 | ndk_conf_merge_http_complex_value_value\ 138 | (conf->prop, prev->prop, default,##__VA_ARGS__) 139 | 140 | #define ndk_conf_merge_http_complex_value_array_prop(prop,default,...)\ 141 | ndk_conf_merge_http_complex_value_array_value\ 142 | (conf->prop, prev->prop, default,##__VA_ARGS__) 143 | 144 | #define ndk_conf_merge_keyval_prop(prop,default,...)\ 145 | ndk_conf_merge_keyval_value\ 146 | (conf->prop, prev->prop, default,##__VA_ARGS__) 147 | 148 | #define ndk_conf_merge_keyval1_prop(prop,default,...)\ 149 | ndk_conf_merge_keyval1_value\ 150 | (conf->prop, prev->prop, default,##__VA_ARGS__) 151 | 152 | #define ndk_conf_merge_msec_prop(prop,default,...)\ 153 | ndk_conf_merge_msec_value\ 154 | (conf->prop, prev->prop, default,##__VA_ARGS__) 155 | 156 | #define ndk_conf_merge_null_prop(prop,default,...)\ 157 | ndk_conf_merge_null_value\ 158 | (conf->prop, prev->prop, default,##__VA_ARGS__) 159 | 160 | #define ndk_conf_merge_num_prop(prop,default,...)\ 161 | ndk_conf_merge_num_value\ 162 | (conf->prop, prev->prop, default,##__VA_ARGS__) 163 | 164 | #define ndk_conf_merge_num64_prop(prop,default,...)\ 165 | ndk_conf_merge_num64_value\ 166 | (conf->prop, prev->prop, default,##__VA_ARGS__) 167 | 168 | #define ndk_conf_merge_num_flag_prop(prop,default,...)\ 169 | ndk_conf_merge_num_flag_value\ 170 | (conf->prop, prev->prop, default,##__VA_ARGS__) 171 | 172 | #define ndk_conf_merge_off_prop(prop,default,...)\ 173 | ndk_conf_merge_off_value\ 174 | (conf->prop, prev->prop, default,##__VA_ARGS__) 175 | 176 | #define ndk_conf_merge_ptr_prop(prop,default,...)\ 177 | ndk_conf_merge_ptr_value\ 178 | (conf->prop, prev->prop, default,##__VA_ARGS__) 179 | 180 | #define ndk_conf_merge_regex_prop(prop,default,...)\ 181 | ndk_conf_merge_regex_value\ 182 | (conf->prop, prev->prop, default,##__VA_ARGS__) 183 | 184 | #define ndk_conf_merge_regex_array_prop(prop,default,...)\ 185 | ndk_conf_merge_regex_array_value\ 186 | (conf->prop, prev->prop, default,##__VA_ARGS__) 187 | 188 | #define ndk_conf_merge_regex_array_caseless_prop(prop,default,...)\ 189 | ndk_conf_merge_regex_array_caseless_value\ 190 | (conf->prop, prev->prop, default,##__VA_ARGS__) 191 | 192 | #define ndk_conf_merge_regex_caseless_prop(prop,default,...)\ 193 | ndk_conf_merge_regex_caseless_value\ 194 | (conf->prop, prev->prop, default,##__VA_ARGS__) 195 | 196 | #define ndk_conf_merge_sec_prop(prop,default,...)\ 197 | ndk_conf_merge_sec_value\ 198 | (conf->prop, prev->prop, default,##__VA_ARGS__) 199 | 200 | #define ndk_conf_merge_sec_flag_prop(prop,default,...)\ 201 | ndk_conf_merge_sec_flag_value\ 202 | (conf->prop, prev->prop, default,##__VA_ARGS__) 203 | 204 | #define ndk_conf_merge_size_prop(prop,default,...)\ 205 | ndk_conf_merge_size_value\ 206 | (conf->prop, prev->prop, default,##__VA_ARGS__) 207 | 208 | #define ndk_conf_merge_split_path_prop(prop,default,...)\ 209 | ndk_conf_merge_split_path_value\ 210 | (conf->prop, prev->prop, default,##__VA_ARGS__) 211 | 212 | #define ndk_conf_merge_str_prop(prop,default,...)\ 213 | ndk_conf_merge_str_value\ 214 | (conf->prop, prev->prop, default,##__VA_ARGS__) 215 | 216 | #define ndk_conf_merge_str_array_prop(prop,default,...)\ 217 | ndk_conf_merge_str_array_value\ 218 | (conf->prop, prev->prop, default,##__VA_ARGS__) 219 | 220 | #define ndk_conf_merge_str_array_multi_prop(prop,default,...)\ 221 | ndk_conf_merge_str_array_multi_value\ 222 | (conf->prop, prev->prop, default,##__VA_ARGS__) 223 | 224 | #define ndk_conf_merge_true_prop(prop,default,...)\ 225 | ndk_conf_merge_true_value\ 226 | (conf->prop, prev->prop, default,##__VA_ARGS__) 227 | 228 | -------------------------------------------------------------------------------- /src/ndk_path.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /* This function cleans a path to its most basic form, performing the following transformations : 5 | * 6 | * - ./ -> [empty] 7 | * - // -> / 8 | * - /base/parent/../ -> /base/ 9 | * 10 | * If possible, it leaves the original string in place and does not copy characters, otherwise 11 | * characters are copied. 12 | */ 13 | 14 | void 15 | ndk_clean_path (ngx_str_t *path, ngx_uint_t complex, size_t off) 16 | { 17 | u_char *s, *p, *m, *e, c, *l; 18 | ngx_uint_t root; 19 | 20 | if (path->len == 1) { 21 | 22 | if (path->data[0] == '.') { 23 | path->len = 0; 24 | } 25 | 26 | return; 27 | } 28 | 29 | /* strip initial './' */ 30 | 31 | s = path->data; 32 | e = s + path->len; 33 | 34 | if (off) { 35 | p = s + off; 36 | goto check_basic; 37 | } 38 | 39 | if (*s == '/') 40 | root = 1; 41 | else 42 | root = 0; 43 | 44 | while (s < e) { 45 | 46 | switch (*s) { 47 | 48 | case '/' : 49 | 50 | /* '//' => '/' */ 51 | 52 | s++; 53 | continue; 54 | 55 | case '.' : 56 | 57 | if (s == e-1) { 58 | 59 | if (root) { 60 | path->data[0] = '/'; 61 | path->len = 1; 62 | } else { 63 | path->len = 0; 64 | } 65 | 66 | return; 67 | } 68 | 69 | /* './' => '' */ 70 | 71 | if (s[1] == '/') { 72 | 73 | s += 2; 74 | 75 | if (s == e) { 76 | 77 | path->len = 0; 78 | return; 79 | } 80 | 81 | continue; 82 | } 83 | } 84 | 85 | break; 86 | } 87 | 88 | if (root && *s != '/') { 89 | s--; 90 | } 91 | 92 | p = s; 93 | 94 | check_basic : 95 | 96 | for ( ; p '/' */ 110 | 111 | m = p + 2; 112 | goto copy; 113 | 114 | case '.' : 115 | 116 | if (e - p == 2) 117 | break; 118 | 119 | switch (p[2]) { 120 | 121 | case '/' : 122 | 123 | /* './' => '' */ 124 | 125 | m = p + 2; 126 | goto copy; 127 | 128 | case '.' : 129 | 130 | if (e - p == 3 || p[3] == '/') { 131 | 132 | if (p == s) { 133 | 134 | s += 3; 135 | continue; 136 | } 137 | 138 | if (p - s >= 2) { 139 | 140 | if (p[-1] == '.' && p[-2] == '.') { 141 | 142 | if (p - s == 2 || p[-3] == '/') { /* = '../../' */ 143 | 144 | p += 2; /* 3? */ 145 | continue; 146 | } 147 | } 148 | } 149 | 150 | m = p + 4; 151 | 152 | if (complex) { 153 | 154 | for (p--; p >= s; p--) { 155 | 156 | switch (*p) { 157 | 158 | case '/' : 159 | goto copy; 160 | 161 | case '$' : 162 | 163 | p = m - 1; 164 | 165 | if (m == e) 166 | goto end_basic; 167 | 168 | goto new_dir_first; 169 | } 170 | } 171 | 172 | } else { 173 | 174 | for (p--; p > s; p--) { 175 | 176 | /* '/path/folder/../' => '/path/' */ 177 | 178 | if (*p == '/') 179 | break; 180 | } 181 | } 182 | 183 | goto copy; 184 | } 185 | } 186 | } 187 | } 188 | } 189 | 190 | end_basic : 191 | 192 | path->data = s; 193 | path->len = p - s; 194 | 195 | return; 196 | 197 | copy : 198 | 199 | p++; 200 | 201 | if (m < e) 202 | goto new_dir; 203 | 204 | while (m < e) { 205 | 206 | c = *m; 207 | *p = c; 208 | p++; 209 | 210 | if (c == '/') { 211 | 212 | m++; 213 | 214 | new_dir : 215 | 216 | for ( ; m '' */ 236 | 237 | m += 2; 238 | if (m == e) 239 | break; 240 | 241 | goto new_dir; 242 | 243 | case '.' : 244 | 245 | if (e - m == 2 || m[2] == '/') { 246 | 247 | if (m - s >= 3) { /* NOTE : this is one higher than above because m has moved on 1 */ 248 | 249 | if (p[-2] == '.' && p[-3] == '.') { 250 | 251 | if (m - s == 3 || p[-4] == '/') { /* = '../../' */ 252 | 253 | p[0] = '.'; 254 | p[1] = '.'; 255 | p[2] = '/'; 256 | p += 3; 257 | m += 3; 258 | goto new_dir; 259 | } 260 | } 261 | } 262 | 263 | if (complex) { 264 | 265 | l = p; 266 | 267 | for (p -= 2; p >= s; p--) { 268 | 269 | switch (*p) { 270 | 271 | case '/' : 272 | break; 273 | 274 | case '$' : 275 | 276 | l[0] = '.'; 277 | l[1] = '.'; 278 | l[2] = '/'; 279 | p = l + 4; 280 | break; 281 | 282 | default : 283 | continue; 284 | } 285 | 286 | break; 287 | } 288 | 289 | m += 3; 290 | if (m == e) 291 | goto end; 292 | 293 | goto new_dir; 294 | 295 | } else { 296 | 297 | for (p -= 2; p > s; p--) { 298 | 299 | /* '/path/folder/../' => '/path/' */ 300 | 301 | if (*p == '/') 302 | break; 303 | } 304 | 305 | m += 3; 306 | if (m == e) 307 | goto end; 308 | 309 | goto new_dir; 310 | } 311 | } 312 | } 313 | } 314 | 315 | } else { 316 | m++; 317 | } 318 | } 319 | 320 | end : 321 | 322 | path->data = s; 323 | path->len = p - s; 324 | } 325 | 326 | 327 | /* This function converts a path to its directory version, and assumes that there is always space 328 | * to allocatate an extra character on the end (which is only true if the provided strings always 329 | * have NULL's at the end (hence the 'safe'). 330 | */ 331 | 332 | void 333 | ndk_path_to_dir_safe (ngx_str_t *path, ngx_uint_t complex, size_t off) 334 | { 335 | size_t len; 336 | u_char *p, *m; 337 | 338 | ndk_clean_path (path, complex, off); 339 | 340 | len = path->len; 341 | if (!len) 342 | return; 343 | 344 | p = path->data; 345 | m = p + len - 1; 346 | 347 | if (*m != '/') { 348 | 349 | p [len] = '/'; 350 | path->len++; 351 | } 352 | } 353 | 354 | 355 | /* Divides a path given by path/to/path1:path/to/path2 into separate strings and returns an 356 | * array of these strings. 357 | */ 358 | 359 | ngx_array_t * 360 | ndk_split_path_create (ngx_conf_t *cf, ngx_str_t *path) 361 | { 362 | ngx_str_t *str; 363 | int n; 364 | u_char *m, *s, *e; 365 | ngx_array_t *a; 366 | 367 | if (path == NULL) 368 | return NULL; 369 | 370 | n = ndk_strcntc (path, ':'); 371 | 372 | a = ngx_array_create (cf->pool, n + 1, sizeof (ngx_str_t)); 373 | if (a == NULL) { 374 | return NULL; 375 | } 376 | 377 | s = path->data; 378 | e = s + path->len; 379 | 380 | while (s < e) { 381 | 382 | m = s; 383 | 384 | while (m < e && *m != ':') m++; 385 | 386 | if (m == s) { 387 | s = m+1; 388 | continue; 389 | } 390 | 391 | str = ngx_array_push (a); 392 | if (str == NULL) { 393 | return NULL; 394 | } 395 | 396 | str->data = s; 397 | str->len = m - s; 398 | 399 | if (ngx_conf_full_name (cf->cycle, str, 0) == NGX_ERROR) 400 | return NULL; 401 | 402 | s = m+1; 403 | } 404 | 405 | return a; 406 | } 407 | 408 | 409 | 410 | ngx_array_t * 411 | ndk_split_path_create_raw (ngx_conf_t *cf, char *path) 412 | { 413 | ngx_str_t *str; 414 | int n; 415 | char *m, *s; 416 | ngx_array_t *a; 417 | 418 | if (path == NULL) 419 | return NULL; 420 | 421 | n = ndk_strccnt (path, ':'); 422 | 423 | a = ngx_array_create (cf->pool, n + 1, sizeof (ngx_str_t)); 424 | if (a == NULL) { 425 | return NULL; 426 | } 427 | 428 | s = path; 429 | 430 | 431 | while (*s != '\0') { 432 | 433 | m = s; 434 | 435 | while (*m != '\0' && *m != ':') m++; 436 | 437 | if (m == s) { 438 | s = m+1; 439 | continue; 440 | } 441 | 442 | str = ngx_array_push (a); 443 | if (str == NULL) { 444 | return NULL; 445 | } 446 | 447 | str->data = (u_char *) s; 448 | str->len = m - s; 449 | 450 | if (ngx_conf_full_name (cf->cycle, str, 0) == NGX_ERROR) 451 | return NULL; 452 | 453 | if (*m == '\0') 454 | break; 455 | 456 | s = m+1; 457 | } 458 | 459 | return a; 460 | } 461 | 462 | 463 | 464 | char * 465 | ndk_conf_set_full_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 466 | { 467 | char *p = conf; 468 | 469 | ngx_str_t *path, *value; 470 | ngx_conf_post_t *post; 471 | 472 | path = (ngx_str_t *) (p + cmd->offset); 473 | 474 | if (path->data) { 475 | return "is duplicate"; 476 | } 477 | 478 | value = cf->args->elts; 479 | 480 | *path = value[1]; 481 | 482 | if (ngx_conf_full_name (cf->cycle, path, 0) == NGX_ERROR) 483 | return NGX_CONF_ERROR; 484 | 485 | if (cmd->post) { 486 | post = cmd->post; 487 | return post->post_handler(cf, post, path); 488 | } 489 | 490 | return NGX_CONF_OK; 491 | } 492 | 493 | 494 | 495 | char * 496 | ndk_conf_set_split_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 497 | { 498 | /* TODO : change to use the path func above */ 499 | 500 | char *p = conf; 501 | 502 | ngx_str_t *value, *str; 503 | ngx_array_t **a; 504 | ngx_conf_post_t *post; 505 | int n; 506 | u_char *m, *s, *e; 507 | 508 | a = (ngx_array_t **) (p + cmd->offset); 509 | 510 | if (*a != NGX_CONF_UNSET_PTR) { 511 | return "is duplicate"; 512 | } 513 | 514 | value = cf->args->elts; 515 | value++; 516 | 517 | n = ndk_strcntc (value, ':') + 1; 518 | 519 | *a = ngx_array_create (cf->pool, n, sizeof (ngx_str_t)); 520 | if (*a == NULL) { 521 | return NGX_CONF_ERROR; 522 | } 523 | 524 | s = value->data; 525 | e = s + value->len; 526 | 527 | while (s < e) { 528 | 529 | m = s; 530 | 531 | while (m < e && *m != ':') m++; 532 | 533 | if (m == s) { 534 | s = m+1; 535 | continue; 536 | } 537 | 538 | str = ngx_array_push (*a); 539 | if (str == NULL) { 540 | return NGX_CONF_ERROR; 541 | } 542 | 543 | str->data = s; 544 | str->len = m - s; 545 | 546 | if (ngx_conf_full_name (cf->cycle, str, 0) == NGX_ERROR) 547 | return NGX_CONF_ERROR; 548 | 549 | s = m+1; 550 | } 551 | 552 | 553 | if (cmd->post) { 554 | post = cmd->post; 555 | return post->post_handler (cf, post, a); 556 | } 557 | 558 | return NGX_CONF_OK; 559 | } 560 | 561 | 562 | 563 | char * 564 | ndk_conf_set_full_path (ngx_conf_t *cf, void *data, ngx_str_t *path) 565 | { 566 | if (ngx_conf_full_name (cf->cycle, path, 0) == NGX_ERROR) 567 | return NGX_CONF_ERROR; 568 | 569 | return NGX_CONF_OK; 570 | } 571 | 572 | 573 | 574 | char * 575 | ndk_conf_set_full_conf_path (ngx_conf_t *cf, void *data, ngx_str_t *path) 576 | { 577 | if (ngx_conf_full_name (cf->cycle, path, 1) == NGX_ERROR) 578 | return NGX_CONF_ERROR; 579 | 580 | return NGX_CONF_OK; 581 | } 582 | 583 | 584 | --------------------------------------------------------------------------------