From d4c9f10efe815af146438cafb694d16da0e5650a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:47 +0200 Subject: tagging ychat-0.7.0 --- CHANGES | 62 +-------- COPYING | 0 INSTALL | 0 Makefile | 70 +++++----- NEWS | 12 -- README | 53 ++++---- TODO | 66 ++++------ configure | 33 +---- etc/ychat.conf | 96 +++----------- html/admin.html | 4 +- html/colors.html | 8 +- html/demo.html | 4 +- html/frameset.html | 2 +- html/help.html | 6 +- html/index.html | 19 ++- html/input.html | 48 +++---- html/online.html | 5 +- html/options.html | 12 +- html/register.html | 21 ++- html/stream.html | 24 ++-- html/style.css | 49 +------ scripts/buildnr.pl | 2 +- scripts/makeyhttpd.pl | 10 +- scripts/stats.pl | 24 ++-- src/chat/base.h | 4 +- src/chat/chat.cpp | 75 +++-------- src/chat/chat.h | 7 +- src/chat/room.cpp | 21 +-- src/chat/room.h | 11 +- src/chat/sess.cpp | 40 +----- src/chat/sess.h | 17 +-- src/chat/sman.cpp | 11 +- src/chat/sman.h | 6 +- src/chat/user.cpp | 12 +- src/chat/user.h | 6 +- src/cli/cli.cpp | 59 ++------- src/cli/cli.h | 11 +- src/conf/conf.cpp | 18 +-- src/conf/conf.h | 10 +- src/configure | 10 +- src/data/con.cpp | 48 +++---- src/data/con.h | 14 +- src/data/con_base.cpp | 5 +- src/data/con_base.h | 6 +- src/data/data.cpp | 263 ++++++++++++++++++------------------- src/data/data.h | 24 ++-- src/data/data_base.cpp | 240 ++++++++++++++++----------------- src/data/data_base.h | 49 ++++--- src/glob.h | 14 +- src/html.cpp | 34 +++-- src/html.h | 15 ++- src/incl.h | 5 +- src/logd.cpp | 21 +-- src/logd.h | 7 +- src/main.cpp | 27 ++-- src/maps/hmap.h | 6 +- src/maps/hmap.tmpl | 15 +-- src/maps/mtools.h | 4 + src/maps/nmap.h | 3 + src/maps/smap.h | 3 +- src/maps/smap.tmpl | 12 +- src/modl.cpp | 16 +-- src/modl.h | 2 +- src/mods/Makefile | 9 +- src/mods/commands/yc_away.cpp | 18 +-- src/mods/commands/yc_col.cpp | 2 - src/mods/commands/yc_exec.cpp | 2 - src/mods/commands/yc_fake.cpp | 6 +- src/mods/commands/yc_getroom.cpp | 2 - src/mods/commands/yc_getrusage.cpp | 2 - src/mods/commands/yc_getstatus.cpp | 2 - src/mods/commands/yc_help.cpp | 2 - src/mods/commands/yc_invisible.cpp | 6 +- src/mods/commands/yc_j.cpp | 2 - src/mods/commands/yc_ko.cpp | 4 +- src/mods/commands/yc_m.cpp | 1 - src/mods/commands/yc_md5.cpp | 2 - src/mods/commands/yc_me.cpp | 2 - src/mods/commands/yc_msg.cpp | 35 ++--- src/mods/commands/yc_q.cpp | 2 - src/mods/commands/yc_reload.cpp | 2 - src/mods/commands/yc_ren.cpp | 2 - src/mods/commands/yc_s.cpp | 13 +- src/mods/commands/yc_set.cpp | 2 - src/mods/commands/yc_template.cpp | 2 - src/mods/commands/yc_time.cpp | 2 - src/mods/commands/yc_topic.cpp | 16 +-- src/mods/commands/yc_uptime.cpp | 2 - src/mods/commands/yc_version.cpp | 4 +- src/mods/html/yc_admin.cpp | 4 +- src/mods/html/yc_colors.cpp | 10 +- src/mods/html/yc_help.cpp | 4 +- src/mods/html/yc_options.cpp | 14 +- src/mods/html/yc_register.cpp | 18 ++- src/msgs.h | 37 ++---- src/name.cpp | 4 +- src/name.h | 8 +- src/ncur/menu.cpp | 11 +- src/ncur/menu.h | 7 +- src/ncur/ncur.cpp | 43 +++--- src/ncur/ncur.h | 18 +-- src/reqp.cpp | 120 +++++++++-------- src/reqp.h | 35 +++-- src/sock/sock.cpp | 136 ++++++++++--------- src/sock/sock.h | 39 +++--- src/stats.cpp | 1 - src/stats.h | 2 +- src/thrd/pool.cpp | 164 ++++++++++------------- src/thrd/pool.h | 38 ++++-- src/thrd/thro.cpp | 3 +- src/thrd/thro.h | 12 +- src/time/timo.cpp | 4 +- src/time/timr.cpp | 35 ++--- src/time/timr.h | 8 +- src/tool/dir.cpp | 18 +-- src/tool/dir.h | 8 +- src/tool/tool.cpp | 161 ++++------------------- src/tool/tool.h | 86 ++++++++++-- src/wrap.cpp | 6 +- src/wrap.h | 14 +- 120 files changed, 1217 insertions(+), 1776 deletions(-) mode change 100755 => 100644 COPYING mode change 100755 => 100644 INSTALL mode change 100755 => 100644 Makefile mode change 100755 => 100644 README mode change 100755 => 100644 src/msgs.h diff --git a/CHANGES b/CHANGES index c58ca31..5ab5c46 100644 --- a/CHANGES +++ b/CHANGES @@ -1,64 +1,4 @@ -Changes from 0.7.4.1-RELEASE to 0.7.5-RELEASE -- Garbage collector will now run once a hour rather than each ten minutes. -- Dynamic thread pool improvements. -- Removed equiv-http-refresh meta tag from the online list. -- Minor bugfix in the /topic command. -- Implemented "User list" - -Changes from 0.7.4-RELEASE to 0.7.4.1-RELEASE: -- Dynamic thread pool bugfix (dead lock) - -Changes from 0.7.3-RELEASE to 0.7.4-RELEASE: -- Code cleanup. -- Made the thread pool increasing dynamic. -- Added some thread pool optimazions. -- Added some more ${MAKE} vars to the Makefiles. -- Added Content-length to the HTTPD header. -- Added the !command to the command line interface. -- Added Content-type text/plain. -- Added scrolling checkbox to input.html -- Removed modl from yhttpd. Dynamic modules are not needed in yhttpd yet. -- Improved session engine. -- Fixed auto logout bug. -- Fixed newline bug (one \n too much for each html template) -- Logging can now be completely disabled. - -Changes from 0.7.2 to 0.7.3-RELEASE: -- Added FreeBSD 5.3-RELEASE support. -- Added chat.enableguest option. -- Added the /all command (Global system message) -- Renamed the /getstatus command into /about. -- Fixed the &-bug (& should be allowed in messages). \AND is now a - synonym for & too. -- Fixed the /msg bug (In /msg the string replacer should be activated). -- Fixed logging bug (do not log any timestamps if there are no messages). - -Changes from 0.7.1 to 0.7.2-RELEASE: -New features: -- /morph -- Added the new standard html template design. -Bugfixes: -- /away prints a . instead of a : if no away reason is given. -- /ko message was wrong. Displayed not room name of the user to be kicked out. -- /invisible command displayed wrong private messages. -- /getstatus had no help text. -- /msg and /s should now print the system time if printalwaystime == true. -- Added a blank to the /uptime message. -- /topic now prints the topic in the user's color. -- Fixed some typos. - -Changes from 0.7.0 to 0.7.1-RELEASE: -- Added ${MAKE} to the config file because some Linux distros dont use - the "gmake" command for GNU make but just "make"! Modified the - configure script to generate a make.version file. -- Removed some typos from the ychat.conf. -- Fixed the auto away message. This one will be posted in the room - as public rather than only private to the auto-away-user. -- Fixed some documentation stuff for yhttpd because yhttpd does not - need MySQL at all. -- Added the chat.maxlength.word option. - -Changes from 0.6 to 0.7.0-RELEASE: +Changes from 0.6 to 0.7 RELEASE - Better stability - Better performance (using more hmaps) - HTML color switcher menu diff --git a/COPYING b/COPYING old mode 100755 new mode 100644 diff --git a/INSTALL b/INSTALL old mode 100755 new mode 100644 diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 index e0b6e07..8d141ed --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ -MAKE=`tail -n 1 make.version` PREFIX=`grep "define PREFIX" src/glob.h | cut -d'"' -f2` -all: version base modules version +all: base modules version @echo "Now edit the ychat.conf and run ychat!" @echo "The config file is searched in the following order:" @echo " ./ychat.conf " @@ -8,40 +7,46 @@ all: version base modules version @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. -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 +install: deinstall + @echo "Instaling ychat to $(PREFIX)" + @cp bin/ychat $(PREFIX)/bin + @if ! test -d $(PREFIX)/lib/ychat; then mkdir -p $(PREFIX)/lib/ychat; fi + @if ! test -d $(PREFIX)/share/ychat/log/rooms; then mkdir -p $(PREFIX)/share/ychat/log/rooms; fi + @if ! test -d $(PREFIX)/etc; then mkdir $(PREFIX)/etc; fi + @if test -d mods; then cp -Rp mods $(PREFIX)/lib/ychat/mods; fi + @cp -Rp html $(PREFIX)/share/ychat/html + @cp -Rp lang $(PREFIX)/share/ychat/lang + @if test -f $(PREFIX)/etc/ychat.conf; then mv $(PREFIX)/etc/ychat.conf $(PREFIX)/etc/ychat.conf.bak; fi + @cp etc/ychat.conf etc/ychat.conf.tmp + @sed "s#mods/#$(PREFIX)/lib/ychat/mods/#" etc/ychat.conf.tmp > etc/ychat.conf.tmp.2 && mv etc/ychat.conf.tmp.2 etc/ychat.conf.tmp + @sed "s#\"log/#\"$(PREFIX)/share/ychat/log/#" etc/ychat.conf.tmp > etc/ychat.conf.tmp.2 && mv etc/ychat.conf.tmp.2 etc/ychat.conf.tmp + @sed "s#LANGUAGE_DIR=\"lang/#LANGUAGE_DIR=\"$(PREFIX)/share/ychat/lang/#" etc/ychat.conf.tmp > etc/ychat.conf.tmp.2 && mv etc/ychat.conf.tmp.2 etc/ychat.conf.tmp + @sed "s#HTML_TEMPLATE_DIR=\"html/#HTML_TEMPLATE_DIR=\"$(PREFIX)/share/ychat/html/#" etc/ychat.conf.tmp > etc/ychat.conf.tmp.2 && mv etc/ychat.conf.tmp.2 etc/ychat.conf.tmp + @mv etc/ychat.conf.tmp $(PREFIX)/etc/ychat.conf + @echo "yChat configuration file can be found under" + @echo " $(PREFIX)/etc/ychat.conf" + @echo "Copy it to ~/.ychat/ychat.conf to use local settings :-)" + @echo "Be sure that $(PREFIX)/share/ychat/logs is writable by your user or modify " + @echo "logging dirs in the ychat.conf to a local directory." + @echo "The most secure would be an additional user 'ychat'!" uninstall: deinstall deinstall: - @echo Install/deinstall is not supported! - @echo Start yChat with ./bin/ychat instead! - @exit 1 + @echo "Deinstalling ychat from $(PREFIX)" + @if test -f $(PREFIX)/bin/ychat; then rm -f $(PREFIX)/bin/ychat; fi + @if test -d $(PREFIX)/lib/ychat; then rm -Rf $(PREFIX)/lib/ychat; fi + @if test -d $(PREFIX)/share/ychat; then rm -Rf $(PREFIX)/share/ychat; fi + @echo "Done. Please remove manually $(PREFIX)/etc/ychat.conf to complete" modules: - @if test -d ./src/mods; then ${MAKE} -C ./src/mods; fi + @if test -d ./src/mods; then gmake -C ./src/mods; fi clean_modules: - @if test -d ./src/mods; then ${MAKE} -C ./src/mods clean; fi + @if test -d ./src/mods; then gmake -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 + @gmake -C ./src clean_base: - @${MAKE} -C ./src clean + @gmake -C ./src clean stats: @perl scripts/stats.pl run: @@ -59,26 +64,25 @@ yhttpdbase: #//*>> clean: clean_base clean_modules help: - @echo "You may run ${MAKE} with the following parameters:" - @grep "^ ${MAKE} " README + @echo "You may run gmake with the following parameters:" + @grep "^ gmake " README @echo "For more questions read the README file or contact mail@ychat.org!" setup: @./configure - @${MAKE} + @gmake config: @sh -c "scripts/config.sh" - @echo If you run ${MAKE} config from the command line then you may need + @echo If you run gmake 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 -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 + @echo "`grep VERSION src/msgs.h | cut -d'"' -f2`-`grep BRANCH src/msgs.h| cut -d'"' -f2` Build `grep BUILD src/msgs.h| cut -d' ' -f3`" debug: @gdb bin/ychat ychat.core diff --git a/NEWS b/NEWS index c720995..310dde8 100644 --- a/NEWS +++ b/NEWS @@ -1,15 +1,3 @@ -::(12.02.05)::Released yChat 0.7.5. The garbage collector will now run once a hour. The dynamic thread pool has been improved. Removed thre equiv-http-refresh meta tag from the online list. Added a minor bugfix in the /topic command. Implemented an HTML based list of all logged in users and the /users command which does the same. -::(12.02.05)::Released yChat 0.7.4.1 This new version includes a major bugfix made in the new dynamic thread pool which has been introdouced in 0.7.4. The bug resulted in a thread pool dead lock.. Tagged yChat 0.7.5-CURRENT into CVS. -::(12.02.05)::Released yChat 0.7.4. This release includes a code cleanup and a dynamic increasing thread pool. Also, some other thread pool and session engine improvements were made. The Makefiles got more organized and the HTTPD header has got a Content-length line. The Content-type text/plain is now also supported. The command line interface has got the ! (bang) operator. So you can run programs of your shell through yChat. The HTML interface has got a scrolling checkbox to de/activate the scrolling of the chat stream. Last but not least some bugfixes were made. -::(09.02.05)::Tagged yChat 0.7.4-PRERELEASE into CVS. The RELEASE will follow this week. -::(08.01.05)::We passed the build number 3000! 3000 times yChat has been compiled during the developing process since there are build numbers! Also the first steps have been made porting yChat/yhttpd to the Windows platform using Cygwin (yChat 0.7.4-CURRENT Build 3040 CYGWIN_NT-5.1 1.5.12 (0.116/4/2) i686). It runs without having installed Cygwin and having an 1MB cygwin1.dll file instead. There are still some issues (like dynamic modules [which means, that there are no chat commands and no color choser etc], command line interface, ncurses interface, database support) which do not yet run on Cygwin. But those issues will be resolved the next weeks. An alpha (experimental) binary yChat/Win32 release might be done also. -::(04.01.05)::First we wish all of you a happy new year. Second we have to announce that yhttpd 0.7-CURRENT now also has tested on an OpenBSD/i386 MP 3.6 box with success. Also yChat 0.7.4-CURRENT is now available from CVS. -::(29.12.04)::Released yChat 0.7.3-RELEASE. New features: Added the /all command (Global system message), added FreeBSD 5.3-RELEASE support, added chat.enableguest option. Renamed the /getstatus command into /about. Fixed some bugs. -::(09.11.04)::Released yChat 0.7.2-RELEASE. New features: /morph. Added the new standard html template design. Bugfixes: /away prints a . instead of a : if no away reason is given. /ko message was wrong. Displayed not room name of the user to be kicked out. /invisible command displayed wrong private messages. /getstatus had no help text. /msg and /s should now print the system time if printalwaystime == true. Added a blank to the /uptime message. /topic now prints the topic in the user's color. -- Fixed some typos. -::(06.11.04)::Released yChat and yhttpd 0.7.1-RELEASE. Added ${MAKE} to the Make file because some Linux distros dont use the "gmake" command for GNU make but just "make"! Modified the configure script to generate a make.version file. Removed some typos from the ychat.conf. Fixed the auto away message. This one will be posted in the room as public rather than only private to the auto-away-user. Fixed some documentation stuff for yhttpd because yhttpd does not need MySQL at all. Added the chat.maxlength.word option. -::(02.11.04)::We now provided a yhttpd-0.7.tar.bz2 file for download which is a source code package of the HTTP kernel of yChat. This one can be used as a stand alone web server. Also a yhttpd branch will be created for yhttpd as well. :) We also started to work on the 0.7.x-CURRENT versions which will become some day 0.8-RELEASE. -::(01.11.04)::We now provided a ychat-0.7.tar.bz2 file for download which is a source code package of the release we made yesterday. It also contains some fixes since then. You can download it on this site under Sourcecode -> Source packages -> CPP-yChat. :) ::(31.10.04)::After a long yChat 0.7-CURRENT developing phase we are proud to anounce yChat 0.7-RELEASE. By now, there may not any 0.7 release source packages for download available but you can fetch the release from the current cvs instead until source packages are available. This release has the biggest change log ever in yChat history. Here are some highlights: Included color switcher user interface, smart garbage collection engine, real MySQL support, nick registration + password protection, completly rewritten configure and Makefile scripts, perl script for source code stats, system_log and room_log, logout button, string replace for smileys e.g., additional CLI mode in parallel to the ncurses mode for the admin interface, memory watching, HTTP POST request handling in addition to POST request handling, CGI support, md5-summing of session ids to make reverse engineering of sessions harder, yhttpd generation script out of the yChat source tree, XML based configuration file, and lots of new configuration options which we can't list all here. yChat 0.7-RELEASE is known to compile and work correctly with GNU G++ 3.1, 3.2, 3.3 and 3.4. This announcement will be as well on Freshmeat.net on monday. ::(30.10.04)::yChat now has been tested on an OpenBSD 3.6 MP box with success. It has been compiled with GNU make 3.80 and GNU G++ 3.3.2. OpenBSD is now the 3rd operating system which is know to work with yChat. The other two tested OSes are still FreeBSD and Linux. All other UNIX and UNIX like operating systems should also work. But if you have tested it please write us an email to tell us about. ;) ::(26.09.04)::Renamed yChat Advanced 0.5 into yChat 0.6-RELEASE and yChat 0.6-CURRENT into yChat 0.7-CURRENT. diff --git a/README b/README old mode 100755 new mode 100644 index 16c31df..b240e00 --- a/README +++ b/README @@ -1,7 +1,7 @@ -yChat; Homepage: www.yChat.org; Version 0.7.5-RELEASE +yChat; Homepage: www.yChat.org; Version 0.7-RELEASE Copyright (C) 2003 Paul C. Buetow, Volker Richter -Copyright (C) 2004, 2005 Paul C. Buetow +Copyright (C) 2004 Paul C. Buetow ----------------------------------------------------------------- This program is free software; you can redistribute it and/or @@ -55,7 +55,8 @@ Engine powerd browsers like Mozilla, Firefox, Camino etc. yChat runs completely stand alone and does not need another webserver to build on like Apache and does not need to be run via any kind of CGI. yChat creates its own socket on a customized port (standard port: 2000) and seems to be a full -featured HTTP web server to the clients (web browsers). +features HTTP web server to the clients (web browsers). All it needs is an +external database server (currently MySQL only). The yChat code base can be converted to an yhttpd code base automaticaly. yhttpd is the webserver subset of yChat which runs completely stand alone and provides @@ -69,12 +70,11 @@ internal data structures hash maps are used to garuantee searching certain values in O(1) amount of time. If a hash maps gets full, it will be rehashed. The maximum usage in % can be redefined too (standard is 90%). Currently, yChat has been measured providing over 5000 hits/requests per second (chat message -postings) on a FreeBSD based server box while using less than 2% of CPU usage -on a Athlon XP 1900+. Performance seems to be limited by your bandwith only. -Also, each user gets its own session id (random string) with a standard length -of 50 chars to authenticate each logged in user. The length of the session id -can be redefined as well. Also, the session id will get md5-hashed optionally -so thats even harder to reverse engineering the session ids of other users. +postings) on a FreeBSD based server box. Performance seems to be limited by +your bandwith only. Also, each user gets its own session id (random string) +with a standard length of 50 chars to authenticate each logged in user. The +length of the session id can be redefined as well. Soon, OpenSSL sockets will +be included too to enable HTTPS chatting. - Its HTML template based and easy to customize via XML based configuration - All HTML sites are predefined as HTML-Template files and can be easily modified @@ -103,7 +103,7 @@ administrative tasks. In addition, you can switch to the CLI (command line interface) mode of the administration interface in order to be provided with more available functions (like keeping track of the current system usage etc.). If you dont like ncurses and/or the CLI you can disable both options in the pre- -compile options. +compile options. - It has logging capabilities - The logging manager keeps track to all yChat system messages (such as users @@ -131,8 +131,7 @@ time intervals (see also "Garbage collector"). Also, each Chat-User gets it own thread. There is no need of memory wastage by creating for each task a new process. All User-Threads are managed by a thread pool to avoid CPU wastage creating every time a new thread by reusing thread objects which have done its -jobs already and have been readded into the queue of the thread pool. The -standard sizes of the queue and the total pool size can be set in ychat.conf. +jobs already and have been added to the pool again.. - Its using a smart garbage collection engine - All users and rooms which dont have to be kept in the main memory (because the @@ -157,17 +156,15 @@ lot of user and room objects are created and destroyed frequently. yChat Makefiles only have been tested with GNU make and may not work with other make versions. -//<<* - mysql-client 4.x (3.x may do too but is not supported) Includes libmysqlclient and the mysql.h header files. -//*>> - ncurses 5.x Includes libncurses and the ncurses.h header files. - Screen Only needed if yChat should run in background with - ncurses or CLI enabled. + ncurses enabled. - Perl 5.x Is needed for some scripts. Is not needed if you use precompiled binaries. @@ -178,16 +175,13 @@ The following platforms have been tested with success. If you find out that a listed platform did not work at all please contact me: Operating system (arch) GNU G++ GNU make -- FreeBSD 5.3-RELEASE (i386) 3.4.2 3.80 - FreeBSD 5.2.1-RELEASE (i386) 3.3.3 3.80 -- FreeBSD 4.10-RELEASE (i386) 3.4.1 3.80 - FreeBSD 4.9-RELEASE (i386) 3.3.4 3.80 -- Gentoo Linux 2004 (i386) 3.3.2 3.80 -- OpenBSD 3.6 SMP (i386) 3.3.2 3.80 -- Red Hat Linux 8.0 SMP (i386) 3.2-7 3.79 +- FreeBSD 4.10-RELEASE (i386) 3.4.1 3.80 +- Gentoo Linux 2004.2 (i386) 3.3.2 3.80 +- OpenBSD 3.6 MP (i386) 3.3.2 3.80 - Slackware Linux 10.0 (i386) 3.4.0 3.80 -- SUSE Linux 9.0 (i386) 3.3.1 3.80 -- SUSE Linux 8.1 (i386) 3.2 3.79.1 +- SUSE Linux 8.0, G (i386) 3.3.1 3.80 Other platforms like Linux based systems, other BSD-Systems or UNICES are very likely to work too. @@ -197,11 +191,11 @@ are very likely to work too. Before you compile the source you have to be sure to use at least GCC version 3.1 with pthreads enabled. ( Type gcc -v to check it ). GCC 2.95 and 3.0 did not work while testing and WON'T BE SUPPORTED! -If you like to support yChat, please write us an email and tell what -you can/like/would help ;-]. Please also take a look at the yChat +If you like to support yChat++, please write us an email and tell what +you can/like/would help ;-]. Please also take a look at the yChat++ homepage which is located at http://www.yChat.org. -1.3.0 HOW TO OBTAIN YCHAT: +1.3.0 HOW TO OBTAIN YCHAT++: yChat can be downloaded as a source package or through CVS. @@ -225,7 +219,7 @@ Now you may continue with the installation. Invoke "./configure". Afterwards you will get prompted with the before-compile options of yChat. After choosing those options you are ready to type "gmake" -afterwards. See below what gmake is doing. +afterwards. //<<* If you have choosen MySQL database support, then take a look at section 1.3.2 @@ -238,21 +232,23 @@ You may also invoke gmake with the following options (the PREFIX can be set in the yChat configurator which will be launched by the top configure script or gmake config): - gmake or gmake all (compiles everything, also modules and runs "gmake mail") + gmake or gmake all (compiles everything, also modules) gmake base (only compiles the base) gmake base_start (only compiles the base and starts the server) gmake clean (cleans everything) gmake clean_base (only cleans the base obj and rpo files) gmake clean_modules (only cleans the modules .so files) gmake config (runs yChat configurator) + gmake deinstall (deinstalls ychat from PREFIX) gmake gpl (shows the GNU General Public License) gmake help (shows all available ychat gmake targets) - gmake mail (sends a mail to the yChat developers containing build opts.) + gmake install (installs ychat to PREFIX) gmake modules (only compiles modules) gmake mrproper (same as gmake clean plus removing all temp files) gmake setup (runs all configure scripts and afterwards gmake all) gmake start (compiles everything and starts the server) gmake stats (generates ychat statistics) + gmake uninstall (same as deinstall) gmake version (shows the current version of yChat) //<<* gmake yhttpdbase (generates an yhttpd code base) @@ -273,7 +269,6 @@ If you in hury, then you may just type gmake setup. In the yChat configurator you may just choose all the default values. If done, yChat will get compiled and is ready to run with ./bin/ychat! - //<<* 1.3.3 MYSQL SETUP diff --git a/TODO b/TODO index d20d2b1..2af0696 100644 --- a/TODO +++ b/TODO @@ -1,41 +1,31 @@ -Might do's for next RELEASE: -- Remove Chat stuff from yhttpd.conf -- dir : public vector -- Disable /help command for commands wich are not accessible for the - specific user. -- Flood protection -- Add /nick, /beam, /su -- Add / to whisper to the last person to whom the user has been whispered the last time. -- Room maxuser limit. +To do for next RELEASE: +- Improve some HTTPD-Stuff. +- Add socket timeouts. -To do in general for some later RELEASE: -- Not found sites should get a 404 error site! -- Implement dynamic timer -- Implement ncurse object browser -- Implement yXML subproject -- Implement ODBC support -- Implement login counter. -- Implement msg post counter. -- Implement online time counter. -- Implement hall of fame rankings of the counters above. Also add a msg/minute hall of fame. -- Implement traffic stats -- Implement more chat commands -- Implement new dynamic command permission method -- Implement SSL sockets with OpenSSL -- Implement user profiles -- Implement action form to input.html -- Implement IRC support -- Implement possibility sending Mails through external SMTP server (for password reminder etc) -- Implement chat moderator option -- Implement several HTML styles, each user can use his favourite style -- Implement compatibility to Opera, Links, Konqueror and Safari -- Implement browser side caching for gfx files support -- Disable http-refresh of the online frame. Reload it only if there has been s.t. changed. -- Implement a http:// url detection and make a link out of it! -- Remove user.cpp member variables as possible and replace them with hash maps - for (integer,mutex) and (string,mutex) pairs. Maybe use s.t. like this: - p_user->val("name"); to get the users name and p_user->val("name","val"); to - reset his name. Maybe use templates to get different types besides strings: - p_user->val("hits"); +To do in general: - Write changes of the configuration back into XML if wished. +- Add scroll pause button to input.html +- Add some chat commands +- Make more values of the conf object dynamic (on the fly changable by the CLI) +- Make the thread pool size dynamic +- Remove inline methods +- New dynamic command permission method + The admin should allow/deny commands for each user seperately +- Add PostgreSQL support +- Add SQLite support +- Add SSL sockets with OpenSSL +- Add user profiles +- Add action form to input.html +- FreeBSD ports tree inclusion +- Several HTML styles, each user can use his favourite style +- Chat moderator option +- Possibility sending Mails through external SMTP server + (for password reminder etc) +- Advanced chat statistics +- Add IRC support +- Add ICQ support +- Add MPI support (load balancing) +- Forum +- Compatibility to Opera, Links, Konqueror and Safari +- Add browser side caching for gfx files support diff --git a/configure b/configure index 20e84d0..0f9f844 100755 --- a/configure +++ b/configure @@ -9,7 +9,7 @@ fi perl -e ' use strict; $|=1; - sub check_gcc { + sub check { my $f = shift; my $s = shift; my $r = 0; @@ -29,32 +29,10 @@ perl -e ' print "GNU G++ $f.$s found!\n"; return $r; } - sub check_make { - print "Checking for GNU make\n"; - my $err = "No GNU make found.\nPlease install a version of GNU make!\n"; - my $make; - if (`which gmake`) { - $make = "gmake"; - } elsif ( `which make` ) { - $make = "make"; - } else { - print $err; - exit(1); - } - - `sh -c "$make -v > make.version 2>/dev/null"`; - if ( `cat make.version` =~ /GNU Make/ ) { - `echo $make >> make.version`; - } else { - print $err; - exit(1); - } - } - &check_make; print "Checking compiler version\n"; my $r = 0; for (my $i = 4; $i > 0 && $r == 0; --$i ) { - $r = &check_gcc(3,$i); + $r = &check(3,$i); } if ($r == 0) { print "No suitable g++ compiler found!\n"; @@ -70,9 +48,4 @@ perl -e ' exit(0); ' `echo "$*" | sed "s/-//g"` -if test -f err -then - rm -f err -else - echo You are ready to type gmake now! -fi +echo You are ready to type gmake now! diff --git a/etc/ychat.conf b/etc/ychat.conf index b611678..29be334 100644 --- a/etc/ychat.conf +++ b/etc/ychat.conf @@ -1,13 +1,9 @@ - + - - - @@ -64,9 +54,6 @@ - @@ -85,7 +72,7 @@ - - - - @@ -221,25 +195,25 @@ sets command status - @@ -302,9 +273,6 @@ - @@ -320,9 +288,6 @@ - @@ -335,9 +300,6 @@ - @@ -359,9 +321,6 @@ - @@ -394,18 +353,12 @@ - - @@ -434,7 +387,7 @@ Your room name too long!<br><br> - - @@ -592,16 +537,12 @@ - - @@ -631,7 +572,7 @@ If set to true, all command modules will be preloaded at server startup @@ -675,9 +616,6 @@ - diff --git a/html/admin.html b/html/admin.html index 3dee7a2..2811219 100755 --- a/html/admin.html +++ b/html/admin.html @@ -7,7 +7,7 @@ - + @@ -407,7 +407,7 @@
- yChat is OpenSource - get it at http://www.yChat.org + yChat is OpenSource - get it at http://www.yChat.org

diff --git a/html/demo.html b/html/demo.html index b04ee15..819ae27 100755 --- a/html/demo.html +++ b/html/demo.html @@ -7,7 +7,7 @@ - +
Hello %%nick%%, all chat configuration options available are summarized below. @@ -26,7 +26,7 @@

- yChat is OpenSource - get it at http://www.yChat.org + yChat is OpenSource - get it at http://www.yChat.org
diff --git a/html/colors.html b/html/colors.html index 8b23014..a881280 100755 --- a/html/colors.html +++ b/html/colors.html @@ -26,7 +26,7 @@ } //--> - +
%%msgs%%
@@ -39,7 +39,7 @@
(color of your nickname):
- +
@@ -51,7 +51,7 @@
(color of your text messages):
- +
@@ -22,6 +22,6 @@ This is the demo website provided by yChat :-)
%%ychat.version%%

%%INFO%%


-
yChat is OpenSource - get it at http://www.yChat.org
+
yChat is OpenSource - get it at http://www.yChat.org
diff --git a/html/frameset.html b/html/frameset.html index 672f8fa..51c58ee 100755 --- a/html/frameset.html +++ b/html/frameset.html @@ -6,7 +6,7 @@ %%ychat.version%% - + Your browser does not support frames, diff --git a/html/help.html b/html/help.html index ad9a25f..29ac849 100755 --- a/html/help.html +++ b/html/help.html @@ -7,11 +7,11 @@ - + - %%USERLIST%% + %%USERLIST%%
Hello %%nick%%, all chat commands available are summarized below (Please notice that only currently - in memory loaded command modules are listed here which should be the case by yChat default configuration). You can also access help for a specific command with the /help command. Example: /help commandname: + in memory loaded command modules are listed here which should be the case by yChat default configuration):

@@ -21,7 +21,7 @@

- yChat is OpenSource - get it at http://www.yChat.org + yChat is OpenSource - get it at http://www.yChat.org
diff --git a/html/index.html b/html/index.html index 983e7ef..7337772 100755 --- a/html/index.html +++ b/html/index.html @@ -7,14 +7,11 @@ - + - + + @@ -24,22 +21,22 @@ Enter your nick:
- +

Enter your password:
- +

Enter your room:
- +


-Register a new nick +Register a new nick

If you don't want to register you may login @@ -49,6 +46,6 @@ without a password using an unregistered nick.
-
-%%ychat.version%%

%%INFO%% -
-
yChat%%ychat.version%%

%%INFO%%
 


-
yChat is OpenSource - get it at http://www.yChat.org
+
yChat is OpenSource - get it at http://www.yChat.org
diff --git a/html/input.html b/html/input.html index 31ed9fe..b5e4cd2 100755 --- a/html/input.html +++ b/html/input.html @@ -10,7 +10,6 @@ - + + + + + + + + + +
-
- - - -
-
- Colors - Options - Help - Users - Admin - Logout - Scrolling: - -
+ + +
+
+ Colors + + Options + + Help + + Admin + + Logout +
diff --git a/html/online.html b/html/online.html index 6a10fd9..29b606d 100755 --- a/html/online.html +++ b/html/online.html @@ -2,8 +2,9 @@ + - + %%ROOMNAME%%

@@ -13,7 +14,7 @@ %%ROOMTOPIC%%
diff --git a/html/options.html b/html/options.html index 4dd5b35..6573441 100755 --- a/html/options.html +++ b/html/options.html @@ -6,7 +6,7 @@ Options menu - %%ychat.version%% - +
%%msgs%% @@ -16,19 +16,19 @@
Your E-Mail address:
- +

Your old password (needed if you want to enter a new password):
- +

Your new password:
- +

Your new password again:
- +

@@ -41,7 +41,7 @@ Your new password again:


- yChat is OpenSource - get it at http://www.yChat.org + yChat is OpenSource - get it at http://www.yChat.org

diff --git a/html/register.html b/html/register.html index 082e805..2caf27d 100755 --- a/html/register.html +++ b/html/register.html @@ -7,14 +7,11 @@ - + - + + @@ -24,30 +21,30 @@ Nick registration

%%INFO%% Enter your desired nick:
- +

Enter your E-Mail address:
- +

Enter your password:
- +

Enter your password again:
- +


-If you don't want to register go back +If you don't want to register go back
-
-Nick registration

%%INFO%% -
-
yChatNick registration

%%INFO%%
 


-
yChat is OpenSource - get it at http://www.yChat.org
+
yChat is OpenSource - get it at http://www.yChat.org
diff --git a/html/stream.html b/html/stream.html index 5bbdb43..493e9d3 100755 --- a/html/stream.html +++ b/html/stream.html @@ -8,27 +8,29 @@ - - Welcome to yChat %%nick%%! diff --git a/html/style.css b/html/style.css index ade4a1a..e31bd7e 100755 --- a/html/style.css +++ b/html/style.css @@ -1,52 +1,11 @@ -body, div { +BODY, TD { font-family: Verdana, Helvetica, sans-serif; - background-color: #000000; - color: #FFFFEF; font-size: 11pt; } - -input { - color: #000000; - font-family: Verdana, Helvetica, sans-serif; - text-decoration: none; - color: #FFFFEF; - background-color: #000000; - border: solid #555555 1px; - font-size: 9pt; - padding: 2px; -} - -input.text { - background-color: #AA5100; -} - -.fancy { - font-family: Verdana, Helvetica, sans-serif; - text-decoration: none; - color: #FFFFEF; - background-color: #000000; - border: solid #555555 1px; - font-size: 9pt; - padding: 2px; -} - -a:hover.fancy { - text-decoration: none; - color: #FFFFEF; - background-color: #323232; - border: solid #FFFFEF 1px; -} - -b { - background-color: #323232; - border: solid #555555 1px; -} - -body.stream { - background-color: #323232; +A { + color: #dddddd; } - .signature { - color: #AAAAAA; + color: #dddddd; font-size: 9pt; } diff --git a/scripts/buildnr.pl b/scripts/buildnr.pl index ee3d3e2..e691a11 100755 --- a/scripts/buildnr.pl +++ b/scripts/buildnr.pl @@ -13,7 +13,7 @@ close MSGS; foreach (@msgs) { - if ( /define BUILDNR/ ) + if ( /BUILDNR/ ) { s/(BUILDNR )(.+)$/$1.($2+1)/e; print; diff --git a/scripts/makeyhttpd.pl b/scripts/makeyhttpd.pl index 101343a..2805360 100644 --- a/scripts/makeyhttpd.pl +++ b/scripts/makeyhttpd.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# The yChat & yhttpd Project (2004, 2005) +# The yChat & yhttpd Project (2004) # # This scripts modifies the yChat sources to yhttpd sources. @@ -17,8 +17,6 @@ my @delete = ( 'src/data', 'src/irc', 'src/contrib/crypt', - 'src/modl.h', - 'src/modl.cpp', 'src/mods', 'src/mods/commands', 'src/mods/irc', @@ -77,7 +75,7 @@ foreach (@delete) { system("rm -Rf $_"); } -print "\nDeleting CVS directories\n"; +print "Deleting CVS directories\n"; system("find . -name CVS | xargs rm -Rf"); print "Creating new dirs\n->"; @@ -86,14 +84,14 @@ foreach (@createdir) { system("mkdir $_"); } -print "\nRenaming config file\n"; +print "Renaming config file\n"; system("mv etc/ychat.conf etc/yhttpd.conf"); print "Moving html templates\n"; system("mv demo.html html/index.html"); system("mv test.cgi notfound.html style.css html"); -print "Removing marked lines of code\n->"; +print "Removing marked lines of code\n ->"; &remove_marked_lines('.'); sub remove_marked_lines { diff --git a/scripts/stats.pl b/scripts/stats.pl index e5cc2b3..38cc67c 100755 --- a/scripts/stats.pl +++ b/scripts/stats.pl @@ -9,7 +9,6 @@ use strict; use scripts::modules::file; my %stats; -my $param = shift; &recursive("."); @@ -18,16 +17,19 @@ $stats{"Lines total"} = $stats{"Lines of source"} + $stats{"Lines of text"} + $stats{"Lines of HTML"}; -unless (defined $param) { - - print "$_ = " . $stats{$_} . "\n" - for ( sort keys %stats ); - -} else { - - print $stats{$_} . " " - for sort keys %stats; - +my $bool = 0; +foreach ( sort keys %stats ) +{ + if ($bool == 0) + { + print "$_ = " . $stats{$_} . "\n"; + $bool = 1; + } + else + { + print "$_ = " . $stats{$_} . "\n"; + $bool = 0; + } } print "\n"; diff --git a/src/chat/base.h b/src/chat/base.h index dc44c69..ae2e926 100755 --- a/src/chat/base.h +++ b/src/chat/base.h @@ -57,14 +57,14 @@ public: type_obj -> reconf (); } - void get_data( map *p_map_string ) + void get_data( map_string *p_map_string ) { smap::run_func( &base::get_data_ , (void*)p_map_string ); } static void get_data_( type* type_obj, void* v_arg ) { - type_obj -> get_data ( (map*) v_arg ); + type_obj -> get_data ( (map_string*) v_arg ); } diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp index 493c2a5..56e9189 100755 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -6,7 +6,6 @@ #include "chat.h" #include "../tool/tool.h" #include "../maps/mtools.h" -#include using namespace std; @@ -65,15 +64,13 @@ void chat::get_user_( room *room_obj, void *v_arg ) { container* param = (container*) v_arg; - if ( *((bool*)param->elem[1]) ) return; - param->elem[2] = (void*)room_obj->get_elem( *((string*)param->elem[0]), *((bool*)param->elem[1]) ); } void -chat::login( map &map_params ) +chat::login( map_string &map_params ) { string s_user = map_params["nick"]; @@ -156,8 +153,8 @@ chat::login( map &map_params ) { sess* p_sess = wrap::SMAN->create_session(); //p_sess->set_value( string("nick"), (void *) new string(s_user) ); - p_sess->set_user(p_user); - map_params["tmpid"] = p_sess->get_tmpid(); + p_sess->set_name(s_user); + map_params["tmpid"] = p_sess->get_id(); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_has_sess( true ); } @@ -167,9 +164,9 @@ chat::login( map &map_params ) { p_user = new user( s_user ); - // prove if nick is registered, else create a guest chatter. + // prove if nick is registered #ifdef DATABASE - map map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin"); + map_string map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin"); if ( map_results["nick"] == tool::to_lower(s_user) ) { @@ -194,23 +191,15 @@ chat::login( map &map_params ) } else #endif - { // If not registered prove if guest chatting is enabled. - if (wrap::CONF->get_elem("chat.enableguest") != "true") { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.noguest" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. - wrap::system_message( LOGINE4 + s_user ); - return; - } - - // Guest chatter are enabled, use standard font colors + { // If not registered use standard font colors map_params["color1"] = wrap::CONF->get_elem( "chat.html.user.color1" ); map_params["color2"] = wrap::CONF->get_elem( "chat.html.user.color2" ); map_params["status"] = wrap::CONF->get_elem( "chat.defaultrang" ); } sess* p_sess = wrap::SMAN->create_session(); - p_sess->set_user(p_user); - map_params["tmpid"] = p_sess->get_tmpid(); + p_sess->set_name(s_user); + map_params["tmpid"] = p_sess->get_id(); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_col1( map_params["color1"] ); p_user->set_col2( map_params["color2"] ); @@ -267,7 +256,7 @@ chat::login( map &map_params ) } void -chat::post( user* p_user, map &map_params ) +chat::post( user* p_user, map_string &map_params ) { p_user->renew_timeout(); @@ -284,37 +273,22 @@ chat::post( user* p_user, map &map_params ) + wrap::CONF->get_elem( "chat.msgs.err.messagelength" ) + "
\n"; p_user->msg_post( &s_private ); } - - int i_max_word_length = tool::string2int(wrap::CONF->get_elem( "chat.maxlength.word" )); - - // Check max word length - list list_msg = tool::split_string( s_msg, " "); - list::iterator iter = list_msg.begin(); - - for ( s_msg = ""; iter != list_msg.end(); ++iter ) - { - if ( iter->length() > i_max_word_length ) - { - string s_tmp[] = { iter->substr(0, i_max_word_length ), iter->substr(i_max_word_length) }; - iter = list_msg.erase( iter ); - iter = list_msg.insert( iter, s_tmp[1] ); - iter = list_msg.insert( iter, s_tmp[0] ); - --iter; - } - else - { - s_msg.append(*iter + " "); - } - } - + if ( wrap::CONF->get_elem( "chat.html.tagsallow" ) != "true" ) tool::strip_html( &s_msg ); - unsigned i_pos = s_msg.find( "/" ); + auto unsigned i_pos = s_msg.find( "/" ); if ( i_pos == 0 ) return p_user->command( s_msg ); - string_replacer(&s_msg); + if ( wrap::CONF->get_elem( "chat.html.replace.activate" ) == "true" ) + { + for (vector::iterator iter = vec_replace_keys.end()-1; + iter != vec_replace_keys.begin(); + iter-- ) + s_msg = tool::replace( s_msg, *iter, wrap::CONF->get_elem(map_replace_strings[*iter]) ); + } + string s_post; if ( wrap::CONF->get_elem( "chat.printalwaystime" ) == "true" ) @@ -338,15 +312,4 @@ chat::reconf() { } -void -chat::string_replacer(string *p_msg) { - if ( wrap::CONF->get_elem( "chat.html.replace.activate" ) == "true" ) - { - for (vector::iterator iter = vec_replace_keys.end()-1; - iter != vec_replace_keys.begin(); - iter-- ) - *p_msg = tool::replace( *p_msg, *iter, wrap::CONF->get_elem(map_replace_strings[*iter]) ); - } -} - #endif diff --git a/src/chat/chat.h b/src/chat/chat.h index 86b7c0b..c37bebc 100755 --- a/src/chat/chat.h +++ b/src/chat/chat.h @@ -21,7 +21,7 @@ using namespace std; class chat : public base, public perm { private: - map map_replace_strings; + map_string map_replace_strings; vector vec_replace_keys; public: @@ -46,10 +46,10 @@ public: static void get_user_( room* room_obj, void *v_arg ); // will be called every time a user tries to login. - void login( map &map_params ); + void login( map_string &map_params ); // will be called if a user posts a message. - void post ( user* u_user, map &map_params ); + void post ( user* u_user, map_string &map_params ); void del_elem( string s_name ) { @@ -57,6 +57,5 @@ public: } void reconf(); - void string_replacer(string *p_msg); }; #endif diff --git a/src/chat/room.cpp b/src/chat/room.cpp index c21639a..b2f17f8 100755 --- a/src/chat/room.cpp +++ b/src/chat/room.cpp @@ -9,10 +9,8 @@ using namespace std; room::room( string s_name ) : name( s_name ) { pthread_mutex_init( &mut_s_topic, NULL ); -#ifdef LOGGING p_logd = new logd( wrap::CONF->get_elem("chat.logging.roomlogdir") + get_lowercase_name(), wrap::CONF->get_elem("chat.logging.roomloglines") ); -#endif wrap::STAT->increment_num_rooms(); } @@ -23,9 +21,7 @@ room::~room() // Delete all user objects run_func( mtools::delete_obj ); -#ifdef LOGGING delete p_logd; -#endif pthread_mutex_destroy( &mut_s_topic ); pthread_mutex_destroy( &mut_s_name ); @@ -42,23 +38,14 @@ room::get_topic() } void -room::set_topic( string s_topic ) +room::set_topic( string s_topic) { pthread_mutex_lock ( &mut_s_topic ); - if ( s_topic == "" ) - this->s_topic = ""; - else - this->s_topic = s_topic + "

"; + this->s_topic = s_topic; pthread_mutex_unlock( &mut_s_topic ); reload_onlineframe(); } -void -room::set_topic( string s_topic, string s_color ) -{ - set_topic( "" + s_topic + ""); -} - void room::clean_room() { @@ -85,17 +72,13 @@ room::set_name( string s_name ) return; } -#ifdef LOGGING p_logd->flush_logs(); -#endif if ( s_name == "" ) return; name::set_name( s_name ); -#ifdef LOGGING p_logd->set_logfile( wrap::CONF->get_elem("chat.logging.roomlogdir"), get_lowercase_name() ); -#endif } #endif diff --git a/src/chat/room.h b/src/chat/room.h index 255f90e..cc59424 100755 --- a/src/chat/room.h +++ b/src/chat/room.h @@ -19,9 +19,7 @@ class room : public base, public name private: string s_topic; pthread_mutex_t mut_s_topic; -#ifdef LOGGING logd* p_logd; -#endif public: room( string s_name ); @@ -56,9 +54,7 @@ public: } void msg_post( string *p_msg ) { -#ifdef LOGGING p_logd->log_simple_line( logd::remove_html_tags(*p_msg) ); -#endif base::msg_post( p_msg ); } @@ -68,10 +64,9 @@ public: } virtual void set_name( string s_name ); - string get_topic(); - void set_topic( string s_topic ); - void set_topic( string s_topic, string s_color ); - void clean_room(); + virtual string get_topic(); + virtual void set_topic( string s_topic ); + virtual void clean_room(); diff --git a/src/chat/sess.cpp b/src/chat/sess.cpp index 801a6bf..b41c8ce 100755 --- a/src/chat/sess.cpp +++ b/src/chat/sess.cpp @@ -3,55 +3,27 @@ #include "sess.h" -sess::sess( string s_tmpid ) +sess::sess( string s_id ) { - this->p_user = NULL; - this->s_tmpid = s_tmpid; + this->sess_id=s_id; } sess::~sess() { + } string -sess::get_tmpid() +sess::get_id() { - return s_tmpid; -} - -string -sess::get_name() -{ - if ( p_user = NULL ) - return ""; - - return p_user->get_name(); -} - -void -sess::set_name(string s_name) -{ - if ( p_user != NULL ) - p_user->set_name(s_name); -} - -user* -sess::get_user() -{ - return p_user; -} - -void -sess::set_user(user* p_user) -{ - this->p_user = p_user; + return this->sess_id; } void sess::invalidate() { - this->s_tmpid = "0"; + this->sess_id = "0"; } #endif diff --git a/src/chat/sess.h b/src/chat/sess.h index 033e954..717564a 100755 --- a/src/chat/sess.h +++ b/src/chat/sess.h @@ -3,29 +3,24 @@ #ifndef SESS_H #define SESS_H +#include #include -#include "user.h" class cont; using namespace std; -class sess +class sess : public name { + private: - string s_tmpid; - user *p_user; + string sess_id; public: - sess(string s_tmpid); + sess(string s_id); ~sess(); - string get_tmpid(); - - void set_user(user* p_user); - user* get_user(); - void set_name(string s_name); - string get_name(); + string get_id(); void invalidate(); }; #endif diff --git a/src/chat/sman.cpp b/src/chat/sman.cpp index 6ae665f..464bf24 100755 --- a/src/chat/sman.cpp +++ b/src/chat/sman.cpp @@ -19,7 +19,7 @@ sman::~sman() pthread_mutex_destroy( &mut_i_session_count ); } -string sman::generate_id( int i_len ) +string sman::generate_id( int len ) { string valid_chars = wrap::CONF->get_elem("chat.session.validchars"); string s_ret = ""; @@ -27,7 +27,7 @@ string sman::generate_id( int i_len ) srand(time(0)+tool::string2int(wrap::CONF->get_elem("chat.session.kloakkey"))); int i_char; - for (int i = 0; i < i_len; i++) + for (int i = 0; i < len; i++) { i_char = rand() % 64; s_ret += valid_chars[i_char]; @@ -45,9 +45,9 @@ string sman::generate_id( int i_len ) sess *sman::create_session( ) { - string s_tmpid = generate_id( tool::string2int( wrap::CONF->get_elem( "chat.session.length" ) ) ); + string s_id = generate_id( tool::string2int( wrap::CONF->get_elem( "chat.session.length" ) ) ); - sess* p_sess = new sess( s_tmpid ); + sess* p_sess = new sess( s_id ); pthread_mutex_lock( &mut_i_session_count ); i_session_count++; @@ -56,8 +56,7 @@ sess *sman::create_session( ) #endif pthread_mutex_unlock( &mut_i_session_count ); - //???? - add_elem( p_sess, s_tmpid ); + add_elem( p_sess, s_id ); return p_sess; } diff --git a/src/chat/sman.h b/src/chat/sman.h index 20b1a76..1843aec 100755 --- a/src/chat/sman.h +++ b/src/chat/sman.h @@ -13,7 +13,7 @@ using namespace std; class sman : private smap { private: - string generate_id( int i_len ); + string generate_id( int len ); int i_session_count; pthread_mutex_t mut_i_session_count; @@ -24,10 +24,10 @@ private: public: sman(); ~sman(); - sess *get_session( string s_tmpid ); + sess *get_session( string s_id ); int get_session_count( ); sess *create_session( ); - void destroy_session( string s_tmpid ); + void destroy_session( string s_id ); #ifdef NCURSES void print_init_ncurses(); #endif diff --git a/src/chat/user.cpp b/src/chat/user.cpp index b292a11..a8b48dc 100755 --- a/src/chat/user.cpp +++ b/src/chat/user.cpp @@ -97,7 +97,7 @@ user::get_colored_name() } void -user::get_data( map *p_map_data ) +user::get_data( map_string *p_map_data ) { string s_req = (*p_map_data)["!get"]; @@ -393,8 +393,8 @@ user::command( string &s_command ) { check_restore_away(); - unsigned pos = s_command.find( "/" ); - unsigned pos2 = s_command.find( " " ); + auto unsigned int pos = s_command.find( "/" ); + auto unsigned int pos2 = s_command.find( " " ); if( pos != string::npos ) { s_command.replace( pos, 1, "" ); @@ -490,8 +490,6 @@ user::check_timeout( int* i_idle_timeout ) + "';"; msg_post( &s_quit ); set_online( false ); - - pthread_cond_signal( &cond_message ); } else if ( ! get_away() && i_idle_timeout[2] <= i_user_timeout ) @@ -500,7 +498,7 @@ user::check_timeout( int* i_idle_timeout ) string s_msg = wrap::CONF->get_elem("chat.msgs.userautoawaytimeout"); set_away( true, s_msg ); string s_msg2 = wrap::TIMR->get_time() + " " + get_colored_name()+ "" + s_msg + "
\n"; - get_room()->msg_post( &s_msg2 ); + msg_post( &s_msg2 ); get_room()->reload_onlineframe(); } } @@ -534,7 +532,7 @@ user::get_user_list( string &s_list ) } else if ( get_status() != tool::string2int( wrap::CONF->get_elem("chat.defaultrang") ) && ! get_fake() ) { - string s_status = "rang" + tool::int2string( get_status() ); + string s_status = "RANG" + tool::int2string( get_status() ); string s_msgs = wrap::CONF->get_elem( "chat.msgs." + s_status ); s_list.append("get_elem("chat.html.rangimages.location") + tool::to_lower(s_status) + ".png\"" ) .append( " alt='" ) diff --git a/src/chat/user.h b/src/chat/user.h index 4acb8f0..a88aea7 100755 --- a/src/chat/user.h +++ b/src/chat/user.h @@ -34,7 +34,7 @@ private: string s_pass; // password room* p_room; // pointer to the user's room. - map map_changed_data; // Needed to tell yChat which data to change after user is removed! + map_string map_changed_data; // Needed to tell yChat which data to change after user is removed! bool b_set_changed_data; // Only set change data if required! // Modules which are allowed to be executed by the user. @@ -72,10 +72,10 @@ private: void clean(); // gets specific data of this user und stores it in - // (*p_map)["nick"]. this method will be used + // (*p_map_string)["nick"]. this method will be used // every time data has to be got from every user of a room // or even of the system. - void get_data( map *p_map_data ); + void get_data( map_string *p_map_data ); string get_colored_name(); string get_colored_bold_name() diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index e39275a..006adc1 100755 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -16,13 +16,11 @@ cli::cli( ) cli::~cli() { } - int cli::parse_input( string s_input ) { string s_param = ""; unsigned i_pos = s_input.find_first_of(" "); - if ( i_pos != string::npos ) { s_param = s_input.substr(i_pos+1); s_input = s_input.substr(0, i_pos); @@ -31,20 +29,17 @@ cli::parse_input( string s_input ) if ( s_input.compare("help") == 0 || s_input.compare("h") == 0) { cout << CLIPRMO << "COMMAND LINE INTERFACE HELP MENU" << endl; - cout << CLIPRMO << " !command - Uses system to run a command" << endl; #ifdef DEBUG cout << CLIPRMO << " (d)ebug - Starts debug routine (cli.cpp)" << endl; #endif cout << CLIPRMO << " (e)cho VAR - Prints out configuration value of VAR" << endl - << CLIPRMO << " Wildcards can be used too, example: echo http*" << endl; + << CLIPRMO << " Wildcards can be used too, example: echo HTML*" << endl + << CLIPRMO << " (h)elp - Prints out this help!" << endl + << CLIPRMO << " (m)ysql - Runs MySQL client on yChat DB" << endl; #ifdef NCURSES - cout << CLIPRMO << " (ex)it - Quits CLI mode and respawns ncurses mode" << endl; + cout << CLIPRMO << " (q)uit - Quits CLI mode and respawns ncurses mode" << endl; #endif - cout << CLIPRMO << " (h)elp - Prints out this help!" << endl; - //<<* - cout << CLIPRMO << " (m)ysql - Runs MySQL client on yChat DB" << endl - << CLIPRMO << " (rel)oad - Reloads all modules" << endl; - //*>> + cout << CLIPRMO << " (rel)oad - Reloads all modules" << endl; #ifdef EXPERIM cout << CLIPRMO << " (re)conf - Reloads configuration (EXPERIMENTAL)" << endl; #endif @@ -53,18 +48,13 @@ cli::parse_input( string s_input ) << CLIPRMO << " (set) VAR VAL - Sets configuration value VAR to VAL" << endl << CLIPRMO << " (sh)ell - Runs a system shell" << endl << CLIPRMO << " (s)hutdown - Shuts down the whole server" << endl - << CLIPRMO << " (t)ime - Prints out time and uptime" << endl; - cout << CLIPRMO << " (unl)oad - Unloads all loaded modules" << endl;//<< - cout << CLIPRMO << " (u)nset VAR - Deletes configuration value VAR" << endl + << CLIPRMO << " (t)ime - Prints out time and uptime" << endl + << CLIPRMO << " (unl)oad - Unloads all loaded modules" << endl + << CLIPRMO << " (u)nset VAR - Deltetes configuration value VAR" << endl << CLIPRMO << " (v)ersion - Prints out version" << endl; cout << CLIPRMI; } - else if( s_input.at(0) == '!' ) - { - system( s_input.substr(1).c_str() ); - cout << CLIPRMI; - } #ifdef DEBUG else if( s_input.compare("d") == 0 || s_input.compare("debug") == 0 ) { @@ -75,7 +65,6 @@ cli::parse_input( string s_input ) else if( s_input.compare("echo") == 0 || s_input.compare("e") == 0 ) { string s_val; - // Check wildcards unsigned i_pos = s_param.find("*"); if ( i_pos != string::npos ) @@ -84,13 +73,11 @@ cli::parse_input( string s_input ) vector* p_vec = wrap::CONF->get_key_vector(); sort(p_vec->begin(), p_vec->end()); vector::iterator iter; - for ( iter = p_vec->begin(); iter != p_vec->end(); iter++ ) if ( iter->find(s_param) == 0 ) s_val.append( *iter + " := " + wrap::CONF->get_elem(*iter) + "\n" + CLIPRMO ); delete p_vec; } - else { s_val = wrap::CONF->get_elem(s_param); @@ -98,41 +85,30 @@ cli::parse_input( string s_input ) if( s_val.empty() ) s_val = "Value not set"; - cout << CLIPRMO << s_val << endl; cout << CLIPRMI; } - - //<<* else if( s_input.compare("mysql") == 0 || s_input.compare("m") == 0 ) { cout << CLIPRMO << CLIMSQL << endl; - system((wrap::CONF->get_elem("chat.system.mysqlclient") + " -p -h " + wrap::CONF->get_elem("chat.database.serverhost") + " -u " + wrap::CONF->get_elem("chat.database.user") ).c_str()); - cout << CLIPRMO << CLIWELC << endl; cout << CLIPRMI; } - //*>> - #ifdef NCURSES - else if( s_input.compare("exit") == 0 || s_input.compare("ex") == 0 ) + else if( s_input.compare("quit") == 0 || s_input.compare("q") == 0 ) { return 0; } #endif - - //<<* else if( s_input.compare("reload") == 0 || s_input.compare("rel") == 0 ) { cout << CLIPRMO; wrap::MODL->reload_modules(); cout << CLIPRMI; } - //*>> - #ifdef EXPERIM else if( s_input.compare("reconf") == 0 || s_input.compare("re") == 0 ) { @@ -140,47 +116,38 @@ cli::parse_input( string s_input ) cout << CLIPRMI; } #endif - else if( s_input.compare("rusage") == 0 || s_input.compare("r") == 0 ) { print_rusage(); cout << CLIPRMI; } - else if( s_input.compare("ru") == 0 || s_input.compare("rusageh") == 0 ) { cout << wrap::STAT->get_rusage_history( "ru_maxrss", string(CLIPRMO) + " " ); cout << CLIPRMI; } - else if( s_input.compare("set") == 0 ) { string s_varname = ""; i_pos = s_param.find_first_of(" "); - if ( i_pos != string::npos ) { s_varname = s_param.substr(0, i_pos); - if ( s_param.length() > i_pos+1 ) s_param = s_param.substr(i_pos+1); - else s_param = ""; } string s_old_val = wrap::CONF->get_elem(s_varname); - if ( !s_old_val.empty() ) { cout << CLIPRMO << "Old value: " << s_old_val << endl; wrap::CONF->del_elem(s_varname); } - wrap::CONF->add_elem(s_param, s_varname); cout << CLIPRMO << "New value: " << s_param << endl; cout << CLIPRMI; } - else if( s_input.compare("shell") == 0 || s_input.compare("sh") == 0 ) { cout << CLIPRMO << CLISHEL << endl; @@ -188,26 +155,20 @@ cli::parse_input( string s_input ) cout << CLIPRMO << CLIWELC << endl; cout << CLIPRMI; } - else if( s_input.compare("shutdown") == 0 || s_input.compare("s") == 0 ) { exit(0); } - else if( s_input.compare("t") == 0 || s_input.compare("time") == 0 ) { cout << CLIPRMO << "Time: " << wrap::TIMR->get_time() << endl << CLIPRMO << "Uptime: " << wrap::TIMR->get_uptime() << endl; cout << CLIPRMI; } - - //<<* else if( s_input.compare("unl") == 0 || s_input.compare("unload") == 0 ) { cout << CLIPRMO; wrap::MODL->unload_modules(); cout << CLIPRMI; } - //*>> - else if( s_input.compare("u") == 0 || s_input.compare("unset") == 0 ) { if (!s_param.empty()) @@ -225,13 +186,11 @@ cli::parse_input( string s_input ) cout << CLIPRMI; } } - else if( s_input.compare("v") == 0 || s_input.compare("version") == 0 ) { cout << CLIPRMO << tool::ychat_version() << " " << UNAME << endl; cout << CLIPRMI; } - else { cout << CLIPRMO << CLIHELP << "\"" << s_input << "\"" << endl; diff --git a/src/cli/cli.h b/src/cli/cli.h index cc5a5fc..2c37c17 100755 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -5,11 +5,11 @@ #include #include -#ifndef RUSAGE_SELF -#define RUSAGE_SELF 0 +#ifndef RUSAGE_SELF +#define RUSAGE_SELF 0 #endif -#ifndef RUSAGE_CHILDREN -#define RUSAGE_CHILDREN -1 +#ifndef RUSAGE_CHILDREN +#define RUSAGE_CHILDREN -1 #endif #include "../incl.h" @@ -30,7 +30,7 @@ class cli #endif { private: - int parse_input(string s_input); + int parse_input( string s_input ); public: cli( ); @@ -47,6 +47,7 @@ public: #else void start(); #endif + }; #endif diff --git a/src/conf/conf.cpp b/src/conf/conf.cpp index e54cbd4..6670f66 100755 --- a/src/conf/conf.cpp +++ b/src/conf/conf.cpp @@ -1,3 +1,5 @@ +// class conf implementation. + #ifndef CONF_CPP #define CONF_CPP @@ -17,7 +19,7 @@ conf::conf( string s_conf, map* p_start_params ) : nmap* p_vec) { //cout << p_vec->size() << ": (Value:" << p_child->Value() << ") (Type:" << p_child->Type() << ")" << endl; - if ( strcmp(p_child->Value(),"category") == 0 ) + if ( strcmp(p_child->Value(),"category") == 0) { p_vec->push_back(p_child->ToElement()->Attribute("name")); parse_xml(p_child, p_vec); p_vec->pop_back(); } - else if ( strcmp(p_child->Value(),"option") == 0 ) + else if ( strcmp(p_child->Value(),"option") == 0) { string s_option_name = ""; @@ -150,14 +152,4 @@ conf::exit_if_xml_error() const } } -//<<* -string -conf::colored_error_msg(string s_key) -{ - return "::get_elem("chat.html.errorcolor") - + "\">" + nmap::get_elem(s_key) + "
\n"; -} -//*>> - #endif diff --git a/src/conf/conf.h b/src/conf/conf.h index 3a7d0c6..7508872 100755 --- a/src/conf/conf.h +++ b/src/conf/conf.h @@ -1,7 +1,9 @@ +// class conf declaration. this class parses the server config file. + #ifndef CONF_H #define CONF_H -class conf; // Predefine for nmap.tmpl +class conf; #include "../incl.h" #include "../maps/nmap.h" @@ -16,12 +18,10 @@ private: TiXmlDocument* p_xml; void exit_if_xml_error() const; void parse_xml( TiXmlNode* p_node, vector* p_vec); - public: - conf(string s_conf, map* p_start_params); + //conf ( string s_conf ); + conf ( string s_conf, map* p_start_params ); ~conf(); - - string colored_error_msg( string s_key ); //<< }; #endif diff --git a/src/configure b/src/configure index 64cc404..2e0a34a 100755 --- a/src/configure +++ b/src/configure @@ -145,7 +145,6 @@ perl -e ' print "(The environment variables have to be seperated by an :)\n"; exit(1); } - `touch ../err`; return ""; } @@ -191,16 +190,14 @@ perl -e ' my $compiler = `tail -n 1 ../g++.version`; my $version = `tail -n 2 ../g++.version | head -n 1`; my $uname = `uname -srm`; - my $compopt = join "; ", split /\n/, `cat ../g++.version`; chomp $uname; - chomp $compopt; print "Configuring for $uname...\n"; chomp $cpp; chomp $version; while () { s/^(CC=).*\n/$1$compiler/; s/^(SRCS=).*/$1$cpp/; - s/ -frepo//; # unless $version =~ /3\.4/; + s/ -frepo// unless $version =~ /3\.4/; if ( $uname !~ /Linux/i ) { print "Disabling -ldl flag...\n" if s/ -ldl//; } @@ -235,7 +232,6 @@ perl -e ' open F, ">msgs.h" or die "msgs.h: $!\n"; foreach (@msgs) { s/(UNAME)(.+)$/UNAME "$uname"/; - s/(COMPOPT)(.+)$/COMPOPT "$compopt"/; print F; } close F; @@ -243,9 +239,7 @@ perl -e ' if ( -d "mods" ) { chdir("mods"); my $cflags = "-fno-inline -fno-default-inline"; - $cflags .= " -nostdlib" - if $uname =~ /FreeBSD/i - && `uname -r` =~ /^4\./; + $cflags .= " -nostdlib" if $uname !~ /Linux/i; system("echo $cflags > cflags.add"); system("./configure"); chdir(".."); diff --git a/src/data/con.cpp b/src/data/con.cpp index 316776b..b381232 100755 --- a/src/data/con.cpp +++ b/src/data/con.cpp @@ -8,36 +8,36 @@ using namespace std; con::con() { - p_mysql = mysql_init(NULL); + p_mysql = mysql_init(NULL); - while ( !p_mysql ) - { - wrap::system_message( MYSQLE1 ); - usleep( 30000000 ); - mysql_init(p_mysql); - } + while ( !p_mysql ) + { + wrap::system_message( MYSQLE1 ); + usleep( 30000000 ); + mysql_init(p_mysql); + } - while ( mysql_real_connect( - p_mysql, - (const char*)wrap::CONF->get_elem("chat.database.serverhost").c_str(), - (const char*)wrap::CONF->get_elem("chat.database.user").c_str(), - (const char*)wrap::CONF->get_elem("chat.database.password").c_str(), - (const char*)wrap::CONF->get_elem("chat.database.dbname").c_str(), - tool::string2int(wrap::CONF->get_elem("chat.database.port")), - NULL, 0 ) == NULL ) - { - wrap::system_message( MYSQLQU + string( mysql_error(p_mysql) ) ); - usleep( 30000000 ); - } + while ( mysql_real_connect( + p_mysql, + (const char*)wrap::CONF->get_elem("chat.database.serverhost").c_str(), + (const char*)wrap::CONF->get_elem("chat.database.user").c_str(), + (const char*)wrap::CONF->get_elem("chat.database.password").c_str(), + (const char*)wrap::CONF->get_elem("chat.database.dbname").c_str(), + tool::string2int(wrap::CONF->get_elem("chat.database.port")), + NULL, 0 ) == NULL ) + { + wrap::system_message( MYSQLQU + string( mysql_error(p_mysql) ) ); + usleep( 30000000 ); + } } con::~con() { - if ( p_mysql ) - { - if (mysql_ping( p_mysql ) != 0) - mysql_close( p_mysql ); - } + if ( p_mysql ) + { + if (mysql_ping( p_mysql ) != 0) + mysql_close( p_mysql ); + } } #endif diff --git a/src/data/con.h b/src/data/con.h index 5c454f8..bc54341 100755 --- a/src/data/con.h +++ b/src/data/con.h @@ -4,19 +4,19 @@ #ifndef CON_H #define CON_H -#include +#include #include #include "con_base.h" using namespace std; class con : public con_base - { - public: - MYSQL* p_mysql; - con( ); - ~con( ); - }; +{ +public: + MYSQL* p_mysql; + con( ); + ~con( ); +}; #endif #endif diff --git a/src/data/con_base.cpp b/src/data/con_base.cpp index 003a376..24bbbc9 100755 --- a/src/data/con_base.cpp +++ b/src/data/con_base.cpp @@ -8,11 +8,12 @@ using namespace std; con_base::con_base() { - renew_timeout( ); + renew_timeout( ); } con_base::~con_base() -{} +{ +} #endif diff --git a/src/data/con_base.h b/src/data/con_base.h index 16086db..60b12c2 100755 --- a/src/data/con_base.h +++ b/src/data/con_base.h @@ -9,11 +9,11 @@ using namespace std; class con_base : public timo - { - public: +{ +public: con_base( ); ~con_base( ); - }; +}; #endif #endif diff --git a/src/data/data.cpp b/src/data/data.cpp index 340883e..e8f309c 100644 --- a/src/data/data.cpp +++ b/src/data/data.cpp @@ -7,197 +7,194 @@ using namespace std; data::data() -{} +{ +} data::~data() -{} +{ +} -map +map_string data::select_user_data( string s_user, string s_query) { - string s_where_rule = " WHERE nick = \"" + s_user + "\""; - vector vec_elements; - MYSQL_RES* p_result = select_query( s_query, s_where_rule, vec_elements ); - return parse_result( p_result, vec_elements ); + string s_where_rule = " WHERE nick = \"" + s_user + "\""; + vector vec_elements; + MYSQL_RES* p_result = select_query( s_query, s_where_rule, vec_elements ); + return parse_result( p_result, vec_elements ); } -MYSQL_RES* +MYSQL_RES* data::select_query( string s_query, string s_where_rule, vector& vec_elements ) { - con* p_con = get_con(); + con* p_con = get_con(); - vec_elements = map_queries[s_query]; - string s_mysql_query = "SELECT "; - vector::iterator iter = vec_elements.begin(); + vec_elements = map_queries[s_query]; + string s_mysql_query = "SELECT "; + vector::iterator iter = vec_elements.begin(); - string s_table = *iter; - iter++; + string s_table = *iter; iter++; - while ( iter != vec_elements.end() ) - { - s_mysql_query.append( secure_query(*iter) ); - if ( ++iter != vec_elements.end() ) - s_mysql_query.append( ", " ); - } + while ( iter != vec_elements.end() ) + { + s_mysql_query.append( secure_query(*iter) ); + if ( ++iter != vec_elements.end() ) + s_mysql_query.append( ", " ); + } - s_mysql_query.append(" FROM " + s_table + s_where_rule ); - print_query( MYSQLQU + s_mysql_query ); + s_mysql_query.append(" FROM " + s_table + s_where_rule ); + print_query( MYSQLQU + s_mysql_query ); - MYSQL_RES* p_result = NULL; + MYSQL_RES* p_result = NULL; - if ( 0 == mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) ) - { - p_result = mysql_store_result( p_con->p_mysql ); - push_con( p_con ); - } + if ( 0 == mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) ) + { + p_result = mysql_store_result( p_con->p_mysql ); + push_con( p_con ); + } - else - { - wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) ); - if (p_con != NULL) - delete p_con; - } + else + { + wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) ); + if (p_con != NULL) + delete p_con; + } - return p_result; + return p_result; } -map +map_string data::parse_result( MYSQL_RES* p_result, vector& vec_elements ) { - map map_ret; - if ( p_result != NULL ) - { - MYSQL_ROW row; - vector::iterator vec_iter = vec_elements.begin(); - vec_iter++; - - while( (row = mysql_fetch_row(p_result)) ) - for ( int i=0; i < mysql_num_fields(p_result); i++, vec_iter++ ) - map_ret[*vec_iter] = string(row[i]); - - mysql_free_result( p_result ); - } - return map_ret; + map_string map_ret; + if ( p_result != NULL ) + { + MYSQL_ROW row; + vector::iterator vec_iter = vec_elements.begin(); vec_iter++; + + while( (row = mysql_fetch_row(p_result)) ) + for ( int i=0; i < mysql_num_fields(p_result); i++, vec_iter++ ) + map_ret[*vec_iter] = string(row[i]); + + mysql_free_result( p_result ); + } + return map_ret; } void -data::insert_user_data( string s_user, string s_query, map insert_map ) +data::insert_user_data( string s_user, string s_query, map_string insert_map ) { - insert_query( s_query, insert_map ); + insert_query( s_query, insert_map ); } void -data::insert_query( string s_query, map map_insert ) +data::insert_query( string s_query, map_string map_insert ) { - vector vec_elements = map_queries[s_query]; - vector::iterator iter = vec_elements.begin(); - - string s_table = *iter; - iter++; - string s_mysql_query = "INSERT INTO " + s_table + " ("; - - while ( iter != vec_elements.end() ) - { - s_mysql_query.append( *iter ); - - if ( ++iter != vec_elements.end() ) - s_mysql_query.append( ", " ); - else - s_mysql_query.append( ") VALUES(" ); - } + vector vec_elements = map_queries[s_query]; + vector::iterator iter = vec_elements.begin(); + + string s_table = *iter; iter++; + string s_mysql_query = "INSERT INTO " + s_table + " ("; + + while ( iter != vec_elements.end() ) + { + s_mysql_query.append( *iter ); + + if ( ++iter != vec_elements.end() ) + s_mysql_query.append( ", " ); + else + s_mysql_query.append( ") VALUES(" ); + } - iter = vec_elements.begin(); - iter++; + iter = vec_elements.begin(); iter++; - while ( iter != vec_elements.end() ) - { - s_mysql_query.append( "\"" + secure_query(map_insert[*iter]) + "\"" ); - if ( ++iter != vec_elements.end() ) - s_mysql_query.append( ", " ); - else - s_mysql_query.append( ")" ); - } + while ( iter != vec_elements.end() ) + { + s_mysql_query.append( "\"" + secure_query(map_insert[*iter]) + "\"" ); + if ( ++iter != vec_elements.end() ) + s_mysql_query.append( ", " ); + else + s_mysql_query.append( ")" ); + } - print_query( MYSQLQU + s_mysql_query ); + print_query( MYSQLQU + s_mysql_query ); - con* p_con = get_con(); + con* p_con = get_con(); - if ( 0 != mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) ) - wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) ); + if ( 0 != mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) ) + wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) ); - push_con( p_con ); + push_con( p_con ); - return; + return; } -void -data::update_user_data( string s_user, string s_query, map update_map ) +void +data::update_user_data( string s_user, string s_query, map_string update_map ) { - vector vec_elements = map_queries[s_query]; + vector vec_elements = map_queries[s_query]; - if ( vec_elements.size() == 0 ) - return; + if ( vec_elements.size() == 0 ) + return; - vector::iterator iter = vec_elements.begin(); - vector::iterator iter_second = vec_elements.begin(); - iter_second++; + vector::iterator iter = vec_elements.begin(); + vector::iterator iter_second = vec_elements.begin(); + iter_second++; - string s_table = *iter; - iter++; - string s_mysql_query = "UPDATE " + s_table + " SET "; - bool b_flag = 0; + string s_table = *iter; iter++; + string s_mysql_query = "UPDATE " + s_table + " SET "; + bool b_flag = 0; - while ( iter != vec_elements.end() ) - { - if ( update_map[*iter] == "" ) // Dont update data if it has not been changed / if its empty! - { - iter++; - continue; - } + while ( iter != vec_elements.end() ) + { + if ( update_map[*iter] == "" ) // Dont update data if it has not been changed / if its empty! + { + iter++; + continue; + } - if ( iter != iter_second && b_flag ) - s_mysql_query.append( ", " ); + if ( iter != iter_second && b_flag ) + s_mysql_query.append( ", " ); - s_mysql_query.append( *iter + "=\"" + secure_query(update_map[*iter]) + "\"" ); - b_flag = 1; - iter++; - } + s_mysql_query.append( *iter + "=\"" + secure_query(update_map[*iter]) + "\"" ); + b_flag = 1; + iter++; + } - if ( b_flag ) - { - s_mysql_query.append( " WHERE nick=\"" + tool::to_lower(s_user) + "\"" ); + if ( b_flag ) + { + s_mysql_query.append( " WHERE nick=\"" + tool::to_lower(s_user) + "\"" ); - con* p_con = get_con(); - print_query( MYSQLQU + s_mysql_query ); + con* p_con = get_con(); + print_query( MYSQLQU + s_mysql_query ); - if ( 0 != mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) ) - wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) ); + if ( 0 != mysql_query( p_con->p_mysql, (const char*)s_mysql_query.c_str() ) ) + wrap::system_message( MYSQLQU + string( mysql_error(p_con->p_mysql) ) ); - push_con( p_con ); - } + push_con( p_con ); + } } string data::secure_query( string s_mysql_query ) { - // Prevent from MySQL injection attacks (escaping " and \) - unsigned i_pos = s_mysql_query.find("\\"); + // Prevent from MySQL injection attacks (escaping " and \) + unsigned i_pos = s_mysql_query.find("\\"); - while ( i_pos != string::npos ) - { - s_mysql_query.replace( i_pos, 1, "/" ); - i_pos = s_mysql_query.find("\\"); - } + while ( i_pos != string::npos ) + { + s_mysql_query.replace( i_pos, 1, "/" ); + i_pos = s_mysql_query.find("\\"); + } - i_pos = s_mysql_query.find("\""); + i_pos = s_mysql_query.find("\""); - while ( i_pos != string::npos ) - { - s_mysql_query.replace( i_pos, 1, "'" ); - i_pos = s_mysql_query.find("\""); - } + while ( i_pos != string::npos ) + { + s_mysql_query.replace( i_pos, 1, "'" ); + i_pos = s_mysql_query.find("\""); + } - return s_mysql_query; + return s_mysql_query; } #endif diff --git a/src/data/data.h b/src/data/data.h index 21c03d2..fa21763 100644 --- a/src/data/data.h +++ b/src/data/data.h @@ -10,20 +10,20 @@ using namespace std; class data : public data_base // data implementation used in data.h - { - private: - MYSQL_RES* select_query( string s_query, string s_where_rule, vector& vec_elements ); - map parse_result( MYSQL_RES* p_result, vector& vec_elements ); - void insert_query( string s_query, map map_insert ); - string secure_query( string s_mysql_query ); - public: +{ +private: + MYSQL_RES* select_query( string s_query, string s_where_rule, vector& vec_elements ); + map_string parse_result( MYSQL_RES* p_result, vector& vec_elements ); + void insert_query( string s_query, map_string map_insert ); + string secure_query( string s_mysql_query ); +public: data( ); - ~data( ); + ~data( ); - map select_user_data( string s_user, string s_query ); - void insert_user_data( string s_user, string s_query, map insert_map ); - void update_user_data( string s_user, string s_query, map update_map ); - }; + map_string select_user_data( string s_user, string s_query ); + void insert_user_data( string s_user, string s_query, map_string insert_map ); + void update_user_data( string s_user, string s_query, map_string update_map ); +}; #endif #endif diff --git a/src/data/data_base.cpp b/src/data/data_base.cpp index 2cbe070..c8bf033 100644 --- a/src/data/data_base.cpp +++ b/src/data/data_base.cpp @@ -8,94 +8,92 @@ using namespace std; data_base::data_base( ) { - pthread_mutex_init ( &mut_con, NULL ); - - vector vec_keys = *wrap::CONF->get_key_vector(); - vector::iterator iter; + pthread_mutex_init ( &mut_con, NULL ); + + vector vec_keys = *wrap::CONF->get_key_vector(); + vector::iterator iter; + + // Reads all DATA_ elements of conf.txt! + for ( iter = vec_keys.begin(); iter != vec_keys.end(); iter++ ) + { + if ( iter->length() > 20 + && iter->compare(0, 19, "chat.database.mysql") == 0 + && iter->find(".descr") == string::npos ) + { + vector vec_tokens; + string s_element = wrap::CONF->get_elem(*iter); + unsigned i_pos = 0; + + for ( bool b_find = 1; b_find; ) + { + i_pos = s_element.find_first_of( " ", 0 ); + + if ( i_pos != string::npos ) + { + vec_tokens.push_back( s_element.substr(0, i_pos) ); + s_element = s_element.substr( i_pos+1 ); + } - // Reads all DATA_ elements of conf.txt! - for ( iter = vec_keys.begin(); iter != vec_keys.end(); iter++ ) + else { - if ( iter->length() > 20 - && iter->compare(0, 19, "chat.database.mysql") == 0 - && iter->find(".descr") == string::npos ) - { - vector vec_tokens; - string s_element = wrap::CONF->get_elem(*iter); - unsigned i_pos = 0; - - for ( bool b_find = 1; b_find; ) - { - i_pos = s_element.find_first_of( " ", 0 ); - - if ( i_pos != string::npos ) - { - vec_tokens.push_back( s_element.substr(0, i_pos) ); - s_element = s_element.substr( i_pos+1 ); - } - - else - { - vec_tokens.push_back( s_element ); - b_find = 0; - } - } - - string s_mysqlquery = iter->substr(20); - wrap::system_message(MYSQLQ2 + s_mysqlquery); - map_queries[s_mysqlquery] = vec_tokens; - } + vec_tokens.push_back( s_element ); + b_find = 0; } + } + + string s_mysqlquery = iter->substr(20); + wrap::system_message(MYSQLQ2 + s_mysqlquery); + map_queries[s_mysqlquery] = vec_tokens; + } + } } -void data_base::initialize_connections() -{ - int i_min_con = tool::string2int( wrap::CONF->get_elem("chat.database.mincon") ), - i_max_con = tool::string2int( wrap::CONF->get_elem("chat.database.maxcon") ); +void data_base::initialize_connections() { + int i_min_con = tool::string2int( wrap::CONF->get_elem("chat.database.mincon") ), + i_max_con = tool::string2int( wrap::CONF->get_elem("chat.database.maxcon") ); - wrap::system_message(DATAIN0 + tool::int2string(i_max_con)); - wrap::system_message(DATAIN1 + tool::int2string(i_min_con)); + wrap::system_message(DATAIN0 + tool::int2string(i_max_con)); + wrap::system_message(DATAIN1 + tool::int2string(i_min_con)); - for ( int i = 0; i < i_min_con && i < i_max_con; i++ ) - push_back( new con() ); + for ( int i = 0; i < i_min_con && i < i_max_con; i++ ) + push_back( new con() ); #ifdef NCURSES - - print_queue_size(); + print_queue_size(); #endif } data_base::~data_base() { - pthread_mutex_destroy ( &mut_con ); + pthread_mutex_destroy ( &mut_con ); } -map +map_string data_base::select_user_data( string s_user, string s_query) { - print_query( DATAQUE + s_query ); - map map_ret; - return map_ret; + print_query( DATAQUE + s_query ); + map_string map_ret; + return map_ret; } void -data_base::insert_user_data( string s_user, string s_query, map insert_map ) +data_base::insert_user_data( string s_user, string s_query, map_string insert_map ) { - print_query( DATAQUE + s_query ); + print_query( DATAQUE + s_query ); } void -data_base::update_user_data( string s_user, string s_query, map update_map ) +data_base::update_user_data( string s_user, string s_query, map_string update_map ) { - print_query( DATAQUE + s_query ); + print_query( DATAQUE + s_query ); } void data_base::print_query( string s_query ) { #ifdef DATA_PRINT_QUERIES - print_query_( s_query ); + print_query_( s_query ); #endif } @@ -103,125 +101,119 @@ data_base::print_query( string s_query ) void data_base::print_query_( string s_query ) { - wrap::system_message( s_query ); + wrap::system_message( s_query ); } #endif con* data_base::get_con() { - pthread_mutex_lock( &mut_con ); + pthread_mutex_lock( &mut_con ); - if ( empty() ) - { - wrap::system_message( DATANEW + string("(") + tool::int2string(size()+1) + ")" ); - pthread_mutex_unlock( &mut_con ); - return new con; - } + if ( empty() ) + { + wrap::system_message( DATANEW + string("(") + tool::int2string(size()+1) + ")" ); + pthread_mutex_unlock( &mut_con ); + return new con; + } - else if ( size() > i_max_con-1 ) - { - wrap::system_message( DATAMAX + string("(") + tool::int2string(i_max_con) + ")" ); - usleep( 5000000 ); - pthread_mutex_unlock( &mut_con ); - return get_con(); - } + else if ( size() > i_max_con-1 ) + { + wrap::system_message( DATAMAX + string("(") + tool::int2string(i_max_con) + ")" ); + usleep( 5000000 ); + pthread_mutex_unlock( &mut_con ); + return get_con(); + } - con* p_con = *begin(); - pop_front(); + con* p_con = *begin(); + pop_front(); #ifdef NCURSES - - print_queue_size(); + print_queue_size(); #endif - pthread_mutex_unlock( &mut_con ); - wrap::system_message( DATAGET ); + pthread_mutex_unlock( &mut_con ); + wrap::system_message( DATAGET ); - p_con->renew_timeout(); - return p_con; + p_con->renew_timeout(); + return p_con; } void -data_base::push_con( con* p_con ) +data_base::push_con( con* p_con ) { - pthread_mutex_lock( &mut_con ); - push_front( p_con ); + pthread_mutex_lock( &mut_con ); + push_front( p_con ); #ifdef NCURSES - - print_queue_size(); + print_queue_size(); #endif - - pthread_mutex_unlock( &mut_con ); - wrap::system_message( DATAADD ); + pthread_mutex_unlock( &mut_con ); + wrap::system_message( DATAADD ); } #ifdef NCURSES void data_base::print_queue_size() { - if ( wrap::NCUR->is_ready() ) + if ( wrap::NCUR->is_ready() ) { - mvprintw( NCUR_CON_QUEUE_X,NCUR_CON_QUEUE_Y, "Con. queue: %d ", size()); - refresh(); - } + mvprintw( NCUR_CON_QUEUE_X,NCUR_CON_QUEUE_Y, "Con. queue: %d ", size()); + refresh(); + } } #endif void data_base::disconnect_all_connections() { - wrap::system_message( DATADIS ); - pthread_mutex_lock( &mut_con ); + wrap::system_message( DATADIS ); + pthread_mutex_lock( &mut_con ); - while ( !empty() ) - { - con* p_con = *begin(); - pop_front(); - delete p_con; - } - - pthread_mutex_unlock( &mut_con ); + while ( !empty() ) + { + con* p_con = *begin(); + pop_front(); + delete p_con; + } + + pthread_mutex_unlock( &mut_con ); #ifdef NCURSES - - print_queue_size(); + print_queue_size(); #endif } void data_base::check_data_con_timeout() { - int i_timeout_time = tool::string2int(wrap::CONF->get_elem("chat.database.contimeout")); - int i_last_activity; + int i_timeout_time = tool::string2int(wrap::CONF->get_elem("chat.database.contimeout")); + int i_last_activity; - pthread_mutex_lock( &mut_con ); - - list< list::iterator > erase_list; - for ( list::iterator iter = begin(); + pthread_mutex_lock( &mut_con ); + + list< list::iterator > erase_list; + for ( list::iterator iter = begin(); iter != end(); iter++ ) - { - i_last_activity = (int) (*iter)->get_last_activity(); - if ( i_timeout_time <= i_last_activity ) - { - con* p_con = *iter; - erase_list.push_back(iter); - delete p_con; - wrap::system_message(DATADI2 + tool::int2string(size()-erase_list.size()+1) + "," - + tool::int2string(i_timeout_time) + "," - + tool::int2string(i_last_activity) + ")"); - } - } + { + i_last_activity = (int) (*iter)->get_last_activity(); + if ( i_timeout_time <= i_last_activity ) + { + con* p_con = *iter; + erase_list.push_back(iter); + delete p_con; + wrap::system_message(DATADI2 + tool::int2string(size()-erase_list.size()+1) + "," + + tool::int2string(i_timeout_time) + "," + + tool::int2string(i_last_activity) + ")"); + } + } for ( list< list::iterator >::iterator erase_iter = erase_list.begin(); erase_iter != erase_list.end(); erase_iter++ ) - erase( *erase_iter ); + erase( *erase_iter ); #ifdef NCURSES - print_queue_size(); #endif - - pthread_mutex_unlock( &mut_con ); + pthread_mutex_unlock( &mut_con ); } diff --git a/src/data/data_base.h b/src/data/data_base.h index 97ad31e..b38d978 100644 --- a/src/data/data_base.h +++ b/src/data/data_base.h @@ -11,38 +11,35 @@ using namespace std; class data_base : protected list - { - private: - pthread_mutex_t mut_con; - int i_max_con; +{ + private: + pthread_mutex_t mut_con; + int i_max_con; #ifdef NCURSES - - void print_queue_size(); + void print_queue_size(); #endif - protected: - map< string, vector > map_queries; - void print_query( string s_query ); + protected: + map< string, vector > map_queries; + void print_query( string s_query ); #ifdef DATA_PRINT_QUERIES - - virtual void print_query_( string s_query ); + virtual void print_query_( string s_query ); #endif - - con* get_con(); - void push_con( con* p_con ); - - public: - data_base(); - ~data_base(); - - void initialize_connections(); - virtual map select_user_data( string s_user, string s_query ); - virtual void insert_user_data( string s_user, string s_query, map insert_map ); - virtual void update_user_data( string s_user, string s_query, map update_map ); - void disconnect_all_connections(); - void check_data_con_timeout(); - }; + con* get_con(); + void push_con( con* p_con ); + + public: + data_base(); + ~data_base(); + + void initialize_connections(); + virtual map_string select_user_data( string s_user, string s_query ); + virtual void insert_user_data( string s_user, string s_query, map_string insert_map ); + virtual void update_user_data( string s_user, string s_query, map_string update_map ); + void disconnect_all_connections(); + void check_data_con_timeout(); +}; #endif #endif diff --git a/src/glob.h b/src/glob.h index 99954b0..a426042 100755 --- a/src/glob.h +++ b/src/glob.h @@ -5,6 +5,7 @@ gmake config in the main directory! */ + #include // global variables. @@ -31,7 +32,7 @@ Should yChat get compiled with database support? Currently MyS- QL only is a supported database. */ -#define DATABASE +//#define DATABASE #ifdef DATABASE /* - CONFIG - @@ -64,7 +65,7 @@ Please specify the size of a temporary buffer. (Will be used f- or different tasks) */ -#define READBUF 2048 +#define READBUF 1024 /* - CONFIG - Please specify the maximum length of a HTTP post request. @@ -83,7 +84,7 @@ is enabled or in the server-window if yChat has been compiled without ncurses support. This option shows you all incoming requests with the client IP and port numbers. You probably want - this to be turned off if you have heavy server load. + this to be turned of if you have heavy server load. */ //#define VERBOSE @@ -94,11 +95,6 @@ */ //#define EXPERIM -/* - CONFIG - - Should yChat get compiled with logging support? -*/ -#define LOGGING - /* - CONFIG - Should yChat get compiled with ncurses support? */ @@ -183,6 +179,8 @@ using namespace std; +// some custom typedefs for datatypes which are needed often. +typedef map map_string; typedef int function( void *v_arg ); struct container diff --git a/src/html.cpp b/src/html.cpp index 3b5f6b0..1f839bb 100755 --- a/src/html.cpp +++ b/src/html.cpp @@ -27,7 +27,7 @@ html::clear_cache( ) } string -html::parse( map &map_params ) +html::parse( map_string &map_params ) { string s_file = map_params["request"]; @@ -37,10 +37,10 @@ html::parse( map &map_params ) // if not, read file. if ( ! smap::is_avail( s_file ) ) { - string s_path = get_name(); - ifstream if_templ( s_path.append( s_file ).c_str(), ios::binary ); + auto string s_path = get_name(); + auto ifstream fs_templ( s_path.append( s_file ).c_str(), ios::binary ); - if ( ! if_templ ) + if ( ! fs_templ ) { wrap::system_message( OFFFOUND + s_path ); if(map_params["request"]== wrap::CONF->get_elem( "httpd.html.notfound" )) @@ -51,17 +51,14 @@ html::parse( map &map_params ) } - char c_buf; - while( !if_templ.eof() ) + auto char c_buf; + while( !fs_templ.eof() ) { - if_templ.get( c_buf ); - s_templ += c_buf; + fs_templ.get( c_buf ); + s_templ+=c_buf; } - if ( map_params["content-type"].compare(0,5,"text/") == 0 ) - s_templ.erase(s_templ.end()-1); - - if_templ.close(); + fs_templ.close(); wrap::system_message( TECACHE + s_path ); @@ -78,7 +75,7 @@ html::parse( map &map_params ) } // find %%KEY%% token and substituate those. - unsigned pos[2]; + auto unsigned int pos[2]; pos[0] = pos[1] = 0; for(;;) @@ -95,8 +92,8 @@ html::parse( map &map_params ) break; // get key and val. - string s_key = s_templ.substr( pos[0], pos[1]-pos[0] ); - string s_val = wrap::CONF->get_elem( s_key ); + auto string s_key = s_templ.substr( pos[0], pos[1]-pos[0] ); + auto string s_val = wrap::CONF->get_elem( s_key ); // if s_val is empty use map_params. if ( s_val.empty() ) @@ -106,9 +103,9 @@ html::parse( map &map_params ) s_templ.replace( pos[0]-2, pos[1]-pos[0]+4, s_val ); // calculate the string displacement. - int i_diff = s_val.length() - ( pos[1] - pos[0] + 4); + auto int i_dif = s_val.length() - ( pos[1] - pos[0] + 4); - pos[1] += 2 + i_diff; + pos[1] += 2 + i_dif; }; @@ -117,7 +114,7 @@ html::parse( map &map_params ) //<<* void -html::online_list( user *p_user, map &map_params ) +html::online_list( user *p_user, map_string &map_params ) { // prepare user_list. string s_list; @@ -142,7 +139,6 @@ html::print_cached( int i_docs ) mvprintw( NCUR_CACHED_DOCS_X, NCUR_CACHED_DOCS_Y, "Docs: %d ", i_docs); refresh(); } - #endif #endif diff --git a/src/html.h b/src/html.h index 1bb486a..70d91d3 100755 --- a/src/html.h +++ b/src/html.h @@ -12,24 +12,27 @@ using namespace std; class html : public smap, name { +private: + public: - html( ); + // public methods. + html( ); // simple constructor. ~html( ); - // Clears the template cache so that new html templates will be read - // from hard disk. This method is needed after changeing s.t. on + // clears the template cache so that new html templates will be read + // from hard disk. this method is needed after changeing s.t. on // the html-template files. void clear_cache( ); - // Returns a parsed html-template. this method will check first if the + // returns a parsed html-template. this method will check first if the // required html-template exists inside the classes template cache. if not // then the file will be read from file and added to the cache. // afterwards the html-template will be parsed and returned. // map_params contains the client request parameters which also will be // used for string substituation. - string parse( map &map_params ); + string parse( map_string &map_params ); - void online_list( user *p_user, map &map_params ); //<< + void online_list( user *p_user, map_string &map_params ); //<< #ifdef NCURSES void print_cached( int i_docs ); #endif diff --git a/src/incl.h b/src/incl.h index e7e9413..d62a57f 100755 --- a/src/incl.h +++ b/src/incl.h @@ -1,12 +1,9 @@ -#include #include +#include #include - #include "glob.h" - #ifdef NCURSES #include #endif - #include "msgs.h" #include "wrap.h" diff --git a/src/logd.cpp b/src/logd.cpp index fd78ea2..44c42e2 100755 --- a/src/logd.cpp +++ b/src/logd.cpp @@ -1,12 +1,8 @@ - #ifndef LOGD_CPP #define LOGD_CPP -#include "logd.h" - -#ifdef LOGGING - #include +#include "logd.h" logd::logd( string s_filename, string s_log_lines ) { @@ -77,36 +73,28 @@ logd::flush() } void -logd::log_access( map request ) +logd::log_access( map_string request ) { string s_time = get_time_string(); string s_logstr = request["REMOTE_ADDR"] + " - - "+s_time+" \"" + request["QUERY_STRING"]+"\" 200 0 \""+request["request"]+"\" \""+request["User-Agent"]+"\"\n"; pthread_mutex_lock ( &mut_s_logging ); s_queue.push(s_logstr); - if ( s_queue.size() > i_lines ) flush(); - pthread_mutex_unlock( &mut_s_logging ); } void logd::log_simple_line( string s_line ) { - // Dont log empty lines! - if (s_line.empty()) - return; - string s_time = get_time_string(); string s_logstr = s_time + " " + s_line; pthread_mutex_lock ( &mut_s_logging ); s_queue.push(s_logstr); - if ( s_queue.size() > i_lines ) flush(); - pthread_mutex_unlock( &mut_s_logging ); } @@ -114,7 +102,7 @@ void logd::set_logfile( string s_path, string s_filename ) { // Remove "/" from filename! - unsigned i_pos = s_filename.find( "/" ); + unsigned int i_pos = s_filename.find( "/" ); while ( i_pos != string::npos ) { s_filename.replace( i_pos, 1, "SLASH" ); @@ -166,7 +154,4 @@ logd::set_lines( const int i_lines ) { this->i_lines = i_lines; } - -#endif - #endif diff --git a/src/logd.h b/src/logd.h index f799d21..b91efe0 100755 --- a/src/logd.h +++ b/src/logd.h @@ -1,6 +1,5 @@ #include "incl.h" -#ifdef LOGGING #ifndef LOGD_H #define LOGD_H @@ -9,6 +8,7 @@ class logd { + private: string s_logfile; queue s_queue; @@ -26,12 +26,11 @@ public: ~logd(); void set_logfile( string s_path, string s_filename ); - void log_access( map request ); + void log_access( map_string request ); void log_simple_line( string s_line ); void flush_logs(); static string remove_html_tags( string s_log ); }; -#endif -#endif +#endif diff --git a/src/main.cpp b/src/main.cpp index 26f11c9..c4330d8 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ /* * yChat++; Contact: www.yChat.org; Mail@yChat.org * Copyright (C) 2003 Paul C. Buetow, Volker Richter - * Copyright (C) 2004, 2005 Paul C. Buetow + * Copyright (C) 2004 Paul C. Buetow * ----------------------------------------------------------------- * * This program is free software; you can redistribute it and/or @@ -20,9 +20,6 @@ * */ -#ifndef MAIN_CPP -#define MAIN_CPP - #include #include #include "incl.h" @@ -42,8 +39,7 @@ parse_argc( int argc, char* argv[] ) string s_output = ""; - // Set to 1 if a config option key has to be read - // ( ./ychat -o key1 value1 -o key2 value2 ... ); + // Set to 1 if a config option key has to be read ( ./ychat -o key1 value1 -o key2 value2 ... ); bool b_conf = 0; // Will store the key of an additional option value (see also b_conf) @@ -51,12 +47,12 @@ parse_argc( int argc, char* argv[] ) for (int i=1; argv[i] != 0; i++) { + if ( !s_key.empty() ) { (*start_params)[s_key] = string(argv[i]); s_key.clear(); } - else if ( b_conf ) { s_key = string(argv[i]); @@ -67,20 +63,18 @@ parse_argc( int argc, char* argv[] ) { if ( string(argv[i]).find("v") != string::npos ) s_output.append(tool::ychat_version()+"\n"); - if ( string(argv[i]).find("h") != string::npos ) - s_output.append( YCUSAGE ); - + s_output.append( "Usage: ./ychat {h|v}|{o confkey confvalue}\n" ); if ( string(argv[i]).find("o") != string::npos ) b_conf = 1; } } - if ( !s_output.empty() ) + if ( s_output.compare("") != 0 ) { cout << s_output; delete start_params; - exit(1); + exit(0); } return start_params; @@ -121,11 +115,9 @@ main(int argc, char* argv[]) // init the html-template manager. wrap::WRAP->HTML = wrap::HTML = new html; -#ifdef LOGGING // init the system message logd wrap::WRAP->LOGD = wrap::LOGD = new logd( wrap::CONF->get_elem("httpd.logging.systemfile"), wrap::CONF->get_elem("httpd.logging.systemlines") ); -#endif //<<* // init the session manager. wrap::WRAP->SMAN = wrap::SMAN = new sman; @@ -142,8 +134,6 @@ main(int argc, char* argv[]) // wait until ncurses interface has been initialized. while ( ! wrap::NCUR->is_ready() ) usleep(1000); - - wrap::HTML->print_cached(0); #endif //<<* @@ -155,10 +145,10 @@ main(int argc, char* argv[]) wrap::WRAP->TIMR = wrap::TIMR = new timr; wrap::TIMR->run(); // run the thread - //<<* // init the module-loader manager. wrap::WRAP->MODL = wrap::MODL = new modl; + //<<* // init the garbage collector wrap::WRAP->GCOL = wrap::GCOL = new gcol; @@ -187,7 +177,6 @@ main(int argc, char* argv[]) wrap::SOCK->start(); cout << DOWNMSG << endl; + return 0; } - -#endif diff --git a/src/maps/hmap.h b/src/maps/hmap.h index 38ea2e4..a0824ec 100644 --- a/src/maps/hmap.h +++ b/src/maps/hmap.h @@ -9,6 +9,11 @@ using namespace std; +// void add_elem( obj_type x, key_type k ) --> Insert x +// void del_elem( key_type k ) --> Remove x +// obj_type get_elem( key_type k ) --> Return item that matches x +// void make_empty( ) --> Remove all items + template class hmap { @@ -72,7 +77,6 @@ public: virtual void make_empty( ); virtual void make_empty( void (*func)(key_type) ); virtual void del_elem ( const key_type &k ); - virtual void rename_key ( const key_type &k1, const key_type &k2 ); virtual obj_type set_elem ( const obj_type &x, const key_type &k ); virtual void run_func( void (*func)(obj_type) ); diff --git a/src/maps/hmap.tmpl b/src/maps/hmap.tmpl index cc2ec24..10facac 100644 --- a/src/maps/hmap.tmpl +++ b/src/maps/hmap.tmpl @@ -104,17 +104,6 @@ void hmap::del_elem( const key_type & k ) array[ i_current_pos ].info = DELETED; } -// Remove item x from the hash table. -template -void hmap::rename_key( const key_type & k1, const key_type & k2 ) -{ - int i_current_pos = find_pos( k1 ); - if( is_active( i_current_pos ) ) { - array[ i_current_pos ].info = DELETED; - add_elem( array[ i_current_pos ].element, k2 ); - } -} - // Finds item x and resets its value. template obj_type hmap::set_elem( const obj_type & x, const key_type & k ) @@ -286,4 +275,8 @@ hmap::get_size() return size; } + + + #endif + diff --git a/src/maps/mtools.h b/src/maps/mtools.h index 6062191..f32a49e 100644 --- a/src/maps/mtools.h +++ b/src/maps/mtools.h @@ -1,6 +1,7 @@ #ifndef MTOOLS_H #define MTOOLS_H + template struct mtools { @@ -8,4 +9,7 @@ struct mtools }; #include "mtools.tmpl" + #endif + + diff --git a/src/maps/nmap.h b/src/maps/nmap.h index e29da3b..56d30f5 100644 --- a/src/maps/nmap.h +++ b/src/maps/nmap.h @@ -19,4 +19,7 @@ class nmap : public smap }; #include "nmap.tmpl" + #endif + + diff --git a/src/maps/smap.h b/src/maps/smap.h index a3ee89d..e056519 100644 --- a/src/maps/smap.h +++ b/src/maps/smap.h @@ -13,6 +13,7 @@ template class smap : public hmap { + private: pthread_mutex_t mut_smap; @@ -29,7 +30,6 @@ class smap : public hmap void add_elem ( const obj_type &x, const key_type &k ); obj_type set_elem ( const obj_type &x, const key_type &k ); void del_elem ( const key_type &k ); - void rename_key ( const key_type &k1, const key_type &k2 ); bool is_avail ( const key_type &k ); obj_type get_elem ( const key_type &k ); obj_type pop_elem ( const key_type &k ); @@ -52,4 +52,5 @@ class smap : public hmap }; #include "smap.tmpl" + #endif diff --git a/src/maps/smap.tmpl b/src/maps/smap.tmpl index 670b84d..3167504 100644 --- a/src/maps/smap.tmpl +++ b/src/maps/smap.tmpl @@ -15,6 +15,7 @@ smap::~smap() pthread_mutex_destroy( &mut_smap ); } + template void smap::lock_mutex() { pthread_mutex_lock( &mut_smap ); @@ -76,14 +77,6 @@ smap::del_elem( const key_type & k ) pthread_mutex_unlock( &mut_smap ); } -template void -smap::rename_key( const key_type & k1, const key_type & k2 ) -{ - pthread_mutex_lock ( &mut_smap ); - hmap::rename_key( k1, k2 ); - pthread_mutex_unlock( &mut_smap ); -} - template obj_type smap::get_elem( const key_type &k ) @@ -164,6 +157,7 @@ void smap::make_empty_insecure( void (*func)(key_type) ) hmap::make_empty( func ); } + template void smap::add_elem_insecure( const obj_type &x, const key_type &k ) { @@ -212,4 +206,6 @@ smap::get_key_vector_insecure() return hmap::get_key_vector(); } + #endif + diff --git a/src/modl.cpp b/src/modl.cpp index 77e645c..ca620ce 100755 --- a/src/modl.cpp +++ b/src/modl.cpp @@ -1,4 +1,5 @@ #ifndef MODL_CPP + #define MODL_CPP #include @@ -11,12 +12,12 @@ using namespace std; -modl::modl() : smap(HMAPOCC) +modl::modl( ) : smap(HMAPOCC) { #ifdef NCURSES print_cached( 0 ); #endif - + if ( wrap::CONF->get_elem( "httpd.modules.preloadcommands" ).compare( "true" ) == 0 ) preload_modules( wrap::CONF->get_elem("httpd.modules.commandsdir") ); @@ -50,7 +51,7 @@ modl::preload_modules( string s_path ) do { if ( iter->length() >= 3 && iter->compare( iter->length()-3, 3, ".so" ) == 0 ) - cache_module( s_path + *iter, false ); + cache_module( s_path + *iter ); } while ( ++iter != dir_vec.end() ); } @@ -69,7 +70,7 @@ modl::dlclose_( dynmod* mod ) } dynmod* -modl::cache_module( string s_name, bool b_print_sys_msg ) +modl::cache_module( string s_name ) { void *the_module = NULL; function *the_func = NULL; @@ -91,8 +92,8 @@ modl::cache_module( string s_name, bool b_print_sys_msg ) return NULL; } - if ( b_print_sys_msg ) - wrap::system_message( MODULEC + s_name.substr( s_name.find_last_of("/")+1 ) ); + wrap::system_message( MODULEC + s_name.substr( s_name.find_last_of("/")+1 ) ); + dynmod *mod = new dynmod; // encapsulates the function and module handler. mod->the_func = the_func ; // the function to execute @@ -116,7 +117,7 @@ modl::get_module( string s_name ) { wrap::system_message( MODULER + s_name.substr( s_name.find_last_of("/")+1 ) ); dynmod* mod = get_elem( s_name ); - return ! mod ? cache_module( s_name, true ) : mod; + return ! mod ? cache_module( s_name ) : mod; } void @@ -145,7 +146,6 @@ modl::reload_modules() preload_modules( wrap::CONF->get_elem("httpd.modules.commandsdir") ); preload_modules( wrap::CONF->get_elem("httpd.modules.htmldir") ); } - #ifdef NCURSES void modl::print_cached( int i_mods ) diff --git a/src/modl.h b/src/modl.h index a65077d..50587cd 100755 --- a/src/modl.h +++ b/src/modl.h @@ -11,7 +11,7 @@ class modl : private smap { private: static void dlclose_( dynmod* mod ); - dynmod* cache_module ( string s_name, bool b_print_sys_msg ); + dynmod* cache_module ( string s_name ); void preload_modules( string s_path ); #ifdef NCURSES diff --git a/src/mods/Makefile b/src/mods/Makefile index 1b0712b..36ab1f0 100755 --- a/src/mods/Makefile +++ b/src/mods/Makefile @@ -1,9 +1,8 @@ -MAKE=`tail -n 1 ../../make.version` all: mods mods: - @${MAKE} -C ./commands #//<< - @${MAKE} -C ./html + gmake -C ./commands #//<< + gmake -C ./html clean: - @${MAKE} -C ./commands clean #//<< - @${MAKE} -C ./html clean + gmake -C ./commands clean #//<< + gmake -C ./html clean @if test -d ../../mods; then rm -Rf ../../mods; fi diff --git a/src/mods/commands/yc_away.cpp b/src/mods/commands/yc_away.cpp index af4a4a5..e78121e 100755 --- a/src/mods/commands/yc_away.cpp +++ b/src/mods/commands/yc_away.cpp @@ -31,21 +31,11 @@ extern "C" { + p_conf->get_elem("chat.msgs.setmodeaway") + ""; - if ( params->size() > 0 ) + for ( iter = params->begin(); iter != params->end(); iter++ ) { - s_msg.append(": "); - for ( iter = params->begin(); iter != params->end(); iter++ ) - { - s_msg.append( " " + *iter ); - s_away.append( *iter + " " ); - } + s_msg.append( " " + *iter ); + s_away.append( *iter + " " ); } - - else - { - s_msg.append("."); - } - s_msg.append( "
\n" ); room* p_room = p_user->get_room(); @@ -63,8 +53,6 @@ extern "C" { p_user->set_away( true, s_away ); p_room->reload_onlineframe(); p_room->msg_post ( &s_msg ); - - return 0; } } diff --git a/src/mods/commands/yc_col.cpp b/src/mods/commands/yc_col.cpp index 4449278..00d86e2 100755 --- a/src/mods/commands/yc_col.cpp +++ b/src/mods/commands/yc_col.cpp @@ -64,8 +64,6 @@ extern "C" { p_user->set_col1(s_color); p_user->set_col2(s_color2); } - - return 0; } int valid_color( string s_color ){ diff --git a/src/mods/commands/yc_exec.cpp b/src/mods/commands/yc_exec.cpp index f912c20..b8377b3 100755 --- a/src/mods/commands/yc_exec.cpp +++ b/src/mods/commands/yc_exec.cpp @@ -59,8 +59,6 @@ extern "C" { p_user->msg_post( &s_output ); pclose(file); } - - return 0; } } diff --git a/src/mods/commands/yc_fake.cpp b/src/mods/commands/yc_fake.cpp index c708841..820f35e 100755 --- a/src/mods/commands/yc_fake.cpp +++ b/src/mods/commands/yc_fake.cpp @@ -15,15 +15,13 @@ extern "C" { bool b_fake = p_user->get_fake(); string s_msg = (b_fake == 1 - ? p_conf->get_elem("chat.msgs.unsetmodefake") + "
\n" - : p_conf->get_elem("chat.msgs.setmodefake") + "
\n"); + ? p_conf->get_elem("chat.msgs.setmodefake") + "
\n" + : p_conf->get_elem("chat.msgs.unsetmodefake") + "
\n"); p_user->set_fake( !b_fake ); p_user->get_room()->reload_onlineframe(); p_user->msg_post ( &s_msg ); - - return 0; } } diff --git a/src/mods/commands/yc_getroom.cpp b/src/mods/commands/yc_getroom.cpp index 87e2d25..91de447 100755 --- a/src/mods/commands/yc_getroom.cpp +++ b/src/mods/commands/yc_getroom.cpp @@ -45,8 +45,6 @@ extern "C" { } } - - return 0; } } diff --git a/src/mods/commands/yc_getrusage.cpp b/src/mods/commands/yc_getrusage.cpp index 83dcbb9..9eb74ee 100755 --- a/src/mods/commands/yc_getrusage.cpp +++ b/src/mods/commands/yc_getrusage.cpp @@ -49,8 +49,6 @@ extern "C" { ); p_user->msg_post( new string( c_msg ) ); - - return 0; } } diff --git a/src/mods/commands/yc_getstatus.cpp b/src/mods/commands/yc_getstatus.cpp index 086e126..ee4f922 100644 --- a/src/mods/commands/yc_getstatus.cpp +++ b/src/mods/commands/yc_getstatus.cpp @@ -51,8 +51,6 @@ extern "C" { } } - - return 0; } } diff --git a/src/mods/commands/yc_help.cpp b/src/mods/commands/yc_help.cpp index 41899c3..3e7d821 100755 --- a/src/mods/commands/yc_help.cpp +++ b/src/mods/commands/yc_help.cpp @@ -44,8 +44,6 @@ extern "C" { + "
\n"; p_user->msg_post( &s_msg ); - - return 0; } } diff --git a/src/mods/commands/yc_invisible.cpp b/src/mods/commands/yc_invisible.cpp index b78d934..dcc2498 100755 --- a/src/mods/commands/yc_invisible.cpp +++ b/src/mods/commands/yc_invisible.cpp @@ -15,16 +15,14 @@ extern "C" { bool b_invisible = p_user->get_invisible(); string s_msg = b_invisible - ? p_conf->get_elem("chat.msgs.setmodeinvisible") + ? p_conf->get_elem("chat.msgs.setmodeaway") + "
\n" - : p_conf->get_elem("chat.msgs.unsetmodeinvisible") + : p_conf->get_elem("chat.msgs.unsetmodeaway") + "
\n"; p_user->set_invisible( !b_invisible ); p_user->get_room()->reload_onlineframe(); p_user->msg_post ( &s_msg ); - - return 0; } } diff --git a/src/mods/commands/yc_j.cpp b/src/mods/commands/yc_j.cpp index 903e49b..46d2cd9 100755 --- a/src/mods/commands/yc_j.cpp +++ b/src/mods/commands/yc_j.cpp @@ -97,8 +97,6 @@ extern "C" { } } } - - return 0; } } diff --git a/src/mods/commands/yc_ko.cpp b/src/mods/commands/yc_ko.cpp index ac32ac7..4084242 100755 --- a/src/mods/commands/yc_ko.cpp +++ b/src/mods/commands/yc_ko.cpp @@ -33,7 +33,7 @@ extern "C" { + p_conf->get_elem( "chat.msgs.userkicksout1" ) + p_searched_user->get_colored_bold_name() + p_conf->get_elem( "chat.msgs.userkicksout2" ) - + p_searched_user->get_room()->get_bold_name() + + p_user->get_room()->get_bold_name() + "
\n"; room* p_room1 = p_user->get_room(); @@ -64,8 +64,6 @@ extern "C" { p_user->msg_post( &s_msg ); } } - - return 0; } } diff --git a/src/mods/commands/yc_m.cpp b/src/mods/commands/yc_m.cpp index a93cc3b..3c607a9 100755 --- a/src/mods/commands/yc_m.cpp +++ b/src/mods/commands/yc_m.cpp @@ -37,7 +37,6 @@ extern "C" { s_msg.append( "
\n" ); p_user->get_room()->msg_post( &s_msg ); - return 0; } } diff --git a/src/mods/commands/yc_md5.cpp b/src/mods/commands/yc_md5.cpp index d79d952..055d964 100755 --- a/src/mods/commands/yc_md5.cpp +++ b/src/mods/commands/yc_md5.cpp @@ -47,8 +47,6 @@ extern "C" { p_user->msg_post( &s_msg ); } - - return 0; } } diff --git a/src/mods/commands/yc_me.cpp b/src/mods/commands/yc_me.cpp index 66d54da..12c733e 100755 --- a/src/mods/commands/yc_me.cpp +++ b/src/mods/commands/yc_me.cpp @@ -37,8 +37,6 @@ extern "C" { s_msg.append( "
\n" ); p_user->get_room()->msg_post( &s_msg ); - return 0; - } } diff --git a/src/mods/commands/yc_msg.cpp b/src/mods/commands/yc_msg.cpp index 33beee4..dda26b3 100755 --- a/src/mods/commands/yc_msg.cpp +++ b/src/mods/commands/yc_msg.cpp @@ -17,7 +17,6 @@ extern "C" { vector *params = (vector*) c->elem[2]; // param array chat* p_chat = (chat*) ((dynamic_wrap*)c->elem[3])->CHAT; conf* p_conf = (conf*) ((dynamic_wrap*)c->elem[3])->CONF; - timr* p_timr = (timr*) ((dynamic_wrap*)c->elem[3])->TIMR; if ( ! params->empty() ) { @@ -28,22 +27,30 @@ extern "C" { if ( b_found ) { - string s_time = ""; - if ( p_conf->get_elem("chat.printalwaystime") == "true" ) - s_time = p_timr->get_time() + " "; - - string s_msg = s_time + " " + p_conf->get_elem("chat.msgs.whisperto") + " " + p_whisper_user->get_colored_name() + ": get_col2() + "\">"; + string s_msg = " " + + p_conf->get_elem("chat.msgs.whisperto") + + " " + + p_whisper_user->get_colored_name() + + ": get_col2() + + "\">"; - string s_whisper_msg = s_time + "" + p_user->get_colored_name() + " " + p_conf->get_elem("chat.msgs.whisper") + ": get_col2() + "\">"; + string s_whisper_msg = "" + + p_user->get_colored_name() + + " " + + p_conf->get_elem("chat.msgs.whisper") + + ": get_col2() + + "\">"; - string s_tmp = ""; for ( iter++; iter != params->end(); iter++ ) - s_tmp.append( *iter + " " ); + { + s_msg .append( *iter + " " ); + s_whisper_msg.append( *iter + " " ); + } - p_chat->string_replacer(&s_tmp); - - s_msg .append( s_tmp + "
\n" ); - s_whisper_msg.append( s_tmp + "

\n" ); + s_msg .append( "

\n" ); + s_whisper_msg.append( "

\n" ); p_user ->msg_post( &s_msg ); p_whisper_user->msg_post( &s_whisper_msg ); @@ -61,8 +68,6 @@ extern "C" { p_user->msg_post( &s_msg ); } } - - return 0; } } diff --git a/src/mods/commands/yc_q.cpp b/src/mods/commands/yc_q.cpp index 4c9584d..3c614f7 100755 --- a/src/mods/commands/yc_q.cpp +++ b/src/mods/commands/yc_q.cpp @@ -22,8 +22,6 @@ extern "C" { p_user->msg_post( &s_quit ); p_user->set_online(false); - - return 0; } } diff --git a/src/mods/commands/yc_reload.cpp b/src/mods/commands/yc_reload.cpp index 8b9cd0a..7050a36 100755 --- a/src/mods/commands/yc_reload.cpp +++ b/src/mods/commands/yc_reload.cpp @@ -17,8 +17,6 @@ extern "C" { p_user->get_room()->reload_onlineframe(); p_user->msg_post ( &s_msg ); - - return 0; } } diff --git a/src/mods/commands/yc_ren.cpp b/src/mods/commands/yc_ren.cpp index 9735d8e..c6fa984 100755 --- a/src/mods/commands/yc_ren.cpp +++ b/src/mods/commands/yc_ren.cpp @@ -66,8 +66,6 @@ extern "C" { p_room->reload_onlineframe(); } } - - return 0; } } diff --git a/src/mods/commands/yc_s.cpp b/src/mods/commands/yc_s.cpp index 30a6892..4effccb 100755 --- a/src/mods/commands/yc_s.cpp +++ b/src/mods/commands/yc_s.cpp @@ -22,14 +22,11 @@ extern "C" { vector *params= (vector*) c->elem[2]; // param array conf* p_conf = (conf*) ((dynamic_wrap*)c->elem[3])->CONF; - timr* p_timr = (timr*) ((dynamic_wrap*)c->elem[3])->TIMR; - - string s_time = ""; - if ( p_conf->get_elem("chat.printalwaystime") == "true" ) - s_time = p_timr->get_time() + " "; - - string s_msg = s_time + "" + p_user->get_colored_name() + " " + p_conf->get_elem("chat.msgs.scream") + " get_col2() + "\">"; + string s_msg = "" + p_user->get_colored_name() + " " + + p_conf->get_elem("chat.msgs.scream") + + " get_col2() + + "\">"; if ( ! params->empty() ) { vector::iterator iter = params->begin(); @@ -40,8 +37,6 @@ extern "C" { s_msg.append( "
\n" ); p_user->get_room()->msg_post( &s_msg ); - return 0; - } } diff --git a/src/mods/commands/yc_set.cpp b/src/mods/commands/yc_set.cpp index a18b5e9..9adb907 100755 --- a/src/mods/commands/yc_set.cpp +++ b/src/mods/commands/yc_set.cpp @@ -94,8 +94,6 @@ extern "C" { + "

\n"; p_user->msg_post( &s_msg ); } - - return 0; } } diff --git a/src/mods/commands/yc_template.cpp b/src/mods/commands/yc_template.cpp index e0aa009..8100f42 100755 --- a/src/mods/commands/yc_template.cpp +++ b/src/mods/commands/yc_template.cpp @@ -17,8 +17,6 @@ extern "C" { string *quitstring=new string("Text to send
"); p_user->msg_post( quitstring ); - - return 0; } } diff --git a/src/mods/commands/yc_time.cpp b/src/mods/commands/yc_time.cpp index c22e542..2b1950a 100755 --- a/src/mods/commands/yc_time.cpp +++ b/src/mods/commands/yc_time.cpp @@ -14,8 +14,6 @@ extern "C" { string s_msg = p_conf->get_elem("chat.msgs.servertime") + p_timr->get_time() + "
\n"; p_user->msg_post( &s_msg ); - - return 0; } } diff --git a/src/mods/commands/yc_topic.cpp b/src/mods/commands/yc_topic.cpp index 5541dc4..1f5587e 100755 --- a/src/mods/commands/yc_topic.cpp +++ b/src/mods/commands/yc_topic.cpp @@ -19,13 +19,11 @@ extern "C" { string s_topic; string s_col; - room* p_room = p_user->get_room(); - if ( ! params->empty() ) { vector::iterator iter; - s_col = "get_col1() + "\">"; + s_col = ""; s_msg = p_timr->get_time() + " " @@ -53,26 +51,24 @@ extern "C" { p_user->msg_post ( &s_private_msg ); } - s_topic = "( " + s_topic + ")"; - p_room->set_topic( s_topic, p_user->get_col1() ); + s_topic = "( " + s_col + s_topic + ")

"; } else { s_msg = p_timr->get_time() + " " - + p_user->get_colored_bold_name() + + p_user->get_colored_name() + " " + p_conf->get_elem("chat.msgs.topicdelete"); - - p_room->set_topic( "" ); } s_msg.append( "
\n" ); - p_room->msg_post ( &s_msg ); + room* p_room = p_user->get_room(); - return 0; + p_room->set_topic( s_topic ); + p_room->msg_post ( &s_msg ); } } diff --git a/src/mods/commands/yc_uptime.cpp b/src/mods/commands/yc_uptime.cpp index 5fe0929..d19a622 100755 --- a/src/mods/commands/yc_uptime.cpp +++ b/src/mods/commands/yc_uptime.cpp @@ -14,8 +14,6 @@ extern "C" { string s_msg = p_conf->get_elem("chat.msgs.uptime") + p_timr->get_uptime() + "
\n"; p_user->msg_post( &s_msg ); - - return 0; } } diff --git a/src/mods/commands/yc_version.cpp b/src/mods/commands/yc_version.cpp index d64fabd..0586a12 100755 --- a/src/mods/commands/yc_version.cpp +++ b/src/mods/commands/yc_version.cpp @@ -14,9 +14,7 @@ extern "C" { { container *c=(container *)v_arg; user *p_user = (user*)c->elem[1]; // the corresponding user - p_user->msg_post( tool::ychat_version() + "
\n"); - - return 0; + p_user->msg_post( tool::ychat_version() + " " + UNAME + "
\n"); } } diff --git a/src/mods/html/yc_admin.cpp b/src/mods/html/yc_admin.cpp index b6b979e..1709c6b 100644 --- a/src/mods/html/yc_admin.cpp +++ b/src/mods/html/yc_admin.cpp @@ -21,7 +21,7 @@ extern "C" { dynamic_wrap* p_wrap = (dynamic_wrap*) c->elem[0]; user* p_user = (user*) c->elem[2]; conf* p_conf = (conf*) p_wrap->CONF; - string* p_content = &(*((map*) c->elem[1]))["content"]; + string* p_content = &(*((map_string*) c->elem[1]))["content"]; vector* p_vec_keys = p_conf->get_key_vector(); sort(p_vec_keys->begin(), p_vec_keys->end()); @@ -62,8 +62,6 @@ extern "C" { } // while p_content->append( "
\n
\n" ); - - return 0; } } diff --git a/src/mods/html/yc_colors.cpp b/src/mods/html/yc_colors.cpp index 6d2c5ab..6b2f11b 100755 --- a/src/mods/html/yc_colors.cpp +++ b/src/mods/html/yc_colors.cpp @@ -12,9 +12,9 @@ extern "C" { container* c = (container*) v_arg; dynamic_wrap* p_wrap = (dynamic_wrap*) c->elem[0]; conf* p_conf = (conf*) p_wrap->CONF; - string* p_col1 = &(*((map*) c->elem[1]))["col1"]; - string* p_col2 = &(*((map*) c->elem[1]))["col2"]; - string* p_flag = &(*((map*) c->elem[1]))["flag"]; + string* p_col1 = &(*((map_string*) c->elem[1]))["col1"]; + string* p_col2 = &(*((map_string*) c->elem[1]))["col2"]; + string* p_flag = &(*((map_string*) c->elem[1]))["flag"]; user* p_user = (user*) c->elem[2]; p_col1->erase(0); @@ -25,11 +25,9 @@ extern "C" { if ( *p_flag == "submit" ) { - string* p_msgs = &(*((map*) c->elem[1]))["msgs"]; + string* p_msgs = &(*((map_string*) c->elem[1]))["msgs"]; p_msgs->append( p_conf->get_elem( "chat.msgs.optionschanged" ) ); } - - return 0; } } diff --git a/src/mods/html/yc_help.cpp b/src/mods/html/yc_help.cpp index 4d6db03..acb10c2 100755 --- a/src/mods/html/yc_help.cpp +++ b/src/mods/html/yc_help.cpp @@ -15,7 +15,7 @@ extern "C" { modl* p_modl = (modl*) p_wrap->MODL; conf* p_conf = (conf*) p_wrap->CONF; chat* p_chat = (chat*) p_wrap->CHAT; - string* s_content = &(*((map*) c->elem[1]))["content"]; + string* s_content = &(*((map_string*) c->elem[1]))["content"]; vector* p_vec_keys = p_modl->get_mod_vector(); @@ -41,8 +41,6 @@ extern "C" { } p_vec_keys_iter++; } - - return 0; } } diff --git a/src/mods/html/yc_options.cpp b/src/mods/html/yc_options.cpp index 47c3153..86aa8b9 100755 --- a/src/mods/html/yc_options.cpp +++ b/src/mods/html/yc_options.cpp @@ -12,16 +12,16 @@ extern "C" { container* c = (container*) v_arg; dynamic_wrap* p_wrap = (dynamic_wrap*) c->elem[0]; conf* p_conf = (conf*) p_wrap->CONF; - string* p_flag = &(*((map*) c->elem[1]))["flag"]; - string* p_email = &(*((map*) c->elem[1]))["email"]; - string* p_pass = &(*((map*) c->elem[1]))["pass"]; - string* p_newpass = &(*((map*) c->elem[1]))["newpass"]; - string* p_newpass2 = &(*((map*) c->elem[1]))["newpass2"]; + string* p_flag = &(*((map_string*) c->elem[1]))["flag"]; + string* p_email = &(*((map_string*) c->elem[1]))["email"]; + string* p_pass = &(*((map_string*) c->elem[1]))["pass"]; + string* p_newpass = &(*((map_string*) c->elem[1]))["newpass"]; + string* p_newpass2 = &(*((map_string*) c->elem[1]))["newpass2"]; user* p_user = (user*) c->elem[2]; if ( *p_flag == "submit" ) { - string* p_msgs = &(*((map*) c->elem[1]))["msgs"]; + string* p_msgs = &(*((map_string*) c->elem[1]))["msgs"]; // If the password has to be changed: if ( *p_pass != "" || *p_newpass != "" || *p_newpass2 != "" ) @@ -48,8 +48,6 @@ extern "C" { { p_email->append( p_user->get_email() ); } - - return 0; } } diff --git a/src/mods/html/yc_register.cpp b/src/mods/html/yc_register.cpp index 5d65b50..98f2b85 100755 --- a/src/mods/html/yc_register.cpp +++ b/src/mods/html/yc_register.cpp @@ -14,12 +14,12 @@ extern "C" { dynamic_wrap* p_wrap = (dynamic_wrap*) c->elem[0]; conf* p_conf = (conf*) p_wrap->CONF; data* p_data = (data*) p_wrap->DATA; - string* p_msgs = &(*((map*) c->elem[1]))["INFO"]; - string* p_nick = &(*((map*) c->elem[1]))["nick"]; - string* p_email = &(*((map*) c->elem[1]))["email"]; - string* p_pass = &(*((map*) c->elem[1]))["pass"]; - string* p_pass2 = &(*((map*) c->elem[1]))["pass2"]; - string* p_request = &(*((map*) c->elem[1]))["request"]; + string* p_msgs = &(*((map_string*) c->elem[1]))["INFO"]; + string* p_nick = &(*((map_string*) c->elem[1]))["nick"]; + string* p_email = &(*((map_string*) c->elem[1]))["email"]; + string* p_pass = &(*((map_string*) c->elem[1]))["pass"]; + string* p_pass2 = &(*((map_string*) c->elem[1]))["pass2"]; + string* p_request = &(*((map_string*) c->elem[1]))["request"]; user* p_user = (user*) c->elem[2]; string s_nick = *p_nick; @@ -57,7 +57,7 @@ extern "C" { else { - map result_map = p_data->select_user_data( *p_nick, "selectnick" ); + map_string result_map = p_data->select_user_data( *p_nick, "selectnick" ); if (result_map["nick"] == *p_nick) { p_msgs->append( p_conf->get_elem( "chat.msgs.err.registerexists" ) ); @@ -69,7 +69,7 @@ extern "C" { p_msgs->append( p_conf->get_elem( "chat.msgs.registernick" ) ); p_request->replace( 0, p_request->length(), p_conf->get_elem("httpd.startsite") ); - map map_insert = *((map*) c->elem[1]); + map_string map_insert = *((map_string*) c->elem[1]); map_insert["password"] = *p_pass; map_insert["color1"] = p_conf->get_elem("chat.html.user.color1"); map_insert["color2"] = p_conf->get_elem("chat.html.user.color2"); @@ -85,8 +85,6 @@ extern "C" { p_data->insert_user_data( *p_nick, "registernick", map_insert ); } } - - return 0; #endif } } diff --git a/src/msgs.h b/src/msgs.h old mode 100755 new mode 100644 index 1a6b659..3d56333 --- a/src/msgs.h +++ b/src/msgs.h @@ -9,7 +9,7 @@ #define CFILEOK "Parsing config file" #define CFILEFA "Failed opening config file!" #define CONTACT "Contact: http://www.yChat.org, Mail@yChat.org, ICQ: 11655527" -#define CLRHTML "HTML: Cleared the document cache " +#define CLRHTML "HTML: Cleared the template cache " #define CLIWELC "Command Line Interface (type help for a list of all commands)" #define CLIPRMO ">> " #define CLIPRMI "<< " @@ -25,9 +25,9 @@ #define DATAIN1 "Data: Initializing mincon to " #define DATAMAX "Data: Max database connections reached " #define DATAMA0 "Data: Max database connections " -#define DATANEW "Data: Creating new database connection " +#define DATANEW "Data: Creating new database conbbnection " #define DESCRIP "Copyright (C) 2003 Paul C. Buetow, Volker Richter" -#define DESCRI2 "Copyright (C) 2004, 2005 Paul C. Buetow" +#define DESCRI2 "Copyright (C) 2004 Paul C. Buetow" #define DONEMSG "done" #define DOWNMSG "Shutting down " #define GARBAGE "Garbage: Initializing collector " @@ -36,7 +36,7 @@ #define GARROOM "Garbage: Added room " #define GARUSER "Garbage: Added user " #define GARUSE2 "Garbage: Recycle user " -#define LISTERR "Sock: Listen error " +#define LISTERR "Sock: Listen error " #define LOGERR1 "Logging: Could not open logfile " #define LOGERR2 "Logging: No filename specified " #define LOGINER "Chat: Login failed (password), nick: " @@ -44,33 +44,23 @@ #define LOGINE1 "Chat: Login failed (alpha nick), nick: " #define LOGINE2 "Chat: Login failed (nick length), nick: " #define LOGINE3 "Chat: Login failed (room length), nick/room: " -#define LOGINE4 "Chat: Login failed (guests disabled), nick: " #define MODULEC "Modl: Caching " #define MODULER "Modl: Requesting " #define MODUNLO "Modl: Unloading all modules " #define MODRELO "Modl: Reloading all modules " - #ifdef DATABASE #define MYSQLQU "MySQL: " #define MYSQLQ2 "MySQL: Adding query " #define MYSQLE1 "MySQL: Error running mysql_init " #endif - #define NCURADM "ADMINISTRATOR's MAIN MENU" #define NCURMSG "SERVER SYSTEM MESSAGES" -#define NCURSE0 "HTTP server: " -#define NCURSE1 "Thread pool: " -#define NCURSE2 "Data stats: " -#define NCURSE3 "Chat stats: " -#define NCURSE4 "Caching: " #define NEWREQU "Sock: New request " #define NEWROOM "Chat: New room " #define NEWUSER "Chat: New user " #define OFFFOUND "HTML: File not found " #define PERMSTD "Reading standard command exec permissions" #define POOLERR "Pool: Malloc error " -#define POOLER2 "Pool: Max pool size reached (" -#define POOLFLL "Pool: Allocating new thread (" #define READERR "Sock: Read error " #define REMROOM "Garbage: Removing room " #define REMUSER "Garbage: Removing user " @@ -92,7 +82,7 @@ #define SOCKER2 "Sock: Unknown hostname " #define SOCKRDY "Sock: Server socket is ready " #define SSLINIT "SSL: Initializing OpenSSL" -#define TECACHE "HTML: Caching document " +#define TECACHE "HTML: Caching template " #define THRDSTR "Thread: Running" #define TIMERAT "Timer: User autoaway timeout " #define TIMERIN "Timer: Initializing " @@ -103,20 +93,9 @@ #define XMLREAD "XML: Reading " #define XMLERR "XML Error: " #define XMLER1 "XML Error: Unable to load file " -#define VERSION "0.7.5" +#define VERSION "yChat 0.7" #define BRANCH "RELEASE" -#define BUILDNR 3213 -#define UNAME "FreeBSD 5.3-RELEASE-p2 i386" -#define COMPOPT "Using built-in specs.; Configured with: FreeBSD/i386 system compiler; Thread model: posix; gcc version 3.4.2 [FreeBSD] 20040728; 3.4; g++" -#define YCUSAGE "Usage: ./ychat {h|v}|{o confkey confvalue}\n" - -#define HEADER1 "HTTP/1.0 200 OK\r\n" -#define HEADER2 "Server: yChat/" VERSION "-" BRANCH "\r\n" -#define HEADER3 "Cache-control: no-cache\r\n" -#define HEADER4 "Pragma: no-cache\r\n" -#define HEADER5 "Transfer-Encoding: chunked\r\n" -#define HEADER6 "Connection: keep-alive\r\n" -#define HEADER7 "Content-Length: "; -#define HEADER8 "Content-Type: "; +#define BUILDNR 2797 +#define UNAME "Linux 2.6.8.1 i686" #endif diff --git a/src/name.cpp b/src/name.cpp index fd9f33b..646b4d9 100755 --- a/src/name.cpp +++ b/src/name.cpp @@ -1,3 +1,5 @@ +// class name implementation. + #ifndef NAME_CPP #define NAME_CPP @@ -10,7 +12,6 @@ name::name() { pthread_mutex_init( &mut_s_name, NULL); } - name::name( string s_name ) { pthread_mutex_init( &mut_s_name, NULL); @@ -46,4 +47,5 @@ name::set_name( string s_name ) pthread_mutex_unlock( &mut_s_name ); } + #endif diff --git a/src/name.h b/src/name.h index 1e79c0e..d5a67da 100755 --- a/src/name.h +++ b/src/name.h @@ -1,3 +1,4 @@ +// class name declaration. #include "incl.h" #ifndef NAME_H @@ -8,6 +9,7 @@ using namespace std; class name { protected: + // private members: string s_name; // object's name. pthread_mutex_t mut_s_name; @@ -16,9 +18,11 @@ public: virtual string get_lowercase_name ( ); virtual void set_name ( string s_name ); - name(); + // public methods: + name( ); name( string s_name ); // a standard constructor. - ~name(); + ~name( ); + }; #endif diff --git a/src/ncur/menu.cpp b/src/ncur/menu.cpp index 3243df9..c5734a5 100755 --- a/src/ncur/menu.cpp +++ b/src/ncur/menu.cpp @@ -6,9 +6,8 @@ #ifndef MENU_CPP #define MENU_CPP -using namespace std; -menu::menu( int i_startx, int i_starty, int i_width, int i_height, char *c_header, char **choices, int i_numchoices, const chtype ch ) +using namespace std; menu::menu( int i_startx, int i_starty, int i_width, int i_height, char *c_header, char **choices, int i_numchoices, const chtype ch ) { this->i_startx = i_startx; this->i_starty = i_starty; @@ -51,17 +50,16 @@ menu::display() box( win, 0, 0 ); mvwprintw( win, y++, x, "%s", c_header ); - for( i = 0; i < i_numchoices; i++ ) + for( i=0; i>" ", - //>>" ", + "Unload all modules ", + "Reload all modules ", "Clear template cache ", "Run garbage collector ", //<< //>>" ", @@ -46,14 +44,13 @@ ncur::start( void *p_void ) "Compile changed sources ", "Recompile all sources ", "Show source stats ", - "Command line interface ", - //<<* + "Command Line Interface ", #ifdef DATABASE - "Close DB connections ", + "Disconnect from DB ", //<< #else - " ", + " ", //<< #endif - //*>> + //>>" ", "Shut down server" }; @@ -65,20 +62,21 @@ ncur::start( void *p_void ) mvwprintw( p_serveroutput, 2, 2, NCURMSG ); wrefresh ( p_serveroutput ); - print( string("yChat ") + VERSION ); + print( VERSION ); p_menu = new menu( 1, 1, 30, 19, NCURADM, choices, 11, COLOR_PAIR(1)); - mvprintw(NCUR_SERVER_HEADER_X,NCUR_SERVER_HEADER_Y, NCURSE0); - mvprintw(NCUR_POOL_HEADER_X,NCUR_POOL_HEADER_Y, NCURSE1); - mvprintw(NCUR_DATA_HEADER_X,NCUR_DATA_HEADER_Y, NCURSE2); //<< - mvprintw(NCUR_CHAT_HEADER_X,NCUR_CHAT_HEADER_Y, NCURSE3); //<< - mvprintw(NCUR_CACHED_HEADER_X,NCUR_CACHED_HEADER_Y, NCURSE4); - + mvprintw( NCUR_SERVER_HEADER_X,NCUR_SERVER_HEADER_Y, "HTTP server:"); + mvprintw( NCUR_POOL_HEADER_X,NCUR_POOL_HEADER_Y, "Thread pool:"); +#ifdef DATABASE + mvprintw( NCUR_DATA_HEADER_X,NCUR_DATA_HEADER_Y, "Data stats:"); //<< +#endif + mvprintw( NCUR_CHAT_HEADER_X,NCUR_CHAT_HEADER_Y, "Chat stats:"); //<< + mvprintw( NCUR_CACHED_HEADER_X,NCUR_CACHED_HEADER_Y, "Caching:"); wrap::HTML->print_cached(0); - is_ready(true); + is_ready( true ); wrap::SMAN->print_init_ncurses(); //<< wrap::STAT->print_num_rooms(); //<< @@ -121,10 +119,8 @@ ncur::print( char* c_print ) int i; char* c_temp = new char[i_message_length]; memcpy( c_temp, c_print, strlen(c_print) ); - - for ( i = strlen(c_print); i < i_message_length; ++i ) + for ( i = strlen(c_print); i < i_message_length; i++ ) c_temp[i] = ' '; - c_temp[i] = '\0'; pthread_mutex_lock( &mut_messages ); @@ -133,7 +129,7 @@ ncur::print( char* c_print ) { char* c_front = p_messagelist->front(); p_messagelist->pop_front(); - free(c_front); + free( c_front ); } p_messagelist->push_back( c_temp ); @@ -144,7 +140,7 @@ ncur::print( char* c_print ) list::iterator iter; iter = p_messagelist->begin(); - for ( i = 4; i < 18 && iter != p_messagelist->end(); ++i, ++iter ) + for ( i=4; i<18 && iter != p_messagelist->end(); i++, iter++ ) mvwprintw( p_serveroutput, i, 2, *iter ); wrefresh ( p_serveroutput ); @@ -161,7 +157,6 @@ ncur::switch_main_menu_( int i_choice ) if( i_choice != 0 ) switch ( i_choice ) { - //<<* case 1: wrap::MODL->unload_modules(); mvprintw( 20,2, "Unloaded all modules "); @@ -172,7 +167,6 @@ ncur::switch_main_menu_( int i_choice ) mvprintw( 20,2, "Reloaded all modules "); refresh(); break; - //*>> case 3: wrap::HTML->clear_cache(); mvprintw( 20,2, "Cleared the template cache "); @@ -280,6 +274,5 @@ ncur::is_ready() pthread_mutex_unlock( &mut_is_ready ); return b_ret; } - #endif #endif diff --git a/src/ncur/ncur.h b/src/ncur/ncur.h index 53849d0..692a48a 100755 --- a/src/ncur/ncur.h +++ b/src/ncur/ncur.h @@ -1,10 +1,8 @@ #include "../incl.h" #ifdef NCURSES - #ifndef NCUR_H #define NCUR_H - #include #include @@ -19,12 +17,11 @@ private: menu* p_menu; WINDOW* p_serveroutput; list* p_messagelist; // contains the messages for p_serveroutput! + pthread_mutex_t mut_messages; // for syncronization of p_serveroutput! int i_message_length; // the maximum length of a system message! - bool b_is_ready; // is set to TRUE if the admin interface is initialized. + bool b_is_ready; // is set to TRUE if the admin interface is initialized. static void init_ncurses(); static void close_ncurses(); - - pthread_mutex_t mut_messages; pthread_mutex_t mut_is_ready; public: @@ -32,18 +29,15 @@ public: ~ncur( ); void start( void *p_void ); - void print( char* c_print ); - void print( string s_msg ); - void print( string* p_msg ); + virtual void print( char* c_print ); + virtual void print( string s_msg ); + virtual void print( string* p_msg ); void is_ready( bool b_is_ready ); bool is_ready(); static void switch_main_menu_( int i_choice ); void shutdown(); - void activate_menu_win() - { - p_menu->activate_menu_win(); - } + { p_menu->activate_menu_win(); } }; #endif diff --git a/src/reqp.cpp b/src/reqp.cpp index 8186764..caba9ec 100755 --- a/src/reqp.cpp +++ b/src/reqp.cpp @@ -6,19 +6,20 @@ using namespace std; -#define HEADER HEADER1 HEADER2 HEADER3 HEADER4 -#define STREAM HEADER5 HEADER6 - -const string reqp::s_http = HEADER; -const string reqp::s_http_stream = STREAM; -const string reqp::s_http_colength = HEADER7; -const string reqp::s_http_cotype = HEADER8; +string reqp::HTTP_CODEOK = "HTTP/1.1 200 OK\r\n"; +string reqp::HTTP_SERVER = "Server: yChat (Unix)\r\n"; +string reqp::HTTP_CONTAC = "Contact: www.yChat.org\r\n"; +string reqp::HTTP_EXPIRE = "Expires: 0\r\n"; +string reqp::HTTP_CACHEC = "Cache-control: no-cache\r\nPragma: no-cache\r\n"; +string reqp::HTTP_CONNEC = "Connection: keep-alive\r\n"; +string reqp::HTTP_CHUNKE = "Transfer-Encoding: chunked\r\n"; +string reqp::HTTP_COTYPE = "Content-Type: "; reqp::reqp( ) {} void -reqp::get_request_parameters( string s_parameters, map& map_params ) +reqp::get_request_parameters( string s_parameters, map_string& map_params ) { string s_tmp; unsigned i_pos, i_pos2; @@ -27,8 +28,8 @@ reqp::get_request_parameters( string s_parameters, map& map_param { s_tmp = s_parameters.substr(0, i_pos ); - if ( (i_pos2 = s_tmp.find("=")) != string::npos ) - map_params[ s_tmp.substr(0, i_pos2) ] = tool::replace( s_tmp.substr( i_pos2+1 ), "\\AND", "&"); + if ( (i_pos2 = s_tmp.find("=")) != string::npos ) + map_params[ s_tmp.substr(0, i_pos2) ] = s_tmp.substr( i_pos2+1 ); s_parameters = s_parameters.substr( i_pos + 1 ); } @@ -36,14 +37,14 @@ reqp::get_request_parameters( string s_parameters, map& map_param // Get the last request parameter, which does not have a "&" on the end! if( (i_pos = s_parameters.find("=")) != string::npos ) map_params[ s_parameters.substr(0, i_pos) ] = s_parameters.substr( i_pos+1 ); - - //map::iterator iter; - //for ( iter = map_params.begin(); iter != map_params.end(); ++iter ) - //cout << ">>>" << iter->first << "=" << iter->second << endl; + + // map_string::iterator iter; + // for ( iter = map_params.begin(); iter != map_params.end(); ++iter ) + // cout << ">>>" << iter->first << "=" << iter->second << endl; } string -reqp::get_url( int &i_sock, string s_req, map &map_params ) +reqp::get_url( thrd* p_thrd, string s_req, map_string &map_params ) { unsigned i_pos, i_pos2; string s_vars( "" ); @@ -101,7 +102,7 @@ reqp::get_url( int &i_sock, string s_req, map &map_params ) if ( (i_pos = s_req.find("event=")) == string::npos) { char c_req[POSTBUF]; - i_len = read(i_sock, c_req, POSTBUF); + i_len = read(p_thrd->get_sock(), c_req, POSTBUF); s_req = c_req; s_req = s_req.substr(0, i_len); @@ -143,7 +144,7 @@ reqp::get_content_type( string s_file ) } void -reqp::parse_headers( string s_req, map &map_params ) +reqp::parse_headers( string s_req, map_string &map_params ) { int pos = s_req.find("\n"); @@ -151,11 +152,10 @@ reqp::parse_headers( string s_req, map &map_params ) { map_params["QUERY_STRING"] = tool::trim(s_req.substr(0,pos-1)); - int pos2; do { string s_line( s_req.substr(0, pos) ); - pos2 = s_line.find(":"); + int pos2 = s_line.find(":"); if (pos2 != string::npos && s_line.length() > pos2+1) map_params[ tool::trim(s_line.substr(0, pos2)) ] = tool::trim(s_line.substr(pos2+1)); @@ -168,17 +168,19 @@ reqp::parse_headers( string s_req, map &map_params ) } int -reqp::htoi(string *p_str) +reqp::htoi(string *s) { - int value, c; - c = p_str->at(0); + int value; + int c; + + c = s->at(0); if( isupper(c) ) c = tolower(c); value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16; - c = p_str->at(1); + c = s->at(1); if( isupper(c) ) c = tolower(c); @@ -189,32 +191,31 @@ reqp::htoi(string *p_str) } string -reqp::url_decode( string s_url ) +reqp::url_decode( string s_str ) { string s_dest = ""; - int i_len = s_url.size(); + int i_len = s_str.size(); int i_prv = i_len - 2; - char c; for( int i = 0; i < i_len; ++i) { - c = s_url.at(i); - if( c == '+' ) + char ch = s_str.at(i); + if( ch == '+' ) { s_dest += " "; } - else if (c == '%' && i < i_prv) + else if (ch == '%' && i < i_prv) { - string s_tmp = s_url.substr(i+1, 2); - c = (char) htoi(&s_tmp); - s_dest += c; + string s_tmp = s_str.substr(i+1, 2); + ch = (char) htoi(&s_tmp); + s_dest += ch; i += 2; } else { - s_dest += c; + s_dest += ch; } } @@ -231,23 +232,34 @@ reqp::get_from_header( string s_req, string s_hdr ) if ( (i_pos[1] = s_req.find( "\n", i_pos[0]) ) == string::npos ) return ""; - unsigned i_len = s_hdr.length(); + int i_len = s_hdr.length(); return s_req.substr( i_pos[0] + i_len, i_pos[1] - i_pos[0] - i_len - 1 ); } string -reqp::parse( int &i_sock, string s_req, map &map_params ) +reqp::parse( thrd* p_thrd, string s_req, map_string &map_params ) { // store all request informations in map_params. store the url in // map_params["request"]. - get_url( i_sock, s_req, map_params ); + get_url( p_thrd, s_req, map_params ); parse_headers( s_req, map_params ); string s_event( map_params["event"] ); - map_params["content-type"] = get_content_type( map_params["request"] ); + // create the http header. + string s_rep( HTTP_CODEOK ); + s_rep.append( HTTP_SERVER ); + s_rep.append( HTTP_CONTAC ); + s_rep.append( HTTP_EXPIRE ); + s_rep.append( HTTP_CACHEC ); + s_rep.append( HTTP_CONNEC ); + + if ( s_event.compare("stream") == 0 ) + s_rep.append( HTTP_CHUNKE ); - string s_rep( "" ); + s_rep.append( HTTP_COTYPE ); + s_rep.append( get_content_type( map_params["request"] ) ); + s_rep.append("\r\n\r\n"); //<<* // check the event variable. @@ -269,12 +281,16 @@ reqp::parse( int &i_sock, string s_req, map &map_params ) else { - sess *p_sess = wrap::SMAN->get_session( map_params["tmpid"] ); - user *p_user = NULL; + bool b_found; - if( p_sess != NULL ) + // user* p_user = s_chat::get().get_user( map_params["nick"], b_found ); + sess *sess_temp= wrap::SMAN->get_session( map_params["tmpid"] ); + + user *p_user; + if( sess_temp != NULL ) { - p_user = p_sess->get_user(); + string s_nick = sess_temp->get_name(); + p_user = wrap::CHAT->get_user( s_nick, b_found); } else @@ -282,7 +298,7 @@ reqp::parse( int &i_sock, string s_req, map &map_params ) return s_rep; } - if ( ! p_user ) + if ( ! b_found ) { map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.notonline" ); map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. @@ -307,7 +323,7 @@ reqp::parse( int &i_sock, string s_req, map &map_params ) { string s_msg ( wrap::HTML->parse( map_params ) ); p_user->msg_post( &s_msg); - wrap::SOCK->chat_stream( i_sock, p_user, map_params ); + wrap::SOCK-> chat_stream( p_thrd->get_sock(), p_user, map_params ); } // if a request for the online list of the active room. @@ -340,25 +356,13 @@ reqp::parse( int &i_sock, string s_req, map &map_params ) s_rep.append( wrap::HTML->parse( map_params ) ); } - // create the http header. - - string s_resp(s_http); - if ( s_event.compare("stream") == 0 ) - s_resp.append( s_http_stream ); - - s_resp.append( s_http_colength + tool::int2string(s_rep.size()) + "\n" - + map_params["content-type"] + "\r\n\r\n" ); - - s_resp.append(s_rep); - - // return the parsed html-template. - return s_resp; + return s_rep; } //<<* void -reqp::run_html_mod( string s_event, map &map_params, user* p_user ) +reqp::run_html_mod( string s_event, map_string &map_params, user* p_user ) { container *c = new container; diff --git a/src/reqp.h b/src/reqp.h index 9fec7e2..519100e 100755 --- a/src/reqp.h +++ b/src/reqp.h @@ -1,41 +1,50 @@ #include "incl.h" + #ifndef REQP_H #define REQP_H #include +#include "thrd/thrd.h" using namespace std; +typedef map > map_string; + class reqp { private: - static const string s_http; - static const string s_http_stream; - static const string s_http_colength; - static const string s_http_cotype; + static string HTTP_CODEOK, + HTTP_CODENF, + HTTP_EXPIRE, + HTTP_SERVER, + HTTP_CONTAC, + HTTP_CACHEC, + HTTP_CONNEC, + HTTP_CHUNKE, + HTTP_COTYPE; // returns the request url from thr client's http request header // until the first "?" and stores all request parameter values // ( behind "?" ) into map_params. - string get_url( int &i_sock, string s_req, map &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... ). - string get_from_header( string s_req, string s_hdr ); + virtual string get_from_header( string s_req, string s_hdr ); - int htoi( string *p_str ); - void run_html_mod( string s_event, map &map_params, user* p_user ); //<< + virtual int htoi( string *s ); + virtual void run_html_mod( string s_event, map_string &map_params, user* p_user ); //<< // Removes double dots ".." string remove_dots( string s_req ); // Parses "event=bla?blu=bli&sadasda=asddds ..." string and stores them in the map - void get_request_parameters( string s_parameters, map& map_params ); + void get_request_parameters( string s_parameters, map_string& map_params ); public: reqp( ); - string parse( int &i_sock, string s_req, map &map_params ); - string url_decode ( string s_url ); - string get_content_type( string s_file ); - void parse_headers( string s_req, map &map_params ); + virtual string parse( thrd* p_thrd, string s_req, map_string &map_params ); + virtual string url_decode ( string ); + virtual string get_content_type( string ); + virtual void parse_headers( string s_req, map_string &map_params ); }; #endif diff --git a/src/sock/sock.cpp b/src/sock/sock.cpp index c08a3cd..531ccb9 100755 --- a/src/sock/sock.cpp +++ b/src/sock/sock.cpp @@ -18,20 +18,20 @@ sock::sock() this->i_threads = 0; this->req_parser = new reqp(); this->thrd_pool = new pool(); -#ifdef LOGGING this->log_daemon = new logd( wrap::CONF->get_elem( "httpd.logging.accessfile" ), - wrap::CONF->get_elem( "httpd.logging.accesslines" ) ); -#endif + + pthread_mutex_init( &mut_threads, NULL ); } sock::~sock() { + pthread_mutex_destroy( &mut_threads ); } //<<* void -sock::chat_stream( int i_sock, user *p_user, map &map_params ) +sock::chat_stream( int i_sock, user* p_user, map_string &map_params ) { string s_msg( "\n" ); @@ -45,13 +45,8 @@ sock::chat_stream( int i_sock, user *p_user, map &map_params ) do { s_msg = p_user->get_mess( ); - if ( 0 > send( i_sock, s_msg.c_str(), s_msg.size(), 0 ) ) - { p_user->set_online( false ); - break; - } - pthread_cond_wait( &(p_user->cond_message), &mutex ); } while( p_user->get_online() ); @@ -60,14 +55,12 @@ sock::chat_stream( int i_sock, user *p_user, map &map_params ) // if there is still a message to send: s_msg = p_user->get_mess( ); - if ( ! s_msg.empty() ) send( i_sock, s_msg.c_str(), s_msg.size(), 0 ); // remove the user from its room. string s_user( p_user->get_name() ); string s_user_lowercase( p_user->get_lowercase_name() ); - p_user->get_room()->del_elem( s_user_lowercase ); // post the room that the user has left the chat. @@ -90,17 +83,17 @@ sock::chat_stream( int i_sock, user *p_user, map &map_params ) int sock::make_server_socket( int i_port ) { - size_t i_sock; + size_t sock; struct sockaddr_in name; // create the server socket. - i_sock = socket (PF_INET, SOCK_STREAM, 0); - if (i_sock < 0) + sock = socket (PF_INET, SOCK_STREAM, 0); + if (sock < 0) { wrap::system_message( SOCKERR ); if ( ++i_port > MAXPORT ) - exit(1); + exit(-1); wrap::system_message( SOCKERR ); @@ -109,23 +102,22 @@ sock::make_server_socket( int i_port ) // give the server socket a name. name.sin_family = AF_INET; - name.sin_port = htons(i_port); - name.sin_addr.s_addr = htonl(INADDR_ANY); - int i_optval = 1; + name.sin_port = htons (i_port); + name.sin_addr.s_addr = htonl (INADDR_ANY); + int optval=1; - setsockopt( i_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&i_optval, sizeof(int) ); + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(int)); - if ( bind(i_sock, (struct sockaddr *) &name, sizeof (name)) < 0 ) + if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) { wrap::system_message( BINDERR ); if ( ++i_port > MAXPORT ) - exit(1); + exit(-1); wrap::system_message( string(SOCKERR) + tool::int2string(i_port) ); - // Rerun recursive. return make_server_socket( i_port ); } @@ -136,61 +128,47 @@ sock::make_server_socket( int i_port ) refresh(); #endif - return i_sock; + return sock; } int -sock::read_write( int* p_sock ) +sock::read_write( thrd* p_thrd, int i_sock ) { - int i_sock = *p_sock; char c_req[READSOCK]; - int i_bytes = read(i_sock, c_req, READSOCK); + int i_bytes = read (i_sock, c_req, READSOCK); if (i_bytes <= 0) { wrap::system_message( READERR ); } - else { // stores the request params. - map map_params; + map_string map_params; // get the s_rep ( s_html response which will be send imediatly to the client struct sockaddr_in client; size_t size = sizeof(client); -#ifdef CYGWIN - getpeername( i_sock, (struct sockaddr *)&client, (int*)&size); -#else getpeername( i_sock, (struct sockaddr *)&client, &size); -#endif map_params["REMOTE_ADDR"] = inet_ntoa(client.sin_addr); //map_params["REMOTE_PORT"] = ntohs(client.sin_port); - string s_rep = req_parser->parse( i_sock, string( c_req ), map_params ); + string s_rep = req_parser->parse( p_thrd, string( c_req ), map_params ); -#ifdef LOGGING log_daemon->log_access(map_params); -#endif // send s_rep to the client. - send(i_sock, s_rep.c_str(), s_rep.size(), 0); + send( i_sock, s_rep.c_str(), s_rep.size(), 0 ); // dont need those vals anymore. map_params.clear(); - shutdown( i_sock, 2 ); - close ( i_sock ); - return 0; } - shutdown( i_sock, 2 ); - close ( i_sock ); - - return 1; + return -1; } int @@ -200,20 +178,23 @@ sock::start() #ifdef NCURSES print_hits(); + print_threads(); thrd_pool->print_pool_size(); #endif - int i_port = tool::string2int( wrap::CONF->get_elem( "httpd.serverport" ) ); - int i_sock, i; + auto int i_port = tool::string2int( wrap::CONF->get_elem( "httpd.serverport" ) ); + + int sock; fd_set active_fd_set, read_fd_set; + int i; struct sockaddr_in clientname; size_t size; // create the server socket and set it up to accept connections. - i_sock = make_server_socket ( i_port ); + sock = make_server_socket ( i_port ); - if (listen (i_sock, 1) < 0) + if (listen (sock, 1) < 0) { wrap::system_message( LISTERR ); exit( EXIT_FAILURE ); @@ -223,7 +204,7 @@ sock::start() // initialize the set of active sockets. FD_ZERO (&active_fd_set); - FD_SET (i_sock, &active_fd_set); + FD_SET (sock, &active_fd_set); while( b_run ) { @@ -240,26 +221,21 @@ sock::start() for ( i = 0; i < FD_SETSIZE; i++ ) if ( FD_ISSET (i, &read_fd_set) ) { - if ( i == i_sock ) + if ( i == sock ) { // connection request on original socket. - ++i_req; - + i_req++; #ifdef NCURSES print_hits(); #endif - int i_new_sock; - size = sizeof(clientname); -#ifdef CYGWIN - i_new_sock = accept (i_sock, (struct sockaddr *) &clientname, (int*)&size); -#else - i_new_sock = accept (i_sock, (struct sockaddr *) &clientname, &size); -#endif + int new_sock; + size = sizeof (clientname); + new_sock = accept (sock, (struct sockaddr *) &clientname, &size); - if (i_new_sock < 0) + if (new_sock < 0) { wrap::system_message( ACCPERR ); - close(i_new_sock); + close ( new_sock ); } else @@ -271,22 +247,54 @@ sock::start() + tool::int2string(ntohs ( clientname.sin_port )) ); #endif - FD_SET (i_new_sock, &active_fd_set); + FD_SET (new_sock, &active_fd_set); } } else { - int *p_sock = new int; - *p_sock = i; - thrd_pool->run( (void*) p_sock ); + thrd_pool->run( (void*) new thrd( i ) ); FD_CLR( i, &active_fd_set ); } } } } +void +sock::increase_num_threads() +{ + pthread_mutex_lock( &mut_threads ); + i_threads++; + pthread_mutex_unlock( &mut_threads ); + +#ifdef NCURSES + print_threads(); +#endif +} + +void +sock::decrease_num_threads() +{ + pthread_mutex_lock( &mut_threads ); + i_threads--; + pthread_mutex_unlock( &mut_threads ); + +#ifdef NCURSES + print_threads(); +#endif +} + #ifdef NCURSES +void +sock::print_threads() +{ + if ( wrap::NCUR->is_ready() ) + { + mvprintw( NCUR_POOL_RUNNING_X,NCUR_POOL_RUNNING_Y, "In use: %d ", i_threads); + refresh(); + } +} + void sock::print_hits() { diff --git a/src/sock/sock.h b/src/sock/sock.h index 7023be5..6f3419e 100755 --- a/src/sock/sock.h +++ b/src/sock/sock.h @@ -3,19 +3,18 @@ #ifndef SOCK_H #define SOCK_H + #include #include #include #include #include #include - #include "../thrd/pool.h" +#include "../thrd/thrd.h" #include "../reqp.h" #include "../chat/user.h" -#ifdef LOGGING #include "../logd.h" -#endif using namespace std; @@ -23,46 +22,50 @@ class sock { private: // total number of server requests. - unsigned long long i_req; + unsigned long long int i_req; bool b_run; // true while socket manager is running. - reqp *req_parser; // parses the http requests from clients. - pool *thrd_pool; // the thread pool. -#ifdef LOGGING - logd *log_daemon; // the log daemon -#endif - char *c_buffer; // char buffer! - int i_threads; // total amount of threads inside the thread pool. + reqp* req_parser; // parses the http requests from clients. + pool* thrd_pool; // the thread pool. + logd* log_daemon; // the log daemon + char* c_buffer; // char buffer! + int i_threads; // total amount of threads inside the thread pool. + pthread_mutex_t mut_threads; pthread_mutex_t mut_hits; + public: // creates a server socket. - int make_server_socket( int i_port ); + int make_server_socket( int port ); // small inline methods: bool get_run() const { return b_run; } - bool set_run( bool b_run ) { this->b_run = b_run; } - sock( ); + // public methods. + explicit sock( ); // simple constructor. ~sock( ); - - int read_write( int* p_sock ); - int start(); + virtual int read_write( thrd* p_thrd, int filedes ); + virtual int start(); // the chat stream there all the chat messages will sent through. - static void chat_stream( int i_sock, user* p_user, map &map_params ); //<< + static void chat_stream( int i_sock, user* p_user, map_string &map_params ); //<< + void increase_num_threads(); + void decrease_num_threads(); #ifdef NCURSES + + void print_threads(); void print_hits(); #endif + }; #endif diff --git a/src/stats.cpp b/src/stats.cpp index 95d8ab1..7fba04d 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -145,5 +145,4 @@ stats::print_num_rooms() } #endif //*>> - #endif diff --git a/src/stats.h b/src/stats.h index 608232e..647f504 100644 --- a/src/stats.h +++ b/src/stats.h @@ -4,11 +4,11 @@ #define STATS_H #include "tool/tool.h" - #include #include #include #include +#include using namespace std; diff --git a/src/thrd/pool.cpp b/src/thrd/pool.cpp index ef7b0a3..1db639d 100755 --- a/src/thrd/pool.cpp +++ b/src/thrd/pool.cpp @@ -2,26 +2,25 @@ #define POOL_CPP #include "pool.h" +#include "thrd.h" using namespace std; -int pool::i_thrd_used = 0; - pool::pool() { - i_thrd_pool_size = tool::string2int( wrap::CONF->get_elem( "httpd.thread.initpoolsize" ) ); + i_thrd_pool_size = tool::string2int( wrap::CONF->get_elem( "httpd.thread.poolsize" ) ); i_thrd_pool_queue = tool::string2int( wrap::CONF->get_elem( "httpd.thread.queuesize" ) ); - tpool_init( &thread_pool, i_thrd_pool_size, i_thrd_pool_queue); + tpool_init( &thread_pool, i_thrd_pool_size, i_thrd_pool_queue, 0 ); } void -pool::tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size) +pool::tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size, int do_not_block_when_full ) { int i, rtn; tpool_t tpool; // allocate a pool data structure - if (( tpool = (tpool_t) malloc( sizeof( struct tpool ) ) ) == 0 ) + if (( tpool = (tpool_t) malloc( sizeof( struct tpool ) ) ) == NULL ) { wrap::system_message( POOLERR ); exit(-1); @@ -30,18 +29,21 @@ pool::tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size) // initialize th fields tpool->num_threads = num_worker_threads; tpool->max_queue_size = max_queue_size; + tpool->do_not_block_when_full = do_not_block_when_full; - if ( ( tpool->threads = (pthread_t*) malloc( sizeof(pthread_t)*num_worker_threads ) ) == 0 ) + if ( ( tpool->threads = (pthread_t*) malloc( sizeof( pthread_t ) *num_worker_threads ) ) == NULL ) { wrap::system_message( POOLERR ); exit(-1); } tpool->cur_queue_size = 0; - tpool->queue_head = 0; - tpool->queue_tail = 0; + tpool->queue_head = NULL; + tpool->queue_tail = NULL; + tpool->queue_closed = 0; + tpool->shutdown = 0; - if ( ( rtn = pthread_mutex_init( &(tpool->queue_lock), 0 ) ) != 0 ) + if ( ( rtn = pthread_mutex_init( &(tpool->queue_lock), NULL ) ) != 0 ) { string s_err( "pthread_mutex_init " ); s_err.append( strerror( rtn ) ); @@ -50,166 +52,146 @@ pool::tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size) exit(-1); } - - else if ( ( rtn = pthread_cond_init( &(tpool->queue_not_empty), 0 ) ) != 0 ) + else if ( ( rtn = pthread_cond_init( &(tpool->queue_not_empty), NULL ) ) != 0 ) { - string s_err( "pthread_cond_init (1): " ); + string s_err( "pthread_mutex_init " ); s_err.append( strerror( rtn ) ); wrap::system_message( s_err ); - exit(1); + exit(-1); } - - else if ( ( rtn = pthread_cond_init( &(tpool->queue_not_full), 0 ) ) != 0 ) + else if ( ( rtn = pthread_cond_init( &(tpool->queue_not_full), NULL ) ) != 0 ) { - string s_err( "pthread_cond_init (2): " ); + string s_err( "pthread_mutex_init " ); s_err.append( strerror( rtn ) ); wrap::system_message( s_err ); - exit(1); + exit(-1); } - - else if ( ( rtn = pthread_cond_init( &(tpool->queue_empty), 0 ) ) != 0 ) + else if ( ( rtn = pthread_cond_init( &(tpool->queue_empty), NULL ) ) != 0 ) { string s_err( "pthread_mutex_init " ); s_err.append( strerror( rtn ) ); wrap::system_message( s_err ); - exit(1); + exit(-1); } - // create threads - for ( i = 0; i < num_worker_threads; ++i ) - pthread_create( &(tpool->threads[i]) , 0, tpool_thread, (void*)tpool ); + for ( i = 0; i < num_worker_threads; i++ ) + pthread_create( &(tpool->threads[i]) , NULL, tpool_thread, (void*)tpool ); *tpoolp = tpool; } void* -pool::tpool_thread( void* p_void ) +pool::tpool_thread( void* arg ) { - tpool_t tpool = (tpool_t) p_void; + tpool_t tpool = (tpool_t) arg; tpool_work_t *my_workp; - for( pthread_mutex_lock( &(tpool->queue_lock) );; - pthread_mutex_lock( &(tpool->queue_lock) ), --i_thrd_used ) - { + while( true ) + { + pthread_mutex_lock( &(tpool->queue_lock) ); -#ifdef NCURSES - print_threads(i_thrd_used); -#endif + while ( (tpool->cur_queue_size == 0) && (!tpool->shutdown) ) + pthread_cond_wait( &(tpool->queue_not_empty), &(tpool->queue_lock) ); - while (tpool->cur_queue_size == 0) - pthread_cond_wait( &(tpool->queue_not_empty), &(tpool->queue_lock) ); + if (tpool->shutdown) + { + pthread_mutex_unlock( &(tpool->queue_lock) ); + pthread_exit( NULL ); + } my_workp = tpool->queue_head; tpool->cur_queue_size--; if ( tpool->cur_queue_size == 0) - tpool->queue_head = tpool->queue_tail = 0; + tpool->queue_head = tpool->queue_tail = NULL; else tpool->queue_head = my_workp->next; - if ( tpool->cur_queue_size == ( tpool->max_queue_size - 1 ) ) + if ( ( ! tpool->do_not_block_when_full ) && + ( tpool->cur_queue_size == ( tpool->max_queue_size - 1 ) ) ) pthread_cond_signal( &(tpool->queue_not_full) ); - if ( tpool->cur_queue_size == 0 ) + if ( tpool->cur_queue_size == 0 ) pthread_cond_signal( &(tpool->queue_empty) ); pthread_mutex_unlock( &(tpool->queue_lock) ); - - (*(my_workp->routine))(my_workp->p_void); - - free(my_workp); + (*(my_workp->routine))(my_workp->arg); + free((void*)my_workp); } } -void pool::run_func( void *p_void ) +void pool::run_func( void *v_pointer ) { - int* p_sock = (int*)p_void; - wrap::SOCK->read_write( p_sock ); - delete p_sock; + wrap::SOCK->increase_num_threads(); + + // recasting the client thread object. + thrd *t = (thrd*) v_pointer; + + // start parsing the client request and sending response's back. + t-> run (); + + // close the client socket. + t->~thrd(); + + wrap::SOCK->decrease_num_threads(); + + free(v_pointer); } int -pool::tpool_add_work( tpool_t tpool, void(*routine)(void*), void* p_void ) /// +pool::tpool_add_work( tpool_t tpool, void(*routine)(void*), void* arg ) /// { tpool_work_t *workp; pthread_mutex_lock( &(tpool->queue_lock) ); - if ( ++i_thrd_used == tpool->num_threads ) + if( ( tpool->cur_queue_size == tpool->max_queue_size ) && + tpool->do_not_block_when_full ) { - int i_max_pool_size = tool::string2int( wrap::CONF->get_elem( "httpd.thread.maxpoolsize" ) ); - if ( i_max_pool_size != 0 && i_thrd_used > i_max_pool_size ) - { - wrap::system_message(POOLER2+tool::int2string(i_thrd_used)+")"); - } - - else - { - int i_size = tpool->num_threads + 1; - - wrap::system_message(POOLFLL+tool::int2string(i_size)+")"); - - tpool->threads = (pthread_t*)realloc((void*)tpool->threads, sizeof(pthread_t)*tpool->num_threads); - - for ( int i = tpool->num_threads; i < i_size; ++i ) - pthread_create( &(tpool->threads[i]) , 0, tpool_thread, (void*)tpool ); - - i_thrd_pool_size = tpool->num_threads = i_size; -#ifdef NCURSES - print_pool_size(); -#endif - } + pthread_mutex_unlock( &(tpool->queue_lock) ); + return -1; } -#ifdef NCURSES - print_threads(i_thrd_used); -#endif - - while (tpool->cur_queue_size == tpool->max_queue_size) + while( ( tpool->cur_queue_size == tpool->max_queue_size ) && + ( ! ( tpool->shutdown || tpool->queue_closed ) ) ) pthread_cond_wait( &(tpool->queue_not_full), &(tpool->queue_lock) ); + if( tpool->shutdown || tpool->queue_closed ) + { + pthread_mutex_unlock( &tpool->queue_lock ); + return -1; + } + // allocate work structure: workp = (tpool_work_t*) malloc( sizeof( tpool_work_t ) ); workp->routine = routine; - workp->p_void = p_void; - workp->next = 0; + workp->arg = arg; + workp->next = NULL; - if (tpool->cur_queue_size == 0 ) + if( tpool->cur_queue_size == 0 ) { tpool->queue_tail = tpool->queue_head = workp; } - else { (tpool->queue_tail)->next = workp; tpool->queue_tail = workp; } - tpool->cur_queue_size++; pthread_cond_signal( &tpool->queue_not_empty ); + tpool->cur_queue_size++; pthread_mutex_unlock( &(tpool->queue_lock) ); - - return 0; + return 1; } #ifdef NCURSES -void -pool::print_threads(int i_thrd_used) -{ - if ( wrap::NCUR->is_ready() ) - { - mvprintw( NCUR_POOL_RUNNING_X,NCUR_POOL_RUNNING_Y, "In use: %d ", i_thrd_used); - refresh(); - } -} - void pool::print_pool_size() { diff --git a/src/thrd/pool.h b/src/thrd/pool.h index cbd1e83..a744133 100755 --- a/src/thrd/pool.h +++ b/src/thrd/pool.h @@ -8,11 +8,10 @@ using namespace std; class pool { private: - static int i_thrd_used; - - typedef struct tpool_work { + typedef struct tpool_work + { void (*routine)(void*); /// - void *p_void; + void *arg; struct tpool_work *next; } tpool_work_t; @@ -22,6 +21,7 @@ private: // pool characteristics: int num_threads; int max_queue_size; + int do_not_block_when_full; // pool state pthread_t *threads; @@ -34,6 +34,9 @@ private: pthread_cond_t queue_not_empty; pthread_cond_t queue_not_full; pthread_cond_t queue_empty; + + int queue_closed; + int shutdown; } *tpool_t; @@ -42,23 +45,32 @@ private: tpool_t thread_pool; - void tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size); - int tpool_add_work( tpool_t tpool, void(*routine)(void*), void* p_void ); - static void* tpool_thread( void *p_void); - static void run_func( void *p_void ); + void + tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size, int do_not_block_when_full ); + + int + tpool_add_work( tpool_t tpool, void(*routine)(void*), void* arg ); + // virtual void + // tpool_destroy( tpool_t tpoolp, int finish ); + + static void* + tpool_thread( void* arg); + + static void + run_func( void *v_pointer ); + + // public methods: public: - pool(); + pool( ); // inline (speed)! - void run( void *p_void ) + void run( void *arg ) { - tpool_add_work( thread_pool, run_func, p_void ); + tpool_add_work( thread_pool, run_func, arg ); } - #ifdef NCURSES void print_pool_size(); - static void print_threads(int i_thrd_used); #endif }; diff --git a/src/thrd/thro.cpp b/src/thrd/thro.cpp index 739ba0e..f6acf53 100644 --- a/src/thrd/thro.cpp +++ b/src/thrd/thro.cpp @@ -16,7 +16,7 @@ thro::~thro() void thro::run() { - void *p_void; + void* p_void; run( p_void ); } @@ -41,4 +41,5 @@ thro::start( void *p_void ) wrap::system_message( THRDSTR ); } + #endif diff --git a/src/thrd/thro.h b/src/thrd/thro.h index 9ad1e3e..ef38793 100644 --- a/src/thrd/thro.h +++ b/src/thrd/thro.h @@ -1,3 +1,5 @@ +// Threaded Object (thro) + #include "../incl.h" #ifndef THRO_H @@ -11,18 +13,18 @@ private: pthread_t pthread; struct elements { - thro *p_thro; - void *p_void; + thro* p_thro; + void* p_void; } elem; - static void* start_( void *p_void ); + static void* start_( void* p_void ); public: thro( ); ~thro( ); void run(); - void run( void *p_void ); - virtual void start( void *p_void ); + void run( void* p_void ); + virtual void start( void* p_void ); }; #endif diff --git a/src/time/timo.cpp b/src/time/timo.cpp index d00bafe..c44ebae 100755 --- a/src/time/timo.cpp +++ b/src/time/timo.cpp @@ -9,7 +9,6 @@ timo::timo() { pthread_mutex_init( &mut_t_time, NULL ); } - timo::~timo() { pthread_mutex_destroy( &mut_t_time ); @@ -19,11 +18,9 @@ double timo::get_last_activity( ) { double d_ret; - pthread_mutex_lock ( &mut_t_time ); d_ret = wrap::TIMR->get_time_diff( t_time ); pthread_mutex_unlock( &mut_t_time ); - return d_ret; } @@ -35,4 +32,5 @@ timo::renew_timeout( ) pthread_mutex_unlock( &mut_t_time ); } + #endif diff --git a/src/time/timr.cpp b/src/time/timr.cpp index 12b5972..fa308d3 100755 --- a/src/time/timr.cpp +++ b/src/time/timr.cpp @@ -10,14 +10,11 @@ timr::timr() { wrap::system_message( TIMERIN ); b_timer_active = true; - pthread_mutex_init( &mut_s_time, NULL); pthread_mutex_init( &mut_s_uptime, NULL); pthread_mutex_init( &mut_i_offset, NULL); - i_time_offset = tool::string2int( wrap::CONF->get_elem("chat.timeoffset") ); wrap::system_message( TIMEROF + tool::int2string( i_time_offset ) ); - s_time = "00:00:00"; s_uptime = "00:00:00"; } @@ -45,8 +42,10 @@ timr::get_offset() } void -timr::start( void *v_ptr ) +timr::start( void *v_pointer ) { +// timr* p_timer = this; //static_cast(this); + wrap::system_message( TIMERTH ); #ifdef NCURSES @@ -59,7 +58,6 @@ timr::start( void *v_ptr ) time( &clock_start ); tm time_start = *localtime( &clock_start ); tm time_now; - while ( get_timer_active() ) { // sleep a second! @@ -73,12 +71,10 @@ timr::start( void *v_ptr ) // set the current time && the current ychat uptime! set_time( difftime( clock_now, clock_start ), time_now.tm_sec, time_now.tm_min, time_now.tm_hour ); - #ifdef NCURSES if (wrap::NCUR->is_ready()) print_time( ); #endif - // run every minute: if ( time_now.tm_sec == 0 ) { @@ -86,12 +82,12 @@ timr::start( void *v_ptr ) cout << TIMERUP << get_uptime() << endl; #endif //<<* - int* p_timeout_settings = new int[3]; - p_timeout_settings[0] = tool::string2int(wrap::CONF->get_elem("chat.idle.timeout")); - p_timeout_settings[1] = tool::string2int(wrap::CONF->get_elem("chat.idle.awaytimeout")); - p_timeout_settings[2] = tool::string2int(wrap::CONF->get_elem("chat.idle.autoawaytimeout")); - wrap::CHAT->check_timeout( p_timeout_settings ); - delete p_timeout_settings; + int* i_timeout_settings = new int[3]; + i_timeout_settings[0] = tool::string2int(wrap::CONF->get_elem("chat.idle.timeout")); + i_timeout_settings[1] = tool::string2int(wrap::CONF->get_elem("chat.idle.awaytimeout")); + i_timeout_settings[2] = tool::string2int(wrap::CONF->get_elem("chat.idle.autoawaytimeout")); + wrap::CHAT->check_timeout( i_timeout_settings ); + delete i_timeout_settings; string s_ping = "\n"; wrap::CHAT->msg_post( &s_ping ); @@ -105,11 +101,11 @@ timr::start( void *v_ptr ) // run every ten minutes: if ( time_now.tm_min % 10 == 0 ) { + wrap::GCOL->remove_garbage(); //<< + // run every hour if ( time_now.tm_hour % 60 == 0 ) { - wrap::GCOL->remove_garbage(); //<< - // run every day if (time_now.tm_min == 0 || time_now.tm_min == 60 ) if (time_now.tm_hour == 0 || time_now.tm_hour == 24) @@ -139,7 +135,6 @@ timr::set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur int i_hours = (int) d_uptime / 3600; int i_minutes = (int) d_uptime / 60; - while ( i_minutes >= 60 ) i_minutes -= 60; @@ -148,8 +143,7 @@ timr::set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur // Calculate offset time i_cur_hours += get_offset(); - - for ( int i = 24-i_cur_hours; i < 0; i = 24-i_cur_hours ) + for (int i = 24 - i_cur_hours; i < 0; i = 24 - i_cur_hours) i_cur_hours =- i; if (i_cur_hours == 24) @@ -181,11 +175,10 @@ timr::add_zero_to_front( string s_time ) } double -timr::get_time_diff( time_t &clock_diff ) +timr::get_time_diff( time_t& clock_diff ) { time_t clock_now; time( &clock_now ); - - return difftime(clock_now, clock_diff); + return difftime( clock_now, clock_diff ); } #endif diff --git a/src/time/timr.h b/src/time/timr.h index 46234b3..a327d5b 100755 --- a/src/time/timr.h +++ b/src/time/timr.h @@ -26,10 +26,10 @@ public: ~timr(); bool get_timer_active() const; - void start( void *v_ptr ); + void start( void *v_pointer ); #ifdef NCURSES - void print_time(); + void print_time( ); #endif void set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur_hours ); @@ -56,8 +56,8 @@ public: return s_ret; } - int get_offset(); - double get_time_diff( time_t &clock_diff ); + virtual int get_offset(); + virtual double get_time_diff( time_t& clock_diff ); }; #endif diff --git a/src/tool/dir.cpp b/src/tool/dir.cpp index ae48d5f..392112a 100644 --- a/src/tool/dir.cpp +++ b/src/tool/dir.cpp @@ -12,7 +12,7 @@ dir::dir() dir::~dir() { - vec_dir.clear(); + dir_vec.clear(); close_dir(); } @@ -29,9 +29,9 @@ dir::open_dir( string &s_dir ) if ( b_open ) return false; - p_d = opendir( s_dir.c_str() ); + dp = opendir( s_dir.c_str() ); - if ( p_d == NULL ) + if ( dp == NULL ) return false; // Could not open dir. b_open = true; @@ -42,9 +42,9 @@ dir::open_dir( string &s_dir ) void dir::close_dir() { - if ( b_open && p_d != NULL ) + if ( b_open && dp != NULL ) { - closedir( p_d ); + closedir( dp ); b_open = false; } } @@ -52,15 +52,15 @@ dir::close_dir() void dir::read_dir() { - if ( p_d != NULL ) - while( p_ep = readdir( p_d ) ) - vec_dir.push_back( string( p_ep->d_name ) ); + if ( dp != NULL ) + while( ep = readdir( dp ) ) + dir_vec.push_back( string( ep->d_name ) ); } vector dir::get_dir_vec() { - return vec_dir; + return dir_vec; } #endif diff --git a/src/tool/dir.h b/src/tool/dir.h index 22ec510..cff265f 100644 --- a/src/tool/dir.h +++ b/src/tool/dir.h @@ -6,9 +6,7 @@ #include #include #include - #include - #include "../incl.h" using namespace std; @@ -17,9 +15,9 @@ class dir { private: bool b_open; - DIR *p_d; - struct dirent *p_ep; - vector vec_dir; + DIR *dp; + struct dirent *ep; + vector dir_vec; public: dir(); diff --git a/src/tool/tool.cpp b/src/tool/tool.cpp index dec9bdb..1da4a12 100644 --- a/src/tool/tool.cpp +++ b/src/tool/tool.cpp @@ -11,135 +11,30 @@ #include "tool.h" -bool -tool::is_alpha_numeric( string &s_digit ) -{ - const char *p_digit = s_digit.c_str(); - int i_len = strlen( p_digit ); - - for( int i=0; i= '0' && *p_digit <='9') - { - i_res = (i_res * 10) + (*p_digit - '0'); - p_digit++; - } - - // Check that there were no non-digits at end. - if (*p_digit != 0) - { - return -1; - } - - return i_res; -} - -string -tool::to_lower( string s_str ) -{ - string s_tmp(""); - - for( int i = 0; i < s_str.size() ;i++ ) - s_tmp = s_tmp + (char) tolower( s_str.at(i) ); - - return s_tmp; -} - -void -tool::strip_html( string *p_str) -{ - int i_pos; - - if( (i_pos=p_str->find("<", 0)) == string::npos ) - return; - - while(true) - { - p_str->replace(i_pos, 1, "<"); - - if( (i_pos = p_str->find("<", 0)) == string::npos ) - return; - } -} - -string -tool::ychat_version() -{ - return "yChat " + string(VERSION) - + "-" + string(BRANCH) - + " Build " + int2string(BUILDNR); -} - -list -tool::split_string(string s_string, string s_split) { - list list_ret; - unsigned i_pos, i_len = s_split.length(); - - while ( (i_pos = s_string.find(s_split)) != string::npos ) - { - list_ret.push_back( s_string.substr(0, i_pos) ); - s_string = s_string.substr( i_pos + i_len ); - } - - list_ret.push_back( s_string ); - - return list_ret; -} - string tool::trim( string s_str ) { - if( s_str.empty() ) - return s_str; + if(s_str.empty()) + return ""; char c_cur = s_str[0]; - int i_pos = 0; + auto int pos=0; // left trim - while ( c_cur == ' '|| c_cur == '\n' || c_cur == '\r' ) + while (c_cur==' '|| c_cur == '\n' || c_cur == '\r') { - s_str.erase(i_pos,1); - c_cur = s_str[++i_pos]; + s_str.erase(pos,1); + c_cur = s_str[++pos]; } // right trim - i_pos = s_str.size(); + pos=s_str.size(); c_cur = s_str[s_str.size()]; - while ( c_cur == ' ' || c_cur == '\n' || c_cur == '\0' || c_cur == '\r' ) + while (c_cur==' ' || c_cur == '\n' || c_cur == '\0' || c_cur == '\r') { - s_str.erase(i_pos, 1); - c_cur = s_str[--i_pos]; + s_str.erase(pos,1); + c_cur = s_str[--pos]; } return s_str; @@ -149,16 +44,16 @@ char* tool::clean_char( char* c_str ) { // Ralf: - for ( char* c_pos = c_str; *c_pos != '\0'; ++c_pos ) + char *c_pos; + for (c_pos = c_str; *c_pos != '\0'; ++c_pos) if ( iscntrl(*c_pos) ) *c_pos = ' '; - return c_str; } string tool::replace( string s_string, string s_search, string s_replace ) { - unsigned i_pos[2]; + unsigned int i_pos[2]; for ( i_pos[0] = s_string.find( s_search ); i_pos[0] != string::npos; @@ -174,34 +69,32 @@ tool::replace( string s_string, string s_search, string s_replace ) string tool::get_extension( string s_file ) { - int i_pos = s_file.find_last_of("."); - - if( i_pos != string::npos ) + int pos = s_file.find_last_of("."); + if(pos != string::npos) { - string s_ext = s_file.substr(i_pos+1, s_file.size()-i_pos-1 ); - for( int i = 0; i < s_ext.size(); ++i ) - s_ext[i] = tolower(s_ext[i]); + string s_ext=s_file.substr(pos+1, s_file.size()-(pos+1)); + for(int i = 0;i - using namespace std; class tool { public: - static list split_string(string s_string, string s_split); - static bool is_alpha_numeric( string &s_digit ); + static bool is_alpha_numeric( string &s_digit ) + { + auto const char *digit = s_digit.c_str(); + auto int i_len = strlen( digit ); + + + for( int i=0; i= '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; + } + static void strip_html( string *s_str) + { + auto int i_pos; + if((i_pos=s_str->find("<",0))==string::npos) + return; + while(true) + { + s_str->replace(i_pos,1,"<"); + if((i_pos=s_str->find("<",0))==string::npos) + return; + } + } + static string get_extension( string s_file ); - static string to_lower( string s_str ); - static void strip_html( string *p_str ); - static string shell_command( string s_command, method m_method ); - static string ychat_version(); + static string to_lower( string s ) + { + string s_tmp(""); + for(int i=0;i < s.size() ;i++) + s_tmp=s_tmp+(char)tolower(s.at(i)); + return s_tmp; + } + + static string shell_command( string s_command, method m_method ); + + static string ychat_version() + { + return string(VERSION) + "-" + string(BRANCH) + " Build " + int2string(BUILDNR); + } }; #endif diff --git a/src/wrap.cpp b/src/wrap.cpp index a0e1443..b6c8358 100755 --- a/src/wrap.cpp +++ b/src/wrap.cpp @@ -12,14 +12,12 @@ data* wrap::DATA; #endif gcol* wrap::GCOL; sman* wrap::SMAN; -modl* wrap::MODL; //*>> conf* wrap::CONF; html* wrap::HTML; -#ifdef LOGGING logd* wrap::LOGD; -#endif +modl* wrap::MODL; #ifdef NCURSES ncur* wrap::NCUR; #endif @@ -37,8 +35,6 @@ wrap::system_message( string s_message ) #ifdef SERVMSG cout << s_message << endl; #endif -#ifdef LOGGING wrap::LOGD->log_simple_line( s_message + "\n" ); -#endif } #endif diff --git a/src/wrap.h b/src/wrap.h index 214227e..afc45b1 100755 --- a/src/wrap.h +++ b/src/wrap.h @@ -2,6 +2,7 @@ #define WRAP_H #include "incl.h" + #ifdef DATABASE #include "data/data.h" #endif @@ -9,12 +10,8 @@ #include "conf/conf.h" #include "chat/gcol.h" #include "html.h" -#ifdef LOGGING #include "logd.h" -#endif -//<<* #include "modl.h" -//*>> #ifdef NCURSES #include "ncur/ncur.h" #endif @@ -35,14 +32,12 @@ class dynamic_wrap #endif gcol* GCOL; sman* SMAN; - modl* MODL; //*>> conf* CONF; html* HTML; -#ifdef LOGGING logd* LOGD; -#endif + modl* MODL; #ifdef NCURSES ncur* NCUR; #endif @@ -76,14 +71,12 @@ public: #ifdef IRCBOT static ybot* YBOT; #endif - static modl* MODL; //*>> static conf* CONF; static html* HTML; -#ifdef LOGGING static logd* LOGD; -#endif + static modl* MODL; #ifdef NCURSES static ncur* NCUR; #endif @@ -93,4 +86,5 @@ public: static dynamic_wrap* WRAP; }; + #endif -- cgit v1.2.3