Abstract the session default database
The default database can now be manipulated with a set of functions exposed by the maxscale/protocol/mysql.h header. This removes the need to handle the structures themselves in the modules and is a step towards moving the dcb->data contents inside the session.
This commit is contained in:
2
server/modules/filter/cache/CMakeLists.txt
vendored
2
server/modules/filter/cache/CMakeLists.txt
vendored
@ -17,7 +17,7 @@ if (JANSSON_FOUND)
|
||||
storagefactory.cc
|
||||
storagereal.cc
|
||||
)
|
||||
target_link_libraries(cache maxscale-common ${JANSSON_LIBRARIES})
|
||||
target_link_libraries(cache maxscale-common ${JANSSON_LIBRARIES} MySQLCommon)
|
||||
set_target_properties(cache PROPERTIES VERSION "1.0.0")
|
||||
set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs)
|
||||
install_module(cache core)
|
||||
|
||||
@ -205,15 +205,15 @@ CacheFilterSession* CacheFilterSession::Create(Cache* pCache, MXS_SESSION* pSess
|
||||
ss_dassert(pSession->client_dcb);
|
||||
ss_dassert(pSession->client_dcb->data);
|
||||
|
||||
MYSQL_session *pMysqlSession = (MYSQL_session*)pSession->client_dcb->data;
|
||||
const char* zDb = mxs_mysql_get_current_db(pSession);
|
||||
char* zDefaultDb = NULL;
|
||||
|
||||
if (pMysqlSession->db[0] != 0)
|
||||
if (zDb[0] != 0)
|
||||
{
|
||||
zDefaultDb = MXS_STRDUP(pMysqlSession->db);
|
||||
zDefaultDb = MXS_STRDUP(zDb);
|
||||
}
|
||||
|
||||
if ((pMysqlSession->db[0] == 0) || zDefaultDb)
|
||||
if ((zDb[0] == 0) || zDefaultDb)
|
||||
{
|
||||
pCacheFilterSession = new (std::nothrow) CacheFilterSession(pSession, pCache, zDefaultDb);
|
||||
|
||||
|
||||
@ -7,13 +7,13 @@ if(BISON_FOUND AND FLEX_FOUND)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_library(dbfwfilter SHARED dbfwfilter.c ${BISON_ruleparser_OUTPUTS} ${FLEX_token_OUTPUTS})
|
||||
target_link_libraries(dbfwfilter maxscale-common)
|
||||
target_link_libraries(dbfwfilter maxscale-common MySQLCommon)
|
||||
set_target_properties(dbfwfilter PROPERTIES VERSION "1.0.0")
|
||||
install_module(dbfwfilter core)
|
||||
|
||||
# The offline rule check utility
|
||||
add_executable(dbfwchk dbfw_rule_check.c ${BISON_ruleparser_OUTPUTS} ${FLEX_token_OUTPUTS})
|
||||
target_link_libraries(dbfwchk maxscale-common)
|
||||
target_link_libraries(dbfwchk maxscale-common MySQLCommon)
|
||||
install_executable(dbfwchk core)
|
||||
|
||||
else()
|
||||
|
||||
@ -1745,7 +1745,7 @@ GWBUF* gen_dummy_error(FW_SESSION* session, char* msg)
|
||||
}
|
||||
|
||||
dcb = session->session->client_dcb;
|
||||
mysql_session = (MYSQL_session*) dcb->data;
|
||||
const char* db = mxs_mysql_get_current_db(session->session);
|
||||
errlen = msg != NULL ? strlen(msg) : 0;
|
||||
errmsg = (char*) MXS_MALLOC((512 + errlen) * sizeof(char));
|
||||
|
||||
@ -1755,14 +1755,14 @@ GWBUF* gen_dummy_error(FW_SESSION* session, char* msg)
|
||||
}
|
||||
|
||||
|
||||
if (mysql_session->db[0] == '\0')
|
||||
if (db[0] == '\0')
|
||||
{
|
||||
sprintf(errmsg, "Access denied for user '%s'@'%s'", dcb->user, dcb->remote);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(errmsg, "Access denied for user '%s'@'%s' to database '%s'",
|
||||
dcb->user, dcb->remote, mysql_session->db);
|
||||
dcb->user, dcb->remote, db);
|
||||
}
|
||||
|
||||
if (msg != NULL)
|
||||
|
||||
@ -807,21 +807,15 @@ void pushMessage(MQ_INSTANCE *instance, amqp_basic_properties_t* prop, char* msg
|
||||
static MXS_FILTER_SESSION *
|
||||
newSession(MXS_FILTER *instance, MXS_SESSION *session)
|
||||
{
|
||||
MYSQL_session *sessauth = session->client_dcb->data;
|
||||
char *db = sessauth->db;
|
||||
if (db)
|
||||
const char *db = mxs_mysql_get_current_db(session);
|
||||
char* my_db = NULL;
|
||||
|
||||
if (*db)
|
||||
{
|
||||
if (strnlen(db, 128) > 0)
|
||||
my_db = MXS_STRDUP(my_db);
|
||||
if (!my_db)
|
||||
{
|
||||
db = MXS_STRDUP(db);
|
||||
if (!db)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
db = NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -832,11 +826,11 @@ newSession(MXS_FILTER *instance, MXS_SESSION *session)
|
||||
my_session->was_query = false;
|
||||
my_session->uid = NULL;
|
||||
my_session->session = session;
|
||||
my_session->db = db;
|
||||
my_session->db = my_db;
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_FREE(db);
|
||||
MXS_FREE(my_db);
|
||||
}
|
||||
|
||||
return (MXS_FILTER_SESSION*)my_session;
|
||||
|
||||
Reference in New Issue
Block a user