diff options
Diffstat (limited to 'src/data/data_base.cpp')
| -rw-r--r-- | src/data/data_base.cpp | 148 |
1 files changed, 63 insertions, 85 deletions
diff --git a/src/data/data_base.cpp b/src/data/data_base.cpp index b8e79b4..2cbe070 100644 --- a/src/data/data_base.cpp +++ b/src/data/data_base.cpp @@ -1,27 +1,3 @@ -/*:* - *: File: ./src/data/data_base.cpp - *: - *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE - *: - *: Copyright (C) 2003 Paul C. Buetow, Volker Richter - *: Copyright (C) 2004 Paul C. Buetow - *: Copyright (C) 2005 EXA Digital Solutions GbR - *: - *: This program is free software; you can redistribute it and/or - *: modify it under the terms of the GNU General Public License - *: as published by the Free Software Foundation; either version 2 - *: of the License, or (at your option) any later version. - *: - *: This program is distributed in the hope that it will be useful, - *: but WITHOUT ANY WARRANTY; without even the implied warranty of - *: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - *: GNU General Public License for more details. - *: - *: You should have received a copy of the GNU General Public License - *: along with this program; if not, write to the Free Software - *: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *:*/ - #include "data_base.h" #ifdef DATABASE @@ -39,39 +15,40 @@ data_base::data_base( ) // 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 ) { - 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 + if ( iter->length() > 20 + && iter->compare(0, 19, "chat.database.mysql") == 0 + && iter->find(".descr") == string::npos ) { - vec_tokens.push_back( s_element ); - b_find = 0; + 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; } - } - - string s_mysqlquery = iter->substr(20); - wrap::system_message(MYSQLQ2 + s_mysqlquery); - map_queries[s_mysqlquery] = vec_tokens; } - } } -void data_base::init_connections() +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") ); @@ -93,23 +70,23 @@ data_base::~data_base() pthread_mutex_destroy ( &mut_con ); } -hashmap<string> +map<string,string> data_base::select_user_data( string s_user, string s_query) { print_query( DATAQUE + s_query ); - hashmap<string> map_ret; + map<string,string> map_ret; return map_ret; } void -data_base::insert_user_data( string s_user, string s_query, hashmap<string> insert_map ) +data_base::insert_user_data( string s_user, string s_query, map<string,string> insert_map ) { print_query( DATAQUE + s_query ); } void -data_base::update_user_data( string s_user, string s_query, hashmap<string> update_map ) +data_base::update_user_data( string s_user, string s_query, map<string,string> update_map ) { print_query( DATAQUE + s_query ); } @@ -136,18 +113,19 @@ 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; - } + { + 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(); - } + { + wrap::system_message( DATAMAX + string("(") + tool::int2string(i_max_con) + ")" ); + usleep( 5000000 ); + pthread_mutex_unlock( &mut_con ); + return get_con(); + } con* p_con = *begin(); @@ -184,10 +162,10 @@ 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(); - } + { + mvprintw( NCUR_CON_QUEUE_X,NCUR_CON_QUEUE_Y, "Con. queue: %d ", size()); + refresh(); + } } #endif @@ -198,11 +176,11 @@ data_base::disconnect_all_connections() pthread_mutex_lock( &mut_con ); while ( !empty() ) - { - con* p_con = *begin(); - pop_front(); - delete p_con; - } + { + con* p_con = *begin(); + pop_front(); + delete p_con; + } pthread_mutex_unlock( &mut_con ); #ifdef NCURSES @@ -222,18 +200,18 @@ data_base::check_data_con_timeout() 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 ); |
