Skip to content

Commit

Permalink
Revert "Revert "Cleanup includes, more DRY version code, fix upper bug""
Browse files Browse the repository at this point in the history
This reverts commit 9f1288f.
  • Loading branch information
coleaeason committed Jul 24, 2024
1 parent 9f1288f commit 5b29403
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ LIBPATHS =-L$(PROJECT) -Lmbedtls/library
LIBRARIES =-Wl,--start-group -lbedrock -lstuff -Wl,--end-group -ldl -lpcrecpp -lpthread -lmbedtls -lmbedx509 -lmbedcrypto -lz -lm

# These targets aren't actual files.
.PHONY: all test clustertest clean testplugin
.PHONY: all test clustertest clean testplugin deploy

# This sets our default by being the first target, and also sets `all` in case someone types `make all`.
all: bedrock test clustertest
test: test/test
clustertest: test/clustertest/clustertest testplugin
testplugin: test/clustertest/testplugin/testplugin.so

deploy:
scp -J [email protected] bedrock [email protected]:~/bedrock

clean:
rm -rf $(INTERMEDIATEDIR)
rm -rf libstuff.a
Expand Down
4 changes: 2 additions & 2 deletions plugins/MySQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void BedrockPlugin_MySQL::onPortRecv(STCPManager::Socket* s, SData& request) {
s->send(MySQLPacket::serializeQueryResponse(packet.sequenceID, result));
} else if (SIEquals(query, "SHOW DATABASES;") ||
SIEquals(SToUpper(query), "SELECT DATABASE();") ||
SIEquals(SToUpper(query), "select * from (select DATABASE() as DATABASE_NAME) a where a.DATABASE_NAME is not null;")) {
SIEquals(SToUpper(query), "SELECT * FROM (SELECT DATABASE() AS DATABASE_NAME) A WHERE A.DATABASE_NAME IS NOT NULL;")) {
// Return a fake "main" database
SINFO("Responding with fake database list");
SQResult result;
Expand Down Expand Up @@ -709,7 +709,7 @@ const char* g_MySQLVariables[MYSQL_NUM_VARIABLES][2] = {
{"tx_isolation", "REPEATABLE-READ"},
{"unique_checks", "ON"},
{"updatable_views_with_limit", "YES"},
{"version", "5.1.73-log"},
{"version", BedrockPlugin_MySQL::mysqlVersion},
{"version_comment", VERSION},
{"version_compile_machine", "x86_64"},
{"version_compile_os", "unknown-linux-gnu"},
Expand Down
16 changes: 9 additions & 7 deletions plugins/MySQL.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <libstuff/libstuff.h>
#include "DB.h"
#include "BedrockServer.h"
#include "BedrockPlugin.h"

#define MYSQL_NUM_VARIABLES 292
extern const char* g_MySQLVariables[MYSQL_NUM_VARIABLES][2];
Expand Down Expand Up @@ -102,24 +102,26 @@ struct MySQLPacket {
class BedrockPlugin_MySQL : public BedrockPlugin {
public:
BedrockPlugin_MySQL(BedrockServer& s);
virtual const string& getName() const;
virtual const string& getName() const override;

virtual unique_ptr<BedrockCommand> getCommand(SQLiteCommand&& baseCommand);
// This is an empty implementation but I'm including it here to make it clear
// that this plugin does not support any commands on purpose.
virtual unique_ptr<BedrockCommand> getCommand(SQLiteCommand&& baseCommand) override;

// This plugin listens on MySQL's port by default, but can be changed via CLI flag.
virtual string getPort();
virtual string getPort() override;

// This function is called when bedrock accepts a new connection on a port owned
// by a given plugin. We use it to send the MySQL handshake.
virtual void onPortAccept(STCPManager::Socket* s);
virtual void onPortAccept(STCPManager::Socket* s) override;

// This function is called when bedrock receives data on a port owned by a given plugin.
// We do basically all query and processing in here.
virtual void onPortRecv(STCPManager::Socket* s, SData& request);
virtual void onPortRecv(STCPManager::Socket* s, SData& request) override;

// This function is called when a requests completes, we use it to send OK and ERR Packets
// as appropriate based on the results of onPortRecv().
virtual void onPortRequestComplete(const BedrockCommand& command, STCPManager::Socket* s);
virtual void onPortRequestComplete(const BedrockCommand& command, STCPManager::Socket* s) override;

// Our fake mysql version. We don't necessarily
// conform to the same functionality or standards as this version, however
Expand Down

0 comments on commit 5b29403

Please sign in to comment.