diff options
125 files changed, 1457 insertions, 1586 deletions
@@ -1,46 +1,4 @@ -Changes from 0.7.4-RELEASE to 0.7.4.1-RELEASE: -- Thread pool bugfix. - -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: +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. @@ -51,7 +9,7 @@ Changes from 0.7.0 to 0.7.1-RELEASE: 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.0 RELEASE - Better stability - Better performance (using more hmaps) - HTML color switcher menu @@ -1,6 +1,6 @@ -MAKE=`tail -n 1 make.version` +MAKE=`tail -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,24 +8,7 @@ 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 @@ -33,10 +16,13 @@ install: deinstall @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" @@ -46,9 +32,6 @@ install: deinstall @echo "The most secure would be an additional user 'ychat'!" uninstall: deinstall deinstall: - @echo Install/deinstall is currently not working! - @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 @@ -102,6 +85,6 @@ mrproper: clean @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 @@ -1,11 +1,4 @@ -::(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. +::(06.11.04)::Released yChat and yhttpd 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. ::(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. @@ -1,7 +1,7 @@ -yChat; Homepage: www.yChat.org; Version 0.7.4.1-RELEASE +yChat; Homepage: www.yChat.org; Version 0.7.1-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,7 @@ 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). 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 @@ -178,16 +178,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 +194,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 +222,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,7 +235,7 @@ 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) @@ -249,7 +246,6 @@ or gmake config): gmake gpl (shows the GNU General Public License) gmake help (shows all available ychat gmake targets) gmake install (installs ychat to PREFIX) - gmake mail (sends a mail to the yChat developers containing build opts.) 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) @@ -276,7 +272,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 @@ -1,28 +1,10 @@ -Might do's for next RELEASE: -- dir : public vector<string> -- Remove modl from yhttpd base (keep only in yChat base). -- Disable /help command for commands wich are not accessible for the - specific user. +To do for next RELEASE: - Flood protection -- Add /nick, /beam, /su -- Improve /ko, /msg, so they can used on several users at once with /ko (user1,user2) -- Improve /ko, so that there can be a reason specified as well. -- Add / to whisper to the last person to whom the user has been whispered the last time. -- Room maxuser limit. - -Known Bugs: -- Not found sites should get a 404 error site! - -To do in general for some later RELEASE: -- 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. -- Make the thread pool size dynamic - Make CLI accessible through a chat command /cli -- 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! -- Add scroll pause button to input.html +- Fixing logging bug (do not log any timestamps if there are no messages) +- Remove sess.cpp, use sman.cpp only. + +To do in general: - 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 @@ -32,10 +14,15 @@ To do in general for some later RELEASE: - Improve some HTTPD-Stuff - Add traffic stats - 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 @@ -44,10 +31,11 @@ To do in general for some later RELEASE: - 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 -- Add own tiny ncursed XML editor @@ -70,9 +70,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 391cf6b..66ad66a 100644 --- a/etc/ychat.conf +++ b/etc/ychat.conf @@ -1,13 +1,9 @@ -<?xml version="5.0" encoding="ISO-8859-1" standalone="yes" ?> +<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?> <category name="chat"> <option name="defaultop"> <value>Snoop</value> <descr>The default user which has operator status</descr> </option> - <option name="enableguest"> - <value>true</value> - <descr>Is set to true if guest chatters are allowed. If database support is disabled this option HAS to be enabled otherwise no login will work because all chatter are treated as guests if there is no database!</descr> - </option> <option name="defaultrang"> <value>3</value> <descr>The default user rang/status</descr> @@ -40,9 +36,6 @@ <option name="version"> <value>3</value> </option> - <option name="compopt"> - <value>3</value> - </option> <option name="s"> <value>3</value> </option> @@ -61,9 +54,6 @@ <option name="getroom"> <value>3</value> </option> - <option name="morph"> - <value>3</value> - </option> <option name="away"> <value>3</value> </option> @@ -94,7 +84,7 @@ <descr>Seconds of idling after a database connection will be closed. Will be checked once each minute</descr> </option> <option name="serverhost"> - <value>localhost</value> + <value>fibonacci.exa-ds.com</value> <descr>Specifies hostname oder ip address of the MySQL database server</descr> </option> <option name="user"> @@ -102,7 +92,7 @@ <descr>Specifies the MySQL username</descr> </option> <option name="password"> - <value>hahaha</value> + <value>yctest</value> <descr>Specifies the MySQL password</descr> </option> <option name="dbname"> @@ -134,7 +124,7 @@ </category> <category name="maxlength"> <option name="word"> - <value>50</value> + <value>15</value> <descr>Maximum length of a word inside a chat message. The word will be seperate by a blank if exceeded</descr> </option> <option name="message"> @@ -169,11 +159,8 @@ </option> </category> <category name="msgs"> - <option name="system"> - <value>Global system message: </value> - </option> <option name="servertime"> - <value>The server system time: </value> + <value>The server system time:</value> </option> <option name="guest"> <value>This person is a guest chatter!</value> @@ -184,9 +171,6 @@ <option name="userrenamesroom"> <value> renames the room into </value> </option> - <option name="usermorphs"> - <value> morphs his name into </value> - </option> <option name="optionschanged"> <value>Your options have been changed!<br><br></value> </option> @@ -215,25 +199,25 @@ <value> sets command status</value> </option> <option name="setmodeaway"> - <value> sets mode away</value> + <value> sets mode away: </value> </option> <option name="setmodefake"> <value>Fake modus acticated!</value> </option> <option name="setmodeinvisible"> - <value>Invisible modus activated!</value> + <value>Invisible modus deactivated!</value> </option> <option name="topic"> <value> changes the topic to:</value> </option> <option name="topiccut"> - <value>The topic you have choosen was too long and has been cut!</value> + <value>The topic you|ve choosen was too long and has been cut!</value> </option> <option name="topicdelete"> <value> deletes the topic of the room.</value> </option> <option name="unsetmodeaway"> - <value> is back </value> + <value> is back</value> </option> <option name="unsetmodefake"> <value>Fake modus deactivated!</value> @@ -242,7 +226,7 @@ <value>Invisible modus deactivated!</value> </option> <option name="uptime"> - <value>yChat uptime: </value> + <value>yChat uptime:</value> </option> <option name="userautoawaytimeout"> <value> has been set to away (auto away)</value> @@ -278,9 +262,6 @@ <value>Whispered to </value> </option> <category name="help"> - <option name="all"> - <value>Writes a global system message into all available rooms. Usage: /all MESSAGE</value> - </option> <option name="away"> <value>Sets mode away. Usage: /away AWAYTEST</value> </option> @@ -296,9 +277,6 @@ <option name="getrusage"> <value>Shows informations describing the resources utilized by the yChat process. Usage: /getrusage</value> </option> - <option name="about"> - <value>Gets some usefull and interesting infos about NICK. Usage: /about NICK</value> - </option> <option name="help"> <value>Shows help text for a specific command. Usage: /help chatcommand</value> </option> @@ -314,9 +292,6 @@ <option name="m"> <value>Writes the text italic (two colors). Usage: /m ACTION</value> </option> - <option name="morph"> - <value>Morphes your current nick into MORPHNICK. This command is used to change the upper and lower case letters of your current nick. Usage: /morph MORPHNICK</value> - </option> <option name="md5"> <value>MD5 hashes SOME STRINGS with SALT. Usage: /md5 SOME STRINGS SALT</value> </option> @@ -329,9 +304,6 @@ <option name="version"> <value>Shows the version of the running yChat server. Usage: /version</value> </option> - <option name="compopt"> - <value>Shows some options of the compiler being used to build this yChat version. It also shows the current systen architecture and operating system as well as the yChat build number. Usage: /compopt</value> - </option> <option name="q"> <value>Leaving the chat. Usage: /q</value> </option> @@ -385,18 +357,12 @@ <option name="messagelength"> <value>Your message was too long and has been shortened!</value> </option> - <option name="morphnick"> - <value>Your morph nick needs to be the same like your current nick, only up- and lowercase letters are allowed to differ!</value> - </option> <option name="nicklength"> <value>Your nick is too long!<br><br></value> </option> <option name="nonick"> <value>You need to specify a nickname!<br><br></value> </option> - <option name="noguest"> - <value>Guest chatting is currently disabled. Please use a registered nick!</value> - </option> <option name="noroom"> <value>You have to enter a valid room name!<br><br></value> </option> @@ -425,7 +391,7 @@ <value>Your room name too long!<br><br></value> </option> <option name="wrongcommandusage"> - <value>Wrong command usage. Please read the help site or type /help commandname!</value> + <value>Wrong command usage. Please read the help site!</value> </option> <option name="wrongpassword"> <value>The nickname you have selected already exists in the user database and you have entered a wrong password!<br><br></value> @@ -481,10 +447,6 @@ <value>FF0000</value> <descr>Specifies the standard error message color</descr> </option> - <option name="sysmsgcolor"> - <value>FF0000</value> - <descr>Specifies the standard system message color</descr> - </option> <option name="onlinebefore"> <value><tr><td></value> <descr>HTML-Tags which will be placed before each nickname in the user online frame</descr> @@ -554,7 +516,7 @@ <descr>Specifies the relative or absolute path to the directory of the room log files</descr> </option> <option name="roomloglines"> - <value>20</value> + <value>10</value> <descr>Number of room log lines which will be buffered in the main memory until they will be written into the file</descr> </option> </category> @@ -583,16 +545,12 @@ </option> </category> <category name="thread"> - <option name="initpoolsize"> - <value>1</value> - <descr>Initial number of threads running at the same time. If all threads are used, the pool will double its size. Lowest value is 1.</descr> - </option> - <option name="maxpoolsize"> - <value>0</value> - <descr>Maximum amount of parallel running threads. Change this to 0 if you want to use unlimited threads.</descr> + <option name="poolsize"> + <value>50</value> + <descr>Number of threads running at the same time</descr> </option> <option name="queuesize"> - <value>50</value> + <value>10</value> <descr>Max. number of jobs which can wait for a free thread of the thread pool</descr> </option> </category> @@ -666,9 +624,6 @@ <option name="png"> <value>image/png</value> </option> - <option name="txt"> - <value>text/plain</value> - </option> <option name="default"> <value>text/html</value> </option> 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 @@ </title> <link rel=stylesheet href="style.css" type=text/css> </head> -<body> +<body bgcolor=#000000 text=#ffff00> <table align=center width=500> <tr><td> Hello %%nick%%, all chat configuration options available are summarized below. @@ -26,7 +26,7 @@ <br><br> <center> <span class="signature"> - yChat is OpenSource - get it at <a class="fancy" target="_blank" href="http://www.yChat.org">http://www.yChat.org</a> + yChat is OpenSource - get it at <a target="_blank" href="http://www.yChat.org">http://www.yChat.org</a> </span> </center> </body> 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 @@ } //--> </script> -<body> +<body bgcolor=#000000 text=#ffff00> <center> %%msgs%% <form name="colors" action="colors.html" onsubmit="return doonsubmit();"> @@ -39,7 +39,7 @@ <br> (color of your nickname): <br> - <input class="text" name="col1" size="6" maxlength="6" value="%%col1%%"> + <input name="col1" size="6" maxlength="6" value="%%col1%%"> </div> </td> <td width=20> @@ -51,7 +51,7 @@ <br> (color of your text messages): <br> - <input class="text" name="col2" size="6" maxlength="6" value="%%col2%%"> + <input name="col2" size="6" maxlength="6" value="%%col2%%"> </div> </td> </tr> @@ -407,7 +407,7 @@ <br> <center> <span class="signature"> - yChat is OpenSource - get it at <a class="fancy" target="_blank" href="http://www.yChat.org">http://www.yChat.org</a> + yChat is OpenSource - get it at <a target="_blank" href="http://www.yChat.org">http://www.yChat.org</a> </span> </center> <br> 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 @@ </title> <link rel=stylesheet href="style.css" type=text/css> </head> -<body> +<body bgcolor=#000000 text=#ffff00> <table align=center width=500> <tr> <td align=center class=header>%%ychat.version%%<br><br>%%INFO%%</td> @@ -22,6 +22,6 @@ This is the demo website provided by yChat :-) </tr> </table> <br><br> -<center><span class="signature">yChat is OpenSource - get it at <a class="fancy" target="_blank" href="http://www.yChat.org">http://www.yChat.org</a></span></center> +<center><span class="signature">yChat is OpenSource - get it at <a target="_blank" href="http://www.yChat.org">http://www.yChat.org</a></span></center> </body> </html> 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%% </title> </head> - <frameset boders="0" rows="*,70"> + <frameset rows="*,70"> <noframes> Your browser does not support frames, </noframes> diff --git a/html/help.html b/html/help.html index 57ae511..29ac849 100755 --- a/html/help.html +++ b/html/help.html @@ -7,7 +7,7 @@ </title> <link rel=stylesheet href="style.css" type=text/css> </head> -<body> +<body bgcolor=#000000 text=#ffff00> <table align=center width=500> <tr><td> Hello %%nick%%, all chat commands available are summarized below (Please notice that only currently @@ -21,7 +21,7 @@ <br><br> <center> <span class="signature"> - yChat is OpenSource - get it at <a class="fancy" target="_blank" href="http://www.yChat.org">http://www.yChat.org</a> + yChat is OpenSource - get it at <a target="_blank" href="http://www.yChat.org">http://www.yChat.org</a> </span> </center> </body> diff --git a/html/images/y_black.png b/html/images/y_black.png Binary files differnew file mode 100755 index 0000000..49d2645 --- /dev/null +++ b/html/images/y_black.png 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 @@ </title> <link rel=stylesheet href="style.css" type=text/css> </head> -<body> +<body bgcolor=#000000 text=#ffff00> <table align=center width=500> <tr> -<td> -<center> -%%ychat.version%%<br><br>%%INFO%% -</center> -</td> +<td align=center><img src="images/y_black.png" alt="yChat"></td> +<td align=center class=header>%%ychat.version%%<br><br>%%INFO%%</td> </tr> <tr> <td colspan=2> </td> @@ -24,22 +21,22 @@ <form action="frameset.html" method="POST"> <input type="hidden" name="event" value="login"> Enter your nick:<br> - <input class="text" type="text" name="nick" value="%%nick%%" maxlength="%%chat.maxlength.username%%" accesskey="n"> + <input type="text" name="nick" value="%%nick%%" maxlength="%%chat.maxlength.username%%" accesskey="n"> <br> <br> Enter your password:<br> - <input class="text" type="password" name="password" value="%%pass%%" maxlength="%%chat.maxlength.password%%" accesskey="p"> + <input type="password" name="password" value="%%pass%%" maxlength="%%chat.maxlength.password%%" accesskey="p"> <br> <br> Enter your room:<br> - <input class="text" type="text" name="room" value="%%chat.defaultroom%%" maxlength="%%chat.maxlength.roomname%%" accesskey="r"> + <input type="text" name="room" value="%%chat.defaultroom%%" maxlength="%%chat.maxlength.roomname%%" accesskey="r"> <br> <br> <input type="hidden" name="end" value="end"> <input type="submit" value="login" accesskey="s"> </form> <br> -<a class="fancy" href="register.html">Register</a> a new nick +<a href="register.html">Register</a> a new nick <br> <br> If you don't want to register you may login @@ -49,6 +46,6 @@ without a password using an unregistered nick. </tr> </table> <br><br> -<center><span class="signature">yChat is OpenSource - get it at <a class="fancy" target="_blank" href="http://www.yChat.org">http://www.yChat.org</a></span></center> +<center><span class="signature">yChat is OpenSource - get it at <a target="_blank" href="http://www.yChat.org">http://www.yChat.org</a></span></center> </body> </html> diff --git a/html/input.html b/html/input.html index 93e04d2..b5e4cd2 100755 --- a/html/input.html +++ b/html/input.html @@ -10,7 +10,6 @@ <!-- function delout() { - document.input.message.value = document.input.message.value.replace(/&/g, '\\AND'); document.input.submit(); document.input.message.value = ""; document.input.message.focus(); @@ -26,34 +25,36 @@ var top = (screen.availHeight-height)/2; var win = window.open(site,"_blank","width="+width+",height="+height+",left="+left+",top="+top+",scrollbars=yes"); } - function chgscroll(f) - { - if(f.checked) - parent.stream.autoscroll(); - else - parent.stream.stopscroll(); - } //--> </script> </head> - <body> + <body bgcolor=#000000 text=#ffffff> + <table> + <tr><td> <form method="GET" name="input" action="input.html" target="blank" onsubmit="return delout();"> - <div style="position: absolute; top: 5px;"> - <input class="text" type="text" name="message" size="60" maxlength="%%chat.maxlength.message%%"> - <input type="submit" value="Send" accesskey='s'> - <input type="button" value="Select" accesskey='e' onclick="javascript:selectinput();"> - </div> - <div style="position: absolute; top: 29px;"> - <a href='#' class="fancy" onclick="javascript:popup('colors.html?event=colors&tmpid=%%tmpid%%', 600, 480)">Colors</a> - <a href='#' class="fancy" onclick="javascript:popup('options.html?event=options&tmpid=%%tmpid%%', 600, 480)">Options</a> - <a href='#' class="fancy" onclick="javascript:popup('help.html?event=help&tmpid=%%tmpid%%', 600, 480)">Help</a> - <a href='#' class="fancy" onclick="javascript:popup('admin.html?event=admin&tmpid=%%tmpid%%', 600, 480)">Admin</a> - <a href='input.html?event=input&tmpid=%%tmpid%%&message=%2Fq' class="fancy" target='blank'>Logout</a> - Scrolling: - <input type="checkbox" name="scroll" checked onClick="chgscroll(this);"> - </div> <input type="hidden" name="event" value="input"> <input type="hidden" name="tmpid" value="%%tmpid%%"> + <input type="text" name="message" size="60" maxlength="%%chat.maxlength.message%%"> + <input type="submit" value="send" accesskey='s'> + <input type="button" value="select" accesskey='e' onclick="javascript:selectinput();"> </form> + </td> + <td valign=top> + <a href='#' onclick="javascript:popup('colors.html?event=colors&tmpid=%%tmpid%%', 600, 480)">Colors</a> + </td> + <td valign=top> + <a href='#' onclick="javascript:popup('options.html?event=options&tmpid=%%tmpid%%', 600, 480)">Options</a> + </td> + <td valign=top> + <a href='#' onclick="javascript:popup('help.html?event=help&tmpid=%%tmpid%%', 600, 480)">Help</a> + </td> + <td valign=top> + <a href='#' onclick="javascript:popup('admin.html?event=admin&tmpid=%%tmpid%%', 600, 480)">Admin</a> + </td> + <td valign=top> + <a href='input.html?event=input&tmpid=%%tmpid%%&message=%2Fq' target='blank'>Logout</a> + </td> + </tr> + </table> </body> </html> diff --git a/html/online.html b/html/online.html index fc1fd84..29b606d 100755 --- a/html/online.html +++ b/html/online.html @@ -4,7 +4,7 @@ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="refresh" content="20"> <link rel=stylesheet href="style.css" type=text/css> - <body> + <body bgcolor=#000000 text=#ffffff> <b>%%ROOMNAME%%</b> <br> <br> 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%% </title> <link rel=stylesheet href="style.css" type=text/css> -<body> +<body bgcolor=#000000 text=#ffff00> <table align=center width=500> <tr><td> %%msgs%% @@ -16,19 +16,19 @@ <br> <form name="options" action="options.html"> Your E-Mail address:<br> - <input class="text" type="text" size="40" maxlength="%%chat.maxlength.emailaddress%%" name="email" value="%%email%%" accesskey="e"> + <input type="text" size="40" maxlength="%%chat.maxlength.emailaddress%%" name="email" value="%%email%%" accesskey="e"> <br> <br> Your old password (needed if you want to enter a new password):<br> - <input class="text" type="password" maxlength="%%chat.maxlength.password%%" name="pass" accesskey="p"> + <input type="password" maxlength="%%chat.maxlength.password%%" name="pass" accesskey="p"> <br> <br> Your new password:<br> - <input class="text" type="password" maxlength="%%chat.maxlength.password%%" name="newpass" accesskey="q"> + <input type="password" maxlength="%%chat.maxlength.password%%" name="newpass" accesskey="q"> <br> <br> Your new password again:<br> - <input class="text" type="password" maxlength="%%chat.maxlength.password%%" name="newpass2" accesskey="r"> + <input type="password" maxlength="%%chat.maxlength.password%%" name="newpass2" accesskey="r"> <br> <br> <input type="hidden" name="event" value="options"> @@ -41,7 +41,7 @@ Your new password again:<br> <br><br> <center> <span class="signature"> - yChat is OpenSource - get it at <a class="fancy" target="_blank" href="http://www.yChat.org">http://www.yChat.org</a> + yChat is OpenSource - get it at <a target="_blank" href="http://www.yChat.org">http://www.yChat.org</a> </span> </center> <br> 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 @@ </title> <link rel=stylesheet href="style.css" type=text/css> </head> -<body> +<body bgcolor=#000000 text=#ffff00> <table align=center width=500> <tr> -<td> -<center> -Nick registration<br><br>%%INFO%% -</center> -</td> +<td align=center><img src="images/y_black.png" alt="yChat"></td> +<td align=center class=header>Nick registration<br><br>%%INFO%%</td> </tr> <tr> <td colspan=2> </td> @@ -24,30 +21,30 @@ Nick registration<br><br>%%INFO%% <form action="register.html" method="POST"> <input type="hidden" value="register" name="event"> Enter your desired nick:<br> - <input class="text" type="text" maxlength="%%chat.maxlength.username%%" name="nick" value="%%nick%%" accesskey="n"> + <input type="text" maxlength="%%chat.maxlength.username%%" name="nick" value="%%nick%%" accesskey="n"> <br> <br> Enter your E-Mail address:<br> - <input class="text" type="text" maxlength="%%chat.maxlength.emailaddress%%" name="email" value="%%email%%" accesskey="e"> + <input type="text" maxlength="%%chat.maxlength.emailaddress%%" name="email" value="%%email%%" accesskey="e"> <br> <br> Enter your password:<br> - <input class="text" type="password" maxlength="%%chat.maxlength.password%%" name="pass" accesskey="p"> + <input type="password" maxlength="%%chat.maxlength.password%%" name="pass" accesskey="p"> <br> <br> Enter your password again:<br> - <input class="text" type="password" maxlength="%%chat.maxlength.password%%" name="pass2" accesskey="q"> + <input type="password" maxlength="%%chat.maxlength.password%%" name="pass2" accesskey="q"> <br> <br> <input type="hidden" name="end" value="end"> <input type="submit" value="Register" accesskey="s"> </form> <br> -If you don't want to register go <a class="fancy" href="%%httpd.startsite%%">back</a> +If you don't want to register go <a href="%%httpd.startsite%%">back</a> </td> </tr> </table> <br><br> -<center><span class="signature">yChat is OpenSource - get it at <a class="fancy" target="_blank" href="http://www.yChat.org">http://www.yChat.org</a></span></center> +<center><span class="signature">yChat is OpenSource - get it at <a target="_blank" href="http://www.yChat.org">http://www.yChat.org</a></span></center> </body> </html> 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 @@ <link rel=stylesheet href="style.css" type=text/css> <script language="JavaScript"> var scrolling; - var ison; - function autoscroll() + var isOn; + function autoScroll() { - if(!ison){ + if(!isOn) + { scrolling = window.setInterval("window.scroll(1,1606682)",70); - ison = true; + isOn = true; } } - function stopscroll() + + function stopScroll() { - if(ison) + if(isOn) { - window.clearInterval(scrolling); - ison = false; + window.clearInterval(scrolling); + isOn=false; } } </script> </head> -<body class="stream"> -<script language="JavaScript"> - autoscroll(); +<body bgcolor=#000000 text=#ffffff> +<script> +autoScroll(); </script> 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/mergeconf.pl b/scripts/mergeconf.pl new file mode 100755 index 0000000..85e76cb --- /dev/null +++ b/scripts/mergeconf.pl @@ -0,0 +1,104 @@ +#!/usr/bin/perl + +# The yChat Project (2003) +# +# This script merges configuration files + +use strict; + +use scripts::modules::file; + +my @files = ('conf.txt','lang/en.txt','lang/de.txt'); + +foreach my $filename ( @files ) +{ + next if ( ! -f $filename || ! -f "$filename.old" ); + + print "=> Merge $filename\n"; + my @newoptions = &merge("$filename.old",$filename ); + if (defined $newoptions[0]) + { + print " => Modified $filename. Edit to set the new values [or leave standard]\n => New options are:"; + foreach (@newoptions) + { + print " $_"; + } + print "\n"; + } +} + +sub merge +{ + my ($oldfile,$newfile) = @_; + my @oldfile = fopen($oldfile); + my @newfile = fopen($newfile); + my %oldfile = get_options(@oldfile); + my %newfile = get_options(@newfile); + my @newoptions; + + foreach my $option (keys %newfile) + { + unless (defined $oldfile{$option}) + { + push @newoptions, $option; + my $_comment = $newfile{$option}[0]; + my $_value = $newfile{$option}[1]; + my $_comment_b = $newfile{$option}[2]; + my $_behind = $newfile{$option}[3]; + print " => Adding to $newfile\n => New option is $option\n" + ." => Adding it after option $_behind\n"; + + my $added = 0; + my $insert = $_comment . "$option=\"$_value\";$_comment_b\n"; + foreach (@oldfile) + { + if (/^$_behind.+$/) + { + $_ .= $insert; + $added = 1; + last; + } + } + if ( $added == 0 ) + { + print " => Adding new option at EOF\n"; + push @oldfile, $insert; + } + } + } + + &fwrite($newfile,@oldfile); + + return @newoptions; +} + +sub get_options +{ + my @file = @_; + my %options; + my $option_comment; + my $option_before = ''; + + foreach (@file) + { + if (/(^.+)="(.+)";(.*)/) + { + my $option = $1; + my $option_value = $2; + my $option_comment_behind = $3; + my @values = ($option_comment, + $option_value, + $option_comment_behind, + $option_before); + $options{$option} = \@values; + $option_comment = ''; + $option_before = $option; + } + else + { + $option_comment .= $_; + } + } + + return %options; +} 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<string,string> *p_map_string ) + void get_data( map_string *p_map_string ) { smap<type*,string>::run_func( &base<type>::get_data_ , (void*)p_map_string ); } static void get_data_( type* type_obj, void* v_arg ) { - type_obj -> get_data ( (map<string,string>*) v_arg ); + type_obj -> get_data ( (map_string*) v_arg ); } diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp index 493c2a5..86bc140 100755 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -65,15 +65,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<string,string> &map_params ) +chat::login( map_string &map_params ) { string s_user = map_params["nick"]; @@ -156,8 +154,8 @@ chat::login( map<string,string> &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 +165,9 @@ chat::login( map<string,string> &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<string,string> 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 +192,15 @@ chat::login( map<string,string> &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 +257,7 @@ chat::login( map<string,string> &map_params ) } void -chat::post( user* p_user, map<string,string> &map_params ) +chat::post( user* p_user, map_string &map_params ) { p_user->renew_timeout(); @@ -310,11 +300,18 @@ chat::post( user* p_user, map<string,string> &map_params ) 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<string>::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 +335,4 @@ chat::reconf() { } -void -chat::string_replacer(string *p_msg) { - if ( wrap::CONF->get_elem( "chat.html.replace.activate" ) == "true" ) - { - for (vector<string>::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<room>, public perm { private: - map<string,string> map_replace_strings; + map_string map_replace_strings; vector<string> 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<string,string> &map_params ); + void login( map_string &map_params ); // will be called if a user posts a message. - void post ( user* u_user, map<string,string> &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<user*>::delete_obj ); -#ifdef LOGGING delete p_logd; -#endif pthread_mutex_destroy( &mut_s_topic ); pthread_mutex_destroy( &mut_s_name ); @@ -42,24 +38,15 @@ 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 + "<br><br>"; + 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( "<font color=\"#" + s_color + "\">" + s_topic + "</font>"); -} - -void room::clean_room() { pthread_mutex_lock ( &mut_s_topic ); @@ -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<user>, 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<user>::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 <map> #include <string> -#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<sess*,string> { 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 a73a909..40dbee8 100755 --- a/src/chat/user.cpp +++ b/src/chat/user.cpp @@ -97,7 +97,7 @@ user::get_colored_name() } void -user::get_data( map<string,string> *p_map_data ) +user::get_data( map_string *p_map_data ) { string s_req = (*p_map_data)["!get"]; @@ -490,8 +490,6 @@ user::check_timeout( int* i_idle_timeout ) + "';</script>"; msg_post( &s_quit ); set_online( false ); - - pthread_cond_signal( &cond_message ); } else if ( ! get_away() && i_idle_timeout[2] <= i_user_timeout ) 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<string,string> 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<string,string>)["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<string,string> *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..2b110db 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,7 +29,6 @@ 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 @@ -40,11 +37,9 @@ cli::parse_input( string s_input ) #ifdef NCURSES cout << CLIPRMO << " (ex)it - 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 << " (h)elp - Prints out this help!" << endl + << CLIPRMO << " (m)ysql - Runs MySQL client on yChat DB" << 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<string>* p_vec = wrap::CONF->get_key_vector(); sort(p_vec->begin(), p_vec->end()); vector<string>::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 ) { 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 <iostream> #include <vector> -#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<string,string>* p_start_params ) : nmap<string,st string s_config; - for ( int i = 0; i < 4; ++i ) + for ( int i = 0; i<4; i++ ) { cout << "Checking for " << s_check[i]; ifstream if_check( s_check[i].c_str() ); @@ -77,14 +79,14 @@ conf::parse_xml(TiXmlNode* p_node, vector<string>* 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 "<font color=\"#" - + nmap<string,string>::get_elem("chat.html.errorcolor") - + "\">" + nmap<string,string>::get_elem(s_key) + "</font><br>\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<string>* p_vec); - public: - conf(string s_conf, map<string,string>* p_start_params); + //conf ( string s_conf ); + conf ( string s_conf, map<string,string>* p_start_params ); ~conf(); - - string colored_error_msg( string s_key ); //<< }; #endif diff --git a/src/conf/lang.cpp b/src/conf/lang.cpp new file mode 100755 index 0000000..04dd13b --- /dev/null +++ b/src/conf/lang.cpp @@ -0,0 +1,67 @@ +#ifndef LANG_CPP +#define LANG_CPP + +#include <fstream> +#include "lang.h" + +using namespace std; + +lang::lang( string s_lang = "en" ) : nmap<string,string>::nmap(HMAPOCC), name::name( s_lang ) +{ + parse( ); // parse the config file. +} + +lang::~lang() +{} + +void +lang::parse() +{ + // wrap::system_message( CFILEOK + get_name() ); + + string filename(wrap::CONF->get_elem("LANGUAGE_DIR")); + filename.append(get_name()+".txt"); + + ifstream fs_conf( filename.c_str() ); + + if ( ! fs_conf ) + { + // wrap::system_message( CFILEOFF + get_name() ); + return; + } + + char c_buf[READBUF]; + + while( fs_conf.getline( c_buf, READBUF ) ) + { + string s_token( c_buf ); + unsigned int ui_pos = s_token.find( "#", 0 ); + + // if line is commented out: + if ( ui_pos == 0 ) + continue; + + ui_pos = s_token.find( ";", 0 ); + + // if token has not been found. + if ( ui_pos == string::npos ) + continue; + + s_token = s_token.substr( 0 , --ui_pos ); + ui_pos = s_token.find ( "\"", 0 ); + + if ( ui_pos == string::npos ) + continue; + + string s_val = s_token.substr( ui_pos+1, s_token.length() ); + string s_key = s_token.substr( 0 , --ui_pos ); + + // fill the map. + nmap<string,string>::add_elem(s_val, s_key ); + } + + fs_conf.close(); + fs_conf.~ifstream(); +} + +#endif diff --git a/src/conf/lang.h b/src/conf/lang.h new file mode 100755 index 0000000..6230e2f --- /dev/null +++ b/src/conf/lang.h @@ -0,0 +1,23 @@ +#include "../incl.h" + +#ifndef LANG_H +#define LANG_H + +#include "../name.h" +#include "../maps/nmap.h" + +using namespace std; + +class lang : public nmap<string,string>, name +{ +private: + +public: + // public methods: + lang ( string s_lang ); // standard constructor. + ~lang(); // standard destructor. + + virtual void parse( ); // parses the config file. +}; + +#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 (<Fin>) { 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 <mysql/mysql.h> +#include <mysql/mysql.h> #include <iostream> #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<string,string> +map_string data::select_user_data( string s_user, string s_query) { - string s_where_rule = " WHERE nick = \"" + s_user + "\""; - vector<string> 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<string> 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<string>& vec_elements ) { - con* p_con = get_con(); + con* p_con = get_con(); - vec_elements = map_queries[s_query]; - string s_mysql_query = "SELECT "; - vector<string>::iterator iter = vec_elements.begin(); + vec_elements = map_queries[s_query]; + string s_mysql_query = "SELECT "; + vector<string>::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<string,string> +map_string data::parse_result( MYSQL_RES* p_result, vector<string>& vec_elements ) { - map<string,string> map_ret; - if ( p_result != NULL ) - { - MYSQL_ROW row; - vector<string>::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<string>::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<string,string> 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<string,string> map_insert ) +data::insert_query( string s_query, map_string map_insert ) { - vector<string> vec_elements = map_queries[s_query]; - vector<string>::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<string> vec_elements = map_queries[s_query]; + vector<string>::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<string,string> update_map ) +void +data::update_user_data( string s_user, string s_query, map_string update_map ) { - vector<string> vec_elements = map_queries[s_query]; + vector<string> vec_elements = map_queries[s_query]; - if ( vec_elements.size() == 0 ) - return; + if ( vec_elements.size() == 0 ) + return; - vector<string>::iterator iter = vec_elements.begin(); - vector<string>::iterator iter_second = vec_elements.begin(); - iter_second++; + vector<string>::iterator iter = vec_elements.begin(); + vector<string>::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<string>& vec_elements ); - map<string,string> parse_result( MYSQL_RES* p_result, vector<string>& vec_elements ); - void insert_query( string s_query, map<string,string> map_insert ); - string secure_query( string s_mysql_query ); - public: +{ +private: + MYSQL_RES* select_query( string s_query, string s_where_rule, vector<string>& vec_elements ); + map_string parse_result( MYSQL_RES* p_result, vector<string>& vec_elements ); + void insert_query( string s_query, map_string map_insert ); + string secure_query( string s_mysql_query ); +public: data( ); - ~data( ); + ~data( ); - map<string,string> select_user_data( string s_user, string s_query ); - void insert_user_data( string s_user, string s_query, map<string,string> insert_map ); - void update_user_data( string s_user, string s_query, map<string,string> 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<string> vec_keys = *wrap::CONF->get_key_vector(); - vector<string>::iterator iter; + pthread_mutex_init ( &mut_con, NULL ); + + vector<string> vec_keys = *wrap::CONF->get_key_vector(); + vector<string>::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<string> 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<string> 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<string,string> +map_string data_base::select_user_data( string s_user, string s_query) { - print_query( DATAQUE + s_query ); - map<string,string> 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<string,string> 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<string,string> 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<con*>::iterator > erase_list; - for ( list<con*>::iterator iter = begin(); + pthread_mutex_lock( &mut_con ); + + list< list<con*>::iterator > erase_list; + for ( list<con*>::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<con*>::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<con*> - { - 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<string> > map_queries; - void print_query( string s_query ); + protected: + map< string, vector<string> > 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<string,string> select_user_data( string s_user, string s_query ); - virtual void insert_user_data( string s_user, string s_query, map<string,string> insert_map ); - virtual void update_user_data( string s_user, string s_query, map<string,string> 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 @@ -5,6 +5,7 @@ gmake config in the main directory! */ + #include <map> // 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 @@ -95,11 +96,6 @@ //#define EXPERIM /* - CONFIG - - Should yChat get compiled with logging support? -*/ -#define LOGGING - -/* - CONFIG - Should yChat get compiled with ncurses support? */ #define NCURSES @@ -183,6 +179,8 @@ using namespace std; +// some custom typedefs for datatypes which are needed often. +typedef map<string, string> 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<string,string> &map_params ) +html::parse( map_string &map_params ) { string s_file = map_params["request"]; @@ -37,10 +37,10 @@ html::parse( map<string,string> &map_params ) // if not, read file. if ( ! smap<string,string>::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<string,string> &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<string,string> &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<string,string> &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<string,string> &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<string,string> &map_params ) //<<* void -html::online_list( user *p_user, map<string,string> &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 @@ -12,24 +12,27 @@ using namespace std; class html : public smap<string, string>, 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<string,string> &map_params ); + string parse( map_string &map_params ); - void online_list( user *p_user, map<string,string> &map_params ); //<< + void online_list( user *p_user, map_string &map_params ); //<< #ifdef NCURSES void print_cached( int i_docs ); #endif @@ -1,12 +1,9 @@ -#include <pthread.h> #include <iostream> +#include <pthread.h> #include <string> - #include "glob.h" - #ifdef NCURSES #include <ncurses.h> #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 <fstream> +#include "logd.h" logd::logd( string s_filename, string s_log_lines ) { @@ -77,36 +73,28 @@ logd::flush() } void -logd::log_access( map<string,string> 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 @@ -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<string> s_queue; @@ -26,12 +26,11 @@ public: ~logd(); void set_logfile( string s_path, string s_filename ); - void log_access( map<string,string> 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 <unistd.h> #include <signal.h> #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.tmpl b/src/maps/hmap.tmpl index cc2ec24..dcd0426 100644 --- a/src/maps/hmap.tmpl +++ b/src/maps/hmap.tmpl @@ -286,4 +286,8 @@ hmap<obj_type, key_type>::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 <class type_> 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<obj_type, key_type> }; #include "nmap.tmpl" + #endif + + diff --git a/src/maps/smap.h b/src/maps/smap.h index a3ee89d..2096139 100644 --- a/src/maps/smap.h +++ b/src/maps/smap.h @@ -13,6 +13,7 @@ template <class obj_type, class key_type> class smap : public hmap<obj_type, key_type> { + private: pthread_mutex_t mut_smap; @@ -52,4 +53,5 @@ class smap : public hmap<obj_type, key_type> }; #include "smap.tmpl" + #endif diff --git a/src/maps/smap.tmpl b/src/maps/smap.tmpl index 670b84d..5ec7d38 100644 --- a/src/maps/smap.tmpl +++ b/src/maps/smap.tmpl @@ -15,6 +15,7 @@ smap<obj_type, key_type>::~smap() pthread_mutex_destroy( &mut_smap ); } + template <class obj_type, class key_type> void smap<obj_type, key_type>::lock_mutex() { pthread_mutex_lock( &mut_smap ); @@ -164,6 +165,7 @@ void smap<obj_type, key_type>::make_empty_insecure( void (*func)(key_type) ) hmap<obj_type,key_type>::make_empty( func ); } + template <class obj_type, class key_type> void smap<obj_type, key_type>::add_elem_insecure( const obj_type &x, const key_type &k ) { @@ -212,4 +214,6 @@ smap<obj_type, key_type>::get_key_vector_insecure() return hmap<obj_type,key_type>::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 <limits.h> @@ -11,12 +12,12 @@ using namespace std; -modl::modl() : smap<dynmod*,string>(HMAPOCC) +modl::modl( ) : smap<dynmod*,string>(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 ) @@ -11,7 +11,7 @@ class modl : private smap<dynmod*,string> { 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") + "<font color=" + p_user->get_col2() + ">"; - 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( "</font><br>\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..85ac21a 100755 --- a/src/mods/commands/yc_fake.cpp +++ b/src/mods/commands/yc_fake.cpp @@ -22,8 +22,6 @@ extern "C" { 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 new file mode 100644 index 0000000..ee4f922 --- /dev/null +++ b/src/mods/commands/yc_getstatus.cpp @@ -0,0 +1,57 @@ +#include "../../incl.h" + +/* + gcc -shared -o yc_name.so yc_name.cpp +*/ + +using namespace std; + +extern "C" { + int extern_function(void *v_arg) + { + + container *c=(container *)v_arg; + + user *p_user = (user*) c->elem[1]; // the corresponding user + vector<string> *params = (vector<string>*) 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; + + if ( ! params->empty() ) + { + vector<string>::iterator iter = params->begin(); + string s_searched_user( *iter ); + bool b_found; + user* p_searched_user = p_chat->get_user( s_searched_user, b_found ); + + if ( b_found ) + { + string s_msg = "<b>" + p_searched_user->get_colored_name() + "</b>" + + p_conf->get_elem("chat.msgs.userhasstatus") + "<b>" + + tool::int2string(p_searched_user->get_status()) + + "</b>, " + + p_conf->get_elem("chat.msgs.userinroom") + "<b>" + + p_searched_user->get_room()->get_name() + + "</b><br>\n" + + p_conf->get_elem("chat.msgs.lastactivity") + "<b>" + + tool::int2string((int)( p_searched_user->get_last_activity())) + + "</b><br>\n"; + p_user->msg_post( &s_msg ); + } + + else + { + string s_msg = "<font color=\"#" + + p_conf->get_elem("chat.html.errorcolor") + + "\"><b>" + + s_searched_user + "</b> " + + p_conf->get_elem("chat.msgs.err.notavailable") + + "</font><br>\n"; + p_user->msg_post( &s_msg ); + + } + } + } + +} + 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" { + "</font><br>\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") + "<br>\n" - : p_conf->get_elem("chat.msgs.unsetmodeinvisible") + : p_conf->get_elem("chat.msgs.unsetmodeaway") + "<br>\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() + "<br>\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( "</font></i><br>\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( "</font></i><br>\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<string> *params = (vector<string>*) 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 + "<i> " + p_conf->get_elem("chat.msgs.whisperto") + " " + p_whisper_user->get_colored_name() + ": <font color=\"#" + p_user->get_col2() + "\">"; + string s_msg = "<i> " + + p_conf->get_elem("chat.msgs.whisperto") + + " " + + p_whisper_user->get_colored_name() + + ": <font color=\"#" + + p_user->get_col2() + + "\">"; - string s_whisper_msg = s_time + "<i>" + p_user->get_colored_name() + " " + p_conf->get_elem("chat.msgs.whisper") + ": <font color=\"#" + p_user->get_col2() + "\">"; + string s_whisper_msg = "<i>" + + p_user->get_colored_name() + + " " + + p_conf->get_elem("chat.msgs.whisper") + + ": <font color=\"#" + + p_user->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 + "</font></i><br>\n" ); - s_whisper_msg.append( s_tmp + "</font></i><br>\n" ); + s_msg .append( "</font></i><br>\n" ); + s_whisper_msg.append( "</font></i><br>\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<string> *params= (vector<string>*) 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 + "<i>" + p_user->get_colored_name() + " " + p_conf->get_elem("chat.msgs.scream") + " <font color=\"#" + p_user->get_col2() + "\"><b>"; + string s_msg = "<i>" + p_user->get_colored_name() + " " + + p_conf->get_elem("chat.msgs.scream") + + " <font color=\"#" + p_user->get_col2() + + "\"><b>"; if ( ! params->empty() ) { vector<string>::iterator iter = params->begin(); @@ -40,8 +37,6 @@ extern "C" { s_msg.append( "</b></font></i><br>\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" { + "</font><br>\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<br>"); 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() + "<br>\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 0fd01e9..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<string>::iterator iter; - s_col = "<font color=\"" + p_user->get_col1() + "\">"; + s_col = "<font color=" + p_user->get_col2() + ">"; s_msg = p_timr->get_time() + " " @@ -53,8 +51,7 @@ 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 + "</font>)<br><br>"; } else @@ -64,15 +61,14 @@ extern "C" { + p_user->get_colored_name() + " " + p_conf->get_elem("chat.msgs.topicdelete"); - - p_room->set_topic( "" ); } s_msg.append( "<script confuage='JavaScript'>parent.online.location.reload();</script><br>\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() + "<br>\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() + "<br>\n"); - - return 0; + p_user->msg_post( tool::ychat_version() + " " + UNAME + "<br>\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<string,string>*) c->elem[1]))["content"]; + string* p_content = &(*((map_string*) c->elem[1]))["content"]; vector<string>* 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( "</table>\n<br>\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<string,string>*) c->elem[1]))["col1"]; - string* p_col2 = &(*((map<string,string>*) c->elem[1]))["col2"]; - string* p_flag = &(*((map<string,string>*) 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<string,string>*) 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<string,string>*) c->elem[1]))["content"]; + string* s_content = &(*((map_string*) c->elem[1]))["content"]; vector<string>* 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<string,string>*) c->elem[1]))["flag"]; - string* p_email = &(*((map<string,string>*) c->elem[1]))["email"]; - string* p_pass = &(*((map<string,string>*) c->elem[1]))["pass"]; - string* p_newpass = &(*((map<string,string>*) c->elem[1]))["newpass"]; - string* p_newpass2 = &(*((map<string,string>*) 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<string,string>*) 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<string,string>*) c->elem[1]))["INFO"]; - string* p_nick = &(*((map<string,string>*) c->elem[1]))["nick"]; - string* p_email = &(*((map<string,string>*) c->elem[1]))["email"]; - string* p_pass = &(*((map<string,string>*) c->elem[1]))["pass"]; - string* p_pass2 = &(*((map<string,string>*) c->elem[1]))["pass2"]; - string* p_request = &(*((map<string,string>*) 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<string,string> 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<string,string> map_insert = *((map<string,string>*) 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 } } @@ -27,7 +27,7 @@ #define DATAMA0 "Data: Max database connections " #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 threads (" #define READERR "Sock: Read error " #define REMROOM "Garbage: Removing room " #define REMUSER "Garbage: Removing user " @@ -103,20 +93,9 @@ #define XMLREAD "XML: Reading " #define XMLERR "XML Error: " #define XMLER1 "XML Error: Unable to load file " -#define VERSION "0.7.4.1" +#define VERSION "yChat 0.7.1" #define BRANCH "RELEASE" -#define BUILDNR 3187 -#define UNAME "FreeBSD 5.3-RELEASE-p5 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 2885 +#define UNAME "FreeBSD 5.2.1-RELEASE-p10 i386" #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 @@ -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<i_numchoices; i++ ) { - ++y; + y++; - if( i_highlight == i+1 ) // Highlight the current selection. + if( i_highlight == i + 1 ) /* High light the present choice */ { wattron( win, A_REVERSE); mvwprintw( win, y, x, "%d. %s", i, choices[i]); wattroff( win, A_REVERSE); } - else { mvwprintw( win, y, x, "%d. %s", i, choices[i]); @@ -109,6 +107,7 @@ menu::start( void (*swich_case_menu_action)(int) ) break; } + // Menu action. ( *swich_case_menu_action ) ( i_choice ); i_choice = 0; diff --git a/src/ncur/menu.h b/src/ncur/menu.h index d931be3..7e4fc5b 100755 --- a/src/ncur/menu.h +++ b/src/ncur/menu.h @@ -1,7 +1,6 @@ #include "../incl.h" #ifdef NCURSES - #ifndef MENU_H #define MENU_H @@ -28,11 +27,7 @@ public: void display(); void start( void (*swich_case_menu_action)(int) ); - - void activate_menu_win() - { - keypad(win, 1); - } + void activate_menu_win() { keypad(win, 1); } }; #endif diff --git a/src/ncur/ncur.cpp b/src/ncur/ncur.cpp index cee3d06..fa91a74 100755 --- a/src/ncur/ncur.cpp +++ b/src/ncur/ncur.cpp @@ -35,10 +35,8 @@ ncur::start( void *p_void ) ncur::init_ncurses(); char *choices[] = { - "Unload all modules ", //<< - "Reload all modules ", //<< - //>>" ", - //>>" ", + "Unload all modules ", + "Reload all modules ", "Clear template cache ", "Run garbage collector ", //<< //>>" ", @@ -64,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(); //<< @@ -120,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 ); @@ -132,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 ); @@ -143,7 +140,7 @@ ncur::print( char* c_print ) list<char*>::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 ); @@ -160,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 "); @@ -171,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 "); @@ -279,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 <ncurses.h> #include <list> @@ -19,12 +17,11 @@ private: menu* p_menu; WINDOW* p_serveroutput; list<char*>* 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..8c59c3a 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<string,string>& 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<string,string>& 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<string,string>& 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<string,string>::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<string,string> &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<string,string> &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<string,string> &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<string,string> &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<string,string> &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<string,string> &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<string,string> &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<string,string> &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<string,string> &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<string,string> &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<string,string> &map_params, user* p_user ) +reqp::run_html_mod( string s_event, map_string &map_params, user* p_user ) { container *c = new container; @@ -1,41 +1,50 @@ #include "incl.h" + #ifndef REQP_H #define REQP_H #include <map> +#include "thrd/thrd.h" using namespace std; +typedef map<string, string, less<string> > 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<string,string> &map_params ); + virtual string get_url( thrd* p_thrd, string s_req, map_string &map_params ); // returns a specific value of the client's http request header. // ( s.t. like the User-Agent, Referer etc... ). - 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<string,string> &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<string,string>& map_params ); + void get_request_parameters( string s_parameters, map_string& map_params ); public: reqp( ); - string parse( int &i_sock, string s_req, map<string,string> &map_params ); - string url_decode ( string s_url ); - string get_content_type( string s_file ); - void parse_headers( string s_req, map<string,string> &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/Makefile b/src/sock/Makefile new file mode 100644 index 0000000..f5895f1 --- /dev/null +++ b/src/sock/Makefile @@ -0,0 +1,23 @@ +#CC=gcc33 +CC=g++ +INCLUDE= +DEBUG=-D_GNU_SOURCE +#CFLAGS=-Wall -O3 -s $(DEBUG) $(INCLUDE) +#CFLAGS=-Wall -g -ansi -pedantic $(DEBUG) $(INCLUDE) +CFLAGS=-Wall -g $(DEBUG) $(INCLUDE) +LIBS=-lstdc++ + +OBJECTS=main-test.o tcp-client.o exception.o +PROGRAM=main-test + +all: $(PROGRAM) + +$(PROGRAM): $(OBJECTS) + $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LIBS) + +.cpp.o: + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f $(PROGRAM) $(OBJECTS) + diff --git a/src/sock/README b/src/sock/README new file mode 100644 index 0000000..9d3aac9 --- /dev/null +++ b/src/sock/README @@ -0,0 +1 @@ +ossl.h not yet implemented (see header info) diff --git a/src/sock/sock.cpp b/src/sock/sock.cpp index bc5eb55..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<string,string> &map_params ) +sock::chat_stream( int i_sock, user* p_user, map_string &map_params ) { string s_msg( "\n" ); @@ -45,10 +45,8 @@ sock::chat_stream( int i_sock, user *p_user, map<string,string> &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 ); - pthread_cond_wait( &(p_user->cond_message), &mutex ); } while( p_user->get_online() ); @@ -57,14 +55,12 @@ sock::chat_stream( int i_sock, user *p_user, map<string,string> &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. @@ -87,17 +83,17 @@ sock::chat_stream( int i_sock, user *p_user, map<string,string> &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 ); @@ -106,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 ); } @@ -133,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<string,string> 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 @@ -197,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 ); @@ -220,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 ) { @@ -237,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 @@ -268,23 +247,55 @@ 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() { if ( wrap::NCUR->is_ready() ) 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 <queue> #include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> - #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<string,string> &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 <stdio.h> #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> +#include <iostream> using namespace std; diff --git a/src/thrd/pool.cpp b/src/thrd/pool.cpp index efea948..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,146 +52,133 @@ 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 ); + 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( ;; ) + while( true ) { pthread_mutex_lock( &(tpool->queue_lock) ); - while ( tpool->cur_queue_size == 0) - pthread_cond_wait( &(tpool->queue_not_empty), &(tpool->queue_lock) ); + while ( (tpool->cur_queue_size == 0) && (!tpool->shutdown) ) + 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); - - pthread_mutex_lock( &(tpool->queue_lock) ); - --i_thrd_used; -#ifdef NCURSES - print_threads(i_thrd_used); -#endif - pthread_mutex_unlock( &(tpool->queue_lock) ); - - //free( (void*) my_workp ); - 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 * 2; - - 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; @@ -199,22 +188,11 @@ pool::tpool_add_work( tpool_t tpool, void(*routine)(void*), void* p_void ) /// 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() { if ( wrap::NCUR->is_ready() ) diff --git a/src/thrd/pool.h b/src/thrd/pool.h index c4dcd21..a744133 100755 --- a/src/thrd/pool.h +++ b/src/thrd/pool.h @@ -8,10 +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; @@ -21,6 +21,7 @@ private: // pool characteristics: int num_threads; int max_queue_size; + int do_not_block_when_full; // pool state pthread_t *threads; @@ -33,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; @@ -41,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/thrd.cpp b/src/thrd/thrd.cpp new file mode 100755 index 0000000..63135a8 --- /dev/null +++ b/src/thrd/thrd.cpp @@ -0,0 +1,26 @@ +#ifndef THRD_CPP +#define THRD_CPP + +#include "thrd.h" +#include <sys/socket.h> + +using namespace std; + +thrd::thrd( int i_sock ) +{ + this->i_sock = i_sock; +} + +thrd::~thrd() +{ + shutdown ( get_sock() , 2 ); + close ( get_sock() ); +} + +void +thrd::run() +{ + wrap::SOCK->read_write( this, i_sock ); +} + +#endif diff --git a/src/thrd/thrd.h b/src/thrd/thrd.h new file mode 100755 index 0000000..7cd63b7 --- /dev/null +++ b/src/thrd/thrd.h @@ -0,0 +1,28 @@ +// class thrd declaration. +#include "../incl.h" + +#ifndef THRD_H +#define THRD_H + +using namespace std; + +class thrd +{ +private: + int i_sock; + +public: + + // small inline methods: + int get_sock() + { + return i_sock; + } + + // public methods: + explicit thrd( int i_sock ); + ~thrd(); // destructor. + virtual void run(); +}; + +#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 40240c3..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<timr*>(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 = "<!-- PING! //-->\n"; wrap::CHAT->msg_post( &s_ping ); @@ -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<string> 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 <stdio.h> #include <sys/types.h> #include <dirent.h> - #include <vector> - #include "../incl.h" using namespace std; @@ -17,9 +15,9 @@ class dir { private: bool b_open; - DIR *p_d; - struct dirent *p_ep; - vector<string> vec_dir; + DIR *dp; + struct dirent *ep; + vector<string> dir_vec; public: dir(); diff --git a/src/tool/tool.cpp b/src/tool/tool.cpp index dec9bdb..e2ef9ae 100644 --- a/src/tool/tool.cpp +++ b/src/tool/tool.cpp @@ -11,95 +11,6 @@ #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<i_len; i++ ) - { - if ( ! isalnum( *p_digit ) ) - return false; - p_digit++; - } - - return true; -} - -string -tool::int2string( int i_int ) -{ - char buf[64]; - sprintf(buf, "%d", i_int); - return buf; -} - -long -tool::unixtime() -{ - time_t clock; - return (long) time( &clock ); -} - -int -tool::string2int( string s_digit ) -{ - const char *p_digit = s_digit.c_str(); - int i_res = 0; - - // Convert each digit char and add into result. - while (*p_digit >= '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<string> tool::split_string(string s_string, string s_split) { list<string> list_ret; @@ -119,27 +30,27 @@ tool::split_string(string s_string, string s_split) { 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 +60,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 +85,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<s_ext.size();i++) + s_ext[i]=tolower(s_ext[i]); return to_lower(s_ext); } - return ""; } char* tool::int2char( int i_int ) { - char *buf = new char[64]; - sprintf(buf, "%d", i_int); - return buf; + char *buffer = new char[64]; + sprintf(buffer, "%d", i_int); + return buffer; } string tool::shell_command( string s_command, method m_method ) { FILE *file; - char buf[READBUF]; - char *c_pos; + char buffer[READBUF]; + char* c_pos; string s_ret = ""; wrap::system_message(SHELLEX); @@ -216,18 +125,16 @@ tool::shell_command( string s_command, method m_method ) { while(true) { - if(fgets(buf, READBUF, file) == NULL) + if(fgets(buffer, READBUF, file) == NULL) break; - switch (m_method) { case METH_NCURSES: - wrap::system_message( clean_char(buf) ); + wrap::system_message( clean_char(buffer) ); break; default: - s_ret.append("\n" + string(buf)); + s_ret.append("\n" + string(buffer)); } // switch } - pclose(file); } diff --git a/src/tool/tool.h b/src/tool/tool.h index b296514..7352772 100644 --- a/src/tool/tool.h +++ b/src/tool/tool.h @@ -11,19 +11,87 @@ class tool { public: static list<string> split_string(string s_string, string s_split); - static bool is_alpha_numeric( string &s_digit ); + + static bool is_alpha_numeric( string &s_digit ) + { + const char *digit = s_digit.c_str(); + int i_len = strlen( digit ); + + for( int i=0; i<i_len; i++ ) + { + if ( ! isalnum( *digit ) ) + return false; + digit++; + } + return true; + } + static char* int2char( int i_int ); static char* clean_char( char* c_str); static string trim( string s_str ); static string replace( string s_string, string s_search, string s_replace ); - static string int2string( int i_int ); - static long unixtime(); - static int string2int( string s_digit ); + + static string int2string( int i_int ) + { + char buffer[64]; + sprintf(buffer, "%d", i_int); + return string(buffer); + } + + static long unixtime() + { + time_t clock; + return (long) time( &clock ); + } + + static int string2int( string s_digit ) + { + auto const char *digit = s_digit.c_str(); + int result = 0; + + // Convert each digit char and add into result. + while (*digit >= '0' && *digit <='9') + { + result = (result * 10) + (*digit - '0'); + digit++; + } + + // Check that there were no non-digits at end. + if (*digit != 0) + { + return -1; + } + + return result; + } + 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 @@ -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 |
