summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base.cpp92
-rw-r--r--src/base.h94
-rw-r--r--src/chat.cpp179
-rw-r--r--src/chat.h69
-rw-r--r--src/conf.cpp99
-rw-r--r--src/conf.h47
-rw-r--r--src/cont.cpp47
-rw-r--r--src/cont.h52
-rw-r--r--src/hmap.cpp206
-rw-r--r--src/hmap.h146
-rw-r--r--src/lang.cpp102
-rw-r--r--src/lang.h47
-rw-r--r--src/mutx.cpp43
-rw-r--r--src/mutx.h44
-rw-r--r--src/pool.cpp203
-rw-r--r--src/pool.h75
-rw-r--r--src/room.cpp39
-rw-r--r--src/room.h57
-rw-r--r--src/s_chat.cpp33
-rw-r--r--src/s_chat.h50
-rw-r--r--src/s_conf.cpp33
-rw-r--r--src/s_conf.h50
-rw-r--r--src/s_html.cpp33
-rw-r--r--src/s_html.h50
-rw-r--r--src/s_lang.cpp33
-rw-r--r--src/s_lang.h51
-rw-r--r--src/s_mutx.cpp33
-rw-r--r--src/s_mutx.h50
-rw-r--r--src/s_sman.cpp33
-rw-r--r--src/s_sman.h50
-rw-r--r--src/s_sock.cpp33
-rw-r--r--src/s_sock.h50
-rw-r--r--src/s_tool.cpp162
-rw-r--r--src/s_tool.h44
-rw-r--r--src/sess.cpp62
-rw-r--r--src/sess.h51
-rw-r--r--src/sman.cpp80
-rw-r--r--src/sman.h59
-rw-r--r--src/sock.cpp263
-rw-r--r--src/sock.h80
-rw-r--r--src/thrd.cpp52
-rw-r--r--src/thrd.h52
-rw-r--r--src/user.cpp167
-rw-r--r--src/user.h125
44 files changed, 3420 insertions, 0 deletions
diff --git a/src/base.cpp b/src/base.cpp
new file mode 100644
index 0000000..68ccd80
--- /dev/null
+++ b/src/base.cpp
@@ -0,0 +1,92 @@
+/*:*
+ *: File: ./src/base.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+/*
+ This file is part of yChat
+
+ $Author: buetow $
+ $Date: 2005-11-12 15:51:43 $
+
+ $Header: /cvs/cvsroot/ychat-0.5/src/base.cpp,v 1.4 2005-11-12 15:51:43 buetow Exp $
+*/
+// template class data implementation;
+
+#ifndef BASE_CPP
+#define BASE_CPP
+
+#include "base.h"
+
+template<class type>
+base<type>::base()
+{
+ map_elem = new hmap<type*,string>(80);
+ pthread_mutex_init (&mut_map_elem, NULL );
+}
+
+template<class type>
+base<type>::~base( )
+{
+ pthread_mutex_destroy( &mut_map_elem );
+}
+
+template<class type>
+void
+base<type>::add_elem( type* p_type )
+{
+ pthread_mutex_lock ( &mut_map_elem );
+ map_elem->add_elem ( p_type, p_type->get_name());
+ pthread_mutex_unlock( &mut_map_elem );
+}
+
+template<class type>
+void
+base<type>::del_elem( string &s_name )
+{
+ pthread_mutex_lock ( &mut_map_elem );
+ map_elem->del_elem ( s_name );
+ pthread_mutex_unlock( &mut_map_elem );
+}
+
+template<class type>
+type*
+base<type>::get_elem( string &s_name, bool &b_found )
+{
+ pthread_mutex_lock ( &mut_map_elem );
+ type* p_type = map_elem->get_elem( s_name );
+ pthread_mutex_unlock( &mut_map_elem );
+
+ b_found = p_type == NULL ? false : true;
+
+ return p_type;
+}
+
+template<class type>
+void
+base<type>::run_func( void (*func)(type*, void*), void* v_arg )
+{
+ pthread_mutex_lock ( &mut_map_elem );
+ map_elem->run_func( func, v_arg );
+ pthread_mutex_unlock( &mut_map_elem );
+}
+
+#endif
diff --git a/src/base.h b/src/base.h
new file mode 100644
index 0000000..300c916
--- /dev/null
+++ b/src/base.h
@@ -0,0 +1,94 @@
+/*:*
+ *: File: ./src/base.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// template class data declaration;
+
+#ifndef BASE_H
+#define BASE_H
+
+#include "incl.h"
+#include "hmap.h"
+
+template<class type>
+class base
+{
+private:
+ hmap<type*,string>* map_elem;
+ pthread_mutex_t mut_map_elem;
+
+public:
+ base();
+ ~base();
+
+ virtual void add_elem( type* p_type ); // add a element.
+ virtual void del_elem( string &s_name ); // delete a alement.
+ virtual type* get_elem( string &s_name, bool &b_found ); // get a element.
+
+ // execute func on all elements of map_elem. v_pointer is the argument.
+ virtual void run_func( void (*func)(type*, void*), void* v_arg );
+
+ // chat::msg_post sends to all users of the system a message.
+ // room::msg_post sends to all users of the room a message.
+ // user::msg_post sends to the user a message.
+ void msg_post( string *s_msg )
+ {
+ run_func( &base<type>::msg_post_ , (void*)s_msg );
+ }
+ static void msg_post_( type* type_obj, void* v_arg )
+ {
+ string *p_msg = (string*) v_arg;
+ type_obj -> msg_post( p_msg );
+ }
+
+ void get_data( map_string *p_map_string )
+ {
+ run_func( &base<type>::get_data_ , (void*)p_map_string );
+ }
+ static void get_data_( type* type_obj, void* v_arg )
+ {
+ map_string *map_params = (map_string*) v_arg;
+ type_obj -> get_data ( map_params );
+ }
+
+ // chat::get_user_list gets a list of all users of the system.
+ // room::get_user_list gets a list of all users of the room.
+ // user::get_user_list gets a "list" of a user <font color="usercolor">username</font>seperator
+ void get_user_list( string &s_list, string &s_seperator )
+ {
+
+ container c;
+ c.elem[0] = (void*) &s_list;
+ c.elem[1] = (void*) &s_seperator;
+
+ run_func( &base<type>::get_user_list_, (void*)&c );
+ }
+ static void get_user_list_( type* type_obj, void* v_arg )
+ {
+ container *c = (container*) v_arg;
+ type_obj -> get_user_list( *((string*)c->elem[0]), *((string*)c->elem[1]) );
+ }
+};
+
+#include "base.cpp"
+
+#endif
diff --git a/src/chat.cpp b/src/chat.cpp
new file mode 100644
index 0000000..8fd60e7
--- /dev/null
+++ b/src/chat.cpp
@@ -0,0 +1,179 @@
+/*:*
+ *: File: ./src/chat.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class chat implementation.
+
+#ifndef s_chat_CXX
+#define s_chat_CXX
+
+#include "chat.h"
+#include "s_conf.h"
+#include "s_mutx.h"
+#include "s_tool.h"
+
+using namespace std;
+
+chat::chat( )
+{
+ if ( s_conf::get
+ ().get_val( "HTML" ) == "OFF" )
+ b_strip_html = true;
+ else
+ b_strip_html = false;
+
+}
+
+chat::~chat( )
+{}
+
+user*
+chat::get_user( string &s_user )
+{
+ bool b_flag;
+ return get_user( s_user, b_flag );
+}
+
+user*
+chat::get_user( string &s_user, bool &b_found )
+{
+ container param;
+
+ param.elem[0] = (void*) &s_user ;
+ param.elem[1] = (void*) &b_found;
+
+ b_found = false;
+
+ run_func( get_user_, (void*)&param );
+
+ if ( *( (bool*)param.elem[1] ) )
+ return (user*)param.elem[2];
+}
+
+void
+chat::get_user_( room *room_obj, void *v_arg )
+{
+ container* param = (container*) v_arg;
+ param->elem[2] = (void*)room_obj->get_elem( *((string*)param->elem[0]), *((bool*)param->elem[1]) );
+}
+
+void
+chat::login( map_string &map_params )
+{
+ string s_user = map_params["nick"];
+
+ // prove if nick is empty:
+ if ( s_user.empty() )
+ {
+ map_params["INFO"] = E_NONICK;
+ map_params["request"] = s_conf::get
+ ().get_val( "STARTMPL" ); // redirect to the startpage.
+ return;
+ }
+
+ // prove if the nick ist alphanumeric:
+ else if ( ! s_tool::is_alpha_numeric( s_user ) )
+ {
+ map_params["INFO"] = E_ALPNUM;
+ map_params["request"] = s_conf::get
+ ().get_val( "STARTMPL" ); // redirect to the startpage.
+ return;
+ }
+
+ bool b_flag;
+
+ // prove if nick is already online / logged in.
+ get_user( s_user, b_flag );
+ if ( b_flag )
+ {
+ map_params["INFO"] = E_ONLINE;
+ map_params["request"] = s_conf::get
+ ().get_val( "STARTMPL" );
+ return;
+ }
+
+ string s_room = map_params["room"];
+ room* p_room = get_room( s_room , b_flag );
+
+ // if room does not exist add room to list!
+ if ( ! b_flag )
+ {
+ p_room = new room( s_room );
+
+#ifdef VERBOSE
+
+ pthread_mutex_lock ( &s_mutx::get
+ ().mut_stdout );
+ cout << NEWROOM << s_room << endl;
+ pthread_mutex_unlock( &s_mutx::get
+ ().mut_stdout );
+#endif
+
+ add_elem( p_room );
+ }
+
+ user *p_user = new user( s_user );
+
+ // add user to the room.
+ p_room->add_user( p_user );
+ sess *ns =s_sman::get
+ ().createSession();
+ ns->setValue(string("nick"), (void *)new string(s_user) );
+ map_params["tmpid"]=ns->getId();
+ // post "username enters the chat" into the room.
+ p_room->msg_post( new string( s_user.append( s_lang::get
+ ().get_val( "USERENTR" ) ) ) );
+
+#ifdef VERBOSE
+
+ pthread_mutex_lock ( &s_mutx::get
+ ().mut_stdout );
+ cout << LOGINPR << s_user << endl;
+ pthread_mutex_unlock( &s_mutx::get
+ ().mut_stdout );
+#endif
+}
+
+void
+chat::post( user* p_user, map_string &map_params )
+{
+
+ string s_msg( map_params["message"] );
+
+ auto unsigned i_pos = s_msg.find( "/" );
+
+ if ( b_strip_html )
+ s_tool::strip_html( &s_msg );
+
+ string s_post( "<font color=\"" );
+
+ s_post.append( p_user->get_col1() )
+ .append( "\">" )
+ .append( p_user->get_name() )
+ .append( ": " )
+ .append( s_msg )
+ .append( "</font><br>\n" );
+
+ p_user->get_p_room()->msg_post( &s_post );
+}
+
+#endif
diff --git a/src/chat.h b/src/chat.h
new file mode 100644
index 0000000..02864f1
--- /dev/null
+++ b/src/chat.h
@@ -0,0 +1,69 @@
+/*:*
+ *: File: ./src/chat.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class chat declaration.
+
+#ifndef s_chat_H
+#define s_chat_H
+
+#include <vector>
+#include "incl.h"
+#include "base.h"
+#include "room.h"
+#include "user.h"
+#include "sess.h"
+#include "s_lang.h"
+#include "s_sman.h"
+
+using namespace std;
+
+class chat : public base<room>
+{
+private:
+ bool b_strip_html;
+
+public:
+
+
+ room* get_room( string &s_name, bool &b_found )
+ {
+ return static_cast<room*>( get_elem( s_name, b_found ) );
+ }
+
+ // public methods:
+ explicit chat(); // a standard constructor.
+ ~chat(); // destructor.
+
+ // get the object of a specific user.
+ virtual user* get_user( string &s_nick );
+ virtual user* get_user( string &s_nick, bool &b_found );
+ static void get_user_( room* room_obj, void *v_arg );
+
+ // will be called every time a user tries to login.
+ virtual void login( map_string &map_params );
+
+ // will be called if a user posts a message.
+ virtual void post ( user* u_user, map_string &map_params );
+};
+
+#endif
diff --git a/src/conf.cpp b/src/conf.cpp
new file mode 100644
index 0000000..3dd3c6c
--- /dev/null
+++ b/src/conf.cpp
@@ -0,0 +1,99 @@
+/*:*
+ *: File: ./src/conf.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class conf implementation.
+
+#ifndef s_conf_CXX
+#define s_conf_CXX
+
+#include <fstream>
+#include "conf.h"
+
+using namespace std;
+
+conf::conf( string s_conf = CONFILE ) : name( s_conf )
+{
+ parse( ); // parse the config file.
+}
+
+conf::~conf()
+{}
+
+void
+conf::parse()
+{
+#ifdef VERBOSE
+ cout << CFILEOK << get_name() << endl;
+#endif
+
+ ifstream fs_conf( get_name().c_str() );
+
+ if ( ! fs_conf )
+ {
+#ifdef VERBOSE
+ cout << CFILENO << get_name() << endl;
+#endif
+
+ 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 );
+
+#ifdef VERBOSE2
+
+ cout << s_key << "=" << s_val << endl;
+#endif
+
+ // fill the map.
+ map_vals[s_key] = s_val;
+ }
+
+ fs_conf.close();
+ fs_conf.~ifstream();
+}
+
+#endif
diff --git a/src/conf.h b/src/conf.h
new file mode 100644
index 0000000..954ce75
--- /dev/null
+++ b/src/conf.h
@@ -0,0 +1,47 @@
+/*:*
+ *: File: ./src/conf.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class conf declaration. this class parses the server config file.
+
+#ifndef s_conf_H
+#define s_conf_H
+
+#include "incl.h"
+#include "cont.h"
+#include "name.h"
+
+using namespace std;
+
+class conf : public cont, name
+{
+private:
+
+public:
+ // public methods:
+ conf ( string s_conf ); // standard constructor.
+ ~conf(); // standard destructor.
+
+ virtual void parse( ); // parses the config file.
+};
+
+#endif
diff --git a/src/cont.cpp b/src/cont.cpp
new file mode 100644
index 0000000..497b456
--- /dev/null
+++ b/src/cont.cpp
@@ -0,0 +1,47 @@
+/*:*
+ *: File: ./src/cont.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class cont implementation.
+
+#ifndef CONT_CXX
+#define CONT_CXX
+
+#include "cont.h"
+#include "s_mutx.h"
+
+using namespace std;
+
+string
+cont::get_val( string s_key )
+{
+ if ( map_vals.find( s_key ) != map_vals.end() )
+ return map_vals[ s_key ];
+ return string();
+}
+
+cont::~cont()
+{
+ map_vals.~map_string();
+}
+
+#endif
diff --git a/src/cont.h b/src/cont.h
new file mode 100644
index 0000000..810ff2d
--- /dev/null
+++ b/src/cont.h
@@ -0,0 +1,52 @@
+/*:*
+ *: File: ./src/cont.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class cont declaration. defines a simple data container class.
+
+#ifndef CONT_H
+#define CONT_H
+
+#include "incl.h"
+#include "hmap.h"
+
+using namespace std;
+
+class cont
+{
+protected:
+ map_string map_vals;
+
+public:
+ cont::~cont();
+
+ // small inline methods:
+ void clear_vals()
+ {
+ map_vals.clear();
+ } // removes all values.
+
+ // public methods:
+ virtual string get_val( string s_key ); // get a specific map_vals value.
+};
+
+#endif
diff --git a/src/hmap.cpp b/src/hmap.cpp
new file mode 100644
index 0000000..81db939
--- /dev/null
+++ b/src/hmap.cpp
@@ -0,0 +1,206 @@
+/*:*
+ *: File: ./src/hmap.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef hmap_cpp
+#define hmap_cpp
+
+
+#include "hmap.h"
+
+using namespace std;
+
+bool isPrime( int n );
+int nextPrime( int n );
+
+// Construct the hash table.
+template <class obj_type, class key_type>
+hmap<obj_type, key_type>::hmap( double mop )
+ : maxOccupiedPercentage(mop), array( nextPrime( 101 ) )
+{
+ cout << "hmap Constructor" << endl;
+ lookups = 0;
+ make_empty( );
+}
+
+// Insert item x into the hash table. If the item is
+// already present, do nothing
+template <class obj_type, class key_type>
+void hmap<obj_type, key_type>::add_elem( const obj_type &x, const key_type &k )
+{
+ // Insert x as active
+ int currentPos = findPos( k );
+ if( isActive( currentPos ) )
+ return;
+
+ array[ currentPos ] = hash_entry( x, k, ACTIVE );
+ // cout << "Inserted=" << x << "= at " << currentPos << endl;
+ if( ++occupied > array.size( ) * maxOccupiedPercentage )
+ rehash( );
+}
+
+// Expand the hash table.
+template <class obj_type, class key_type>
+void hmap<obj_type, key_type>::rehash( )
+{
+ vector<hash_entry> oldArray = array;
+
+ // Create new double-sized, empty table
+ array.resize( nextPrime( 2 * oldArray.size( ) ) );
+ for( int j = 0; j < array.size( ); j++ )
+ array[ j ].info = EMPTY;
+
+ // Copy table over
+ make_empty( );
+ for( int i = 0; i < oldArray.size( ); i++ )
+ if( oldArray[ i ].info == ACTIVE )
+ add_elem( oldArray[ i ].element, oldArray[ i ].key );
+}
+
+// Hash function, can only handle strings.
+// If you want to hash other objects you will have to
+// create a hash table for them
+template <class obj_type, class key_type>
+unsigned int hmap<obj_type, key_type>::hash( const string & key ) const
+{
+ unsigned int hashVal = 0;
+ // cout << key << "%";
+
+ for( size_t i = 0; i < key.size(); i++ )
+ hashVal = ( hashVal << 5 ) ^ key[ i ] ^ hashVal;
+
+ return hashVal;
+}
+
+// Method that performs quadratic probing resolution.
+// Return the position where the search for x terminates.
+template <class obj_type, class key_type>
+int hmap<obj_type, key_type>::findPos( const key_type &k )
+{
+ int collisionNum = 0;
+ int currentPos = hash( k ) % array.size( );
+ lookups++;
+
+ while( array[ currentPos ].info != EMPTY &&
+ array[ currentPos ].key != k )
+ {
+ // cout << array[ currentPos ].element << "!=" << x << endl;
+ lookups++;
+ currentPos += 2 * ++collisionNum - 1; // Compute ith probe
+
+ if( currentPos >= array.size( ) )
+ currentPos -= array.size( );
+ }
+
+ // cout << currentPos << " ";
+ return currentPos;
+}
+
+// Remove item x from the hash table.
+template <class obj_type, class key_type>
+void hmap<obj_type, key_type>::del_elem( const key_type & k )
+{
+ int currentPos = findPos( k );
+ if( isActive( currentPos ) )
+ array[ currentPos ].info = DELETED;
+}
+
+// Find item x in the hash table.
+// Return a pointer to the matching item or 0 if not found
+template <class obj_type, class key_type>
+obj_type hmap<obj_type, key_type>::get_elem( const key_type &k )
+{
+ int currentPos = findPos( k );
+ if( isActive( currentPos ) )
+ return array[ currentPos ].element;
+ else
+ return 0;
+}
+
+// Make the hash table logically empty.
+template <class obj_type, class key_type>
+void hmap<obj_type, key_type>::make_empty( )
+{
+ occupied = 0;
+ for( int i = 0; i < array.size( ); i++ )
+ array[ i ].info = EMPTY;
+}
+
+// Return true if currentPos exists and is active.
+template <class obj_type, class key_type>
+bool hmap<obj_type, key_type>::isActive( int currentPos ) const
+{
+ return array[ currentPos ].info == ACTIVE;
+}
+
+
+// Internal method to test if a positive number is prime.
+// Not an efficient algorithm.
+template <class obj_type, class key_type>
+bool hmap<obj_type, key_type>::isPrime( int n ) const
+{
+ if( n == 2 || n == 3 )
+ return true;
+
+ else if( n == 1 || n % 2 == 0 )
+ return false;
+
+ for( int i = 3; i * i <= n; i += 2 )
+ if( n % i == 0 )
+ return false;
+
+ return true;
+}
+
+// Internal method to return a prime number at least as large as n.
+// Assumes n > 0.
+template <class obj_type, class key_type>
+int hmap<obj_type, key_type>::nextPrime( int n ) const
+{
+ if( n % 2 == 0 )
+ n++;
+
+ for( ; !isPrime( n ); n += 2 )
+ ;
+
+ return n;
+}
+template<class obj_type, class key_type>
+void
+hmap<obj_type, key_type>::run_func( void (*func)(obj_type) )
+{
+ for( int i = 0; i < array.size( ); i++ )
+ if ( array[i].info == ACTIVE )
+ ( *func ) ( array[i].element );
+}
+
+template<class obj_type, class key_type>
+void
+hmap<obj_type, key_type>::run_func( void (*func)(obj_type, void*), void* v_arg )
+{
+ for( int i = 0; i < array.size( ); i++ )
+ if ( array[i].info == ACTIVE )
+ ( *func ) ( array[i].element, v_arg );
+}
+
+#endif
+
diff --git a/src/hmap.h b/src/hmap.h
new file mode 100644
index 0000000..0360019
--- /dev/null
+++ b/src/hmap.h
@@ -0,0 +1,146 @@
+/*:*
+ *: File: ./src/hmap.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#pragma warning(disable:4786)
+
+#ifndef hmap_h
+#define hmap_h
+
+#include <vector>
+#include "incl.h"
+
+using namespace std;
+
+// void add_elem( obj_type x, key_type k ) --> Insert x
+// void del_elem( key_type k ) --> Remove x
+// obj_type get_elem( key_type k ) --> Return item that matches x
+// void make_empty( ) --> Remove all items
+
+template <class obj_type, class key_type>
+class hmap
+{
+private:
+ enum entry_type
+ {
+ ACTIVE, EMPTY, DELETED
+ };
+
+ struct hash_entry
+ {
+ obj_type element;
+ key_type key;
+ entry_type info;
+
+ hash_entry( const obj_type &e = obj_type( ), const key_type &k = key_type( ), entry_type i = EMPTY ) : element( e ), key( k ), info( i )
+ { }
+ }
+ ;
+
+ int occupied;
+
+ virtual bool isActive( int currentPos ) const;
+ virtual void rehash( );
+ virtual bool isPrime ( int n ) const;
+ virtual int nextPrime( int n ) const;
+ double maxOccupiedPercentage;
+
+protected:
+ int lookups;
+ unsigned int hash( const string &key ) const;
+ vector<hash_entry> array;
+
+public:
+ hmap( double moc );
+
+ virtual int findPos ( const key_type &k );
+ virtual void make_empty( );
+ virtual void add_elem ( const obj_type &x, const key_type &k );
+ virtual void del_elem ( const key_type &k );
+ virtual obj_type get_elem ( const key_type &k );
+
+ virtual void run_func( void (*func)(obj_type) );
+ virtual void run_func( void (*func)(obj_type, void*), void* v_arg );
+
+ // inline:
+ void getSize()
+ {
+ int size = 0;
+ for( int j = 0; j < array.size( ); j++ )
+ if (array[ j ].info == ACTIVE)
+ size++;
+ return size;
+ };
+
+ int getLookups()
+ {
+ return lookups;
+ };
+
+ int getCapacity()
+ {
+ return array.size();
+ };
+
+ double getLambda()
+ {
+ return static_cast<double>(getSize())/static_cast<double>(getCapacity());
+ }
+
+ obj_type& operator[]( key_type &k )
+ {
+ return get_elem( k );
+ }
+
+};
+
+template <class obj_type, class key_type>
+class linearhmap : public hmap<obj_type, key_type>
+{
+public:
+ linearhmap(double moc) : hmap<obj_type, key_type>(moc)
+ {}
+ ;
+
+ virtual int findPos( const key_type &k )
+ {
+ int collisionNum = 0;
+ int currentPos = hash( k ) % hmap<obj_type, key_type>::array.size( );
+ hmap<obj_type, key_type>::lookups++;
+
+ while( hmap<obj_type, key_type>::array[ currentPos ].info != hmap<obj_type, key_type>::EMPTY &&
+ hmap<obj_type, key_type>::array[ currentPos ].key != k )
+ {
+ hmap<obj_type, key_type>::lookups ++;
+ currentPos++;
+
+ if( currentPos >= hmap<obj_type, key_type>::array.size( ) )
+ currentPos -= hmap<obj_type, key_type>::array.size( );
+ }
+
+ return currentPos;
+ }
+};
+
+#include "hmap.cpp"
+
+#endif
diff --git a/src/lang.cpp b/src/lang.cpp
new file mode 100644
index 0000000..3477c39
--- /dev/null
+++ b/src/lang.cpp
@@ -0,0 +1,102 @@
+/*:*
+ *: File: ./src/lang.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class conf implementation.
+
+#ifndef s_lang_CXX
+#define s_lang_CXX
+
+#include <fstream>
+#include "lang.h"
+
+using namespace std;
+
+lang::lang( string s_lang = "en" ) : name( s_lang )
+{
+ parse( ); // parse the config file.
+}
+
+lang::~lang()
+{}
+
+void
+lang::parse()
+{
+#ifdef VERBOSE
+ cout << CFILEOK << get_name() << endl;
+#endif
+
+ string filename("lang/");
+ filename.append(get_name());
+
+ ifstream fs_conf( filename.c_str() );
+
+ if ( ! fs_conf )
+ {
+#ifdef VERBOSE
+ cout << CFILENO << get_name() << endl;
+#endif
+
+ 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 );
+
+#ifdef VERBOSE2
+
+ cout << s_key << "=" << s_val << endl;
+#endif
+
+ // fill the map.
+ map_vals[s_key] = s_val;
+ }
+
+ fs_conf.close();
+ fs_conf.~ifstream();
+}
+
+#endif
diff --git a/src/lang.h b/src/lang.h
new file mode 100644
index 0000000..5c6d428
--- /dev/null
+++ b/src/lang.h
@@ -0,0 +1,47 @@
+/*:*
+ *: File: ./src/lang.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class conf declaration. this class parses the server config file.
+
+#ifndef s_lang_H
+#define s_lang_H
+
+#include "incl.h"
+#include "cont.h"
+#include "name.h"
+
+using namespace std;
+
+class lang : public cont, 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/mutx.cpp b/src/mutx.cpp
new file mode 100644
index 0000000..277b193
--- /dev/null
+++ b/src/mutx.cpp
@@ -0,0 +1,43 @@
+/*:*
+ *: File: ./src/mutx.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class mutx implementation.
+
+#ifndef s_mutx_CXX
+#define s_mutx_CXX
+
+#include "mutx.h"
+
+using namespace std;
+
+mutx::mutx()
+{
+ pthread_mutex_init( &mut_stdout, NULL );
+}
+
+mutx::~mutx()
+{
+ pthread_mutex_destroy( &mut_stdout );
+}
+
+#endif
diff --git a/src/mutx.h b/src/mutx.h
new file mode 100644
index 0000000..20d688a
--- /dev/null
+++ b/src/mutx.h
@@ -0,0 +1,44 @@
+/*:*
+ *: File: ./src/mutx.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class mutx declaration.
+
+#ifndef s_mutx_H
+#define s_mutx_H
+
+#include "incl.h"
+
+using namespace std;
+
+class mutx
+{
+public:
+ // this mutex is needed for sync stdout and sdterr of different threads.
+ pthread_mutex_t mut_stdout;
+
+ // public methods.
+ explicit mutx( ); // simple constructor.
+ ~mutx( ); // simple constructor.
+};
+
+#endif
diff --git a/src/pool.cpp b/src/pool.cpp
new file mode 100644
index 0000000..e2e3db2
--- /dev/null
+++ b/src/pool.cpp
@@ -0,0 +1,203 @@
+/*:*
+ *: File: ./src/pool.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef POOL_CPP
+#define POOL_CPP
+
+#include "pool.h"
+
+using namespace std;
+
+pool::pool()
+{
+ pthread_mutex_init(&mut_threads, 0);
+ pthread_mutex_init(&mut_queue_tasks, 0);
+ pthread_mutex_init(&mut_num_avail_threads, 0);
+ pthread_cond_init(&cond_new_task, 0);
+
+ i_num_total_threads = 0;
+ i_num_avail_threads = s_tool::string2int( s_conf::get
+ ().get_val( "THRDPOOL" ) );
+ increase_pool(i_num_avail_threads);
+}
+
+pool::~pool()
+{
+ pthread_mutex_lock(&mut_queue_tasks);
+ while (!queue_tasks.empty())
+ {
+ delete queue_tasks.front();
+ queue_tasks.pop();
+ }
+ pthread_mutex_unlock(&mut_queue_tasks);
+
+ pthread_mutex_destroy(&mut_threads);
+ pthread_mutex_destroy(&mut_queue_tasks);
+ pthread_mutex_destroy(&mut_num_avail_threads);
+ pthread_cond_destroy(&cond_new_task);
+}
+
+int
+pool::increase_pool(int i_num)
+{
+#ifdef VERBOSE
+ pthread_mutex_lock ( &s_mutx::get
+ ().mut_stdout );
+ cout << POOLFLL + s_tool::int2string(i_num) +","+s_tool::int2string(i_num_total_threads)+")" << endl;
+ pthread_mutex_unlock( &s_mutx::get
+ ().mut_stdout );
+#endif
+
+ int i_max_pool_size = s_tool::string2int( s_conf::get
+ ().get_val( "THRDPMAX" ) );
+
+ for ( int i = 0; i < i_num; ++i )
+ {
+ if ( i_max_pool_size != 0 && i_num_total_threads >= i_max_pool_size )
+ {
+#ifdef VERBOSE
+ pthread_mutex_lock ( &s_mutx::get
+ ().mut_stdout );
+ cout << POOLER2+s_tool::int2string(i_max_pool_size)+")" << endl;
+ cout << POOLER1+s_tool::int2string(i)+")" << endl;
+ pthread_mutex_unlock( &s_mutx::get
+ ().mut_stdout );
+#endif
+
+ return i;
+ }
+
+ ++i_num_total_threads;
+ pthread_t p_pthread;
+ pthread_create(&p_pthread, 0, wait_for_task, (void*) this );
+ }
+
+ return i_num;
+}
+
+void
+pool::add_task( void(*p_func)(void*), void* p_void )
+{
+ pthread_mutex_lock(&mut_queue_tasks);
+ queue_tasks.push(new task(p_func, p_void));
+ pthread_mutex_unlock(&mut_queue_tasks);
+
+ pthread_cond_signal(&cond_new_task);
+
+}
+
+void*
+pool::wait_for_task( void* p_void )
+{
+ pool* p_pool = static_cast<pool*>(p_void);
+
+ for (;;)
+ {
+ pthread_mutex_lock(&p_pool->mut_threads);
+ pthread_cond_wait(&p_pool->cond_new_task, &p_pool->mut_threads);
+
+ pthread_mutex_lock(&p_pool->mut_num_avail_threads);
+ if ( --p_pool->i_num_avail_threads < 5 )
+ {
+ int i_size = 9 - p_pool->i_num_avail_threads;
+ i_size = p_pool->increase_pool(i_size);
+ p_pool->i_num_avail_threads += i_size;
+ }
+ pthread_mutex_unlock(&p_pool->mut_num_avail_threads);
+
+ pthread_mutex_lock(&p_pool->mut_queue_tasks);
+ task* p_task = p_pool->queue_tasks.front();
+ p_pool->queue_tasks.pop();
+ pthread_mutex_unlock(&p_pool->mut_queue_tasks);
+
+ pthread_mutex_unlock(&p_pool->mut_threads);
+
+ (*(p_task->p_func))(p_task->p_void);
+ delete p_task;
+
+ pthread_mutex_lock(&p_pool->mut_num_avail_threads);
+ p_pool->i_num_avail_threads++;
+ pthread_mutex_unlock(&p_pool->mut_num_avail_threads);
+ }
+
+ return 0;
+}
+
+void
+pool::run(void* p_void)
+{
+ add_task(run_func, p_void);
+}
+
+void
+pool::run_func(void *p_void)
+{
+#ifdef VERBOSE
+ pthread_mutex_lock ( &s_mutx::get
+ ().mut_stdout );
+ cout << THREADS << endl;
+ pthread_mutex_unlock( &s_mutx::get
+ ().mut_stdout );
+#endif
+
+ // recasting the client thread object.
+ thrd *t = (thrd*) p_void;
+
+ // start parsing the client request and sending response's back.
+ t-> run ();
+
+ // close the client socket.
+ t->~thrd();
+
+ free(p_void);
+
+#ifdef VERBOSE
+
+ pthread_mutex_lock ( &s_mutx::get
+ ().mut_stdout );
+ cout << THREADE << endl;
+ pthread_mutex_unlock( &s_mutx::get
+ ().mut_stdout );
+#endif
+}
+
+bool
+pool::allow_user_login()
+{
+ pthread_mutex_lock(&mut_num_avail_threads);
+ if ( i_num_avail_threads < 2 )
+ {
+ int i_max_pool_size = s_tool::string2int( s_conf::get
+ ().get_val( "THRDPMAX" ) );
+ if ( i_max_pool_size != 0 && i_max_pool_size == i_num_total_threads )
+ {
+ pthread_mutex_unlock(&mut_num_avail_threads);
+ return false;
+ }
+ }
+ pthread_mutex_unlock(&mut_num_avail_threads);
+
+ return true;
+}
+
+#endif
diff --git a/src/pool.h b/src/pool.h
new file mode 100644
index 0000000..fdb7202
--- /dev/null
+++ b/src/pool.h
@@ -0,0 +1,75 @@
+/*:*
+ *: File: ./src/pool.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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 "incl.h"
+#include "thrd.h"
+#include "s_tool.h"
+#include "s_conf.h"
+#include "s_mutx.h"
+
+#ifndef POOL_H
+#define POOL_H
+
+#include <queue>
+
+using namespace std;
+
+class pool
+{
+private:
+ struct task
+ {
+ void(*p_func)(void*);
+ void *p_void;
+
+ task(void(*p_func)(void*), void *p_void)
+ {
+ this->p_func = p_func;
+ this->p_void = p_void;
+ }
+ };
+
+ pthread_mutex_t mut_threads;
+ pthread_mutex_t mut_queue_tasks;
+ pthread_mutex_t mut_num_avail_threads;
+ pthread_cond_t cond_new_task;
+
+ int i_num_avail_threads;
+ int i_num_total_threads;
+
+ queue<task*> queue_tasks;
+
+ int increase_pool(int i_num);
+ void add_task( void(*p_func)(void*), void* p_void );
+ static void* wait_for_task(void *p_void);
+ static void run_func(void *p_void);
+
+public:
+ pool();
+ ~pool();
+
+ void run(void* p_void);
+ bool allow_user_login();
+};
+
+#endif
diff --git a/src/room.cpp b/src/room.cpp
new file mode 100644
index 0000000..841bb12
--- /dev/null
+++ b/src/room.cpp
@@ -0,0 +1,39 @@
+/*:*
+ *: File: ./src/room.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class room implementation.
+
+#ifndef ROOM_CXX
+#define ROOM_CXX
+
+#include "room.h"
+
+using namespace std;
+
+room::room( string s_name ) : name( s_name )
+{}
+
+room::~room()
+{}
+
+#endif
diff --git a/src/room.h b/src/room.h
new file mode 100644
index 0000000..03c0fcd
--- /dev/null
+++ b/src/room.h
@@ -0,0 +1,57 @@
+/*:*
+ *: File: ./src/room.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class room declaration.
+
+#ifndef ROOM_H
+#define ROOM_H
+
+#include "incl.h"
+#include "base.h"
+#include "name.h"
+#include "user.h"
+
+using namespace std;
+
+class room : public base<user>, public name
+{
+private:
+
+public:
+ void add_user( user* p_user )
+ {
+ p_user->set_p_room( this );
+ add_elem( p_user );
+ }
+
+ user* get_user( string &s_name, bool &b_found )
+ {
+ return static_cast<user*>( get_elem( s_name, b_found ) );
+ }
+
+ // public methods:
+ explicit room( string s_name ); // a constructor.
+ ~room(); // room destructor.
+};
+
+#endif
diff --git a/src/s_chat.cpp b/src/s_chat.cpp
new file mode 100644
index 0000000..912907e
--- /dev/null
+++ b/src/s_chat.cpp
@@ -0,0 +1,33 @@
+/*:*
+ *: File: ./src/s_chat.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GCHT_CXX
+#define GCHT_CXX
+
+#include "s_chat.h"
+
+using namespace std;
+
+chat* s_chat::obj;
+
+#endif
diff --git a/src/s_chat.h b/src/s_chat.h
new file mode 100644
index 0000000..c2c0836
--- /dev/null
+++ b/src/s_chat.h
@@ -0,0 +1,50 @@
+/*:*
+ *: File: ./src/s_chat.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GCHT_H
+#define GCHT_H
+
+#include "chat.h"
+
+using namespace std;
+
+class s_chat
+{
+private:
+ static chat* obj;
+
+public:
+ static void init()
+ {
+ obj = new chat();
+ }
+
+ static chat& get
+ ()
+ {
+ return *obj;
+ }
+};
+
+
+#endif
diff --git a/src/s_conf.cpp b/src/s_conf.cpp
new file mode 100644
index 0000000..1c193fe
--- /dev/null
+++ b/src/s_conf.cpp
@@ -0,0 +1,33 @@
+/*:*
+ *: File: ./src/s_conf.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GCON_CXX
+#define GCON_CXX
+
+#include "s_conf.h"
+
+using namespace std;
+
+conf* s_conf::obj;
+
+#endif
diff --git a/src/s_conf.h b/src/s_conf.h
new file mode 100644
index 0000000..8f2b0f7
--- /dev/null
+++ b/src/s_conf.h
@@ -0,0 +1,50 @@
+/*:*
+ *: File: ./src/s_conf.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GCON_H
+#define GCON_H
+
+#include "conf.h"
+
+using namespace std;
+
+class s_conf
+{
+private:
+ static conf* obj;
+
+public:
+ static void init()
+ {
+ obj = new conf( CONFILE );
+ }
+
+ static conf& get
+ ()
+ {
+ return *obj;
+ }
+};
+
+
+#endif
diff --git a/src/s_html.cpp b/src/s_html.cpp
new file mode 100644
index 0000000..b4dfd21
--- /dev/null
+++ b/src/s_html.cpp
@@ -0,0 +1,33 @@
+/*:*
+ *: File: ./src/s_html.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GHTM_CXX
+#define GHTM_CXX
+
+#include "s_html.h"
+
+using namespace std;
+
+html* s_html::obj;
+
+#endif
diff --git a/src/s_html.h b/src/s_html.h
new file mode 100644
index 0000000..6392205
--- /dev/null
+++ b/src/s_html.h
@@ -0,0 +1,50 @@
+/*:*
+ *: File: ./src/s_html.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GHTM_H
+#define GHTM_H
+
+#include "html.h"
+
+using namespace std;
+
+class s_html
+{
+private:
+ static html* obj;
+
+public:
+ static void init()
+ {
+ obj = new html();
+ }
+
+ static html& get
+ ()
+ {
+ return *obj;
+ }
+};
+
+
+#endif
diff --git a/src/s_lang.cpp b/src/s_lang.cpp
new file mode 100644
index 0000000..fda5d2c
--- /dev/null
+++ b/src/s_lang.cpp
@@ -0,0 +1,33 @@
+/*:*
+ *: File: ./src/s_lang.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GCON_CXX
+#define GCON_CXX
+
+#include "s_lang.h"
+
+using namespace std;
+
+lang* s_lang::obj;
+
+#endif
diff --git a/src/s_lang.h b/src/s_lang.h
new file mode 100644
index 0000000..a0700e7
--- /dev/null
+++ b/src/s_lang.h
@@ -0,0 +1,51 @@
+/*:*
+ *: File: ./src/s_lang.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GLANG_H
+#define GLANG_H
+
+#include "lang.h"
+#include "s_conf.h"
+using namespace std;
+
+class s_lang
+{
+private:
+ static lang* obj;
+
+public:
+ static void init()
+ {
+ obj = new lang( s_conf::get
+ ().get_val( "LANGUAGE" ) );
+ }
+
+ static lang& get
+ ()
+ {
+ return *obj;
+ }
+};
+
+
+#endif
diff --git a/src/s_mutx.cpp b/src/s_mutx.cpp
new file mode 100644
index 0000000..74dc252
--- /dev/null
+++ b/src/s_mutx.cpp
@@ -0,0 +1,33 @@
+/*:*
+ *: File: ./src/s_mutx.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GMUT_CXX
+#define GMUT_CXX
+
+#include "s_mutx.h"
+
+using namespace std;
+
+mutx* s_mutx::obj;
+
+#endif
diff --git a/src/s_mutx.h b/src/s_mutx.h
new file mode 100644
index 0000000..d59162a
--- /dev/null
+++ b/src/s_mutx.h
@@ -0,0 +1,50 @@
+/*:*
+ *: File: ./src/s_mutx.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GMUT_H
+#define GMUT_H
+
+#include "mutx.h"
+
+using namespace std;
+
+class s_mutx
+{
+private:
+ static mutx* obj;
+
+public:
+ static void init()
+ {
+ obj = new mutx();
+ }
+
+ static mutx& get
+ ()
+ {
+ return *obj;
+ }
+};
+
+
+#endif
diff --git a/src/s_sman.cpp b/src/s_sman.cpp
new file mode 100644
index 0000000..e75d2be
--- /dev/null
+++ b/src/s_sman.cpp
@@ -0,0 +1,33 @@
+/*:*
+ *: File: ./src/s_sman.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GSMAN_CXX
+#define GSMAN_CXX
+
+#include "s_sman.h"
+
+using namespace std;
+
+sman* s_sman::obj;
+
+#endif
diff --git a/src/s_sman.h b/src/s_sman.h
new file mode 100644
index 0000000..2c019f9
--- /dev/null
+++ b/src/s_sman.h
@@ -0,0 +1,50 @@
+/*:*
+ *: File: ./src/s_sman.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GSMAN_H
+#define GSMAN_H
+
+#include "sman.h"
+
+using namespace std;
+
+class s_sman
+{
+private:
+ static sman* obj;
+
+public:
+ static void init()
+ {
+ obj = new sman();
+ }
+
+ static sman& get
+ ()
+ {
+ return *obj;
+ }
+};
+
+
+#endif
diff --git a/src/s_sock.cpp b/src/s_sock.cpp
new file mode 100644
index 0000000..99ce130
--- /dev/null
+++ b/src/s_sock.cpp
@@ -0,0 +1,33 @@
+/*:*
+ *: File: ./src/s_sock.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GSOC_CXX
+#define GSOC_CXX
+
+#include "s_sock.h"
+
+using namespace std;
+
+sock* s_sock::obj;
+
+#endif
diff --git a/src/s_sock.h b/src/s_sock.h
new file mode 100644
index 0000000..5025597
--- /dev/null
+++ b/src/s_sock.h
@@ -0,0 +1,50 @@
+/*:*
+ *: File: ./src/s_sock.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef GSOC_H
+#define GSOC_H
+
+#include "sock.h"
+
+using namespace std;
+
+class s_sock
+{
+private:
+ static sock* obj;
+
+public:
+ static void init()
+ {
+ obj = new sock();
+ }
+
+ static sock& get
+ ()
+ {
+ return *obj;
+ }
+};
+
+
+#endif
diff --git a/src/s_tool.cpp b/src/s_tool.cpp
new file mode 100644
index 0000000..8784d12
--- /dev/null
+++ b/src/s_tool.cpp
@@ -0,0 +1,162 @@
+/*:*
+ *: File: ./src/s_tool.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef s_tool_CXX
+#define s_tool_CXX
+
+#include <ctype.h>
+#include <time.h>
+#include "s_tool.h"
+
+bool
+s_tool::is_alpha_numeric( string &s_digit )
+{
+ auto const char *digit = s_digit.c_str();
+ auto int i_len = strlen( digit );
+
+ for( int i=0; i<i_len; i++ )
+ {
+ if ( ! isalnum( *digit ) )
+ return false;
+ digit++;
+ }
+
+ return true;
+}
+string
+s_tool::trim( string s_str )
+{
+ if(s_str.empty())
+ return "";
+ char c_cur=s_str[0];
+ auto int pos=0;
+ // left trim
+ while(c_cur==' ' || c_cur == '\n' || c_cur == '\r')
+ {
+ s_str.erase(pos,1);
+
+ c_cur=s_str[++pos];
+
+ }
+ // right trim
+
+ pos=s_str.size();
+ c_cur=s_str[s_str.size()];
+
+ while(c_cur==' ' || c_cur == '\n' || c_cur == '\0' || c_cur == '\r')
+ {
+ s_str.erase(pos,1);
+ c_cur=s_str[--pos];
+
+ }
+ return s_str;
+}
+
+string
+s_tool::getExtension( string s_file )
+{
+ int pos = s_file.find_last_of(".");
+ if(pos != string::npos)
+ {
+ string s_ext=s_file.substr(pos+1, s_file.size()-(pos+1));
+ for(int i = 0;i<s_ext.size();i++)
+ s_ext[i]=toupper(s_ext[i]);
+ return s_ext;
+ }
+ return "";
+}
+
+string
+s_tool::int2string( int i_num )
+{
+ char buf[64];
+ sprintf(buf, "%d", i_num);
+ return buf;
+}
+
+int
+s_tool::string2int( string s_digit )
+{
+ auto const char *digit = s_digit.c_str();
+ int result = 0;
+
+ // Convert each digit char and add into result.
+ while (*digit >= '0' && *digit <='9')
+ {
+ result = (result * 10) + (*digit - '0');
+ digit++;
+ }
+
+ // Check that there were no non-digits at end.
+ if (*digit != 0)
+ {
+ return -1;
+ }
+
+ return result;
+}
+
+long
+s_tool::unixtime()
+{
+ return (long) time( NULL );
+}
+
+
+void
+s_tool::strip_html( string *s_str )
+{
+ auto int i_pos;
+
+ if((i_pos=s_str->find("<",0))==string::npos)
+ return;
+ while(true)
+ {
+
+ s_str->replace(i_pos,1,"&lt;");
+
+ if((i_pos=s_str->find("<",0))==string::npos)
+ return;
+
+ }
+}
+
+string
+s_tool::replace( string s_string, string s_search, string s_replace )
+{
+ unsigned i_pos[2];
+
+ for ( i_pos[0] = s_string.find( s_search );
+ i_pos[0] != string::npos;
+ i_pos[0] = s_string.find( s_search, i_pos[1] ) )
+ {
+ s_string.replace( i_pos[0], s_search.length(), s_replace );
+ i_pos[1] = i_pos[0] + s_replace.length();
+ }
+
+ return s_string;
+}
+
+
+
+#endif
diff --git a/src/s_tool.h b/src/s_tool.h
new file mode 100644
index 0000000..7e811e1
--- /dev/null
+++ b/src/s_tool.h
@@ -0,0 +1,44 @@
+/*:*
+ *: File: ./src/s_tool.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef s_tool_H
+#define s_tool_H
+
+#include "incl.h"
+
+using namespace std;
+
+class s_tool
+{
+public:
+ static bool is_alpha_numeric( string &s_digit );
+ static int string2int( string s_digit );
+ static string int2string( int i_num );
+ static string trim( string s_str );
+ static long unixtime();
+ static void strip_html( string *s_str);
+ static string getExtension( string s_file );
+ static string replace( string s_string, string s_search, string s_replace );
+};
+
+#endif
diff --git a/src/sess.cpp b/src/sess.cpp
new file mode 100644
index 0000000..1b5b1e2
--- /dev/null
+++ b/src/sess.cpp
@@ -0,0 +1,62 @@
+/*:*
+ *: File: ./src/sess.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef SESS_CPP
+#define SESS_CPP
+
+#include "sess.h"
+
+sess::sess( string s_id )
+{
+ this->sess_id=s_id;
+}
+
+string sess::getId()
+{
+ return this->sess_id;
+}
+
+
+void sess::invalidate()
+{
+ this->sess_id="0";
+ this->sess_values.clear();
+}
+
+void sess::setValue( string s_key, void *lpvalue )
+{
+ this->sess_values[s_key]=lpvalue;
+}
+void *sess::getValue( string s_key )
+{
+ return this->sess_values[s_key];
+}
+string sess::dump()
+{
+ string s_ret=string("Session Dump of Session ") + this->getId();
+ map<string, void*>::const_iterator it;
+ for(it=this->sess_values.begin();it!=this->sess_values.end();it++)
+ s_ret=s_ret + "\nkey: " + it->first;
+ return s_ret;
+}
+#endif
diff --git a/src/sess.h b/src/sess.h
new file mode 100644
index 0000000..9da7fde
--- /dev/null
+++ b/src/sess.h
@@ -0,0 +1,51 @@
+/*:*
+ *: File: ./src/sess.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef s_sess_H
+#define s_sess_H
+
+#include "incl.h"
+#include "cont.h"
+#include "name.h"
+#include <map>
+#include <string>
+#include "hmap.h"
+using namespace std;
+
+typedef map<string, void *> sess_map;
+
+class sess : public cont, name
+{
+
+private:
+ sess_map sess_values;
+ string sess_id;
+public:
+ sess(string s_id);
+ string getId();
+ void setValue(string s_key, void *lpvalue);
+ void *getValue( string s_key );
+ void invalidate();
+ string dump();
+};
+#endif
diff --git a/src/sman.cpp b/src/sman.cpp
new file mode 100644
index 0000000..ed6bea2
--- /dev/null
+++ b/src/sman.cpp
@@ -0,0 +1,80 @@
+/*:*
+ *: File: ./src/sman.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef SMAN_CXX
+#define SMAN_CXX
+
+#include "sman.h"
+
+sman::sman()
+{
+ this->sessions=new hmap<sess *, string>(80);
+ this->sessioncount=0;
+}
+sman::~sman()
+{
+ delete this->sessions;
+}
+
+string sman::generateId( int len )
+{
+ string valid_chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
+ string s_ret="";
+ srand(time(0)+160682);
+ for(int i=0;i<len;i++)
+ {
+ int i_char=rand() % 64;
+ s_ret+=valid_chars[i_char];
+ }
+ return s_ret;
+}
+sess *sman::createSession( )
+{
+ string new_id=this->generateId(s_tool::string2int( s_conf::get
+ ().get_val( "SESSION_LENGTH" ) ) );
+
+ sess* p_sess = getSession(new_id);
+
+ // Prove if session id already exists.
+ if (p_sess)
+ return createSession();
+
+ sess *new_sess= new sess( new_id );
+
+ this->sessioncount++;
+ this->sessions->add_elem( new_sess, new_id );
+
+
+ return new_sess;
+}
+
+sess *sman::getSession( string s_id )
+{
+ return this->sessions->get_elem( s_id );
+}
+void sman::destroySession( string s_id )
+{
+ this->sessioncount--;
+ this->sessions->del_elem( s_id );
+}
+#endif
diff --git a/src/sman.h b/src/sman.h
new file mode 100644
index 0000000..3ce0ee9
--- /dev/null
+++ b/src/sman.h
@@ -0,0 +1,59 @@
+/*:*
+ *: File: ./src/sman.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+#ifndef SMAN_H
+#define SMAN_H
+
+#include "incl.h"
+#include "hmap.h"
+#include "sess.h"
+#include "s_tool.h"
+#include "s_conf.h"
+#include <cstdlib>
+
+using namespace std;
+
+class sman
+{
+
+private:
+ hmap<sess *, string> *sessions;
+ string generateId( int len );
+ int sessioncount;
+public:
+ sman();
+ ~sman();
+ sess *getSession( string s_id );
+ int getSessionCount( )
+ {
+ return this->sessioncount;
+ }
+ sess *createSession( );
+ void destroySession( string s_id );
+
+
+};
+
+
+#endif
+
diff --git a/src/sock.cpp b/src/sock.cpp
new file mode 100644
index 0000000..5f85d02
--- /dev/null
+++ b/src/sock.cpp
@@ -0,0 +1,263 @@
+/*:*
+ *: File: ./src/sock.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class sock implementation. the multiplex socket implementation has been token from the
+// GNU C Library Examples and modified in order to fit in here ( POSIX threads etc. ).
+
+#ifndef s_sock_CXX
+#define s_sock_CXX
+
+#include <unistd.h>
+
+#include "sock.h"
+#include "s_chat.h"
+#include "s_conf.h"
+#include "s_mutx.h"
+#include "s_tool.h"
+#include "s_lang.h"
+#include "s_sman.h"
+#include "chat.h"
+#include "user.h"
+
+using namespace std;
+
+sock::sock()
+{
+ this->b_run = true;
+ this->i_req = 0;
+ this->req_parser = new reqp();
+ this->thrd_pool = new pool();
+}
+
+void
+sock::chat_stream( int i_sock, user* p_user, map_string &map_params )
+{
+ string s_msg( "\n" );
+
+ pthread_mutex_lock ( &(p_user->mut_message) );
+
+ for ( int i = 0; i < PUSHSTR; i++ )
+ send( i_sock, s_msg.c_str(), s_msg.size(), 0 );
+
+ do
+ {
+ s_msg = p_user->get_mess( );
+ if ( 0 > send( i_sock, s_msg.c_str(), s_msg.size(), 0 ) )
+ p_user->set_online( false );
+ pthread_cond_wait( &(p_user->cond_message), &(p_user->mut_message) );
+ }
+ while( p_user->get_online() );
+
+ // if there is still a message to send:
+ s_msg = p_user->get_mess( );
+ if ( ! s_msg.empty() )
+ send( i_sock, s_msg.c_str(), s_msg.size(), 0 );
+
+ pthread_mutex_unlock( &(p_user->mut_message) );
+
+ // remove the user from its room.
+ string s_user( p_user->get_name() );
+ p_user->get_p_room()->del_elem( s_user );
+
+ // post the room that the user has left the chat.
+ p_user->get_p_room()->msg_post( new string( p_user->get_name().append( s_lang::get
+ ().get_val( "USERLEAV" ) ) ) );
+ s_sman::get
+ ().destroySession( p_user->get_id() );
+#ifdef VERBOSE
+
+ cout << s_user << " left | SessionCount: " << s_sman::get
+ ().getSessionCount() << endl;
+#endif
+
+ p_user->~user();
+}
+
+int
+sock::make_socket( uint16_t i_port )
+{
+ int sock;
+ struct sockaddr_in name;
+
+ // create the server socket.
+ sock = socket (PF_INET, SOCK_STREAM, 0);
+ if (sock < 0)
+ {
+ cerr << "Sock: socket error" << endl;
+
+ if ( ((int)++i_port) > MAXPORT )
+ exit(-1);
+
+ cerr << SOCKERR << i_port << endl;
+ return make_socket( i_port );
+ }
+
+ // give the server socket a name.
+ name.sin_family = AF_INET;
+ name.sin_port = htons (i_port);
+ name.sin_addr.s_addr = htonl (INADDR_ANY);
+ int optval=1;
+
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(int));
+
+ if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
+ {
+ cerr << "Sock: bind error" << endl;
+
+ if ( ++i_port > MAXPORT )
+ exit(-1);
+
+ cout << SOCKERR << i_port << endl;
+ return make_socket( i_port );
+ }
+
+ return sock;
+}
+
+int
+sock::read_write( thrd* p_thrd, int i_sock )
+{
+ char c_req[2048];
+
+ int i_bytes;
+ i_bytes = read (i_sock, c_req, 2048);
+
+ if (i_bytes < 0)
+ {
+ cerr << "Sock: read error " << endl;
+ }
+
+ else
+ {
+ // stores the request params.
+ map_string map_params;
+
+ // get the s_rep ( s_html response which will be send imediatly to the client
+ // and fill map_params with request values.
+ auto string s_temp=(string)c_req;
+ struct sockaddr_in client;
+ size_t size=sizeof(client);
+
+ getpeername( i_sock, (struct sockaddr *)&client, &size);
+
+ map_params["REMOTE_ADDR"]=inet_ntoa(client.sin_addr);
+ map_params["REMOTE_PORT"]=ntohs( client.sin_port);
+
+
+ string s_rep = req_parser->parse( p_thrd, string( c_req ), map_params );
+ send( i_sock, s_rep.c_str(), s_rep.size(), 0 );
+
+ // dont need those vals anymore.
+ map_params.clear();
+
+ return 0;
+ }
+
+ return -1;
+}
+
+int
+sock::start()
+{
+ auto int i_port = s_tool::string2int( s_conf::get
+ ().get_val( "SRVRPORT" ) );
+
+ int sock;
+ fd_set active_fd_set, read_fd_set;
+ int i;
+ struct sockaddr_in clientname;
+ size_t size;
+
+#ifdef VERBOSE
+
+ cout << SOCKCRT << "localhost:" << i_port << endl;
+#endif
+
+ // create the server socket and set it up to accept connections.
+ sock = make_socket ( i_port );
+
+ if (listen (sock, 1) < 0)
+ {
+ cerr << "Sock: listen error" << endl;
+ exit( EXIT_FAILURE );
+ }
+
+#ifdef VERBOSE
+ cout << SOCKRDY << endl;
+#endif
+
+ // initialize the set of active sockets.
+ FD_ZERO (&active_fd_set);
+ FD_SET (sock, &active_fd_set);
+
+ while( b_run )
+ {
+ // block until input arrives on one or more active sockets.
+ read_fd_set = active_fd_set;
+ if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0)
+ {
+ cerr << "Sock: select error" << endl;
+ exit( EXIT_FAILURE );
+ }
+
+ // service all the sockets with input pending.
+ for ( i = 0; i < FD_SETSIZE; i++ )
+ if ( FD_ISSET (i, &read_fd_set) )
+ {
+ if ( i == sock )
+ {
+ // connection request on original socket.
+ i_req++;
+ int new_sock;
+ size = sizeof (clientname);
+ new_sock = accept (sock,
+ (struct sockaddr *) &clientname,
+ &size);
+
+ if (new_sock < 0)
+ {
+ cerr << "Sock: accept error" << endl;
+ close ( new_sock );
+ }
+
+#ifdef VERBOSE
+ cout << CONNECT << i_req << " "
+ << inet_ntoa( clientname.sin_addr )
+ << ":"
+ << ntohs ( clientname.sin_port )
+ << endl;
+#endif
+
+ FD_SET (new_sock, &active_fd_set);
+ }
+
+ else
+ {
+ thrd_pool->run( (void*) new thrd( i ) );
+ FD_CLR( i, &active_fd_set );
+ }
+ }
+ }
+}
+
+#endif
diff --git a/src/sock.h b/src/sock.h
new file mode 100644
index 0000000..73614bd
--- /dev/null
+++ b/src/sock.h
@@ -0,0 +1,80 @@
+/*:*
+ *: File: ./src/sock.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class sock declaration.
+
+#ifndef s_sock_H
+#define s_sock_H
+
+#include <queue>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include "incl.h"
+#include "pool.h"
+#include "reqp.h"
+#include "thrd.h"
+#include "user.h"
+using namespace std;
+
+class sock
+{
+private:
+ // total number of server requests.
+ unsigned long long int i_req;
+
+ bool b_run; // true while socket manager is running.
+ reqp* req_parser; // parses the http requests from clients.
+ pool* thrd_pool; // the thread pool.
+ // creates a server socket.
+ virtual int make_socket( uint16_t port );
+
+public:
+ // small inline methods:
+ bool get_run() const
+ {
+ return b_run;
+ }
+ bool set_run( bool b_run )
+ {
+ this->b_run = b_run;
+ }
+
+ // public methods.
+ explicit sock( ); // simple constructor.
+ virtual int read_write( thrd* p_thrd, int filedes );
+ virtual int start();
+
+ // the chat stream there all the chat messages will sent through.
+ static void chat_stream( int i_sock, user* p_user, map_string &map_params );
+
+};
+
+#endif
diff --git a/src/thrd.cpp b/src/thrd.cpp
new file mode 100644
index 0000000..6c53393
--- /dev/null
+++ b/src/thrd.cpp
@@ -0,0 +1,52 @@
+/*:*
+ *: File: ./src/thrd.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class thrd implementation.
+
+#ifndef THRD_CXX
+#define THRD_CXX
+
+#include "thrd.h"
+#include "s_sock.h"
+
+using namespace std;
+
+thrd::thrd( int i_sock )
+{
+ this->i_sock = i_sock;
+}
+
+thrd::~thrd()
+{
+ shutdown ( get_sock() , 2 );
+ close ( get_sock() );
+}
+
+void
+thrd::run()
+{
+ s_sock::get
+ ().read_write( this, i_sock );
+}
+
+#endif
diff --git a/src/thrd.h b/src/thrd.h
new file mode 100644
index 0000000..3520db2
--- /dev/null
+++ b/src/thrd.h
@@ -0,0 +1,52 @@
+/*:*
+ *: File: ./src/thrd.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class thrd declaration.
+
+#ifndef THRD_H
+#define THRD_H
+
+#include "incl.h"
+
+using namespace std;
+
+class thrd
+{
+private:
+ int i_sock;
+
+public:
+
+ // small inline methods:
+ int get_sock()
+ {
+ return i_sock;
+ }
+
+ // public methods:
+ explicit thrd( int i_sock );
+ ~thrd(); // destructor.
+ virtual void run();
+};
+
+#endif
diff --git a/src/user.cpp b/src/user.cpp
new file mode 100644
index 0000000..6ca8cdd
--- /dev/null
+++ b/src/user.cpp
@@ -0,0 +1,167 @@
+/*:*
+ *: File: ./src/user.cpp
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class user implementation.
+
+#ifndef USER_CXX
+#define USER_CXX
+
+#include "user.h"
+#include "s_conf.h"
+#include "s_tool.h"
+
+using namespace std;
+
+user::user( string s_name ) : name( s_name )
+{
+ this -> b_online = true;
+ this -> l_time = s_tool::unixtime();
+ this -> s_col1 = s_conf::get
+ ().get_val( "USERCOL1" );
+
+ pthread_mutex_init( &mut_b_online, NULL);
+ pthread_mutex_init( &mut_i_sock , NULL);
+ pthread_mutex_init( &mut_l_time , NULL);
+ pthread_mutex_init( &mut_p_room , NULL);
+ pthread_mutex_init( &mut_s_mess , NULL);
+ pthread_cond_init ( &cond_message, NULL);
+ pthread_mutex_init( &mut_message , NULL);
+}
+
+user::~user()
+{
+ pthread_mutex_destroy( &mut_b_online );
+ pthread_mutex_destroy( &mut_i_sock );
+ pthread_mutex_destroy( &mut_l_time );
+ pthread_mutex_destroy( &mut_p_room );
+ pthread_mutex_destroy( &mut_s_mess );
+ pthread_cond_destroy ( &cond_message );
+ pthread_mutex_destroy( &mut_message );
+}
+
+void
+user::get_data( map_string *p_map_data )
+{
+ string s_req = (*p_map_data)["!get"];
+
+ // get the nick and the color of the user.
+ if ( s_req == "nick" )
+ (*p_map_data)[get_name()] = get_col1();
+}
+
+string
+user::get_mess( )
+{
+ string s_ret( "" );
+ pthread_mutex_lock ( &mut_s_mess );
+ s_ret.append( s_mess );
+ s_mess = *new string("");
+ pthread_mutex_unlock( &mut_s_mess );
+
+ return s_ret;
+}
+
+bool
+user::get_online( )
+{
+ bool b_ret;
+ pthread_mutex_lock ( &mut_b_online );
+ b_ret = b_online;
+ pthread_mutex_unlock( &mut_b_online );
+ return b_ret;
+}
+
+void
+user::set_online( bool b_online )
+{
+ pthread_mutex_lock ( &mut_b_online );
+ this -> b_online = b_online;
+ pthread_mutex_unlock( &mut_b_online );
+}
+
+room*
+user::get_p_room( )
+{
+ room* p_return;
+ pthread_mutex_lock ( &mut_p_room );
+ p_return = p_room;
+ pthread_mutex_unlock( &mut_p_room );
+ return p_return;
+}
+
+void
+user::set_p_room( room* p_room )
+{
+ pthread_mutex_lock ( &mut_p_room );
+ this -> p_room = p_room;
+ pthread_mutex_unlock( &mut_p_room );
+}
+
+int
+user::get_sock( )
+{
+ int i_ret;
+ pthread_mutex_lock ( &mut_i_sock );
+ i_ret = i_sock;
+ pthread_mutex_unlock( &mut_i_sock );
+ return i_ret;
+}
+
+void
+user::set_sock( int i_sock )
+{
+ pthread_mutex_lock ( &mut_i_sock );
+ this -> i_sock = i_sock;
+ pthread_mutex_unlock( &mut_i_sock );
+}
+
+void
+user::renew_stamp( )
+{
+ pthread_mutex_lock ( &mut_l_time );
+ l_time = s_tool::unixtime();
+ pthread_mutex_unlock( &mut_l_time );
+}
+
+void
+user::msg_post( string *p_msg )
+{
+ pthread_mutex_lock ( &mut_s_mess );
+ s_mess.append( *p_msg );
+ pthread_mutex_unlock( &mut_s_mess );
+
+ pthread_cond_signal( &cond_message );
+}
+
+void
+user::get_user_list( string &s_list, string &s_seperator )
+{
+ s_list.append( "<font color=\"" )
+ .append( get_col1() )
+ .append( "\">" )
+ .append( get_name() )
+ .append( "</font>\n" )
+ .append( s_seperator );
+
+}
+#endif
diff --git a/src/user.h b/src/user.h
new file mode 100644
index 0000000..9877642
--- /dev/null
+++ b/src/user.h
@@ -0,0 +1,125 @@
+/*:*
+ *: File: ./src/user.h
+ *:
+ *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
+ *:
+ *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
+ *: 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.
+ *:*/
+
+// class user declaration.
+#ifndef USER_H
+#define USER_H
+
+#include "incl.h"
+#include "hmap.h"
+#include "name.h"
+#include "s_lang.h"
+using namespace std;
+
+class room;
+
+class user : public name
+{
+private:
+ // private members:
+ bool b_away; // true if user is away.
+ bool b_online; // true if user is online.
+ int i_sock; // user's stream socket descriptor.
+ long l_time; // user's last activity time.
+ rang r_rang; // user's rang ( see enum rang @ globals.h ).
+ rang r_oldr; // user's previous rang.
+ string s_id;
+ string s_agnt; // user's http user agent.
+ string s_away; // user's last away message.
+ string s_col1; // user's nick color.
+ string s_mess; // message string which has to be sent to the user.
+ room* p_room; // pointer to the user's room.
+
+ pthread_mutex_t mut_b_online;
+ pthread_mutex_t mut_i_sock;
+ pthread_mutex_t mut_l_time;
+ pthread_mutex_t mut_s_mess;
+ pthread_mutex_t mut_p_room;
+
+public:
+ pthread_cond_t cond_message;
+ pthread_mutex_t mut_message;
+
+ // small inline methods:
+ string get_col1() const
+ {
+ return s_col1;
+ }
+ string get_id() const
+ {
+ return s_id;
+ }
+ void set_id ( string s_id )
+ {
+ this -> s_id = s_id;
+ }
+ void set_col1 ( string s_col1 )
+ {
+ this -> s_col1 = s_col1;
+ }
+
+ rang get_rang ( ) const
+ {
+ return r_rang;
+ }
+ void set_rang ( rang r_rang )
+ {
+ r_oldr = this -> r_rang;
+ this -> r_rang = r_rang;
+ }
+
+ bool new_msgs ( )
+ {
+ return s_mess.empty();
+ }
+ // public methods:
+ explicit user( string s_name ); // a standard constructor.
+ ~user(); // user destructor.
+
+ // gets specific data of this user und stores it in
+ // (*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.
+ virtual void get_data( map_string *p_map_data );
+
+ virtual bool get_online();
+ virtual void set_online( bool b_online );
+ virtual room* get_p_room();
+ virtual void set_p_room( room* p_room );
+ virtual int get_sock ( );
+ virtual void set_sock ( int i_sock );
+
+ // gets the message and clears s_mess;
+ virtual string get_mess();
+
+ // actualizes the user's timestamp.
+ virtual void renew_stamp();
+
+ // Here are starting methods which are mainly needed by the data<type> class.
+
+ // appends a string to s_mess including br.
+ virtual void msg_post( string *p_msg );
+ virtual void get_user_list( string &s_list, string &s_seperator );
+};
+
+#endif