diff options
Diffstat (limited to 'src')
42 files changed, 325 insertions, 156 deletions
diff --git a/src/chat/base.h b/src/chat/base.h index 9da4304..b995c5c 100755 --- a/src/chat/base.h +++ b/src/chat/base.h @@ -9,6 +9,9 @@ template<class type> class base : public nhashmap<type*> { +protected: + void dumpit(); + public: base(); ~base(); @@ -22,6 +25,7 @@ public: } virtual type* get_elem( string s_name, bool &b_found ); // get a element. + virtual type* get_elem( string s_name ); virtual void add_elem( type* p_type ); // add a element. // chat::msg_post sends to all users of the system a message. diff --git a/src/chat/base.tmpl b/src/chat/base.tmpl index 0be21aa..5b0fceb 100755 --- a/src/chat/base.tmpl +++ b/src/chat/base.tmpl @@ -22,10 +22,40 @@ base<type>::get_elem( string s_name, bool &b_found ) } template<class type> +type* +base<type>::get_elem( string s_name) +{ + bool b; + return get_elem(s_name, b); +} + +template<class type> void base<type>::add_elem( type* p_type ) { nhashmap<type*>::add_elem(p_type, p_type->get_lowercase_name()); } +template<class type> +void +base<type>::dumpit() +{ + dumpable::add("[base]"); + vector<string>* p_vec = nhashmap<type*>::get_key_vector(); + + vector<string>::iterator iter; + for (iter = p_vec->begin(); iter != p_vec->end(); ++iter) + { + dumpable::add(*iter); + type* p_elem = get_elem(*iter); + if (p_elem) + { + dumpable::next_no_newline(); + dumpable::add(p_elem->dump(dumpable::get_level())); + } + } + + delete p_vec; +} + #endif diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp index 0839261..e4cbaac 100755 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -165,7 +165,6 @@ chat::login( map<string,string> &map_params ) else { 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_user->set_tmpid( map_params["tmpid"] ); @@ -361,4 +360,11 @@ chat::string_replacer(string *p_msg) } } +void +chat::dumpit() +{ + dumpable::add("[chat]"); + base<room>::dumpit(); +} + #endif diff --git a/src/chat/chat.h b/src/chat/chat.h index 47645c3..bb087d5 100755 --- a/src/chat/chat.h +++ b/src/chat/chat.h @@ -23,6 +23,7 @@ class chat : public base<room>, public perm private: map<string,string> map_replace_strings; vector<string> vec_replace_keys; + void dumpit(); public: virtual room* get_room( string s_name ) diff --git a/src/chat/gcol.cpp b/src/chat/gcol.cpp index 7df111d..d4c9416 100755 --- a/src/chat/gcol.cpp +++ b/src/chat/gcol.cpp @@ -44,6 +44,8 @@ gcol::add_user_to_garbage( user* p_user ) p_user->s_mess_delete(); p_map_users->add_elem( p_user, tool::to_lower(p_user->get_name()) ); wrap::system_message( GARUSER + p_user->get_name() ); + p_user->destroy_session(); + #ifdef NCURSES print_garbage(); diff --git a/src/chat/room.cpp b/src/chat/room.cpp index b927d40..0e28c84 100755 --- a/src/chat/room.cpp +++ b/src/chat/room.cpp @@ -101,4 +101,14 @@ room::set_name( string s_name ) #endif } +void +room::dumpit() +{ + dumpable::add("[room]"); + dumpable::add("Name: "+get_name()); + dumpable::add("Topic: "+get_topic()); + base<user>::dumpit(); +} + + #endif diff --git a/src/chat/room.h b/src/chat/room.h index 06b0a9a..4c5fac6 100755 --- a/src/chat/room.h +++ b/src/chat/room.h @@ -23,6 +23,8 @@ private: logd* p_logd; #endif + + void dumpit(); public: room( string s_name ); diff --git a/src/chat/sman.cpp b/src/chat/sman.cpp index d80d421..530aa17 100755 --- a/src/chat/sman.cpp +++ b/src/chat/sman.cpp @@ -21,23 +21,33 @@ sman::~sman() string sman::generate_id( int i_len ) { - string valid_chars = wrap::CONF->get_elem("chat.session.validchars"); + string s_valid = wrap::CONF->get_elem("chat.session.validchars"); string s_ret = ""; srand(time(0)+tool::string2int(wrap::CONF->get_elem("chat.session.kloakkey"))); int i_char; + for (int i = 0; i < i_len; i++) { - i_char = rand() % 64; - s_ret += valid_chars[i_char]; + i_char = rand() % s_valid.length(); + s_ret += s_valid[i_char]; } if ( wrap::CONF->get_elem("chat.session.md5hash") == "true" ) { string s_salt = wrap::CONF->get_elem("chat.session.md5salt"); - s_ret = string(md5::MD5Crypt(s_ret.c_str(), s_salt.c_str())); - return s_ret.substr(s_ret.find(s_salt) + s_salt.length() + 3); + string s_hash(md5::MD5Crypt(s_ret.c_str(), s_salt.c_str())); + s_ret.append(s_hash.substr(s_ret.find(s_salt) + s_salt.length() + 3)); + } + + // Prove, if the TempID already exists + sess* p_sess = get_elem(s_ret); + + if (p_sess) + { + wrap::system_message(SESSEXI); + return generate_id(i_len); } return s_ret; diff --git a/src/chat/sman.h b/src/chat/sman.h index 992fc64..13fc45a 100755 --- a/src/chat/sman.h +++ b/src/chat/sman.h @@ -7,10 +7,11 @@ #include "sess.h" #include "../maps/shashmap.h" +#include "../monitor/dump.h" using namespace std; -class sman : private shashmap<sess*> +class sman : public shashmap<sess*> { private: string generate_id( int i_len ); diff --git a/src/chat/user.cpp b/src/chat/user.cpp index 4f1646b..bac8b7e 100755 --- a/src/chat/user.cpp +++ b/src/chat/user.cpp @@ -73,23 +73,27 @@ user::initialize() void user::clean() { + destroy_session(); + set_fake( false ); + set_invisible( false ); + set_away( false, "" ); +} + +void +user::destroy_session() +{ + if ( !get_has_sess() ) + return; - // If this user has a session - if ( get_has_sess() ) - { #ifdef DATABASE - // Store all changed data into the mysql table if this user is registered: - if ( b_is_reg ) - wrap::DATA->update_user_data( get_name(), "savechangednick", map_changed_data ); + // Store all changed data into the mysql table if this user is registered: + if ( b_is_reg ) + wrap::DATA->update_user_data( get_name(), "savechangednick", map_changed_data ); #endif - wrap::SMAN->destroy_session( get_tmpid() ); - // wrap::system_message( SESSION + tool::int2string( wrap::SMAN->get_session_count() ) ); - } - - set_fake( false ); - set_invisible( false ); - set_away( false, "" ); + set_has_sess(false); + wrap::SMAN->destroy_session(get_tmpid()); + set_tmpid(""); } string @@ -411,7 +415,7 @@ user::command( string &s_command ) string s_command2 = s_command.substr(0, pos2-1); s_mod.append( s_command2 ).append( ".so" ); - dynmod *mod = wrap::MODL->get_module( s_mod ); + dynmod *mod = wrap::MODL->get_module( s_mod, get_name() ); if ( mod == NULL || wrap::CHAT->get_command_disabled( s_command2 ) || @@ -577,4 +581,15 @@ void user::reconf() {} +void +user::dumpit() +{ + dumpable::add("[user]"); + dumpable::add("Name: " + get_name() + + "; Room: " + get_room()->get_name() + + "; Status: " + tool::int2string(get_status())); + dumpable::add("TempID: " + get_tmpid()); +} + + #endif diff --git a/src/chat/user.h b/src/chat/user.h index 443eef6..1d16695 100755 --- a/src/chat/user.h +++ b/src/chat/user.h @@ -5,13 +5,14 @@ #include "../name.h" #include "../time/timo.h" +#include "../monitor/dump.h" //#include "../memb/memb.h" class room; using namespace std; -class user : public name, public timo//, public memb<string> +class user : public name, public timo, public dumpable //, public memb<string> { private: @@ -56,7 +57,8 @@ private: pthread_mutex_t mut_map_changed_data; void initialize(); - void set_changed_data( string s_varname, string s_value ); + void set_changed_data( string s_varname, string s_value ); + void dumpit(); public: pthread_cond_t cond_message; @@ -67,6 +69,7 @@ public: ~user(); void clean(); + void destroy_session(); // gets specific data of this user und stores it in // (*p_map<string,string>)["nick"]. this method will be used diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 96a0010..cc0f5e5 100755 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -37,6 +37,8 @@ cli::parse_input( string s_input ) cout << CLIPRMO << " (d)ebug - Starts debug routine (cli.cpp)" << endl; #endif + cout << CLIPRMO << " (du)mp [part] - Prints out a dump of the data structure" << endl; + cout << CLIPRMO << " (Run without part to list all possibilities)" << endl; cout << CLIPRMO << " (e)cho VAR - Prints out configuration value of VAR" << endl; cout << CLIPRMO << " Wildcards can be used too, example: echo http*" << endl; #ifdef NCURSES @@ -78,6 +80,11 @@ cli::parse_input( string s_input ) cout << CLIPRMI; } #endif + else if ( s_input.compare("du") == 0 || s_input.compare("dump") == 0 ) + { + dump d(vectorize(s_param)); + cout << CLIPRMI; + } else if( s_input.compare("echo") == 0 || s_input.compare("e") == 0 ) { string s_val; @@ -134,6 +141,7 @@ cli::parse_input( string s_input ) { cout << CLIPRMO; wrap::MODL->reload_modules(); + cout << MODRELO << endl; cout << CLIPRMI; } //*>> @@ -207,6 +215,7 @@ cli::parse_input( string s_input ) { cout << CLIPRMO; wrap::MODL->unload_modules(); + cout << MODUNLO << endl; cout << CLIPRMI; } //*>> @@ -285,6 +294,26 @@ cli::print_rusage() delete p_rusage; } +vector<string> +cli::vectorize(string s_param) +{ + vector<string> vec_ret; + unsigned i_pos; + + for (i_pos = s_param.find(" "); + i_pos != string::npos; + i_pos = s_param.find(" ")) + { + vec_ret.push_back(s_param.substr(0, i_pos)); + s_param = s_param.substr(i_pos+1); + } + + if (!s_param.empty()) + vec_ret.push_back(s_param); + + return vec_ret; +} + #ifdef DEBUG void cli::debug_routine() diff --git a/src/cli/cli.h b/src/cli/cli.h index 23e1d1c..7d51e3f 100755 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -22,6 +22,8 @@ #include "../thrd/thro.h" #endif +#include "../monitor/dump.h" + using namespace std; #ifndef NCURSES @@ -32,8 +34,9 @@ class cli { #endif private: - int parse_input(string s_input); - + int parse_input(string s_input); + vector<string> vectorize(string s_param); + public: cli( ); ~cli( ); @@ -52,7 +55,6 @@ void start(void* p_void); void start(); #endif - }; #endif diff --git a/src/conf/conf.cpp b/src/conf/conf.cpp index 2e5893b..38c29c4 100755 --- a/src/conf/conf.cpp +++ b/src/conf/conf.cpp @@ -36,6 +36,7 @@ conf::conf( string s_conf, map<string,string>* p_start_params ) : name::name( s_ cout << CFILEFA << endl; exit(1); } + else { cout << CFILEOK << "..." << endl; @@ -76,12 +77,18 @@ conf::parse_xml(TiXmlNode* p_node, vector<string>* 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(),"config") == 0 ) + { + parse_xml(p_child, p_vec); + } + + else 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 ) { string s_option_name = ""; diff --git a/src/configure b/src/configure index eb54cce..973e85a 100755 --- a/src/configure +++ b/src/configure @@ -156,15 +156,17 @@ perl -e ' $ofile =~ s/\.cpp/\.o/; print Fout "../obj/$ofile: $cppfile\n"; print Fout "\t\@if ! test -d `dirname ../obj/$ofile`; then mkdir -p `dirname ../obj/$ofile`; fi\n"; - if ( $ofile =~ /contrib\/.+/ ) + my $class = $ofile; + $class =~ s/\.o//; + if ( $class =~ /contrib\/.+/ ) { - my $dirname = `dirname $ofile`; - print Fout "\t\@echo -n \"Compiling contributed class $ofile \"\n"; + my $dirname = `dirname $class`; + print Fout "\t\@echo -n \"Compiling contributed class $class \"\n"; } else { - print Fout "\t\@echo -n \"Compiling base class $ofile \"\n"; + print Fout "\t\@echo -n \"Compiling base class $class \"\n"; } print Fout "\t\@\$(CC) \$(CFLAGS) \$(INCLUDES) $args -c -o ../obj/$ofile $cppfile\n"; diff --git a/src/data/data_base.cpp b/src/data/data_base.cpp index 05f4e0a..8150608 100644 --- a/src/data/data_base.cpp +++ b/src/data/data_base.cpp @@ -47,7 +47,7 @@ data_base::data_base( ) } } -void data_base::initialize_connections() +void data_base::init_connections() { int i_min_con = tool::string2int( wrap::CONF->get_elem("chat.database.mincon") ), i_max_con = tool::string2int( wrap::CONF->get_elem("chat.database.maxcon") ); diff --git a/src/data/data_base.h b/src/data/data_base.h index 1da5ce7..79f5630 100644 --- a/src/data/data_base.h +++ b/src/data/data_base.h @@ -36,7 +36,7 @@ public: data_base(); ~data_base(); - void initialize_connections(); + void init_connections(); virtual hashmap<string> select_user_data( string s_user, string s_query ); virtual void insert_user_data( string s_user, string s_query, hashmap<string> insert_map ); virtual void update_user_data( string s_user, string s_query, hashmap<string> update_map ); @@ -83,7 +83,7 @@ /* - CONFIG - Should yChat get compiled with ncurses support? */ -//#define NCURSES +#define NCURSES /* - CONFIG - Please specify the maximum length of a HTTP post request. @@ -121,7 +121,7 @@ will print a warning message into the system messages and will not core dump if an error occurs. */ -#define CTCSEGV +//#define CTCSEGV /* - CONFIG - Please chose if you want to use verbose server outputs or not. diff --git a/src/html.cpp b/src/html.cpp index 4160f60..3f47867 100755 --- a/src/html.cpp +++ b/src/html.cpp @@ -43,12 +43,11 @@ html::parse( map<string,string> &map_params ) if ( ! if_templ ) { wrap::system_message( OFFFOUND + s_path ); - if(map_params["request"]== wrap::CONF->get_elem( "httpd.html.notfound" )) + if(map_params["request"] == wrap::CONF->get_elem( "httpd.html.notfound" )) return ""; map_params["request"] = wrap::CONF->get_elem( "httpd.html.notfound" ); return parse( map_params ); - } char c_buf; diff --git a/src/main.cpp b/src/main.cpp index ffe5484..c0adb5e 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,11 +23,6 @@ #include "incl.h" #include "sign.h" -#ifndef NCURSES -#ifdef CLI -#include "cli/cli.h" -#endif -#endif #include "maps/hashmap.h" @@ -85,98 +80,18 @@ parse_argc( int argc, char* argv[] ) int main(int argc, char* argv[]) { - map<string,string>* p_start_params = parse_argc( argc, argv ); - cout << tool::ychat_version() << endl << DESCRIP << endl << DESCRI2 << endl << CONTACT << endl << SEPERAT << endl; - - // All the static data classes have to be initialized once. otherwise they will - // contain only empty pointers and the chat server won't work correctly. - // the order of the initializations is very importand. for example the s_html::init() - // invokations assumes an initialized conf class. - - // Init the dynamic wrapper (is needed to pass all wrapped objects through a single pointer). - wrap::WRAP = new dynamic_wrap; - - // Init the config manager. - wrap::WRAP->CONF = wrap::CONF = new conf( CONFILE, p_start_params ); - delete p_start_params, - - // Init the statistic manager. - wrap::WRAP->STAT = wrap::STAT = new stats; - - // Init the html-template manager. - wrap::WRAP->HTML = wrap::HTML = new html; - -#ifdef LOGGING - // Init the system message logd - wrap::WRAP->LOGD = wrap::LOGD = new logd( wrap::CONF->get_elem("httpd.logging.systemfile"), - wrap::CONF->get_elem("httpd.logging.systemlines") ); -#endif - //<<* - // Init the session manager. - wrap::WRAP->SMAN = wrap::SMAN = new sman; - //*>> - - -#ifdef NCURSES - - wrap::WRAP->NCUR = wrap::NCUR = new ncur; // init the ncurses admin interface. - wrap::NCUR->run(); // run the thread - - // Wait until ncurses interface has been initialized. - do { - usleep(1000); - } while ( ! wrap::NCUR->is_ready() ); - - wrap::HTML->print_cached(0); -#endif - - // Init the thread pool - wrap::WRAP->POOL = wrap::POOL = new pool; - // Init the socket manager. - wrap::WRAP->SOCK = wrap::SOCK = new sock; - - //<<* - // Init the chat manager. - wrap::WRAP->CHAT = wrap::CHAT = new chat; - //*>> - - // Init the system timer. - wrap::WRAP->TIMR = wrap::TIMR = new timr; - wrap::TIMR->run(); // run the thread - - //<<* - // Init the module-loader manager. - wrap::WRAP->MODL = wrap::MODL = new modl; - - // Init the garbage collector - wrap::WRAP->GCOL = wrap::GCOL = new gcol; - - // Init the data manager. -#ifdef DATABASE - - wrap::WRAP->DATA = wrap::DATA = new data; -#endif - //*>> - -#ifndef NCURSES -#ifdef CLI - - cli* p_cli = new cli; - p_cli->run(); -#endif -#endif + wrap::init_wrapper(parse_argc(argc, argv)); //<<* // Initialize database connection queue #ifdef DATABASE - - wrap::DATA->initialize_connections(); + wrap::DATA->init_connections(); #endif //*>> diff --git a/src/maps/shashmap.h b/src/maps/shashmap.h index 6152ba2..99dd7c8 100644 --- a/src/maps/shashmap.h +++ b/src/maps/shashmap.h @@ -4,6 +4,8 @@ #include <pthread.h> #include "hashmap.h" +#include "../monitor/dump.h" + using namespace std; template @@ -13,11 +15,15 @@ template class hash_type = size_hash<string>, class alloc_type = compare_allocator<string> > -class shashmap : protected hashmap<obj_type, key_type_, hash_type, alloc_type> +class shashmap : protected hashmap<obj_type, key_type_, hash_type, alloc_type>, + public dumpable { private: pthread_mutex_t mut_shashmap; +protected: + virtual void dumpit(); + public: explicit shashmap(); ~shashmap(); @@ -36,6 +42,7 @@ public: virtual inline vector<key_type_>* get_key_vector(); virtual inline void run_func( void (*func)(obj_type) ); virtual inline void run_func( void (*func)(obj_type, void*), void* v_arg ); + }; #include "shashmap.tmpl" diff --git a/src/maps/shashmap.tmpl b/src/maps/shashmap.tmpl index 4559284..c864d28 100644 --- a/src/maps/shashmap.tmpl +++ b/src/maps/shashmap.tmpl @@ -139,3 +139,17 @@ shashmap<obj_type, key_type_, hash_type, alloc_type>::run_func( void (*func)(obj hashmap<obj_type, key_type_, hash_type, alloc_type>::run_func(func, v_arg); pthread_mutex_unlock( &mut_shashmap ); } + +template<class obj_type, class key_type_, class hash_type, class alloc_type> +void +shashmap<obj_type, key_type_, hash_type, alloc_type>::dumpit() +{ + dumpable::add("[shashmap]"); + vector<key_type_>* p_vec = get_key_vector(); + + typename vector<key_type_>::iterator iter; + for (iter = p_vec->begin(); iter != p_vec->end(); ++iter) + dumpable::add(*iter); + + delete p_vec; +} diff --git a/src/modl.cpp b/src/modl.cpp index 6668109..32fe33a 100755 --- a/src/modl.cpp +++ b/src/modl.cpp @@ -113,6 +113,14 @@ modl::cache_module( string s_name, bool b_print_sys_msg ) } 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 ) { wrap::system_message( MODULER + s_name.substr( s_name.find_last_of("/")+1 ) ); @@ -7,7 +7,7 @@ using namespace std; -class modl : private shashmap<dynmod*> +class modl : public shashmap<dynmod*> { private: static void dlclose_( dynmod* mod ); @@ -24,6 +24,7 @@ public: ~modl(); dynmod* get_module( string s_name ); + dynmod* get_module( string s_name, string s_user ); vector<string>* get_mod_vector() { diff --git a/src/mods/commands/Makefile b/src/mods/commands/Makefile index 6aec38d..43346bb 100644 --- a/src/mods/commands/Makefile +++ b/src/mods/commands/Makefile @@ -1,11 +1,11 @@ SRCS=yc_about.cpp yc_all.cpp yc_away.cpp yc_col.cpp yc_compopt.cpp yc_exec.cpp yc_fake.cpp yc_getroom.cpp yc_getrusage.cpp yc_help.cpp yc_invisible.cpp yc_j.cpp yc_ko.cpp yc_m.cpp yc_md5.cpp yc_me.cpp yc_morph.cpp yc_msg.cpp yc_q.cpp yc_reload.cpp yc_ren.cpp yc_s.cpp yc_set.cpp yc_template.cpp yc_time.cpp yc_topic.cpp yc_uptime.cpp yc_users.cpp yc_version.cpp MODS=$(addprefix ../../../mods/commands/, $(SRCS:.cpp=.so)) -CC=g++ +CC=g++33 INCLUDES=`cat ../../includes.add` CFLAGS=`cat ../cflags.add` all: mods $(MODS): - @echo -n "Compiling command module `basename $@` " + @echo -n "Compiling command module `basename $@ | sed s/\.so// | sed s/yc_//` " @if ! test -d `dirname $@`; then mkdir -p `dirname $@`; fi @$(CC) $(CFLAGS) $(INCLUDES) -shared -s -o $@ `echo $(notdir $@) | sed s/.so/.cpp/` @du -hc $@ | tail -n 1 | sed s/total// | sed "s/ //g" diff --git a/src/mods/commands/Makefile.in b/src/mods/commands/Makefile.in index ce8c00f..7ca8455 100755 --- a/src/mods/commands/Makefile.in +++ b/ |
