diff --git a/CastIt.cpp b/CastIt.cpp
index 2f5ba73..c324f62 100644
--- a/CastIt.cpp
+++ b/CastIt.cpp
@@ -3,7 +3,6 @@
#include "StdAfx.h"
#include "CastIt.h"
-#include "DB.h"
#include "CastItDlg.h"
diff --git a/CastIt.rc b/CastIt.rc
index e6e98ba..27ac70c 100644
--- a/CastIt.rc
+++ b/CastIt.rc
@@ -141,7 +141,7 @@ CAPTION "Configuration Castit"
FONT 8, "MS Sans Serif"
BEGIN
EDITTEXT IDC_POLLINTERVAL,356,164,50,14,ES_AUTOHSCROLL
- CONTROL "Insert Data Into MySQL DB",IDC_MYSQL_FLAG,"Button",
+ CONTROL "Insert Data Into Database",IDC_MYSQL_FLAG,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,22,30,102,10
EDITTEXT IDC_MY_HOSTNAME,70,42,87,14,ES_AUTOHSCROLL
EDITTEXT IDC_MY_USERNAME,70,62,87,14,ES_AUTOHSCROLL
@@ -151,7 +151,7 @@ BEGIN
EDITTEXT IDC_AGGREGATE,167,42,60,14,ES_AUTOHSCROLL
EDITTEXT IDC_DELETE_SONGHISTORY_INTERVAL,168,91,60,14,
ES_AUTOHSCROLL
- PUSHBUTTON "Verify Connectivity To MySQL DB",IDC_VERIFY_CONNECTION,
+ PUSHBUTTON "Verify Connectivity To Database",IDC_VERIFY_CONNECTION,
22,146,119,14,BS_FLAT
PUSHBUTTON "Create DB Tables",IDC_CREATE_TABLES,148,146,67,14,
BS_FLAT
@@ -169,11 +169,11 @@ BEGIN
14,BS_LEFT | BS_FLAT
DEFPUSHBUTTON "Finish",IDOK,52,286,50,14,BS_FLAT
PUSHBUTTON "Cancel",IDCANCEL,112,286,50,14,BS_FLAT
- LTEXT "MySQL Hostname",IDC_STATIC,9,45,58,8
- LTEXT "MySQL Username",IDC_STATIC,9,65,58,8
- LTEXT "MySQL Password",IDC_STATIC,9,85,57,8
- LTEXT "MySQL Database",IDC_STATIC,9,106,57,8
- LTEXT "MySQL Table Prefix",IDC_STATIC,9,127,64,8
+ LTEXT "Database Hostname",IDC_STATIC,9,45,58,8
+ LTEXT "Database Username",IDC_STATIC,9,65,58,8
+ LTEXT "Database Password",IDC_STATIC,9,85,57,8
+ LTEXT "Database Name",IDC_STATIC,9,106,57,8
+ LTEXT "Database Table Prefix",IDC_STATIC,9,127,64,8
LTEXT "Number of hours to aggregate history",IDC_STATIC,162,28,
120,10
LTEXT "Delete Song History After Specified Interval",
@@ -181,7 +181,7 @@ BEGIN
LTEXT "Hours",IDC_STATIC,234,94,26,8
LTEXT "Hours",IDC_STATIC,233,43,30,8
LTEXT "Interval Settings",IDC_STATIC,299,166,57,8
- GROUPBOX "MySQL Settings",IDC_STATIC,7,21,278,144
+ GROUPBOX "Database Settings",IDC_STATIC,7,21,278,144
GROUPBOX "URL Settings",IDC_STATIC,7,170,278,66
LTEXT "Input Template",IDC_STATIC,301,41,48,8
LTEXT "Output Template",IDC_STATIC,301,78,54,8
diff --git a/CastIt.vcxproj b/CastIt.vcxproj
index 2c6b416..84f5f10 100644
--- a/CastIt.vcxproj
+++ b/CastIt.vcxproj
@@ -97,7 +97,7 @@
Level3
true
ProgramDatabase
- $(ProjectDir);libxml2-2.4.9/include;mysql-connector-c-8.0-win32/include;curl/include;%(AdditionalIncludeDirectories)
+ $(ProjectDir);libxml2-2.4.9/include;curl/include;%(AdditionalIncludeDirectories)
WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
.\Debug\
true
@@ -127,11 +127,10 @@
true
Windows
.\Debug\CastIt.exe
- mysql-connector-c-8.0-win32/lib;%(AdditionalLibraryDirectories)
- curl/lib/curlstatic.lib;libxml2-2.4.9/win32/libxml2/libxml2_a/libxml2.lib;libmysql.lib;ws2_32.lib;%(AdditionalDependencies)
+ %(AdditionalLibraryDirectories)
+ curl/lib/curlstatic.lib;libxml2-2.4.9/win32/libxml2/libxml2_a/libxml2.lib;ws2_32.lib;%(AdditionalDependencies)
- copy /Y "$(ProjectDir)mysql-connector-c-8.0-win32\lib\libmysql.dll" "$(OutDir)"
@@ -143,7 +142,7 @@
MaxSpeed
true
Level3
- $(ProjectDir);libxml2-2.4.9/include;mysql-connector-c-8.0-win32/include;curl/include;%(AdditionalIncludeDirectories)
+ $(ProjectDir);libxml2-2.4.9/include;curl/include;%(AdditionalIncludeDirectories)
WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
.\Release\
true
@@ -170,11 +169,10 @@
true
Windows
.\Release\CastIt.exe
- mysql-connector-c-8.0-win32/lib;%(AdditionalLibraryDirectories)
- curl/lib/curlstatic.lib;libxml2-2.4.9/win32/libxml2/libxml2_a/libxml2.lib;libmysql.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;wsock32.lib;%(AdditionalDependencies)
+ %(AdditionalLibraryDirectories)
+ curl/lib/curlstatic.lib;libxml2-2.4.9/win32/libxml2/libxml2_a/libxml2.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;wsock32.lib;%(AdditionalDependencies)
- copy /Y "$(ProjectDir)mysql-connector-c-8.0-win32\lib\libmysql.dll" "$(OutDir)"
@@ -187,7 +185,7 @@
Level3
true
ProgramDatabase
- $(ProjectDir);libxml2-2.4.9/include;mysql-connector-c-8.0-winx64/include;curl/include;%(AdditionalIncludeDirectories)
+ $(ProjectDir);libxml2-2.4.9/include;curl/include;%(AdditionalIncludeDirectories)
WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
.\x64\Debug\
true
@@ -217,11 +215,10 @@
true
Windows
.\x64\Debug\CastIt.exe
- mysql-connector-c-8.0-winx64/lib;%(AdditionalLibraryDirectories)
- curl/lib/curlstatic.lib;libxml2-2.4.9/win32/libxml2/libxml2_a/libxml2.lib;libmysql.lib;ws2_32.lib;%(AdditionalDependencies)
+ %(AdditionalLibraryDirectories)
+ curl/lib/curlstatic.lib;libxml2-2.4.9/win32/libxml2/libxml2_a/libxml2.lib;ws2_32.lib;%(AdditionalDependencies)
- copy /Y "$(ProjectDir)mysql-connector-c-8.0-winx64\lib\libmysql.dll" "$(OutDir)"
@@ -233,7 +230,7 @@
MaxSpeed
true
Level3
- $(ProjectDir);libxml2-2.4.9/include;mysql-connector-c-8.0-winx64/include;curl/include;%(AdditionalIncludeDirectories)
+ $(ProjectDir);libxml2-2.4.9/include;curl/include;%(AdditionalIncludeDirectories)
WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
.\x64\Release\
true
@@ -260,11 +257,10 @@
true
Windows
.\x64\Release\CastIt.exe
- mysql-connector-c-8.0-winx64/lib;%(AdditionalLibraryDirectories)
- curl/lib/curlstatic.lib;libxml2-2.4.9/win32/libxml2/libxml2_a/libxml2.lib;libmysql.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;wsock32.lib;%(AdditionalDependencies)
+ %(AdditionalLibraryDirectories)
+ curl/lib/curlstatic.lib;libxml2-2.4.9/win32/libxml2/libxml2_a/libxml2.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;wsock32.lib;%(AdditionalDependencies)
- copy /Y "$(ProjectDir)mysql-connector-c-8.0-winx64\lib\libmysql.dll" "$(OutDir)"
@@ -274,7 +270,6 @@
-
@@ -307,7 +302,6 @@
-
@@ -351,7 +345,6 @@
-
@@ -384,7 +377,6 @@
-
diff --git a/CastIt.vcxproj.filters b/CastIt.vcxproj.filters
index 7399317..d30a8bd 100644
--- a/CastIt.vcxproj.filters
+++ b/CastIt.vcxproj.filters
@@ -33,7 +33,6 @@
Source Files
-
Source Files
@@ -97,7 +96,6 @@
Header Files
-
Header Files
@@ -252,9 +250,6 @@
Resource Files
-
- Resource Files
-
Resource Files
@@ -324,9 +319,6 @@
Resource Files
-
- Resource Files
-
diff --git a/CastItDlg.cpp b/CastItDlg.cpp
index 9dd509c..8b39896 100644
--- a/CastItDlg.cpp
+++ b/CastItDlg.cpp
@@ -545,17 +545,17 @@ void CCastItDlg::config_read()
m_colBW2Width = GetPrivateProfileInt(gAppName, "colBW2Width", 125, gConfigFile);
m_colBW3Width = GetPrivateProfileInt(gAppName, "colBW3Width", 125, gConfigFile);
- GetPrivateProfileString(gAppName, "mysqlUsername", "", buf, sizeof(buf), gConfigFile);
+ GetPrivateProfileString(gAppName, "dbUsername", "", buf, sizeof(buf), gConfigFile);
configDialog.m_Username = buf;
- GetPrivateProfileString(gAppName, "mysqlPassword", "", buf, sizeof(buf), gConfigFile);
+ GetPrivateProfileString(gAppName, "dbPassword", "", buf, sizeof(buf), gConfigFile);
configDialog.m_Password = buf;
- GetPrivateProfileString(gAppName, "mysqlDatabase", "", buf, sizeof(buf), gConfigFile);
+ GetPrivateProfileString(gAppName, "dbDatabase", "", buf, sizeof(buf), gConfigFile);
configDialog.m_Database = buf;
- GetPrivateProfileString(gAppName, "mysqlHostname", "", buf, sizeof(buf), gConfigFile);
+ GetPrivateProfileString(gAppName, "dbHostname", "", buf, sizeof(buf), gConfigFile);
configDialog.m_Hostname = buf;
- GetPrivateProfileString(gAppName, "mysqlTableprefix", "", buf, sizeof(buf), gConfigFile);
+ GetPrivateProfileString(gAppName, "dbTableprefix", "", buf, sizeof(buf), gConfigFile);
configDialog.m_TablePrefix = buf;
- configDialog.m_MysqlFlag = GetPrivateProfileInt(gAppName, "mysqlMysqFlag", 1, gConfigFile);
+ configDialog.m_DBEnabled = GetPrivateProfileInt(gAppName, "dbEnabledFlag", 1, gConfigFile);
configDialog.m_PollInterval = GetPrivateProfileInt(gAppName, "pollInterval", 120, gConfigFile);
@@ -705,13 +705,13 @@ void CCastItDlg::config_write()
// WritePrivateProfileString(gAppName, "CC_Password", configDialog.m_CC_Password, gConfigFile);
- WritePrivateProfileString(gAppName, "mysqlUsername", configDialog.m_Username, gConfigFile);
- WritePrivateProfileString(gAppName, "mysqlPassword", configDialog.m_Password, gConfigFile);
- WritePrivateProfileString(gAppName, "mysqlDatabase", configDialog.m_Database, gConfigFile);
- WritePrivateProfileString(gAppName, "mysqlHostname", configDialog.m_Hostname, gConfigFile);
- WritePrivateProfileString(gAppName, "mysqlTableprefix", configDialog.m_TablePrefix, gConfigFile);
- SAFE_SPRINTF(buf, "%d", configDialog.m_MysqlFlag);
- WritePrivateProfileString(gAppName, "mysqlMysqFlag", buf, gConfigFile);
+ WritePrivateProfileString(gAppName, "dbUsername", configDialog.m_Username, gConfigFile);
+ WritePrivateProfileString(gAppName, "dbPassword", configDialog.m_Password, gConfigFile);
+ WritePrivateProfileString(gAppName, "dbDatabase", configDialog.m_Database, gConfigFile);
+ WritePrivateProfileString(gAppName, "dbHostname", configDialog.m_Hostname, gConfigFile);
+ WritePrivateProfileString(gAppName, "dbTableprefix", configDialog.m_TablePrefix, gConfigFile);
+ SAFE_SPRINTF(buf, "%d", configDialog.m_DBEnabled);
+ WritePrivateProfileString(gAppName, "dbEnabledFlag", buf, gConfigFile);
SAFE_SPRINTF(buf, "%d", configDialog.m_PollInterval);
WritePrivateProfileString(gAppName, "pollInterval", buf, gConfigFile);
@@ -1417,20 +1417,7 @@ void CCastItDlg::getServerData()
if (configDialog.m_GenerateTemplate) {
SubstituteTagsInTemplate(&sData, i);
}
- if (configDialog.m_MysqlFlag) {
- configDialog.database.username = configDialog.m_Username;
- configDialog.database.password = configDialog.m_Password;
- configDialog.database.hostname = configDialog.m_Hostname;
- configDialog.database.dbname = configDialog.m_Database;
-
- insertIntoMySQL(&(configDialog.database), configDialog.m_TablePrefix, serverURLs.GetAt(i) + serverMountpoints.GetAt(i), &sData);
- if (m_AggregateInfo) {
- if (configDialog.m_Aggregate > 0) {
- aggregateHistory(&(configDialog.database), configDialog.m_TablePrefix, serverURLs.GetAt(i) + serverMountpoints.GetAt(i), &sData, configDialog.m_Aggregate);
- }
- }
- if (configDialog.m_DeleteSongHistoryInterval > 0) {
- deleteOldHistory(&(configDialog.database), configDialog.m_TablePrefix, serverURLs.GetAt(i) + serverMountpoints.GetAt(i), &sData, configDialog.m_DeleteSongHistoryInterval);
+ if (configDialog.m_DBEnabled) {
}
}
/* if (configDialog.m_UpdateCC) {
@@ -1930,13 +1917,13 @@ void CCastItDlg::OnCciniBackup()
WritePrivateProfileString(gAppName, "col7Width", buf, gBackupConfig);
- WritePrivateProfileString(gAppName, "mysqlUsername", configDialog.m_Username, gBackupConfig);
- WritePrivateProfileString(gAppName, "mysqlPassword", configDialog.m_Password, gBackupConfig);
- WritePrivateProfileString(gAppName, "mysqlDatabase", configDialog.m_Database, gBackupConfig);
- WritePrivateProfileString(gAppName, "mysqlHostname", configDialog.m_Hostname, gBackupConfig);
- WritePrivateProfileString(gAppName, "mysqlTableprefix", configDialog.m_TablePrefix, gBackupConfig);
- SAFE_SPRINTF(buf, "%d", configDialog.m_MysqlFlag);
- WritePrivateProfileString(gAppName, "mysqlMysqFlag", buf, gBackupConfig);
+ WritePrivateProfileString(gAppName, "dbUsername", configDialog.m_Username, gBackupConfig);
+ WritePrivateProfileString(gAppName, "dbPassword", configDialog.m_Password, gBackupConfig);
+ WritePrivateProfileString(gAppName, "dbDatabase", configDialog.m_Database, gBackupConfig);
+ WritePrivateProfileString(gAppName, "dbHostname", configDialog.m_Hostname, gBackupConfig);
+ WritePrivateProfileString(gAppName, "dbTableprefix", configDialog.m_TablePrefix, gBackupConfig);
+ SAFE_SPRINTF(buf, "%d", configDialog.m_DBEnabled);
+ WritePrivateProfileString(gAppName, "dbEnabledFlag", buf, gBackupConfig);
SAFE_SPRINTF(buf, "%d", configDialog.m_PollInterval);
WritePrivateProfileString(gAppName, "pollInterval", buf, gBackupConfig);
diff --git a/CastItDlg.h b/CastItDlg.h
index cc33ec8..d897c0f 100644
--- a/CastItDlg.h
+++ b/CastItDlg.h
@@ -15,7 +15,6 @@ typedef CArray IntArray;
#include "common.h"
#include "afxdialogex.h"
#include "ConfigurationDialog.h" // Added by ClassView
-#include "DB.h" // Added by ClassView
#include "AddServer.h" // Added by ClassView
#include "SystemTray.h"
#include "HyperLink.h"
@@ -52,7 +51,6 @@ class CCastItDlg : public CDialogEx
void OnAdmin();
void OnPlayStream();
CAddServer addServerDialog;
- DB database;
CConfigurationDialog configDialog;
void config_write();
int m_col1Width;
diff --git a/Castit.ini b/Castit.ini
index f801628..35db5b7 100644
--- a/Castit.ini
+++ b/Castit.ini
@@ -7,12 +7,12 @@ col4Width=322
col5Width=322
col6Width=322
col7Width=322
-mysqlUsername=YOUR_MYSQL_USERNAME
-mysqlPassword=YOUR_MYSQL_PASSWORD
-mysqlDatabase=
-mysqlHostname=YOUR_MYSQL_HOST
-mysqlTableprefix=
-mysqlMysqFlag=0
+dbUsername=YOUR_DB_USERNAME
+dbPassword=YOUR_DB_PASSWORD
+dbDatabase=
+dbHostname=YOUR_DB_HOST
+dbTableprefix=
+dbEnabledFlag=0
pollInterval=10
Aggregate=0
DeleteSongHistoryInterval=0
diff --git a/ConfigurationDialog.cpp b/ConfigurationDialog.cpp
index e7a9b66..0de8a8a 100644
--- a/ConfigurationDialog.cpp
+++ b/ConfigurationDialog.cpp
@@ -29,7 +29,7 @@ CConfigurationDialog::CConfigurationDialog(CWnd* pParent /*=NULL*/)
m_Password = _T("");
m_TablePrefix = _T("");
m_Username = _T("");
- m_MysqlFlag = FALSE;
+ m_DBEnabled = FALSE;
m_Aggregate = 0;
m_DeleteSongHistoryInterval = 0;
m_PollInterval = 0;
@@ -50,8 +50,6 @@ void CConfigurationDialog::DoDataExchange(CDataExchange* pDX)
//{{AFX_DATA_MAP(CConfigurationDialog)
DDX_Control(pDX, IDC_DELETE_SONGHISTORY_INTERVAL, m_DeleteSongCtl);
DDX_Control(pDX, IDC_AGGREGATE, m_AggregateCtl);
- DDX_Control(pDX, IDC_CREATE_TABLES, m_CreatCtl);
- DDX_Control(pDX, IDC_VERIFY_CONNECTION, m_VerifyCtl);
DDX_Control(pDX, IDC_MY_USERNAME, m_UsernameCtl);
DDX_Control(pDX, IDC_MY_TABLEPREFIX, m_TablePrefixCtl);
DDX_Control(pDX, IDC_MY_PASSWORD, m_PasswordCtl);
@@ -62,7 +60,7 @@ void CConfigurationDialog::DoDataExchange(CDataExchange* pDX)
DDX_Text(pDX, IDC_MY_PASSWORD, m_Password);
DDX_Text(pDX, IDC_MY_TABLEPREFIX, m_TablePrefix);
DDX_Text(pDX, IDC_MY_USERNAME, m_Username);
- DDX_Check(pDX, IDC_MYSQL_FLAG, m_MysqlFlag);
+ DDX_Check(pDX, IDC_database_FLAG, m_DBEnabled);
DDX_Text(pDX, IDC_AGGREGATE, m_Aggregate);
DDX_Text(pDX, IDC_DELETE_SONGHISTORY_INTERVAL, m_DeleteSongHistoryInterval);
DDX_Text(pDX, IDC_POLLINTERVAL, m_PollInterval);
@@ -83,9 +81,7 @@ void CConfigurationDialog::DoDataExchange(CDataExchange* pDX)
BEGIN_MESSAGE_MAP(CConfigurationDialog, CDialog)
//{{AFX_MSG_MAP(CConfigurationDialog)
- ON_BN_CLICKED(IDC_MYSQL_FLAG, OnMysqlFlag)
- ON_BN_CLICKED(IDC_VERIFY_CONNECTION, OnVerifyConnection)
- ON_BN_CLICKED(IDC_CREATE_TABLES, OnCreateTables)
+ ON_BN_CLICKED(IDC_database_FLAG, OnDatabaseFlag)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BROWSE1, OnBrowse1)
ON_BN_CLICKED(IDC_BROWSE2, OnBrowse2)
@@ -106,11 +102,11 @@ END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConfigurationDialog message handlers
-void CConfigurationDialog::OnMysqlFlag()
+void CConfigurationDialog::OnDatabaseFlag()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
- if (m_MysqlFlag) {
+ if (m_DBEnabled) {
m_UsernameCtl.EnableWindow(TRUE);
m_PasswordCtl.EnableWindow(TRUE);
m_HostnameCtl.EnableWindow(TRUE);
@@ -118,8 +114,6 @@ void CConfigurationDialog::OnMysqlFlag()
m_DeleteSongCtl.EnableWindow(TRUE);
m_AggregateCtl.EnableWindow(TRUE);
m_TablePrefixCtl.EnableWindow(TRUE);
- m_VerifyCtl.EnableWindow(TRUE);
- m_CreatCtl.EnableWindow(TRUE);
}
else {
m_UsernameCtl.EnableWindow(FALSE);
@@ -129,173 +123,11 @@ void CConfigurationDialog::OnMysqlFlag()
m_DeleteSongCtl.EnableWindow(FALSE);
m_AggregateCtl.EnableWindow(FALSE);
m_TablePrefixCtl.EnableWindow(FALSE);
- m_VerifyCtl.EnableWindow(FALSE);
- m_CreatCtl.EnableWindow(FALSE);
}
}
-void CConfigurationDialog::OnVerifyConnection()
-{
- CWaitCursor wait;
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- database.username = m_Username;
- database.password = m_Password;
- database.hostname = m_Hostname;
- database.dbname = m_Database;
-
- if (database.Connect()) {
- MessageBox("Successful connection", NULL, MB_ICONINFORMATION);
- LogMessage(LOG_INFO,"MySQL Connection Successfull");
- }
- else {
- char buf[255];
- if (!strncmp(database.getErrorMessage(), "Unknown database", strlen("Unknown database"))) {
- SAFE_SPRINTF(buf, "Connectivity validated, but database %s doesn't seem to exist, do you want it created ?", m_Database);
- if (MessageBox(buf, NULL, MB_YESNO) == IDYES) {
- database.dbname = "";
- if (!database.Connect()) {
- SAFE_SPRINTF(buf, "Sorry, but having major problems doing that..(%s)", database.getErrorMessage());
- LogMessage(LOG_INFO, buf);
- MessageBox(buf, NULL, MB_ICONERROR);
- }
- else {
- SAFE_SPRINTF(buf, "create database %s", m_Database);
- LogMessage(LOG_INFO, buf);
- if (!database.Query(buf)) {
- SAFE_SPRINTF(buf, "Sorry, but having major problems doing that..(%s)", database.getErrorMessage());
- LogMessage(LOG_INFO, buf);
- }
- else {
- SAFE_SPRINTF(buf, "Database created..(%s)", m_Database);
- LogMessage(LOG_INFO, buf);
- }
- database.dbname = m_Database;
- MessageBox(buf, NULL, MB_ICONINFORMATION);
- }
-
- }
- }
- else {
- SAFE_SPRINTF(buf, "Error verifying connection (%s)", database.getErrorMessage());
- LogMessage(LOG_INFO, buf);
- MessageBox(buf, NULL, MB_ICONERROR);
- }
- }
- database.Disconnect();
-}
-
-void CConfigurationDialog::OnCreateTables()
-{
- // TODO: Add your control notification handler code here
- char sql1[1024] = "";
- char sql2[1024] = "";
- char sql3[1024] = "";
- char sql4[1024] = "";
- char sql5[1024] = "";
- CString message = "";
-
- UpdateData(TRUE);
-
- database.username = m_Username;
- database.password = m_Password;
- database.hostname = m_Hostname;
- database.dbname = m_Database;
-
- SAFE_SPRINTF(sql1, "CREATE TABLE IF NOT EXISTS %sshoutcast_serverinfo ( \
- serverURL varchar(255) default NULL,\
- currentlisteners int(11) default NULL,\
- peaklisteners int(11) default NULL,\
- maxlisteners int(11) default NULL,\
- averagetime int(11) default NULL,\
- streamhits int(11) default NULL,\
- bitrate int(11) default NULL,\
- time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", m_TablePrefix);
-
-
-
- SAFE_SPRINTF(sql2, "CREATE TABLE IF NOT EXISTS %ssonginfo (\
- serverURL varchar(255) default NULL, \
- songTitle varchar(255) default NULL, \
- currentlisteners int(11) default NULL,\
- time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", m_TablePrefix);
-
- SAFE_SPRINTF(sql3, "CREATE TABLE IF NOT EXISTS %sshoutcast_history ( \
- serverURL varchar(255) default NULL,\
- avgcurrentlisteners int(11) default NULL,\
- avgpeaklisteners int(11) default NULL,\
- avgmaxlisteners int(11) default NULL,\
- avgaveragetime int(11) default NULL,\
- avgstreamhits int(11) default NULL,\
- time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", m_TablePrefix);
-
- SAFE_SPRINTF(sql4, "CREATE TABLE IF NOT EXISTS %sicecast2_history ( \
- serverURL varchar(255) default NULL,\
- avgcurrentlisteners int(11) default NULL,\
- avgconnections int(11) default NULL,\
- time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", m_TablePrefix);
-
- SAFE_SPRINTF(sql5, "CREATE TABLE IF NOT EXISTS %sicecast2_serverinfo ( \
- server_name varchar(255) default NULL,\
- current_song varchar(255) default NULL,\
- server_url varchar(255) default NULL,\
- ice2_br int(11) default NULL,\
- ice2_ql int(11) default NULL,\
- ice2_chn int(11) default NULL,\
- ice2_sr int(11) default NULL,\
- ice2_cons int(11) default NULL,\
- ice2_cl int(11) default NULL,\
- ice2_strtype varchar(255) default NULL,\
- ice2_desc varchar(255) default NULL,\
- time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", m_TablePrefix);
-
- if (!database.Connect()) {
- LogMessage(LOG_INFO, "Cannot connect to DB, check your settings");
- MessageBox("Cannot connect to DB, check your settings", NULL, MB_ICONERROR);
- }
- else {
- if (database.Query(sql1)) {
- message += "Table (" + m_TablePrefix + "shoutcast_serverinfo) created OK\r\n";
- }else{
- message += "Table (" + m_TablePrefix + "shoutcast_serverinfo) creation FAILED (" + database.getErrorMessage() + ")\r\n";
- }
- if (database.Query(sql2)) {
- message += "Table (" + m_TablePrefix + "songinfo) created OK\r\n";
- }else {
- message += "Table (" + m_TablePrefix + "songinfo) creation FAILED (" + database.getErrorMessage() + ")\r\n";
- }
- if (database.Query(sql3)) {
- message += "Table (" + m_TablePrefix + "shoutcast_history) created OK\r\n";
- }else{
- message += "Table (" + m_TablePrefix + "shoutcast_history) creation FAILED (" + database.getErrorMessage() + ")\r\n";
- }
- if (database.Query(sql4)) {
- message += "Table (" + m_TablePrefix + "icecast2_history) created OK\r\n";
- }else{
- message += "Table (" + m_TablePrefix + "icecast2_history) creation FAILED (" + database.getErrorMessage() + ")\r\n";
- }
- if (database.Query(sql5)) {
- message += "Table (" + m_TablePrefix + "icecast2_serverinfo) created OK\r\n";
- }else {
- message += "Table (" + m_TablePrefix + "icecast2_serverinfo) creation FAILED (" + database.getErrorMessage() + ")\r\n";
- }
- }
-
- MessageBox(message, NULL, MB_ICONINFORMATION);
- }
-
-
-void CConfigurationDialog::OnClose()
-{
- // TODO: Add your message handler code here and/or call default
-
- CDialog::OnClose();
-
-
-}
-
BOOL CConfigurationDialog::OnInitDialog()
{
CDialog::OnInitDialog();
@@ -327,12 +159,8 @@ BOOL CConfigurationDialog::OnInitDialog()
// m_btnHelp5.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
// TODO: Add extra initialization here
- database.username = m_Username;
- database.password = m_Password;
- database.hostname = m_Hostname;
- database.dbname = m_Database;
- OnMysqlFlag();
+ OnDatabaseFlag();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
@@ -460,8 +288,8 @@ void CConfigurationDialog::OnViewHelpTip2()
CString message = "";
- message += "Mysql Tip\n";
- message += "It is recomended that you use a local mysql server\n";
+ message += "Database Tip\n";
+ message += "It is recomended that you use a local database server\n";
message += "this will speed up the process of gathering stats.\n";
message += "Tips:\n";
message += " Number of hours to aggregate history will enable you\n";
@@ -473,7 +301,7 @@ void CConfigurationDialog::OnViewHelpTip2()
message += " -Averagelistentime (in seconds)\n";
message += " -Average hits to stream\n";
message += "This is CastIts most powerfull feature\n";
- message += "Delete song history will empty the mysql database table of songs\n";
+ message += "Delete song history will empty the database table of songs\n";
message += "If you want a to keep all songs then leave this to zero\n";
MessageBox(message, NULL, MB_ICONINFORMATION);
diff --git a/ConfigurationDialog.h b/ConfigurationDialog.h
index 1f1915e..d89a231 100644
--- a/ConfigurationDialog.h
+++ b/ConfigurationDialog.h
@@ -1,7 +1,6 @@
#if !defined(AFX_CONFIGURATIONDIALOG_H__C185B148_D53B_4FDB_AD4E_35A53E912F7C__INCLUDED_)
#define AFX_CONFIGURATIONDIALOG_H__C185B148_D53B_4FDB_AD4E_35A53E912F7C__INCLUDED_
-#include "DB.h"
#include "FTPInfo.h" // Added by ClassView
#include "BtnST.h"
#include "BCMenu.h"
@@ -35,8 +34,6 @@ class CConfigurationDialog : public CDialog
enum { IDD = IDD_CONFIG_DIALOG };
CEdit m_DeleteSongCtl;
CEdit m_AggregateCtl;
- CButton m_CreatCtl;
- CButton m_VerifyCtl;
CEdit m_UsernameCtl;
CEdit m_TablePrefixCtl;
CEdit m_PasswordCtl;
@@ -47,7 +44,7 @@ class CConfigurationDialog : public CDialog
CString m_Password;
CString m_TablePrefix;
CString m_Username;
- BOOL m_MysqlFlag;
+ BOOL m_DBEnabled;
int m_Aggregate;
int m_DeleteSongHistoryInterval;
int m_PollInterval;
@@ -61,7 +58,6 @@ class CConfigurationDialog : public CDialog
// BOOL m_UpdateCC;
//}}AFX_DATA
- DB database;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CConfigurationDialog)
@@ -75,9 +71,7 @@ class CConfigurationDialog : public CDialog
// Generated message map functions
//{{AFX_MSG(CConfigurationDialog)
- afx_msg void OnMysqlFlag();
- afx_msg void OnVerifyConnection();
- afx_msg void OnCreateTables();
+ afx_msg void OnDatabaseFlag();
afx_msg void OnClose();
virtual BOOL OnInitDialog();
afx_msg void OnBrowse1();
diff --git a/DB.cpp b/DB.cpp
deleted file mode 100644
index d8b7063..0000000
--- a/DB.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-#ifdef WIN32
-#include
-#include
-#endif
-#include "mysql.h"
-#include
-#include
-#include "DB.h"
-#include
-#ifdef WIN32
-#include
-#include
-#else
-#include
-#endif
-
-extern "C" {
-int mysql_library_init(int, char**, char**);
-void mysql_library_end(void);
-void mysql_thread_end(void);
-}
-
-double DBGetCurrentTime() {
- double thetime;
- struct timeval tv;
-#ifdef _WIN32
- time_t ltime;
-
- thetime = time(<ime);
-#else
- gettimeofday(&tv, NULL);
- thetime = (double)tv.tv_sec + (double)((double)tv.tv_usec / (double)1000000);
-#endif
-
- return thetime;
-}
-
-static bool library_initialized = false;
-
-DB::DB() {
- if (!library_initialized) {
- mysql_library_init(0, nullptr, nullptr);
- atexit(mysql_library_end);
- library_initialized = true;
- }
- pResult = 0;
- sqlTimings = 0;
- memset(tempQuery, '\000', sizeof(tempQuery));
- port = 3306;
- flags = 0;
-}
-DB::~DB() {
- if (pResult) {
- mysql_free_result(pResult);
- }
-}
-char *DB::getErrorMessage() {
- return mysql_error(&mySQL);
-}
-int DB::Connect() {
-
- mysql_init(&mySQL);
-
-
- mysql_options(&mySQL, MYSQL_READ_DEFAULT_GROUP, "scastd");
-#ifdef MYSQL_OPT_RECONNECT
- bool reconnect = true;
- mysql_options(&mySQL, MYSQL_OPT_RECONNECT, &reconnect);
-#endif
-
-
- if (!mysql_real_connect(&mySQL, hostname, username, password, dbname, port, nullptr, flags)) {
- return 0;
- }
- return 1;
-}
-int DB::Query(char *query) {
- // double startTime = 0.0;
- // double endTime = 0.0;
-
- numFetches = 0;
- if (strcpy_s(tempQuery, sizeof(tempQuery), query) != 0) {
- fprintf(stderr, "Query string truncated\n");
- return 0;
- }
- if (sqlTimings) {
- startTime = DBGetCurrentTime();
- }
- if (pResult) {
- mysql_free_result(pResult);
- }
- if (mysql_query(&mySQL, query) != 0) {
- fprintf(stderr, "Misformed query (%s)\n", query);
- fprintf(stderr, "Error: %s\n", mysql_error(&mySQL));
- return(0);
- }
-
- pResult = mysql_store_result(&mySQL);
- if (pResult) {
- numFields = mysql_num_fields(pResult);
- numRows = mysql_num_rows(pResult);
- }
- if (sqlTimings) {
- endTime = DBGetCurrentTime();
- }
-
- if (sqlTimings) {
- fprintf(stdout, "Query %f secs - SQL: %s\n", endTime - startTime, query);
- }
- return(1);
-
-}
-MYSQL_ROW DB::Fetch() {
- if (pResult) {
- numFetches++;
- return mysql_fetch_row(pResult);
- }
- else {
- return 0;
- }
- return 0;
-}
-
-void DB::EndQuery() {
- if (sqlTimings) {
- endTime = DBGetCurrentTime();
- }
- if (sqlTimings) {
- fprintf(stdout, "Total Time Query (%d fetches) %f secs - SQL: %s\n", numFetches, endTime - startTime, tempQuery);
- }
-}
-void DB::Disconnect() {
- mysql_close(&mySQL);
- return;
-}
-
-MYSQL_STMT *DB::Prepare(const char *query) {
- MYSQL_STMT *stmt = mysql_stmt_init(&mySQL);
- if (!stmt) {
- return NULL;
- }
- if (mysql_stmt_prepare(stmt, query, (unsigned long)strlen(query)) != 0) {
- mysql_stmt_close(stmt);
- return NULL;
- }
- return stmt;
-}
-
-int DB::BindParams(MYSQL_STMT *stmt, MYSQL_BIND *bind) {
- return mysql_stmt_bind_param(stmt, bind) == 0;
-}
-
-int DB::BindResult(MYSQL_STMT *stmt, MYSQL_BIND *bind) {
- return mysql_stmt_bind_result(stmt, bind) == 0;
-}
-
-int DB::Execute(MYSQL_STMT *stmt) {
- return mysql_stmt_execute(stmt) == 0;
-}
-
-int DB::Fetch(MYSQL_STMT *stmt) {
- return mysql_stmt_fetch(stmt);
-}
-
-void DB::CloseStatement(MYSQL_STMT *stmt) {
- if (stmt) {
- mysql_stmt_close(stmt);
- }
-}
diff --git a/DB.h b/DB.h
deleted file mode 100644
index 06da901..0000000
--- a/DB.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef _DB_
-#define _DB_
-#include "mysql.h"
-
-
-class DB {
-public:
- MYSQL mySQL;
- MYSQL_RES *pResult;
- MYSQL_ROW row;
- CString username;
- CString password;
- CString hostname;
- CString dbname;
- unsigned int port;
- unsigned long flags;
- long numFields;
- long numRows;
- int sqlTimings;
- long numFetches;
- double startTime;
- double endTime;
- char tempQuery[2046];
- char errorMessage[255];
-
- int Connect();
- void Disconnect();
- char *getErrorMessage();
- int Query(char *);
- void EndQuery();
- MYSQL_ROW Fetch();
-
- // Prepared statement helpers
- MYSQL_STMT *Prepare(const char *query);
- int BindParams(MYSQL_STMT *stmt, MYSQL_BIND *bind);
- int BindResult(MYSQL_STMT *stmt, MYSQL_BIND *bind);
- int Execute(MYSQL_STMT *stmt);
- int Fetch(MYSQL_STMT *stmt);
- void CloseStatement(MYSQL_STMT *stmt);
- DB();
- ~DB();
-};
-#endif
diff --git a/common.h b/common.h
index 95f8985..52b4788 100644
--- a/common.h
+++ b/common.h
@@ -1,6 +1,5 @@
#ifndef _COMMON_H
#define _COMMON_H
-#include "DB.h"
typedef struct tagServerData {
int serverType;
int currentListeners;
@@ -44,10 +43,7 @@ struct MemoryStruct {
};
char *URLCall(CString URL);
-int aggregateHistory(DB *db, CString tablePrefix, CString serverURL, serverData *pData, int age);
-int deleteOldHistory(DB *db, CString tablePrefix, CString serverURL, serverData *pData, int age);
int getStats(CString serverURL, CString serverPassword, int serverType,CString serverMountpoint, serverData *pData, char *errorMessage, size_t errorMessageSize);
-int insertIntoMySQL(DB *db, CString tablePrefix, CString serverURL, serverData *pData);
CString URLize(CString data);
CString URLizeint(int data);
#endif
diff --git a/mysql.h b/mysql.h
deleted file mode 100644
index 2722c43..0000000
--- a/mysql.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef MYSQL_STUB_H
-#define MYSQL_STUB_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct st_mysql MYSQL;
-typedef struct st_mysql_res MYSQL_RES;
-typedef char **MYSQL_ROW;
-typedef struct st_mysql_stmt MYSQL_STMT;
-typedef struct st_mysql_bind MYSQL_BIND;
-
-#define MYSQL_READ_DEFAULT_GROUP 0
-#define MYSQL_OPT_RECONNECT 0
-
-unsigned int mysql_num_fields(MYSQL_RES *res);
-unsigned long long mysql_num_rows(MYSQL_RES *res);
-MYSQL_RES *mysql_store_result(MYSQL *mysql);
-MYSQL_ROW mysql_fetch_row(MYSQL_RES *result);
-void mysql_free_result(MYSQL_RES *result);
-const char *mysql_error(MYSQL *mysql);
-MYSQL *mysql_init(MYSQL *mysql);
-int mysql_options(MYSQL *mysql, int option, const void *arg);
-MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user,
- const char *passwd, const char *db,
- unsigned int port, const char *unix_socket,
- unsigned long clientflag);
-int mysql_query(MYSQL *mysql, const char *stmt_str);
-void mysql_close(MYSQL *sock);
-MYSQL_STMT *mysql_stmt_init(MYSQL *mysql);
-int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length);
-int mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind);
-int mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind);
-int mysql_stmt_execute(MYSQL_STMT *stmt);
-int mysql_stmt_fetch(MYSQL_STMT *stmt);
-void mysql_stmt_close(MYSQL_STMT *stmt);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/scastd.cpp b/scastd.cpp
index 35fc3d3..77a1eb7 100644
--- a/scastd.cpp
+++ b/scastd.cpp
@@ -22,13 +22,11 @@
#include
#include
-#include "DB.h"
#include "common.h"
#include "log.h"
-MYSQL_ROW row;
int paused = 0;
int exiting = 0;
@@ -548,366 +546,3 @@ int getStats(CString serverURL, CString serverPassword, int serverType, CString
return 1;
}
-int deleteOldHistory(DB *db, CString tablePrefix, CString serverURL, serverData *pData, int age)
-{
- char query[4096] = "";
- db->Connect();
-
- sprintf_s(query, sizeof(query),
- "delete from %ssonginfo where time < NOW() - INTERVAL ? HOUR and serverURL = ?",
- tablePrefix);
-
- MYSQL_STMT *stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND bind[2];
- memset(bind, 0, sizeof(bind));
- bind[0].buffer_type = MYSQL_TYPE_LONG;
- bind[0].buffer = &age;
- const char *srv = serverURL;
- bind[1].buffer_type = MYSQL_TYPE_STRING;
- bind[1].buffer = (char *)srv;
- bind[1].buffer_length = strlen(srv);
- db->BindParams(stmt, bind);
- if (!db->Execute(stmt)) {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- }
- db->CloseStatement(stmt);
- }
-
- db->Disconnect();
- return 0;
-}
-int aggregateHistory(DB *db, CString tablePrefix, CString serverURL, serverData *pData, int age)
-{
- char query[4096] = "";
- long totalcurrentlisteners = 0;
- long totalconnections = 0;
- long totalpeaklisteners = 0;
- long totalmaxlisteners = 0;
- long totalaveragetime = 0;
- long totalstreamhits = 0;
-
- double avgcurrentlisteners = 0.0;
- double avgconnections = 0.0;
- double avgpeaklisteners = 0.0;
- double avgmaxlisteners = 0.0;
- double avgaveragetime = 0.0;
- double avgstreamhits = 0.0;
-
- db->Connect();
-
- if (pData->serverType == 0) {
- sprintf_s(query, sizeof(query),
- "select currentlisteners, peaklisteners, maxlisteners, averagetime, streamhits from %sshoutcast_serverinfo where time < NOW() - INTERVAL ? HOUR and serverURL = ?",
- tablePrefix);
- MYSQL_STMT *stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND bind[2];
- memset(bind, 0, sizeof(bind));
- bind[0].buffer_type = MYSQL_TYPE_LONG;
- bind[0].buffer = &age;
- const char *srv = serverURL;
- bind[1].buffer_type = MYSQL_TYPE_STRING;
- bind[1].buffer = (char *)srv;
- bind[1].buffer_length = strlen(srv);
- db->BindParams(stmt, bind);
-
- long cl = 0, pl = 0, ml = 0, at = 0, sh = 0;
- MYSQL_BIND result[5];
- memset(result, 0, sizeof(result));
- result[0].buffer_type = MYSQL_TYPE_LONG; result[0].buffer = &cl;
- result[1].buffer_type = MYSQL_TYPE_LONG; result[1].buffer = &pl;
- result[2].buffer_type = MYSQL_TYPE_LONG; result[2].buffer = &ml;
- result[3].buffer_type = MYSQL_TYPE_LONG; result[3].buffer = &at;
- result[4].buffer_type = MYSQL_TYPE_LONG; result[4].buffer = &sh;
- db->BindResult(stmt, result);
- db->Execute(stmt);
-
- int numrows = 0;
- while (db->Fetch(stmt) == 0) {
- totalcurrentlisteners += cl;
- totalpeaklisteners += pl;
- totalmaxlisteners += ml;
- totalaveragetime += at;
- totalstreamhits += sh;
- numrows++;
- }
- db->CloseStatement(stmt);
-
- if (numrows > 0) {
- avgcurrentlisteners = totalcurrentlisteners / numrows;
- avgpeaklisteners = totalpeaklisteners / numrows;
- avgmaxlisteners = totalmaxlisteners / numrows;
- avgaveragetime = totalaveragetime / numrows;
- avgstreamhits = totalstreamhits / numrows;
-
- sprintf_s(query, sizeof(query),
- "insert into %sshoutcast_history (serverURL, avgcurrentlisteners, avgpeaklisteners, avgmaxlisteners, avgaveragetime, avgstreamhits, time) values(?, ?, ?, ?, ?, ?, NULL)",
- tablePrefix);
- stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND ibind[6];
- memset(ibind, 0, sizeof(ibind));
- ibind[0].buffer_type = MYSQL_TYPE_STRING; ibind[0].buffer = (char *)srv; ibind[0].buffer_length = strlen(srv);
- int icl = (int)avgcurrentlisteners, ipl = (int)avgpeaklisteners, iml = (int)avgmaxlisteners, iat = (int)avgaveragetime, ish = (int)avgstreamhits;
- ibind[1].buffer_type = MYSQL_TYPE_LONG; ibind[1].buffer = &icl;
- ibind[2].buffer_type = MYSQL_TYPE_LONG; ibind[2].buffer = &ipl;
- ibind[3].buffer_type = MYSQL_TYPE_LONG; ibind[3].buffer = &iml;
- ibind[4].buffer_type = MYSQL_TYPE_LONG; ibind[4].buffer = &iat;
- ibind[5].buffer_type = MYSQL_TYPE_LONG; ibind[5].buffer = &ish;
- db->BindParams(stmt, ibind);
- if (db->Execute(stmt)) {
- db->CloseStatement(stmt);
- sprintf_s(query, sizeof(query),
- "delete from %sshoutcast_serverinfo where time < NOW() - INTERVAL ? HOUR and serverURL = ?",
- tablePrefix);
- stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND dbind[2];
- memset(dbind, 0, sizeof(dbind));
- dbind[0].buffer_type = MYSQL_TYPE_LONG; dbind[0].buffer = &age;
- dbind[1].buffer_type = MYSQL_TYPE_STRING; dbind[1].buffer = (char *)srv; dbind[1].buffer_length = strlen(srv);
- db->BindParams(stmt, dbind);
- if (!db->Execute(stmt)) {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- }
- db->CloseStatement(stmt);
- }
- } else {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- db->CloseStatement(stmt);
- }
- }
- }
- }
- }
-
- if (pData->serverType == 1) {
- sprintf_s(query, sizeof(query),
- "select ice2_cl, ice2_cons from %sicecast2_serverinfo where time < NOW() - INTERVAL ? HOUR and server_url = ?",
- tablePrefix);
- MYSQL_STMT *stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND bind[2];
- memset(bind, 0, sizeof(bind));
- bind[0].buffer_type = MYSQL_TYPE_LONG;
- bind[0].buffer = &age;
- const char *srv = serverURL;
- bind[1].buffer_type = MYSQL_TYPE_STRING;
- bind[1].buffer = (char *)srv;
- bind[1].buffer_length = strlen(srv);
- db->BindParams(stmt, bind);
-
- long cl = 0, cons = 0;
- MYSQL_BIND result[2];
- memset(result, 0, sizeof(result));
- result[0].buffer_type = MYSQL_TYPE_LONG; result[0].buffer = &cl;
- result[1].buffer_type = MYSQL_TYPE_LONG; result[1].buffer = &cons;
- db->BindResult(stmt, result);
- db->Execute(stmt);
-
- int numrows = 0;
- while (db->Fetch(stmt) == 0) {
- totalcurrentlisteners += cl;
- totalconnections += cons;
- numrows++;
- }
- db->CloseStatement(stmt);
-
- if (numrows > 0) {
- avgcurrentlisteners = totalcurrentlisteners / numrows;
- avgconnections = totalconnections / numrows;
-
- sprintf_s(query, sizeof(query),
- "insert into %sicecast2_history (serverURL, avgcurrentlisteners, avgconnections, time) values(?, ?, ?, NULL)",
- tablePrefix);
- stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND ibind[3];
- memset(ibind, 0, sizeof(ibind));
- ibind[0].buffer_type = MYSQL_TYPE_STRING; ibind[0].buffer = (char *)srv; ibind[0].buffer_length = strlen(srv);
- int icl = (int)avgcurrentlisteners, icons = (int)avgconnections;
- ibind[1].buffer_type = MYSQL_TYPE_LONG; ibind[1].buffer = &icl;
- ibind[2].buffer_type = MYSQL_TYPE_LONG; ibind[2].buffer = &icons;
- db->BindParams(stmt, ibind);
- if (db->Execute(stmt)) {
- db->CloseStatement(stmt);
- sprintf_s(query, sizeof(query),
- "delete from %sicecast2_serverinfo where time < NOW() - INTERVAL ? HOUR and server_url = ?",
- tablePrefix);
- stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND dbind[2];
- memset(dbind, 0, sizeof(dbind));
- dbind[0].buffer_type = MYSQL_TYPE_LONG; dbind[0].buffer = &age;
- dbind[1].buffer_type = MYSQL_TYPE_STRING; dbind[1].buffer = (char *)srv; dbind[1].buffer_length = strlen(srv);
- db->BindParams(stmt, dbind);
- if (!db->Execute(stmt)) {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- }
- db->CloseStatement(stmt);
- }
- } else {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- db->CloseStatement(stmt);
- }
- }
- }
- }
- }
-
- db->Disconnect();
- return 0;
-}
-int insertIntoMySQL(DB *db, CString tablePrefix, CString serverURL, serverData *pData)
-{
- char query[4096] = "";
- int insert_flag = 0;
-
- db->Connect();
-
- sprintf_s(query, sizeof(query),
- "select songTitle from %ssonginfo where serverURL = ? order by time desc limit 1",
- tablePrefix);
- MYSQL_STMT *stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND bind[1];
- memset(bind, 0, sizeof(bind));
- const char *srv = serverURL;
- bind[0].buffer_type = MYSQL_TYPE_STRING;
- bind[0].buffer = (char *)srv;
- bind[0].buffer_length = strlen(srv);
- db->BindParams(stmt, bind);
-
- char lastSong[1024] = "";
- MYSQL_BIND result[1];
- memset(result, 0, sizeof(result));
- result[0].buffer_type = MYSQL_TYPE_STRING;
- result[0].buffer = lastSong;
- result[0].buffer_length = sizeof(lastSong);
- db->BindResult(stmt, result);
- db->Execute(stmt);
- if (db->Fetch(stmt) == 0) {
- if (!strcmp(pData->songTitle, lastSong)) {
- insert_flag = 0;
- } else {
- insert_flag = 1;
- }
- } else {
- insert_flag = 1;
- }
- db->CloseStatement(stmt);
- }
-
- if (insert_flag) {
- if (pData->serverType == 0) {
- sprintf_s(query, sizeof(query),
- "insert into %ssonginfo values(?, ?, ?, NULL)", tablePrefix);
- stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND bind[3];
- memset(bind, 0, sizeof(bind));
- const char *srv = serverURL;
- bind[0].buffer_type = MYSQL_TYPE_STRING; bind[0].buffer = (char *)srv; bind[0].buffer_length = strlen(srv);
- bind[1].buffer_type = MYSQL_TYPE_STRING; bind[1].buffer = (char *)pData->songTitle; bind[1].buffer_length = strlen(pData->songTitle);
- bind[2].buffer_type = MYSQL_TYPE_LONG; bind[2].buffer = &pData->currentListeners;
- db->BindParams(stmt, bind);
- if (!db->Execute(stmt)) {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- }
- db->CloseStatement(stmt);
- }
- }
- if (pData->serverType == 1) {
- sprintf_s(query, sizeof(query),
- "insert into %ssonginfo values(?, ?, ?, NULL)", tablePrefix);
- stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND bind[3];
- memset(bind, 0, sizeof(bind));
- const char *srv = serverURL;
- bind[0].buffer_type = MYSQL_TYPE_STRING; bind[0].buffer = (char *)srv; bind[0].buffer_length = strlen(srv);
- bind[1].buffer_type = MYSQL_TYPE_STRING; bind[1].buffer = (char *)pData->songTitle; bind[1].buffer_length = strlen(pData->songTitle);
- bind[2].buffer_type = MYSQL_TYPE_LONG; bind[2].buffer = &pData->icecast2_listeners;
- db->BindParams(stmt, bind);
- if (!db->Execute(stmt)) {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- }
- db->CloseStatement(stmt);
- }
- }
- }
-
- if (pData->serverType == 0) {
- sprintf_s(query, sizeof(query),
- "insert into %sshoutcast_serverinfo (serverURL, currentlisteners, peaklisteners, maxlisteners, averagetime, streamhits, bitrate, time) values(?, ?, ?, ?, ?, ?, ?, NULL)",
- tablePrefix);
- stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND bind[7];
- memset(bind, 0, sizeof(bind));
- const char *srv = serverURL;
- bind[0].buffer_type = MYSQL_TYPE_STRING; bind[0].buffer = (char *)srv; bind[0].buffer_length = strlen(srv);
- bind[1].buffer_type = MYSQL_TYPE_LONG; bind[1].buffer = &pData->currentListeners;
- bind[2].buffer_type = MYSQL_TYPE_LONG; bind[2].buffer = &pData->peakListeners;
- bind[3].buffer_type = MYSQL_TYPE_LONG; bind[3].buffer = &pData->maxListeners;
- bind[4].buffer_type = MYSQL_TYPE_LONG; bind[4].buffer = &pData->avgTime;
- bind[5].buffer_type = MYSQL_TYPE_LONG; bind[5].buffer = &pData->streamHits;
- bind[6].buffer_type = MYSQL_TYPE_LONG; bind[6].buffer = &pData->bitrate;
- db->BindParams(stmt, bind);
- if (!db->Execute(stmt)) {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- }
- db->CloseStatement(stmt);
- }
- }
-
- if (pData->serverType == 1) {
- sprintf_s(query, sizeof(query),
- "insert into %sicecast2_serverinfo (server_name, current_song, server_url, ice2_br, ice2_ql, ice2_chn, ice2_sr, ice2_cons, ice2_cl, ice2_strtype, ice2_desc) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- tablePrefix);
- stmt = db->Prepare(query);
- if (stmt) {
- MYSQL_BIND bind[11];
- memset(bind, 0, sizeof(bind));
- const char *srv = serverURL;
- bind[0].buffer_type = MYSQL_TYPE_STRING; bind[0].buffer = pData->streamName; bind[0].buffer_length = strlen(pData->streamName);
- bind[1].buffer_type = MYSQL_TYPE_STRING; bind[1].buffer = pData->songTitle; bind[1].buffer_length = strlen(pData->songTitle);
- bind[2].buffer_type = MYSQL_TYPE_STRING; bind[2].buffer = (char *)srv; bind[2].buffer_length = strlen(srv);
- bind[3].buffer_type = MYSQL_TYPE_LONG; bind[3].buffer = &pData->icecast2_bitrate;
- bind[4].buffer_type = MYSQL_TYPE_LONG; bind[4].buffer = &pData->icecast2_quality;
- bind[5].buffer_type = MYSQL_TYPE_LONG; bind[5].buffer = &pData->icecast2_channels;
- bind[6].buffer_type = MYSQL_TYPE_LONG; bind[6].buffer = &pData->icecast2_samplerate;
- bind[7].buffer_type = MYSQL_TYPE_LONG; bind[7].buffer = &pData->icecast2_connections;
- bind[8].buffer_type = MYSQL_TYPE_LONG; bind[8].buffer = &pData->icecast2_listeners;
- bind[9].buffer_type = MYSQL_TYPE_STRING; bind[9].buffer = pData->icecast2_stream_type; bind[9].buffer_length = strlen(pData->icecast2_stream_type);
- bind[10].buffer_type = MYSQL_TYPE_STRING; bind[10].buffer = pData->icecast2_serverdescription; bind[10].buffer_length = strlen(pData->icecast2_serverdescription);
- db->BindParams(stmt, bind);
- if (!db->Execute(stmt)) {
- char buf[1024] = "";
- sprintf_s(buf, sizeof(buf), "MySQL Error (%s)", db->getErrorMessage());
- LogMessage(LOG_ERROR, buf);
- }
- db->CloseStatement(stmt);
- }
- }
-
- db->Disconnect();
- return 1;
-}