From 5f4e214740242513c837c8a005ca23779bab1d0c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:45 +0200 Subject: tagging ychat-0.8.2 --- src/Makefile.in | 8 +-- src/chat/chat.cpp | 9 ++- src/chat/user.cpp | 87 +++++++++++++++++++++-- src/chat/user.h | 35 ++++++---- src/cli/cli.cpp | 46 ++++++++++-- src/cli/cli.h | 16 ++--- src/conf/conf.cpp | 36 ++++++++-- src/conf/conf.h | 6 +- src/configure | 154 +++++++++++++++++++++++------------------ src/contrib/README | 4 +- src/contrib/xml/README | 2 +- src/glob.h | 55 ++++++++++++--- src/html.cpp | 16 +++++ src/html.h | 2 + src/logd.cpp | 2 +- src/main.cpp | 15 ++-- src/maps/hashmap.h | 14 ++-- src/maps/nhashmap.h | 8 +-- src/maps/shashmap.h | 12 ++-- src/maps/shashmap.tmpl | 8 ++- src/modl.cpp | 149 ++++++++++++++++++++++++++++----------- src/modl.h | 30 +++++--- src/mods/commands/yc_gag.cpp | 24 ------- src/mods/commands/yc_q.cpp | 2 +- src/mods/commands/yc_ungag.cpp | 24 ------- src/monitor/dump.cpp | 38 ++++++---- src/monitor/dump.h | 31 ++++++--- src/monitor/stats.cpp | 48 +++++++++++++ src/monitor/stats.h | 13 ++++ src/msgs.h | 31 ++++++--- src/ncur/ncur.cpp | 45 ++++++++++-- src/reqp.cpp | 91 ++++++++++++++++++++++++ src/reqp.h | 1 + src/sign.cpp | 21 +++++- src/sign.h | 4 +- src/sock/sock.cpp | 75 +++++++++++++++++++- src/sock/sock.h | 15 ++-- src/time/timo.h | 2 +- src/time/timr.cpp | 21 +++++- src/tool/tool.cpp | 4 +- src/tool/tool.h | 2 +- src/wrap.cpp | 36 ++++++++++ src/wrap.h | 43 ++++++++++++ 43 files changed, 978 insertions(+), 307 deletions(-) mode change 100644 => 100755 src/mods/commands/yc_gag.cpp mode change 100644 => 100755 src/mods/commands/yc_ungag.cpp mode change 100755 => 100644 src/msgs.h (limited to 'src') diff --git a/src/Makefile.in b/src/Makefile.in index 262f3a6..0382389 100755 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -6,16 +6,16 @@ LDFLAGS=$(LIBADD) -lstdc++ LDADD=-pthread -D_THREAD_SAFE -export-dynamic -ldl INCLUDES=`cat includes.add` CFLAGS=-fno-inline -fno-default-inline -frepo -all: yhttpd +all: ychat $(SRCS): $(CC) $(INCLUDES) $(CFLAGS) -c $*.cpp infotext: @echo Compiling base -yhttpd: infotext $(OBJS) +ychat: infotext $(OBJS) $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) - @mv yhttpd ../bin + @mv ychat ../bin @echo -n "Size of linked executable: " - @du -hc ../bin/yhttpd | tail -n 1 + @du -hc ../bin/ychat | tail -n 1 clean: @echo Cleaning base obj @if test -d ../obj; then rm -Rf ../obj; fi diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp index e405472..ed8f48d 100755 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -170,7 +170,6 @@ chat::login( map &map_params ) map_params["tmpid"] = p_sess->get_tmpid(); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_has_sess( true ); - wrap::system_message("New tmpid: " + map_params["tmpid"] ); } } else // if ( p_user == NULL ) // If not in garbage create a new user! @@ -224,7 +223,6 @@ chat::login( map &map_params ) sess* p_sess = wrap::SMAN->create_session(); p_sess->set_user(p_user); map_params["tmpid"] = p_sess->get_tmpid(); - wrap::system_message("New tmpid: " + map_params["tmpid"] ); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_col1( map_params["color1"] ); p_user->set_col2( map_params["color2"] ); @@ -328,6 +326,13 @@ chat::post( user* p_user, map &map_params ) if ( i_pos == 0 ) return p_user->command( s_msg ); + if (p_user->get_is_gag()) + { + p_user->msg_post(wrap::CONF->colored_error_msg("chat.msgs.err.gagged")); + return; + } + + string_replacer(&s_msg); string s_post; diff --git a/src/chat/user.cpp b/src/chat/user.cpp index 2b76ec8..eb49f8c 100755 --- a/src/chat/user.cpp +++ b/src/chat/user.cpp @@ -25,6 +25,7 @@ user::~user() pthread_mutex_destroy( & mut_b_invisible ); pthread_mutex_destroy( & mut_b_has_sess ); pthread_mutex_destroy( & mut_b_is_reg ); + pthread_mutex_destroy( & mut_b_is_gag ); pthread_mutex_destroy( & mut_s_mess ); pthread_mutex_destroy( & mut_s_pass ); pthread_mutex_destroy( & mut_p_room ); @@ -41,11 +42,14 @@ user::~user() void user::initialize() { + time(&t_flood_time); init_strings(wrap::CONF->get_vector("chat.fields.userstrings")); init_ints(wrap::CONF->get_vector("chat.fields.userints")); init_bools(wrap::CONF->get_vector("chat.fields.userbools")); + this -> p_room = 0; this -> b_is_reg = false; + this -> b_is_gag = false; this -> b_set_changed_data = false; this -> b_away = false; this -> b_fake = false; @@ -60,6 +64,7 @@ user::initialize() pthread_mutex_init( & mut_b_invisible , NULL ); pthread_mutex_init( & mut_b_has_sess , NULL ); pthread_mutex_init( & mut_b_is_reg , NULL ); + pthread_mutex_init( & mut_b_is_gag , NULL ); pthread_mutex_init( & mut_s_mess , NULL ); pthread_mutex_init( & mut_s_pass , NULL ); pthread_mutex_init( & mut_p_room , NULL ); @@ -72,7 +77,6 @@ user::initialize() pthread_cond_init ( &cond_message, NULL); pthread_mutex_init( &mut_message , NULL); renew_timeout(); - } void @@ -181,12 +185,30 @@ user::get_is_reg( ) return b_ret; } +bool +user::get_is_gag( ) +{ + bool b_ret; + pthread_mutex_lock ( &mut_b_is_gag ); + b_ret = b_is_gag; + pthread_mutex_unlock( &mut_b_is_gag ); + return b_ret; +} + void user::set_is_reg( bool b_is_reg ) { this -> b_is_reg = b_is_reg; } +void +user::set_is_gag( bool b_is_gag ) +{ + pthread_mutex_lock ( &mut_b_is_gag ); + this -> b_is_gag = b_is_gag; + pthread_mutex_unlock( &mut_b_is_gag ); +} + void user::set_online( bool b_online ) { @@ -489,13 +511,52 @@ user::msg_post( string *p_msg ) } void -user::check_timeout( int* i_idle_timeout ) +user::post_action_msg(string s_msgkey) +{ + get_room()->msg_post(wrap::TIMR->get_time()+" "+get_colored_bold_name()+wrap::CONF->get_elem(s_msgkey)+"
\n"); +} + +void +user::renew_timeout() { - int i_user_timeout = (int) get_last_activity(); + timo::renew_timeout(); + double d_time_diff = wrap::TIMR->get_time_diff(t_flood_time); - if ( get_away() ? i_idle_timeout[1] <= i_user_timeout : i_idle_timeout[0] <= i_user_timeout ) + if (d_time_diff < static_cast(wrap::CONF->get_int("chat.floodprotection.seconds"))) { - wrap::system_message( string(TIMERTO) + "(" + get_name() + "," + tool::int2string(i_user_timeout) + ")"); + if (++i_flood_messages > static_cast(wrap::CONF->get_int("chat.floodprotection.messages"))) + { + room* p_room = get_room(); + if (p_room == 0) + { + i_flood_messages = 0; + return; + } + + wrap::system_message(CHATFLO+get_name()+","+p_room->get_name()+","+tool::int2string(i_flood_messages)+")"); + msg_post(wrap::CONF->colored_error_msg("chat.msgs.err.flooding")); + if (!get_is_gag()) + { + set_is_gag(true); + post_action_msg("chat.msgs.floodgag"); + } + } + } + + else + { + time(&t_flood_time); + i_flood_messages = 0; + } +} + +void +user::check_timeout( int* i_idle_timeout ) +{ + double d_user_timeout = get_last_activity(); + if ( get_away() ? i_idle_timeout[1] <= d_user_timeout : i_idle_timeout[0] <= d_user_timeout ) + { + wrap::system_message( string(TIMERTO) + "(" + get_name() + "," + tool::int2string((int)d_user_timeout) + ")"); string s_quit = ""; @@ -504,9 +565,9 @@ user::check_timeout( int* i_idle_timeout ) pthread_cond_signal( &cond_message ); } - else if ( ! get_away() && i_idle_timeout[2] <= i_user_timeout ) + else if ( ! get_away() && i_idle_timeout[2] <= d_user_timeout ) { - wrap::system_message( string(TIMERAT) + "(" + get_name() + "," + tool::int2string(i_user_timeout) + ")"); + wrap::system_message( string(TIMERAT) + "(" + get_name() + "," + tool::int2string((int)d_user_timeout) + ")"); string s_msg = wrap::CONF->get_elem("chat.msgs.userautoawaytimeout"); set_away( true, s_msg ); string s_msg2 = wrap::TIMR->get_time() + " " + get_colored_name()+ "" + s_msg + "
\n"; @@ -599,5 +660,17 @@ user::dumpit() ("TempID: " + get_tmpid()); } +bool +user::same_rooms(user *p_user) +{ + return p_user->get_room()->get_lowercase_name() + .compare(this->get_room()->get_lowercase_name()) == 0; +} + +string +user::make_colors(string s_msg) +{ + return "" + s_msg + ""; +} #endif diff --git a/src/chat/user.h b/src/chat/user.h index 62814b5..06310ca 100755 --- a/src/chat/user.h +++ b/src/chat/user.h @@ -23,16 +23,19 @@ private: // private members: string s_mess; // message string which has to be sent to the user. - bool b_online; // true if user is online. - bool b_has_sess; // true if user already has a session! - bool b_is_reg; // true if user is registered - bool b_away; // true if user is away. - bool b_fake; // true if user hides his status logo (does not work for guest) - bool b_invisible; // true if user hides his status logo (does not work for guest) - bool b_set_changed_data; // Only set change data if required! - - int i_status; // user's rang ( see enum rang @ globals.h ). - int i_old_status; // user's previous status. + bool b_online; // true if user is online. + bool b_has_sess; // true if user already has a session! + bool b_is_reg; // true if user is registered + bool b_is_gag; // true if user is gagged + bool b_away; // true if user is away. + bool b_fake; // true if user hides his status logo (does not work for guest) + bool b_invisible; // true if user hides his status logo (does not work for guest) + bool b_set_changed_data; // Only set change data if required! + + int i_status; // user's rang ( see enum rang @ globals.h ). + int i_old_status; // user's previous status. + int i_flood_messages; // user's message posts (needed for flood protection, does not need to be syncronized) + time_t t_flood_time; // user's time count (needed for flood protection, does not need to be syncronized) string s_tmpid; string s_agnt; // user's http user agent. @@ -55,6 +58,7 @@ private: pthread_mutex_t mut_b_invisible; pthread_mutex_t mut_b_has_sess; pthread_mutex_t mut_b_is_reg; + pthread_mutex_t mut_b_is_gag; pthread_mutex_t mut_s_pass; pthread_mutex_t mut_p_room; pthread_mutex_t mut_s_col1; @@ -94,15 +98,14 @@ public: bool get_invisible(); bool get_has_sess(); bool get_is_reg(); + bool get_is_gag(); void set_online( bool b_online ); void set_fake( bool b_fake ); void set_invisible( bool b_invisible ); void set_has_sess( bool b_has_sess ); void set_is_reg( bool b_is_reg ); - void set_changed_data_on() - { - b_set_changed_data = 1; - } + void set_is_gag( bool b_is_gag ); + void set_changed_data_on() { b_set_changed_data = 1; } bool get_away( ); string get_away_msg( ); void set_away( bool b_away, string s_away ); @@ -122,7 +125,9 @@ public: int get_status( ); void set_status( int i_status ); bool new_msgs ( ); + void post_action_msg(string s_msgkey); void check_timeout( int* i_idle_timeout ); + void renew_timeout(); // executes a command. void command( string &s_command ); @@ -142,6 +147,8 @@ public: void get_user_list( string &s_list ); void check_restore_away(); void reconf(); + bool same_rooms(user *p_user); + string make_colors(string s_msg); }; #endif diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 0adddb1..0e7b531 100755 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -31,7 +31,7 @@ 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 - << CLIPRMO << " !command - Uses system to run a command" << endl; + << CLIPRMO << " !command - Uses system to run a command" << endl; #ifdef DEBUG cout << CLIPRMO << " (d)ebug - Starts debug routine (cli.cpp)" << endl; @@ -47,17 +47,22 @@ cli::parse_input( string s_input ) #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; + //*>> #ifdef EXPERIM cout << CLIPRMO << " (re)conf - Reloads configuration (EXPERIMENTAL)" << endl; #endif cout << CLIPRMO << " (r)usage - Shows current resource usage" << endl - << CLIPRMO << " (ru)sageh - Shows resource usage history (yhttpd needs to run > 1 day)" << endl + << CLIPRMO << " (ru)sageh - Shows resource usage history (yChat needs to run > 1 day)" << endl << 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 << " (v)ersion - Prints out version" << endl; cout << CLIPRMI; @@ -110,6 +115,19 @@ cli::parse_input( string s_input ) 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 ) @@ -118,11 +136,20 @@ cli::parse_input( string s_input ) } #endif + //<<* + else if( s_input.compare("reload") == 0 || s_input.compare("rel") == 0 ) + { + cout << CLIPRMO; + wrap::MODL->reload_modules(); + cout << MODRELO << endl; + cout << CLIPRMI; + } + //*>> #ifdef EXPERIM else if( s_input.compare("reconf") == 0 || s_input.compare("re") == 0 ) { - wrap::HTTPD->reconf(); + wrap::CHAT->reconf(); cout << CLIPRMI; } #endif @@ -183,6 +210,15 @@ cli::parse_input( string s_input ) cout << CLIPRMI; } + //<<* + else if( s_input.compare("unl") == 0 || s_input.compare("unload") == 0 ) + { + cout << CLIPRMO; + wrap::MODL->unload_modules(); + cout << MODUNLO << endl; + cout << CLIPRMI; + } + //*>> else if( s_input.compare("u") == 0 || s_input.compare("unset") == 0 ) { @@ -203,7 +239,7 @@ cli::parse_input( string s_input ) } else if( s_input.compare("v") == 0 || s_input.compare("version") == 0 ) { - cout << CLIPRMO << tool::yhttpd_version() << " " << UNAME << endl; + cout << CLIPRMO << tool::ychat_version() << " " << UNAME << endl; cout << CLIPRMI; } else @@ -259,7 +295,7 @@ cli::print_rusage() } vector -cli::vectorize(string s_param) +cli::vectorize(string s_param) { vector vec_ret; unsigned i_pos; diff --git a/src/cli/cli.h b/src/cli/cli.h index 7d51e3f..8ec75cb 100755 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -30,30 +30,30 @@ using namespace std; class cli : public thro { #else -class cli +class cli { #endif private: int parse_input(string s_input); vector vectorize(string s_param); - + public: -cli( ); -~cli( ); + cli( ); + ~cli( ); #ifdef DEBUG -void debug_routine(); + void debug_routine(); #endif -void print_rusage(); + void print_rusage(); #ifndef NCURSES -void start(void* p_void); + void start(void* p_void); #else -void start(); + void start(); #endif }; diff --git a/src/conf/conf.cpp b/src/conf/conf.cpp index 5d5a535..a4a2679 100755 --- a/src/conf/conf.cpp +++ b/src/conf/conf.cpp @@ -6,11 +6,11 @@ using namespace std; -conf::conf( string s_conf, map* p_start_params ) : name::name( s_conf ) +conf::conf( string s_conf, map* p_main_loop_params ) : name::name( s_conf ) { string s_check[] = { get_name(), - string(getenv("HOME"))+string("/.yhttpd/") + get_name(), + string(getenv("HOME"))+string("/.ychat/") + get_name(), string("./etc/") + get_name(), string("/etc/") + get_name(), string(PREFIX+string("etc/")+get_name()) }; @@ -54,11 +54,11 @@ conf::conf( string s_conf, map* p_start_params ) : name::name( s_ vector vec_string; parse_xml(p_xml, &vec_string); - shashmap::add_elem_insecure(tool::yhttpd_version(), "yhttpd.version"); + shashmap::add_elem_insecure(tool::ychat_version(), "ychat.version"); - // Overrides yhttpd.conf values with command line options (yhttpd -o key1 value1 -o key2 value2 ...) + // Overrides ychat.conf values with command line options (ychat -o key1 value1 -o key2 value2 ...) map::iterator iter; - for ( iter = p_start_params->begin(); iter != p_start_params->end(); iter++ ) + for ( iter = p_main_loop_params->begin(); iter != p_main_loop_params->end(); iter++ ) { shashmap::del_elem_insecure(iter->first); shashmap::add_elem_insecure(iter->second, iter->first); @@ -161,11 +161,35 @@ conf::exit_if_xml_error() const } } +//<<* +string +conf::colored_error_msg(string s_key) +{ + return "::get_elem("chat.html.errorcolor") + + "\">" + shashmap::get_elem(s_key) + "
\n"; +} +//*>> int conf::get_int(string s_key) { - return tool::string2int(get_elem(s_key)); + return tool::string2int(get_elem(s_key)); } +vector +conf::get_vector(string s_key) +{ + vector vec_ret; + string s_val = get_elem(s_key); + + for (unsigned i_pos = s_val.find(" "); i_pos != string::npos; i_pos = s_val.find(" ")) + { + vec_ret.push_back(s_val.substr(0, i_pos)); + s_val = s_val.substr(i_pos+1); + } + + vec_ret.push_back(s_val); + return vec_ret; +} #endif diff --git a/src/conf/conf.h b/src/conf/conf.h index b385059..7dc779c 100755 --- a/src/conf/conf.h +++ b/src/conf/conf.h @@ -19,10 +19,12 @@ private: void parse_xml( TiXmlNode* p_node, vector* p_vec); public: - conf(string s_conf, map* p_start_params); + conf(string s_conf, map* p_main_loop_params); ~conf(); - int get_int(string s_key); + string colored_error_msg(string s_key); //<< + int get_int(string s_key); + vector get_vector(string s_key); }; #endif diff --git a/src/configure b/src/configure index 5577c10..43854d8 100755 --- a/src/configure +++ b/src/configure @@ -1,7 +1,7 @@ #!/bin/sh # -# The yhttpd Project (2003 - 2005) +# The yChat Project (2003 - 2005) # if ! ../scripts/checkperl.sh @@ -26,14 +26,19 @@ perl -e ' my @headers = ( "dlfcn.h", "pthread.h", + "mysql/mysql.h", #//<< Not needed for yhttpd "netinet/in.h", "time.h", "ncurses.h", + "openssl/ssl.h", "::test::ext/hash_map" ); my @libs = ( - "libncurses.so" + "libmysqlclient.so", #//<< Not needed for yhttpd + "libncurses.so", + "libssl.so", + "libcrypto.so" ); my @headerpaths = ( @@ -59,36 +64,76 @@ perl -e ' "/opt/local/lib" ); + my %dependfiles = ( + database => ["data"], + ycurses => ["curses", "ycui.cpp", "ycui.h"], + logging => ["logd.cpp", "logd.h"], + cli => ["cli"], + opnssl => ["sock/sslsock.cpp", "sock/sslsock.h"] + ); + open FILE, "glob.h" or die "glob.h: $!\n"; - while() - { - if ( /\/\/#define DATABASE/ ) - { + while() { + if ( /\/\/#define DATABASE/ ) { remove_from_array("mysql/mysql.h",\@headers); remove_from_array("libmysqlclient.so",\@libs); + mkdir "../backuped" unless -d "../backuped"; + `mv $_ ../backuped` for @{$dependfiles{database}}; + } + + elsif ( /^#define DATABASE/ && !-d "data") { + `mv ../backuped/$_ .` for @{$dependfiles{database}}; + } + + if ( /\/\/#define LOGGING/ ) { + mkdir "../backuped" unless -d "../backuped"; + `mv $_ ../backuped` for @{$dependfiles{logging}}; + } + + elsif ( /^#define LOGGING/ && !-f "logd.cpp") { + `mv ../backuped/$_ .` for @{$dependfiles{logging}}; + } + + if ( /\/\/#define CLI/ ) { + mkdir "../backuped" unless -d "../backuped"; + `mv $_ ../backuped` for @{$dependfiles{cli}}; + } + + elsif ( /^#define CLI/ && !-d "cli") { + `mv ../backuped/$_ .` for @{$dependfiles{cli}}; } - if ( /\/\/#define NCURSES/ ) - { - remove_from_array("ncurses.h",\@headers); - remove_from_array("libncurses.so",\@libs); + if ( /\/\/#define YCURSES/ ) { + for ("ncurses", "menu", "panel") { + remove_from_array("$_.h",\@headers); + remove_from_array("lib$_.so",\@libs); + } + + mkdir "../backuped" unless -d "../backuped"; + `mv $_ ../backuped` for @{$dependfiles{ycurses}}; + } + + elsif ( /^#define YCURSES/ && !-d "curses") { + `mv ../backuped/$_ .` for @{$dependfiles{ycurses}}; + } + + if ( /\/\/#define OPENSSL/ ) { + remove_from_array("openssl/ssl.h",\@headers); + remove_from_array("lib$_.so",\@libs) for ("ssl", "crypto"); } } close FILE; - if ( defined $ENV{YHTTPDHEADERPATHS} ) - { - map { print "Adding $_...\n"; - unshift @headerpaths, $_ } split /:/, $ENV{YHTTPDHEADERPATHS}; + if ( defined $ENV{YCHATHEADERPATHS} ) { + map { print "Adding $_...\n"; unshift @headerpaths, $_ } + split /:/, $ENV{YCHATHEADERPATHS}; } - if ( defined $ENV{YHTTPDLIBPATHS} ) - { - map { print "Adding $_...\n"; - unshift @libpaths, $_ } split /:/, $ENV{YHTTPDLIBPATHS}; + if ( defined $ENV{YCHATLIBPATHS} ) { + map { print "Adding $_...\n"; unshift @libpaths, $_ } + split /:/, $ENV{YCHATLIBPATHS}; } - print "Headers:\n"; my $testit = 0; @@ -103,10 +148,7 @@ perl -e ' my $incadd = &make_add("-I", \%incadd); my $libadd = &make_add("-L", \%libadd); - for ( @libs ) - { - $libadd .= "-l$_ " if s/^lib// and s/\.so$//; - } + for ( @libs ) { $libadd .= "-l$_ " if s/^lib// and s/\.so$//; } print "Incadd: $incadd\n"; print "Libadd: $libadd\n"; @@ -133,8 +175,7 @@ perl -e ' chomp $cpp; chomp $version; - while () - { + while () { s/^(CC=).*\n/$1$compiler/; s/^(SRCS=).*/$1$cpp/; s/ -frepo//; # unless $version =~ /3\.4/; @@ -148,8 +189,7 @@ perl -e ' my $args = join(" -",@ARGV); $args = "-".$args unless $args eq ""; - for my $cppfile (split / /, $cpp) - { + for my $cppfile (split / /, $cpp) { my $ofile = $cppfile; $ofile =~ s/\.cpp/\.o/; print Fout "../obj/$ofile: $cppfile\n"; @@ -158,14 +198,12 @@ perl -e ' $class =~ s/\.o//; my $text; - if ( $class =~ /contrib\/.+/ ) - { + if ( $class =~ /contrib\/.+/ ) { my $dirname = `dirname $class`; $text = "\t\@echo -n \"Contributed class $class \"\n"; } - else - { + else { $text = "\t\@echo -n \"Base class $class \"\n"; } @@ -181,16 +219,14 @@ perl -e ' unlink("msgs.h"); open F, ">msgs.h" or die "msgs.h: $!\n"; - for (@msgs) - { + for (@msgs) { s/(UNAME)(.+)$/UNAME "$uname"/; s/(COMPOPT)(.+)$/COMPOPT "$compopt"/; print F; } close F; - if ( -d "mods" ) - { + if ( -d "mods" ) { chdir("mods"); my $cflags = "-fno-inline -fno-default-inline"; @@ -201,15 +237,12 @@ perl -e ' chdir(".."); } - sub remove_from_array - { + sub remove_from_array { my $elem = shift; my $array = shift; - for ( my $i = 0; $i <= $#$array; ++$i ) - { - if ( $$array[$i] eq $elem ) - { + for ( my $i = 0; $i <= $#$array; ++$i ) { + if ( $$array[$i] eq $elem ) { splice(@$array,$i,1); last; } @@ -233,24 +266,18 @@ perl -e ' pop(@_); } - if ($print) - { + if ($print) { print "Checking for $check..."; print "\n" if $testit; } - for (@_) - { - if ( -f "$_/$check" ) - { - if ($testit) - { + for (@_) { + if ( -f "$_/$check" ) { + if ($testit) { return $_ if test_include($_, $check); return ""; - } - else - { + } else { print "OK\n"; return "" if $_ eq "/usr/lib" or $_ eq "/usr/include"; return $_; @@ -258,28 +285,25 @@ perl -e ' } } - for (@_) - { + for (@_) { next unless -d $_; opendir D, $_ or warn "$_: $!\n"; my @dir = readdir(D); closedir D; - for my $dir ( @dir ) - { + for my $dir ( @dir ) { next if $dir =~ /^\.+$/ or !-d "$_/$dir"; my $path = &check($deep-1, $check, "$_/$dir", "subsearch"); return $path if $path ne ""; } } - if ($print) - { + if ($print) { print "NOT OK\n"; print "Please make sure that you have the needed software installed!\n"; print "If you have a special path for your includes then edit src/configure!\n"; - print "Or set the environment variables YHTTPDHEADERPATHS and YHTTPDLIBPATHS.\n"; - print " Example: setenv YHTTPDHEADERPATHS \"/your/header/includes:/a/includes\"\n"; + print "Or set the environment variables YCHATHEADERPATHS and YCHATLIBPATHS.\n"; + print " Example: setenv YCHATHEADERPATHS \"/your/header/includes:/a/includes\"\n"; print "(The environment variables have to be seperated by an :)\n"; print "PS: You may use the locate and/or find command to search for files.\n"; exit(1); @@ -301,8 +325,7 @@ perl -e ' return $ret; } - sub test_include - { + sub test_include { my $shift = shift; my $check = shift; my $return = 0; @@ -313,14 +336,11 @@ perl -e ' my $cmd = "`tail -n 1 ../g++.version` -I$shift __test.cpp -o /dev/null 2>/dev/null"; system $cmd; - unless ($?) - { + unless ($?) { print "OK\n"; $return = 1; - } - else - { + } else { print "Not OK\n"; } diff --git a/src/contrib/README b/src/contrib/README index 105f25d..873f114 100644 --- a/src/contrib/README +++ b/src/contrib/README @@ -1,5 +1,5 @@ -This directory includes source code which has been included directly into yhttpd but is not -programmed by the yhttpd project explicitly which means the source code here is from extern. +This directory includes source code which has been included directly into yChat but is not +programmed by the yChat project explicitly which means the source code here is from extern. Used versions: tinyxml 2.3.2 diff --git a/src/contrib/xml/README b/src/contrib/xml/README index 7da9dfd..c03aaad 100644 --- a/src/contrib/xml/README +++ b/src/contrib/xml/README @@ -1,7 +1,7 @@ ATTENTION: This version of TinyXML has ben very little modified by -Paul C. Buetow in 2004 to fit the yhttpd project. +Paul C. Buetow in 2004 to fit the yChat project. To get the original source go to http://www.sourceforge.net/projects/tinyxml diff --git a/src/glob.h b/src/glob.h index f4b824f..7c4a761 100755 --- a/src/glob.h +++ b/src/glob.h @@ -15,16 +15,49 @@ #define true 1 #define false 0 +//<<* +/* FIRST THE YCHAT ONLY OPTIONS */ /* - CONFIG - - Should yhttpd get compiled with comand line interface support? + Should yChat get compiled with database support? Currently MyS- + QL only is a supported database. +*/ +//#define DATABASE + +#ifdef DATABASE +#define USE_MYSQL +/* - CONFIG - + Should all database queries printed out at the admin interface? + (This option wont take action if database support has not been + chosen) +*/ +#define DATA_PRINT_QUERIES +#endif + +/* - CONFIG - + Defines the amount of newlines which have to be sent to the clie- + nt's chat stream after the first log-in. It prevents a white scr- + een because of browser buffers or proxies. +*/ +#define PUSHSTR 500 + +/* AFTERWARDS THE YCHAT AND YHTTPD OPTIONS */ +//*>> + +/* - CONFIG - + Should yChat get compiled with OpenSSL support? +*/ +//#define OPENSSL + +/* - CONFIG - + Should yChat get compiled with comand line interface support? */ #define CLI /* - CONFIG - What should be the name of the config file? */ -#define CONFILE "yhttpd.conf" +#define CONFILE "ychat.conf" /* - DISABLED - Enable debugging options. @@ -34,18 +67,18 @@ /* - DISABLED - If you want to enable EXPERIMENTAL features, then set this val- ue to true. Else use false which is recommended! All experimen- - al features are marked inside of the running yhttpd! + al features are marked inside of the running yChat! */ //#define EXPERIM /* - CONFIG - - Should yhttpd get compiled with logging support? + Should yChat get compiled with logging support? */ #define LOGGING /* - CONFIG - Please enter the highest networking port which is allowed to be - used. If yhttpd is unable to create the server socket on a cert- + used. If yChat is unable to create the server socket on a cert- ain port, it will increment the port number and retries to cre- ate another socket on the incremented port number. This proced- ure will continue until MAXPORT has been reached. @@ -63,7 +96,7 @@ #define MAXLENGTH 1024 /* - CONFIG - - Should yhttpd get compiled with ncurses support? + Should yChat get compiled with ncurses support? */ #define NCURSES @@ -85,7 +118,7 @@ #define READSOCK 2048 /* - CONFIG - - In which prefix should yhttpd be installed if typing gmake inst- + In which prefix should yChat be installed if typing gmake inst- all? */ #define PREFIX "/usr/local" @@ -99,7 +132,7 @@ //#define SERVMSG /* - CONFIG - - Set to true if you want yhttpd to catch the SIGSEGV signal. yhttpd + Set to true if you want yChat to catch the SIGSEGV signal. yChat will print a warning message into the system messages and will not core dump if an error occurs. */ @@ -108,7 +141,7 @@ /* - CONFIG - Please chose if you want to use verbose server outputs or not. The verbose messages will appear in the ncurses menu if ncurses - is enabled or in the server-window if yhttpd has been compiled + 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. @@ -141,8 +174,8 @@ #define NCUR_CON_QUEUE_X 23 #define NCUR_CON_QUEUE_Y 35 -#define NCUR_HTTPD_HEADER_X 21 -#define NCUR_HTTPD_HEADER_Y 52 +#define NCUR_CHAT_HEADER_X 21 +#define NCUR_CHAT_HEADER_Y 52 #define NCUR_NUM_ROOMS_X 22 #define NCUR_NUM_ROOMS_Y 52 #define NCUR_SESSION_X 23 diff --git a/src/html.cpp b/src/html.cpp index ace041a..3f47867 100755 --- a/src/html.cpp +++ b/src/html.cpp @@ -115,6 +115,22 @@ html::parse( map &map_params ) return s_templ; } +//<<* +void +html::online_list( user *p_user, map &map_params ) +{ + // prepare user_list. + string s_list; + + room* p_room = p_user->get_room(); + + p_room->get_user_list( s_list ); + + map_params["room"] = p_room->get_name(); + map_params["topic"] = p_room->get_topic(); + map_params["userlist"] = s_list; +} +//*>> #ifdef NCURSES void diff --git a/src/html.h b/src/html.h index 14a7161..7ec3c76 100755 --- a/src/html.h +++ b/src/html.h @@ -5,6 +5,7 @@ #define HTML_H #include "maps/shashmap.h" +#include "chat/user.h" #include "name.h" using namespace std; @@ -28,6 +29,7 @@ public: // used for string substituation. string parse( map &map_params ); + void online_list( user *p_user, map &map_params ); //<< #ifdef NCURSES void print_cached( int i_docs ); diff --git a/src/logd.cpp b/src/logd.cpp index e120fd8..664cd14 100755 --- a/src/logd.cpp +++ b/src/logd.cpp @@ -81,7 +81,7 @@ logd::flush() void logd::log_access( map &map_request ) { - //static int i_access_lines = wrap::CONF->get_elem("httpd.logging.accesslines"); + //static int i_access_lines = wrap::CONF->get_elem("httpd.logging.access_lines"); string s_time = get_time_string(); string s_logstr = map_request["REMOTE_ADDR"] + " - - "+s_time+" \"" + map_request["QUERY_STRING"]+"\" 200 0 \""+map_request["request"]+"\" \""+map_request["User-Agent"]+"\"\n"; diff --git a/src/main.cpp b/src/main.cpp index 87f1cab..a9f9170 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ /* - * yhttpd; Contact: www.yChat.org; Mail@yChat.org + * yChat; Contact: www.yChat.org; Mail@yChat.org * Copyright (C) 2003 Paul C. Buetow, Volker Richter * Copyright (C) 2004 Paul C. Buetow * Copyright (C) 2005 EXA Digital Solutions GbR @@ -37,7 +37,7 @@ parse_argc( int argc, char* argv[] ) string s_output = ""; // Set to 1 if a config option key has to be read - // ( ./yhttpd -o key1 value1 -o key2 value2 ... ); + // ( ./ychat -o key1 value1 -o key2 value2 ... ); bool b_conf = 0; // Will store the key of an additional option value (see also b_conf) @@ -58,7 +58,7 @@ parse_argc( int argc, char* argv[] ) else { if ( string(argv[i]).find("v") != string::npos ) - s_output.append(tool::yhttpd_version()+"\n"); + s_output.append(tool::ychat_version()+"\n"); if ( string(argv[i]).find("h") != string::npos ) s_output.append( YCUSAGE ); @@ -81,7 +81,7 @@ parse_argc( int argc, char* argv[] ) int main(int argc, char* argv[]) { - cout << tool::yhttpd_version() << endl + cout << tool::ychat_version() << endl << DESCRIP << endl << DESCRI2 << endl << CONTACT << endl @@ -89,6 +89,13 @@ main(int argc, char* argv[]) wrap::init_wrapper(parse_argc(argc, argv)); + //<<* + // Initialize database connection queue +#ifdef DATABASE + + wrap::DATA->init_connections(); +#endif + //*>> sign::init_signal_handlers(); diff --git a/src/maps/hashmap.h b/src/maps/hashmap.h index 1bdc515..b3a3212 100644 --- a/src/maps/hashmap.h +++ b/src/maps/hashmap.h @@ -6,13 +6,13 @@ using namespace std; template -struct compare_allocator +struct compare_allocator { inline bool operator()(key_type_ t_key_1, key_type_ t_key_2) const; }; template -struct equals_allocator +struct equals_allocator { inline bool operator()(key_type_ t_key_1, key_type_ t_key_2) const; }; @@ -31,10 +31,10 @@ struct self_hash template < - class obj_type, - class key_type_ = string, - class hash_type = size_hash, - class alloc_type = compare_allocator +class obj_type, +class key_type_ = string, +class hash_type = size_hash, +class alloc_type = compare_allocator > struct hashmap : public __gnu_cxx::hash_map { @@ -42,7 +42,7 @@ struct hashmap : public __gnu_cxx::hash_map* get_key_vector(); virtual inline bool exists(key_type_ t_key); virtual inline void run_func( void (*func)(obj_type) ); diff --git a/src/maps/nhashmap.h b/src/maps/nhashmap.h index 7f17a55..f440230 100644 --- a/src/maps/nhashmap.h +++ b/src/maps/nhashmap.h @@ -7,10 +7,10 @@ using namespace std; template < - class obj_type, - class key_type_ = string, - class hash_type = size_hash, - class alloc_type = compare_allocator +class obj_type, +class key_type_ = string, +class hash_type = size_hash, +class alloc_type = compare_allocator > struct nhashmap : public shashmap { diff --git a/src/maps/shashmap.h b/src/maps/shashmap.h index 99dd7c8..f692e32 100644 --- a/src/maps/shashmap.h +++ b/src/maps/shashmap.h @@ -10,13 +10,13 @@ using namespace std; template < - class obj_type, - class key_type_ = string, - class hash_type = size_hash, - class alloc_type = compare_allocator +class obj_type, +class key_type_ = string, +class hash_type = size_hash, +class alloc_type = compare_allocator > class shashmap : protected hashmap, - public dumpable + public dumpable { private: pthread_mutex_t mut_shashmap; @@ -30,7 +30,7 @@ public: virtual inline void set_elem(obj_type t_obj, key_type_ t_key); virtual inline obj_type get_set_elem(obj_type t_obj, key_type_ t_key); virtual inline obj_type get_or_callback_set - (obj_type (*func)(void*), void* p_void, key_type_ t_key); + (obj_type (*func)(void*), void* p_void, key_type_ t_key); virtual inline void add_elem(obj_type t_obj, key_type_ t_key); virtual inline void add_elem_insecure(obj_type t_obj, key_type_ t_key); virtual inline obj_type get_elem(key_type_ t_key); diff --git a/src/maps/shashmap.tmpl b/src/maps/shashmap.tmpl index c864d28..0bd5796 100644 --- a/src/maps/shashmap.tmpl +++ b/src/maps/shashmap.tmpl @@ -43,7 +43,7 @@ shashmap::get_or_callback_set { pthread_mutex_lock( &mut_shashmap ); obj_type t_ret = hashmap::get_or_callback_set - (func, p_void, t_key); + (func, p_void, t_key); pthread_mutex_unlock( &mut_shashmap ); return t_ret; } @@ -144,12 +144,14 @@ template void shashmap::dumpit() { - dumpable::add("[shashmap]"); + dumpable::add + ("[shashmap]"); vector* p_vec = get_key_vector(); typename vector::iterator iter; for (iter = p_vec->begin(); iter != p_vec->end(); ++iter) - dumpable::add(*iter); + dumpable::add + (*iter); delete p_vec; } diff --git a/src/modl.cpp b/src/modl.cpp index dc6770b..32fe33a 100755 --- a/src/modl.cpp +++ b/src/modl.cpp @@ -1,59 +1,85 @@ -// class modl implementation. - -#ifndef MODL_CXX -#define MODL_CXX +#ifndef MODL_CPP +#define MODL_CPP #include #include #include #include -#include "s_mutx.h" #include "modl.h" +#include "tool/dir.h" using namespace std; -modl::modl( ) +modl::modl() { - map_mods = new hmap(80); - pthread_mutex_init( &mut_map_mods, NULL ); +#ifdef NCURSES + print_cached( 0 ); +#endif + + if ( wrap::CONF->get_elem( "httpd.modules.preloadcommands" ).compare( "true" ) == 0 ) + preload_modules( wrap::CONF->get_elem("httpd.modules.commandsdir") ); + + if ( wrap::CONF->get_elem( "httpd.modules.preloadhtml" ).compare( "true" ) == 0 ) + preload_modules( wrap::CONF->get_elem("httpd.modules.htmldir") ); } modl::~modl() { - pthread_mutex_lock ( &mut_map_mods ); - // dlclose all the_module's first! - map_mods->run_func ( &modl::dlclose_ ); + run_func( &modl::dlclose_ ); // then clean the hash map. - map_mods->make_empty ( ); + unload_modules(); +} - pthread_mutex_unlock ( &mut_map_mods ); - pthread_mutex_destroy( &mut_map_mods ); +void +modl::preload_modules( string s_path ) +{ + dir* p_dir = new dir(); + p_dir->open_dir( s_path ); + + p_dir->read_dir(); + + vector dir_vec = p_dir->get_dir_vec(); + + if ( ! dir_vec.empty() ) + { + vector::iterator iter = dir_vec.begin(); + + do + { + if ( iter->length() >= 3 && iter->compare( iter->length()-3, 3, ".so" ) == 0 ) + cache_module( s_path + *iter, false ); + } + while ( ++iter != dir_vec.end() ); + } + + dir_vec.clear(); + + // This also closes the dir. + delete p_dir; } void modl::dlclose_( dynmod* mod ) { dlclose( mod->the_module ); + free ( mod ); } dynmod* -modl::cache_module( string s_name ) +modl::cache_module( string s_name, bool b_print_sys_msg ) { void *the_module = NULL; function *the_func = NULL; - the_module = dlopen( s_name.c_str(), RTLD_NOW ); + the_module = dlopen( s_name.c_str(), RTLD_LAZY ); + //the_module = dlopen( s_name.c_str(), RTLD_NOW ); if ( the_module == NULL ) { - pthread_mutex_lock ( &s_mutx::get - ().mut_stdout ); - cerr << "dlerror: " << dlerror() << endl; - pthread_mutex_unlock( &s_mutx::get - ().mut_stdout ); + wrap::system_message( dlerror() ); return NULL; } @@ -61,44 +87,85 @@ modl::cache_module( string s_name ) if ( the_func == NULL ) { - pthread_mutex_lock ( &s_mutx::get - ().mut_stdout ); - cerr << "dlerror: " << dlerror() << endl; - pthread_mutex_unlock( &s_mutx::get - ().mut_stdout ); + wrap::system_message( dlerror() ); return NULL; } -#ifdef VERBOSE - pthread_mutex_lock ( &s_mutx::get - ().mut_stdout ); - cout << MODULEC << s_name << endl; - pthread_mutex_unlock( &s_mutx::get - ().mut_stdout ); -#endif + if ( b_print_sys_msg ) + wrap::system_message( MODULEC + s_name.substr( s_name.find_last_of("/")+1 ) ); dynmod *mod = new dynmod; // encapsulates the function and module handler. mod->the_func = the_func ; // the function to execute mod->the_module = the_module; // the module handler to close if function + // is not needed anymore. - pthread_mutex_lock ( &mut_map_mods ); - map_mods->add_elem ( mod, s_name ); - pthread_mutex_unlock( &mut_map_mods ); + add_elem( mod, s_name ); // DO NOT CLOSE AS LONG THERE EXIST A POINTER TO THE FUNCTION - // dlclose( module ); + // dlclose( module ); will be called in modl::~modl()! + +#ifdef NCURSES + + print_cached( size() ); +#endif return mod; } +dynmod* +modl::get_module( string s_name, string s_user ) +{ + wrap::system_message( MODULER + s_name.substr( s_name.find_last_of("/")+1 ) + " (" + s_user + ")"); + dynmod* mod = get_elem( s_name ); + return ! mod ? cache_module( s_name, true ) : mod; +} + dynmod* modl::get_module( string s_name ) { - pthread_mutex_lock ( &mut_map_mods ); - dynmod* mod = map_mods->get_elem( s_name ); - pthread_mutex_unlock( &mut_map_mods ); + wrap::system_message( MODULER + s_name.substr( s_name.find_last_of("/")+1 ) ); + dynmod* mod = get_elem( s_name ); + return ! mod ? cache_module( s_name, true ) : mod; +} + +void +modl::unload_modules() +{ + wrap::system_message( MODUNLO ); + + // dlclose all the_module's first! + run_func( &modl::dlclose_ ); + + // then clean the hash map. + shashmap::clear(); + +#ifdef NCURSES + + print_cached( size() ); +#endif - return ! mod ? cache_module( s_name ) : mod; } +void +modl::reload_modules() +{ + unload_modules(); + + wrap::system_message( MODRELO ); + preload_modules( wrap::CONF->get_elem("httpd.modules.commandsdir") ); + preload_modules( wrap::CONF->get_elem("httpd.modules.htmldir") ); +} + +#ifdef NCURSES +void +modl::print_cached( int i_mods ) +{ + if ( !wrap::NCUR->is_ready() ) + return; + + mvprintw( NCUR_CACHED_MODS_X, NCUR_CACHED_MODS_Y, "Mods: %d ", i_mods); + refresh(); +} +#endif + #endif diff --git a/src/modl.h b/src/modl.h index b496120..73abd58 100755 --- a/src/modl.h +++ b/src/modl.h @@ -1,29 +1,39 @@ -// class modl declaration. +#include "incl.h" #ifndef MODL_H #define MODL_H -#include "incl.h" -#include "hmap.h" +#include "maps/shashmap.h" using namespace std; - -class modl +class modl : public shashmap { private: - hmap* map_mods; - pthread_mutex_t mut_map_mods; - static void dlclose_( dynmod* mod ); - dynmod* cache_module ( string s_name ); + dynmod* cache_module ( string s_name, bool b_print_sys_msg ); + void preload_modules( string s_path ); + +#ifdef NCURSES + + void print_cached( int i_mods ); +#endif public: modl(); ~modl(); - dynmod* get_module ( string s_name ); + dynmod* get_module( string s_name ); + dynmod* get_module( string s_name, string s_user ); + + vector* get_mod_vector() + { + vector* p_ret = get_key_vector(); + return p_ret; + } + void unload_modules(); + void reload_modules(); }; #endif diff --git a/src/mods/commands/yc_gag.cpp b/src/mods/commands/yc_gag.cpp old mode 100644 new mode 100755 index e58a22d..2da03f6 --- a/src/mods/commands/yc_gag.cpp +++ b/src/mods/commands/yc_gag.cpp @@ -1,27 +1,3 @@ -/*:* - *: File: ./src/mods/commands/yc_gag.cpp - *: - *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT - *: - *: 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 "../../chat/user.h" #include "../../chat/room.h" /* diff --git a/src/mods/commands/yc_q.cpp b/src/mods/commands/yc_q.cpp index 1df6156..a250f72 100755 --- a/src/mods/commands/yc_q.cpp +++ b/src/mods/commands/yc_q.cpp @@ -17,7 +17,7 @@ extern "C" conf* p_conf = (conf*) ((dynamic_wrap*)c->elem[3])->CONF; - string s_quit = ""; diff --git a/src/mods/commands/yc_ungag.cpp b/src/mods/commands/yc_ungag.cpp old mode 100644 new mode 100755 index 6d8c03c..b727be2 --- a/src/mods/commands/yc_ungag.cpp +++ b/src/mods/commands/yc_ungag.cpp @@ -1,27 +1,3 @@ -/*:* - *: File: ./src/mods/commands/yc_ungag.cpp - *: - *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT - *: - *: 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 "../../chat/user.h" #include "../../chat/room.h" /* diff --git a/src/monitor/dump.cpp b/src/monitor/dump.cpp index 6b49bfe..71cc862 100644 --- a/src/monitor/dump.cpp +++ b/src/monitor/dump.cpp @@ -8,13 +8,13 @@ using namespace std; const string dumpable::s_sep = "->"; const int dumpable::i_max_level = 100; -dumpable::dumpable() +dumpable::dumpable() { initialize(0); } void -dumpable::initialize(int i_level) +dumpable::initialize(int i_level) { this->i_level = i_level; this->i_lined = i_level; @@ -24,13 +24,13 @@ dumpable::initialize(int i_level) } string -dumpable::dump() +dumpable::dump() { return dump(0); } string -dumpable::dump(int i_level) +dumpable::dump(int i_level) { initialize(i_level); dumpit(); @@ -38,34 +38,37 @@ dumpable::dump(int i_level) } void -dumpable::add(string s_line) +dumpable::add + (string s_line) { if ( i_lined > i_max_level ) i_lined = i_max_level; - if (!b_lined) + if (!b_lined) s_dump.append(s_sep); - else for ( int i = 0; i < i_lined; ++i ) - s_dump.append(" "); + else + for ( int i = 0; i < i_lined; ++i ) + s_dump.append(" "); s_dump.append(s_line); - if (b_next_no_nl) + if (b_next_no_nl) b_next_no_nl = false; else s_dump.append("\n"); - if (!b_lined) { + if (!b_lined) + { b_lined = true; i_lined = i_level + s_sep.length(); } } int -dumpable::get_level() const -{ +dumpable::get_level() const +{ return i_lined; } @@ -74,6 +77,7 @@ dump::dump(vector vec_params) if (vec_params.empty()) { cout << CLIPRMO << "all conf sock"; + cout << " chat modl sman"; //<< Not for yhttpd cout << endl; return; } @@ -98,6 +102,16 @@ dump::run(vector &vec_params) if (!s_part.compare("sock") || !s_part.compare("all")) s_ret.append(wrap::SOCK->dump()); + //<<* + if (!s_part.compare("modl") || !s_part.compare("all")) + s_ret.append(wrap::MODL->dump()); + + if (!s_part.compare("sman") || !s_part.compare("all")) + s_ret.append(wrap::SMAN->dump()); + + if (!s_part.compare("chat") || !s_part.compare("all")) + s_ret.append(wrap::CHAT->dump()); + //*>> } return s_ret; diff --git a/src/monitor/dump.h b/src/monitor/dump.h index 8e84cb1..ffb3529 100644 --- a/src/monitor/dump.h +++ b/src/monitor/dump.h @@ -15,24 +15,35 @@ private: string s_dump; static const string s_sep; - static const int i_max_level; + static const int i_max_level; virtual void dumpit() = 0; void initialize(int i_level); void reset(); protected: - void add(unsigned i_num) - { add(""); } - - void add(int i_num) - { add(""); } - - void add(string s_line); + void add + (unsigned i_num) + { + add + (""); + } + + void add + (int i_num) + { + add + (""); + } + + void add + (string s_line); dumpable(); - void next_no_newline() - { b_next_no_nl = true; } + void next_no_newline() + { + b_next_no_nl = true; + } public: string dump(); diff --git a/src/monitor/stats.cpp b/src/monitor/stats.cpp index e0aa146..5d5cc39 100644 --- a/src/monitor/stats.cpp +++ b/src/monitor/stats.cpp @@ -10,14 +10,17 @@ stats::stats() i_rusage_vec_size = tool::string2int( wrap::CONF->get_elem("httpd.stats.rusagehistory")); + i_num_rooms = 0; //<< pthread_mutex_init( &mut_vec_rusage, NULL ); + pthread_mutex_init( &mut_num_rooms, NULL ); //<< } stats::~stats() { pthread_mutex_destroy( &mut_vec_rusage ); + pthread_mutex_destroy( &mut_num_rooms ); //<< } void @@ -98,5 +101,50 @@ stats::get_rusage_history( string s_type, string s_seperator ) return s_ret; } +//<<* +int +stats::get_num_rooms() +{ + pthread_mutex_lock ( &mut_num_rooms ); + int i_ret = i_num_rooms; + pthread_mutex_unlock( &mut_num_rooms ); + return i_ret; +} + +void +stats::increment_num_rooms() +{ + pthread_mutex_lock ( &mut_num_rooms ); + ++i_num_rooms; + pthread_mutex_unlock( &mut_num_rooms ); +#ifdef NCURSES + + print_num_rooms(); +#endif +} +void +stats::decrement_num_rooms() +{ + pthread_mutex_lock ( &mut_num_rooms ); + --i_num_rooms; + pthread_mutex_unlock( &mut_num_rooms ); +#ifdef NCURSES + + print_num_rooms(); +#endif +} + +#ifdef NCURSES +void +stats::print_num_rooms() +{ + if ( !wrap::NCUR->is_ready() ) + return; + + mvprintw( NCUR_NUM_ROOMS_X, NCUR_NUM_ROOMS_Y, "Rooms: %d", get_num_rooms()); + refresh(); +} +#endif +//*>> #endif diff --git a/src/monitor/stats.h b/src/monitor/stats.h index 0478258..231d876 100644 --- a/src/monitor/stats.h +++ b/src/monitor/stats.h @@ -21,6 +21,8 @@ private: vector< map > vec_rusage_history; pthread_mutex_t mut_vec_rusage; + int i_num_rooms; //<< + pthread_mutex_t mut_num_rooms; //<< void set_rusage_vec_size( int i_rusage_vec_size ); @@ -28,9 +30,20 @@ public: stats( ); ~stats( ); + //<<* + int get_num_rooms(); + void increment_num_rooms(); + void decrement_num_rooms(); + //*>> void update_rusage_history(); string get_rusage_history( string s_type, string s_seperator ); long get_ru_maxrss(); + //<<* +#ifdef NCURSES + + void print_num_rooms(); +#endif + //*>> }; #endif diff --git a/src/msgs.h b/src/msgs.h old mode 100755 new mode 100644 index b317366..031debe --- a/src/msgs.h +++ b/src/msgs.h @@ -4,8 +4,9 @@ // alphabetical ordered: #define ACCPERR "Sock: Accept error " #define BINDERR "Sock: Bind error " -#define HTTPDREP "Chat: Using replacement strings" -#define HTTPDDOP "Chat: Default operator login " +#define CHATREP "Chat: Using replacement strings" +#define CHATDOP "Chat: Default operator login " +#define CHATFLO "Chat: Flooding (" #define CFILEOK "Parsing config file" #define CFILEFA "Failed opening config file!" #define CONTACT "Contact: http://www.yChat.org, Mail@yChat.org, ICQ: 11655527" @@ -93,17 +94,24 @@ #define STATUPR "Stats: Updated rusage history" #define STATRSS "Stats: Max resident set size " #define REUROOM "Garbage: Reusing room object " -#define SOCKER1 "Sock: Can't create socket, aborting" -#define SOCKUNS "Sock: Starting hypertext transport [HTTP]" #define SOCKCLN "Sock: Initializing a client socket at " #define SOCKCON "Sock: Connecting to " #define SOCKCRT "Sock: Created socket on " #define SOCKSRV "Sock: Initializing server socket " #define SOCKERR "Sock: Can't create socket, trying next port " +#define SOCKER1 "Sock: Can't create socket, aborting" #define SOCKER2 "Sock: Unknown hostname " #define SOCKRDY "Sock: Server socket is ready " #define SOCKCAC "Sock: Caching IP " #define SOCKCA2 "Sock: Cleaning IP cache (" +#define SOCKUNS "Sock: Starting unsecure transport [HTTP]" +#ifdef OPENSSL +#define SSLERR1 "SSL: Can't create socket" +#define SSLERR2 "SSL: Private key does not match cert. file" +#define SSLERR3 "SSL: Can't create new SSL context" +#define SSLERR4 "SSL: Can't create new SSL socket via accept" +#define SOCKSEC "SSL: Starting secure transport [HTTPS]" +#endif #define TECACHE "HTML: Caching document " #define THRDSTR "Thread: Running" #define TIMERAT "Timer: User autoaway timeout " @@ -115,16 +123,16 @@ #define XMLREAD "XML: Reading " #define XMLERR "XML Error: " #define XMLER1 "XML Error: Unable to load file " -#define VERSION "0.7.2" +#define VERSION "0.8.2" #define BRANCH "RELEASE" -#define BUILDNR 3807 -#define UNAME "FreeBSD 5.4-DEVEL i386" -#define COMPOPT "Using built-in specs.; Configured with: FreeBSD/i386 system compiler; Thread model: posix; gcc version 3.4 [FreeBSD] 20040728; 3.4; g++" -#define YCUSAGE "Usage: ./yhttpd {h|v}|{o confkey confvalue}\n" +#define BUILDNR 4003 +#define UNAME "FreeBSD 5.4-RELEASE-p3 i386" +#define COMPOPT "Using built-in specs.; Configured with: FreeBSD/i386 system compiler; Thread model: posix; gcc version 3.4.2 [FreeBSD] 20040728; 3.4; g++" +#define YCUSAGE "Usage: ./ychat {h|v}|{o confkey confvalue}\n" #define HEADER1 "HTTP/1.1 200 OK\r\n" -#define HEADER2 "Server: yhttpd/" VERSION "-" BRANCH "\r\n" -#define HEADER3 "Cache-control: no-cache\r\n" +#define HEADER2 "Server: yChat/" VERSION "-" BRANCH "\r\n" +#define HEADER3 "Cache-Control: no-cache\r\n" #define HEADER4 "Pragma: no-cache\r\n" #define HEADER5 "Transfer-Encoding: chunked\r\n" #define HEADER6 "Connection: keep-alive\r\n" @@ -132,5 +140,6 @@ #define HEADER8 "Content-Type: "; #define HEADER8b "; charset=ISO-8859-1\r\n"; #define HEADER9 "Allow: GET\r\n"; +//#define MEMBERE "Memb: No such member " #endif diff --git a/src/ncur/ncur.cpp b/src/ncur/ncur.cpp index 3518bbd..3200ee0 100755 --- a/src/ncur/ncur.cpp +++ b/src/ncur/ncur.cpp @@ -38,16 +38,26 @@ ncur::start( void *p_void ) ncur::init_ncurses(); char *choices[] = { - " ", - " ", + "Unload all modules ", //<< + "Reload all modules ", //<< + //>>" ", + //>>" ", "Clear template cache ", - " ", + "Run garbage collector ", //<< + //>>" ", "Show max res. set size ", "Compile changed sources ", "Recompile all sources ", "Show source stats ", "Command line interface ", - " ", + //<<* +#ifdef DATABASE + "Close DB connections ", +#else + " ", +#endif + //*>> + //>>" ", "Shut down server" }; @@ -58,18 +68,23 @@ ncur::start( void *p_void ) mvwprintw( p_serveroutput, 2, 2, NCURMSG ); wrefresh ( p_serveroutput ); - print( string("yhttpd ") + VERSION ); + print( string("yChat ") + VERSION ); p_menu = new menu( 1, 1, 30, 19, NCURADM, choices, 11, COLOR_PAIR(1)); mvprintw(NCUR_SERVER_HEADER_X,NCUR_SERVER_HEADER_Y, NCURSE0); mvprintw(NCUR_POOL_HEADER_X,NCUR_POOL_HEADER_Y, NCURSE1); + mvprintw(NCUR_DATA_HEADER_X,NCUR_DATA_HEADER_Y, NCURSE2); //<< + mvprintw(NCUR_CHAT_HEADER_X,NCUR_CHAT_HEADER_Y, NCURSE3); //<< mvprintw(NCUR_CACHED_HEADER_X,NCUR_CACHED_HEADER_Y, NCURSE4); wrap::HTML->print_cached(0); is_ready(true); + wrap::SMAN->print_init_ncurses(); //<< + wrap::STAT->print_num_rooms(); //<< + wrap::SOCK->print_server_port(); p_menu->start( &switch_main_menu_ ); @@ -150,12 +165,29 @@ ncur::switch_main_menu_( int i_choice ) if( i_choice != 0 ) switch ( i_choice ) { + //<<* + case 1: + wrap::MODL->unload_modules(); + mvprintw( 20,2, "Unloaded all modules "); + refresh(); + break; + case 2: + wrap::MODL->reload_modules(); + mvprintw( 20,2, "Reloaded all modules "); + refresh(); + break; + //*>> case 3: wrap::HTML->clear_cache(); mvprintw( 20,2, "Cleared the template cache "); refresh(); break; case 4: + //<<* + if ( ! wrap::GCOL->remove_garbage() ) + wrap::NCUR->print( GAROFFNE ); + mvprintw( 20,2, "Garbage collector activated "); + //*>> refresh(); break; case 5: @@ -197,6 +229,7 @@ ncur::switch_main_menu_( int i_choice ) case 10: #ifdef DATABASE + wrap::DATA->disconnect_all_connections(); //<< #endif break; @@ -222,7 +255,7 @@ ncur::init_ncurses() noecho(); cbreak(); // Line buffering disabled. pass on everything init_pair(1, COLOR_BLACK, COLOR_CYAN); - mvprintw( 0,2, (char*)(tool::yhttpd_version()).c_str()); + mvprintw( 0,2, (char*)(tool::ychat_version()).c_str()); curs_set(0); refresh(); } diff --git a/src/reqp.cpp b/src/reqp.cpp index df9de5d..9b5da0b 100755 --- a/src/reqp.cpp +++ b/src/reqp.cpp @@ -237,6 +237,77 @@ reqp::parse( socketcontainer *p_sock, string s_req, map &map_para string s_rep( "" ); + //<<* + // check the event variable. + if ( ! s_event.empty() ) + { + // login procedure. + if ( s_event == "login" ) + { + wrap::CHAT->login( map_params ); + } + else if ( s_event == "register" ) + { + user* p_user = new user; + map_params["INFO"] = ""; + run_html_mod( s_event, map_params, p_user ); + wrap::GCOL->add_user_to_garbage( p_user ); + } + else + { + sess *p_sess = wrap::SMAN->get_session( map_params["tmpid"] ); + user *p_user = NULL; + + if( p_sess != NULL ) + { + p_user = p_sess->get_user(); + } + else + { + wrap::system_message(SESSERR); + return s_rep; + } + + if ( ! p_user ) + { + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.notonline" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + } + else + { + map_params["nick"] = p_user->get_name().c_str(); + + // if a message input. + if ( s_event == "input" ) + { + if ( p_user ) + { + p_user->check_restore_away(); + wrap::CHAT->post( p_user, map_params ); + } + } + + // if a chat stream + else if ( s_event == "stream" ) + { + string s_msg ( wrap::HTML->parse( map_params ) ); + p_user->msg_post( &s_msg); + wrap::SOCK->chat_stream( p_sock, p_user, map_params ); + } + + // if a request for the online list of the active room. + else if ( s_event == "online" ) + { + wrap::HTML->online_list( p_user, map_params ); + } + else //if ( s_event != "input" ) + { + run_html_mod( s_event, map_params, p_user ); + } + } + } + } + //*>> if ( wrap::CONF->get_elem("httpd.enablecgi").compare("true") == 0 && string::npos != map_params["request"].find(".cgi") ) @@ -269,6 +340,26 @@ reqp::parse( socketcontainer *p_sock, string s_req, map &map_para return s_resp; } +//<<* +void +reqp::run_html_mod( string s_event, map &map_params, user* p_user ) +{ + container *c = new container; + + c->elem[0] = (void*) wrap::WRAP; + c->elem[1] = (void*) &map_params; + c->elem[2] = (void*) p_user; + + string s_mod = wrap::CONF->get_elem("httpd.modules.htmldir") + "yc_" + s_event + ".so"; + + dynmod* p_module = wrap::MODL->get_module( s_mod, p_user->get_name() ); + + if ( p_module != NULL ) + ( *( p_module->the_func ) ) ( static_cast(c) ); + + delete c; +} +//*>> string reqp::remove_dots( string s_ret ) diff --git a/src/reqp.h b/src/reqp.h index 93e32e4..5a378fa 100755 --- a/src/reqp.h +++ b/src/reqp.h @@ -24,6 +24,7 @@ private: string get_from_header( string s_req, string s_hdr ); int htoi( string *p_str ); + void run_html_mod( string s_event, map &map_params, user* p_user ); //<< // Removes double dots ".." string remove_dots( string s_req ); diff --git a/src/sign.cpp b/src/sign.cpp index ad3e02a..584b5f7 100644 --- a/src/sign.cpp +++ b/src/sign.cpp @@ -9,6 +9,13 @@ sign::clean_template_cache(int i_param) wrap::HTML->clear_cache(); } +//<<* +void +sign::reload_dlopen_modules(int i_param) +{ + wrap::MODL->reload_modules(); +} +//*>> #ifdef CTCSEGV void @@ -23,10 +30,19 @@ sign::terminate_received(int i_param) { #ifdef NCURSES + //<<* + if ( ! wrap::GCOL->remove_garbage() ) + wrap::NCUR->print( GAROFFNE ); + //*>> mvprintw( 21,2, "Good bye !"); wrap::NCUR->close_ncurses(); + //<<* +#else + + wrap::GCOL->remove_garbage(); + //*>> #endif exit(0); @@ -40,9 +56,12 @@ sign::init_signal_handlers() signal(SIGPIPE, SIG_IGN); signal(SIGUSR1, clean_template_cache); + signal(SIGUSR2, reload_dlopen_modules); //<< #ifdef CTCSEGV - signal(SIGSEGV, sigsev_received); + + signal(SIGSEGV, sigsev_received); #endif + signal(SIGHUP, terminate_received); signal(SIGINT, terminate_received); signal(SIGTERM, terminate_received); diff --git a/src/sign.h b/src/sign.h index b11bf75..0f909b3 100644 --- a/src/sign.h +++ b/src/sign.h @@ -7,8 +7,10 @@ class sign { private: - static void clean_template_cache(int i_param); + static void clean_template_cache(int i_param); + static void reload_dlopen_modules(int i_param); //<< #ifdef CTCSEGV + static void sigsev_received(int i_param); #endif diff --git a/src/sock/sock.cpp b/src/sock/sock.cpp index b73b78f..9d673ef 100755 --- a/src/sock/sock.cpp +++ b/src/sock/sock.cpp @@ -45,6 +45,64 @@ sock::_close(socketcontainer *p_sock) delete p_sock; } +//<<* +void +sock::chat_stream( socketcontainer *p_sock, user *p_user, map &map_params ) +{ + string s_msg( "\n" ); + + for ( int i = 0; i < PUSHSTR; i++ ) + _send(p_sock,s_msg.c_str(), s_msg.size()); + + pthread_mutex_t mutex; + pthread_mutex_init( &mutex, NULL ); + pthread_mutex_lock( &mutex ); + + do + { + s_msg = p_user->get_mess( ); + + if ( 0 > _send( p_sock, s_msg.c_str(), s_msg.size() ) ) + { + p_user->set_online( false ); + break; + } + + pthread_cond_wait( &(p_user->cond_message), &mutex ); + } + while( p_user->get_online() ); + + pthread_mutex_destroy( &mutex ); + + // if there is still a message to send: + s_msg = p_user->get_mess( ); + + if ( ! s_msg.empty() ) + _send( p_sock, s_msg.c_str(), s_msg.size()); + + // remove the user from its room. + string s_user( p_user->get_name() ); + string s_user_lowercase( p_user->get_lowercase_name() ); + + p_user->get_room()->del_elem( s_user_lowercase ); + + // post the room that the user has left the chat. + s_msg = wrap::TIMR->get_time() + " " + + p_user->get_colored_bold_name() + + wrap::CONF->get_elem( "chat.msgs.userleaveschat" ) + + "
\n"; + + p_user->get_room()->msg_post( &s_msg ); + p_user->get_room()->reload_onlineframe(); + +#ifdef VERBOSE + + cout << REMUSER << s_user << endl; +#endif + + wrap::GCOL->add_user_to_garbage( p_user ); +} +//*>> int sock::_make_server_socket( int i_port ) @@ -331,6 +389,15 @@ sock::_main_loop_init() wrap::system_message(SOCKUNS); } +#ifdef OPENSSL +// This method is virtual, and is overloaded by sslsock! +bool +sock::_main_loop_do_ssl_stuff(int &i_new_sock) +{ + return 0; +} +#endif + socketcontainer* sock::_create_container(int &i_sock) { @@ -372,8 +439,6 @@ sock::start() FD_ZERO (&active_fd_set); FD_SET (i_sock, &active_fd_set); - print_server_port(); - while( b_run ) { // block until input arrives on one or more active sockets. @@ -403,6 +468,12 @@ sock::start() size = sizeof(clientname); i_new_sock = accept (i_sock, (struct sockaddr *) &clientname, &size); +#ifdef OPENSSL + + if (_main_loop_do_ssl_stuff(i_new_sock)) + continue; +#endif + #ifdef VERBOSE wrap::system_message(NEWREQU diff --git a/src/sock/sock.h b/src/sock/sock.h index 65fe756..264d9d1 100755 --- a/src/sock/sock.h +++ b/src/sock/sock.h @@ -11,6 +11,7 @@ #include #include "../reqp.h" +#include "../chat/user.h" #include "../thrd/pool.h" #include "../maps/shashmap.h" @@ -70,11 +71,17 @@ public: void clean_ipcache(); // the chat stream there all the chat messages will sent through. - virtual inline int _send(socketcontainer *p_sock, const char *sz, int len); - virtual inline int _read(socketcontainer *p_sock, char *sz, int len); - virtual inline int _close(socketcontainer *p_sock); + void chat_stream( socketcontainer* p_sock, user* p_user, map &map_params ); //<< + virtual int _send(socketcontainer *p_sock, const char *sz, int len); + virtual int _read(socketcontainer *p_sock, char *sz, int len); + virtual int _close(socketcontainer *p_sock); virtual void _main_loop_init(); - virtual inline socketcontainer* _create_container(int& i_sock); +#ifdef OPENSSL + + virtual bool _main_loop_do_ssl_stuff(int& i_new_sock); +#endif + + virtual socketcontainer* _create_container(int& i_sock); virtual int _make_server_socket(int i_port); #ifdef NCURSES diff --git a/src/time/timo.h b/src/time/timo.h index 32268df..ea160c1 100755 --- a/src/time/timo.h +++ b/src/time/timo.h @@ -16,7 +16,7 @@ public: ~timo( ); double get_last_activity(); - void renew_timeout(); + virtual void renew_timeout(); }; #endif diff --git a/src/time/timr.cpp b/src/time/timr.cpp index 6a95984..9e1522f 100755 --- a/src/time/timr.cpp +++ b/src/time/timr.cpp @@ -71,7 +71,7 @@ timr::start( void *v_ptr ) time_now = *localtime( &clock_now ); - // set the current time && the current yhttpd uptime! + // set the current time && the current ychat uptime! set_time( difftime( clock_now, clock_start ), time_now.tm_sec, time_now.tm_min, time_now.tm_hour ); @@ -87,14 +87,31 @@ timr::start( void *v_ptr ) #ifdef SERVMSG cout << TIMERUP << get_uptime() << endl; #endif + //<<* + int* p_timeout_settings = new int[3]; + p_timeout_settings[0] = tool::string2int(wrap::CONF->get_elem("chat.idle.timeout")); + p_timeout_settings[1] = tool::string2int(wrap::CONF->get_elem("chat.idle.awaytimeout")); + p_timeout_settings[2] = tool::string2int(wrap::CONF->get_elem("chat.idle.autoawaytimeout")); + wrap::CHAT->check_timeout( p_timeout_settings ); + delete p_timeout_settings; + + string s_ping = "\n"; + wrap::CHAT->msg_post( &s_ping ); + +#ifdef DATABASE + // Disconnecting idle database conenction + wrap::DATA->check_data_con_timeout(); +#endif + //*>> // Run every ten minutes: if ( time_now.tm_min % 10 == 0 ) { - wrap::SOCK->clean_ipcache(); + wrap::SOCK->clean_ipcache(); // Run every hour if ( time_now.tm_min % 60 == 0 ) { + wrap::GCOL->remove_garbage(); //<< // Run every day if (time_now.tm_min == 0 || time_now.tm_min == 60 ) diff --git a/src/tool/tool.cpp b/src/tool/tool.cpp index dbb1f22..3b8e326 100644 --- a/src/tool/tool.cpp +++ b/src/tool/tool.cpp @@ -93,9 +93,9 @@ tool::strip_html( string *p_str) } string -tool::yhttpd_version() +tool::ychat_version() { - return "yhttpd " + string(VERSION) + return "yChat " + string(VERSION) + "-" + string(BRANCH) + " Build " + int2string(BUILDNR); } diff --git a/src/tool/tool.h b/src/tool/tool.h index 7a1958d..e0dea50 100644 --- a/src/tool/tool.h +++ b/src/tool/tool.h @@ -23,7 +23,7 @@ public: static string to_lower( string s_str ); static void strip_html( string *p_str ); static string shell_command( string s_command, method m_method ); - static string yhttpd_version(); + static string ychat_version(); }; #endif diff --git a/src/wrap.cpp b/src/wrap.cpp index e6fb851..e071cc9 100755 --- a/src/wrap.cpp +++ b/src/wrap.cpp @@ -5,6 +5,15 @@ using namespace std; +//<<* +chat* wrap::CHAT = NULL; +#ifdef DATABASE +data* wrap::DATA = NULL; +#endif +gcol* wrap::GCOL = NULL; +sman* wrap::SMAN = NULL; +modl* wrap::MODL = NULL; +//*>> conf* wrap::CONF = NULL; html* wrap::HTML = NULL; @@ -67,10 +76,20 @@ wrap::init_wrapper(map* p_main_loop_params) CONF->get_elem("httpd.logging.systemlines") ); #endif + //<<* + // Init the session manager. + WRAP->SMAN = SMAN = new sman; + //*>> // Init the socket manager. int i_port = tool::string2int( wrap::CONF->get_elem( "httpd.serverport" ) ); +#ifndef OPENSSL + WRAP->SOCK = SOCK = new sock; +#else + + WRAP->SOCK = SOCK = new sslsock; +#endif // create the server socket and set it up to accept connections. if(SOCK->_make_server_socket ( i_port ) <= 0) @@ -103,10 +122,27 @@ wrap::init_wrapper(map* p_main_loop_params) // Init the thread pool WRAP->POOL = POOL = new pool; + //<<* + // Init the chat manager. + WRAP->CHAT = CHAT = new chat; + //*>> // Init the system timer. WRAP->TIMR = TIMR = new timr; + //<<* + // Init the module-loader manager. + WRAP->MODL = MODL = new modl; + + // Init the garbage collector + WRAP->GCOL = GCOL = new gcol; + + // Init the data manager. +#ifdef DATABASE + + WRAP->DATA = DATA = new data; +#endif + //*>> // Run threads TIMR->run(); diff --git a/src/wrap.h b/src/wrap.h index 23d2aa3..4b0da6f 100755 --- a/src/wrap.h +++ b/src/wrap.h @@ -7,15 +7,25 @@ struct socketcontainer { int i_sock; +#ifdef OPENSSL + void *p_ssl_context; +#endif + }; #ifdef DATABASE +#include "data/data.h" #endif +#include "chat/chat.h" #include "conf/conf.h" +#include "chat/gcol.h" #include "html.h" #ifdef LOGGING #include "logd.h" #endif +//<<* +#include "modl.h" +//*>> #ifdef NCURSES #include "ncur/ncur.h" @@ -25,8 +35,14 @@ struct socketcontainer #endif #endif +#include "chat/sman.h" +#ifndef OPENSSL #include "sock/sock.h" +#else +#include "sock/sslsock.h" +#endif + #include "monitor/stats.h" #include "time/timr.h" #include "thrd/pool.h" @@ -38,6 +54,17 @@ using namespace std; class dynamic_wrap { public: + //<<* + chat* CHAT; +#ifdef DATABASE + + data* DATA; +#endif + + gcol* GCOL; + sman* SMAN; + modl* MODL; + //*>> conf* CONF; html* HTML; @@ -73,6 +100,22 @@ public: static void init_wrapper(map* p_main_loop_params); + //<<* + static chat* CHAT; +#ifdef DATABASE + + static data* DATA; +#endif + + static gcol* GCOL; + static sman* SMAN; +#ifdef IRCBOT + + static ybot* YBOT; +#endif + + static modl* MODL; + //*>> static conf* CONF; static html* HTML; -- cgit v1.2.3