diff options
| author | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:41 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:41 +0200 |
| commit | 9cd3ccffd5372dfde3af478e3f832f18db4be3f1 (patch) | |
| tree | 631c295a4a4a16b57502b847626763a279bf6df7 /ychat-0.2 | |
| parent | 13aaf70af703748fe096e0664c305cd202637ad2 (diff) | |
tagging tags
Diffstat (limited to 'ychat-0.2')
65 files changed, 2768 insertions, 0 deletions
diff --git a/ychat-0.2/CHAT.cpp b/ychat-0.2/CHAT.cpp new file mode 100755 index 0000000..1358a06 --- /dev/null +++ b/ychat-0.2/CHAT.cpp @@ -0,0 +1,10 @@ +#ifndef GCHT_CXX +#define GCHT_CXX + +#include "CHAT.h" + +using namespace std; + +chat* CHAT::obj; + +#endif diff --git a/ychat-0.2/CHAT.h b/ychat-0.2/CHAT.h new file mode 100755 index 0000000..6c015f4 --- /dev/null +++ b/ychat-0.2/CHAT.h @@ -0,0 +1,26 @@ +#ifndef GCHT_H +#define GCHT_H + +#include "chat.h" + +using namespace std; + +class CHAT +{ +private: + static chat* obj; + +public: + static void init() + { + obj = new chat(); + } + + static chat& get() + { + return *obj; + } +}; + + +#endif diff --git a/ychat-0.2/CONF.cpp b/ychat-0.2/CONF.cpp new file mode 100755 index 0000000..8b5441c --- /dev/null +++ b/ychat-0.2/CONF.cpp @@ -0,0 +1,10 @@ +#ifndef GCON_CXX +#define GCON_CXX + +#include "CONF.h" + +using namespace std; + +conf* CONF::obj; + +#endif diff --git a/ychat-0.2/CONF.h b/ychat-0.2/CONF.h new file mode 100755 index 0000000..f3dc5c9 --- /dev/null +++ b/ychat-0.2/CONF.h @@ -0,0 +1,26 @@ +#ifndef GCON_H +#define GCON_H + +#include "conf.h" + +using namespace std; + +class CONF +{ +private: + static conf* obj; + +public: + static void init() + { + obj = new conf( CONFILE ); + } + + static conf& get() + { + return *obj; + } +}; + + +#endif diff --git a/ychat-0.2/HTML.cpp b/ychat-0.2/HTML.cpp new file mode 100755 index 0000000..a93bc0a --- /dev/null +++ b/ychat-0.2/HTML.cpp @@ -0,0 +1,10 @@ +#ifndef GHTM_CXX +#define GHTM_CXX + +#include "HTML.h" + +using namespace std; + +html* HTML::obj; + +#endif diff --git a/ychat-0.2/HTML.h b/ychat-0.2/HTML.h new file mode 100755 index 0000000..16bf13d --- /dev/null +++ b/ychat-0.2/HTML.h @@ -0,0 +1,26 @@ +#ifndef GHTM_H +#define GHTM_H + +#include "html.h" + +using namespace std; + +class HTML +{ +private: + static html* obj; + +public: + static void init() + { + obj = new html(); + } + + static html& get() + { + return *obj; + } +}; + + +#endif diff --git a/ychat-0.2/MUTX.cpp b/ychat-0.2/MUTX.cpp new file mode 100755 index 0000000..41382f3 --- /dev/null +++ b/ychat-0.2/MUTX.cpp @@ -0,0 +1,10 @@ +#ifndef GMUT_CXX +#define GMUT_CXX + +#include "MUTX.h" + +using namespace std; + +mutx* MUTX::obj; + +#endif diff --git a/ychat-0.2/MUTX.h b/ychat-0.2/MUTX.h new file mode 100755 index 0000000..f2e9980 --- /dev/null +++ b/ychat-0.2/MUTX.h @@ -0,0 +1,26 @@ +#ifndef GMUT_H +#define GMUT_H + +#include "mutx.h" + +using namespace std; + +class MUTX +{ +private: + static mutx* obj; + +public: + static void init() + { + obj = new mutx(); + } + + static mutx& get() + { + return *obj; + } +}; + + +#endif diff --git a/ychat-0.2/Makefile b/ychat-0.2/Makefile new file mode 100755 index 0000000..7506171 --- /dev/null +++ b/ychat-0.2/Makefile @@ -0,0 +1,12 @@ +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/ychat-0.2/README.txt b/ychat-0.2/README.txt new file mode 100755 index 0000000..af513e8 --- /dev/null +++ b/ychat-0.2/README.txt @@ -0,0 +1,177 @@ +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 +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. + +----------------------------------------------------------------- + +Notes: I programmed this on FreeBSD but should also compile without +big problems on Linux or other UNIX-like systems. +If you have tested one of those then pleace write me the name of the OS, +kernel version, make version and compiler & version. I will list it +right here: + +The following platforms have been tested with success: + +- FreeBSD 5.0-RELEASE, GCC 3.2.1, FreeBSD 5.0 make and GNU make 3.80 + +- Linux Kernel 2.4.19, GCC 3.2.0, GNU make 3.79.1 + +Before you compile the source you have to be sure to use at least GCC +version 3.x with pthreads enabled. ( Type gcc -v to check it ). +GCC 2.95 did not work while testing on linux and won't be supported! + +If you like to support yChat++, please write me an email and tell me +what you can/like/would help ;-]. Please also take a look at the +yChat++ homepage ( www.yChat.org ). + +Installation: Just invoke "make", edit the conf.txt and run the +server with ./ychat, point your webbrowser to http://yourip:port/index.html +( ignoring the index.html on the end of the url will not work! ). +... have fun :-). + +If you like customizing the design/layout/language of yChat, you will have +to edit msgs.h and glob.h before you compile the sources. Afterwards you can +change the html-template files which are placed in the html/ subdirectory. + +Files: + +conf.txt - The yChat configuration file. ( read by conf.cpp ). + +base.cpp - Encapsulates vector fields of room's or user ( may be later + hash_maps ) and provides methods for manipulating base data + objects. + +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. + +room.cpp - Specifies a chat room. For each chat room an instance of + this class exists. + +thrd.cpp - This class is needed by sock.cpp while creating a POSIX thread. + All data which a thread needs to do its tasks are stored in a + thrd object and then a pointer to it will be passed to the + POSIX thread function. + +user.cpp - Specifies a chat user. For each chat user an instance of + this class exists. + +Abstract classes: + +cont.cpp - All classes which need to store "key - value" data sets + inherit from this class. ( cont for content ). + +name.cpp - All classes which own a private member string name inherit + from this class. It also provides public get_name and + set_name methods. + +As described ( main.cpp ), there are so called managers. Managers are +accessible through their assigned wrapper classes and may be +instanciated only once. + +chat.cpp - The chat manager. Is responsible for managing the internal + data structure of the system and also covers a lot of + important methods of the system. + +conf.cpp - The config manager. Parses the config file specified in + glob.h and stores all the values of it in a map. + +html.cpp - The html-template manager. Reads the requested html-template + files, stores them in an internal cache ( averts reading + template-files from hd twice or more ) and parses the + partivular template in order to substituate dynamic values + of it. + +mutx.cpp - The mutex manager. Contains all global mutex handlers for + synchronizing POSIX thread shared data. until now only the + stdout is synchronized by mutx.cpp because most of objects + use their own mutex'. + +sock.cpp - The socket manager. Manages the socket connections. There + are multiplexed sockets. For each requests a new POSIX thread + will be created. + +Files written in capital letters contain static C++ classes + +CHAT.cpp - Static wrapper for the dynamic chat class. holds one global + reachable instance of chat until the program shuts down. + +CONF.cpp - Static wrapper for the dynamic conf class. holds one global + reachable instance of conf until the program shuts down. + +HTML.cpp - Static wrapper for the dynamic html class. holds one global + reachable instance of conf until the program shuts down. + +MUTX.cpp - Static wrapper for the dynamic mutx class. holds one global + reachable instance of conf until the program shuts down. + +SOCK.cpp - Static wrapper for the dynamic sock class. holds one global + reachable instance of conf until the program shuts down. + +TOOL.cpp - Static class which includes some usefull global reachable + methods which are not integraded in independent classes. + +Special header files ( all other header files which are not listed here +belong to their respective .cpp files ): + +data.h - Implements a generic class ( template class ) for accessing + data from a base ( see base.cpp ) object. this methods are + all inline and use rekursive algorithm and function pointers. + +glob.h - Defines global variables which are known by compilation + time. + +incl.h - This file is included from every other header file and + includes a set of headers which every class should be able + to use. + +msgs.h - Defines console output messages for verbosity level 0 ( see + glob.h for setting up verbosity levels ). and also defines + all the system messages. you may edit this file for translating + the system user language. + + +The basic class structure: + + base + | + | + data<type> name + / \ / \ + / \ / \ +chat room user + + cont + / \ + / \ +conf html + +Version Lines of code + 0.1 2402 + 0.2 2377 + +New in 0.2: + - POST request now work. + - Thread pool ( pool.cpp ). + - Bugfixes diff --git a/ychat-0.2/SOCK.cpp b/ychat-0.2/SOCK.cpp new file mode 100755 index 0000000..c5b451e --- /dev/null +++ b/ychat-0.2/SOCK.cpp @@ -0,0 +1,10 @@ +#ifndef GSOC_CXX +#define GSOC_CXX + +#include "SOCK.h" + +using namespace std; + +sock* SOCK::obj; + +#endif diff --git a/ychat-0.2/SOCK.h b/ychat-0.2/SOCK.h new file mode 100755 index 0000000..dacc05f --- /dev/null +++ b/ychat-0.2/SOCK.h @@ -0,0 +1,26 @@ +#ifndef GSOC_H +#define GSOC_H + +#include "sock.h" + +using namespace std; + +class SOCK +{ +private: + static sock* obj; + +public: + static void init() + { + obj = new sock(); + } + + static sock& get() + { + return *obj; + } +}; + + +#endif diff --git a/ychat-0.2/TOOL.cpp b/ychat-0.2/TOOL.cpp new file mode 100755 index 0000000..7709695 --- /dev/null +++ b/ychat-0.2/TOOL.cpp @@ -0,0 +1,33 @@ +#ifndef TOOL_CXX +#define TOOL_CXX + +#include <time.h> +#include "TOOL.h" + +int +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 +TOOL::unixtime() +{ + return (long) time( NULL ); +} + +#endif diff --git a/ychat-0.2/TOOL.h b/ychat-0.2/TOOL.h new file mode 100755 index 0000000..de2c4a2 --- /dev/null +++ b/ychat-0.2/TOOL.h @@ -0,0 +1,15 @@ +#ifndef TOOL_H +#define TOOL_H + +#include "incl.h" + +using namespace std; + +class TOOL +{ +public: + static int string2int( string s_digit ); + static long unixtime(); +}; + +#endif diff --git a/ychat-0.2/base.cpp b/ychat-0.2/base.cpp new file mode 100755 index 0000000..9a67340 --- /dev/null +++ b/ychat-0.2/base.cpp @@ -0,0 +1,88 @@ +// template class data implementation; + +#ifndef BASE_CPP +#define BASE_CPP + +#include "base.h" + +base::base() +{ + pthread_mutex_init (&mut_vec_elem, NULL ); +} + +base::~base( ) +{ + pthread_mutex_destroy( &mut_vec_elem ); +} + +void +base::add_elem( name* p_name ) +{ + pthread_mutex_lock ( &mut_vec_elem ); + vec_elem.push_back ( p_name ); + pthread_mutex_unlock( &mut_vec_elem ); +} + +bool +base::del_elem( string &s_name ) +{ + vector<name*>::iterator iter; + pthread_mutex_lock ( &mut_vec_elem ); + + iter = vec_elem.begin(); + while( iter != vec_elem.end() ) + { + if ( (*iter)->get_name() == s_name ) + { + vec_elem.erase( iter ); + pthread_mutex_unlock( &mut_vec_elem ); + return true; + } + iter++; + } + + pthread_mutex_unlock( &mut_vec_elem ); + return false; +} + +name* +base::get_elem( string &s_name, bool &b_found ) +{ + vector<name*>::iterator iter; + pthread_mutex_lock ( &mut_vec_elem ); + + iter = vec_elem.begin(); + while( iter != vec_elem.end() ) + { + if ( (*iter)->get_name() == s_name ) + { + b_found = true; + pthread_mutex_unlock( &mut_vec_elem ); + return (*iter); + } + iter++; + } + + pthread_mutex_unlock( &mut_vec_elem ); + + b_found = false; + + return new name(); +} + +void +base::run_func( void (*func)(name*, void*), void* v_arg ) +{ + vector<name*>::iterator iter; + pthread_mutex_lock ( &mut_vec_elem ); + + // execute func foreach element of vec_elem with + // 1st argument: a pointer of a element of vec_elem. + // 2nd argument: a void pointer of a object. + for( iter = vec_elem.begin(); iter != vec_elem.end(); iter++ ) + ( *func ) ( (*iter), v_arg ); + + pthread_mutex_unlock( &mut_vec_elem ); +} + +#endif diff --git a/ychat-0.2/base.h b/ychat-0.2/base.h new file mode 100755 index 0000000..d1c37ba --- /dev/null +++ b/ychat-0.2/base.h @@ -0,0 +1,28 @@ +// template class data declaration; + +#ifndef BASE_H +#define BASE_H + +#include <vector> +#include "incl.h" +#include "name.h" + +class base +{ +private: + vector<name*> vec_elem ; + pthread_mutex_t mut_vec_elem; + +public: + base(); + ~base(); + + virtual void add_elem( name* p_name ); // add a element. + virtual bool del_elem( string &s_name ); // delete a alement. + virtual name* get_elem( string &s_name, bool &b_found ); // get a element. + + // execute func on all elements of vec_elem. v_pointer is the argument. + virtual void run_func( void (*func)(name*, void*), void* v_arg ); +}; + +#endif diff --git a/ychat-0.2/chat.cpp b/ychat-0.2/chat.cpp new file mode 100755 index 0000000..7b0ccd2 --- /dev/null +++ b/ychat-0.2/chat.cpp @@ -0,0 +1,121 @@ +// class chat implementation. + +#ifndef CHAT_CXX +#define CHAT_CXX + +#include "chat.h" +#include "CONF.h" +#include "MUTX.h" + +using namespace std; + +chat::chat( ) +{ +} + +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*)¶m ); + + if ( *( (bool*)param.elem[1] ) ) + return (user*)param.elem[2]; +} + +void +chat::get_user_( name *name_obj, void *v_arg ) +{ + container* param = (container*) v_arg; + room *room_obj = static_cast<room*>(name_obj); + 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"] = 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"] = 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 |
