@@ -34,12 +34,13 @@ static const char *redirectionio_set_project_key(cmd_parms *cmd, void *cfg, cons
34
34
static const char * redirectionio_set_logs_enable (cmd_parms * cmd , void * cfg , const char * arg );
35
35
static const char * redirectionio_set_scheme (cmd_parms * cmd , void * cfg , const char * arg );
36
36
static const char * redirectionio_set_show_rule_ids (cmd_parms * cmd , void * cfg , const char * arg );
37
- static const char * redirectionio_set_pass (cmd_parms * cmd , void * cfg , const char * arg );
37
+ static const char * redirectionio_set_server (cmd_parms * cmd , void * dc , int argc , char * const argv [] );
38
38
static void redirectionio_apache_log_callback (const char * log_str , const void * data , short level );
39
+ static apr_status_t redirectionio_atoi (const char * line , apr_size_t len );
39
40
40
41
static const command_rec redirectionio_directives [] = {
41
42
AP_INIT_TAKE1 ("redirectionio" , redirectionio_set_enable , NULL , OR_ALL , "Enable or disable redirectionio" ),
42
- AP_INIT_TAKE1 ("redirectionioPass" , redirectionio_set_pass , NULL , OR_ALL , "Agent server location" ),
43
+ AP_INIT_TAKE_ARGV ("redirectionioPass" , redirectionio_set_server , NULL , OR_ALL , "Agent server location" ),
43
44
AP_INIT_TAKE1 ("redirectionioProjectKey" , redirectionio_set_project_key , NULL , OR_ALL , "RedirectionIO project key" ),
44
45
AP_INIT_TAKE1 ("redirectionioLogs" , redirectionio_set_logs_enable , NULL , OR_ALL , "Enable or disable logging for redirectionio" ),
45
46
AP_INIT_TAKE1 ("redirectionioScheme" , redirectionio_set_scheme , NULL , OR_ALL , "Force scheme to use when matching request" ),
@@ -87,9 +88,9 @@ static int redirectionio_match_handler(request_rec *r) {
87
88
if (config -> connection_pool == NULL ) {
88
89
if (apr_reslist_create (
89
90
& config -> connection_pool ,
90
- RIO_MIN_CONNECTIONS ,
91
- RIO_KEEP_CONNECTIONS ,
92
- RIO_MAX_CONNECTIONS ,
91
+ config -> server . min_conns ,
92
+ config -> server . keep_conns ,
93
+ config -> server . max_conns ,
93
94
0 ,
94
95
redirectionio_pool_construct ,
95
96
redirectionio_pool_destruct ,
@@ -103,7 +104,7 @@ static int redirectionio_match_handler(request_rec *r) {
103
104
return DECLINED ;
104
105
}
105
106
106
- apr_reslist_timeout_set (config -> connection_pool , RIO_TIMEOUT );
107
+ apr_reslist_timeout_set (config -> connection_pool , config -> server . timeout * 1000 );
107
108
apr_pool_cleanup_register (config -> pool , config -> connection_pool , redirectionio_child_exit , redirectionio_child_exit );
108
109
}
109
110
@@ -386,14 +387,14 @@ static apr_status_t redirectionio_create_connection(redirectionio_connection *co
386
387
apr_status_t rv ;
387
388
apr_int32_t family = APR_INET ;
388
389
389
- if (config -> protocol == UNIX ) {
390
+ if (config -> server . protocol == UNIX ) {
390
391
family = APR_UNIX ;
391
392
}
392
393
393
- rv = apr_sockaddr_info_get (& conn -> rio_addr , config -> server , family , config -> port , 0 , pool );
394
+ rv = apr_sockaddr_info_get (& conn -> rio_addr , config -> server . pass , family , config -> server . port , 0 , pool );
394
395
395
396
if (rv != APR_SUCCESS ) {
396
- ap_log_perror (APLOG_MARK , APLOG_ERR , 0 , pool , "mod_redirectionio: apr_sockaddr_info_get failed %s:%d %s" , config -> server , config -> port , apr_strerror (rv , errbuf , sizeof (errbuf )));
397
+ ap_log_perror (APLOG_MARK , APLOG_ERR , 0 , pool , "mod_redirectionio: apr_sockaddr_info_get failed %s:%d %s" , config -> server . pass , config -> server . port , apr_strerror (rv , errbuf , sizeof (errbuf )));
397
398
398
399
return rv ;
399
400
}
@@ -439,7 +440,7 @@ static apr_status_t redirectionio_create_connection(redirectionio_connection *co
439
440
return rv ;
440
441
}
441
442
442
- rv = apr_socket_timeout_set (conn -> rio_sock , RIO_TIMEOUT );
443
+ rv = apr_socket_timeout_set (conn -> rio_sock , config -> server . timeout * 1000 );
443
444
444
445
if (rv != APR_SUCCESS ) {
445
446
ap_log_perror (APLOG_MARK , APLOG_ERR , 0 , pool , "mod_redirectionio: Error setting socket timeout: %s" , apr_strerror (rv , errbuf , sizeof (errbuf )));
@@ -495,10 +496,14 @@ static void *create_redirectionio_dir_conf(apr_pool_t *pool, char *context) {
495
496
config -> enable_logs = -1 ;
496
497
config -> project_key = NULL ;
497
498
config -> scheme = NULL ;
498
- config -> protocol = TCP ;
499
- config -> port = 10301 ;
500
- config -> server = "127.0.0.1" ;
501
- config -> pass_set = -1 ;
499
+ config -> server .protocol = TCP ;
500
+ config -> server .pass = "127.0.0.1" ;
501
+ config -> server .pass_set = -1 ;
502
+ config -> server .port = 10301 ;
503
+ config -> server .min_conns = RIO_MIN_CONNECTIONS ;
504
+ config -> server .max_conns = RIO_MAX_CONNECTIONS ;
505
+ config -> server .keep_conns = RIO_KEEP_CONNECTIONS ;
506
+ config -> server .timeout = RIO_TIMEOUT ;
502
507
config -> pool = pool ;
503
508
config -> show_rule_ids = -1 ;
504
509
}
@@ -542,16 +547,24 @@ static void *merge_redirectionio_dir_conf(apr_pool_t *pool, void *parent, void *
542
547
conf -> scheme = conf_current -> scheme ;
543
548
}
544
549
545
- if (conf_current -> pass_set == -1 ) {
546
- conf -> port = conf_parent -> port ;
547
- conf -> protocol = conf_parent -> protocol ;
548
- conf -> server = conf_parent -> server ;
549
- conf -> pass_set = conf_parent -> pass_set ;
550
+ if (conf_current -> server .pass_set == -1 ) {
551
+ conf -> server .port = conf_parent -> server .port ;
552
+ conf -> server .protocol = conf_parent -> server .protocol ;
553
+ conf -> server .pass = conf_parent -> server .pass ;
554
+ conf -> server .pass_set = conf_parent -> server .pass_set ;
555
+ conf -> server .min_conns = conf_parent -> server .min_conns ;
556
+ conf -> server .max_conns = conf_parent -> server .max_conns ;
557
+ conf -> server .keep_conns = conf_parent -> server .keep_conns ;
558
+ conf -> server .timeout = conf_parent -> server .timeout ;
550
559
} else {
551
- conf -> port = conf_current -> port ;
552
- conf -> protocol = conf_current -> protocol ;
553
- conf -> server = conf_current -> server ;
554
- conf -> pass_set = conf_current -> pass_set ;
560
+ conf -> server .port = conf_current -> server .port ;
561
+ conf -> server .protocol = conf_current -> server .protocol ;
562
+ conf -> server .pass = conf_current -> server .pass ;
563
+ conf -> server .pass_set = conf_current -> server .pass_set ;
564
+ conf -> server .min_conns = conf_current -> server .min_conns ;
565
+ conf -> server .max_conns = conf_current -> server .max_conns ;
566
+ conf -> server .keep_conns = conf_current -> server .keep_conns ;
567
+ conf -> server .timeout = conf_current -> server .timeout ;
555
568
}
556
569
557
570
conf -> pool = pool ;
@@ -688,44 +701,108 @@ static const char *redirectionio_set_show_rule_ids(cmd_parms *cmd, void *cfg, co
688
701
return NULL ;
689
702
}
690
703
691
- static const char * redirectionio_set_pass (cmd_parms * cmd , void * cfg , const char * arg ) {
704
+ static const char * redirectionio_set_server (cmd_parms * cmd , void * cfg , int argc , char * const argv [] ) {
692
705
apr_uri_t uri ;
693
706
redirectionio_config * conf = (redirectionio_config * )cfg ;
707
+ const char * server_pass ;
708
+ int i ;
709
+ size_t arg_len ;
694
710
695
- if (apr_uri_parse ( cmd -> pool , arg , & uri ) != APR_SUCCESS ) {
696
- ap_log_error (APLOG_MARK , APLOG_ERR , 0 , NULL , "mod_redirectionio: Could not parse agent url %s , disable module." , arg );
711
+ if (argc < 1 ) {
712
+ ap_log_error (APLOG_MARK , APLOG_ERR , 0 , NULL , "mod_redirectionio: Could not parse agent server, no parameter , disable module." );
697
713
conf -> enable = 0 ;
698
714
699
715
return NULL ;
700
716
}
701
717
702
- conf -> pass_set = 1 ;
718
+ server_pass = argv [0 ];
719
+
720
+ if (apr_uri_parse (cmd -> pool , server_pass , & uri ) != APR_SUCCESS ) {
721
+ ap_log_error (APLOG_MARK , APLOG_ERR , 0 , NULL , "mod_redirectionio: Could not parse agent url %s, disable module." , server_pass );
722
+ conf -> enable = 0 ;
723
+
724
+ return NULL ;
725
+ }
726
+
727
+ conf -> server .pass_set = 1 ;
703
728
704
729
if (uri .scheme != NULL && apr_strnatcmp (uri .scheme , "unix" ) == 0 ) {
705
- conf -> protocol = UNIX ;
730
+ conf -> server . protocol = UNIX ;
706
731
}
707
732
708
733
if (uri .scheme != NULL && apr_strnatcmp (uri .scheme , "tcp" ) == 0 ) {
709
- conf -> protocol = TCP ;
734
+ conf -> server . protocol = TCP ;
710
735
}
711
736
712
- if (conf -> protocol != UNIX && conf -> protocol != TCP ) {
737
+ if (conf -> server . protocol != UNIX && conf -> server . protocol != TCP ) {
713
738
ap_log_error (APLOG_MARK , APLOG_ERR , 0 , NULL , "mod_redirectionio: Server protocol is %s, but must be 'unix://' or 'tcp://', disable module." , uri .scheme );
714
739
conf -> enable = 0 ;
715
740
}
716
741
717
- if (conf -> protocol == UNIX && uri .path ) {
718
- conf -> server = uri .path ;
742
+ if (conf -> server . protocol == UNIX && uri .path ) {
743
+ conf -> server . pass = uri .path ;
719
744
}
720
745
721
- if (conf -> protocol == TCP && uri .hostname ) {
722
- conf -> server = uri .hostname ;
746
+ if (conf -> server . protocol == TCP && uri .hostname ) {
747
+ conf -> server . pass = uri .hostname ;
723
748
}
724
749
725
750
if (uri .port ) {
726
- conf -> port = uri .port ;
751
+ conf -> server .port = uri .port ;
752
+ }
753
+
754
+ for (i = 1 ; i < argc ; i ++ ) {
755
+ arg_len = strlen (argv [i ]);
756
+
757
+ if (strncasecmp (argv [i ], "min_conns=" , 10 ) == 0 ) {
758
+ conf -> server .min_conns = redirectionio_atoi (& argv [i ][10 ], arg_len - 10 );
759
+
760
+ if (conf -> server .min_conns == APR_EGENERAL ) {
761
+ goto invalid ;
762
+ }
763
+
764
+ continue ;
765
+ }
766
+
767
+ if (strncasecmp (argv [i ], "max_conns=" , 10 ) == 0 ) {
768
+ conf -> server .max_conns = redirectionio_atoi (& argv [i ][10 ], arg_len - 10 );
769
+
770
+ if (conf -> server .max_conns == APR_EGENERAL ) {
771
+ goto invalid ;
772
+ }
773
+
774
+ continue ;
775
+ }
776
+
777
+ if (strncasecmp (argv [i ], "keep_conns=" , 11 ) == 0 ) {
778
+ conf -> server .keep_conns = redirectionio_atoi (& argv [i ][11 ], arg_len - 11 );
779
+
780
+ if (conf -> server .keep_conns == APR_EGENERAL ) {
781
+ goto invalid ;
782
+ }
783
+
784
+ continue ;
785
+ }
786
+
787
+ if (strncasecmp (argv [i ], "timeout=" , 8 ) == 0 ) {
788
+ conf -> server .timeout = (apr_interval_time_t ) redirectionio_atoi (& argv [i ][8 ], arg_len - 8 );
789
+
790
+ if (conf -> server .timeout == (apr_interval_time_t ) APR_EGENERAL ) {
791
+ goto invalid ;
792
+ }
793
+
794
+ continue ;
795
+ }
796
+
797
+ goto invalid ;
727
798
}
728
799
800
+ return NULL ;
801
+
802
+ invalid :
803
+ ap_log_error (APLOG_MARK , APLOG_ERR , 0 , NULL , "mod_redirectionio: invalid parameter when setting pass: %s." , argv [i ]);
804
+ conf -> enable = 0 ;
805
+
729
806
return NULL ;
730
807
}
731
808
@@ -734,3 +811,28 @@ static void redirectionio_apache_log_callback(const char* log_str, const void* d
734
811
ap_log_rerror (APLOG_MARK , APLOG_ERR , 0 , (request_rec * )data , "mod_redirectionio api error: %s" , log_str );
735
812
}
736
813
}
814
+
815
+ static apr_status_t redirectionio_atoi (const char * line , apr_size_t len ) {
816
+ int value , cutoff , cutlim ;
817
+
818
+ if (len == 0 ) {
819
+ return APR_EGENERAL ;
820
+ }
821
+
822
+ cutoff = INT_MAX / 10 ;
823
+ cutlim = INT_MAX % 10 ;
824
+
825
+ for (value = 0 ; len -- ; line ++ ) {
826
+ if (* line < '0' || * line > '9' ) {
827
+ return APR_EGENERAL ;
828
+ }
829
+
830
+ if (value >= cutoff && (value > cutoff || * line - '0' > cutlim )) {
831
+ return APR_EGENERAL ;
832
+ }
833
+
834
+ value = value * 10 + (* line - '0' );
835
+ }
836
+
837
+ return value ;
838
+ }
0 commit comments