summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rwxr-xr-xsrc/main.cpp220
1 files changed, 61 insertions, 159 deletions
diff --git a/src/main.cpp b/src/main.cpp
index f80747e..6a96c38 100755
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,7 +1,7 @@
/*
- * yChat; Contact: www.yChat.org; Mail@yChat.org
+ * yChatContact: www.yChat.org; Mail@yChat.org
* Copyright (C) 2003 Paul C. Buetow, Volker Richter
- * Copyright (C) 2004, 2005 Paul C. Buetow
+ * Copyright (C) 2005 Paul C. Buetow
* -----------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or
@@ -20,176 +20,78 @@
*
*/
-#ifndef MAIN_CPP
-#define MAIN_CPP
-
-#include <unistd.h>
+// needed for ignoring SIGPIPE.
#include <signal.h>
-#include "incl.h"
-
-#ifndef NCURSES
-#ifdef CLI
-#include "cli/cli.h"
-#endif
-#endif
-
-#include "maps/hashmap.h"
-
-using namespace std;
-
-map<string,string>*
-parse_argc( int argc, char* argv[] )
-{
- map<string,string>* start_params = new map<string,string>;
-
- string s_output = "";
-
- // 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)
- string s_key;
-
- 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]);
- b_conf = 0;
- }
-
- else
- {
- 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 );
-
- if ( string(argv[i]).find("o") != string::npos )
- b_conf = 1;
- }
- }
-
- if ( !s_output.empty() )
- {
- cout << s_output;
- delete start_params;
- exit(1);
- }
-
- return start_params;
-}
-
-int
-main(int argc, char* argv[])
-{
- map<string,string>* p_start_params = parse_argc( argc, argv );
-
- cout << tool::ychat_version() << endl
- << DESCRIP << endl
- << DESCRI2 << endl
- << CONTACT << endl
- << SEPERAT << endl;
-
- // ignore SIGPIPE. otherwise the server will shut down with "Broken pipe" if
- // a client unexpected disconnects himself from a SOCK_STREAM.
- signal( SIGPIPE, SIG_IGN );
-
- // all the static data classes have to be initialized once. otherwise they will
- // contain only empty pointers and the chat server won't work correctly.
- // the order of the initializations is very importand. for example the s_html::init()
- // invokations assumes an initialized s_conf class.
- // begin to draw the ncurses amdin interface in a new pthread.
- // init the dynamic wrapper (is needed to pass all wrapped objects through a single pointer).
- wrap::WRAP = new dynamic_wrap;
-
- // init the config manager.
- wrap::WRAP->CONF = wrap::CONF = new conf( CONFILE, p_start_params );
- delete p_start_params,
-
-
- // init the statistic manager.
- wrap::WRAP->STAT = wrap::STAT = new stats;
-
- // 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;
- //*>>
-
-
- // init the socket manager.
- wrap::WRAP->SOCK = wrap::SOCK = new sock;
+// include header files which are included from every class too.
+#include "incl.h"
-#ifdef NCURSES
- wrap::WRAP->NCUR = wrap::NCUR = new ncur; // init the ncurses admin interface.
- wrap::NCUR->run(); // run the thread
+// include the chat manager.
+#include "s_chat.h"
- // wait until ncurses interface has been initialized.
- while ( ! wrap::NCUR->is_ready() )
- usleep(1000);
+// include the config manager.
+#include "s_conf.h"
- wrap::HTML->print_cached(0);
-#endif
+// include the html-template manager.
+#include "s_html.h"
- //<<*
- // init the chat manager.
- wrap::WRAP->CHAT = wrap::CHAT = new chat;
- //*>>
+// include the mutex manager for global synchronization.
+#include "s_mutx.h"
- // init the system timer.
- wrap::WRAP->TIMR = wrap::TIMR = new timr;
- wrap::TIMR->run(); // run the thread
+// include the socket manager.
+#include "s_sock.h"
- //<<*
- // init the module-loader manager.
- wrap::WRAP->MODL = wrap::MODL = new modl;
+// include the language manager
+#include "s_lang.h"
- // init the garbage collector
- wrap::WRAP->GCOL = wrap::GCOL = new gcol;
+// include the session manager
+#include "s_sman.h"
- // init the data manager.
-#ifdef DATABASE
- wrap::WRAP->DATA = wrap::DATA = new data;
-#endif
- //*>>
+using namespace std;
-#ifndef NCURSES
-#ifdef CLI
- cli* p_cli = new cli;
- p_cli->run();
-#endif
+int main()
+{
+#ifdef VERBOSE
+
+ cout << " ___ _ _ " << endl
+ << " _ _ / __\\ |__ __ _| |_ " << endl
+ << "| | | |/ / | '_ \\ / _` | __|" << endl
+ << "| |_| / /___| | | | (_| | |_ " << endl
+ << " \\__, \\____/|_| |_|\\__,_|\\__|" << endl
+ << " |___/ " << endl << endl
+
+ << DESCRIP << endl
+ << VERSION << ", "
+ << CONTACT << endl
+ << SEPERAT << endl
+ << STARTMS << endl ;
#endif
- //<<*
- // Initialize database connection queue
-#ifdef DATABASE
- wrap::DATA->initialize_connections();
+ // ignore SIGPIPE. otherwise the server will shut down with "Broken pipe" if
+ // a client unexpected disconnects himself from a SOCK_STREAM.
+ signal( SIGPIPE, SIG_IGN );
+
+ // all the static data classes have to be initialized once. otherwise they will
+ // contain only empty pointers and the chat server won't work correctly.
+ // the order of the initializations is very importand. for example the s_html::init()
+ // invokations assumes an initialized s_conf class.
+ s_mutx::init(); // init the mutex manager.
+ s_conf::init(); // init the config manager.
+ s_html::init(); // init the html-template manager.
+ s_lang::init(); // init the language manager
+ s_sman::init(); // init the session manager.
+ s_sock::init(); // init the socket manager.
+ s_chat::init(); // init the chat manager.
+
+ // start the socket manager. this one will listen for incoming http requests and will
+ // forward them to the specified routines which will generate a http response.
+ s_sock::get
+ ().start();
+
+#ifdef VERBOSE
+
+ cout << DOWNMSG << endl;
#endif
- //*>>
-
- // start the socket manager. this one will listen for incoming http requests and will
- // forward them to the specified routines which will generate a http response.
- wrap::SOCK->start();
- cout << DOWNMSG << endl;
- return 0;
+ return 0;
}
-
-#endif