MXS-1835 Turn all protocol modules into C++

This commit is contained in:
Johan Wikman
2018-04-27 12:04:35 +03:00
parent da16ba538d
commit 7876c3c70f
10 changed files with 58 additions and 36 deletions

View File

@ -1,4 +1,4 @@
add_library(cdc SHARED cdc.c) add_library(cdc SHARED cdc.cc)
target_link_libraries(cdc maxscale-common) target_link_libraries(cdc maxscale-common)
set_target_properties(cdc PROPERTIES VERSION "1.0.1") set_target_properties(cdc PROPERTIES VERSION "1.0.1")
install_module(cdc core) install_module(cdc core)

View File

@ -59,9 +59,11 @@ static void write_auth_err(DCB *dcb);
static char* cdc_default_auth() static char* cdc_default_auth()
{ {
return "CDCPlainAuth"; return const_cast<char*>("CDCPlainAuth");
} }
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -111,6 +113,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
}
/** /**
* Read event for EPOLLIN on the CDC protocol module. * Read event for EPOLLIN on the CDC protocol module.
* *

View File

@ -1,4 +1,4 @@
add_library(httpd SHARED httpd.c) add_library(httpd SHARED httpd.cc)
target_link_libraries(httpd maxscale-common) target_link_libraries(httpd maxscale-common)
set_target_properties(httpd PROPERTIES VERSION "1.0.1") set_target_properties(httpd PROPERTIES VERSION "1.0.1")
install_module(httpd core) install_module(httpd core)

View File

@ -57,6 +57,8 @@ static int httpd_get_line(int sock, char *buf, int size);
static void httpd_send_headers(DCB *dcb, int final, bool auth_ok); static void httpd_send_headers(DCB *dcb, int final, bool auth_ok);
static char *httpd_default_auth(); static char *httpd_default_auth();
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -105,6 +107,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
}
/*lint +e14 */ /*lint +e14 */
static const char* default_auth = "NullAuthAllow"; static const char* default_auth = "NullAuthAllow";
@ -139,7 +143,7 @@ static int httpd_read_event(DCB* dcb)
HTTPD_session *client_data = NULL; HTTPD_session *client_data = NULL;
GWBUF *uri; GWBUF *uri;
client_data = dcb->data; client_data = static_cast<HTTPD_session*>(dcb->data);
/** /**
* get the request line * get the request line

View File

@ -1,4 +1,4 @@
add_library(mariadbbackend SHARED mysql_backend.c) add_library(mariadbbackend SHARED mysql_backend.cc)
# TODO: Refactor mariadbbackend so that COM_CHANGE_USER processing is # TODO: Refactor mariadbbackend so that COM_CHANGE_USER processing is
# transparent to the protocol module. After this change, we don't need to # transparent to the protocol module. After this change, we don't need to
# link against mysqlauth. # link against mysqlauth.

View File

@ -58,6 +58,8 @@ static bool get_ip_string_and_port(struct sockaddr_storage *sa, char *ip, int ip
in_port_t *port_out); in_port_t *port_out);
static bool gw_connection_established(DCB* dcb); static bool gw_connection_established(DCB* dcb);
extern "C"
{
/* /*
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -107,6 +109,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
}
/** /**
* The default authenticator name for this protocol * The default authenticator name for this protocol
* *
@ -116,7 +120,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
*/ */
static char *gw_backend_default_auth() static char *gw_backend_default_auth()
{ {
return "MySQLBackendAuth"; return const_cast<char*>("MySQLBackendAuth");
} }
/*lint +e14 */ /*lint +e14 */
@ -416,7 +420,7 @@ static inline void prepare_for_write(DCB *dcb, GWBUF *buffer)
if (GWBUF_IS_TYPE_SESCMD(buffer)) if (GWBUF_IS_TYPE_SESCMD(buffer))
{ {
mxs_mysql_cmd_t cmd = mxs_mysql_get_command(buffer); mxs_mysql_cmd_t cmd = static_cast<mxs_mysql_cmd_t>(mxs_mysql_get_command(buffer));
protocol_add_srv_command(proto, cmd); protocol_add_srv_command(proto, cmd);
} }
if (GWBUF_SHOULD_COLLECT_RESULT(buffer)) if (GWBUF_SHOULD_COLLECT_RESULT(buffer))
@ -567,7 +571,7 @@ static void do_handle_error(DCB *dcb, mxs_error_action_t action, const char *err
if (!dcb->dcb_errhandle_called) if (!dcb->dcb_errhandle_called)
{ {
GWBUF *errbuf = mysql_create_custom_error(1, 0, errmsg); GWBUF *errbuf = mysql_create_custom_error(1, 0, errmsg);
void *rsession = session->router_session; MXS_ROUTER_SESSION *rsession = static_cast<MXS_ROUTER_SESSION*>(session->router_session);
MXS_ROUTER_OBJECT *router = session->service->router; MXS_ROUTER_OBJECT *router = session->service->router;
MXS_ROUTER *router_instance = session->service->router_instance; MXS_ROUTER *router_instance = session->service->router_instance;
@ -1102,7 +1106,7 @@ static int gw_write_backend_event(DCB *dcb)
*/ */
static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue) static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
{ {
MySQLProtocol *backend_protocol = dcb->protocol; MySQLProtocol *backend_protocol = static_cast<MySQLProtocol*>(dcb->protocol);
int rc = 0; int rc = 0;
CHK_DCB(dcb); CHK_DCB(dcb);
@ -1152,7 +1156,8 @@ static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
return 1; return 1;
} }
GWBUF *buf = gw_create_change_user_packet(dcb->session->client_dcb->data, dcb->protocol); GWBUF *buf = gw_create_change_user_packet(static_cast<MYSQL_session*>(dcb->session->client_dcb->data),
static_cast<MySQLProtocol*>(dcb->protocol));
int rc = 0; int rc = 0;
if (dcb_write(dcb, buf)) if (dcb_write(dcb, buf))
@ -1222,7 +1227,7 @@ static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
case MXS_AUTH_STATE_COMPLETE: case MXS_AUTH_STATE_COMPLETE:
{ {
uint8_t* ptr = GWBUF_DATA(queue); uint8_t* ptr = GWBUF_DATA(queue);
mxs_mysql_cmd_t cmd = mxs_mysql_get_command(queue); mxs_mysql_cmd_t cmd = static_cast<mxs_mysql_cmd_t>(mxs_mysql_get_command(queue));
MXS_DEBUG("write to dcb %p fd %d protocol state %s.", MXS_DEBUG("write to dcb %p fd %d protocol state %s.",
dcb, dcb->fd, STRPROTOCOLSTATE(backend_protocol->protocol_auth_state)); dcb, dcb->fd, STRPROTOCOLSTATE(backend_protocol->protocol_auth_state));
@ -1426,7 +1431,7 @@ static int backend_write_delayqueue(DCB *dcb, GWBUF *buffer)
MYSQL_session mses; MYSQL_session mses;
gw_get_shared_session_auth_info(dcb, &mses); gw_get_shared_session_auth_info(dcb, &mses);
gwbuf_free(buffer); gwbuf_free(buffer);
buffer = gw_create_change_user_packet(&mses, dcb->protocol); buffer = gw_create_change_user_packet(&mses, static_cast<MySQLProtocol*>(dcb->protocol));
} }
int rc = 1; int rc = 1;
@ -1480,8 +1485,8 @@ static int gw_change_user(DCB *backend,
int auth_ret = 1; int auth_ret = 1;
current_session = (MYSQL_session *)in_session->client_dcb->data; current_session = (MYSQL_session *)in_session->client_dcb->data;
backend_protocol = backend->protocol; backend_protocol = static_cast<MySQLProtocol*>(backend->protocol);
client_protocol = in_session->client_dcb->protocol; client_protocol = static_cast<MySQLProtocol*>(in_session->client_dcb->protocol);
/* now get the user, after 4 bytes header and 1 byte command */ /* now get the user, after 4 bytes header and 1 byte command */
client_auth_packet += 5; client_auth_packet += 5;
@ -1586,16 +1591,14 @@ static int gw_change_user(DCB *backend,
if (auth_ret != 0) if (auth_ret != 0)
{ {
char *password_set = NULL; bool password_set = false;
char *message = NULL; char *message = NULL;
if (auth_token_len > 0) if (auth_token_len > 0)
{ {
password_set = (char *)client_sha1; // If the length of the authentication token is non-0, then
} // it means that the client provided a password.
else password_set = true;
{
password_set = "";
} }
/** /**
@ -1608,7 +1611,7 @@ static int gw_change_user(DCB *backend,
message = create_auth_fail_str(username, message = create_auth_fail_str(username,
backend->session->client_dcb->remote, backend->session->client_dcb->remote,
password_set, password_set,
false, NULL,
auth_ret); auth_ret);
if (message == NULL) if (message == NULL)
{ {
@ -1665,11 +1668,11 @@ static GWBUF* process_response_data(DCB* dcb,
int nbytes_to_process) int nbytes_to_process)
{ {
int npackets_left = 0; /*< response's packet count */ int npackets_left = 0; /*< response's packet count */
size_t nbytes_left = 0; /*< nbytes to be read for the packet */ int nbytes_left = 0; /*< nbytes to be read for the packet */
MySQLProtocol* p; MySQLProtocol* p;
GWBUF* outbuf = NULL; GWBUF* outbuf = NULL;
int initial_packets = npackets_left; int initial_packets = npackets_left;
size_t initial_bytes = nbytes_left; int initial_bytes = nbytes_left;
/** Get command which was stored in gw_MySQLWrite_backend */ /** Get command which was stored in gw_MySQLWrite_backend */
p = DCB_PROTOCOL(dcb, MySQLProtocol); p = DCB_PROTOCOL(dcb, MySQLProtocol);
@ -1696,7 +1699,9 @@ static GWBUF* process_response_data(DCB* dcb,
*/ */
if (npackets_left == 0) if (npackets_left == 0)
{ {
succp = protocol_get_response_status(p, &npackets_left, &nbytes_left); size_t bytes; // nbytes_left is int, but the type must be size_t.
succp = protocol_get_response_status(p, &npackets_left, &bytes);
nbytes_left = bytes;
if (!succp || npackets_left == 0) if (!succp || npackets_left == 0)
{ {
@ -1706,7 +1711,8 @@ static GWBUF* process_response_data(DCB* dcb,
* packet content. Fails if read buffer doesn't include * packet content. Fails if read buffer doesn't include
* enough data to read the packet length. * enough data to read the packet length.
*/ */
init_response_status(*readbuf, srvcmd, &npackets_left, &nbytes_left); init_response_status(*readbuf, srvcmd, &npackets_left, &bytes);
nbytes_left = bytes;
} }
initial_packets = npackets_left; initial_packets = npackets_left;
@ -1716,7 +1722,7 @@ static GWBUF* process_response_data(DCB* dcb,
ss_dassert(npackets_left > 0); ss_dassert(npackets_left > 0);
/** Read incomplete packet. */ /** Read incomplete packet. */
if (nbytes_left > nbytes_to_process) if ((int)nbytes_left > nbytes_to_process)
{ {
/** Includes length info so it can be processed */ /** Includes length info so it can be processed */
if (nbytes_to_process >= 5) if (nbytes_to_process >= 5)
@ -1728,7 +1734,7 @@ static GWBUF* process_response_data(DCB* dcb,
nbytes_to_process = 0; nbytes_to_process = 0;
} }
/** Packet was read. All bytes belonged to the last packet. */ /** Packet was read. All bytes belonged to the last packet. */
else if (nbytes_left == nbytes_to_process) else if ((int)nbytes_left == nbytes_to_process)
{ {
nbytes_left = 0; nbytes_left = 0;
nbytes_to_process = 0; nbytes_to_process = 0;
@ -1743,7 +1749,7 @@ static GWBUF* process_response_data(DCB* dcb,
*/ */
else else
{ {
ss_dassert(nbytes_left < nbytes_to_process); ss_dassert((int)nbytes_left < nbytes_to_process);
ss_dassert(nbytes_left > 0); ss_dassert(nbytes_left > 0);
ss_dassert(npackets_left > 0); ss_dassert(npackets_left > 0);
outbuf = gwbuf_append(outbuf, gwbuf_split(readbuf, nbytes_left)); outbuf = gwbuf_append(outbuf, gwbuf_split(readbuf, nbytes_left));
@ -2106,7 +2112,7 @@ static void gw_send_proxy_protocol_header(DCB *backend_dcb)
{ {
rval = snprintf(proxy_header, sizeof(proxy_header), "PROXY %s\r\n", family_str); rval = snprintf(proxy_header, sizeof(proxy_header), "PROXY %s\r\n", family_str);
} }
if (rval < 0 || rval >= sizeof(proxy_header)) if (rval < 0 || rval >= (int)sizeof(proxy_header))
{ {
MXS_ERROR("Proxy header printing error, produced '%s'.", proxy_header); MXS_ERROR("Proxy header printing error, produced '%s'.", proxy_header);
return; return;

View File

@ -1,4 +1,4 @@
add_library(maxscaled SHARED maxscaled.c) add_library(maxscaled SHARED maxscaled.cc)
target_link_libraries(maxscaled maxscale-common) target_link_libraries(maxscaled maxscale-common)
set_target_properties(maxscaled PROPERTIES VERSION "1.0.0") set_target_properties(maxscaled PROPERTIES VERSION "1.0.0")
install_module(maxscaled core) install_module(maxscaled core)

View File

@ -157,6 +157,8 @@ static bool authenticate_socket(MAXSCALED *protocol, DCB *dcb)
return authenticated; return authenticated;
} }
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -207,6 +209,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
}
/*lint +e14 */ /*lint +e14 */
/** /**
@ -216,7 +220,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
*/ */
static char *mxsd_default_auth() static char *mxsd_default_auth()
{ {
return "MaxAdminAuth"; return const_cast<char*>("MaxAdminAuth");
} }
/** /**
@ -397,7 +401,7 @@ static int maxscaled_accept(DCB *listener)
static int maxscaled_close(DCB *dcb) static int maxscaled_close(DCB *dcb)
{ {
MAXSCALED *maxscaled = dcb->protocol; MAXSCALED *maxscaled = static_cast<MAXSCALED*>(dcb->protocol);
if (!maxscaled) if (!maxscaled)
{ {
@ -424,7 +428,7 @@ static int maxscaled_close(DCB *dcb)
*/ */
static int maxscaled_listen(DCB *listener, char *config) static int maxscaled_listen(DCB *listener, char *config)
{ {
char *socket_path = NULL; const char *socket_path = NULL;
/* check for default UNIX socket */ /* check for default UNIX socket */
if (strncmp(config, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG_LEN) == 0) if (strncmp(config, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG_LEN) == 0)

View File

@ -1,4 +1,4 @@
add_library(telnetd SHARED telnetd.c) add_library(telnetd SHARED telnetd.cc)
target_link_libraries(telnetd maxscale-common) target_link_libraries(telnetd maxscale-common)
set_target_properties(telnetd PROPERTIES VERSION "1.0.1") set_target_properties(telnetd PROPERTIES VERSION "1.0.1")
install_module(telnetd core) install_module(telnetd core)

View File

@ -76,6 +76,8 @@ static char *telnetd_default_auth();
static void telnetd_command(DCB *, unsigned char *cmd); static void telnetd_command(DCB *, unsigned char *cmd);
static void telnetd_echo(DCB *dcb, int enable); static void telnetd_echo(DCB *dcb, int enable);
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -125,6 +127,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
}; };
return &info; return &info;
} }
}
/*lint +e14 */ /*lint +e14 */
/** /**
@ -134,7 +138,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
*/ */
static char *telnetd_default_auth() static char *telnetd_default_auth()
{ {
return "NullAuthAllow"; return const_cast<char*>("NullAuthAllow");
} }
/** /**
@ -315,7 +319,7 @@ static int telnetd_accept(DCB *listener)
static int telnetd_close(DCB *dcb) static int telnetd_close(DCB *dcb)
{ {
TELNETD *telnetd = dcb->protocol; TELNETD *telnetd = static_cast<TELNETD*>(dcb->protocol);
if (telnetd && telnetd->username) if (telnetd && telnetd->username)
{ {