From 520f54d6219b7c625b4e07463ac393e6982ddab6 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:41 +0200 Subject: tagging ychat-0.7.1 --- src/chat/base.h | 4 +- src/chat/chat.cpp | 50 +++---- src/chat/chat.h | 7 +- src/chat/room.cpp | 21 +-- src/chat/room.h | 11 +- src/chat/sess.cpp | 40 +----- src/chat/sess.h | 17 +-- src/chat/sman.cpp | 11 +- src/chat/sman.h | 6 +- src/chat/user.cpp | 4 +- src/chat/user.h | 6 +- src/cli/cli.cpp | 53 +------- src/cli/cli.h | 11 +- src/conf/conf.cpp | 18 +-- src/conf/conf.h | 10 +- src/conf/lang.cpp | 67 ++++++++++ src/conf/lang.h | 23 ++++ src/configure | 10 +- src/data/con.cpp | 48 +++---- src/data/con.h | 14 +- src/data/con_base.cpp | 5 +- src/data/con_base.h | 6 +- src/data/data.cpp | 263 ++++++++++++++++++------------------- src/data/data.h | 24 ++-- src/data/data_base.cpp | 240 ++++++++++++++++----------------- src/data/data_base.h | 49 ++++--- src/glob.h | 14 +- src/html.cpp | 34 +++-- src/html.h | 15 ++- src/incl.h | 5 +- src/logd.cpp | 21 +-- src/logd.h | 7 +- src/main.cpp | 27 ++-- src/maps/hmap.tmpl | 4 + src/maps/mtools.h | 4 + src/maps/nmap.h | 3 + src/maps/smap.h | 2 + src/maps/smap.tmpl | 4 + src/modl.cpp | 16 +-- src/modl.h | 2 +- src/mods/Makefile | 9 +- src/mods/commands/yc_away.cpp | 18 +-- src/mods/commands/yc_col.cpp | 2 - src/mods/commands/yc_exec.cpp | 2 - src/mods/commands/yc_fake.cpp | 2 - src/mods/commands/yc_getroom.cpp | 2 - src/mods/commands/yc_getrusage.cpp | 2 - src/mods/commands/yc_getstatus.cpp | 57 ++++++++ src/mods/commands/yc_help.cpp | 2 - src/mods/commands/yc_invisible.cpp | 6 +- src/mods/commands/yc_j.cpp | 2 - src/mods/commands/yc_ko.cpp | 4 +- src/mods/commands/yc_m.cpp | 1 - src/mods/commands/yc_md5.cpp | 2 - src/mods/commands/yc_me.cpp | 2 - src/mods/commands/yc_msg.cpp | 35 ++--- src/mods/commands/yc_q.cpp | 2 - src/mods/commands/yc_reload.cpp | 2 - src/mods/commands/yc_ren.cpp | 2 - src/mods/commands/yc_s.cpp | 13 +- src/mods/commands/yc_set.cpp | 2 - src/mods/commands/yc_template.cpp | 2 - src/mods/commands/yc_time.cpp | 2 - src/mods/commands/yc_topic.cpp | 14 +- src/mods/commands/yc_uptime.cpp | 2 - src/mods/commands/yc_version.cpp | 4 +- src/mods/html/yc_admin.cpp | 4 +- src/mods/html/yc_colors.cpp | 10 +- src/mods/html/yc_help.cpp | 4 +- src/mods/html/yc_options.cpp | 14 +- src/mods/html/yc_register.cpp | 18 ++- src/msgs.h | 31 +---- src/name.cpp | 4 +- src/name.h | 8 +- src/ncur/menu.cpp | 11 +- src/ncur/menu.h | 7 +- src/ncur/ncur.cpp | 34 ++--- src/ncur/ncur.h | 18 +-- src/reqp.cpp | 120 +++++++++-------- src/reqp.h | 35 +++-- src/sock/Makefile | 23 ++++ src/sock/README | 1 + src/sock/sock.cpp | 133 ++++++++++--------- src/sock/sock.h | 39 +++--- src/stats.cpp | 1 - src/stats.h | 2 +- src/thrd/pool.cpp | 162 ++++++++++------------- src/thrd/pool.h | 37 ++++-- src/thrd/thrd.cpp | 26 ++++ src/thrd/thrd.h | 28 ++++ src/thrd/thro.cpp | 3 +- src/thrd/thro.h | 12 +- src/time/timo.cpp | 4 +- src/time/timr.cpp | 31 ++--- src/time/timr.h | 8 +- src/tool/dir.cpp | 18 +-- src/tool/dir.h | 8 +- src/tool/tool.cpp | 145 ++++---------------- src/tool/tool.h | 84 ++++++++++-- src/wrap.cpp | 6 +- src/wrap.h | 14 +- 101 files changed, 1208 insertions(+), 1264 deletions(-) create mode 100755 src/conf/lang.cpp create mode 100755 src/conf/lang.h create mode 100644 src/mods/commands/yc_getstatus.cpp create mode 100644 src/sock/Makefile create mode 100644 src/sock/README create mode 100755 src/thrd/thrd.cpp create mode 100755 src/thrd/thrd.h (limited to 'src') diff --git a/src/chat/base.h b/src/chat/base.h index dc44c69..ae2e926 100755 --- a/src/chat/base.h +++ b/src/chat/base.h @@ -57,14 +57,14 @@ public: type_obj -> reconf (); } - void get_data( map *p_map_string ) + void get_data( map_string *p_map_string ) { smap::run_func( &base::get_data_ , (void*)p_map_string ); } static void get_data_( type* type_obj, void* v_arg ) { - type_obj -> get_data ( (map*) v_arg ); + type_obj -> get_data ( (map_string*) v_arg ); } diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp index 493c2a5..86bc140 100755 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -65,15 +65,13 @@ void chat::get_user_( room *room_obj, void *v_arg ) { container* param = (container*) v_arg; - if ( *((bool*)param->elem[1]) ) return; - param->elem[2] = (void*)room_obj->get_elem( *((string*)param->elem[0]), *((bool*)param->elem[1]) ); } void -chat::login( map &map_params ) +chat::login( map_string &map_params ) { string s_user = map_params["nick"]; @@ -156,8 +154,8 @@ chat::login( map &map_params ) { sess* p_sess = wrap::SMAN->create_session(); //p_sess->set_value( string("nick"), (void *) new string(s_user) ); - p_sess->set_user(p_user); - map_params["tmpid"] = p_sess->get_tmpid(); + p_sess->set_name(s_user); + map_params["tmpid"] = p_sess->get_id(); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_has_sess( true ); } @@ -167,9 +165,9 @@ chat::login( map &map_params ) { p_user = new user( s_user ); - // prove if nick is registered, else create a guest chatter. + // prove if nick is registered #ifdef DATABASE - map map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin"); + map_string map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin"); if ( map_results["nick"] == tool::to_lower(s_user) ) { @@ -194,23 +192,15 @@ chat::login( map &map_params ) } else #endif - { // If not registered prove if guest chatting is enabled. - if (wrap::CONF->get_elem("chat.enableguest") != "true") { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.noguest" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. - wrap::system_message( LOGINE4 + s_user ); - return; - } - - // Guest chatter are enabled, use standard font colors + { // If not registered use standard font colors map_params["color1"] = wrap::CONF->get_elem( "chat.html.user.color1" ); map_params["color2"] = wrap::CONF->get_elem( "chat.html.user.color2" ); map_params["status"] = wrap::CONF->get_elem( "chat.defaultrang" ); } sess* p_sess = wrap::SMAN->create_session(); - p_sess->set_user(p_user); - map_params["tmpid"] = p_sess->get_tmpid(); + p_sess->set_name(s_user); + map_params["tmpid"] = p_sess->get_id(); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_col1( map_params["color1"] ); p_user->set_col2( map_params["color2"] ); @@ -267,7 +257,7 @@ chat::login( map &map_params ) } void -chat::post( user* p_user, map &map_params ) +chat::post( user* p_user, map_string &map_params ) { p_user->renew_timeout(); @@ -310,11 +300,18 @@ chat::post( user* p_user, map &map_params ) if ( wrap::CONF->get_elem( "chat.html.tagsallow" ) != "true" ) tool::strip_html( &s_msg ); - unsigned i_pos = s_msg.find( "/" ); + auto unsigned i_pos = s_msg.find( "/" ); if ( i_pos == 0 ) return p_user->command( s_msg ); - string_replacer(&s_msg); + if ( wrap::CONF->get_elem( "chat.html.replace.activate" ) == "true" ) + { + for (vector::iterator iter = vec_replace_keys.end()-1; + iter != vec_replace_keys.begin(); + iter-- ) + s_msg = tool::replace( s_msg, *iter, wrap::CONF->get_elem(map_replace_strings[*iter]) ); + } + string s_post; if ( wrap::CONF->get_elem( "chat.printalwaystime" ) == "true" ) @@ -338,15 +335,4 @@ chat::reconf() { } -void -chat::string_replacer(string *p_msg) { - if ( wrap::CONF->get_elem( "chat.html.replace.activate" ) == "true" ) - { - for (vector::iterator iter = vec_replace_keys.end()-1; - iter != vec_replace_keys.begin(); - iter-- ) - *p_msg = tool::replace( *p_msg, *iter, wrap::CONF->get_elem(map_replace_strings[*iter]) ); - } -} - #endif diff --git a/src/chat/chat.h b/src/chat/chat.h index 86b7c0b..c37bebc 100755 --- a/src/chat/chat.h +++ b/src/chat/chat.h @@ -21,7 +21,7 @@ using namespace std; class chat : public base, public perm { private: - map map_replace_strings; + map_string map_replace_strings; vector vec_replace_keys; public: @@ -46,10 +46,10 @@ public: static void get_user_( room* room_obj, void *v_arg ); // will be called every time a user tries to login. - void login( map &map_params ); + void login( map_string &map_params ); // will be called if a user posts a message. - void post ( user* u_user, map &map_params ); + void post ( user* u_user, map_string &map_params ); void del_elem( string s_name ) { @@ -57,6 +57,5 @@ public: } void reconf(); - void string_replacer(string *p_msg); }; #endif diff --git a/src/chat/room.cpp b/src/chat/room.cpp index c21639a..b2f17f8 100755 --- a/src/chat/room.cpp +++ b/src/chat/room.cpp @@ -9,10 +9,8 @@ using namespace std; room::room( string s_name ) : name( s_name ) { pthread_mutex_init( &mut_s_topic, NULL ); -#ifdef LOGGING p_logd = new logd( wrap::CONF->get_elem("chat.logging.roomlogdir") + get_lowercase_name(), wrap::CONF->get_elem("chat.logging.roomloglines") ); -#endif wrap::STAT->increment_num_rooms(); } @@ -23,9 +21,7 @@ room::~room() // Delete all user objects run_func( mtools::delete_obj ); -#ifdef LOGGING delete p_logd; -#endif pthread_mutex_destroy( &mut_s_topic ); pthread_mutex_destroy( &mut_s_name ); @@ -42,23 +38,14 @@ room::get_topic() } void -room::set_topic( string s_topic ) +room::set_topic( string s_topic) { pthread_mutex_lock ( &mut_s_topic ); - if ( s_topic == "" ) - this->s_topic = ""; - else - this->s_topic = s_topic + "

"; + this->s_topic = s_topic; pthread_mutex_unlock( &mut_s_topic ); reload_onlineframe(); } -void -room::set_topic( string s_topic, string s_color ) -{ - set_topic( "" + s_topic + ""); -} - void room::clean_room() { @@ -85,17 +72,13 @@ room::set_name( string s_name ) return; } -#ifdef LOGGING p_logd->flush_logs(); -#endif if ( s_name == "" ) return; name::set_name( s_name ); -#ifdef LOGGING p_logd->set_logfile( wrap::CONF->get_elem("chat.logging.roomlogdir"), get_lowercase_name() ); -#endif } #endif diff --git a/src/chat/room.h b/src/chat/room.h index 255f90e..cc59424 100755 --- a/src/chat/room.h +++ b/src/chat/room.h @@ -19,9 +19,7 @@ class room : public base, public name private: string s_topic; pthread_mutex_t mut_s_topic; -#ifdef LOGGING logd* p_logd; -#endif public: room( string s_name ); @@ -56,9 +54,7 @@ public: } void msg_post( string *p_msg ) { -#ifdef LOGGING p_logd->log_simple_line( logd::remove_html_tags(*p_msg) ); -#endif base::msg_post( p_msg ); } @@ -68,10 +64,9 @@ public: } virtual void set_name( string s_name ); - string get_topic(); - void set_topic( string s_topic ); - void set_topic( string s_topic, string s_color ); - void clean_room(); + virtual string get_topic(); + virtual void set_topic( string s_topic ); + virtual void clean_room(); diff --git a/src/chat/sess.cpp b/src/chat/sess.cpp index 801a6bf..b41c8ce 100755 --- a/src/chat/sess.cpp +++ b/src/chat/sess.cpp @@ -3,55 +3,27 @@ #include "sess.h" -sess::sess( string s_tmpid ) +sess::sess( string s_id ) { - this->p_user = NULL; - this->s_tmpid = s_tmpid; + this->sess_id=s_id; } sess::~sess() { + } string -sess::get_tmpid() +sess::get_id() { - return s_tmpid; -} - -string -sess::get_name() -{ - if ( p_user = NULL ) - return ""; - - return p_user->get_name(); -} - -void -sess::set_name(string s_name) -{ - if ( p_user != NULL ) - p_user->set_name(s_name); -} - -user* -sess::get_user() -{ - return p_user; -} - -void -sess::set_user(user* p_user) -{ - this->p_user = p_user; + return this->sess_id; } void sess::invalidate() { - this->s_tmpid = "0"; + this->sess_id = "0"; } #endif diff --git a/src/chat/sess.h b/src/chat/sess.h index 033e954..717564a 100755 --- a/src/chat/sess.h +++ b/src/chat/sess.h @@ -3,29 +3,24 @@ #ifndef SESS_H #define SESS_H +#include #include -#include "user.h" class cont; using namespace std; -class sess +class sess : public name { + private: - string s_tmpid; - user *p_user; + string sess_id; public: - sess(string s_tmpid); + sess(string s_id); ~sess(); - string get_tmpid(); - - void set_user(user* p_user); - user* get_user(); - void set_name(string s_name); - string get_name(); + string get_id(); void invalidate(); }; #endif diff --git a/src/chat/sman.cpp b/src/chat/sman.cpp index 6ae665f..464bf24 100755 --- a/src/chat/sman.cpp +++ b/src/chat/sman.cpp @@ -19,7 +19,7 @@ sman::~sman() pthread_mutex_destroy( &mut_i_session_count ); } -string sman::generate_id( int i_len ) +string sman::generate_id( int len ) { string valid_chars = wrap::CONF->get_elem("chat.session.validchars"); string s_ret = ""; @@ -27,7 +27,7 @@ string sman::generate_id( int i_len ) srand(time(0)+tool::string2int(wrap::CONF->get_elem("chat.session.kloakkey"))); int i_char; - for (int i = 0; i < i_len; i++) + for (int i = 0; i < len; i++) { i_char = rand() % 64; s_ret += valid_chars[i_char]; @@ -45,9 +45,9 @@ string sman::generate_id( int i_len ) sess *sman::create_session( ) { - string s_tmpid = generate_id( tool::string2int( wrap::CONF->get_elem( "chat.session.length" ) ) ); + string s_id = generate_id( tool::string2int( wrap::CONF->get_elem( "chat.session.length" ) ) ); - sess* p_sess = new sess( s_tmpid ); + sess* p_sess = new sess( s_id ); pthread_mutex_lock( &mut_i_session_count ); i_session_count++; @@ -56,8 +56,7 @@ sess *sman::create_session( ) #endif pthread_mutex_unlock( &mut_i_session_count ); - //???? - add_elem( p_sess, s_tmpid ); + add_elem( p_sess, s_id ); return p_sess; } diff --git a/src/chat/sman.h b/src/chat/sman.h index 20b1a76..1843aec 100755 --- a/src/chat/sman.h +++ b/src/chat/sman.h @@ -13,7 +13,7 @@ using namespace std; class sman : private smap { private: - string generate_id( int i_len ); + string generate_id( int len ); int i_session_count; pthread_mutex_t mut_i_session_count; @@ -24,10 +24,10 @@ private: public: sman(); ~sman(); - sess *get_session( string s_tmpid ); + sess *get_session( string s_id ); int get_session_count( ); sess *create_session( ); - void destroy_session( string s_tmpid ); + void destroy_session( string s_id ); #ifdef NCURSES void print_init_ncurses(); #endif diff --git a/src/chat/user.cpp b/src/chat/user.cpp index a73a909..40dbee8 100755 --- a/src/chat/user.cpp +++ b/src/chat/user.cpp @@ -97,7 +97,7 @@ user::get_colored_name() } void -user::get_data( map *p_map_data ) +user::get_data( map_string *p_map_data ) { string s_req = (*p_map_data)["!get"]; @@ -490,8 +490,6 @@ user::check_timeout( int* i_idle_timeout ) + "';"; msg_post( &s_quit ); set_online( false ); - - pthread_cond_signal( &cond_message ); } else if ( ! get_away() && i_idle_timeout[2] <= i_user_timeout ) diff --git a/src/chat/user.h b/src/chat/user.h index 4acb8f0..a88aea7 100755 --- a/src/chat/user.h +++ b/src/chat/user.h @@ -34,7 +34,7 @@ private: string s_pass; // password room* p_room; // pointer to the user's room. - map map_changed_data; // Needed to tell yChat which data to change after user is removed! + map_string map_changed_data; // Needed to tell yChat which data to change after user is removed! bool b_set_changed_data; // Only set change data if required! // Modules which are allowed to be executed by the user. @@ -72,10 +72,10 @@ private: void clean(); // gets specific data of this user und stores it in - // (*p_map)["nick"]. this method will be used + // (*p_map_string)["nick"]. this method will be used // every time data has to be got from every user of a room // or even of the system. - void get_data( map *p_map_data ); + void get_data( map_string *p_map_data ); string get_colored_name(); string get_colored_bold_name() diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index e39275a..2b110db 100755 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -16,13 +16,11 @@ cli::cli( ) cli::~cli() { } - int cli::parse_input( string s_input ) { string s_param = ""; unsigned i_pos = s_input.find_first_of(" "); - if ( i_pos != string::npos ) { s_param = s_input.substr(i_pos+1); s_input = s_input.substr(0, i_pos); @@ -31,7 +29,6 @@ cli::parse_input( string s_input ) if ( s_input.compare("help") == 0 || s_input.compare("h") == 0) { cout << CLIPRMO << "COMMAND LINE INTERFACE HELP MENU" << endl; - cout << CLIPRMO << " !command - Uses system to run a command" << endl; #ifdef DEBUG cout << CLIPRMO << " (d)ebug - Starts debug routine (cli.cpp)" << endl; #endif @@ -40,11 +37,9 @@ cli::parse_input( string s_input ) #ifdef NCURSES cout << CLIPRMO << " (ex)it - Quits CLI mode and respawns ncurses mode" << endl; #endif - cout << CLIPRMO << " (h)elp - Prints out this help!" << endl; - //<<* - cout << CLIPRMO << " (m)ysql - Runs MySQL client on yChat DB" << endl - << CLIPRMO << " (rel)oad - Reloads all modules" << endl; - //*>> + cout << CLIPRMO << " (h)elp - Prints out this help!" << endl + << CLIPRMO << " (m)ysql - Runs MySQL client on yChat DB" << endl; + cout << CLIPRMO << " (rel)oad - Reloads all modules" << endl; #ifdef EXPERIM cout << CLIPRMO << " (re)conf - Reloads configuration (EXPERIMENTAL)" << endl; #endif @@ -53,18 +48,13 @@ cli::parse_input( string s_input ) << CLIPRMO << " (set) VAR VAL - Sets configuration value VAR to VAL" << endl << CLIPRMO << " (sh)ell - Runs a system shell" << endl << CLIPRMO << " (s)hutdown - Shuts down the whole server" << endl - << CLIPRMO << " (t)ime - Prints out time and uptime" << endl; - cout << CLIPRMO << " (unl)oad - Unloads all loaded modules" << endl;//<< - cout << CLIPRMO << " (u)nset VAR - Deletes configuration value VAR" << endl + << CLIPRMO << " (t)ime - Prints out time and uptime" << endl + << CLIPRMO << " (unl)oad - Unloads all loaded modules" << endl + << CLIPRMO << " (u)nset VAR - Deltetes configuration value VAR" << endl << CLIPRMO << " (v)ersion - Prints out version" << endl; cout << CLIPRMI; } - else if( s_input.at(0) == '!' ) - { - system( s_input.substr(1).c_str() ); - cout << CLIPRMI; - } #ifdef DEBUG else if( s_input.compare("d") == 0 || s_input.compare("debug") == 0 ) { @@ -75,7 +65,6 @@ cli::parse_input( string s_input ) else if( s_input.compare("echo") == 0 || s_input.compare("e") == 0 ) { string s_val; - // Check wildcards unsigned i_pos = s_param.find("*"); if ( i_pos != string::npos ) @@ -84,13 +73,11 @@ cli::parse_input( string s_input ) vector* p_vec = wrap::CONF->get_key_vector(); sort(p_vec->begin(), p_vec->end()); vector::iterator iter; - for ( iter = p_vec->begin(); iter != p_vec->end(); iter++ ) if ( iter->find(s_param) == 0 ) s_val.append( *iter + " := " + wrap::CONF->get_elem(*iter) + "\n" + CLIPRMO ); delete p_vec; } - else { s_val = wrap::CONF->get_elem(s_param); @@ -98,41 +85,30 @@ cli::parse_input( string s_input ) if( s_val.empty() ) s_val = "Value not set"; - cout << CLIPRMO << s_val << endl; cout << CLIPRMI; } - - //<<* else if( s_input.compare("mysql") == 0 || s_input.compare("m") == 0 ) { cout << CLIPRMO << CLIMSQL << endl; - system((wrap::CONF->get_elem("chat.system.mysqlclient") + " -p -h " + wrap::CONF->get_elem("chat.database.serverhost") + " -u " + wrap::CONF->get_elem("chat.database.user") ).c_str()); - cout << CLIPRMO << CLIWELC << endl; cout << CLIPRMI; } - //*>> - #ifdef NCURSES else if( s_input.compare("exit") == 0 || s_input.compare("ex") == 0 ) { return 0; } #endif - - //<<* else if( s_input.compare("reload") == 0 || s_input.compare("rel") == 0 ) { cout << CLIPRMO; wrap::MODL->reload_modules(); cout << CLIPRMI; } - //*>> - #ifdef EXPERIM else if( s_input.compare("reconf") == 0 || s_input.compare("re") == 0 ) { @@ -140,47 +116,38 @@ cli::parse_input( string s_input ) cout << CLIPRMI; } #endif - else if( s_input.compare("rusage") == 0 || s_input.compare("r") == 0 ) { print_rusage(); cout << CLIPRMI; } - else if( s_input.compare("ru") == 0 || s_input.compare("rusageh") == 0 ) { cout << wrap::STAT->get_rusage_history( "ru_maxrss", string(CLIPRMO) + " " ); cout << CLIPRMI; } - else if( s_input.compare("set") == 0 ) { string s_varname = ""; i_pos = s_param.find_first_of(" "); - if ( i_pos != string::npos ) { s_varname = s_param.substr(0, i_pos); - if ( s_param.length() > i_pos+1 ) s_param = s_param.substr(i_pos+1); - else s_param = ""; } string s_old_val = wrap::CONF->get_elem(s_varname); - if ( !s_old_val.empty() ) { cout << CLIPRMO << "Old value: " << s_old_val << endl; wrap::CONF->del_elem(s_varname); } - wrap::CONF->add_elem(s_param, s_varname); cout << CLIPRMO << "New value: " << s_param << endl; cout << CLIPRMI; } - else if( s_input.compare("shell") == 0 || s_input.compare("sh") == 0 ) { cout << CLIPRMO << CLISHEL << endl; @@ -188,26 +155,20 @@ cli::parse_input( string s_input ) cout << CLIPRMO << CLIWELC << endl; cout << CLIPRMI; } - else if( s_input.compare("shutdown") == 0 || s_input.compare("s") == 0 ) { exit(0); } - else if( s_input.compare("t") == 0 || s_input.compare("time") == 0 ) { cout << CLIPRMO << "Time: " << wrap::TIMR->get_time() << endl << CLIPRMO << "Uptime: " << wrap::TIMR->get_uptime() << endl; cout << CLIPRMI; } - - //<<* else if( s_input.compare("unl") == 0 || s_input.compare("unload") == 0 ) { cout << CLIPRMO; wrap::MODL->unload_modules(); cout << CLIPRMI; } - //*>> - else if( s_input.compare("u") == 0 || s_input.compare("unset") == 0 ) { if (!s_param.empty()) @@ -225,13 +186,11 @@ cli::parse_input( string s_input ) cout << CLIPRMI; } } - else if( s_input.compare("v") == 0 || s_input.compare("version") == 0 ) { cout << CLIPRMO << tool::ychat_version() << " " << UNAME << endl; cout << CLIPRMI; } - else { cout << CLIPRMO << CLIHELP << "\"" << s_input << "\"" << endl; diff --git a/src/cli/cli.h b/src/cli/cli.h index cc5a5fc..2c37c17 100755 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -5,11 +5,11 @@ #include #include -#ifndef RUSAGE_SELF -#define RUSAGE_SELF 0 +#ifndef RUSAGE_SELF +#define RUSAGE_SELF 0 #endif -#ifndef RUSAGE_CHILDREN -#define RUSAGE_CHILDREN -1 +#ifndef RUSAGE_CHILDREN +#define RUSAGE_CHILDREN -1 #endif #include "../incl.h" @@ -30,7 +30,7 @@ class cli #endif { private: - int parse_input(string s_input); + int parse_input( string s_input ); public: cli( ); @@ -47,6 +47,7 @@ public: #else void start(); #endif + }; #endif diff --git a/src/conf/conf.cpp b/src/conf/conf.cpp index e54cbd4..6670f66 100755 --- a/src/conf/conf.cpp +++ b/src/conf/conf.cpp @@ -1,3 +1,5 @@ +// class conf implementation. + #ifndef CONF_CPP #define CONF_CPP @@ -17,7 +19,7 @@ conf::conf( string s_conf, map* p_start_params ) : nmap* p_vec) { //cout << p_vec->size() << ": (Value:" << p_child->Value() << ") (Type:" << p_child->Type() << ")" << endl; - if ( strcmp(p_child->Value(),"category") == 0 ) + if ( strcmp(p_child->Value(),"category") == 0) { p_vec->push_back(p_child->ToElement()->Attribute("name")); parse_xml(p_child, p_vec); p_vec->pop_back(); } - else if ( strcmp(p_child->Value(),"option") == 0 ) + else if ( strcmp(p_child->Value(),"option") == 0) { string s_option_name = ""; @@ -150,14 +152,4 @@ conf::exit_if_xml_error() const } } -//<<* -string -conf::colored_error_msg(string s_key) -{ - return "::get_elem("chat.html.errorcolor") - + "\">" + nmap::get_elem(s_key) + "
\n"; -} -//*>> - #endif diff --git a/src/conf/conf.h b/src/conf/conf.h index 3a7d0c6..7508872 100755 --- a/src/conf/conf.h +++ b/src/conf/conf.h @@ -1,7 +1,9 @@ +// class conf declaration. this class parses the server config file. + #ifndef CONF_H #define CONF_H -class conf; // Predefine for nmap.tmpl +class conf; #include "../incl.h" #include "../maps/nmap.h" @@ -16,12 +18,10 @@ private: TiXmlDocument* p_xml; void exit_if_xml_error() const; void parse_xml( TiXmlNode* p_node, vector* p_vec); - public: - conf(string s_conf, map* p_start_params); + //conf ( string s_conf ); + conf ( string s_conf, map* p_start_params ); ~conf(); - - string colored_error_msg( string s_key ); //<< }; #endif diff --git a/src/conf/lang.cpp b/src/conf/lang.cpp new file mode 100755 index 0000000..04dd13b --- /dev/null +++ b/src/conf/lang.cpp @@ -0,0 +1,67 @@ +#ifndef LANG_CPP +#define LANG_CPP + +#include +#include "lang.h" + +using namespace std; + +lang::lang( string s_lang = "en" ) : nmap::nmap(HMAPOCC), name::name( s_lang ) +{ + parse( ); // parse the config file. +} + +lang::~lang() +{} + +void +lang::parse() +{ + // wrap::system_message( CFILEOK + get_name() ); + + string filename(wrap::CONF->get_elem("LANGUAGE_DIR")); + filename.append(get_name()+".txt"); + + ifstream fs_conf( filename.c_str() ); + + if ( ! fs_conf ) + { + // wrap::system_message( CFILEOFF + get_name() ); + return; + } + + char c_buf[READBUF]; + + while( fs_conf.getline( c_buf, READBUF ) ) + { + string s_token( c_buf ); + unsigned int ui_pos = s_token.find( "#", 0 ); + + // if line is commented out: + if ( ui_pos == 0 ) + continue; + + ui_pos = s_token.find( ";", 0 ); + + // if token has not been found. + if ( ui_pos == string::npos ) + continue; + + s_token = s_token.substr( 0 , --ui_pos ); + ui_pos = s_token.find ( "\"", 0 ); + + if ( ui_pos == string::npos ) + continue; + + string s_val = s_token.substr( ui_pos+1, s_token.length() ); + string s_key = s_token.substr( 0 , --ui_pos ); + + // fill the map. + nmap::add_elem(s_val, s_key ); + } + + fs_conf.close(); + fs_conf.~ifstream(); +} + +#endif diff --git a/src/conf/lang.h b/src/conf/lang.h new file mode 100755 index 0000000..6230e2f --- /dev/null +++ b/src/conf/lang.h @@ -0,0 +1,23 @@ +#include "../incl.h" + +#ifndef LANG_H +#define LANG_H + +#include "../name.h" +#include "../maps/nmap.h" + +using namespace std; + +class lang : public nmap, name +{ +private: + +public: + // public methods: + lang ( string s_lang ); // standard constructor. + ~lang(); // standard destructor. + + virtual void parse( ); // parses the config file. +}; + +#endif diff --git a/src/configure b/src/configure index 64cc404..2e0a34a 100755 --- a/src/configure +++ b/src/configure @@ -145,7 +145,6 @@ perl -e ' print "(The environment variables have to be seperated by an :)\n"; exit(1); } - `touch ../err`; return ""; } @@ -191,16 +190,14 @@ perl -e ' my $compiler = `tail -n 1 ../g++.version`; my $version = `tail -n 2 ../g++.version | head -n 1`; my $uname = `uname -srm`; - my $compopt = join "; ", split /\n/, `cat ../g++.version`; chomp $uname; - chomp $compopt; print "Configuring for $uname...\n"; chomp $cpp; chomp $version; while () { s/^(CC=).*\n/$1$compiler/; s/^(SRCS=).*/$1$cpp/; - s/ -frepo//; # unless $version =~ /3\.4/; + s/ -frepo// unless $version =~ /3\.4/; if ( $uname !~ /Linux/i ) { print "Disabling -ldl flag...\n" if s/ -ldl//; } @@ -235,7 +232,6 @@ perl -e ' open F, ">msgs.h" or die "msgs.h: $!\n"; foreach (@msgs) { s/(UNAME)(.+)$/UNAME "$uname"/; - s/(COMPOPT)(.+)$/COMPOPT "$compopt"/; print F; } close F; @@ -243,9 +239,7 @@ perl -e ' if ( -d "mods" ) { chdir("mods"); my $cflags = "-fno-inline -fno-default-inline"; - $cflags .= " -nostdlib" - if $uname =~ /FreeBSD/i - && `uname -r` =~ /^4\./; + $cflags .= " -nostdlib" if $uname !~ /Linux/i; system("echo $cflags > cflags.add"); system("./configure"); chdir(".."); diff --git a/src/data/con.cpp b/src/data/con.cpp index 316776b..b381232 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 5c454f8..bc54341 100755 --- a/src/data/con.h +++ b/src/data/con.h @@ -4,19 +4,19 @@ #ifndef CON_H #define CON_H -#include +#include #include #include "con_base.h" using namespace std; class con : public con_base - { - public: - MYSQL* p_mysql; - con( ); - ~con( ); - }; +{ +public: + MYSQL* p_mysql; + con( ); + ~con( ); +}; #endif #endif diff --git a/src/data/con_base.cpp b/src/data/con_base.cpp index 003a376..24bbbc9 100755 --- a/src/data/con_base.cpp +++ b/src/data/con_base.cpp @@ -8,11 +8,12 @@ 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 16086db..60b12c2 100755 --- a/src/data/con_base.h +++ b/src/data/con_base.h @@ -9,11 +9,11 @@ using namespace std; class con_base : public timo - { - public: +{ +public: con_base( ); ~con_base( ); - }; +}; #endif #endif diff --git a/src/data/data.cpp b/src/data/data.cpp index 340883e..e8f309c 100644 --- a/src/data/data.cpp +++ b/src/data/data.cpp @@ -7,197 +7,194 @@ using namespace std; data::data() -{} +{ +} data::~data() -{} +{ +} -map +map_string data::select_user_data( string s_user, string s_query) { - string s_where_rule = " WHERE nick = \"" + s_user + "\""; - vector 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 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& vec_elements ) { - con* p_con = get_con(); + con* p_con = get_con(); - vec_elements = map_queries[s_query]; - string s_mysql_query = "SELECT "; - vector::iterator iter = vec_elements.begin(); + vec_elements = map_queries[s_query]; + string s_mysql_query = "SELECT "; + vector::iterator iter = vec_elements.begin(); - string s_table = *iter; - iter++; + string s_table = *iter; iter++; - while ( iter != vec_elements.end() ) - { - s_mysql_query.append( secure_query(*iter) ); - if ( ++iter != vec_elements.end() ) - s_mysql_query.append( ", " ); - } + while ( iter != vec_elements.end() ) + { + s_mysql_query.append( secure_query(*iter) ); + if ( ++iter != vec_elements.end() ) + s_mysql_query.append( ", " ); + } - s_mysql_query.append(" FROM " + s_table + s_where_rule ); - print_query( MYSQLQU + s_mysql_query ); + s_mysql_query.append(" FROM " + s_table + s_where_rule ); + print_query( MYSQLQU + s_mysql_query ); - MYSQL_RES* p_result = NULL; + MYSQL_RES* p_result = NULL; - 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 ); - } + 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; - } + 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 +map_string data::parse_result( MYSQL_RES* p_result, vector& vec_elements ) { - map map_ret; - if ( p_result != NULL ) - { - MYSQL_ROW row; - vector::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; + map_string map_ret; + if ( p_result != NULL ) + { + MYSQL_ROW row; + vector::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 insert_map ) +data::insert_user_data( string s_user, string s_query, map_string insert_map ) { - insert_query( s_query, insert_map ); + insert_query( s_query, insert_map ); } void -data::insert_query( string s_query, map map_insert ) +data::insert_query( string s_query, map_string map_insert ) { - vector vec_elements = map_queries[s_query]; - vector::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 vec_elements = map_queries[s_query]; + vector::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(" ); + } - iter = vec_elements.begin(); - iter++; + iter = vec_elements.begin(); iter++; - 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( "\"" + 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 ); + print_query( MYSQLQU + s_mysql_query ); - con* p_con = get_con(); + con* p_con = get_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) ) ); + 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 ); - return; + return; } -void -data::update_user_data( string s_user, string s_query, map update_map ) +void +data::update_user_data( string s_user, string s_query, map_string update_map ) { - vector vec_elements = map_queries[s_query]; + vector vec_elements = map_queries[s_query]; - if ( vec_elements.size() == 0 ) - return; + if ( vec_elements.size() == 0 ) + return; - vector::iterator iter = vec_elements.begin(); - vector::iterator iter_second = vec_elements.begin(); - iter_second++; + vector::iterator iter = vec_elements.begin(); + vector::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! - { - iter++; - continue; - } + while ( iter != vec_elements.end() ) + { + 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("\\"); + // 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("\\"); - } + while ( i_pos != string::npos ) + { + s_mysql_query.replace( i_pos, 1, "/" ); + i_pos = s_mysql_query.find("\\"); + } - 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; + return s_mysql_query; } #endif diff --git a/src/data/data.h b/src/data/data.h index 21c03d2..fa21763 100644 --- a/src/data/data.h +++ b/src/data/data.h @@ -10,20 +10,20 @@ 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& vec_elements ); - map parse_result( MYSQL_RES* p_result, vector& vec_elements ); - void insert_query( string s_query, map map_insert ); - string secure_query( string s_mysql_query ); - public: +{ +private: + MYSQL_RES* select_query( string s_query, string s_where_rule, vector& vec_elements ); + map_string parse_result( MYSQL_RES* p_result, vector& vec_elements ); + void insert_query( string s_query, map_string map_insert ); + string secure_query( string s_mysql_query ); +public: data( ); - ~data( ); + ~data( ); - map select_user_data( string s_user, string s_query ); - void insert_user_data( string s_user, string s_query, map insert_map ); - void update_user_data( string s_user, string s_query, map update_map ); - }; + 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 ); +}; #endif #endif diff --git a/src/data/data_base.cpp b/src/data/data_base.cpp index 2cbe070..c8bf033 100644 --- a/src/data/data_base.cpp +++ b/src/data/data_base.cpp @@ -8,94 +8,92 @@ using namespace std; data_base::data_base( ) { - pthread_mutex_init ( &mut_con, NULL ); - - vector vec_keys = *wrap::CONF->get_key_vector(); - vector::iterator iter; + pthread_mutex_init ( &mut_con, NULL ); + + vector vec_keys = *wrap::CONF->get_key_vector(); + vector::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 ) + { + vector 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 ); + } - // Reads all DATA_ elements of conf.txt! - for ( iter = vec_keys.begin(); iter != vec_keys.end(); iter++ ) + else { - if ( iter->length() > 20 - && iter->compare(0, 19, "chat.database.mysql") == 0 - && iter->find(".descr") == string::npos ) - { - vector 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; - } + 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::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") ); - 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 +map_string data_base::select_user_data( string s_user, string s_query) { - print_query( DATAQUE + s_query ); - map map_ret; - return map_ret; + print_query( DATAQUE + s_query ); + map_string map_ret; + return map_ret; } void -data_base::insert_user_data( string s_user, string s_query, map insert_map ) +data_base::insert_user_data( string s_user, string s_query, map_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 update_map ) +data_base::update_user_data( string s_user, string s_query, map_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 } @@ -103,125 +101,119 @@ 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 ); + pthread_mutex_lock( &mut_con ); - if ( empty() ) - { - wrap::system_message( DATANEW + string("(") + tool::int2string(size()+1) + ")" ); - pthread_mutex_unlock( &mut_con ); - return new 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(); - } + 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() ) + 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 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::iterator > erase_list; - for ( list::iterator iter = begin(); + pthread_mutex_lock( &mut_con ); + + list< list::iterator > erase_list; + for ( list::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::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 97ad31e..b38d978 100644 --- a/src/data/data_base.h +++ b/src/data/data_base.h @@ -11,38 +11,35 @@ using namespace std; class data_base : protected list - { - private: - pthread_mutex_t mut_con; - int i_max_con; +{ + private: + pthread_mutex_t mut_con; + int i_max_con; #ifdef NCURSES - - void print_queue_size(); + void print_queue_size(); #endif - protected: - map< string, vector > map_queries; - void print_query( string s_query ); + protected: + map< string, vector > map_queries; + void print_query( string s_query ); #ifdef DATA_PRINT_QUERIES - - virtual void print_query_( string s_query ); + virtual void print_query_( string s_query ); #endif - - con* get_con(); - void push_con( con* p_con ); - - public: - data_base(); - ~data_base(); - - void initialize_connections(); - virtual map select_user_data( string s_user, string s_query ); - virtual void insert_user_data( string s_user, string s_query, map insert_map ); - virtual void update_user_data( string s_user, string s_query, map update_map ); - void disconnect_all_connections(); - void check_data_con_timeout(); - }; + con* get_con(); + void push_con( con* p_con ); + + 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(); +}; #endif #endif diff --git a/src/glob.h b/src/glob.h index 63648f7..1ff4cbf 100755 --- a/src/glob.h +++ b/src/glob.h @@ -5,6 +5,7 @@ gmake config in the main directory! */ + #include // global variables. @@ -31,7 +32,7 @@ Should yChat get compiled with database support? Currently MyS- QL only is a supported database. */ -//#define DATABASE +#define DATABASE #ifdef DATABASE /* - CONFIG - @@ -64,7 +65,7 @@ Please specify the size of a temporary buffer. (Will be used f- or different tasks) */ -#define READBUF 2048 +#define READBUF 1024 /* - CONFIG - Please specify the maximum length of a HTTP post request. @@ -83,7 +84,7 @@ is enabled or in the server-window if yChat has been compiled without ncurses support. This option shows you all incoming requests with the client IP and port numbers. You probably want - this to be turned off if you have heavy server load. + this to be turned of if you have heavy server load. */ //#define VERBOSE @@ -94,11 +95,6 @@ */ //#define EXPERIM -/* - CONFIG - - Should yChat get compiled with logging support? -*/ -#define LOGGING - /* - CONFIG - Should yChat get compiled with ncurses support? */ @@ -183,6 +179,8 @@ using namespace std; +// some custom typedefs for datatypes which are needed often. +typedef map map_string; typedef int function( void *v_arg ); struct container diff --git a/src/html.cpp b/src/html.cpp index 3b5f6b0..1f839bb 100755 --- a/src/html.cpp +++ b/src/html.cpp @@ -27,7 +27,7 @@ html::clear_cache( ) } string -html::parse( map &map_params ) +html::parse( map_string &map_params ) { string s_file = map_params["request"]; @@ -37,10 +37,10 @@ html::parse( map &map_params ) // if not, read file. if ( ! smap::is_avail( s_file ) ) { - string s_path = get_name(); - ifstream if_templ( s_path.append( s_file ).c_str(), ios::binary ); + auto string s_path = get_name(); + auto ifstream fs_templ( s_path.append( s_file ).c_str(), ios::binary ); - if ( ! if_templ ) + if ( ! fs_templ ) { wrap::system_message( OFFFOUND + s_path ); if(map_params["request"]== wrap::CONF->get_elem( "httpd.html.notfound" )) @@ -51,17 +51,14 @@ html::parse( map &map_params ) } - char c_buf; - while( !if_templ.eof() ) + auto char c_buf; + while( !fs_templ.eof() ) { - if_templ.get( c_buf ); - s_templ += c_buf; + fs_templ.get( c_buf ); + s_templ+=c_buf; } - if ( map_params["content-type"].compare(0,5,"text/") == 0 ) - s_templ.erase(s_templ.end()-1); - - if_templ.close(); + fs_templ.close(); wrap::system_message( TECACHE + s_path ); @@ -78,7 +75,7 @@ html::parse( map &map_params ) } // find %%KEY%% token and substituate those. - unsigned pos[2]; + auto unsigned int pos[2]; pos[0] = pos[1] = 0; for(;;) @@ -95,8 +92,8 @@ html::parse( map &map_params ) break; // get key and val. - string s_key = s_templ.substr( pos[0], pos[1]-pos[0] ); - string s_val = wrap::CONF->get_elem( s_key ); + auto string s_key = s_templ.substr( pos[0], pos[1]-pos[0] ); + auto string s_val = wrap::CONF->get_elem( s_key ); // if s_val is empty use map_params. if ( s_val.empty() ) @@ -106,9 +103,9 @@ html::parse( map &map_params ) s_templ.replace( pos[0]-2, pos[1]-pos[0]+4, s_val ); // calculate the string displacement. - int i_diff = s_val.length() - ( pos[1] - pos[0] + 4); + auto int i_dif = s_val.length() - ( pos[1] - pos[0] + 4); - pos[1] += 2 + i_diff; + pos[1] += 2 + i_dif; }; @@ -117,7 +114,7 @@ html::parse( map &map_params ) //<<* void -html::online_list( user *p_user, map &map_params ) +html::online_list( user *p_user, map_string &map_params ) { // prepare user_list. string s_list; @@ -142,7 +139,6 @@ html::print_cached( int i_docs ) mvprintw( NCUR_CACHED_DOCS_X, NCUR_CACHED_DOCS_Y, "Docs: %d ", i_docs); refresh(); } - #endif #endif diff --git a/src/html.h b/src/html.h index 1bb486a..70d91d3 100755 --- a/src/html.h +++ b/src/html.h @@ -12,24 +12,27 @@ using namespace std; class html : public smap, name { +private: + public: - html( ); + // public methods. + html( ); // simple constructor. ~html( ); - // Clears the template cache so that new html templates will be read - // from hard disk. This method is needed after changeing s.t. on + // clears the template cache so that new html templates will be read + // from hard disk. this method is needed after changeing s.t. on // the html-template files. void clear_cache( ); - // Returns a parsed html-template. this method will check first if the + // returns a parsed html-template. this method will check first if the // required html-template exists inside the classes template cache. if not // then the file will be read from file and added to the cache. // afterwards the html-template will be parsed and returned. // map_params contains the client request parameters which also will be // used for string substituation. - string parse( map &map_params ); + string parse( map_string &map_params ); - void online_list( user *p_user, map &map_params ); //<< + void online_list( user *p_user, map_string &map_params ); //<< #ifdef NCURSES void print_cached( int i_docs ); #endif diff --git a/src/incl.h b/src/incl.h index e7e9413..d62a57f 100755 --- a/src/incl.h +++ b/src/incl.h @@ -1,12 +1,9 @@ -#include #include +#include #include - #include "glob.h" - #ifdef NCURSES #include #endif - #include "msgs.h" #include "wrap.h" diff --git a/src/logd.cpp b/src/logd.cpp index fd78ea2..44c42e2 100755 --- a/src/logd.cpp +++ b/src/logd.cpp @@ -1,12 +1,8 @@ - #ifndef LOGD_CPP #define LOGD_CPP -#include "logd.h" - -#ifdef LOGGING - #include +#include "logd.h" logd::logd( string s_filename, string s_log_lines ) { @@ -77,36 +73,28 @@ logd::flush() } void -logd::log_access( map request ) +logd::log_access( map_string request ) { string s_time = get_time_string(); string s_logstr = request["REMOTE_ADDR"] + " - - "+s_time+" \"" + request["QUERY_STRING"]+"\" 200 0 \""+request["request"]+"\" \""+request["User-Agent"]+"\"\n"; pthread_mutex_lock ( &mut_s_logging ); s_queue.push(s_logstr); - if ( s_queue.size() > i_lines ) flush(); - pthread_mutex_unlock( &mut_s_logging ); } void logd::log_simple_line( string s_line ) { - // Dont log empty lines! - if (s_line.empty()) - return; - string s_time = get_time_string(); string s_logstr = s_time + " " + s_line; pthread_mutex_lock ( &mut_s_logging ); s_queue.push(s_logstr); - if ( s_queue.size() > i_lines ) flush(); - pthread_mutex_unlock( &mut_s_logging ); } @@ -114,7 +102,7 @@ void logd::set_logfile( string s_path, string s_filename ) { // Remove "/" from filename! - unsigned i_pos = s_filename.find( "/" ); + unsigned int i_pos = s_filename.find( "/" ); while ( i_pos != string::npos ) { s_filename.replace( i_pos, 1, "SLASH" ); @@ -166,7 +154,4 @@ logd::set_lines( const int i_lines ) { this->i_lines = i_lines; } - -#endif - #endif diff --git a/src/logd.h b/src/logd.h index f799d21..b91efe0 100755 --- a/src/logd.h +++ b/src/logd.h @@ -1,6 +1,5 @@ #include "incl.h" -#ifdef LOGGING #ifndef LOGD_H #define LOGD_H @@ -9,6 +8,7 @@ class logd { + private: string s_logfile; queue s_queue; @@ -26,12 +26,11 @@ public: ~logd(); void set_logfile( string s_path, string s_filename ); - void log_access( map request ); + void log_access( map_string request ); void log_simple_line( string s_line ); void flush_logs(); static string remove_html_tags( string s_log ); }; -#endif -#endif +#endif diff --git a/src/main.cpp b/src/main.cpp index 26f11c9..c4330d8 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ /* * yChat++; Contact: www.yChat.org; Mail@yChat.org * Copyright (C) 2003 Paul C. Buetow, Volker Richter - * Copyright (C) 2004, 2005 Paul C. Buetow + * Copyright (C) 2004 Paul C. Buetow * ----------------------------------------------------------------- * * This program is free software; you can redistribute it and/or @@ -20,9 +20,6 @@ * */ -#ifndef MAIN_CPP -#define MAIN_CPP - #include #include #include "incl.h" @@ -42,8 +39,7 @@ parse_argc( int argc, char* argv[] ) string s_output = ""; - // Set to 1 if a config option key has to be read - // ( ./ychat -o key1 value1 -o key2 value2 ... ); + // Set to 1 if a config option key has to be read ( ./ychat -o key1 value1 -o key2 value2 ... ); bool b_conf = 0; // Will store the key of an additional option