Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

not compiling yet

  • Loading branch information...
commit 5747a734e019ecd64da025e3e7b5d9c29ed45704 1 parent 6d5e364
@replay authored
Showing with 95 additions and 28 deletions.
  1. +4 −0 config
  2. +91 −28 ngx_http_lower_upper_case.c
View
4 config
@@ -0,0 +1,4 @@
+ngx_addon_name=ngx_http_lower_upper_case_module
+HTTP_MODULES="$HTTP_MODULES ngx_http_lower_upper_case_module"
+NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_lower_upper_case.c"
+CFLAGS="$CFLAGS -I$ngx_addon_dir"
View
119 ngx_http_lower_upper_case.c
@@ -2,27 +2,26 @@
#include <ngx_core.h>
#include <ngx_http.h>
-#include <parser.c>
-
#define UPPER 0
#define LOWER 1
typedef struct {
ngx_conf_t *cf;
- ngx_array_t *ulcases;
+ ngx_array_t *lucases;
} ngx_http_lower_upper_case_conf_t;
typedef struct {
- uintptr_t action:1
- ngx_int_t src_variable_index;
- ngx_http_variable_t *dst_variable;
-} ngx_http_ulcase_t;
+ uintptr_t action:1;
+ uintptr_t src_variable_index;
+ uintptr_t dst_variable_index;
+} ngx_http_lucase_t;
// create confs
static void *ngx_http_lower_upper_case_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_lower_upper_case_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);
static char *ngx_http_lower_upper_directive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static ngx_int_t ngx_http_do_lower_upper(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
static ngx_command_t ngx_http_lower_upper_case_commands[] = {
@@ -30,19 +29,18 @@ static ngx_command_t ngx_http_lower_upper_case_commands[] = {
NGX_HTTP_LOC_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ngx_http_lower_upper_directive,
NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_lower_upper_case_conf_t, action),
+ 0,
NULL },
{ ngx_string("string_to_lowercase"),
NGX_HTTP_LOC_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ngx_http_lower_upper_directive,
NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_lower_upper_case_conf_t, action),
+ 0,
NULL },
ngx_null_command
- };
};
-ngx_http_module_t ngx_http_lower_upper_case_module = {
+static ngx_http_module_t ngx_http_lower_upper_case_module_ctx = {
NULL,
NULL,
@@ -56,6 +54,21 @@ ngx_http_module_t ngx_http_lower_upper_case_module = {
ngx_http_lower_upper_case_merge_loc_conf
};
+ngx_module_t ngx_http_lower_upper_case_module = {
+ NGX_MODULE_V1,
+ &ngx_http_lower_upper_case_module_ctx,
+ ngx_http_lower_upper_case_commands,
+ NGX_HTTP_MODULE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NGX_MODULE_V1_PADDING
+};
+
static void *
ngx_http_php_session_create_loc_conf(ngx_conf_t *cf)
{
@@ -68,20 +81,20 @@ ngx_http_php_session_create_loc_conf(ngx_conf_t *cf)
}
lucf->cf = cf;
- lucf->ulcases = NULL;
+ lucf->lucases = NULL;
return lucf;
}
-static void *
+static char *
ngx_http_lower_upper_case_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_lower_upper_case_conf_t *prev = parent;
ngx_http_lower_upper_case_conf_t *conf = child;
- if (prev->ulcases != NULL)
+ if (prev->lucases != NULL)
{
- conf->ulcases = prev->ulcases;
+ conf->lucases = prev->lucases;
}
return NGX_CONF_OK;
@@ -91,25 +104,25 @@ static char *
ngx_http_lower_upper_directive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_lower_upper_case_conf_t *lucf = conf;
- ngx_http_ulcase_t *ulcase;
- ngx_str_t variable;
- ngx_http_variable_t *ngx_http_variable_t;
+ ngx_http_lucase_t *lucase;
+ ngx_str_t *variable;
+ ngx_http_variable_t *v;
- if (ulcf->cases == NULL) {
- ulcf->cases = ngx_array_create(cf->pool, 1, sizeof(ngx_http_ulcase_t));
- if (ulcf->cases == NULL) {
+ if (lucf->lucases == NULL) {
+ lucf->lucases = ngx_array_create(cf->pool, 1, sizeof(ngx_http_lucase_t));
+ if (lucf->lucases == NULL) {
return NGX_CONF_ERROR;
}
}
- ulcase = ngx_array_push(lucf->cases);
- if (ulcase == NULL) {
+ lucase = ngx_array_push(lucf->lucases);
+ if (lucase == NULL) {
return NGX_CONF_ERROR;
}
variable = cf->args->elts;
if (variable[1].data[0] != '$') {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid variable name \"%V\"", &value[1]);
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid variable name \"%V\"", variable[1]);
return NGX_CONF_ERROR;
}
@@ -121,17 +134,67 @@ ngx_http_lower_upper_directive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (variable[0].data[0] == 's') {
- v->get_handler = ngx_http_to_uppercase;
+ lucase->src_variable_index = ngx_http_get_variable_index(cf, &variable[2]);
+
+ if (variable[0].data[0] == 'u') {
+ lucase->action = UPPER;
} else {
- v->get_handler = ngx_http_to_lowercase;
+ lucase->action = LOWER;
}
+
+ lucase->dst_variable_index = ngx_http_get_variable_index(cf, &variable[1]);
+
+ v->get_handler = ngx_http_do_lower_upper;
+
return NGX_CONF_OK;
}
static ngx_int_t
-ngx_http_to_uppercase(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data)
+ngx_http_do_lower_upper(ngx_http_request_t *r, ngx_http_variable_value_t *dst_v, uintptr_t data)
{
+ ngx_http_lower_upper_case_conf_t *lucf = ngx_http_get_module_loc_conf(r, ngx_http_lower_upper_case_module);
+ ngx_uint_t i;
+ u_char *tmp_void;
+ ngx_http_lucase_t *tmp_value;
+ ngx_http_lucase_t *lucase;
+ ngx_http_variable_value_t *src_v;
+
+ tmp_void = (u_char*) lucf->lucases->elts;
+
+ for (i = 0; i < lucf->lucases->nelts; i++) {
+ tmp_value = (ngx_http_lucase_t*) tmp_void;
+ if (tmp_value->dst_variable_index == data) {
+ lucase = tmp_value;
+ break;
+ }
+ }
+ if (i == lucf->lucases->nelts) {
+ return NGX_ERROR;
+ }
+ src_v = ngx_http_get_indexed_variable(r, lucase->src_variable_index);
+
+ dst_v->len = src_v->len;
+
+ dst_v->data = ngx_pcalloc(r->pool, src_v->len);
+ if (dst_v->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_cpymem(dst_v->data, src_v->data, dst_v->len);
+
+ if (lucase->action == LOWER) {
+ for (i = 0; i < dst_v->len; i++) {
+ ngx_tolower(dst_v->data[i]);
+ }
+ } else {
+ for (i = 0; i < dst_v->len; i++) {
+ ngx_toupper(dst_v->data[i]);
+ }
+ }
+
+ dst_v->valid = 1;
+
+ return NGX_OK;
}
Please sign in to comment.
Something went wrong with that request. Please try again.