Added MySQL Test Connection Feature
This commit is contained in:
parent
8e1af27309
commit
b0084cf9ae
13 changed files with 87 additions and 55 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -3,5 +3,8 @@ output.log
|
|||
main.o
|
||||
logger.o
|
||||
help.o
|
||||
logo.o
|
||||
sql_test.o
|
||||
test_gtk.o
|
||||
os_info.o
|
||||
netbenixCMD
|
||||
12
README.md
12
README.md
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
A little project of mine to learn C.
|
||||
|
||||
Available for: *Linux, (Windows coming soon)*
|
||||
Available for: *Linux*
|
||||
|
||||
Used Libs for Linux: *gtk+3.0*
|
||||
Used Libs for Linux: *gtk+3.0, libmysqlclient*
|
||||
|
||||
Version: *0.1.0*
|
||||
|
||||
## Features:
|
||||
- A help page (OMG!!!)
|
||||
- A little GTK Test
|
||||
- Can detect if you're using linux or Windows and tell the Architecture you're running on
|
||||
|
||||
## Building:
|
||||
### Linux
|
||||
Install packages: make, gtk3, libgtk-3-dev, gcc
|
||||
Install packages: make, gtk3, libgtk-3-dev, gcc, mysql
|
||||
|
||||
Clone Repositroy: ```git clone https://github.com/netbenix/netbenixCMD.git```
|
||||
|
||||
|
|
@ -22,13 +22,11 @@ Go into the just cloned directory
|
|||
|
||||
Build with command: ```make```
|
||||
|
||||
### Windows
|
||||
*Coming soon...*
|
||||
|
||||
## Usage
|
||||
After building use ```./netbenixCMD <argument>``` to start the program
|
||||
|
||||
## Arguments
|
||||
- ```--help``` => Displays all arguments
|
||||
- ```--gtk-test``` => Opens the GTK Test Window
|
||||
- ```--sql-test``` => Makes a test connection to a mysql server
|
||||
- ```--os-info``` => Outputs your OS Information
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
#include "gtk_test.h"
|
||||
#include "../utils/logger.h"
|
||||
|
||||
GtkWidget *window;
|
||||
GtkWidget *fixed1;
|
||||
GtkWidget *button1;
|
||||
GtkWidget *label;
|
||||
GtkWidget *gay_check;
|
||||
GtkWidget *check;
|
||||
GtkWidget *level;
|
||||
GtkBuilder *builder;
|
||||
|
||||
|
|
@ -22,7 +23,7 @@ void createGTKTestWindow(){
|
|||
fixed1 = GTK_WIDGET(gtk_builder_get_object(builder, "fixed1"));
|
||||
button1 = GTK_WIDGET(gtk_builder_get_object(builder, "button1"));
|
||||
label = GTK_WIDGET(gtk_builder_get_object(builder, "label"));
|
||||
gay_check = GTK_WIDGET(gtk_builder_get_object(builder, "gay_check"));
|
||||
check = GTK_WIDGET(gtk_builder_get_object(builder, "check"));
|
||||
level = GTK_WIDGET(gtk_builder_get_object(builder, "level"));
|
||||
|
||||
gtk_widget_show(window);
|
||||
|
|
@ -52,11 +53,11 @@ void on_button1_clicked(GtkButton *b){
|
|||
|
||||
void on_gay_check_toggled(GtkToggleButton *t){
|
||||
if(gtk_toggle_button_get_active(t)){
|
||||
gtk_label_set_text(GTK_LABEL(label), (const gchar*) "Oh hey, I'm gay now.");
|
||||
logger("[GTK] Toggle 'gay_check' changed to toggled.");
|
||||
gtk_label_set_text(GTK_LABEL(label), (const gchar*) "Toggle checked.");
|
||||
logger("[GTK] Toggle 'check' changed to toggled.");
|
||||
} else {
|
||||
gtk_label_set_text(GTK_LABEL(label), (const gchar*) "Well, I'm not longer gay.");
|
||||
logger("[GTK] Toggle 'gay_check' changed to untoggled.");
|
||||
gtk_label_set_text(GTK_LABEL(label), (const gchar*) "Toggle unchecked.");
|
||||
logger("[GTK] Toggle 'check' changed to untoggled.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _TEST_GTK_H_
|
||||
#define _TEST_GTK_H_
|
||||
#ifndef _GTK_TEST_H_
|
||||
#define _GTK_TEST_H_
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
void createGTKTestWindow();
|
||||
|
|
@ -1,13 +1,5 @@
|
|||
#ifdef _WIN32 || _WIN64
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef linux
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define OS "LINUX"
|
||||
#endif
|
||||
|
||||
#include "help.h"
|
||||
|
||||
|
|
@ -15,6 +7,7 @@ void outputHelp(){
|
|||
printf("usage: netbenixCMD [option]\n");
|
||||
printf("Options:\n");
|
||||
printf("--help : this help page\n");
|
||||
printf("--gtk-test : opens the gtk test ; LINUX ONLY\n");
|
||||
printf("--gtk-test : opens the gtk test\n");
|
||||
printf("--sql-test : make a test connection to a mysql server\n");
|
||||
printf("--os-info : shows your os informations\n");
|
||||
}
|
||||
43
commands/sql_test.c
Normal file
43
commands/sql_test.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mysql/mysql.h>
|
||||
#include "sql_test.h"
|
||||
#include "../utils/logger.h"
|
||||
|
||||
|
||||
void testSQLConnection(){
|
||||
|
||||
MYSQL *sql;
|
||||
sql = mysql_init(NULL);
|
||||
char hostname[200];
|
||||
unsigned int port;
|
||||
char user[200];
|
||||
char* password;
|
||||
char database[200];
|
||||
|
||||
printf("====== SQL TEST ======\n");
|
||||
printf("Hostname: ");
|
||||
scanf("%s", &hostname);
|
||||
printf("Port: ");
|
||||
scanf("%u", &port);
|
||||
printf("Database: ");
|
||||
scanf("%s", &database);
|
||||
printf("Username: ");
|
||||
scanf("%s", &user);
|
||||
password = getpass("Password: ");
|
||||
|
||||
if(mysql_real_connect(sql, hostname, user, password, database, 33000, NULL, 0) == NULL){
|
||||
fprintf (stderr, "ERROR: mysql_real_connect():"
|
||||
"%u (%s)\n",mysql_errno (sql), mysql_error (sql));
|
||||
char buffer[1024];
|
||||
snprintf(buffer, sizeof(buffer), "[ERROR] mysql_read_connect(): %u (%s)\n", mysql_errno(sql), mysql_error(sql));
|
||||
logger(buffer);
|
||||
mysql_close(sql);
|
||||
} else {
|
||||
printf("Successfully connected to: %s", hostname);
|
||||
}
|
||||
|
||||
mysql_close(sql);
|
||||
}
|
||||
6
commands/sql_test.h
Normal file
6
commands/sql_test.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef _SQL_TEST_H_
|
||||
#define _SQL_TEST_H_
|
||||
|
||||
void testSQLConnection();
|
||||
|
||||
#endif
|
||||
|
|
@ -54,8 +54,8 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="gay_check">
|
||||
<property name="label" translatable="yes">I'm Gay.</property>
|
||||
<object class="GtkCheckButton" id="check">
|
||||
<property name="label" translatable="yes">Toggle</property>
|
||||
<property name="width_request">107</property>
|
||||
<property name="height_request">24</property>
|
||||
<property name="visible">True</property>
|
||||
|
|
|
|||
BIN
gtk_test.o
Normal file
BIN
gtk_test.o
Normal file
Binary file not shown.
21
main.c
21
main.c
|
|
@ -1,8 +1,3 @@
|
|||
#ifdef _WIN32 || _WIN64
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef linux
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
|
@ -10,14 +5,16 @@
|
|||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkconfig.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "commands/test_gtk.h"
|
||||
#endif
|
||||
#include "commands/gtk_test.h"
|
||||
|
||||
#include "etc/logo.h"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/os_info.h"
|
||||
#include "commands/help.h"
|
||||
|
||||
#include "commands/sql_test.h"
|
||||
|
||||
|
||||
#define VERSION "0.1.0"
|
||||
#define AUTHOR "netbenix"
|
||||
|
||||
|
|
@ -26,6 +23,7 @@ void exit_app(){
|
|||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
char buffer[1024];
|
||||
logger("================================================");
|
||||
|
|
@ -46,15 +44,14 @@ int main(int argc, char *argv[]){
|
|||
logger("Showing Help");
|
||||
outputHelp();
|
||||
} else if (!strcmp(argv[1], "--gtk-test")){
|
||||
#ifdef linux
|
||||
logger("Stating GTK Test");
|
||||
createGTKTestWindow();
|
||||
#else
|
||||
printf("[ERROR] gtk-test is linux only.\n");
|
||||
logger("[ERROR] gtk-test is linux only.");
|
||||
#endif
|
||||
} else if (!strcmp(argv[1], "--os-info")){
|
||||
logger("Showing OS Information");
|
||||
print_Specs();
|
||||
} else if (!strcmp(argv[1], "--sql-test")){
|
||||
logger("Starting SQL Test");
|
||||
testSQLConnection();
|
||||
} else {
|
||||
printf("Argument unknown. Please use --help for more information.\n");
|
||||
snprintf(buffer, sizeof(buffer), "[ERROR] Argument unknown. Given argument: %s", argv[1]);
|
||||
|
|
|
|||
12
makefile
12
makefile
|
|
@ -1,8 +1,8 @@
|
|||
CC= gcc
|
||||
ARGS= -export-dynamic
|
||||
CFLAGS= $(shell pkg-config --cflags gtk+-3.0)
|
||||
LDLIBS= $(shell pkg-config --libs gtk+-3.0)
|
||||
OBJ= main.o logo.o logger.o help.o os_info.o test_gtk.o
|
||||
CFLAGS= $(shell pkg-config --cflags gtk+-3.0) -I/usr/include/mysql
|
||||
LDLIBS= $(shell pkg-config --libs gtk+-3.0) -L/usr/lib/mysql -lmysqlclient
|
||||
OBJ= main.o logo.o logger.o help.o os_info.o gtk_test.o sql_test.o
|
||||
|
||||
netbenixCMD: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(ARGS) -o netbenixCMD $(OBJ) $(LDLIBS)
|
||||
|
|
@ -16,5 +16,7 @@ help.o: commands/help.c
|
|||
$(CC) $(CFLAGS) -c commands/help.c
|
||||
os_info.o: utils/os_info.c
|
||||
$(CC) $(CFLAGS) -c utils/os_info.c
|
||||
test_gtk.o: commands/test_gtk.c
|
||||
$(CC) $(CFLAGS) -c commands/test_gtk.c $(LDLIBS)
|
||||
gtk_test.o: commands/gtk_test.c
|
||||
$(CC) $(CFLAGS) -c commands/gtk_test.c
|
||||
sql_test.o: commands/sql_test.c
|
||||
$(CC) $(CFLAGS) -c commands/sql_test.c
|
||||
BIN
netbenixCMD
BIN
netbenixCMD
Binary file not shown.
|
|
@ -1,26 +1,15 @@
|
|||
#ifdef _WIN32 || _WIN64
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef linux
|
||||
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "os_info.h"
|
||||
#include "logger.h"
|
||||
|
||||
char* getOS(){
|
||||
char *os;
|
||||
os = malloc(sizeof (char) * 20);
|
||||
|
||||
#ifdef _WIN32 || _WIN64
|
||||
strcpy(os, "Windows");
|
||||
#endif
|
||||
#ifdef linux
|
||||
strcpy(os, "Linux");
|
||||
#endif
|
||||
|
|
|
|||
Reference in a new issue