From ed634bc556af8997b9d2d5bf7334073731936365 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:45 +0200 Subject: tagging ychat-0.2 --- CHAT.cpp | 0 CHAT.h | 0 CONF.cpp | 0 CONF.h | 0 HTML.cpp | 0 HTML.h | 0 MUTX.cpp | 0 MUTX.h | 0 Makefile | 107 ++++---------------------------- README.txt | 18 ++++-- SOCK.cpp | 0 SOCK.h | 0 TOOL.cpp | 0 TOOL.h | 0 base.cpp | 37 ----------- base.h | 0 chat.cpp | 30 --------- chat.h | 0 cmnd.cpp | 10 --- cmnd.h | 0 conf.cpp | 10 --- conf.h | 0 conf.txt | 3 +- cont.cpp | 11 ---- cont.h | 0 data.h | 0 gfx/CVS/Root | 2 +- gfx/y_ani_black.gif | Bin gfx/y_ani_white.gif | Bin glob.h | 10 --- html.cpp | 26 -------- html.h | 1 + html/CVS/Entries | 10 ++- html/CVS/Root | 2 +- html/frameset.html | 12 ++-- html/index.html | 63 ++++++------------- html/input.html | 48 +++------------ html/notfound.html | 4 +- html/online.html | 18 +----- html/stream.html | 43 ++++++------- html/y_ani.gif | Bin incl.h | 1 - main.cpp | 6 +- msgs.h | 11 ++-- mutx.cpp | 8 --- mutx.h | 0 name.cpp | 24 -------- name.h | 0 pool.cpp | 46 +++++++------- reqp.cpp | 145 ++++++++++++++++++++++++++++++------------- reqp.h | 11 +++- room.cpp | 11 ---- room.h | 0 sock.cpp | 172 +++++++--------------------------------------------- sock.h | 18 ++---- thrd.cpp | 21 +------ thrd.h | 0 todo.txt | 0 user.cpp | 92 +++++++--------------------- user.h | 7 ++- 60 files changed, 284 insertions(+), 754 deletions(-) mode change 100644 => 100755 CHAT.cpp mode change 100644 => 100755 CHAT.h mode change 100644 => 100755 CONF.cpp mode change 100644 => 100755 CONF.h mode change 100644 => 100755 HTML.cpp mode change 100644 => 100755 HTML.h mode change 100644 => 100755 MUTX.cpp mode change 100644 => 100755 MUTX.h mode change 100644 => 100755 README.txt mode change 100644 => 100755 SOCK.cpp mode change 100644 => 100755 SOCK.h mode change 100644 => 100755 TOOL.cpp mode change 100644 => 100755 TOOL.h mode change 100644 => 100755 base.cpp mode change 100644 => 100755 base.h mode change 100644 => 100755 chat.cpp mode change 100644 => 100755 chat.h mode change 100644 => 100755 cmnd.cpp mode change 100644 => 100755 cmnd.h mode change 100644 => 100755 conf.cpp mode change 100644 => 100755 conf.h mode change 100644 => 100755 conf.txt mode change 100644 => 100755 cont.cpp mode change 100644 => 100755 cont.h mode change 100644 => 100755 data.h mode change 100644 => 100755 gfx/y_ani_black.gif mode change 100644 => 100755 gfx/y_ani_white.gif mode change 100644 => 100755 glob.h mode change 100644 => 100755 html.cpp mode change 100644 => 100755 html.h mode change 100644 => 100755 html/y_ani.gif mode change 100644 => 100755 incl.h mode change 100644 => 100755 main.cpp mode change 100644 => 100755 msgs.h mode change 100644 => 100755 mutx.cpp mode change 100644 => 100755 mutx.h mode change 100644 => 100755 name.cpp mode change 100644 => 100755 name.h mode change 100644 => 100755 reqp.cpp mode change 100644 => 100755 reqp.h mode change 100644 => 100755 room.cpp mode change 100644 => 100755 room.h mode change 100644 => 100755 sock.cpp mode change 100644 => 100755 sock.h mode change 100644 => 100755 thrd.cpp mode change 100644 => 100755 thrd.h mode change 100644 => 100755 todo.txt mode change 100644 => 100755 user.cpp mode change 100644 => 100755 user.h diff --git a/CHAT.cpp b/CHAT.cpp old mode 100644 new mode 100755 diff --git a/CHAT.h b/CHAT.h old mode 100644 new mode 100755 diff --git a/CONF.cpp b/CONF.cpp old mode 100644 new mode 100755 diff --git a/CONF.h b/CONF.h old mode 100644 new mode 100755 diff --git a/HTML.cpp b/HTML.cpp old mode 100644 new mode 100755 diff --git a/HTML.h b/HTML.h old mode 100644 new mode 100755 diff --git a/MUTX.cpp b/MUTX.cpp old mode 100644 new mode 100755 diff --git a/MUTX.h b/MUTX.h old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile index 27a8d90..7506171 100755 --- a/Makefile +++ b/Makefile @@ -1,95 +1,12 @@ -MAKE=`tail -n 1 make.version` -PREFIX=`grep "define PREFIX" src/glob.h | cut -d'"' -f2` -all: version base modules - @echo "Now edit the ychat.conf and run ychat!" - @echo "The config file is searched in the following order:" - @echo " ./ychat.conf " - @echo " ~/.ychat/ychat.conf " - @echo " ./etc/ychat.conf " - @echo " /etc/ychat.conf " - @echo " $(PREFIX)/etc/ychat.conf " - @echo If you want to help the yChat project please run gmake mail - @echo so that the developers receive an email about the platform - @echo being used. - @echo WARNING! This software is EXPERIMENTAL! -mail: - @echo "VERSION:" > mail.tmp - @${MAKE} version >> mail.tmp - @echo >> mail.tmp - @echo "UNAME:" >> mail.tmp - @uname -a >> mail.tmp - @echo >> mail.tmp - @echo "DATE:" >> mail.tmp - @date >> mail.tmp - @echo >> mail.tmp - @echo "COMPILER AND MAKE:" >> mail.tmp - @cat g++.version make.version >> mail.tmp - @cat mail.tmp | mail -s "Successfull build of yChat" successfullbuild@yhttpd.org - @rm -f mail.tmp -install: deinstall -uninstall: deinstall -deinstall: - @echo Install/deinstall is not supported! - @echo Start yChat with ./bin/ychat instead! - @exit 1 -modules: - @if test -d ./src/mods; then ${MAKE} -C ./src/mods; fi -clean_modules: - @if test -d ./src/mods; then ${MAKE} -C ./src/mods clean; fi -base: - @if test -f bin/ychat; then echo "Backing up old binary";if test -f bin/ychat.old; then rm -f bin/ychat.old; fi; mv bin/ychat bin/ychat.old; fi - @perl ./scripts/buildnr.pl - @perl ./scripts/setglobvals.pl - @${MAKE} -C ./src -clean_base: - @${MAKE} -C ./src clean -stats: - @perl scripts/stats.pl -run: - ./bin/ychat -base_start: base - ./bin/ychat -gpl: - @more COPYING -#//<<* -yhttpdbase: - @perl scripts/makeyhttpd.pl || echo "You need to have perl to do this!" - @echo yhttpd code base has been generated in ../yhttpd -#//*>> -clean: clean_base clean_modules -help: - @echo "You may run ${MAKE} with the following parameters:" - @grep "^ ${MAKE} " README - @echo "For more questions read the README file or contact mail@ychat.org!" -setup: - @./configure - @${MAKE} -config: - @sh -c "scripts/config.sh" - @echo If you run ${MAKE} config from the command line then you may need - @echo to rerun ./configure and recompile all now! - -mrproper: clean - @if test -f src/glob.h.org; then mv -f src/glob.h.org src/glob.h;fi - @if test -f g++.version; then rm -f g++.version; fi - @if test -f make.version; then rm -f make.version; fi - @if test -f src/Makefile; then rm -f src/Makefile; fi - @if test -f bin/ychat; then find bin/ -name "*ychat*" | xargs rm -f; fi - @if test -d src/mods; then find src/mods/*/ -name Makefile | xargs rm -f; fi - @find . -name "*.add" | xargs rm -f - @ls | grep core | xargs rm -f -version: - @./scripts/version.sh -debug: - @gdb bin/ychat ychat.core -confdebug: - ./configure -g3 -ggdb -dist: - @./scripts/makedist.sh -ssltest: - openssl genrsa -des3 -out privkey.pem 2048 - openssl req -new -x509 -key privkey.pem -out cert.pem -days 1095 - @mv -f privkey.pem cert.pem etc - - - +SRCS=base.cpp chat.cpp CHAT.cpp cmnd.cpp conf.cpp CONF.cpp cont.cpp html.cpp HTML.cpp main.cpp mutx.cpp MUTX.cpp name.cpp pool.cpp reqp.cpp room.cpp sock.cpp SOCK.cpp thrd.cpp TOOL.cpp user.cpp +OBJS=$(SRCS:.cpp=.o) +CC=c++ +LDFLAGS=-lstdc++ -g +LDADD=-pthread -D_THREAD_SAFE +all: ychat +$(SRCS): + $(CC) $(CFLAGS) -c $*.cpp +ychat: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) +clean: + rm *.o diff --git a/README.txt b/README.txt old mode 100644 new mode 100755 index e68c165..af513e8 --- a/README.txt +++ b/README.txt @@ -1,5 +1,5 @@ -yChat++; Version Basic 0.1b (030320); Homepage: www.yChat.org -Copyright (C) 2003 Paul C. Buetow ( Snooper@yChat.org, ICQ: 11655527 ) +yChat++; Homepage: www.yChat.org; Version 0.2 +Copyright (C) 2003 Paul C. Buetow, Volker Richter ----------------------------------------------------------------- This program is free software; you can redistribute it and/or @@ -58,6 +58,10 @@ base.cpp - Encapsulates vector fields of room's or user ( may be later main.cpp - This includes the required manager headers for starting the server and finally regulates the correct starting. +pool.cpp - The implementation of the thread pool. all threads are stored + in a queue. Each thread will be reused if the assigned job is + finished. + reqp.cpp - This class implements the http request parser. If a client starts a request to the server the reqp class will be invoked. @@ -163,7 +167,11 @@ chat room user / \ conf html -History of lines of code ( including embedded comments ): +Version Lines of code + 0.1 2402 + 0.2 2377 -Version: Lines: - Basic 0.1b 2402 +New in 0.2: + - POST request now work. + - Thread pool ( pool.cpp ). + - Bugfixes diff --git a/SOCK.cpp b/SOCK.cpp old mode 100644 new mode 100755 diff --git a/SOCK.h b/SOCK.h old mode 100644 new mode 100755 diff --git a/TOOL.cpp b/TOOL.cpp old mode 100644 new mode 100755 diff --git a/TOOL.h b/TOOL.h old mode 100644 new mode 100755 diff --git a/base.cpp b/base.cpp old mode 100644 new mode 100755 index 553d090..9a67340 --- a/base.cpp +++ b/base.cpp @@ -4,39 +4,20 @@ #define BASE_CPP #include "base.h" -#include "MUTX.h" base::base() { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "base::base()" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - pthread_mutex_init (&mut_vec_elem, NULL ); } base::~base( ) { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "base::~base( )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - pthread_mutex_destroy( &mut_vec_elem ); } void base::add_elem( name* p_name ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "base::add_elem( name* )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - pthread_mutex_lock ( &mut_vec_elem ); vec_elem.push_back ( p_name ); pthread_mutex_unlock( &mut_vec_elem ); @@ -45,12 +26,6 @@ base::add_elem( name* p_name ) bool base::del_elem( string &s_name ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "base::del_elem( \"" << s_name << "\" )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - vector::iterator iter; pthread_mutex_lock ( &mut_vec_elem ); @@ -73,12 +48,6 @@ base::del_elem( string &s_name ) name* base::get_elem( string &s_name, bool &b_found ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "base:get_elem( \"" << s_name << "\", bool )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - vector::iterator iter; pthread_mutex_lock ( &mut_vec_elem ); @@ -104,12 +73,6 @@ base::get_elem( string &s_name, bool &b_found ) void base::run_func( void (*func)(name*, void*), void* v_arg ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "base:run_func( void (*func)(name*, void*), void* )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - vector::iterator iter; pthread_mutex_lock ( &mut_vec_elem ); diff --git a/base.h b/base.h old mode 100644 new mode 100755 diff --git a/chat.cpp b/chat.cpp old mode 100644 new mode 100755 index 301739e..7b0ccd2 --- a/chat.cpp +++ b/chat.cpp @@ -11,17 +11,10 @@ using namespace std; chat::chat( ) { -#ifdef VERBOSE - cout << "chat::chat()" << endl; -#endif - } chat::~chat( ) { -#ifdef VERBOSE - cout << "chat::~chat()" << endl; -#endif } user* @@ -34,12 +27,6 @@ chat::get_user( string &s_user ) user* chat::get_user( string &s_user, bool &b_found ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "chat::get_user( " << s_user << ", bool& )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - container param; param.elem[0] = (void*) &s_user ; @@ -56,11 +43,6 @@ chat::get_user( string &s_user, bool &b_found ) void chat::get_user_( name *name_obj, void *v_arg ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "chat::get_user_( name *name_obj, void *v_arg )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif container* param = (container*) v_arg; room *room_obj = static_cast(name_obj); param->elem[2] = (void*)room_obj->get_elem( *((string*)param->elem[0]), *((bool*)param->elem[1]) ); @@ -69,12 +51,6 @@ chat::get_user_( name *name_obj, void *v_arg ) void chat::login( map_string &map_params ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "chat::login( map_params )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - string s_user = map_params["nick"]; // prove if nick is empty @@ -131,12 +107,6 @@ chat::login( map_string &map_params ) void chat::post( user* u_user, map_string &map_params ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "chat::post( user* u_user, map_string &map_params )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - string s_msg( "get_col1() ) .append( "\">" ) diff --git a/chat.h b/chat.h old mode 100644 new mode 100755 diff --git a/cmnd.cpp b/cmnd.cpp old mode 100644 new mode 100755 index d6efc23..9ab008a --- a/cmnd.cpp +++ b/cmnd.cpp @@ -10,20 +10,10 @@ using namespace std; cmnd::cmnd( ) { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "cmnd::cmnd( )" << cout; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif } cmnd::~cmnd() { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "cmnd::~cmnd( )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif } #endif diff --git a/cmnd.h b/cmnd.h old mode 100644 new mode 100755 diff --git a/conf.cpp b/conf.cpp old mode 100644 new mode 100755 index 2c7705e..5214edb --- a/conf.cpp +++ b/conf.cpp @@ -10,26 +10,16 @@ using namespace std; conf::conf( string s_conf = CONFILE ) : name( s_conf ) { -#ifdef VERBOSE - cout << "conf::conf()" << endl; -#endif - parse( ); // parse the config file. } conf::~conf() { -#ifdef VERBOSE - cout << "conf::~conf()" << endl; -#endif } void conf::parse() { -#ifdef VERBOSE_ - cout << "conf::parse()" << endl; -#endif #ifdef _VERBOSE cout << CFILEOK << get_name() << endl; #endif diff --git a/conf.h b/conf.h old mode 100644 new mode 100755 diff --git a/conf.txt b/conf.txt old mode 100644 new mode 100755 index c8d4ba7..c31c554 --- a/conf.txt +++ b/conf.txt @@ -17,8 +17,9 @@ # server specific configurations ( not allowed to be removed ): HTMLTEMP="html/"; # directory of the html-template files. -THRDPOOL="100"; # thread pool size. every time all threads are used so many new +THRDPOOL="10"; # thread pool size. every time all threads are used so many new # threads will be added to the pool. +THRDQUEU="100"; # length of the thread pool queue. SRVRPORT="2000"; # local port on which the server listens. STRDROOM="Lounge"; # the name of the standard room. diff --git a/cont.cpp b/cont.cpp old mode 100644 new mode 100755 index e650d34..91cbbca --- a/cont.cpp +++ b/cont.cpp @@ -11,11 +11,6 @@ using namespace std; string cont::get_val( string s_key ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "cont::get_val( \"" << s_key << "\" )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif if ( map_vals.find( s_key ) != map_vals.end() ) return map_vals[ s_key ]; return string(); @@ -23,12 +18,6 @@ cont::get_val( string s_key ) cont::~cont() { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "cont::cont()" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - map_vals.~map_string(); } diff --git a/cont.h b/cont.h old mode 100644 new mode 100755 diff --git a/data.h b/data.h old mode 100644 new mode 100755 diff --git a/gfx/CVS/Root b/gfx/CVS/Root index 4ab853d..6de547b 100644 --- a/gfx/CVS/Root +++ b/gfx/CVS/Root @@ -1 +1 @@ -:pserver:volker@cvs.exa-ds.com:/home/cvsroot +:pserver:paul@internal.ath.cx:/home/cvsroot diff --git a/gfx/y_ani_black.gif b/gfx/y_ani_black.gif old mode 100644 new mode 100755 diff --git a/gfx/y_ani_white.gif b/gfx/y_ani_white.gif old mode 100644 new mode 100755 diff --git a/glob.h b/glob.h old mode 100644 new mode 100755 index f48f3c0..37741f8 --- a/glob.h +++ b/glob.h @@ -21,20 +21,10 @@ // max length of a line read from a socket or a file ( config-file, html-template ). #define READBUF 1024 -// if defined for every http request a new thread will be created. otherwise only for the -// chat streams extra threads will be created. THRDMOD2 DOES NOT WORK RIGHT NOW!! SO -// LET THIS DEFINE UNTOUCHED! BUGFIX WILL FOLLOW! -#define THRDMOD - // definition for verbosity level 0 ( normal outputs ). see vmsg.h for custumizing all // the messages. this messages will only printed out by the master thread. #define _VERBOSE -// definition for verbosity level 1 ( constructors and destructors which are not inline ). -//#define VERBOSE - -// definition for verbosity level 2 ( all methods which are not inline except VERBOSE 1 ). -//#define VERBOSE_ ////////////////////////////////////////////////////////////////////////////////////////// // DO NOT CHANGE ANYTHING BEHIND THIS LINE! diff --git a/html.cpp b/html.cpp old mode 100644 new mode 100755 index 2e6b977..ad0de08 --- a/html.cpp +++ b/html.cpp @@ -12,25 +12,12 @@ using namespace std; html::html( ) { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "html::html()" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - set_name( CONF::get().get_val( "HTMLTEMP" ) ); - pthread_mutex_init( &mut_map_vals, NULL ); } html::~html( ) { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "html::~html()" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - pthread_mutex_destroy( &mut_map_vals ); } @@ -45,13 +32,6 @@ html::clear_cache( ) string html::parse( map_string &map_params ) { - -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "html::parse( map_string& )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - string s_file = map_params["request"]; // check if s_file is in the container. @@ -132,12 +112,6 @@ html::parse( map_string &map_params ) void html::online_list( user *p_user, map_string &map_params ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "html::online_list( user*, map_string& )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - // prepare user_list. string s_list ( "" ); string s_seperator( "
" ); diff --git a/html.h b/html.h old mode 100644 new mode 100755 index 97b5b67..9acf5a9 --- a/html.h +++ b/html.h @@ -9,6 +9,7 @@ #include "user.h" #include "name.h" + using namespace std; class html : public cont, name diff --git a/html/CVS/Entries b/html/CVS/Entries index 12eb550..6738646 100644 --- a/html/CVS/Entries +++ b/html/CVS/Entries @@ -1,11 +1,9 @@ /blank.html/1.1.1.1/Fri Mar 21 15:54:56 2003// /frameset.html/1.1.1.1/Fri Mar 21 15:54:56 2003// -/index.html/1.4/Sun Mar 30 00:34:08 2003// -/input.html/1.2/Sun Mar 30 00:34:08 2003// +/index.html/1.2/Sun Mar 23 19:03:13 2003// +/input.html/1.1.1.1/Fri Mar 21 15:54:56 2003// /notfound.html/1.1.1.1/Fri Mar 21 15:54:56 2003// -/online.html/1.2/Sun Mar 30 00:34:08 2003// -/stream.html/1.2/Sun Mar 30 00:34:08 2003// -/style.css/1.1/Sun Mar 30 11:12:49 2003// +/online.html/1.1.1.1/Fri Mar 21 15:54:56 2003// +/stream.html/1.1.1.1/Fri Mar 21 15:54:56 2003// /y_ani.gif/1.1.1.1/Fri Mar 21 15:54:56 2003// -/y_black.gif/1.1/Sun Mar 30 11:12:49 2003/-kb/ D diff --git a/html/CVS/Root b/html/CVS/Root index 4ab853d..6de547b 100644 --- a/html/CVS/Root +++ b/html/CVS/Root @@ -1 +1 @@ -:pserver:volker@cvs.exa-ds.com:/home/cvsroot +:pserver:paul@internal.ath.cx:/home/cvsroot diff --git a/html/frameset.html b/html/frameset.html index 672f8fa..fe6b973 100755 --- a/html/frameset.html +++ b/html/frameset.html @@ -1,21 +1,19 @@ - - - %%ychat.version%% + %%PGETITLE%% - + Your browser does not support frames, - - + + - + diff --git a/html/index.html b/html/index.html index 983e7ef..172c851 100755 --- a/html/index.html +++ b/html/index.html @@ -1,54 +1,31 @@ - - - %%ychat.version%% + %%PGETITLE%% - - - - - - - - - - - -
-
-%%ychat.version%%

%%INFO%% -
-
 
+Welcome to +
+	 ___ _           _
+ _   _  / __\ |__   __ _| |_ 
+| | | |/ /  | '_ \ / _` | __|
+| |_| / /___| | | | (_| | |_ 
+ \__, \____/|_| |_|\__,_|\__|
+ |___/  
+
+ +
+%%PGETITLE%% +
+
+%%INFO%% +Enter your nick:
-Enter your nick:
- -
-
-Enter your password:
- -
-
-Enter your room:
- -
-
- - + + +
-
-Register a new nick -
-
-If you don't want to register you may login -
-without a password using an unregistered nick. -
-

-
yChat is OpenSource - get it at http://www.yChat.org
diff --git a/html/input.html b/html/input.html index 31ed9fe..e6fb016 100755 --- a/html/input.html +++ b/html/input.html @@ -1,60 +1,32 @@ - - - + - %%HTML_TITLE_TAG_CONTENT%% + %%PGETITLE%% - -
-
- - - -
-
- Colors - Options - Help - Users - Admin - Logout - Scrolling: - -
- + + + + + +
diff --git a/html/notfound.html b/html/notfound.html index a14d44b..574e341 100755 --- a/html/notfound.html +++ b/html/notfound.html @@ -1,9 +1,7 @@ - - - %%HTML_TITLE_TAG_CONTENT%% + %%PGETITLE%% diff --git a/html/online.html b/html/online.html index 3eda553..7f29b0e 100755 --- a/html/online.html +++ b/html/online.html @@ -1,20 +1,6 @@ - - - - - + - %%room%% -
-
- - - - - %%userlist%% -
- %%topic%% -
+ %%MESSAGE%% diff --git a/html/stream.html b/html/stream.html index 4814979..66f8bbd 100755 --- a/html/stream.html +++ b/html/stream.html @@ -1,38 +1,29 @@ - - - + - %%HTML_TITLE_TAG_CONTENT%% + %%PGETITLE%% - - -

Engine: %%ychat.version%%

- - - Welcome to the chat, %%nick%%! + + Welcome to yChat %%nick%%!

- diff --git a/html/y_ani.gif b/html/y_ani.gif old mode 100644 new mode 100755 diff --git a/incl.h b/incl.h old mode 100644 new mode 100755 index 423f5e2..f8e483f --- a/incl.h +++ b/incl.h @@ -12,6 +12,5 @@ // include all the custom global variables. #include "glob.h" - // include all the custom messages. #include "msgs.h" diff --git a/main.cpp b/main.cpp old mode 100644 new mode 100755 index 502e24d..2cbc713 --- a/main.cpp +++ b/main.cpp @@ -19,7 +19,6 @@ * */ - // needed for ignoring SIGPIPE. #include @@ -54,9 +53,8 @@ cout << " ___ _ _ " << endl << " \\__, \\____/|_| |_|\\__,_|\\__|" << endl << " |___/ " << endl << endl - << DESCRIP - << VERSION << endl - << VERSION << endl + << DESCRIP << endl + << VERSION << ", " << CONTACT << endl << SEPERAT << endl << STARTMS << endl ; diff --git a/msgs.h b/msgs.h old mode 100644 new mode 100755 index 65a71e1..f57301c --- a/msgs.h +++ b/msgs.h @@ -19,8 +19,8 @@ #define CFILEOK "Parsing config file " #define CFILENO "Failed opening config file " #define CONNECT "Receiving connection " -#define CONTACT "EMail: Snooper@yChat.org, ICQ: 11655527 " -#define DESCRIP "yChat++ Basic Copyright (C) 2003 Paul C. Buetow " +#define CONTACT "Contact: www.yChat.org, Mail@yChat.org " +#define DESCRIP "yChat++ Copyright (C) 2003 Paul C. Buetow, Volker Richer " #define DOWNMSG "Shutting down " #define LOGINPR "Login procedure succeeded for nick " #define NEWROOM "Adding room " @@ -31,9 +31,8 @@ #define SOCKRDY "Server socket is ready. See port above " #define STARTMS "Starting up " #define TECACHE "Caching template " -#define THREAD1 "Spawning thread ( Mode 1 ) " -#define THREAD2 "Spawning thread ( Mode 2 ) " -#define THRPOOL "Refilling thread pool " -#define VERSION "Version Basic 0.1b (030320) " +#define THREADS "Starting thread job " +#define THREADE "Exiting thread job " +#define VERSION "Version: 0.2" #endif diff --git a/mutx.cpp b/mutx.cpp old mode 100644 new mode 100755 index ff67ed2..bbd5ced --- a/mutx.cpp +++ b/mutx.cpp @@ -9,19 +9,11 @@ using namespace std; mutx::mutx() { -#ifdef VERBOSE - cout << "mutx::mutx()" << endl; -#endif - pthread_mutex_init( &mut_stdout, NULL ); } mutx::~mutx() { -#ifdef VERBOSE - cout << "mutx::~mutx()" << endl; -#endif - pthread_mutex_destroy( &mut_stdout ); } diff --git a/mutx.h b/mutx.h old mode 100644 new mode 100755 diff --git a/name.cpp b/name.cpp old mode 100644 new mode 100755 index 56e73a2..3ef1280 --- a/name.cpp +++ b/name.cpp @@ -4,51 +4,27 @@ #define NAME_CXX #include "name.h" -#include "MUTX.h" using namespace std; name::name( string s_name ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "name::name( \"" << s_name << "\" )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - set_name( s_name ); } name::~name() { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "name::~name[ " << s_name << " ]" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif } string name::get_name() const { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "name::get_name()" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - return s_name; } void name::set_name( string s_name ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "name::set_name( \"" << s_name << "\" )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - this->s_name = s_name; } #endif diff --git a/name.h b/name.h old mode 100644 new mode 100755 diff --git a/pool.cpp b/pool.cpp index 470ea24..503d0f7 100755 --- a/pool.cpp +++ b/pool.cpp @@ -5,17 +5,17 @@ #include "pool.h" -#include "s_conf.h" -#include "s_mutx.h" -#include "s_tool.h" +#include "CONF.h" +#include "MUTX.h" +#include "TOOL.h" #include "thrd.h" using namespace std; pool::pool() { - i_thrd_pool_size = s_tool::string2int( s_conf::get().get_val( "THRDPOOL" ) ); - i_thrd_pool_queue = s_tool::string2int( s_conf::get().get_val( "THRDQUEU" ) ); + i_thrd_pool_size = TOOL::string2int( CONF::get().get_val( "THRDPOOL" ) ); + i_thrd_pool_queue = TOOL::string2int( CONF::get().get_val( "THRDQUEU" ) ); tpool_init( &thread_pool, i_thrd_pool_size, i_thrd_pool_queue, 0 ); } @@ -34,9 +34,9 @@ pool::tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size, i // allocate a pool data structure if (( tpool = (tpool_t) malloc( sizeof( struct tpool ) ) ) == NULL ) { - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cerr << "malloc" << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); exit(-1); } @@ -47,9 +47,9 @@ pool::tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size, i if ( ( tpool->threads = (pthread_t*) malloc( sizeof( pthread_t ) *num_worker_threads ) ) == NULL ) { - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cerr << "malloc" << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); exit(-1); } @@ -61,33 +61,33 @@ pool::tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size, i if ( ( rtn = pthread_mutex_init( &(tpool->queue_lock), NULL ) ) != 0 ) { - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cerr << "pthread_mutex_init " << strerror( rtn ) << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); exit(-1); } else if ( ( rtn = pthread_cond_init( &(tpool->queue_not_empty), NULL ) ) != 0 ) { - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cerr << "pthread_cond_init " << strerror( rtn ) << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); exit(-1); } else if ( ( rtn = pthread_cond_init( &(tpool->queue_not_full), NULL ) ) != 0 ) { - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cerr << "pthread_cond_init " << strerror( rtn ) << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); exit(-1); } else if ( ( rtn = pthread_cond_init( &(tpool->queue_empty), NULL ) ) != 0 ) { - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cerr << "pthread_cond_init " << strerror( rtn ) << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); exit(-1); } // create threads @@ -140,10 +140,10 @@ pool::tpool_thread( void* arg ) void pool::run_func( void *v_pointer ) { -#ifdef VERBOSE - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); +#ifdef _VERBOSE + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cout << THREADS << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); #endif // recasting the client thread object. @@ -157,10 +157,10 @@ void pool::run_func( void *v_pointer ) free(v_pointer); -#ifdef VERBOSE - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); +#ifdef _VERBOSE + pthread_mutex_lock ( &MUTX::get().mut_stdout ); cout << THREADE << endl; - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + pthread_mutex_unlock( &MUTX::get().mut_stdout ); #endif } diff --git a/reqp.cpp b/reqp.cpp old mode 100644 new mode 100755 index 52de971..6cea6a9 --- a/reqp.cpp +++ b/reqp.cpp @@ -7,6 +7,7 @@ #include "CHAT.h" #include "HTML.h" #include "MUTX.h" +#include "sock.h" using namespace std; @@ -20,27 +21,29 @@ string reqp::HTTP_COTYPE = "Content-Type: text/html\n\n"; reqp::reqp( ) { -#ifdef VERBOSE - cout << "reqp::reqp()" << endl; -#endif } string -reqp::get_url( string s_req, map_string &map_params ) +reqp::get_url( thrd* p_thrd, string s_req, map_string &map_params ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "reqp::get_url( s_req )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif + auto unsigned int pos; + string s_ret ( "" ); + string s_vars( "" ); + auto int i_request; + + i_request= ( s_req.find("GET",0) != string::npos ) ? RQ_GET : RQ_POST; - auto unsigned int pos = s_req.find( "HTTP", 0 ); - string s_ret = s_req.substr( 5, pos-6 ); + pos = s_req.find( "HTTP", 0 ); + + if( i_request == RQ_GET ) + s_ret.append( s_req.substr( 5, pos-6 ) ); + else + s_ret.append( s_req.substr( 6, pos-7 ) ); // remove ".." from the request. do { - pos = s_ret.find( "..", 0 ); + pos = s_ret.find( "../", 0 ); if ( pos == string::npos ) break; @@ -50,32 +53,52 @@ reqp::get_url( string s_req, map_string &map_params ) while( true ); // do not add the string behind "?" tp s_ret and add all params behind "?" to map_params. - pos = s_ret.find( "?", 0 ); + if( i_request == RQ_GET ) + pos = s_ret.find( "?", 0 ); + else + pos = s_req.find("\r\n\r\n", 0); + + auto string s_params( "" ); if ( pos != string::npos ) { - auto string s_params = s_ret.substr( pos+1, s_ret.length() -pos-1 ); + if( i_request == RQ_GET ) + s_params.append( s_ret.substr( pos+1, s_ret.length() -pos-1 ) ); + + else + s_params = s_req.substr( pos+4, s_req.length() -pos-1 ); + s_ret = s_ret.substr( 0, pos ); + } - auto unsigned int pos2; - do - { - pos = s_params.find( "=", 0 ); - if ( pos == string::npos ) - break; + if ( i_request == RQ_POST && s_params.empty() ) + { + char c_req[READBUF]; + read ( p_thrd->get_sock() , c_req, READBUF ); + s_params = string( strstr( c_req, "event" ) ); + } - pos2 = s_params.find( "&", 0 ); - if ( pos2 == string::npos ) - { - map_params[ s_params.substr( 0, pos ) ] = s_params.substr( pos+1, s_params.length()-pos-1 ); - break; - } + auto unsigned int pos2; + do + { + pos = s_params.find( "=", 0 ); + if ( pos == string::npos ) + break; - map_params[ s_params.substr( 0, pos ) ] = s_params.substr( pos+1, pos2-pos-1 ); - s_params = s_params.substr( pos2+1, s_params.length()-pos2-1 ); + pos2 = s_params.find( "&", 0 ); + if ( pos2 == string::npos ) + { + auto string sValue( s_params.substr(pos+1, s_params.length()-pos-1) ); + auto string tmpstr( url_decode(sValue) ); + map_params[ s_params.substr( 0, pos ) ] = tmpstr; + break; } - while( true ); + auto string s_temp= s_params.substr( pos+1, pos2-pos-1 ); + map_params[ s_params.substr( 0, pos ) ] = url_decode(s_temp); + + s_params = s_params.substr( pos2+1, s_params.length()-pos2-1 ); } + while( true ); #ifdef _VERBOSE pthread_mutex_lock ( &MUTX::get().mut_stdout ); @@ -88,15 +111,57 @@ reqp::get_url( string s_req, map_string &map_params ) return s_ret; } +int +reqp::htoi(string *s) +{ + int value; + int c; + + c=s->c_str()[0]; + if(isupper(c)) + c=tolower(c); + + value=(c>='0' && c<='9'?c-'0':c-'a'+10)*16; + + c=s->c_str()[1]; + if(isupper(c)) + c=tolower(c); + + value+=c>='0' && c<='9'?c-'0':c-'a'+10; + return value; +} + string -reqp::get_from_header( string s_req, string s_hdr ) +reqp::url_decode( string s_str ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "reqp::get_from_header( s_req, \"" << s_hdr << "\" )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif + auto string sDest=""; + int len = s_str.size(); + + for(int i=0;i #include "incl.h" +#include "thrd.h" using namespace std; @@ -24,15 +28,18 @@ private: // returns the request url from thr client's http request header // until the first "?" and stores all request parameter values // ( behind "?" ) into map_params. - virtual string get_url( string s_req, map_string &map_params ); + virtual string get_url( thrd* p_thrd, string s_req, map_string &map_params ); // returns a specific value of the client's http request header. // ( s.t. like the User-Agent, Referer etc... ). virtual string get_from_header( string s_req, string s_hdr ); + virtual int htoi( string *s ); + public: // public methods. explicit reqp( ); // simple constructor. - virtual string parse( string s_req, map_string &map_params ); + virtual string parse( thrd* p_thrd, string s_req, map_string &map_params ); + virtual string url_decode (string ); }; #endif diff --git a/room.cpp b/room.cpp old mode 100644 new mode 100755 index 2e4971b..0e905e6 --- a/room.cpp +++ b/room.cpp @@ -4,26 +4,15 @@ #define ROOM_CXX #include "room.h" -#include "MUTX.h" using namespace std; room::room( string s_name ) : name( s_name ) { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "room::room( \"" << s_name << "\" )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif } room::~room() { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "room::~room[ " << get_name() << " ]" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif } #endif diff --git a/room.h b/room.h old mode 100644 new mode 100755 diff --git a/sock.cpp b/sock.cpp old mode 100644 new mode 100755 index 009396f..c996ff5 --- a/sock.cpp +++ b/sock.cpp @@ -17,40 +17,22 @@ using namespace std; - -// the posix thread function. this one will called every time a new request socket -// was created succsessfull. in this function a new POSIX thread life begins. -// be carefull because of synchronization issues!!!! -void *sock::posix_thread_func( void *v_pointer ) +sock::sock() { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "*posix_thread_func( void *v_pointer )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - - // recasting the client thread object. - thrd *t = (thrd*) v_pointer; - - // start parsing the client request and sending response's back. - t-> run (); - - t->~thrd(); + this->b_run = true; + this->i_req = 0; + this->req_parser = new reqp(); + this->thrd_pool = new pool(); } -void *sock::posix_thread_func_( void *v_pointer ) +void +sock::chat_stream( int i_sock, map_string &map_params ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "*posix_thread_func_( void *v_pointer )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - - user *p_user = (user*) v_pointer; + user* p_user = CHAT::get().get_user( map_params["nick"] ); + p_user->set_sock( i_sock ); string s_msg( "" ); - int i_sock = p_user->get_sock(); pthread_mutex_lock ( &(p_user->mut_message) ); while( p_user->get_online() ) @@ -60,6 +42,7 @@ void *sock::posix_thread_func_( void *v_pointer ) if ( 0 > send( i_sock, s_msg.c_str(), s_msg.size(), 0 ) ) p_user->set_online( false ); } + pthread_mutex_unlock( &(p_user->mut_message) ); // remove the user from its room. @@ -72,63 +55,9 @@ void *sock::posix_thread_func_( void *v_pointer ) p_user->~user(); } -sock::sock() -{ -#ifdef VERBOSE - cout << "sock::sock()" << endl; -#endif - - this->b_run = true; - this->i_req = 0; - this->req_parser = new reqp(); -} - -void -#ifdef THRDMOD -sock::chat_stream( int i_sock, map_string &map_params ) -#else -sock::chat_stream( int i_sock, map_string &map_params, queue &thrd_pool ) -#endif -{ -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "sock::chat_stream( " << i_sock << ", map_string& )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - - user* p_user = CHAT::get().get_user( map_params["nick"] ); - p_user->set_sock( i_sock ); - -#ifdef THRDMOD - posix_thread_func_( (void*) p_user ); -#else - -#ifdef _VERBOSE - cout << THREAD2 << endl; -#endif - posix_thread_func_( (void*) p_user ); - - auto int i_fail = pthread_create( &thrd_pool.front(), NULL, posix_thread_func_, (void*) p_user ); - - // remove this thread from thread pool because its now in use. - thrd_pool.pop(); - - // check if the thread started correctly. - if ( i_fail ) - { - cerr << "Thrd: error with return code " << i_fail << endl; - } - -#endif -} - int sock::make_socket( uint16_t i_port ) { -#ifdef VERBOSE_ - cout << "sock::make_socket( " << i_port << " )" << endl; -#endif - int sock; struct sockaddr_in name; @@ -149,6 +78,9 @@ sock::make_socket( uint16_t i_port ) 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) { @@ -165,18 +97,13 @@ sock::make_socket( uint16_t i_port ) } int -sock::read_write( int i_sock ) +sock::read_write( thrd* p_thrd, int i_sock ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "sock::read_write( " << i_sock << " )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - char c_req[2048]; + int i_bytes; i_bytes = read (i_sock, c_req, 2048); - + if (i_bytes < 0) { cerr << "Sock: read error " << endl; @@ -189,18 +116,16 @@ sock::read_write( int i_sock ) // get the s_rep ( HTML response which will be send imediatly to the client // and fill map_params with request values. - string s_rep = req_parser->parse( string( c_req ), map_params ); + auto string s_temp=(string)c_req; + + string s_rep = req_parser->parse( p_thrd, string( c_req ), map_params ); // send s_rep to the client. send( i_sock, s_rep.c_str(), s_rep.size(), 0 ); // prove if this is a request for a chat stream! if ( map_params["event"] == "stream" ) -#ifdef THRDMOD chat_stream( i_sock, map_params ); -#else - chat_stream( i_sock, map_params, thrd_pool ); -#endif return 0; } @@ -208,36 +133,10 @@ sock::read_write( int i_sock ) return -1; } -void -sock::refill_thrd_pool( ) -{ -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "sock::refill_thrd_pool( )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif -#ifdef _VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << THRPOOL << i_thrd_pool_size << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - - for (int i=0; irun( (void*) new thrd( i ) ); FD_CLR( i, &active_fd_set ); } } diff --git a/sock.h b/sock.h old mode 100644 new mode 100755 index 9893007..abb5878 --- a/sock.h +++ b/sock.h @@ -15,6 +15,7 @@ #include #include "incl.h" +#include "pool.h" #include "reqp.h" #include "thrd.h" @@ -25,23 +26,16 @@ class sock private: // total number of server requests. unsigned long long int i_req; - queue thrd_pool; - - int i_thrd_pool_size; bool b_run; // true while socket manager is running. reqp* req_parser; // parses the http requests from clients. + pool* thrd_pool; // the thread pool. // the chat stream there all the chat messages will sent through. -#ifdef THRDMOD static void chat_stream( int i_sock, map_string &map_params ); -#else - static void chat_stream( int i_sock, map_string &map_params, queue &thrd_pool ); -#endif - virtual int make_socket( uint16_t port ); - static void *posix_thread_func ( void *v_pointer ); - static void *posix_thread_func_( void *v_pointer ); + // creates a server socket. + virtual int make_socket( uint16_t port ); public: // small inline methods: @@ -50,10 +44,8 @@ public: // public methods. explicit sock( ); // simple constructor. - virtual int read_write( int filedes ); + virtual int read_write( thrd* p_thrd, int filedes ); virtual int start(); - - virtual void refill_thrd_pool( ); // refills the thread pool with new thewads. }; #endif diff --git a/thrd.cpp b/thrd.cpp old mode 100644 new mode 100755 index 14a804c..7c9be50 --- a/thrd.cpp +++ b/thrd.cpp @@ -4,43 +4,24 @@ #define THRD_CXX #include "thrd.h" -#include "MUTX.h" #include "SOCK.h" using namespace std; thrd::thrd( int i_sock ) { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "thrd::thrd( " << i_sock << " )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - this->i_sock = i_sock; } thrd::~thrd() { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "thrd::~thrd()" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - shutdown ( get_sock() , 2 ); } void thrd::run() { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "thrd::run()" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - - SOCK::get().read_write( i_sock ); + SOCK::get().read_write( this, i_sock ); } #endif diff --git a/thrd.h b/thrd.h old mode 100644 new mode 100755 diff --git a/todo.txt b/todo.txt old mode 100644 new mode 100755 diff --git a/user.cpp b/user.cpp old mode 100644 new mode 100755 index 3d981b0..5a4068b --- a/user.cpp +++ b/user.cpp @@ -5,40 +5,29 @@ #include "user.h" #include "CONF.h" -#include "MUTX.h" #include "TOOL.h" using namespace std; user::user( string s_name ) : name( s_name ) { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::user( string \"" << s_name << "\" )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - this -> b_online = true; this -> l_time = TOOL::unixtime(); this -> s_col1 = 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_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); + pthread_mutex_init( &mut_message , NULL); } user::~user() { -#ifdef VERBOSE - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::~user[ \"" << get_name() << "\" ]" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - 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 ); @@ -49,12 +38,6 @@ user::~user() void user::get_data( map_string *p_map_data ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::get_data( map_string* )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - string s_req = (*p_map_data)["!get"]; // get the nick and the color of the user. @@ -65,12 +48,6 @@ user::get_data( map_string *p_map_data ) string user::get_mess( ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::get_mess( )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - string s_ret( "" ); pthread_mutex_lock ( &mut_s_mess ); s_ret.append( s_mess ); @@ -83,12 +60,6 @@ user::get_mess( ) bool user::get_online( ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::get_online( )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - bool b_ret; pthread_mutex_lock ( &mut_b_online ); b_ret = b_online; @@ -99,12 +70,6 @@ user::get_online( ) void user::set_online( bool b_online ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::set_online( bool )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - pthread_mutex_lock ( &mut_b_online ); this -> b_online = b_online; pthread_mutex_unlock( &mut_b_online ); @@ -113,12 +78,6 @@ user::set_online( bool b_online ) room* user::get_p_room( ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::get_p_room( )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - room* p_return; pthread_mutex_lock ( &mut_p_room ); p_return = p_room; @@ -129,25 +88,32 @@ user::get_p_room( ) void user::set_p_room( room* p_room ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::set_p_room( void* )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - 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( ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::renew_stamp( )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif pthread_mutex_lock ( &mut_l_time ); l_time = TOOL::unixtime(); pthread_mutex_unlock( &mut_l_time ); @@ -156,12 +122,6 @@ user::renew_stamp( ) void user::msg_post( string *p_msg ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::msg_post_( string* )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - pthread_mutex_lock ( &mut_s_mess ); s_mess.append( *p_msg ); pthread_mutex_unlock( &mut_s_mess ); @@ -172,12 +132,6 @@ user::msg_post( string *p_msg ) void user::get_user_list( string &s_list, string &s_seperator ) { -#ifdef VERBOSE_ - pthread_mutex_lock ( &MUTX::get().mut_stdout ); - cout << "user::get_user_list( string &s_list, string &s_seperator )" << endl; - pthread_mutex_unlock( &MUTX::get().mut_stdout ); -#endif - s_list.append( "" ) diff --git a/user.h b/user.h old mode 100644 new mode 100755 index cc7bf91..1bdd79e --- a/user.h +++ b/user.h @@ -26,6 +26,7 @@ private: 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; @@ -38,9 +39,6 @@ public: string get_col1() const { return s_col1; } void set_col1 ( string s_col1 ) { this -> s_col1 = s_col1; } - int get_sock() const { return i_sock; } - void set_sock ( int i_sock ) { this -> i_sock = i_sock; } - rang get_rang ( ) const { return r_rang; } void set_rang ( rang r_rang ) { r_oldr = this -> r_rang; this -> r_rang = r_rang; } @@ -60,6 +58,9 @@ public: 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 ); + virtual void renew_stamp(); -- cgit v1.2.3