summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2011-12-06 05:37:41 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2011-12-06 05:37:41 +0100
commit915ebf954d4247c4caeaea5a7e40fce30f19e1bc (patch)
tree6341d69bfbd0159537e94e0fe19480270b913ce8
downloadts3db_postgres-915ebf954d4247c4caeaea5a7e40fce30f19e1bc.tar.gz
ts3db_postgres-915ebf954d4247c4caeaea5a7e40fce30f19e1bc.tar.xz
ts3db_postgres-915ebf954d4247c4caeaea5a7e40fce30f19e1bc.zip
initial import, some test
-rw-r--r--.gitignore3
-rw-r--r--Makefile37
-rw-r--r--ts3db.c135
-rw-r--r--ts3db.h48
4 files changed, 223 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e3531ad
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.d
+*.o
+*.so
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..14ec492
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,37 @@
+TARGET:=libts3db_own.so
+TOP:=.
+
+headers:=$(wildcard ${TOP}/*.h)
+sources:=$(wildcard ${TOP}/*.c)
+deps:=$(sources:.c=.d)
+objects:=$(sources:.c=.o)
+
+
+32BIT=-m32
+CFLAGS=-fPIC $(32BIT) -g
+LDFLAGS=-shared -Wl,-soname,$(TARGET) $(32BIT)
+
+##############################################################################
+
+.PHONY: all clean
+
+all: $(TARGET)
+
+clean:
+ -$(RM) -r $(TARGET) $(objects) $(deps)
+
+ifneq ($(MAKECMDGOALS),clean)
+-include $(deps)
+endif
+
+##############################################################################
+# normal build
+
+$(TARGET): $(objects) $(deps)
+ $(CC) $(LDFLAGS) -o $(TARGET) $(objects)
+
+%.o: %.c
+ $(CC) $(CFLAGS) -MMD -c $< -o $@
+
+%.d: %.c
+ $(CC) $(CFLAGS) -MM -c $< -MF $@
diff --git a/ts3db.c b/ts3db.c
new file mode 100644
index 0000000..9f45ac4
--- /dev/null
+++ b/ts3db.c
@@ -0,0 +1,135 @@
+#include "ts3db.h"
+
+static log_callback log = 0;
+
+char *ts3dbplugin_version()
+{
+ // returns pointer to "127.0.0.1" in constant table ... strange maybe im mistaken here
+ return "0.1";
+}
+
+char *ts3dbplugin_name()
+{
+ // returns pointer to "MySQL plugin, (c)TeamSpeak Systems GmbH" in constant table
+ return "My own DB Plugin";
+}
+
+int ts3dbplugin_disconnect()
+{
+ // load zero terminated array of db connections from global variable
+ // iterate over array elements, call mysql_close on all elements and zero them
+ return 0;
+}
+
+void ts3dbplugin_shutdown()
+{
+ // same as ts3dbplugin_disconnect() but no return 0
+}
+
+int ts3dbplugin_init(log_callback logging, char *parameter)
+{
+ char buf[100];
+
+ log = logging;
+ log("init called", 5);
+ int bar = log(0, 4);
+ sprintf(buf,"%d",bar);
+ log(buf, 5);
+ log(parameter, 5);
+
+ // logcallback is saved to global variable
+ // put pointer do some global structure with offset 12 is saved in variable
+ // if 2nd parameter or its target is zero "tb3db_mysql.ini" is written to a variable
+ // else the pointer is saved its length is determined and saved also saved (saved in variables)
+ // ini file is parsed and values are saved to global variables
+ return 0;
+}
+
+int ts3dbplugin_connect(unsigned int *connection_nr)
+{
+ log("connect called", 5);
+ *connection_nr = 1337;
+
+ // only does somthing usefull when there are less than 100 connections in the connection array
+ // calls mysql_init
+ // big function is big ... needs work
+ // seems to returns 0 on succses seems to return 1280 on failure
+ return 0;
+}
+
+char *ts3dbplugin_getlasterror(unsigned int connection_nr)
+{
+ log("getlasterror called", 5);
+ char buf[100];
+ sprintf(buf,"%d", connection_nr);
+ log(buf, 5);
+
+ // returns output of mysql_error for the connection of the given connection number
+ return "nothing";
+}
+
+unsigned int ts3dbplugin_tableexists(unsigned int connection_nr, const char* regex)
+{
+ log("tableexists called", 5);
+ char buf[100];
+ sprintf(buf,"%d", connection_nr);
+ log(buf, 5);
+ log(regex, 5);
+
+ // returns 0 when no table is found 1 if it is found
+ return 1;
+}
+
+unsigned long long ts3dbplugin_getmodifiedrowcount(unsigned int connection_nr)
+{
+ log("get modified row count", 5);
+ char buf[100];
+ sprintf(buf,"%d", connection_nr);
+ log(buf, 5);
+
+ // returns output of mysql_affected_rows for given connection
+ return 0LL;
+}
+
+unsigned long long ts3dbplugin_getlastinsertid(unsigned int connection_nr)
+{
+ log("get last inserted id", 5);
+ char buf[100];
+ sprintf(buf,"%d", connection_nr);
+ log(buf, 5);
+
+ // returns output of mysql_insert_id for given connection
+ return 0LL;
+}
+
+unsigned int ts3dbplugin_open(unsigned int connection_nr, const char* query,
+ field_callback new_field, value_callback new_value,
+ row_callback new_row, void *context)
+{
+ log("open", 5);
+ char buf[100];
+ sprintf(buf,"%d", connection_nr);
+ log(buf, 5);
+ log(query, 5);
+
+ // get query result
+ // if row ends value is 0
+ // returns 0 for success or 1280 for fail
+ return 0;
+}
+
+unsigned int ts3dbplugin_exec(unsigned int connection_nr, const char* query)
+{
+ log("exec", 5);
+ char buf[100];
+ sprintf(buf,"%d", connection_nr);
+ log(buf, 5);
+ log(query, 5);
+
+ // form sqlite plugin
+ // executes querry -> retrys every 200ms if db is locked, busy or when the db shema has changed
+ // return 1284 if db is full
+ // when result is SQLITE_OK return 0
+ // else do error handling and return 1280
+ return 0;
+}
diff --git a/ts3db.h b/ts3db.h
new file mode 100644
index 0000000..2c7c4cf
--- /dev/null
+++ b/ts3db.h
@@ -0,0 +1,48 @@
+#ifndef TS3DB_H
+#define TS3DB_H
+
+typedef enum {
+ CRITICAL = 0,
+ ERROR = 1,
+ WARNING = 2,
+ DEBUG = 3,
+ INFO = 4,
+ DEVELOP = 5
+} loglevel;
+
+// common/log/log.cpp:73:
+// void Log::logging(const std::string&, LogLevel, const std::string&, uint64)
+// Assertion `lvl >= LogLevel_CRITICAL && lvl <= LogLevel_DEVEL' failed.
+typedef int(*log_callback) (const char *msg, loglevel level);
+
+typedef void(*field_callback) (unsigned int res_nr, char* fieldname, void *context);
+typedef void(*value_callback) (unsigned int index, char *value, void* context);
+typedef void(*row_callback) (void* context);
+
+char *ts3dbplugin_version();
+
+char *ts3dbplugin_name();
+
+int ts3dbplugin_disconnect();
+
+void ts3dbplugin_shutdown();
+
+int ts3dbplugin_init(log_callback log, char *parameter);
+
+int ts3dbplugin_connect(unsigned int *connection_nr);
+
+char *ts3dbplugin_getlasterror(unsigned int connection_nr);
+
+unsigned int ts3dbplugin_tableexists(unsigned int connection_nr, const char* table_name);
+
+unsigned long long ts3dbplugin_getmodifiedrowcount(unsigned int connection_nr);
+
+unsigned long long ts3dbplugin_getlastinsertid(unsigned int connection_nr);
+
+unsigned int ts3dbplugin_open(unsigned int connection_nr, const char* query,
+ field_callback new_field, value_callback new_value,
+ row_callback new_row, void *context);
+
+unsigned int ts3dbplugin_exec(unsigned int connection_nr, const char* query);
+
+#endif