Skip to content

Commit ea0c3fc

Browse files
author
Alexey Botchkov
committed
MDEV-9438 backport feedback-http-proxy to 5.5 and 10.0.
The http-proxy option to the FEEDBACK plugin backported.
1 parent b17a435 commit ea0c3fc

File tree

7 files changed

+102
-13
lines changed

7 files changed

+102
-13
lines changed

mysql-test/suite/plugins/r/feedback_plugin_install.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ select * from information_schema.feedback where variable_name like 'feed%'
88
VARIABLE_NAME VARIABLE_VALUE
99
FEEDBACK used 1
1010
FEEDBACK version 1.1
11+
FEEDBACK_HTTP_PROXY
1112
FEEDBACK_SEND_RETRY_WAIT 60
1213
FEEDBACK_SEND_TIMEOUT 60
1314
FEEDBACK_URL http://mariadb.org/feedback_plugin/post

mysql-test/suite/plugins/r/feedback_plugin_load.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ select * from information_schema.feedback where variable_name like 'feed%'
1010
and variable_name not like '%debug%';
1111
VARIABLE_NAME VARIABLE_VALUE
1212
FEEDBACK version 1.1
13+
FEEDBACK_HTTP_PROXY
1314
FEEDBACK_SEND_RETRY_WAIT 60
1415
FEEDBACK_SEND_TIMEOUT 60
1516
FEEDBACK_URL http://mariadb.org/feedback_plugin/post

mysql-test/suite/plugins/r/feedback_plugin_send.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ select * from information_schema.feedback where variable_name like 'feed%'
1010
and variable_name not like '%debug%';
1111
VARIABLE_NAME VARIABLE_VALUE
1212
FEEDBACK version 1.1
13+
FEEDBACK_HTTP_PROXY
1314
FEEDBACK_SEND_RETRY_WAIT 60
1415
FEEDBACK_SEND_TIMEOUT 60
1516
FEEDBACK_URL http://mariadb.org/feedback_plugin/post

plugin/feedback/feedback.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ulong debug_startup_interval, debug_first_interval, debug_interval;
2929
char server_uid_buf[SERVER_UID_SIZE+1]; ///< server uid will be written here
3030

3131
/* backing store for system variables */
32-
static char *server_uid= server_uid_buf, *url;
32+
static char *server_uid= server_uid_buf, *url, *http_proxy;
3333
char *user_info;
3434
ulong send_timeout, send_retry_wait;
3535

@@ -284,7 +284,13 @@ static int init(void *p)
284284
if (*e == 0 || *e == ' ')
285285
{
286286
if (e > s && (urls[slot]= Url::create(s, e - s)))
287+
{
288+
if (urls[slot]->set_proxy(http_proxy,
289+
http_proxy ? strlen(http_proxy) : 0))
290+
sql_print_error("feedback plugin: invalid proxy '%s'",
291+
http_proxy ? http_proxy : "");
287292
slot++;
293+
}
288294
else
289295
{
290296
if (e > s)
@@ -362,6 +368,9 @@ static MYSQL_SYSVAR_ULONG(send_timeout, send_timeout, PLUGIN_VAR_RQCMDARG,
362368
static MYSQL_SYSVAR_ULONG(send_retry_wait, send_retry_wait, PLUGIN_VAR_RQCMDARG,
363369
"Wait this many seconds before retrying a failed send.",
364370
NULL, NULL, 60, 1, 60*60*24, 1);
371+
static MYSQL_SYSVAR_STR(http_proxy, http_proxy,
372+
PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG,
373+
"Proxy server host:port.", NULL, NULL,0);
365374

366375
#ifndef DBUG_OFF
367376
static MYSQL_SYSVAR_ULONG(debug_startup_interval, debug_startup_interval,
@@ -381,6 +390,7 @@ static struct st_mysql_sys_var* settings[] = {
381390
MYSQL_SYSVAR(url),
382391
MYSQL_SYSVAR(send_timeout),
383392
MYSQL_SYSVAR(send_retry_wait),
393+
MYSQL_SYSVAR(http_proxy),
384394
#ifndef DBUG_OFF
385395
MYSQL_SYSVAR(debug_startup_interval),
386396
MYSQL_SYSVAR(debug_first_interval),

plugin/feedback/feedback.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ class Url {
5151
const char *url() { return full_url.str; }
5252
size_t url_length() { return full_url.length; }
5353
virtual int send(const char* data, size_t data_length) = 0;
54+
virtual int set_proxy(const char *proxy, size_t proxy_len)
55+
{
56+
return 0;
57+
}
5458

5559
static Url* create(const char *url, size_t url_length);
60+
static int parse_proxy_server(const char *proxy_server, size_t proxy_length,
61+
LEX_STRING *host, LEX_STRING *port);
5662
};
5763

5864
extern Url **urls;

plugin/feedback/url_base.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,49 @@ Url* Url::create(const char *url, size_t url_length)
4848
return self;
4949
}
5050

51+
int Url::parse_proxy_server(const char *proxy_server, size_t proxy_length,
52+
LEX_STRING *host, LEX_STRING *port)
53+
{
54+
const char *s;
55+
56+
host->length= 0;
57+
if (proxy_server == NULL)
58+
return 0;
59+
60+
for (; proxy_length > 0 && my_isspace(system_charset_info, *proxy_server);
61+
proxy_server++, proxy_length--) /* no-op */;
62+
63+
if (proxy_length == 0)
64+
return 0;
65+
66+
for (s=proxy_server; *s && *s != ':'; s++) /* no-op */;
67+
68+
host->str= const_cast<char*>(proxy_server);
69+
if ((host->length= s-proxy_server) == 0)
70+
return 0;
71+
72+
port->length= 0;
73+
74+
if (*s == ':')
75+
{
76+
s++;
77+
port->str= const_cast<char*>(s);
78+
while (*s >= '0' && *s <= '9')
79+
{
80+
s++;
81+
port->length++;
82+
}
83+
}
84+
85+
if (port->length == 0)
86+
{
87+
port->str= const_cast<char*>("80");
88+
port->length= 2;
89+
}
90+
91+
host->str= my_strndup(host->str, host->length, MYF(MY_WME));
92+
port->str= my_strndup(port->str, port->length, MYF(MY_WME));
93+
return 0;
94+
}
95+
5196
} // namespace feedback

plugin/feedback/url_http.cc

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,39 @@ class Url_http: public Url {
3838
protected:
3939
const LEX_STRING host, port, path;
4040
bool ssl;
41+
LEX_STRING proxy_host, proxy_port;
42+
43+
int use_proxy()
44+
{
45+
return proxy_host.length;
46+
}
4147

4248
Url_http(LEX_STRING &url_arg, LEX_STRING &host_arg,
4349
LEX_STRING &port_arg, LEX_STRING &path_arg, bool ssl_arg) :
4450
Url(url_arg), host(host_arg), port(port_arg), path(path_arg), ssl(ssl_arg)
45-
{}
51+
{
52+
proxy_host.length= 0;
53+
}
4654
~Url_http()
4755
{
4856
my_free(host.str);
4957
my_free(port.str);
5058
my_free(path.str);
59+
set_proxy(0,0);
5160
}
5261

5362
public:
5463
int send(const char* data, size_t data_length);
64+
int set_proxy(const char *proxy, size_t proxy_len)
65+
{
66+
if (use_proxy())
67+
{
68+
my_free(proxy_host.str);
69+
my_free(proxy_port.str);
70+
}
71+
72+
return parse_proxy_server(proxy, proxy_len, &proxy_host, &proxy_port);
73+
}
5574

5675
friend Url* http_create(const char *url, size_t url_length);
5776
};
@@ -150,7 +169,9 @@ int Url_http::send(const char* data, size_t data_length)
150169
uint len= 0;
151170

152171
addrinfo *addrs, *addr, filter= {0, AF_UNSPEC, SOCK_STREAM, 6, 0, 0, 0, 0};
153-
int res= getaddrinfo(host.str, port.str, &filter, &addrs);
172+
int res= use_proxy() ?
173+
getaddrinfo(proxy_host.str, proxy_port.str, &filter, &addrs) :
174+
getaddrinfo(host.str, port.str, &filter, &addrs);
154175

155176
if (res)
156177
{
@@ -228,16 +249,20 @@ int Url_http::send(const char* data, size_t data_length)
228249
};
229250

230251
len= my_snprintf(buf, sizeof(buf),
231-
"POST %s HTTP/1.0\r\n"
232-
"User-Agent: MariaDB User Feedback Plugin\r\n"
233-
"Host: %s:%s\r\n"
234-
"Accept: */*\r\n"
235-
"Content-Length: %u\r\n"
236-
"Content-Type: multipart/form-data; boundary=%s\r\n"
237-
"\r\n",
238-
path.str, host.str, port.str,
239-
(uint)(2*boundary.length + header.length + data_length + 4),
240-
boundary.str + 2);
252+
use_proxy() ? "POST http://%s:%s/" : "POST ",
253+
host.str, port.str);
254+
255+
len+= my_snprintf(buf+len, sizeof(buf)-len,
256+
"%s HTTP/1.0\r\n"
257+
"User-Agent: MariaDB User Feedback Plugin\r\n"
258+
"Host: %s:%s\r\n"
259+
"Accept: */*\r\n"
260+
"Content-Length: %u\r\n"
261+
"Content-Type: multipart/form-data; boundary=%s\r\n"
262+
"\r\n",
263+
path.str, host.str, port.str,
264+
(uint)(2*boundary.length + header.length + data_length + 4),
265+
boundary.str + 2);
241266

242267
vio_timeout(vio, FOR_READING, send_timeout);
243268
vio_timeout(vio, FOR_WRITING, send_timeout);

0 commit comments

Comments
 (0)