CFLAGS=-Wall -Wshadow -Werror
all:
- gcc -g -O2 -I. -c IRCEvents.c -o IRCEvents.o ${CFLAGS}
- gcc -g -O2 -I. -c main.c -o main.o ${CFLAGS}
- gcc -g -O2 -I. -c ChanNode.c -o ChanNode.o ${CFLAGS}
- gcc -g -O2 -I. -c IRCParser.c -o IRCParser.o ${CFLAGS}
- gcc -g -O2 -I. -c ClientSocket.c -o ClientSocket.o ${CFLAGS}
- gcc -g -O2 -I. -c UserNode.c -o UserNode.o ${CFLAGS}
- gcc -g -O2 -I. -c ChanUser.c -o ChanUser.o ${CFLAGS}
- gcc -g -O2 -I. -c WHOHandler.c -o WHOHandler.o ${CFLAGS}
- gcc -g -O2 -I. -c modcmd.c -o modcmd.o ${CFLAGS}
- gcc -g -O2 -I. -c bots.c -o bots.o ${CFLAGS}
- gcc -g -O2 -I. -c bot_NeonServ.c -o bot_NeonServ.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c IRCEvents.c -o IRCEvents.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c main.c -o main.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c ChanNode.c -o ChanNode.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c IRCParser.c -o IRCParser.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c ClientSocket.c -o ClientSocket.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c UserNode.c -o UserNode.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c ChanUser.c -o ChanUser.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c WHOHandler.c -o WHOHandler.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c modcmd.c -o modcmd.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c mysqlConn.c -o mysqlConn.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c bots.c -o bots.o ${CFLAGS}
+ gcc -g -O2 -I. -I/usr/include/mysql -c bot_NeonServ.c -o bot_NeonServ.o ${CFLAGS}
install:
- gcc -g -O0 -I. -o neonserv *.o ${CFLAGS}
+ gcc -g -O0 -I. -I/usr/include/mysql -o neonserv *.o ${CFLAGS} -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto
clean:
rm *.o
--- /dev/null
+
+#include "mysqlConn.h"
+
+struct used_result {
+ MYSQL_RES *result;
+ struct used_result *next;
+};
+
+static MYSQL *mysql_conn = NULL;
+static struct used_result *used_results;
+
+MYSQL *getMySQL() {
+ return mysql_conn;
+}
+
+void check_mysql() {
+ if(mysql_ping(mysql_conn)) {
+ //mysql error
+ }
+}
+
+MYSQL_RES *mysql_use() {
+ MYSQL_RES *res = mysql_use_result(mysql_conn);
+ struct used_result *result = malloc(sizeof(*result));
+ if (!result) {
+ mysql_free_result(res);
+ return NULL;
+ }
+ result->result = res;
+ result->next = used_results;
+ used_results = result;
+ return res;
+}
+
+void mysql_free() {
+ struct used_result *result, *next;
+ for(result = used_results; result; result = next) {
+ next = result->next;
+ mysql_free_result(result->result);
+ free(result);
+ }
+}
+
+void init_mysql() {
+ mysql_conn = mysql_init(NULL);
+ if (!mysql_real_connect(mysql_conn, MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_BASE, MYSQL_PORT, NULL, 0)) {
+ //error
+ }
+}
+
+void free_mysql() {
+ mysql_close(mysql_conn);
+}
+