summaryrefslogtreecommitdiff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rwxr-xr-xsrc/data/con.cpp48
-rwxr-xr-xsrc/data/con.h8
-rwxr-xr-xsrc/data/con_base.cpp5
-rwxr-xr-xsrc/data/con_base.h4
-rw-r--r--src/data/data.cpp262
-rw-r--r--src/data/data.h18
-rw-r--r--src/data/data_base.cpp232
-rw-r--r--src/data/data_base.h23
8 files changed, 305 insertions, 295 deletions
diff --git a/src/data/con.cpp b/src/data/con.cpp
index b381232..b3aebcc 100755
--- a/src/data/con.cpp
+++ b/src/data/con.cpp
@@ -8,36 +8,36 @@ using namespace std;
con::con()
{
- p_mysql = mysql_init(NULL);
+ p_mysql = mysql_init(NULL);
- while ( !p_mysql )
- {
- wrap::system_message( MYSQLE1 );
- usleep( 30000000 );
- mysql_init(p_mysql);
- }
+ while ( !p_mysql )
+ {
+ wrap::system_message( MYSQLE1 );
+ usleep( 30000000 );
+ mysql_init(p_mysql);
+ }
- while ( mysql_real_connect(
- p_mysql,
- (const char*)wrap::CONF->get_elem("chat.database.serverhost").c_str(),
- (const char*)wrap::CONF->get_elem("chat.database.user").c_str(),
- (const char*)wrap::CONF->get_elem("chat.database.password").c_str(),
- (const char*)wrap::CONF->get_elem("chat.database.dbname").c_str(),
- tool::string2int(wrap::CONF->get_elem("chat.database.port")),
- NULL, 0 ) == NULL )
- {
- wrap::system_message( MYSQLQU + string( mysql_error(p_mysql) ) );
- usleep( 30000000 );
- }
+ while ( mysql_real_connect(
+ p_mysql,
+ (const char*)wrap::CONF->get_elem("chat.database.serverhost").c_str(),
+ (const char*)wrap::CONF->get_elem("chat.database.user").c_str(),
+ (const char*)wrap::CONF->get_elem("chat.database.password").c_str(),
+ (const char*)wrap::CONF->get_elem("chat.database.dbname").c_str(),
+ tool::string2int(wrap::CONF->get_elem("chat.database.port")),
+ NULL, 0 ) == NULL )
+ {
+ wrap::system_message( MYSQLQU + string( mysql_error(p_mysql) ) );
+ usleep( 30000000 );
+ }
}
con::~con()
{
- if ( p_mysql )
- {
- if (mysql_ping( p_mysql ) != 0)
- mysql_close( p_mysql );
- }
+ if ( p_mysql )
+ {
+ if (mysql_ping( p_mysql ) != 0)
+ mysql_close( p_mysql );
+ }
}
#endif
diff --git a/src/data/con.h b/src/data/con.h
index bc54341..9fda07b 100755
--- a/src/data/con.h
+++ b/src/data/con.h
@@ -4,7 +4,7 @@
#ifndef CON_H
#define CON_H
-#include <mysql/mysql.h>
+#include <mysql/mysql.h>
#include <iostream>
#include "con_base.h"
@@ -13,9 +13,9 @@ using namespace std;
class con : public con_base
{
public:
- MYSQL* p_mysql;
- con( );
- ~con( );
+ MYSQL* p_mysql;
+ con( );
+ ~con( );
};
#endif
diff --git a/src/data/con_base.cpp b/src/data/con_base.cpp
index 24bbbc9..003a376 100755
--- a/src/data/con_base.cpp
+++ b/src/data/con_base.cpp
@@ -8,12 +8,11 @@ using namespace std;
con_base::con_base()
{
- renew_timeout( );
+ renew_timeout( );
}
con_base::~con_base()
-{
-}
+{}
#endif
diff --git a/src/data/con_base.h b/src/data/con_base.h
index 60b12c2..9ebb89e 100755
--- a/src/data/con_base.h
+++ b/src/data/con_base.h
@@ -11,8 +11,8 @@ using namespace std;
class con_base : public timo
{
public:
- con_base( );
- ~con_base( );
+ con_base( );
+ ~con_base( );
};
#endif
diff --git a/src/data/data.cpp b/src/data/data.cpp
index e8f309c..fa509dd 100644
--- a/src/data/data.cpp
+++ b/src/data/data.cpp
@@ -7,194 +7,196 @@
using namespace std;
data::data()
-{
-}
+{}
data::~data()
-{
-}
+{}
-map_string
+hashmap<string>
data::select_user_data( string s_user, string s_query)
{
- string s_where_rule = " WHERE nick = \"" + s_user + "\"";
- vector<string> vec_elements;
- MYSQL_RES* p_result = select_query( s_query, s_where_rule, vec_elements );
- return parse_result( p_result, vec_elements );
+ string s_where_rule = " WHERE nick = \"" + s_user + "\"";
+ vector<string> vec_elements;
+ MYSQL_RES* p_result = select_query( s_query, s_where_rule, vec_elements );
+ return parse_result( p_result, vec_elements );
}
-MYSQL_RES*
+MYSQL_RES*
data::select_query( string s_query, string s_where_rule, vector<string>& vec_elements )
{
- con* p_con = get_con();
-
- vec_elements = map_queries[s_query];
- string s_mysql_query = "SELECT ";
- vector<string>::iterator iter = vec_elements.begin();
+ con* p_con = get_con();
- string s_table = *iter; iter++;
+ vec_elements = map_queries[s_query];
+ string s_mysql_query = "SELECT ";
+ vector<string>::iterator iter = vec_elements.begin();
- while ( iter != vec_elements.end() )
- {
- s_mysql_query.append( secure_query(*iter) );
- if ( ++iter != vec_elements.end() )
- s_mysql_query.append( ", " );
- }
+ string s_table = *iter;
+ iter++;
- s_mysql_query.append(" FROM " + s_table + s_where_rule );
- print_query( MYSQLQU + s_mysql_query );
+ while ( iter != vec_elements.end() )
+ {
+ s_mysql_query.append( secure_query(*iter) );
+ if ( ++iter != vec_elements.end() )
+ s_mysql_query.append( ", " );
+ }
- MYSQL_RES* p_result = NULL;
+ s_mysql_query.append(" FROM " + s_table + s_where_rule );
+ print_query( MYSQLQU + s_mysql_query );
- if ( 0 == mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) )
- {
- p_result = mysql_store_result( p_con->p_mysql );
- push_con( p_con );
- }
+ MYSQL_RES* p_result = NULL;
- else
- {
- wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) );
- if (p_con != NULL)
- delete p_con;
- }
+ if ( 0 == mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) )
+ {
+ p_result = mysql_store_result( p_con->p_mysql );
+ push_con( p_con );
+ }
+ else
+ {
+ wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) );
+ if (p_con != NULL)
+ delete p_con;
+ }
- return p_result;
+ return p_result;
}
-map_string
+hashmap<string>
data::parse_result( MYSQL_RES* p_result, vector<string>& vec_elements )
{
- map_string map_ret;
- if ( p_result != NULL )
- {
- MYSQL_ROW row;
- vector<string>::iterator vec_iter = vec_elements.begin(); vec_iter++;
-
- while( (row = mysql_fetch_row(p_result)) )
- for ( int i=0; i < mysql_num_fields(p_result); i++, vec_iter++ )
- map_ret[*vec_iter] = string(row[i]);
-
- mysql_free_result( p_result );
- }
- return map_ret;
+ hashmap<string> map_ret;
+ if ( p_result != NULL )
+ {
+ MYSQL_ROW row;
+ vector<string>::iterator vec_iter = vec_elements.begin();
+ vec_iter++;
+
+ while( (row = mysql_fetch_row(p_result)) )
+ for ( int i=0; i < mysql_num_fields(p_result); i++, vec_iter++ )
+ map_ret[*vec_iter] = string(row[i]);
+
+ mysql_free_result( p_result );
+ }
+ return map_ret;
}
void
-data::insert_user_data( string s_user, string s_query, map_string insert_map )
+data::insert_user_data( string s_user, string s_query, map<string,string> insert_map )
{
- insert_query( s_query, insert_map );
+ insert_query( s_query, insert_map );
}
void
-data::insert_query( string s_query, map_string map_insert )
+data::insert_query( string s_query, map<string,string> map_insert )
{
- vector<string> vec_elements = map_queries[s_query];
- vector<string>::iterator iter = vec_elements.begin();
-
- string s_table = *iter; iter++;
- string s_mysql_query = "INSERT INTO " + s_table + " (";
-
- while ( iter != vec_elements.end() )
- {
- s_mysql_query.append( *iter );
-
- if ( ++iter != vec_elements.end() )
- s_mysql_query.append( ", " );
- else
- s_mysql_query.append( ") VALUES(" );
- }
+ vector<string> vec_elements = map_queries[s_query];
+ vector<string>::iterator iter = vec_elements.begin();
- iter = vec_elements.begin(); iter++;
+ string s_table = *iter;
+ iter++;
+ string s_mysql_query = "INSERT INTO " + s_table + " (";
- while ( iter != vec_elements.end() )
- {
- s_mysql_query.append( "\"" + secure_query(map_insert[*iter]) + "\"" );
- if ( ++iter != vec_elements.end() )
- s_mysql_query.append( ", " );
- else
- s_mysql_query.append( ")" );
- }
+ while ( iter != vec_elements.end() )
+ {
+ s_mysql_query.append( *iter );
- print_query( MYSQLQU + s_mysql_query );
+ if ( ++iter != vec_elements.end() )
+ s_mysql_query.append( ", " );
+ else
+ s_mysql_query.append( ") VALUES(" );
+ }
- con* p_con = get_con();
+ iter = vec_elements.begin();
+ iter++;
- if ( 0 != mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) )
- wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) );
+ while ( iter != vec_elements.end() )
+ {
+ s_mysql_query.append( "\"" + secure_query(map_insert[*iter]) + "\"" );
+ if ( ++iter != vec_elements.end() )
+ s_mysql_query.append( ", " );
+ else
+ s_mysql_query.append( ")" );
+ }
+
+ print_query( MYSQLQU + s_mysql_query );
+
+ con* p_con = get_con();
- push_con( p_con );
+ if ( 0 != mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) )
+ wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) );
- return;
+ push_con( p_con );
+
+ return;
}
-void
-data::update_user_data( string s_user, string s_query, map_string update_map )
+void
+data::update_user_data( string s_user, string s_query, hashmap<string> update_map )
{
- vector<string> vec_elements = map_queries[s_query];
+ vector<string> vec_elements = map_queries[s_query];
- if ( vec_elements.size() == 0 )
- return;
+ if ( vec_elements.size() == 0 )
+ return;
- vector<string>::iterator iter = vec_elements.begin();
- vector<string>::iterator iter_second = vec_elements.begin();
- iter_second++;
+ vector<string>::iterator iter = vec_elements.begin();
+ vector<string>::iterator iter_second = vec_elements.begin();
+ iter_second++;
- string s_table = *iter; iter++;
- string s_mysql_query = "UPDATE " + s_table + " SET ";
- bool b_flag = 0;
+ string s_table = *iter;
+ iter++;
+ string s_mysql_query = "UPDATE " + s_table + " SET ";
+ bool b_flag = 0;
- while ( iter != vec_elements.end() )
- {
- if ( update_map[*iter] == "" ) // Dont update data if it has not been changed / if its empty!
+ while ( iter != vec_elements.end() )
{
- iter++;
- continue;
- }
+ if ( update_map[*iter] == "" ) // Dont update data if it has not been changed / if its empty!
+ {
+ iter++;
+ continue;
+ }
- if ( iter != iter_second && b_flag )
- s_mysql_query.append( ", " );
+ if ( iter != iter_second && b_flag )
+ s_mysql_query.append( ", " );
- s_mysql_query.append( *iter + "=\"" + secure_query(update_map[*iter]) + "\"" );
- b_flag = 1;
- iter++;
- }
+ s_mysql_query.append( *iter + "=\"" + secure_query(update_map[*iter]) + "\"" );
+ b_flag = 1;
+ iter++;
+ }
- if ( b_flag )
- {
- s_mysql_query.append( " WHERE nick=\"" + tool::to_lower(s_user) + "\"" );
+ if ( b_flag )
+ {
+ s_mysql_query.append( " WHERE nick=\"" + tool::to_lower(s_user) + "\"" );
- con* p_con = get_con();
- print_query( MYSQLQU + s_mysql_query );
+ con* p_con = get_con();
+ print_query( MYSQLQU + s_mysql_query );
- if ( 0 != mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) )
- wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) );
+ if ( 0 != mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) )
+ wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) );
- push_con( p_con );
- }
+ push_con( p_con );
+ }
}
string
data::secure_query( string s_mysql_query )
{
- // Prevent from MySQL injection attacks (escaping " and \)
- unsigned i_pos = s_mysql_query.find("\\");
-
- while ( i_pos != string::npos )
- {
- s_mysql_query.replace( i_pos, 1, "/" );
- i_pos = s_mysql_query.find("\\");
- }
+ // Prevent from MySQL injection attacks (escaping " and \)
+ unsigned i_pos = s_mysql_query.find("\\");
- i_pos = s_mysql_query.find("\"");
+ while ( i_pos != string::npos )
+ {
+ s_mysql_query.replace( i_pos, 1, "/" );
+ i_pos = s_mysql_query.find("\\");
+ }
- while ( i_pos != string::npos )
- {
- s_mysql_query.replace( i_pos, 1, "'" );
i_pos = s_mysql_query.find("\"");
- }
- return s_mysql_query;
+ while ( i_pos != string::npos )
+ {
+ s_mysql_query.replace( i_pos, 1, "'" );
+ i_pos = s_mysql_query.find("\"");
+ }
+
+ return s_mysql_query;
}
#endif
diff --git a/src/data/data.h b/src/data/data.h
index fa21763..a6ca90f 100644
--- a/src/data/data.h
+++ b/src/data/data.h
@@ -12,17 +12,17 @@ using namespace std;
class data : public data_base // data implementation used in data.h
{
private:
- MYSQL_RES* select_query( string s_query, string s_where_rule, vector<string>& vec_elements );
- map_string parse_result( MYSQL_RES* p_result, vector<string>& vec_elements );
- void insert_query( string s_query, map_string map_insert );
- string secure_query( string s_mysql_query );
+ MYSQL_RES* select_query( string s_query, string s_where_rule, vector<string>& vec_elements );
+ hashmap<string> parse_result( MYSQL_RES* p_result, vector<string>& vec_elements );
+ void insert_query( string s_query, map<string,string> map_insert );
+ string secure_query( string s_mysql_query );
public:
- data( );
- ~data( );
+ data( );
+ ~data( );
- map_string select_user_data( string s_user, string s_query );
- void insert_user_data( string s_user, string s_query, map_string insert_map );
- void update_user_data( string s_user, string s_query, map_string update_map );
+ hashmap<string> select_user_data( string s_user, string s_query );
+ void insert_user_data( string s_user, string s_query, map<string,string> insert_map );
+ void update_user_data( string s_user, string s_query, hashmap<string> update_map );
};
#endif
diff --git a/src/data/data_base.cpp b/src/data/data_base.cpp
index c8bf033..8150608 100644
--- a/src/data/data_base.cpp
+++ b/src/data/data_base.cpp
@@ -8,92 +8,93 @@ using namespace std;
data_base::data_base( )
{
- pthread_mutex_init ( &mut_con, NULL );
+ pthread_mutex_init ( &mut_con, NULL );
- vector<string> vec_keys = *wrap::CONF->get_key_vector();
- vector<string>::iterator iter;
+ vector<string> vec_keys = *wrap::CONF->get_key_vector();
+ vector<string>::iterator iter;
- // Reads all DATA_ elements of conf.txt!
- for ( iter = vec_keys.begin(); iter != vec_keys.end(); iter++ )
- {
- if ( iter->length() > 20
- && iter->compare(0, 19, "chat.database.mysql") == 0
- && iter->find(".descr") == string::npos )
+ // Reads all DATA_ elements of conf.txt!
+ for ( iter = vec_keys.begin(); iter != vec_keys.end(); iter++ )
{
- vector<string> vec_tokens;
- string s_element = wrap::CONF->get_elem(*iter);
- unsigned i_pos = 0;
-
- for ( bool b_find = 1; b_find; )
- {
- i_pos = s_element.find_first_of( " ", 0 );
-
- if ( i_pos != string::npos )
+ if ( iter->length() > 20
+ && iter->compare(0, 19, "chat.database.mysql") == 0
+ && iter->find(".descr") == string::npos )
{
- vec_tokens.push_back( s_element.substr(0, i_pos) );
- s_element = s_element.substr( i_pos+1 );
+ vector<string> vec_tokens;
+ string s_element = wrap::CONF->get_elem(*iter);
+ unsigned i_pos = 0;
+
+ for ( bool b_find = 1; b_find; )
+ {
+ i_pos = s_element.find_first_of( " ", 0 );
+
+ if ( i_pos != string::npos )
+ {
+ vec_tokens.push_back( s_element.substr(0, i_pos) );
+ s_element = s_element.substr( i_pos+1 );
+ }
+ else
+ {
+ vec_tokens.push_back( s_element );
+ b_find = 0;
+ }
+ }
+
+ string s_mysqlquery = iter->substr(20);
+ wrap::system_message(MYSQLQ2 + s_mysqlquery);
+ map_queries[s_mysqlquery] = vec_tokens;
}
-
- else
- {
- vec_tokens.push_back( s_element );
- b_find = 0;
- }
- }
-
- string s_mysqlquery = iter->substr(20);
- wrap::system_message(MYSQLQ2 + s_mysqlquery);
- map_queries[s_mysqlquery] = vec_tokens;
}
- }
}
-void data_base::initialize_connections() {
- int i_min_con = tool::string2int( wrap::CONF->get_elem("chat.database.mincon") ),
- i_max_con = tool::string2int( wrap::CONF->get_elem("chat.database.maxcon") );
+void data_base::init_connections()
+{
+ int i_min_con = tool::string2int( wrap::CONF->get_elem("chat.database.mincon") ),
+ i_max_con = tool::string2int( wrap::CONF->get_elem("chat.database.maxcon") );
- wrap::system_message(DATAIN0 + tool::int2string(i_max_con));
- wrap::system_message(DATAIN1 + tool::int2string(i_min_con));
+ wrap::system_message(DATAIN0 + tool::int2string(i_max_con));
+ wrap::system_message(DATAIN1 + tool::int2string(i_min_con));
- for ( int i = 0; i < i_min_con && i < i_max_con; i++ )
- push_back( new con() );
+ for ( int i = 0; i < i_min_con && i < i_max_con; i++ )
+ push_back( new con() );
#ifdef NCURSES
- print_queue_size();
+
+ print_queue_size();
#endif
}
data_base::~data_base()
{
- pthread_mutex_destroy ( &mut_con );
+ pthread_mutex_destroy ( &mut_con );
}
-map_string
+hashmap<string>
data_base::select_user_data( string s_user, string s_query)
{
- print_query( DATAQUE + s_query );
- map_string map_ret;
- return map_ret;
+ print_query( DATAQUE + s_query );
+ hashmap<string> map_ret;
+ return map_ret;
}
void
-data_base::insert_user_data( string s_user, string s_query, map_string insert_map )
+data_base::insert_user_data( string s_user, string s_query, hashmap<string> insert_map )
{
- print_query( DATAQUE + s_query );
+ print_query( DATAQUE + s_query );
}
void
-data_base::update_user_data( string s_user, string s_query, map_string update_map )
+data_base::update_user_data( string s_user, string s_query, hashmap<string> update_map )
{
- print_query( DATAQUE + s_query );
+ print_query( DATAQUE + s_query );
}
void
data_base::print_query( string s_query )
{
#ifdef DATA_PRINT_QUERIES
- print_query_( s_query );
+ print_query_( s_query );
#endif
}
@@ -101,119 +102,124 @@ data_base::print_query( string s_query )
void
data_base::print_query_( string s_query )
{
- wrap::system_message( s_query );
+ wrap::system_message( s_query );
}
#endif
con*
data_base::get_con()
{
- pthread_mutex_lock( &mut_con );
-
- if ( empty() )
- {
- wrap::system_message( DATANEW + string("(") + tool::int2string(size()+1) + ")" );
- pthread_mutex_unlock( &mut_con );
- return new con;
- }
+ pthread_mutex_lock( &mut_con );
- else if ( size() > i_max_con-1 )
- {
- wrap::system_message( DATAMAX + string("(") + tool::int2string(i_max_con) + ")" );
- usleep( 5000000 );
- pthread_mutex_unlock( &mut_con );
- return get_con();
- }
+ if ( empty() )
+ {
+ wrap::system_message( DATANEW + string("(") + tool::int2string(size()+1) + ")" );
+ pthread_mutex_unlock( &mut_con );
+ return new con;
+ }
+ else if ( size() > i_max_con-1 )
+ {
+ wrap::system_message( DATAMAX + string("(") + tool::int2string(i_max_con) + ")" );
+ usleep( 5000000 );
+ pthread_mutex_unlock( &mut_con );
+ return get_con();
+ }
- con* p_con = *begin();
- pop_front();
+ con* p_con = *begin();
+ pop_front();
#ifdef NCURSES
- print_queue_size();
+
+ print_queue_size();
#endif
- pthread_mutex_unlock( &mut_con );
- wrap::system_message( DATAGET );
+ pthread_mutex_unlock( &mut_con );
+ wrap::system_message( DATAGET );
- p_con->renew_timeout();
- return p_con;
+ p_con->renew_timeout();
+ return p_con;
}
void
-data_base::push_con( con* p_con )
+data_base::push_con( con* p_con )
{
- pthread_mutex_lock( &mut_con );
- push_front( p_con );
+ pthread_mutex_lock( &mut_con );
+ push_front( p_con );
#ifdef NCURSES
- print_queue_size();
+
+ print_queue_size();
#endif
- pthread_mutex_unlock( &mut_con );
- wrap::system_message( DATAADD );
+
+ pthread_mutex_unlock( &mut_con );
+ wrap::system_message( DATAADD );
}
#ifdef NCURSES
void
data_base::print_queue_size()
{
- if ( wrap::NCUR->is_ready() )
- {
- mvprintw( NCUR_CON_QUEUE_X,NCUR_CON_QUEUE_Y, "Con. queue: %d ", size());
- refresh();
- }
+ if ( wrap::NCUR->is_ready() )
+ {
+ mvprintw( NCUR_CON_QUEUE_X,NCUR_CON_QUEUE_Y, "Con. queue: %d ", size());
+ refresh();
+ }
}
#endif
void
data_base::disconnect_all_connections()
{
- wrap::system_message( DATADIS );
- pthread_mutex_lock( &mut_con );
+ wrap::system_message( DATADIS );
+ pthread_mutex_lock( &mut_con );
- while ( !empty() )
- {
- con* p_con = *begin();
- pop_front();
- delete p_con;
- }
-
- pthread_mutex_unlock( &mut_con );
+ while ( !empty() )
+ {
+ con* p_con = *begin();
+ pop_front();
+ delete p_con;
+ }
+
+ pthread_mutex_unlock( &mut_con );
#ifdef NCURSES
- print_queue_size();
+
+ print_queue_size();
#endif
}
void
data_base::check_data_con_timeout()
{
- int i_timeout_time = tool::string2int(wrap::CONF->get_elem("chat.database.contimeout"));
- int i_last_activity;
+ int i_timeout_time = tool::string2int(wrap::CONF->get_elem("chat.database.contimeout"));
+ int i_last_activity;
- pthread_mutex_lock( &mut_con );
-
- list< list<con*>::iterator > erase_list;
- for ( list<con*>::iterator iter = begin();
+ pthread_mutex_lock( &mut_con );
+
+ list< list<con*>::iterator > erase_list;
+ for ( list<con*>::iterator iter = begin();
iter != end(); iter++ )
{
- i_last_activity = (int) (*iter)->get_last_activity();
- if ( i_timeout_time <= i_last_activity )
- {
- con* p_con = *iter;
- erase_list.push_back(iter);
- delete p_con;
- wrap::system_message(DATADI2 + tool::int2string(size()-erase_list.size()+1) + ","
- + tool::int2string(i_timeout_time) + ","
- + tool::int2string(i_last_activity) + ")");
- }
+ i_last_activity = (int) (*iter)->get_last_activity();
+ if ( i_timeout_time <= i_last_activity )
+ {
+ con* p_con = *iter;
+ erase_list.push_back(iter);
+ delete p_con;
+ wrap::system_message(DATADI2 + tool::int2string(size()-erase_list.size()+1) + ","
+ + tool::int2string(i_timeout_time) + ","
+ + tool::int2string(i_last_activity) + ")");
+ }
}
for ( list< list<con*>::iterator >::iterator erase_iter = erase_list.begin();
erase_iter != erase_list.end(); erase_iter++ )
- erase( *erase_iter );
+ erase( *erase_iter );
#ifdef NCURSES
+
print_queue_size();
#endif
- pthread_mutex_unlock( &mut_con );
+
+ pthread_mutex_unlock( &mut_con );
}
diff --git a/src/data/data_base.h b/src/data/data_base.h
index b38d978..79f5630 100644
--- a/src/data/data_base.h
+++ b/src/data/data_base.h
@@ -12,33 +12,36 @@ using namespace std;
class data_base : protected list<con*>
{
- private:
+private:
pthread_mutex_t mut_con;
int i_max_con;
#ifdef NCURSES
+
void print_queue_size();
#endif
- protected:
- map< string, vector<string> > map_queries;
+protected:
+ hashmap< vector<string> > map_queries;
void print_query( string s_query );
#ifdef DATA_PRINT_QUERIES
+
virtual void print_query_( string s_query );
#endif
+
con* get_con();
void push_con( con* p_con );
- public:
+public:
data_base();
~data_base();
- void initialize_connections();
- virtual map_string select_user_data( string s_user, string s_query );
- virtual void insert_user_data( string s_user, string s_query, map_string insert_map );
- virtual void update_user_data( string s_user, string s_query, map_string update_map );
- void disconnect_all_connections();
- void check_data_con_timeout();
+ void init_connections();
+ virtual hashmap<string> select_user_data( string s_user, string s_query );
+ virtual void insert_user_data( string s_user, string s_query, hashmap<string> insert_map );
+ virtual void update_user_data( string s_user, string s_query, hashmap<string> update_map );
+ void disconnect_all_connections();
+ void check_data_con_timeout();
};
#endif