diff options
| author | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:45 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:45 +0200 |
| commit | 23c5e7d57e1e9216f4da3446656df2dc7202975d (patch) | |
| tree | b387afc4ad6acad4681252df8ce8def5dc8aa54d | |
| parent | 9dcec1feba68dc5ba38cdc634f5bf113c0f77348 (diff) | |
tagging ychat-0.1ychat-0.1
| -rw-r--r-- | CHAT.cpp | 10 | ||||
| -rw-r--r-- | CHAT.h | 26 | ||||
| -rw-r--r-- | CONF.cpp | 10 | ||||
| -rw-r--r-- | CONF.h | 26 | ||||
| -rw-r--r-- | HTML.cpp | 10 | ||||
| -rw-r--r-- | HTML.h | 26 | ||||
| -rw-r--r-- | MUTX.cpp | 10 | ||||
| -rw-r--r-- | MUTX.h | 26 | ||||
| -rw-r--r--[-rwxr-xr-x] | Makefile | 95 | ||||
| -rw-r--r-- | README.txt | 169 | ||||
| -rw-r--r-- | SOCK.cpp | 10 | ||||
| -rw-r--r-- | SOCK.h | 26 | ||||
| -rw-r--r-- | TOOL.cpp | 33 | ||||
| -rw-r--r-- | TOOL.h | 15 | ||||
| -rw-r--r--[-rwxr-xr-x] | base.cpp | 134 | ||||
| -rw-r--r--[-rwxr-xr-x] | base.h | 60 | ||||
| -rw-r--r--[-rwxr-xr-x] | chat.cpp | 95 | ||||
| -rw-r--r--[-rwxr-xr-x] | chat.h | 9 | ||||
| -rw-r--r--[-rwxr-xr-x] | cmnd.cpp | 12 | ||||
| -rw-r--r--[-rwxr-xr-x] | cmnd.h | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | conf.cpp | 20 | ||||
| -rw-r--r--[-rwxr-xr-x] | conf.h | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | conf.txt | 49 | ||||
| -rw-r--r--[-rwxr-xr-x] | cont.cpp | 13 | ||||
| -rw-r--r--[-rwxr-xr-x] | cont.h | 1 | ||||
| -rw-r--r-- | data.h | 62 | ||||
| -rw-r--r--[-rwxr-xr-x] | gfx/y_ani_black.gif | bin | 61100 -> 61100 bytes | |||
| -rw-r--r--[-rwxr-xr-x] | gfx/y_ani_white.gif | bin | 53536 -> 53536 bytes | |||
| -rw-r--r--[-rwxr-xr-x] | glob.h | 14 | ||||
| -rw-r--r--[-rwxr-xr-x] | html.cpp | 65 | ||||
| -rw-r--r--[-rwxr-xr-x] | html.h | 7 | ||||
| -rw-r--r--[-rwxr-xr-x] | html/blank.html | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | html/frameset.html | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | html/index.html | 44 | ||||
| -rw-r--r--[-rwxr-xr-x] | html/input.html | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | html/notfound.html | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | html/online.html | 3 | ||||
| -rw-r--r--[-rwxr-xr-x] | html/stream.html | 3 | ||||
| -rw-r--r--[-rwxr-xr-x] | html/y_ani.gif | bin | 35107 -> 35107 bytes | |||
| -rw-r--r--[-rwxr-xr-x] | incl.h | 1 | ||||
| -rw-r--r--[-rwxr-xr-x] | main.cpp | 40 | ||||
| -rw-r--r--[-rwxr-xr-x] | msgs.h | 20 | ||||
| -rw-r--r--[-rwxr-xr-x] | mutx.cpp | 12 | ||||
| -rw-r--r--[-rwxr-xr-x] | mutx.h | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | name.cpp | 26 | ||||
| -rw-r--r--[-rwxr-xr-x] | name.h | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | reqp.cpp | 199 | ||||
| -rw-r--r--[-rwxr-xr-x] | reqp.h | 12 | ||||
| -rw-r--r--[-rwxr-xr-x] | room.cpp | 11 | ||||
| -rw-r--r--[-rwxr-xr-x] | room.h | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | sock.cpp | 196 | ||||
| -rw-r--r--[-rwxr-xr-x] | sock.h | 26 | ||||
| -rw-r--r--[-rwxr-xr-x] | thrd.cpp | 24 | ||||
| -rw-r--r--[-rwxr-xr-x] | thrd.h | 0 | ||||
| -rw-r--r--[-rwxr-xr-x] | todo.txt | 14 | ||||
| -rw-r--r--[-rwxr-xr-x] | user.cpp | 108 | ||||
| -rw-r--r--[-rwxr-xr-x] | user.h | 13 |
57 files changed, 1194 insertions, 615 deletions
diff --git a/CHAT.cpp b/CHAT.cpp new file mode 100644 index 0000000..1358a06 --- /dev/null +++ b/CHAT.cpp @@ -0,0 +1,10 @@ +#ifndef GCHT_CXX +#define GCHT_CXX + +#include "CHAT.h" + +using namespace std; + +chat* CHAT::obj; + +#endif @@ -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/CONF.cpp b/CONF.cpp new file mode 100644 index 0000000..8b5441c --- /dev/null +++ b/CONF.cpp @@ -0,0 +1,10 @@ +#ifndef GCON_CXX +#define GCON_CXX + +#include "CONF.h" + +using namespace std; + +conf* CONF::obj; + +#endif @@ -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/HTML.cpp b/HTML.cpp new file mode 100644 index 0000000..a93bc0a --- /dev/null +++ b/HTML.cpp @@ -0,0 +1,10 @@ +#ifndef GHTM_CXX +#define GHTM_CXX + +#include "HTML.h" + +using namespace std; + +html* HTML::obj; + +#endif @@ -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/MUTX.cpp b/MUTX.cpp new file mode 100644 index 0000000..41382f3 --- /dev/null +++ b/MUTX.cpp @@ -0,0 +1,10 @@ +#ifndef GMUT_CXX +#define GMUT_CXX + +#include "MUTX.h" + +using namespace std; + +mutx* MUTX::obj; + +#endif @@ -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 @@ -1,83 +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 yhttpd.conf and run yhttpd!" - @echo "The config file is searched in the following order:" - @echo " ./yhttpd.conf " - @echo " ~/.yhttpd/yhttpd.conf " - @echo " ./etc/yhttpd.conf " - @echo " /etc/yhttpd.conf " - @echo " $(PREFIX)/etc/yhttpd.conf " - @echo If you want to help the yhttpd 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 yhttpd" successfullbuild@yChat.org - @rm -f mail.tmp -install: deinstall -uninstall: deinstall -deinstall: - @echo Install/deinstall is not supported! - @echo Start yhttpd with ./bin/yhttpd 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/yhttpd; then echo "Backing up old binary";if test -f bin/yhttpd.old; then rm -f bin/yhttpd.old; fi; mv bin/yhttpd bin/yhttpd.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/yhttpd -base_start: base - ./bin/yhttpd -gpl: - @more COPYING -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/yhttpd; then find bin/ -name "*yhttpd*" | 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/yhttpd yhttpd.core -confdebug: - ./configure -g3 -ggdb -dist: - @./scripts/makedist.sh +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 reqp.cpp room.cpp sock.cpp SOCK.cpp thrd.cpp TOOL.cpp user.cpp +OBJS=$(SRCS:.cpp=.o) +CC=c++ +LDFLAGS=-lstdc++ +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 new file mode 100644 index 0000000..e68c165 --- /dev/null +++ b/README.txt @@ -0,0 +1,169 @@ +yChat++; Version Basic 0.1b (030320); Homepage: www.yChat.org +Copyright (C) 2003 Paul C. Buetow ( Snooper@yChat.org, ICQ: 11655527 ) +----------------------------------------------------------------- + +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. + +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 + +History of lines of code ( including embedded comments ): + +Version: Lines: + Basic 0.1b 2402 diff --git a/SOCK.cpp b/SOCK.cpp new file mode 100644 index 0000000..c5b451e --- /dev/null +++ b/SOCK.cpp @@ -0,0 +1,10 @@ +#ifndef GSOC_CXX +#define GSOC_CXX + +#include "SOCK.h" + +using namespace std; + +sock* SOCK::obj; + +#endif @@ -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/TOOL.cpp b/TOOL.cpp new file mode 100644 index 0000000..7709695 --- /dev/null +++ b/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 @@ -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 @@ -1,65 +1,125 @@ -/* - This file is part of yChat - - $Author: paul $ - $Date: 2003/03/30 01:35:21 $ - - $Header: /home/cvsroot/ychat/base.cpp,v 1.7 2003/03/30 01:35:21 paul Exp $ -*/ // template class data implementation; #ifndef BASE_CPP #define BASE_CPP #include "base.h" +#include "MUTX.h" -template<class type> -base<type>::base() +base::base() { - map_elem = new hmap<name*,string>(80); - pthread_mutex_init (&mut_map_elem, NULL ); +#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 ); } -template<class type> -base<type>::~base( ) +base::~base( ) { - pthread_mutex_destroy( &mut_map_elem ); +#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 ); } -template<class type> void -base<type>::add_elem( name* p_name ) +void +base::add_elem( name* p_name ) { - pthread_mutex_lock ( &mut_map_elem ); - map_elem->add_elem ( p_name, p_name->get_name()); - pthread_mutex_unlock( &mut_map_elem ); +#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 ); } -template<class type> void -base<type>::del_elem( string &s_name ) +bool +base::del_elem( string &s_name ) { - pthread_mutex_lock ( &mut_map_elem ); - map_elem->del_elem ( s_name ); - pthread_mutex_unlock( &mut_map_elem ); +#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<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; } -template<class type> name* -base<type>::get_elem( string &s_name, bool &b_found ) +name* +base::get_elem( string &s_name, bool &b_found ) { - pthread_mutex_lock ( &mut_map_elem ); - name* p_name = map_elem->get_elem( s_name ); - pthread_mutex_unlock( &mut_map_elem ); +#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<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++; + } - b_found = p_name == NULL ? false : true; + pthread_mutex_unlock( &mut_vec_elem ); - return p_name; + b_found = false; + + return new name(); } -template<class type> void -base<type>::run_func( void (*func)(name*, void*), void* v_arg ) +void +base::run_func( void (*func)(name*, void*), void* v_arg ) { - pthread_mutex_lock ( &mut_map_elem ); - map_elem->run_func( func, v_arg ); - pthread_mutex_unlock( &mut_map_elem ); +#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<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 |
