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.5.5/src | |
| parent | 13aaf70af703748fe096e0664c305cd202637ad2 (diff) | |
tagging tags
Diffstat (limited to 'ychat-0.5.5/src')
60 files changed, 5212 insertions, 0 deletions
diff --git a/ychat-0.5.5/src/Makefile b/ychat-0.5.5/src/Makefile new file mode 100644 index 0000000..7164d56 --- /dev/null +++ b/ychat-0.5.5/src/Makefile @@ -0,0 +1,18 @@ +# Generated automatically from Makefile.in by configure. +SRCS=chat.cpp s_chat.cpp conf.cpp s_conf.cpp cont.cpp html.cpp s_html.cpp lang.cpp s_lang.cpp main.cpp mutx.cpp s_mutx.cpp name.cpp pool.cpp reqp.cpp room.cpp sock.cpp s_sock.cpp thrd.cpp s_tool.cpp user.cpp sess.cpp sman.cpp s_sman.cpp +#logd.cpp modl.cpp s_modl.cpp cmnd.cpp +OBJS=$(SRCS:.cpp=.o) +CC=g++ +LDFLAGS= -lstdc++ -g +LDADD=-pthread -D_THREAD_SAFE +all: ychat +$(SRCS): + $(CC) $(CFLAGS) -c $*.cpp +ychat: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) + @mv -f ychat .. +mrproper: clean + @rm -f Makefile config.log config.cache config.status + rm -f ../ychat +clean: + rm *.o diff --git a/ychat-0.5.5/src/Makefile.in b/ychat-0.5.5/src/Makefile.in new file mode 100755 index 0000000..6f43bf9 --- /dev/null +++ b/ychat-0.5.5/src/Makefile.in @@ -0,0 +1,17 @@ +SRCS=chat.cpp s_chat.cpp conf.cpp s_conf.cpp cont.cpp html.cpp s_html.cpp lang.cpp s_lang.cpp main.cpp mutx.cpp s_mutx.cpp name.cpp pool.cpp reqp.cpp room.cpp sock.cpp s_sock.cpp thrd.cpp s_tool.cpp user.cpp sess.cpp sman.cpp s_sman.cpp +#logd.cpp modl.cpp s_modl.cpp cmnd.cpp +OBJS=$(SRCS:.cpp=.o) +CC=g++ +LDFLAGS=@LDFLAGS@ -lstdc++ -g +LDADD=-pthread -D_THREAD_SAFE +all: ychat +$(SRCS): + $(CC) $(CFLAGS) -c $*.cpp +ychat: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) + @mv -f ychat .. +mrproper: clean + @rm -f Makefile config.log config.cache config.status + rm -f ../ychat +clean: + rm *.o diff --git a/ychat-0.5.5/src/base.cpp b/ychat-0.5.5/src/base.cpp new file mode 100755 index 0000000..06c0c2d --- /dev/null +++ b/ychat-0.5.5/src/base.cpp @@ -0,0 +1,69 @@ +/* + This file is part of yChat + + $Author: buetow $ + $Date: 2005/03/02 12:57:41 $ + + $Header: /usr/home/cvs/cvsroot/ychat-stable/src/base.cpp,v 1.1 2005/03/02 12:57:41 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/ychat-0.5.5/src/base.h b/ychat-0.5.5/src/base.h new file mode 100755 index 0000000..9ea405d --- /dev/null +++ b/ychat-0.5.5/src/base.h @@ -0,0 +1,71 @@ +// 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/ychat-0.5.5/src/chat.cpp b/ychat-0.5.5/src/chat.cpp new file mode 100755 index 0000000..38d7a6a --- /dev/null +++ b/ychat-0.5.5/src/chat.cpp @@ -0,0 +1,156 @@ +// 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*)¶m ); + + 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/ychat-0.5.5/src/chat.h b/ychat-0.5.5/src/chat.h new file mode 100755 index 0000000..f8a6523 --- /dev/null +++ b/ychat-0.5.5/src/chat.h @@ -0,0 +1,46 @@ +// 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/ychat-0.5.5/src/conf.cpp b/ychat-0.5.5/src/conf.cpp new file mode 100755 index 0000000..14dc199 --- /dev/null +++ b/ychat-0.5.5/src/conf.cpp @@ -0,0 +1,76 @@ +// 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/ychat-0.5.5/src/conf.h b/ychat-0.5.5/src/conf.h new file mode 100755 index 0000000..7d0b807 --- /dev/null +++ b/ychat-0.5.5/src/conf.h @@ -0,0 +1,24 @@ +// 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/ychat-0.5.5/src/config.cache b/ychat-0.5.5/src/config.cache new file mode 100644 index 0000000..f5f09c0 --- /dev/null +++ b/ychat-0.5.5/src/config.cache @@ -0,0 +1,30 @@ +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs. It is not useful on other systems. +# If it contains results you don't want to keep, you may remove or edit it. +# +# By default, configure uses ./config.cache as the cache file, +# creating it if it does not exist already. You can give configure +# the --cache-file=FILE option to use a different cache file; that is +# what configure does when it calls configure scripts in +# subdirectories, so they share the cache. +# Giving --cache-file=/dev/null disables caching, for debugging configure. +# config.status only pays attention to the cache file if you give it the +# --recheck option to rerun configure. +# +ac_cv_cygwin=${ac_cv_cygwin=no} +ac_cv_header_dirent_dirent_h=${ac_cv_header_dirent_dirent_h=yes} +ac_cv_prog_CXX=${ac_cv_prog_CXX=c++} +ac_cv_search_dlopen=${ac_cv_search_dlopen='none required'} +ac_cv_prog_cxx_cross=${ac_cv_prog_cxx_cross=no} +ac_cv_c_const=${ac_cv_c_const=yes} +ac_cv_header_stdc=${ac_cv_header_stdc=yes} +ac_cv_lib_dir_opendir=${ac_cv_lib_dir_opendir=no} +ac_cv_c_inline=${ac_cv_c_inline=inline} +ac_cv_header_string_h=${ac_cv_header_string_h=yes} +ac_cv_header_unistd_h=${ac_cv_header_unistd_h=yes} +ac_cv_prog_cxx_works=${ac_cv_prog_cxx_works=yes} +ac_cv_prog_cxx_g=${ac_cv_prog_cxx_g=yes} +ac_cv_prog_gxx=${ac_cv_prog_gxx=yes} +ac_cv_prog_CPP=${ac_cv_prog_CPP='cc -E'} +ac_cv_mingw32=${ac_cv_mingw32=no} diff --git a/ychat-0.5.5/src/config.log b/ychat-0.5.5/src/config.log new file mode 100644 index 0000000..0a02618 --- /dev/null +++ b/ychat-0.5.5/src/config.log @@ -0,0 +1,71 @@ +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +configure:528: checking for Cygwin environment +configure:544: cc -c conftest.c 1>&5 +configure: In function `main': +configure:540: error: `__CYGWIN32__' undeclared (first use in this function) +configure:540: error: (Each undeclared identifier is reported only once +configure:540: error: for each function it appears in.) +configure: failed program was: +#line 533 "configure" +#include "confdefs.h" + +int main() { + +#ifndef __CYGWIN__ +#define __CYGWIN__ __CYGWIN32__ +#endif +return __CYGWIN__; +; return 0; } +configure:561: checking for mingw32 environment +configure:573: cc -c conftest.c 1>&5 +configure: In function `main': +configure:569: error: `__MINGW32__' undeclared (first use in this function) +configure:569: error: (Each undeclared identifier is reported only once +configure:569: error: for each function it appears in.) +configure: failed program was: +#line 566 "configure" +#include "confdefs.h" + +int main() { +return __MINGW32__; +; return 0; } +configure:590: checking how to run the C preprocessor +configure:611: cc -E conftest.c >/dev/null 2>conftest.out +configure:674: checking for c++ +configure:706: checking whether the C++ compiler (c++ ) works +configure:722: c++ -o conftest conftest.C 1>&5 +configure:748: checking whether the C++ compiler (c++ ) is a cross-compiler +configure:753: checking whether we are using GNU C++ +configure:762: c++ -E conftest.C +configure:781: checking whether c++ accepts -g +configure:815: checking for library containing dlopen +configure:833: cc -o conftest conftest.c 1>&5 +configure:883: checking for dirent.h that defines DIR +configure:896: cc -c conftest.c 1>&5 +configure:921: checking for opendir in -ldir +configure:940: cc -o conftest conftest.c -ldir 1>&5 +/usr/bin/ld: cannot find -ldir +configure: failed program was: +#line 929 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char opendir(); + +int main() { +opendir() +; return 0; } +configure:1004: checking for ANSI C header files +configure:1017: cc -E conftest.c >/dev/null 2>conftest.out +configure:1084: cc -o conftest conftest.c 1>&5 +configure:1111: checking for unistd.h +configure:1121: cc -E conftest.c >/dev/null 2>conftest.out +configure:1151: checking for string.h +configure:1161: cc -E conftest.c >/dev/null 2>conftest.out +configure:1188: checking for working const +configure:1242: cc -c conftest.c 1>&5 +configure:1263: checking for inline +configure:1277: cc -c conftest.c 1>&5 diff --git a/ychat-0.5.5/src/config.status b/ychat-0.5.5/src/config.status new file mode 100755 index 0000000..ee6dd32 --- /dev/null +++ b/ychat-0.5.5/src/config.status @@ -0,0 +1,151 @@ +#! /bin/sh +# Generated automatically by configure. +# Run this file to recreate the current configuration. +# This directory was configured as follows, +# on host fibonacci.exa-ds.com: +# +# ./configure +# +# Compiler output produced by configure, useful for debugging +# configure, is in ./config.log if it exists. + +ac_cs_usage="Usage: ./config.status [--recheck] [--version] [--help]" +for ac_option +do + case "$ac_option" in + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + echo "running ${CONFIG_SHELL-/bin/sh} ./configure --no-create --no-recursion" + exec ${CONFIG_SHELL-/bin/sh} ./configure --no-create --no-recursion ;; |
