socksd: count connections per test, widen the method2 sentinel
No binary (build failed)
—
(log yok)
| @@ -50,7 +50,7 @@ | |
| * 1 - GSSAPI (not supported) | |
| * 2 - user + password | |
| * "method2 [number]" - connect method to respond with on the second | |
| - | * connection, defaults to the "method" one |
| + | * connection of the test, defaults to the "method" one |
| * "response [number]" - the decimal number to respond to a connect | |
| * SOCKS5: 0 is OK, SOCKS4: 90 is ok | |
| * | |
| @@ -60,7 +60,8 @@ | |
| static const char *backendaddr = "127.0.0.1"; | |
| static uint16_t backendport = 0; /* default is use client's */ | |
| - | static unsigned int connections; /* number of clients served */ |
| + | static unsigned int connections; /* clients served in the current test */ |
| + | static int last_testnum = -1; /* the test the connections belong to */ |
| struct socksd_configurable { | |
| unsigned char version; /* initial version byte in the request must match | |
| @@ -69,7 +70,8 @@ struct socksd_configurable { | |
| unsigned char nmethods_max; /* maximum number of nmethods to expect */ | |
| unsigned char responseversion; | |
| unsigned char responsemethod; | |
| - | unsigned char responsemethod2; |
| + | int responsemethod2; /* negative means unset */ |
| + | int testnum; |
| unsigned char reqcmd; | |
| unsigned char connectrep; | |
| uint16_t port; /* backend port */ | |
| @@ -83,7 +85,7 @@ struct socksd_configurable { | |
| #define CONFIG_NMETHODS_MAX 3 | |
| #define CONFIG_RESPONSEVERSION CONFIG_VERSION | |
| #define CONFIG_RESPONSEMETHOD 0 /* no auth */ | |
| - | #define CONFIG_RESPONSEMETHOD2 0xff /* unset, use CONFIG_RESPONSEMETHOD */ |
| + | #define CONFIG_RESPONSEMETHOD2 (-1) /* unset, use CONFIG_RESPONSEMETHOD */ |
| #define CONFIG_REQCMD 1 /* CONNECT */ | |
| #define CONFIG_PORT backendport | |
| #define CONFIG_ADDR backendaddr | |
| @@ -102,6 +104,7 @@ static void socksd_resetdefaults(void) | |
| s_config.responseversion = CONFIG_RESPONSEVERSION; | |
| s_config.responsemethod = CONFIG_RESPONSEMETHOD; | |
| s_config.responsemethod2 = CONFIG_RESPONSEMETHOD2; | |
| + | s_config.testnum = 0; |
| s_config.reqcmd = CONFIG_REQCMD; | |
| s_config.connectrep = CONFIG_CONNECTREP; | |
| s_config.port = CONFIG_PORT; | |
| @@ -184,10 +187,17 @@ static void socksd_getconfig(void) | |
| else if(!strcmp(key, "method2")) { | |
| pval = value; | |
| if(!curlx_str_number(&pval, &num, 0xff)) { | |
| - | s_config.responsemethod2 = (unsigned char)num; |
| + | s_config.responsemethod2 = (int)num; |
| logmsg("method2 [%d] set", s_config.responsemethod2); | |
| } | |
| } | |
| + | else if(!strcmp(key, "Testnum")) { |
| + | pval = value; |
| + | if(!curlx_str_number(&pval, &num, INT_MAX)) { |
| + | s_config.testnum = (int)num; |
| + | logmsg("testnum = %d", s_config.testnum); |
| + | } |
| + | } |
| else if(!strcmp(key, "response")) { | |
| pval = value; | |
| if(!curlx_str_number(&pval, &num, 0xff)) { | |
| @@ -316,9 +326,13 @@ static curl_socket_t sockit(curl_socket_t fd) | |
| socksd_getconfig(); | |
| - | if((++connections == 2) && (s_config.responsemethod2 != |
| - | CONFIG_RESPONSEMETHOD2)) |
| - | s_config.responsemethod = s_config.responsemethod2; |
| + | if(last_testnum != s_config.testnum) { |
| + | last_testnum = s_config.testnum; |
| + | connections = 0; |
| + | } |
| + | |
| + | if((++connections == 2) && (s_config.responsemethod2 >= 0)) |
| + | s_config.responsemethod = (unsigned char)s_config.responsemethod2; |
| rc = sread(fd, buffer, sizeof(buffer)); | |
| if(rc <= 0) { | |