55
66#include <ndk.h>
77#include "ngx_http_set_rotate.h"
8+ #include "ngx_http_set_misc_module.h"
89#include <stdlib.h>
910
1011
@@ -15,6 +16,8 @@ ngx_http_set_misc_set_rotate(ngx_http_request_t *r,
1516 ngx_http_variable_value_t * rotate_from , * rotate_to , * rotate_num ;
1617 ngx_int_t int_from , int_to , tmp , int_current ;
1718
19+ ngx_http_set_misc_loc_conf_t * conf ;
20+
1821 rotate_num = & v [0 ];
1922 rotate_from = & v [1 ];
2023 rotate_to = & v [2 ];
@@ -41,11 +44,32 @@ ngx_http_set_misc_set_rotate(ngx_http_request_t *r,
4144 int_to = tmp ;
4245 }
4346
44- int_current = ngx_atoi (rotate_num -> data , rotate_num -> len );
45- if (int_current == NGX_ERROR ) {
46- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
47- "set_rotate: bad current value: \"%v\"" , rotate_num );
48- int_current = int_from ;
47+ conf = ngx_http_get_module_loc_conf (r , ngx_http_set_misc_module );
48+
49+ dd ("current value not found: %d" , (int ) rotate_num -> not_found );
50+
51+ if (rotate_num -> len == 0 ) {
52+ if (conf -> current != NGX_CONF_UNSET ) {
53+ int_current = conf -> current ;
54+
55+ } else {
56+ int_current = int_from - 1 ;
57+ }
58+
59+ } else {
60+
61+ int_current = ngx_atoi (rotate_num -> data , rotate_num -> len );
62+ if (int_current == NGX_ERROR ) {
63+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
64+ "set_rotate: bad current value: \"%v\"" , rotate_num );
65+
66+ if (conf -> current != NGX_CONF_UNSET ) {
67+ int_current = conf -> current ;
68+
69+ } else {
70+ int_current = int_from - 1 ;
71+ }
72+ }
4973 }
5074
5175 int_current ++ ;
@@ -54,6 +78,8 @@ ngx_http_set_misc_set_rotate(ngx_http_request_t *r,
5478 int_current = int_from ;
5579 }
5680
81+ conf -> current = int_current ;
82+
5783 res -> data = ngx_palloc (r -> pool , NGX_INT_T_LEN );
5884 if (res -> data == NULL ) {
5985 return NGX_ERROR ;
0 commit comments