Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added new directive set_rotate $value $from $to

  • Loading branch information...
commit 3703a5ee5733a255bf075bde0ba4f9dfd0b5e5a1 1 parent e6a54ab
viperet authored
View
4 config
@@ -7,8 +7,8 @@ fi
ngx_addon_name=ngx_http_set_misc_module
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_set_misc_module"
-NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_set_base32.c $ngx_addon_dir/src/ngx_http_set_default_value.c $ngx_addon_dir/src/ngx_http_set_hashed_upstream.c $ngx_addon_dir/src/ngx_http_set_quote_sql.c $ngx_addon_dir/src/ngx_http_set_quote_json.c $ngx_addon_dir/src/ngx_http_set_unescape_uri.c $ngx_addon_dir/src/ngx_http_set_misc_module.c $ngx_addon_dir/src/ngx_http_set_escape_uri.c $ngx_addon_dir/src/ngx_http_set_hash.c $ngx_addon_dir/src/ngx_http_set_local_today.c $ngx_addon_dir/src/ngx_http_set_hex.c $ngx_addon_dir/src/ngx_http_set_base64.c $ngx_addon_dir/src/ngx_http_set_random.c"
-NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/ngx_http_set_default_value.h $ngx_addon_dir/src/ngx_http_set_hashed_upstream.h $ngx_addon_dir/src/ngx_http_set_quote_sql.h $ngx_addon_dir/src/ngx_http_set_quote_json.h $ngx_addon_dir/src/ngx_http_set_unescape_uri.h $ngx_addon_dir/src/ngx_http_set_escape_uri.h $ngx_addon_dir/src/ngx_http_set_hash.h $ngx_addon_dir/src/ngx_http_set_local_today.h $ngx_addon_dir/src/ngx_http_set_hex.h $ngx_addon_dir/src/ngx_http_set_base64.h $ngx_addon_dir/src/ngx_http_set_random.h $ngx_addon_dir/src/ngx_http_set_misc_module.h"
+NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_set_base32.c $ngx_addon_dir/src/ngx_http_set_default_value.c $ngx_addon_dir/src/ngx_http_set_hashed_upstream.c $ngx_addon_dir/src/ngx_http_set_quote_sql.c $ngx_addon_dir/src/ngx_http_set_quote_json.c $ngx_addon_dir/src/ngx_http_set_unescape_uri.c $ngx_addon_dir/src/ngx_http_set_misc_module.c $ngx_addon_dir/src/ngx_http_set_escape_uri.c $ngx_addon_dir/src/ngx_http_set_hash.c $ngx_addon_dir/src/ngx_http_set_local_today.c $ngx_addon_dir/src/ngx_http_set_hex.c $ngx_addon_dir/src/ngx_http_set_base64.c $ngx_addon_dir/src/ngx_http_set_random.c $ngx_addon_dir/src/ngx_http_set_rotate.c"
+NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/ngx_http_set_default_value.h $ngx_addon_dir/src/ngx_http_set_hashed_upstream.h $ngx_addon_dir/src/ngx_http_set_quote_sql.h $ngx_addon_dir/src/ngx_http_set_quote_json.h $ngx_addon_dir/src/ngx_http_set_unescape_uri.h $ngx_addon_dir/src/ngx_http_set_escape_uri.h $ngx_addon_dir/src/ngx_http_set_hash.h $ngx_addon_dir/src/ngx_http_set_local_today.h $ngx_addon_dir/src/ngx_http_set_hex.h $ngx_addon_dir/src/ngx_http_set_base64.h $ngx_addon_dir/src/ngx_http_set_random.h $ngx_addon_dir/src/ngx_http_set_rotate.h $ngx_addon_dir/src/ngx_http_set_misc_module.h"
if [ $USE_OPENSSL = YES ]; then
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_http_set_hmac.h"
View
18 src/ngx_http_set_misc_module.c
@@ -20,6 +20,7 @@
#include "ngx_http_set_hmac.h"
#endif
#include "ngx_http_set_random.h"
+#include "ngx_http_set_rotate.h"
#define NGX_UNESCAPE_URI_COMPONENT 0
@@ -146,7 +147,14 @@ static ndk_set_var_t ngx_http_set_misc_set_random_filter = {
2,
NULL
};
-
+/*
+static ndk_set_var_t ngx_http_set_misc_set_rotate_filter = {
+ NDK_SET_VAR_VALUE,
+ ngx_http_set_misc_set_rotate,
+ 2,
+ NULL
+};
+*/
static ngx_command_t ngx_http_set_misc_commands[] = {
{ ngx_string ("set_encode_base64"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF
@@ -316,6 +324,14 @@ static ngx_command_t ngx_http_set_misc_commands[] = {
0,
&ngx_http_set_misc_set_random_filter
},
+ { ngx_string ("set_rotate"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF
+ |NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE3,
+ ngx_http_set_rotate,
+ 0,
+ 0,
+ NULL
+ },
ngx_null_command
};
View
84 src/ngx_http_set_rotate.c
@@ -0,0 +1,84 @@
+#ifndef DDEBUG
+#define DDEBUG 0
+#endif
+#include "ddebug.h"
+
+#include <ndk.h>
+#include "ngx_http_set_rotate.h"
+#include <stdlib.h>
+
+ngx_int_t
+ngx_http_set_misc_set_rotate(ngx_http_request_t *r,
+ ngx_str_t *res, ngx_http_variable_value_t *v)
+{
+ ngx_http_variable_value_t *rotate_from, *rotate_to, *rotate_num;
+ ngx_int_t int_from, int_to, tmp, int_current;
+
+ rotate_num = &v[0];
+ rotate_from = &v[1];
+ rotate_to = &v[2];
+
+// rotate_from = v;
+// rotate_to = v + 1;
+
+ int_from = ngx_atoi(rotate_from->data, rotate_from->len);
+ if (int_from == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "set_rotate: bad \"from\" argument: %v", rotate_from);
+ return NGX_ERROR;
+ }
+
+ int_to = ngx_atoi(rotate_to->data, rotate_to->len);
+ if (int_to == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "set_rotate: bad \"to\" argument: %v", rotate_to);
+ return NGX_ERROR;
+ }
+
+ if (int_from > int_to) {
+ tmp = int_from;
+ int_from = int_to;
+ int_to = tmp;
+ }
+
+ int_current = ngx_atoi(rotate_num->data, rotate_num->len);
+ if (int_current == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "set_rotate: bad \"default\" argument: %v", rotate_to);
+ int_current = int_from;
+ }
+
+ int_current++;
+ if(int_current>int_to || int_current<int_from)
+ int_current = int_from;
+
+ res->data = ngx_palloc(r->pool, NGX_INT_T_LEN);
+ if (res->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ res->len = ngx_sprintf(res->data, "%i", int_current) - res->data;
+
+ /* Set all required params */
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+
+ return NGX_OK;
+}
+
+char *
+ngx_http_set_rotate(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_str_t *value;
+ ndk_set_var_t filter;
+
+ value = cf->args->elts;
+
+ filter.type = NDK_SET_VAR_MULTI_VALUE;
+ filter.func = ngx_http_set_misc_set_rotate;
+ filter.size = 3;
+ filter.data = NULL;
+
+ return ndk_set_var_multi_value_core(cf, &value[1], &value[1], &filter);
+}
View
9 src/ngx_http_set_rotate.h
@@ -0,0 +1,9 @@
+#include <ngx_core.h>
+#include <ngx_config.h>
+#include <ngx_http.h>
+
+char * ngx_http_set_rotate(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+
+ngx_int_t ngx_http_set_misc_set_rotate(ngx_http_request_t *r,
+ ngx_str_t *res, ngx_http_variable_value_t *v);
Please sign in to comment.
Something went wrong with that request. Please try again.