Author: rjung Date: Wed Jun 26 09:08:54 2013 New Revision: 1496844 URL: http://svn.apache.org/r1496844 Log: - Use defined constants in ping mode config parsing.
- Fix handling of default values in ping mode config parsing. - Provide utility function to map ping mode numeric value to text representation. Modified: tomcat/jk/trunk/native/common/jk_ajp_common.c tomcat/jk/trunk/native/common/jk_ajp_common.h Modified: tomcat/jk/trunk/native/common/jk_ajp_common.c URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_ajp_common.c?rev=1496844&r1=1496843&r2=1496844&view=diff ============================================================================== --- tomcat/jk/trunk/native/common/jk_ajp_common.c (original) +++ tomcat/jk/trunk/native/common/jk_ajp_common.c Wed Jun 26 09:08:54 2013 @@ -74,6 +74,12 @@ static const char *ajp_state_type[] = { NULL }; +static char ajp_cping_mode[] = { + AJP_CPING_CONNECT_TEXT, + AJP_CPING_PREPOST_TEXT, + AJP_CPING_INTERVAL_TEXT, +}; + #define UNKNOWN_METHOD (-1) static int sc_for_req_method(const char *method, size_t len) @@ -343,25 +349,43 @@ int jk_ajp_get_state_code(const char *v) return JK_AJP_STATE_DEF; } +void jk_ajp_get_cping_text(int mode, char *buf) +{ + int bit = 1; + int log2 = 0; + int pos = 0; + while (bit <= mode && bit <= AJP_CPING_MAX) { + if (mode & bit) { + buf[pos] = ajp_cping_mode[log2]; + pos +=1; + } + bit *= 2; + log2 += 1; + } + buf[pos] = '\0'; +} + int jk_ajp_get_cping_mode(const char *m, int def) { - int mv = def; + int mv = 0; if (!m) - return mv; + return def; while (*m != '\0') { - if (*m == 'C' || *m == 'c') + if (*m == AJP_CPING_CONNECT_TEXT || *m == tolower(AJP_CPING_CONNECT_TEXT)) mv |= AJP_CPING_CONNECT; - if (*m == 'P' || *m == 'p') + if (*m == AJP_CPING_PREPOST_TEXT || *m == tolower(AJP_CPING_PREPOST_TEXT)) mv |= AJP_CPING_PREPOST; - if (*m == 'I' || *m == 'i') + if (*m == AJP_CPING_INTERVAL_TEXT || *m == tolower(AJP_CPING_INTERVAL_TEXT)) mv |= AJP_CPING_INTERVAL; - if (*m == 'A' || *m == 'a') { + if (*m == AJP_CPING_ALL_TEXT || *m == tolower(AJP_CPING_ALL_TEXT)) { mv = AJP_CPING_CONNECT | AJP_CPING_PREPOST | AJP_CPING_INTERVAL; break; } m++; } - return mv; + if (mv) + return mv; + return def; } /* Modified: tomcat/jk/trunk/native/common/jk_ajp_common.h URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_ajp_common.h?rev=1496844&r1=1496843&r2=1496844&view=diff ============================================================================== --- tomcat/jk/trunk/native/common/jk_ajp_common.h (original) +++ tomcat/jk/trunk/native/common/jk_ajp_common.h Wed Jun 26 09:08:54 2013 @@ -236,6 +236,12 @@ extern "C" #define AJP_CPING_CONNECT (1) /* Send cping on fresh connection */ #define AJP_CPING_PREPOST (2) /* Send cping before sending request */ #define AJP_CPING_INTERVAL (4) /* Send cping on regular intervals */ +#define AJP_CPING_MAX (AJP_CPING_INTERVAL) + +#define AJP_CPING_CONNECT_TEXT ('C') /* Send cping on fresh connection */ +#define AJP_CPING_PREPOST_TEXT ('P') /* Send cping before sending request */ +#define AJP_CPING_INTERVAL_TEXT ('I') /* Send cping on regular intervals */ +#define AJP_CPING_ALL_TEXT ('A') /* Send cping on regular intervals */ #define RECOVER_ABORT_IF_TCGETREQUEST 0x0001 /* DON'T RECOVER IF TOMCAT FAILS AFTER RECEIVING REQUEST */ @@ -456,6 +462,7 @@ int ajp_connection_tcp_get_message(ajp_e int JK_METHOD ajp_maintain(jk_worker_t *pThis, time_t now, jk_logger_t *l); +void jk_ajp_get_cping_text(int mode, char *buf); int jk_ajp_get_cping_mode(const char *m, int def); int ajp_has_endpoint(jk_worker_t *pThis, jk_logger_t *l); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org